From 702add65087729bfc0343166bee7613bb768166f Mon Sep 17 00:00:00 2001 From: GichanaMayaka Date: Fri, 10 May 2024 12:21:08 +0200 Subject: [PATCH] feat: Changes to mpesa b2c payment schema and functionalities. More changes incoming. --- .../mpesa_b2c_payment/mpesa_b2c_payment.js | 66 +++++++++++++++++-- .../mpesa_b2c_payment/mpesa_b2c_payment.json | 56 +++++++++++++--- 2 files changed, 107 insertions(+), 15 deletions(-) diff --git a/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.js b/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.js index 8d01757..1478c80 100644 --- a/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.js +++ b/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.js @@ -87,17 +87,69 @@ frappe.ui.form.on("MPesa B2C Payment", { await fetchAndSetContactDetails(frm); }, - party_type: function (frm) { + commandid: function (frm) { + frm.set_value("party_type", ""); frm.set_value("party", ""); - if (frm.doc.party_type === "Supplier") { - frm.set_value("commandid", "BusinessPayment"); - } else if (frm.doc.party_type === "Employee") { - frm.set_value("commandid", "SalaryPayment"); - } else { - frm.set_value("commandid", ""); + if (frm.doc.commandid === "SalaryPayment") { + frm.set_value("party_type", "Employee"); } }, + party_type: function (frm) { + frm.set_query("doctype_to_pay_against", function () { + const doctypeFieldsList = + frm.doc.party_type === "Employee" + ? ["Salary Slip", "Expense Claim", "Employee Advances"] + : ["Purchase Invoice", "Payment Entry"]; + + return { + filters: [["DocType", "name", "in", doctypeFieldsList]], + }; + }); + }, + doctype_to_pay_against: function (frm) { + const doctype = frm.doc.doctype_to_pay_against; + frappe.db + .get_list(doctype, { + fields: ["*"], + filters: { + creation: ["between", frm.doc.start_date, frm.doc.end_date], + }, + }) + .then((response) => { + if (!response.length) { + throw new Error("No Data Fetched"); + } else { + response.forEach(async (data) => { + const contact = await frappe.db.get_value( + "Employee", + { name: data.employee }, + ["cell_number"] + ); + + // Update fields of child table with filtered data + const row = frm.add_child("items"); + frappe.model.set_value(row.doctype, row.name, { + reference_doctype: doctype, + record: data.name, + receiver_name: data.employee, + partyb: contact.message?.cell_number, + }); + cur_frm.refresh_fields("items"); + }); + } + }) + .catch((error) => { + if (error.message === "No Data Fetched") + frappe.msgprint({ + message: __( + `No records fetched for doctype ${doctype} with filters specified` + ), + indicator: "red", + title: "Error", + }); + }); + }, }); async function fetchAndSetContactDetails(frm) { diff --git a/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.json b/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.json index 8bbc1e5..65768d3 100644 --- a/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.json +++ b/navari_mpesa_b2c/mpesa_b2c/doctype/mpesa_b2c_payment/mpesa_b2c_payment.json @@ -10,22 +10,27 @@ "naming_series", "section_break_pujd", "originatorconversationid", + "transaction_details_section", + "commandid", + "remarks", + "column_break_jg71", + "amount", + "occassion", "receiver_details_section", "party_type", "party", - "column_break_rc4l", "party_name", "partyb", + "doctype_to_pay_against", + "column_break_rc4l", + "start_date", + "end_date", + "section_break_rrbq", + "items", "accounts_section", "account_paid_from", "column_break_nsjt", "account_paid_to", - "transaction_details_section", - "commandid", - "remarks", - "column_break_jg71", - "amount", - "occassion", "payment_status_and_errors_section", "status", "error_code", @@ -126,6 +131,7 @@ "fieldname": "party", "fieldtype": "Dynamic Link", "label": "Party", + "mandatory_depends_on": "eval:doc.party_type", "options": "party_type" }, { @@ -185,11 +191,45 @@ { "fieldname": "column_break_oy1c", "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.party_type;", + "fieldname": "section_break_rrbq", + "fieldtype": "Section Break", + "label": "Employee Payments", + "mandatory_depends_on": "eval:doc.party_type;" + }, + { + "depends_on": "eval:doc.party_type === \"Employee\";", + "fieldname": "start_date", + "fieldtype": "Date", + "label": "Start Date", + "mandatory_depends_on": "eval:doc.party_type === \"Employee\";" + }, + { + "depends_on": "eval:doc.party_type === \"Employee\";", + "fieldname": "end_date", + "fieldtype": "Date", + "label": "End Date", + "mandatory_depends_on": "eval:doc.party_type === \"Employee\";" + }, + { + "fieldname": "doctype_to_pay_against", + "fieldtype": "Link", + "label": "Doctype To Pay Against", + "options": "DocType", + "reqd": 1 + }, + { + "fieldname": "items", + "fieldtype": "Table", + "label": "Items", + "options": "MPesa B2C Employee Payment Item" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-11-20 15:45:00.620824", + "modified": "2024-05-10 11:52:17.934998", "modified_by": "Administrator", "module": "MPesa B2C", "name": "MPesa B2C Payment",