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:
@@ -10,6 +10,7 @@ use App\Modules\Catalog\Domain\Exceptions\InvalidCatalogName;
|
||||
use App\Modules\Catalog\Domain\Exceptions\InvalidProductDuration;
|
||||
use App\Modules\Catalog\Domain\Exceptions\ProductNameTaken;
|
||||
use App\Modules\Catalog\Domain\Exceptions\ProductNeedsWorkType;
|
||||
use App\Modules\Catalog\Domain\Exceptions\VatRateNotFound;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\ProductDuration;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
use App\Modules\Shared\Domain\Exceptions\InvalidMoneyAmount;
|
||||
@@ -19,7 +20,7 @@ use Livewire\Form;
|
||||
|
||||
/**
|
||||
* Fields of a product. Price and duration are kept as typed ("12,50") and
|
||||
* parsed by the use case.
|
||||
* parsed by the use case. The price includes VAT for a consumer product.
|
||||
*/
|
||||
class ProductForm extends Form
|
||||
{
|
||||
@@ -29,6 +30,8 @@ class ProductForm extends Form
|
||||
|
||||
public string $price = '';
|
||||
|
||||
public string $vat_rate_id = '';
|
||||
|
||||
public bool $is_consumer_product = false;
|
||||
|
||||
public string $duration = '';
|
||||
@@ -43,6 +46,7 @@ class ProductForm extends Form
|
||||
$this->name = $product->name;
|
||||
$this->unit = $product->unit->value;
|
||||
$this->price = Money::fromCents($product->priceCents)->inputValue();
|
||||
$this->vat_rate_id = (string) $product->vatRateId;
|
||||
$this->is_consumer_product = $product->isConsumerProduct;
|
||||
$this->duration = $product->durationQuarters === 0 ? '' : (new ProductDuration($product->durationQuarters))->format();
|
||||
$this->work_type_id = $product->workTypeId === null ? '' : (string) $product->workTypeId;
|
||||
@@ -56,6 +60,7 @@ class ProductForm extends Form
|
||||
$this->name,
|
||||
ProductUnit::from($this->unit),
|
||||
$this->price,
|
||||
(int) $this->vat_rate_id,
|
||||
$this->is_consumer_product,
|
||||
$this->duration,
|
||||
$this->work_type_id === '' ? null : (int) $this->work_type_id,
|
||||
@@ -74,6 +79,7 @@ class ProductForm extends Form
|
||||
InvalidProductDuration::class => ['duration', 'catalog.errors.invalid_duration'],
|
||||
ProductNeedsWorkType::class => ['work_type_id', 'catalog.errors.work_type_required'],
|
||||
CatalogItemNotFound::class => ['work_type_id', 'catalog.errors.work_type_unavailable'],
|
||||
VatRateNotFound::class => ['vat_rate_id', 'catalog.errors.vat_rate_unavailable'],
|
||||
default => throw $exception,
|
||||
};
|
||||
|
||||
@@ -89,6 +95,7 @@ class ProductForm extends Form
|
||||
'name' => ['required', 'string', 'max:100'],
|
||||
'unit' => ['required', Rule::enum(ProductUnit::class)],
|
||||
'price' => ['required', 'string', 'max:20'],
|
||||
'vat_rate_id' => ['required', 'integer'],
|
||||
'is_consumer_product' => ['boolean'],
|
||||
'duration' => ['nullable', 'string', 'max:10'],
|
||||
'work_type_id' => ['nullable', 'integer'],
|
||||
@@ -107,6 +114,8 @@ class ProductForm extends Form
|
||||
'unit.enum' => __('catalog.errors.invalid_unit'),
|
||||
'price.required' => __('catalog.errors.price_required'),
|
||||
'price.max' => __('catalog.errors.invalid_price'),
|
||||
'vat_rate_id.required' => __('catalog.errors.vat_rate_unavailable'),
|
||||
'vat_rate_id.integer' => __('catalog.errors.vat_rate_unavailable'),
|
||||
'duration.max' => __('catalog.errors.invalid_duration'),
|
||||
'work_type_id.integer' => __('catalog.errors.work_type_unavailable'),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user