Add money permissions, a read-only price list and VAT rates

- Admins give employees and interns personal money permissions (prices,
  expenses, quotes, billing) on the user form. Other modules check them
  through the money.* abilities; admins and management see all amounts,
  subcontractors none.
- Employees and interns get a read-only price list: consumer products
  with VAT always, hourly rates, other products and the mileage rate only
  with the price permission. Subcontractors cannot open it.
- VAT rates are maintained on the price list page, with one default rate
  that always stays in use. Products get a VAT rate; changing a rate's
  percentage applies to every product using it.
- Consumer product prices are entered and stored with VAT, so cash prices
  stay round; the price without VAT is calculated. The product form shows
  the other price as you type.
- Shared VatPercentage value object and Money::addVat()/removeVat(),
  rounding half up to the cent in integer arithmetic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 07:51:19 +02:00
co-authored by Claude Opus 5.5
parent dc2612cf46
commit bdd8d446d8
68 changed files with 2222 additions and 64 deletions
+28
View File
@@ -1,7 +1,9 @@
<?php
use App\Modules\Shared\Domain\Exceptions\InvalidMoneyAmount;
use App\Modules\Shared\Domain\Exceptions\InvalidVatPercentage;
use App\Modules\Shared\Domain\ValueObjects\Money;
use App\Modules\Shared\Domain\ValueObjects\VatPercentage;
it('parses euro amounts typed in Finnish or English notation', function (string $typed, int $cents) {
expect(Money::parse($typed)?->cents)->toBe($cents);
@@ -28,3 +30,29 @@ it('formats with a no-break space and the currency', function () {
expect($money->format())->toBe("1\u{00A0}200,50\u{00A0}€")
->and($money->inputValue())->toBe('1200,50');
});
it('adds and removes VAT, rounding half up to the cent', function (int $net, string $vat, int $gross) {
$percentage = VatPercentage::parse($vat);
expect(Money::fromCents($net)->addVat($percentage)->cents)->toBe($gross);
})->with([
'general rate' => [1434, '25,5', 1800],
'rounds half up' => [2, '25', 3],
'reduced rate' => [1000, '13,5', 1135],
'zero rate' => [999, '0', 999],
]);
it('works out the price without VAT from a consumer price', function () {
expect(Money::fromCents(1800)->removeVat(VatPercentage::parse('25,5'))->cents)->toBe(1434)
->and(Money::fromCents(1000)->removeVat(VatPercentage::parse('0'))->cents)->toBe(1000);
});
it('parses and formats VAT percentages', function () {
expect(VatPercentage::parse('25,5 %')->basisPoints)->toBe(2550)
->and(VatPercentage::parse('13.5')->format())->toBe("13,5\u{00A0}%")
->and(VatPercentage::parse('0')->inputValue())->toBe('0');
});
it('rejects invalid VAT percentages', function (string $typed) {
VatPercentage::parse($typed);
})->throws(InvalidVatPercentage::class)->with(['', '-1', '100,01', '12,345', 'abc']);