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) {
|
function buildMessage(tplRaw, c, inv, qr, totalAmount) {
|
||||||
const amount = Number(inv.amount || 0);
|
const amount = Number(totalAmount || inv.amount || 0);
|
||||||
const qrisAmount = Number((qr && qr.amount) || 0) || amount;
|
const qrisAmount = Number((qr && qr.amount) || 0) || amount;
|
||||||
const qrisCode = Number((qr && qr.uniqueCode) || 0) || 0;
|
const qrisCode = Number((qr && qr.uniqueCode) || 0) || 0;
|
||||||
const qrisAttached = !!(qr && qr.payload);
|
const qrisAttached = !!(qr && qr.payload);
|
||||||
@@ -77,7 +77,8 @@ function buildTargets(isolateDay) {
|
|||||||
if (!invs.length) continue;
|
if (!invs.length) continue;
|
||||||
if (!c.phone || String(c.phone).replace(/\D/g, '').length < 9) continue;
|
if (!c.phone || String(c.phone).replace(/\D/g, '').length < 9) continue;
|
||||||
// invoice terurut dari periode terlama; tagih yang paling lama dulu
|
// 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;
|
return targets;
|
||||||
}
|
}
|
||||||
@@ -118,10 +119,10 @@ async function start(opts = {}) {
|
|||||||
(async () => {
|
(async () => {
|
||||||
for (let i = 0; i < targets.length; i++) {
|
for (let i = 0; i < targets.length; i++) {
|
||||||
if (STATUS.stopped) break;
|
if (STATUS.stopped) break;
|
||||||
const { c, inv } = targets[i];
|
const { c, inv, total } = targets[i];
|
||||||
try {
|
try {
|
||||||
const qr = (isQris && ensureInvoiceQris) ? (ensureInvoiceQris(inv) || {}) : null;
|
const qr = (isQris && ensureInvoiceQris) ? (ensureInvoiceQris(inv, total) || {}) : null;
|
||||||
const caption = buildMessage(tplRaw, c, inv, qr);
|
const caption = buildMessage(tplRaw, c, inv, qr, total);
|
||||||
if (isQris && QRCode && qr && qr.payload) {
|
if (isQris && QRCode && qr && qr.payload) {
|
||||||
const url = await QRCode.toDataURL(qr.payload, { errorCorrectionLevel: 'M', margin: 1, width: 520 });
|
const url = await QRCode.toDataURL(qr.payload, { errorCorrectionLevel: 'M', margin: 1, width: 520 });
|
||||||
const buf = Buffer.from(String(url).split(',')[1], 'base64');
|
const buf = Buffer.from(String(url).split(',')[1], 'base64');
|
||||||
|
|||||||
@@ -30,10 +30,11 @@ function isQrisAmountTaken(amount, opts = {}) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureInvoiceQris(inv) {
|
function ensureInvoiceQris(inv, baseAmountOverride) {
|
||||||
const settings = getSettings() || {};
|
const settings = getSettings() || {};
|
||||||
const invId = Number((inv && inv.id) || 0);
|
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: '' };
|
if (!invId || base <= 0) return { uniqueCode: 0, amount: base, payload: '' };
|
||||||
|
|
||||||
let code = Number(inv.qris_unique_code || 0);
|
let code = Number(inv.qris_unique_code || 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user