|
|
@@ -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(); |
|
|
|
} |
|
|
|
} |