fix(taxes): correct compound tax document flows (#754)

This commit is contained in:
Darko Gjorgjijoski
2026-08-14 00:42:01 +02:00
committed by GitHub
parent 13aa087faf
commit 93dd7df48a
22 changed files with 701 additions and 57 deletions
+49 -3
View File
@@ -28,8 +28,8 @@ test('applies document discount and document-level tax', function () {
test('uses per-item taxes (not document taxes) when tax_per_item is YES', function () {
$totals = DocumentTotals::compute(
[
['price' => 1000, 'quantity' => 1, 'taxes' => [['amount' => 100]]],
['price' => 2000, 'quantity' => 1, 'taxes' => [['amount' => 200]]],
['price' => 1000, 'quantity' => 1, 'taxes' => [['tax_type_id' => 1, 'amount' => 100]]],
['price' => 2000, 'quantity' => 1, 'taxes' => [['tax_type_id' => 2, 'amount' => 200]]],
],
[['amount' => 9999]],
0, 'YES', false, 'YES'
@@ -77,7 +77,7 @@ test('supports negative quantities', function () {
expect($totals['sub_total'])->toBe(-150)->and($totals['total'])->toBe(-150);
});
test('sums a compound tax line just like any other document-level tax line', function () {
test('calculates exclusive document-level compound tax totals', function () {
$totals = DocumentTotals::compute(
[['price' => 10000, 'quantity' => 1]],
[['amount' => 1900], ['amount' => 119, 'compound_tax' => true]],
@@ -87,3 +87,49 @@ test('sums a compound tax line just like any other document-level tax line', fun
expect($totals['tax'])->toBe(2019)
->and($totals['total'])->toBe(12019);
});
test('keeps simple taxes inside an inclusive document total while adding compound taxes', function () {
$totals = DocumentTotals::compute(
[['price' => 11900, 'quantity' => 1]],
[['amount' => 1900], ['amount' => 119, 'compound_tax' => true]],
0, 'NO', true, 'NO'
);
expect($totals['tax'])->toBe(2019)
->and($totals['total'])->toBe(12019);
});
test('calculates exclusive per-item compound tax totals and ignores the UI placeholder', function () {
$totals = DocumentTotals::compute(
[[
'price' => 10000,
'quantity' => 1,
'taxes' => [
['tax_type_id' => 1, 'amount' => 1900],
['tax_type_id' => 2, 'amount' => 119, 'compound_tax' => true],
['tax_type_id' => 0, 'amount' => 0],
],
]],
[], 0, 'YES', false, 'NO'
);
expect($totals['tax'])->toBe(2019)
->and($totals['total'])->toBe(12019);
});
test('keeps simple per-item taxes inside an inclusive total while adding compound taxes', function () {
$totals = DocumentTotals::compute(
[[
'price' => 11900,
'quantity' => 1,
'taxes' => [
['tax_type_id' => 1, 'amount' => 1900],
['tax_type_id' => 2, 'amount' => 119, 'compound_tax' => true],
],
]],
[], 0, 'YES', true, 'NO'
);
expect($totals['tax'])->toBe(2019)
->and($totals['total'])->toBe(12019);
});