diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-12 21:04:39 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-12 21:04:39 +0530 |
commit | 300a4eb39ccea56da416d83400cddc97118e1649 (patch) | |
tree | 9ba1dc0c4f8d64bce52ba9a9fd9a73ac5d090103 /src/classes/item.js | |
parent | 0b4343bed2cace86552929f25202680c0d99c541 (diff) |
showing total (sum) values in InvoiceItemTable
Diffstat (limited to 'src/classes/item.js')
-rw-r--r-- | src/classes/item.js | 17 |
1 files changed, 17 insertions, 0 deletions
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}); |