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

@ -271,6 +271,7 @@ const price = computed({
} else {
updateItemAttribute('price', newValue)
}
setDiscount()
},
})
@ -281,13 +282,8 @@ const discount = computed({
return props.itemData.discount
},
set: (newValue) => {
if (props.itemData.discount_type === 'percentage') {
updateItemAttribute('discount_val', (subtotal.value * newValue) / 100)
} else {
updateItemAttribute('discount_val', Math.round(newValue * 100))
}
updateItemAttribute('discount', newValue)
setDiscount()
},
})
@ -399,7 +395,7 @@ const v$ = useVuelidate(
function updateTax(data) {
props.store.$patch((state) => {
state[props.storeProp].items[props.index]['taxes'][data.index] = data.item
state[props.storeProp].items[props.index].taxes[data.index] = data.item
})
let lastTax = props.itemData.taxes[props.itemData.taxes.length - 1]
@ -416,6 +412,16 @@ function updateTax(data) {
syncItemToStore()
}
function setDiscount() {
const newValue = props.store[props.storeProp].items[props.index].discount
if (props.itemData.discount_type === 'percentage'){
updateItemAttribute('discount_val', Math.round((subtotal.value * newValue) / 100))
}else{
updateItemAttribute('discount_val', Math.round(newValue * 100))
}
}
function searchVal(val) {
updateItemAttribute('name', val)
}
@ -489,6 +495,9 @@ function syncItemToStore() {
totalTax: totalTax.value,
tax: totalTax.value,
taxes: [...itemTaxes],
tax_type_ids: itemTaxes.flatMap(_t =>
_t.tax_type_id ? _t.tax_type_id : [],
),
}
props.store.updateItem(data)