You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0KB

  1. <?php
  2. namespace common\logic\Document\DeliveryNote\Service;
  3. use common\logic\Document\DeliveryNote\Model\DeliveryNote;
  4. use common\logic\Document\Document\Service\DocumentSolver;
  5. use common\logic\Document\Invoice\Model\Invoice;
  6. use common\logic\SolverInterface;
  7. class DeliveryNoteSolver extends DocumentSolver implements SolverInterface
  8. {
  9. public function getInvoiceId(DeliveryNote $deliveryNote): ?int
  10. {
  11. if($deliveryNote->orders && count($deliveryNote->orders) > 0) {
  12. foreach($deliveryNote->orders as $order) {
  13. if($order->id_invoice) {
  14. return $order->id_invoice;
  15. }
  16. }
  17. }
  18. return null;
  19. }
  20. public function isInvoiced(DeliveryNote $deliveryNote): bool
  21. {
  22. return (bool) $this->getInvoiceId($deliveryNote);
  23. }
  24. public function getInvoice(DeliveryNote $deliveryNote): ?Invoice
  25. {
  26. $idInvoice = (int) $this->getInvoiceId($deliveryNote);
  27. return Invoice::searchOne([
  28. 'id' => $idInvoice
  29. ]);
  30. }
  31. }