namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\MeanPayment; | |||||
use common\logic\Order\Order\Model\Order; | 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 common\logic\User\User\Model\User; | ||||
use Yii; | use Yii; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
$producerManager = $this->getProducerManager(); | $producerManager = $this->getProducerManager(); | ||||
$distributionManager = $this->getDistributionManager(); | $distributionManager = $this->getDistributionManager(); | ||||
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { | if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { | ||||
$orderManager->initOrder($order); | $orderManager->initOrder($order); | ||||
if ($order->auto_payment && $configCredit) { | if ($order->auto_payment && $configCredit) { | ||||
if ($orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) { | 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++; | $countOrders++; | ||||
} | } | ||||
} | } |
{ | { | ||||
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
if ($ordersArray) { | if ($ordersArray) { | ||||
foreach ($ordersArray as &$order) { | foreach ($ordersArray as &$order) { | ||||
$creditHistoryArray = []; | $creditHistoryArray = []; | ||||
foreach ($order->creditHistory as $creditHistory) { | |||||
foreach ($order->payment as $payment) { | |||||
$creditHistoryArray[] = [ | $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, | Order::AMOUNT_TOTAL, | ||||
true | true | ||||
) : ''), | ) : ''), | ||||
'credit' => ($creditHistoryManager->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryManager->getAmount( | |||||
$creditHistory, | |||||
'credit' => ($paymentManager->isTypeCredit($payment) ? '+ ' . $paymentManager->getAmount( | |||||
$payment, | |||||
Order::AMOUNT_TOTAL, | Order::AMOUNT_TOTAL, | ||||
true | true | ||||
) : '') | ) : '') | ||||
) : null, | ) : null, | ||||
'pointSale' => $order->pointSale ? ['id' => $order->pointSale->id, 'name' => $order->pointSale->name] : null, | 'pointSale' => $order->pointSale ? ['id' => $order->pointSale->id, 'name' => $order->pointSale->name] : null, | ||||
'productOrder' => $productOrderArray, | 'productOrder' => $productOrderArray, | ||||
'creditHistory' => $creditHistoryArray, | |||||
'paymentArray' => $creditHistoryArray, | |||||
'oneProductUnactivated' => $oneProductUnactivated, | 'oneProductUnactivated' => $oneProductUnactivated, | ||||
'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order), | 'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order), | ||||
'isCreditAutoPayment' => $orderManager->isCreditAutoPayment($order) | |||||
]); | ]); | ||||
} | } | ||||
} | } |
use common\forms\SubscriptionForm; | use common\forms\SubscriptionForm; | ||||
use common\helpers\CSV; | use common\helpers\CSV; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\MeanPayment; | |||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use common\logic\Distribution\Distribution\Model\Distribution; | use common\logic\Distribution\Distribution\Model\Distribution; | ||||
use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution; | use common\logic\Distribution\PointSaleDistribution\Model\PointSaleDistribution; | ||||
use common\logic\Order\ProductOrder\Model\ProductOrder; | use common\logic\Order\ProductOrder\Model\ProductOrder; | ||||
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\Product\Product\Model\Product; | 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\User\Model\User; | ||||
use common\logic\User\UserProducer\Model\UserProducer; | use common\logic\User\UserProducer\Model\UserProducer; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
$pointSaleManager = $this->getPointSaleManager(); | $pointSaleManager = $this->getPointSaleManager(); | ||||
$userPointSaleManager = $this->getUserPointSaleManager(); | $userPointSaleManager = $this->getUserPointSaleManager(); | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$productManager = $this->getProductManager(); | $productManager = $this->getProductManager(); | ||||
$request = \Yii::$app->request; | $request = \Yii::$app->request; | ||||
$oldIdUser = $order->id_user; | $oldIdUser = $order->id_user; | ||||
$amountPaid = $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_PAID); | $amountPaid = $orderManager->getOrderAmountWithTax($order, Order::AMOUNT_PAID); | ||||
if ($oldIdUser != $idUser && $amountPaid > 0) { | if ($oldIdUser != $idUser && $amountPaid > 0) { | ||||
$creditHistoryManager->refundOrder($order, $this->getUserCurrent()); | |||||
$paymentManager->refundOrder($order, $this->getUserCurrent()); | |||||
$order = $orderManager->findOneOrderById($idOrder); | $order = $orderManager->findOneOrderById($idOrder); | ||||
$orderManager->initOrder($order); | $orderManager->initOrder($order); | ||||
} | } | ||||
public function actionPaymentStatus(int $idOrder) | public function actionPaymentStatus(int $idOrder) | ||||
{ | { | ||||
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$order = $orderManager->findOneOrderById($idOrder); | $order = $orderManager->findOneOrderById($idOrder); | ||||
. '</span>'; | . '</span>'; | ||||
// historique | // historique | ||||
$history = CreditHistory::find() | |||||
$history = Payment::find() | |||||
->with('userAction') | ->with('userAction') | ||||
->where(['id_order' => $idOrder]) | ->where(['id_order' => $idOrder]) | ||||
->all(); | ->all(); | ||||
if ($history && is_array($history) && count($history)) { | if ($history && is_array($history) && count($history)) { | ||||
foreach ($history as $creditHistory) { | foreach ($history as $creditHistory) { | ||||
$html .= '<tr>' | $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>'; | . '</tr>'; | ||||
} | } | ||||
} else { | } else { | ||||
/** | /** | ||||
* Effectue le paiement/remboursement d'une commande. | * 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; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$order = $orderManager->findOneOrderById($idOrder); | $order = $orderManager->findOneOrderById($idOrder); | ||||
$orderManager->initOrder($order); | $orderManager->initOrder($order); | ||||
if ($order) { | if ($order) { | ||||
$creditHistoryManager->payOrRefundOrder($type, $order, $this->getUserCurrent()); | |||||
$paymentManager->payOrRefundOrder($type, $order, $meanPayment, $this->getUserCurrent()); | |||||
} | } | ||||
return ['success']; | return ['success']; |
use backend\models\CreditForm; | use backend\models\CreditForm; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Mailjet; | |||||
use backend\models\MailForm; | use backend\models\MailForm; | ||||
use common\helpers\Password; | use common\helpers\Password; | ||||
use common\logic\Order\Order\Model\OrderSearch; | use common\logic\Order\Order\Model\OrderSearch; | ||||
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\PointSale\UserPointSale\Model\UserPointSale; | 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\User; | ||||
use common\logic\User\User\Model\UserSearch; | use common\logic\User\User\Model\UserSearch; | ||||
use common\logic\User\UserProducer\Model\UserProducer; | use common\logic\User\UserProducer\Model\UserProducer; | ||||
use common\logic\User\UserUserGroup\Model\UserUserGroup; | use common\logic\User\UserUserGroup\Model\UserUserGroup; | ||||
use Faker\Provider\HtmlLorem; | |||||
use yii\base\UserException; | use yii\base\UserException; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use yii\filters\VerbFilter; | |||||
use \Yii; | use \Yii; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
$creditForm = new CreditForm; | $creditForm = new CreditForm; | ||||
} | } | ||||
$history = CreditHistory::find() | |||||
$history = Payment::find() | |||||
->with(['order', 'userAction']) | ->with(['order', 'userAction']) | ||||
->where([ | ->where([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, |
namespace backend\models; | namespace backend\models; | ||||
use common\helpers\GlobalParam; | 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\User\Wrapper\UserManager; | ||||
use common\logic\User\UserProducer\Model\UserProducer; | |||||
use common\logic\User\UserProducer\Wrapper\UserProducerManager; | use common\logic\User\UserProducer\Wrapper\UserProducerManager; | ||||
use Yii; | |||||
use yii\base\Model; | use yii\base\Model; | ||||
/** | /** | ||||
{ | { | ||||
$userManager = UserManager::getInstance(); | $userManager = UserManager::getInstance(); | ||||
$userProducerManager = UserProducerManager::getInstance(); | $userProducerManager = UserProducerManager::getInstance(); | ||||
$creditHistoryManager = CreditHistoryManager::getInstance(); | |||||
$producerManager = ProducerManager::getInstance(); | |||||
$paymentManager = PaymentManager::getInstance(); | |||||
if ($this->validate()) { | if ($this->validate()) { | ||||
$user = $userManager->findOneUserById($this->id_user); | $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é | // on prévient l'utilisateur que son compte vient d'être crédité | ||||
if($this->send_mail) { | if($this->send_mail) { |
<th class="column-user">Utilisateur</th> | <th class="column-user">Utilisateur</th> | ||||
<th class="column-point-sale" v-if="idActivePointSale == 0">Point de vente</th> | <th class="column-point-sale" v-if="idActivePointSale == 0">Point de vente</th> | ||||
<th class="column-amount">Montant</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-payment"></th> | ||||
<th class="column-tiller" v-if="producer && producer.tiller">Tiller</th> | <th class="column-tiller" v-if="producer && producer.tiller">Tiller</th> | ||||
<th class="column-actions"></th> | <th class="column-actions"></th> | ||||
</td> | </td> | ||||
<td class="column-state-payment"> | <td class="column-state-payment"> | ||||
<order-state-payment :order="order" :producer="producer"></order-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> | ||||
<td class="column-payment" v-if="producer && producer.credit"> | <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"> | <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 | <span class="glyphicon glyphicon-euro"></span> Recréditer | ||||
</button> | </button> | ||||
<ul class="dropdown-menu"> | <ul class="dropdown-menu"> | ||||
<li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li> | <li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li> | ||||
</ul> | </ul> | ||||
</div> | |||||
</div>--> | |||||
</td> | </td> | ||||
<td v-if="producer && producer.tiller" class="tiller column-tiller"> | <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" /> | <input v-if="order.tiller_synchronization == true" type="checkbox" checked="checked" :id="'checkbox-tiller-synchronization-'+order.id" :data-id-order="order.id" @change="changeSynchroTiller" /> | ||||
</div> | </div> | ||||
<script type="text/x-template" id="order-state-payment"> | <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"> </span> | |||||
<span class="label label-default" v-else-if="order.amount_paid == 0"> </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> | </script> | ||||
<!-- template for the order-form component --> | <!-- template for the order-form component --> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||||
use common\logic\Payment\Model\Payment; | |||||
use common\helpers\MeanPayment; | use common\helpers\MeanPayment; | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$producerManager = $this->getProducerManager(); | $producerManager = $this->getProducerManager(); | ||||
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<?php $form = ActiveForm::begin(); ?> | <?php $form = ActiveForm::begin(); ?> | ||||
<?= $form->field($creditForm, 'type')->dropDownList([ | <?= $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, 'amount')->textInput() ?> | ||||
<?= $form->field($creditForm, 'mean_payment')->dropDownList([ | <?= $form->field($creditForm, 'mean_payment')->dropDownList([ | ||||
<?php foreach($history as $creditHistory): ?> | <?php foreach($history as $creditHistory): ?> | ||||
<tr> | <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> | <td> | ||||
<?php if($creditHistoryManager->isTypeDebit($creditHistory)): ?> | |||||
- <?= $creditHistoryManager->getAmount($creditHistory, true); ?> | |||||
<?php if($paymentManager->isTypeDebit($creditHistory)): ?> | |||||
- <?= $paymentManager->getAmount($creditHistory, true); ?> | |||||
<?php endif; ?> | <?php endif; ?> | ||||
</td> | </td> | ||||
<td> | <td> | ||||
<?php if($creditHistoryManager->isTypeCredit($creditHistory)): ?> | |||||
+ <?= $creditHistoryManager->getAmount($creditHistory, true); ?> | |||||
<?php if($paymentManager->isTypeCredit($creditHistory)): ?> | |||||
+ <?= $paymentManager->getAmount($creditHistory, true); ?> | |||||
<?php endif; ?> | <?php endif; ?> | ||||
</td> | </td> | ||||
<td> | <td> | ||||
<?= $creditHistoryManager->getStrMeanPayment($creditHistory) ?> | |||||
<?= $paymentManager->getStrMeanPayment($creditHistory) ?> | |||||
</td> | </td> | ||||
<td> | <td> | ||||
<?php if(strlen($creditHistory->getComment())): ?> | <?php if(strlen($creditHistory->getComment())): ?> |
.distribution-index #orders table .state-payment-mobile { | .distribution-index #orders table .state-payment-mobile { | ||||
display: none; | 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 { | .distribution-index #orders table td.column-payment div.btn-group { | ||||
width: 125px; | width: 125px; | ||||
} | } | ||||
/* line 326, ../sass/distribution/_index.scss */ | |||||
/* line 328, ../sass/distribution/_index.scss */ | |||||
.distribution-index #orders table tr.view ul { | .distribution-index #orders table tr.view ul { | ||||
list-style-type: none; | list-style-type: none; | ||||
margin-left: 0px; | margin-left: 0px; | ||||
padding-left: 15px; | padding-left: 15px; | ||||
} | } | ||||
/* line 336, ../sass/distribution/_index.scss */ | |||||
/* line 338, ../sass/distribution/_index.scss */ | |||||
.distribution-index #orders table tr.view .comment { | .distribution-index #orders table tr.view .comment { | ||||
margin-top: 20px; | margin-top: 20px; | ||||
} | } | ||||
/* line 340, ../sass/distribution/_index.scss */ | |||||
/* line 342, ../sass/distribution/_index.scss */ | |||||
.distribution-index #orders table tr.view .delivery { | .distribution-index #orders table tr.view .delivery { | ||||
margin-top: 20px; | margin-top: 20px; | ||||
} | } | ||||
/* line 349, ../sass/distribution/_index.scss */ | |||||
/* line 351, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-form-order .modal-container { | .distribution-index .modal-form-order .modal-container { | ||||
width: 100%; | width: 100%; | ||||
padding: 0px; | padding: 0px; | ||||
} | } | ||||
/* line 353, ../sass/distribution/_index.scss */ | |||||
/* line 355, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-form-order .modal-container .modal-body { | .distribution-index .modal-form-order .modal-container .modal-body { | ||||
padding-right: 15px; | 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 { | .distribution-index .modal-form-order .modal-container .modal-body table { | ||||
margin-bottom: 150px; | margin-bottom: 150px; | ||||
} | } | ||||
/* line 361, ../sass/distribution/_index.scss */ | |||||
/* line 363, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-form-order .modal-container .modal-footer { | .distribution-index .modal-form-order .modal-container .modal-footer { | ||||
border-top-color: #f4f4f4; | border-top-color: #f4f4f4; | ||||
position: fixed; | position: fixed; | ||||
text-align: center; | text-align: center; | ||||
border-top: solid 1px #e0e0e0; | 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 { | .distribution-index .modal-form-order .modal-container .modal-footer .actions-form button { | ||||
float: none; | 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 { | .distribution-index .modal-form-order .modal-container .modal-footer .actions-form div.right { | ||||
float: right; | float: right; | ||||
} | } | ||||
/* line 384, ../sass/distribution/_index.scss */ | |||||
/* line 386, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-form-order .btn-credit { | .distribution-index .modal-form-order .btn-credit { | ||||
float: right; | 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 { | .distribution-index .modal-form-order table.table-products .product-ordered td { | ||||
background-color: #e9e9e9; | 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 { | .distribution-index .modal-form-order table.table-products .product-ordered input.input-quantity { | ||||
font-size: 16px; | font-size: 16px; | ||||
font-weight: bold; | 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 { | .distribution-index .modal-form-order table.table-products td.price { | ||||
width: 150px; | 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 { | .distribution-index .modal-form-order table.table-products td.price input { | ||||
text-align: center; | 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 { | .distribution-index .modal-form-order table.table-products td.price .input-group-addon { | ||||
background-color: #eee; | 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 { | .distribution-index .modal-form-order table.table-products td.price .invoice-price { | ||||
margin-top: 8px; | 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 { | .distribution-index .modal-form-order table.table-products td.price .invoice-price .label-invoice-price { | ||||
font-size: 11px; | font-size: 11px; | ||||
font-weight: bold; | font-weight: bold; | ||||
color: gray; | color: gray; | ||||
} | } | ||||
/* line 421, ../sass/distribution/_index.scss */ | |||||
/* line 423, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-form-order table.table-products td.quantity { | .distribution-index .modal-form-order table.table-products td.quantity { | ||||
width: 165px; | 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 { | .distribution-index .modal-form-order table.table-products td.quantity input { | ||||
text-align: center; | text-align: center; | ||||
color: black; | 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 { | .distribution-index .modal-form-order table.table-products td.quantity .form-control { | ||||
border-right: 0px none; | border-right: 0px none; | ||||
padding-right: 4px; | 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 { | .distribution-index .modal-form-order table.table-products td.quantity .input-group-addon { | ||||
padding: 5px; | padding: 5px; | ||||
padding-left: 0px; | padding-left: 0px; | ||||
border-left: 0px none; | border-left: 0px none; | ||||
border-right: 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 { | .distribution-index .modal-form-order table.table-products td.quantity-remaining { | ||||
text-align: right; | 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 { | .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; | 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 { | .distribution-index .modal-form-order table.table-products td.quantity-remaining.negative { | ||||
color: #DD4B39; | 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 { | .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; | font-size: 18px; | ||||
} | } | ||||
/* line 461, ../sass/distribution/_index.scss */ | |||||
/* line 463, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-form-order .actions-form button { | .distribution-index .modal-form-order .actions-form button { | ||||
margin-left: 15px; | margin-left: 15px; | ||||
} | } | ||||
/* line 469, ../sass/distribution/_index.scss */ | |||||
/* line 471, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-payment .info-box .info-box-icon { | .distribution-index .modal-payment .info-box .info-box-icon { | ||||
width: 50px; | width: 50px; | ||||
} | } | ||||
/* line 472, ../sass/distribution/_index.scss */ | |||||
/* line 474, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-payment .info-box .info-box-icon i { | .distribution-index .modal-payment .info-box .info-box-icon i { | ||||
font-size: 30px; | font-size: 30px; | ||||
} | } | ||||
/* line 477, ../sass/distribution/_index.scss */ | |||||
/* line 479, ../sass/distribution/_index.scss */ | |||||
.distribution-index .modal-payment .info-box .info-box-content { | .distribution-index .modal-payment .info-box .info-box-content { | ||||
margin-left: 50px; | margin-left: 50px; | ||||
} | } |
params: { | params: { | ||||
idOrder: idOrder, | idOrder: idOrder, | ||||
type: event.currentTarget.getAttribute('data-type'), | 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) { | .then(function (response) { |
} | } | ||||
td.column-payment { | td.column-payment { | ||||
position: relative; | |||||
div.btn-group { | div.btn-group { | ||||
width: 125px; | width: 125px; | ||||
} | } |
$this->getTaxRateContainer(), | $this->getTaxRateContainer(), | ||||
$this->getUserUserGroupContainer(), | $this->getUserUserGroupContainer(), | ||||
$this->getUserGroupContainer(), | $this->getUserGroupContainer(), | ||||
$this->getCreditHistoryContainer(), | |||||
$this->getPaymentContainer(), | |||||
$this->getProducerPriceRangeContainer(), | $this->getProducerPriceRangeContainer(), | ||||
$this->getUserProducerContainer(), | $this->getUserProducerContainer(), | ||||
$this->getUserPointSaleContainer(), | $this->getUserPointSaleContainer(), |
use common\logic\Order\Order\Wrapper\OrderManager; | use common\logic\Order\Order\Wrapper\OrderManager; | ||||
use common\logic\Order\ProductOrder\Wrapper\ProductOrderContainer; | use common\logic\Order\ProductOrder\Wrapper\ProductOrderContainer; | ||||
use common\logic\Order\ProductOrder\Wrapper\ProductOrderManager; | 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\PointSaleContainer; | ||||
use common\logic\PointSale\PointSale\Wrapper\PointSaleManager; | use common\logic\PointSale\PointSale\Wrapper\PointSaleManager; | ||||
use common\logic\PointSale\UserPointSale\Wrapper\UserPointSaleContainer; | use common\logic\PointSale\UserPointSale\Wrapper\UserPointSaleContainer; | ||||
use common\logic\Ticket\TicketMessage\Wrapper\TicketMessageManager; | use common\logic\Ticket\TicketMessage\Wrapper\TicketMessageManager; | ||||
use common\logic\Ticket\TicketUser\Wrapper\TicketUserContainer; | use common\logic\Ticket\TicketUser\Wrapper\TicketUserContainer; | ||||
use common\logic\Ticket\TicketUser\Wrapper\TicketUserManager; | 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\UserContainer; | ||||
use common\logic\User\User\Wrapper\UserManager; | use common\logic\User\User\Wrapper\UserManager; | ||||
use common\logic\User\UserGroup\Wrapper\UserGroupContainer; | use common\logic\User\UserGroup\Wrapper\UserGroupContainer; | ||||
return SubscriptionManager::getInstance(); | return SubscriptionManager::getInstance(); | ||||
} | } | ||||
public function getCreditHistoryManager(): CreditHistoryManager | |||||
public function getPaymentManager(): PaymentManager | |||||
{ | { | ||||
return CreditHistoryManager::getInstance(); | |||||
return PaymentManager::getInstance(); | |||||
} | } | ||||
public function getUserManager(): UserManager | public function getUserManager(): UserManager | ||||
return UserProducerContainer::getInstance(); | return UserProducerContainer::getInstance(); | ||||
} | } | ||||
public function getCreditHistoryContainer(): CreditHistoryContainer | |||||
public function getPaymentContainer(): PaymentContainer | |||||
{ | { | ||||
return CreditHistoryContainer::getInstance(); | |||||
return PaymentContainer::getInstance(); | |||||
} | } | ||||
public function getDocumentContainer(): DocumentContainer | public function getDocumentContainer(): DocumentContainer |
use common\logic\Distribution\Distribution\Model\Distribution; | use common\logic\Distribution\Distribution\Model\Distribution; | ||||
use common\logic\Document\DeliveryNote\Model\DeliveryNote; | use common\logic\Document\DeliveryNote\Model\DeliveryNote; | ||||
use common\logic\Ticket\Ticket\Model\Ticket; | 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']) ?? ''; | $serverName = isset($_SERVER['SERVER_NAME']) ?? ''; | ||||
'class' => \justcoded\yii2\eventlistener\components\EventListener::class, | 'class' => \justcoded\yii2\eventlistener\components\EventListener::class, | ||||
'listeners' => [], | 'listeners' => [], | ||||
'observers' => [ | 'observers' => [ | ||||
CreditHistory::class => [ | |||||
common\logic\User\UserProducer\Event\CreditHistoryObserver::class | |||||
Payment::class => [ | |||||
common\logic\User\UserProducer\Event\PaymentObserver::class | |||||
], | ], | ||||
Distribution::class => [ | Distribution::class => [ | ||||
common\logic\Subscription\Subscription\Event\DistributionObserver::class | common\logic\Subscription\Subscription\Event\DistributionObserver::class |
use common\logic\Document\Invoice\Model\Invoice; | use common\logic\Document\Invoice\Model\Invoice; | ||||
use common\logic\Document\Quotation\Model\Quotation; | use common\logic\Document\Quotation\Model\Quotation; | ||||
use common\logic\Order\ProductOrder\Model\ProductOrder; | use common\logic\Order\ProductOrder\Model\ProductOrder; | ||||
use common\logic\Payment\Model\Payment; | |||||
use common\logic\PointSale\PointSale\Model\PointSale; | use common\logic\PointSale\PointSale\Model\PointSale; | ||||
use common\logic\Subscription\Subscription\Model\Subscription; | use common\logic\Subscription\Subscription\Model\Subscription; | ||||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||||
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
$this->populateFieldObject('id_point_sale', 'point_sale', $pointSale); | $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() | public function getSubscription() |
self::WITH => [ | self::WITH => [ | ||||
'productOrder', | 'productOrder', | ||||
'productOrder.product', | 'productOrder.product', | ||||
'creditHistory', | |||||
'creditHistory.userAction', | |||||
'payment', | |||||
'payment.userAction', | |||||
'pointSale', | 'pointSale', | ||||
], | ], | ||||
self::JOIN_WITH => [ | self::JOIN_WITH => [ |
use common\logic\Order\ProductOrder\Model\ProductOrder; | use common\logic\Order\ProductOrder\Model\ProductOrder; | ||||
use common\logic\Order\ProductOrder\Service\ProductOrderBuilder; | use common\logic\Order\ProductOrder\Service\ProductOrderBuilder; | ||||
use common\logic\Order\ProductOrder\Service\ProductOrderSolver; | 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\Model\PointSale; | ||||
use common\logic\PointSale\PointSale\Service\PointSaleBuilder; | use common\logic\PointSale\PointSale\Service\PointSaleBuilder; | ||||
use common\logic\PointSale\PointSale\Repository\PointSaleRepository; | use common\logic\PointSale\PointSale\Repository\PointSaleRepository; | ||||
use common\logic\Subscription\Subscription\Service\SubscriptionBuilder; | use common\logic\Subscription\Subscription\Service\SubscriptionBuilder; | ||||
use common\logic\Subscription\Subscription\Repository\SubscriptionRepository; | use common\logic\Subscription\Subscription\Repository\SubscriptionRepository; | ||||
use common\logic\Subscription\Subscription\Service\SubscriptionSolver; | 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\Repository\UserRepository; | ||||
use common\logic\User\User\Service\UserSolver; | use common\logic\User\User\Service\UserSolver; | ||||
use common\logic\User\UserProducer\Repository\UserProducerRepository; | use common\logic\User\UserProducer\Repository\UserProducerRepository; | ||||
{ | { | ||||
protected UserSolver $userSolver; | protected UserSolver $userSolver; | ||||
protected OrderSolver $orderSolver; | protected OrderSolver $orderSolver; | ||||
protected CreditHistoryRepository $creditHistoryRepository; | |||||
protected PaymentRepository $paymentRepository; | |||||
protected ProducerRepository $producerRepository; | protected ProducerRepository $producerRepository; | ||||
protected CreditHistoryBuilder $creditHistoryBuilder; | |||||
protected PaymentBuilder $paymentBuilder; | |||||
protected ProductOrderBuilder $productOrderBuilder; | protected ProductOrderBuilder $productOrderBuilder; | ||||
protected OrderRepository $orderRepository; | protected OrderRepository $orderRepository; | ||||
protected DistributionRepository $distributionRepository; | protected DistributionRepository $distributionRepository; | ||||
{ | { | ||||
$this->userSolver = $this->loadService(UserSolver::class); | $this->userSolver = $this->loadService(UserSolver::class); | ||||
$this->orderSolver = $this->loadService(OrderSolver::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->producerRepository = $this->loadService(ProducerRepository::class); | ||||
$this->creditHistoryBuilder = $this->loadService(CreditHistoryBuilder::class); | |||||
$this->paymentBuilder = $this->loadService(PaymentBuilder::class); | |||||
$this->productOrderBuilder = $this->loadService(ProductOrderBuilder::class); | $this->productOrderBuilder = $this->loadService(ProductOrderBuilder::class); | ||||
$this->orderRepository = $this->loadService(OrderRepository::class); | $this->orderRepository = $this->loadService(OrderRepository::class); | ||||
$this->distributionRepository = $this->loadService(DistributionRepository::class); | $this->distributionRepository = $this->loadService(DistributionRepository::class); | ||||
// remboursement de la commande | // remboursement de la commande | ||||
if ($theOrder->id_user && $this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID) && $configCredit) { | 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), | $this->orderSolver->getOrderAmount($theOrder, Order::AMOUNT_PAID), | ||||
$theOrder->distribution->producer, | $theOrder->distribution->producer, | ||||
$theOrder->user, | $theOrder->user, | ||||
*/ | */ | ||||
public function initOrderPaidAmount(Order $order): void | 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; | $order->paid_amount = 0; | ||||
if (count($history)) { | if (count($history)) { | ||||
foreach ($history as $ch) { | foreach ($history as $ch) { | ||||
if ($ch->type == CreditHistory::TYPE_PAYMENT) { | |||||
if ($ch->type == Payment::TYPE_PAYMENT) { | |||||
$order->paid_amount += $ch->amount; | $order->paid_amount += $ch->amount; | ||||
} elseif ($ch->type == CreditHistory::TYPE_REFUND) { | |||||
} elseif ($ch->type == Payment::TYPE_REFUND) { | |||||
$order->paid_amount -= $ch->amount; | $order->paid_amount -= $ch->amount; | ||||
} | } | ||||
} | } | ||||
$amountPaid = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_PAID); | $amountPaid = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_PAID); | ||||
if ($amountPaid >= 0.01) { | if ($amountPaid >= 0.01) { | ||||
$this->creditHistoryBuilder->createCreditHistory( | |||||
CreditHistory::TYPE_REFUND, | |||||
$this->paymentBuilder->createPayment( | |||||
Payment::TYPE_REFUND, | |||||
$amountPaid, | $amountPaid, | ||||
GlobalParam::getCurrentProducer(), | GlobalParam::getCurrentProducer(), | ||||
$order->user, | $order->user, | ||||
if ($paymentStatus == Order::PAYMENT_PAID) { | if ($paymentStatus == Order::PAYMENT_PAID) { | ||||
return; | return; | ||||
} elseif ($paymentStatus == Order::PAYMENT_SURPLUS) { | } elseif ($paymentStatus == Order::PAYMENT_SURPLUS) { | ||||
$type = CreditHistory::TYPE_REFUND; | |||||
$type = Payment::TYPE_REFUND; | |||||
$amount = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_SURPLUS); | $amount = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_SURPLUS); | ||||
} elseif ($paymentStatus == Order::PAYMENT_UNPAID) { | } elseif ($paymentStatus == Order::PAYMENT_UNPAID) { | ||||
$type = CreditHistory::TYPE_PAYMENT; | |||||
$type = Payment::TYPE_PAYMENT; | |||||
$amount = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_REMAINING); | $amount = $this->orderSolver->getOrderAmount($order, Order::AMOUNT_REMAINING); | ||||
} | } | ||||
$this->creditHistoryBuilder->createCreditHistory( | |||||
$this->paymentBuilder->createPayment( | |||||
$type, | $type, | ||||
$amount, | $amount, | ||||
GlobalParam::getCurrentProducer(), | GlobalParam::getCurrentProducer(), |
use common\logic\Document\Document\Model\Document; | use common\logic\Document\Document\Model\Document; | ||||
use common\logic\Document\Document\Service\DocumentSolver; | use common\logic\Document\Document\Service\DocumentSolver; | ||||
use common\logic\Order\Order\Model\Order; | 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\Producer\Producer\Service\ProducerSolver; | ||||
use common\logic\Product\Product\Model\Product; | use common\logic\Product\Product\Model\Product; | ||||
use common\logic\SolverInterface; | 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\Model\User; | ||||
use common\logic\User\User\Service\UserSolver; | use common\logic\User\User\Service\UserSolver; | ||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
{ | { | ||||
protected UserSolver $userSolver; | protected UserSolver $userSolver; | ||||
protected DocumentSolver $documentSolver; | protected DocumentSolver $documentSolver; | ||||
protected CreditHistorySolver $creditHistorySolver; | |||||
protected PaymentSolver $paymentSolver; | |||||
protected ProducerSolver $producerSolver; | protected ProducerSolver $producerSolver; | ||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->documentSolver = $this->loadService(DocumentSolver::class); | $this->documentSolver = $this->loadService(DocumentSolver::class); | ||||
$this->userSolver = $this->loadService(UserSolver::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); | $this->producerSolver = $this->loadService(ProducerSolver::class); | ||||
} | } | ||||
/** | /** | ||||
* Retourne une chaine de caractère décrivant l'utilisateur lié à la commande. | * Retourne une chaine de caractère décrivant l'utilisateur lié à la commande. | ||||
*/ | */ | ||||
// getStrUser | |||||
public function getOrderUsername(Order $order): string | public function getOrderUsername(Order $order): string | ||||
{ | { | ||||
if (isset($order->user)) { | if (isset($order->user)) { | ||||
/** | /** | ||||
* Retourne un bloc html présentant une date. | * Retourne un bloc html présentant une date. | ||||
*/ | */ | ||||
// getBlockDate | |||||
public function getDateAsHtml(Order $order): string | public function getDateAsHtml(Order $order): string | ||||
{ | { | ||||
return '<div class="block-date"> | return '<div class="block-date"> | ||||
* (libellé, montant, client, action) au format HTML. | * (libellé, montant, client, action) au format HTML. | ||||
* | * | ||||
*/ | */ | ||||
public function getCreditHistoryComment(CreditHistory $creditHistory): string | |||||
public function getPaymentComment(Payment $payment): string | |||||
{ | { | ||||
$str = ''; | $str = ''; | ||||
if (strlen($creditHistory->getComment())) { | |||||
if (strlen($payment->getComment())) { | |||||
$str .= '<br />'; | $str .= '<br />'; | ||||
} | } | ||||
$str .= $this->creditHistorySolver->getStrWording($creditHistory); | |||||
$str .= $this->paymentSolver->getStrWording($payment); | |||||
$order = $creditHistory->getOrderObject(); | |||||
$order = $payment->getOrderObject(); | |||||
if ($order) { | if ($order) { | ||||
$str .= '<br />Montant de la commande : ' . $this->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true); | $str .= '<br />Montant de la commande : ' . $this->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL, true); | ||||
} | } | ||||
$user = $creditHistory->getUserObject(); | |||||
$user = $payment->getUserObject(); | |||||
if ($user) { | if ($user) { | ||||
$str .= '<br />Client : ' . Html::encode($user->getName() . ' ' . $user->getLastname()); | $str .= '<br />Client : ' . Html::encode($user->getName() . ' ' . $user->getLastname()); | ||||
} | } | ||||
$userAction = $creditHistory->getUserActionObject(); | |||||
$userAction = $payment->getUserActionObject(); | |||||
if ($userAction) { | if ($userAction) { | ||||
$str .= '<br />Action : ' . Html::encode($userAction->getName() . ' ' . $userAction->getLastname()); | $str .= '<br />Action : ' . Html::encode($userAction->getName() . ' ' . $userAction->getLastname()); | ||||
} | } |
termes. | termes. | ||||
*/ | */ | ||||
namespace common\logic\User\CreditHistory\Model; | |||||
namespace common\logic\Payment\Model; | |||||
use common\helpers\GlobalParam; | 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; | use yii\data\ActiveDataProvider; | ||||
class CreditHistorySearch extends CreditHistory | |||||
class CreditHistorySearch extends Payment | |||||
{ | { | ||||
public function rules(): array | public function rules(): array | ||||
public function search($params) | 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']) | ->with($optionsSearch['with']) | ||||
->innerJoinWith($optionsSearch['join_with'], true) | ->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') | ->orderBy('id DESC') | ||||
; | ; | ||||
if(isset($this->id_user) && is_numeric($this->id_user)) { | if(isset($this->id_user) && is_numeric($this->id_user)) { | ||||
$query->andWhere([ | $query->andWhere([ | ||||
'credit_history.id_user' => $this->id_user | |||||
'payment.id_user' => $this->id_user | |||||
]) ; | ]) ; | ||||
} | } | ||||
* termes. | * termes. | ||||
*/ | */ | ||||
namespace common\logic\User\CreditHistory\Model; | |||||
namespace common\logic\Payment\Model; | |||||
use common\components\ActiveRecordCommon; | use common\components\ActiveRecordCommon; | ||||
use common\logic\Document\Invoice\Model\Invoice; | |||||
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\Producer\Producer\Model\Producer; | use common\logic\Producer\Producer\Model\Producer; | ||||
use common\logic\User\User\Model\User; | use common\logic\User\User\Model\User; | ||||
use common\logic\User\UserProducer\Event\UserProducerEventSubscriber; | |||||
use yii\db\ActiveQuery; | use yii\db\ActiveQuery; | ||||
class CreditHistory extends ActiveRecordCommon | |||||
class Payment extends ActiveRecordCommon | |||||
{ | { | ||||
const TYPE_INITIAL_CREDIT = 'initial-credit'; | const TYPE_INITIAL_CREDIT = 'initial-credit'; | ||||
const TYPE_CREDIT = 'credit'; | const TYPE_CREDIT = 'credit'; | ||||
*/ | */ | ||||
public static function tableName(): string | public static function tableName(): string | ||||
{ | { | ||||
return 'credit_history'; | |||||
return 'payment'; | |||||
} | } | ||||
/** | /** | ||||
{ | { | ||||
return [ | return [ | ||||
[['amount'], 'required'], | [['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'], | [['date'], 'safe'], | ||||
[['amount'], 'double'], | [['amount'], 'double'], | ||||
[['type', 'mean_payment'], 'string', 'max' => 255], | [['type', 'mean_payment'], 'string', 'max' => 255], | ||||
'id_user' => 'Utilisateur', | 'id_user' => 'Utilisateur', | ||||
'id_user_action' => 'Utilisateur', | 'id_user_action' => 'Utilisateur', | ||||
'id_order' => 'Commande', | 'id_order' => 'Commande', | ||||
'id_invoice' => 'Facture', | |||||
'date' => 'Date', | 'date' => 'Date', | ||||
'amount' => 'Montant', | 'amount' => 'Montant', | ||||
'type' => 'Type', | 'type' => 'Type', | ||||
return $this->order; | 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 | * Getters / setters | ||||
*/ | */ |
<?php | <?php | ||||
namespace common\logic\User\CreditHistory\Repository; | |||||
namespace common\logic\Payment\Repository; | |||||
use common\logic\AbstractRepository; | use common\logic\AbstractRepository; | ||||
use common\logic\Order\Order\Model\Order; | 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 | public function loadDependencies(): void | ||||
{ | { | ||||
$this->loadQuery(CreditHistoryRepositoryQuery::class); | |||||
$this->loadQuery(PaymentRepositoryQuery::class); | |||||
} | } | ||||
public function getDefaultOptionsSearch(): array | public function getDefaultOptionsSearch(): array | ||||
return [ | return [ | ||||
self::WITH => [], | self::WITH => [], | ||||
self::JOIN_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' | |||||
]; | ]; | ||||
} | } | ||||
<?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; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?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) . ' €'; | |||||
} 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'; | |||||
} | |||||
} | |||||
} |
<?php | <?php | ||||
namespace common\logic\User\CreditHistory\Service; | |||||
namespace common\logic\Payment\Service; | |||||
use common\helpers\MeanPayment; | use common\helpers\MeanPayment; | ||||
use common\logic\AbstractService; | use common\logic\AbstractService; | ||||
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\Order\Order\Service\OrderSolver; | use common\logic\Order\Order\Service\OrderSolver; | ||||
use common\logic\Payment\Model\Payment; | |||||
use common\logic\Producer\Producer\Repository\ProducerRepository; | 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\Model\User; | ||||
use common\logic\User\User\Repository\UserRepository; | use common\logic\User\User\Repository\UserRepository; | ||||
use common\logic\UtilsInterface; | use common\logic\UtilsInterface; | ||||
use yii\base\ErrorException; | 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 OrderSolver $orderSolver; | ||||
protected ProducerRepository $producerRepository; | protected ProducerRepository $producerRepository; | ||||
protected UserRepository $userRepository; | protected UserRepository $userRepository; | ||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->creditHistoryBuilder = $this->loadService(CreditHistoryBuilder::class); | |||||
$this->paymentBuilder = $this->loadService(PaymentBuilder::class); | |||||
$this->orderSolver = $this->loadService(OrderSolver::class); | $this->orderSolver = $this->loadService(OrderSolver::class); | ||||
$this->producerRepository = $this->loadService(ProducerRepository::class); | $this->producerRepository = $this->loadService(ProducerRepository::class); | ||||
$this->userRepository = $this->loadService(UserRepository::class); | $this->userRepository = $this->loadService(UserRepository::class); | ||||
public function creditUser(User $user, float $amount, string $meanPayment, User $userAction): void | 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, | $amount, | ||||
$this->getProducerContext(), | $this->getProducerContext(), | ||||
$user, | $user, | ||||
public function debitUser(User $user, float $amount, string $meanPayment, User $userAction): void | 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, | $amount, | ||||
$this->getProducerContext(), | $this->getProducerContext(), | ||||
$user, | $user, | ||||
public function creditOrDebitUser(string $type, User $user, float $amount, string $meanPayment, User $userAction): void | 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); | $this->creditUser($user, $amount, $meanPayment, $userAction); | ||||
} | } | ||||
elseif($type == CreditHistory::TYPE_DEBIT) { | |||||
elseif($type == Payment::TYPE_DEBIT) { | |||||
$this->debitUser($user, $amount, $meanPayment, $userAction); | $this->debitUser($user, $amount, $meanPayment, $userAction); | ||||
} | } | ||||
else { | else { | ||||
} | } | ||||
} | } | ||||
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); | $amountRemaining = $this->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_REMAINING); | ||||
} | } | ||||
if($amountRemaining > 0) { | if($amountRemaining > 0) { | ||||
$this->creditHistoryBuilder->createCreditHistory( | |||||
CreditHistory::TYPE_PAYMENT, | |||||
$this->paymentBuilder->createPayment( | |||||
Payment::TYPE_PAYMENT, | |||||
$amountRemaining, | $amountRemaining, | ||||
$this->getProducerContext(), | $this->getProducerContext(), | ||||
$order->user, | $order->user, | ||||
public function refundOrder(Order $order, User $userAction): void | 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->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_PAID), | ||||
$this->getProducerContext(), | $this->getProducerContext(), | ||||
$order->user, | $order->user, | ||||
public function refundSurplusOrder(Order $order, User $userAction): void | 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->orderSolver->getOrderAmountWithTax($order, Order::AMOUNT_SURPLUS), | ||||
$this->getProducerContext(), | $this->getProducerContext(), | ||||
$order->user, | $order->user, | ||||
); | ); | ||||
} | } | ||||
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); | $this->refundOrder($order, $userAction); | ||||
} | } | ||||
else { | else { |
<?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(); | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?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) . ' €'; | |||||
} 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'; | |||||
} | |||||
} | |||||
} |
<?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(); | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
use justcoded\yii2\eventlistener\observers\ActiveRecordObserver; | use justcoded\yii2\eventlistener\observers\ActiveRecordObserver; | ||||
use yii\db\AfterSaveEvent; | use yii\db\AfterSaveEvent; | ||||
class CreditHistoryObserver extends ActiveRecordObserver | |||||
class PaymentObserver extends ActiveRecordObserver | |||||
{ | { | ||||
public function inserted(AfterSaveEvent $event) | public function inserted(AfterSaveEvent $event) | ||||
{ | { | ||||
$creditHistory = $event->sender; | |||||
$payment = $event->sender; | |||||
$userProducerManager = UserProducerManager::getInstance(); | $userProducerManager = UserProducerManager::getInstance(); | ||||
$userProducerManager->updateCredit($creditHistory); | |||||
$userProducerManager->updateCredit($payment); | |||||
} | } | ||||
} | } |
use common\logic\Order\Order\Model\Order; | use common\logic\Order\Order\Model\Order; | ||||
use common\logic\Order\Order\Repository\OrderRepository; | use common\logic\Order\Order\Repository\OrderRepository; | ||||
use common\logic\Order\Order\Service\OrderSolver; | 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\Model\Producer; | ||||
use common\logic\Producer\Producer\Repository\ProducerRepository; | 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\Model\User; | ||||
use common\logic\User\User\Repository\UserRepository; | |||||
use common\logic\User\UserProducer\Model\UserProducer; | use common\logic\User\UserProducer\Model\UserProducer; | ||||
use common\logic\User\UserProducer\Repository\UserProducerRepository; | use common\logic\User\UserProducer\Repository\UserProducerRepository; | ||||
class UserProducerBuilder extends AbstractBuilder | class UserProducerBuilder extends AbstractBuilder | ||||
{ | { | ||||
protected CreditHistorySolver $creditHistorySolver; | |||||
protected PaymentSolver $paymentSolver; | |||||
protected UserProducerRepository $userProducerRepository; | protected UserProducerRepository $userProducerRepository; | ||||
protected OrderRepository $orderRepository; | protected OrderRepository $orderRepository; | ||||
protected ProducerRepository $producerRepository; | protected ProducerRepository $producerRepository; | ||||
protected OrderSolver $orderSolver; | protected OrderSolver $orderSolver; | ||||
protected UserRepository $userRepository; | |||||
public function loadDependencies(): void | public function loadDependencies(): void | ||||
{ | { | ||||
$this->creditHistorySolver = $this->loadService(CreditHistorySolver::class); | |||||
$this->paymentSolver = $this->loadService(PaymentSolver::class); | |||||
$this->userProducerRepository = $this->loadService(UserProducerRepository::class); | $this->userProducerRepository = $this->loadService(UserProducerRepository::class); | ||||
$this->orderRepository = $this->loadService(OrderRepository::class); | $this->orderRepository = $this->loadService(OrderRepository::class); | ||||
$this->producerRepository = $this->loadService(ProducerRepository::class); | $this->producerRepository = $this->loadService(ProducerRepository::class); | ||||
$this->orderSolver = $this->loadService(OrderSolver::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) | public function instanciateUserProducer(User $user, Producer $producer, bool $bookmark = true, bool $newsletter = true) | ||||
?? $this->createUserProducer($user, $producer, $bookmark, $newsletter); | ?? $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) { | if ($userProducer) { | ||||
$oldCredit = $userProducer->getCredit(); | $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); | $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) { | if ($order) { | ||||
$paymentStatus = $this->orderSolver->getPaymentStatus($order); | $paymentStatus = $this->orderSolver->getPaymentStatus($order); | ||||
} | } | ||||
} | } | ||||
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; | $newCredit = $userProducer->credit; | ||||
if ($this->isCreditLimitCrossed($oldCredit, $newCredit)) { | 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) { | if($user && $user->email && strlen($user->email) > 0) { | ||||
\Yii::$app->mailer->compose( | \Yii::$app->mailer->compose( |
termes. | termes. | ||||
*/ | */ | ||||
use common\logic\Payment\Model\Payment; | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||||
?> | ?> | ||||
<p>Bonjour <?= Html::encode($user->name); ?>,</p> | <p>Bonjour <?= Html::encode($user->name); ?>,</p> | ||||
<p>Votre producteur <strong><?= Html::encode($producer->name); ?></strong> vient | <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 /> | <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> | <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>">Cliquez ici</a> pour voir l'historique de votre crédit.</p> |
*/ | */ | ||||
use common\helpers\Price ; | use common\helpers\Price ; | ||||
use common\logic\User\CreditHistory\Model\CreditHistory; | |||||
use common\logic\Payment\Model\Payment; | |||||
?> | ?> | ||||
Bonjour <?= $user->name; ?>,</p> | 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); ?>. | 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]) ?>"> | Suivez ce lien pour voir l'historique de votre crédit : <?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['credit/history','slug_producer' => $producer->slug]) ?>"> |
<?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'); | |||||
} | |||||
} |
namespace producer\controllers; | namespace producer\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Mailjet; | |||||
use common\helpers\MeanPayment; | 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 producer\models\CreditForm; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
public function actionStripeVerification() | public function actionStripeVerification() | ||||
{ | { | ||||
$orderManager = $this->getOrderManager(); | $orderManager = $this->getOrderManager(); | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$producerManager = $this->getProducerManager(); | $producerManager = $this->getProducerManager(); | ||||
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
$producer = $this->getProducerCurrent(); | $producer = $this->getProducerCurrent(); | ||||
switch ($event->type) { | switch ($event->type) { | ||||
case 'charge.succeeded': | case 'charge.succeeded': | ||||
$creditHistoryExist = CreditHistory::searchOne([ | |||||
$paymentExist = Payment::searchOne([ | |||||
'id_user' => $idUser, | 'id_user' => $idUser, | ||||
'amount' => $amount, | 'amount' => $amount, | ||||
], [ | ], [ | ||||
] | ] | ||||
]); | ]); | ||||
if (!$creditHistoryExist) { | |||||
if (!$paymentExist) { | |||||
$creditHistoryManager->creditUser($user, $amount, MeanPayment::CREDIT_CARD, $user); | |||||
$paymentManager->creditUser($user, $amount, MeanPayment::CREDIT_CARD, $user); | |||||
if (isset($order) && $order) { | if (isset($order) && $order) { | ||||
$creditHistoryManager->payOrder($order, $user, true); | |||||
$paymentManager->payOrder($order, $user, true); | |||||
// client : envoi d'un email de confirmation de paiement | // client : envoi d'un email de confirmation de paiement |
$producerManager = $this->getProducerManager(); | $producerManager = $this->getProducerManager(); | ||||
$productOrderManager = $this->getProductOrderManager(); | $productOrderManager = $this->getProductOrderManager(); | ||||
$userManager = $this->getUserManager(); | $userManager = $this->getUserManager(); | ||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$paymentManager = $this->getPaymentManager(); | |||||
$posts = \Yii::$app->request->post(); | $posts = \Yii::$app->request->post(); | ||||
$productsArray = []; | $productsArray = []; | ||||
)) { | )) { | ||||
// à payer | // à payer | ||||
if ($orderManager->getPaymentStatus($order) == Order::PAYMENT_UNPAID) { | if ($orderManager->getPaymentStatus($order) == Order::PAYMENT_UNPAID) { | ||||
$creditHistoryManager->payOrder($order, $this->getUserCurrent(), true); | |||||
$paymentManager->payOrder($order, $this->getUserCurrent(), true); | |||||
} // surplus à rembourser | } // surplus à rembourser | ||||
elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) { | elseif ($orderManager->getPaymentStatus($order) == Order::PAYMENT_SURPLUS) { | ||||
$creditHistoryManager->refundSurplusOrder($order, $this->getUserCurrent()); | |||||
$paymentManager->refundSurplusOrder($order, $this->getUserCurrent()); | |||||
} | } | ||||
} | } | ||||
* termes. | * termes. | ||||
*/ | */ | ||||
use common\logic\User\CreditHistory\Wrapper\CreditHistoryManager; | |||||
use common\logic\Payment\Wrapper\PaymentManager; | |||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
$creditHistoryManager = CreditHistoryManager::getInstance(); | |||||
$paymentManager = PaymentManager::getInstance(); | |||||
$producer = $this->context->getProducerCurrent(); | $producer = $this->context->getProducerCurrent(); | ||||
$this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); | $this->setTitle('Crédit : <span id="credit-user">' . number_format($creditUser, 2) . ' €</span>'); | ||||
$this->setPageTitle('Crédit'); | $this->setPageTitle('Crédit'); | ||||
'columns' => [ | 'columns' => [ | ||||
[ | [ | ||||
'attribute' => 'date', | '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', | 'attribute' => 'id_user_action', | ||||
'value' => function ($model) use ($creditHistoryManager) { | |||||
return $creditHistoryManager->getStrUserAction($model); | |||||
'value' => function ($model) use ($paymentManager) { | |||||
return $paymentManager->getStrUserAction($model); | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'label' => 'Type', | 'label' => 'Type', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($model) use ($creditHistoryManager) { | |||||
return $creditHistoryManager->getStrWording($model); | |||||
'value' => function ($model) use ($paymentManager) { | |||||
return $paymentManager->getStrWording($model); | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'mean_payment', | 'attribute' => 'mean_payment', | ||||
'value' => function ($model) use ($creditHistoryManager) { | |||||
return $creditHistoryManager->getStrMeanPayment($model); | |||||
'value' => function ($model) use ($paymentManager) { | |||||
return $paymentManager->getStrMeanPayment($model); | |||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'label' => '- Débit', | 'label' => '- Débit', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($model) use ($creditHistoryManager) { | |||||
if ($creditHistoryManager->isTypeDebit($model)) { | |||||
return '- ' . $creditHistoryManager->getAmount($model, true); | |||||
'value' => function ($model) use ($paymentManager) { | |||||
if ($paymentManager->isTypeDebit($model)) { | |||||
return '- ' . $paymentManager->getAmount($model, true); | |||||
} | } | ||||
return ''; | return ''; | ||||
} | } | ||||
[ | [ | ||||
'label' => '+ Crédit', | 'label' => '+ Crédit', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function ($model) use ($creditHistoryManager) { | |||||
if ($creditHistoryManager->isTypeCredit($model)) { | |||||
return '+ ' . $creditHistoryManager->getAmount($model, true); | |||||
'value' => function ($model) use ($paymentManager) { | |||||
if ($paymentManager->isTypeCredit($model)) { | |||||
return '+ ' . $paymentManager->getAmount($model, true); | |||||
} | } | ||||
return ''; | return ''; | ||||
} | } |