76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Models\OrderLine;
|
|
use Domain\Enums\TaxRate;
|
|
use Domain\Models\ValueObjects\OrderLineProduct;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use Money\Money;
|
|
|
|
/**
|
|
* @implements Arrayable<string, mixed>
|
|
*/
|
|
final readonly class OrderLineDto implements Arrayable
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $order_id,
|
|
public OrderLineProduct $product,
|
|
public int $quantity,
|
|
public Money $unit_price,
|
|
public Money $unit_tax,
|
|
public Money $unit_discount,
|
|
public TaxRate $tax_rate,
|
|
public Money $total_ttc,
|
|
public Money $total_ht,
|
|
public Money $total_tax,
|
|
public Money $total_discount,
|
|
public Money $unitPriceDiscountedHt,
|
|
public Money $totalGrossHt,
|
|
) {
|
|
}
|
|
|
|
public static function fromModel(OrderLine $line): self
|
|
{
|
|
return new self(
|
|
id: (int) $line->id,
|
|
order_id: (string) $line->order_id,
|
|
product: $line->product,
|
|
quantity: (int) $line->quantity,
|
|
unit_price: $line->unit_price,
|
|
unit_tax: $line->unit_tax,
|
|
unit_discount: $line->unit_discount,
|
|
tax_rate: $line->tax_rate,
|
|
total_ttc: $line->total_ttc,
|
|
total_ht: $line->total_ht,
|
|
total_tax: $line->total_tax,
|
|
total_discount: $line->total_discount,
|
|
unitPriceDiscountedHt: $line->unitPriceDiscountedHt,
|
|
totalGrossHt: $line->totalGrossHt,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
#[\Override]
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'order_id' => $this->order_id,
|
|
'quantity' => $this->quantity,
|
|
'unit_price' => $this->unit_price->getAmount(),
|
|
'unit_tax' => $this->unit_tax->getAmount(),
|
|
'unit_discount' => $this->unit_discount->getAmount(),
|
|
'tax_rate' => $this->tax_rate->value,
|
|
'total_ttc' => $this->total_ttc->getAmount(),
|
|
'total_ht' => $this->total_ht->getAmount(),
|
|
'total_tax' => $this->total_tax->getAmount(),
|
|
'total_discount' => $this->total_discount->getAmount(),
|
|
];
|
|
}
|
|
}
|