Adding Flat Tax support with fixed amount (#253)

* Possibility to set a fixed amount on tax types settings

* Pint and manage flat taxes on items

* Fix display errors and handle global taxes

* Tests

* Pint with PHP 8.2 cause with PHP 8.3 version it cause workflow error

* Merging percent and fixed amount into one column

* Now display the currency on SelectTaxPopup on fixed taxes
This commit is contained in:
mchev
2025-05-04 02:24:56 +02:00
committed by GitHub
parent 546f75d3a6
commit bf5b544ca3
22 changed files with 306 additions and 39 deletions

View File

@@ -28,8 +28,17 @@ class TaxTypeRequest extends FormRequest
->where('type', TaxType::TYPE_GENERAL) ->where('type', TaxType::TYPE_GENERAL)
->where('company_id', $this->header('company')), ->where('company_id', $this->header('company')),
], ],
'percent' => [ 'calculation_type' => [
'required', 'required',
Rule::in(['percentage', 'fixed']),
],
'percent' => [
'nullable',
'numeric',
],
'fixed_amount' => [
'nullable',
'numeric',
], ],
'description' => [ 'description' => [
'nullable', 'nullable',

View File

@@ -25,6 +25,8 @@ class TaxResource extends JsonResource
'name' => $this->name, 'name' => $this->name,
'amount' => $this->amount, 'amount' => $this->amount,
'percent' => $this->percent, 'percent' => $this->percent,
'calculation_type' => $this->calculation_type,
'fixed_amount' => $this->fixed_amount,
'compound_tax' => $this->compound_tax, 'compound_tax' => $this->compound_tax,
'base_amount' => $this->base_amount, 'base_amount' => $this->base_amount,
'currency_id' => $this->currency_id, 'currency_id' => $this->currency_id,

View File

@@ -17,6 +17,8 @@ class TaxTypeResource extends JsonResource
'id' => $this->id, 'id' => $this->id,
'name' => $this->name, 'name' => $this->name,
'percent' => $this->percent, 'percent' => $this->percent,
'fixed_amount' => $this->fixed_amount,
'calculation_type' => $this->calculation_type,
'type' => $this->type, 'type' => $this->type,
'compound_tax' => $this->compound_tax, 'compound_tax' => $this->compound_tax,
'collective_tax' => $this->collective_tax, 'collective_tax' => $this->collective_tax,

View File

@@ -521,6 +521,7 @@ class Invoice extends Model implements HasMedia
public static function createTaxes($invoice, $taxes) public static function createTaxes($invoice, $taxes)
{ {
$exchange_rate = $invoice->exchange_rate; $exchange_rate = $invoice->exchange_rate;
foreach ($taxes as $tax) { foreach ($taxes as $tax) {

View File

@@ -21,6 +21,7 @@ class Tax extends Model
return [ return [
'amount' => 'integer', 'amount' => 'integer',
'percent' => 'float', 'percent' => 'float',
'fixed_amount' => 'integer',
]; ];
} }

View File

@@ -19,6 +19,7 @@ class TaxType extends Model
{ {
return [ return [
'percent' => 'float', 'percent' => 'float',
'fixed_amount' => 'integer',
'compound_tax' => 'boolean', 'compound_tax' => 'boolean',
]; ];
} }

View File

@@ -22,8 +22,10 @@ class TaxTypeFactory extends Factory
{ {
return [ return [
'name' => $this->faker->word(), 'name' => $this->faker->word(),
'calculation_type' => 'percentage',
'company_id' => User::find(1)->companies()->first()->id, 'company_id' => User::find(1)->companies()->first()->id,
'percent' => $this->faker->numberBetween($min = 0, $max = 100), 'percent' => $this->faker->numberBetween($min = 0, $max = 100),
'fixed_amount' => null,
'description' => $this->faker->text(), 'description' => $this->faker->text(),
'compound_tax' => 0, 'compound_tax' => 0,
'collective_tax' => 0, 'collective_tax' => 0,

View File

@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('tax_types', function (Blueprint $table) {
$table->enum('calculation_type', ['percentage', 'fixed'])->default('percentage')->after('name');
$table->integer('fixed_amount')->nullable()->after('percent');
$table->decimal('percent', 5, 2)->nullable()->change();
});
Schema::table('taxes', function (Blueprint $table) {
$table->enum('calculation_type', ['percentage', 'fixed'])->default('percentage')->after('name');
$table->integer('fixed_amount')->nullable()->after('percent');
$table->decimal('percent', 5, 2)->nullable()->change();
});
}
public function down()
{
Schema::table('tax_types', function (Blueprint $table) {
$table->dropColumn(['calculation_type', 'fixed_amount']);
$table->decimal('percent', 5, 2)->change();
});
Schema::table('taxes', function (Blueprint $table) {
$table->dropColumn(['calculation_type', 'fixed_amount']);
$table->decimal('percent', 5, 2)->change();
});
}
};

View File

@@ -161,7 +161,10 @@
"name": "Name", "name": "Name",
"description": "Description", "description": "Description",
"percent": "Percent", "percent": "Percent",
"compound_tax": "Compound Tax" "compound_tax": "Compound Tax",
"percentage": "Percentage",
"fixed_amount": "Fixed Amount",
"tax_type": "Tax Type"
}, },
"global_search": { "global_search": {
"search": "Search...", "search": "Search...",
@@ -1205,7 +1208,12 @@
"tax_per_item": "Tax Per Item", "tax_per_item": "Tax Per Item",
"tax_name": "Tax Name", "tax_name": "Tax Name",
"compound_tax": "Compound Tax", "compound_tax": "Compound Tax",
"amount": "Amount",
"percent": "Percent", "percent": "Percent",
"fixed_amount": "Fixed Amount",
"calculation_type": "Calculation Type",
"percentage": "Percentage",
"fixed": "Fixed",
"action": "Action", "action": "Action",
"tax_setting_description": "Enable this if you want to add taxes to individual invoice items. By default, taxes are added directly to the invoice.", "tax_setting_description": "Enable this if you want to add taxes to individual invoice items. By default, taxes are added directly to the invoice.",
"created_message": "Tax type created successfully", "created_message": "Tax type created successfully",

View File

@@ -19,12 +19,24 @@
> >
<template #singlelabel="{ value }"> <template #singlelabel="{ value }">
<div class="absolute left-3.5"> <div class="absolute left-3.5">
{{ value.name }} - {{ value.percent }} % {{ value.name }} -
<template v-if="value.calculation_type === 'fixed'">
<BaseFormatMoney :amount="value.fixed_amount" :currency="currency" />
</template>
<template v-else>
{{ value.percent }} %
</template>
</div> </div>
</template> </template>
<template #option="{ option }"> <template #option="{ option }">
{{ option.name }} - {{ option.percent }} % {{ option.name }} -
<template v-if="option.calculation_type === 'fixed'">
<BaseFormatMoney :amount="option.fixed_amount" :currency="currency" />
</template>
<template v-else>
{{ option.percent }} %
</template>
</template> </template>
<template v-if="userStore.hasAbilities(ability)" #action> <template v-if="userStore.hasAbilities(ability)" #action>
@@ -146,7 +158,12 @@ const filteredTypes = computed(() => {
}) })
const taxAmount = computed(() => { const taxAmount = computed(() => {
if (props.discountedTotal && localTax.percent) {
if(localTax.calculation_type === 'fixed') {
return localTax.fixed_amount
}
if (props.discountedTotal) {
const taxPerItemEnabled = props.store[props.storeProp].tax_per_item === 'YES' const taxPerItemEnabled = props.store[props.storeProp].tax_per_item === 'YES'
const discountPerItemEnabled = props.store[props.storeProp].discount_per_item === 'YES' const discountPerItemEnabled = props.store[props.storeProp].discount_per_item === 'YES'
if (taxPerItemEnabled && !discountPerItemEnabled){ if (taxPerItemEnabled && !discountPerItemEnabled){
@@ -188,7 +205,9 @@ if (props.taxData.tax_type_id > 0) {
updateRowTax() updateRowTax()
function onSelectTax(val) { function onSelectTax(val) {
localTax.percent = val.percent localTax.calculation_type = val.calculation_type
localTax.percent = val.calculation_type === 'percentage' ? val.percent : null
localTax.fixed_amount = val.calculation_type === 'fixed' ? val.fixed_amount : null
localTax.tax_type_id = val.id localTax.tax_type_id = val.id
localTax.name = val.name localTax.name = val.name
@@ -232,6 +251,11 @@ function removeTax(index) {
} }
function getTaxAmount() { function getTaxAmount() {
if (localTax.calculation_type === 'fixed') {
return localTax.fixed_amount
}
let total = 0 let total = 0
let discount = 0 let discount = 0
const itemTotal = props.discountedTotal const itemTotal = props.discountedTotal
@@ -250,3 +274,4 @@ function getTaxAmount() {
return Math.round((props.discountedTotal * localTax.percent) / 100) return Math.round((props.discountedTotal * localTax.percent) / 100)
} }
</script> </script>

View File

@@ -50,7 +50,12 @@
v-else-if="store[storeProp].tax_per_item === 'YES'" v-else-if="store[storeProp].tax_per_item === 'YES'"
class="m-0 text-sm font-semibold leading-5 text-gray-500 uppercase" class="m-0 text-sm font-semibold leading-5 text-gray-500 uppercase"
> >
{{ tax.name }} - {{ tax.percent }}% <template v-if="tax.calculation_type === 'percentage'">
{{ tax.name }} - {{ tax.percent }}%
</template>
<template v-else>
{{ tax.name }} - <BaseFormatMoney :amount="tax.fixed_amount" :currency="defaultCurrency" />
</template>
</label> </label>
<BaseContentPlaceholders v-if="isLoading"> <BaseContentPlaceholders v-if="isLoading">
@@ -269,6 +274,8 @@ const itemWiseTaxes = computed(() => {
amount: Math.round(tax.amount), amount: Math.round(tax.amount),
percent: tax.percent, percent: tax.percent,
name: tax.name, name: tax.name,
calculation_type: tax.calculation_type,
fixed_amount: tax.fixed_amount
}) })
} }
}) })
@@ -323,10 +330,12 @@ function selectPercentage() {
function onSelectTax(selectedTax) { function onSelectTax(selectedTax) {
let amount = 0 let amount = 0
if (props.store.getSubtotalWithDiscount && selectedTax.percent) { if (selectedTax.calculation_type === 'percentage' && props.store.getSubtotalWithDiscount && selectedTax.percent) {
amount = Math.round( amount = Math.round(
(props.store.getSubtotalWithDiscount * selectedTax.percent) / 100 (props.store.getSubtotalWithDiscount * selectedTax.percent) / 100
) )
} else if (selectedTax.calculation_type === 'fixed') {
amount = selectedTax.fixed_amount
} }
let data = { let data = {
@@ -336,6 +345,8 @@ function onSelectTax(selectedTax) {
percent: selectedTax.percent, percent: selectedTax.percent,
tax_type_id: selectedTax.id, tax_type_id: selectedTax.id,
amount, amount,
calculation_type: selectedTax.calculation_type,
fixed_amount: selectedTax.fixed_amount
} }
props.store.$patch((state) => { props.store.$patch((state) => {
state[props.storeProp].taxes.push({ ...data }) state[props.storeProp].taxes.push({ ...data })

View File

@@ -1,8 +1,11 @@
<template> <template>
<div class="flex items-center justify-between w-full mt-2 text-sm"> <div class="flex items-center justify-between w-full mt-2 text-sm">
<label class="font-semibold leading-5 text-gray-500 uppercase"> <label v-if="tax.calculation_type === 'percentage'" class="font-semibold leading-5 text-gray-500 uppercase">
{{ tax.name }} ({{ tax.percent }} %) {{ tax.name }} ({{ tax.percent }} %)
</label> </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"> <label class="flex items-center justify-center text-lg text-black">
<BaseFormatMoney :amount="tax.amount" :currency="currency" /> <BaseFormatMoney :amount="tax.amount" :currency="currency" />
@@ -50,6 +53,10 @@ const emit = defineEmits(['update', 'remove'])
const utils = inject('$utils') const utils = inject('$utils')
const taxAmount = computed(() => { const taxAmount = computed(() => {
if (props.tax.calculation_type === 'fixed') {
return props.tax.fixed_amount;
}
if (props.tax.compound_tax && props.store.getSubtotalWithDiscount) { if (props.tax.compound_tax && props.store.getSubtotalWithDiscount) {
return Math.round( return Math.round(
((props.store.getSubtotalWithDiscount + props.store.getTotalSimpleTax) * ((props.store.getSubtotalWithDiscount + props.store.getTotalSimpleTax) *

View File

@@ -110,7 +110,12 @@
cursor-pointer cursor-pointer
" "
> >
{{ taxType.percent }} % <template v-if="taxType.calculation_type === 'fixed'">
<BaseFormatMoney :amount="taxType.fixed_amount" :currency="companyStore.selectedCompanyCurrency" />
</template>
<template v-else>
{{ taxType.percent }} %
</template>
</label> </label>
</div> </div>
</div> </div>
@@ -173,7 +178,9 @@ import { useInvoiceStore } from '@/scripts/admin/stores/invoice'
import { useModalStore } from '@/scripts/stores/modal' import { useModalStore } from '@/scripts/stores/modal'
import { useTaxTypeStore } from '@/scripts/admin/stores/tax-type' import { useTaxTypeStore } from '@/scripts/admin/stores/tax-type'
import { useUserStore } from '@/scripts/admin/stores/user' import { useUserStore } from '@/scripts/admin/stores/user'
import { useCompanyStore } from '@/scripts/admin/stores/company'
import abilities from '@/scripts/admin/stub/abilities' import abilities from '@/scripts/admin/stub/abilities'
import BaseFormatMoney from '@/scripts/components/base/BaseFormatMoney.vue'
const props = defineProps({ const props = defineProps({
type: { type: {
@@ -195,10 +202,15 @@ const emit = defineEmits(['select:taxType'])
const modalStore = useModalStore() const modalStore = useModalStore()
const taxTypeStore = useTaxTypeStore() const taxTypeStore = useTaxTypeStore()
const userStore = useUserStore() const userStore = useUserStore()
const companyStore = useCompanyStore()
const { t } = useI18n() const { t } = useI18n()
const textSearch = ref(null) const textSearch = ref(null)
const formatMoney = (amount) => {
return companyStore.formatMoney(amount)
}
const filteredTaxType = computed(() => { const filteredTaxType = computed(() => {
if (textSearch.value) { if (textSearch.value) {
return taxTypeStore.taxTypes.filter(function (el) { return taxTypeStore.taxTypes.filter(function (el) {

View File

@@ -169,7 +169,7 @@ const taxes = computed({
return { return {
...tax, ...tax,
tax_type_id: tax.id, tax_type_id: tax.id,
tax_name: tax.name + ' (' + tax.percent + '%)', tax_name: tax.name + ' (' + (tax.calculation_type === 'fixed' ? tax.fixed_amount : tax.percent) + (tax.calculation_type === 'fixed' ? companyStore.selectedCompanyCurrency.symbol : '%') + ')',
} }
} }
}), }),
@@ -208,7 +208,17 @@ const v$ = useVuelidate(
const getTaxTypes = computed(() => { const getTaxTypes = computed(() => {
return taxTypeStore.taxTypes.map((tax) => { return taxTypeStore.taxTypes.map((tax) => {
return { ...tax, tax_name: tax.name + ' (' + tax.percent + '%)' } const amount = tax.calculation_type === 'fixed'
? new Intl.NumberFormat(undefined, {
style: 'currency',
currency: companyStore.selectedCompanyCurrency.code
}).format(tax.fixed_amount / 100)
: `${tax.percent}%`
return {
...tax,
tax_name: `${tax.name} (${amount})`
}
}) })
}) })
@@ -229,8 +239,10 @@ async function submitItemData() {
taxes: itemStore.currentItem.taxes.map((tax) => { taxes: itemStore.currentItem.taxes.map((tax) => {
return { return {
tax_type_id: tax.id, tax_type_id: tax.id,
amount: (price.value * tax.percent) / 100, amount: tax.calculation_type === 'fixed' ? tax.fixed_amount : (price.value * tax.percent) / 100,
percent: tax.percent, percent: tax.percent,
fixed_amount: tax.fixed_amount,
calculation_type: tax.calculation_type,
name: tax.name, name: tax.name,
collective_tax: 0, collective_tax: 0,
} }

View File

@@ -34,12 +34,28 @@
</BaseInputGroup> </BaseInputGroup>
<BaseInputGroup <BaseInputGroup
:label="$t('tax_types.tax_type')"
variant="horizontal"
required
>
<BaseSelectInput
v-model="taxTypeStore.currentTaxType.calculation_type"
:options="[
{ id: 'percentage', label: $t('tax_types.percentage') },
{ id: 'fixed', label: $t('tax_types.fixed_amount') }
]"
:allow-empty="false"
value-prop="id"
label-prop="label"
track-by="label"
:searchable="false"
/>
</BaseInputGroup>
<BaseInputGroup
v-if="taxTypeStore.currentTaxType.calculation_type === 'percentage'"
:label="$t('tax_types.percent')" :label="$t('tax_types.percent')"
variant="horizontal" variant="horizontal"
:error="
v$.currentTaxType.percent.$error &&
v$.currentTaxType.percent.$errors[0].$message
"
required required
> >
<BaseMoney <BaseMoney
@@ -51,13 +67,18 @@
precision: 2, precision: 2,
masked: false, masked: false,
}" }"
:invalid="v$.currentTaxType.percent.$error" />
class=" </BaseInputGroup>
relative
w-full <BaseInputGroup
focus:border focus:border-solid focus:border-primary v-else
" :label="$t('tax_types.fixed_amount')"
@input="v$.currentTaxType.percent.$touch()" variant="horizontal"
required
>
<BaseMoney
v-model="fixedAmount"
:currency="defaultCurrency"
/> />
</BaseInputGroup> </BaseInputGroup>
@@ -127,6 +148,8 @@ import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import Guid from 'guid' import Guid from 'guid'
import TaxStub from '@/scripts/admin/stub/abilities' import TaxStub from '@/scripts/admin/stub/abilities'
import { useCompanyStore } from '@/scripts/admin/stores/company'
import { import {
required, required,
minLength, minLength,
@@ -140,6 +163,8 @@ const taxTypeStore = useTaxTypeStore()
const modalStore = useModalStore() const modalStore = useModalStore()
const notificationStore = useNotificationStore() const notificationStore = useNotificationStore()
const estimateStore = useEstimateStore() const estimateStore = useEstimateStore()
const companyStore = useCompanyStore()
const defaultCurrency = computed(() => companyStore.selectedCompanyCurrency)
const { t, tm } = useI18n() const { t, tm } = useI18n()
let isSaving = ref(false) let isSaving = ref(false)
@@ -154,6 +179,9 @@ const rules = computed(() => {
minLength(3) minLength(3)
), ),
}, },
calculation_type: {
required: helpers.withMessage(t('validation.required'), required),
},
percent: { percent: {
required: helpers.withMessage(t('validation.required'), required), required: helpers.withMessage(t('validation.required'), required),
between: helpers.withMessage( between: helpers.withMessage(
@@ -161,6 +189,9 @@ const rules = computed(() => {
between(-100, 100) between(-100, 100)
), ),
}, },
fixed_amount: {
required: helpers.withMessage(t('validation.required'), required),
},
description: { description: {
maxLength: helpers.withMessage( maxLength: helpers.withMessage(
t('validation.description_maxlength', { count: 255 }), t('validation.description_maxlength', { count: 255 }),
@@ -198,16 +229,22 @@ async function submitTaxTypeData() {
function SelectTax(taxData) { function SelectTax(taxData) {
let amount = 0 let amount = 0
if (estimateStore.getSubtotalWithDiscount && taxData.percent) { if (estimateStore.getSubtotalWithDiscount) {
amount = Math.round( if (taxData.calculation_type === 'percentage') {
(estimateStore.getSubtotalWithDiscount * taxData.percent) / 100 amount = Math.round(
) (estimateStore.getSubtotalWithDiscount * taxData.percent) / 100
)
} else {
amount = taxData.fixed_amount
}
} }
let data = { let data = {
...TaxStub, ...TaxStub,
id: Guid.raw(), id: Guid.raw(),
name: taxData.name, name: taxData.name,
calculation_type: taxData.calculation_type,
percent: taxData.percent, percent: taxData.percent,
fixed_amount: taxData.fixed_amount,
tax_type_id: taxData.id, tax_type_id: taxData.id,
amount, amount,
} }
@@ -222,7 +259,9 @@ function selectItemTax(taxData) {
...TaxStub, ...TaxStub,
id: Guid.raw(), id: Guid.raw(),
name: taxData.name, name: taxData.name,
calculation_type: taxData.calculation_type,
percent: taxData.percent, percent: taxData.percent,
fixed_amount: taxData.fixed_amount,
tax_type_id: taxData.id, tax_type_id: taxData.id,
} }
modalStore.refreshData(data) modalStore.refreshData(data)
@@ -236,4 +275,11 @@ function closeTaxTypeModal() {
v$.value.$reset() v$.value.$reset()
}, 300) }, 300)
} }
const fixedAmount = computed({
get: () => taxTypeStore.currentTaxType.fixed_amount / 100,
set: (value) => {
taxTypeStore.currentTaxType.fixed_amount = Math.round(value * 100)
},
})
</script> </script>

View File

@@ -15,7 +15,9 @@ export const useTaxTypeStore = (useWindow = false) => {
currentTaxType: { currentTaxType: {
id: null, id: null,
name: '', name: '',
calculation_type: 'percentage',
percent: 0, percent: 0,
fixed_amount: 0,
description: '', description: '',
compound_tax: false, compound_tax: false,
collective_tax: 0, collective_tax: 0,
@@ -31,7 +33,9 @@ export const useTaxTypeStore = (useWindow = false) => {
this.currentTaxType = { this.currentTaxType = {
id: null, id: null,
name: '', name: '',
calculation_type: 'percentage',
percent: 0, percent: 0,
fixed_amount: 0,
description: '', description: '',
compound_tax: false, compound_tax: false,
collective_tax: 0, collective_tax: 0,

View File

@@ -184,7 +184,12 @@ const taxes = computed({
return { return {
...tax, ...tax,
tax_type_id: tax.id, tax_type_id: tax.id,
tax_name: tax.name + ' (' + tax.percent + '%)', tax_name: `${tax.name} (${tax.calculation_type === 'fixed'
? new Intl.NumberFormat(undefined, {
style: 'currency',
currency: companyStore.selectedCompanyCurrency.code
}).format(tax.fixed_amount / 100)
: `${tax.percent}%`})`,
} }
} }
}), }),
@@ -204,7 +209,12 @@ const getTaxTypes = computed(() => {
return { return {
...tax, ...tax,
tax_type_id: tax.id, tax_type_id: tax.id,
tax_name: tax.name + ' (' + tax.percent + '%)', tax_name: `${tax.name} (${tax.calculation_type === 'fixed'
? new Intl.NumberFormat(undefined, {
style: 'currency',
currency: companyStore.selectedCompanyCurrency.code
}).format(tax.fixed_amount / 100)
: `${tax.percent}%`})`,
} }
}) })
}) })
@@ -280,7 +290,9 @@ async function submitItem() {
data.taxes = itemStore.currentItem.taxes.map((tax) => { data.taxes = itemStore.currentItem.taxes.map((tax) => {
return { return {
tax_type_id: tax.tax_type_id, tax_type_id: tax.tax_type_id,
amount: price.value * tax.percent, calculation_type: tax.calculation_type,
fixed_amount: tax.fixed_amount,
amount: tax.calculation_type === 'fixed' ? tax.fixed_amount : price.value * tax.percent,
percent: tax.percent, percent: tax.percent,
name: tax.name, name: tax.name,
collective_tax: 0, collective_tax: 0,

View File

@@ -20,7 +20,20 @@
:data="fetchData" :data="fetchData"
:columns="taxTypeColumns" :columns="taxTypeColumns"
> >
<template #cell-percent="{ row }"> {{ row.data.percent }} % </template> <template #cell-calculation_type="{ row }">
{{ $t(`settings.tax_types.${row.data.calculation_type}`) }}
</template>
<template #cell-amount="{ row }">
<template v-if="row.data.calculation_type === 'percentage'">
{{ row.data.percent }} %
</template>
<template v-else-if="row.data.calculation_type === 'fixed'">
<BaseFormatMoney :amount="row.data.fixed_amount" :currency="defaultCurrency" />
</template>
<template v-else>
-
</template>
</template>
<template v-if="hasAtleastOneAbility()" #cell-actions="{ row }"> <template v-if="hasAtleastOneAbility()" #cell-actions="{ row }">
<TaxTypeDropdown <TaxTypeDropdown
@@ -64,9 +77,9 @@ const taxTypeStore = useTaxTypeStore()
const modalStore = useModalStore() const modalStore = useModalStore()
const userStore = useUserStore() const userStore = useUserStore()
const moduleStore = useModuleStore() const moduleStore = useModuleStore()
const table = ref(null) const table = ref(null)
const taxPerItemSetting = ref(companyStore.selectedCompanySettings.tax_per_item) const taxPerItemSetting = ref(companyStore.selectedCompanySettings.tax_per_item)
const defaultCurrency = computed(() => companyStore.selectedCompanyCurrency)
const taxTypeColumns = computed(() => { const taxTypeColumns = computed(() => {
return [ return [
@@ -77,8 +90,14 @@ const taxTypeColumns = computed(() => {
tdClass: 'font-medium text-gray-900', tdClass: 'font-medium text-gray-900',
}, },
{ {
key: 'percent', key: 'calculation_type',
label: t('settings.tax_types.percent'), label: t('settings.tax_types.calculation_type'),
thClass: 'extra',
tdClass: 'font-medium text-gray-900',
},
{
key: 'amount',
label: t('settings.tax_types.amount'),
thClass: 'extra', thClass: 'extra',
tdClass: 'font-medium text-gray-900', tdClass: 'font-medium text-gray-900',
}, },

View File

@@ -106,7 +106,11 @@
@foreach ($taxes as $tax) @foreach ($taxes as $tax)
<tr> <tr>
<td class="border-0 total-table-attribute-label"> <td class="border-0 total-table-attribute-label">
{{$tax->name.' ('.$tax->percent.'%)'}} @if($tax->calculation_type === 'fixed')
{{$tax->name }} ({!! format_money_pdf($tax->fixed_amount, $estimate->customer->currency) !!})
@else
{{$tax->name.' ('.$tax->percent.'%)'}}
@endif
</td> </td>
<td class="py-2 border-0 item-cell total-table-attribute-value"> <td class="py-2 border-0 item-cell total-table-attribute-value">
{!! format_money_pdf($tax->amount, $estimate->customer->currency) !!} {!! format_money_pdf($tax->amount, $estimate->customer->currency) !!}
@@ -117,7 +121,11 @@
@foreach ($estimate->taxes as $tax) @foreach ($estimate->taxes as $tax)
<tr> <tr>
<td class="border-0 total-table-attribute-label"> <td class="border-0 total-table-attribute-label">
{{$tax->name.' ('.$tax->percent.'%)'}} @if($tax->calculation_type === 'fixed')
{{$tax->name }} ({!! format_money_pdf($tax->fixed_amount, $estimate->customer->currency) !!})
@else
{{$tax->name.' ('.$tax->percent.'%)'}}
@endif
</td> </td>
<td class="border-0 item-cell total-table-attribute-value" > <td class="border-0 item-cell total-table-attribute-value" >
{!! format_money_pdf($tax->amount, $estimate->customer->currency) !!} {!! format_money_pdf($tax->amount, $estimate->customer->currency) !!}

View File

@@ -125,7 +125,11 @@
@foreach ($taxes as $tax) @foreach ($taxes as $tax)
<tr> <tr>
<td class="border-0 total-table-attribute-label"> <td class="border-0 total-table-attribute-label">
{{$tax->name.' ('.$tax->percent.'%)'}} @if($tax->calculation_type === 'fixed')
{{$tax->name }} ({!! format_money_pdf($tax->fixed_amount, $invoice->customer->currency) !!})
@else
{{$tax->name.' ('.$tax->percent.'%)'}}
@endif
</td> </td>
<td class="py-2 border-0 item-cell total-table-attribute-value"> <td class="py-2 border-0 item-cell total-table-attribute-value">
{!! format_money_pdf($tax->amount, $invoice->customer->currency) !!} {!! format_money_pdf($tax->amount, $invoice->customer->currency) !!}
@@ -136,7 +140,11 @@
@foreach ($invoice->taxes as $tax) @foreach ($invoice->taxes as $tax)
<tr> <tr>
<td class="border-0 total-table-attribute-label"> <td class="border-0 total-table-attribute-label">
{{$tax->name.' ('.$tax->percent.'%)'}} @if($tax->calculation_type === 'fixed')
{{$tax->name }} ({!! format_money_pdf($tax->fixed_amount, $invoice->customer->currency) !!})
@else
{{$tax->name.' ('.$tax->percent.'%)'}}
@endif
</td> </td>
<td class="py-2 border-0 item-cell total-table-attribute-value"> <td class="py-2 border-0 item-cell total-table-attribute-value">
{!! format_money_pdf($tax->amount, $invoice->customer->currency) !!} {!! format_money_pdf($tax->amount, $invoice->customer->currency) !!}

View File

@@ -141,3 +141,31 @@ test('search items', function () {
$response->assertOk(); $response->assertOk();
}); });
test('create item with fixed amount tax', function () {
$item = Item::factory()->raw([
'taxes' => [
Tax::factory()->raw([
'calculation_type' => 'fixed',
'fixed_amount' => 5000,
]),
],
]);
$response = postJson('api/v1/items', $item);
$response->assertOk();
$this->assertDatabaseHas('items', [
'name' => $item['name'],
'description' => $item['description'],
'price' => $item['price'],
'company_id' => $item['company_id'],
]);
$this->assertDatabaseHas('taxes', [
'item_id' => $response->getData()->data->id,
'calculation_type' => 'fixed',
'fixed_amount' => 5000,
]);
});

View File

@@ -97,3 +97,16 @@ test('create negative tax type', function () {
$this->assertDatabaseHas('tax_types', $taxType); $this->assertDatabaseHas('tax_types', $taxType);
}); });
test('create fixed amount tax type', function () {
$taxType = TaxType::factory()->raw([
'calculation_type' => 'fixed',
'percent' => null,
'fixed_amount' => 5000,
]);
postJson('api/v1/tax-types', $taxType)
->assertStatus(201);
$this->assertDatabaseHas('tax_types', $taxType);
});