mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-27 19:51:09 -04:00 
			
		
		
		
	fix initial tax per item issue
This commit is contained in:
		| @ -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: () => { | ||||
|  | ||||
| @ -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) { | ||||
|     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> | ||||
|  | ||||
| @ -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, | ||||
|           }) | ||||
|  | ||||
| @ -144,6 +144,16 @@ export const useEstimateStore = (useWindow = false) => { | ||||
|             .get(`/api/v1/estimates/${id}`) | ||||
|             .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 | ||||
|               // } | ||||
|               resolve(response) | ||||
|             }) | ||||
|             .catch((err) => { | ||||
|  | ||||
| @ -135,6 +135,16 @@ export const useInvoiceStore = (useWindow = false) => { | ||||
|             .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 | ||||
|               } | ||||
|               resolve(response) | ||||
|             }) | ||||
|             .catch((err) => { | ||||
|  | ||||
| @ -138,6 +138,7 @@ | ||||
|  | ||||
| <script setup> | ||||
| import { computed, ref, watch, onMounted } from 'vue' | ||||
| import { cloneDeep } from 'lodash' | ||||
| import { useRoute, useRouter } from 'vue-router' | ||||
| import { useI18n } from 'vue-i18n' | ||||
| import { | ||||
| @ -257,11 +258,23 @@ async function submitForm() { | ||||
|  | ||||
|   isSaving.value = true | ||||
|  | ||||
|   let data = { | ||||
|   let data = cloneDeep({ | ||||
|     ...estimateStore.newEstimate, | ||||
|     sub_total: estimateStore.getSubTotal, | ||||
|     total: estimateStore.getTotal, | ||||
|     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 | ||||
|  | ||||
| @ -147,6 +147,7 @@ import { | ||||
|   decimal, | ||||
| } from '@vuelidate/validators' | ||||
| import useVuelidate from '@vuelidate/core' | ||||
| import { cloneDeep } from 'lodash' | ||||
|  | ||||
| import { useInvoiceStore } from '@/scripts/admin/stores/invoice' | ||||
| import { useModuleStore } from '@/scripts/admin/stores/module' | ||||
| @ -258,11 +259,23 @@ async function submitForm() { | ||||
|  | ||||
|   isSaving.value = true | ||||
|  | ||||
|   let data = { | ||||
|   let data = cloneDeep({ | ||||
|     ...invoiceStore.newInvoice, | ||||
|     sub_total: invoiceStore.getSubTotal, | ||||
|     total: invoiceStore.getTotal, | ||||
|     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 { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user