fix initial tax per item issue

This commit is contained in:
yashkanakiya
2023-08-25 09:33:30 +05:30
parent 05d5ce26fd
commit 27660c6bce
7 changed files with 81 additions and 8 deletions

View File

@ -274,7 +274,7 @@ const price = computed({
},
})
const subtotal = computed(() => props.itemData.price * props.itemData.quantity)
const subtotal = computed(() => Math.round(props.itemData.price * props.itemData.quantity))
const discount = computed({
get: () => {

View File

@ -147,10 +147,20 @@ const filteredTypes = computed(() => {
const taxAmount = computed(() => {
if (localTax.compound_tax && props.discountedTotal) {
const taxPerItemEnabled = props.store[props.storeProp].tax_per_item === 'YES'
const discountPerItemEnabled = props.store[props.storeProp].discount_per_item === 'NO'
if (taxPerItemEnabled && !discountPerItemEnabled){
return getTaxAmount()
}
return ((props.discountedTotal + props.totalTax) * localTax.percent) / 100
}
if (props.discountedTotal && localTax.percent) {
if (props.discountedTotal && localTax.percent) {
const taxPerItemEnabled = props.store[props.storeProp].tax_per_item === 'YES'
const discountPerItemEnabled = props.store[props.storeProp].discount_per_item === 'NO'
if (taxPerItemEnabled && !discountPerItemEnabled){
return getTaxAmount()
}
return (props.discountedTotal * localTax.percent) / 100
}
@ -222,4 +232,23 @@ function removeTax(index) {
state[props.storeProp].items[props.itemIndex].taxes.splice(index, 1)
})
}
function getTaxAmount() {
let total = 0
let discount = 0
const itemTotal = props.discountedTotal
const modelDiscount = props.store[props.storeProp].discount ? props.store[props.storeProp].discount.toFixed(2) : 0
const type = props.store[props.storeProp].discount_type
if (modelDiscount > 0) {
props.store[props.storeProp].items.forEach((_i) => {
total += _i.total
})
const proportion = (itemTotal / total).toFixed(2)
discount = type === 'fixed' ? modelDiscount * 100 : (total * modelDiscount) / 100
const itemDiscount = Math.round(discount * proportion)
const discounted = itemTotal - itemDiscount
return Math.round((discounted * localTax.percent) / 100)
}
return Math.round((props.discountedTotal * localTax.percent) / 100)
}
</script>

View File

@ -233,9 +233,7 @@ const totalDiscount = computed({
},
set: (newValue) => {
if (props.store[props.storeProp].discount_type === 'percentage') {
props.store[props.storeProp].discount_val = Math.round(
(props.store.getSubTotal * newValue) / 100
)
props.store[props.storeProp].discount_val = Math.round((props.store.getSubTotal * newValue.toFixed(2)) / 100)
} else {
props.store[props.storeProp].discount_val = Math.round(newValue * 100)
}
@ -265,7 +263,7 @@ const itemWiseTaxes = computed(() => {
} else if (tax.tax_type_id) {
taxes.push({
tax_type_id: tax.tax_type_id,
amount: tax.amount,
amount: Math.round(tax.amount),
percent: tax.percent,
name: tax.name,
})