use App\Entity\OrderShop; | use App\Entity\OrderShop; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | ||||
use Lc\ShopBundle\Context\OrderPaymentInterface; | |||||
use Lc\ShopBundle\Context\OrderProductInterface; | use Lc\ShopBundle\Context\OrderProductInterface; | ||||
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\OrderDeliveryAddressType; | use Lc\ShopBundle\Form\Backend\Order\OrderDeliveryAddressType; | ||||
use Lc\ShopBundle\Form\Backend\Order\OrderInvoiceAddressType; | 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\OrderProductsType; | ||||
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCartType; | use Lc\ShopBundle\Form\Backend\Order\OrderReductionCartType; | ||||
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; | use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; | ||||
use Lc\ShopBundle\Form\Backend\Order\OrderStatusType; | use Lc\ShopBundle\Form\Backend\Order\OrderStatusType; | ||||
use Lc\ShopBundle\Model\OrderPayment; | |||||
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; | ||||
$formOrderInvoiceAddress->handleRequest($this->request); | $formOrderInvoiceAddress->handleRequest($this->request); | ||||
if ($formOrderInvoiceAddress->isSubmitted() && $formOrderInvoiceAddress->isValid()) { | 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->persist($orderShop); | ||||
$this->em->flush(); | $this->em->flush(); | ||||
$response['status'] = 'success'; | $response['status'] = 'success'; | ||||
return new Response(json_encode($response)); | return new Response(json_encode($response)); | ||||
} | } | ||||
public function orderPaymentAction() | |||||
{ | |||||
$id = $this->request->query->get('id'); | |||||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||||
$orderShop = $easyadmin['item']; | |||||
$orderPaymentClass =$this->em->getClassMetadata(OrderPaymentInterface::class); | |||||
$orderPayment = new $orderPaymentClass->name; | |||||
$formOrderPayment = $this->createForm(OrderPaymentType::class, $orderPayment); | |||||
$formOrderPayment->handleRequest($this->request); | |||||
if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) { | |||||
$orderPayment->setOrderShop($orderShop); | |||||
$this->em->persist($orderPayment); | |||||
$this->em->flush(); | |||||
$response['status'] = 'success'; | |||||
$response['message'] = 'La paiement a bien été ajouté'; | |||||
} else { | |||||
$response['status'] = 'error'; | |||||
$response['message'] = 'Une erreur est survenue'; | |||||
} | |||||
$response['data'] = $this->orderUtils->getOrderAsJsonObject($orderShop);; | |||||
return new Response(json_encode($response)); | |||||
} | |||||
public function orderReductionCartAction() | public function orderReductionCartAction() | ||||
]) | ]) | ||||
)); | )); | ||||
$formOrderPayment = $this->createForm(OrderPaymentType::class, null, array( | |||||
'action' => $this->generateUrl('easyadmin', [ | |||||
'action' => 'orderPayment', | |||||
'entity' => $this->entity['name'], | |||||
'id' => $parameters['entity']->getId() | |||||
]) | |||||
)); | |||||
if(!isset($parameters['form_order_delivery_address'])) { | if(!isset($parameters['form_order_delivery_address'])) { | ||||
$formOrderDeliveryAddress = $this->createForm(OrderDeliveryAddressType::class, null, array( | $formOrderDeliveryAddress = $this->createForm(OrderDeliveryAddressType::class, null, array( | ||||
'data' => $parameters['entity'], | 'data' => $parameters['entity'], | ||||
$parameters['form_order_products'] = $formOrderProducts->createView(); | $parameters['form_order_products'] = $formOrderProducts->createView(); | ||||
$parameters['form_order_invoice_address'] = $formOrderInvoiceAddress->createView(); | $parameters['form_order_invoice_address'] = $formOrderInvoiceAddress->createView(); | ||||
$parameters['form_order_status'] = $formOrderStatus->createView(); | $parameters['form_order_status'] = $formOrderStatus->createView(); | ||||
$parameters['form_order_payment'] = $formOrderPayment->createView(); | |||||
} | } | ||||
return parent::renderTemplate($actionName, $templatePath, $parameters); | return parent::renderTemplate($actionName, $templatePath, $parameters); | ||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Form\Backend\Order; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\OrderPaymentInterface; | |||||
use Lc\ShopBundle\Model\OrderPayment; | |||||
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\NumberType; | |||||
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; | |||||
class OrderPaymentType extends AbstractType | |||||
{ | |||||
protected $em; | |||||
public function __construct(EntityManagerInterface $em) | |||||
{ | |||||
$this->em = $em; | |||||
} | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder | |||||
->add('type', ChoiceType::class, 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 | |||||
), | |||||
'required' => true | |||||
)) | |||||
->add('paidAt', DateType::class, array( | |||||
'widget' => 'single_text', | |||||
'required' => true | |||||
)) | |||||
->add('reference', TextType::class) | |||||
->add('amount', NumberType::class) | |||||
->add('comment', TextareaType::class) | |||||
->add('saveOrderPayment', ButtonType::class, array( | |||||
'label' => 'field.OrderShop.saveOrderPayment' | |||||
)); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'data_class' => $this->em->getClassMetadata(OrderPaymentInterface::class)->getName(), | |||||
]); | |||||
} | |||||
} |
protected $merchantAddressText; | protected $merchantAddressText; | ||||
/** | /** | ||||
* @ORM\Column(type="text") | |||||
* @ORM\Column(type="text",nullable=true) | |||||
*/ | */ | ||||
protected $buyerAddressText; | protected $buyerAddressText; | ||||
return $this->buyerAddressText; | return $this->buyerAddressText; | ||||
} | } | ||||
public function setBuyerAddressText(string $buyerAddressText): self | |||||
public function setBuyerAddressText(?string $buyerAddressText): self | |||||
{ | { | ||||
$this->buyerAddressText = $buyerAddressText; | $this->buyerAddressText = $buyerAddressText; | ||||
public function __toString() | public function __toString() | ||||
{ | { | ||||
return 'Par : '.$this->type.' le : '.$this->getPaidAt()->format('d-m-Y H:i'); | |||||
return $this->amount. '€ par '.$this->type.' le '.$this->getPaidAt()->format('d-m-Y'); | |||||
} | } | ||||
public function getOrderShop(): ?OrderShop | public function getOrderShop(): ?OrderShop |
*/ | */ | ||||
protected $invoiceAddress; | protected $invoiceAddress; | ||||
/** | |||||
* @ORM\Column(type="text", nullable=true) | |||||
*/ | |||||
protected $invoiceAddressText; | |||||
/** | /** | ||||
* @ORM\Column(type="datetime", nullable=true) | * @ORM\Column(type="datetime", nullable=true) | ||||
*/ | */ | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getInvoiceAddressText(): ?string | |||||
{ | |||||
return $this->invoiceAddressText; | |||||
} | |||||
public function setInvoiceAddressText(string $invoiceAddressText): self | |||||
{ | |||||
$this->invoiceAddressText = $invoiceAddressText; | |||||
return $this; | |||||
} | |||||
public function getComment(): ?string | public function getComment(): ?string | ||||
{ | { | ||||
return $this->comment; | return $this->comment; |
isLoading: true, | isLoading: true, | ||||
addProductId: null, | addProductId: null, | ||||
addProductQuantity: null, | addProductQuantity: null, | ||||
sectionsArray: [ | sectionsArray: [ | ||||
{ | { | ||||
name: 'cart', | name: 'cart', | ||||
addProductToOrder: function () { | addProductToOrder: function () { | ||||
this.postForm('#addProductToOrderForm', false); | this.postForm('#addProductToOrderForm', false); | ||||
}, | }, | ||||
addOrderPayment: function () { | |||||
this.postForm('#orderPaymentForm', '#modal-order-payment'); | |||||
}, | |||||
updateOrderProducts: function () { | updateOrderProducts: function () { | ||||
this.postForm('#orderProductsForm', false); | this.postForm('#orderProductsForm', false); | ||||
}, | }, | ||||
updateOrderDeliveryAddress: function () { | updateOrderDeliveryAddress: function () { | ||||
this.postForm('#orderDeliveryAddressForm', '#modal-order-invoice-address'); | this.postForm('#orderDeliveryAddressForm', '#modal-order-invoice-address'); | ||||
}, | }, | ||||
updateOrderDeliveryAvailability:function(){ | |||||
updateOrderDeliveryAvailability: function () { | |||||
this.postForm('#orderDeliveryAvailabilityForm', '#modal-order-delivery-availability'); | this.postForm('#orderDeliveryAvailabilityForm', '#modal-order-delivery-availability'); | ||||
}, | }, | ||||
addOrderReductionCart:function(){ | |||||
addOrderReductionCart: function () { | |||||
this.postForm('#orderReductionCartForm', '#modal-reduction-cart'); | this.postForm('#orderReductionCartForm', '#modal-reduction-cart'); | ||||
}, | }, | ||||
addOrderReductionCredit:function(){ | |||||
addOrderReductionCredit: function () { | |||||
this.postForm('#orderReductionCreditForm', '#modal-reduction-credit'); | this.postForm('#orderReductionCreditForm', '#modal-reduction-credit'); | ||||
}, | }, | ||||
postForm:function(formId, modalId){ | |||||
postForm: function (formId, modalId) { | |||||
var app = this; | var app = this; | ||||
this.isLoading = true; | this.isLoading = true; | ||||
if(modalId)$(modalId).modal('hide'); | |||||
if (modalId) $(modalId).modal('hide'); | |||||
$.ajax({ | $.ajax({ | ||||
url: $(formId).prop('action'), | url: $(formId).prop('action'), | ||||
method: "POST", | method: "POST", | ||||
this.isLoading = false; | this.isLoading = false; | ||||
}, | }, | ||||
}, | }, | ||||
watch: { | |||||
} | |||||
watch: {} | |||||
}); | }); | ||||
</div> | </div> | ||||
<div class="col-4" > | <div class="col-4" > | ||||
<div v-if="order.deliveryType == 'at-home'"> | |||||
<div v-if="order.deliveryType == 'home'"> | |||||
<h6><strong>{{ "field.default.deliveryAddress"|trans({}, 'lcshop') }} : </strong></h6> | <h6><strong>{{ "field.default.deliveryAddress"|trans({}, 'lcshop') }} : </strong></h6> | ||||
<address v-html="order.deliveryAddress"> | <address v-html="order.deliveryAddress"> | ||||
</address> | </address> | ||||
</div> | </div> | ||||
<div class="col-12"> | <div class="col-12"> | ||||
<h6><strong>{{ "field.default.deliveryAvailabilty"|trans({}, 'lcshop') }} : </strong></h6> | <h6><strong>{{ "field.default.deliveryAvailabilty"|trans({}, 'lcshop') }} : </strong></h6> | ||||
<div v-if="order.deliveryType == 'at-home'"> | |||||
<div v-if="order.deliveryType == 'home'"> | |||||
<div v-html="order.deliveryAvailabilityZone"> | <div v-html="order.deliveryAvailabilityZone"> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-reduction-credit"> | <button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-reduction-credit"> | ||||
{{ "action.addReductionCredit"|trans }} | {{ "action.addReductionCredit"|trans }} | ||||
</button> | </button> | ||||
<br /> | |||||
<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#} | |||||
${order.orderPaid} | |||||
<ul v-for="(orderPayment, i) in order.orderPayments"> | |||||
<li>${orderPayment}</li> | |||||
</ul> | |||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-order-payment"> | |||||
{{ "action.addOrderPayment"|trans }} | |||||
</button> | |||||
</div> | </div> | ||||
{% include '@LcShop/backend/order/modal_orderstatus.html.twig' %} | {% include '@LcShop/backend/order/modal_orderstatus.html.twig' %} | ||||
{% include '@LcShop/backend/order/modal_reductioncart.html.twig' %} | {% include '@LcShop/backend/order/modal_reductioncart.html.twig' %} | ||||
{% include '@LcShop/backend/order/modal_reductioncredit.html.twig' %} | {% include '@LcShop/backend/order/modal_reductioncredit.html.twig' %} | ||||
{% include '@LcShop/backend/order/modal_orderpayment.html.twig' %} | |||||
{{ macros.endCard }} | {{ macros.endCard }} | ||||
</div> | </div> | ||||
</div> | </div> |
{{ form_row(form_order_delivery_availability.deliveryAvailabilityPointSale) }} | {{ form_row(form_order_delivery_availability.deliveryAvailabilityPointSale) }} | ||||
</div> | </div> | ||||
<div class="col" v-else-if="order.deliveryType=='at-home'"> | |||||
<div class="col" v-else-if="order.deliveryType=='home'"> | |||||
{{ form_row(form_order_delivery_availability.deliveryAvailabilityZone) }} | {{ form_row(form_order_delivery_availability.deliveryAvailabilityZone) }} | ||||
</div> | </div> | ||||
<div class="modal fade show" id="modal-order-payment"> | |||||
{{ form_start(form_order_payment, {'attr': { 'id' : 'orderPaymentForm'}}) }}) }} | |||||
{% form_theme form_order_payment '@LcShop/backend/form/custom_bootstrap_4.html.twig' %} | |||||
<div class="modal-dialog"> | |||||
<div class="modal-content"> | |||||
<div class="modal-header"> | |||||
<h4>{{ "form.group.OrderShop.orderPayment"|trans }}</h4> | |||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |||||
<span aria-hidden="true">×</span> | |||||
</button> | |||||
</div> | |||||
<div class="modal-body"> | |||||
{{ form_row(form_order_payment.type) }} | |||||
{{ form_row(form_order_payment.paidAt) }} | |||||
{{ form_row(form_order_payment.amount) }} | |||||
{{ form_row(form_order_payment.reference) }} | |||||
{{ form_row(form_order_payment.comment) }} | |||||
</div> | |||||
<div class="modal-footer justify-content-between"> | |||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |||||
{{ form_row(form_order_payment.saveOrderPayment, {"attr": {'class' : 'btn btn-primary', '@click' : 'addOrderPayment'}}) }} | |||||
</div> | |||||
</div> | |||||
<!-- /.modal-content --> | |||||
</div> | |||||
{{ form_end(form_order_payment) }} | |||||
</div> |
$orderPayment->setReference($reference) ; | $orderPayment->setReference($reference) ; | ||||
$orderPayment->setComment($comment) ; | $orderPayment->setComment($comment) ; | ||||
$orderPayment->setPaidAt($paidAt) ; | $orderPayment->setPaidAt($paidAt) ; | ||||
$this->em->persist($orderPayment) ; | $this->em->persist($orderPayment) ; | ||||
$this->em->flush() ; | $this->em->flush() ; | ||||
} | } | ||||
public function isOrderPaid($orderShop){ | |||||
if($this->getTotalOrderPayments($orderShop) >= $this->priceUtils->getTotalWithTaxAndReduction($orderShop)){ | |||||
return true; | |||||
}else{ | |||||
return false; | |||||
} | |||||
} | |||||
public function getTotalOrderPayments($orderShop):float | |||||
{ | |||||
$totalAmount = floatval(0); | |||||
foreach ($orderShop->getOrderPayments() as $orderPayment){ | |||||
$totalAmount = $orderPayment->getAmount() + $totalAmount; | |||||
} | |||||
return $totalAmount; | |||||
} | |||||
} | } |