Browse Source

Système compte prépayés

feature/export_comptable
Fab 4 years ago
parent
commit
72f9527e7b
7 changed files with 137 additions and 69 deletions
  1. +15
    -0
      ShopBundle/Controller/Backend/AdminController.php
  2. +19
    -32
      ShopBundle/Controller/Backend/OrderController.php
  3. +40
    -7
      ShopBundle/Controller/Backend/UserMerchantController.php
  4. +37
    -16
      ShopBundle/Form/Backend/UserMerchant/CreditHistoryType.php
  5. +2
    -4
      ShopBundle/Model/PayoffTrait.php
  6. +22
    -8
      ShopBundle/Resources/views/backend/usermerchant/modal_addcredithistory.html.twig
  7. +2
    -2
      ShopBundle/Resources/views/backend/usermerchant/show.html.twig

+ 15
- 0
ShopBundle/Controller/Backend/AdminController.php View File

$this->translator = $translator; $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 * Réécriture de show action pr rediriger vers l'édition
*/ */

+ 19
- 32
ShopBundle/Controller/Backend/OrderController.php View File



if ($actionName == 'show') { if ($actionName == 'show') {
if (!isset($parameters['form_order_delivery_address'])) { 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); return parent::renderTemplate($actionName, $templatePath, $parameters);
} }


if ($actionName == 'show') { if ($actionName == 'show') {
if (!isset($parameters['form_order_delivery_address'])) { 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); 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() protected function newAction()
{ {

+ 40
- 7
ShopBundle/Controller/Backend/UserMerchantController.php View File



namespace Lc\ShopBundle\Controller\Backend; namespace Lc\ShopBundle\Controller\Backend;


use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use FOS\UserBundle\Model\UserManagerInterface; use FOS\UserBundle\Model\UserManagerInterface;
use Lc\ShopBundle\Context\CreditHistoryInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface; use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\NewsInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface; use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\UserInterface; use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Form\Backend\UserMerchant\CreditHistoryType;
use Lc\ShopBundle\Services\CreditUtils; use Lc\ShopBundle\Services\CreditUtils;
use Lc\ShopBundle\Services\Utils; use Lc\ShopBundle\Services\Utils;
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; 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\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;


$this->creditUtils = $creditUtils; $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() protected function newAction()
{ {
$this->dispatch(EasyAdminEvents::PRE_NEW); $this->dispatch(EasyAdminEvents::PRE_NEW);
$entity = $easyadmin['item']; $entity = $easyadmin['item'];


$fields = $this->entity['show']['fields']; $fields = $this->entity['show']['fields'];
$deleteForm = $this->createDeleteForm($this->entity['name'], $id);


$this->dispatch(EasyAdminEvents::POST_SHOW, [ $this->dispatch(EasyAdminEvents::POST_SHOW, [
'deleteForm' => $deleteForm,
//'deleteForm' => $deleteForm,
'fields' => $fields, 'fields' => $fields,
'entity' => $entity, 'entity' => $entity,
]); ]);


$parameters = [ $parameters = [
'entity' => $entity, 'entity' => $entity,
'fields' => $fields,
'delete_form' => $deleteForm->createView()
'fields' => $fields
]; ];


return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]); 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 */ * Réécriture de edit action pr rediriger vers le show */
public function editAction() public function editAction()

+ 37
- 16
ShopBundle/Form/Backend/UserMerchant/CreditHistoryType.php View File

<?php <?php


namespace Lc\ShopBundle\Form\Backend\Order;
namespace Lc\ShopBundle\Form\Backend\UserMerchant;


use App\Entity\Product; use App\Entity\Product;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\CreditHistoryInterface;
use Lc\ShopBundle\Context\OrderProductInterface; use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface; use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderShopInterface; use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\ReductionCartInterface; use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface; use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Form\DataTransformer\ProductToIdTransformer; 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\Bridge\Doctrine\Form\Type\EntityType;
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\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; 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\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; 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\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;




public function buildForm(FormBuilderInterface $builder, array $options) 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'
));




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

+ 2
- 4
ShopBundle/Model/PayoffTrait.php View File

return $this; return $this;
} }


public function getMeanPayment(?string $meanPayment): self
public function getMeanPayment() : ?string
{ {
$this->meanPayment = $meanPayment;

return $this;
return $this->meanPayment ;
} }





+ 22
- 8
ShopBundle/Resources/views/backend/usermerchant/modal_addcredithistory.html.twig View File

{% trans_default_domain 'lcshop' %} {% 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-dialog">


<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <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"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div class="col"> <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> </div>
<div class="modal-footer justify-content-between"> <div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <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>
</div> </div>
<!-- /.modal-content --> <!-- /.modal-content -->
</div> </div>
{{ form_end(form_add_order_reduction_cart) }}
{{ form_end(add_credit_history_form) }}
</div> </div>

+ 2
- 2
ShopBundle/Resources/views/backend/usermerchant/show.html.twig View File

<li><i>Aucun mouvement pour ce compte prépayé</i></li> <li><i>Aucun mouvement pour ce compte prépayé</i></li>
{% endfor %} {% 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 }} {{ "action.addCreditHistory"|trans }}
</button> </button>


{% include 'LcShopBundle:backend/usermerchant:modal_addcredithistory.html.twig' %}
{% endblock main %} {% endblock main %}





Loading…
Cancel
Save