namespace Lc\CaracoleBundle\Builder\Order; | namespace Lc\CaracoleBundle\Builder\Order; | ||||
use App\Builder\Distribution\DistributionBuilder; | use App\Builder\Distribution\DistributionBuilder; | ||||
use App\Entity\Order\OrderStatus; | |||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder; | use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder; | ||||
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryModel; | use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryModel; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusInterface; | use Lc\CaracoleBundle\Model\Order\OrderStatusInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | |||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | ||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | use Lc\CaracoleBundle\Model\Product\ProductInterface; | ||||
): OrderShopInterface { | ): OrderShopInterface { | ||||
$orderShop = $this->orderShopFactory->create($section, $user, $visitor); | $orderShop = $this->orderShopFactory->create($section, $user, $visitor); | ||||
$this->setOrderStatus($orderShop, OrderStatusModel::ALIAS_CART); | |||||
$this->setOrderStatus($orderShop, OrderStatus::ALIAS_CART); | |||||
$this->entityManager->create($orderShop); | $this->entityManager->create($orderShop); | ||||
$this->entityManager->flush(); | $this->entityManager->flush(); | ||||
} | } | ||||
if ($this->orderShopResolver->isPaid($orderShop)) { | if ($this->orderShopResolver->isPaid($orderShop)) { | ||||
$nextStatus = OrderStatusModel::ALIAS_PAID; | |||||
$nextStatus = OrderStatus::ALIAS_PAID; | |||||
} else { | } else { | ||||
$nextStatus = OrderStatusModel::ALIAS_PARTIAL_PAYMENT; | |||||
$nextStatus = OrderStatus::ALIAS_PARTIAL_PAYMENT; | |||||
} | } | ||||
if ($orderShop->getOrderStatus()->getAlias() != $nextStatus) { | if ($orderShop->getOrderStatus()->getAlias() != $nextStatus) { | ||||
$orderShop->setStatDeliveryPriceWithTaxAndReduction( | $orderShop->setStatDeliveryPriceWithTaxAndReduction( | ||||
$this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop) | $this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop) | ||||
); | ); | ||||
$orderShop->setStatMarginDeliveryWithReductions( | |||||
$this->priceSolver->getMarginDeliveryWithReductions($orderShop) | |||||
); | |||||
$this->entityManager->persist($orderShop); | $this->entityManager->persist($orderShop); | ||||
if ($flush) { | if ($flush) { | ||||
} | } | ||||
public function setStatsInfo(OrderShopInterface $orderShop, $flush = true) | |||||
{ | |||||
$orderShop->setStatTotal($this->priceSolver->getTotal($orderShop)); | |||||
$orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop)); | |||||
$orderShop->setStatTotalOrderProductsWithReductions( | |||||
$this->priceSolver->getTotalOrderProductsWithReductions($orderShop) | |||||
); | |||||
$orderShop->setStatTotalOrderProductsWithTaxAndReductions( | |||||
$this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop) | |||||
); | |||||
$orderShop->setStatMarginOrderProductsWithReductions( | |||||
$this->priceSolver->getMarginOrderProductsWithReductions($orderShop) | |||||
); | |||||
$orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop)); | |||||
$orderShop->setStatDeliveryPriceWithTaxAndReduction( | |||||
$this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop) | |||||
); | |||||
$this->entityManager->update($orderShop); | |||||
if ($flush) { | |||||
$this->entityManager->flush(); | |||||
} | |||||
} | |||||
//Semble ne jamais être utilisé | |||||
//TODO : à supprimer si pas d'erreur arpès 1/01/2025 | |||||
// public function setStatsInfo(OrderShopInterface $orderShop, $flush = true) | |||||
// { | |||||
// $orderShop->setStatTotal($this->priceSolver->getTotal($orderShop)); | |||||
// $orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop)); | |||||
// $orderShop->setStatTotalOrderProductsWithReductions( | |||||
// $this->priceSolver->getTotalOrderProductsWithReductions($orderShop) | |||||
// ); | |||||
// $orderShop->setStatTotalOrderProductsWithTaxAndReductions( | |||||
// $this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop) | |||||
// ); | |||||
// $orderShop->setStatMarginOrderProductsWithReductions( | |||||
// $this->priceSolver->getMarginOrderProductsWithReductions($orderShop) | |||||
// ); | |||||
// $orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop)); | |||||
// $orderShop->setStatDeliveryPriceWithTaxAndReduction( | |||||
// $this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop) | |||||
// ); | |||||
// $orderShop->setStatMarginDeliveryWithReductions( | |||||
// $this->priceSolver->getMarginDeliveryWithReductions($orderShop) | |||||
// ); | |||||
// | |||||
// | |||||
// $this->entityManager->update($orderShop); | |||||
// if ($flush) { | |||||
// $this->entityManager->flush(); | |||||
// } | |||||
// } | |||||
public function setHasReach(int $reachStep, OrderShopInterface $orderShop) | public function setHasReach(int $reachStep, OrderShopInterface $orderShop) |
const ALIAS_CANCELED_WAITING_REFUND = 'canceled-waiting-refund'; | const ALIAS_CANCELED_WAITING_REFUND = 'canceled-waiting-refund'; | ||||
const ALIAS_REFUND = 'refund'; | const ALIAS_REFUND = 'refund'; | ||||
//TODO : AJOUTER un champ valid ds orderSTATUS | //TODO : AJOUTER un champ valid ds orderSTATUS | ||||
static $statusAliasAsValid = [ | static $statusAliasAsValid = [ | ||||
self::ALIAS_PAID, | |||||
self::ALIAS_WAITING_DELIVERY, | |||||
self::ALIAS_WAITING_BANK_RETURN, | |||||
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, | |||||
self::ALIAS_DELIVERED_WITHOUT_PAYMENT, | |||||
self::ALIAS_DONE | |||||
self::ALIAS_PAID, | |||||
self::ALIAS_WAITING_DELIVERY, | |||||
self::ALIAS_WAITING_BANK_RETURN, | |||||
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, | |||||
self::ALIAS_DELIVERED_WITHOUT_PAYMENT, | |||||
self::ALIAS_DONE | |||||
]; | ]; | ||||
static $statusAliasWaitingDelivery = [ | static $statusAliasWaitingDelivery = [ | ||||
self::ALIAS_WAITING_DELIVERY, | |||||
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, | |||||
self::ALIAS_WAITING_DELIVERY, | |||||
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, | |||||
]; | ]; | ||||
static $statusAliasAsCart = [ | static $statusAliasAsCart = [ | ||||
self::ALIAS_CART, | |||||
self::ALIAS_PARTIAL_PAYMENT, | |||||
self::ALIAS_WAITING_PAYMENT_ONLINE, | |||||
self::ALIAS_ERROR_PAYMENT_ONLINE | |||||
self::ALIAS_CART, | |||||
self::ALIAS_PARTIAL_PAYMENT, | |||||
self::ALIAS_WAITING_PAYMENT_ONLINE, | |||||
self::ALIAS_ERROR_PAYMENT_ONLINE | |||||
]; | ]; | ||||
/** | /** |
namespace Lc\CaracoleBundle\Repository\Order; | namespace Lc\CaracoleBundle\Repository\Order; | ||||
use App\Entity\Order\OrderStatus; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | |||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | use Lc\CaracoleBundle\Model\Product\ProductInterface; | ||||
use Lc\CaracoleBundle\Repository\SectionStoreTrait; | use Lc\CaracoleBundle\Repository\SectionStoreTrait; | ||||
use Lc\CaracoleBundle\Repository\AbstractStore; | use Lc\CaracoleBundle\Repository\AbstractStore; | ||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query->filterByProduct($product); | $query->filterByProduct($product); | ||||
$query->filterByOrderStatus(OrderStatusModel::$statusAliasAsCart); | |||||
$query->filterByOrderStatus(OrderStatus::$statusAliasAsCart); | |||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
} | } |
use App\Builder\Distribution\DistributionBuilder; | use App\Builder\Distribution\DistributionBuilder; | ||||
use App\Entity\Distribution\Distribution; | use App\Entity\Distribution\Distribution; | ||||
use App\Entity\User\User; | |||||
use App\Entity\Order\OrderStatus; | |||||
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\Distribution\DistributionInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | |||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | ||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | use Lc\CaracoleBundle\Model\Product\ProductInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | ||||
$query | $query | ||||
->selectCount() | ->selectCount() | ||||
->filterByReductionCredit($reductionCredit) | ->filterByReductionCredit($reductionCredit) | ||||
->filterByStatus(OrderStatusModel::$statusAliasAsValid); | |||||
->filterByStatus(OrderStatus::$statusAliasAsValid); | |||||
return $query->count(); | return $query->count(); | ||||
} | } | ||||
$query | $query | ||||
->selectCount() | ->selectCount() | ||||
->filterByReductionCart($reductionCart) | ->filterByReductionCart($reductionCart) | ||||
->filterByStatus(OrderStatusModel::$statusAliasAsValid); | |||||
->filterByStatus(OrderStatus::$statusAliasAsValid); | |||||
return $query->count(); | return $query->count(); | ||||
} | } | ||||
->selectCount() | ->selectCount() | ||||
->filterByUser($user) | ->filterByUser($user) | ||||
->filterByReductionCart($reductionCart) | ->filterByReductionCart($reductionCart) | ||||
->filterByStatus(OrderStatusModel::$statusAliasAsValid); | |||||
->filterByStatus(OrderStatus::$statusAliasAsValid); | |||||
return $query->count(); | return $query->count(); | ||||
} | } | ||||
$query | $query | ||||
->selectOrderReductionCarts() | ->selectOrderReductionCarts() | ||||
->filterByStatus(OrderStatusModel::$statusAliasAsCart); | |||||
->filterByStatus(OrderStatus::$statusAliasAsCart); | |||||
return $query->findOne(); | return $query->findOne(); | ||||
} | } | ||||
$query | $query | ||||
->filterByDistribution($distribution) | ->filterByDistribution($distribution) | ||||
->filterByStatus(OrderStatusModel::$statusAliasAsValid) | |||||
->filterByStatus(OrderStatus::$statusAliasAsValid) | |||||
->filterIsNotComplementaryOrderShop() | ->filterIsNotComplementaryOrderShop() | ||||
->orderBy('.cycleId', 'DESC'); | ->orderBy('.cycleId', 'DESC'); | ||||
$query | $query | ||||
->filterByDistribution($distribution) | ->filterByDistribution($distribution) | ||||
->filterByUser($user) | ->filterByUser($user) | ||||
->filterByStatus(OrderStatusModel::$statusAliasAsValid) | |||||
->filterByStatus(OrderStatus::$statusAliasAsValid) | |||||
->filterIsNotComplementaryOrderShop() | ->filterIsNotComplementaryOrderShop() | ||||
->orderBy('.cycleId', 'DESC'); | ->orderBy('.cycleId', 'DESC'); | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query | $query | ||||
->filterByStatus(OrderStatusModel::$statusAliasAsValid) | |||||
->filterByStatus(OrderStatus::$statusAliasAsValid) | |||||
->filterIsNotComplementaryOrderShop() | ->filterIsNotComplementaryOrderShop() | ||||
->orderBy('.idValidOrder', 'DESC'); | ->orderBy('.idValidOrder', 'DESC'); | ||||
} | } | ||||
if (isset($params['isCart'])) { | if (isset($params['isCart'])) { | ||||
$query->filterByStatus(OrderStatusModel::$statusAliasAsCart); | |||||
$query->filterByStatus(OrderStatus::$statusAliasAsCart); | |||||
} | } | ||||
if (isset($params['isValid'])) { | if (isset($params['isValid'])) { | ||||
$query->filterByStatus(OrderStatusModel::$statusAliasAsValid); | |||||
$query->filterByStatus(OrderStatus::$statusAliasAsValid); | |||||
} | } | ||||
if (isset($params['isWaitingDelivery'])) { | if (isset($params['isWaitingDelivery'])) { | ||||
$query->filterByStatus(OrderStatusModel::$statusAliasWaitingDelivery); | |||||
$query->filterByStatus(OrderStatus::$statusAliasWaitingDelivery); | |||||
} | } | ||||
if (isset($params['orderStatus'])) { | if (isset($params['orderStatus'])) { | ||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query | $query | ||||
->filterByAlias(OrderStatusModel::$statusAliasAsValid) | |||||
->filterByAlias(OrderStatus::$statusAliasAsValid) | |||||
->filterByDistributions($distributions) | ->filterByDistributions($distributions) | ||||
->filterByProducts($products) | ->filterByProducts($products) | ||||
->selectSum() | ->selectSum() | ||||
$query = $this->createQuery($query); | $query = $this->createQuery($query); | ||||
$query | $query | ||||
->filterByAlias(OrderStatusModel::$statusAliasAsValid) | |||||
->filterByAlias(OrderStatus::$statusAliasAsValid) | |||||
->filterByDistribution($distribution) | ->filterByDistribution($distribution) | ||||
->filterByProduct($product) | ->filterByProduct($product) | ||||
->selectSumQuantityOrder() | ->selectSumQuantityOrder() | ||||
$query = $this->createQuery($query); | $query = $this->createQuery($query); | ||||
$query->filterByAlias(OrderStatusModel::$statusAliasAsCart); | |||||
$query->filterByAlias(OrderStatus::$statusAliasAsCart); | |||||
$query->filterByUserIsNull(); | $query->filterByUserIsNull(); | ||||
$query->filterByVisitorIsNull(); | $query->filterByVisitorIsNull(); | ||||
namespace Lc\CaracoleBundle\Solver\Order; | namespace Lc\CaracoleBundle\Solver\Order; | ||||
use App\Entity\Order\OrderShop; | use App\Entity\Order\OrderShop; | ||||
use App\Entity\Order\OrderStatus; | |||||
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopModel; | use Lc\CaracoleBundle\Model\Order\OrderShopModel; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusInterface; | use Lc\CaracoleBundle\Model\Order\OrderStatusInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | |||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | ||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | use Lc\CaracoleBundle\Model\Product\ProductInterface; | ||||
{ | { | ||||
if ($orderShop->getOrderStatus() && in_array( | if ($orderShop->getOrderStatus() && in_array( | ||||
$orderShop->getOrderStatus()->getAlias(), | $orderShop->getOrderStatus()->getAlias(), | ||||
OrderStatusModel::$statusAliasAsValid | |||||
OrderStatus::$statusAliasAsValid | |||||
) > 0) { | ) > 0) { | ||||
return true; | return true; | ||||
} | } | ||||
{ | { | ||||
if ($orderShop->getOrderStatus() && in_array( | if ($orderShop->getOrderStatus() && in_array( | ||||
$orderShop->getOrderStatus()->getAlias(), | $orderShop->getOrderStatus()->getAlias(), | ||||
OrderStatusModel::$statusAliasAsCart | |||||
OrderStatus::$statusAliasAsCart | |||||
) > 0) { | ) > 0) { | ||||
return true; | return true; | ||||
} | } | ||||
public function isDone(OrderShopInterface $orderShop): bool | public function isDone(OrderShopInterface $orderShop): bool | ||||
{ | { | ||||
if ($orderShop->getOrderStatus() && $orderShop->getOrderStatus()->getAlias() == OrderStatusModel::ALIAS_DONE) { | |||||
if ($orderShop->getOrderStatus() && $orderShop->getOrderStatus()->getAlias() == OrderStatus::ALIAS_DONE) { | |||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; |