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

@ -138,22 +138,13 @@ export const useEstimateStore = (useWindow = false) => {
})
},
fetchEstimate(id) {
fetchEstimate(id, expand = []) {
return new Promise((resolve, reject) => {
axios
.get(`/api/v1/estimates/${id}`)
.get(`/api/v1/estimates/${id}`, { params: { expand } })
.then((response) => {
Object.assign(this.newEstimate, response.data.data)
if (this.newEstimate.discount_per_item === 'NO') {
this.newEstimate.items.forEach((_i, index) => {
if (_i.discount_type === 'fixed')
this.newEstimate.items[index].discount = _i.discount / 100
})
}
else {
if (this.newEstimate.discount_type === 'fixed')
this.newEstimate.discount = this.newEstimate.discount / 100
}
this.setEstimateData(response.data.data)
this.setCustomerAddresses(this.newEstimate.customer)
resolve(response)
})
.catch((err) => {
@ -164,6 +155,41 @@ export const useEstimateStore = (useWindow = false) => {
})
},
setEstimateData(estimate) {
Object.assign(this.newEstimate, estimate)
if (this.newEstimate.tax_per_item === 'YES') {
this.newEstimate.items.forEach((_i) => {
if (_i.taxes && !_i.taxes.length){
_i.taxes.push({ ...taxStub, id: Guid.raw() })
}
})
}
if (this.newEstimate.discount_per_item === 'YES') {
this.newEstimate.items.forEach((_i, index) => {
if (_i.discount_type === 'fixed'){
this.newEstimate.items[index].discount = _i.discount / 100
}
})
}
else {
if (this.newEstimate.discount_type === 'fixed'){
this.newEstimate.discount = this.newEstimate.discount / 100
}
}
},
setCustomerAddresses(customer) {
const customer_business = customer.customer_business
if (customer_business?.billing_address){
this.newEstimate.customer.billing_address = customer_business.billing_address
}
if (customer_business?.shipping_address){
this.newEstimate.customer.shipping_address = customer_business.shipping_address
}
},
addSalesTaxUs() {
const taxTypeStore = useTaxTypeStore()
let salesTax = { ...taxStub }