Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reconciliation feature for selecting invoices or payments calculate total amount and outstanding balance for respective party #44251

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<div id="invoices_display" style="margin-bottom: 15px;"></div>'
);
$(this.frm.fields_dict.payments.wrapper).before(
'<div id="payments_display" style="margin-bottom: 15px;"></div>'
);
}

// 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({
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = `
<div style="font-weight: bold; font-size: 14px; color: green;">
<p>Invoice Total: ${currencyFormatter.format(invoiceTotal)}</p>
</div>
<div style="font-weight: bold; font-size: 14px; color: red;">
<p>Selected Invoice's: ${currencyFormatter.format(selectedInvoiceAmt)}</p>
</div>
`;

const paymentsHtml = `
<div style="display: flex; justify-content: space-between; font-weight: bold; font-size: 14px; color: green;">
<p>Payment Total: ${currencyFormatter.format(paymentTotal)}</p>
<p style="color: blue;"> Total Outstanding: ${currencyFormatter.format(totalOutstanding)} </p>
</div>
<div style="display: flex; justify-content: space-between; font-weight: bold; font-size: 14px; color: red;">
<p>Selected Payment's: ${currencyFormatter.format(selectedPaymentAmt)}</p>
<p style="color: blue;"> Selected Amount: ${currencyFormatter.format(selectedDifference)} </p>
</div>
`;

// Update the HTML in the DOM
$("#invoices_display").html(invoicesHtml);
$("#payments_display").html(paymentsHtml);
}
};

frappe.ui.form.on("Payment Reconciliation Allocation", {
Expand Down
Loading