Files
InvoiceShelf/resources/scripts/admin/components/estimate-invoice-common/CreateTotalTaxes.vue
Fabio Ribeiro d69a56e2d5 feat: Tax included (#370)
* feat: Tax included

* Added a toggle switch in tax settings to enable the feature.
* Database migration adding tax_included field into estimates, invoices
  and recurring invoices table.
* Toggle switch to enable and store the tax_included by estimates,
  invoices and recurring invoices.
* In case of tax included enabled, total taxes will be recalculated and
  the invoices, estimates and recurring invoices total won't be sum with
  taxes.
* Apply tax included when discount_per_item/tax_per_item item is enabled.
* Custom component to show the net total when tax included is enabled.
* Update invoice and estimates pdfs with net total.

* chore: Tax included by default

A switch button inside the tax settings to enable the tax included by
default in invoices, estimates and recurring invoices.
2025-08-28 10:28:24 +02:00

109 lines
2.4 KiB
Vue

<template>
<div class="flex items-center justify-between w-full mt-2 text-sm">
<label v-if="tax.calculation_type === 'percentage'" class="font-semibold leading-5 text-gray-500 uppercase">
{{ tax.name }} ({{ tax.percent }} %)
</label>
<label v-else class="font-semibold leading-5 text-gray-500 uppercase">
{{ tax.name }} (<BaseFormatMoney :amount="tax.fixed_amount" :currency="currency" />)
</label>
<label class="flex items-center justify-center text-lg text-black">
<BaseFormatMoney :amount="tax.amount" :currency="currency" />
<BaseIcon
name="TrashIcon"
class="h-5 ml-2 cursor-pointer"
@click="$emit('remove', tax.id)"
/>
</label>
</div>
</template>
<script setup>
import { computed, watch, inject, watchEffect } from 'vue'
const props = defineProps({
index: {
type: Number,
required: true,
},
tax: {
type: Object,
required: true,
},
taxes: {
type: Array,
required: true,
},
currency: {
type: [Object, String],
required: true,
},
store: {
type: Object,
default: null,
},
storeProp: {
type: String,
default: '',
},
data: {
type: String,
default: '',
},
})
const emit = defineEmits(['update', 'remove'])
const utils = inject('$utils')
const taxAmount = computed(() => {
if (props.tax.calculation_type === 'fixed') {
return props.tax.fixed_amount;
}
if (props.tax.compound_tax && props.store.getSubtotalWithDiscount) {
return Math.round(
((props.store.getSubtotalWithDiscount + props.store.getTotalSimpleTax) *
props.tax.percent) /
100
)
}
if (props.store.getSubtotalWithDiscount && props.tax.percent && props.store[props.storeProp].tax_included) {
return Math.round(
props.store.getSubtotalWithDiscount - (
props.store.getSubtotalWithDiscount / (1 + (props.tax.percent / 100))
)
)
}
if (props.store.getSubtotalWithDiscount && props.tax.percent) {
return Math.round(
(props.store.getSubtotalWithDiscount * props.tax.percent) / 100
)
}
return 0
})
watchEffect(() => {
if (props.store.getSubtotalWithDiscount) {
updateTax()
}
if (props.store.getTotalSimpleTax) {
updateTax()
}
})
watch(
() => props.store[props.storeProp].tax_included,
(val) => {
updateTax()
}, { deep: true },
)
function updateTax() {
emit('update', {
...props.tax,
amount: taxAmount.value,
})
}
</script>