Browse Source

Dashboard statistiques

feature/export_comptable
Fab 4 years ago
parent
commit
2168d7e9fa
5 changed files with 85 additions and 29 deletions
  1. +15
    -6
      ShopBundle/Controller/Frontend/CartController.php
  2. +1
    -0
      ShopBundle/Resources/translations/lcshop.fr.yaml
  3. +16
    -9
      ShopBundle/Services/Order/OrderUtils.php
  4. +16
    -7
      ShopBundle/Services/Order/OrderUtilsReductionTrait.php
  5. +37
    -7
      ShopBundle/Services/Price/OrderShopPriceUtils.php

+ 15
- 6
ShopBundle/Controller/Frontend/CartController.php View File

use Lc\ShopBundle\Model\OrderReductionCart; use Lc\ShopBundle\Model\OrderReductionCart;
use Lc\ShopBundle\Model\ProductFamily; use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\UserUtils; use Lc\ShopBundle\Services\UserUtils;
use Lc\ShopBundle\Services\UtilsManager;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\Generator\UrlGenerator;
{ {
protected $orderUtils ; protected $orderUtils ;
protected $userUtils ; protected $userUtils ;
protected $priceUtils ;
protected $router ; protected $router ;
protected $productFamilyRepository ; protected $productFamilyRepository ;
protected $orderProductRepository ; protected $orderProductRepository ;
protected $orderProducts = [] ; protected $orderProducts = [] ;




public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils,
UserUtils $userUtils, UrlGeneratorInterface $router)
public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils,
UrlGeneratorInterface $router, UtilsManager $utilsManager)
{ {
parent::__construct($em, $security, $merchantUtils); parent::__construct($em, $security, $merchantUtils);
$this->orderUtils = $orderUtils ;
$this->userUtils = $userUtils ;
$this->orderUtils = $utilsManager->getOrderUtils() ;
$this->userUtils = $utilsManager->getUserUtils() ;
$this->priceUtils = $utilsManager->getPriceUtils() ;
$this->router = $router ; $this->router = $router ;
$this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ; $this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ;
$this->orderProductRepository = $this->em->getRepository($this->em->getClassMetaData(OrderProductInterface::class)->getName()) ; $this->orderProductRepository = $this->em->getRepository($this->em->getClassMetaData(OrderProductInterface::class)->getName()) ;
&& $this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit) && $this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)
&& !$this->orderUtils->isReductionCreditAddedToOrder($orderShop, $reductionCredit)) { && !$this->orderUtils->isReductionCreditAddedToOrder($orderShop, $reductionCredit)) {


$this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit) ;
$this->addFlash('success', 'Votre avoir a bien été ajouté à votre panier.') ;
$return = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit) ;

if($return) {
$this->addFlash('success', 'Votre avoir a bien été ajouté à votre panier.') ;
}
else {
$this->addFlash('error', 'Vous ne pouvez pas effectuer cette action. Le montant de la commande est insuffisant.') ;
}
} }
else { else {
$this->addFlash('error', "Impossible d'effectuer cette action"); $this->addFlash('error', "Impossible d'effectuer cette action");

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

amountMin: Le montant minimum de commandes n'est pas respecté amountMin: Le montant minimum de commandes n'est pas respecté
qauntity: La réduction n'est plus disponible qauntity: La réduction n'est plus disponible
quantityPerUser: La reduction n'est plus disponible pour cet utilisateur quantityPerUser: La reduction n'est plus disponible pour cet utilisateur
alreadyInCart: La réduction a déjà été ajoutée à votre panier
reductionCredit: reductionCredit:
userNotAllow: Cet avoir n'est pas disponible pour cet utilisateur userNotAllow: Cet avoir n'est pas disponible pour cet utilisateur
alreayUse: Cet avoir a déjà été utilisé alreayUse: Cet avoir a déjà été utilisé

+ 16
- 9
ShopBundle/Services/Order/OrderUtils.php View File

if (!$updated) { if (!$updated) {
$orderShop->addOrderProduct($orderProductAdd); $orderShop->addOrderProduct($orderProductAdd);


if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);

if ($persist) {
if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);
}
$this->em->persist($orderProductAdd);
$this->em->persist($orderShop);
if ($persist) {
if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);
} }
$this->em->persist($orderProductAdd);
$this->em->persist($orderShop);
} }


$return = true; $return = true;
if ($persist) { if ($persist) {
$this->em->flush(); $this->em->flush();
} }

$this->eventOrderShopChangeQuantity($orderShop) ;
} }
} }
else { else {
return $orderProductsByProductFamily; return $orderProductsByProductFamily;
} }


public function isOrderShopPositiveAmount(OrderShopInterface $orderShop)
{
return $this->priceUtils->getTotalWithTax($orderShop) > 0 ;
}

public function eventOrderShopChangeQuantity(OrderShopInterface $orderShop)
{

}
} }

+ 16
- 7
ShopBundle/Services/Order/OrderUtilsReductionTrait.php View File

$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo()); $orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType()); $orderReductionCart->setType($reductionCart->getType());


$this->em->persist($orderReductionCart);
$this->em->flush();
$orderShop->addOrderReductionCart($orderReductionCart) ;


return $orderReductionCart;
if($this->isOrderShopPositiveAmount($orderShop)) {
$this->em->persist($orderReductionCart);
$this->em->flush();
return $orderReductionCart ;
}

return false;
} }


public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit) public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)
// n'a pas été utilisé // n'a pas été utilisé
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) { if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) {
$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse'); $this->utils->addFlash('error', 'error.reductionCredit.alreadyUse');

return false; return false;
} }


$orderReductionCredit->setUnit($reductionCredit->getUnit()); $orderReductionCredit->setUnit($reductionCredit->getUnit());
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate()); $orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());


$this->em->persist($orderReductionCredit);
$this->em->flush();
$orderShop->addOrderReductionCredit($orderReductionCredit) ;


return $orderReductionCredit;
if($this->isOrderShopPositiveAmount($orderShop)) {
$this->em->persist($orderReductionCredit);
$this->em->flush();
return $orderReductionCredit;
}

return false ;
} }


/*public function getReductionCreditsAvailable($order) /*public function getReductionCreditsAvailable($order)

+ 37
- 7
ShopBundle/Services/Price/OrderShopPriceUtils.php View File

public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop) public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop)
{ {
$total = $this->getTotalOrderProducts($orderShop) ; $total = $this->getTotalOrderProducts($orderShop) ;
$total -= $this->getTotalReductionCartsAmount($orderShop) ;
$total -= $this->getTotalReductionCreditsAmount($orderShop) ;
return $total ;
}

public function getTotalOrderProductsWithReductionCarts(OrderShopInterface $orderShop)
{
$total = $this->getTotalOrderProducts($orderShop) ;
$total -= $this->getTotalReductionCartsAmount($orderShop) ;
return $total ;
}


public function getTotalReductionCartsAmount(OrderShopInterface $orderShop)
{
$totalReductionAmount = 0 ; $totalReductionAmount = 0 ;
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) {
$totalReductionAmount += $this->getOrderProductsReductionCartAmountWithoutTax($orderShop,$orderReductionCart); $totalReductionAmount += $this->getOrderProductsReductionCartAmountWithoutTax($orderShop,$orderReductionCart);
} }
return $totalReductionAmount ;
}


public function getTotalReductionCreditsAmount(OrderShopInterface $orderShop)
{
$totalReductionAmount = 0 ;
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
$totalReductionAmount += $this->getOrderProductsReductionCreditAmountWithoutTax($orderShop,$orderReductionCredit); $totalReductionAmount += $this->getOrderProductsReductionCreditAmountWithoutTax($orderShop,$orderReductionCredit);
} }
return $totalReductionAmount ;
}


$total -= $totalReductionAmount ;

public function getTotalOrderProductsWithTaxAndReductions(OrderShopInterface $orderShop)
{
$total = $this->getTotalOrderProductsWithTax($orderShop) ;
$total -= $this->getTotalReductionCartsAmountWithTax($orderShop) ;
$total -= $this->getTotalReductionCreditsAmountWithTax($orderShop) ;
return $total ; return $total ;
} }


} }




public function getTotalOrderProductsWithTaxAndReductions(OrderShopInterface $orderShop)
public function getTotalOrderProductsWithTaxAndReductionCarts(OrderShopInterface $orderShop)
{ {
$total = $this->getTotalOrderProductsWithTax($orderShop) ; $total = $this->getTotalOrderProductsWithTax($orderShop) ;
$total -= $this->getTotalReductionCartsAmountWithTax($orderShop) ;
return $total ;
}


public function getTotalReductionCartsAmountWithTax(OrderShopInterface $orderShop)
{
$totalReductionAmount = 0 ; $totalReductionAmount = 0 ;
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) {
$totalReductionAmount += $this->getOrderProductsReductionCartAmountWithTax($orderShop,$orderReductionCart); $totalReductionAmount += $this->getOrderProductsReductionCartAmountWithTax($orderShop,$orderReductionCart);
} }
return $totalReductionAmount ;
}


public function getTotalReductionCreditsAmountWithTax(OrderShopInterface $orderShop)
{
$totalReductionAmount = 0 ;
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
$totalReductionAmount += $this->getOrderProductsReductionCreditAmountWithTax($orderShop,$orderReductionCredit); $totalReductionAmount += $this->getOrderProductsReductionCreditAmountWithTax($orderShop,$orderReductionCredit);
} }

$total -= $totalReductionAmount ;

return $total ;
return $totalReductionAmount ;
} }


public function getOrderProductsReductionCartAmountWithoutTax(OrderShopInterface $order, $orderReductionCart) public function getOrderProductsReductionCartAmountWithoutTax(OrderShopInterface $order, $orderReductionCart)

Loading…
Cancel
Save