|
|
@@ -40,6 +40,7 @@ namespace producer\controllers; |
|
|
|
|
|
|
|
use common\helpers\GlobalParam; |
|
|
|
use common\helpers\Mailjet; |
|
|
|
use common\logic\Order\Order\Order; |
|
|
|
use common\logic\Producer\Producer\Producer; |
|
|
|
use common\logic\User\CreditHistory\CreditHistory; |
|
|
|
use common\logic\User\User\User; |
|
|
@@ -57,7 +58,7 @@ class OrderController extends ProducerBaseController |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionOrder($id = 0, $date = '') |
|
|
|
public function actionOrder(int $id = 0, $date = '') |
|
|
|
{ |
|
|
|
$params = []; |
|
|
|
$producer = $this->getProducer(); |
|
|
@@ -69,24 +70,16 @@ class OrderController extends ProducerBaseController |
|
|
|
} |
|
|
|
|
|
|
|
if ($id) { |
|
|
|
$order = Order::searchOne([ |
|
|
|
'id' => $id |
|
|
|
]); |
|
|
|
if ($order) { |
|
|
|
if ($order->getState() == Order::STATE_OPEN) { |
|
|
|
$params['order'] = $order; |
|
|
|
} |
|
|
|
$order = $this->getOrderContainer()->getRepository()->getOneById($id); |
|
|
|
if ($order && $this->getOrderContainer()->getSolver()->isStateOpen($order)) { |
|
|
|
$params['order'] = $order; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (strlen($date)) { |
|
|
|
$distribution = DistributionModel::searchOne([ |
|
|
|
'date' => $date, |
|
|
|
'id_producer' => $producer->id |
|
|
|
]); |
|
|
|
|
|
|
|
$distribution = $this->getDistributionContainer()->getRepository()->getOne($producer, $date); |
|
|
|
if ($distribution) { |
|
|
|
$distributionsArray = DistributionModel::filterDistributionsByDateDelay([$distribution]); |
|
|
|
$distributionsArray = $this->getDistributionContainer()->getSolver()->filterDistributionsByDateDelay([$distribution]); |
|
|
|
if (count($distributionsArray) == 1) { |
|
|
|
$params['date'] = $date; |
|
|
|
} |
|
|
@@ -107,7 +100,7 @@ class OrderController extends ProducerBaseController |
|
|
|
->with('productOrder', 'pointSale', 'creditHistory') |
|
|
|
->joinWith('distribution', 'distribution.producer') |
|
|
|
->where([ |
|
|
|
'id_user' => Yii::$app->user->id, |
|
|
|
'id_user' => $this->getUserCurrent()->id, |
|
|
|
'distribution.id_producer' => $producer->id |
|
|
|
]) |
|
|
|
->params([':date_today' => date('Y-m-d')]); |
|
|
@@ -137,25 +130,22 @@ class OrderController extends ProducerBaseController |
|
|
|
|
|
|
|
/** |
|
|
|
* Supprime un producteur. |
|
|
|
* |
|
|
|
* @param integer $id |
|
|
|
*/ |
|
|
|
public function actionRemoveProducer($id = 0) |
|
|
|
public function actionRemoveProducer(int $id = 0) |
|
|
|
{ |
|
|
|
$userProducer = UserProducer::find() |
|
|
|
->where(['id_producer' => $id, 'id_user' => GlobalParam::getCurrentUserId()]) |
|
|
|
->one(); |
|
|
|
$producer = $this->getProducerContainer()->getRepository()->getOneById($id); |
|
|
|
|
|
|
|
$userProducer->active = 0; |
|
|
|
$userProducer->save(); |
|
|
|
$this->getUserProducerContainer()->getBuilder()->updateActive( |
|
|
|
$this->getUserCurrent(), |
|
|
|
$producer, |
|
|
|
false |
|
|
|
); |
|
|
|
|
|
|
|
$this->redirect(['order/index']); |
|
|
|
return $this->redirect(['order/index']); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Crée une commande. |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionAjaxProcess() |
|
|
|
{ |
|
|
@@ -165,14 +155,14 @@ class OrderController extends ProducerBaseController |
|
|
|
$producer = $this->getProducer(); |
|
|
|
$idProducer = $producer->id; |
|
|
|
|
|
|
|
$posts = Yii::$app->request->post(); |
|
|
|
$posts = \Yii::$app->request->post(); |
|
|
|
|
|
|
|
if ($idProducer) { |
|
|
|
$this->_verifyProducerActive($idProducer); |
|
|
|
} |
|
|
|
|
|
|
|
if ($order->load($posts)) { |
|
|
|
$user = User::getCurrent(); |
|
|
|
$user = $this->getUserCurrent(); |
|
|
|
|
|
|
|
$order = Order::find() |
|
|
|
->where('id_distribution = :id_distribution') |
|
|
@@ -312,9 +302,6 @@ class OrderController extends ProducerBaseController |
|
|
|
|
|
|
|
/** |
|
|
|
* Vérifie si un producteur est actif. |
|
|
|
* |
|
|
|
* @param integer $idProducer |
|
|
|
* @throws NotFoundHttpException |
|
|
|
*/ |
|
|
|
public function _verifyProducerActive($idProducer) |
|
|
|
{ |
|
|
@@ -326,12 +313,10 @@ class OrderController extends ProducerBaseController |
|
|
|
|
|
|
|
/** |
|
|
|
* Traite le formulaire de création/modification de commande. |
|
|
|
* |
|
|
|
* @param Commande $order |
|
|
|
*/ |
|
|
|
public function processForm($order, $user) |
|
|
|
{ |
|
|
|
$posts = Yii::$app->request->post(); |
|
|
|
$posts = \Yii::$app->request->post(); |
|
|
|
$productsArray = []; |
|
|
|
$totalQuantity = 0; |
|
|
|
$producer = $this->getProducer(); |