blob: dcb917ac77cbba38fe55532baffbf37d5462dcf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import currency from "currency.js"
export default class InvoiceItem {
UnitOfMeasure: string
Quantity: string
Name: string
Description: string
HSN: string
UnitPrice: string
GSTPercentage: string
BrandName: string
constructor() {
this.Name = ''
this.Description = ''
this.HSN = ''
this.UnitPrice = ''
this.GSTPercentage = ''
this.UnitOfMeasure = ''
this.Quantity = ""
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)
})
})
|