Commit ba1503e4e20ac22fe908b805516db679a10a9a48

Authored by Adhidarma Hadiwinoto
1 parent 73a6b0a5b9
Exists in master

Classic calculateBaseBillAmountAuto splitted from calculateBaseBillAmount

Showing 1 changed file with 20 additions and 4 deletions Side-by-side Diff

... ... @@ -143,8 +143,13 @@ function splitPostpaidDetail(str) {
143 143 return retval;
144 144 }
145 145  
146   -function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) {
147   - const keywords = customKeywords || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA'];
  146 +function calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval) {
  147 + const tagihanAsliKeyvalKeywords = ((productKeyval && productKeyval.KEYWORD_TAGASLI) || '')
  148 + .split(/ *, */);
  149 +
  150 + const keywords = (tagihanAsliKeyvalKeywords && Array.isArray(tagihanAsliKeyvalKeywords) && tagihanAsliKeyvalKeywords.length && tagihanAsliKeyvalKeywords)
  151 + || customKeywords
  152 + || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA'];
148 153  
149 154 let retval = 0;
150 155 let detailCount = (detailSplitted || []).length;
... ... @@ -157,8 +162,18 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval,
157 162 }
158 163 }
159 164  
160   - if (retval) return retval;
161   - if (!productKeyval || !Array.isArray(productKeyval) || !productKeyval.length) return 0;
  165 + return retval;
  166 +}
  167 +
  168 +function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) {
  169 + if (
  170 + !productKeyval
  171 + || !Array.isArray(productKeyval)
  172 + || !productKeyval.KEYWORD_TOTALTAG
  173 + || !productKeyval.KEYWORD_ADMINFEE
  174 + ) {
  175 + return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount);
  176 + }
162 177  
163 178 const billCountOrDefault = billCount || 1;
164 179  
... ... @@ -182,6 +197,7 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval,
182 197 return totalTagihanValue - (adminFeeValue * billCountOrDefault);
183 198 }
184 199  
  200 +
185 201 function getBillCount(msg) {
186 202 const matches = (msg || '').match(/JMLBLN:(\d+)BLN/);
187 203 return (matches && Number(matches[1])) || null;