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"): diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index c5b815b5e619..152180a0b9d3 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -131,6 +131,24 @@ 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 +205,9 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo }, }); } + + // call select_total function while changing party field + this.frm.trigger("select_total"); } receivable_payable_account() { @@ -375,6 +396,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", {