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({ const discount = computed({
get: () => { get: () => {

View File

@ -147,10 +147,20 @@ const filteredTypes = computed(() => {
const taxAmount = computed(() => { const taxAmount = computed(() => {
if (localTax.compound_tax && props.discountedTotal) { 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 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 return (props.discountedTotal * localTax.percent) / 100
} }
@ -222,4 +232,23 @@ function removeTax(index) {
state[props.storeProp].items[props.itemIndex].taxes.splice(index, 1) 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> </script>

View File

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

View File

@ -144,6 +144,16 @@ export const useEstimateStore = (useWindow = false) => {
.get(`/api/v1/estimates/${id}`) .get(`/api/v1/estimates/${id}`)
.then((response) => { .then((response) => {
Object.assign(this.newEstimate, response.data.data) 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
// }
resolve(response) resolve(response)
}) })
.catch((err) => { .catch((err) => {

View File

@ -135,6 +135,16 @@ export const useInvoiceStore = (useWindow = false) => {
.then((response) => { .then((response) => {
Object.assign(this.newInvoice, response.data.data) Object.assign(this.newInvoice, response.data.data)
this.newInvoice.customer = response.data.data.customer 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
}
resolve(response) resolve(response)
}) })
.catch((err) => { .catch((err) => {

View File

@ -138,6 +138,7 @@
<script setup> <script setup>
import { computed, ref, watch, onMounted } from 'vue' import { computed, ref, watch, onMounted } from 'vue'
import { cloneDeep } from 'lodash'
import { useRoute, useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { import {
@ -257,11 +258,23 @@ async function submitForm() {
isSaving.value = true isSaving.value = true
let data = { let data = cloneDeep({
...estimateStore.newEstimate, ...estimateStore.newEstimate,
sub_total: estimateStore.getSubTotal, sub_total: estimateStore.getSubTotal,
total: estimateStore.getTotal, total: estimateStore.getTotal,
tax: estimateStore.getTotalTax, tax: estimateStore.getTotalTax,
})
if (data.discount_per_item === 'NO') {
data.items.forEach((item, index) => {
if (item.discount_type === 'fixed'){
data.items[index].discount = Math.round(item.discount * 100)
}
})
}
else {
if (data.discount_type === 'fixed'){
data.discount = Math.round(data.discount * 100)
}
} }
const action = isEdit.value const action = isEdit.value

View File

@ -147,6 +147,7 @@ import {
decimal, decimal,
} from '@vuelidate/validators' } from '@vuelidate/validators'
import useVuelidate from '@vuelidate/core' import useVuelidate from '@vuelidate/core'
import { cloneDeep } from 'lodash'
import { useInvoiceStore } from '@/scripts/admin/stores/invoice' import { useInvoiceStore } from '@/scripts/admin/stores/invoice'
import { useModuleStore } from '@/scripts/admin/stores/module' import { useModuleStore } from '@/scripts/admin/stores/module'
@ -258,11 +259,23 @@ async function submitForm() {
isSaving.value = true isSaving.value = true
let data = { let data = cloneDeep({
...invoiceStore.newInvoice, ...invoiceStore.newInvoice,
sub_total: invoiceStore.getSubTotal, sub_total: invoiceStore.getSubTotal,
total: invoiceStore.getTotal, total: invoiceStore.getTotal,
tax: invoiceStore.getTotalTax, tax: invoiceStore.getTotalTax,
})
if (data.discount_per_item === 'NO') {
data.items.forEach((item, index) => {
if (item.discount_type === 'fixed'){
data.items[index].discount = item.discount * 100
}
})
}
else {
if (data.discount_type === 'fixed'){
data.discount = data.discount * 100
}
} }
try { try {