Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

OrderShopRepositoryQuery.php 12KB

3 lat temu
2 lat temu
3 lat temu
3 lat temu
3 lat temu
2 lat temu
3 lat temu
3 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
2 lat temu
3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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 filterHasOrderProducts()
  243. {
  244. return $this->andWhere('orderShop.orderProducts IS NOT EMPTY');
  245. }
  246. public function selectOrderReductionCarts(): self
  247. {
  248. $this->joinOrderReductionCarts();
  249. return $this->addSelect('orderReductionCarts');
  250. }
  251. public function joinOrderProducts(bool $addSelect = false): self
  252. {
  253. if (!$this->isJoinOrderProducts) {
  254. $this->isJoinOrderProducts = true;
  255. $this->leftJoin('.orderProducts', 'orderProducts');
  256. if ($addSelect) {
  257. $this->addSelect('orderProducts');
  258. }
  259. }
  260. return $this;
  261. }
  262. public function joinProduct(bool $addSelect = false): self
  263. {
  264. $this->joinOrderProducts($addSelect);
  265. if (!$this->isJoinProduct) {
  266. $this->isJoinProduct = true;
  267. $this->leftJoin('orderProducts.product', 'product');
  268. if ($addSelect) {
  269. $this->addSelect('product');
  270. }
  271. }
  272. return $this;
  273. }
  274. public function joinDistribution(bool $addSelect = false): self
  275. {
  276. if (!$this->isJoinDistribution) {
  277. $this->isJoinDistribution = true;
  278. $this->leftJoin('.distribution', 'distribution');
  279. if ($addSelect) {
  280. $this->addSelect('distribution');
  281. }
  282. }
  283. return $this;
  284. }
  285. public function joinProductFamily(bool $addSelect = false): self
  286. {
  287. $this->joinProduct($addSelect);
  288. if (!$this->isJoinProductFamily) {
  289. $this->isJoinProductFamily = true;
  290. $this->leftJoin('product.productFamily', 'productFamily');
  291. if ($addSelect) {
  292. $this->addSelect('productFamily');
  293. }
  294. }
  295. return $this;
  296. }
  297. public function joinOrderReductionCredits(): self
  298. {
  299. if (!$this->isJoinOrderReductionCredits) {
  300. $this->isJoinOrderReductionCredits = true;
  301. return $this
  302. ->innerJoin('.orderReductionCredits', 'orderReductionCredits');
  303. }
  304. return $this;
  305. }
  306. public function joinOrderStatus(): self
  307. {
  308. if (!$this->isJoinOrderStatus) {
  309. $this->isJoinOrderStatus = true;
  310. return $this
  311. ->leftJoin('.orderStatus', 'orderStatus');
  312. }
  313. return $this;
  314. }
  315. public function joinOrderReductionCarts(): self
  316. {
  317. if (!$this->isJoinOrderReductionCarts) {
  318. $this->isJoinOrderReductionCarts = true;
  319. return $this
  320. ->leftJoin('.orderReductionCarts', 'orderReductionCarts');
  321. }
  322. return $this;
  323. }
  324. public function joinMerchant(): self
  325. {
  326. $this->joinSection();
  327. if (!$this->isJoinMerchant) {
  328. $this->isJoinMerchant = true;
  329. return $this
  330. ->leftJoin('s.merchant', 'merchant');
  331. }
  332. return $this;
  333. }
  334. public function joinComplementaryOrderShops(): self
  335. {
  336. if (!$this->isJoinComplementaryOrderShops) {
  337. $this->isJoinComplementaryOrderShops = true;
  338. return $this
  339. ->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
  340. }
  341. return $this;
  342. }
  343. public function joinDeliveryPointSale(): self
  344. {
  345. if (!$this->isJoinDeliveryPointSale) {
  346. $this->isJoinDeliveryPointSale = true;
  347. return $this
  348. ->leftJoin('.deliveryPointSale', 'deliveryPointSale');
  349. }
  350. return $this;
  351. }
  352. public function joinOrderPayment(): self
  353. {
  354. if (!$this->isJoinOrderPayment) {
  355. $this->isJoinOrderPayment = true;
  356. return $this
  357. ->leftJoin('.orderPayments', 'orderPayments');
  358. }
  359. return $this;
  360. }
  361. }