From a8cbfa7338cddab2835cc914c53b58a1ff9d12a0 Mon Sep 17 00:00:00 2001 From: monroy95 Date: Tue, 5 Jan 2021 17:27:24 +0000 Subject: [PATCH] #18 OK generacion multiples pdf para Payment Entry con standard format --- .../cambiare_cheque_print_set.js | 75 ++++++++++++++++--- .../cambiare_cheque_print_set.py | 3 +- .../cheque_to_print/cheque_to_print.json | 11 ++- 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.js b/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.js index 58e4314..975ae18 100755 --- a/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.js +++ b/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.js @@ -29,15 +29,7 @@ frappe.ui.form.on('Cambiare Cheque Print Set', { currency: frm.doc.currency }, }, - // freeze: true, - // freeze_message: __('Generando reporte, por favor espere...'), callback: function (r) { - // if (!r.exc) { - // clearInterval(frm.page['interval']); - // frm.reload_doc(); - // } - console.log(r.message); - frm.doc.cheque_to_print = [] frm.refresh_field("cheque_to_print"); @@ -47,7 +39,8 @@ frappe.ui.form.on('Cambiare Cheque Print Set', { cheque_no: element.cheque_no, amount: element.amount, party_type: element.party_type, - third_party: element.third_party + third_party: element.third_party, + id: element.id }); }); frm.refresh_field("cheque_to_print"); @@ -55,5 +48,69 @@ frappe.ui.form.on('Cambiare Cheque Print Set', { frm.save(); } }); + }, + refresh: function (frm) { + frm.add_custom_button(__('TEST'), () => { + let data_je = []; + let data_pe = []; + + frm.doc.cheque_to_print.forEach(element => { + if (element.transaction_id == 'Journal Entry') { + data_je.push(element.id); + } + + if (element.transaction_id == 'Payment Entry') { + data_pe.push(element.id); + } + }); + + console.log(data_je, data_pe); + + + + const dialog = new frappe.ui.Dialog({ + title: __('Print Documents'), + fields: [{ + 'fieldtype': 'Check', + 'label': __('With Letterhead'), + 'fieldname': 'with_letterhead' + }, + { + 'fieldtype': 'Select', + 'label': __('Print Format'), + 'fieldname': 'print_sel', + options: frappe.meta.get_print_formats(frm.doc.doctype) + }] + }); + + dialog.set_primary_action(__('Print'), args => { + if (!args) return; + + // Primero se imprimen los cheques para payment entry + for (const iterator of ['Payment Entry', 'Journal Entry']) { + console.log(iterator) + + const default_print_format = 'Standard'; // frappe.get_meta(iterator).default_print_format; + const with_letterhead = args.with_letterhead ? 1 : 0; + const print_format = args.print_sel ? args.print_sel : 'Standard'; //default_print_format; + const json_string = JSON.stringify(data_pe); + + const w = window.open('/api/method/frappe.utils.print_format.download_multi_pdf?' + + 'doctype=' + encodeURIComponent(iterator) + + '&name=' + encodeURIComponent(json_string) + + '&format=' + encodeURIComponent(print_format) + + '&no_letterhead=' + (with_letterhead ? '0' : '1')); + if (!w) { + frappe.msgprint(__('Please enable pop-ups')); + return; + } + + } + }); + + dialog.show(); + + + }).addClass('btn btn-primary'); } }); diff --git a/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py b/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py index f9201c2..f459594 100755 --- a/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py +++ b/cambiare_gtq/cambiare_gtq/doctype/cambiare_cheque_print_set/cambiare_cheque_print_set.py @@ -50,7 +50,7 @@ def get_data_of_payment_entry(filters): data = frappe.db.sql( f""" - SELECT 'Payment Entry' AS transaction_id, reference_no AS cheque_no, + SELECT name AS id, 'Payment Entry' AS transaction_id, reference_no AS cheque_no, paid_amount AS amount, party_type, party AS third_party FROM `tabPayment Entry` WHERE mode_of_payment='Cheque' AND company='{filters.company}' @@ -100,6 +100,7 @@ def get_data_of_journal_entry(filters): 'party_type': ['!=', '']}, fieldname=['party_type', 'party'], as_dict=1)[0] all_data.append({ + 'id': data_je.get('id'), 'transaction_id': 'Journal Entry', 'cheque_no': cheque_no, 'amount': amount, diff --git a/cambiare_gtq/cambiare_gtq/doctype/cheque_to_print/cheque_to_print.json b/cambiare_gtq/cambiare_gtq/doctype/cheque_to_print/cheque_to_print.json index 228e2c6..b33af3e 100644 --- a/cambiare_gtq/cambiare_gtq/doctype/cheque_to_print/cheque_to_print.json +++ b/cambiare_gtq/cambiare_gtq/doctype/cheque_to_print/cheque_to_print.json @@ -8,7 +8,8 @@ "cheque_no", "amount", "party_type", - "third_party" + "third_party", + "id" ], "fields": [ { @@ -50,10 +51,16 @@ "options": "Payment Entry\nJournal Entry", "read_only": 1, "translatable": 1 + }, + { + "fieldname": "id", + "fieldtype": "Data", + "label": "ID", + "read_only": 1 } ], "istable": 1, - "modified": "2021-01-04 16:38:50.122641", + "modified": "2021-01-05 11:04:07.383002", "modified_by": "Administrator", "module": "Cambiare GTQ", "name": "Cheque To Print",