diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 9f495e9fd8a..48a18e95b7a 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -152,6 +152,11 @@ frappe.ui.form.on('Payment Entry', { frm.events.hide_unhide_fields(frm); frm.events.set_dynamic_labels(frm); frm.events.show_general_ledger(frm); +<<<<<<< HEAD +======= + erpnext.accounts.ledger_preview.show_accounting_ledger_preview(frm); + erpnext.accounts.unreconcile_payments.add_unreconcile_btn(frm); +>>>>>>> 25fe752185 (chore: move functions to a separate file in utils) }, validate_company: (frm) => { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 90ee7613929..a411889fbdd 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -178,22 +178,7 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e } } - if (doc.docstatus == 1) { - frappe.call({ - "method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.doc_has_payments", - "args": { - "doctype": this.frm.doc.doctype, - "docname": this.frm.doc.name - }, - callback: function(r) { - if (r.message) { - me.frm.add_custom_button(__("Un-Reconcile"), function() { - erpnext.utils.build_unreconcile_dialog(cur_frm); - }); - } - } - }); - } + erpnext.accounts.unreconcile_payments.add_unreconcile_btn(me.frm); } diff --git a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py index cced2b3de49..c80365b0ef0 100644 --- a/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py +++ b/erpnext/accounts/doctype/unreconcile_payments/unreconcile_payments.py @@ -117,15 +117,22 @@ def get_linked_payments_for_doc( @frappe.whitelist() -def create_unreconcile_doc_for_selection( - company: str = None, dt: str = None, dn: str = None, selections: list = None -): +def create_unreconcile_doc_for_selection(selections=None): if selections: + selections = frappe.json.loads(selections) # assuming each row is a unique voucher for row in selections: unrecon = frappe.new_doc("Unreconcile Payments") - unrecon.company = company - unrecon.voucher_type = dt - unrecon.voucher_type = dn + unrecon.company = row.get("company") + unrecon.voucher_type = row.get("voucher_type") + unrecon.voucher_no = row.get("voucher_no") unrecon.add_references() + # remove unselected references + unrecon.allocations = [ + x + for x in unrecon.allocations + if x.reference_doctype == row.get("against_voucher_type") + and x.reference_name == row.get("against_voucher_no") + ] + unrecon.save().submit() diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js index 7b230af2699..5df6318a1cd 100644 --- a/erpnext/public/js/erpnext.bundle.js +++ b/erpnext/public/js/erpnext.bundle.js @@ -18,6 +18,11 @@ import "./utils/customer_quick_entry"; import "./utils/supplier_quick_entry"; import "./call_popup/call_popup"; import "./utils/dimension_tree_filter"; +<<<<<<< HEAD +======= +import "./utils/ledger_preview.js"; +import "./utils/unreconcile.js"; +>>>>>>> 25fe752185 (chore: move functions to a separate file in utils) import "./utils/barcode_scanner"; import "./telephony"; import "./templates/call_link.html"; diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 14532286696..eafc1ed70e6 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -666,61 +666,8 @@ erpnext.utils.update_child_items = function(opts) { }).show(); } -erpnext.utils.build_unreconcile_dialog = function(frm) { - if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) { - let child_table_fields = [ - { label: __("Voucher Type"), fieldname: "voucher_type", fieldtype: "Dynamic Link", options: "DocType", in_list_view: 1, read_only: 1}, - { label: __("Voucher No"), fieldname: "voucher_no", fieldtype: "Link", options: "voucher_type", in_list_view: 1, read_only: 1 }, - { label: __("Allocated Amount"), fieldname: "allocated_amount", fieldtype: "Float", in_list_view: 1, read_only: 1 }, - ] - let unreconcile_dialog_fields = [ - { - label: __('Allocations'), - fieldname: 'allocations', - fieldtype: 'Table', - read_only: 1, - fields: child_table_fields, - }, - ]; - // get linked payments - frappe.call({ - "method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.get_linked_payments_for_doc", - "args": { - "company": frm.doc.company, - "doctype": frm.doc.doctype, - "docname": frm.doc.name - }, - callback: function(r) { - if (r.message) { - // populate child table with allocations - unreconcile_dialog_fields[0].data = r.message; - unreconcile_dialog_fields[0].get_data = function(){ return r.message}; - let d = new frappe.ui.Dialog({ - title: 'Un-Reconcile Allocations', - fields: unreconcile_dialog_fields, - size: 'large', - cannot_add_rows: 1, - primary_action_label: 'Un-Reconcile', - primary_action(values) { - - let selected_allocations = values.allocations.filter(x=>x.__checked); - if (selected_allocations.length > 0) { - // assuming each row is an individual voucher - // pass this to server side method that created unreconcile doc for row - } else { - frappe.msgprint("No Selection"); - } - } - }); - - d.show(); - } - } - }); - } -} erpnext.utils.map_current_doc = function(opts) { function _map() { diff --git a/erpnext/public/js/utils/unreconcile.js b/erpnext/public/js/utils/unreconcile.js new file mode 100644 index 00000000000..509cd394100 --- /dev/null +++ b/erpnext/public/js/utils/unreconcile.js @@ -0,0 +1,106 @@ +frappe.provide('erpnext.accounts'); + +erpnext.accounts.unreconcile_payments = { + add_unreconcile_btn(frm) { + if (frm.doc.docstatus == 1) { + frappe.call({ + "method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.doc_has_payments", + "args": { + "doctype": frm.doc.doctype, + "docname": frm.doc.name + }, + callback: function(r) { + if (r.message) { + frm.add_custom_button(__("Un-Reconcile"), function() { + erpnext.accounts.unreconcile_payments.build_unreconcile_dialog(frm); + }); + } + } + }); + } + }, + + build_unreconcile_dialog(frm) { + if (['Sales Invoice', 'Purchase Invoice', 'Payment Entry', 'Journal Entry'].includes(frm.doc.doctype)) { + let child_table_fields = [ + { label: __("Voucher Type"), fieldname: "voucher_type", fieldtype: "Dynamic Link", options: "DocType", in_list_view: 1, read_only: 1}, + { label: __("Voucher No"), fieldname: "voucher_no", fieldtype: "Link", options: "voucher_type", in_list_view: 1, read_only: 1 }, + { label: __("Allocated Amount"), fieldname: "allocated_amount", fieldtype: "Float", in_list_view: 1, read_only: 1 }, + ] + let unreconcile_dialog_fields = [ + { + label: __('Allocations'), + fieldname: 'allocations', + fieldtype: 'Table', + read_only: 1, + fields: child_table_fields, + }, + ]; + + // get linked payments + frappe.call({ + "method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.get_linked_payments_for_doc", + "args": { + "company": frm.doc.company, + "doctype": frm.doc.doctype, + "docname": frm.doc.name + }, + callback: function(r) { + if (r.message) { + // populate child table with allocations + unreconcile_dialog_fields[0].data = r.message; + unreconcile_dialog_fields[0].get_data = function(){ return r.message}; + + let d = new frappe.ui.Dialog({ + title: 'Un-Reconcile Allocations', + fields: unreconcile_dialog_fields, + size: 'large', + cannot_add_rows: 1, + primary_action_label: 'Un-Reconcile', + primary_action(values) { + + let selected_allocations = values.allocations.filter(x=>x.__checked); + if (selected_allocations.length > 0) { + // assuming each row is an individual voucher + // pass this to server side method that creates unreconcile doc for each row + if (['Sales Invoice', 'Purchase Invoice'].includes(frm.doc.doctype)) { + let selection_map = selected_allocations.map(function(elem) { + return { + company: elem.company, + voucher_type: elem.voucher_type, + voucher_no: elem.voucher_no, + against_voucher_type: frm.doc.doctype, + against_voucher_no: frm.doc.name + }; + + }); + + erpnext.utils.create_unreconcile_docs(selection_map); + d.hide(); + } + + } else { + frappe.msgprint("No Selection"); + } + } + }); + + d.show(); + } + } + }); + } + }, + + create_unreconcile_docs(selection_map) { + frappe.call({ + "method": "erpnext.accounts.doctype.unreconcile_payments.unreconcile_payments.create_unreconcile_doc_for_selection", + "args": { + "selections": selection_map + }, + }); + } + + + +}