Add the price list: hourly rates, products and mileage rate
- Work types get an hourly rate (VAT 0), set on the work type form or in the hourly rate grid of the new Hinnasto page (/catalog/prices), which saves a cell when focus leaves it. - Fixed-price products with a unit from a list, consumer product flag and automatic hours, which need a work type. Products are moved and deactivated, never deleted. - The mileage rate is stored in a new settings table through the shared Settings contract. - Shared Money value object keeps amounts in cents, parses "85,50" and formats "85,50 €". - Prices are read only through PriceListQueries, not CatalogQueries, so personal money permissions can be added in one place next. - Only admins and management can open the pages for now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Domain\Entities;
|
||||
|
||||
use App\Modules\Catalog\Domain\Enums\ProductUnit;
|
||||
use App\Modules\Catalog\Domain\Exceptions\ProductNeedsWorkType;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
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.
|
||||
*/
|
||||
final class Product extends CatalogItem
|
||||
{
|
||||
private function __construct(
|
||||
?int $id,
|
||||
CatalogName $name,
|
||||
private ProductUnit $unit,
|
||||
private Money $price,
|
||||
private bool $consumerProduct,
|
||||
private ProductDuration $duration,
|
||||
private ?int $workTypeId,
|
||||
bool $active,
|
||||
int $sortOrder,
|
||||
) {
|
||||
parent::__construct($id, $name, $active, $sortOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ProductNeedsWorkType
|
||||
*/
|
||||
public static function create(CatalogName $name, ProductUnit $unit, Money $price, 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);
|
||||
}
|
||||
|
||||
public static function reconstitute(int $id, CatalogName $name, ProductUnit $unit, Money $price, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId, bool $active, int $sortOrder): self
|
||||
{
|
||||
return new self($id, $name, $unit, $price, $consumerProduct, $duration, $workTypeId, $active, $sortOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ProductNeedsWorkType
|
||||
*/
|
||||
public function update(CatalogName $name, ProductUnit $unit, Money $price, bool $consumerProduct, ProductDuration $duration, ?int $workTypeId): void
|
||||
{
|
||||
self::ensureWorkTypeForDuration($duration, $workTypeId);
|
||||
|
||||
$this->name = $name;
|
||||
$this->unit = $unit;
|
||||
$this->price = $price;
|
||||
$this->consumerProduct = $consumerProduct;
|
||||
$this->duration = $duration;
|
||||
$this->workTypeId = $workTypeId;
|
||||
}
|
||||
|
||||
public function unit(): ProductUnit
|
||||
{
|
||||
return $this->unit;
|
||||
}
|
||||
|
||||
public function price(): Money
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
public function isConsumerProduct(): bool
|
||||
{
|
||||
return $this->consumerProduct;
|
||||
}
|
||||
|
||||
public function duration(): ProductDuration
|
||||
{
|
||||
return $this->duration;
|
||||
}
|
||||
|
||||
public function workTypeId(): ?int
|
||||
{
|
||||
return $this->workTypeId;
|
||||
}
|
||||
|
||||
private static function ensureWorkTypeForDuration(ProductDuration $duration, ?int $workTypeId): void
|
||||
{
|
||||
if (! $duration->isNone() && $workTypeId === null) {
|
||||
throw new ProductNeedsWorkType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,11 @@ namespace App\Modules\Catalog\Domain\Entities;
|
||||
|
||||
use App\Modules\Catalog\Domain\Exceptions\ServiceNotInUnit;
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
use App\Modules\Shared\Domain\ValueObjects\Money;
|
||||
|
||||
/**
|
||||
* A work type (työtehtävä), e.g. editointi. Tasks and time entries are
|
||||
* recorded against work types, and hourly rates (phase 2) belong to them.
|
||||
* recorded against work types, and the hourly rate (VAT 0) belongs to them.
|
||||
*/
|
||||
final class WorkType extends CatalogItem
|
||||
{
|
||||
@@ -20,6 +21,7 @@ final class WorkType extends CatalogItem
|
||||
CatalogName $name,
|
||||
bool $active,
|
||||
int $sortOrder,
|
||||
private ?Money $hourlyRate = null,
|
||||
) {
|
||||
parent::__construct($id, $name, $active, $sortOrder);
|
||||
}
|
||||
@@ -27,16 +29,29 @@ final class WorkType extends CatalogItem
|
||||
/**
|
||||
* @throws ServiceNotInUnit
|
||||
*/
|
||||
public static function create(ServiceUnit $serviceUnit, ?Service $service, CatalogName $name, int $sortOrder): self
|
||||
public static function create(ServiceUnit $serviceUnit, ?Service $service, CatalogName $name, int $sortOrder, ?Money $hourlyRate = null): self
|
||||
{
|
||||
self::ensureServiceInUnit($serviceUnit, $service);
|
||||
|
||||
return new self(null, (int) $serviceUnit->id(), $service?->id(), $name, true, $sortOrder);
|
||||
return new self(null, (int) $serviceUnit->id(), $service?->id(), $name, true, $sortOrder, $hourlyRate);
|
||||
}
|
||||
|
||||
public static function reconstitute(int $id, int $serviceUnitId, ?int $serviceId, CatalogName $name, bool $active, int $sortOrder): self
|
||||
public static function reconstitute(int $id, int $serviceUnitId, ?int $serviceId, CatalogName $name, bool $active, int $sortOrder, ?Money $hourlyRate = null): self
|
||||
{
|
||||
return new self($id, $serviceUnitId, $serviceId, $name, $active, $sortOrder);
|
||||
return new self($id, $serviceUnitId, $serviceId, $name, $active, $sortOrder, $hourlyRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Null means the work type has no price yet.
|
||||
*/
|
||||
public function hourlyRate(): ?Money
|
||||
{
|
||||
return $this->hourlyRate;
|
||||
}
|
||||
|
||||
public function changeHourlyRate(?Money $hourlyRate): void
|
||||
{
|
||||
$this->hourlyRate = $hourlyRate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user