Переглянути джерело

Pages commandes suppresion reduction

feature/export_comptable
Fab 4 роки тому
джерело
коміт
dd24e157a9
20 змінених файлів з 426 додано та 180 видалено
  1. +109
    -112
      ShopBundle/Controller/Backend/OrderController.php
  2. +4
    -4
      ShopBundle/Form/Backend/Order/AddOrderReductionCartType.php
  3. +4
    -4
      ShopBundle/Form/Backend/Order/AddOrderReductionCreditType.php
  4. +3
    -3
      ShopBundle/Form/Backend/Order/AddPoductToOrderType.php
  5. +43
    -0
      ShopBundle/Form/Backend/Order/DeleteOrderReductionCartType.php
  6. +43
    -0
      ShopBundle/Form/Backend/Order/DeleteOrderReductionCreditType.php
  7. +18
    -0
      ShopBundle/Resources/public/js/backend/script/default/utils.js
  8. +36
    -12
      ShopBundle/Resources/public/js/backend/script/order/vuejs-order.js
  9. +35
    -15
      ShopBundle/Resources/translations/lcshop.fr.yaml
  10. +6
    -4
      ShopBundle/Resources/views/backend/order/edit-cart.html.twig
  11. +1
    -1
      ShopBundle/Resources/views/backend/order/form/modal_addproducttoorder.html.twig
  12. +6
    -6
      ShopBundle/Resources/views/backend/order/form/modal_addreductioncart.html.twig
  13. +6
    -6
      ShopBundle/Resources/views/backend/order/form/modal_addreductioncredit.html.twig
  14. +30
    -0
      ShopBundle/Resources/views/backend/order/form/modal_deletereductioncart.html.twig
  15. +30
    -0
      ShopBundle/Resources/views/backend/order/form/modal_deletereductioncredit.html.twig
  16. +14
    -4
      ShopBundle/Resources/views/backend/order/macros.html.twig
  17. +7
    -6
      ShopBundle/Services/Order/OrderUtils.php
  18. +3
    -0
      ShopBundle/Services/Order/OrderUtilsReductionTrait.php
  19. +3
    -2
      ShopBundle/Services/Price/OrderShopPriceUtils.php
  20. +25
    -1
      ShopBundle/Services/Utils.php

+ 109
- 112
ShopBundle/Controller/Backend/OrderController.php Переглянути файл

@@ -5,14 +5,19 @@ namespace Lc\ShopBundle\Controller\Backend;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use Lc\ShopBundle\Context\OrderPaymentInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderReductionCreditInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Form\Backend\Order\AddPoductToOrderType;
use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCartType;
use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCreditType;
use Lc\ShopBundle\Form\Backend\Order\OrderDeliveryAddressType;
use Lc\ShopBundle\Form\Backend\Order\OrderInvoiceAddressType;
use Lc\ShopBundle\Form\Backend\Order\OrderPaymentType;
use Lc\ShopBundle\Form\Backend\Order\OrderProductsType;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCartType;
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCartType;
use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCreditType;
use Lc\ShopBundle\Form\Backend\Order\OrderStatusType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@@ -115,15 +120,11 @@ class OrderController extends AdminController

public function addProductToOrderAction()
{

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$orderProductClass = $this->em->getClassMetadata(OrderProductInterface::class);
$formAddProductToOrder = $this->createForm(AddPoductToOrderType::class);

$formAddProductToOrder->handleRequest($this->request);

if ($formAddProductToOrder->get('product')->getData() == null) {
$response['status'] = 'error';
$response['message'] = 'Vous devez choisir un produit dans la liste';
@@ -158,12 +159,8 @@ class OrderController extends AdminController
public function orderProductsAction()
{

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$formOrderProducts = $this->createForm(OrderProductsType::class, $orderShop);

$formOrderProducts->handleRequest($this->request);


@@ -171,19 +168,19 @@ class OrderController extends AdminController
$error = false;
// dump($formOrderProducts->get('orderProducts')->getData());
foreach ($orderShop->getOrderProducts() as $orderProduct) {
if($this->orderUtils->isProductAvailable($orderProduct->getProduct(),$orderProduct->getQuantityOrder())) {
if ($this->orderUtils->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder())) {
if ($orderProduct->getQuantityOrder() <= 0) {
$this->em->remove($orderProduct);
} else {
$this->em->persist($orderProduct);
}
}else{
} else {
$error = true;
$response['status'] = 'error';
$response['message'] = 'Le prduit n\'est pas disponible dans cette quantité';
}
}
if(!$error) {
if (!$error) {
$this->em->flush();
$response['status'] = 'success';
$response['message'] = 'La commande a bien été modifié';
@@ -200,70 +197,51 @@ class OrderController extends AdminController
public function orderInvoiceAddressAction()
{

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$formOrderInvoiceAddress = $this->createForm(OrderInvoiceAddressType::class, $orderShop);

$formOrderInvoiceAddress->handleRequest($this->request);

if ($formOrderInvoiceAddress->isSubmitted() && $formOrderInvoiceAddress->isValid()) {
//TODO si la commande est valide on hydrate le champ invoiceAddresText et on vide invoiceAddres
$this->em->persist($orderShop);
$this->em->flush();
$response['status'] = 'success';
$response['message'] = 'La commande a bien été modifié';
$this->utils->addFlash('success', 'success.order.changeInvoiceAddress');
} else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('success', 'error.form.submitted');
}
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return new Response(json_encode($response));
return $this->createOrderAjaxReponse($orderShop);
}

public function orderStatusAction()
{

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$orderShop = $this->getOrderShopEntity();
$formOrderStatus = $this->createForm(OrderStatusType::class, $orderShop);

$formOrderStatus->handleRequest($this->request);

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

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

return $this->redirectToRoute('easyadmin', [
'action' => 'show',
'entity' => $this->request->query->get('entity'),
'id' => $id
'id' => $orderShop->getId()
]);

}




public function orderPaymentAction()
{

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

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

$orderPayment = new $orderPaymentClass->name;

$formOrderPayment = $this->createForm(OrderPaymentType::class, $orderPayment);

$formOrderPayment->handleRequest($this->request);
@@ -272,112 +250,124 @@ class OrderController extends AdminController
$orderPayment->setOrderShop($orderShop);
$this->em->persist($orderPayment);
$this->em->flush();
$response['status'] = 'success';
$response['message'] = 'La paiement a bien été ajouté';
$this->utils->addFlash('success', 'success.order.addPayment');
} else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('success', 'error.form.submitted');
}
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return new Response(json_encode($response));
return $this->createOrderAjaxReponse($orderShop);
}


public function orderReductionCartAction()
public function addOrderReductionCartAction()
{
$orderShop = $this->getOrderShopEntity();
$formAddOrderReductionCart = $this->createForm(AddOrderReductionCartType::class, $orderShop);
$formAddOrderReductionCart->handleRequest($this->request);

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$formOrderReductionCart = $this->createForm(OrderReductionCartType::class, $orderShop);
if ($formAddOrderReductionCart->isSubmitted() && $formAddOrderReductionCart->isValid()) {

$formOrderReductionCart->handleRequest($this->request);

if ($formOrderReductionCart->isSubmitted() && $formOrderReductionCart->isValid()) {
$reductionCart = $formOrderReductionCart->get('reductionCart')->getData();
$reductionCart = $formAddOrderReductionCart->get('reductionCart')->getData();
$orderShop->reductionError = array();
if ($this->orderUtils->isReductionCartAllowAddToOrder($orderShop, $reductionCart)) {
$orderReductionCart = $this->orderUtils->createOrderReductionCart($orderShop, $reductionCart);
$this->em->persist($orderReductionCart);
$this->em->flush();

$this->utils->addFlash('success', 'success.order.addReductionCart');
}
} else {
$this->utils->addFlash('error', $formAddOrderReductionCart->getErrors());
}
return $this->createOrderAjaxReponse($orderShop);
}

public function addOrderReductionCreditAction()
{
$orderShop = $this->getOrderShopEntity();
$formAddOrderReductionCredit = $this->createForm(AddOrderReductionCreditType::class, $orderShop);
$formAddOrderReductionCredit->handleRequest($this->request);

$response['status'] = 'success';
$response['message'] = 'La réduction a bien été ajouté';
if ($formAddOrderReductionCredit->isSubmitted() && $formAddOrderReductionCredit->isValid()) {
$reductionCredit = $formAddOrderReductionCredit->get('reductionCredit')->getData();
if ($this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)) {

} else {
$response['status'] = 'error';
$response['message'] = 'Cette réduction ne peut pas être appliqué sur cette commande';
$orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit);
$this->em->persist($orderReductionCredit);
$this->em->flush();

$response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
}
$response['message'] .= '</ul>';
$this->utils->addFlash('success', 'success.order.addReductionCredit');
}

} else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('error', $formAddOrderReductionCredit->getErrors());
}
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return new Response(json_encode($response));
return $this->createOrderAjaxReponse($orderShop);
}


public function orderReductionCreditAction()
public function deleteOrderReductionCartAction()
{

$id = $this->request->query->get('id');
$easyadmin = $this->request->attributes->get('easyadmin');
$orderShop = $easyadmin['item'];

$formOrderReductionCredit = $this->createForm(OrderReductionCreditType::class, $orderShop);

$formOrderReductionCredit->handleRequest($this->request);

if ($formOrderReductionCredit->isSubmitted() && $formOrderReductionCredit->isValid()) {
$reductionCredit = $formOrderReductionCredit->get('reductionCredit')->getData();
$orderShop->reductionError = array();
if ($this->orderUtils->isReductionCreditAllowAddToOrder($orderShop, $reductionCredit)) {
$orderReductionCredit = $this->orderUtils->createOrderReductionCredit($orderShop, $reductionCredit);
$this->em->persist($orderReductionCredit);
$orderShop = $this->getOrderShopEntity();
$formDeleteOrderReductionCart = $this->createForm(DeleteOrderReductionCartType::class);
$formDeleteOrderReductionCart->handleRequest($this->request);

if ($formDeleteOrderReductionCart->isSubmitted() && $formDeleteOrderReductionCart->isValid()) {
$orderReductionCart = $this->em->getRepository(OrderReductionCartInterface::class)->find($formDeleteOrderReductionCart->get('id')->getData());
if($orderReductionCart && $orderShop->getOrderReductionCarts()->contains($orderReductionCart)){
$orderShop->removeOrderReductionCart($orderReductionCart);
$this->em->remove($orderReductionCart);
$this->em->flush();

$this->utils->addFlash('warning', 'success.order.removeReductionCart');
}

$response['status'] = 'success';
$response['message'] = 'L\'avoir a bien été ajouté';
} else {
$this->utils->addFlash('error', $formDeleteOrderReductionCart->getErrors());
}
return $this->createOrderAjaxReponse($orderShop);
}

} else {
$response['status'] = 'error';
$response['message'] = 'Cet avoir ne peut pas être appliqué sur cette commande';
public function deleteOrderReductionCreditAction()
{
$orderShop = $this->getOrderShopEntity();
$formDeleteOrderReductionCredit = $this->createForm(DeleteOrderReductionCreditType::class);
$formDeleteOrderReductionCredit->handleRequest($this->request);

if ($formDeleteOrderReductionCredit->isSubmitted() && $formDeleteOrderReductionCredit->isValid()) {
$orderReductionCredit = $this->em->getRepository(OrderReductionCreditInterface::class)->find($formDeleteOrderReductionCredit->get('id')->getData());
if($formDeleteOrderReductionCredit && $orderShop->getOrderReductionCredits()->contains($orderReductionCredit)){
$orderShop->removeOrderReductionCredit($orderReductionCredit);
$this->em->remove($orderReductionCredit);
$this->em->flush();

$response['message'] .= '<ul>';
foreach ($orderShop->reductionError as $error) {
$response['message'] .= '<li> <i>' . $this->translator->trans($error, array(), 'lcshop') . '</i></li>';
}
$response['message'] .= '</ul>';
$this->utils->addFlash('warning', 'success.order.removeReductionCredit');
}

} else {
$response['status'] = 'error';
$response['message'] = 'Une erreur est survenue';
$this->utils->addFlash('error', $formDeleteOrderReductionCredit->getErrors());
}
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);;
return $this->createOrderAjaxReponse($orderShop);
}

protected function createOrderAjaxReponse(OrderShopInterface $order)
{
$response['flashMessages'] = $this->utils->getFlashMessages();
$response['data'] = $this->orderUtils->getOrderAsJsonObject($order);
return new Response(json_encode($response));
}


public function renderOrderCartTemplate($actionName, $templatePath, array $parameters = [])
{
dump($actionName);
if ($actionName == 'show') {
if (!isset($parameters['form_order_delivery_address'])) {
$parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView();
}
$parameters['form_order_reduction_credit'] = $this->createOrderForm(OrderReductionCreditType::class, 'orderReductionCredit', $parameters)->createView();
$parameters['form_order_reduction_cart'] = $this->createOrderForm(OrderReductionCartType::class, 'orderReductionCart', $parameters)->createView();
$parameters['form_add_order_reduction_credit'] = $this->createOrderForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView();
$parameters['form_add_order_reduction_cart'] = $this->createOrderForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_cart'] = $this->createOrderForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_credit'] = $this->createOrderForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView();
$parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView();
$parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView();
$parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();
@@ -391,11 +381,12 @@ class OrderController extends AdminController

if ($actionName == 'show') {
if (!isset($parameters['form_order_delivery_address'])) {

$parameters['form_order_delivery_address'] = $this->createOrderForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView();
}
$parameters['form_order_reduction_credit'] = $this->createOrderForm(OrderReductionCreditType::class, 'orderReductionCredit', $parameters)->createView();
$parameters['form_order_reduction_cart'] = $this->createOrderForm(OrderReductionCartType::class, 'orderReductionCart', $parameters)->createView();
$parameters['form_add_order_reduction_credit'] = $this->createOrderForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView();
$parameters['form_add_order_reduction_cart'] = $this->createOrderForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_cart'] = $this->createOrderForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView();
$parameters['form_delete_order_reduction_credit'] = $this->createOrderForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView();
$parameters['form_add_product_to_order'] = $this->createOrderForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView();
$parameters['form_order_products'] = $this->createOrderForm(OrderProductsType::class, 'orderProducts', $parameters)->createView();
$parameters['form_order_invoice_address'] = $this->createOrderForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView();
@@ -488,7 +479,7 @@ class OrderController extends AdminController
'order' => $this->orderUtils->getOrderAsJsonObject($entity)

];
dump($this->entity['name']);
return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]);
}

@@ -506,4 +497,10 @@ dump($this->entity['name']);
]);
}

protected function getOrderShopEntity()
{
$easyadmin = $this->request->attributes->get('easyadmin');
return $easyadmin['item'];
}

}

ShopBundle/Form/Backend/Order/OrderReductionCartType.php → ShopBundle/Form/Backend/Order/AddOrderReductionCartType.php Переглянути файл

@@ -19,7 +19,7 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class OrderReductionCartType extends AbstractType
class AddOrderReductionCartType extends AbstractType
{
protected $em;

@@ -42,8 +42,8 @@ class OrderReductionCartType extends AbstractType
'required' => true,
'mapped'=>false
));
$builder->add('saveOrderReductionCart', ButtonType::class, array(
'label' => 'field.OrderShop.saveOrderReductionCart'
$builder->add('add', ButtonType::class, array(
'label' => 'action.add'
));


@@ -55,4 +55,4 @@ class OrderReductionCartType extends AbstractType
'data_class' => $this->em->getClassMetadata(OrderShopInterface::class)->getName(),
]);
}
}
}

ShopBundle/Form/Backend/Order/OrderReductionCreditType.php → ShopBundle/Form/Backend/Order/AddOrderReductionCreditType.php Переглянути файл

@@ -21,7 +21,7 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class OrderReductionCreditType extends AbstractType
class AddOrderReductionCreditType extends AbstractType
{
protected $em;
protected $orderUtils;
@@ -48,8 +48,8 @@ class OrderReductionCreditType extends AbstractType
'required' => true,
'mapped'=>false
));
$builder->add('saveOrderReductionCredit', ButtonType::class, array(
'label' => 'field.OrderShop.saveOrderReductionCredit'
$builder->add('add', ButtonType::class, array(
'label' => 'action.add'
));


@@ -61,4 +61,4 @@ class OrderReductionCreditType extends AbstractType
'data_class' => $this->em->getClassMetadata(OrderShopInterface::class)->getName(),
]);
}
}
}

+ 3
- 3
ShopBundle/Form/Backend/Order/AddPoductToOrderType.php Переглянути файл

@@ -49,8 +49,8 @@ class AddPoductToOrderType extends AbstractType
->add('quantity', IntegerType::class, array(
'mapped' => false
))
->add('addProductToOrder', ButtonType::class, array(
'label'=> 'field.OrderShop.addOrderToProduct'
->add('add', ButtonType::class, array(
'label'=> 'action.add'
));
}

@@ -60,4 +60,4 @@ class AddPoductToOrderType extends AbstractType
'translation_domain'=>'lcshop'
]);
}
}
}

+ 43
- 0
ShopBundle/Form/Backend/Order/DeleteOrderReductionCartType.php Переглянути файл

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

namespace Lc\ShopBundle\Form\Backend\Order;

use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DeleteOrderReductionCartType extends AbstractType
{
protected $em ;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em ;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', HiddenType::class)
->add('delete', ButtonType::class);

/* ->add('id', HiddenType::class);*/
}

public function configureOptions(OptionsResolver $resolver)
{
/*$resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(OrderReductionCartInterface::class)->getName(),
]);*/
}
}

+ 43
- 0
ShopBundle/Form/Backend/Order/DeleteOrderReductionCreditType.php Переглянути файл

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

namespace Lc\ShopBundle\Form\Backend\Order;

use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DeleteOrderReductionCreditType extends AbstractType
{
protected $em ;

public function __construct(EntityManagerInterface $em)
{
$this->em = $em ;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', HiddenType::class)
->add('delete', ButtonType::class);

/* ->add('id', HiddenType::class);*/
}

public function configureOptions(OptionsResolver $resolver)
{
/*$resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(OrderReductionCartInterface::class)->getName(),
]);*/
}
}

+ 18
- 0
ShopBundle/Resources/public/js/backend/script/default/utils.js Переглянути файл

@@ -153,6 +153,14 @@ function userNotAllowToEdit() {



function setFlashMessages(flashMessages){
for (var type in flashMessages) {
for (var key in flashMessages[type]) {
generateNotice(type, flashMessages[type][key]);
}
}
}

function generateNotice(type, text) {
toastr.options.timeOut = 30000;
toastr[type](text);
@@ -175,3 +183,13 @@ function generateNotice(type, text) {
}
});*/
}


function checkFormValidity(formId){
if(!document.getElementById(formId.substr(1)).checkValidity()){
document.getElementById(formId.substr(1)).reportValidity()
return false;
}else{
return true;
}
}

+ 36
- 12
ShopBundle/Resources/public/js/backend/script/order/vuejs-order.js Переглянути файл

@@ -105,9 +105,17 @@ appOrder = new Vue({
},
mounted: function () {
this.updateOrder(window.orderObject);
this.preventFormSubmit();
//log($(this.$el).find('#orderProductsForm').replace(/__name__/g, 0));
},
methods: {
preventFormSubmit: function (){
$(document).keypress(function(e) {
if (e.which == 13) {
e.preventDefault();
}
});
},
addProductToOrder: function () {
this.postForm('#addProductToOrderForm', false);
},
@@ -127,26 +135,42 @@ appOrder = new Vue({
this.postForm('#orderDeliveryAvailabilityForm', '#modal-order-delivery-availability');
},
addOrderReductionCart: function () {
this.postForm('#orderReductionCartForm', '#modal-reduction-cart');
this.postForm('#addOrderReductionCartForm', '#modal-add-reduction-cart');
},
modalOrderReductionCart: function (id) {
$('#modal-delete-reduction-cart').find('#delete_order_reduction_cart_id').val(id);
$('#modal-delete-reduction-cart').modal("show")
},
deleteOrderReductionCart: function () {
this.postForm('#deleteOrderReductionCartForm', '#modal-delete-reduction-cart');
},
modalOrderReductionCredit: function (id) {
$('#modal-delete-reduction-credit').find('#delete_order_reduction_credit_id').val(id);
$('#modal-delete-reduction-credit').modal("show")
},
deleteOrderReductionCredit: function () {
this.postForm('#deleteOrderReductionCreditForm', '#modal-delete-reduction-credit');
},
addOrderReductionCredit: function () {
this.postForm('#orderReductionCreditForm', '#modal-reduction-credit');
this.postForm('#addOrderReductionCreditForm', '#modal-add-reduction-credit');
},

postForm: function (formId, modalId) {
var app = this;
this.isLoading = true;
if (modalId) $(modalId).modal('hide');
$.ajax({
url: $(formId).prop('action'),
method: "POST",
data: $(formId).serialize(),
dataType: "json",
success: function (response) {
generateNotice(response.status, response.message);
app.updateOrder(response.data);
}
});
if(checkFormValidity(formId)) {
$.ajax({
url: $(formId).prop('action'),
method: "POST",
data: $(formId).serialize(),
dataType: "json",
success: function (response) {
setFlashMessages(response.flashMessages);
app.updateOrder(response.data);
}
});
}
},
updateOrder: function (orderObject) {
this.orderProducts = orderObject.orderProducts;

+ 35
- 15
ShopBundle/Resources/translations/lcshop.fr.yaml Переглянути файл

@@ -45,22 +45,41 @@ group:
None: Aucune valeur
label.form.empty_value: Choisissez une option
form.label.delete: Supprimer l'image

success:
order:
addPayment: Le paiement a bien été ajouté
changeStatus: Le statut de la commande a été modifié
changeInvoiceAddress: L'adresse de facuration a bien été modifié
changeDeliveryAddress: L'adresse de livraison a bien été modifié
error:
form:
submitted: Une erreur est survenue à la soumission du formulaire
order:
closeSale: Les commandes sont actuellements fermés
invoiceAddressMissing: Vous n'avez pas d'adresse de facturation
deliveryAddressMissing: Vous n'avez pas d'adresse de livraison
deliverySlotMissing: Vous n'avez pas de créneau de livraison
productUnavailable: Certains produits ne sont plus disponibles
nextStatusNotAllow: La commande ne peut passer à ce statut
noPayment: Le montant de la commande n'a pas été règlé dans sa totalité

reductionCart:
conditionsError: Cette réduction ne peut pas être appliqué sur cette commande
date: La réduction n'est plus active
pointSale: L'ambassade ne correspond pas
deliveryZone: La zone de livraison ne correspond pas
deliverySlot: La créneau de livraison ne correspond pas
groupUser: Le(s) groupe(s) utilisateurs ne correspondent pas
user: L'utilisateur ne correspond pas
combinable: La réduction n'est pas cumulable avec celle dejà appliqué
amountMin: Le montant minimum de commandes n'est pas respecté
qauntity: La réduction n'est plus disponible
quantityPerUser: La reduction n'est plus disponible pour cet utilisateur
reductionCredit:
userNotAllow: Cet avoir n'est pas disponible pour cet utilisateur
alreayUse: Cet avoir a déjà été utilisé
field:
error:
orderStatus:
nextStatusAllowed: La commande ne peut passer à ce statut
noPayment: Le montant de la commande n'a pas été règlé dans sa totalité
reductionCart:
date: La réduction n'est plus active
pointSale: L'ambassade ne correspond pas
deliveryZone: La zone de livraison ne correspond pas
deliverySlot: La créneau de livraison ne correspond pas
groupUser: Le(s) groupe(s) utilisateurs ne correspondent pas
user: L'utilisateur ne correspond pas
combinable: La réduction n'est pas cumulable avec celle dejà appliqué
amountMin: Le montant minimum de commandes n'est pas respecté
qauntity: La réduction n'est plus disponible
quantityPerUser: La reduction n'est plus disponible pour cet utilisateur
default:
placeholder: Choisissez une option
deliveryPointSale: Lieu de livraison
@@ -271,6 +290,7 @@ action:
list: Retour à la liste
deselect: Désélectionner
form.empty_value: Aucun(e)
add: Ajouter
user:
account: Mon compte
logout: Me déconnecter

+ 6
- 4
ShopBundle/Resources/views/backend/order/edit-cart.html.twig Переглянути файл

@@ -4,9 +4,9 @@
{% import '@LcShop/backend/order/macros.html.twig' as orderMacros %}

{% block main %}
{% form_theme form_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{# {% form_theme form_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{% form_theme form_add_product_to_order '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{% form_theme form_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
{% form_theme form_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}#}
<div class="lc-vue-js-container" id="lc-order-edit">


@@ -52,8 +52,10 @@
{% include '@LcShop/backend/order/form/modal_deliveryaddress.html.twig' %}
{% include '@LcShop/backend/order/form/modal_deliveryavailability.html.twig' %}
{% include '@LcShop/backend/order/form/modal_orderstatus.html.twig' %}
{% include '@LcShop/backend/order/form/modal_reductioncredit.html.twig' %}
{% include '@LcShop/backend/order/form/modal_reductioncart.html.twig' %}
{% include '@LcShop/backend/order/form/modal_addreductioncredit.html.twig' %}
{% include '@LcShop/backend/order/form/modal_addreductioncart.html.twig' %}
{% include '@LcShop/backend/order/form/modal_deletereductioncart.html.twig' %}
{% include '@LcShop/backend/order/form/modal_deletereductioncredit.html.twig' %}
{% include '@LcShop/backend/order/form/modal_addproducttoorder.html.twig' %}

{# {{ macros.startCard(3, 'OrderShop.addProduct', 'success') }}

+ 1
- 1
ShopBundle/Resources/views/backend/order/form/modal_addproducttoorder.html.twig Переглянути файл

@@ -23,7 +23,7 @@
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_widget(form_add_product_to_order.addProductToOrder, {"attr": {'class' : 'btn btn-primary', '@click' : 'addProductToOrder'}}) }}
{{ form_widget(form_add_product_to_order.add, {"attr": {'class' : 'btn btn-primary', '@click' : 'addProductToOrder'}}) }}
</div>
</div>
<!-- /.modal-content -->

ShopBundle/Resources/views/backend/order/form/modal_reductioncart.html.twig → ShopBundle/Resources/views/backend/order/form/modal_addreductioncart.html.twig Переглянути файл

@@ -1,8 +1,8 @@
{% trans_default_domain 'lcshop' %}

<div class="modal fade show" id="modal-reduction-cart">
{{ form_start(form_order_reduction_cart, {'attr': { 'id' : 'orderReductionCartForm'}}) }}) }}
{% form_theme form_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal fade show" id="modal-add-reduction-cart">
{{ form_start(form_add_order_reduction_cart, {'attr': { 'id' : 'addOrderReductionCartForm'}}) }}
{% form_theme form_add_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog">

<div class="modal-content">
@@ -14,16 +14,16 @@
</div>
<div class="modal-body">
<div class="col">
{{ form_row(form_order_reduction_cart.reductionCart) }}
{{ form_row(form_add_order_reduction_cart.reductionCart) }}
</div>

</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_order_reduction_cart.saveOrderReductionCart, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCart'}}) }}
{{ form_row(form_add_order_reduction_cart.add, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCart'}}) }}
</div>
</div>
<!-- /.modal-content -->
</div>
{{ form_end(form_order_reduction_cart) }}
{{ form_end(form_add_order_reduction_cart) }}
</div>

ShopBundle/Resources/views/backend/order/form/modal_reductioncredit.html.twig → ShopBundle/Resources/views/backend/order/form/modal_addreductioncredit.html.twig Переглянути файл

@@ -1,8 +1,8 @@
{% trans_default_domain 'lcshop' %}

<div class="modal fade show" id="modal-reduction-credit">
{{ form_start(form_order_reduction_credit, {'attr': {'class': 'row', 'id' : 'orderReductionCreditForm'}}) }}) }}
{% form_theme form_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal fade show" id="modal-add-reduction-credit">
{{ form_start(form_add_order_reduction_credit, {'attr': {'class': 'row', 'id' : 'addOrderReductionCreditForm'}}) }}
{% form_theme form_add_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog">

<div class="modal-content">
@@ -14,16 +14,16 @@
</div>
<div class="modal-body">
<div class="col">
{{ form_row(form_order_reduction_credit.reductionCredit) }}
{{ form_row(form_add_order_reduction_credit.reductionCredit) }}
</div>

</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_order_reduction_credit.saveOrderReductionCredit, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCredit'}}) }}
{{ form_row(form_add_order_reduction_credit.add, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCredit'}}) }}
</div>
</div>
<!-- /.modal-content -->
</div>
{{ form_end(form_order_reduction_credit) }}
{{ form_end(form_add_order_reduction_credit) }}
</div>

+ 30
- 0
ShopBundle/Resources/views/backend/order/form/modal_deletereductioncart.html.twig Переглянути файл

@@ -0,0 +1,30 @@
{% trans_default_domain 'lcshop' %}

<div class="modal fade show" id="modal-delete-reduction-cart">
{{ form_start(form_delete_order_reduction_cart, {'attr': { 'id' : 'deleteOrderReductionCartForm'}}) }}
{% form_theme form_delete_order_reduction_cart '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog">

<div class="modal-content">
<div class="modal-header">
<h4>{{ "action.order.deleteReductionCart"|trans }}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col">
Est-vous sur de vouloir surppimer cette réduction
{{ form_row(form_delete_order_reduction_cart.id) }}
</div>

</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_delete_order_reduction_cart.delete, {"attr": {'class' : 'btn btn-primary', '@click': 'deleteOrderReductionCart'}}) }}
</div>
</div>
<!-- /.modal-content -->
</div>#}
{{ form_end(form_delete_order_reduction_cart) }}
</div>

+ 30
- 0
ShopBundle/Resources/views/backend/order/form/modal_deletereductioncredit.html.twig Переглянути файл

@@ -0,0 +1,30 @@
{% trans_default_domain 'lcshop' %}

<div class="modal fade show" id="modal-delete-reduction-credit">
{{ form_start(form_delete_order_reduction_credit, {'attr': { 'id' : 'deleteOrderReductionCreditForm'}}) }}
{% form_theme form_delete_order_reduction_credit '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}
<div class="modal-dialog">

<div class="modal-content">
<div class="modal-header">
<h4>{{ "action.order.deleteReductionCredit"|trans }}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="col">
Est-vous sur de vouloir surppimer cette réduction
{{ form_row(form_delete_order_reduction_credit.id) }}
</div>

</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
{{ form_row(form_delete_order_reduction_credit.delete, {"attr": {'class' : 'btn btn-primary', '@click': 'deleteOrderReductionCredit'}}) }}
</div>
</div>
<!-- /.modal-content -->
</div>#}
{{ form_end(form_delete_order_reduction_credit) }}
</div>

+ 14
- 4
ShopBundle/Resources/views/backend/order/macros.html.twig Переглянути файл

@@ -72,10 +72,10 @@
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-add-product-to-order">
<i class="fa fa-plus"></i> {{ "action.order.addOrderProduct"|trans }}
</button>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-reduction-cart">
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-add-reduction-cart">
<i class="fa fa-shopping-basket"></i> {{ "action.order.addReductionCart"|trans }}
</button>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-reduction-credit">
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-add-reduction-credit">
<i class="fa fa-backspace"></i> {{ "action.order.addReductionCredit"|trans }}
</button>
</div>
@@ -89,13 +89,23 @@
</tr>
<template v-for="(orderReductionCart, key) in order.orderReductionCarts">
<tr>
<th>${orderReductionCart.title}</th>
<th>
${orderReductionCart.title}
<button type="button" class="btn-sm btn-danger" @click="modalOrderReductionCart(orderReductionCart.id)">
<i class="fa fa-trash"></i>
</button>
</th>
<td>${orderReductionCart.amount}€</td>
</tr>
</template>
<template v-for="(orderReductionCredit, key) in order.orderReductionCredits">
<tr>
<th>${orderReductionCredit.title}</th>
<th>${orderReductionCredit.title}

<button type="button" class="btn-sm btn-danger" @click="modalOrderReductionCredit(orderReductionCredit.id)">
<i class="fa fa-trash"></i>
</button>
</th>
<td>${orderReductionCredit.amount}€</td>
</tr>
</template>

+ 7
- 6
ShopBundle/Services/Order/OrderUtils.php Переглянути файл

@@ -26,6 +26,7 @@ use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\DocumentUtils;
use Lc\ShopBundle\Services\Price\OrderShopPriceUtils;
use Lc\ShopBundle\Services\UserUtils;
use Lc\ShopBundle\Services\Utils;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;

@@ -43,11 +44,11 @@ class OrderUtils
protected $priceUtils;
protected $productFamilyUtils;
protected $documentUtils;
protected $session;
protected $utils;

public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils,
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils,
DocumentUtils $documentUtils, SessionInterface $session)
DocumentUtils $documentUtils, Utils $utils)
{
$this->em = $em;
$this->security = $security;
@@ -59,7 +60,7 @@ class OrderUtils
$this->priceUtils = $priceUtils;
$this->productFamilyUtils = $productFamilyUtils;
$this->documentUtils = $documentUtils;
$this->session = $session;
$this->utils = $utils;
}


@@ -91,7 +92,7 @@ class OrderUtils
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
$this->utils->addFlash('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
} else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
}
@@ -224,7 +225,7 @@ class OrderUtils
$textError .= ' dans cette quantité ' ;
$textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ;
}
$this->session->getFlashBag()->add('error', $textError) ;
$this->utils->addFlash('error', $textError);
}

return $return ;
@@ -405,7 +406,7 @@ class OrderUtils
if ($this->getTotalOrderPayments($order) >= $this->priceUtils->getTotalWithTax($order)) {
return true;
} else {
$order->editError[] = 'field.error.orderStatus.noPayment';
$this->utils->addFlash('error', 'error.order.noPayment');
return false;
}
}

+ 3
- 0
ShopBundle/Services/Order/OrderUtilsReductionTrait.php Переглянути файл

@@ -67,11 +67,14 @@ trait OrderUtilsReductionTrait

// appartient à l'utilisateur
if(!$reductionCredit->getUsers()->contains($user)) {
$this->utils->addFlash('error', 'error.reductionCredit.userNotAllow');
return false ;
}

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

return false;
}


+ 3
- 2
ShopBundle/Services/Price/OrderShopPriceUtils.php Переглянути файл

@@ -36,6 +36,7 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface
foreach ($orderShop->getOrderProducts() as $orderProduct) {
$total += $this->orderProductPriceUtils->getTotalWithTaxAndReduction($orderProduct);
}

return $total;

}
@@ -61,8 +62,8 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface
];
}

$orderProductsTaxes[$idTaxRate]['totalOrderProducts'] += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct) * $this->getReductionsCoef($orderShop);
$orderProductsTaxes[$idTaxRate]['totalTaxes'] += $this->orderProductPriceUtils->getTotalTaxes($orderProduct) * $this->getReductionsCoef($orderShop) ;
$orderProductsTaxes[$idTaxRate]['totalOrderProducts'] += $this->orderProductPriceUtils->getTotalWithReduction($orderProduct) / $this->getReductionsCoef($orderShop);
$orderProductsTaxes[$idTaxRate]['totalTaxes'] += $this->orderProductPriceUtils->getTotalTaxes($orderProduct) / $this->getReductionsCoef($orderShop) ;
}

return $orderProductsTaxes ;

+ 25
- 1
ShopBundle/Services/Utils.php Переглянути файл

@@ -13,17 +13,23 @@ use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Context\UserPointSaleInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class Utils
{
protected $em ;
protected $parameterBag ;
protected $merchantUtils ;
protected $session;
protected $translator;

public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag)
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, SessionInterface $session, TranslatorInterface $translator)
{
$this->em = $em ;
$this->parameterBag = $parameterBag ;
$this->session = $session;
$this->translator = $translator;
}


@@ -299,4 +305,22 @@ class Utils
return '' ;
}

public function addFlash($success, $message, $extraMessages = array(), $params=array(), $domain='lcshop'){
$message = $this->translator->trans($message, $params,$domain);

if (count($extraMessages)) {
$message .= '<ul>';
foreach ($extraMessages as $extraMessage) {
$message .= '<li> <i>' . $this->translator->trans($extraMessage, array(), $domain) . '</i></li>';
}
$message .= '</ul>';
}

$this->session->getFlashBag()->add($success, $message);

}

public function getFlashMessages(){
return $this->session->getFlashBag()->all();
}
}

Завантаження…
Відмінити
Зберегти