namespace Lc\ShopBundle\Controller\Backend; | namespace Lc\ShopBundle\Controller\Backend; | ||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | ||||
use FOS\UserBundle\Model\UserManagerInterface; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\OrderPaymentInterface; | use Lc\ShopBundle\Context\OrderPaymentInterface; | ||||
use Lc\ShopBundle\Context\OrderProductInterface; | use Lc\ShopBundle\Context\OrderProductInterface; | ||||
use Lc\ShopBundle\Context\OrderReductionCartInterface; | use Lc\ShopBundle\Context\OrderReductionCartInterface; | ||||
use Lc\ShopBundle\Context\OrderReductionCreditInterface; | use Lc\ShopBundle\Context\OrderReductionCreditInterface; | ||||
use Lc\ShopBundle\Context\OrderShopInterface; | use Lc\ShopBundle\Context\OrderShopInterface; | ||||
use Lc\ShopBundle\Context\OrderUtilsInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | use Lc\ShopBundle\Context\UserInterface; | ||||
use Lc\ShopBundle\Form\Backend\Order\AddPoductToOrderType; | use Lc\ShopBundle\Form\Backend\Order\AddPoductToOrderType; | ||||
use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCartType; | use Lc\ShopBundle\Form\Backend\Order\DeleteOrderReductionCartType; | ||||
use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCartType; | use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCartType; | ||||
use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCreditType; | use Lc\ShopBundle\Form\Backend\Order\AddOrderReductionCreditType; | ||||
use Lc\ShopBundle\Form\Backend\Order\OrderStatusType; | use Lc\ShopBundle\Form\Backend\Order\OrderStatusType; | ||||
use Lc\ShopBundle\Model\CreditHistory; | |||||
use Lc\ShopBundle\Model\OrderStatus; | |||||
use Lc\ShopBundle\Services\CreditUtils; | |||||
use Lc\ShopBundle\Services\Utils; | |||||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
use Symfony\Component\HttpFoundation\Response; | use Symfony\Component\HttpFoundation\Response; | ||||
use Symfony\Component\Security\Core\Security; | |||||
use Symfony\Contracts\Translation\TranslatorInterface; | |||||
class OrderController extends AdminController | class OrderController extends AdminController | ||||
{ | { | ||||
protected $creditUtils; | |||||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, MerchantUtilsInterface $merchantUtils, MailjetTransport $mailjetTransport, OrderUtilsInterface $orderUtils, TranslatorInterface $translator, CreditUtils $creditUtils) | |||||
{ | |||||
parent::__construct($security, $userManager, $em, $utils, $merchantUtils, $mailjetTransport, $orderUtils, $translator); | |||||
$this->creditUtils = $creditUtils; | |||||
} | |||||
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null) | protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null) | ||||
{ | { | ||||
$filterIsOrderStatus = false; | $filterIsOrderStatus = false; | ||||
$formOrderStatus->handleRequest($this->request); | $formOrderStatus->handleRequest($this->request); | ||||
if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) { | if ($formOrderStatus->isSubmitted() && $formOrderStatus->isValid()) { | ||||
$oldStatus = $orderShop->getOrderStatus(); | |||||
if ($orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop)) { | |||||
$orderShop = $this->orderUtils->changeOrderStatus($formOrderStatus->get('orderStatus')->getData(), $orderShop); | |||||
if($oldStatus !== $orderShop->getOrderStatus()){ | |||||
$this->utils->addFlash('success', 'success.order.changeStatus'); | $this->utils->addFlash('success', 'success.order.changeStatus'); | ||||
} | } | ||||
} else { | } else { | ||||
if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) { | if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) { | ||||
$orderPayment->setOrderShop($orderShop); | $orderPayment->setOrderShop($orderShop); | ||||
$this->em->persist($orderPayment); | |||||
$this->em->flush(); | |||||
$this->utils->addFlash('success', 'success.order.addPayment'); | |||||
if($orderPayment->getMeanPayment('credit')){ | |||||
$orderPayment->setEditable(false); | |||||
$params['amount'] = $orderPayment->getAmount(); | |||||
$params['orderPayment'] = $orderPayment->getId(); | |||||
$creditHistory = $this->creditUtils->initCreditHistory(CreditHistory::TYPE_DEBIT, $orderShop->getUser(), $params); | |||||
if($this->creditUtils->saveCreditHistory($creditHistory)) { | |||||
$this->em->persist($orderPayment); | |||||
$this->em->flush(); | |||||
$this->utils->addFlash('success', 'success.credit.debited'); | |||||
$this->utils->addFlash('success', 'success.order.addPayment'); | |||||
}else{ | |||||
$this->utils->addFlash('success', 'error.credit.debited'); | |||||
} | |||||
}else{ | |||||
$orderPayment->setEditable(true); | |||||
$this->em->persist($orderPayment); | |||||
$this->em->flush(); | |||||
$this->utils->addFlash('success', 'success.order.addPayment'); | |||||
} | |||||
} else { | } else { | ||||
$this->utils->addFlash('error', $formOrderPayment->getErrors()); | $this->utils->addFlash('error', $formOrderPayment->getErrors()); | ||||
} | } | ||||
} | } | ||||
public function renderOrderCartTemplate($actionName, $templatePath, array $parameters = []) | |||||
{ | |||||
if ($actionName == 'show') { | |||||
if (!isset($parameters['form_order_delivery_address'])) { | |||||
$parameters['form_order_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); | |||||
} | |||||
$parameters['form_add_order_reduction_credit'] = $this->createCustomForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView(); | |||||
$parameters['form_add_order_reduction_cart'] = $this->createCustomForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView(); | |||||
$parameters['form_delete_order_reduction_cart'] = $this->createCustomForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView(); | |||||
$parameters['form_delete_order_reduction_credit'] = $this->createCustomForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView(); | |||||
$parameters['form_add_product_to_order'] = $this->createCustomForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView(); | |||||
$parameters['form_order_products'] = $this->createCustomForm(OrderProductsType::class, 'orderProducts', $parameters)->createView(); | |||||
$parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); | |||||
$parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); | |||||
} | |||||
return parent::renderTemplate($actionName, $templatePath, $parameters); | |||||
} | |||||
public function renderOrderShopTemplate($actionName, $templatePath, array $parameters = []) | public function renderOrderShopTemplate($actionName, $templatePath, array $parameters = []) | ||||
{ | { | ||||
if ($actionName == 'show') { | if ($actionName == 'show') { | ||||
if (!isset($parameters['form_order_delivery_address'])) { | |||||
$parameters['form_order_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); | |||||
$orderShop = $this->getOrderShopEntity(); | |||||
switch ($orderShop->getOrderStatus()->getAlias()){ | |||||
case OrderStatus::ALIAS_CART : | |||||
if (!isset($parameters['form_order_delivery_address'])) { | |||||
$parameters['form_order_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); | |||||
} | |||||
$parameters['form_add_order_reduction_credit'] = $this->createCustomForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView(); | |||||
$parameters['form_add_order_reduction_cart'] = $this->createCustomForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView(); | |||||
$parameters['form_delete_order_reduction_cart'] = $this->createCustomForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView(); | |||||
$parameters['form_delete_order_reduction_credit'] = $this->createCustomForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView(); | |||||
$parameters['form_add_product_to_order'] = $this->createCustomForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView(); | |||||
$parameters['form_order_products'] = $this->createCustomForm(OrderProductsType::class, 'orderProducts', $parameters)->createView(); | |||||
break; | |||||
case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT : | |||||
case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE : | |||||
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); | |||||
$parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); | |||||
$parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); | |||||
break; | |||||
} | } | ||||
$parameters['form_add_order_reduction_credit'] = $this->createCustomForm(AddOrderReductionCreditType::class, 'addOrderReductionCredit', $parameters)->createView(); | |||||
$parameters['form_add_order_reduction_cart'] = $this->createCustomForm(AddOrderReductionCartType::class, 'addOrderReductionCart', $parameters)->createView(); | |||||
$parameters['form_delete_order_reduction_cart'] = $this->createCustomForm(DeleteOrderReductionCartType::class, 'deleteOrderReductionCart', $parameters)->createView(); | |||||
$parameters['form_delete_order_reduction_credit'] = $this->createCustomForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $parameters)->createView(); | |||||
$parameters['form_add_product_to_order'] = $this->createCustomForm(AddPoductToOrderType::class, 'addProductToOrder', $parameters)->createView(); | |||||
$parameters['form_order_products'] = $this->createCustomForm(OrderProductsType::class, 'orderProducts', $parameters)->createView(); | |||||
$parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); | |||||
$parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); | |||||
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); | |||||
} | } | ||||
dump($templatePath); | |||||
return parent::renderTemplate($actionName, $templatePath, $parameters); | return parent::renderTemplate($actionName, $templatePath, $parameters); | ||||
} | } | ||||
]; | ]; | ||||
return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]); | |||||
return $this->executeDynamicMethod('renderOrderShopTemplate', ['show', $this->entity['templates']['show'], $parameters]); | |||||
} | } | ||||
/** | /** |
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\OrderPaymentInterface; | use Lc\ShopBundle\Context\OrderPaymentInterface; | ||||
use Lc\ShopBundle\Model\OrderPayment; | use Lc\ShopBundle\Model\OrderPayment; | ||||
use Lc\ShopBundle\Services\Utils; | |||||
use Symfony\Component\Form\AbstractType; | use Symfony\Component\Form\AbstractType; | ||||
use Symfony\Component\Form\Extension\Core\Type\ButtonType; | use Symfony\Component\Form\Extension\Core\Type\ButtonType; | ||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
public function buildForm(FormBuilderInterface $builder, array $options) | public function buildForm(FormBuilderInterface $builder, array $options) | ||||
{ | { | ||||
$builder | $builder | ||||
->add('type', ChoiceType::class, array( | |||||
->add('meanPayment', ChoiceType::class, array( | |||||
'choices' => array( | 'choices' => array( | ||||
'field.orderPayment.' . OrderPayment::TYPE_CHEQUE => OrderPayment::TYPE_CHEQUE, | |||||
'field.orderPayment.' . OrderPayment::TYPE_CREDIT => OrderPayment::TYPE_CREDIT, | |||||
'field.orderPayment.' . OrderPayment::TYPE_CREDIT_CARD => OrderPayment::TYPE_CREDIT_CARD | |||||
'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CHEQUE => Utils::MEAN_PAYMENT_CHEQUE , | |||||
'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CREDIT_CARD => Utils::MEAN_PAYMENT_CREDIT_CARD, | |||||
'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CREDIT => Utils::MEAN_PAYMENT_CREDIT, | |||||
'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_TRANSFER => Utils::MEAN_PAYMENT_TRANSFER, | |||||
'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH | |||||
), | ), | ||||
'required' => true | 'required' => true | ||||
)) | )) |
'widget' => 'single_text', | 'widget' => 'single_text', | ||||
'required' => true | 'required' => true | ||||
)) | )) | ||||
->add('reference', TextType::class) | |||||
->add('reference', TextType::class, array( | |||||
'required'=>false | |||||
)) | |||||
->add('comment', TextareaType::class) | |||||
->add('comment', TextareaType::class, array( | |||||
'required'=>false | |||||
)) | |||||
->add('add', SubmitType::class, array( | ->add('add', SubmitType::class, array( | ||||
'label' => 'action.add' | 'label' => 'action.add' | ||||
)); | )); |
*/ | */ | ||||
protected $editable; | protected $editable; | ||||
public function __toString() | |||||
{ | |||||
return $this->amount. ' le '.$this->getPaidAt()->format('d-m-y').' par '.$this->getMeanPayment(); | |||||
} | |||||
public function getOrderShop(): ?OrderShop | public function getOrderShop(): ?OrderShop | ||||
{ | { | ||||
return $this->orderShop; | return $this->orderShop; |
var app = this; | var app = this; | ||||
fields = ['fieldQuantity', 'fieldProduct']; | fields = ['fieldQuantity', 'fieldProduct']; | ||||
fields.forEach(function (field) { | fields.forEach(function (field) { | ||||
var name = $(app.$refs[field]).prop('name'); | |||||
var id = $(app.$refs[field]).prop('id'); | |||||
name = name.replace(/__name__/g, app.keyItem); | |||||
id = id.replace(/__name__/g, app.keyItem); | |||||
$(app.$refs[field]).prop('name', name); | |||||
$(app.$refs[field]).prop('id', id); | |||||
if($(app.$refs[field]).length) { | |||||
var name = $(app.$refs[field]).prop('name'); | |||||
var id = $(app.$refs[field]).prop('id'); | |||||
name = name.replace(/__name__/g, app.keyItem); | |||||
id = id.replace(/__name__/g, app.keyItem); | |||||
$(app.$refs[field]).prop('name', name); | |||||
$(app.$refs[field]).prop('id', id); | |||||
} | |||||
//log(app.$refs[field]); | //log(app.$refs[field]); | ||||
}); | }); | ||||
}, | }, | ||||
this.postForm('#addProductToOrderForm', false); | this.postForm('#addProductToOrderForm', false); | ||||
}, | }, | ||||
addOrderPayment: function () { | addOrderPayment: function () { | ||||
this.postForm('#orderPaymentForm', '#modal-order-payment'); | this.postForm('#orderPaymentForm', '#modal-order-payment'); | ||||
}, | }, | ||||
updateOrderProducts: function () { | updateOrderProducts: function () { | ||||
postForm: function (formId, modalId) { | postForm: function (formId, modalId) { | ||||
var app = this; | var app = this; | ||||
this.isLoading = true; | |||||
if (modalId) $(modalId).modal('hide'); | |||||
if(checkFormValidity(formId)) { | if(checkFormValidity(formId)) { | ||||
this.isLoading = true; | |||||
if (modalId) $(modalId).modal('hide'); | |||||
$.ajax({ | $.ajax({ | ||||
url: $(formId).prop('action'), | url: $(formId).prop('action'), | ||||
method: "POST", | method: "POST", |
changeInvoiceAddress: L'adresse de facuration a bien été modifié | changeInvoiceAddress: L'adresse de facuration a bien été modifié | ||||
changeDeliveryAddress: L'adresse de livraison a bien été modifié | changeDeliveryAddress: L'adresse de livraison a bien été modifié | ||||
addProduct: Le produit a bien été ajouté | addProduct: Le produit a bien été ajouté | ||||
credt: | |||||
debited: Le compte prépayé a bien été débité | |||||
error: | error: | ||||
form: | form: | ||||
submitted: Une erreur est survenue à la soumission du formulaire | submitted: Une erreur est survenue à la soumission du formulaire | ||||
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é | ||||
credit: | |||||
notActive: Cet utilisateur n'a pas activé son compte prépayé | |||||
debited: Une erreur est survenue, le crédit n'a pas été débité | |||||
field: | field: | ||||
default: | default: | ||||
placeholder: Choisissez une option | placeholder: Choisissez une option |
{% include '@LcShop/backend/order/form/card_orderproducts.html.twig' %} | {% include '@LcShop/backend/order/form/card_orderproducts.html.twig' %} | ||||
{{ macros.cardOverlay('isLoading') }} | {{ macros.cardOverlay('isLoading') }} | ||||
{# <div class="col-6"> | |||||
<div class="col-6"> | |||||
<h6><strong>Historiques des paiments</strong></h6> | <h6><strong>Historiques des paiments</strong></h6> | ||||
#}{#TODO: afficher si la commande est règlé et afficher une alerte si le montant des paiments est supérieur au montant total de la commande#}{##}{##}{##}{##}{# | |||||
{#TODO: afficher si la commande est règlé et afficher une alerte si le montant des paiments est supérieur au montant total de la commande#} | |||||
${order.orderPaid} | ${order.orderPaid} | ||||
<ul v-for="(orderPayment, i) in order.orderPayments"> | <ul v-for="(orderPayment, i) in order.orderPayments"> | ||||
<li>${orderPayment}</li> | <li>${orderPayment}</li> | ||||
</ul> | </ul> | ||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-order-payment"> | |||||
{{ "action.addOrderPayment"|trans }} | |||||
</button> | |||||
</div>#} | |||||
</div> | |||||
{{ macros.endCard() }} | {{ macros.endCard() }} | ||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-order-payment"> | |||||
{{ "action.addOrderPayment"|trans }} | |||||
</button> | |||||
{% if form_order_invoice_address is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_invoiceaddress.html.twig' %} | |||||
{% endif %} | |||||
{% if form_order_delivery_address is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_deliveryaddress.html.twig' %} | |||||
{% endif %} | |||||
{% if form_order_delivery_availability is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_deliveryavailability.html.twig' %} | |||||
{% endif %} | |||||
{% if form_order_status is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_orderstatus.html.twig' %} | |||||
{% endif %} | |||||
{% if form_add_order_reduction_credit is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_addreductioncredit.html.twig' %} | |||||
{% endif %} | |||||
{% if form_add_order_reduction_cart is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_addreductioncart.html.twig' %} | |||||
{% endif %} | |||||
{% if form_delete_order_reduction_cart is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_deletereductioncart.html.twig' %} | |||||
{% endif %} | |||||
{% if form_delete_order_reduction_credit is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_deletereductioncredit.html.twig' %} | |||||
{% endif %} | |||||
{% if form_add_product_to_order is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_addproducttoorder.html.twig' %} | |||||
{% endif %} | |||||
{% if form_order_payment is defined %} | |||||
{% include '@LcShop/backend/order/form/modal_orderpayment.html.twig' %} | |||||
{% endif %} | |||||
{% include '@LcShop/backend/order/form/modal_invoiceaddress.html.twig' %} | |||||
{% 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_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') }} | {# {{ macros.startCard(3, 'OrderShop.addProduct', 'success') }} | ||||
{% include '@LcShop/backend/order/form/addproducttoorder.html.twig' %} | {% include '@LcShop/backend/order/form/addproducttoorder.html.twig' %} |
</div>#} | </div>#} | ||||
<div class="col-12"> | <div class="col-12"> | ||||
{{ form_start(form_order_products, {'attr': {'id' : 'orderProductsForm'}}) }} | |||||
{% if form_order_products is defined %} | |||||
{{ form_start(form_order_products, {'attr': {'id' : 'orderProductsForm'}}) }} | |||||
<script> | |||||
window.templateTest = '{{ orderMacros.productsTemplate(form_order_products)|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; | |||||
</script> | |||||
{% else %} | |||||
<script> | |||||
window.templateTest = '{{ orderMacros.productsTemplate(null)|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; | |||||
</script> | |||||
{% endif %} | |||||
<script> | |||||
window.templateTest = '{{ orderMacros.productsTemplate(form_order_products)|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; | |||||
</script> | |||||
{{ orderMacros.tableHead() }} | {{ orderMacros.tableHead() }} | ||||
{{ orderMacros.products(form_order_products) }} | |||||
{{ orderMacros.products() }} | |||||
{{ orderMacros.tableTotal() }} | {{ orderMacros.tableTotal() }} | ||||
{% if form_order_products is defined %} | |||||
{% do form_order_products.orderProducts.setRendered %} | {% do form_order_products.orderProducts.setRendered %} | ||||
{{ form_end(form_order_products) }} | |||||
{{ form_end(form_order_products) }} | |||||
{% endif %} | |||||
<div class="clearfix"></div> | <div class="clearfix"></div> | ||||
<script> | <script> |
</button> | </button> | ||||
</div> | </div> | ||||
<div class="modal-body"> | <div class="modal-body"> | ||||
{{ form_row(form_order_payment.type) }} | |||||
{{ form_row(form_order_payment.meanPayment) }} | |||||
{{ form_row(form_order_payment.paidAt) }} | {{ form_row(form_order_payment.paidAt) }} | ||||
{{ form_row(form_order_payment.amount) }} | {{ form_row(form_order_payment.amount) }} | ||||
{{ form_row(form_order_payment.reference) }} | {{ form_row(form_order_payment.reference) }} |
{% endmacro %} | {% endmacro %} | ||||
{% macro products(form_order_products) %} | |||||
{% macro products() %} | |||||
<tbody> | <tbody> | ||||
<template v-for="(orderProduct, key) in orderProducts"> | <template v-for="(orderProduct, key) in orderProducts"> | ||||
<order-product ref="orderProductBLOP" :order-product="orderProduct" :edition-mode="editionMode" | <order-product ref="orderProductBLOP" :order-product="orderProduct" :edition-mode="editionMode" | ||||
{% endmacro %} | {% endmacro %} | ||||
{% macro productsTemplate(form_order_products) %} | |||||
{% macro productsTemplate(form_order_products=null) %} | |||||
<tr class="order-product-item"> | <tr class="order-product-item"> | ||||
<td colspan="2">{% verbatim %}{{orderProduct.title}}{% endverbatim %}</td> | <td colspan="2">{% verbatim %}{{orderProduct.title}}{% endverbatim %}</td> | ||||
<td> | <td> | ||||
{% verbatim %}{{orderProduct.availableQuantity}}{% endverbatim %} | {% verbatim %}{{orderProduct.availableQuantity}}{% endverbatim %} | ||||
</td> | </td> | ||||
<td> | <td> | ||||
{% if form_order_products is not null %} | |||||
<div :class="editionMode ? '' : 'hidden'"> | <div :class="editionMode ? '' : 'hidden'"> | ||||
{{ form_widget(form_order_products.orderProducts.vars.prototype.quantityOrder, {'attr' : {'ref': 'fieldQuantity', 'v-model' : 'orderProduct.quantityOrder', '@change' : 'updateOrderProducts'}}) }} | {{ form_widget(form_order_products.orderProducts.vars.prototype.quantityOrder, {'attr' : {'ref': 'fieldQuantity', 'v-model' : 'orderProduct.quantityOrder', '@change' : 'updateOrderProducts'}}) }} | ||||
{{ form_widget(form_order_products.orderProducts.vars.prototype.product, {'attr' : {'ref' : 'fieldProduct', 'v-model' : 'orderProduct.product'}}) }} | {{ form_widget(form_order_products.orderProducts.vars.prototype.product, {'attr' : {'ref' : 'fieldProduct', 'v-model' : 'orderProduct.product'}}) }} | ||||
<div :class="editionMode ? 'hidden' : ''"> | <div :class="editionMode ? 'hidden' : ''"> | ||||
{% verbatim %}{{ orderProduct.quantityOrder }}{% endverbatim %} | {% verbatim %}{{ orderProduct.quantityOrder }}{% endverbatim %} | ||||
</div> | </div> | ||||
{% else %} | |||||
{% verbatim %}{{ orderProduct.quantityOrder }}{% endverbatim %} | |||||
{% endif %} | |||||
</td> | </td> | ||||
<td> | <td> | ||||
{% verbatim %}{{orderProduct.totalWithTaxAndReduction}}{% endverbatim %}€ | {% verbatim %}{{orderProduct.totalWithTaxAndReduction}}{% endverbatim %}€ |
{{ form_row(add_credit_history_form.type) }} | {{ form_row(add_credit_history_form.type) }} | ||||
</div> | </div> | ||||
<div class="col"> | <div class="col"> | ||||
{{ form_row(add_credit_history_form.amount) }} | |||||
{{ form_label(add_credit_history_form.amount) }} | |||||
<div class="form-widget"> | |||||
<div class="input-group"> | |||||
{{ form_widget(add_credit_history_form.amount) }} | |||||
<div class="input-group-append"> | |||||
<span class="input-group-text">€ </span> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
</div> | </div> | ||||
<div class="col"> | <div class="col"> | ||||
{{ form_row(add_credit_history_form.meanPayment) }} | {{ form_row(add_credit_history_form.meanPayment) }} | ||||
</div> | </div> |
{% extends '@LcShop/backend/default/show.html.twig' %} | |||||
{% extends '@LcShop/backend/default/show.html.twig' %} | |||||
{% block main %} | {% block main %} | ||||
{% for creditHistory in entity.creditHistories %} | |||||
<li>{{ creditHistory.amount }}</li> | |||||
{% else %} | |||||
<li><i>Aucun mouvement pour ce compte prépayé</i></li> | |||||
{% endfor %} | |||||
<div class="row"> | |||||
<div class="col-12"> | |||||
<div class="card card-outline card-primary"> | |||||
<div class="card-header"> | |||||
<h2 class="card-title text-lg "> | |||||
{{ entity.user.summary }} : <strong>{{ entity.credit }}€</strong> | |||||
</h2> | |||||
<button type="button" class="btn btn-primary float-right" data-toggle="modal" | |||||
data-target="#modal-add-credit-history"> | |||||
{{ "action.addCreditHistory"|trans }} | |||||
</button> | |||||
</div> | |||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-add-credit-history"> | |||||
{{ "action.addCreditHistory"|trans }} | |||||
</button> | |||||
<div class="card-body p-0"> | |||||
<table class="table datatable-simple table-bordered table-hover table-striped"> | |||||
<thead> | |||||
<tr> | |||||
<th data-index="0" class="" data-searchable="text">Id</th> | |||||
<th data-index="1" class="" data-searchable="select">Type</th> | |||||
<th data-index="2" class="" data-searchable="select">Amount</th> | |||||
<th data-index="3" class="" data-searchable="text">MeanPayment</th> | |||||
<th data-index="4" class="" data-searchable="tex">PaidAt</th> | |||||
<th data-index="5" class="" data-searchable="text">Reference</th> | |||||
<th data-index="6" class="" data-searchable="">Comment</th> | |||||
</tr> | |||||
</thead> | |||||
<tbody> | |||||
{% for creditHistory in entity.creditHistories %} | |||||
<tr draggable="true" rel="{{ creditHistory.id }}" data-id="{{ creditHistory.id }}"> | |||||
<td class="sorted">{{ creditHistory.id }}</td> | |||||
<td class="">{{ creditHistory.type }}</td> | |||||
<td class="">{{ creditHistory.amount }} €</td> | |||||
<td class="">{{ creditHistory.meanPayment }}</td> | |||||
<td class="">{{ creditHistory.paidAt|date('d-m-y') }}</td> | |||||
<td class="">{{ creditHistory.reference }}</td> | |||||
<td class="">{{ creditHistory.comment }}</td> | |||||
</tr> | |||||
{% else %} | |||||
<tr> | |||||
<td class="no-results" colspan="7"> | |||||
{{ 'search.no_results'|trans(_trans_parameters, 'EasyAdminBundle') }} | |||||
</td> | |||||
</tr> | |||||
{% endfor %} | |||||
</tbody> | |||||
<tfoot></tfoot> | |||||
</table> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
{% include 'LcShopBundle:backend/usermerchant:modal_addcredithistory.html.twig' %} | {% include 'LcShopBundle:backend/usermerchant:modal_addcredithistory.html.twig' %} | ||||
{% endblock main %} | {% endblock main %} | ||||
{% block head_stylesheets %} | |||||
{{ parent() }} | |||||
<link rel="stylesheet" href="{{ asset('bundles/lcshop/css/backend/adminlte/plugins/datatables/fixedHeader.dataTables.min.css') }}"> | |||||
<link rel="stylesheet" | |||||
href="{{ asset('bundles/lcshop/css/backend/adminlte/plugins/datatables/dataTables.bootstrap4.min.css') }}"> | |||||
{% endblock %} | |||||
{% block plugin_javascript %} | |||||
{{ parent() }} | |||||
<script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/jquery.dataTables.min.js') }}"></script> | |||||
<script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/dataTables.bootstrap4.min.js') }}"></script> | |||||
<script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/dataTables.responsive.min.js') }}"></script> | |||||
<script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/jquery.highlight.js') }}"></script> | |||||
<script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/responsive.bootstrap4.min.js') }}"></script> | |||||
<script src="{{ asset('bundles/lcshop/js/backend/plugin/datatables/dataTables.fixedHeader.min.js') }}"></script> | |||||
{% endblock %} | |||||
{% block script_javascript %} | |||||
{{ parent() }} | |||||
<script src="{{ asset('bundles/lcshop/js/backend/script/default/init-list.js') }}"></script> | |||||
{% endblock %} | |||||
return $this->updateCreditActive($user, $merchant, false) ; | return $this->updateCreditActive($user, $merchant, false) ; | ||||
} | } | ||||
public function isCreditActive(UserInterface $user, MerchantInterface $merchant = null){ | |||||
$userMerchant = $this->getUserMerchant($user, $merchant); | |||||
if($userMerchant && $userMerchant->isCreditActive()) { | |||||
return true; | |||||
}else{ | |||||
return false; | |||||
} | |||||
} | |||||
public function checkCreditActive(UserMerchantInterface $userMerchant) | public function checkCreditActive(UserMerchantInterface $userMerchant) | ||||
{ | { | ||||
if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) { | if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) { |
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; | use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; | ||||
use Lc\ShopBundle\Model\Product; | use Lc\ShopBundle\Model\Product; | ||||
use Lc\ShopBundle\Model\ProductFamily; | use Lc\ShopBundle\Model\ProductFamily; | ||||
use Lc\ShopBundle\Services\CreditUtils; | |||||
use Lc\ShopBundle\Services\DocumentUtils; | use Lc\ShopBundle\Services\DocumentUtils; | ||||
use Lc\ShopBundle\Services\Price\OrderShopPriceUtils; | use Lc\ShopBundle\Services\Price\OrderShopPriceUtils; | ||||
use Lc\ShopBundle\Services\UserUtils; | use Lc\ShopBundle\Services\UserUtils; | ||||
protected $productFamilyUtils; | protected $productFamilyUtils; | ||||
protected $documentUtils; | protected $documentUtils; | ||||
protected $utils; | protected $utils; | ||||
protected $creditUtils; | |||||
public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils, | public function __construct(EntityManagerInterface $em, Security $security, UserUtils $userUtils, | ||||
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils, | MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils, | ||||
DocumentUtils $documentUtils, Utils $utils) | |||||
DocumentUtils $documentUtils, Utils $utils, CreditUtils $creditUtils) | |||||
{ | { | ||||
$this->em = $em; | $this->em = $em; | ||||
$this->security = $security; | $this->security = $security; | ||||
$this->productFamilyUtils = $productFamilyUtils; | $this->productFamilyUtils = $productFamilyUtils; | ||||
$this->documentUtils = $documentUtils; | $this->documentUtils = $documentUtils; | ||||
$this->utils = $utils; | $this->utils = $utils; | ||||
$this->creditUtils = $creditUtils; | |||||
} | } | ||||