From 300a4eb39ccea56da416d83400cddc97118e1649 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 12 Oct 2022 21:04:39 +0530 Subject: showing total (sum) values in InvoiceItemTable --- src/classes/item.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/classes/item.js') diff --git a/src/classes/item.js b/src/classes/item.js index 0486262..639a63f 100644 --- a/src/classes/item.js +++ b/src/classes/item.js @@ -64,3 +64,20 @@ export const editItem = (item, ok, fail) => { .then(res => ok()) .catch(err => fail()) } + +export const getDiscountValue = (item) => item.DiscountPercentage > 0 + ? ((item.UnitPrice * item.Quantity)/100) * item.DiscountPercentage : 0.00; + +export const getGSTValue = (item) => item.GSTPercentage > 0 + ? (((item.UnitPrice * item.Quantity) - getDiscountValue(item))/100) * item.GSTPercentage : 0.00; + +export const getAmount = (item) => + (item.UnitPrice * item.Quantity) - getDiscountValue(item) + getGSTValue(item) + +export const calcSum = (items) => items.reduce((prev, current, id, arr) => ({ + GST: prev.GST + getGSTValue(current), + Discount: prev.Discount + getDiscountValue(current), + UnitPrice: prev.UnitPrice + current.UnitPrice, + Amount: prev.Amount + getAmount(current), + Quantity: prev.Quantity + current.Quantity +}), {GST: 0, Discount: 0, UnitPrice: 0, Amount: 0, Quantity: 0}); -- cgit v1.2.3