Commit 664b79966c499440ef0bd95a9e909305124b3197
1 parent
aa483547d4
Exists in
master
calculateBaseBillAmount enchancement
Showing 1 changed file with 5 additions and 3 deletions Side-by-side Diff
index.js
... | ... | @@ -143,7 +143,7 @@ function splitPostpaidDetail(str) { |
143 | 143 | return retval; |
144 | 144 | } |
145 | 145 | |
146 | -function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval) { | |
146 | +function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) { | |
147 | 147 | const keywords = customKeywords || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA']; |
148 | 148 | |
149 | 149 | let retval = 0; |
... | ... | @@ -160,6 +160,8 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval) |
160 | 160 | if (retval) return retval; |
161 | 161 | if (!productKeyval || !Array.isArray(productKeyval) || !productKeyval.length) return 0; |
162 | 162 | |
163 | + const billCountOrDefault = billCount || 1; | |
164 | + | |
163 | 165 | const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG; |
164 | 166 | if (!totalTagihanKeyword) return 0; |
165 | 167 | |
... | ... | @@ -170,14 +172,14 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval) |
170 | 172 | const defaultAdminFee = Number(productKeyval.ADMINFEE || ''); |
171 | 173 | |
172 | 174 | const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE; |
173 | - if (!adminFeeKeyword && defaultAdminFee) return totalTagihanValue - defaultAdminFee; | |
175 | + if (!adminFeeKeyword && defaultAdminFee) return totalTagihanValue - (defaultAdminFee * billCountOrDefault); | |
174 | 176 | if (!adminFeeKeyword) return 0; |
175 | 177 | |
176 | 178 | const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword); |
177 | 179 | const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, '')); |
178 | 180 | if (!adminFeeValue) return 0; |
179 | 181 | |
180 | - return totalTagihanValue - adminFeeValue; | |
182 | + return totalTagihanValue - (adminFeeValue * billCountOrDefault); | |
181 | 183 | } |
182 | 184 | |
183 | 185 | function getBillCount(msg) { |