From c3206679f476e7fd001756190024e03f05340ea2 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 6 Jul 2024 03:20:30 +0530 Subject: populated items list and total in print preview --- src/classes/invoice_item.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/classes/invoice_item.ts') diff --git a/src/classes/invoice_item.ts b/src/classes/invoice_item.ts index c3da433..fe92f10 100644 --- a/src/classes/invoice_item.ts +++ b/src/classes/invoice_item.ts @@ -22,7 +22,7 @@ export default class InvoiceItem { } } -export const calculate = (items: InvoiceItem[]) => items.map((x: InvoiceItem) => { +export const calculate = (x: InvoiceItem) => { const quantity = currency(x.Quantity) const unitPrice = currency(x.UnitPrice) const gstPercentage = currency(x.GSTPercentage) @@ -39,4 +39,24 @@ export const calculate = (items: InvoiceItem[]) => items.map((x: InvoiceItem) => , AmountWithoutGST: amountWithoutGST , TotalAmount: amountWithoutGST.multiply(gstPercentage).divide(100).add(amountWithoutGST) }) -}) +} + +export const calculateArr = (items: InvoiceItem[]) => + items.map((x: InvoiceItem) => calculate(x)) + +export const calculateTotal = (items: InvoiceItem[]) => + items.reduce((total, item) => { + const c = calculate(item) + + return ({ + TotalQuantity: total.TotalQuantity.add(c.Quantity), + TotalGSTValue: total.TotalGSTValue.add(c.TotalGSTValue), + TotalWithoutGST: total.TotalWithoutGST.add(c.AmountWithoutGST), + TotalWithGST: total.TotalWithGST.add(c.TotalAmount) + }) + }, { + TotalQuantity: currency(0), + TotalGSTValue: currency(0), + TotalWithoutGST: currency(0), + TotalWithGST: currency(0) + }) -- cgit v1.2.3