Browse Source

Processus de commande

feature/export_comptable
Fab 4 years ago
parent
commit
2a83f27208
3 changed files with 28 additions and 14 deletions
  1. +2
    -1
      ShopBundle/Repository/BaseRepository.php
  2. +5
    -4
      ShopBundle/Repository/OrderShopRepository.php
  3. +21
    -9
      ShopBundle/Services/OrderUtilsReductionTrait.php

+ 2
- 1
ShopBundle/Repository/BaseRepository.php View File

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Lc\ShopBundle\Context\FilterMerchantInterface; use Lc\ShopBundle\Context\FilterMerchantInterface;
use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface; use Lc\ShopBundle\Context\MerchantUtilsInterface;
} }




public function findByMerchantQuery()
public function findByMerchantQuery() :QueryBuilder
{ {
return $this->createQueryBuilder('e') return $this->createQueryBuilder('e')
->where('e.merchant = :currentMerchant') ->where('e.merchant = :currentMerchant')

+ 5
- 4
ShopBundle/Repository/OrderShopRepository.php View File



namespace Lc\ShopBundle\Repository; namespace Lc\ShopBundle\Repository;


use Doctrine\ORM\QueryBuilder;
use Lc\ShopBundle\Context\DefaultRepositoryInterface; use Lc\ShopBundle\Context\DefaultRepositoryInterface;
use Lc\ShopBundle\Context\OrderShopInterface; use Lc\ShopBundle\Context\OrderShopInterface;


$query = $this->filterOrderValid($query); $query = $this->filterOrderValid($query);
$query->select('count(e.id)'); $query->select('count(e.id)');
$query->andWhere('e.user = :user'); $query->andWhere('e.user = :user');
$query->leftJoin('e.orderReductionCredits', 'orc');
$query->join('e.orderReductionCredits', 'orc');
$query->andWhere('orc.reductionCredit = :reductionCredit'); $query->andWhere('orc.reductionCredit = :reductionCredit');
$query->setParameter('reductionCredit', $reductionCredit); $query->setParameter('reductionCredit', $reductionCredit);
$query->setParameter('user', $user); $query->setParameter('user', $user);
$query = $this->findByMerchantQuery(); $query = $this->findByMerchantQuery();
$query = $this->filterOrderValid($query); $query = $this->filterOrderValid($query);
$query->select('count(e.id)'); $query->select('count(e.id)');
$query->leftJoin('e.orderReductionCart', 'orc');
$query->join('e.orderReductionCart', 'orc');
$query->andWhere('orc.reductionCart = :reductionCart'); $query->andWhere('orc.reductionCart = :reductionCart');
$query->setParameter('reductionCart', $reductionCart); $query->setParameter('reductionCart', $reductionCart);
return $query->getQuery()->getSingleScalarResult(); return $query->getQuery()->getSingleScalarResult();
$query = $this->filterOrderValid($query); $query = $this->filterOrderValid($query);
$query->select('count(e.id)'); $query->select('count(e.id)');
$query->andWhere('e.user = :user'); $query->andWhere('e.user = :user');
$query->leftJoin('e.orderReductionCart', 'orc');
$query->join('e.orderReductionCart', 'orc');
$query->andWhere('orc.reductionCart = :reductionCart'); $query->andWhere('orc.reductionCart = :reductionCart');
$query->setParameter('reductionCart', $reductionCart); $query->setParameter('reductionCart', $reductionCart);
$query->setParameter('user', $user); $query->setParameter('user', $user);
} }




public function filterOrderValid($query){
public function filterOrderValid(?QueryBuilder $query) :QueryBuilder {


$query->leftJoin('e.orderStatus', 'os'); $query->leftJoin('e.orderStatus', 'os');
$query->andWhere('os.alias IN (:alias)'); $query->andWhere('os.alias IN (:alias)');

+ 21
- 9
ShopBundle/Services/OrderUtilsReductionTrait.php View File

use Lc\ShopBundle\Context\UserInterface; use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Document; use Lc\ShopBundle\Model\Document;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Lc\ShopBundle\Model\ReductionCart;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;


{ {
public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2) public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
{ {
return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
|| ($orderProductReductionCatalog1 || ($orderProductReductionCatalog1
&& $orderProductReductionCatalog2 && $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit() && $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;
&& (string)$orderProductReductionCatalog1->getValue() == (string)$orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate());
} }




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


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


return $orderReductionCart; return $orderReductionCart;
} }


public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){
public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit)
{


if($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser())>0){
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser()) > 0) {
return false; return false;
}else{
} else {
return true; return true;
} }
} }


public function getReductionCartRemainingQuantity($reductionCart) :float
{
return $reductionCart->getAvailableQuantity() - $this->orderShopRepo->countValidOrderWithReductionCart();
}

public function getReductionCartRemainingQuantityPerUser($reductionCart) :float
{
return $reductionCart->getAvailableQuantityPerUser() - $this->orderShopRepo->countValidOrderWithReductionCartPerUser();
}


public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit) public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit)
{ {
$orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class); $orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class);
}*/ }*/





} }

Loading…
Cancel
Save