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.

59 lines
1.7KB

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