From c4880df0d9f5ca268e337e28c6fa33e3bb93ad6b Mon Sep 17 00:00:00 2001 From: Prashant Kamble <99401472+pra17shant@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:09:02 +0000 Subject: [PATCH 1/4] feat: Add reconciliation feature for selecting invoices or payments, calculate total amount and outstanding balance for respective party --- .../payment_reconciliation.js | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index c5b815b5e619..51d5988f7b44 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -131,6 +131,20 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo }, }); } + + // Initialise display field + if (!this.frm.fields_dict.invoices_display) { + $(this.frm.fields_dict.invoices.wrapper).before('
'); + $(this.frm.fields_dict.payments.wrapper).before('
'); + } + + // call select_total function while clicking Invoice Table or Payment Table + this.frm.fields_dict['invoices'].grid.wrapper.on('click', '.grid-row-check', (event) => { + this.frm.trigger("select_total"); + }); + this.frm.fields_dict['payments'].grid.wrapper.on('click', '.grid-row-check', (event) => { + this.frm.trigger("select_total"); + }); } set_query_for_dimension_filters() { frappe.call({ @@ -187,6 +201,9 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo }, }); } + + // call select_total function while changing party field + this.frm.trigger("select_total"); } receivable_payable_account() { @@ -375,6 +392,58 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo }, }); } + + select_total() { + const currencyFormatter = new Intl.NumberFormat('en-IN', { + currency: 'INR', + minimumFractionDigits: 2, + maximumFractionDigits: 2, + }); + + // Helper function to sum the values of a field in an array of rows + const sumField = (rows, field) => rows.reduce((sum, row) => sum + (row[field] || 0), 0); + + // Get selected invoices and payments + const selectedInvoices = this.frm.fields_dict.invoices.grid.get_selected_children(); + const selectedPayments = this.frm.fields_dict.payments.grid.get_selected_children(); + + // Calculate totals for selected invoices and payments + const selectedInvoiceAmt = sumField(selectedInvoices, 'outstanding_amount'); + const selectedPaymentAmt = sumField(selectedPayments, 'amount'); + + // Calculate total for all invoices and payments + const invoiceTotal = sumField(this.frm.doc.invoices || [], 'outstanding_amount'); + const paymentTotal = sumField(this.frm.doc.payments || [], 'amount'); + + // Calculate differences + const totalOutstanding = invoiceTotal - paymentTotal; + const selectedDifference = selectedInvoiceAmt - selectedPaymentAmt; + + // Prepare HTML for invoices and payments display + const invoicesHtml = ` +
+

Invoice Total: ${currencyFormatter.format(invoiceTotal)}

+
+
+

Selected Invoice's: ${currencyFormatter.format(selectedInvoiceAmt)}

+
+ `; + + const paymentsHtml = ` +
+

Payment Total: ${currencyFormatter.format(paymentTotal)}

+

Total Outstanding: ${currencyFormatter.format(totalOutstanding)}

+
+
+

Selected Payment's: ${currencyFormatter.format(selectedPaymentAmt)}

+

Selected Amount: ${currencyFormatter.format(selectedDifference)}

+
+ `; + + // Update the HTML in the DOM + $('#invoices_display').html(invoicesHtml); + $('#payments_display').html(paymentsHtml); + } }; frappe.ui.form.on("Payment Reconciliation Allocation", { @@ -403,4 +472,4 @@ frappe.ui.form.on("Payment Reconciliation Allocation", { }, }); -extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({ frm: cur_frm })); +extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({ frm: cur_frm })); \ No newline at end of file From eab1e32b97ce9eaeeb387f66366f2f5b7aa3bc0d Mon Sep 17 00:00:00 2001 From: Prashant Kamble <99401472+pra17shant@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:06:47 +0000 Subject: [PATCH 2/4] fix: Pri-commit Issue --- .../payment_reconciliation.js | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index 51d5988f7b44..152180a0b9d3 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -134,17 +134,21 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo // Initialise display field if (!this.frm.fields_dict.invoices_display) { - $(this.frm.fields_dict.invoices.wrapper).before('
'); - $(this.frm.fields_dict.payments.wrapper).before('
'); - } + $(this.frm.fields_dict.invoices.wrapper).before( + '
' + ); + $(this.frm.fields_dict.payments.wrapper).before( + '
' + ); + } // call select_total function while clicking Invoice Table or Payment Table - this.frm.fields_dict['invoices'].grid.wrapper.on('click', '.grid-row-check', (event) => { - this.frm.trigger("select_total"); - }); - this.frm.fields_dict['payments'].grid.wrapper.on('click', '.grid-row-check', (event) => { - this.frm.trigger("select_total"); - }); + this.frm.fields_dict["invoices"].grid.wrapper.on("click", ".grid-row-check", (event) => { + this.frm.trigger("select_total"); + }); + this.frm.fields_dict["payments"].grid.wrapper.on("click", ".grid-row-check", (event) => { + this.frm.trigger("select_total"); + }); } set_query_for_dimension_filters() { frappe.call({ @@ -394,31 +398,31 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo } select_total() { - const currencyFormatter = new Intl.NumberFormat('en-IN', { - currency: 'INR', + const currencyFormatter = new Intl.NumberFormat("en-IN", { + currency: "INR", minimumFractionDigits: 2, maximumFractionDigits: 2, }); - + // Helper function to sum the values of a field in an array of rows const sumField = (rows, field) => rows.reduce((sum, row) => sum + (row[field] || 0), 0); - + // Get selected invoices and payments const selectedInvoices = this.frm.fields_dict.invoices.grid.get_selected_children(); const selectedPayments = this.frm.fields_dict.payments.grid.get_selected_children(); - + // Calculate totals for selected invoices and payments - const selectedInvoiceAmt = sumField(selectedInvoices, 'outstanding_amount'); - const selectedPaymentAmt = sumField(selectedPayments, 'amount'); - + const selectedInvoiceAmt = sumField(selectedInvoices, "outstanding_amount"); + const selectedPaymentAmt = sumField(selectedPayments, "amount"); + // Calculate total for all invoices and payments - const invoiceTotal = sumField(this.frm.doc.invoices || [], 'outstanding_amount'); - const paymentTotal = sumField(this.frm.doc.payments || [], 'amount'); - + const invoiceTotal = sumField(this.frm.doc.invoices || [], "outstanding_amount"); + const paymentTotal = sumField(this.frm.doc.payments || [], "amount"); + // Calculate differences const totalOutstanding = invoiceTotal - paymentTotal; const selectedDifference = selectedInvoiceAmt - selectedPaymentAmt; - + // Prepare HTML for invoices and payments display const invoicesHtml = `
@@ -428,7 +432,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo

Selected Invoice's: ${currencyFormatter.format(selectedInvoiceAmt)}

`; - + const paymentsHtml = `

Payment Total: ${currencyFormatter.format(paymentTotal)}

@@ -439,11 +443,11 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo

Selected Amount: ${currencyFormatter.format(selectedDifference)}

`; - + // Update the HTML in the DOM - $('#invoices_display').html(invoicesHtml); - $('#payments_display').html(paymentsHtml); - } + $("#invoices_display").html(invoicesHtml); + $("#payments_display").html(paymentsHtml); + } }; frappe.ui.form.on("Payment Reconciliation Allocation", { @@ -472,4 +476,4 @@ frappe.ui.form.on("Payment Reconciliation Allocation", { }, }); -extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({ frm: cur_frm })); \ No newline at end of file +extend_cscript(cur_frm.cscript, new erpnext.accounts.PaymentReconciliationController({ frm: cur_frm })); From 692a40733e59349bec2c39f40433fec984d4170e Mon Sep 17 00:00:00 2001 From: Prashant Kamble <99401472+pra17shant@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:58:12 +0000 Subject: [PATCH 3/4] Fix: Currency Precision Issue in Journal Entry Minor diff adjust credit or debit side --- .../accounts/doctype/journal_entry/journal_entry.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 3dcf96dbc13b..399d64191d40 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -890,6 +890,17 @@ def set_total_debit_credit(self): self.total_credit, self.precision("total_credit") ) + # It checks if the absolute difference is less than or equal to 0.01. + # If so, it adjusts either total_debit or total_credit by setting one to the value of the other (whichever is higher), and the difference is set to zero. + + if abs(self.difference) <= 0.01: + if self.total_debit > self.total_credit: + self.total_credit = flt(self.total_debit, self.precision("total_credit")) + else: + self.total_debit = flt(self.total_credit, self.precision("total_debit")) + + self.difference = 0 + def validate_multi_currency(self): alternate_currency = [] for d in self.get("accounts"): From 667cb8678b5c1ba82e499706b81643eec7fdea30 Mon Sep 17 00:00:00 2001 From: Prashant Kamble <99401472+pra17shant@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:58:12 +0000 Subject: [PATCH 4/4] Fix:#44265 Currency Precision Issue in Journal Entry Minor diff adjust credit or debit side --- .../accounts/doctype/journal_entry/journal_entry.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 3dcf96dbc13b..399d64191d40 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -890,6 +890,17 @@ def set_total_debit_credit(self): self.total_credit, self.precision("total_credit") ) + # It checks if the absolute difference is less than or equal to 0.01. + # If so, it adjusts either total_debit or total_credit by setting one to the value of the other (whichever is higher), and the difference is set to zero. + + if abs(self.difference) <= 0.01: + if self.total_debit > self.total_credit: + self.total_credit = flt(self.total_debit, self.precision("total_credit")) + else: + self.total_debit = flt(self.total_credit, self.precision("total_debit")) + + self.difference = 0 + def validate_multi_currency(self): alternate_currency = [] for d in self.get("accounts"):