@@ -4,15 +4,18 @@ namespace Lc\ShopBundle\Controller\Backend; | |||
use App\Entity\OrderShop; | |||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||
use Lc\ShopBundle\Context\OrderPaymentInterface; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Form\Backend\Order\AddPoductToOrderType; | |||
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\OrderStatusType; | |||
use Lc\ShopBundle\Model\OrderPayment; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |||
use Symfony\Component\HttpFoundation\Response; | |||
@@ -144,6 +147,7 @@ class OrderController extends AdminController | |||
$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'; | |||
@@ -220,6 +224,35 @@ class OrderController extends AdminController | |||
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() | |||
@@ -363,6 +396,14 @@ class OrderController extends AdminController | |||
]) | |||
)); | |||
$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'])) { | |||
$formOrderDeliveryAddress = $this->createForm(OrderDeliveryAddressType::class, null, array( | |||
'data' => $parameters['entity'], | |||
@@ -380,6 +421,7 @@ class OrderController extends AdminController | |||
$parameters['form_order_products'] = $formOrderProducts->createView(); | |||
$parameters['form_order_invoice_address'] = $formOrderInvoiceAddress->createView(); | |||
$parameters['form_order_status'] = $formOrderStatus->createView(); | |||
$parameters['form_order_payment'] = $formOrderPayment->createView(); | |||
} | |||
return parent::renderTemplate($actionName, $templatePath, $parameters); | |||
} |
@@ -0,0 +1,59 @@ | |||
<?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(), | |||
]); | |||
} | |||
} |
@@ -56,7 +56,7 @@ abstract class Document extends AbstractDocumentEntity implements FilterMerchant | |||
protected $merchantAddressText; | |||
/** | |||
* @ORM\Column(type="text") | |||
* @ORM\Column(type="text",nullable=true) | |||
*/ | |||
protected $buyerAddressText; | |||
@@ -185,7 +185,7 @@ abstract class Document extends AbstractDocumentEntity implements FilterMerchant | |||
return $this->buyerAddressText; | |||
} | |||
public function setBuyerAddressText(string $buyerAddressText): self | |||
public function setBuyerAddressText(?string $buyerAddressText): self | |||
{ | |||
$this->buyerAddressText = $buyerAddressText; | |||
@@ -49,7 +49,7 @@ abstract class OrderPayment extends AbstractEntity | |||
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 |
@@ -35,6 +35,11 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa | |||
*/ | |||
protected $invoiceAddress; | |||
/** | |||
* @ORM\Column(type="text", nullable=true) | |||
*/ | |||
protected $invoiceAddressText; | |||
/** | |||
* @ORM\Column(type="datetime", nullable=true) | |||
*/ | |||
@@ -198,6 +203,18 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa | |||
return $this; | |||
} | |||
public function getInvoiceAddressText(): ?string | |||
{ | |||
return $this->invoiceAddressText; | |||
} | |||
public function setInvoiceAddressText(string $invoiceAddressText): self | |||
{ | |||
$this->invoiceAddressText = $invoiceAddressText; | |||
return $this; | |||
} | |||
public function getComment(): ?string | |||
{ | |||
return $this->comment; |
@@ -87,7 +87,6 @@ appOrder = new Vue({ | |||
isLoading: true, | |||
addProductId: null, | |||
addProductQuantity: null, | |||
sectionsArray: [ | |||
{ | |||
name: 'cart', | |||
@@ -114,6 +113,9 @@ appOrder = new Vue({ | |||
addProductToOrder: function () { | |||
this.postForm('#addProductToOrderForm', false); | |||
}, | |||
addOrderPayment: function () { | |||
this.postForm('#orderPaymentForm', '#modal-order-payment'); | |||
}, | |||
updateOrderProducts: function () { | |||
this.postForm('#orderProductsForm', false); | |||
}, | |||
@@ -123,19 +125,20 @@ appOrder = new Vue({ | |||
updateOrderDeliveryAddress: function () { | |||
this.postForm('#orderDeliveryAddressForm', '#modal-order-invoice-address'); | |||
}, | |||
updateOrderDeliveryAvailability:function(){ | |||
updateOrderDeliveryAvailability: function () { | |||
this.postForm('#orderDeliveryAvailabilityForm', '#modal-order-delivery-availability'); | |||
}, | |||
addOrderReductionCart:function(){ | |||
addOrderReductionCart: function () { | |||
this.postForm('#orderReductionCartForm', '#modal-reduction-cart'); | |||
}, | |||
addOrderReductionCredit:function(){ | |||
addOrderReductionCredit: function () { | |||
this.postForm('#orderReductionCreditForm', '#modal-reduction-credit'); | |||
}, | |||
postForm:function(formId, modalId){ | |||
postForm: function (formId, modalId) { | |||
var app = this; | |||
this.isLoading = true; | |||
if(modalId)$(modalId).modal('hide'); | |||
if (modalId) $(modalId).modal('hide'); | |||
$.ajax({ | |||
url: $(formId).prop('action'), | |||
method: "POST", | |||
@@ -153,8 +156,7 @@ appOrder = new Vue({ | |||
this.isLoading = false; | |||
}, | |||
}, | |||
watch: { | |||
} | |||
watch: {} | |||
}); | |||
@@ -23,7 +23,7 @@ | |||
</div> | |||
<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> | |||
<address v-html="order.deliveryAddress"> | |||
</address> | |||
@@ -52,7 +52,7 @@ | |||
</div> | |||
<div class="col-12"> | |||
<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> | |||
</div> | |||
@@ -92,6 +92,17 @@ | |||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#modal-reduction-credit"> | |||
{{ "action.addReductionCredit"|trans }} | |||
</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> | |||
@@ -19,6 +19,7 @@ | |||
{% include '@LcShop/backend/order/modal_orderstatus.html.twig' %} | |||
{% include '@LcShop/backend/order/modal_reductioncart.html.twig' %} | |||
{% include '@LcShop/backend/order/modal_reductioncredit.html.twig' %} | |||
{% include '@LcShop/backend/order/modal_orderpayment.html.twig' %} | |||
{{ macros.endCard }} | |||
</div> | |||
</div> |
@@ -18,7 +18,7 @@ | |||
{{ form_row(form_order_delivery_availability.deliveryAvailabilityPointSale) }} | |||
</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) }} | |||
</div> | |||
@@ -0,0 +1,28 @@ | |||
<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> |
@@ -430,9 +430,25 @@ class OrderUtils | |||
$orderPayment->setReference($reference) ; | |||
$orderPayment->setComment($comment) ; | |||
$orderPayment->setPaidAt($paidAt) ; | |||
$this->em->persist($orderPayment) ; | |||
$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; | |||
} | |||
} |