|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- <?php
-
- namespace Lc\CaracoleBundle\Repository\Order;
-
- use Knp\Component\Pager\PaginatorInterface;
- use Lc\CaracoleBundle\Model\Address\AddressInterface;
- use Lc\CaracoleBundle\Model\Distribution\DistributionInterface;
- use Lc\CaracoleBundle\Model\Order\OrderPaymentInterface;
- use Lc\CaracoleBundle\Model\Product\ProductInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
- use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
- use Lc\CaracoleBundle\Model\User\VisitorInterface;
- use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Repository\AbstractRepositoryQuery;
- use DateTime;
-
- class OrderShopRepositoryQuery extends AbstractRepositoryQuery
- {
- use SectionRepositoryQueryTrait;
-
- protected bool $isJoinProduct = false;
- protected bool $isJoinDistribution = false;
- protected bool $isJoinProductFamily = false;
- protected bool $isJoinOrderProducts = false;
- protected bool $isJoinOrderReductionCredits = false;
- protected bool $isJoinOrderReductionCarts = false;
- protected bool $isJoinOrderStatus = false;
- protected bool $isJoinMerchant = false;
- protected bool $isJoinUser = false;
- protected bool $isJoinComplementaryOrderShops = false;
- protected bool $isJoinDeliveryPointSale = false;
- protected bool $isJoinOrderPayment = false;
- protected bool $isFilteredByStatus = false;
-
- public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'orderShop', $paginator);
- }
-
- public function selectSumStatTotalWithTax(): self
- {
- return $this
- ->select(
- 'SUM(DISTINCT(orderShop.statTotalWithTax)) as total'
- );
- }
-
- public function selectSumQuantityOrder(): self
- {
- $this->joinOrderProducts();
- return $this
- ->select(
- 'SUM(orderProducts.quantityOrder) as quantity'
- );
- }
-
- public function selectSum(): self
- {
- $this->joinProduct();
- $this->joinDistribution();
- return $this
- ->select(
- 'SUM(orderProducts.quantityOrder) as quantity, distribution.cycleNumber as cycleNumber, distribution.year as year , product.id as productId'
- );
- }
-
-
- public function selectCountUser(): self
- {
- return $this
- ->select('count(DISTINCT(orderShop.user)) as total');
- }
-
-
- // @TODO : nécessaire ?
- public function selectParam($select): self
- {
- return $this
- ->addSelect($select);
- }
-
- public function selectCount(): self
- {
- return $this
- ->select('count(DISTINCT(orderShop.id)) as total');
- }
-
- public function joinUser(): self
- {
- if (!$this->isJoinUser) {
- $this->isJoinUser = true;
-
- return $this
- ->leftJoin('.user', 'user');
- }
- return $this;
- }
-
- public function filterByUser(UserInterface $user): self
- {
- return $this
- ->andWhere('.user = :user')
- ->setParameter('user', $user);
- }
-
- public function filterByUserEmail(string $email): self
- {
- $this->joinUser();
- return $this
- ->andWhere('user.email LIKE :email')
- ->setParameter('email', $email);
- }
-
- public function filterByUserLastname(string $lastname): self
- {
- $this->joinUser();
- return $this
- ->andWhere('user.lastname LIKE :lastname')
- ->setParameter('lastname', $lastname);
- }
-
-
- public function filterByUserFirstname(string $firstname): self
- {
- $this->joinUser();
- return $this
- ->andWhere('user.firstname LIKE :firstname')
- ->setParameter('firstname', $firstname);
- }
-
- public function filterByAlias(array $status): self
- {
- $this->joinOrderStatus();
-
- return $this
- ->andWhere('orderStatus.alias IN (:alias)')
- ->setParameter('alias', $status);
- }
-
- public function filterByDistributionData(string $cycleType, int $cycleNumber, int $year){
- $this->joinDistribution();
-
- return $this
- ->andWhere('distribution.cycleType LIKE :cycleType')
- ->andWhere('distribution.cycleNumber LIKE :cycleNumber')
- ->andWhere('distribution.year LIKE :year')
- ->setParameter('cycleType', $cycleType)
- ->setParameter('cycleNumber', $cycleNumber)
- ->setParameter('year', $year);
- }
-
- public function filterByDistributions(array $distributionArray): self
- {
- return $this
- ->andWhere('.distribution IN (:distributions)')
- ->setParameter('distributions', $distributionArray);
- }
-
- public function filterByProducts(array $products): self
- {
- $this->joinOrderProducts();
-
- return $this
- ->andWhere('product.id IN(:products)')
- ->setParameter('products', $products);
- }
-
- public function filterByProduct(ProductInterface $product): self
- {
- $this->joinProduct();
-
- return $this
- ->andWhere('orderProducts.product = :product')
- ->setParameter('product', $product);
- }
-
- public function filterIsMerchantOnline(): self
- {
- $this->joinMerchant();
- return $this
- ->andWhere('merchant.status = :status')
- ->setParameter(':status', 1);
- }
-
- public function filterByDateStart(string $dateField, DateTime $dateStart): self
- {
- return $this
- ->andWhere('.' . $dateField . ' >= :dateStart')
- ->setParameter('dateStart', $dateStart);
- }
-
- public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
- {
- return $this
- ->andWhere('.' . $dateField . ' <= :dateEnd')
- ->setParameter('dateEnd', $dateEnd);
- }
-
- public function filterByVisitor(VisitorInterface $visitor): self
- {
- return $this->andWhereEqual('visitor', $visitor);
- }
-
- public function filterByAddress(AddressInterface $address): self
- {
- return $this
- ->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
- ->setParameter('address', $address);
- }
-
- public function filterByStatus(array $statusArray): self
- {
- $this->joinOrderStatus();
- // TODO: Voir pour faire mieux
- // On fait qu'une seule fois le filtre
- if (!$this->isFilteredByStatus) {
- $this->isFilteredByStatus = true;
- return $this
- ->andWhere('orderStatus.alias IN (:alias)')
- ->setParameter('alias', $statusArray);
- }
-
- return $this;
- }
-
- public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
- {
- $this->joinOrderReductionCredits();
-
- return $this
- ->andWhere('orderReductionCredits.reductionCredit = :reductionCredit')
- ->setParameter('reductionCredit', $reductionCredit);
- }
-
- public function filterByReductionCart(ReductionCartInterface $reductionCart): self
- {
- $this->joinOrderReductionCarts();
-
- return $this
- ->andWhere('orderReductionCarts.reductionCart = :reductionCart')
- ->setParameter('reductionCart', $reductionCart);
- }
-
- public function filterByDistribution(DistributionInterface $distribution): self
- {
- return $this
- ->andWhere('.distribution = :distribution')
- ->setParameter('distribution', $distribution);
- }
-
- public function filterByMeanPayment(string $meanPayment): self
- {
- $this->joinOrderPayment();
-
- return $this
- ->andWhere('orderPayments.meanPayment = :meanPayment')
- ->setParameter('meanPayment', $meanPayment);
- }
-
- public function filterByDeliveryType(string $deliveryType): self
- {
- return $this
- ->andWhere('.deliveryType = :deliveryType')
- ->setParameter('deliveryType', $deliveryType);
- }
-
- public function filterIsNotComplementaryOrderShop(): self
- {
- return $this
- ->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
- }
-
- public function filterIsComplementaryOrderShop(): self
- {
- return $this
- ->andWhere('.mainOrderShop = true OR .mainOrderShop IS NOT NULL');
- }
-
- public function filterIsNullMainOrderShop(): self
- {
- return $this
- ->andWhere('.mainOrderShop IS NULL');
- }
-
- public function filterMinimumTomorrowDelivery(): self
- {
- return $this->andWhere('.deliveryDate > :today')->setParameter('today', (new DateTime())->setTime(23, 59));
- }
-
- public function filterHasOrderProducts()
- {
- return $this->andWhere('orderShop.orderProducts IS NOT EMPTY');
- }
-
- public function selectOrderReductionCarts(): self
- {
- $this->joinOrderReductionCarts();
-
- return $this->addSelect('orderReductionCarts');
- }
-
- public function joinOrderProducts(bool $addSelect = false): self
- {
- if (!$this->isJoinOrderProducts) {
- $this->isJoinOrderProducts = true;
-
- $this->leftJoin('.orderProducts', 'orderProducts');
-
- if ($addSelect) {
- $this->addSelect('orderProducts');
- }
- }
- return $this;
- }
-
- public function joinProduct(bool $addSelect = false): self
- {
- $this->joinOrderProducts($addSelect);
- if (!$this->isJoinProduct) {
- $this->isJoinProduct = true;
-
- $this->leftJoin('orderProducts.product', 'product');
-
- if ($addSelect) {
- $this->addSelect('product');
- }
- }
- return $this;
- }
-
- public function joinDistribution(bool $addSelect = false): self
- {
- if (!$this->isJoinDistribution) {
- $this->isJoinDistribution = true;
-
- $this->leftJoin('.distribution', 'distribution');
-
- if ($addSelect) {
- $this->addSelect('distribution');
- }
- }
- return $this;
- }
-
- public function joinProductFamily(bool $addSelect = false): self
- {
- $this->joinProduct($addSelect);
- if (!$this->isJoinProductFamily) {
- $this->isJoinProductFamily = true;
-
- $this->leftJoin('product.productFamily', 'productFamily');
- if ($addSelect) {
- $this->addSelect('productFamily');
- }
- }
- return $this;
- }
-
- public function joinOrderReductionCredits(): self
- {
- if (!$this->isJoinOrderReductionCredits) {
- $this->isJoinOrderReductionCredits = true;
-
- return $this
- ->innerJoin('.orderReductionCredits', 'orderReductionCredits');
- }
- return $this;
- }
-
- public function joinOrderStatus(): self
- {
- if (!$this->isJoinOrderStatus) {
- $this->isJoinOrderStatus = true;
-
- return $this
- ->leftJoin('.orderStatus', 'orderStatus');
- }
- return $this;
- }
-
- public function joinOrderReductionCarts(): self
- {
- if (!$this->isJoinOrderReductionCarts) {
- $this->isJoinOrderReductionCarts = true;
-
- return $this
- ->leftJoin('.orderReductionCarts', 'orderReductionCarts');
- }
- return $this;
- }
-
- public function joinMerchant(): self
- {
- $this->joinSection();
- if (!$this->isJoinMerchant) {
- $this->isJoinMerchant = true;
-
- return $this
- ->leftJoin('s.merchant', 'merchant');
- }
- return $this;
- }
-
- public function joinComplementaryOrderShops(): self
- {
- if (!$this->isJoinComplementaryOrderShops) {
- $this->isJoinComplementaryOrderShops = true;
-
- return $this
- ->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
- }
- return $this;
- }
-
- public function joinDeliveryPointSale(): self
- {
- if (!$this->isJoinDeliveryPointSale) {
- $this->isJoinDeliveryPointSale = true;
-
- return $this
- ->leftJoin('.deliveryPointSale', 'deliveryPointSale');
- }
- return $this;
- }
-
- public function joinOrderPayment(): self
- {
- if (!$this->isJoinOrderPayment) {
- $this->isJoinOrderPayment = true;
-
- return $this
- ->leftJoin('.orderPayments', 'orderPayments');
- }
- return $this;
- }
-
- }
|