Ver código fonte

Implementation de Distribution

packProduct
Fab 3 anos atrás
pai
commit
9ddca6c967
17 arquivos alterados com 365 adições e 78 exclusões
  1. +8
    -0
      Builder/Distribution/DistributionBuilder.php
  2. +12
    -15
      Builder/Order/OrderShopBuilder.php
  3. +59
    -0
      Container/Distribution/DistributionContainer.php
  4. +2
    -2
      Definition/Field/Order/OrderShopFieldDefinition.php
  5. +23
    -0
      Factory/Distribution/DistributionFactory.php
  6. +17
    -16
      Generator/OrderReferenceGenerator.php
  7. +8
    -0
      Model/Distribution/DistributionInterface.php
  8. +73
    -0
      Model/Distribution/DistributionModel.php
  9. +1
    -5
      Model/Order/OrderShopInterface.php
  10. +8
    -6
      Model/Order/OrderShopModel.php
  11. +15
    -0
      Repository/Distribution/DistributionRepository.php
  12. +31
    -0
      Repository/Distribution/DistributionRepositoryQuery.php
  13. +51
    -0
      Repository/Distribution/DistributionStore.php
  14. +8
    -6
      Repository/Order/OrderShopRepositoryQuery.php
  15. +35
    -23
      Repository/Order/OrderShopStore.php
  16. +6
    -5
      Resolver/OpeningResolver.php
  17. +8
    -0
      Solver/Distribution/DistributionSolver.php

+ 8
- 0
Builder/Distribution/DistributionBuilder.php Ver arquivo

@@ -0,0 +1,8 @@
<?php

namespace Lc\CaracoleBundle\Builder\Distribution;

class DistributionBuilder
{

}

+ 12
- 15
Builder/Order/OrderShopBuilder.php Ver arquivo

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Builder\Order;

use App\Builder\Distribution\DistributionBuilder;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Builder\File\DocumentBuilder;
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent;
@@ -61,6 +62,7 @@ class OrderShopBuilder
protected ProductSolver $productSolver;
protected OrderShopResolver $orderShopResolver;
protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver;
protected DistributionBuilder $distributionBuilder;

public function __construct(
EntityManagerInterface $entityManager,
@@ -77,7 +79,8 @@ class OrderShopBuilder
OpeningResolver $openingResolver,
ProductSolver $productSolver,
OrderShopResolver $orderShopResolver,
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver
OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver,
DistributionBuilder $distributionBuilder
) {
$this->entityManager = $entityManager;
$this->orderShopStore = $orderShopStore;
@@ -94,6 +97,7 @@ class OrderShopBuilder
$this->productSolver = $productSolver;
$this->orderShopResolver = $orderShopResolver;
$this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver;
$this->distributionBuilder = $distributionBuilder;
}

public function create(
@@ -358,21 +362,14 @@ class OrderShopBuilder
}
}

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);
}



+ 59
- 0
Container/Distribution/DistributionContainer.php Ver arquivo

@@ -0,0 +1,59 @@
<?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;
}

}

+ 2
- 2
Definition/Field/Order/OrderShopFieldDefinition.php Ver arquivo

@@ -38,7 +38,7 @@ class OrderShopFieldDefinition extends AbstractFieldDefinition
'createdAt' => DateTimeField::new('createdAt')->setSortable(true),
'updatedAt' => DateTimeField::new('updatedAt')->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),
'cycleId' => IntegerField::new('cycleId')->setSortable(true),
'deliveryType' => Field::new('deliveryType')->setSortable(true),
@@ -53,4 +53,4 @@ class OrderShopFieldDefinition extends AbstractFieldDefinition
];
}

}
}

+ 23
- 0
Factory/Distribution/DistributionFactory.php Ver arquivo

@@ -0,0 +1,23 @@
<?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;
}

}

+ 17
- 16
Generator/OrderReferenceGenerator.php Ver arquivo

@@ -16,17 +16,17 @@ class OrderReferenceGenerator
$this->settingSolver = $settingSolver;
}

public function buildReference(OrderShopInterface $orderShop, \DateTimeInterface $distributionDate = null): string
public function buildReference(OrderShopInterface $orderShop): string
{
switch ($orderShop->getSection()->getCycleType()) {
case SectionModel::CYCLE_TYPE_DAY:
return $this->buildReferenceCycleDay($orderShop);
case SectionModel::CYCLE_TYPE_WEEK:
return $this->buildReferenceCycleWeek($orderShop, $distributionDate);
return $this->buildReferenceCycleWeek($orderShop);
case SectionModel::CYCLE_TYPE_MONTH:
return $this->buildReferenceCycleMonth($orderShop, $distributionDate);
return $this->buildReferenceCycleMonth($orderShop);
case SectionModel::CYCLE_TYPE_YEAR:
return $this->buildReferenceCycleYear($orderShop, $distributionDate);
return $this->buildReferenceCycleYear($orderShop);
}

return 'C' . $orderShop->getId();
@@ -38,29 +38,26 @@ class OrderReferenceGenerator
'C' . $this->numberPad($orderShop->getCycleId(), 3);
}

public function buildReferenceCycleWeek(OrderShopInterface $orderShop, \DateTimeInterface $distributionDate): string
public function buildReferenceCycleWeek(OrderShopInterface $orderShop): string
{
return $this->getPrefixReference($orderShop) .
'S' . $distributionDate->format('W') .
'S' . $orderShop->getDistribution()->getCycleNumber() .
'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) .
'M' . $distributionDate->format('m') .
'M' . $orderShop->getDistribution()->getCycleNumber() .
'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) .
'C' . $this->numberPad($orderShop->getCycleId(), 5) .
'A' . $distributionDate->format('y');
'A' . $this->formatYear($orderShop->getDistribution()->getYear());
}

public function getPrefixReference(OrderShopInterface $orderShop): string
@@ -71,9 +68,13 @@ class OrderReferenceGenerator
);
}

public function numberPad($number, $length): string
protected function numberPad($number, $length): string
{
return str_pad($number, $length, "0", STR_PAD_LEFT);
}

protected function formatYear(int $year):int{
return substr($year, -2);
}

}

+ 8
- 0
Model/Distribution/DistributionInterface.php Ver arquivo

@@ -0,0 +1,8 @@
<?php

namespace Lc\CaracoleBundle\Model\Distribution;

interface DistributionInterface
{

}

+ 73
- 0
Model/Distribution/DistributionModel.php Ver arquivo

@@ -0,0 +1,73 @@
<?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;
}
}

+ 1
- 5
Model/Order/OrderShopInterface.php Ver arquivo

@@ -132,10 +132,6 @@ interface OrderShopInterface

public function setCycleId(?int $cycleId): OrderShopModel;

public function getCycleNumber(): ?int;

public function setCycleNumber(?int $cycleNumber): OrderShopModel;

public function getOrderShopCreatedAt(): ?\DateTimeInterface;

public function setOrderShopCreatedAt(?\DateTimeInterface $orderShopCreatedAt
@@ -236,4 +232,4 @@ interface OrderShopInterface

public function setStatDeliveryPriceWithTaxAndReduction(?float $statDeliveryPriceWithTaxAndReduction
): OrderShopModel;
}
}

+ 8
- 6
Model/Order/OrderShopModel.php Ver arquivo

@@ -8,6 +8,7 @@ use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Config\TaxRateInterface;
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface;
use Lc\CaracoleBundle\Model\File\DocumentInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
@@ -115,9 +116,10 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti
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)
@@ -601,14 +603,14 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti
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;
}

+ 15
- 0
Repository/Distribution/DistributionRepository.php Ver arquivo

@@ -0,0 +1,15 @@
<?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);
}
}

+ 31
- 0
Repository/Distribution/DistributionRepositoryQuery.php Ver arquivo

@@ -0,0 +1,31 @@
<?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);
}
}

+ 51
- 0
Repository/Distribution/DistributionStore.php Ver arquivo

@@ -0,0 +1,51 @@
<?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();
}
}

+ 8
- 6
Repository/Order/OrderShopRepositoryQuery.php Ver arquivo

@@ -7,6 +7,7 @@ use App\Entity\Delivery\DeliveryAvailabilityZone;
use App\Entity\PointSale\PointSale;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
@@ -59,6 +60,7 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
public function selectSum(): self
{
$this->joinProduct();
$this->joinDistribution();
return $this
->select(
'SUM(orderProduct.quantityOrder) as quantity, .cycleNumber as cycleNumber, product.id as productId'
@@ -102,11 +104,11 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
->setParameter('alias', $status);
}

public function filterByCycleNumbers(array $cycleNumbers): self
public function filterByDistributions(array $distributions): self
{
return $this
->andWhere('.cycleNumber IN(:cycleNumbers)')
->setParameter('cycleNumbers', $cycleNumbers);
->andWhere('.distribution IN(:distributions)')
->setParameter('distributions', $distributions);
}

public function filterByProducts(array $products): self
@@ -190,11 +192,11 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
->setParameter('reductionCart', $reductionCart);
}

public function filterByCycleNumber(int $cycleNumber): self
public function filterByDistribution(DistributionInterface $distribution): self
{
return $this
->andWhere('.cycleNumber = :cycleNumber')
->setParameter('cycleNumber', $cycleNumber);
->andWhere('.distribution = :distribution')
->setParameter('distribution', $distribution);
}

public function filterIsNotComplementaryOrderShop(): self

+ 35
- 23
Repository/Order/OrderShopStore.php Ver arquivo

@@ -2,8 +2,11 @@

namespace Lc\CaracoleBundle\Repository\Order;

use App\Builder\Distribution\DistributionBuilder;
use App\Entity\Distribution\Distribution;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Builder\File\DocumentBuilder;
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
@@ -47,6 +50,7 @@ class OrderShopStore extends AbstractStore
protected UrlGeneratorInterface $router;
protected OrderShopSolver $orderShopSolver;
protected ReductionCartStore $reductionCartStore;
protected DistributionBuilder $distributionBuilder;

public function __construct(
OrderShopRepositoryQuery $query,
@@ -62,7 +66,8 @@ class OrderShopStore extends AbstractStore
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore
ReductionCartStore $reductionCartStore,
DistributionBuilder $distributionBuilder
) {
$this->query = $query;
$this->entityManager = $entityManager;
@@ -78,6 +83,7 @@ class OrderShopStore extends AbstractStore
$this->router = $router;
$this->orderShopSolver = $orderShopSolver;
$this->reductionCartStore = $reductionCartStore;
$this->distributionBuilder = $distributionBuilder;
}

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
@@ -102,12 +108,13 @@ class OrderShopStore extends AbstractStore
}

// getOrderShopsOfWeek
public function getByCurrentCycle($params = [], $query = null)
//getByCurrentCycle
public function getByCurrentDistribution($params = [], $query = null)
{
return $this->getBy(
array_merge(
[
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section),
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
],
$params
@@ -117,13 +124,13 @@ class OrderShopStore extends AbstractStore
}

// 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(
[
'user' => $user,
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section),
'excludeComplementaryOrderShops' => true
],
$params
@@ -134,12 +141,13 @@ class OrderShopStore extends AbstractStore

//public $countOrderShopsOfWeek = 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(
array_merge(
[
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section),
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
@@ -162,9 +170,9 @@ class OrderShopStore extends AbstractStore
}

// 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) {
return intval($lastOrder->getCycleId() + 1);
} else {
@@ -210,11 +218,12 @@ class OrderShopStore extends AbstractStore
);
}

public function countValidByCurrentCycle($query = null): int
//countValidByCurrentCycle
public function countValidByCurrentDistribution($query = null): int
{
return $this->countBy(
[
'cycleNumber' => $this->orderShopSolver->getCycleNumberCurrentOrder($this->section),
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
@@ -296,12 +305,13 @@ class OrderShopStore extends AbstractStore
}

// findLastOrderValidOfWeek
public function getOneLastValidByCycle(int $cycleNumber, $query = null): ?OrderShopInterface
//getOneLastValidByCycle
public function getOneLastValidByDistribution(DistributionInterface $distribution, $query = null): ?OrderShopInterface
{
$query = $this->createDefaultQuery($query);

$query
->filterByCycleNumber($cycleNumber)
->filterByDistribution($distribution)
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.cycleId', 'DESC');
@@ -370,8 +380,8 @@ class OrderShopStore extends AbstractStore
$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'])) {
@@ -530,8 +540,9 @@ class OrderShopStore extends AbstractStore
return $reductionCartsArray;
}

public function countValidOrderProductsOfCyclesByProducts(
array $cycleNumbers,
//countValidOrderProductsOfCyclesByProducts
public function countValidOrderProductsOfDistributionsByProducts(
array $distributions,
array $products,
$query = null
): array {
@@ -539,25 +550,26 @@ class OrderShopStore extends AbstractStore

$query
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByCycleNumbers($cycleNumbers)
->filterByDistributions($distributions)
->filterByProducts($products)
->selectSum()
->groupBy('.cycleNumber, product.id');
->groupBy('.distribution, product.id');


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
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByCycleNumber($cycleNumber)
->filterByDistribution($distribution)
->filterByProduct($productId)
->selectSumQuantityOrder()
->groupBy('.cycleNumber, product.id');
->groupBy('.distribution, product.id');

$result = $query->findOne();


+ 6
- 5
Resolver/OpeningResolver.php Ver arquivo

@@ -75,7 +75,7 @@ class OpeningResolver
}

// 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.');
return false;
}
@@ -148,11 +148,12 @@ class OpeningResolver
}

// isMaximumOrderWeekAchieved
public function isMaximumOrderCycleAchieved(SectionInterface $section)
//isMaximumOrderCycleAchieved
public function isMaximumOrderDistributionAchieved(SectionInterface $section)
{
$countOrderShopCycle = $this->orderShopStore
->setSection($section)
->countValidByCurrentCycle();
->countValidByCurrentDistribution();

$orderMaximumPerCycle = $this->settingSolver->getSettingValue(
$section,
@@ -277,10 +278,10 @@ class OpeningResolver
}

// @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)
&& $this->isMaximumOrderCycleAchieved($section)
&& $this->isMaximumOrderDistributionAchieved($section)
&& count($orderShopsUser) > 0;
}


+ 8
- 0
Solver/Distribution/DistributionSolver.php Ver arquivo

@@ -0,0 +1,8 @@
<?php

namespace Lc\CaracoleBundle\Solver\Distribution;

class DistributionSolver
{

}

Carregando…
Cancelar
Salvar