Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

LineItemDTO.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\DTO;
  3. use App\Models\Accounting\DocumentLineItem;
  4. use App\Utilities\Currency\CurrencyConverter;
  5. readonly class LineItemDTO
  6. {
  7. public function __construct(
  8. public string $name,
  9. public string $description,
  10. public int $quantity,
  11. public string $unitPrice,
  12. public string $subtotal,
  13. ) {}
  14. public static function fromModel(DocumentLineItem $lineItem): self
  15. {
  16. return new self(
  17. name: $lineItem->offering->name ?? '',
  18. description: $lineItem->description ?? '',
  19. quantity: $lineItem->quantity,
  20. unitPrice: self::formatToMoney($lineItem->unit_price, $lineItem->documentable->currency_code),
  21. subtotal: self::formatToMoney($lineItem->subtotal, $lineItem->documentable->currency_code),
  22. );
  23. }
  24. protected static function formatToMoney(float | string | int $value, ?string $currencyCode): string
  25. {
  26. if (is_int($value)) {
  27. return CurrencyConverter::formatCentsToMoney($value, $currencyCode);
  28. }
  29. return CurrencyConverter::formatToMoney($value, $currencyCode);
  30. }
  31. }