54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?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');
|
|
}
|
|
}
|
|
}
|