Browse Source

Système compte prépayés

feature/export_comptable
Fab 4 years ago
parent
commit
1208b5e050
17 changed files with 166 additions and 76 deletions
  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 View File

if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) { if ($formOrderPayment->isSubmitted() && $formOrderPayment->isValid()) {
$orderPayment->setOrderShop($orderShop); $orderPayment->setOrderShop($orderShop);


if($orderPayment->getMeanPayment('credit')){
if($orderPayment->getMeanPayment() === Utils::MEAN_PAYMENT_CREDIT){
$orderPayment->setEditable(false); $orderPayment->setEditable(false);
$params['amount'] = $orderPayment->getAmount();
$params['orderPayment'] = $orderPayment->getId();
$params['orderPayment'] = $orderPayment;
$creditHistory = $this->creditUtils->initCreditHistory(CreditHistory::TYPE_DEBIT, $orderShop->getUser(), $params); $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{ }else{
$this->utils->addFlash('success', 'error.credit.debited');
$this->utils->addFlash('error', 'error.credit.notEnoughCredit');
} }


}else{ }else{


switch ($orderShop->getOrderStatus()->getAlias()){ switch ($orderShop->getOrderStatus()->getAlias()){
case OrderStatus::ALIAS_CART : case OrderStatus::ALIAS_CART :

if (!isset($parameters['form_order_delivery_address'])) { if (!isset($parameters['form_order_delivery_address'])) {
$parameters['form_order_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView(); $parameters['form_order_delivery_address'] = $this->createCustomForm(OrderDeliveryAddressType::class, 'orderDeliveryAddress', $parameters)->createView();
} }
$parameters['form_delete_order_reduction_credit'] = $this->createCustomForm(DeleteOrderReductionCreditType::class, 'deleteOrderReductionCredit', $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_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_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; break;
case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT : case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT :
case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE : case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE :




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



+ 4
- 3
ShopBundle/Controller/Backend/UserMerchantController.php View File

$addCreditHistoryForm->handleRequest($this->request); $addCreditHistoryForm->handleRequest($this->request);
if ($addCreditHistoryForm->isSubmitted() && $addCreditHistoryForm->isValid()) { if ($addCreditHistoryForm->isSubmitted() && $addCreditHistoryForm->isValid()) {
$creditHistory->setUserMerchant($userMerchant); $creditHistory->setUserMerchant($userMerchant);
dump($creditHistory);
if($this->creditUtils->saveCreditHistory($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{ }else{
$this->utils->addFlash('warning', 'error.credit.notAdded');
$this->utils->addFlash('error', 'error.credit.notAdded');
} }


} else { } else {

+ 14
- 7
ShopBundle/Form/Backend/Order/OrderPaymentType.php View File

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\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType; 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\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
$builder $builder
->add('meanPayment', ChoiceType::class, array( ->add('meanPayment', ChoiceType::class, array(
'choices' => 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_CREDIT => Utils::MEAN_PAYMENT_CREDIT,
'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_TRANSFER => Utils::MEAN_PAYMENT_TRANSFER, 'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_TRANSFER => Utils::MEAN_PAYMENT_TRANSFER,
'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH 'field.default.meanPaymentOptions.' . Utils::MEAN_PAYMENT_CASH => Utils::MEAN_PAYMENT_CASH
'widget' => 'single_text', 'widget' => 'single_text',
'required' => true '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'
)); ));




{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => $this->em->getClassMetadata(OrderPaymentInterface::class)->getName(), 'data_class' => $this->em->getClassMetadata(OrderPaymentInterface::class)->getName(),
'translation_domain' => 'lcshop'
]); ]);
} }
} }

+ 4
- 5
ShopBundle/Form/Backend/UserMerchant/CreditHistoryType.php View File

{ {
$builder->add('type', ChoiceType::class, array( $builder->add('type', ChoiceType::class, array(
'choices' => 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 'required' => true
)) ))
->add('amount', NumberType::class, array(

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

+ 33
- 0
ShopBundle/Model/CreditHistory.php View File

} }
} }


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 public function getMeanPaymentInheritedLabel(): string
{ {
return 'field.default.meanPaymentOptions.'.$this->getMeanPaymentInherited() ; return 'field.default.meanPaymentOptions.'.$this->getMeanPaymentInherited() ;

+ 9
- 0
ShopBundle/Resources/public/css/backend/custom.css View File

.lc-offline-field label::after{content:' [hors ligne]'} .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 */ /* Général */
.btn.btn-primary.action-save{float: right;} .btn.btn-primary.action-save{float: right;}
.button-action .btn{margin-left: 10px;} .button-action .btn{margin-left: 10px;}

+ 9
- 0
ShopBundle/Resources/public/js/backend/script/default/init-common.js View File

initAdminLtePlugin(); initAdminLtePlugin();
initButtonConfirm() initButtonConfirm()
initNotice(); 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() { function initNotice() {

+ 7
- 1
ShopBundle/Resources/public/js/backend/script/order/vuejs-order.js View File

}, },
addOrderPayment: function () { 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 () { updateOrderProducts: function () {
this.postForm('#orderProductsForm', false); this.postForm('#orderProductsForm', false);

+ 22
- 2
ShopBundle/Resources/translations/lcshop.fr.yaml View File

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



action: action:
new: Créer %entity_label% new: Créer %entity_label%
addOrderProduct: Ajouter un produit addOrderProduct: Ajouter un produit
addReductionCart: Ajouter une réduction addReductionCart: Ajouter une réduction
addReductionCredit: Ajouter un avoir addReductionCredit: Ajouter un avoir
credit:
add: Ajouter du crédit


resetting: resetting:
check_email: | check_email: |

+ 3
- 3
ShopBundle/Resources/views/backend/default/list.html.twig View File



{% set searchable = ''%} {% 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'%} {% set searchable = 'input'%}
{% elseif metadata.type == 'association' %} {% elseif metadata.type == 'association' %}
{% set searchable= "select" %} {% set searchable= "select" %}
{% elseif metadata.type == 'text' %}
{% set searchable= "select-text" %}
{#{% elseif metadata.type == 'text' %}
{% set searchable= "select-text" %}#}
{% elseif metadata.type=="toggle" %} {% elseif metadata.type=="toggle" %}
{% set searchable= "select" %} {% set searchable= "select" %}
{% endif %} {% endif %}

+ 7
- 0
ShopBundle/Resources/views/backend/form/custom_bootstrap_4.html.twig View File



{% endblock form_widget %} {% 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 -%} {%- block choice_widget_collapsed -%}
{% if placeholder is empty %}{% set placeholder = 'field.default.placeholder' %}{% endif %} {% if placeholder is empty %}{% set placeholder = 'field.default.placeholder' %}{% endif %}
{{ parent() }} {{ parent() }}

+ 0
- 1
ShopBundle/Resources/views/backend/order/edit-cart.html.twig View File

{{ "action.addOrderPayment"|trans }} {{ "action.addOrderPayment"|trans }}
</button> </button>



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

+ 4
- 3
ShopBundle/Resources/views/backend/order/form/modal_orderpayment.html.twig View File

{% trans_default_domain'lcshop' %}
<div class="modal fade show" id="modal-order-payment"> <div class="modal fade show" id="modal-order-payment">
{{ form_start(form_order_payment, {'attr': { 'id' : 'orderPaymentForm'}}) }}) }} {{ form_start(form_order_payment, {'attr': { 'id' : 'orderPaymentForm'}}) }}) }}
{% form_theme form_order_payment '@LcShop/backend/form/custom_bootstrap_4.html.twig' %} {% form_theme form_order_payment '@LcShop/backend/form/custom_bootstrap_4.html.twig' %}


<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <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"> <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">
{{ form_row(form_order_payment.meanPayment) }} {{ form_row(form_order_payment.meanPayment) }}
{{ form_row(form_order_payment.paidAt) }}
{{ form_row(form_order_payment.amount) }} {{ form_row(form_order_payment.amount) }}
{{ form_row(form_order_payment.paidAt) }}
{{ form_row(form_order_payment.reference) }} {{ form_row(form_order_payment.reference) }}
{{ form_row(form_order_payment.comment) }} {{ form_row(form_order_payment.comment) }}
</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_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>
</div> </div>
<!-- /.modal-content --> <!-- /.modal-content -->

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



<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <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"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span> <span aria-hidden="true">×</span>
</button> </button>
{{ form_row(add_credit_history_form.type) }} {{ form_row(add_credit_history_form.type) }}
</div> </div>
<div class="col"> <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>


<div class="col"> <div class="col">

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

{% extends '@LcShop/backend/default/show.html.twig' %} {% extends '@LcShop/backend/default/show.html.twig' %}


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


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


<thead> <thead>
<tr> <tr>
<th data-index="0" class="" data-searchable="text">Id</th> <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> <th data-index="6" class="" data-searchable="">Comment</th>
</tr> </tr>
</thead> </thead>
<tr draggable="true" rel="{{ creditHistory.id }}" data-id="{{ creditHistory.id }}"> <tr draggable="true" rel="{{ creditHistory.id }}" data-id="{{ creditHistory.id }}">


<td class="sorted">{{ creditHistory.id }}</td> <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> </tr>


{% else %} {% else %}

+ 13
- 14
ShopBundle/Services/CreditUtils.php View File

$isCreditActive = $this->isCreditActive($userMerchant) ; $isCreditActive = $this->isCreditActive($userMerchant) ;


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

if($creditHistory->getType() == CreditHistory::TYPE_CREDIT) { if($creditHistory->getType() == CreditHistory::TYPE_CREDIT) {
$userMerchantAmount = $userMerchant->getCredit() + $creditHistory->getAmountInherited() ; $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;
}
} }
} }
} }
return false ; return false ;
} }


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


public function getMerchant($merchant) public function getMerchant($merchant)

+ 7
- 3
ShopBundle/Twig/BackendTwigExtension.php View File



public function lcTrad($field, $entityName, $type = "field") 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'); $trad = $this->trans->trans($tradKey, array(), 'lcshop');
if ($trad == $tradKey) { if ($trad == $tradKey) {
$trad = $this->trans->trans($tradDefaultKey, array(), 'lcshop'); $trad = $this->trans->trans($tradDefaultKey, array(), 'lcshop');

Loading…
Cancel
Save