Commit aa483547d44d1c7411ed40b7e039ebf528ca3bdf

Authored by Adhidarma Hadiwinoto
1 parent facc75c66c
Exists in master

calculateBaseBillAmount support productKeyval

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

... ... @@ -119,7 +119,7 @@ function getDetailFromMessage(msg, rule, replacementRules) {
119 119 match_idx: 1,
120 120 }
121 121 }
122   -
  122 +
123 123 return (
124 124 regexLooperReplace(extractFromMessage(msg, rule), replacementRules) || ''
125 125 ).trim() || null;
... ... @@ -143,8 +143,8 @@ function splitPostpaidDetail(str) {
143 143 return retval;
144 144 }
145 145  
146   -function calculateBaseBillAmount(detailSplitted, customKeywords) {
147   - const keywords = customKeywords || ['TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA'];
  146 +function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval) {
  147 + const keywords = customKeywords || ['TAGIHANASLI', 'TAGIHAN', 'DENDA', 'RPPREMI', 'BIAYA'];
148 148  
149 149 let retval = 0;
150 150 let detailCount = (detailSplitted || []).length;
... ... @@ -157,7 +157,27 @@ function calculateBaseBillAmount(detailSplitted, customKeywords) {
157 157 }
158 158 }
159 159  
160   - return retval;
  160 + if (retval) return retval;
  161 + if (!productKeyval || !Array.isArray(productKeyval) || !productKeyval.length) return 0;
  162 +
  163 + const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG;
  164 + if (!totalTagihanKeyword) return 0;
  165 +
  166 + const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword);
  167 + const totalTagihanValue = Number((totalTagihanItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''));
  168 + if (!totalTagihanValue) return 0;
  169 +
  170 + const defaultAdminFee = Number(productKeyval.ADMINFEE || '');
  171 +
  172 + const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE;
  173 + if (!adminFeeKeyword && defaultAdminFee) return totalTagihanValue - defaultAdminFee;
  174 + if (!adminFeeKeyword) return 0;
  175 +
  176 + const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword);
  177 + const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''));
  178 + if (!adminFeeValue) return 0;
  179 +
  180 + return totalTagihanValue - adminFeeValue;
161 181 }
162 182  
163 183 function getBillCount(msg) {