Browse Source

Merge branch 'feature/paiement_partiel' into develop

develop
Guillaume 3 years ago
parent
commit
f38376ee88
6 changed files with 96 additions and 45 deletions
  1. +1
    -3
      ShopBundle/Controller/Backend/OrderController.php
  2. +6
    -1
      ShopBundle/Manager/EntityManager.php
  3. +4
    -6
      ShopBundle/Model/OrderStatus.php
  4. +2
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  5. +47
    -10
      ShopBundle/Services/Order/OrderUtils.php
  6. +36
    -24
      ShopBundle/Services/Order/OrderUtilsPaymentTrait.php

+ 1
- 3
ShopBundle/Controller/Backend/OrderController.php View File

$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView(); $parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView();
break; break;
case OrderStatus::ALIAS_ERROR_PAYMENT_ONLINE : case OrderStatus::ALIAS_ERROR_PAYMENT_ONLINE :
case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT :
case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE : case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE :
$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView(); $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(); $parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView();
$parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); $parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView();
$parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); $parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();
break; 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_DELIVERY :
case OrderStatus::ALIAS_WAITING_BANK_RETURN : case OrderStatus::ALIAS_WAITING_BANK_RETURN :
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); $parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView();

+ 6
- 1
ShopBundle/Manager/EntityManager.php View File

return $this; return $this;
} }


protected function persist($entity)
public function persist($entity)
{ {
$this->entityManager->persist($entity); $this->entityManager->persist($entity);
} }


public function refresh($entity)
{
$this->entityManager->refresh($entity);
}

public function getEntityName($className) public function getEntityName($className)
{ {
if (substr($className, -9) === 'Interface') { if (substr($className, -9) === 'Interface') {

+ 4
- 6
ShopBundle/Model/OrderStatus.php View File

const ALIAS_CART = 'cart' ; const ALIAS_CART = 'cart' ;
const ALIAS_CART_CANCELED = 'cart-canceled' ; const ALIAS_CART_CANCELED = 'cart-canceled' ;
const ALIAS_WAITING_PAYMENT_ONLINE = 'waiting-payment-online' ; 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_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_ERROR_PAYMENT_ONLINE = 'error-payment-online' ;
const ALIAS_PAID_BY_CREDIT = 'paid-by-credit' ;
const ALIAS_WAITING_DELIVERY = 'waiting-delivery' ; const ALIAS_WAITING_DELIVERY = 'waiting-delivery' ;
const ALIAS_WAITING_DELIVERY_WITH_PAYMENT = 'waiting-delivery-with-payment' ; const ALIAS_WAITING_DELIVERY_WITH_PAYMENT = 'waiting-delivery-with-payment' ;
const ALIAS_DELIVERED_WITHOUT_PAYMENT = 'delivered-without-payment' ; const ALIAS_DELIVERED_WITHOUT_PAYMENT = 'delivered-without-payment' ;


//TODO : AJOUTER un champ valid ds orderSTATUS //TODO : AJOUTER un champ valid ds orderSTATUS
static $statusAliasAsValid = [ static $statusAliasAsValid = [
self::ALIAS_PAID_ONLINE,
self::ALIAS_PAID_BY_CREDIT,
self::ALIAS_PAID,
self::ALIAS_WAITING_DELIVERY, self::ALIAS_WAITING_DELIVERY,
self::ALIAS_WAITING_BANK_RETURN, self::ALIAS_WAITING_BANK_RETURN,
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT,


static $statusAliasAsCart = [ static $statusAliasAsCart = [
self::ALIAS_CART, self::ALIAS_CART,
self::ALIAS_PARTIAL_PAYMENT,
self::ALIAS_WAITING_PAYMENT_ONLINE, self::ALIAS_WAITING_PAYMENT_ONLINE,
self::ALIAS_WAITING_PAYMENT_CREDIT,
self::ALIAS_ERROR_PAYMENT_ONLINE self::ALIAS_ERROR_PAYMENT_ONLINE
]; ];



+ 2
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml View File

deliverySlotMissing: Vous n'avez pas de créneau de livraison deliverySlotMissing: Vous n'avez pas de créneau de livraison
productUnavailable: Certains produits ne sont plus disponibles productUnavailable: Certains produits ne sont plus disponibles
nextStatusNotAllow: La commande ne peut passer à ce statut 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é. otherOrderAlreadyExist: Une autre commande existe déjà pour cet utilisateur, vous avez été redirigé.
minimumAmountZone: Montant minimum de commande non respecté pour cette zone minimumAmountZone: Montant minimum de commande non respecté pour cette zone
minimumAmountPointSale: Montant minimum de commande non respecté pour ce point de vente minimumAmountPointSale: Montant minimum de commande non respecté pour ce point de vente
noPayment: Aucun paiement n'a été enregistré pour cette commande
reductionCart: reductionCart:
conditionsError: Cette réduction ne peut pas être appliqué sur cette commande conditionsError: Cette réduction ne peut pas être appliqué sur cette commande
date: La réduction n'est plus active date: La réduction n'est plus active

+ 47
- 10
ShopBundle/Services/Order/OrderUtils.php View File



use App\Entity\OrderProductReductionCatalog; use App\Entity\OrderProductReductionCatalog;
use App\Entity\OrderShop; use App\Entity\OrderShop;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\OrderStatus;
use Lc\ShopBundle\Context\DocumentInterface; use Lc\ShopBundle\Context\DocumentInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface; use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderReductionCreditInterface; use Lc\ShopBundle\Context\OrderReductionCreditInterface;
use Lc\ShopBundle\Context\SectionInterface; use Lc\ShopBundle\Context\SectionInterface;
use Lc\ShopBundle\Context\SectionUtilsInterface; use Lc\ShopBundle\Context\SectionUtilsInterface;
use Lc\ShopBundle\Context\UserUtilsInterface; use Lc\ShopBundle\Context\UserUtilsInterface;
use Lc\ShopBundle\Manager\EntityManager;
use Lc\ShopBundle\Model\ProductFamily; use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\CreditUtils; use Lc\ShopBundle\Services\CreditUtils;
use Lc\ShopBundle\Services\DocumentUtils; use Lc\ShopBundle\Services\DocumentUtils;
protected $router; protected $router;
protected $sectionUtils ; 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->em = $em;
$this->security = $security; $this->security = $security;
$this->userUtils = $userUtils; $this->userUtils = $userUtils;
$this->merchantUtils = $merchantUtils; $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->priceUtils = $priceUtils;
$this->productFamilyUtils = $productFamilyUtils; $this->productFamilyUtils = $productFamilyUtils;
$this->documentUtils = $documentUtils; $this->documentUtils = $documentUtils;
$data['count'] = $this->countQuantities($order); $data['count'] = $this->countQuantities($order);
$data['total_with_tax'] = $this->priceUtils->getTotalWithTax($order); $data['total_with_tax'] = $this->priceUtils->getTotalWithTax($order);
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order); $data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order);
$data['total_remaining_to_be_paid'] = $this->getTotalRemainingToBePaid($order) ;
} }
return $data; return $data;
} }


public function newOrderStatusHistory($order, $status, $origin = 'user') 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->setOrderShop($order);
$orderStatusHistory->setOrderStatus($status); $orderStatusHistory->setOrderStatus($status);
$orderStatusHistory->setOrigin($origin); $orderStatusHistory->setOrigin($origin);


} }


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 ;
}


} }

+ 36
- 24
ShopBundle/Services/Order/OrderUtilsPaymentTrait.php View File

namespace Lc\ShopBundle\Services\Order; namespace Lc\ShopBundle\Services\Order;




use App\Entity\CreditHistory;
use App\Factory\Order\OrderPaymentFactory;
use Lc\ShopBundle\Context\OrderPaymentInterface; use Lc\ShopBundle\Context\OrderPaymentInterface;
use Lc\ShopBundle\Services\Utils;


trait OrderUtilsPaymentTrait 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) 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; return true;
} else {
}
else {
return false; return false;
} }


} }


public function getTotalOrderPayments($order, $mergeComplementaryOrderShop = false): float public function getTotalOrderPayments($order, $mergeComplementaryOrderShop = false): float
return $totalAmount; 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()
{

}
} }

Loading…
Cancel
Save