@@ -51,6 +51,21 @@ class AdminController extends EasyAdminController | |||
$this->translator = $translator; | |||
} | |||
public function createCustomForm($class, $action, $parameters, $data = true) | |||
{ | |||
$options = array(); | |||
if ($data) $options['data'] = $parameters['entity']; | |||
$options['action'] = $this->generateUrl('easyadmin', array( | |||
'action' => $action, | |||
'entity' => $this->entity['name'], | |||
'id' => $parameters['entity']->getId() | |||
)); | |||
return $this->createForm($class, null, $options); | |||
} | |||
/** | |||
* Réécriture de show action pr rediriger vers l'édition | |||
*/ |
@@ -354,16 +354,16 @@ 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_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $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(); | |||
$parameters['form_order_status'] = $this->createOrderForm(OrderStatusType::class, 'orderStatus', $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); | |||
} | |||
@@ -373,35 +373,22 @@ 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_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $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(); | |||
$parameters['form_order_status'] = $this->createOrderForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); | |||
$parameters['form_order_payment'] = $this->createOrderForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->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(); | |||
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); | |||
} | |||
return parent::renderTemplate($actionName, $templatePath, $parameters); | |||
} | |||
public function createOrderForm($class, $action, $parameters, $data = true) | |||
{ | |||
$options = array(); | |||
if ($data) $options['data'] = $parameters['entity']; | |||
$options['action'] = $this->generateUrl('easyadmin', array( | |||
'action' => $action, | |||
'entity' => $this->entity['name'], | |||
'id' => $parameters['entity']->getId() | |||
)); | |||
return $this->createForm($class, null, $options); | |||
} | |||
protected function newAction() | |||
{ |
@@ -2,20 +2,19 @@ | |||
namespace Lc\ShopBundle\Controller\Backend; | |||
use App\Repository\UserRepository; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||
use FOS\UserBundle\Model\UserManagerInterface; | |||
use Lc\ShopBundle\Context\CreditHistoryInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\NewsInterface; | |||
use Lc\ShopBundle\Context\OrderUtilsInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Form\Backend\UserMerchant\CreditHistoryType; | |||
use Lc\ShopBundle\Services\CreditUtils; | |||
use Lc\ShopBundle\Services\Utils; | |||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |||
use Symfony\Component\Security\Core\Security; | |||
use Symfony\Contracts\Translation\TranslatorInterface; | |||
@@ -29,6 +28,32 @@ class UserMerchantController extends AdminController | |||
$this->creditUtils = $creditUtils; | |||
} | |||
public function addCreditHistoryAction(){ | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$userMerchant = $easyadmin['item']; | |||
$creditHistoryClass = $this->em->getClassMetadata(CreditHistoryInterface::class); | |||
$creditHistory = new $creditHistoryClass->name; | |||
$addCreditHistoryForm = $this->createForm(CreditHistoryType::class, $creditHistory); | |||
$addCreditHistoryForm->handleRequest($this->request); | |||
if ($addCreditHistoryForm->isSubmitted() && $addCreditHistoryForm->isValid()) { | |||
if($this->creditUtils->saveCreditHistory()){ | |||
$this->utils->addFlash('warning', 'success.credit.added'); | |||
}else{ | |||
$this->utils->addFlash('warning', 'error.credit.notAdded'); | |||
} | |||
} else { | |||
$this->utils->addFlash('error', $addCreditHistoryForm->getErrors()); | |||
} | |||
return $this->redirectToRoute('easyadmin', [ | |||
'action' => 'show', | |||
'entity' => $this->request->query->get('entity'), | |||
'id' => $userMerchant->getId() | |||
]); | |||
} | |||
protected function newAction() | |||
{ | |||
$this->dispatch(EasyAdminEvents::PRE_NEW); | |||
@@ -103,23 +128,31 @@ class UserMerchantController extends AdminController | |||
$entity = $easyadmin['item']; | |||
$fields = $this->entity['show']['fields']; | |||
$deleteForm = $this->createDeleteForm($this->entity['name'], $id); | |||
$this->dispatch(EasyAdminEvents::POST_SHOW, [ | |||
'deleteForm' => $deleteForm, | |||
//'deleteForm' => $deleteForm, | |||
'fields' => $fields, | |||
'entity' => $entity, | |||
]); | |||
$parameters = [ | |||
'entity' => $entity, | |||
'fields' => $fields, | |||
'delete_form' => $deleteForm->createView() | |||
'fields' => $fields | |||
]; | |||
return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]); | |||
} | |||
public function renderUserMerchantTemplate($actionName, $templatePath, array $parameters = []){ | |||
if ($actionName == 'show') { | |||
$parameters['add_credit_history_form'] = $this->createCustomForm(CreditHistoryType::class, 'addCreditHistory', $parameters, false)->createView(); | |||
} | |||
return parent::renderTemplate($actionName, $templatePath, $parameters); | |||
} | |||
/** | |||
* Réécriture de edit action pr rediriger vers le show */ | |||
public function editAction() |
@@ -1,9 +1,10 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form\Backend\Order; | |||
namespace Lc\ShopBundle\Form\Backend\UserMerchant; | |||
use App\Entity\Product; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\CreditHistoryInterface; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
use Lc\ShopBundle\Context\OrderReductionCartInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
@@ -12,12 +13,19 @@ use Lc\ShopBundle\Context\ProductInterface; | |||
use Lc\ShopBundle\Context\ReductionCartInterface; | |||
use Lc\ShopBundle\Context\ReductionCreditInterface; | |||
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer; | |||
use Lc\ShopBundle\Model\CreditHistory; | |||
use Lc\ShopBundle\Services\Utils; | |||
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\ChoiceType; | |||
use Symfony\Component\Form\Extension\Core\Type\DateType; | |||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | |||
use Symfony\Component\Form\Extension\Core\Type\MoneyType; | |||
use Symfony\Component\Form\Extension\Core\Type\NumberType; | |||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
@@ -33,23 +41,36 @@ class CreditHistoryType extends AbstractType | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$entity = $options['data']; | |||
$builder->add('type', ChoiceType::class, array( | |||
'choices' => array( | |||
'field.creditHistory.typeOptions.'.CreditHistory::TYPE_CREDIT => CreditHistory::TYPE_CREDIT, | |||
'field.creditHistory.typeOptions.'.CreditHistory::TYPE_DEBIT => CreditHistory::TYPE_DEBIT | |||
), | |||
'required' => true | |||
)) | |||
->add('amount', NumberType::class, array( | |||
$reductionCreditClass = $this->em->getClassMetadata(ReductionCreditInterface::class); | |||
$reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class);; | |||
)) | |||
->add('meanPayment', ChoiceType::class, array( | |||
'choices' => array( | |||
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH, | |||
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CHEQUE => Utils::MEAN_PAYMENT_CHEQUE, | |||
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CREDIT => Utils::MEAN_PAYMENT_CREDIT, | |||
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CREDIT_CARD => Utils::MEAN_PAYMENT_CREDIT_CARD, | |||
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_TRANSFER => Utils::MEAN_PAYMENT_TRANSFER | |||
), | |||
'required' => true | |||
)) | |||
->add('paidAt', DateType::class, array( | |||
'widget' => 'single_text', | |||
'required' => true | |||
)) | |||
->add('reference', TextType::class) | |||
$builder | |||
->add('reductionCredit', EntityType::class, array( | |||
'class' => $reductionCreditClass->getName(), | |||
'choices' => $reductionCreditRepo->findReductionCreditsByUser($entity->getUser()), | |||
//'choices' => $this->orderUtils->getReductionCreditsAvailable($entity), | |||
'required' => true, | |||
'mapped'=>false | |||
->add('comment', TextareaType::class) | |||
->add('add', SubmitType::class, array( | |||
'label' => 'action.add' | |||
)); | |||
$builder->add('add', ButtonType::class, array( | |||
'label' => 'action.add' | |||
)); | |||
} | |||
@@ -57,7 +78,7 @@ class CreditHistoryType extends AbstractType | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults([ | |||
'data_class' => $this->em->getClassMetadata(OrderShopInterface::class)->getName(), | |||
'data_class' => $this->em->getClassMetadata(CreditHistoryInterface::class)->getName(), | |||
]); | |||
} | |||
} |
@@ -46,11 +46,9 @@ trait PayoffTrait | |||
return $this; | |||
} | |||
public function getMeanPayment(?string $meanPayment): self | |||
public function getMeanPayment() : ?string | |||
{ | |||
$this->meanPayment = $meanPayment; | |||
return $this; | |||
return $this->meanPayment ; | |||
} | |||
@@ -1,29 +1,43 @@ | |||
{% trans_default_domain 'lcshop' %} | |||
<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 fade show" id="modal-add-credit-history"> | |||
{{ form_start(add_credit_history_form, {'attr': { 'id' : 'addCreditHistory'}}) }} | |||
{% form_theme add_credit_history_form '@LcShop/backend/form/custom_bootstrap_4.html.twig' %} | |||
<div class="modal-dialog"> | |||
<div class="modal-content"> | |||
<div class="modal-header"> | |||
<h4>{{ "action.order.addReductionCart"|trans }}</h4> | |||
<h4>{{ "action.addCreditHistory"|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"> | |||
{{ form_row(form_add_order_reduction_cart.reductionCart) }} | |||
{{ form_row(add_credit_history_form.type) }} | |||
</div> | |||
<div class="col"> | |||
{{ form_row(add_credit_history_form.amount) }} | |||
</div> | |||
<div class="col"> | |||
{{ form_row(add_credit_history_form.meanPayment) }} | |||
</div> | |||
<div class="col"> | |||
{{ form_row(add_credit_history_form.paidAt) }} | |||
</div> | |||
<div class="col"> | |||
{{ form_row(add_credit_history_form.reference) }} | |||
</div> | |||
<div class="col"> | |||
{{ form_row(add_credit_history_form.comment) }} | |||
</div> | |||
</div> | |||
<div class="modal-footer justify-content-between"> | |||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |||
{{ form_row(form_add_order_reduction_cart.add, {"attr": {'class' : 'btn btn-primary', '@click': 'addOrderReductionCart'}}) }} | |||
{{ form_row(add_credit_history_form.add, {"attr": {'class' : 'btn btn-primary'}}) }} | |||
</div> | |||
</div> | |||
<!-- /.modal-content --> | |||
</div> | |||
{{ form_end(form_add_order_reduction_cart) }} | |||
{{ form_end(add_credit_history_form) }} | |||
</div> |
@@ -8,11 +8,11 @@ | |||
<li><i>Aucun mouvement pour ce compte prépayé</i></li> | |||
{% endfor %} | |||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-add-credit-hitory"> | |||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-add-credit-history"> | |||
{{ "action.addCreditHistory"|trans }} | |||
</button> | |||
{% include 'LcShopBundle:backend/usermerchant:modal_addcredithistory.html.twig' %} | |||
{% endblock main %} | |||