2026-09-30 17:57:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Dto;
|
|
|
|
|
|
|
|
|
|
use App\Models\OrderLine;
|
|
|
|
|
use Domain\Enums\TaxRate;
|
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
|
use Money\Money;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @implements Arrayable<string, mixed>
|
|
|
|
|
*/
|
|
|
|
|
final readonly class OrderLineDto implements Arrayable
|
|
|
|
|
{
|
2026-11-02 14:53:06 +01:00
|
|
|
public Money $unit_price_discounted_ht;
|
|
|
|
|
|
|
|
|
|
public Money $unitPriceTtc;
|
|
|
|
|
|
|
|
|
|
public Money $total_gross_ht;
|
|
|
|
|
|
2026-09-30 17:57:20 +02:00
|
|
|
public function __construct(
|
|
|
|
|
public int $id,
|
|
|
|
|
public string $order_id,
|
2026-11-02 14:53:06 +01:00
|
|
|
public string $product_name,
|
|
|
|
|
public ?string $product_inco_id,
|
|
|
|
|
public ?string $product_brand_label,
|
|
|
|
|
public bool $is_variable_weight,
|
|
|
|
|
public ?Money $price_kg_ttc,
|
2026-09-30 17:57:20 +02:00
|
|
|
public int $quantity,
|
|
|
|
|
public Money $unit_price,
|
|
|
|
|
public Money $unit_tax,
|
|
|
|
|
public Money $unit_discount,
|
|
|
|
|
public TaxRate $tax_rate,
|
2026-11-02 14:53:06 +01:00
|
|
|
public Money $unit_price_ttc,
|
2026-09-30 17:57:20 +02:00
|
|
|
public Money $total_ht,
|
|
|
|
|
public Money $total_tax,
|
|
|
|
|
public Money $total_discount,
|
2026-11-02 14:53:06 +01:00
|
|
|
public Money $total_ttc,
|
2026-09-30 17:57:20 +02:00
|
|
|
public Money $unitPriceDiscountedHt,
|
|
|
|
|
public Money $totalGrossHt,
|
|
|
|
|
) {
|
2026-11-02 14:53:06 +01:00
|
|
|
$this->unit_price_discounted_ht = $this->unitPriceDiscountedHt;
|
|
|
|
|
$this->unitPriceTtc = $this->unit_price_ttc;
|
|
|
|
|
$this->total_gross_ht = $this->totalGrossHt;
|
2026-09-30 17:57:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function fromModel(OrderLine $line): self
|
|
|
|
|
{
|
2026-11-02 14:53:06 +01:00
|
|
|
$product = $line->product;
|
|
|
|
|
|
2026-09-30 17:57:20 +02:00
|
|
|
return new self(
|
|
|
|
|
id: (int) $line->id,
|
|
|
|
|
order_id: (string) $line->order_id,
|
2026-11-02 14:53:06 +01:00
|
|
|
product_name: $product->name,
|
|
|
|
|
product_inco_id: (string) $product->incoId->value,
|
|
|
|
|
product_brand_label: $product->brand->label(),
|
|
|
|
|
is_variable_weight: $product->weight->isVariable,
|
|
|
|
|
price_kg_ttc: $product->priceKgTtc,
|
2026-09-30 17:57:20 +02:00
|
|
|
quantity: (int) $line->quantity,
|
|
|
|
|
unit_price: $line->unit_price,
|
|
|
|
|
unit_tax: $line->unit_tax,
|
|
|
|
|
unit_discount: $line->unit_discount,
|
|
|
|
|
tax_rate: $line->tax_rate,
|
2026-11-02 14:53:06 +01:00
|
|
|
unit_price_ttc: $line->unitPriceTtc,
|
2026-09-30 17:57:20 +02:00
|
|
|
total_ht: $line->total_ht,
|
|
|
|
|
total_tax: $line->total_tax,
|
|
|
|
|
total_discount: $line->total_discount,
|
2026-11-02 14:53:06 +01:00
|
|
|
total_ttc: $line->total_ttc,
|
2026-09-30 17:57:20 +02:00
|
|
|
unitPriceDiscountedHt: $line->unitPriceDiscountedHt,
|
|
|
|
|
totalGrossHt: $line->totalGrossHt,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<string, mixed>
|
|
|
|
|
*/
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function toArray(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-11-02 14:53:06 +01:00
|
|
|
'id' => $this->id,
|
|
|
|
|
'order_id' => $this->order_id,
|
|
|
|
|
'product_name' => $this->product_name,
|
|
|
|
|
'product_inco_id' => $this->product_inco_id,
|
|
|
|
|
'product_brand_label' => $this->product_brand_label,
|
|
|
|
|
'is_variable_weight' => $this->is_variable_weight,
|
|
|
|
|
'price_kg_ttc' => $this->price_kg_ttc?->getAmount(),
|
|
|
|
|
'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,
|
|
|
|
|
'unit_price_ttc' => $this->unit_price_ttc->getAmount(),
|
|
|
|
|
'unit_price_discounted_ht' => $this->unit_price_discounted_ht->getAmount(),
|
|
|
|
|
'total_ttc' => $this->total_ttc->getAmount(),
|
|
|
|
|
'total_ht' => $this->total_ht->getAmount(),
|
|
|
|
|
'total_tax' => $this->total_tax->getAmount(),
|
|
|
|
|
'total_discount' => $this->total_discount->getAmount(),
|
|
|
|
|
'total_gross_ht' => $this->total_gross_ht->getAmount(),
|
2026-09-30 17:57:20 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|