Bladeren bron

[Administration] Distributions > formulaire commande : bug crédit lors du changement de l'utilisateur d'une commande #141

refactoring
Guillaume Bourgeois 2 jaren geleden
bovenliggende
commit
20b06c0951
4 gewijzigde bestanden met toevoegingen van 42 en 23 verwijderingen
  1. +1
    -0
      backend/controllers/DistributionController.php
  2. +35
    -21
      backend/controllers/OrderController.php
  3. +3
    -1
      backend/views/distribution/index.php
  4. +3
    -1
      common/models/Order.php

+ 1
- 0
backend/controllers/DistributionController.php Bestand weergeven

@@ -274,6 +274,7 @@ class DistributionController extends BackendController
foreach ($order->creditHistory as $creditHistory) {
$creditHistoryArray[] = [
'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)),
'user' => $creditHistory->user->getUsername(),
'user_action' => $creditHistory->strUserAction(),
'wording' => $creditHistory->getStrWording(),
'debit' => ($creditHistory->isTypeDebit() ? '- ' . $creditHistory->getAmount(

+ 35
- 21
backend/controllers/OrderController.php Bestand weergeven

@@ -39,6 +39,7 @@
namespace backend\controllers;

use common\helpers\GlobalParam;
use common\models\CreditHistory;
use common\models\Order;
use common\models\ProductOrder;
use common\models\Product;
@@ -940,10 +941,28 @@ class OrderController extends BackendController
if ($order &&
$order->distribution->id_producer == GlobalParam::getCurrentProducerId()) {

$user = false;
$oldIdUser = $order->id_user;
if ($idUser) {
$order->username = '';
$order->id_user = $idUser;

// commentaire du point de vente
$userPointSale = UserPointSale::searchOne([
'id_point_sale' => $order->id_point_sale,
'id_user' => $idUser
]);

if ($userPointSale && strlen($userPointSale->comment)) {
$order->comment_point_sale = $userPointSale->comment;
}
} else {
$order->username = $username;
$order->id_user = 0;
}

$user = User::searchOne(['id' => $order->id_user]);
$userProducer = false;
if (isset($order->user) && $order->user) {
$user = $order->user;
if ($user) {
$userProducer = UserProducer::searchOne([
'id_user' => $user->id,
'id_producer' => $order->distribution->id_producer
@@ -1002,28 +1021,23 @@ class OrderController extends BackendController
$order->mean_payment = $meanPayment;
$order->comment = $comment;

if ($idUser) {
$order->username = '';
$order->id_user = $idUser;

// commentaire du point de vente
$userPointSale = UserPointSale::searchOne([
'id_point_sale' => $order->id_point_sale,
'id_user' => $idUser
]);

if ($userPointSale && strlen($userPointSale->comment)) {
$order->comment_point_sale = $userPointSale->comment;
}
} else {
$order->username = $username;
$order->id_user = 0;
}

$order->save();

$order = Order::searchOne(['id' => $order->id]);
if ($order && $processCredit) {
// Si changement d'user : on rembourse l'ancien user
$amountPaid = $order->getAmount(Order::AMOUNT_PAID);
if($oldIdUser != $idUser && $amountPaid > 0) {
$order->saveCreditHistory(
CreditHistory::TYPE_REFUND,
$amountPaid,
GlobalParam::getCurrentProducerId(),
$oldIdUser,
User::getCurrentId()
);
$order = Order::searchOne(['id' => $order->id]);
}

$order->processCredit();
}
}

+ 3
- 1
backend/views/distribution/index.php Bestand weergeven

@@ -507,6 +507,7 @@ $this->setPageTitle('Distributions') ;
<td>Date</td>
<td>Utilisateur</td>
<td>Action</td>
<td>Origine action</td>
<td>- Débit</td>
<td>+ Crédit</td>
</tr>
@@ -514,8 +515,9 @@ $this->setPageTitle('Distributions') ;
<tbody>
<tr v-for="creditHistory in order.creditHistory">
<td>{{ creditHistory.date }}</td>
<td>{{ creditHistory.user_action }}</td>
<td>{{ creditHistory.user }}</td>
<td v-html="creditHistory.wording"></td>
<td>{{ creditHistory.user_action }}</td>
<td v-html="creditHistory.debit"></td>
<td v-html="creditHistory.credit"></td>
</tr>

+ 3
- 1
common/models/Order.php Bestand weergeven

@@ -552,7 +552,7 @@ class Order extends ActiveRecordCommon
public function saveCreditHistory($type, $amount, $idProducer, $idUser, $idUserAction)
{
$creditHistory = new CreditHistory;
$creditHistory->id_user = $this->id_user;
$creditHistory->id_user = $idUser;
$creditHistory->id_order = $this->id;
$creditHistory->amount = $amount;
$creditHistory->type = $type;
@@ -573,6 +573,8 @@ class Order extends ActiveRecordCommon
if ($this->id_user) {
$paymentStatus = $this->getPaymentStatus();

echo $paymentStatus;

if ($paymentStatus == self::PAYMENT_PAID) {
return true;
} elseif ($paymentStatus == self::PAYMENT_SURPLUS) {

Laden…
Annuleren
Opslaan