Commit 70b752d0c00508fd031e975b5f31c4f89acca7b5
1 parent
96017767e7
Exists in
master
calculateBaseBillAmount
Showing 2 changed files with 36 additions and 1 deletions Side-by-side Diff
index.js
... | ... | @@ -141,6 +141,22 @@ function splitPostpaidDetail(str) { |
141 | 141 | return retval; |
142 | 142 | } |
143 | 143 | |
144 | +function calculateBaseBillAmount(detailSpitted) { | |
145 | + const keywords = ['TAGIHAN', 'DENDA', 'RPPREMI']; | |
146 | + | |
147 | + let retval = 0; | |
148 | + let detailCount = (detailSpitted || []).length; | |
149 | + | |
150 | + for (let i = 0; i < detailCount; i += 1) { | |
151 | + const item = detailSpitted[i]; | |
152 | + if (keywords.indexOf(item.keyword.toUpperCase()) >= 0) { | |
153 | + retval += Number(item.value) || 0; | |
154 | + } | |
155 | + } | |
156 | + | |
157 | + return retval; | |
158 | +} | |
159 | + | |
144 | 160 | exports.getRcFromMessage = getRcFromMessage; |
145 | 161 | exports.getPriceFromMessage = getPriceFromMessage; |
146 | 162 | exports.getSnFromMessage = getSnFromMessage; |
... | ... | @@ -149,4 +165,5 @@ exports.isInquiryResponseMessage = isInquiryResponseMessage; |
149 | 165 | exports.isPaymentResponseMessage = isPaymentResponseMessage; |
150 | 166 | exports.isPostpaidResponseMessage = isPostpaidResponseMessage; |
151 | 167 | exports.getDetailFromMessage = getDetailFromMessage; |
152 | -exports.splitPostpaidDetail = splitPostpaidDetail; | |
153 | 168 | \ No newline at end of file |
169 | +exports.splitPostpaidDetail = splitPostpaidDetail; | |
170 | +exports.calculateBaseBillAmount = calculateBaseBillAmount; |
test/main.js
... | ... | @@ -110,4 +110,22 @@ describe('#irs', function() { |
110 | 110 | splitted.find((item) => item.keyword === 'DENDA').value.should.equal('9000'); |
111 | 111 | }); |
112 | 112 | }); |
113 | + | |
114 | + describe('#calculateBaseBillAmount', () => { | |
115 | + it('should return correct value - inquiry', () => { | |
116 | + const detail = 'NAMA:MUSHOLLA-NURUL-KHOIR/DAYA:450/TARIF:S2/JMLBLN:1BLN/PERIODE:201712/METERKINI:18984/METERLALU:18932/TAGIHAN:14441/ADM:1600/DENDA:3000/TOTALTAGIHAN:19041'; | |
117 | + const splitted = irs.splitPostpaidDetail(detail); | |
118 | + | |
119 | + irs.calculateBaseBillAmount(splitted).should.equal(17441); | |
120 | + | |
121 | + }) | |
122 | + | |
123 | + it('should return correct value - payment', () => { | |
124 | + const detail = 'S/N: 0BNS25G5082152526173/NAMA:DONAR-HARHAP/DAYA:900/TARIF:R1M/JMLBLN:2BLN/PERIODE:201910,201911/METERKINI:5508/METERLALU:5508/TAGIHAN:131560/ADM:5000/DENDA:9000/TOTALBAYAR:145560'; | |
125 | + const splitted = irs.splitPostpaidDetail(detail); | |
126 | + | |
127 | + irs.calculateBaseBillAmount(splitted).should.equal(140560); | |
128 | + | |
129 | + }) | |
130 | + }); | |
113 | 131 | }); |
114 | 132 | \ No newline at end of file |