aboutsummaryrefslogtreecommitdiff
path: root/src/classes
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes')
-rw-r--r--src/classes/invoice.ts16
-rw-r--r--src/classes/invoice_item.ts24
2 files changed, 37 insertions, 3 deletions
diff --git a/src/classes/invoice.ts b/src/classes/invoice.ts
index 213eddc..0fee42f 100644
--- a/src/classes/invoice.ts
+++ b/src/classes/invoice.ts
@@ -1,7 +1,7 @@
import Address from './address'
import Item from './item'
-export default class Customer {
+export default class Invoice {
InvoiceDate: string
InvoiceNumber: number
BillingAddress: Address
@@ -32,3 +32,17 @@ export default class Customer {
this.CustomerWebsite = ""
}
}
+
+export class InvoiceTotal {
+ TotalQuantity: string
+ TotalGSTValue: string
+ TotalWithoutGST: string
+ TotalWithGST: string
+
+ constructor() {
+ this.TotalQuantity = ""
+ this.TotalGSTValue = ""
+ this.TotalWithoutGST = ""
+ this.TotalWithGST = ""
+ }
+}
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)
+ })