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 ++++ src/components/pickers/item-picker.js | 10 +-- src/components/tables/invoice-item-table.js | 116 ++++++++++++++++++---------- src/components/tables/scss/table.scss | 8 ++ src/views/invoice/new.js | 13 +++- 5 files changed, 113 insertions(+), 51 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}); diff --git a/src/components/pickers/item-picker.js b/src/components/pickers/item-picker.js index 339319f..d756427 100644 --- a/src/components/pickers/item-picker.js +++ b/src/components/pickers/item-picker.js @@ -37,10 +37,10 @@ const ItemPicker = ({invoiceItems, addInvoiceItem}) => { } const handleInput = e => { - const { name, value } = e.target; + const { name, value, type } = e.target; setItem(prevItem => ({ ...prevItem, - [name]: value + [name]: type === "number" ? parseFloat(value) : value })); } @@ -65,7 +65,7 @@ const ItemPicker = ({invoiceItems, addInvoiceItem}) => { {items.map(i => )} @@ -76,8 +76,8 @@ const ItemPicker = ({invoiceItems, addInvoiceItem}) => { type="number" value={item.Quantity} name="Quantity" - min={item.MinQuantity} - max={item.MaxQuantity} + min={item.MinQuantity > 0 ? item.MinQuantity : 1} + max={item.MaxQuantity > 0 ? item.MaxQuantity : null} onChange={handleInput} />