aboutsummaryrefslogtreecommitdiff
path: root/src/classes/invoice_item.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/invoice_item.ts')
-rw-r--r--src/classes/invoice_item.ts24
1 files changed, 22 insertions, 2 deletions
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)
+ })