Просмотр исходного кода

[Administration] Documents > Factures : gestion des paiements #1219

feature/souke
Guillaume Bourgeois 1 год назад
Родитель
Сommit
1c4647faf0
41 измененных файлов: 600 добавлений и 534 удалений
  1. +2
    -5
      backend/controllers/CronController.php
  2. +13
    -11
      backend/controllers/DistributionController.php
  3. +13
    -14
      backend/controllers/OrderController.php
  4. +2
    -5
      backend/controllers/UserController.php
  5. +3
    -10
      backend/models/CreditForm.php
  6. +28
    -11
      backend/views/distribution/index.php
  7. +12
    -12
      backend/views/user/credit.php
  8. +34
    -30
      backend/web/css/screen.css
  9. +2
    -1
      backend/web/js/vuejs/distribution-index.js
  10. +2
    -0
      backend/web/sass/distribution/_index.scss
  11. +1
    -1
      common/components/BusinessLogic.php
  12. +6
    -6
      common/components/BusinessLogicTrait.php
  13. +3
    -3
      common/config/main.php
  14. +3
    -3
      common/logic/Order/Order/Model/Order.php
  15. +2
    -2
      common/logic/Order/Order/Repository/OrderRepository.php
  16. +17
    -24
      common/logic/Order/Order/Service/OrderBuilder.php
  17. +10
    -13
      common/logic/Order/Order/Service/OrderSolver.php
  18. +12
    -8
      common/logic/Payment/Model/CreditHistorySearch.php
  19. +21
    -5
      common/logic/Payment/Model/Payment.php
  20. +7
    -7
      common/logic/Payment/Repository/PaymentRepository.php
  21. +23
    -0
      common/logic/Payment/Repository/PaymentRepositoryQuery.php
  22. +72
    -0
      common/logic/Payment/Service/PaymentBuilder.php
  23. +14
    -0
      common/logic/Payment/Service/PaymentDefinition.php
  24. +98
    -0
      common/logic/Payment/Service/PaymentSolver.php
  25. +43
    -22
      common/logic/Payment/Service/PaymentUtils.php
  26. +49
    -0
      common/logic/Payment/Wrapper/PaymentContainer.php
  27. +25
    -0
      common/logic/Payment/Wrapper/PaymentManager.php
  28. +0
    -23
      common/logic/User/CreditHistory/Repository/CreditHistoryRepositoryQuery.php
  29. +0
    -74
      common/logic/User/CreditHistory/Service/CreditHistoryBuilder.php
  30. +0
    -14
      common/logic/User/CreditHistory/Service/CreditHistoryDefinition.php
  31. +0
    -100
      common/logic/User/CreditHistory/Service/CreditHistorySolver.php
  32. +0
    -49
      common/logic/User/CreditHistory/Wrapper/CreditHistoryContainer.php
  33. +0
    -25
      common/logic/User/CreditHistory/Wrapper/CreditHistoryManager.php
  34. +3
    -3
      common/logic/User/UserProducer/Event/PaymentObserver.php
  35. +23
    -22
      common/logic/User/UserProducer/Service/UserProducerBuilder.php
  36. +2
    -2
      common/mail/creditUser-html.php
  37. +2
    -2
      common/mail/creditUser-text.php
  38. +27
    -0
      console/migrations/m230913_071815_alter_table_credit_history_rename_payment.php
  39. +7
    -8
      producer/controllers/CreditController.php
  40. +3
    -3
      producer/controllers/OrderController.php
  41. +16
    -16
      producer/views/credit/history.php

+ 2
- 5
backend/controllers/CronController.php Просмотреть файл

@@ -38,10 +38,7 @@

namespace backend\controllers;

use common\helpers\MeanPayment;
use common\logic\Order\Order\Model\Order;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\User\Model\User;
use Yii;
use yii\filters\VerbFilter;
@@ -112,7 +109,7 @@ class CronController extends BackendController
$producerManager = $this->getProducerManager();
$distributionManager = $this->getDistributionManager();
$orderManager = $this->getOrderManager();
$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();
$userManager = $this->getUserManager();

if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
@@ -165,7 +162,7 @@ class CronController extends BackendController
$orderManager->initOrder($order);
if ($order->auto_payment && $configCredit) {
if ($orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) {
$creditHistoryManager->payOrder($order, $userManager->findOneUserById(User::ID_USER_SYSTEM), false);
$paymentManager->payOrder($order, $userManager->findOneUserById(User::ID_USER_SYSTEM), false);
$countOrders++;
}
}

+ 13
- 11
backend/controllers/DistributionController.php Просмотреть файл

@@ -286,7 +286,7 @@ class DistributionController extends BackendController
{
$userManager = $this->getUserManager();
$orderManager = $this->getOrderManager();
$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();

if ($ordersArray) {
foreach ($ordersArray as &$order) {
@@ -317,19 +317,20 @@ class DistributionController extends BackendController

$creditHistoryArray = [];

foreach ($order->creditHistory as $creditHistory) {
foreach ($order->payment as $payment) {
$creditHistoryArray[] = [
'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)),
'user' => $userManager->getUsername($creditHistory->getUserObject()),
'user_action' => $creditHistoryManager->getStrUserAction($creditHistory),
'wording' => $creditHistoryManager->getStrWording($creditHistory),
'debit' => ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . $creditHistoryManager->getAmount(
$creditHistory,
'mean_payment' => $payment->mean_payment,
'date' => date('d/m/Y H:i:s', strtotime($payment->date)),
'user' => $userManager->getUsername($payment->getUserObject()),
'user_action' => $paymentManager->getStrUserAction($payment),
'wording' => $paymentManager->getStrWording($payment),
'debit' => ($paymentManager->isTypeDebit($payment) ? '- ' . $paymentManager->getAmount(
$payment,
Order::AMOUNT_TOTAL,
true
) : ''),
'credit' => ($creditHistoryManager->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryManager->getAmount(
$creditHistory,
'credit' => ($paymentManager->isTypeCredit($payment) ? '+ ' . $paymentManager->getAmount(
$payment,
Order::AMOUNT_TOTAL,
true
) : '')
@@ -363,9 +364,10 @@ class DistributionController extends BackendController
) : null,
'pointSale' => $order->pointSale ? ['id' => $order->pointSale->id, 'name' => $order->pointSale->name] : null,
'productOrder' => $productOrderArray,
'creditHistory' => $creditHistoryArray,
'paymentArray' => $creditHistoryArray,
'oneProductUnactivated' => $oneProductUnactivated,
'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order),
'isCreditAutoPayment' => $orderManager->isCreditAutoPayment($order)
]);
}
}

+ 13
- 14
backend/controllers/OrderController.php Просмотреть файл

@@ -41,7 +41,6 @@ namespace backend\controllers;
use common\forms\SubscriptionForm;
use common\helpers\CSV;
use common\helpers\GlobalParam;
use common\helpers\MeanPayment;
use common\helpers\Price;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution;
@@ -50,7 +49,7 @@ use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Product\Product\Model\Product;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\Payment\Model\Payment;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Model\UserProducer;
use yii\filters\AccessControl;
@@ -889,7 +888,7 @@ class OrderController extends BackendController
$userManager = $this->getUserManager();
$pointSaleManager = $this->getPointSaleManager();
$userPointSaleManager = $this->getUserPointSaleManager();
$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();
$productManager = $this->getProductManager();

$request = \Yii::$app->request;
@@ -915,7 +914,7 @@ class OrderController extends BackendController
$oldIdUser = $order->id_user;
$amountPaid = $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_PAID);
if ($oldIdUser != $idUser && $amountPaid > 0) {
$creditHistoryManager->refundOrder($order, $this->getUserCurrent());
$paymentManager->refundOrder($order, $this->getUserCurrent());
$order = $orderManager->findOneOrderById($idOrder);
$orderManager->initOrder($order);
}
@@ -1016,7 +1015,7 @@ class OrderController extends BackendController
public function actionPaymentStatus(int $idOrder)
{
$orderManager = $this->getOrderManager();
$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();

$order = $orderManager->findOneOrderById($idOrder);

@@ -1052,7 +1051,7 @@ class OrderController extends BackendController
. '</span>';

// historique
$history = CreditHistory::find()
$history = Payment::find()
->with('userAction')
->where(['id_order' => $idOrder])
->all();
@@ -1064,11 +1063,11 @@ class OrderController extends BackendController
if ($history && is_array($history) && count($history)) {
foreach ($history as $creditHistory) {
$html .= '<tr>'
. '<td>' . date('d/m/Y H:i:s', strtotime($creditHistoryManager->getDate($creditHistory))) . '</td>'
. '<td>' . Html::encode($creditHistoryManager->getStrUserAction($creditHistory)) . '</td>'
. '<td>' . $creditHistoryManager->getStrWording($creditHistory) . '</td>'
. '<td>' . ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . Price::getPriceWithTax($creditHistory->amount) : '') . '</td>'
. '<td>' . ($creditHistoryManager->isTypeCredit($creditHistory) ? '+ ' . Price::getPriceWithTax($creditHistory->amount) : '') . '</td>'
. '<td>' . date('d/m/Y H:i:s', strtotime($paymentManager->getDate($creditHistory))) . '</td>'
. '<td>' . Html::encode($paymentManager->getStrUserAction($creditHistory)) . '</td>'
. '<td>' . $paymentManager->getStrWording($creditHistory) . '</td>'
. '<td>' . ($paymentManager->isTypeDebit($creditHistory) ? '- ' . Price::getPriceWithTax($creditHistory->amount) : '') . '</td>'
. '<td>' . ($paymentManager->isTypeCredit($creditHistory) ? '+ ' . Price::getPriceWithTax($creditHistory->amount) : '') . '</td>'
. '</tr>';
}
} else {
@@ -1092,17 +1091,17 @@ class OrderController extends BackendController
/**
* Effectue le paiement/remboursement d'une commande.
*/
public function actionAjaxPayment(int $idOrder, string $type, float $amount): array
public function actionAjaxPayment(int $idOrder, string $type, string $meanPayment): array
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$orderManager = $this->getOrderManager();
$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();
$order = $orderManager->findOneOrderById($idOrder);
$orderManager->initOrder($order);

if ($order) {
$creditHistoryManager->payOrRefundOrder($type, $order, $this->getUserCurrent());
$paymentManager->payOrRefundOrder($type, $order, $meanPayment, $this->getUserCurrent());
}

return ['success'];

+ 2
- 5
backend/controllers/UserController.php Просмотреть файл

@@ -40,21 +40,18 @@ namespace backend\controllers;

use backend\models\CreditForm;
use common\helpers\GlobalParam;
use common\helpers\Mailjet;
use backend\models\MailForm;
use common\helpers\Password;
use common\logic\Order\Order\Model\OrderSearch;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\UserPointSale\Model\UserPointSale;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\Payment\Model\Payment;
use common\logic\User\User\Model\User;
use common\logic\User\User\Model\UserSearch;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserUserGroup\Model\UserUserGroup;
use Faker\Provider\HtmlLorem;
use yii\base\UserException;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use \Yii;
use yii\helpers\Html;
use yii\web\NotFoundHttpException;
@@ -405,7 +402,7 @@ class UserController extends BackendController
$creditForm = new CreditForm;
}

$history = CreditHistory::find()
$history = Payment::find()
->with(['order', 'userAction'])
->where([
'id_user' => $user->id,

+ 3
- 10
backend/models/CreditForm.php Просмотреть файл

@@ -39,15 +39,9 @@ termes.
namespace backend\models;

use common\helpers\GlobalParam;
use common\helpers\Mailjet;
use common\logic\Producer\Producer\Wrapper\ProducerManager;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\CreditHistory\Wrapper\CreditHistoryManager;
use common\logic\User\User\Model\User;
use common\logic\Payment\Wrapper\PaymentManager;
use common\logic\User\User\Wrapper\UserManager;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserProducer\Wrapper\UserProducerManager;
use Yii;
use yii\base\Model;

/**
@@ -105,12 +99,11 @@ class CreditForm extends Model
{
$userManager = UserManager::getInstance();
$userProducerManager = UserProducerManager::getInstance();
$creditHistoryManager = CreditHistoryManager::getInstance();
$producerManager = ProducerManager::getInstance();
$paymentManager = PaymentManager::getInstance();

if ($this->validate()) {
$user = $userManager->findOneUserById($this->id_user);
$creditHistoryManager->creditOrDebitUser($this->type, $user, $this->amount, $this->mean_payment, $userManager->getCurrent());
$paymentManager->creditOrDebitUser($this->type, $user, $this->amount, $this->mean_payment, $userManager->getCurrent());
// on prévient l'utilisateur que son compte vient d'être crédité
if($this->send_mail) {

+ 28
- 11
backend/views/distribution/index.php Просмотреть файл

@@ -322,7 +322,7 @@ $this->setPageTitle('Distributions') ;
<th class="column-user">Utilisateur</th>
<th class="column-point-sale" v-if="idActivePointSale == 0">Point de vente</th>
<th class="column-amount">Montant</th>
<th class="column-state-payment">Crédit</th>
<th class="column-state-payment">Paiement / crédit</th>
<th class="column-payment"></th>
<th class="column-tiller" v-if="producer && producer.tiller">Tiller</th>
<th class="column-actions"></th>
@@ -377,9 +377,28 @@ $this->setPageTitle('Distributions') ;
</td>
<td class="column-state-payment">
<order-state-payment :order="order" :producer="producer"></order-state-payment>

<template v-if="order.isCreditAutoPayment">
({{ order.user.credit.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }})
<span class="glyphicon glyphicon-time" title="Paiement automatique la veille de la distribution" v-if="(order.amount_paid == 0 || order.amount_paid < order.amount)"></span>
</template>


</td>
<td class="column-payment" v-if="producer && producer.credit">
<div class="btn-group" v-if="order.user && !order.date_delete">

<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Paiement <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="money">Payer en espèce</a></li>
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="cheque">Payer par chèque</a></li>
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="transfer">Payer par virement</a></li>
<li><a href="javascript:void(0);" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" data-mean-payment="credit-card">Payer par carte bancaire</a></li>
<li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li>
</ul>

<!--<div class="btn-group" v-if="order.user && !order.date_delete">
<button class="btn btn-xs btn-default" v-if="order.amount_paid == order.amount" @click="orderPaymentClick" :data-id-order="order.id" data-type="refund" :data-amount="order.amount">
<span class="glyphicon glyphicon-euro"></span> Recréditer
</button>
@@ -400,7 +419,7 @@ $this->setPageTitle('Distributions') ;
<ul class="dropdown-menu">
<li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li>
</ul>
</div>
</div>-->
</td>
<td v-if="producer && producer.tiller" class="tiller column-tiller">
<input v-if="order.tiller_synchronization == true" type="checkbox" checked="checked" :id="'checkbox-tiller-synchronization-'+order.id" :data-id-order="order.id" @change="changeSynchroTiller" />
@@ -581,14 +600,12 @@ $this->setPageTitle('Distributions') ;
</div>

<script type="text/x-template" id="order-state-payment">
<div class="input-group">
<span class="label label-success input-group-addon" v-if="order.amount_paid == order.amount">débité</span>
<span class="label label-default input-group-addon" v-else-if="order.amount_paid == 0">non débité</span>
<span class="label label-default input-group-addon" v-else-if="order.amount_paid > order.amount">surplus</span>
<span class="label label-warning input-group-addon" v-else-if="order.amount_paid < order.amount">reste à débiter</span>

<span class="glyphicon glyphicon-time" title="Paiement automatique" v-if="order.auto_payment && producer && producer.credit && (order.amount_paid == 0 || order.amount_paid < order.amount)"></span>
</div>
<span class="label label-success" v-if="order.amount_paid == order.amount">&nbsp;</span>
<span class="label label-default" v-else-if="order.amount_paid == 0">&nbsp;</span>
<!--<span class="label label-success input-group-addon" v-if="order.amount_paid == order.amount">débité</span>
<span class="label label-default input-group-addon" v-else-if="order.amount_paid == 0">non débité</span>
<span class="label label-default input-group-addon" v-else-if="order.amount_paid > order.amount">surplus</span>
<span class="label label-warning input-group-addon" v-else-if="order.amount_paid < order.amount">reste à débiter</span>-->
</script>

<!-- template for the order-form component -->

+ 12
- 12
backend/views/user/credit.php Просмотреть файл

@@ -39,10 +39,10 @@ termes.
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\helpers\GlobalParam;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\Payment\Model\Payment;
use common\helpers\MeanPayment;

$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();
$producerManager = $this->getProducerManager();
$userManager = $this->getUserManager();

@@ -89,8 +89,8 @@ $this->addBreadcrumb('Créditer') ;
<div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($creditForm, 'type')->dropDownList([
CreditHistory::TYPE_CREDIT => 'Crédit',
CreditHistory::TYPE_DEBIT => 'Débit',
Payment::TYPE_CREDIT => 'Crédit',
Payment::TYPE_DEBIT => 'Débit',
]) ?>
<?= $form->field($creditForm, 'amount')->textInput() ?>
<?= $form->field($creditForm, 'mean_payment')->dropDownList([
@@ -130,21 +130,21 @@ $this->addBreadcrumb('Créditer') ;
<?php foreach($history as $creditHistory): ?>

<tr>
<td><?= $creditHistoryManager->getDate($creditHistory, true) ; ?></td>
<td><?= Html::encode($creditHistoryManager->getStrUserAction($creditHistory)); ?></td>
<td><?= $creditHistoryManager->getStrWording($creditHistory); ?></td>
<td><?= $paymentManager->getDate($creditHistory, true) ; ?></td>
<td><?= Html::encode($paymentManager->getStrUserAction($creditHistory)); ?></td>
<td><?= $paymentManager->getStrWording($creditHistory); ?></td>
<td>
<?php if($creditHistoryManager->isTypeDebit($creditHistory)): ?>
- <?= $creditHistoryManager->getAmount($creditHistory, true); ?>
<?php if($paymentManager->isTypeDebit($creditHistory)): ?>
- <?= $paymentManager->getAmount($creditHistory, true); ?>
<?php endif; ?>
</td>
<td>
<?php if($creditHistoryManager->isTypeCredit($creditHistory)): ?>
+ <?= $creditHistoryManager->getAmount($creditHistory, true); ?>
<?php if($paymentManager->isTypeCredit($creditHistory)): ?>
+ <?= $paymentManager->getAmount($creditHistory, true); ?>
<?php endif; ?>
</td>
<td>
<?= $creditHistoryManager->getStrMeanPayment($creditHistory) ?>
<?= $paymentManager->getStrMeanPayment($creditHistory) ?>
</td>
<td>
<?php if(strlen($creditHistory->getComment())): ?>

+ 34
- 30
backend/web/css/screen.css Просмотреть файл

@@ -2310,38 +2310,42 @@ termes.
.distribution-index #orders table .state-payment-mobile {
display: none;
}
/* line 320, ../sass/distribution/_index.scss */
/* line 319, ../sass/distribution/_index.scss */
.distribution-index #orders table td.column-payment {
position: relative;
}
/* line 322, ../sass/distribution/_index.scss */
.distribution-index #orders table td.column-payment div.btn-group {
width: 125px;
}
/* line 326, ../sass/distribution/_index.scss */
/* line 328, ../sass/distribution/_index.scss */
.distribution-index #orders table tr.view ul {
list-style-type: none;
margin-left: 0px;
padding-left: 15px;
}
/* line 336, ../sass/distribution/_index.scss */
/* line 338, ../sass/distribution/_index.scss */
.distribution-index #orders table tr.view .comment {
margin-top: 20px;
}
/* line 340, ../sass/distribution/_index.scss */
/* line 342, ../sass/distribution/_index.scss */
.distribution-index #orders table tr.view .delivery {
margin-top: 20px;
}
/* line 349, ../sass/distribution/_index.scss */
/* line 351, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .modal-container {
width: 100%;
padding: 0px;
}
/* line 353, ../sass/distribution/_index.scss */
/* line 355, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .modal-container .modal-body {
padding-right: 15px;
}
/* line 356, ../sass/distribution/_index.scss */
/* line 358, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .modal-container .modal-body table {
margin-bottom: 150px;
}
/* line 361, ../sass/distribution/_index.scss */
/* line 363, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .modal-container .modal-footer {
border-top-color: #f4f4f4;
position: fixed;
@@ -2353,64 +2357,64 @@ termes.
text-align: center;
border-top: solid 1px #e0e0e0;
}
/* line 373, ../sass/distribution/_index.scss */
/* line 375, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .modal-container .modal-footer .actions-form button {
float: none;
}
/* line 377, ../sass/distribution/_index.scss */
/* line 379, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .modal-container .modal-footer .actions-form div.right {
float: right;
}
/* line 384, ../sass/distribution/_index.scss */
/* line 386, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .btn-credit {
float: right;
}
/* line 390, ../sass/distribution/_index.scss */
/* line 392, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products .product-ordered td {
background-color: #e9e9e9;
}
/* line 394, ../sass/distribution/_index.scss */
/* line 396, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products .product-ordered input.input-quantity {
font-size: 16px;
font-weight: bold;
}
/* line 400, ../sass/distribution/_index.scss */
/* line 402, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.price {
width: 150px;
}
/* line 403, ../sass/distribution/_index.scss */
/* line 405, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.price input {
text-align: center;
}
/* line 407, ../sass/distribution/_index.scss */
/* line 409, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.price .input-group-addon {
background-color: #eee;
}
/* line 411, ../sass/distribution/_index.scss */
/* line 413, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.price .invoice-price {
margin-top: 8px;
}
/* line 413, ../sass/distribution/_index.scss */
/* line 415, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.price .invoice-price .label-invoice-price {
font-size: 11px;
font-weight: bold;
color: gray;
}
/* line 421, ../sass/distribution/_index.scss */
/* line 423, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity {
width: 165px;
}
/* line 424, ../sass/distribution/_index.scss */
/* line 426, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity input {
text-align: center;
color: black;
}
/* line 429, ../sass/distribution/_index.scss */
/* line 431, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity .form-control {
border-right: 0px none;
padding-right: 4px;
}
/* line 434, ../sass/distribution/_index.scss */
/* line 436, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity .input-group-addon {
padding: 5px;
padding-left: 0px;
@@ -2418,35 +2422,35 @@ termes.
border-left: 0px none;
border-right: 0px none;
}
/* line 443, ../sass/distribution/_index.scss */
/* line 445, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity-remaining {
text-align: right;
}
/* line 446, ../sass/distribution/_index.scss */
/* line 448, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity-remaining.quantity-remaining, .distribution-index .modal-form-order table.table-products td.quantity-remaining.infinite {
color: #00A65A;
}
/* line 450, ../sass/distribution/_index.scss */
/* line 452, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity-remaining.negative {
color: #DD4B39;
}
/* line 454, ../sass/distribution/_index.scss */
/* line 456, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity-remaining.infinite, .distribution-index .modal-form-order table.table-products td.quantity-remaining.empty {
font-size: 18px;
}
/* line 461, ../sass/distribution/_index.scss */
/* line 463, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order .actions-form button {
margin-left: 15px;
}
/* line 469, ../sass/distribution/_index.scss */
/* line 471, ../sass/distribution/_index.scss */
.distribution-index .modal-payment .info-box .info-box-icon {
width: 50px;
}
/* line 472, ../sass/distribution/_index.scss */
/* line 474, ../sass/distribution/_index.scss */
.distribution-index .modal-payment .info-box .info-box-icon i {
font-size: 30px;
}
/* line 477, ../sass/distribution/_index.scss */
/* line 479, ../sass/distribution/_index.scss */
.distribution-index .modal-payment .info-box .info-box-content {
margin-left: 50px;
}

+ 2
- 1
backend/web/js/vuejs/distribution-index.js Просмотреть файл

@@ -509,7 +509,8 @@ var app = new Vue({
params: {
idOrder: idOrder,
type: event.currentTarget.getAttribute('data-type'),
amount: event.currentTarget.getAttribute('data-amount')
meanPayment: event.currentTarget.getAttribute('data-mean-payment')
//amount: event.currentTarget.getAttribute('data-amount')
}
})
.then(function (response) {

+ 2
- 0
backend/web/sass/distribution/_index.scss Просмотреть файл

@@ -317,6 +317,8 @@ termes.
}

td.column-payment {
position: relative;

div.btn-group {
width: 125px;
}

+ 1
- 1
common/components/BusinessLogic.php Просмотреть файл

@@ -15,7 +15,7 @@ class BusinessLogic
$this->getTaxRateContainer(),
$this->getUserUserGroupContainer(),
$this->getUserGroupContainer(),
$this->getCreditHistoryContainer(),
$this->getPaymentContainer(),
$this->getProducerPriceRangeContainer(),
$this->getUserProducerContainer(),
$this->getUserPointSaleContainer(),

+ 6
- 6
common/components/BusinessLogicTrait.php Просмотреть файл

@@ -23,6 +23,8 @@ use common\logic\Order\Order\Wrapper\OrderContainer;
use common\logic\Order\Order\Wrapper\OrderManager;
use common\logic\Order\ProductOrder\Wrapper\ProductOrderContainer;
use common\logic\Order\ProductOrder\Wrapper\ProductOrderManager;
use common\logic\Payment\Wrapper\PaymentContainer;
use common\logic\Payment\Wrapper\PaymentManager;
use common\logic\PointSale\PointSale\Wrapper\PointSaleContainer;
use common\logic\PointSale\PointSale\Wrapper\PointSaleManager;
use common\logic\PointSale\UserPointSale\Wrapper\UserPointSaleContainer;
@@ -49,8 +51,6 @@ use common\logic\Ticket\TicketMessage\Wrapper\TicketMessageContainer;
use common\logic\Ticket\TicketMessage\Wrapper\TicketMessageManager;
use common\logic\Ticket\TicketUser\Wrapper\TicketUserContainer;
use common\logic\Ticket\TicketUser\Wrapper\TicketUserManager;
use common\logic\User\CreditHistory\Wrapper\CreditHistoryContainer;
use common\logic\User\CreditHistory\Wrapper\CreditHistoryManager;
use common\logic\User\User\Wrapper\UserContainer;
use common\logic\User\User\Wrapper\UserManager;
use common\logic\User\UserGroup\Wrapper\UserGroupContainer;
@@ -172,9 +172,9 @@ trait BusinessLogicTrait
return SubscriptionManager::getInstance();
}

public function getCreditHistoryManager(): CreditHistoryManager
public function getPaymentManager(): PaymentManager
{
return CreditHistoryManager::getInstance();
return PaymentManager::getInstance();
}

public function getUserManager(): UserManager
@@ -227,9 +227,9 @@ trait BusinessLogicTrait
return UserProducerContainer::getInstance();
}

public function getCreditHistoryContainer(): CreditHistoryContainer
public function getPaymentContainer(): PaymentContainer
{
return CreditHistoryContainer::getInstance();
return PaymentContainer::getInstance();
}

public function getDocumentContainer(): DocumentContainer

+ 3
- 3
common/config/main.php Просмотреть файл

@@ -41,7 +41,7 @@ use common\components\DolibarrApi;
use common\logic\Distribution\Distribution\Model\Distribution;
use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Ticket\Ticket\Model\Ticket;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\Payment\Model\Payment;

$serverName = isset($_SERVER['SERVER_NAME']) ?? '';

@@ -159,8 +159,8 @@ return [
'class' => \justcoded\yii2\eventlistener\components\EventListener::class,
'listeners' => [],
'observers' => [
CreditHistory::class => [
common\logic\User\UserProducer\Event\CreditHistoryObserver::class
Payment::class => [
common\logic\User\UserProducer\Event\PaymentObserver::class
],
Distribution::class => [
common\logic\Subscription\Subscription\Event\DistributionObserver::class

+ 3
- 3
common/logic/Order/Order/Model/Order.php Просмотреть файл

@@ -43,9 +43,9 @@ use common\logic\Document\DeliveryNote\Model\DeliveryNote;
use common\logic\Document\Invoice\Model\Invoice;
use common\logic\Document\Quotation\Model\Quotation;
use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\Payment\Model\Payment;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\User\Model\User;
use common\components\ActiveRecordCommon;

@@ -183,9 +183,9 @@ class Order extends ActiveRecordCommon
$this->populateFieldObject('id_point_sale', 'point_sale', $pointSale);
}

public function getCreditHistory()
public function getPayment()
{
return $this->hasMany(CreditHistory::class, ['id_order' => 'id']);
return $this->hasMany(Payment::class, ['id_order' => 'id']);
}

public function getSubscription()

+ 2
- 2
common/logic/Order/Order/Repository/OrderRepository.php Просмотреть файл

@@ -55,8 +55,8 @@ class OrderRepository extends AbstractRepository
self::WITH => [
'productOrder',
'productOrder.product',
'creditHistory',
'creditHistory.userAction',
'payment',
'payment.userAction',
'pointSale',
],
self::JOIN_WITH => [

+ 17
- 24
common/logic/Order/Order/Service/OrderBuilder.php Просмотреть файл

@@ -19,6 +19,9 @@ use common\logic\Order\Order\Repository\OrderRepository;
use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\Order\ProductOrder\Service\ProductOrderBuilder;
use common\logic\Order\ProductOrder\Service\ProductOrderSolver;
use common\logic\Payment\Model\Payment;
use common\logic\Payment\Repository\PaymentRepository;
use common\logic\Payment\Service\PaymentBuilder;
use common\logic\PointSale\PointSale\Model\PointSale;
use common\logic\PointSale\PointSale\Service\PointSaleBuilder;
use common\logic\PointSale\PointSale\Repository\PointSaleRepository;
@@ -30,9 +33,6 @@ use common\logic\Subscription\Subscription\Model\Subscription;
use common\logic\Subscription\Subscription\Service\SubscriptionBuilder;
use common\logic\Subscription\Subscription\Repository\SubscriptionRepository;
use common\logic\Subscription\Subscription\Service\SubscriptionSolver;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\CreditHistory\Service\CreditHistoryBuilder;
use common\logic\User\CreditHistory\Repository\CreditHistoryRepository;
use common\logic\User\User\Repository\UserRepository;
use common\logic\User\User\Service\UserSolver;
use common\logic\User\UserProducer\Repository\UserProducerRepository;
@@ -42,9 +42,9 @@ class OrderBuilder extends AbstractBuilder
{
protected UserSolver $userSolver;
protected OrderSolver $orderSolver;
protected CreditHistoryRepository $creditHistoryRepository;
protected PaymentRepository $paymentRepository;
protected ProducerRepository $producerRepository;
protected CreditHistoryBuilder $creditHistoryBuilder;
protected PaymentBuilder $paymentBuilder;
protected ProductOrderBuilder $productOrderBuilder;
protected OrderRepository $orderRepository;
protected DistributionRepository $distributionRepository;
@@ -65,9 +65,9 @@ class OrderBuilder extends AbstractBuilder
{
$this->userSolver = $this->loadService(UserSolver::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
$this->creditHistoryRepository = $this->loadService(CreditHistoryRepository::class);
$this->paymentRepository = $this->loadService(PaymentRepository::class);
$this->producerRepository = $this->loadService(ProducerRepository::class);
$this->creditHistoryBuilder = $this->loadService(CreditHistoryBuilder::class);
$this->paymentBuilder = $this->loadService(PaymentBuilder::class);
$this->productOrderBuilder = $this->loadService(ProductOrderBuilder::class);
$this->orderRepository = $this->loadService(OrderRepository::class);
$this->distributionRepository = $this->loadService(DistributionRepository::class);
@@ -213,8 +213,8 @@ class OrderBuilder extends AbstractBuilder
// remboursement de la commande
if ($theOrder->id_user && $this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID) && $configCredit) {

$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_REFUND,
$this->paymentBuilder->createPayment(
Payment::TYPE_REFUND,
$this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID),
$theOrder->distribution->producer,
$theOrder->user,
@@ -413,22 +413,15 @@ class OrderBuilder extends AbstractBuilder
*/
public function initOrderPaidAmount(Order $order): void
{
// Attention : $order->creditHistory pas à jour si un paiement vient d'avoir lieu
/*if (isset($order->creditHistory)) {
$history = $order->creditHistory;
} else {
$history = $this->creditHistoryRepository->getByOrder($order);
}*/

$history = $this->creditHistoryRepository->getByOrder($order);
$history = $this->paymentRepository->getByOrder($order);

$order->paid_amount = 0;

if (count($history)) {
foreach ($history as $ch) {
if ($ch->type == CreditHistory::TYPE_PAYMENT) {
if ($ch->type == Payment::TYPE_PAYMENT) {
$order->paid_amount += $ch->amount;
} elseif ($ch->type == CreditHistory::TYPE_REFUND) {
} elseif ($ch->type == Payment::TYPE_REFUND) {
$order->paid_amount -= $ch->amount;
}
}
@@ -443,8 +436,8 @@ class OrderBuilder extends AbstractBuilder
$amountPaid = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_PAID);

if ($amountPaid >= 0.01) {
$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_REFUND,
$this->paymentBuilder->createPayment(
Payment::TYPE_REFUND,
$amountPaid,
GlobalParam::getCurrentProducer(),
$order->user,
@@ -483,14 +476,14 @@ class OrderBuilder extends AbstractBuilder
if ($paymentStatus == Order::PAYMENT_PAID) {
return;
} elseif ($paymentStatus == Order::PAYMENT_SURPLUS) {
$type = CreditHistory::TYPE_REFUND;
$type = Payment::TYPE_REFUND;
$amount = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_SURPLUS);
} elseif ($paymentStatus == Order::PAYMENT_UNPAID) {
$type = CreditHistory::TYPE_PAYMENT;
$type = Payment::TYPE_PAYMENT;
$amount = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_REMAINING);
}

$this->creditHistoryBuilder->createCreditHistory(
$this->paymentBuilder->createPayment(
$type,
$amount,
GlobalParam::getCurrentProducer(),

+ 10
- 13
common/logic/Order/Order/Service/OrderSolver.php Просмотреть файл

@@ -7,12 +7,11 @@ use common\logic\AbstractService;
use common\logic\Document\Document\Model\Document;
use common\logic\Document\Document\Service\DocumentSolver;
use common\logic\Order\Order\Model\Order;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Payment\Model\Payment;
use common\logic\Payment\Service\PaymentSolver;
use common\logic\Producer\Producer\Service\ProducerSolver;
use common\logic\Product\Product\Model\Product;
use common\logic\SolverInterface;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\CreditHistory\Service\CreditHistorySolver;
use common\logic\User\User\Model\User;
use common\logic\User\User\Service\UserSolver;
use yii\helpers\Html;
@@ -21,14 +20,14 @@ class OrderSolver extends AbstractService implements SolverInterface
{
protected UserSolver $userSolver;
protected DocumentSolver $documentSolver;
protected CreditHistorySolver $creditHistorySolver;
protected PaymentSolver $paymentSolver;
protected ProducerSolver $producerSolver;

public function loadDependencies(): void
{
$this->documentSolver = $this->loadService(DocumentSolver::class);
$this->userSolver = $this->loadService(UserSolver::class);
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class);
$this->paymentSolver = $this->loadService(PaymentSolver::class);
$this->producerSolver = $this->loadService(ProducerSolver::class);
}

@@ -114,7 +113,6 @@ class OrderSolver extends AbstractService implements SolverInterface
/**
* Retourne une chaine de caractère décrivant l'utilisateur lié à la commande.
*/
// getStrUser
public function getOrderUsername(Order $order): string
{
if (isset($order->user)) {
@@ -177,7 +175,6 @@ class OrderSolver extends AbstractService implements SolverInterface
/**
* Retourne un bloc html présentant une date.
*/
// getBlockDate
public function getDateAsHtml(Order $order): string
{
return '<div class="block-date">
@@ -427,26 +424,26 @@ class OrderSolver extends AbstractService implements SolverInterface
* (libellé, montant, client, action) au format HTML.
*
*/
public function getCreditHistoryComment(CreditHistory $creditHistory): string
public function getPaymentComment(Payment $payment): string
{
$str = '';
if (strlen($creditHistory->getComment())) {
if (strlen($payment->getComment())) {
$str .= '<br />';
}

$str .= $this->creditHistorySolver->getStrWording($creditHistory);
$str .= $this->paymentSolver->getStrWording($payment);

$order = $creditHistory->getOrderObject();
$order = $payment->getOrderObject();
if ($order) {
$str .= '<br />Montant de la commande : ' . $this->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true);
}

$user = $creditHistory->getUserObject();
$user = $payment->getUserObject();
if ($user) {
$str .= '<br />Client : ' . Html::encode($user->getName() . ' ' . $user->getLastname());
}

$userAction = $creditHistory->getUserActionObject();
$userAction = $payment->getUserActionObject();
if ($userAction) {
$str .= '<br />Action : ' . Html::encode($userAction->getName() . ' ' . $userAction->getLastname());
}

common/logic/User/CreditHistory/Model/CreditHistorySearch.php → common/logic/Payment/Model/CreditHistorySearch.php Просмотреть файл

@@ -36,13 +36,14 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

namespace common\logic\User\CreditHistory\Model;
namespace common\logic\Payment\Model;

use common\helpers\GlobalParam;
use common\logic\User\CreditHistory\Repository\CreditHistoryRepository;
use common\helpers\MeanPayment;
use common\logic\Payment\Repository\PaymentRepository;
use yii\data\ActiveDataProvider;

class CreditHistorySearch extends CreditHistory
class CreditHistorySearch extends Payment
{
public function rules(): array
@@ -57,13 +58,16 @@ class CreditHistorySearch extends CreditHistory
public function search($params)
{
$creditHistoryRepository = CreditHistoryRepository::getInstance();
$optionsSearch = $creditHistoryRepository->getDefaultOptionsSearch() ;
$paymentRepository = PaymentRepository::getInstance();
$optionsSearch = $paymentRepository->getDefaultOptionsSearch() ;
$query = CreditHistory::find()
$query = Payment::find()
->with($optionsSearch['with'])
->innerJoinWith($optionsSearch['join_with'], true)
->where(['credit_history.id_producer' => GlobalParam::getCurrentProducerId()])
->where([
'payment.id_producer' => GlobalParam::getCurrentProducerId(),
'payment.mean_payment' => MeanPayment::CREDIT
])
->orderBy('id DESC')
;
@@ -82,7 +86,7 @@ class CreditHistorySearch extends CreditHistory
if(isset($this->id_user) && is_numeric($this->id_user)) {
$query->andWhere([
'credit_history.id_user' => $this->id_user
'payment.id_user' => $this->id_user
]) ;
}


common/logic/User/CreditHistory/Model/CreditHistory.php → common/logic/Payment/Model/Payment.php Просмотреть файл

@@ -36,16 +36,16 @@
* termes.
*/

namespace common\logic\User\CreditHistory\Model;
namespace common\logic\Payment\Model;

use common\components\ActiveRecordCommon;
use common\logic\Document\Invoice\Model\Invoice;
use common\logic\Order\Order\Model\Order;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\User\Model\User;
use common\logic\User\UserProducer\Event\UserProducerEventSubscriber;
use yii\db\ActiveQuery;

class CreditHistory extends ActiveRecordCommon
class Payment extends ActiveRecordCommon
{
const TYPE_INITIAL_CREDIT = 'initial-credit';
const TYPE_CREDIT = 'credit';
@@ -58,7 +58,7 @@ class CreditHistory extends ActiveRecordCommon
*/
public static function tableName(): string
{
return 'credit_history';
return 'payment';
}

/**
@@ -68,7 +68,7 @@ class CreditHistory extends ActiveRecordCommon
{
return [
[['amount'], 'required'],
[['id_user', 'id_user_action', 'id_order', 'id_producer'], 'integer'],
[['id_user', 'id_user_action', 'id_order', 'id_invoice', 'id_producer'], 'integer'],
[['date'], 'safe'],
[['amount'], 'double'],
[['type', 'mean_payment'], 'string', 'max' => 255],
@@ -86,6 +86,7 @@ class CreditHistory extends ActiveRecordCommon
'id_user' => 'Utilisateur',
'id_user_action' => 'Utilisateur',
'id_order' => 'Commande',
'id_invoice' => 'Facture',
'date' => 'Date',
'amount' => 'Montant',
'type' => 'Type',
@@ -154,6 +155,21 @@ class CreditHistory extends ActiveRecordCommon
return $this->order;
}

public function getInvoice(): ActiveQuery
{
return $this->hasOne(Invoice::class, ['id' => 'id_invoice']);
}

public function populateInvoice(Invoice $invoice): void
{
$this->populateFieldObject('id_invoice', 'invoice', $invoice);
}

public function getInvoiceObject(): ?Invoice
{
return $this->invoice;
}

/*
* Getters / setters
*/

common/logic/User/CreditHistory/Repository/CreditHistoryRepository.php → common/logic/Payment/Repository/PaymentRepository.php Просмотреть файл

@@ -1,18 +1,18 @@
<?php

namespace common\logic\User\CreditHistory\Repository;
namespace common\logic\Payment\Repository;

use common\logic\AbstractRepository;
use common\logic\Order\Order\Model\Order;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\Payment\Model\Payment;

class CreditHistoryRepository extends AbstractRepository
class PaymentRepository extends AbstractRepository
{
protected CreditHistoryRepositoryQuery $query;
protected PaymentRepositoryQuery $query;

public function loadDependencies(): void
{
$this->loadQuery(CreditHistoryRepositoryQuery::class);
$this->loadQuery(PaymentRepositoryQuery::class);
}

public function getDefaultOptionsSearch(): array
@@ -20,8 +20,8 @@ class CreditHistoryRepository extends AbstractRepository
return [
self::WITH => [],
self::JOIN_WITH => [],
self::ORDER_BY => CreditHistory::tableName() . '.date ASc',
self::ATTRIBUTE_ID_PRODUCER => CreditHistory::tableName() . '.id_producer'
self::ORDER_BY => Payment::tableName() . '.date ASc',
self::ATTRIBUTE_ID_PRODUCER => Payment::tableName() . '.id_producer'
];
}


+ 23
- 0
common/logic/Payment/Repository/PaymentRepositoryQuery.php Просмотреть файл

@@ -0,0 +1,23 @@
<?php

namespace common\logic\Payment\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Order\Order\Model\Order;
use common\logic\Payment\Service\PaymentDefinition;

class PaymentRepositoryQuery extends AbstractRepositoryQuery
{
protected PaymentDefinition $definition;

public function loadDependencies(): void
{
$this->loadDefinition(PaymentDefinition::class);
}

public function filterByOrder(Order $order): self
{
$this->andWhere(['id_order' => $order->id]);
return $this;
}
}

+ 72
- 0
common/logic/Payment/Service/PaymentBuilder.php Просмотреть файл

@@ -0,0 +1,72 @@
<?php

namespace common\logic\Payment\Service;

use common\logic\AbstractBuilder;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Payment\Model\Payment;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\User\Model\User;

class PaymentBuilder extends AbstractBuilder
{
protected PaymentSolver $paymentSolver;
protected OrderSolver $orderSolver;

public function loadDependencies(): void
{
$this->paymentSolver = $this->loadService(PaymentSolver::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
}

public function instanciatePayment(
string $type,
float $amount,
Producer $producer,
User $user,
User $userAction,
string $meanPayment = null,
Order $order = null
): Payment
{
$payment = new Payment;

$payment->type = $type;
$payment->amount = round($amount, 2);
$payment->populateProducer($producer);
$payment->populateUser($user);
$payment->populateUserAction($userAction);

if($order) {
$payment->populateOrder($order);
}

if($meanPayment) {
$payment->mean_payment = $meanPayment;
}

return $payment;
}

public function createPayment(
string $type,
float $amount,
Producer $producer,
User $user,
User $userAction,
string $meanPayment = null,
Order $order = null
): ?Payment
{
if ($amount > -0.01 && $amount < 0.01) {
return null;
}

$payment = $this->instanciatePayment($type, $amount, $producer, $user, $userAction, $meanPayment, $order);
$payment->setComment($payment->getComment() . $this->orderSolver->getPaymentComment($payment));
$this->create($payment);

return $payment;
}
}

+ 14
- 0
common/logic/Payment/Service/PaymentDefinition.php Просмотреть файл

@@ -0,0 +1,14 @@
<?php

namespace common\logic\Payment\Service;

use common\logic\AbstractDefinition;
use common\logic\Payment\Model\Payment;

class PaymentDefinition extends AbstractDefinition
{
public function getEntityFqcn(): string
{
return Payment::class;
}
}

+ 98
- 0
common/logic/Payment/Service/PaymentSolver.php Просмотреть файл

@@ -0,0 +1,98 @@
<?php

namespace common\logic\Payment\Service;

use common\helpers\MeanPayment;
use common\logic\AbstractService;
use common\logic\Payment\Model\Payment;
use common\logic\SolverInterface;

class PaymentSolver extends AbstractService implements SolverInterface
{
public function isTypeDebit(Payment $payment): bool
{
return in_array($payment->getType(), [
Payment::TYPE_DEBIT,
Payment::TYPE_PAYMENT,
]);
}

public function isTypeCredit(Payment $payment): bool
{
return in_array($payment->getType(), [
Payment::TYPE_CREDIT,
Payment::TYPE_INITIAL_CREDIT,
Payment::TYPE_REFUND
]);
}

public function getAmount(Payment $payment, bool $format = false): string
{
if ($format) {
return number_format($payment->getAmount(), 2) . '&nbsp;€';
} else {
return $payment->getAmount();
}
}

/**
* Retourne le libellé du CreditHistory informant de son type et
* éventuellement de la date de sa commande associée.
*
*/
public function getStrWording(Payment $payment): string
{
$str = '';
$type = $payment->getType();

if (Payment::TYPE_INITIAL_CREDIT == $type) {
$str = 'Crédit initial';
} elseif (Payment::TYPE_CREDIT == $type) {
$str = 'Crédit';
} elseif (Payment::TYPE_PAYMENT == $type) {
$str = 'Débit';
} elseif (Payment::TYPE_REFUND == $type) {
$str = 'Recrédit';
} elseif (Payment::TYPE_DEBIT == $type) {
$str = 'Débit';
}

if (Payment::TYPE_PAYMENT == $type || Payment::TYPE_REFUND == $type) {
$order = $payment->getOrderObject();
if ($order && $order->distribution) {
$str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->distribution->date));
} else {
$str .= '<br />Commande supprimée';
}
}

return $str;
}

public function getDate(Payment $payment, bool $format = false): string
{
$date = $payment->getDate();

if ($format) {
return date('d/m/Y à H:i:s', strtotime($date));
} else {
return $date;
}
}

public function getStrMeanPayment(Payment $payment): string
{
return MeanPayment::getStrBy($payment->getMeanPayment());
}

public function getStrUserAction(Payment $payment): string
{
$userAction = $payment->getUserActionObject();

if ($userAction) {
return $userAction->getName() . ' ' . $userAction->getlastname();
} else {
return 'Système';
}
}
}

common/logic/User/CreditHistory/Service/CreditUtils.php → common/logic/Payment/Service/PaymentUtils.php Просмотреть файл

@@ -1,28 +1,28 @@
<?php

namespace common\logic\User\CreditHistory\Service;
namespace common\logic\Payment\Service;

use common\helpers\MeanPayment;
use common\logic\AbstractService;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Payment\Model\Payment;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\User\Model\User;
use common\logic\User\User\Repository\UserRepository;
use common\logic\UtilsInterface;
use yii\base\ErrorException;

class CreditUtils extends AbstractService implements UtilsInterface
class PaymentUtils extends AbstractService implements UtilsInterface
{
protected CreditHistoryBuilder $creditHistoryBuilder;
protected PaymentBuilder $paymentBuilder;
protected OrderSolver $orderSolver;
protected ProducerRepository $producerRepository;
protected UserRepository $userRepository;

public function loadDependencies(): void
{
$this->creditHistoryBuilder = $this->loadService(CreditHistoryBuilder::class);
$this->paymentBuilder = $this->loadService(PaymentBuilder::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
$this->producerRepository = $this->loadService(ProducerRepository::class);
$this->userRepository = $this->loadService(UserRepository::class);
@@ -30,8 +30,8 @@ class CreditUtils extends AbstractService implements UtilsInterface

public function creditUser(User $user, float $amount, string $meanPayment, User $userAction): void
{
$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_CREDIT,
$this->paymentBuilder->createPayment(
Payment::TYPE_CREDIT,
$amount,
$this->getProducerContext(),
$user,
@@ -42,8 +42,8 @@ class CreditUtils extends AbstractService implements UtilsInterface

public function debitUser(User $user, float $amount, string $meanPayment, User $userAction): void
{
$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_DEBIT,
$this->paymentBuilder->createPayment(
Payment::TYPE_DEBIT,
$amount,
$this->getProducerContext(),
$user,
@@ -54,10 +54,10 @@ class CreditUtils extends AbstractService implements UtilsInterface

public function creditOrDebitUser(string $type, User $user, float $amount, string $meanPayment, User $userAction): void
{
if($type == CreditHistory::TYPE_CREDIT) {
if($type == Payment::TYPE_CREDIT) {
$this->creditUser($user, $amount, $meanPayment, $userAction);
}
elseif($type == CreditHistory::TYPE_DEBIT) {
elseif($type == Payment::TYPE_DEBIT) {
$this->debitUser($user, $amount, $meanPayment, $userAction);
}
else {
@@ -65,7 +65,28 @@ class CreditUtils extends AbstractService implements UtilsInterface
}
}

public function payOrder(Order $order, User $userAction, bool $checkCreditLimit): void
public function payOrder(Order $order, string $meanPayment, User $userAction, bool $checkCreditLimit)
{
if($meanPayment == MeanPayment::CREDIT) {
$this->payOrderByCredit($order, $userAction, $checkCreditLimit);
}
elseif(key_exists($meanPayment, MeanPayment::getAll())) {
$this->paymentBuilder->createPayment(
Payment::TYPE_PAYMENT,
$this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_REMAINING),
$this->getProducerContext(),
$order->user,
$userAction,
$meanPayment,
$order
);
}
else {
throw new ErrorException('Moyen de paiement inconnu : '.$meanPayment);
}
}

public function payOrderByCredit(Order $order, User $userAction, bool $checkCreditLimit): void
{
$amountRemaining = $this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_REMAINING);

@@ -79,8 +100,8 @@ class CreditUtils extends AbstractService implements UtilsInterface
}

if($amountRemaining > 0) {
$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_PAYMENT,
$this->paymentBuilder->createPayment(
Payment::TYPE_PAYMENT,
$amountRemaining,
$this->getProducerContext(),
$order->user,
@@ -93,8 +114,8 @@ class CreditUtils extends AbstractService implements UtilsInterface

public function refundOrder(Order $order, User $userAction): void
{
$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_REFUND,
$this->paymentBuilder->createPayment(
Payment::TYPE_REFUND,
$this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_PAID),
$this->getProducerContext(),
$order->user,
@@ -106,8 +127,8 @@ class CreditUtils extends AbstractService implements UtilsInterface

public function refundSurplusOrder(Order $order, User $userAction): void
{
$this->creditHistoryBuilder->createCreditHistory(
CreditHistory::TYPE_REFUND,
$this->paymentBuilder->createPayment(
Payment::TYPE_REFUND,
$this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_SURPLUS),
$this->getProducerContext(),
$order->user,
@@ -117,12 +138,12 @@ class CreditUtils extends AbstractService implements UtilsInterface
);
}

public function payOrRefundOrder(string $type, Order $order, User $userAction, bool $checkCreditLimit = false): void
public function payOrRefundOrder(string $type, Order $order, string $meanPayment, User $userAction, bool $checkCreditLimit = false): void
{
if($type == CreditHistory::TYPE_PAYMENT) {
$this->payOrder($order, $userAction, $checkCreditLimit);
if($type == Payment::TYPE_PAYMENT) {
$this->payOrder($order, $meanPayment, $userAction, $checkCreditLimit);
}
elseif($type == CreditHistory::TYPE_REFUND) {
elseif($type == Payment::TYPE_REFUND) {
$this->refundOrder($order, $userAction);
}
else {

+ 49
- 0
common/logic/Payment/Wrapper/PaymentContainer.php Просмотреть файл

@@ -0,0 +1,49 @@
<?php

namespace common\logic\Payment\Wrapper;

use common\logic\AbstractContainer;
use common\logic\Payment\Repository\PaymentRepository;
use common\logic\Payment\Service\PaymentUtils;
use common\logic\Payment\Service\PaymentBuilder;
use common\logic\Payment\Service\PaymentDefinition;
use common\logic\Payment\Service\PaymentSolver;

class PaymentContainer extends AbstractContainer
{
public function getServices(): array
{
return [
PaymentDefinition::class,
PaymentSolver::class,
PaymentBuilder::class,
PaymentRepository::class,
PaymentUtils::class,
];
}

public function getDefinition(): PaymentDefinition
{
return PaymentDefinition::getInstance();
}

public function getSolver(): PaymentSolver
{
return PaymentSolver::getInstance();
}

public function getBuilder(): PaymentBuilder
{
return PaymentBuilder::getInstance();
}

public function getRepository(): PaymentRepository
{
return PaymentRepository::getInstance();
}

public function getPaymentUtils(): PaymentUtils
{
return PaymentUtils::getInstance();
}
}

+ 25
- 0
common/logic/Payment/Wrapper/PaymentManager.php Просмотреть файл

@@ -0,0 +1,25 @@
<?php

namespace common\logic\Payment\Wrapper;

use common\logic\AbstractManager;
use common\logic\Payment\Repository\PaymentRepository;
use common\logic\Payment\Service\PaymentUtils;
use common\logic\Payment\Service\PaymentBuilder;
use common\logic\Payment\Service\PaymentDefinition;
use common\logic\Payment\Service\PaymentSolver;

/**
* @mixin PaymentDefinition
* @mixin PaymentSolver
* @mixin PaymentRepository
* @mixin PaymentBuilder
* @mixin PaymentUtils
*/
class PaymentManager extends AbstractManager
{
public function getContainerFqcn(): string
{
return PaymentContainer::class;
}
}

+ 0
- 23
common/logic/User/CreditHistory/Repository/CreditHistoryRepositoryQuery.php Просмотреть файл

@@ -1,23 +0,0 @@
<?php

namespace common\logic\User\CreditHistory\Repository;

use common\logic\AbstractRepositoryQuery;
use common\logic\Order\Order\Model\Order;
use common\logic\User\CreditHistory\Service\CreditHistoryDefinition;

class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery
{
protected CreditHistoryDefinition $definition;

public function loadDependencies(): void
{
$this->loadDefinition(CreditHistoryDefinition::class);
}

public function filterByOrder(Order $order): self
{
$this->andWhere(['id_order' => $order->id]);
return $this;
}
}

+ 0
- 74
common/logic/User/CreditHistory/Service/CreditHistoryBuilder.php Просмотреть файл

@@ -1,74 +0,0 @@
<?php

namespace common\logic\User\CreditHistory\Service;

use common\logic\AbstractBuilder;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\User\Model\User;
use yii\base\Event;

class CreditHistoryBuilder extends AbstractBuilder
{
protected CreditHistorySolver $creditHistorySolver;
protected OrderSolver $orderSolver;

public function loadDependencies(): void
{
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
}

public function instanciateCreditHistory(
string $type,
float $amount,
Producer $producer,
User $user,
User $userAction,
string $meanPayment = null,
Order $order = null
): CreditHistory
{
$creditHistory = new CreditHistory;

$creditHistory->type = $type;
$creditHistory->amount = round($amount, 2);
$creditHistory->populateProducer($producer);
$creditHistory->populateUser($user);
$creditHistory->populateUserAction($userAction);

if($order) {
$creditHistory->populateOrder($order);
}

if($meanPayment) {
$creditHistory->mean_payment = $meanPayment;
}

return $creditHistory;
}

// saveCreditHistory
public function createCreditHistory(
string $type,
float $amount,
Producer $producer,
User $user,
User $userAction,
string $meanPayment = null,
Order $order = null
): ?CreditHistory
{
if ($amount > -0.01 && $amount < 0.01) {
return null;
}

$creditHistory = $this->instanciateCreditHistory($type, $amount, $producer, $user, $userAction, $meanPayment, $order);
$creditHistory->setComment($creditHistory->getComment() . $this->orderSolver->getCreditHistoryComment($creditHistory));
$this->create($creditHistory);

return $creditHistory;
}
}

+ 0
- 14
common/logic/User/CreditHistory/Service/CreditHistoryDefinition.php Просмотреть файл

@@ -1,14 +0,0 @@
<?php

namespace common\logic\User\CreditHistory\Service;

use common\logic\AbstractDefinition;
use common\logic\User\CreditHistory\Model\CreditHistory;

class CreditHistoryDefinition extends AbstractDefinition
{
public function getEntityFqcn(): string
{
return CreditHistory::class;
}
}

+ 0
- 100
common/logic/User/CreditHistory/Service/CreditHistorySolver.php Просмотреть файл

@@ -1,100 +0,0 @@
<?php

namespace common\logic\User\CreditHistory\Service;

use common\helpers\MeanPayment;
use common\logic\AbstractService;
use common\logic\SolverInterface;
use common\logic\User\CreditHistory\Model\CreditHistory;
use yii\helpers\Html;

class CreditHistorySolver extends AbstractService implements SolverInterface
{
public function isTypeDebit(CreditHistory $creditHistory): bool
{
return in_array($creditHistory->getType(), [
CreditHistory::TYPE_DEBIT,
CreditHistory::TYPE_PAYMENT,
]);
}

public function isTypeCredit(CreditHistory $creditHistory): bool
{
return in_array($creditHistory->getType(), [
CreditHistory::TYPE_CREDIT,
CreditHistory::TYPE_INITIAL_CREDIT,
CreditHistory::TYPE_REFUND
]);
}

public function getAmount(CreditHistory $creditHistory, bool $format = false): string
{
if ($format) {
return number_format($creditHistory->getAmount(), 2) . '&nbsp;€';
} else {
return $creditHistory->getAmount();
}
}

/**
* Retourne le libellé du CreditHistory informant de son type et
* éventuellement de la date de sa commande associée.
*
*/
public function getStrWording(CreditHistory $creditHistory): string
{
$str = '';
$type = $creditHistory->getType();

if (CreditHistory::TYPE_INITIAL_CREDIT == $type) {
$str = 'Crédit initial';
} elseif (CreditHistory::TYPE_CREDIT == $type) {
$str = 'Crédit';
} elseif (CreditHistory::TYPE_PAYMENT == $type) {
$str = 'Débit';
} elseif (CreditHistory::TYPE_REFUND == $type) {
$str = 'Recrédit';
} elseif (CreditHistory::TYPE_DEBIT == $type) {
$str = 'Débit';
}

if (CreditHistory::TYPE_PAYMENT == $type || CreditHistory::TYPE_REFUND == $type) {
$order = $creditHistory->getOrderObject();
if ($order && $order->distribution) {
$str .= '<br />Commande : ' . date('d/m/Y', strtotime($order->distribution->date));
} else {
$str .= '<br />Commande supprimée';
}
}

return $str;
}

public function getDate(CreditHistory $creditHistory, bool $format = false): string
{
$date = $creditHistory->getDate();

if ($format) {
return date('d/m/Y à H:i:s', strtotime($date));
} else {
return $date;
}
}

public function getStrMeanPayment(CreditHistory $creditHistory): string
{
return MeanPayment::getStrBy($creditHistory->getMeanPayment());
}

// strUserAction
public function getStrUserAction(CreditHistory $creditHistory): string
{
$userAction = $creditHistory->getUserActionObject();

if ($userAction) {
return $userAction->getName() . ' ' . $userAction->getlastname();
} else {
return 'Système';
}
}
}

+ 0
- 49
common/logic/User/CreditHistory/Wrapper/CreditHistoryContainer.php Просмотреть файл

@@ -1,49 +0,0 @@
<?php

namespace common\logic\User\CreditHistory\Wrapper;

use common\logic\AbstractContainer;
use common\logic\User\CreditHistory\Repository\CreditHistoryRepository;
use common\logic\User\CreditHistory\Service\CreditHistoryBuilder;
use common\logic\User\CreditHistory\Service\CreditHistoryDefinition;
use common\logic\User\CreditHistory\Service\CreditHistorySolver;
use common\logic\User\CreditHistory\Service\CreditUtils;

class CreditHistoryContainer extends AbstractContainer
{
public function getServices(): array
{
return [
CreditHistoryDefinition::class,
CreditHistorySolver::class,
CreditHistoryBuilder::class,
CreditHistoryRepository::class,
CreditUtils::class,
];
}

public function getDefinition(): CreditHistoryDefinition
{
return CreditHistoryDefinition::getInstance();
}

public function getSolver(): CreditHistorySolver
{
return CreditHistorySolver::getInstance();
}

public function getBuilder(): CreditHistoryBuilder
{
return CreditHistoryBuilder::getInstance();
}

public function getRepository(): CreditHistoryRepository
{
return CreditHistoryRepository::getInstance();
}

public function getCreditUtils(): CreditUtils
{
return CreditUtils::getInstance();
}
}

+ 0
- 25
common/logic/User/CreditHistory/Wrapper/CreditHistoryManager.php Просмотреть файл

@@ -1,25 +0,0 @@
<?php

namespace common\logic\User\CreditHistory\Wrapper;

use common\logic\AbstractManager;
use common\logic\User\CreditHistory\Repository\CreditHistoryRepository;
use common\logic\User\CreditHistory\Service\CreditHistoryBuilder;
use common\logic\User\CreditHistory\Service\CreditHistoryDefinition;
use common\logic\User\CreditHistory\Service\CreditHistorySolver;
use common\logic\User\CreditHistory\Service\CreditUtils;

/**
* @mixin CreditHistoryDefinition
* @mixin CreditHistorySolver
* @mixin CreditHistoryRepository
* @mixin CreditHistoryBuilder
* @mixin CreditUtils
*/
class CreditHistoryManager extends AbstractManager
{
public function getContainerFqcn(): string
{
return CreditHistoryContainer::class;
}
}

common/logic/User/UserProducer/Event/CreditHistoryObserver.php → common/logic/User/UserProducer/Event/PaymentObserver.php Просмотреть файл

@@ -6,13 +6,13 @@ use common\logic\User\UserProducer\Wrapper\UserProducerManager;
use justcoded\yii2\eventlistener\observers\ActiveRecordObserver;
use yii\db\AfterSaveEvent;

class CreditHistoryObserver extends ActiveRecordObserver
class PaymentObserver extends ActiveRecordObserver
{
public function inserted(AfterSaveEvent $event)
{
$creditHistory = $event->sender;
$payment = $event->sender;
$userProducerManager = UserProducerManager::getInstance();

$userProducerManager->updateCredit($creditHistory);
$userProducerManager->updateCredit($payment);
}
}

+ 23
- 22
common/logic/User/UserProducer/Service/UserProducerBuilder.php Просмотреть файл

@@ -7,29 +7,32 @@ use common\logic\AbstractBuilder;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\Order\Repository\OrderRepository;
use common\logic\Order\Order\Service\OrderSolver;
use common\logic\Payment\Model\Payment;
use common\logic\Payment\Service\PaymentSolver;
use common\logic\Producer\Producer\Model\Producer;
use common\logic\Producer\Producer\Repository\ProducerRepository;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\CreditHistory\Service\CreditHistorySolver;
use common\logic\User\User\Model\User;
use common\logic\User\User\Repository\UserRepository;
use common\logic\User\UserProducer\Model\UserProducer;
use common\logic\User\UserProducer\Repository\UserProducerRepository;

class UserProducerBuilder extends AbstractBuilder
{
protected CreditHistorySolver $creditHistorySolver;
protected PaymentSolver $paymentSolver;
protected UserProducerRepository $userProducerRepository;
protected OrderRepository $orderRepository;
protected ProducerRepository $producerRepository;
protected OrderSolver $orderSolver;
protected UserRepository $userRepository;

public function loadDependencies(): void
{
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class);
$this->paymentSolver = $this->loadService(PaymentSolver::class);
$this->userProducerRepository = $this->loadService(UserProducerRepository::class);
$this->orderRepository = $this->loadService(OrderRepository::class);
$this->producerRepository = $this->loadService(ProducerRepository::class);
$this->orderSolver = $this->loadService(OrderSolver::class);
$this->userRepository = $this->loadService(UserRepository::class);
}

public function instanciateUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true)
@@ -59,34 +62,34 @@ class UserProducerBuilder extends AbstractBuilder
?? $this->createUserProducer($user, $producer, $bookmark, $newsletter);
}

public function updateCredit(CreditHistory $creditHistory): void
public function updateCredit(Payment $payment): void
{
$userProducer = $this->userProducerRepository->findOneUserProducer($creditHistory->user);
$userProducer = $this->userProducerRepository->findOneUserProducer($payment->user);

if ($userProducer) {
$oldCredit = $userProducer->getCredit();

$this->deductCredit($userProducer, $creditHistory);
$this->initMeanPaymentOrder($creditHistory);
$this->sendCreditLimitReminder($userProducer, $creditHistory, $oldCredit);
$this->deductCredit($userProducer, $payment);
$this->initMeanPaymentOrder($payment);
$this->sendCreditLimitReminder($userProducer, $payment, $oldCredit);
}
}

public function deductCredit(UserProducer $userProducer, CreditHistory $creditHistory)
public function deductCredit(UserProducer $userProducer, Payment $payment)
{
if ($this->creditHistorySolver->isTypeCredit($creditHistory)) {
$userProducer->setCredit($userProducer->getCredit() + $creditHistory->getAmount());
} elseif ($this->creditHistorySolver->isTypeDebit($creditHistory)) {
$userProducer->setCredit($userProducer->getCredit() - $creditHistory->getAmount());
if ($this->paymentSolver->isTypeCredit($payment)) {
$userProducer->setCredit($userProducer->getCredit() + $payment->getAmount());
} elseif ($this->paymentSolver->isTypeDebit($payment)) {
$userProducer->setCredit($userProducer->getCredit() - $payment->getAmount());
}

$this->update($userProducer);
}

public function initMeanPaymentOrder($creditHistory)
public function initMeanPaymentOrder(Payment $payment)
{
if ($creditHistory->id_order && $creditHistory->id_order > 0) {
$order = $this->orderRepository->findOneOrderById((int) $creditHistory->id_order);
if ($payment->id_order && $payment->id_order > 0) {
$order = $this->orderRepository->findOneOrderById((int) $payment->id_order);

if ($order) {
$paymentStatus = $this->orderSolver->getPaymentStatus($order);
@@ -101,16 +104,14 @@ class UserProducerBuilder extends AbstractBuilder
}
}

public function sendCreditLimitReminder($userProducer, $creditHistory, $oldCredit)
public function sendCreditLimitReminder($userProducer, $payment, $oldCredit)
{
$userRepository = \Yii::$app->logic->getUserContainer()->getRepository();
$producerRepository = \Yii::$app->logic->getProducerContainer()->getRepository();
$newCredit = $userProducer->credit;

if ($this->isCreditLimitCrossed($oldCredit, $newCredit)) {

$user = $userRepository->findOneUserById($creditHistory->id_user);
$producer = $producerRepository->findOneProducerById($creditHistory->id_producer);
$user = $this->userRepository->findOneUserById($payment->id_user);
$producer = $this->producerRepository->findOneProducerById($payment->id_producer);

if($user && $user->email && strlen($user->email) > 0) {
\Yii::$app->mailer->compose(

+ 2
- 2
common/mail/creditUser-html.php Просмотреть файл

@@ -36,16 +36,16 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use common\logic\Payment\Model\Payment;
use yii\helpers\Html;
use common\helpers\Price;
use common\logic\User\CreditHistory\Model\CreditHistory;

?>

<p>Bonjour <?= Html::encode($user->name); ?>,</p>

<p>Votre producteur <strong><?= Html::encode($producer->name); ?></strong> vient
de <?php if($creditForm->type == CreditHistory::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <strong><?= Price::format($creditForm->amount); ?></strong> sur le site <a href="http://www.opendistrib.net/">Opendistrib</a>.</p>
de <?php if($creditForm->type == Payment::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <strong><?= Price::format($creditForm->amount); ?></strong> sur le site <a href="http://www.opendistrib.net/">Opendistrib</a>.</p>

<p>Votre compte est désormais à <strong><?= Price::format($userProducer->credit); ?></strong><br />
<a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>">Cliquez ici</a> pour voir l'historique de votre crédit.</p>

+ 2
- 2
common/mail/creditUser-text.php Просмотреть файл

@@ -37,13 +37,13 @@ termes.
*/

use common\helpers\Price ;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\Payment\Model\Payment;

?>

Bonjour <?= $user->name; ?>,</p>

Votre producteur <?= $producer->name; ?> vient de <?php if($creditForm->type == CreditHistory::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <?= Price::format($creditForm->amount); ?> sur le site http://www.opendistrib.net/
Votre producteur <?= $producer->name; ?> vient de <?php if($creditForm->type == Payment::TYPE_CREDIT): ?>créditer<?php else: ?>débiter<?php endif; ?> votre compte de <?= Price::format($creditForm->amount); ?> sur le site http://www.opendistrib.net/

Votre compte est désormais à : <?= Price::format($userProducer->credit); ?>.
Suivez ce lien pour voir l'historique de votre crédit : <?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>">

+ 27
- 0
console/migrations/m230913_071815_alter_table_credit_history_rename_payment.php Просмотреть файл

@@ -0,0 +1,27 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

/**
* Class m230913_071815_alter_table_credit_history_rename_payment
*/
class m230913_071815_alter_table_credit_history_rename_payment extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->renameTable('credit_history', 'payment');
$this->addColumn('payment', 'id_invoice', Schema::TYPE_INTEGER);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->renameTable('payment', 'credit_history');
}
}

+ 7
- 8
producer/controllers/CreditController.php Просмотреть файл

@@ -39,10 +39,9 @@
namespace producer\controllers;

use common\helpers\GlobalParam;
use common\helpers\Mailjet;
use common\helpers\MeanPayment;
use common\logic\User\CreditHistory\Model\CreditHistory;
use common\logic\User\CreditHistory\Model\CreditHistorySearch;
use common\logic\Payment\Model\Payment;
use common\logic\Payment\Model\CreditHistorySearch;
use producer\models\CreditForm;
use yii\filters\VerbFilter;

@@ -181,7 +180,7 @@ class CreditController extends ProducerBaseController
public function actionStripeVerification()
{
$orderManager = $this->getOrderManager();
$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();
$producerManager = $this->getProducerManager();
$userManager = $this->getUserManager();
$producer = $this->getProducerCurrent();
@@ -225,7 +224,7 @@ class CreditController extends ProducerBaseController
switch ($event->type) {
case 'charge.succeeded':

$creditHistoryExist = CreditHistory::searchOne([
$paymentExist = Payment::searchOne([
'id_user' => $idUser,
'amount' => $amount,
], [
@@ -234,13 +233,13 @@ class CreditController extends ProducerBaseController
]
]);

if (!$creditHistoryExist) {
if (!$paymentExist) {

$creditHistoryManager->creditUser($user, $amount, MeanPayment::CREDIT_CARD, $user);
$paymentManager->creditUser($user, $amount, MeanPayment::CREDIT_CARD, $user);

if (isset($order) && $order) {

$creditHistoryManager->payOrder($order, $user, true);
$paymentManager->payOrder($order, $user, true);


// client : envoi d'un email de confirmation de paiement

+ 3
- 3
producer/controllers/OrderController.php Просмотреть файл

@@ -329,7 +329,7 @@ class OrderController extends ProducerBaseController
$producerManager = $this->getProducerManager();
$productOrderManager = $this->getProductOrderManager();
$userManager = $this->getUserManager();
$creditHistoryManager = $this->getCreditHistoryManager();
$paymentManager = $this->getPaymentManager();

$posts = \Yii::$app->request->post();
$productsArray = [];
@@ -455,10 +455,10 @@ class OrderController extends ProducerBaseController
)) {
// à payer
if ($orderManager->getPaymentStatus($order) == Order::PAYMENT_UNPAID) {
$creditHistoryManager->payOrder($order, $this->getUserCurrent(), true);
$paymentManager->payOrder($order, $this->getUserCurrent(), true);
} // surplus à rembourser
elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) {
$creditHistoryManager->refundSurplusOrder($order, $this->getUserCurrent());
$paymentManager->refundSurplusOrder($order, $this->getUserCurrent());
}
}


+ 16
- 16
producer/views/credit/history.php Просмотреть файл

@@ -36,10 +36,10 @@
* termes.
*/

use common\logic\User\CreditHistory\Wrapper\CreditHistoryManager;
use common\logic\Payment\Wrapper\PaymentManager;
use yii\grid\GridView;

$creditHistoryManager = CreditHistoryManager::getInstance();
$paymentManager = PaymentManager::getInstance();
$producer = $this->context->getProducerCurrent();
$this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>');
$this->setPageTitle('Crédit');
@@ -61,35 +61,35 @@ if ($this->context->getProducerCurrent()->online_payment) {
'columns' => [
[
'attribute' => 'date',
'value' => function ($model) use ($creditHistoryManager) {
return $creditHistoryManager->getDate($model, true);
'value' => function ($model) use ($paymentManager) {
return $paymentManager->getDate($model, true);
}
],
[
'attribute' => 'id_user_action',
'value' => function ($model) use ($creditHistoryManager) {
return $creditHistoryManager->getStrUserAction($model);
'value' => function ($model) use ($paymentManager) {
return $paymentManager->getStrUserAction($model);
}
],
[
'label' => 'Type',
'format' => 'raw',
'value' => function ($model) use ($creditHistoryManager) {
return $creditHistoryManager->getStrWording($model);
'value' => function ($model) use ($paymentManager) {
return $paymentManager->getStrWording($model);
}
],
[
'attribute' => 'mean_payment',
'value' => function ($model) use ($creditHistoryManager) {
return $creditHistoryManager->getStrMeanPayment($model);
'value' => function ($model) use ($paymentManager) {
return $paymentManager->getStrMeanPayment($model);
}
],
[
'label' => '- Débit',
'format' => 'raw',
'value' => function ($model) use ($creditHistoryManager) {
if ($creditHistoryManager->isTypeDebit($model)) {
return '-&nbsp;' . $creditHistoryManager->getAmount($model, true);
'value' => function ($model) use ($paymentManager) {
if ($paymentManager->isTypeDebit($model)) {
return '-&nbsp;' . $paymentManager->getAmount($model, true);
}
return '';
}
@@ -97,9 +97,9 @@ if ($this->context->getProducerCurrent()->online_payment) {
[
'label' => '+ Crédit',
'format' => 'raw',
'value' => function ($model) use ($creditHistoryManager) {
if ($creditHistoryManager->isTypeCredit($model)) {
return '+&nbsp;' . $creditHistoryManager->getAmount($model, true);
'value' => function ($model) use ($paymentManager) {
if ($paymentManager->isTypeCredit($model)) {
return '+&nbsp;' . $paymentManager->getAmount($model, true);
}
return '';
}

Загрузка…
Отмена
Сохранить