Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

OrderShopRepositoryQuery.php 12KB

3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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\Order\OrderPaymentInterface;
  7. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  8. use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
  9. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  10. use Lc\CaracoleBundle\Model\User\VisitorInterface;
  11. use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
  12. use Lc\SovBundle\Model\User\UserInterface;
  13. use Lc\SovBundle\Repository\AbstractRepositoryQuery;
  14. use DateTime;
  15. class OrderShopRepositoryQuery extends AbstractRepositoryQuery
  16. {
  17. use SectionRepositoryQueryTrait;
  18. protected bool $isJoinProduct = false;
  19. protected bool $isJoinDistribution = false;
  20. protected bool $isJoinProductFamily = false;
  21. protected bool $isJoinOrderProducts = false;
  22. protected bool $isJoinOrderReductionCredits = false;
  23. protected bool $isJoinOrderReductionCarts = false;
  24. protected bool $isJoinOrderStatus = false;
  25. protected bool $isJoinMerchant = false;
  26. protected bool $isJoinUser = false;
  27. protected bool $isJoinComplementaryOrderShops = false;
  28. protected bool $isJoinDeliveryPointSale = false;
  29. protected bool $isJoinOrderPayment = false;
  30. protected bool $isFilteredByStatus = false;
  31. public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
  32. {
  33. parent::__construct($repository, 'orderShop', $paginator);
  34. }
  35. public function selectSumStatTotalWithTax(): self
  36. {
  37. return $this
  38. ->select(
  39. 'SUM(DISTINCT(orderShop.statTotalWithTax)) as total'
  40. );
  41. }
  42. public function selectSumQuantityOrder(): self
  43. {
  44. $this->joinOrderProducts();
  45. return $this
  46. ->select(
  47. 'SUM(orderProducts.quantityOrder) as quantity'
  48. );
  49. }
  50. public function selectSum(): self
  51. {
  52. $this->joinProduct();
  53. $this->joinDistribution();
  54. return $this
  55. ->select(
  56. 'SUM(orderProducts.quantityOrder) as quantity, distribution.cycleNumber as cycleNumber, distribution.year as year , product.id as productId'
  57. );
  58. }
  59. public function selectCountUser(): self
  60. {
  61. return $this
  62. ->select('count(DISTINCT(orderShop.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(DISTINCT(orderShop.id)) as total');
  74. }
  75. public function joinUser(): self
  76. {
  77. if (!$this->isJoinUser) {
  78. $this->isJoinUser = true;
  79. return $this
  80. ->leftJoin('.user', 'user');
  81. }
  82. return $this;
  83. }
  84. public function filterByUser(UserInterface $user): self
  85. {
  86. return $this
  87. ->andWhere('.user = :user')
  88. ->setParameter('user', $user);
  89. }
  90. public function filterByUserEmail(string $email): self
  91. {
  92. $this->joinUser();
  93. return $this
  94. ->andWhere('user.email LIKE :email')
  95. ->setParameter('email', $email);
  96. }
  97. public function filterByUserLastname(string $lastname): self
  98. {
  99. $this->joinUser();
  100. return $this
  101. ->andWhere('user.lastname LIKE :lastname')
  102. ->setParameter('lastname', $lastname);
  103. }
  104. public function filterByUserFirstname(string $firstname): self
  105. {
  106. $this->joinUser();
  107. return $this
  108. ->andWhere('user.firstname LIKE :firstname')
  109. ->setParameter('firstname', $firstname);
  110. }
  111. public function filterByAlias(array $status): self
  112. {
  113. $this->joinOrderStatus();
  114. return $this
  115. ->andWhere('orderStatus.alias IN (:alias)')
  116. ->setParameter('alias', $status);
  117. }
  118. public function filterByDistributionData(string $cycleType, int $cycleNumber, int $year){
  119. $this->joinDistribution();
  120. return $this
  121. ->andWhere('distribution.cycleType LIKE :cycleType')
  122. ->andWhere('distribution.cycleNumber LIKE :cycleNumber')
  123. ->andWhere('distribution.year LIKE :year')
  124. ->setParameter('cycleType', $cycleType)
  125. ->setParameter('cycleNumber', $cycleNumber)
  126. ->setParameter('year', $year);
  127. }
  128. public function filterByDistributions(array $distributionArray): self
  129. {
  130. return $this
  131. ->andWhere('.distribution IN (:distributions)')
  132. ->setParameter('distributions', $distributionArray);
  133. }
  134. public function filterByProducts(array $products): self
  135. {
  136. $this->joinOrderProducts();
  137. return $this
  138. ->andWhere('product.id IN(:products)')
  139. ->setParameter('products', $products);
  140. }
  141. public function filterByProduct(ProductInterface $product): self
  142. {
  143. $this->joinProduct();
  144. return $this
  145. ->andWhere('orderProducts.product = :product')
  146. ->setParameter('product', $product);
  147. }
  148. public function filterIsMerchantOnline(): self
  149. {
  150. $this->joinMerchant();
  151. return $this
  152. ->andWhere('merchant.status = :status')
  153. ->setParameter(':status', 1);
  154. }
  155. public function filterByDateStart(string $dateField, DateTime $dateStart): self
  156. {
  157. return $this
  158. ->andWhere('.' . $dateField . ' >= :dateStart')
  159. ->setParameter('dateStart', $dateStart);
  160. }
  161. public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
  162. {
  163. return $this
  164. ->andWhere('.' . $dateField . ' <= :dateEnd')
  165. ->setParameter('dateEnd', $dateEnd);
  166. }
  167. public function filterByVisitor(VisitorInterface $visitor): self
  168. {
  169. return $this->andWhereEqual('visitor', $visitor);
  170. }
  171. public function filterByAddress(AddressInterface $address): self
  172. {
  173. return $this
  174. ->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
  175. ->setParameter('address', $address);
  176. }
  177. public function filterByStatus(array $statusArray): self
  178. {
  179. $this->joinOrderStatus();
  180. // TODO: Voir pour faire mieux
  181. // On fait qu'une seule fois le filtre
  182. if (!$this->isFilteredByStatus) {
  183. $this->isFilteredByStatus = true;
  184. return $this
  185. ->andWhere('orderStatus.alias IN (:alias)')
  186. ->setParameter('alias', $statusArray);
  187. }
  188. return $this;
  189. }
  190. public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
  191. {
  192. $this->joinOrderReductionCredits();
  193. return $this
  194. ->andWhere('orderReductionCredits.reductionCredit = :reductionCredit')
  195. ->setParameter('reductionCredit', $reductionCredit);
  196. }
  197. public function filterByReductionCart(ReductionCartInterface $reductionCart): self
  198. {
  199. $this->joinOrderReductionCarts();
  200. return $this
  201. ->andWhere('orderReductionCarts.reductionCart = :reductionCart')
  202. ->setParameter('reductionCart', $reductionCart);
  203. }
  204. public function filterByDistribution(DistributionInterface $distribution): self
  205. {
  206. return $this
  207. ->andWhere('.distribution = :distribution')
  208. ->setParameter('distribution', $distribution);
  209. }
  210. public function filterByMeanPayment(string $meanPayment): self
  211. {
  212. $this->joinOrderPayment();
  213. return $this
  214. ->andWhere('orderPayments.meanPayment = :meanPayment')
  215. ->setParameter('meanPayment', $meanPayment);
  216. }
  217. public function filterByDeliveryType(string $deliveryType): self
  218. {
  219. return $this
  220. ->andWhere('.deliveryType = :deliveryType')
  221. ->setParameter('deliveryType', $deliveryType);
  222. }
  223. public function filterIsNotComplementaryOrderShop(): self
  224. {
  225. return $this
  226. ->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
  227. }
  228. public function filterIsComplementaryOrderShop(): self
  229. {
  230. return $this
  231. ->andWhere('.mainOrderShop = true OR .mainOrderShop IS NOT NULL');
  232. }
  233. public function filterIsNullMainOrderShop(): self
  234. {
  235. return $this
  236. ->andWhere('.mainOrderShop IS NULL');
  237. }
  238. public function filterMinimumTomorrowDelivery(): self
  239. {
  240. return $this->andWhere('.deliveryDate > :today')->setParameter('today', (new DateTime())->setTime(23, 59));
  241. }
  242. public function selectOrderReductionCarts(): self
  243. {
  244. $this->joinOrderReductionCarts();
  245. return $this->addSelect('orderReductionCarts');
  246. }
  247. public function joinOrderProducts(bool $addSelect = false): self
  248. {
  249. if (!$this->isJoinOrderProducts) {
  250. $this->isJoinOrderProducts = true;
  251. $this->leftJoin('.orderProducts', 'orderProducts');
  252. if ($addSelect) {
  253. $this->addSelect('orderProducts');
  254. }
  255. }
  256. return $this;
  257. }
  258. public function joinProduct(bool $addSelect = false): self
  259. {
  260. $this->joinOrderProducts($addSelect);
  261. if (!$this->isJoinProduct) {
  262. $this->isJoinProduct = true;
  263. $this->leftJoin('orderProducts.product', 'product');
  264. if ($addSelect) {
  265. $this->addSelect('product');
  266. }
  267. }
  268. return $this;
  269. }
  270. public function joinDistribution(bool $addSelect = false): self
  271. {
  272. if (!$this->isJoinDistribution) {
  273. $this->isJoinDistribution = true;
  274. $this->leftJoin('.distribution', 'distribution');
  275. if ($addSelect) {
  276. $this->addSelect('distribution');
  277. }
  278. }
  279. return $this;
  280. }
  281. public function joinProductFamily(bool $addSelect = false): self
  282. {
  283. $this->joinProduct($addSelect);
  284. if (!$this->isJoinProductFamily) {
  285. $this->isJoinProductFamily = true;
  286. $this->leftJoin('product.productFamily', 'productFamily');
  287. if ($addSelect) {
  288. $this->addSelect('productFamily');
  289. }
  290. }
  291. return $this;
  292. }
  293. public function joinOrderReductionCredits(): self
  294. {
  295. if (!$this->isJoinOrderReductionCredits) {
  296. $this->isJoinOrderReductionCredits = true;
  297. return $this
  298. ->innerJoin('.orderReductionCredits', 'orderReductionCredits');
  299. }
  300. return $this;
  301. }
  302. public function joinOrderStatus(): self
  303. {
  304. if (!$this->isJoinOrderStatus) {
  305. $this->isJoinOrderStatus = true;
  306. return $this
  307. ->leftJoin('.orderStatus', 'orderStatus');
  308. }
  309. return $this;
  310. }
  311. public function joinOrderReductionCarts(): self
  312. {
  313. if (!$this->isJoinOrderReductionCarts) {
  314. $this->isJoinOrderReductionCarts = true;
  315. return $this
  316. ->leftJoin('.orderReductionCarts', 'orderReductionCarts');
  317. }
  318. return $this;
  319. }
  320. public function joinMerchant(): self
  321. {
  322. $this->joinSection();
  323. if (!$this->isJoinMerchant) {
  324. $this->isJoinMerchant = true;
  325. return $this
  326. ->leftJoin('s.merchant', 'merchant');
  327. }
  328. return $this;
  329. }
  330. public function joinComplementaryOrderShops(): self
  331. {
  332. if (!$this->isJoinComplementaryOrderShops) {
  333. $this->isJoinComplementaryOrderShops = true;
  334. return $this
  335. ->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
  336. }
  337. return $this;
  338. }
  339. public function joinDeliveryPointSale(): self
  340. {
  341. if (!$this->isJoinDeliveryPointSale) {
  342. $this->isJoinDeliveryPointSale = true;
  343. return $this
  344. ->leftJoin('.deliveryPointSale', 'deliveryPointSale');
  345. }
  346. return $this;
  347. }
  348. public function joinOrderPayment(): self
  349. {
  350. if (!$this->isJoinOrderPayment) {
  351. $this->isJoinOrderPayment = true;
  352. return $this
  353. ->leftJoin('.orderPayments', 'orderPayments');
  354. }
  355. return $this;
  356. }
  357. }