@@ -459,7 +459,6 @@ class OrderController extends AdminController | |||
$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView(); | |||
break; | |||
case OrderStatus::ALIAS_ERROR_PAYMENT_ONLINE : | |||
case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT : | |||
case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE : | |||
$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView(); | |||
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); | |||
@@ -467,8 +466,7 @@ class OrderController extends AdminController | |||
$parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); | |||
$parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); | |||
break; | |||
case OrderStatus::ALIAS_PAID_BY_CREDIT : | |||
case OrderStatus::ALIAS_PAID_ONLINE : | |||
case OrderStatus::ALIAS_PAID : | |||
case OrderStatus::ALIAS_WAITING_DELIVERY : | |||
case OrderStatus::ALIAS_WAITING_BANK_RETURN : | |||
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); |
@@ -50,8 +50,8 @@ class EntityManager | |||
if(method_exists($entity, 'setUpdatedBy')) { | |||
$entity->setUpdatedBy($this->getUserSystem()); | |||
} | |||
if(method_exists($entity, 'setCreadtedBy')) { | |||
$entity->setCreadtedBy($this->getUserSystem()); | |||
if(method_exists($entity, 'setCreatedBy')) { | |||
$entity->setCreatedBy($this->getUserSystem()); | |||
} | |||
} | |||
@@ -79,6 +79,13 @@ class EntityManager | |||
return $this; | |||
} | |||
public function remove($entity): self | |||
{ | |||
$this->entityManager->remove($entity) ; | |||
return $this ; | |||
} | |||
public function flush(): self | |||
{ | |||
$this->entityManager->flush(); | |||
@@ -93,18 +100,28 @@ class EntityManager | |||
return $this; | |||
} | |||
protected function persist($entity) | |||
public function persist($entity) | |||
{ | |||
$this->entityManager->persist($entity); | |||
} | |||
public function refresh($entity) | |||
{ | |||
$this->entityManager->refresh($entity); | |||
} | |||
public function getClassMetadata($className) | |||
{ | |||
return $this->entityManager->getClassMetadata($className) ; | |||
} | |||
public function getEntityName($className) | |||
{ | |||
if (substr($className, -9) === 'Interface') { | |||
return $this->entityManager->getClassMetadata($className)->getName(); | |||
} else { | |||
} | |||
else { | |||
return $className; | |||
} | |||
} | |||
} |
@@ -14,11 +14,10 @@ abstract class OrderStatus | |||
const ALIAS_CART = 'cart' ; | |||
const ALIAS_CART_CANCELED = 'cart-canceled' ; | |||
const ALIAS_WAITING_PAYMENT_ONLINE = 'waiting-payment-online' ; | |||
const ALIAS_WAITING_PAYMENT_CREDIT = 'waiting-payment-credit' ; | |||
const ALIAS_WAITING_BANK_RETURN = 'waiting-bank-return' ; | |||
const ALIAS_PAID_ONLINE = 'paid-online' ; | |||
const ALIAS_PARTIAL_PAYMENT = 'partial-payment' ; | |||
const ALIAS_PAID = 'paid' ; | |||
const ALIAS_ERROR_PAYMENT_ONLINE = 'error-payment-online' ; | |||
const ALIAS_PAID_BY_CREDIT = 'paid-by-credit' ; | |||
const ALIAS_WAITING_DELIVERY = 'waiting-delivery' ; | |||
const ALIAS_WAITING_DELIVERY_WITH_PAYMENT = 'waiting-delivery-with-payment' ; | |||
const ALIAS_DELIVERED_WITHOUT_PAYMENT = 'delivered-without-payment' ; | |||
@@ -30,8 +29,7 @@ abstract class OrderStatus | |||
//TODO : AJOUTER un champ valid ds orderSTATUS | |||
static $statusAliasAsValid = [ | |||
self::ALIAS_PAID_ONLINE, | |||
self::ALIAS_PAID_BY_CREDIT, | |||
self::ALIAS_PAID, | |||
self::ALIAS_WAITING_DELIVERY, | |||
self::ALIAS_WAITING_BANK_RETURN, | |||
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, | |||
@@ -46,8 +44,8 @@ abstract class OrderStatus | |||
static $statusAliasAsCart = [ | |||
self::ALIAS_CART, | |||
self::ALIAS_PARTIAL_PAYMENT, | |||
self::ALIAS_WAITING_PAYMENT_ONLINE, | |||
self::ALIAS_WAITING_PAYMENT_CREDIT, | |||
self::ALIAS_ERROR_PAYMENT_ONLINE | |||
]; | |||
@@ -98,6 +98,8 @@ group: | |||
listLoopBesancon: Adresses de Besançon à spécifier (lat / long) | |||
User: | |||
item: Utilisateur | |||
Notification: | |||
main: Notifications | |||
@@ -141,10 +143,11 @@ error: | |||
deliverySlotMissing: Vous n'avez pas de créneau de livraison | |||
productUnavailable: Certains produits ne sont plus disponibles | |||
nextStatusNotAllow: La commande ne peut passer à ce statut | |||
noPayment: Le montant de la commande n'a pas été règlé dans sa totalité | |||
incompletePayment: Le montant de la commande n'a pas été règlé dans sa totalité | |||
otherOrderAlreadyExist: Une autre commande existe déjà pour cet utilisateur, vous avez été redirigé. | |||
minimumAmountZone: Montant minimum de commande non respecté pour cette zone | |||
minimumAmountPointSale: Montant minimum de commande non respecté pour ce point de vente | |||
noPayment: Aucun paiement n'a été enregistré pour cette commande | |||
reductionCart: | |||
conditionsError: Cette réduction ne peut pas être appliqué sur cette commande | |||
date: La réduction n'est plus active | |||
@@ -308,6 +311,7 @@ field: | |||
groupUsers: Groupes | |||
ticketTypesNotification: Catégorie ticket | |||
newsletter: Newsletter | |||
isEligibleTicketRestaurant: Éligible ticket restaurant | |||
PointSale: | |||
code: Code |
@@ -8,8 +8,11 @@ | |||
{{ form_row(form.status) }} | |||
</div> | |||
<div class="col-6"> | |||
<label>Status de vente</label> | |||
<label>Statut de vente</label> | |||
{{ form_row(form.saleStatus) }} | |||
<label>Éligible ticket restaurant</label> | |||
{{ form_row(form.isEligibleTicketRestaurant) }} | |||
</div> | |||
<div class="col-12"> |
@@ -31,8 +31,12 @@ class MailUtils | |||
protected $parameterBag; | |||
protected $merchantUtils; | |||
public function __construct(MailjetTransport $mailjetTransport, Environment $templating, ParameterBagInterface $parameterBag, MerchantUtilsInterface $merchantUtils) | |||
{ | |||
public function __construct( | |||
MailjetTransport $mailjetTransport, | |||
Environment $templating, | |||
ParameterBagInterface $parameterBag, | |||
MerchantUtilsInterface $merchantUtils | |||
) { | |||
$this->transport = $mailjetTransport; | |||
$this->templating = $templating; | |||
$this->parameterBag = $parameterBag; | |||
@@ -105,6 +109,6 @@ class MailUtils | |||
$message->getHeaders()->addMailboxHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo); | |||
}*/ | |||
$this->transport->send($message); | |||
return $this->transport->send($message); | |||
} | |||
} |
@@ -5,28 +5,55 @@ namespace Lc\ShopBundle\Services; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\HttpFoundation\ParameterBag; | |||
use Symfony\Contracts\HttpClient\HttpClientInterface; | |||
use Twig\Environment; | |||
class MailjetSMS | |||
class MailjetSmsUtils | |||
{ | |||
const TO_USER = 'to-user' ; | |||
const CONTENT_MESSAGE = 'content-message' ; | |||
const CONTENT_TEMPLATE = 'content-template' ; | |||
const CONTENT_DATA = 'content-data' ; | |||
protected $client; | |||
protected $parameterBag; | |||
protected $mailUtils ; | |||
protected $utils ; | |||
protected $templating ; | |||
public function __construct(HttpClientInterface $client, ParameterBagInterface $parameterBag, UtilsManager $utilsManager) | |||
{ | |||
public function __construct( | |||
HttpClientInterface $client, | |||
ParameterBagInterface $parameterBag, | |||
MailUtils $mailUtils, | |||
Utils $utils, | |||
Environment $templating | |||
) { | |||
$this->client = $client; | |||
$this->parameterBag = $parameterBag; | |||
$this->mailUtils = $utilsManager->getMailUtils() ; | |||
$this->utils = $utilsManager->getUtils() ; | |||
$this->mailUtils = $mailUtils ; | |||
$this->utils = $utils ; | |||
$this->templating = $templating ; | |||
} | |||
public function send($user, $message) | |||
public function send($params = []) | |||
{ | |||
$user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null ; | |||
if($user) { | |||
$phone = $this->utils->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->mailUtils->send([ | |||
MailUtils::SUBJECT => 'Notification par SMS à '.$phone, |
@@ -4,7 +4,7 @@ namespace Lc\ShopBundle\Services\Order; | |||
use App\Entity\OrderProductReductionCatalog; | |||
use App\Entity\OrderShop; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use App\Entity\OrderStatus; | |||
use Lc\ShopBundle\Context\DocumentInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\OrderReductionCreditInterface; | |||
@@ -16,6 +16,7 @@ use Lc\ShopBundle\Context\ReductionCreditInterface; | |||
use Lc\ShopBundle\Context\SectionInterface; | |||
use Lc\ShopBundle\Context\SectionUtilsInterface; | |||
use Lc\ShopBundle\Context\UserUtilsInterface; | |||
use Lc\ShopBundle\Manager\EntityManager; | |||
use Lc\ShopBundle\Model\ProductFamily; | |||
use Lc\ShopBundle\Services\CreditUtils; | |||
use Lc\ShopBundle\Services\DocumentUtils; | |||
@@ -50,18 +51,28 @@ class OrderUtils | |||
protected $router; | |||
protected $sectionUtils ; | |||
public function __construct(EntityManagerInterface $em, Security $security, RouterInterface $router, UserUtilsInterface $userUtils, | |||
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils, | |||
DocumentUtils $documentUtils, Utils $utils, CreditUtils $creditUtils, SectionUtilsInterface $sectionUtils) | |||
public function __construct( | |||
EntityManager $em, | |||
Security $security, | |||
RouterInterface $router, | |||
UserUtilsInterface $userUtils, | |||
MerchantUtilsInterface $merchantUtils, | |||
PriceUtilsInterface $priceUtils, | |||
ProductFamilyUtilsInterface $productFamilyUtils, | |||
DocumentUtils $documentUtils, | |||
Utils $utils, | |||
CreditUtils $creditUtils, | |||
SectionUtilsInterface $sectionUtils | |||
) | |||
{ | |||
$this->em = $em; | |||
$this->security = $security; | |||
$this->userUtils = $userUtils; | |||
$this->merchantUtils = $merchantUtils; | |||
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName()); | |||
$this->reductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(ReductionCreditInterface::class)->getName()); | |||
$this->orderReductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCreditInterface::class)->getName()); | |||
$this->documentRepo = $this->em->getRepository($this->em->getClassMetadata(DocumentInterface::class)->getName()); | |||
$this->orderShopRepo = $this->em->getRepository($this->em->getEntityName(OrderShopInterface::class)); | |||
$this->reductionCreditRepo = $this->em->getRepository($this->em->getEntityName(ReductionCreditInterface::class)); | |||
$this->orderReductionCreditRepo = $this->em->getRepository($this->em->getEntityName(OrderReductionCreditInterface::class)); | |||
$this->documentRepo = $this->em->getRepository($this->em->getEntityName(DocumentInterface::class)); | |||
$this->priceUtils = $priceUtils; | |||
$this->productFamilyUtils = $productFamilyUtils; | |||
$this->documentUtils = $documentUtils; | |||
@@ -257,6 +268,7 @@ class OrderUtils | |||
$data['count'] = $this->countQuantities($order); | |||
$data['total_with_tax'] = $this->priceUtils->getTotalWithTax($order); | |||
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order); | |||
$data['total_remaining_to_be_paid'] = $this->getTotalRemainingToBePaid($order) ; | |||
} | |||
return $data; | |||
} | |||
@@ -296,8 +308,8 @@ class OrderUtils | |||
public function newOrderStatusHistory($order, $status, $origin = 'user') | |||
{ | |||
$orderStatusHistoryClass = $this->em->getClassMetadata(OrderStatusHistoryInterface::class); | |||
$orderStatusHistory = new $orderStatusHistoryClass->name; | |||
$orderStatusHistoryClass = $this->em->getEntityName(OrderStatusHistoryInterface::class); | |||
$orderStatusHistory = new $orderStatusHistoryClass; | |||
$orderStatusHistory->setOrderShop($order); | |||
$orderStatusHistory->setOrderStatus($status); | |||
$orderStatusHistory->setOrigin($origin); | |||
@@ -395,5 +407,30 @@ class OrderUtils | |||
} | |||
public function addPayment($orderShop, $meanPayment, $amount) | |||
{ | |||
$this->createOrderPayment([ | |||
'orderShop' => $orderShop, | |||
'meanPayment' => $meanPayment, | |||
'amount' => $amount | |||
]) ; | |||
$this->em->refresh($orderShop) ; | |||
if($this->isOrderPaid($orderShop)) { | |||
$nextStatus = OrderStatus::ALIAS_PAID ; | |||
} | |||
else { | |||
$nextStatus = OrderStatus::ALIAS_PARTIAL_PAYMENT ; | |||
} | |||
if($orderShop->getOrderStatus()->getAlias() != $nextStatus) { | |||
$orderShop = $this->changeOrderStatus( | |||
$nextStatus, | |||
$orderShop | |||
); | |||
} | |||
return $orderShop ; | |||
} | |||
} |
@@ -3,46 +3,44 @@ | |||
namespace Lc\ShopBundle\Services\Order; | |||
use App\Entity\CreditHistory; | |||
use App\Factory\Order\OrderPaymentFactory; | |||
use Lc\ShopBundle\Context\OrderPaymentInterface; | |||
use Lc\ShopBundle\Services\Utils; | |||
trait OrderUtilsPaymentTrait | |||
{ | |||
public function createOrderPayment($orderShop, $meanPayment, $amount, $reference = null, $comment = null, $paidAt = null) | |||
public function createOrderPayment($params = []) | |||
{ | |||
$classOrderPayment = $this->em->getClassMetadata(OrderPaymentInterface::class)->getName(); | |||
$orderPayment = new $classOrderPayment; | |||
$orderPayment->setOrderShop($orderShop); | |||
$orderPayment->setMeanPayment($meanPayment); | |||
$orderPayment->setAmount($amount); | |||
$orderPayment->setReference($reference); | |||
$orderPayment->setComment($comment); | |||
$orderPayment->setEditable(false); | |||
$orderPayment->setCreatedBy($orderShop->getUser()); | |||
$orderPayment->setUpdatedBy($orderShop->getUser()); | |||
if ($paidAt) { | |||
$orderPayment->setPaidAt($paidAt); | |||
} else { | |||
$orderPayment->setPaidAt(new \DateTime('now')); | |||
$orderPayment = $this->factoryManager->createEntity(OrderPaymentFactory::class, $params); | |||
if(isset($params['meanPayment']) && $params['meanPayment'] == Utils::MEAN_PAYMENT_CREDIT) { | |||
$this->creditUtils->createCreditHistory(CreditHistory::TYPE_DEBIT, $this->security->getUser(), [ | |||
'orderPayment' => $orderPayment | |||
]); | |||
} | |||
$this->em->persist($orderPayment); | |||
$this->em->flush(); | |||
$this->em->create($orderPayment) ; | |||
$this->em->flush() ; | |||
return $orderPayment; | |||
return $orderPayment ; | |||
} | |||
public function isOrderPaid($order, $mergeComplementaryOrderShop = false) | |||
{ | |||
$totalOrderPayments = $this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) ; | |||
$totalOrder = $this->priceUtils->getTotalWithTax($order) ; | |||
if ( (abs($totalOrderPayments - $totalOrder) < 0.00001 | |||
|| $totalOrderPayments >= $totalOrder) | |||
&& $totalOrder > 0) { | |||
if ($this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) >= $this->priceUtils->getTotalWithTax($order) && $this->priceUtils->getTotalWithTax($order) > 0) { | |||
return true; | |||
} else { | |||
} | |||
else { | |||
return false; | |||
} | |||
} | |||
public function getTotalOrderPayments($order, $mergeComplementaryOrderShop = false): float | |||
@@ -61,4 +59,18 @@ trait OrderUtilsPaymentTrait | |||
return $totalAmount; | |||
} | |||
public function getTotalRemainingToBePaid($order) | |||
{ | |||
return $this->priceUtils->getTotalWithTax($order) - $this->getTotalOrderPayments($order) ; | |||
} | |||
public function isOrderShopPositiveAmountRemainingToBePaid($orderShop) | |||
{ | |||
return $this->getTotalRemainingToBePaid($orderShop) > 0 ; | |||
} | |||
public function addPayment() | |||
{ | |||
} | |||
} |
@@ -73,13 +73,18 @@ trait OrderUtilsReductionTrait | |||
$orderShop->addOrderReductionCart($orderReductionCart) ; | |||
if($this->isOrderShopPositiveAmount($orderShop)) { | |||
if($this->isOrderShopPositiveAmount($orderShop) | |||
&& $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) { | |||
$this->em->persist($orderReductionCart); | |||
$this->em->flush(); | |||
return $orderReductionCart ; | |||
} | |||
return false; | |||
else { | |||
$orderShop->removeOrderReductionCart($orderReductionCart) ; | |||
return false; | |||
} | |||
} | |||
public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit) | |||
@@ -148,13 +153,19 @@ trait OrderUtilsReductionTrait | |||
$orderShop->addOrderReductionCredit($orderReductionCredit) ; | |||
if($this->isOrderShopPositiveAmount($orderShop)) { | |||
if($this->isOrderShopPositiveAmount($orderShop) | |||
&& $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) { | |||
$this->em->persist($orderReductionCredit); | |||
$this->em->flush(); | |||
return $orderReductionCredit; | |||
} | |||
else { | |||
$orderShop->removeOrderReductionCredit($orderReductionCredit) ; | |||
return false ; | |||
return false; | |||
} | |||
} | |||
@@ -29,6 +29,7 @@ class UtilsManager | |||
protected $statisticsUtils; | |||
protected $pointLocationUtils ; | |||
protected $sectionUtils ; | |||
protected $mailjetSmsUtils ; | |||
public function __construct( | |||
Utils $utils, | |||
@@ -44,7 +45,8 @@ class UtilsManager | |||
TicketUtils $ticketUtils, | |||
PointLocationUtils $pointLocationUtils, | |||
UtilsProcess $utilsProcess, | |||
SectionUtilsInterface $sectionUtils | |||
SectionUtilsInterface $sectionUtils, | |||
MailjetSmsUtils $mailjetSmsUtils | |||
) | |||
{ | |||
$this->utils = $utils ; | |||
@@ -61,6 +63,7 @@ class UtilsManager | |||
$this->pointLocationUtils = $pointLocationUtils ; | |||
$this->utilsProcess = $utilsProcess ; | |||
$this->sectionUtils = $sectionUtils ; | |||
$this->mailjetSmsUtils = $mailjetSmsUtils ; | |||
} | |||
public function getUtils(): Utils | |||
@@ -133,4 +136,9 @@ class UtilsManager | |||
return $this->sectionUtils ; | |||
} | |||
public function getMailjetSmsUtils(): MailjetSmsUtils | |||
{ | |||
return $this->mailjetSmsUtils ; | |||
} | |||
} |