diff options
Diffstat (limited to 'src/classes/invoice_item.ts')
-rw-r--r-- | src/classes/invoice_item.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/classes/invoice_item.ts b/src/classes/invoice_item.ts index a7a0a85..dcb917a 100644 --- a/src/classes/invoice_item.ts +++ b/src/classes/invoice_item.ts @@ -1,3 +1,5 @@ +import currency from "currency.js" + export default class InvoiceItem { UnitOfMeasure: string Quantity: string @@ -19,3 +21,22 @@ export default class InvoiceItem { this.BrandName = "" } } + +export const calculate = (items: InvoiceItem[]) => items.map((x: InvoiceItem) => { + const quantity = currency(x.Quantity) + const unitPrice = currency(x.UnitPrice) + const gstPercentage = currency(x.GSTPercentage) + const gstValue = unitPrice.multiply(gstPercentage).divide(100) + const totalGSTValue = gstValue.multiply(quantity) + const amountWithoutGST = unitPrice.multiply(quantity) + + return({ + ...x + , Quantity: quantity + , UnitPrice: unitPrice + , GSTValue: gstValue + , TotalGSTValue: totalGSTValue + , AmountWithoutGST: amountWithoutGST + , TotalAmount: amountWithoutGST.add(totalGSTValue) + }) +}) |