Merge pull request #616 from mchev/taxdecimal

Support 3-decimal tax percentages (e.g. 6.625%)
This commit is contained in:
mchev
2026-04-08 09:28:44 +02:00
committed by GitHub
4 changed files with 92 additions and 9 deletions

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('tax_types', function (Blueprint $table) {
$table->decimal('percent', 5, 3)->nullable()->change();
});
Schema::table('taxes', function (Blueprint $table) {
$table->decimal('percent', 5, 3)->nullable()->change();
});
}
public function down(): void
{
Schema::table('tax_types', function (Blueprint $table) {
$table->decimal('percent', 5, 2)->nullable()->change();
});
Schema::table('taxes', function (Blueprint $table) {
$table->decimal('percent', 5, 2)->nullable()->change();
});
}
};

View File

@@ -58,15 +58,16 @@
variant="horizontal" variant="horizontal"
required required
> >
<BaseMoney <BaseInput
v-model="taxTypeStore.currentTaxType.percent" :model-value="taxTypeStore.currentTaxType.percent"
:currency="{ type="number"
decimal: '.', step="0.001"
thousands: ',', min="-100"
symbol: '% ', max="100"
precision: 2, inline-addon="%"
masked: false, :invalid="v$.currentTaxType.percent.$error"
}" @update:model-value="onTaxPercentInput"
@blur="onTaxPercentBlur"
/> />
</BaseInputGroup> </BaseInputGroup>
@@ -207,7 +208,38 @@ const v$ = useVuelidate(
computed(() => taxTypeStore) computed(() => taxTypeStore)
) )
function onTaxPercentInput(val) {
v$.value.currentTaxType.percent.$touch()
if (val === '' || val === null) {
taxTypeStore.currentTaxType.percent = null
return
}
const n = typeof val === 'number' ? val : parseFloat(val)
taxTypeStore.currentTaxType.percent = Number.isNaN(n) ? null : n
}
function onTaxPercentBlur() {
const p = taxTypeStore.currentTaxType.percent
if (p === null || p === undefined || p === '') {
return
}
const n = typeof p === 'number' ? p : parseFloat(p)
if (Number.isNaN(n)) {
return
}
taxTypeStore.currentTaxType.percent = Math.round(n * 1000) / 1000
}
async function submitTaxTypeData() { async function submitTaxTypeData() {
if (taxTypeStore.currentTaxType.calculation_type === 'percentage') {
onTaxPercentBlur()
}
v$.value.currentTaxType.$touch() v$.value.currentTaxType.$touch()
if (v$.value.currentTaxType.$invalid) { if (v$.value.currentTaxType.$invalid) {
return true return true

View File

@@ -248,4 +248,5 @@ function openTaxModal() {
refreshData: table.value && table.value.refresh, refreshData: table.value && table.value.refresh,
}) })
} }
</script> </script>

View File

@@ -5,6 +5,7 @@ use App\Http\Requests\TaxTypeRequest;
use App\Models\TaxType; use App\Models\TaxType;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum; use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\deleteJson; use function Pest\Laravel\deleteJson;
@@ -110,3 +111,22 @@ test('create fixed amount tax type', function () {
$this->assertDatabaseHas('tax_types', $taxType); $this->assertDatabaseHas('tax_types', $taxType);
}); });
test('create percentage tax type with three decimals', function () {
$payload = TaxType::factory()->raw([
'calculation_type' => 'percentage',
'percent' => 6.625,
'fixed_amount' => null,
]);
$response = postJson('api/v1/tax-types', $payload)
->assertStatus(201);
$taxTypeId = $response->json('data.id');
expect($taxTypeId)->not()->toBeNull();
$rawPercent = DB::table('tax_types')->where('id', $taxTypeId)->value('percent');
expect((string) $rawPercent)->toBe('6.625');
});