foreach ($order->creditHistory as $creditHistory) { | foreach ($order->creditHistory as $creditHistory) { | ||||
$creditHistoryArray[] = [ | $creditHistoryArray[] = [ | ||||
'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), | 'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), | ||||
'user' => $creditHistory->user->getUsername(), | |||||
'user_action' => $creditHistory->strUserAction(), | 'user_action' => $creditHistory->strUserAction(), | ||||
'wording' => $creditHistory->getStrWording(), | 'wording' => $creditHistory->getStrWording(), | ||||
'debit' => ($creditHistory->isTypeDebit() ? '- ' . $creditHistory->getAmount( | 'debit' => ($creditHistory->isTypeDebit() ? '- ' . $creditHistory->getAmount( |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\models\CreditHistory; | |||||
use common\models\Order; | use common\models\Order; | ||||
use common\models\ProductOrder; | use common\models\ProductOrder; | ||||
use common\models\Product; | use common\models\Product; | ||||
if ($order && | if ($order && | ||||
$order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | $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; | $userProducer = false; | ||||
if (isset($order->user) && $order->user) { | |||||
$user = $order->user; | |||||
if ($user) { | |||||
$userProducer = UserProducer::searchOne([ | $userProducer = UserProducer::searchOne([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_producer' => $order->distribution->id_producer | 'id_producer' => $order->distribution->id_producer | ||||
$order->mean_payment = $meanPayment; | $order->mean_payment = $meanPayment; | ||||
$order->comment = $comment; | $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->save(); | ||||
$order = Order::searchOne(['id' => $order->id]); | $order = Order::searchOne(['id' => $order->id]); | ||||
if ($order && $processCredit) { | 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(); | $order->processCredit(); | ||||
} | } | ||||
} | } |
<td>Date</td> | <td>Date</td> | ||||
<td>Utilisateur</td> | <td>Utilisateur</td> | ||||
<td>Action</td> | <td>Action</td> | ||||
<td>Origine action</td> | |||||
<td>- Débit</td> | <td>- Débit</td> | ||||
<td>+ Crédit</td> | <td>+ Crédit</td> | ||||
</tr> | </tr> | ||||
<tbody> | <tbody> | ||||
<tr v-for="creditHistory in order.creditHistory"> | <tr v-for="creditHistory in order.creditHistory"> | ||||
<td>{{ creditHistory.date }}</td> | <td>{{ creditHistory.date }}</td> | ||||
<td>{{ creditHistory.user_action }}</td> | |||||
<td>{{ creditHistory.user }}</td> | |||||
<td v-html="creditHistory.wording"></td> | <td v-html="creditHistory.wording"></td> | ||||
<td>{{ creditHistory.user_action }}</td> | |||||
<td v-html="creditHistory.debit"></td> | <td v-html="creditHistory.debit"></td> | ||||
<td v-html="creditHistory.credit"></td> | <td v-html="creditHistory.credit"></td> | ||||
</tr> | </tr> |
public function saveCreditHistory($type, $amount, $idProducer, $idUser, $idUserAction) | public function saveCreditHistory($type, $amount, $idProducer, $idUser, $idUserAction) | ||||
{ | { | ||||
$creditHistory = new CreditHistory; | $creditHistory = new CreditHistory; | ||||
$creditHistory->id_user = $this->id_user; | |||||
$creditHistory->id_user = $idUser; | |||||
$creditHistory->id_order = $this->id; | $creditHistory->id_order = $this->id; | ||||
$creditHistory->amount = $amount; | $creditHistory->amount = $amount; | ||||
$creditHistory->type = $type; | $creditHistory->type = $type; | ||||
if ($this->id_user) { | if ($this->id_user) { | ||||
$paymentStatus = $this->getPaymentStatus(); | $paymentStatus = $this->getPaymentStatus(); | ||||
echo $paymentStatus; | |||||
if ($paymentStatus == self::PAYMENT_PAID) { | if ($paymentStatus == self::PAYMENT_PAID) { | ||||
return true; | return true; | ||||
} elseif ($paymentStatus == self::PAYMENT_SURPLUS) { | } elseif ($paymentStatus == self::PAYMENT_SURPLUS) { |