Files
ns_erpnext_app/ns_app/public/js/sales_invoice.js
2026-01-13 11:10:35 -05:00

69 lines
1.7 KiB
JavaScript

frappe.ui.form.on("Sales Invoice", {
refresh(frm) {
if (frm.doc.docstatus !== 1) return; // submitted only
frm.add_custom_button("Run Payment", () => {
run_payment_flow(frm);
});
}
});
function run_payment_flow(frm) {
frappe.call({
method: "ns_app.api.payments.check_autopay",
args: {
customer: frm.doc.customer
},
callback(r) {
if (!r.message) return;
if (r.message.autopay_enabled) {
run_autopay(frm, r.message.autopay_id);
} else {
open_manual_payment_form(frm);
}
}
});
function run_autopay(frm, autopay_id) {
frappe.confirm(
`Run AutoPay for $${frm.doc.grand_total}?`,
() => {
frappe.call({
method: "ns_app.api.payments.run_autopay_payment",
args: {
invoice: frm.doc.name,
autopay_id: autopay_id,
amount: frm.doc.grand_total
},
callback(r) {
frappe.msgprint(r.message || "Payment processed");
frm.reload_doc();
}
});
}
);
}
function open_manual_payment_form(frm) {
const dialog = new frappe.ui.Dialog({
title: "Enter Payment",
fields: [
{
fieldtype: "HTML",
fieldname: "payment_form",
options: `<iframe
src="https://payments.yourprovider.com/pay?invoice=${frm.doc.name}&amount=${frm.doc.grand_total}"
style="width:100%;height:500px;border:none;"
></iframe>`
}
]
});
dialog.show();
}
}