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.

246 lines
7.0KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Order;
  3. use App\Entity\Delivery\DeliveryAvailabilityPointSale;
  4. use App\Entity\Delivery\DeliveryAvailabilityZone;
  5. use App\Entity\PointSale\PointSale;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  8. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  9. use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
  10. use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
  11. use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
  12. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  13. use Lc\CaracoleBundle\Model\User\VisitorInterface;
  14. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  15. use Lc\SovBundle\Model\User\UserInterface;
  16. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  17. use DateTime;
  18. class OrderShopRepositoryQuery extends AbstractRepositoryQuery
  19. {
  20. use SectionRepositoryQueryTrait;
  21. protected bool $isJoinProduct = false;
  22. protected bool $isJoinOrderProduct = false;
  23. protected bool $isJoinOrderReductionCredits = false;
  24. protected bool $isJoinOrderReductionCarts = false;
  25. protected bool $isJoinOrderStatus = false;
  26. protected bool $isJoinMerchant = false;
  27. protected bool $isJoinSection = false;
  28. protected bool $isJoinComplementaryOrderShops = false;
  29. protected bool $isJoinDeliveryPointSale = false;
  30. public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
  31. {
  32. parent::__construct($repository, 'r', $paginator);
  33. }
  34. // @TODO : nécessaire ?
  35. public function selectParam($select): self
  36. {
  37. return $this
  38. ->addSelect($select);
  39. }
  40. public function selectCount(): self
  41. {
  42. return $this
  43. ->select('count(r.id) as total');
  44. }
  45. public function filterByMerchant(MerchantInterface $merchant)
  46. {
  47. $this->joinMerchant();
  48. return $this->andWhere('s.merchant = :merchant')
  49. ->setParameter('merchant', $merchant);
  50. }
  51. public function filterByUser(UserInterface $user): self
  52. {
  53. return $this
  54. ->andWhere('.user = :user')
  55. ->setParameter('user', $user);
  56. }
  57. public function filterIsMerchantOnline(): self
  58. {
  59. $this->joinMerchant();
  60. return $this
  61. ->andWhere('merchant.status = :status')
  62. ->setParameter(':status', 1);
  63. }
  64. public function filterByDateStart(string $dateField, DateTime $dateStart): self
  65. {
  66. return $this
  67. ->andWhere('.' . $dateField . ' >= :dateStart')
  68. ->setParameter('dateStart', $dateStart);
  69. }
  70. public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
  71. {
  72. return $this
  73. ->andWhere('.' . $dateField . ' <= :dateEnd')
  74. ->setParameter('dateEnd', $dateEnd);
  75. }
  76. public function filterByVisitor(VisitorInterface $visitor): self
  77. {
  78. return $this
  79. ->andWhere('.visitor = :visitor')
  80. ->setParameter('visitor', $visitor);
  81. }
  82. public function filterByAddress(AddressInterface $address): self
  83. {
  84. return $this
  85. ->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
  86. ->setParameter('address', $address);
  87. }
  88. public function filterByStatus(array $statusArray): self
  89. {
  90. $this->joinOrderStatus();
  91. return $this
  92. ->andWhere('os.alias IN (:alias)')
  93. ->setParameter('alias', $statusArray);
  94. }
  95. public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
  96. {
  97. $this->joinOrderReductionCredits();
  98. return $this
  99. ->andWhere('orc.reductionCredit = :reductionCredit')
  100. ->setParameter('reductionCredit', $reductionCredit);
  101. }
  102. public function filterByReductionCart(ReductionCartInterface $reductionCart): self
  103. {
  104. $this->joinOrderReductionCarts();
  105. return $this
  106. ->andWhere('orcart.reductionCart = :reductionCart')
  107. ->setParameter('reductionCart', $reductionCart);
  108. }
  109. public function filterByCycleNumber(int $cycleNumber): self
  110. {
  111. return $this
  112. ->andWhere('.cycleNumber = :cycleNumber')
  113. ->setParameter('cycleNumber', $cycleNumber);
  114. }
  115. public function filterIsNotComplementaryOrderShop(): self
  116. {
  117. return $this
  118. ->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
  119. }
  120. public function filterIsNullMainOrderShop(): self
  121. {
  122. return $this
  123. ->andWhere('.mainOrderShop IS NULL');
  124. }
  125. public function selectOrderReductionCarts(): self
  126. {
  127. $this->joinOrderReductionCarts();
  128. return $this->addSelect('orcart');
  129. }
  130. public function joinOrderProduct(): self
  131. {
  132. if (!$this->isJoinOrderProduct) {
  133. $this->isJoinOrderProduct = true;
  134. return $this
  135. ->innerJoin('.orderProducts', 'op');
  136. }
  137. return $this;
  138. }
  139. public function joinOrderReductionCredits(): self
  140. {
  141. if (!$this->isJoinOrderReductionCredits) {
  142. $this->isJoinOrderReductionCredits = true;
  143. return $this
  144. ->innerJoin('.orderReductionCredits', 'orc');
  145. }
  146. return $this;
  147. }
  148. public function joinOrderStatus(): self
  149. {
  150. if (!$this->isJoinOrderStatus) {
  151. $this->isJoinOrderStatus = true;
  152. return $this
  153. ->leftJoin('.orderStatus', 'os');
  154. }
  155. return $this;
  156. }
  157. public function joinOrderReductionCarts(): self
  158. {
  159. if (!$this->isJoinOrderReductionCarts) {
  160. $this->isJoinOrderReductionCarts = true;
  161. return $this
  162. ->leftJoin('.orderReductionCarts', 'orcart');
  163. }
  164. return $this;
  165. }
  166. public function joinMerchant(): self
  167. {
  168. $this->joinSection();
  169. if (!$this->isJoinMerchant) {
  170. $this->isJoinMerchant = true;
  171. return $this
  172. ->leftJoin('s.merchant', 'merchant');
  173. }
  174. return $this;
  175. }
  176. public function joinSection(): self
  177. {
  178. if (!$this->isJoinSection) {
  179. $this->isJoinSection = true;
  180. return $this
  181. ->leftJoin('.section', 's');
  182. }
  183. return $this;
  184. }
  185. public function joinComplementaryOrderShops(): self
  186. {
  187. if (!$this->isJoinComplementaryOrderShops) {
  188. $this->isJoinComplementaryOrderShops = true;
  189. return $this
  190. ->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
  191. }
  192. return $this;
  193. }
  194. public function joinDeliveryPointSale(): self
  195. {
  196. if (!$this->isJoinDeliveryPointSale) {
  197. $this->isJoinDeliveryPointSale = true;
  198. return $this
  199. ->leftJoin('.deliveryPointSale', 'pointSale');
  200. }
  201. return $this;
  202. }
  203. }