use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel; | use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel; | ||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | ||||
use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | ||||
use Lc\CaracoleBundle\Solver\Credit\CreditHistorySolver; | |||||
use Lc\CaracoleBundle\Solver\User\UserMerchantSolver; | |||||
class CreditHistoryBuilder | class CreditHistoryBuilder | ||||
{ | { | ||||
protected CreditHistoryFactory $creditHistoryFactory; | protected CreditHistoryFactory $creditHistoryFactory; | ||||
protected CreditHistorySolver $creditHistorySolver; | |||||
protected UserMerchantSolver $userMerchantSolver; | |||||
protected UserMerchantStore $userMerchantStore; | protected UserMerchantStore $userMerchantStore; | ||||
protected UserMerchantBuilder $userMerchantBuilder; | protected UserMerchantBuilder $userMerchantBuilder; | ||||
public function __construct( | public function __construct( | ||||
CreditHistoryFactory $creditHistoryFactory, | CreditHistoryFactory $creditHistoryFactory, | ||||
CreditHistorySolver $creditHistorySolver, | |||||
UserMerchantStore $userMerchantStore, | UserMerchantStore $userMerchantStore, | ||||
UserMerchantBuilder $userMerchantBuilder | |||||
UserMerchantBuilder $userMerchantBuilder, | |||||
UserMerchantSolver $userMerchantSolver | |||||
) { | ) { | ||||
$this->creditHistoryFactory = $creditHistoryFactory; | $this->creditHistoryFactory = $creditHistoryFactory; | ||||
$this->creditHistorySolver = $creditHistorySolver; | |||||
$this->userMerchantStore = $userMerchantStore; | $this->userMerchantStore = $userMerchantStore; | ||||
$this->userMerchantBuilder = $userMerchantBuilder; | $this->userMerchantBuilder = $userMerchantBuilder; | ||||
$this->userMerchantSolver = $userMerchantSolver; | |||||
} | } | ||||
public function create( | public function create( | ||||
// saveCreditHistory | // saveCreditHistory | ||||
public function save(CreditHistoryInterface $creditHistory): bool | public function save(CreditHistoryInterface $creditHistory): bool | ||||
{ | { | ||||
if ($creditHistory) { | |||||
$userMerchant = $creditHistory->getUserMerchant(); | |||||
$isCreditActive = $this->userMerchantStore->isCreditActive($userMerchant); | |||||
$amount = $this->creditHistorySolver->getAmountInherited($creditHistory); | |||||
$userMerchant = $creditHistory->getUserMerchant(); | |||||
$isCreditActive = $this->userMerchantSolver->isCreditActive($userMerchant); | |||||
if ($isCreditActive) { | |||||
if ($creditHistory->getType() == CreditHistoryModel::TYPE_CREDIT) { | |||||
$userMerchantAmount = $userMerchant->getCredit() + $creditHistory->getAmountInherited(); | |||||
if ($isCreditActive) { | |||||
if ($creditHistory->getType() == CreditHistoryModel::TYPE_CREDIT) { | |||||
$userMerchantAmount = $userMerchant->getCredit() + $amount; | |||||
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount); | |||||
return true; | |||||
} elseif ($creditHistory->getType() == CreditHistoryModel::TYPE_DEBIT) { | |||||
if ($this->userMerchantSolver->isCreditSufficientToPay( | |||||
$userMerchant, | |||||
$amount | |||||
)) { | |||||
$userMerchantAmount = $userMerchant->getCredit() - $amount; | |||||
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount); | $this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount); | ||||
return true; | 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; | |||||
} | |||||
} else { | |||||
return false; | |||||
} | } | ||||
} | } | ||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Builder\Reduction; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\CaracoleBundle\Factory\Reduction\ReductionCreditFactory; | |||||
use Lc\CaracoleBundle\Model\Config\TaxRateModel; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; | |||||
use Lc\CaracoleBundle\Repository\Order\OrderProductStore; | |||||
use Lc\CaracoleBundle\Repository\Section\SectionStore; | |||||
use Lc\CaracoleBundle\Solver\Price\PriceSolver; | |||||
use Lc\CaracoleBundle\Solver\User\UserSolver; | |||||
use Lc\SovBundle\Notification\MailMailjetNotification; | |||||
class ReductionCreditBuilder | |||||
{ | |||||
protected EntityManagerInterface $entityManager; | |||||
protected OrderProductStore $orderProductStore; | |||||
protected ReductionCreditFactory $reductionCreditFactory; | |||||
protected PriceSolver $priceSolver; | |||||
protected MailMailjetNotification $mailMailjetNotification; | |||||
protected UserSolver $userSolver; | |||||
protected SectionStore $sectionStore; | |||||
public function __construct( | |||||
EntityManagerInterface $entityManager, | |||||
OrderProductStore $orderProductStore, | |||||
ReductionCreditFactory $reductionCreditFactory, | |||||
PriceSolver $priceSolver, | |||||
MailMailjetNotification $mailMailjetNotification, | |||||
UserSolver $userSolver, | |||||
SectionStore $sectionStore | |||||
) { | |||||
$this->entityManager = $entityManager; | |||||
$this->orderProductStore = $orderProductStore; | |||||
$this->reductionCreditFactory = $reductionCreditFactory; | |||||
$this->priceSolver = $priceSolver; | |||||
$this->mailMailjetNotification = $mailMailjetNotification; | |||||
$this->userSolver = $userSolver; | |||||
$this->sectionStore = $sectionStore; | |||||
} | |||||
// generateReductionGiftFormOrderShop | |||||
public function createReductionGiftFormOrderShop(OrderShopInterface $orderShop) | |||||
{ | |||||
$user = $orderShop->getUser(); | |||||
$orderProductsGiftVouchers = $this->orderProductStore->getGiftVouchersByOrder($orderShop); | |||||
$sectionMarket = $this->sectionStore | |||||
->setMerchant($orderShop->getSection()->getMerchant()) | |||||
->getOneMarket(); | |||||
foreach ($orderProductsGiftVouchers as $orderProductsGiftVoucher) { | |||||
$i = 1; | |||||
// création de la reductionCredit | |||||
while ($i <= $orderProductsGiftVoucher->getQuantityOrder()) { | |||||
$reductionGift = $this->reductionCreditFactory->create($sectionMarket, ReductionCreditModel::TYPE_GIFT); | |||||
$reductionGift->setTitle($orderProductsGiftVoucher->getTitle()); | |||||
$reductionGift->setOwner($user); | |||||
$reductionGift->setCreatedBy($user); | |||||
$reductionGift->setUpdatedBy($user); | |||||
$reductionGift->setValue($this->priceSolver->getPriceWithTax($orderProductsGiftVoucher->getProduct())); | |||||
$reductionGift->setBehaviorTaxRate(TaxRateModel::BEHAVIOR_TAX_RATE_INCLUDED); | |||||
$this->entityManager->persist($reductionGift); | |||||
$i++; | |||||
} | |||||
} | |||||
$this->entityManager->flush(); | |||||
if (count($orderProductsGiftVouchers) > 0) { | |||||
$this->mailMailjetNotification->send([ | |||||
MailMailjetNotification::SUBJECT => 'Comment offrir votre bon cadeau ?', | |||||
MailMailjetNotification::TO_EMAIL => $user->getEmail(), | |||||
MailMailjetNotification::TO_NAME => $this->userSolver->getName($user), | |||||
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/how-to-offer-gift-voucher' | |||||
]); | |||||
} | |||||
} | |||||
} |
CaracoleBundle |
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery; | use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery; | ||||
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; | use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; | ||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | use Lc\CaracoleBundle\Resolver\MerchantResolver; | ||||
use Lc\CaracoleBundle\Solver\Merchant\MerchantSolver; | |||||
use Lc\SovBundle\Solver\Setting\SettingSolver; | use Lc\SovBundle\Solver\Setting\SettingSolver; | ||||
class MerchantContainer | class MerchantContainer | ||||
{ | { | ||||
protected MerchantFactory $factory; | protected MerchantFactory $factory; | ||||
protected MerchantSolver $solver; | |||||
protected MerchantBuilder $builder; | protected MerchantBuilder $builder; | ||||
protected MerchantResolver $resolver; | protected MerchantResolver $resolver; | ||||
protected MerchantRepositoryQuery $repositoryQuery; | protected MerchantRepositoryQuery $repositoryQuery; | ||||
public function __construct( | public function __construct( | ||||
MerchantFactory $factory, | MerchantFactory $factory, | ||||
MerchantSolver $solver, | |||||
MerchantBuilder $builder, | MerchantBuilder $builder, | ||||
MerchantResolver $resolver, | MerchantResolver $resolver, | ||||
MerchantRepositoryQuery $repositoryQuery, | MerchantRepositoryQuery $repositoryQuery, | ||||
MerchantStore $store | MerchantStore $store | ||||
) { | ) { | ||||
$this->factory = $factory; | $this->factory = $factory; | ||||
$this->solver = $solver; | |||||
$this->builder = $builder; | $this->builder = $builder; | ||||
$this->resolver = $resolver; | $this->resolver = $resolver; | ||||
$this->repositoryQuery = $repositoryQuery; | $this->repositoryQuery = $repositoryQuery; | ||||
return $this->factory; | return $this->factory; | ||||
} | } | ||||
public function getSolver(): MerchantSolver | |||||
{ | |||||
return $this->solver; | |||||
} | |||||
public function getResolver(): MerchantResolver | public function getResolver(): MerchantResolver | ||||
{ | { | ||||
return $this->resolver; | return $this->resolver; |
use Lc\CaracoleBundle\Context\MerchantContextTrait; | use Lc\CaracoleBundle\Context\MerchantContextTrait; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | use Lc\CaracoleBundle\Model\Section\SectionInterface; | ||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
class ReductionCreditFactory extends AbstractFactory | class ReductionCreditFactory extends AbstractFactory | ||||
{ | { | ||||
public function create(SectionInterface $section): ReductionCreditInterface | |||||
public function create(SectionInterface $section, string $type = ReductionCreditModel::TYPE_CREDIT): ReductionCreditInterface | |||||
{ | { | ||||
$reductionCredit = new ReductionCredit(); | $reductionCredit = new ReductionCredit(); | ||||
$reductionCredit->setSection($section); | $reductionCredit->setSection($section); | ||||
$reductionCredit->setType($type); | |||||
$reductionCredit->setStatus(1); | |||||
return $reductionCredit; | return $reductionCredit; | ||||
} | } |
namespace Lc\CaracoleBundle\Repository\Order; | namespace Lc\CaracoleBundle\Repository\Order; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | 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; | ||||
return $query; | return $query; | ||||
} | } | ||||
//findOrderProductsInCartsByProduct | |||||
// findGiftVouchersByOrder | |||||
public function getGiftVouchersByOrder(OrderShopInterface $orderShop): array | |||||
{ | |||||
$query = $this->createQuery(); | |||||
$query | |||||
->filterByOrderShop($orderShop) | |||||
->filterIsGiftVoucherActive(); | |||||
return $query->find(); | |||||
} | |||||
// findOrderProductsInCartsByProduct | |||||
public function getInCartsByProduct(ProductInterface $product, $query = null): array | public function getInCartsByProduct(ProductInterface $product, $query = null): array | ||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); |
{ | { | ||||
use SectionRepositoryQueryTrait; | use SectionRepositoryQueryTrait; | ||||
protected $isJoinUsers = false; | |||||
public function __construct(ReductionCreditRepository $repository, PaginatorInterface $paginator) | public function __construct(ReductionCreditRepository $repository, PaginatorInterface $paginator) | ||||
{ | { | ||||
parent::__construct($repository, 'r', $paginator); | parent::__construct($repository, 'r', $paginator); | ||||
->andWhere('.type = :type') | ->andWhere('.type = :type') | ||||
->setParameter('type', $type); | ->setParameter('type', $type); | ||||
} | } | ||||
public function filterInactive() | |||||
{ | |||||
$this->joinUsers(); | |||||
return $this->having('COUNT(users.id) = 0'); | |||||
} | |||||
public function filterActive() | |||||
{ | |||||
$this->joinUsers(); | |||||
return $this->having('COUNT(users.id) > 0'); | |||||
} | |||||
public function joinUsers() | |||||
{ | |||||
return $this->leftJoin('.users', 'users'); | |||||
} | |||||
} | } |
public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface | ||||
{ | { | ||||
if($this->section) { | |||||
$query->filterBySection($this->section); | |||||
} | |||||
if(isset($this->merchant) && $this->merchant) { | |||||
$query->filterByMerchantViaSection($this->merchant); | |||||
} | |||||
$this->addFilterBySectionOptionnal($query); | |||||
$this->addFilterByMerchantViaSectionOptionnal($query); | |||||
$query->filterIsOnlineAndOffline(); | $query->filterIsOnlineAndOffline(); | ||||
// findReductionGiftToUseByUser | // findReductionGiftToUseByUser | ||||
public function getReductionGiftToUseByUser(UserInterface $user, $query = null) | public function getReductionGiftToUseByUser(UserInterface $user, $query = null) | ||||
{ | { | ||||
/// @TODO : à écrire | |||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query->filterByUser($user); | $query->filterByUser($user); | ||||
return $query->find(); | return $query->find(); | ||||
// findReductionGiftOwnedByUser | // findReductionGiftOwnedByUser | ||||
public function getReductionGiftOwnedByUser(UserInterface $user, $query = null) | public function getReductionGiftOwnedByUser(UserInterface $user, $query = null) | ||||
{ | { | ||||
/// @TODO : à écrire | |||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query->filterByOwner($user); | |||||
$query | |||||
->filterByOwner($user) | |||||
->filterInactive(); | |||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
// findReductionGiftOwnedActiveByUser | // findReductionGiftOwnedActiveByUser | ||||
public function getReductionGiftOwnedActiveByUser(UserInterface $user, $query = null) | public function getReductionGiftOwnedActiveByUser(UserInterface $user, $query = null) | ||||
{ | { | ||||
/// @TODO : à écrire | |||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query->filterByOwner($user); | |||||
$query | |||||
->filterByOwner($user) | |||||
->filterActive(); | |||||
return $query->find(); | return $query->find(); | ||||
} | } | ||||
<?php | |||||
namespace Lc\CaracoleBundle\Solver\Merchant; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
class MerchantSolver | |||||
{ | |||||
public function getNewsletters(MerchantInterface $merchant): array | |||||
{ | |||||
$newsletterArray = []; | |||||
foreach($merchant->getSections() as $section) { | |||||
foreach($section->getNewsletters() as $newsletter) { | |||||
$newsletterArray[] = $newsletter; | |||||
} | |||||
} | |||||
return $newsletterArray; | |||||
} | |||||
} |