Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

156 lines
4.0KB

  1. <?php
  2. namespace domain\Order\Order;
  3. use domain\Document\DeliveryNote\DeliveryNote;
  4. use domain\Document\Invoice\Invoice;
  5. use domain\Order\OrderStatus\OrderStatus;
  6. use domain\User\User\User;
  7. use domain\_\AbstractRepositoryQuery;
  8. class OrderRepositoryQuery extends AbstractRepositoryQuery
  9. {
  10. protected OrderDefinition $definition;
  11. public function loadDependencies(): void
  12. {
  13. $this->loadDefinition(OrderDefinition::class);
  14. }
  15. public function filterById(int $id): self
  16. {
  17. $this->andWhere(['order.id' => $id]);
  18. return $this;
  19. }
  20. public function filterByOrigin(string $origin)
  21. {
  22. $this->andWhere(['origin' => $origin]);
  23. return $this;
  24. }
  25. public function filterByDate(\DateTime $date)
  26. {
  27. $this
  28. ->andWhere('`order`.date >= \'' .$date->format('Y-m-d 00:00:00').'\'')
  29. ->andWhere('`order`.date <= \'' .$date->format('Y-m-d 23:59:59').'\'');
  30. return $this;
  31. }
  32. public function filterByDistributionDate(string $date): self
  33. {
  34. $this->andWhere(['distribution.date' => $date]);
  35. return $this;
  36. }
  37. public function filterByDistributionDateStartEnd(\DateTime $dateStart, \DateTime $dateEnd): self
  38. {
  39. $this
  40. ->andWhere('distribution.date >= \'' .$dateStart->format('Y-m-d').'\'')
  41. ->andWhere('distribution.date <= \'' .$dateEnd->format('Y-m-d').'\'');
  42. return $this;
  43. }
  44. public static function getSqlFilterIsValid(): string
  45. {
  46. return " (`order`.order_status_alias = '".OrderStatus::ALIAS_ORDERED."' OR `order`.order_status_alias = '".OrderStatus::ALIAS_UPDATED."') ";
  47. }
  48. public static function getSqlFilterIsOrderStatusNotDeleted(): string
  49. {
  50. return " (`order`.order_status_alias != '".OrderStatus::ALIAS_DELETED."') ";
  51. }
  52. public function filterIsValid(): self
  53. {
  54. $this->andWhere(self::getSqlFilterIsValid());
  55. return $this;
  56. }
  57. public function filterIsOrderStatusNotDeleted(): self
  58. {
  59. $this->andWhere('order_status_alias != :status_deleted')
  60. ->addParams([':status_deleted' => OrderStatus::ALIAS_DELETED]);
  61. return $this;
  62. }
  63. public function filterIsOrderStatusAliasNull(): self
  64. {
  65. $this->andWhere('order_status_alias IS NULL');
  66. return $this;
  67. }
  68. public function filterByUser(User $user): self
  69. {
  70. $this->andWhere(['order.id_user' => $user->id]);
  71. return $this;
  72. }
  73. public function filterIsIncoming(): self
  74. {
  75. $this->andWhere('distribution.date >= :date_today')
  76. ->addParams([':date_today' => date('Y-m-d')]);
  77. return $this;
  78. }
  79. public function filterIsPassed(): self
  80. {
  81. $this->andWhere('distribution.date < :date_today')
  82. ->addParams([':date_today' => date('Y-m-d')]);
  83. return $this;
  84. }
  85. public function filterIsInvoiced(Invoice $invoice): self
  86. {
  87. $this->andWhere('order.id_invoice IS NOT NULL AND order.id_invoice = :id_invoice')
  88. ->addParams([':id_invoice' => $invoice->id]);
  89. return $this;
  90. }
  91. public function filterIsLinkedDeliveryNote(DeliveryNote $deliveryNote): self
  92. {
  93. $this->andWhere('order.id_delivery_note IS NOT NULL AND order.id_delivery_note = :id_delivery_note')
  94. ->addParams([':id_delivery_note' => $deliveryNote->id]);
  95. return $this;
  96. }
  97. public function filterIsNotInvoiced(): self
  98. {
  99. $this->andWhere('order.id_invoice IS NULL');
  100. return $this;
  101. }
  102. public function filterIsNotLinkedDeliveryNote(): self
  103. {
  104. $this->andWhere('order.id_delivery_note IS NULL');
  105. return $this;
  106. }
  107. public function filterIsNotIgnoreWhenInvoicing(): self
  108. {
  109. $this->andWhere('order.ignore_when_invoicing IS NULL');
  110. return $this;
  111. }
  112. public function orderByDistributionDate(string $order = 'ASC'): self
  113. {
  114. $this->orderBy('distribution.date '.$order );
  115. return $this;
  116. }
  117. }