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.

58 line
1.6KB

  1. <?php
  2. namespace domain\Document\DeliveryNote;
  3. use domain\Order\Order\Order;
  4. use domain\_\AbstractRepository;
  5. class DeliveryNoteRepository extends AbstractRepository
  6. {
  7. protected DeliveryNoteRepositoryQuery $query;
  8. public function loadDependencies(): void
  9. {
  10. $this->loadQuery(DeliveryNoteRepositoryQuery::class);
  11. }
  12. public function getDefaultOptionsSearch(): array
  13. {
  14. return [
  15. self::WITH => [],
  16. self::JOIN_WITH => ['user AS user_delivery_note', 'producer'],
  17. self::ORDER_BY => 'date ASC',
  18. self::ATTRIBUTE_ID_PRODUCER => 'delivery_note.id_producer'
  19. ];
  20. }
  21. public function findOneDeliveryNoteById(int $id): ?DeliveryNote
  22. {
  23. return $this->createDefaultQuery()
  24. ->filterById($id)
  25. ->findOne();
  26. }
  27. public function getOneDeliveryNoteExistingFromOrders(array $ordersArray): ?DeliveryNote
  28. {
  29. $i = 0;
  30. $deliveryNote = null;
  31. do {
  32. $order = $ordersArray[$i];
  33. if ($order->distribution->id_producer == $this->getProducerContextId() && $order->id_delivery_note > 0) {
  34. $deliveryNote = $this->findOneDeliveryNoteById($order->id_delivery_note);
  35. }
  36. $i++;
  37. } while ($deliveryNote == null && isset($ordersArray[$i]));
  38. return $deliveryNote;
  39. }
  40. public function findOneDeliveryNoteByOrder(Order $order): ?DeliveryNote
  41. {
  42. $deliveryNoteExist = null;
  43. if ($order->id_delivery_note) {
  44. $deliveryNoteExist = $this->findOneDeliveryNoteById($order->id_delivery_note);
  45. }
  46. return $deliveryNoteExist;
  47. }
  48. }