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.

73 satır
2.2KB

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