Browse Source

Merge branch 'develop'

master
Guillaume 3 years ago
parent
commit
110768c3f5
1 changed files with 162 additions and 156 deletions
  1. +162
    -156
      Repository/Order/OrderShopStore.php

+ 162
- 156
Repository/Order/OrderShopStore.php View File

use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\CaracoleBundle\Repository\AbstractStore; use Lc\CaracoleBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface; use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\FlashBagTranslator; use Lc\SovBundle\Translation\FlashBagTranslator;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
protected OrderShopSolver $orderShopSolver; protected OrderShopSolver $orderShopSolver;
protected ReductionCartStore $reductionCartStore; protected ReductionCartStore $reductionCartStore;
protected DistributionBuilder $distributionBuilder; protected DistributionBuilder $distributionBuilder;
protected SettingSolver $settingSolver;


public function __construct( public function __construct(
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceSolver $priceSolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
ReductionCartSolver $reductionCartSolver,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagTranslator $flashBagTranslator,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore,
DistributionBuilder $distributionBuilder
)
{
OrderShopRepositoryQuery $query,
EntityManagerInterface $entityManager,
PriceSolver $priceSolver,
DocumentBuilder $documentBuilder,
ReductionCreditStore $reductionCreditStore,
ReductionCartSolver $reductionCartSolver,
SectionStore $sectionStore,
OrderProductStore $orderProductStore,
MerchantStore $merchantStore,
FlashBagTranslator $flashBagTranslator,
ParameterBagInterface $parameterBag,
UrlGeneratorInterface $router,
OrderShopSolver $orderShopSolver,
ReductionCartStore $reductionCartStore,
DistributionBuilder $distributionBuilder,
SettingSolver $settingSolver
) {
$this->query = $query; $this->query = $query;
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->priceSolver = $priceSolver; $this->priceSolver = $priceSolver;
$this->orderShopSolver = $orderShopSolver; $this->orderShopSolver = $orderShopSolver;
$this->reductionCartStore = $reductionCartStore; $this->reductionCartStore = $reductionCartStore;
$this->distributionBuilder = $distributionBuilder; $this->distributionBuilder = $distributionBuilder;
$this->settingSolver = $settingSolver;
} }


public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$this $this
->addFilterBySectionOptionnal($query)
->addFilterByMerchantViaSectionOptionnal($query);
->addFilterBySectionOptionnal($query)
->addFilterByMerchantViaSectionOptionnal($query);


return $query; return $query;
} }
public function getByCurrentDistribution($params = [], $query = null) public function getByCurrentDistribution($params = [], $query = null)
{ {
return $this->getBy( return $this->getBy(
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
],
$params
),
$query
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder(
$this->section
),
'isValid' => true,
],
$params
),
$query
); );
} }


public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null) public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null)
{ {
return $this->getByCurrentDistribution( return $this->getByCurrentDistribution(
array_merge(
[
'user' => $user,
'excludeComplementaryOrderShops' => true
],
$params
),
$query
array_merge(
[
'user' => $user,
'excludeComplementaryOrderShops' => true
],
$params
),
$query
); );
} }


public function countByCurrentDistribution(array $params, $query = null) public function countByCurrentDistribution(array $params, $query = null)
{ {
return $this->countBy( return $this->countBy(
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
),
$query
array_merge(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder(
$this->section
),
'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
],
$params
),
$query
); );


// @TODO : optimisation à remettre en place // @TODO : optimisation à remettre en place
public function countValidByUserAllMerchant($user, $query = null): int public function countValidByUserAllMerchant($user, $query = null): int
{ {
return $this->countBy( return $this->countBy(
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'user' => $user,
'isValid' => true,
// @TODO : à tester
'isMerchantOnline' => true,
'excludeComplementaryOrderShops' => true
],
$query
); );
} }


public function countValidByUser(UserInterface $user = null, $query = null): int public function countValidByUser(UserInterface $user = null, $query = null): int
{ {
return $this->countBy( return $this->countBy(
[
'user' => $user,
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'user' => $user,
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
); );
} }


public function countValidByCurrentDistribution($query = null): int public function countValidByCurrentDistribution($query = null): int
{ {
return $this->countBy( return $this->countBy(
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
[
'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
'isValid' => true,
'excludeComplementaryOrderShops' => true
],
$query
); );
} }


// countValidOrderWithReductionCredit // countValidOrderWithReductionCredit
public function countValidWithReductionCredit( public function countValidWithReductionCredit(
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
): int
{

ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
): int {
//TODO vérifier que ne pas utiliser createDefaultQuery est pertinent //TODO vérifier que ne pas utiliser createDefaultQuery est pertinent
$query = $this->createQuery($query); $query = $this->createQuery($query);


} }


$query $query
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);


return $query->count(); return $query->count();
} }


// countValidOrderWithReductionCart // countValidOrderWithReductionCart
public function countValidWithReductionCart( public function countValidWithReductionCart(
ReductionCartInterface $reductionCart,
$query = null
): int
{
ReductionCartInterface $reductionCart,
$query = null
): int {
$query = $this->createQuery($query); $query = $this->createQuery($query);


$query $query
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);


return $query->count(); return $query->count();
} }


// countValidOrderWithReductionCartPerUser // countValidOrderWithReductionCartPerUser
public function countValidWithReductionCartByUser( public function countValidWithReductionCartByUser(
ReductionCartInterface $reductionCart,
UserInterface $user,
$query = null
): int
{
ReductionCartInterface $reductionCart,
UserInterface $user,
$query = null
): int {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatusModel::$statusAliasAsValid);


return $query->count(); return $query->count();
} }


// findCartCurrent // findCartCurrent
public function getOneCartCurrent(UserInterface $user = null, VisitorInterface $visitor = null, $query = null): ?OrderShopInterface
{
public function getOneCartCurrent(
UserInterface $user = null,
VisitorInterface $visitor = null,
$query = null
): ?OrderShopInterface {
if (is_null($user) && is_null($visitor)) { if (is_null($user) && is_null($visitor)) {
return null; return null;
} }
} }


$query $query
->selectOrderReductionCarts()
->filterByStatus(OrderStatusModel::$statusAliasAsCart);
->selectOrderReductionCarts()
->filterByStatus(OrderStatusModel::$statusAliasAsCart);


return $query->findOne(); return $query->findOne();
} }


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


$query $query
->filterByDistribution($distribution)
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.cycleId', 'DESC');
->filterByDistribution($distribution)
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.cycleId', 'DESC');


return $query->findOne(); return $query->findOne();
} }
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);


$query $query
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.idValidOrder', 'DESC');
->filterByStatus(OrderStatusModel::$statusAliasAsValid)
->filterIsNotComplementaryOrderShop()
->orderBy('.idValidOrder', 'DESC');


return $query->findOne(); return $query->findOne();
} }


$orderShops = $query->find(); $orderShops = $query->find();


if (isset($params['mergeComplementaryOrderShops'])) {
if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'] == true) {
foreach ($orderShops as $orderShop) { foreach ($orderShops as $orderShop) {
$this->orderShopSolver->mergeComplentaryOrderShops($orderShop); $this->orderShopSolver->mergeComplentaryOrderShops($orderShop);
} }
$query->filterMinimumTomorrowDelivery(); $query->filterMinimumTomorrowDelivery();
} }


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


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


} }


public function isReductionCreditUsed( public function isReductionCreditUsed(
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
)
{
ReductionCreditInterface $reductionCredit,
UserInterface $user = null,
$query = null
) {
if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) { if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) {
return true; return true;
} else { } else {
public function getReductionCreditsAvailableByUser(UserInterface $user): array public function getReductionCreditsAvailableByUser(UserInterface $user): array
{ {
$reductionCredits = $this->reductionCreditStore $reductionCredits = $this->reductionCreditStore
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);


$reductionCreditsArray = []; $reductionCreditsArray = [];
foreach ($reductionCredits as $reductionCredit) { foreach ($reductionCredits as $reductionCredit) {
public function getReductionGiftsAvailableByUser(UserInterface $user): array public function getReductionGiftsAvailableByUser(UserInterface $user): array
{ {
$reductionGifts = $this->reductionCreditStore $reductionGifts = $this->reductionCreditStore
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);
->setMerchant($this->merchant)
->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);


$reductionGiftsArray = []; $reductionGiftsArray = [];
foreach ($reductionGifts as $reductionGift) { foreach ($reductionGifts as $reductionGift) {
public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float
{ {
return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart( return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart(
$reductionCart
);
$reductionCart
);
} }


// getReductionCartUsedQuantityPerUser // getReductionCartUsedQuantityPerUser
public function getReductionCartUsedQuantityByUser( public function getReductionCartUsedQuantityByUser(
ReductionCartInterface $reductionCart,
UserInterface $user
): float
{
ReductionCartInterface $reductionCart,
UserInterface $user
): float {
return $this->countValidWithReductionCartByUser($reductionCart, $user); return $this->countValidWithReductionCartByUser($reductionCart, $user);
} }




// getReductionCartRemainingQuantityPerUser // getReductionCartRemainingQuantityPerUser
public function getReductionCartRemainingQuantityByUser( public function getReductionCartRemainingQuantityByUser(
ReductionCartInterface $reductionCart,
UserInterface $user
): float
{
ReductionCartInterface $reductionCart,
UserInterface $user
): float {
if ($reductionCart->getAvailableQuantityPerUser()) { if ($reductionCart->getAvailableQuantityPerUser()) {
return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser( return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser(
$reductionCart,
$user
);
$reductionCart,
$user
);
} }


return false; return false;
public function getReductionCartAvailableByUser(UserInterface $user, $query = null) public function getReductionCartAvailableByUser(UserInterface $user, $query = null)
{ {
$reductionCarts = $this->reductionCartStore $reductionCarts = $this->reductionCartStore
->setMerchant($this->merchant)
->getOnline();
->setMerchant($this->merchant)
->getOnline();


$reductionCartsArray = []; $reductionCartsArray = [];
foreach ($reductionCarts as $reductionCart) { foreach ($reductionCarts as $reductionCart) {
if ($this->reductionCartSolver->matchWithUser($reductionCart, $user) if ($this->reductionCartSolver->matchWithUser($reductionCart, $user)
&& $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {

&& $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
&& $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
&& (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {
$reductionCartsArray[] = $reductionCart; $reductionCartsArray[] = $reductionCart;
} }
} }


//countValidOrderProductsOfCyclesByProducts //countValidOrderProductsOfCyclesByProducts
public function countValidOrderProductsOfDistributionsByProducts( public function countValidOrderProductsOfDistributionsByProducts(
array $distributions,
array $products,
$query = null
): array
{
array $distributions,
array $products,
$query = null
): array {
$query = $this->createDefaultQuery($query); $query = $this->createDefaultQuery($query);
$query $query
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistributions($distributions)
->filterByProducts($products)
->selectSum()
->groupBy('distribution.cycleNumber, product.id');
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistributions($distributions)
->filterByProducts($products)
->selectSum()
->groupBy('distribution.cycleNumber, product.id');




return $query->find(); return $query->find();
} }


//countValidOrderProductsOfCycleByProduct //countValidOrderProductsOfCycleByProduct
public function countValidOrderProductsOfDistributionByProduct(DistributionInterface $distribution, ProductInterface $product, $query = null): ?string
{
public function countValidOrderProductsOfDistributionByProduct(
DistributionInterface $distribution,
ProductInterface $product,
$query = null
): ?string {
//TODO attention à vérifier //TODO attention à vérifier
$query = $this->createQuery($query); $query = $this->createQuery($query);


$query $query
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistribution($distribution)
->filterByProduct($product)
->selectSumQuantityOrder()
->joinDistribution()
->groupBy('distribution.cycleNumber, product.id');
->filterByAlias(OrderStatusModel::$statusAliasAsValid)
->filterByDistribution($distribution)
->filterByProduct($product)
->selectSumQuantityOrder()
->joinDistribution()
->groupBy('distribution.cycleNumber, product.id');


$result = $query->findOne(); $result = $query->findOne();


} }


public function isReductionCreditAllowAddToOrder( public function isReductionCreditAllowAddToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
)
{
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit
) {
$user = $orderShop->getUser(); $user = $orderShop->getUser();


// appartient à l'utilisateur // appartient à l'utilisateur

Loading…
Cancel
Save