Skip to content

Commit

Permalink
feat: Changes to mpesa b2c payment schema and functionalities. More c…
Browse files Browse the repository at this point in the history
…hanges incoming.
  • Loading branch information
GichanaMayaka committed May 10, 2024
1 parent 46bc78c commit 702add6
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>${doctype}</b> with filters specified`
),
indicator: "red",
title: "Error",
});
});
},
});

async function fetchAndSetContactDetails(frm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -126,6 +131,7 @@
"fieldname": "party",
"fieldtype": "Dynamic Link",
"label": "Party",
"mandatory_depends_on": "eval:doc.party_type",
"options": "party_type"
},
{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 702add6

Please sign in to comment.