diff --git a/.gitignore b/.gitignore index ba04025..33110cf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ *.swp tags node_modules -__pycache__ \ No newline at end of file +__pycache__ +*.md \ No newline at end of file diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js index 78bdf8b..437ed1b 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.js @@ -11,7 +11,10 @@ frappe.ui.form.on('Payment Advice', { refresh: function (frm) { if (frm.doc.__islocal && !frm.doc.transaction_date) { - frm.set_value('transaction_date', frappe.datetime.get_today()); + frm.set_value('transaction_date', frappe.datetime.get_today()); + toggle_exchange_rate_field(frm); + set_amount_labels(frm); + convert_amount(frm); } if (frm.doc.docstatus === 1) { @@ -95,6 +98,20 @@ frappe.ui.form.on('Payment Advice', { company: function(frm) { set_cost_center_filter(frm); }, + + transaction_currency(frm) { + toggle_exchange_rate_field(frm); + set_amount_labels(frm); + convert_amount(frm); + }, + + exchange_rate(frm) { + convert_amount(frm); + }, + + amount(frm) { + convert_amount(frm); + } }); // Set up event handlers for the table @@ -270,11 +287,30 @@ frappe.ui.form.on('Payment Advice Reference', { filter = ['advance_amount', date_field] } else if (row.reference_doctype == "Purchase Invoice") { if (frappe.meta.has_field("Purchase Invoice", "custom_job_record")) { - filter = ['grand_total', date_field, 'custom_job_record', 'outstanding_amount', 'bill_no']; + filter = ['grand_total', date_field, 'custom_job_record', 'outstanding_amount', 'bill_no', 'base_grand_total', 'currency', 'conversion_rate']; } else { - filter = ['grand_total', date_field, 'outstanding_amount', 'bill_no']; + filter = ['grand_total', date_field, 'outstanding_amount', 'bill_no', 'base_grand_total', 'currency', 'conversion_rate']; } - } else { + } else if (row.reference_doctype == "Sales Invoice") { + if (frappe.meta.has_field("Sales Invoice", "custom_job_record")) { + filter = ['grand_total', date_field, 'custom_job_record', 'outstanding_amount', 'base_grand_total', 'currency', 'conversion_rate']; + } else { + filter = ['grand_total', date_field, 'outstanding_amount', 'base_grand_total', 'currency', 'conversion_rate']; + } + } else if (row.reference_doctype == "Sales Order") { + if (frappe.meta.has_field("Sales Order", "custom_job_record")) { + filter = ['grand_total', date_field, 'custom_job_record', 'base_grand_total', 'currency', 'conversion_rate']; + } else { + filter = ['grand_total', date_field, 'base_grand_total', 'currency', 'conversion_rate']; + } + } else if (row.reference_doctype == "Purchase Order") { + if (frappe.meta.has_field("Purchase Order", "custom_job_record")) { + filter = ['grand_total', date_field, 'custom_job_record', 'base_grand_total', 'currency', 'conversion_rate']; + } else { + filter = ['grand_total', date_field, 'base_grand_total', 'currency', 'conversion_rate']; + } + } + else { filter = ['grand_total', date_field] } @@ -289,13 +325,27 @@ frappe.ui.form.on('Payment Advice Reference', { (r) => { if (r) { - if (r.grand_total != null) { - frappe.model.set_value(cdt, cdn, 'amount', r.grand_total); + if (r.base_grand_total != null) { + frappe.model.set_value(cdt, cdn, 'amount', r.base_grand_total); if (r.outstanding_amount && r.outstanding_amount != null) { frappe.model.set_value(cdt, cdn, 'net_payable_amount', r.outstanding_amount); - frappe.model.set_value(cdt, cdn, 'settled_amount', r.grand_total - r.outstanding_amount); + frappe.model.set_value(cdt, cdn, 'settled_amount', r.base_grand_total - r.outstanding_amount); + } + } + + if (r.currency && r.conversion_rate) { + frappe.model.set_value(cdt, cdn, 'currency', r.currency); + frappe.model.set_value(cdt, cdn, 'exchange_rate', r.conversion_rate); + + if (r.grand_total){ + frappe.model.set_value(cdt, cdn, 'amount_in_currency', r.grand_total); + if (r.outstanding_amount && r.outstanding_amount != null) { + frappe.model.set_value(cdt, cdn, 'net_payable_amount_in_currency', r.outstanding_amount/r.conversion_rate); + frappe.model.set_value(cdt, cdn, 'settled_amount_in_currency', r.grand_total - (r.outstanding_amount/r.conversion_rate)); + } } + } if (r.advance_amount != null) { @@ -342,3 +392,99 @@ frappe.ui.form.on('Payment Advice Reference', { } }); + + +//Exchange Rate Show / Hide + +function toggle_exchange_rate_field(frm) { + + const company_currency = frappe.defaults.get_default("currency"); + + if (frm.doc.transaction_currency === company_currency) { + // frm.set_df_property('exchange_rate', 'hidden', 1); + frm.set_value('exchange_rate', 1); + } else { + // frm.set_df_property('exchange_rate', 'hidden', 0); + } +} + + +//MAIN CALCULATION (MASTER) + +function convert_amount(frm) { + + if (!frm.doc.amount) return; + + let total = 0; + if ( + frm.doc.transaction_currency && + frm.doc.transaction_currency !== frm.doc.company_currency && + frm.doc.exchange_rate + ) { + total = flt(frm.doc.amount) / flt(frm.doc.exchange_rate); + } + else { + total = flt(frm.doc.amount); + } + + total = flt(total, 6); + frm.set_value("amount_in_trans_cur", total); + frm.set_value("amount_to_be_settled_trans_curr", flt(frm.doc.amount_to_be_settled) / flt(frm.doc.exchange_rate)); + + + let amount_paid_trans = flt(frm.doc.amount_paid) / flt(frm.doc.exchange_rate); + frm.set_value("amount_paid_in_trans_curr", amount_paid_trans); + +} + + +//Dynamic Labels + +function set_amount_labels(frm) { + + const company_currency = frappe.defaults.get_default("currency"); + const txn_currency = frm.doc.transaction_currency || company_currency; + + frm.set_df_property( + "amount", + "label", + `Total Amount (${company_currency})` + ); + + frm.set_df_property( + "amount_paid", + "label", + `Total Amount Paid (${company_currency})` + ); + + frm.set_df_property( + "amount_to_be_settled", + "label", + `Total To Be Settled (${company_currency})` + ); + + frm.set_df_property( + "amount_in_trans_cur", + "label", + `Total Amount (${txn_currency})` + ); + + frm.set_df_property( + "amount_paid_in_trans_curr", + "label", + `Total Amount Paid (${txn_currency})` + ); + + frm.set_df_property( + "amount_to_be_settled_trans_curr", + "label", + `Total To Be Settled (${txn_currency})` + ); + + frm.set_df_property( + "exchange_rate", + "description", + `1 ${txn_currency} = ? ${company_currency}` + ); +} + diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json index a7c966b..2865567 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.json @@ -24,12 +24,17 @@ "references_section", "payment_advice_reference", "transaction_details_section", + "transaction_currency", "amount", "amount_paid", - "column_break_stbs", - "amount_to_be_settled", "amount_to_be_settled_in_words", - "transaction_currency", + "amount_to_be_settled", + "column_break_stbs", + "exchange_rate", + "amount_in_trans_cur", + "amount_paid_in_trans_curr", + "amount_words_trans_curr", + "amount_to_be_settled_trans_curr", "section_break_favc", "payment_amount", "reference_no", @@ -319,6 +324,36 @@ "fieldtype": "Date", "label": "Payment Entry Date", "read_only": 1 + }, + { + "fieldname": "exchange_rate", + "fieldtype": "Currency", + "label": "Exchange Rate", + "precision": "6" + }, + { + "fieldname": "amount_in_trans_cur", + "fieldtype": "Currency", + "label": "Total Amount", + "read_only": 1 + }, + { + "fieldname": "amount_paid_in_trans_curr", + "fieldtype": "Currency", + "label": "Total Amount Paid", + "read_only": 1 + }, + { + "fieldname": "amount_words_trans_curr", + "fieldtype": "Data", + "label": "Amount To be Settled In Words", + "read_only": 1 + }, + { + "fieldname": "amount_to_be_settled_trans_curr", + "fieldtype": "Currency", + "label": "Total Amount To be Settled", + "read_only": 1 } ], "index_web_pages_for_search": 1, @@ -329,7 +364,7 @@ "link_fieldname": "custom_payment_advice" } ], - "modified": "2025-11-18 10:38:08.153731", + "modified": "2026-02-12 18:23:42.737425", "modified_by": "Administrator", "module": "Payment Advice", "name": "Payment Advice", diff --git a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py index af92e58..93659f9 100644 --- a/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py +++ b/payment_advice/payment_advice/doctype/payment_advice/payment_advice.py @@ -153,3 +153,4 @@ def create_payment_entry(payment_advice): except Exception as e: frappe.log_error(f"Error creating payment entry: {str(e)}") frappe.throw(f"Error creating payment entry: {str(e)}") + diff --git a/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json b/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json index 8ee9aa4..2cf2aeb 100644 --- a/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json +++ b/payment_advice/payment_advice/doctype/payment_advice_reference/payment_advice_reference.json @@ -12,9 +12,17 @@ "date", "aeging", "cost_center", + "currency", + "exchange_rate", + "section_break_pbul", "amount", "settled_amount", "net_payable_amount", + "column_break_dgbd", + "amount_in_currency", + "settled_amount_in_currency", + "net_payable_amount_in_currency", + "section_break_sfdc", "remarks" ], "fields": [ @@ -86,12 +94,56 @@ "label": "Cost Center", "options": "Cost Center", "read_only": 1 + }, + { + "fieldname": "section_break_pbul", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_dgbd", + "fieldtype": "Column Break" + }, + { + "fieldname": "amount_in_currency", + "fieldtype": "Currency", + "label": "Total Amount in Currency", + "read_only": 1 + }, + { + "fieldname": "settled_amount_in_currency", + "fieldtype": "Currency", + "label": "Settled Amount in Currency", + "read_only": 1 + }, + { + "fieldname": "net_payable_amount_in_currency", + "fieldtype": "Currency", + "label": "Net Payable Amount in Currency", + "read_only": 1 + }, + { + "fieldname": "section_break_sfdc", + "fieldtype": "Section Break" + }, + { + "fieldname": "currency", + "fieldtype": "Link", + "label": "Currency", + "options": "Currency", + "read_only": 1 + }, + { + "fieldname": "exchange_rate", + "fieldtype": "Float", + "label": "Exchange Rate", + "precision": "6", + "read_only": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2025-08-12 14:38:26.178631", + "modified": "2026-02-12 19:20:45.177581", "modified_by": "Administrator", "module": "Payment Advice", "name": "Payment Advice Reference",