Selaa lähdekoodia

Merge branch 'develop' of https://gitea.laclic.fr/Laclic/LcShopBundle into develop

feature/export_comptable
Fab 4 vuotta sitten
vanhempi
commit
97e0e59c64
9 muutettua tiedostoa jossa 344 lisäystä ja 6 poistoa
  1. +58
    -0
      ShopBundle/Controller/Frontend/CartController.php
  2. +1
    -1
      ShopBundle/Repository/OrderShopRepository.php
  3. +12
    -0
      ShopBundle/Services/OrderUtils.php
  4. +13
    -3
      ShopBundle/Services/OrderUtilsReductionTrait.php
  5. +94
    -0
      ShopBundle/Services/Price/OrderProductPriceUtils.php
  6. +64
    -0
      ShopBundle/Services/Price/OrderShopPriceUtils.php
  7. +36
    -0
      ShopBundle/Services/Price/PriceUtilsTrait.php
  8. +54
    -0
      ShopBundle/Services/Price/ProductPriceUtils.php
  9. +12
    -2
      ShopBundle/Services/PriceUtils.php

+ 58
- 0
ShopBundle/Controller/Frontend/CartController.php Näytä tiedosto

@@ -2,11 +2,13 @@

namespace Lc\ShopBundle\Controller\Frontend ;

use App\Entity\ReductionCredit;
use App\Form\Frontend\OrderProductsType;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderReductionCreditInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
@@ -81,6 +83,17 @@ class CartController extends BaseController
return new JsonResponse($return) ;
}

public function redirectToReferer($request) {
$referer = $request->headers->get('referer');

if($referer) {
return $this->redirect($referer);
}
else {
return $this->redirectToRoute('frontend_order_cart');
}
}

public function deleteReductionCart(Request $request)
{
$id = $request->get('id') ;
@@ -100,6 +113,51 @@ class CartController extends BaseController
$this->addFlash('error', 'Une erreur est survenue lors de la suppression de la réduction. ') ;
}

return $this->redirectToReferer($request) ;
}

public function addReductionCredit(Request $request)
{
$id = $request->get('id') ;
$orderShop = $this->orderUtils->getCartCurrent() ;
$user = $this->security->getUser() ;

$reductionCreditRepository = $this->em->getRepository(ReductionCredit::class) ;
$reductionCredit = $reductionCreditRepository->find($id) ;

if($orderShop && $user && $reductionCredit
&& $this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)
&& !$this->orderUtils->isReductionCreditAddedToOrder($orderShop, $reductionCredit)) {

$this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit) ;
$this->addFlash('success', 'Votre avoir a bien été ajouté à votre panier.') ;
}
else {
$this->addFlash('error', "Impossible d'effectuer cette action");
}

return $this->redirectToReferer($request) ;
}

public function deleteReductionCredit(Request $request)
{
$id = $request->get('id') ;

$orderReductionCreditRepository = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCreditInterface::class)->getName()) ;
$orderReductionCredit = $orderReductionCreditRepository->findOneById((int) $id) ;

$orderShop = $this->orderUtils->getCartCurrent() ;

if($orderReductionCredit && $orderShop->getOrderReductionCredits() && $orderShop->getOrderReductionCredits()->contains($orderReductionCredit)) {
$this->em->remove($orderReductionCredit) ;
$this->em->flush() ;

$this->addFlash('success', 'Votre avoir a bien été supprimé de votre panier.') ;
}
else {
$this->addFlash('error', 'Une erreur est survenue lors de la suppression de votre avoir. ') ;
}

$referer = $request->headers->get('referer');

if($referer) {

+ 1
- 1
ShopBundle/Repository/OrderShopRepository.php Näytä tiedosto

@@ -31,7 +31,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query = $this->filterOrderValid($query);
$query->select('count(e.id)');
$query->andWhere('e.user = :user');
$query->join('e.orderReductionCredits', 'orc');
$query->innerJoin('e.orderReductionCredits', 'orc');
$query->andWhere('orc.reductionCredit = :reductionCredit');
$query->setParameter('reductionCredit', $reductionCredit);
$query->setParameter('user', $user);

+ 12
- 0
ShopBundle/Services/OrderUtils.php Näytä tiedosto

@@ -35,6 +35,7 @@ class OrderUtils
protected $merchantUtils;
protected $orderShopRepo;
protected $reductionCreditRepo ;
protected $orderReductionCreditRepo ;
protected $priceUtils;
protected $productFamilyUtils;
protected $documentUtils;
@@ -50,6 +51,7 @@ class OrderUtils
$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->priceUtils = $priceUtils;
$this->productFamilyUtils = $productFamilyUtils;
$this->documentUtils = $documentUtils;
@@ -473,4 +475,14 @@ class OrderUtils
return $reductionCreditsArray ;
}

public function isReductionCreditAddedToOrder($orderShop, $reductionCredit)
{
foreach($orderShop->getOrderReductionCredits() as $orderReductionCredit) {
if($orderReductionCredit->getReductionCredit() == $reductionCredit) {
return true ;
}
}

return false ;
}
}

+ 13
- 3
ShopBundle/Services/OrderUtilsReductionTrait.php Näytä tiedosto

@@ -79,12 +79,19 @@ trait OrderUtilsReductionTrait

public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)
{
$user = $orderShop->getUser() ;

if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser()) > 0) {
// appartient à l'utilisateur
if(!$reductionCredit->getUsers()->contains($user)) {
return false ;
}

// n'a pas été utilisé
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) {
return false;
} else {
return true;
}

return true;
}

public function getReductionCartRemainingQuantity($reductionCart) :float
@@ -111,6 +118,9 @@ trait OrderUtilsReductionTrait
$orderReductionCredit->setUnit($reductionCredit->getUnit());
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());

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

return $orderReductionCredit;
}


+ 94
- 0
ShopBundle/Services/Price/OrderProductPriceUtils.php Näytä tiedosto

@@ -0,0 +1,94 @@
<?php

namespace Lc\ShopBundle\Price\Services;

use Doctrine\Common\Collections\Collection;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ProductPropertyInterface;
use Lc\ShopBundle\Context\ReductionCatalogInterface;

class OrderProductPriceUtils
{
use PriceUtilsTrait ;

protected $productPriceUtils ;

public function __construct(ProductPriceUtils $productPriceUtils)
{
$this->productPriceUtils = $productPriceUtils ;
}

public function getPrice(OrderProductInterface $orderProduct)
{

}

public function getPriceWithTax(OrderProductInterface $orderProduct)
{

}

public function getPriceWithTaxAndReduction(OrderProductInterface $orderProduct)
{

}

public function getPriceByRefUnit(OrderProductInterface $orderProduct)
{

}

public function getPriceByRefUnitWithTax(OrderProductInterface $orderProduct)
{

}

public function getPriceByRefUnitWithTaxAndReduction(OrderProductInterface $orderProduct)
{

}

public function getTotal(OrderProductInterface $orderProduct)
{

}

public function getTotalWithReductionCatalog(OrderProductInterface $orderProduct)
{

}

public function getTotalWithReductionCart(OrderProductInterface $orderProduct)
{

}

public function getTotalWithReductions(OrderProductInterface $orderProduct)
{

}

public function getTotalWithTax(OrderProductInterface $orderProduct)
{

}

public function getTotalWithTaxAndReductionCatalog(OrderProductInterface $orderProduct)
{

}

public function getTotalWithTaxAndReductionCart(OrderProductInterface $orderProduct)
{

}

public function getTotalWithTaxAndReductions(OrderProductInterface $orderProduct)
{

}
}


+ 64
- 0
ShopBundle/Services/Price/OrderShopPriceUtils.php Näytä tiedosto

@@ -0,0 +1,64 @@
<?php

namespace Lc\ShopBundle\Price\Services;

use Doctrine\Common\Collections\Collection;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ProductPropertyInterface;
use Lc\ShopBundle\Context\ReductionCatalogInterface;

class OrderShopPriceUtils
{
use PriceUtilsTrait ;

protected $orderProductPriceUtils ;

public function __construct(OrderProductPriceUtils $orderProductPriceUtils)
{
$this->orderProductPriceUtils = $orderProductPriceUtils ;
}

public function getTotal(OrderShopInterface $orderShop)
{

}

public function getTotalWithReductionCatalog(OrderShopInterface $orderShop)
{

}

public function getTotalWithReductionCart(OrderShopInterface $orderShop)
{

}

public function getTotalWithReductions(OrderShopInterface $orderShop)
{

}

public function getTotalWithTax(OrderShopInterface $orderShop)
{

}

public function getTotalWithTaxAndReductionCatalog(OrderShopInterface $orderShop)
{

}

public function getTotalWithTaxAndReductionCart(OrderShopInterface $orderShop)
{

}

public function getTotalWithTaxAndReductions(OrderShopInterface $orderShop)
{

}
}


+ 36
- 0
ShopBundle/Services/Price/PriceUtilsTrait.php Näytä tiedosto

@@ -0,0 +1,36 @@
<?php

namespace Lc\ShopBundle\Price\Services;

trait PriceUtilsTrait
{
public function applyTax($price, $taxRateValue)
{
return $this->round($this->applyPercent($price, $taxRateValue));
}

public function applyReductionPercent($price, $percentage)
{
return $this->applyPercent($price, -$percentage);
}

public function applyReductionAmount($price, $amount)
{
return $price - $amount;
}

public function applyPercent($price, $percentage)
{
return $price * ($percentage / 100 + 1);
}

public function applyPercentNegative($price, $percentage)
{
return $price / ($percentage / 100 + 1);
}

public function round($price)
{
return round((($price * 100)) / 100, 2);
}
}

+ 54
- 0
ShopBundle/Services/Price/ProductPriceUtils.php Näytä tiedosto

@@ -0,0 +1,54 @@
<?php

namespace Lc\ShopBundle\Price\Services;

use Doctrine\Common\Collections\Collection;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\ProductPropertyInterface;
use Lc\ShopBundle\Context\ReductionCatalogInterface;

class ProductPriceUtils
{
use PriceUtilsTrait ;

public function getPrice(ProductPropertyInterface $product)
{
if ($product->getBehaviorPriceInherited() == 'by-piece') {
return $product->getPriceInherited();
}
elseif ($product->getBehaviorPriceInherited() == 'by-reference-unit') {
if ($product->getQuantityInherited() > 0) {
return $product->getPriceByRefUnitInherited() * ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient());
}
}
}

public function getPriceWithTax(ProductPropertyInterface $product)
{

}

public function getPriceWithTaxAndReduction(ProductPropertyInterface $product)
{

}

public function getPriceByRefUnit(ProductPropertyInterface $product)
{

}

public function getPriceByRefUnitWithTax(ProductPropertyInterface $product)
{

}

public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
{

}
}


+ 12
- 2
ShopBundle/Services/PriceUtils.php Näytä tiedosto

@@ -165,10 +165,10 @@ class PriceUtils
{

if ($withTax) {
$priceToReturn = $this->getTotalOrderProductsWithTaxAndReductionCatalog();
$priceToReturn = $this->getTotalOrderProductsWithTaxAndReductionCatalog($order);
}
else {
$priceToReturn = $this->getTotalOrderProductsWithReductionCatalog();
$priceToReturn = $this->getTotalOrderProductsWithReductionCatalog($order);
}
foreach ($order->getOrderReductionCarts() as $orderReductionCart) {
if ($orderReductionCart->getUnit() == 'percent') {
@@ -200,6 +200,16 @@ class PriceUtils
return $this->getSumOrderProductsDispatch($entity, true);
}

public function getTotalOrderProductsWithReduction($entity)
{
return $this->getTotalOrderProductsWithReductionCatalog($entity);
}

public function getTotalOrderProductsWithTaxAndReduction($entity)
{
return $this->getTotalOrderProductsWithTaxAndReductionCatalog($entity);
}

public function getTotalOrderProductsWithReductionCatalog($entity)
{
return $this->getSumOrderProductsDispatch($entity, false, true);

Loading…
Peruuta
Tallenna