*/ final readonly class OrderLineDto implements Arrayable { public Money $unit_price_discounted_ht; public Money $unitPriceTtc; public Money $total_gross_ht; public function __construct( public int $id, public string $order_id, public string $product_name, public ?string $product_inco_id, public ?string $product_brand_label, public bool $is_variable_weight, public ?Money $price_kg_ttc, public int $quantity, public Money $unit_price, public Money $unit_tax, public Money $unit_discount, public TaxRate $tax_rate, public Money $unit_price_ttc, public Money $total_ht, public Money $total_tax, public Money $total_discount, public Money $total_ttc, public Money $unitPriceDiscountedHt, public Money $totalGrossHt, ) { $this->unit_price_discounted_ht = $this->unitPriceDiscountedHt; $this->unitPriceTtc = $this->unit_price_ttc; $this->total_gross_ht = $this->totalGrossHt; } public static function fromModel(OrderLine $line): self { $product = $line->product; return new self( id: (int) $line->id, order_id: (string) $line->order_id, 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, quantity: (int) $line->quantity, unit_price: $line->unit_price, unit_tax: $line->unit_tax, unit_discount: $line->unit_discount, tax_rate: $line->tax_rate, unit_price_ttc: $line->unitPriceTtc, total_ht: $line->total_ht, total_tax: $line->total_tax, total_discount: $line->total_discount, total_ttc: $line->total_ttc, unitPriceDiscountedHt: $line->unitPriceDiscountedHt, totalGrossHt: $line->totalGrossHt, ); } /** * @return array */ #[\Override] public function toArray(): array { return [ '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(), ]; } }