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 11KB

пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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 $isJoinOrderProducts = false;
  21. protected bool $isJoinOrderReductionCredits = false;
  22. protected bool $isJoinOrderReductionCarts = false;
  23. protected bool $isJoinOrderStatus = false;
  24. protected bool $isJoinMerchant = false;
  25. protected bool $isJoinUser = false;
  26. protected bool $isJoinComplementaryOrderShops = false;
  27. protected bool $isJoinDeliveryPointSale = false;
  28. public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
  29. {
  30. parent::__construct($repository, 'orderShop', $paginator);
  31. }
  32. public function selectSumStatTotalWithTax(): self
  33. {
  34. return $this
  35. ->select(
  36. 'SUM(DISTINCT(orderShop.statTotalWithTax)) as total'
  37. );
  38. }
  39. public function selectSumQuantityOrder(): self
  40. {
  41. $this->joinOrderProducts();
  42. return $this
  43. ->select(
  44. 'SUM(orderProducts.quantityOrder) as quantity'
  45. );
  46. }
  47. public function selectSum(): self
  48. {
  49. $this->joinProduct();
  50. $this->joinDistribution();
  51. return $this
  52. ->select(
  53. 'SUM(orderProducts.quantityOrder) as quantity, distribution.cycleNumber as cycleNumber, distribution.year as year , product.id as productId'
  54. );
  55. }
  56. public function selectCountUser(): self
  57. {
  58. return $this
  59. ->select('count(DISTINCT(orderShop.user)) as total');
  60. }
  61. // @TODO : nécessaire ?
  62. public function selectParam($select): self
  63. {
  64. return $this
  65. ->addSelect($select);
  66. }
  67. public function selectCount(): self
  68. {
  69. return $this
  70. ->select('count(DISTINCT(orderShop.id)) as total');
  71. }
  72. public function joinUser(): self
  73. {
  74. if (!$this->isJoinUser) {
  75. $this->isJoinUser = true;
  76. return $this
  77. ->leftJoin('.user', 'user');
  78. }
  79. return $this;
  80. }
  81. public function filterByUser(UserInterface $user): self
  82. {
  83. return $this
  84. ->andWhere('.user = :user')
  85. ->setParameter('user', $user);
  86. }
  87. public function filterByUserEmail(string $email): self
  88. {
  89. $this->joinUser();
  90. return $this
  91. ->andWhere('user.email LIKE :email')
  92. ->setParameter('email', $email);
  93. }
  94. public function filterByUserLastname(string $lastname): self
  95. {
  96. $this->joinUser();
  97. return $this
  98. ->andWhere('user.lastname LIKE :lastname')
  99. ->setParameter('lastname', $lastname);
  100. }
  101. public function filterByUserFirstname(string $firstname): self
  102. {
  103. $this->joinUser();
  104. return $this
  105. ->andWhere('user.firstname LIKE :firstname')
  106. ->setParameter('firstname', $firstname);
  107. }
  108. public function filterByAlias(array $status): self
  109. {
  110. $this->joinOrderStatus();
  111. return $this
  112. ->andWhere('orderStatus.alias IN (:alias)')
  113. ->setParameter('alias', $status);
  114. }
  115. public function filterByDistributions(array $distributions): self
  116. {
  117. return $this
  118. ->andWhere('.distribution IN(:distributions)')
  119. ->setParameter('distributions', $distributions);
  120. }
  121. public function filterByProducts(array $products): self
  122. {
  123. $this->joinOrderProducts();
  124. return $this
  125. ->andWhere('product.id IN(:products)')
  126. ->setParameter('products', $products);
  127. }
  128. public function filterByProduct(ProductInterface $product): self
  129. {
  130. $this->joinProduct();
  131. return $this
  132. ->andWhere('orderProducts.product = :product')
  133. ->setParameter('product', $product);
  134. }
  135. public function filterIsMerchantOnline(): self
  136. {
  137. $this->joinMerchant();
  138. return $this
  139. ->andWhere('merchant.status = :status')
  140. ->setParameter(':status', 1);
  141. }
  142. public function filterByDateStart(string $dateField, DateTime $dateStart): self
  143. {
  144. return $this
  145. ->andWhere('.' . $dateField . ' >= :dateStart')
  146. ->setParameter('dateStart', $dateStart);
  147. }
  148. public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
  149. {
  150. return $this
  151. ->andWhere('.' . $dateField . ' <= :dateEnd')
  152. ->setParameter('dateEnd', $dateEnd);
  153. }
  154. public function filterByVisitor(VisitorInterface $visitor): self
  155. {
  156. return $this->andWhereEqual('visitor', $visitor);
  157. }
  158. public function filterByAddress(AddressInterface $address): self
  159. {
  160. return $this
  161. ->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
  162. ->setParameter('address', $address);
  163. }
  164. public function filterByStatus(array $statusArray): self
  165. {
  166. $this->joinOrderStatus();
  167. return $this
  168. ->andWhere('orderStatus.alias IN (:alias)')
  169. ->setParameter('alias', $statusArray);
  170. }
  171. public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
  172. {
  173. $this->joinOrderReductionCredits();
  174. return $this
  175. ->andWhere('orderReductionCredits.reductionCredit = :reductionCredit')
  176. ->setParameter('reductionCredit', $reductionCredit);
  177. }
  178. public function filterByReductionCart(ReductionCartInterface $reductionCart): self
  179. {
  180. $this->joinOrderReductionCarts();
  181. return $this
  182. ->andWhere('orderReductionCarts.reductionCart = :reductionCart')
  183. ->setParameter('reductionCart', $reductionCart);
  184. }
  185. public function filterByDistribution(DistributionInterface $distribution): self
  186. {
  187. return $this
  188. ->andWhere('.distribution = :distribution')
  189. ->setParameter('distribution', $distribution);
  190. }
  191. public function filterIsNotComplementaryOrderShop(): self
  192. {
  193. return $this
  194. ->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
  195. }
  196. public function filterIsNullMainOrderShop(): self
  197. {
  198. return $this
  199. ->andWhere('.mainOrderShop IS NULL');
  200. }
  201. public function filterMinimumTomorrowDelivery(): self
  202. {
  203. return $this->andWhere('.deliveryDate > :today')->setParameter('today', (new DateTime())->setTime(23, 59));
  204. }
  205. public function selectOrderReductionCarts(): self
  206. {
  207. $this->joinOrderReductionCarts();
  208. return $this->addSelect('orderReductionCarts');
  209. }
  210. public function joinOrderProducts(bool $addSelect = false): self
  211. {
  212. if (!$this->isJoinOrderProducts) {
  213. $this->isJoinOrderProducts = true;
  214. $this->leftJoin('.orderProducts', 'orderProducts');
  215. if ($addSelect) {
  216. $this->addSelect('orderProducts');
  217. }
  218. }
  219. return $this;
  220. }
  221. public function joinProduct(bool $addSelect = false): self
  222. {
  223. $this->joinOrderProducts($addSelect);
  224. if (!$this->isJoinProduct) {
  225. $this->isJoinProduct = true;
  226. $this->leftJoin('orderProducts.product', 'product');
  227. if ($addSelect) {
  228. $this->addSelect('product');
  229. }
  230. }
  231. return $this;
  232. }
  233. public function joinDistribution(bool $addSelect = false): self
  234. {
  235. if (!$this->isJoinDistribution) {
  236. $this->isJoinDistribution = true;
  237. $this->leftJoin('.distribution', 'distribution');
  238. if ($addSelect) {
  239. $this->addSelect('distribution');
  240. }
  241. }
  242. return $this;
  243. }
  244. public function joinProductFamily(bool $addSelect = false): self
  245. {
  246. $this->joinProduct($addSelect);
  247. if (!$this->isJoinProductFamily) {
  248. $this->isJoinProductFamily = true;
  249. $this->leftJoin('product.productFamily', 'productFamily');
  250. if ($addSelect) {
  251. $this->addSelect('productFamily');
  252. }
  253. }
  254. return $this;
  255. }
  256. public function joinOrderReductionCredits(): self
  257. {
  258. if (!$this->isJoinOrderReductionCredits) {
  259. $this->isJoinOrderReductionCredits = true;
  260. return $this
  261. ->innerJoin('.orderReductionCredits', 'orderReductionCredits');
  262. }
  263. return $this;
  264. }
  265. public function joinOrderStatus(): self
  266. {
  267. if (!$this->isJoinOrderStatus) {
  268. $this->isJoinOrderStatus = true;
  269. return $this
  270. ->leftJoin('.orderStatus', 'orderStatus');
  271. }
  272. return $this;
  273. }
  274. public function joinOrderReductionCarts(): self
  275. {
  276. if (!$this->isJoinOrderReductionCarts) {
  277. $this->isJoinOrderReductionCarts = true;
  278. return $this
  279. ->leftJoin('.orderReductionCarts', 'orderReductionCarts');
  280. }
  281. return $this;
  282. }
  283. public function joinMerchant(): self
  284. {
  285. $this->joinSection();
  286. if (!$this->isJoinMerchant) {
  287. $this->isJoinMerchant = true;
  288. return $this
  289. ->leftJoin('s.merchant', 'merchant');
  290. }
  291. return $this;
  292. }
  293. public function joinComplementaryOrderShops(): self
  294. {
  295. if (!$this->isJoinComplementaryOrderShops) {
  296. $this->isJoinComplementaryOrderShops = true;
  297. return $this
  298. ->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
  299. }
  300. return $this;
  301. }
  302. public function joinDeliveryPointSale(): self
  303. {
  304. if (!$this->isJoinDeliveryPointSale) {
  305. $this->isJoinDeliveryPointSale = true;
  306. return $this
  307. ->leftJoin('.deliveryPointSale', 'deliveryPointSale');
  308. }
  309. return $this;
  310. }
  311. }