Переглянути джерело

Système compte prépayés

feature/export_comptable
Fab 4 роки тому
джерело
коміт
1208b5e050
17 змінених файлів з 166 додано та 76 видалено
  1. +15
    -10
      ShopBundle/Controller/Backend/OrderController.php
  2. +4
    -3
      ShopBundle/Controller/Backend/UserMerchantController.php
  3. +14
    -7
      ShopBundle/Form/Backend/Order/OrderPaymentType.php
  4. +4
    -5
      ShopBundle/Form/Backend/UserMerchant/CreditHistoryType.php
  5. +33
    -0
      ShopBundle/Model/CreditHistory.php
  6. +9
    -0
      ShopBundle/Resources/public/css/backend/custom.css
  7. +9
    -0
      ShopBundle/Resources/public/js/backend/script/default/init-common.js
  8. +7
    -1
      ShopBundle/Resources/public/js/backend/script/order/vuejs-order.js
  9. +22
    -2
      ShopBundle/Resources/translations/lcshop.fr.yaml
  10. +3
    -3
      ShopBundle/Resources/views/backend/default/list.html.twig
  11. +7
    -0
      ShopBundle/Resources/views/backend/form/custom_bootstrap_4.html.twig
  12. +0
    -1
      ShopBundle/Resources/views/backend/order/edit-cart.html.twig
  13. +4
    -3
      ShopBundle/Resources/views/backend/order/form/modal_orderpayment.html.twig
  14. +2
    -12
      ShopBundle/Resources/views/backend/usermerchant/modal_addcredithistory.html.twig
  15. +13
    -12
      ShopBundle/Resources/views/backend/usermerchant/show.html.twig
  16. +13
    -14
      ShopBundle/Services/CreditUtils.php
  17. +7
    -3
      ShopBundle/Twig/BackendTwigExtension.php

+ 15
- 10
ShopBundle/Controller/Backend/OrderController.php Переглянути файл

@@ -261,18 +261,19 @@ class OrderController extends AdminController
if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) {
$orderPayment->setOrderShop($orderShop);

if($orderPayment->getMeanPayment('credit')){
if($orderPayment->getMeanPayment() === Utils::MEAN_PAYMENT_CREDIT){
$orderPayment->setEditable(false);
$params['amount'] = $orderPayment->getAmount();
$params['orderPayment'] = $orderPayment->getId();
$params['orderPayment'] = $orderPayment;
$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');
if ($this->creditUtils->isCreditSufficientToPay($creditHistory->getUserMerchant(), $creditHistory->getAmountInherited())) {
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');
$this->utils->addFlash('error', 'error.credit.notEnoughCredit');
}

}else{
@@ -399,6 +400,7 @@ class OrderController extends AdminController

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();
}
@@ -408,6 +410,9 @@ class OrderController extends AdminController
$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_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;
case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT :
case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE :
@@ -419,7 +424,7 @@ class OrderController extends AdminController


}
dump($templatePath);
return parent::renderTemplate($actionName, $templatePath, $parameters);
}


+ 4
- 3
ShopBundle/Controller/Backend/UserMerchantController.php Переглянути файл

@@ -39,11 +39,12 @@ class UserMerchantController extends AdminController
$addCreditHistoryForm->handleRequest($this->request);
if ($addCreditHistoryForm->isSubmitted() && $addCreditHistoryForm->isValid()) {
$creditHistory->setUserMerchant($userMerchant);
dump($creditHistory);
if($this->creditUtils->saveCreditHistory($creditHistory)){
$this->utils->addFlash('warning', 'success.credit.added');

//TODo envoyer un email à l'utilisateur
$this->utils->addFlash('success', 'success.credit.added');
}else{
$this->utils->addFlash('warning', 'error.credit.notAdded');
$this->utils->addFlash('error', 'error.credit.notAdded');
}

} else {

+ 14
- 7
ShopBundle/Form/Backend/Order/OrderPaymentType.php Переглянути файл

@@ -11,6 +11,7 @@ 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\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -31,8 +32,8 @@ class OrderPaymentType extends AbstractType
$builder
->add('meanPayment', ChoiceType::class, array(
'choices' => array(
'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_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
@@ -43,11 +44,16 @@ class OrderPaymentType extends AbstractType
'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'
->add('amount', MoneyType::class, array(
))
->add('reference', TextType::class, array(
'required' => false
))
->add('comment', TextareaType::class, array(
'required' => false
))
->add('add', ButtonType::class, array(
'label' => 'action.add'
));


@@ -57,6 +63,7 @@ class OrderPaymentType extends AbstractType
{
$resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(OrderPaymentInterface::class)->getName(),
'translation_domain' => 'lcshop'
]);
}
}

+ 4
- 5
ShopBundle/Form/Backend/UserMerchant/CreditHistoryType.php Переглянути файл

@@ -43,14 +43,12 @@ class CreditHistoryType extends AbstractType
{
$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
'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(

))
->add('amount', MoneyType::class)
->add('meanPayment', ChoiceType::class, array(
'choices' => array(
'field.default.meanPaymentOptions.'.Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH,
@@ -83,6 +81,7 @@ class CreditHistoryType extends AbstractType
{
$resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(CreditHistoryInterface::class)->getName(),
'translation_domain'=>'lcshop'
]);
}
}

+ 33
- 0
ShopBundle/Model/CreditHistory.php Переглянути файл

@@ -82,6 +82,39 @@ abstract class CreditHistory extends AbstractEntity implements PayoffInterface
}
}

public function getPaidAtInherited (): ?\DateTimeInterface
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getPaidAt();
} else if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getPaidAt();
} else {
return $this->getPaidAt();
}
}

public function getReferenceInherited (): ?string
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getReference();
} else if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getReference();
} else {
return $this->getReference();
}
}

public function getCommentInherited (): ?string
{
if ($this->getOrderPayment() !== null) {
return $this->getOrderPayment()->getComment();
} else if ($this->getOrderRefund() !== null) {
return $this->getOrderRefund()->getComment();
} else {
return $this->getComment();
}
}

public function getMeanPaymentInheritedLabel(): string
{
return 'field.default.meanPaymentOptions.'.$this->getMeanPaymentInherited() ;

+ 9
- 0
ShopBundle/Resources/public/css/backend/custom.css Переглянути файл

@@ -94,6 +94,15 @@ table th .select2-container--default .select2-selection--single{padding:0.3rem 0
.lc-offline-field label::after{content:' [hors ligne]'}


input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
-webkit-appearance: none;
}

input[type=number] {
-moz-appearance: textfield;
}

/* Général */
.btn.btn-primary.action-save{float: right;}
.button-action .btn{margin-left: 10px;}

+ 9
- 0
ShopBundle/Resources/public/js/backend/script/default/init-common.js Переглянути файл

@@ -3,6 +3,15 @@ jQuery(document).ready(function () {
initAdminLtePlugin();
initButtonConfirm()
initNotice();

$('form').on('focus', 'input[type=number]', function (e) {
$(this).on('wheel.disableScroll', function (e) {
e.preventDefault()
})
})
$('form').on('blur', 'input[type=number]', function (e) {
$(this).off('wheel.disableScroll')
})
});

function initNotice() {

+ 7
- 1
ShopBundle/Resources/public/js/backend/script/order/vuejs-order.js Переглянути файл

@@ -132,7 +132,13 @@ appOrder = new Vue({
},
addOrderPayment: function () {

this.postForm('#orderPaymentForm', '#modal-order-payment');
if($('#order_payment_meanPayment').val() == 'credit'){
if(window.confirm("Vous allez débitez le compte prépayé, êtes vous sur ?")){
this.postForm('#orderPaymentForm', '#modal-order-payment');
}
}else{
this.postForm('#orderPaymentForm', '#modal-order-payment');
}
},
updateOrderProducts: function () {
this.postForm('#orderProductsForm', false);

+ 22
- 2
ShopBundle/Resources/translations/lcshop.fr.yaml Переглянути файл

@@ -42,6 +42,7 @@ group:
OrderShop:
resume: Résumé de commande
addProduct: Ajout de produit à la commande
orderPayment: Ajouter un règlement
None: Aucune valeur
label.form.empty_value: Choisissez une option
form.label.delete: Supprimer l'image
@@ -53,8 +54,9 @@ success:
changeInvoiceAddress: L'adresse de facuration a bien été modifié
changeDeliveryAddress: L'adresse de livraison a bien été modifié
addProduct: Le produit a bien été ajouté
credt:
credit:
debited: Le compte prépayé a bien été débité
added: Le compte a bien été crédité
error:
form:
submitted: Une erreur est survenue à la soumission du formulaire
@@ -84,7 +86,8 @@ error:
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é
notEnoughCredit:
notEnoughCredit: Le compte prépayé n'est pas suffisament allimenté
notAdded: Le crédit n'a pas été ajouté
field:
default:
placeholder: Choisissez une option
@@ -110,6 +113,8 @@ field:
lastname: Nom
firstname: Prénom
country: Pays
product: Produit
quantity: Quantité
address: Adresse
zip: Code postal
city: Ville
@@ -184,8 +189,14 @@ field:
deliveryTypeOptions:
point-sale: En ambassade
home: À domicile
paidAt: Payé le
reference: Référence
comment: Commentaire
meanPayment: Mode de règlement
meanPaymentHelp: Format attendu xx.xx
meanPaymentOptions:
cheque: Chèque
cb: Carte bancaire
cash: Espèce
transfer: Virement
credit: Compte prépayé
@@ -286,6 +297,13 @@ field:
addOrderToProduct: Ajouter le produit
total: Total
status: Statut
UserMerchant:
credit: Solde du compte prépayé
CreditHistory:
typeOptions:
credit: Crédit
debit: Débit


action:
new: Créer %entity_label%
@@ -309,6 +327,8 @@ action:
addOrderProduct: Ajouter un produit
addReductionCart: Ajouter une réduction
addReductionCredit: Ajouter un avoir
credit:
add: Ajouter du crédit

resetting:
check_email: |

+ 3
- 3
ShopBundle/Resources/views/backend/default/list.html.twig Переглянути файл

@@ -128,12 +128,12 @@

{% set searchable = ''%}

{% if metadata.type == 'integer' or metadata.type =="string" %}
{% if metadata.type == 'integer' or metadata.type =="string" or metadata.type == 'text'%}
{% set searchable = 'input'%}
{% elseif metadata.type == 'association' %}
{% set searchable= "select" %}
{% elseif metadata.type == 'text' %}
{% set searchable= "select-text" %}
{#{% elseif metadata.type == 'text' %}
{% set searchable= "select-text" %}#}
{% elseif metadata.type=="toggle" %}
{% set searchable= "select" %}
{% endif %}

+ 7
- 0
ShopBundle/Resources/views/backend/form/custom_bootstrap_4.html.twig Переглянути файл

@@ -13,6 +13,13 @@

{% endblock form_widget %}

{% block money_widget %}
{%- set attr = attr|merge({pattern: ('^[0-9]+(\.[0-9]{1,2})?$')|trim}) -%}
{%- set money_pattern = "{{ widget }} €" -%}

{{ parent() }}
{% endblock %}

{%- block choice_widget_collapsed -%}
{% if placeholder is empty %}{% set placeholder = 'field.default.placeholder' %}{% endif %}
{{ parent() }}

+ 0
- 1
ShopBundle/Resources/views/backend/order/edit-cart.html.twig Переглянути файл

@@ -36,7 +36,6 @@
{{ "action.addOrderPayment"|trans }}
</button>


{% if form_order_invoice_address is defined %}
{% include '@LcShop/backend/order/form/modal_invoiceaddress.html.twig' %}
{% endif %}

+ 4
- 3
ShopBundle/Resources/views/backend/order/form/modal_orderpayment.html.twig Переглянути файл

@@ -1,3 +1,4 @@
{% trans_default_domain'lcshop' %}
<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' %}
@@ -5,21 +6,21 @@

<div class="modal-content">
<div class="modal-header">
<h4>{{ "form.group.OrderShop.orderPayment"|trans }}</h4>
<h4>{{ "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.meanPayment) }}
{{ form_row(form_order_payment.paidAt) }}
{{ form_row(form_order_payment.amount) }}
{{ form_row(form_order_payment.paidAt) }}
{{ 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'}}) }}
{{ form_widget(form_order_payment.add, {"attr": {'class' : 'btn btn-primary', '@click' : 'addOrderPayment'}}) }}
</div>
</div>
<!-- /.modal-content -->

+ 2
- 12
ShopBundle/Resources/views/backend/usermerchant/modal_addcredithistory.html.twig Переглянути файл

@@ -7,7 +7,7 @@

<div class="modal-content">
<div class="modal-header">
<h4>{{ "action.addCreditHistory"|trans }}</h4>
<h4>{{ "action.credit.add"|trans }}</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
@@ -17,17 +17,7 @@
{{ form_row(add_credit_history_form.type) }}
</div>
<div class="col">

{{ 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>
{{ form_row(add_credit_history_form.amount) }}
</div>

<div class="col">

+ 13
- 12
ShopBundle/Resources/views/backend/usermerchant/show.html.twig Переглянути файл

@@ -1,5 +1,6 @@
{% extends '@LcShop/backend/default/show.html.twig' %}

{% trans_default_domain 'lcshop' %}
{% block main %}

<div class="row">
@@ -11,7 +12,7 @@
</h2>
<button type="button" class="btn btn-primary float-right" data-toggle="modal"
data-target="#modal-add-credit-history">
{{ "action.addCreditHistory"|trans }}
{{ "action.credit.add"|trans }}
</button>
</div>

@@ -22,11 +23,11 @@
<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="1" class="" data-searchable="select-text">Type</th>
<th data-index="2" class="" data-searchable="input">Amount</th>
<th data-index="3" class="" data-searchable="input">MeanPayment</th>
<th data-index="4" class="" data-searchable="date">PaidAt</th>
<th data-index="5" class="" data-searchable="input">Reference</th>
<th data-index="6" class="" data-searchable="">Comment</th>
</tr>
</thead>
@@ -35,12 +36,12 @@
<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>
<td class="association">{{ creditHistory.type }}</td>
<td class="">{{ creditHistory.amountInherited }} €</td>
<td class="">{{ creditHistory.meanPaymentInherited }}</td>
<td class="">{{ creditHistory.paidAtInherited |date('d-m-y') }}</td>
<td class="">{{ creditHistory.referenceInherited }}</td>
<td class="">{{ creditHistory.commentInherited }}</td>
</tr>

{% else %}

+ 13
- 14
ShopBundle/Services/CreditUtils.php Переглянути файл

@@ -158,21 +158,18 @@ class CreditUtils
$isCreditActive = $this->isCreditActive($userMerchant) ;

if($isCreditActive) {
$this->em->persist($creditHistory) ;
$this->em->flush() ;

if($creditHistory->getType() == CreditHistory::TYPE_CREDIT) {
$userMerchantAmount = $userMerchant->getCredit() + $creditHistory->getAmountInherited() ;
}
elseif($creditHistory->getType() == CreditHistory::TYPE_DEBIT) {
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited() ;
}
if($this->isCreditSufficientToPay($userMerchant,$userMerchantAmount)) {
$this->updateCredit($userMerchant, $userMerchantAmount) ;
return true ;
}else{
$this->utils->addFlash('success', 'error.credit.notEnoughCredit');
return false ;
$this->updateCredit($userMerchant,$creditHistory, $userMerchantAmount);
return true;
}elseif($creditHistory->getType() == CreditHistory::TYPE_DEBIT) {
if ($this->isCreditSufficientToPay($userMerchant, $creditHistory->getAmountInherited())) {
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited();
$this->updateCredit($userMerchant,$creditHistory, $userMerchantAmount);
return true;
} else {
return false;
}
}
}
}
@@ -180,11 +177,13 @@ class CreditUtils
return false ;
}

public function updateCredit($userMerchant, $amount)
public function updateCredit($userMerchant, $creditHistory, $amount)
{
$this->em->persist($creditHistory) ;
$userMerchant->setCredit($amount) ;
$this->em->persist($userMerchant) ;
$this->em->flush() ;
return $userMerchant;
}

public function getMerchant($merchant)

+ 7
- 3
ShopBundle/Twig/BackendTwigExtension.php Переглянути файл

@@ -47,9 +47,13 @@ class BackendTwigExtension extends AbstractExtension

public function lcTrad($field, $entityName, $type = "field")
{

$tradKey = $type . '.' . $entityName . '.' . $field;
$tradDefaultKey = $type . '.default.' . $field;
if(strpos($field, '.')===false) {
$tradKey = $type . '.' . $entityName . '.' . $field;
$tradDefaultKey = $type . '.default.' . $field;
}else{
$tradKey = $type . $field;
$tradDefaultKey = $type .'.default'. substr($field,strpos($field, '.'));
}
$trad = $this->trans->trans($tradKey, array(), 'lcshop');
if ($trad == $tradKey) {
$trad = $this->trans->trans($tradDefaultKey, array(), 'lcshop');

Завантаження…
Відмінити
Зберегти