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.

OrderShopRepositoryQuery.php 9.3KB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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\Distribution\DistributionInterface;
  9. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  10. use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
  11. use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
  12. use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
  13. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  14. use Lc\CaracoleBundle\Model\User\VisitorInterface;
  15. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  16. use Lc\SovBundle\Model\User\UserInterface;
  17. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  18. use DateTime;
  19. class OrderShopRepositoryQuery extends AbstractRepositoryQuery
  20. {
  21. use SectionRepositoryQueryTrait;
  22. protected bool $isJoinProduct = false;
  23. protected bool $isJoinProductFamily = false;
  24. protected bool $isJoinOrderProduct = false;
  25. protected bool $isJoinOrderReductionCredits = false;
  26. protected bool $isJoinOrderReductionCarts = false;
  27. protected bool $isJoinOrderStatus = false;
  28. protected bool $isJoinMerchant = false;
  29. protected bool $isJoinComplementaryOrderShops = false;
  30. protected bool $isJoinDeliveryPointSale = false;
  31. public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
  32. {
  33. parent::__construct($repository, 'r', $paginator);
  34. }
  35. public function selectSumStatTotalWithTax(): self
  36. {
  37. return $this
  38. ->select(
  39. 'SUM(r.statTotalWithTax) as total'
  40. );
  41. }
  42. public function selectSumQuantityOrder(): self
  43. {
  44. $this->joinOrderProduct();
  45. return $this
  46. ->select(
  47. 'SUM(orderProduct.quantityOrder) as quantity'
  48. );
  49. }
  50. public function selectSum(): self
  51. {
  52. $this->joinProduct();
  53. $this->joinDistribution();
  54. return $this
  55. ->select(
  56. 'SUM(orderProduct.quantityOrder) as quantity, .cycleNumber as cycleNumber, product.id as productId'
  57. );
  58. }
  59. public function selectCountUser(): self
  60. {
  61. return $this
  62. ->select('count(DISTINCT(r.user)) as total');
  63. }
  64. // @TODO : nécessaire ?
  65. public function selectParam($select): self
  66. {
  67. return $this
  68. ->addSelect($select);
  69. }
  70. public function selectCount(): self
  71. {
  72. return $this
  73. ->select('count(r.id) as total');
  74. }
  75. public function filterByUser(UserInterface $user): self
  76. {
  77. return $this
  78. ->andWhere('.user = :user')
  79. ->setParameter('user', $user);
  80. }
  81. public function filterByAlias(array $status): self
  82. {
  83. $this->joinOrderStatus();
  84. return $this
  85. ->andWhere('os.alias IN (:alias)')
  86. ->setParameter('alias', $status);
  87. }
  88. public function filterByDistributions(array $distributions): self
  89. {
  90. return $this
  91. ->andWhere('.distribution IN(:distributions)')
  92. ->setParameter('distributions', $distributions);
  93. }
  94. public function filterByProducts(array $products): self
  95. {
  96. $this->joinOrderProduct();
  97. return $this
  98. ->andWhere('product.id IN(:products)')
  99. ->setParameter('products', $products);
  100. }
  101. public function filterByProduct(int $productId): self
  102. {
  103. $this->joinProduct();
  104. return $this
  105. ->andWhere('orderProduct.product = :product')
  106. ->setParameter('product', $productId);
  107. }
  108. public function filterIsMerchantOnline(): self
  109. {
  110. $this->joinMerchant();
  111. return $this
  112. ->andWhere('merchant.status = :status')
  113. ->setParameter(':status', 1);
  114. }
  115. public function filterByDateStart(string $dateField, DateTime $dateStart): self
  116. {
  117. return $this
  118. ->andWhere('.' . $dateField . ' >= :dateStart')
  119. ->setParameter('dateStart', $dateStart);
  120. }
  121. public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
  122. {
  123. return $this
  124. ->andWhere('.' . $dateField . ' <= :dateEnd')
  125. ->setParameter('dateEnd', $dateEnd);
  126. }
  127. public function filterByVisitor(VisitorInterface $visitor): self
  128. {
  129. return $this
  130. ->andWhere('.visitor = :visitor')
  131. ->setParameter('visitor', $visitor);
  132. }
  133. public function filterByAddress(AddressInterface $address): self
  134. {
  135. return $this
  136. ->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
  137. ->setParameter('address', $address);
  138. }
  139. public function filterByStatus(array $statusArray): self
  140. {
  141. $this->joinOrderStatus();
  142. return $this
  143. ->andWhere('os.alias IN (:alias)')
  144. ->setParameter('alias', $statusArray);
  145. }
  146. public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
  147. {
  148. $this->joinOrderReductionCredits();
  149. return $this
  150. ->andWhere('orc.reductionCredit = :reductionCredit')
  151. ->setParameter('reductionCredit', $reductionCredit);
  152. }
  153. public function filterByReductionCart(ReductionCartInterface $reductionCart): self
  154. {
  155. $this->joinOrderReductionCarts();
  156. return $this
  157. ->andWhere('orcart.reductionCart = :reductionCart')
  158. ->setParameter('reductionCart', $reductionCart);
  159. }
  160. public function filterByDistribution(DistributionInterface $distribution): self
  161. {
  162. return $this
  163. ->andWhere('.distribution = :distribution')
  164. ->setParameter('distribution', $distribution);
  165. }
  166. public function filterIsNotComplementaryOrderShop(): self
  167. {
  168. return $this
  169. ->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
  170. }
  171. public function filterIsNullMainOrderShop(): self
  172. {
  173. return $this
  174. ->andWhere('.mainOrderShop IS NULL');
  175. }
  176. public function selectOrderReductionCarts(): self
  177. {
  178. $this->joinOrderReductionCarts();
  179. return $this->addSelect('orcart');
  180. }
  181. public function joinOrderProduct(bool $addSelect = false): self
  182. {
  183. if (!$this->isJoinOrderProduct) {
  184. $this->isJoinOrderProduct = true;
  185. $this->innerJoin('.orderProducts', 'orderProduct');
  186. if ($addSelect) {
  187. $this->addSelect('orderProduct');
  188. }
  189. }
  190. return $this;
  191. }
  192. public function joinProduct(bool $addSelect = false): self
  193. {
  194. $this->joinOrderProduct($addSelect);
  195. if (!$this->isJoinProduct) {
  196. $this->isJoinProduct = true;
  197. $this->leftJoin('orderProduct.product', 'product');
  198. if ($addSelect) {
  199. $this->addSelect('product');
  200. }
  201. }
  202. return $this;
  203. }
  204. public function joinProductFamily(bool $addSelect = false): self
  205. {
  206. $this->joinProduct($addSelect);
  207. if (!$this->isJoinProductFamily) {
  208. $this->isJoinProductFamily = true;
  209. $this->leftJoin('product.productFamily', 'productFamily');
  210. if ($addSelect) {
  211. $this->addSelect('productFamily');
  212. }
  213. }
  214. return $this;
  215. }
  216. public function joinOrderReductionCredits(): self
  217. {
  218. if (!$this->isJoinOrderReductionCredits) {
  219. $this->isJoinOrderReductionCredits = true;
  220. return $this
  221. ->innerJoin('.orderReductionCredits', 'orc');
  222. }
  223. return $this;
  224. }
  225. public function joinOrderStatus(): self
  226. {
  227. if (!$this->isJoinOrderStatus) {
  228. $this->isJoinOrderStatus = true;
  229. return $this
  230. ->leftJoin('.orderStatus', 'os');
  231. }
  232. return $this;
  233. }
  234. public function joinOrderReductionCarts(): self
  235. {
  236. if (!$this->isJoinOrderReductionCarts) {
  237. $this->isJoinOrderReductionCarts = true;
  238. return $this
  239. ->leftJoin('.orderReductionCarts', 'orcart');
  240. }
  241. return $this;
  242. }
  243. public function joinMerchant(): self
  244. {
  245. $this->joinSection();
  246. if (!$this->isJoinMerchant) {
  247. $this->isJoinMerchant = true;
  248. return $this
  249. ->leftJoin('s.merchant', 'merchant');
  250. }
  251. return $this;
  252. }
  253. public function joinComplementaryOrderShops(): self
  254. {
  255. if (!$this->isJoinComplementaryOrderShops) {
  256. $this->isJoinComplementaryOrderShops = true;
  257. return $this
  258. ->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
  259. }
  260. return $this;
  261. }
  262. public function joinDeliveryPointSale(): self
  263. {
  264. if (!$this->isJoinDeliveryPointSale) {
  265. $this->isJoinDeliveryPointSale = true;
  266. return $this
  267. ->leftJoin('.deliveryPointSale', 'pointSale');
  268. }
  269. return $this;
  270. }
  271. }