From 332e2847cfbdaecc1767220170ef18812f73787c Mon Sep 17 00:00:00 2001
From: Adhidarma Hadiwinoto <me@adhisimon.org>
Date: Wed, 23 Sep 2020 13:07:49 +0700
Subject: [PATCH] Perbaikan validitas totalTagihanItem

---
 index.js | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 731a15b..91364f6 100644
--- a/index.js
+++ b/index.js
@@ -173,20 +173,26 @@ function calculateBaseBillAmount(detailSplitted, customKeywords, productKeyval,
     ) {
         return calculateBaseBillAmountAuto(detailSplitted, customKeywords, productKeyval, billCount);
     }
-    
+
     const billCountOrDefault = billCount || 1;
 
     const totalTagihanKeyword = productKeyval.KEYWORD_TOTALTAG;
     if (!totalTagihanKeyword) return 0;
 
     const totalTagihanItem = detailSplitted.find((item) => (item.keyword || '').toUpperCase() === totalTagihanKeyword.toUpperCase());
-    const totalTagihanValue = Number((totalTagihanItem.value || '').trim().replace(/^rp */i, '').replace(/\./g, ''));
+    const totalTagihanValue = Number(
+        ((totalTagihanItem && totalTagihanItem.value) || '')
+            .trim()
+            .replace(/^rp */i, '')
+            .replace(/\./g, '')
+    );
+
     if (!totalTagihanValue) {
         if (process.env.DEBUG_IRS_CALCULATE_BASE_BILL_AMOUNT) {
             // eslint-disable-next-line no-console
             console.log('=========== MISSING totalTagihanValue D7282FA7');
         }
-        
+
         return 0;
     }
 
-- 
1.9.0