Parcourir la source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Fab il y a 3 ans
Parent
révision
0f871736db
3 fichiers modifiés avec 616 ajouts et 16 suppressions
  1. +9
    -0
      Repository/Merchant/MerchantStore.php
  2. +337
    -1
      Repository/Order/OrderShopRepositoryQuery.php
  3. +270
    -15
      Repository/Order/OrderShopStore.php

+ 9
- 0
Repository/Merchant/MerchantStore.php Voir le fichier

@@ -23,4 +23,13 @@ class MerchantStore extends AbstractStore
return $query->findOne();
}

//TODO pas de merchant_configs

// public function findAllWithConfigs()
// {
// $qb = $this->createQueryBuilder('hub');
// $qb->innerJoin('hub.merchantConfigs', 'merchant_configs');
// return $qb->getQuery()->getResult();
// }

}

+ 337
- 1
Repository/Order/OrderShopRepositoryQuery.php Voir le fichier

@@ -2,17 +2,353 @@

namespace Lc\CaracoleBundle\Repository\Order;

use App\Entity\Delivery\DeliveryAvailabilityPointSale;
use App\Entity\Delivery\DeliveryAvailabilityZone;
use App\Entity\PointSale\PointSale;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
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 $isJoinOrderReductionCredits = false;
protected $isJoinOrderReductionCarts = false;
protected $isJoinOrderStatus = false;
protected $isJoinComplementaryOrderShops = false;
protected $isJoinDeliveryPointSale = false;
protected $isJoinDeliveryAvailabilityZone = false;
protected $isJoinDeliverySlotZone = false;
protected $isJoinDeliveryAvailabilityPointSale = false;
protected $isJoinDeliverySlotPointSale = false;
protected $isHorsTournee = false;
protected $isGiftVoucher = false;

public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'r', $paginator);
}

public function selectParam($select): self
{
return $this
->addSelect($select);
}

public function selectCount(): self
{
return $this
->addSelect('count(r.id) as total');
}

public function filterByUser(UserInterface $user): self
{
return $this
->andWhere('.user = :user')
->setParameter('user', $user);
}

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 filterByEstimatedDeliveryDateStart(DateTime $dateStart): self
{
return $this
->andWhere('.estimatedDeliveryDateTime >= :deliveryDateStart')
->setParameter('deliveryDateStart', $dateStart);
}

public function filterByEstimatedDeliveryDateEnd(DateTime $dateEnd): self
{
return $this
->andWhere('.estimatedDeliveryDateTime < :deliveryDateEnd')
->setParameter('deliveryDateEnd', $dateEnd);
}

public function filterByDeliveryDateStart(DateTime $dateStart): self
{
return $this
->andWhere('.deliveryDate >= :deliveryDateStart')
->setParameter('deliveryDateStart', $dateStart);
}

public function filterByDeliveryDateEnd(DateTime $dateEnd): self
{
return $this
->andWhere('.deliveryDate < :deliveryDateEnd')
->setParameter('deliveryDateEnd', $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 filterByWeekDeliveryTruck(string $weekDeliveryTrucks): self
{
return $this
->andWhere('.weekDeliveryTruck IN (:weekDeliveryTrucks)')
->setParameter('weekDeliveryTrucks', $weekDeliveryTrucks);
}

public function filterByStatus(array $statusArray): self
{
$this->joinOrderStatus();

return $this
->andWhere('os.alias IN (:alias)')
->setParameter('alias', $statusArray);
}

public function filterByReductionCredit(OrderReductionCreditInterface $reductionCredit): self
{
$this->joinOrderReductionCredits();

return $this
->andWhere('orc.reductionCredit = :reductionCredit')
->setParameter('reductionCredit', $reductionCredit);
}

public function filterByReductionCart(OrderReductionCartInterface $reductionCart): self
{
$this->joinOrderReductionCarts();

return $this
->andWhere('orcart.reductionCart = :reductionCart')
->setParameter('reductionCart', $reductionCart);
}

public function filterByAvailabilityPointZone(DeliveryAvailabilityZone $deliveryAvailabilityZone): self
{
return $this
->andWhere('.deliveryAvailabilityZone = :deliveryAvailabilityZone')
->setParameter('deliveryAvailabilityZone', $deliveryAvailabilityZone);
}

public function filterByAvailabilityPointSale(DeliveryAvailabilityPointSale $deliveryAvailabilityPointSale): self
{
return $this
->andWhere('.deliveryAvailabilityPointSale = :deliveryAvailabilityPointSale')
->setParameter('deliveryAvailabilityPointSale', $deliveryAvailabilityPointSale);
}

public function filterByWeekNumber(int $weekNumber): self
{
return $this
->andWhere('.weekNumber = :weekNumber')
->setParameter('weekNumber', $weekNumber);
}

public function filterIsNotMainOrderShop(): self
{
return $this
->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
}

public function filterIsNullMainOrderShop(): self
{
return $this
->andWhere('.mainOrderShop IS NULL');
}

public function filterIsNullDeliveryPointSale(): self
{
$this
->joinDeliveryPointSale()
->andWhere(
'.deliveryPointSale IS NULL OR (pointSale.isDepository = 0 AND (pointSale.devAlias IS NULL OR (pointSale.devAlias != :devAliasHorsTournee AND pointSale.devAlias != :devAliasGiftVoucher)))'
)
->setParameterGiftVoucher()
->setParameterHorsTournee();

return $this;
}

public function filterIsNotNullDeliveryPointSale(): self
{
$this
->joinDeliveryPointSale()
->andWhere(
'pointSale IS NOT NULL AND pointSale.isDepository = 1 AND (pointSale.devAlias IS NULL OR (pointSale.devAlias != :devAliasHorsTournee AND pointSale.devAlias != :devAliasGiftVoucher))'
)
->setParameterGiftVoucher()
->setParameterHorsTournee();

return $this;
}


public function filterIsPointSale(string $devAlias = 'devAliasHorsTournee'): self
{
$this
->joinDeliveryPointSale()
->andWhere('pointSale IS NOT NULL AND pointSale.devAlias = :' . $devAlias);

if($devAlias == 'devAliasHorsTournee'){
$this->setParameterHorsTournee();
} elseif($devAlias == 'devAliasGiftVoucher') {
$this->setParameterGiftVoucher();
}

return $this;
}

public function selectOrderReductionCarts(): self
{
$this->joinOrderReductionCarts();

return $this->addSelect('orcart');
}

public function setParameterGiftVoucher(): self
{
if (!$this->isGiftVoucher) {
$this->isGiftVoucher = true;

return $this
->setParameter('devAliasGiftVoucher', PointSale::DEV_ALIAS_GIFT_VOUCHER);
}
return $this;
}

public function setParameterHorsTournee(): self
{
if (!$this->isHorsTournee) {
$this->isHorsTournee = true;

return $this
->setParameter('devAliasHorsTournee', PointSale::DEV_ALIAS_OFF_CIRCUIT);
}
return $this;
}

public function joinOrderReductionCredits(): self
{
if (!$this->isJoinOrderReductionCredits) {
$this->isJoinOrderReductionCredits = true;

return $this
->innerJoin('.orderReductionCredits', 'orc');
}
return $this;
}

public function joinDeliveryAvailabilityZone(): self
{
if (!$this->isJoinDeliveryAvailabilityZone) {
$this->isJoinDeliveryAvailabilityZone = true;

return $this
->leftJoin('.deliveryAvailabilityZone', 'deliveryAvailabilityZone');
}
return $this;
}

public function joinDeliverySlotZone(): self
{
$this->joinDeliveryAvailabilityZone();

if (!$this->isJoinDeliverySlotZone) {
$this->isJoinDeliverySlotZone = true;

return $this
->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone');
}
return $this;
}

public function joinDeliveryAvailabilityPointSale(): self
{
if (!$this->isJoinDeliveryAvailabilityPointSale) {
$this->isJoinDeliveryAvailabilityPointSale = true;

return $this
->leftJoin('.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale');
}
return $this;
}

public function joinDeliverySlotPointSale(): self
{
$this->joinDeliveryAvailabilityZone();

if (!$this->isJoinDeliverySlotPointSale) {
$this->isJoinDeliverySlotPointSale = true;

return $this
->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale');
}
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 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;
}
}

+ 270
- 15
Repository/Order/OrderShopStore.php Voir le fichier

@@ -2,26 +2,33 @@

namespace Lc\CaracoleBundle\Repository\Order;

use App\Entity\Order\OrderStatus;
use Lc\CaracoleBundle\Builder\File\DocumentBuilder;
use Lc\CaracoleBundle\Factory\File\DocumentFactory;
use Lc\CaracoleBundle\Model\File\DocumentModel;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\CaracoleBundle\Resolver\Reference\DocumentReferenceResolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;

class OrderShopStore extends AbstractStore
{
use SectionStoreTrait;

protected OrderShopRepositoryQuery $query;
protected PriceResolver $priceResolver;
protected DocumentReferenceResolver $documentReferenceResolver;
protected DocumentBuilder $documentBuilder;

public function __construct(
OrderShopRepositoryQuery $query,
PriceResolver $priceResolver,
DocumentReferenceResolver $documentReferenceResolver,
DocumentBuilder $documentBuilder
OrderShopRepositoryQuery $query,
PriceResolver $priceResolver,
DocumentReferenceResolver $documentReferenceResolver,
DocumentBuilder $documentBuilder
) {
$this->query = $query;
$this->priceResolver = $priceResolver;
@@ -70,11 +77,11 @@ class OrderShopStore extends AbstractStore
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct);
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct);
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction(
$orderProduct
$orderProduct
);
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction(
array($orderProduct)
array($orderProduct)
);
$i++;
}
@@ -91,14 +98,14 @@ class OrderShopStore extends AbstractStore
$productFamily = $orderProduct->getProduct()->getProductFamily();
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
$orderProductsByProductFamily[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
'order_products' => [],
'total_quantity_weight' => 0,
];
}
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
$orderProductsByProductFamily[$productFamily->getId(
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
)->getCoefficient()) * $orderProduct->getQuantityOrder();
)->getCoefficient()) * $orderProduct->getQuantityOrder();
}
}

@@ -117,8 +124,8 @@ class OrderShopStore extends AbstractStore
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop);

if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true;
} else {
return false;
@@ -157,10 +164,10 @@ class OrderShopStore extends AbstractStore
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
if ($newOrderShop === null) {
$newOrderShop = $this->createOrderShop(
array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
)
array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
)
);
}

@@ -224,4 +231,252 @@ class OrderShopStore extends AbstractStore

return $orderShop;
}*/


public function countValidOrderWithReductionCredit(
OrderReductionCreditInterface $reductionCredit,
UserInterface $user = null
): string {
$query = $this->query->create();

if ($user) {
$query->filterByUser($user);
}
$query
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

return $query->count();
}

public function countValidOrderWithReductionCart(OrderReductionCartInterface $reductionCart): string
{
$query = $this->query->create();

$query
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

return $query->count();
}

public function countValidOrderWithReductionCartPerUser(
OrderReductionCartInterface $reductionCart,
UserInterface $user
): string {
$query = $this->query->create();

$query
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

return $query->count();
}

//findCartCurrent
public function getCartCurrent(array $params): ?OrderShopInterface
{
$query = $this->query->create();

if (isset($params['user'])) {
$query
->filterByUser($params['user']);
}
if (isset($params['visitor'])) {
$query
->filterByVisitor($params['visitor']);
}

$query
->selectOrderReductionCarts()
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

$results = $query->find();

if ($results) {
return $results[0];
}

return null;
}

//findLastOrderValidOfWeek
public function getOneLastOrderValidOfWeek(int $weekNumber): ?OrderShopInterface
{
$query = $this->query->create();

$query
->filterByWeekNumber($weekNumber)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.weekId', 'DESC')
->filterBySection($this->section);

return $query->findOne();
}

//findLastOrderValid
public function getOneLastOrderValid(): ?OrderShopInterface
{
$query = $this->query->create();

$query
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.idValidOrder', 'DESC')
->filterBySection($this->section);

return $query->findOne();
}

//TODO Fonction à tester

// findAllBy
public function getAllBy(array $params = [])
{
$query = $this->query->create();

if (isset($params['section'])) {
$query->filterBySection($params['section']);
} else {
$query->filterBySection($this->section);
}

if (isset($params['count']) && $params['count']) {
$query->selectCount();
}

if (isset($params['select'])) {
$query->selectParam($params['select']);
}

if (isset($params['dateStart']) || isset($params['dateEnd'])) {
$params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate';
}

if (isset($params['dateStart'])) {
$query->filterByDateStart($params['dateField'], $params['dateStart']);
}

if (isset($params['dateEnd'])) {
$query->filterByDateEnd($params['dateField'], $params['dateEnd']);
}

if (isset($params['weekNumber'])) {
$query->filterByWeekNumber($params['weekNumber']);
}

if (isset($params['isCart'])) {
$query->filterByStatus(OrderStatus::$statusAliasAsCart);
}

if (isset($params['isValid'])) {
$query->filterByStatus(OrderStatus::$statusAliasAsValid);
}

if (isset($params['isWaitingDelivery'])) {
$query->filterByStatus(OrderStatus::$statusAliasWaitingDelivery);
}

if (isset($params['orderStatus'])) {
$query->filterByStatus($params['orderStatus']);
}

if (isset($params['user'])) {
$query->filterByUser($params['user']);
}

if (isset($params['address'])) {
$query->filterByAddress($params['address']);
}

if (isset($params['weekDeliveryTrucks'])) {
$query->filterByWeekDeliveryTruck($params['weekDeliveryTrucks']);
}

if (isset($params['estimatedDeliveryDateTime'])) {
$date = clone $params['estimatedDeliveryDateTime'];
$query
->filterByEstimatedDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByEstimatedDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
}


if (isset($params['deliveryDate'])) {
$date = clone $params['deliveryDate'];
$query
->filterByDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
}

if (isset($params['mergeComplementaryOrderShops'])) {
//TODO jointure peut être pas utile
$query
->joinComplementaryOrderShops();
}

if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) {
$query->filterIsNullMainOrderShop();
}

if (isset($params['isCircuit'])) {
$query->filterIsNullDeliveryPointSale();
}

if (isset($params['isDepository'])) {
$query->filterIsNotNullDeliveryPointSale();
}

if (isset($params['isOffCircuit'])) {
$query->filterIsPointSale('devAliasHorsTournee');
}

if (isset($params['isGiftVoucher'])) {
$query->filterIsPointSale('devAliasGiftVoucher');
}

if (isset($params['deliveryAvailability'])) {
$deliveryAvailability = $params['deliveryAvailability'];
$deliveryAvailabilityZone = ($deliveryAvailability instanceof DeliveryAvailabilityZone) ? $deliveryAvailability : false;
$deliveryAvailabilityPointSale = ($deliveryAvailability instanceof DeliveryAvailabilityPointSale) ? $deliveryAvailability : false;

if ($deliveryAvailabilityZone) {
$query->filterByAvailabilityPointZone($deliveryAvailabilityZone);
}

if ($deliveryAvailabilityPointSale) {
$query->filterByAvailabilityPointZone($deliveryAvailabilityPointSale);
}
} else {
$query->joinDeliverySlotZone();
$query->joinDeliverySlotPointSale();
}

if (isset($params['orderBy'])) {
$query->orderBy(
$params['orderBy'],
isset($params['orderByDirection']) ? $params['orderByDirection'] : 'DESC'
);
} else {
$query->orderBy('.id', 'DESC');
}

if (isset($params['groupBy'])) {
$query->groupBy($params['groupBy']);
}

if (isset($params['count']) && $params['count']) {
return $query->count();
}

return $query->find();
}
}

Chargement…
Annuler
Enregistrer