mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-29 12:41:10 -04:00
add changes in tax per item calculation
This commit is contained in:
@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user