fix(qris): kirim tagihan manual pakai total tunggakan
All checks were successful
CI / test (push) Successful in 2m43s
All checks were successful
CI / test (push) Successful in 2m43s
- ensureInvoiceQris menerima base total agar kode unik konsisten dengan cron/portal - pesan manual menampilkan total tagihan, bukan satu invoice
This commit is contained in:
@@ -40,8 +40,8 @@ function spintax(t) {
|
||||
});
|
||||
}
|
||||
|
||||
function buildMessage(tplRaw, c, inv, qr) {
|
||||
const amount = Number(inv.amount || 0);
|
||||
function buildMessage(tplRaw, c, inv, qr, totalAmount) {
|
||||
const amount = Number(totalAmount || inv.amount || 0);
|
||||
const qrisAmount = Number((qr && qr.amount) || 0) || amount;
|
||||
const qrisCode = Number((qr && qr.uniqueCode) || 0) || 0;
|
||||
const qrisAttached = !!(qr && qr.payload);
|
||||
@@ -77,7 +77,8 @@ function buildTargets(isolateDay) {
|
||||
if (!invs.length) continue;
|
||||
if (!c.phone || String(c.phone).replace(/\D/g, '').length < 9) continue;
|
||||
// invoice terurut dari periode terlama; tagih yang paling lama dulu
|
||||
targets.push({ c, inv: invs[0] });
|
||||
const total = invs.reduce((sum, row) => sum + (Number(row.amount) || 0), 0);
|
||||
targets.push({ c, inv: invs[0], total });
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
@@ -118,10 +119,10 @@ async function start(opts = {}) {
|
||||
(async () => {
|
||||
for (let i = 0; i < targets.length; i++) {
|
||||
if (STATUS.stopped) break;
|
||||
const { c, inv } = targets[i];
|
||||
const { c, inv, total } = targets[i];
|
||||
try {
|
||||
const qr = (isQris && ensureInvoiceQris) ? (ensureInvoiceQris(inv) || {}) : null;
|
||||
const caption = buildMessage(tplRaw, c, inv, qr);
|
||||
const qr = (isQris && ensureInvoiceQris) ? (ensureInvoiceQris(inv, total) || {}) : null;
|
||||
const caption = buildMessage(tplRaw, c, inv, qr, total);
|
||||
if (isQris && QRCode && qr && qr.payload) {
|
||||
const url = await QRCode.toDataURL(qr.payload, { errorCorrectionLevel: 'M', margin: 1, width: 520 });
|
||||
const buf = Buffer.from(String(url).split(',')[1], 'base64');
|
||||
|
||||
@@ -30,10 +30,11 @@ function isQrisAmountTaken(amount, opts = {}) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function ensureInvoiceQris(inv) {
|
||||
function ensureInvoiceQris(inv, baseAmountOverride) {
|
||||
const settings = getSettings() || {};
|
||||
const invId = Number((inv && inv.id) || 0);
|
||||
const base = Number((inv && inv.amount) || 0);
|
||||
// baseAmountOverride dipakai bila nominal QRIS = total beberapa tagihan
|
||||
const base = Number(baseAmountOverride || (inv && inv.amount) || 0);
|
||||
if (!invId || base <= 0) return { uniqueCode: 0, amount: base, payload: '' };
|
||||
|
||||
let code = Number(inv.qris_unique_code || 0);
|
||||
|
||||
Reference in New Issue
Block a user