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
@@ -11,9 +11,11 @@ use App\Modules\Catalog\Domain\ValueObjects\ProductDuration;
use App\Modules\Shared\Domain\ValueObjects\Money;
/**
* A fixed-price product (passikuvat, tulosteet). Consumer products' prices
* are visible to every user. Selling a product with a duration books those
* hours for the seller on the product's work type.
* A fixed-price product (passikuvat, tulosteet) with a VAT rate. Consumer
* products' prices are visible to every user and are entered and stored
* with VAT, so cash prices stay round; other prices are without VAT.
* Selling a product with a duration books those hours for the seller on
* the product's work type.
*/
final class Product extends CatalogItem
{
@@ -22,6 +24,7 @@ final class Product extends CatalogItem
CatalogName $name,
private ProductUnit $unit,
private Money $price,
private int $vatRateId,
private bool $consumerProduct,
private ProductDuration $duration,
private ?int $workTypeId,
@@ -34,28 +37,29 @@ final class Product extends CatalogItem
/**
* @throws ProductNeedsWorkType
*/
public static function create(CatalogName $name, ProductUnit $unit, Money $price, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId, int $sortOrder): self
public static function create(CatalogName $name, ProductUnit $unit, Money $price, int $vatRateId, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId, int $sortOrder): self
{
self::ensureWorkTypeForDuration($duration, $workTypeId);
return new self(null, $name, $unit, $price, $consumerProduct, $duration, $workTypeId, true, $sortOrder);
return new self(null, $name, $unit, $price, $vatRateId, $consumerProduct, $duration, $workTypeId, true, $sortOrder);
}
public static function reconstitute(int $id, CatalogName $name, ProductUnit $unit, Money $price, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId, bool $active, int $sortOrder): self
public static function reconstitute(int $id, CatalogName $name, ProductUnit $unit, Money $price, int $vatRateId, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId, bool $active, int $sortOrder): self
{
return new self($id, $name, $unit, $price, $consumerProduct, $duration, $workTypeId, $active, $sortOrder);
return new self($id, $name, $unit, $price, $vatRateId, $consumerProduct, $duration, $workTypeId, $active, $sortOrder);
}
/**
* @throws ProductNeedsWorkType
*/
public function update(CatalogName $name, ProductUnit $unit, Money $price, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId): void
public function update(CatalogName $name, ProductUnit $unit, Money $price, int $vatRateId, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId): void
{
self::ensureWorkTypeForDuration($duration, $workTypeId);
$this->name = $name;
$this->unit = $unit;
$this->price = $price;
$this->vatRateId = $vatRateId;
$this->consumerProduct = $consumerProduct;
$this->duration = $duration;
$this->workTypeId = $workTypeId;
@@ -71,11 +75,24 @@ final class Product extends CatalogItem
return $this->price;
}
public function vatRateId(): int
{
return $this->vatRateId;
}
public function isConsumerProduct(): bool
{
return $this->consumerProduct;
}
/**
* Whether price() includes VAT, which is so for consumer products.
*/
public function priceIncludesVat(): bool
{
return $this->consumerProduct;
}
public function duration(): ProductDuration
{
return $this->duration;
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace App\Modules\Catalog\Domain\Entities;
use App\Modules\Catalog\Domain\Exceptions\DefaultVatRateMustBeActive;
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
use App\Modules\Shared\Domain\ValueObjects\VatPercentage;
/**
* A VAT rate products are sold with, e.g. "Yleinen 25,5 %". When the law
* changes, the percentage is changed and every product using the rate
* follows. The default rate applies to hours, expenses and mileage, so it
* is always in use.
*/
final class VatRate extends CatalogItem
{
private function __construct(
?int $id,
CatalogName $name,
private VatPercentage $percentage,
private bool $default,
bool $active,
int $sortOrder,
) {
parent::__construct($id, $name, $active, $sortOrder);
}
public static function create(CatalogName $name, VatPercentage $percentage, int $sortOrder): self
{
return new self(null, $name, $percentage, false, true, $sortOrder);
}
public static function reconstitute(int $id, CatalogName $name, VatPercentage $percentage, bool $default, bool $active, int $sortOrder): self
{
return new self($id, $name, $percentage, $default, $active, $sortOrder);
}
public function changePercentage(VatPercentage $percentage): void
{
$this->percentage = $percentage;
}
/**
* Makes this the default rate; also puts it back in use.
*/
public function makeDefault(): void
{
$this->default = true;
$this->active = true;
}
public function clearDefault(): void
{
$this->default = false;
}
/**
* @throws DefaultVatRateMustBeActive
*/
public function deactivate(): void
{
if ($this->default) {
throw new DefaultVatRateMustBeActive;
}
parent::deactivate();
}
public function percentage(): VatPercentage
{
return $this->percentage;
}
public function isDefault(): bool
{
return $this->default;
}
}