Commit 29a9db174119628e45ec1636b36016c2caf0aedd

Authored by Adhidarma Hadiwinoto
1 parent 2b2e7581eb
Exists in master

Perbaikan calculateBaseBillAmount uppercase keyword

Showing 2 changed files with 49 additions and 8 deletions Side-by-side Diff

... ... @@ -168,29 +168,53 @@ function calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyv
168 168 function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval, billCount) {
169 169 if (
170 170 !productKeyval
171   - || !Array.isArray(productKeyval)
172   - || !productKeyval.KEYWORD_TOTALTAG
  171 + || !productKeyval.KEYWORD_TOTALTAG
173 172 || !productKeyval.KEYWORD_ADMINFEE
174 173 ) {
175 174 return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount);
176 175 }
177   -
  176 +
178 177 const billCountOrDefault = billCount || 1;
179 178  
180 179 const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG;
181 180 if (!totalTagihanKeyword) return 0;
182 181  
183   - const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword);
  182 + const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword.toUpperCase());
184 183 const totalTagihanValue = Number((totalTagihanItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''));
185   - if (!totalTagihanValue) return 0;
  184 + if (!totalTagihanValue) {
  185 + if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) {
  186 + // eslint-disable-next-line no-console
  187 + console.log('=========== MISSING totalTagihanValue D7282FA7');
  188 + }
  189 +
  190 + return 0;
  191 + }
186 192  
187 193 const defaultAdminFee = Number(productKeyval.ADMINFEE || '');
188 194  
189 195 const adminFeeKeyword = productKeyval.KEYWORD_ADMINFEE;
190   - if (!adminFeeKeyword && defaultAdminFee) return totalTagihanValue - (defaultAdminFee * billCountOrDefault);
191   - if (!adminFeeKeyword) return 0;
  196 + if (!adminFeeKeyword && defaultAdminFee) {
  197 + if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) {
  198 + // eslint-disable-next-line no-console
  199 + console.log('======== TOTAL TAGIHAN VALUE - (DEFAULT ADMIN FEE * BILL COUNT) D35E56AD') ;
  200 + }
  201 + return totalTagihanValue - (defaultAdminFee * billCountOrDefault);
  202 + }
192 203  
193   - const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword);
  204 + if (!adminFeeKeyword) {
  205 + if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) {
  206 + // eslint-disable-next-line no-console
  207 + console.log('======== Missing adminFeeKeyword');
  208 + }
  209 +
  210 + return 0;
  211 + }
  212 +
  213 + const adminFeeItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === adminFeeKeyword.toUpperCase());
  214 + if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) {
  215 + // eslint-disable-next-line no-console
  216 + console.log(`======== adminFeeItem: ${adminFeeKeyword}`, adminFeeItem);
  217 + }
194 218 const adminFeeValue = Number((adminFeeItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''));
195 219 if (!adminFeeValue) return 0;
196 220  
... ... @@ -179,6 +179,13 @@ describe('#irs', function() {
179 179 splitted.find((item) => item.keyword === 'TAGIHAN').value.should.equal('131560');
180 180 splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000');
181 181 });
  182 +
  183 + it('should return correct result - tajira', () => {
  184 + const splitted = irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000');
  185 + // console.log(splitted);
  186 + splitted.find((item) => item.keyword === 'REFID').value.should.equal('20770812');
  187 + splitted.find((item) => item.keyword === 'Admin').value.should.equal('2500');
  188 + });
182 189 });
183 190  
184 191 describe('#calculateBaseBillAmount', () => {
... ... @@ -214,6 +221,16 @@ describe('#irs', function() {
214 221 // },
215 222 // 1
216 223 ).should.equal(10140);
  224 +
  225 + irs.calculateBaseBillAmount(
  226 + irs.splitPostpaidDetail('REFID:20770812/NAMA:SALWA AZ ZAHRA/CABANG:1012-DEPOK/Periode:1/Admin:2500/TOTALBAYAR:28.000'),
  227 + null,
  228 + {
  229 + KEYWORD_TOTALTAG: 'TOTALBAYAR',
  230 + KEYWORD_ADMINFEE: 'Admin',
  231 + },
  232 + 1
  233 + ).should.equal(25500);
217 234 });
218 235 });
219 236