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.6KB

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