diff options
Diffstat (limited to 'src/components/Display/SummaryDisplay.js')
-rw-r--r-- | src/components/Display/SummaryDisplay.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/components/Display/SummaryDisplay.js b/src/components/Display/SummaryDisplay.js index 2f65e79..9b1ca6b 100644 --- a/src/components/Display/SummaryDisplay.js +++ b/src/components/Display/SummaryDisplay.js @@ -13,10 +13,12 @@ const getBasicSummary = (items) => { let totalRawPrice = 0; let totalQuantity = 0; - for (let i = 0; i < items.length; i++) { - totalRawPrice += items[i].TotalPrice; - totalQuantity += items[i].Quantity - } + items.some((i) => { + totalRawPrice += i.TotalPrice; + totalQuantity += i.Quantity; + return null; + } + ) return ( { @@ -31,14 +33,17 @@ const getFullSummary = (items) => { let totalDiscount = 0; // to be subtracted from totalRawPrice let totalTax = 0; - for (let i = 0; i < items.length; i++) { - const itemTotalPrice = items[i].TotalPrice; - const itemDiscount = (items[i].Discount / 100) * itemTotalPrice; + items.some((i) => { + const itemTotalPrice = i.TotalPrice; + const itemDiscount = (i.Discount / 100) * itemTotalPrice; totalRawPrice += itemTotalPrice; totalDiscount += itemDiscount; - totalTax += (items[i].GST / 100) * (itemTotalPrice - itemDiscount); - } + totalTax += (i.GST / 100) * (itemTotalPrice - itemDiscount); + return null; + }) + + const totalPriceAfterTax = (totalRawPrice - totalDiscount) + totalTax; const totalRoundedOff = Math.abs(totalPriceAfterTax - Math.round(totalPriceAfterTax)); |