<?php | |||||
namespace Lc\CaracoleBundle\Builder\Distribution; | |||||
class DistributionBuilder | |||||
{ | |||||
} |
namespace Lc\CaracoleBundle\Builder\Order; | namespace Lc\CaracoleBundle\Builder\Order; | ||||
use App\Builder\Distribution\DistributionBuilder; | |||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | ||||
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; | use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; | ||||
protected ProductSolver $productSolver; | protected ProductSolver $productSolver; | ||||
protected OrderShopResolver $orderShopResolver; | protected OrderShopResolver $orderShopResolver; | ||||
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver; | protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver; | ||||
protected DistributionBuilder $distributionBuilder; | |||||
public function __construct( | public function __construct( | ||||
EntityManagerInterface $entityManager, | EntityManagerInterface $entityManager, | ||||
OpeningResolver $openingResolver, | OpeningResolver $openingResolver, | ||||
ProductSolver $productSolver, | ProductSolver $productSolver, | ||||
OrderShopResolver $orderShopResolver, | OrderShopResolver $orderShopResolver, | ||||
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver | |||||
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver, | |||||
DistributionBuilder $distributionBuilder | |||||
) { | ) { | ||||
$this->entityManager = $entityManager; | $this->entityManager = $entityManager; | ||||
$this->orderShopStore = $orderShopStore; | $this->orderShopStore = $orderShopStore; | ||||
$this->productSolver = $productSolver; | $this->productSolver = $productSolver; | ||||
$this->orderShopResolver = $orderShopResolver; | $this->orderShopResolver = $orderShopResolver; | ||||
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver; | $this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver; | ||||
$this->distributionBuilder = $distributionBuilder; | |||||
} | } | ||||
public function create( | public function create( | ||||
} | } | ||||
} | } | ||||
public function initCycleNumber(OrderShopInterface $orderShop): void | |||||
//initCycleNumber | |||||
public function initDistribution(OrderShopInterface $orderShop): void | |||||
{ | { | ||||
$cycleNumber = null; | |||||
$deliveryDate = $orderShop->getDeliveryDate(); | |||||
switch ($orderShop->getSection()->getCycleType()) { | |||||
case SectionModel::CYCLE_TYPE_DAY: | |||||
$cycleNumber = $deliveryDate->format('z'); | |||||
break; | |||||
case SectionModel::CYCLE_TYPE_WEEK: | |||||
$cycleNumber = $deliveryDate->format('W'); | |||||
break; | |||||
} | |||||
$orderShop->setCycleNumber($cycleNumber); | |||||
$distribution = $this->distributionBuilder->guessDistributionByDeliveryDate( | |||||
$orderShop->getDeliveryDate(), | |||||
$orderShop->getSection() | |||||
); | |||||
$orderShop->setDistribution($distribution); | |||||
} | } | ||||
<?php | |||||
namespace Lc\CaracoleBundle\Container\Distribution; | |||||
use Lc\CaracoleBundle\Builder\Distribution\DistributionBuilder; | |||||
use Lc\CaracoleBundle\Factory\Distribution\DistributionFactory; | |||||
use Lc\CaracoleBundle\Repository\Distribution\DistributionRepositoryQuery; | |||||
use Lc\CaracoleBundle\Repository\Distribution\DistributionStore; | |||||
use Lc\CaracoleBundle\Solver\Distribution\DistributionSolver; | |||||
class DistributionContainer | |||||
{ | |||||
protected DistributionFactory $factory; | |||||
protected DistributionRepositoryQuery $repositoryQuery; | |||||
protected DistributionStore $store; | |||||
protected DistributionBuilder $builder; | |||||
protected DistributionSolver $solver; | |||||
public function __construct( | |||||
DistributionFactory $factory, | |||||
DistributionRepositoryQuery $repositoryQuery, | |||||
DistributionStore $store, | |||||
DistributionBuilder $builder, | |||||
DistributionSolver $solver | |||||
) { | |||||
$this->factory = $factory; | |||||
$this->repositoryQuery = $repositoryQuery; | |||||
$this->store = $store; | |||||
$this->solver = $solver; | |||||
$this->builder = $builder; | |||||
} | |||||
public function getFactory(): DistributionFactory | |||||
{ | |||||
return $this->factory; | |||||
} | |||||
public function getRepositoryQuery(): DistributionRepositoryQuery | |||||
{ | |||||
return $this->repositoryQuery; | |||||
} | |||||
public function getStore(): DistributionStore | |||||
{ | |||||
return $this->store; | |||||
} | |||||
public function getSolver(): DistributionSolver | |||||
{ | |||||
return $this->solver; | |||||
} | |||||
public function getBuilder(): DistributionBuilder | |||||
{ | |||||
return $this->builder; | |||||
} | |||||
} |
'createdAt' => DateTimeField::new('createdAt')->setSortable(true), | 'createdAt' => DateTimeField::new('createdAt')->setSortable(true), | ||||
'updatedAt' => DateTimeField::new('updatedAt')->setSortable(true), | 'updatedAt' => DateTimeField::new('updatedAt')->setSortable(true), | ||||
'orderShopCreatedAt' => DateTimeField::new('orderShopCreatedAt')->setSortable(true), | 'orderShopCreatedAt' => DateTimeField::new('orderShopCreatedAt')->setSortable(true), | ||||
'cycleNumber' => IntegerField::new('cycleNumber')->setSortable(true), | |||||
'distribution' => AssociationField::new('distribution')->setSortable(true), | |||||
'cycleDeliveryId' => IntegerField::new('cycleDeliveryId')->setSortable(true), | 'cycleDeliveryId' => IntegerField::new('cycleDeliveryId')->setSortable(true), | ||||
'cycleId' => IntegerField::new('cycleId')->setSortable(true), | 'cycleId' => IntegerField::new('cycleId')->setSortable(true), | ||||
'deliveryType' => Field::new('deliveryType')->setSortable(true), | 'deliveryType' => Field::new('deliveryType')->setSortable(true), | ||||
]; | ]; | ||||
} | } | ||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Factory\Distribution; | |||||
use App\Entity\Distribution\Distribution; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\SovBundle\Factory\AbstractFactory; | |||||
class DistributionFactory extends AbstractFactory | |||||
{ | |||||
public function create(int $cycleNumber, int $year, SectionInterface $section):Distribution | |||||
{ | |||||
$distribution = new Distribution(); | |||||
$distribution->setSection($section); | |||||
$distribution->setCycleNumber($cycleNumber); | |||||
$distribution->setYear($year); | |||||
return $distribution; | |||||
} | |||||
} |
$this->settingSolver = $settingSolver; | $this->settingSolver = $settingSolver; | ||||
} | } | ||||
public function buildReference(OrderShopInterface $orderShop, \DateTimeInterface $distributionDate = null): string | |||||
public function buildReference(OrderShopInterface $orderShop): string | |||||
{ | { | ||||
switch ($orderShop->getSection()->getCycleType()) { | switch ($orderShop->getSection()->getCycleType()) { | ||||
case SectionModel::CYCLE_TYPE_DAY: | case SectionModel::CYCLE_TYPE_DAY: | ||||
return $this->buildReferenceCycleDay($orderShop); | return $this->buildReferenceCycleDay($orderShop); | ||||
case SectionModel::CYCLE_TYPE_WEEK: | case SectionModel::CYCLE_TYPE_WEEK: | ||||
return $this->buildReferenceCycleWeek($orderShop, $distributionDate); | |||||
return $this->buildReferenceCycleWeek($orderShop); | |||||
case SectionModel::CYCLE_TYPE_MONTH: | case SectionModel::CYCLE_TYPE_MONTH: | ||||
return $this->buildReferenceCycleMonth($orderShop, $distributionDate); | |||||
return $this->buildReferenceCycleMonth($orderShop); | |||||
case SectionModel::CYCLE_TYPE_YEAR: | case SectionModel::CYCLE_TYPE_YEAR: | ||||
return $this->buildReferenceCycleYear($orderShop, $distributionDate); | |||||
return $this->buildReferenceCycleYear($orderShop); | |||||
} | } | ||||
return 'C' . $orderShop->getId(); | return 'C' . $orderShop->getId(); | ||||
'C' . $this->numberPad($orderShop->getCycleId(), 3); | 'C' . $this->numberPad($orderShop->getCycleId(), 3); | ||||
} | } | ||||
public function buildReferenceCycleWeek(OrderShopInterface $orderShop, \DateTimeInterface $distributionDate): string | |||||
public function buildReferenceCycleWeek(OrderShopInterface $orderShop): string | |||||
{ | { | ||||
return $this->getPrefixReference($orderShop) . | return $this->getPrefixReference($orderShop) . | ||||
'S' . $distributionDate->format('W') . | |||||
'S' . $orderShop->getDistribution()->getCycleNumber() . | |||||
'C' . $this->numberPad($orderShop->getCycleId(), 4) . | 'C' . $this->numberPad($orderShop->getCycleId(), 4) . | ||||
'A' . $distributionDate->format('y'); | |||||
'A' . $this->formatYear($orderShop->getDistribution()->getYear()); | |||||
} | } | ||||
public function buildReferenceCycleMonth( | |||||
OrderShopInterface $orderShop, | |||||
\DateTimeInterface $distributionDate | |||||
): string { | |||||
public function buildReferenceCycleMonth(OrderShopInterface $orderShop): string { | |||||
return $this->getPrefixReference($orderShop) . | return $this->getPrefixReference($orderShop) . | ||||
'M' . $distributionDate->format('m') . | |||||
'M' . $orderShop->getDistribution()->getCycleNumber() . | |||||
'C' . $this->numberPad($orderShop->getCycleId(), 4) . | 'C' . $this->numberPad($orderShop->getCycleId(), 4) . | ||||
'A' . $distributionDate->format('y'); | |||||
'A' . $this->formatYear($orderShop->getDistribution()->getYear()); | |||||
} | } | ||||
public function buildReferenceCycleYear(OrderShopInterface $orderShop, \DateTimeInterface $distributionDate): string | |||||
public function buildReferenceCycleYear(OrderShopInterface $orderShop): string | |||||
{ | { | ||||
return $this->getPrefixReference($orderShop) . | return $this->getPrefixReference($orderShop) . | ||||
'C' . $this->numberPad($orderShop->getCycleId(), 5) . | 'C' . $this->numberPad($orderShop->getCycleId(), 5) . | ||||
'A' . $distributionDate->format('y'); | |||||
'A' . $this->formatYear($orderShop->getDistribution()->getYear()); | |||||
} | } | ||||
public function getPrefixReference(OrderShopInterface $orderShop): string | public function getPrefixReference(OrderShopInterface $orderShop): string | ||||
); | ); | ||||
} | } | ||||
public function numberPad($number, $length): string | |||||
protected function numberPad($number, $length): string | |||||
{ | { | ||||
return str_pad($number, $length, "0", STR_PAD_LEFT); | return str_pad($number, $length, "0", STR_PAD_LEFT); | ||||
} | } | ||||
protected function formatYear(int $year):int{ | |||||
return substr($year, -2); | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Model\Distribution; | |||||
interface DistributionInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Model\Distribution; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
use Lc\CaracoleBundle\Doctrine\Extension\PayoffTrait; | |||||
use Lc\CaracoleBundle\Model\Order\OrderPaymentInterface; | |||||
use Lc\CaracoleBundle\Model\Order\OrderRefundInterface; | |||||
use Lc\CaracoleBundle\Doctrine\Extension\PayoffInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||||
use Gedmo\Mapping\Annotation as Gedmo; | |||||
use Lc\SovBundle\Doctrine\EntityInterface; | |||||
use Lc\SovBundle\Doctrine\Extension\BlameableNullableTrait; | |||||
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | |||||
/** | |||||
* @ORM\MappedSuperclass() | |||||
*/ | |||||
abstract class DistributionModel implements DistributionInterface, EntityInterface | |||||
{ | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $section; | |||||
/** | |||||
* @ORM\Column(type="integer") | |||||
*/ | |||||
protected $cycleNumber; | |||||
/** | |||||
* @ORM\Column(type="integer") | |||||
*/ | |||||
protected $year; | |||||
public function getSection(): ?SectionInterface | |||||
{ | |||||
return $this->section; | |||||
} | |||||
public function setSection(?SectionInterface $section): self | |||||
{ | |||||
$this->section = $section; | |||||
return $this; | |||||
} | |||||
public function getCycleNumber(): ?int | |||||
{ | |||||
return $this->cycleNumber; | |||||
} | |||||
public function setCycleNumber(int $cycleNumber): self | |||||
{ | |||||
$this->cycleNumber = $cycleNumber; | |||||
return $this; | |||||
} | |||||
public function getYear(): ?int | |||||
{ | |||||
return $this->year; | |||||
} | |||||
public function setYear(int $year): self | |||||
{ | |||||
$this->year = $year; | |||||
return $this; | |||||
} | |||||
} |
public function setCycleId(?int $cycleId): OrderShopModel; | public function setCycleId(?int $cycleId): OrderShopModel; | ||||
public function getCycleNumber(): ?int; | |||||
public function setCycleNumber(?int $cycleNumber): OrderShopModel; | |||||
public function getOrderShopCreatedAt(): ?\DateTimeInterface; | public function getOrderShopCreatedAt(): ?\DateTimeInterface; | ||||
public function setOrderShopCreatedAt(?\DateTimeInterface $orderShopCreatedAt | public function setOrderShopCreatedAt(?\DateTimeInterface $orderShopCreatedAt | ||||
public function setStatDeliveryPriceWithTaxAndReduction(?float $statDeliveryPriceWithTaxAndReduction | public function setStatDeliveryPriceWithTaxAndReduction(?float $statDeliveryPriceWithTaxAndReduction | ||||
): OrderShopModel; | ): OrderShopModel; | ||||
} | |||||
} |
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface; | use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface; | ||||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | use Lc\CaracoleBundle\Model\Address\AddressInterface; | ||||
use Lc\CaracoleBundle\Model\Config\TaxRateInterface; | use Lc\CaracoleBundle\Model\Config\TaxRateInterface; | ||||
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface; | |||||
use Lc\CaracoleBundle\Model\File\DocumentInterface; | use Lc\CaracoleBundle\Model\File\DocumentInterface; | ||||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | ||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | use Lc\CaracoleBundle\Model\Section\SectionInterface; | ||||
protected $cycleId; | protected $cycleId; | ||||
/** | /** | ||||
* @ORM\Column(type="integer", nullable=true) | |||||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Distribution\DistributionInterface") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | */ | ||||
protected $cycleNumber; | |||||
protected $distribution; | |||||
/** | /** | ||||
* @ORM\Column(type="datetime", nullable=true) | * @ORM\Column(type="datetime", nullable=true) | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getCycleNumber(): ?int | |||||
public function getDistribution(): ?DistributionInterface | |||||
{ | { | ||||
return $this->cycleNumber; | |||||
return $this->distribution; | |||||
} | } | ||||
public function setCycleNumber(?int $cycleNumber): self | |||||
public function setDistribution(?DistributionInterface $distribution): self | |||||
{ | { | ||||
$this->cycleNumber = $cycleNumber; | |||||
$this->distribution = $distribution; | |||||
return $this; | return $this; | ||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Distribution; | |||||
use App\Entity\Distribution\Distribution; | |||||
use Doctrine\Persistence\ManagerRegistry; | |||||
use Lc\SovBundle\Repository\AbstractRepository; | |||||
class DistributionRepository extends AbstractRepository | |||||
{ | |||||
public function __construct(ManagerRegistry $registry) | |||||
{ | |||||
parent::__construct($registry, Distribution::class); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Distribution; | |||||
use Knp\Component\Pager\PaginatorInterface; | |||||
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
class DistributionRepositoryQuery extends AbstractRepositoryQuery | |||||
{ | |||||
use SectionRepositoryQueryTrait; | |||||
public function __construct(DistributionRepository $repository, PaginatorInterface $paginator) | |||||
{ | |||||
parent::__construct($repository, 'd', $paginator); | |||||
} | |||||
public function filterByYear(int $year): self | |||||
{ | |||||
return $this | |||||
->andWhere('.year = :year') | |||||
->setParameter('year', $year); | |||||
} | |||||
public function filterByCycleNumber(int $cycleNumber): self | |||||
{ | |||||
return $this | |||||
->andWhere('.cycleNumber = :cycleNumber') | |||||
->setParameter('cycleNumber', $cycleNumber); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Distribution; | |||||
use App\Entity\Distribution\Distribution; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | |||||
use Lc\SovBundle\Repository\AbstractStore; | |||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | |||||
class DistributionStore extends AbstractStore | |||||
{ | |||||
use SectionStoreTrait; | |||||
protected DistributionRepositoryQuery $query; | |||||
public function __construct(DistributionRepositoryQuery $query) | |||||
{ | |||||
$this->query = $query; | |||||
} | |||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->orderBy('id'); | |||||
return $query; | |||||
} | |||||
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
$query->filterBySection($this->section); | |||||
return $query; | |||||
} | |||||
public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | |||||
{ | |||||
return $query; | |||||
} | |||||
public function getOneByCycleNumberYearAndSection( | |||||
int $cycleNumber, | |||||
int $year, | |||||
SectionInterface $section | |||||
): ?Distribution { | |||||
$query = $this->createQuery(); | |||||
$query->filterByCycleNumber($cycleNumber); | |||||
$query->filterByYear($year); | |||||
$query->filterBySection($section); | |||||
return $query->findOne(); | |||||
} | |||||
} |
use App\Entity\PointSale\PointSale; | use App\Entity\PointSale\PointSale; | ||||
use Knp\Component\Pager\PaginatorInterface; | use Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | use Lc\CaracoleBundle\Model\Address\AddressInterface; | ||||
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; | use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; | use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; | ||||
public function selectSum(): self | public function selectSum(): self | ||||
{ | { | ||||
$this->joinProduct(); | $this->joinProduct(); | ||||
$this->joinDistribution(); | |||||
return $this | return $this | ||||
->select( | ->select( | ||||
'SUM(orderProduct.quantityOrder) as quantity, .cycleNumber as cycleNumber, product.id as productId' | 'SUM(orderProduct.quantityOrder) as quantity, .cycleNumber as cycleNumber, product.id as productId' | ||||
->setParameter('alias', $status); | ->setParameter('alias', $status); | ||||
} | } | ||||
public function filterByCycleNumbers(array $cycleNumbers): self | |||||
public function filterByDistributions(array $distributions): self | |||||
{ | { | ||||
return $this | return $this | ||||
->andWhere('.cycleNumber IN(:cycleNumbers)') | |||||
->setParameter('cycleNumbers', $cycleNumbers); | |||||
->andWhere('.distribution IN(:distributions)') | |||||
->setParameter('distributions', $distributions); | |||||
} | } | ||||
public function filterByProducts(array $products): self | public function filterByProducts(array $products): self | ||||
->setParameter('reductionCart', $reductionCart); | ->setParameter('reductionCart', $reductionCart); | ||||
} | } | ||||
public function filterByCycleNumber(int $cycleNumber): self | |||||
public function filterByDistribution(DistributionInterface $distribution): self | |||||
{ | { | ||||
return $this | return $this | ||||
->andWhere('.cycleNumber = :cycleNumber') | |||||
->setParameter('cycleNumber', $cycleNumber); | |||||
->andWhere('.distribution = :distribution') | |||||
->setParameter('distribution', $distribution); | |||||
} | } | ||||
public function filterIsNotComplementaryOrderShop(): self | public function filterIsNotComplementaryOrderShop(): self |
namespace Lc\CaracoleBundle\Repository\Order; | namespace Lc\CaracoleBundle\Repository\Order; | ||||
use App\Builder\Distribution\DistributionBuilder; | |||||
use App\Entity\Distribution\Distribution; | |||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | ||||
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | ||||
protected UrlGeneratorInterface $router; | protected UrlGeneratorInterface $router; | ||||
protected OrderShopSolver $orderShopSolver; | protected OrderShopSolver $orderShopSolver; | ||||
protected ReductionCartStore $reductionCartStore; | protected ReductionCartStore $reductionCartStore; | ||||
protected DistributionBuilder $distributionBuilder; | |||||
public function __construct( | public function __construct( | ||||
OrderShopRepositoryQuery $query, | OrderShopRepositoryQuery $query, | ||||
ParameterBagInterface $parameterBag, | ParameterBagInterface $parameterBag, | ||||
UrlGeneratorInterface $router, | UrlGeneratorInterface $router, | ||||
OrderShopSolver $orderShopSolver, | OrderShopSolver $orderShopSolver, | ||||
ReductionCartStore $reductionCartStore | |||||
ReductionCartStore $reductionCartStore, | |||||
DistributionBuilder $distributionBuilder | |||||
) { | ) { | ||||
$this->query = $query; | $this->query = $query; | ||||
$this->entityManager = $entityManager; | $this->entityManager = $entityManager; | ||||
$this->router = $router; | $this->router = $router; | ||||
$this->orderShopSolver = $orderShopSolver; | $this->orderShopSolver = $orderShopSolver; | ||||
$this->reductionCartStore = $reductionCartStore; | $this->reductionCartStore = $reductionCartStore; | ||||
$this->distributionBuilder = $distributionBuilder; | |||||
} | } | ||||
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | ||||
} | } | ||||
// getOrderShopsOfWeek | // getOrderShopsOfWeek | ||||
public function getByCurrentCycle($params = [], $query = null) | |||||
//getByCurrentCycle | |||||
public function getByCurrentDistribution($params = [], $query = null) | |||||
{ | { | ||||
return $this->getBy( | return $this->getBy( | ||||
array_merge( | array_merge( | ||||
[ | [ | ||||
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section), | |||||
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section), | |||||
'isValid' => true, | 'isValid' => true, | ||||
], | ], | ||||
$params | $params | ||||
} | } | ||||
// getOrderShopsOfWeekByUser | // getOrderShopsOfWeekByUser | ||||
public function getByCurrentCycleAndUser(UserInterface $user = null, array $params = [], $query = null) | |||||
//getByCurrentCycleAndUser | |||||
public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null) | |||||
{ | { | ||||
return $this->getByCurrentCycle( | |||||
return $this->getByCurrentDistribution( | |||||
array_merge( | array_merge( | ||||
[ | [ | ||||
'user' => $user, | 'user' => $user, | ||||
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section), | |||||
'excludeComplementaryOrderShops' => true | 'excludeComplementaryOrderShops' => true | ||||
], | ], | ||||
$params | $params | ||||
//public $countOrderShopsOfWeek = null; | //public $countOrderShopsOfWeek = null; | ||||
// public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true, $query = null) | // public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true, $query = null) | ||||
public function countByCurrentCycle(array $params, $query = null) | |||||
//countByCurrentCycle | |||||
public function countByCurrentDistribution(array $params, $query = null) | |||||
{ | { | ||||
return $this->countBy( | return $this->countBy( | ||||
array_merge( | array_merge( | ||||
[ | [ | ||||
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section), | |||||
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section), | |||||
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true, | 'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true, | ||||
], | ], | ||||
$params | $params | ||||
} | } | ||||
// getNextWeekId | // getNextWeekId | ||||
public function getNextCycleId(int $cycleNumber, $query = null): int | |||||
public function getNextCycleId(Distribution $distribution, $query = null): int | |||||
{ | { | ||||
$lastOrder = $this->getOneLastValidByCycle($cycleNumber, $query); | |||||
$lastOrder = $this->getOneLastValidByDistribution($distribution, $query); | |||||
if ($lastOrder) { | if ($lastOrder) { | ||||
return intval($lastOrder->getCycleId() + 1); | return intval($lastOrder->getCycleId() + 1); | ||||
} else { | } else { | ||||
); | ); | ||||
} | } | ||||
public function countValidByCurrentCycle($query = null): int | |||||
//countValidByCurrentCycle | |||||
public function countValidByCurrentDistribution($query = null): int | |||||
{ | { | ||||
return $this->countBy( | return $this->countBy( | ||||
[ | [ | ||||
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section), | |||||
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section), | |||||
'isValid' => true, | 'isValid' => true, | ||||
'excludeComplementaryOrderShops' => true | 'excludeComplementaryOrderShops' => true | ||||
], | ], | ||||
} | } | ||||
// findLastOrderValidOfWeek | // findLastOrderValidOfWeek | ||||
public function getOneLastValidByCycle(int $cycleNumber, $query = null): ?OrderShopInterface | |||||
//getOneLastValidByCycle | |||||
public function getOneLastValidByDistribution(DistributionInterface $distribution, $query = null): ?OrderShopInterface | |||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query | $query | ||||
->filterByCycleNumber($cycleNumber) | |||||
->filterByDistribution($distribution) | |||||
->filterByStatus(OrderStatusModel::$statusAliasAsValid) | ->filterByStatus(OrderStatusModel::$statusAliasAsValid) | ||||
->filterIsNotComplementaryOrderShop() | ->filterIsNotComplementaryOrderShop() | ||||
->orderBy('.cycleId', 'DESC'); | ->orderBy('.cycleId', 'DESC'); | ||||
$query->filterByDateEnd($params['dateField'], $params['dateEnd']); | $query->filterByDateEnd($params['dateField'], $params['dateEnd']); | ||||
} | } | ||||
if (isset($params['cycleNumber'])) { | |||||
$query->filterByCycleNumber($params['cycleNumber']); | |||||
if (isset($params['distribution'])) { | |||||
$query->filterByDistribution($params['distribution']); | |||||
} | } | ||||
if (isset($params['isCart'])) { | if (isset($params['isCart'])) { | ||||
return $reductionCartsArray; | return $reductionCartsArray; | ||||
} | } | ||||
public function countValidOrderProductsOfCyclesByProducts( | |||||
array $cycleNumbers, | |||||
//countValidOrderProductsOfCyclesByProducts | |||||
public function countValidOrderProductsOfDistributionsByProducts( | |||||
array $distributions, | |||||
array $products, | array $products, | ||||
$query = null | $query = null | ||||
): array { | ): array { | ||||
$query | $query | ||||
->filterByAlias(OrderStatusModel::$statusAliasAsValid) | ->filterByAlias(OrderStatusModel::$statusAliasAsValid) | ||||
->filterByCycleNumbers($cycleNumbers) | |||||
->filterByDistributions($distributions) | |||||
->filterByProducts($products) | ->filterByProducts($products) | ||||
->selectSum() | ->selectSum() | ||||
->groupBy('.cycleNumber, product.id'); | |||||
->groupBy('.distribution, product.id'); | |||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
public function countValidOrderProductsOfCycleByProduct(int $cycleNumber, int $productId, $query = null): ?string | |||||
//countValidOrderProductsOfCycleByProduct | |||||
public function countValidOrderProductsOfDistributionByProduct(DistributionInterface $distribution, int $productId, $query = null): ?string | |||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query | $query | ||||
->filterByAlias(OrderStatusModel::$statusAliasAsValid) | ->filterByAlias(OrderStatusModel::$statusAliasAsValid) | ||||
->filterByCycleNumber($cycleNumber) | |||||
->filterByDistribution($distribution) | |||||
->filterByProduct($productId) | ->filterByProduct($productId) | ||||
->selectSumQuantityOrder() | ->selectSumQuantityOrder() | ||||
->groupBy('.cycleNumber, product.id'); | |||||
->groupBy('.distribution, product.id'); | |||||
$result = $query->findOne(); | $result = $query->findOne(); | ||||
} | } | ||||
// Nombre maximum de commandes par cycle (voir configuration de section) | // Nombre maximum de commandes par cycle (voir configuration de section) | ||||
if ($this->isMaximumOrderCycleAchieved($section)) { | |||||
if ($this->isMaximumOrderDistributionAchieved($section)) { | |||||
$this->addMessage('Le nombre maximum de commande a été atteint.'); | $this->addMessage('Le nombre maximum de commande a été atteint.'); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
// isMaximumOrderWeekAchieved | // isMaximumOrderWeekAchieved | ||||
public function isMaximumOrderCycleAchieved(SectionInterface $section) | |||||
//isMaximumOrderCycleAchieved | |||||
public function isMaximumOrderDistributionAchieved(SectionInterface $section) | |||||
{ | { | ||||
$countOrderShopCycle = $this->orderShopStore | $countOrderShopCycle = $this->orderShopStore | ||||
->setSection($section) | ->setSection($section) | ||||
->countValidByCurrentCycle(); | |||||
->countValidByCurrentDistribution(); | |||||
$orderMaximumPerCycle = $this->settingSolver->getSettingValue( | $orderMaximumPerCycle = $this->settingSolver->getSettingValue( | ||||
$section, | $section, | ||||
} | } | ||||
// @TODO : ajouter une option dans les sections (permettre les commandes complémentaires ou non) | // @TODO : ajouter une option dans les sections (permettre les commandes complémentaires ou non) | ||||
$orderShopsUser = $this->orderShopStore->setSection($section)->getByCurrentCycleAndUser($user); | |||||
$orderShopsUser = $this->orderShopStore->setSection($section)->getByCurrentDistributionAndUser($user); | |||||
return $this->isOpenSale($section, $user) | return $this->isOpenSale($section, $user) | ||||
&& $this->isMaximumOrderCycleAchieved($section) | |||||
&& $this->isMaximumOrderDistributionAchieved($section) | |||||
&& count($orderShopsUser) > 0; | && count($orderShopsUser) > 0; | ||||
} | } | ||||
<?php | |||||
namespace Lc\CaracoleBundle\Solver\Distribution; | |||||
class DistributionSolver | |||||
{ | |||||
} |