|
- <?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\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 $isJoinOrderProduct = false;
- protected bool $isJoinOrderReductionCredits = false;
- protected bool $isJoinOrderReductionCarts = false;
- protected bool $isJoinOrderStatus = false;
- protected bool $isJoinMerchant = false;
- protected bool $isJoinComplementaryOrderShops = false;
- protected bool $isJoinDeliveryPointSale = false;
-
- public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
- {
- parent::__construct($repository, 'r', $paginator);
- }
-
-
- public function selectSumStatTotalWithTax(): self
- {
- return $this
- ->select(
- 'SUM(DISTINCT(r.statTotalWithTax)) as total'
- );
- }
-
- public function selectSumQuantityOrder(): self
- {
- $this->joinOrderProduct();
- return $this
- ->select(
- 'SUM(orderProduct.quantityOrder) as quantity'
- );
- }
-
-
- public function selectSum(): self
- {
- $this->joinProduct();
- $this->joinDistribution();
- return $this
- ->select(
- 'SUM(orderProduct.quantityOrder) as quantity, distribution.cycleNumber as cycleNumber, distribution.year as year , product.id as productId'
- );
- }
-
-
- public function selectCountUser(): self
- {
- return $this
- ->select('count(DISTINCT(r.user)) as total');
- }
-
-
- // @TODO : nécessaire ?
- public function selectParam($select): self
- {
- return $this
- ->addSelect($select);
- }
-
- public function selectCount(): self
- {
- return $this
- ->select('count(DISTINCT(r.id)) as total');
- }
-
- public function filterByUser(UserInterface $user): self
- {
- return $this
- ->andWhere('.user = :user')
- ->setParameter('user', $user);
- }
-
- public function filterByAlias(array $status): self
- {
- $this->joinOrderStatus();
-
- return $this
- ->andWhere('os.alias IN (:alias)')
- ->setParameter('alias', $status);
- }
-
- public function filterByDistributions(array $distributions): self
- {
- return $this
- ->andWhere('.distribution IN(:distributions)')
- ->setParameter('distributions', $distributions);
- }
-
- public function filterByProducts(array $products): self
- {
- $this->joinOrderProduct();
-
- return $this
- ->andWhere('product.id IN(:products)')
- ->setParameter('products', $products);
- }
-
- public function filterByProduct(ProductInterface $product): self
- {
- $this->joinProduct();
-
- return $this
- ->andWhere('orderProduct.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
- ->andWhere('.visitor = :visitor')
- ->setParameter('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();
-
- return $this
- ->andWhere('os.alias IN (:alias)')
- ->setParameter('alias', $statusArray);
- }
-
- public function filterByReductionCredit(ReductionCreditInterface $reductionCredit): self
- {
- $this->joinOrderReductionCredits();
-
- return $this
- ->andWhere('orc.reductionCredit = :reductionCredit')
- ->setParameter('reductionCredit', $reductionCredit);
- }
-
- public function filterByReductionCart(ReductionCartInterface $reductionCart): self
- {
- $this->joinOrderReductionCarts();
-
- return $this
- ->andWhere('orcart.reductionCart = :reductionCart')
- ->setParameter('reductionCart', $reductionCart);
- }
-
- public function filterByDistribution(DistributionInterface $distribution): self
- {
- return $this
- ->andWhere('.distribution = :distribution')
- ->setParameter('distribution', $distribution);
- }
-
- public function filterIsNotComplementaryOrderShop(): self
- {
- return $this
- ->andWhere('.mainOrderShop = false OR .mainOrderShop IS 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 selectOrderReductionCarts(): self
- {
- $this->joinOrderReductionCarts();
-
- return $this->addSelect('orcart');
- }
-
-
- public function joinOrderProduct(bool $addSelect = false): self
- {
- if (!$this->isJoinOrderProduct) {
- $this->isJoinOrderProduct = true;
-
- $this->innerJoin('.orderProducts', 'orderProduct');
- if ($addSelect) {
- $this->addSelect('orderProduct');
- }
- }
- return $this;
- }
-
- public function joinProduct(bool $addSelect = false): self
- {
- $this->joinOrderProduct($addSelect);
- if (!$this->isJoinProduct) {
- $this->isJoinProduct = true;
-
- $this->leftJoin('orderProduct.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', 'orc');
- }
- return $this;
- }
-
- public function joinOrderStatus(): self
- {
- if (!$this->isJoinOrderStatus) {
- $this->isJoinOrderStatus = true;
-
- return $this
- ->leftJoin('.orderStatus', 'os');
- }
- return $this;
- }
-
- public function joinOrderReductionCarts(): self
- {
- if (!$this->isJoinOrderReductionCarts) {
- $this->isJoinOrderReductionCarts = true;
-
- return $this
- ->leftJoin('.orderReductionCarts', 'orcart');
- }
- 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', 'pointSale');
- }
- return $this;
- }
-
- }
|