2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Domain\Models\ValueObjects;
|
|
|
|
|
|
|
|
|
|
use Money\Money;
|
|
|
|
|
|
|
|
|
|
final readonly class OrderLine
|
|
|
|
|
{
|
|
|
|
|
public Money $unitTtc;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
public OrderLineProduct $product,
|
|
|
|
|
public int $quantity,
|
|
|
|
|
public Money $unitPriceHt,
|
|
|
|
|
public Money $unitDiscount,
|
|
|
|
|
public Money $unitTax,
|
|
|
|
|
public Money $totalHt,
|
|
|
|
|
public Money $totalDiscount,
|
|
|
|
|
public Money $totalTax,
|
|
|
|
|
public Money $totalTtc,
|
|
|
|
|
) {
|
|
|
|
|
$this->unitTtc = $unitPriceHt->subtract($unitDiscount)->add($unitTax);
|
|
|
|
|
|
|
|
|
|
if ($quantity <= 0) {
|
|
|
|
|
throw new \DomainException('Quantity must be greater than 0');
|
|
|
|
|
}
|
|
|
|
|
if ($unitPriceHt->isNegative()) {
|
|
|
|
|
throw new \DomainException('Unit price must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
if ($unitDiscount->isNegative()) {
|
|
|
|
|
throw new \DomainException('Unit discount must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
if ($unitTax->isNegative()) {
|
|
|
|
|
throw new \DomainException('Unit tax must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
if ($this->unitTtc->isNegative()) {
|
|
|
|
|
throw new \DomainException('Unit TTC must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
if ($totalHt->isNegative()) {
|
|
|
|
|
throw new \DomainException('Total HT must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
if ($totalDiscount->isNegative()) {
|
|
|
|
|
throw new \DomainException('Total discount must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
if ($totalTax->isNegative()) {
|
|
|
|
|
throw new \DomainException('Total tax must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
if ($totalTtc->isNegative()) {
|
|
|
|
|
throw new \DomainException('Total TTC must be non-negative');
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-29 20:21:32 +01:00
|
|
|
|
|
|
|
|
public static function fromBasketProduct(BasketProduct $item): self
|
|
|
|
|
{
|
|
|
|
|
return new self(
|
|
|
|
|
product: OrderLineProduct::fromBasketProduct($item),
|
|
|
|
|
quantity: $item->qty,
|
|
|
|
|
unitPriceHt: clone $item->unitPriceHt,
|
|
|
|
|
unitDiscount: clone $item->unitDiscount,
|
|
|
|
|
unitTax: clone $item->unitTax(),
|
|
|
|
|
totalHt: clone $item->subtotalHt(),
|
|
|
|
|
totalDiscount: clone $item->discountTotal(),
|
|
|
|
|
totalTax: clone $item->taxTotal(),
|
|
|
|
|
totalTtc: clone $item->totalTtc()
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|