@@ -0,0 +1,50 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Builder\Credit; | |||
use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder; | |||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | |||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel; | |||
use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | |||
class CreditHistoryBuilder | |||
{ | |||
protected UserMerchantStore $userMerchantStore; | |||
protected UserMerchantBuilder $userMerchantBuilder; | |||
public function __construct( | |||
UserMerchantStore $userMerchantStore, | |||
UserMerchantBuilder $userMerchantBuilder | |||
) { | |||
$this->userMerchantStore = $userMerchantStore; | |||
$this->userMerchantBuilder = $userMerchantBuilder; | |||
} | |||
// saveCreditHistory | |||
public function save(CreditHistoryInterface $creditHistory) | |||
{ | |||
if ($creditHistory) { | |||
$userMerchant = $creditHistory->getUserMerchant(); | |||
$isCreditActive = $this->userMerchantStore->isCreditActive($userMerchant); | |||
if ($isCreditActive) { | |||
if ($creditHistory->getType() == CreditHistoryModel::TYPE_CREDIT) { | |||
$userMerchantAmount = $userMerchant->getCredit() + $creditHistory->getAmountInherited(); | |||
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount); | |||
return true; | |||
} elseif ($creditHistory->getType() == CreditHistoryModel::TYPE_DEBIT) { | |||
if ($this->userMerchantStore->isCreditSufficientToPay($userMerchant, $creditHistory->getAmountInherited())) { | |||
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited(); | |||
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount); | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -8,12 +8,17 @@ use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; | |||
use Lc\CaracoleBundle\Factory\File\DocumentFactory; | |||
use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory; | |||
use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory; | |||
use Lc\CaracoleBundle\Factory\Order\OrderReductionCartFactory; | |||
use Lc\CaracoleBundle\Factory\Order\OrderReductionCreditFactory; | |||
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | |||
use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory; | |||
use Lc\CaracoleBundle\Model\File\DocumentModel; | |||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | |||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||
use Lc\CaracoleBundle\Model\User\VisitorInterface; | |||
use Lc\CaracoleBundle\Repository\Order\OrderProductStore; | |||
@@ -272,4 +277,98 @@ class OrderShopBuilder | |||
return $document; | |||
} | |||
public function addReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart) | |||
{ | |||
$orderReductionCartFactory = new OrderReductionCartFactory(); | |||
$orderReductionCart = $orderReductionCartFactory->create($orderShop, $reductionCart); | |||
$orderShop->addOrderReductionCart($orderReductionCart) ; | |||
if($this->orderShopStore->isPositiveAmount($orderShop) | |||
&& $this->isPositiveAmountRemainingToBePaid($orderShop)) { | |||
$this->entityManager->persist($orderReductionCart); | |||
$this->entityManager->flush(); | |||
return $orderReductionCart ; | |||
} | |||
else { | |||
$orderShop->removeOrderReductionCart($orderReductionCart) ; | |||
return false; | |||
} | |||
} | |||
// createOrderReductionCredit | |||
public function addReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit) | |||
{ | |||
$orderReductionCreditFactory = new OrderReductionCreditFactory(); | |||
$orderReductionCredit = $orderReductionCreditFactory->create($orderShop, $reductionCredit); | |||
$orderShop->addOrderReductionCredit($orderReductionCredit) ; | |||
if($this->isOrderShopPositiveAmount($orderShop) | |||
&& $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) { | |||
$this->entityManager->persist($orderReductionCredit); | |||
$this->entityManager->flush(); | |||
return $orderReductionCredit; | |||
} | |||
else { | |||
$orderShop->removeOrderReductionCredit($orderReductionCredit) ; | |||
return false; | |||
} | |||
} | |||
public function deductAvailabilityProduct(OrderShopInterface $orderShop) | |||
{ | |||
// @TODO : à refactorer en plaçant dans src tout ce qui est spécifique à PDL | |||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | |||
//Si ce n'esrt pas une relivraison OU si c'est une relivraison + relivraison + ce n'est pas une erruer producteur | |||
if (!$orderProduct->isRedelivery() || ($orderProduct->isRedelivery() && $orderProduct->isRedeliverySupplierOrder() && !$orderProduct->isRedeliverySupplierMistake())) { | |||
switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) { | |||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE : | |||
//Disponibilité par unité de référence | |||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient())); | |||
$productFamily = $orderProduct->getProduct()->getProductFamily(); | |||
$productFamily->setAvailableQuantity($newAvailability); | |||
$productFamily->setUpdatedBy($orderShop->getUser()); | |||
$this->entityManager->persist($productFamily); | |||
break; | |||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY : | |||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); | |||
$productFamily = $orderProduct->getProduct()->getProductFamily(); | |||
$productFamily->setAvailableQuantity($newAvailability); | |||
$productFamily->setUpdatedBy($orderShop->getUser()); | |||
$this->entityManager->persist($productFamily); | |||
break; | |||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : | |||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); | |||
$product = $orderProduct->getProduct(); | |||
$product->setAvailableQuantity($newAvailability); | |||
$product->setUpdatedBy($orderShop->getUser()); | |||
$this->entityManager->persist($product); | |||
break; | |||
} | |||
$this->entityManager->flush(); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,34 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Builder\User; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\CaracoleBundle\Factory\User\UserPointSaleFactory; | |||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
class UserBuilder | |||
{ | |||
protected EntityManagerInterface $entityManager; | |||
public function __construct(EntityManagerInterface $entityManager) | |||
{ | |||
$this->entityManager = $entityManager; | |||
} | |||
public function linkToPointSale(UserInterface $user, PointSaleInterface $pointSale) | |||
{ | |||
if (!$user->isLinkedToPointSale($pointSale)) { | |||
$userPointSaleFactory = new UserPointSaleFactory(); | |||
$userPointSale = $userPointSaleFactory->create($user, $pointSale); | |||
$this->entityManager->persist($userPointSale); | |||
$this->entityManager->flush(); | |||
return true; | |||
} | |||
return false; | |||
} | |||
} | |||
@@ -0,0 +1,99 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Builder\User; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory; | |||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | |||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||
use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
class UserMerchantBuilder | |||
{ | |||
protected EntityManagerInterface $entityManager; | |||
protected UserMerchantStore $userMerchantStore; | |||
public function __construct( | |||
EntityManagerInterface $entityManager, | |||
UserMerchantStore $userMerchantStore | |||
) { | |||
$this->entityManager = $entityManager; | |||
$this->userMerchantStore = $userMerchantStore; | |||
} | |||
public function createIfNotExist(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface | |||
{ | |||
$userMerchant = $this->userMerchantStore | |||
->setMerchant($merchant) | |||
->getOneByUser($user); | |||
if (!$userMerchant) { | |||
$userMerchantFactory = new UserMerchantFactory(); | |||
$userMerchant = $userMerchantFactory | |||
->setMerchant($merchant) | |||
->create($user); | |||
} | |||
return $userMerchant; | |||
} | |||
public function init(UserInterface $user, MerchantInterface $merchant, bool $active = true, bool $creditActive = false, float $credit = null, bool $persist = true) | |||
{ | |||
$userMerchant = $this->createIfNotExist($user, $merchant); | |||
$userMerchant->setActive($active); | |||
$userMerchant->setCreditActive($creditActive) ; | |||
$userMerchant->setCredit($credit) ; | |||
if($persist) { | |||
$this->entityManager->persist($userMerchant); | |||
$this->entityManager->flush(); | |||
} | |||
return $userMerchant; | |||
} | |||
public function updateCreditActive( | |||
UserInterface $user, | |||
MerchantInterface $merchant, | |||
$creditActive = true | |||
): UserMerchantInterface { | |||
$userMerchant = $this->createIfNotExist($user, $merchant); | |||
$userMerchant->setCreditActive($creditActive); | |||
$this->entityManager->persist($userMerchant); | |||
$this->entityManager->flush(); | |||
return $userMerchant; | |||
} | |||
public function activeCredit(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface | |||
{ | |||
return $this->updateCreditActive($user, $merchant, true); | |||
} | |||
public function unactiveCredit(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface | |||
{ | |||
return $this->updateCreditActive($user, $merchant, false); | |||
} | |||
public function updateCredit( | |||
UserMerchantInterface $userMerchant, | |||
CreditHistoryInterface $creditHistory, | |||
float $amount | |||
): UserMerchantInterface { | |||
$userMerchant->setCredit($amount); | |||
$this->entityManager->persist($creditHistory); | |||
$this->entityManager->persist($userMerchant); | |||
$this->entityManager->flush(); | |||
return $userMerchant; | |||
} | |||
} | |||
@@ -4,14 +4,20 @@ namespace Lc\CaracoleBundle\Factory\Credit; | |||
use App\Entity\Credit\CreditHistory; | |||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | |||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
class CreditHistoryFactory extends AbstractFactory | |||
{ | |||
public function create(): CreditHistoryInterface | |||
// createCreditHistory | |||
public function create(string $type, UserMerchantInterface $userMerchant): CreditHistoryInterface | |||
{ | |||
$creditHistory = new CreditHistory(); | |||
$creditHistory->setType($type) ; | |||
$creditHistory->setUserMerchant($userMerchant) ; | |||
return $creditHistory; | |||
} | |||
@@ -4,14 +4,28 @@ namespace Lc\CaracoleBundle\Factory\Order; | |||
use App\Entity\Order\OrderReductionCart; | |||
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
class OrderReductionCartFactory extends AbstractFactory | |||
{ | |||
public function create(): OrderReductionCartInterface | |||
// createOrderReductionCart | |||
public function create(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart, $code = null): OrderReductionCartInterface | |||
{ | |||
$orderReductionCart = new OrderReductionCart(); | |||
$orderReductionCart->setOrderShop($orderShop); | |||
$orderReductionCart->setReductionCart($reductionCart); | |||
$orderReductionCart->setTitle($reductionCart->getTitle()); | |||
$orderReductionCart->setValue($reductionCart->getValue()); | |||
$orderReductionCart->setUnit($reductionCart->getUnit()); | |||
$orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate()); | |||
$orderReductionCart->setFreeShipping($reductionCart->getFreeShipping()); | |||
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo()); | |||
$orderReductionCart->setType($reductionCart->getType()); | |||
$orderReductionCart->setCodeUsed($code); | |||
return $orderReductionCart; | |||
} | |||
@@ -4,14 +4,24 @@ namespace Lc\CaracoleBundle\Factory\Order; | |||
use App\Entity\Order\OrderReductionCredit; | |||
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
class OrderReductionCreditFactory extends AbstractFactory | |||
{ | |||
public function create(): OrderReductionCreditInterface | |||
public function create(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit): OrderReductionCreditInterface | |||
{ | |||
$orderReductionCredit = new OrderReductionCredit(); | |||
$orderReductionCredit->setOrderShop($orderShop); | |||
$orderReductionCredit->setReductionCredit($reductionCredit); | |||
$orderReductionCredit->setTitle($reductionCredit->getTitle()); | |||
$orderReductionCredit->setValue($reductionCredit->getValue()); | |||
$orderReductionCredit->setUnit($reductionCredit->getUnit()); | |||
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate()); | |||
$orderReductionCredit->setType($reductionCredit->getType()); | |||
return $orderReductionCredit; | |||
} | |||
@@ -3,18 +3,23 @@ | |||
namespace Lc\CaracoleBundle\Factory\User; | |||
use App\Entity\User\UserMerchant; | |||
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait; | |||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
class UserMerchantFactory extends AbstractFactory | |||
{ | |||
use MerchantFactoryTrait; | |||
public function create(MerchantInterface $merchant): UserMerchantInterface | |||
// createUserMerchant | |||
public function create(UserInterface $user): UserMerchantInterface | |||
{ | |||
$userMerchant = new UserMerchant(); | |||
$userMerchant->setMerchant($merchant); | |||
$userMerchant->setMerchant($this->merchant); | |||
$userMerchant->setUser($user); | |||
return $userMerchant; | |||
} |
@@ -0,0 +1,21 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Factory\User; | |||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||
use Lc\CaracoleBundle\Model\User\UserPointSaleInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
class UserPointSaleFactory extends AbstractFactory | |||
{ | |||
public function create(UserInterface $user, PointSaleInterface $pointSale): UserPointSaleInterface | |||
{ | |||
$userPointSale = parent::create(); | |||
$userPointSale->setUser($user); | |||
$userPointSale->setPointSale($pointSale); | |||
return $userPointSale; | |||
} | |||
} |
@@ -110,6 +110,19 @@ abstract class OrderProductModel implements PriceInterface | |||
return $title; | |||
} | |||
// isOrderProductAvailable | |||
public function isAvailable() | |||
{ | |||
return $this->getProduct()->isAvailable($this->getQuantityOrder()); | |||
} | |||
// isOrderProductAvailableAddCart | |||
public function isAvailableAddCart(OrderShopInterface $orderShop = null) | |||
{ | |||
$product = $this->getProduct(); | |||
return $this->isProductAvailable($product, $this->getQuantityOrder(), true, $orderShop); | |||
} | |||
public function getOrderShop(): ?OrderShopInterface | |||
{ | |||
return $this->orderShop; |
@@ -29,6 +29,23 @@ abstract class OrderProductReductionCatalogModel | |||
return $this; | |||
} | |||
// getSummaryOrderProductReductionCatalog | |||
public function getSummary() | |||
{ | |||
$text = ''; | |||
if ($this->getUnit() == 'amount') { | |||
$text .= '- ' . $this->getValue() . ' €'; | |||
} | |||
if ($this->getUnit() == 'percent') { | |||
$text .= '- ' . $this->getValue() . ' %'; | |||
} | |||
return $text; | |||
} | |||
// compareOrderProductReductionCatalog | |||
public function compare($orderProductReductionCatalog) | |||
{ | |||
return $orderProductReductionCatalog |
@@ -11,6 +11,8 @@ use Lc\CaracoleBundle\Model\Address\AddressInterface; | |||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | |||
use Lc\CaracoleBundle\Model\File\DocumentInterface; | |||
use Lc\CaracoleBundle\Model\File\DocumentModel; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | |||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | |||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||
use Lc\SovBundle\Model\Ticket\TicketInterface; | |||
use Lc\CaracoleBundle\Model\User\VisitorInterface; | |||
@@ -188,26 +190,48 @@ abstract class OrderShopModel extends AbstractLightEntity implements FilterSecti | |||
public function hasOrderProductAlreadyInCart($orderProductTest) | |||
{ | |||
foreach($this->getOrderProducts() as $orderProduct) { | |||
if($orderProduct->getProduct() == $orderProductTest->getProduct()) { | |||
return $orderProduct ; | |||
foreach ($this->getOrderProducts() as $orderProduct) { | |||
if ($orderProduct->getProduct() == $orderProductTest->getProduct()) { | |||
return $orderProduct; | |||
} | |||
} | |||
return false ; | |||
return false; | |||
} | |||
public function getOrderProductsByProductFamily($productFamily) | |||
{ | |||
$arrayOrderProducts = [] ; | |||
$arrayOrderProducts = []; | |||
foreach($this->getOrderProducts() as $orderProduct) { | |||
if($orderProduct->getProduct()->getProductFamily() == $productFamily) { | |||
$arrayOrderProducts[] = $orderProduct ; | |||
foreach ($this->getOrderProducts() as $orderProduct) { | |||
if ($orderProduct->getProduct()->getProductFamily() == $productFamily) { | |||
$arrayOrderProducts[] = $orderProduct; | |||
} | |||
} | |||
return $arrayOrderProducts ; | |||
return $arrayOrderProducts; | |||
} | |||
public function getQuantityOrderByProduct(ProductInterface $product, $byWeight = false) | |||
{ | |||
$quantity = 0; | |||
$productFamily = $product->getProductFamily(); | |||
$behaviorCountStock = $productFamily->getBehaviorCountStock(); | |||
foreach ($this->getOrderProducts() as $orderProduct) { | |||
if ($orderProduct->getProduct()->getId() == $product->getId() | |||
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) | |||
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { | |||
if ($byWeight) { | |||
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct( | |||
) / $orderProduct->getProduct()->getUnitInherited()->getCoefficient()); | |||
} else { | |||
$quantity += $orderProduct->getQuantityOrder(); | |||
} | |||
} | |||
} | |||
return $quantity; | |||
} | |||
public function getValidationDate(): ?\DateTimeInterface |
@@ -8,6 +8,7 @@ use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait; | |||
use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface; | |||
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; | |||
use Gedmo\Mapping\Annotation as Gedmo; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\SovBundle\Doctrine\Extension\SortableInterface; | |||
use Lc\SovBundle\Doctrine\Extension\SortableTrait; | |||
use Lc\SovBundle\Doctrine\Extension\StatusTrait; | |||
@@ -74,6 +75,117 @@ abstract class ProductModel extends AbstractLightEntity implements SortableInter | |||
return $title; | |||
} | |||
public function isProductSaleStatusOn() | |||
{ | |||
if ($this->getProductFamily()->getSaleStatus() != 1) { | |||
return false; | |||
} | |||
$allCategoriesSalesOff = true; | |||
$unavailableSpecificDay = false; | |||
foreach ($this->getProductFamily()->getProductCategories() as $category) { | |||
if ($category->getParent()) { | |||
if ($category->getSaleStatus() && $category->getParent()->getSaleStatus()) { | |||
$allCategoriesSalesOff = false; | |||
} | |||
} else { | |||
if ($category->getSaleStatus()) { | |||
$allCategoriesSalesOff = false; | |||
} | |||
} | |||
// specific day | |||
// @TODO : spécifique pdl ? | |||
$displaySpecificDay = $category->getDisplaySpecificDay(); | |||
if ($displaySpecificDay && $displaySpecificDay != date('N')) { | |||
$unavailableSpecificDay = true; | |||
} | |||
} | |||
if ($allCategoriesSalesOff) { | |||
return false; | |||
} | |||
if ($unavailableSpecificDay) { | |||
return false; | |||
} | |||
return true; | |||
} | |||
// isProductAvailable | |||
public function isAvailable($quantityOrder = 0, $checkCart = false, $orderShop = null) | |||
{ | |||
if ($this->getStatus() != 1 || $this->getProductFamily()->getStatus() != 1 || !$this->isProductSaleStatusOn()) { | |||
return false; | |||
} | |||
// @TODO : orderShop à définir où est appelé isProductAvailable | |||
if ($checkCart && !$orderShop) { | |||
throw new \Exception("Attention jeune padawan : définir le orderShop à l'endroit où est appelé isProductAvailable"); | |||
} | |||
$productFamily = $this->getProductFamily(); | |||
$quantityAsked = $quantityOrder; | |||
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
if (!$quantityOrder) { | |||
$quantityAsked = $orderShop->getQuantityOrderByProduct($this, true); | |||
} else { | |||
$quantityAsked = ($this->getQuantityInherited() / $this->getUnitInherited()->getCoefficient()) * $quantityOrder; | |||
} | |||
if ($checkCart) { | |||
$quantityAsked += $orderShop->getQuantityOrderByProduct($this, true); | |||
} | |||
} | |||
if (($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY | |||
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) { | |||
if (!$quantityOrder) { | |||
$quantityAsked = $orderShop->getQuantityOrderByProduct($this); | |||
} | |||
if ($checkCart) { | |||
$quantityAsked += $orderShop->getQuantityOrderByProduct($this); | |||
} | |||
} | |||
if ($this->getAvailableQuantityInherited() >= $quantityAsked | |||
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
// getProductQuantityMaxAddCart | |||
public function getQuantityMaxAddCart(OrderShopInterface $orderShop) | |||
{ | |||
$productFamily = $this->getProductFamily(); | |||
$byWeight = false; | |||
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
$byWeight = true; | |||
} | |||
return $this->getAvailableQuantityInherited() - $orderShop->getQuantityOrderByProduct($this, $byWeight); | |||
} | |||
// getProductQuantity | |||
public function getProductQuantity() | |||
{ | |||
$productFamily = $this->getProductFamily(); | |||
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
return $this->getQuantityInherited() / $this->getUnitInherited()->getCoefficient(); | |||
} else { | |||
return 1; | |||
} | |||
} | |||
public function getBuyingPriceInherited() | |||
{ | |||
if ($this->getBuyingPrice()) { |
@@ -19,6 +19,7 @@ use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||
use Lc\SovBundle\Doctrine\Extension\StatusInterface; | |||
use Lc\SovBundle\Doctrine\Extension\StatusTrait; | |||
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
@@ -99,6 +100,41 @@ abstract class ReductionCartModel extends AbstractLightEntity implements Reducti | |||
$this->uncombinables = new ArrayCollection(); | |||
} | |||
// isReductionCartMatchWithUser | |||
public function matchWithUser(UserInterface $user) | |||
{ | |||
$conditionUser = false; | |||
if ($user) { | |||
if ($this->getUsers()->isEmpty() || $this->getUsers()->contains($user)) { | |||
$conditionUser = true; | |||
} | |||
} | |||
return $conditionUser; | |||
} | |||
// isReductionCartMatchWithGroupUser | |||
public function matchWithGroupUser(UserInterface $user) | |||
{ | |||
$conditionGroupUser = false; | |||
if ($user) { | |||
if ($user->getGroupUsers() && count($user->getGroupUsers()) > 0) { | |||
foreach ($user->getGroupUsers() as $groupUser) { | |||
if ($this->getGroupUsers()->isEmpty() || $this->getGroupUsers()->contains($groupUser)) { | |||
$conditionGroupUser = true; | |||
} | |||
} | |||
} else { | |||
if ($reductionCart->getGroupUsers()->isEmpty()) { | |||
$conditionGroupUser = true; | |||
} | |||
} | |||
} | |||
return $conditionGroupUser; | |||
} | |||
public function getTitle(): ?string | |||
{ |
@@ -7,6 +7,7 @@ use Doctrine\Common\Collections\Collection; | |||
use Doctrine\ORM\Mapping as ORM; | |||
use Gedmo\Mapping\Annotation as Gedmo; | |||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | |||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||
@@ -67,7 +68,6 @@ abstract class UserModel extends SovUserModel | |||
protected $newsletters; | |||
/** | |||
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface") | |||
*/ | |||
@@ -129,6 +129,18 @@ abstract class UserModel extends SovUserModel | |||
return (string)ucfirst(strtolower($this->getFirstname())) . ' ' . strtoupper($this->getLastname()); | |||
} | |||
// isUserLinkedToPointSale | |||
public function isLinkedToPointSale(PointSaleInterface $pointSale) | |||
{ | |||
foreach ($this->getUserPointSales() as $userPointSale) { | |||
if ($userPointSale->getPointSale()->getId() == $pointSale->getId()) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
public function getPhone(): ?string | |||
{ | |||
return $this->phone; |
@@ -0,0 +1,114 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Notification; | |||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; | |||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Twig\Environment; | |||
class MailMailjetNotification | |||
{ | |||
const SUBJECT = 'subject'; | |||
const SUBJECT_PREFIX = 'subject-prefix'; | |||
const TO_EMAIL = 'to-email'; | |||
const COPY_TO = 'copy-to'; | |||
const COPY_HIDDEN_TO = 'copy-hidden-to'; | |||
const TO_NAME = 'to-name'; | |||
const FROM_EMAIL = 'from-email'; | |||
const FROM_NAME = 'from-name'; | |||
const REPLY_TO = 'reply-to'; | |||
const CONTENT_TEMPLATE = 'content-template'; | |||
const CONTENT_DATA = 'content-data'; | |||
const ATTACHMENT_DATA = 'attachment-data'; | |||
const ATTACHMENT_FILENAME = 'attachment-filename'; | |||
const ATTACHMENT_CONTENT_TYPE = 'attachment-content-type'; | |||
//const DISPOSITION_NOTIFICATION_TO = 'disposition-notification-to' ; | |||
protected $transport; | |||
protected $templating; | |||
protected $parameterBag; | |||
protected $merchantResolver; | |||
public function __construct( | |||
MailjetTransport $mailjetTransport, | |||
Environment $templating, | |||
ParameterBagInterface $parameterBag, | |||
MerchantResolver $merchantResolver | |||
) { | |||
$this->transport = $mailjetTransport; | |||
$this->templating = $templating; | |||
$this->parameterBag = $parameterBag; | |||
$this->merchantResolver = $merchantResolver; | |||
} | |||
public function send($params = []) | |||
{ | |||
$merchantCurrent = $this->merchantResolver->getCurrent(); | |||
$merchantConfigEmailFrom = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_FROM); | |||
$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL])) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom; | |||
$merchantConfigEmailFromName = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_FROM_NAME); | |||
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName; | |||
$merchantConfigEmailSubjectPrefix = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_SUBJECT_PREFIX); | |||
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix; | |||
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) { | |||
$emailSubjectPrefix .= ' '; | |||
} | |||
$message = new \Swift_Message($emailSubjectPrefix . $params[self::SUBJECT]); | |||
if ($this->parameterBag->get('mailjet.dev.redirect.active')==1) { | |||
$message->addTo($this->parameterBag->get('mailjet.dev.redirect.email'), | |||
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null); | |||
} else { | |||
$message->addTo( | |||
$params[self::TO_EMAIL], | |||
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null); | |||
} | |||
$contentData = [] ; | |||
if(isset($params[self::CONTENT_DATA])) { | |||
$contentData = $params[self::CONTENT_DATA] ; | |||
} | |||
$message->addFrom($emailFrom, $emailFromName) | |||
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $contentData), 'text/html') | |||
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $contentData)); | |||
if(isset($params[self::COPY_TO]) && strlen($params[self::COPY_TO])) { | |||
$message->addCc($params[self::COPY_TO]); | |||
} | |||
if(isset($params[self::COPY_HIDDEN_TO]) && strlen($params[self::COPY_HIDDEN_TO])) { | |||
$message->addBcc($params[self::COPY_HIDDEN_TO]); | |||
} | |||
if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) { | |||
$message->addReplyTo($params[self::REPLY_TO]); | |||
} | |||
if(isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) { | |||
$message->attach(\Swift_Attachment::newInstance( | |||
$params[self::ATTACHMENT_DATA], | |||
$params[self::ATTACHMENT_FILENAME], | |||
$params[self::ATTACHMENT_CONTENT_TYPE] | |||
)); | |||
} | |||
/*if(isset($params[self::DISPOSITION_NOTIFICATION_TO]) && $params[self::DISPOSITION_NOTIFICATION_TO]) { | |||
$emailFromDispositionNotificationTo = $emailFrom ; | |||
if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) { | |||
$emailFromDispositionNotificationTo = $params[self::REPLY_TO] ; | |||
} | |||
$message->getHeaders()->addTextHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo) ; | |||
$message->getHeaders()->addMailboxHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo); | |||
}*/ | |||
return $this->transport->send($message); | |||
} | |||
} |
@@ -0,0 +1,103 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Notification; | |||
use Lc\SovBundle\Component\StringComponent; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Contracts\HttpClient\HttpClientInterface; | |||
use Twig\Environment; | |||
class SmsFactorNotification | |||
{ | |||
const TO_USER = 'to-user' ; | |||
const CONTENT_MESSAGE = 'content-message' ; | |||
const CONTENT_TEMPLATE = 'content-template' ; | |||
const CONTENT_DATA = 'content-data' ; | |||
protected HttpClientInterface $client; | |||
protected ParameterBagInterface $parameterBag; | |||
protected MailMailjetNotification $mailMailjetNotification ; | |||
protected StringComponent $stringComponent ; | |||
protected Environment $templating ; | |||
public function __construct( | |||
HttpClientInterface $client, | |||
ParameterBagInterface $parameterBag, | |||
MailMailjetNotification $mailMailjetNotification, | |||
StringComponent $stringComponent, | |||
Environment $templating | |||
) { | |||
$this->client = $client; | |||
$this->parameterBag = $parameterBag; | |||
$this->mailMailjetNotification = $mailMailjetNotification ; | |||
$this->stringComponent = $stringComponent ; | |||
$this->templating = $templating ; | |||
} | |||
public function send($params = []) | |||
{ | |||
$user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null ; | |||
if($user) { | |||
$phone = $this->stringComponent->formatPhoneNumber($user->getPhone()) ; | |||
$message = '' ; | |||
if(isset($params[self::CONTENT_MESSAGE])) { | |||
$message = $params[self::CONTENT_MESSAGE] ; | |||
} | |||
elseif(isset($params[self::CONTENT_TEMPLATE])) { | |||
$template = $params[self::CONTENT_TEMPLATE] ; | |||
$paramsTemplate = [] ; | |||
if(isset($params[self::CONTENT_DATA]) && is_array($params[self::CONTENT_DATA])) { | |||
$paramsTemplate = $params[self::CONTENT_DATA] ; | |||
} | |||
$message = $this->templating->render($template, $paramsTemplate) ; | |||
} | |||
if($this->parameterBag->get('mailjet.dev.redirect.active') == 1) { | |||
$this->mailMailjetNotification->send([ | |||
MailMailjetNotification::SUBJECT => 'Notification par SMS à '.$phone, | |||
MailMailjetNotification::TO_EMAIL => $user->getEmail(), | |||
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/notification', | |||
MailMailjetNotification::CONTENT_DATA => [ | |||
'message' => $message | |||
], | |||
]); | |||
return true ; | |||
} | |||
else { | |||
$token = $this->parameterBag->get('smsfactor.token'); | |||
$from = $this->parameterBag->get('smsfactor.from'); | |||
if ($token && strlen($token) > 0) { | |||
$response = $this->client->request( | |||
'GET', | |||
'https://api.smsfactor.com/send', | |||
[ | |||
'headers' => [ | |||
'Authorization' => 'Bearer ' . $token, | |||
'Content-Type' => 'application/json; charset=utf-8', | |||
'Accept' => 'application/json' | |||
], | |||
'query' => [ | |||
'sender' => $from, | |||
'to' => $phone, | |||
'text' => $message, | |||
], | |||
] | |||
); | |||
return $response ; | |||
} | |||
else { | |||
throw new \ErrorException('Le token SMS SmsFactor n\'est pas défini.'); | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -26,6 +26,5 @@ class UnitStore extends AbstractStore | |||
} | |||
return $unitsList; | |||
} | |||
} |
@@ -2,6 +2,8 @@ | |||
namespace Lc\CaracoleBundle\Repository\Order; | |||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
class OrderProductStore extends AbstractStore |
@@ -105,6 +105,7 @@ class OrderShopStore extends AbstractStore | |||
return $orderProductsByProductFamily; | |||
} | |||
// isOrderShopPositiveAmount | |||
public function isPositiveAmount(OrderShopInterface $orderShop) | |||
{ | |||
return $this->priceResolver->getTotalWithTax($orderShop) >= 0; | |||
@@ -145,7 +146,8 @@ class OrderShopStore extends AbstractStore | |||
return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop); | |||
} | |||
public function isOrderShopPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool | |||
// isOrderShopPositiveAmountRemainingToBePaid | |||
public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool | |||
{ | |||
return $this->getTotalRemainingToBePaid($orderShop) > 0; | |||
} |
@@ -2,6 +2,8 @@ | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
class ProductFamilyStore extends AbstractStore | |||
@@ -12,4 +14,15 @@ class ProductFamilyStore extends AbstractStore | |||
{ | |||
$this->query = $query; | |||
} | |||
public function isOneProductAvailableAddCart(array $products): bool | |||
{ | |||
foreach ($products as $product) { | |||
if ($product->isAvailable(1, true)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -2,14 +2,60 @@ | |||
namespace Lc\CaracoleBundle\Repository\Product; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
class ProductStore extends AbstractStore | |||
{ | |||
protected ProductRepositoryQuery $query; | |||
protected PriceResolver $priceResolver; | |||
public function __construct(ProductRepositoryQuery $query) | |||
public function __construct(ProductRepositoryQuery $query, PriceResolver $priceResolver) | |||
{ | |||
$this->query = $query; | |||
$this->priceResolver = $priceResolver; | |||
} | |||
public function getCheapestProduct($productFamily) | |||
{ | |||
$priceResolver = $this->priceResolver; | |||
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceResolver) { | |||
return $priceResolver->getPriceWithTaxAndReduction($a) > $priceResolver->getPriceWithTaxAndReduction($b); | |||
}, true); | |||
} | |||
public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily) | |||
{ | |||
$priceResolver = $this->priceResolver; | |||
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceResolver) { | |||
return $priceResolver->getPriceByRefUnitWithTaxAndReduction($a) > $priceResolver->getPriceByRefUnitWithTaxAndReduction($b); | |||
}, false); | |||
} | |||
public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily) | |||
{ | |||
$priceResolver = $this->priceResolver; | |||
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceResolver) { | |||
return $priceResolver->getPriceByRefUnitWithTaxAndReduction($a) < $priceResolver->getPriceByRefUnitWithTaxAndReduction($b); | |||
}, false); | |||
} | |||
private function getCheapestOrMostExpensiveProduct(ProductFamilyInterface $productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) | |||
{ | |||
if ($productFamily->getActiveProducts()) { | |||
$products = $productFamily->getProductsOnline()->getValues(); | |||
if (count($products) > 0) { | |||
usort($products, $comparisonFunction); | |||
return $products[0]; | |||
} | |||
} else { | |||
return $productFamily->getOriginProduct(); | |||
} | |||
if ($returnSelfIfNotActiveProducts) { | |||
return $productFamily; | |||
} else { | |||
return false; | |||
} | |||
} | |||
} |
@@ -14,4 +14,11 @@ class ReductionCartRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
parent::__construct($repository, 'r', $paginator); | |||
} | |||
public function filterByCode(string $code) | |||
{ | |||
return $this | |||
->andWhere('.codes LIKE :code') | |||
->setParameter('code', '%'.$code.'%') ; | |||
} | |||
} |
@@ -2,14 +2,88 @@ | |||
namespace Lc\CaracoleBundle\Repository\Reduction; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | |||
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
class ReductionCartStore extends AbstractStore | |||
{ | |||
protected ReductionCartRepositoryQuery $query; | |||
protected OrderShopStore $orderShopStore; | |||
public function __construct(ReductionCartRepositoryQuery $query) | |||
{ | |||
public function __construct( | |||
ReductionCartRepositoryQuery $query, | |||
OrderShopStore $orderShopStore | |||
) { | |||
$this->query = $query; | |||
$this->orderShopStore = $orderShopStore; | |||
} | |||
// getReductionCartByCode | |||
public function getByCode(string $code) | |||
{ | |||
$query = $this->query->create(); | |||
$query->filterByCode($code); | |||
$reductionCarts = $query->find(); | |||
$findReductionCart = null; | |||
foreach ($reductionCarts as $reductionCart) { | |||
if ($reductionCart && in_array($code, $reductionCart->getCodes())) { | |||
$findReductionCart = $reductionCart; | |||
} | |||
} | |||
return $findReductionCart; | |||
} | |||
// getReductionCartRemainingQuantity | |||
public function getRemainingQuantity(ReductionCartInterface $reductionCart): float | |||
{ | |||
return $reductionCart->getAvailableQuantity() - $this->orderShopStore->countValidOrderWithReductionCart( | |||
$reductionCart | |||
); | |||
} | |||
// getReductionCartUsedQuantityPerUser | |||
public function getUsedQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float | |||
{ | |||
return $this->orderShopStore->countValidOrderWithReductionCartPerUser($reductionCart, $user); | |||
} | |||
// getReductionCartUsedQuantity | |||
public function getUsedQuantity(ReductionCartInterface $reductionCart): float | |||
{ | |||
return $this->orderShopStore->countValidOrderWithReductionCart($reductionCart); | |||
} | |||
// getReductionCartRemainingQuantityPerUser | |||
public function getRemainingQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float | |||
{ | |||
if ($reductionCart->getAvailableQuantityPerUser()) { | |||
return $reductionCart->getAvailableQuantityPerUser( | |||
) - $this->orderShopRepo->countValidOrderWithReductionCartPerUser($reductionCart, $user); | |||
} | |||
return false; | |||
} | |||
// findAllAvailableForUser / getReductionCartsAvailableByUser | |||
public function getAvailablesByUser(UserInterface $user) | |||
{ | |||
$reductionCarts = $this->query->find(); | |||
$reductionCartsArray = []; | |||
foreach ($reductionCarts as $reductionCart) { | |||
if ($reductionCart->matchWithUser($user) | |||
&& $reductionCart->matchWithGroupUser($user) | |||
&& $this->getRemainingQuantityByUser($reductionCart, $user) | |||
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) { | |||
$reductionCartsArray[] = $reductionCart; | |||
} | |||
} | |||
return $reductionCartsArray; | |||
} | |||
} |
@@ -3,7 +3,9 @@ | |||
namespace Lc\CaracoleBundle\Repository\Reduction; | |||
use Knp\Component\Pager\PaginatorInterface; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; | |||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||
class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery | |||
@@ -14,4 +16,23 @@ class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
parent::__construct($repository, 'r', $paginator); | |||
} | |||
public function filterStatusOnline() | |||
{ | |||
return $this->andWhere('.status = 1'); | |||
} | |||
public function filterByUser(UserInterface $user) | |||
{ | |||
return $this | |||
->andWhere(':user MEMBER OF .users') | |||
->setParameter('user', $user); | |||
} | |||
public function filterByType(string $type = ReductionCreditModel::TYPE_CREDIT) | |||
{ | |||
return $this | |||
->andWhere('.type = :type') | |||
->setParameter('type', $type); | |||
} | |||
} |
@@ -2,14 +2,123 @@ | |||
namespace Lc\CaracoleBundle\Repository\Reduction; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | |||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; | |||
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
class ReductionCreditStore extends AbstractStore | |||
{ | |||
protected ReductionCreditRepositoryQuery $query; | |||
protected OrderShopStore $orderShopStore; | |||
public function __construct(ReductionCreditRepositoryQuery $query) | |||
{ | |||
public function __construct( | |||
ReductionCreditRepositoryQuery $query, | |||
OrderShopStore $orderShopStore | |||
) { | |||
$this->query = $query; | |||
$this->orderShopStore = $orderShopStore; | |||
} | |||
// isReductionCreditAllowAddToOrder | |||
public function isAllowAddToOrder(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit) | |||
{ | |||
$user = $orderShop->getUser(); | |||
// appartient à l'utilisateur | |||
if (!$reductionCredit->getUsers()->contains($user)) { | |||
// @TODO : gérer les addFlash dans le controleur | |||
//$this->utils->addFlash('error', 'error.reductionCredit.userNotAllow'); | |||
return false; | |||
} | |||
// n'a pas été utilisé | |||
if ($reductionCredit->getType() == ReductionCredit::TYPE_CREDIT) { | |||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) { | |||
//$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse'); | |||
return false; | |||
} | |||
} else { | |||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit) > 0) { | |||
//$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse'); | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
// findReductionCreditsByUser | |||
public function getByTypeAndUser(string $type = ReductionCreditModel::TYPE_CREDIT, UserInterface $user) | |||
{ | |||
$query = $this->query->create(); | |||
$query | |||
->filterStatusOnline() | |||
->filterByType($type) | |||
->filterByUser($user); | |||
return $query->find(); | |||
} | |||
public function getReductionCreditsAvailableByUser(UserInterface $user) | |||
{ | |||
$reductionCredits = $this->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user); | |||
$reductionCreditsArray = []; | |||
foreach ($reductionCredits as $reductionCredit) { | |||
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) { | |||
$reductionCreditsArray[] = $reductionCredit; | |||
} | |||
} | |||
return $reductionCreditsArray; | |||
} | |||
public function getReductionGiftsAvailableByUser($user) | |||
{ | |||
$reductionGifts = $this->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user); | |||
$reductionGiftsArray = []; | |||
foreach ($reductionGifts as $reductionGift) { | |||
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) { | |||
$reductionGiftsArray[] = $reductionGift; | |||
} | |||
} | |||
return $reductionGiftsArray; | |||
} | |||
public function isReductionGiftUsed(ReductionCreditInterface $reductionGift) | |||
{ | |||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null) | |||
{ | |||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
public function isReductionCreditAddedToOrder( | |||
OrderShopInterface $orderShop, | |||
ReductionCreditInterface $reductionCredit | |||
) { | |||
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||
if ($orderReductionCredit->getReductionCredit() == $reductionCredit) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Repository\User; | |||
use Knp\Component\Pager\PaginatorInterface; | |||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||
class UserMerchantRepositoryQuery extends AbstractRepositoryQuery | |||
@@ -14,4 +15,11 @@ class UserMerchantRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
parent::__construct($repository, 'r', $paginator); | |||
} | |||
public function filterByUser(UserInterface $user) | |||
{ | |||
return $this | |||
->andWhere('.user = :user') | |||
->setParameter('user', $user); | |||
} | |||
} |
@@ -2,14 +2,56 @@ | |||
namespace Lc\CaracoleBundle\Repository\User; | |||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||
use Lc\SovBundle\Model\User\UserInterface; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
class UserMerchantStore extends AbstractStore | |||
{ | |||
use MerchantStoreTrait; | |||
protected UserMerchantRepositoryQuery $query; | |||
public function __construct(UserMerchantRepositoryQuery $query) | |||
{ | |||
$this->query = $query; | |||
} | |||
// getUserMerchant | |||
public function getOneByUser(UserInterface $user) | |||
{ | |||
$query = $this->query->create(); | |||
$query | |||
->filterByMerchant($this->merchant) | |||
->filterByUser($user); | |||
return $query->findOne(); | |||
} | |||
public function isCreditActive(UserMerchantInterface $userMerchant = null) | |||
{ | |||
if (!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) { | |||
return false; | |||
} | |||
return true; | |||
} | |||
public function isCreditActiveByUser(UserInterface $user) | |||
{ | |||
$userMerchant = $this->getOneByUser($user); | |||
return $this->isCreditActive($userMerchant); | |||
} | |||
public function isCreditSufficientToPay(UserMerchantInterface $userMerchant, float $amount) | |||
{ | |||
if ($this->isCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) { | |||
return true; | |||
} | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\User; | |||
use App\Entity\User\UserPointSale; | |||
use Doctrine\Persistence\ManagerRegistry; | |||
use Lc\SovBundle\Repository\AbstractRepository; | |||
class UserPointSaleRepository extends AbstractRepository | |||
{ | |||
public function __construct(ManagerRegistry $registry) | |||
{ | |||
parent::__construct($registry, UserPointSale::class); | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\User; | |||
use Knp\Component\Pager\PaginatorInterface; | |||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||
class UserPointSaleRepositoryQuery extends AbstractRepositoryQuery | |||
{ | |||
public function __construct(UserPointSaleRepository $repository, PaginatorInterface $paginator) | |||
{ | |||
parent::__construct($repository, 'r', $paginator); | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\User; | |||
use Lc\SovBundle\Repository\AbstractStore; | |||
class UserPointSaleStore extends AbstractStore | |||
{ | |||
protected UserPointSaleRepositoryQuery $query; | |||
public function __construct(UserPointSaleRepositoryQuery $query) | |||
{ | |||
$this->query = $query; | |||
} | |||
} |