Browse Source

Processus de commande

feature/export_comptable
Fab 4 years ago
parent
commit
98869f9129
8 changed files with 184 additions and 107 deletions
  1. +13
    -16
      ShopBundle/Controller/Backend/OrderController.php
  2. +5
    -4
      ShopBundle/Controller/Backend/ProductFamilyController.php
  3. +5
    -0
      ShopBundle/Model/ProductFamily.php
  4. +4
    -4
      ShopBundle/Resources/views/backend/order/panel_cart.html.twig
  5. +1
    -1
      ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig
  6. +3
    -3
      ShopBundle/Resources/views/backend/productfamily/panel_stock.html.twig
  7. +37
    -79
      ShopBundle/Services/OrderUtils.php
  8. +116
    -0
      ShopBundle/Services/OrderUtilsReductionTrait.php

+ 13
- 16
ShopBundle/Controller/Backend/OrderController.php View File

@@ -28,12 +28,12 @@ class OrderController extends AdminController
$filterOrderStatus = false;


if ($dqlFilter['orderStatus'])$filterOrderStatus = $dqlFilter['orderStatus'];
if ($dqlFilter['orderStatus']) $filterOrderStatus = $dqlFilter['orderStatus'];
$dqlFilter = $dqlFilter['filter'];

$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter);

$queryBuilder->leftJoin('entity.orderStatus','orderStatus');
$queryBuilder->leftJoin('entity.orderStatus', 'orderStatus');

dump($filterOrderStatus);
if ($filterOrderStatus) {
@@ -45,7 +45,6 @@ class OrderController extends AdminController
}



public function updateEntity($entity)
{

@@ -92,7 +91,6 @@ class OrderController extends AdminController
}



public function getUserViaFirstStepForm($entity)
{
$userClass = $this->em->getClassMetadata(UserInterface::class);
@@ -194,10 +192,10 @@ class OrderController extends AdminController

if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) {

if($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)){
if ($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)) {
$this->addFlash('success', 'La commande a bien été modifié.');
}
}else{
} else {
$this->addFlash('error', 'Une erreur s\'est produite');
}

@@ -252,7 +250,7 @@ class OrderController extends AdminController
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderPaymentClass =$this->em->getClassMetadata(OrderPaymentInterface::class);
$orderPaymentClass = $this->em->getClassMetadata(OrderPaymentInterface::class);

$orderPayment = new $orderPaymentClass->name;

@@ -275,7 +273,6 @@ class OrderController extends AdminController
}



public function orderReductionCartAction()
{

@@ -290,7 +287,7 @@ class OrderController extends AdminController
if ($formOrderReductionCart->isSubmitted() && $formOrderReductionCart->isValid()) {
$reductionCart = $formOrderReductionCart->get('reductionCart')->getData();
$orderShop->reductionError = array();
if($this->orderUtils->isReductionCartAllowToBeAddToOrder($orderShop, $reductionCart)){
if ($this->orderUtils->isReductionCartAllowToBeAddToOrder($orderShop, $reductionCart)) {
$orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart);
$this->em->persist($orderReductionCart);
$this->em->flush();
@@ -299,13 +296,13 @@ class OrderController extends AdminController
$response['status'] = 'success';
$response['message'] = 'La réduction a bien été ajouté';

}else{
} else {
$response['status'] = 'error';
$response['message'] = 'Cette réduction ne peut pas être appliqué sur cette commande';

$response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>'.$this->translator->trans($error, array(), 'lcshop'). '</i></li>';
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
}
$response['message'] .= '</ul>';
}
@@ -333,7 +330,7 @@ class OrderController extends AdminController
if ($formOrderReductionCredit->isSubmitted() && $formOrderReductionCredit->isValid()) {
$reductionCredit = $formOrderReductionCredit->get('reductionCredit')->getData();
$orderShop->reductionError = array();
if($this->orderUtils->isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit)){
if ($this->orderUtils->isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit)) {
$orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit);
$this->em->persist($orderReductionCredit);
$this->em->flush();
@@ -342,13 +339,13 @@ class OrderController extends AdminController
$response['status'] = 'success';
$response['message'] = 'L\'avoir a bien été ajouté';

}else{
} else {
$response['status'] = 'error';
$response['message'] = 'Cet avoir ne peut pas être appliqué sur cette commande';

$response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>'.$this->translator->trans($error, array(), 'lcshop'). '</i></li>';
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
}
$response['message'] .= '</ul>';
}
@@ -424,7 +421,7 @@ class OrderController extends AdminController
])
));

if(!isset($parameters['form_order_delivery_address'])) {
if (!isset($parameters['form_order_delivery_address'])) {
$formOrderDeliveryAddress = $this->createForm(OrderDeliveryAddressType::class, null, array(
'data' => $parameters['entity'],
'action' => $this->generateUrl('easyadmin', [
@@ -497,7 +494,7 @@ class OrderController extends AdminController
$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$entity = $easyadmin['item'];
$easyadmin['entity']['name'] = 'OrderShop';
$easyadmin['entity']['name'] = 'OrderShop';
$fields = $this->entity['show']['fields'];
$deleteForm = $this->createDeleteForm($this->entity['name'], $id);


+ 5
- 4
ShopBundle/Controller/Backend/ProductFamilyController.php View File

@@ -10,6 +10,7 @@ use Lc\ShopBundle\Context\ReductionCatalogInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType;
use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType;
use Lc\ShopBundle\Model\ProductFamily;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
@@ -58,11 +59,11 @@ class ProductFamilyController extends AdminController
));

$formBuilder->add('behaviorCountStock', ChoiceType::class, array(
'empty_data' => 'by-product-family',
'empty_data' => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY,
'choices' => array(
'field.ProductFamily.behaviorCountStockOptions.byQuantity' => 'by-quantity',
'field.ProductFamily.behaviorCountStockOptions.byProductFamily' => 'by-product-family',
'field.ProductFamily.behaviorCountStockOptions.byProduct' => 'by-product'
'field.ProductFamily.behaviorCountStockOptions.' . ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE,
'field.ProductFamily.behaviorCountStockOptions.' . ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY,
'field.ProductFamily.behaviorCountStockOptions.' . ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT => ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT
),
'translation_domain' => 'lcshop',
'multiple' => false,

+ 5
- 0
ShopBundle/Model/ProductFamily.php View File

@@ -17,6 +17,11 @@ use Lc\ShopBundle\Context\ProductPropertyInterface;

abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface
{
const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure' ;
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family' ;
const BEHAVIOR_COUNT_STOCK_BY_PRODUCT = 'by-product' ;
const TYPE_CREDIT = 'credit' ;

use ProductPropertyTrait;



+ 4
- 4
ShopBundle/Resources/views/backend/order/panel_cart.html.twig View File

@@ -16,13 +16,13 @@
{% endfor %}
</div>
<div class="col">
<div v-show="behaviorCountStock == 'by-product-family' || behaviorCountStock == 'by-quantity'"
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY') }}' || behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'"
class="form-group">
{{ form_label(form.availableQuantity) }}
<div class="form-widget">
<div class="input-group">
{{ form_widget(form.availableQuantity) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span>
</div>
</div>
@@ -33,7 +33,7 @@
<div class="form-widget">
<div class="input-group">
{{ form_widget(form.availableQuantityDefault) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span>
</div>
</div>
@@ -44,4 +44,4 @@
</div>
</fieldset>
</div>
</div>
</div>

+ 1
- 1
ShopBundle/Resources/views/backend/productfamily/panel_products.html.twig View File

@@ -22,7 +22,7 @@
{{ macros.productField(2, product.price, 'price', false, '€', 'v-show="productFamily.behaviorPrice == \'by-piece\'"') }}
{{ macros.productField(2, product.priceWithTax, 'priceWithTax', false, '€', 'v-show="productFamily.behaviorPrice == \'by-piece\'"') }}

{{ macros.productField(1, product.availableQuantity, 'availableQuantity',false, '', 'v-show="productFamily.behaviorCountStock== \'by-product\'"') }}
{{ macros.productField(1, product.availableQuantity, 'availableQuantity',false, '', 'v-show="productFamily.behaviorCountStock== \' '~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') ~' \'"') }}
{{ macros.productField(1, product.availableQuantityDefault, 'availableQuantityDefault',false, '', 'v-show="productFamily.behaviorCountStock== \'by-product\'"') }}

{{ macros.productField(2, product.propertyExpirationDate, 'propertyExpirationDate','propertyExpirationDateValue', '', 'v-show="productFamily.behaviorExpirationDate== \'by-product\'"') }}

+ 3
- 3
ShopBundle/Resources/views/backend/productfamily/panel_stock.html.twig View File

@@ -18,13 +18,13 @@
{% endfor %}
</div>
<div class="col">
<div v-show="behaviorCountStock == 'by-product-family' || behaviorCountStock == 'by-quantity'"
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY') }}' || behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'"
class="form-group">
{{ form_label(form.availableQuantity) }}
<div class="form-widget">
<div class="input-group">
{{ form_widget(form.availableQuantity) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span>
</div>
</div>
@@ -35,7 +35,7 @@
<div class="form-widget">
<div class="input-group">
{{ form_widget(form.availableQuantityDefault) }}
<div v-show="behaviorCountStock == 'by-quantity'" class="input-group-append">
<div v-show="behaviorCountStock == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'" class="input-group-append">
<span class="input-group-text">${ getUnitReference() }</span>
</div>
</div>

+ 37
- 79
ShopBundle/Services/OrderUtils.php View File

@@ -20,11 +20,14 @@ use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Document;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Lc\ShopBundle\Model\ProductFamily;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;

class OrderUtils
{
use OrderUtilsReductionTrait;

protected $em;
protected $security;
protected $userUtils;
@@ -53,6 +56,7 @@ class OrderUtils

public function getCartCurrent()
{

$paramsSearchOrderShop = [];

$user = $this->security->getUser();
@@ -202,19 +206,11 @@ class OrderUtils
$return = true ;
}
}
return $return ;
}

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


public function countQuantities($orderShop)
{
@@ -299,22 +295,6 @@ class OrderUtils
return $data;
}

public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog)
{
$text = '';

if ($orderProductReductionCatalog) {
if ($orderProductReductionCatalog->getUnit() == 'amount') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;€';
}

if ($orderProductReductionCatalog->getUnit() == 'percent') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;%';
}
}

return $text;
}

public function newOrderStatusHistory($order, $status, $origin = 'user')
{
@@ -326,62 +306,9 @@ class OrderUtils
$this->em->persist($orderStatusHistory);
}

public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
{
$orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
$orderReductionCart = new $orderReductionCartClass->name;

$orderReductionCart->setOrderShop($orderShop);
$orderReductionCart->setReductionCart($reductionCart);

$orderReductionCart->setTitle($reductionCart->getTitle());
$orderReductionCart->setValue($reductionCart->getValue());
$orderReductionCart->setUnit($reductionCart->getUnit());
$orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate());
$orderReductionCart->setFreeShipping($reductionCart->getFreeShipping());
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType());

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

return $orderReductionCart;
}

public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){

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

public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit)
{
$orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class);
$orderReductionCredit = new $orderReductionCreditClass->name;

$orderReductionCredit->setOrderShop($orderShop);
$orderReductionCredit->setReductionCredit($reductionCredit);

$orderReductionCredit->setTitle($reductionCredit->getTitle());
$orderReductionCredit->setValue($reductionCredit->getValue());
$orderReductionCredit->setUnit($reductionCredit->getUnit());
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());

return $orderReductionCredit;
}

/*public function getReductionCreditsAvailable($order)
{
$reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);

$reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser());
foreach ($reductionCredits as $reductionCredit){

}
}*/

public function mergeOrderShops($orderShop1, $orderShop2)
{
@@ -470,4 +397,35 @@ class OrderUtils
}
return $totalAmount;
}

public function deductAvailabilityProduct(\Lc\ShopBundle\Model\OrderShop $orderShop){
foreach ($orderShop->getOrderProducts() as $orderProduct){
switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) {
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :



break;
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :

$oldAvailability = $orderProduct->getProduct()->getProductFamily()->getAvailableQuantity();
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
$orderProduct->getProduct()->getProductFamily()->setAvailableQuantity($newAvailability);

$this->em->persist($orderProduct->getProduct()->getProductFamily());

break;
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantity();
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
$orderProduct->getProduct()->setAvailableQuantity($newAvailability);

$this->em->persist($orderProduct->getProduct());

break;
}

$this->em->flush();
}
}
}

+ 116
- 0
ShopBundle/Services/OrderUtilsReductionTrait.php View File

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

namespace Lc\ShopBundle\Services;

use App\Entity\OrderProductReductionCatalog;
use App\Entity\OrderShop;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\DocumentInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderPaymentInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCreditInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
use Lc\ShopBundle\Context\OrderStatusInterface;
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Document;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;

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


public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog)
{
$text = '';

if ($orderProductReductionCatalog) {
if ($orderProductReductionCatalog->getUnit() == 'amount') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;€';
}

if ($orderProductReductionCatalog->getUnit() == 'percent') {
$text .= '- ' . $orderProductReductionCatalog->getValue() . '&nbsp;%';
}
}

return $text;
}


public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
{
$orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
$orderReductionCart = new $orderReductionCartClass->name;

$orderReductionCart->setOrderShop($orderShop);
$orderReductionCart->setReductionCart($reductionCart);

$orderReductionCart->setTitle($reductionCart->getTitle());
$orderReductionCart->setValue($reductionCart->getValue());
$orderReductionCart->setUnit($reductionCart->getUnit());
$orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate());
$orderReductionCart->setFreeShipping($reductionCart->getFreeShipping());
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
$orderReductionCart->setType($reductionCart->getType());

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

return $orderReductionCart;
}

public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){

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

public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit)
{
$orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class);
$orderReductionCredit = new $orderReductionCreditClass->name;

$orderReductionCredit->setOrderShop($orderShop);
$orderReductionCredit->setReductionCredit($reductionCredit);

$orderReductionCredit->setTitle($reductionCredit->getTitle());
$orderReductionCredit->setValue($reductionCredit->getValue());
$orderReductionCredit->setUnit($reductionCredit->getUnit());
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());

return $orderReductionCredit;
}

/*public function getReductionCreditsAvailable($order)
{
$reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);

$reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser());
foreach ($reductionCredits as $reductionCredit){

}
}*/



}

Loading…
Cancel
Save