add changes in tax per item calculation

This commit is contained in:
yashkanakiya
2023-08-25 17:45:43 +05:30
parent 4fc67c74e4
commit dbd75bbe68
7 changed files with 148 additions and 48 deletions

View File

@ -128,23 +128,14 @@ export const useInvoiceStore = (useWindow = false) => {
})
},
fetchInvoice(id) {
fetchInvoice(id, expand = []) {
return new Promise((resolve, reject) => {
axios
.get(`/api/v1/invoices/${id}`)
.get(`/api/v1/invoices/${id}`, { params: { expand } })
.then((response) => {
Object.assign(this.newInvoice, response.data.data)
this.newInvoice.customer = response.data.data.customer
if (this.newInvoice.discount_per_item === 'NO') {
this.newInvoice.items.forEach((_i, index) => {
if (_i.discount_type === 'fixed')
this.newInvoice.items[index].discount = _i.discount / 100
})
}
else {
if (this.newInvoice.discount_type === 'fixed')
this.newInvoice.discount = this.newInvoice.discount / 100
}
this.setInvoiceData(response.data.data)
this.setCustomerAddresses(this.newInvoice.customer)
resolve(response)
})
.catch((err) => {
@ -154,6 +145,38 @@ export const useInvoiceStore = (useWindow = false) => {
})
},
setInvoiceData(invoice) {
Object.assign(this.newInvoice, invoice)
if (this.newInvoice.tax_per_item === 'YES') {
this.newInvoice.items.forEach((_i) => {
if (_i.taxes && !_i.taxes.length)
_i.taxes.push({ ...taxStub, id: Guid.raw() })
})
}
if (this.newInvoice.discount_per_item === 'YES') {
this.newInvoice.items.forEach((_i, index) => {
if (_i.discount_type === 'fixed')
this.newInvoice.items[index].discount = _i.discount / 100
})
}
else {
if (this.newInvoice.discount_type === 'fixed')
this.newInvoice.discount = this.newInvoice.discount / 100
}
},
setCustomerAddresses(customer) {
const customer_business = customer.customer_business
if (customer_business?.billing_address)
this.newInvoice.customer.billing_address = customer_business.billing_address
if (customer_business?.shipping_address)
this.newInvoice.customer.shipping_address = customer_business.shipping_address
},
addSalesTaxUs() {
const taxTypeStore = useTaxTypeStore()
let salesTax = { ...taxStub }