diff --git a/index.js b/index.js index ccfd4c1..a7e4216 100644 --- a/index.js +++ b/index.js @@ -143,7 +143,7 @@ function splitPostpaidDetail(str) { return retval; } -function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval) { +function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) { const keywords = customKeywords || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA']; let retval = 0; @@ -160,6 +160,8 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval) if (retval) return retval; if (!productKeyval || !Array.isArray(productKeyval) || !productKeyval.length) return 0; + const billCountOrDefault = billCount || 1; + const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG; if (!totalTagihanKeyword) return 0; @@ -170,14 +172,14 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval) const defaultAdminFee = Number(productKeyval.ADMINFEE || ''); const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE; - if (!adminFeeKeyword && defaultAdminFee) return totalTagihanValue - defaultAdminFee; + if (!adminFeeKeyword && defaultAdminFee) return totalTagihanValue - (defaultAdminFee * billCountOrDefault); if (!adminFeeKeyword) return 0; const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword); const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); if (!adminFeeValue) return 0; - return totalTagihanValue - adminFeeValue; + return totalTagihanValue - (adminFeeValue * billCountOrDefault); } function getBillCount(msg) {