From 664b79966c499440ef0bd95a9e909305124b3197 Mon Sep 17 00:00:00 2001 From: Adhidarma Hadiwinoto <me@adhisimon.org> Date: Sun, 20 Sep 2020 00:24:27 +0700 Subject: [PATCH] calculateBaseBillAmount enchancement --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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) { -- 1.9.0