@@ -42,6 +42,10 @@ use common\helpers\GlobalParam; | |||
use backend\models\AccessUserProducerForm; | |||
use common\logic\Document\DeliveryNote\DeliveryNoteManager; | |||
use common\logic\Producer\Producer\ProducerManager; | |||
use common\logic\User\User\User; | |||
use common\logic\User\User\UserSearch; | |||
use yii\filters\AccessControl; | |||
use yii\filters\VerbFilter; | |||
/** | |||
* UserController implements the CRUD actions for User model. | |||
@@ -53,12 +57,12 @@ class AccessController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -80,22 +84,16 @@ class AccessController extends BackendController | |||
*/ | |||
public function actionIndex() | |||
{ | |||
$userSearch = new UserSearch; | |||
$userSearch = new UserSearch(); | |||
$usersArray = $userSearch->search()->query->all(); | |||
$modelAccessUserProducerForm = new AccessUserProducerForm; | |||
if ($modelAccessUserProducerForm->load(Yii::$app->request->post()) && $modelAccessUserProducerForm->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | |||
if ($modelAccessUserProducerForm->load(\Yii::$app->request->post()) && $modelAccessUserProducerForm->save()) { | |||
$this->setFlash('success', 'Droits ajoutés à l\'utilisateur'); | |||
} | |||
$usersAccessArray = User::find() | |||
->where([ | |||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||
'status' => User::STATUS_PRODUCER | |||
]) | |||
->all(); | |||
$producer = Producer::searchOne(); | |||
$producer = $this->getProducerCurrent(); | |||
$usersAccessArray = $this->getUserManager()->findUsersByProducer($producer->id); | |||
return $this->render('index', [ | |||
'usersArray' => $usersArray, | |||
@@ -107,18 +105,14 @@ class AccessController extends BackendController | |||
public function actionDelete($idUser) | |||
{ | |||
$user = User::searchOne([ | |||
'id' => $idUser | |||
]); | |||
$userManager = $this->getUserManager(); | |||
$user = $userManager->findOneUserById($idUser); | |||
if ($user) { | |||
$user->id_producer = 0; | |||
$user->status = User::STATUS_ACTIVE; | |||
$user->save(); | |||
Yii::$app->getSession()->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | |||
$userManager->deleteAccess($user); | |||
$this->setFlash('success', 'Droits de l\'utilisateur supprimé.'); | |||
} | |||
return $this->redirect(['index']); | |||
} | |||
} |
@@ -39,6 +39,7 @@ | |||
namespace backend\controllers; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\Producer\Producer\Producer; | |||
use common\logic\Product\Product\Product; | |||
use common\controllers\CommonController; | |||
@@ -55,6 +56,10 @@ class BackendController extends CommonController | |||
} | |||
} | |||
public function getProducerCurrent(): Producer | |||
{ | |||
return Producer::searchOne(); | |||
} | |||
} | |||
?> |
@@ -39,8 +39,10 @@ | |||
namespace backend\controllers; | |||
use backend\models\MailForm; | |||
use common\logic\User\User\User; | |||
use yii\filters\AccessControl; | |||
use yii\filters\VerbFilter; | |||
use yii\web\NotFoundHttpException; | |||
use common\models\ User; | |||
/** | |||
* UserController implements the CRUD actions for User model. | |||
@@ -52,19 +54,19 @@ class CommunicateAdminController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
'delete' => ['post'], | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||
return $this->getUserManager()->isCurrentAdmin(); | |||
} | |||
] | |||
], | |||
@@ -72,15 +74,13 @@ class CommunicateAdminController extends BackendController | |||
]; | |||
} | |||
/** | |||
* | |||
* | |||
* @return mixed | |||
*/ | |||
public function actionIndex($section = 'producers') | |||
{ | |||
$producerManager = $this->getProducerManager(); | |||
$userManager = $this->getUserManager(); | |||
if ($section == 'producers') { | |||
$producers = Producer::find()->where(['producer.active' => 1])->with(['contact'])->all(); | |||
$producers = $producerManager->findProducersActive(); | |||
$usersArray = []; | |||
$users = []; | |||
foreach ($producers as $producer) { | |||
@@ -96,11 +96,7 @@ class CommunicateAdminController extends BackendController | |||
} | |||
} | |||
} elseif ($section == 'users') { | |||
$users = User::find() | |||
->where([ | |||
'user.status' => User::STATUS_ACTIVE | |||
]) | |||
->all(); | |||
$users = $userManager->findUsersByStatus(User::STATUS_ACTIVE); | |||
$usersArray = []; | |||
foreach ($users as $user) { | |||
if (isset($user['email']) && strlen($user['email'])) { | |||
@@ -112,12 +108,12 @@ class CommunicateAdminController extends BackendController | |||
} | |||
$mailForm = new MailForm(); | |||
if ($mailForm->load(Yii::$app->request->post()) && $mailForm->validate()) { | |||
if ($mailForm->load(\Yii::$app->request->post()) && $mailForm->validate()) { | |||
$resultSendEmail = $mailForm->sendEmail($users, false); | |||
if ($resultSendEmail) { | |||
Yii::$app->getSession()->setFlash('success', 'Votre email a bien été envoyé.'); | |||
$this->setFlash('success', 'Votre email a bien été envoyé.'); | |||
} else { | |||
Yii::$app->getSession()->setFlash('error', 'Un problème est survenu lors de l\'envoi de votre email.'); | |||
$this->setFlash('error', 'Un problème est survenu lors de l\'envoi de votre email.'); | |||
} | |||
$mailForm->subject = ''; | |||
$mailForm->message = ''; |
@@ -38,6 +38,10 @@ | |||
namespace backend\controllers; | |||
use kartik\mpdf\Pdf; | |||
use yii\filters\AccessControl; | |||
use yii\filters\VerbFilter; | |||
/** | |||
* UserController implements the CRUD actions for User model. | |||
*/ | |||
@@ -48,13 +52,13 @@ class CommunicateController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
'delete' => ['post'], | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -71,13 +75,11 @@ class CommunicateController extends BackendController | |||
/** | |||
* Affiche la page d'accueil de la section avec un aperçu du mpde d'emploi | |||
* à imprimer. | |||
* | |||
* @return string | |||
*/ | |||
public function actionIndex() | |||
{ | |||
$producer = Producer::searchOne(); | |||
$pointsSaleArray = PointSale::searchAll(); | |||
$producer = $this->getProducerCurrent(); | |||
$pointsSaleArray = $this->getPointSaleManager()->findPointSales(); | |||
return $this->render('index', [ | |||
'producer' => $producer, | |||
@@ -93,7 +95,7 @@ class CommunicateController extends BackendController | |||
*/ | |||
public function actionInstructions() | |||
{ | |||
$producer = Producer::searchOne(); | |||
$producer = $this->getProducerCurrent(); | |||
// get your HTML raw content without any layouts or scripts | |||
$content = $this->renderPartial('instructions_multi', [ |
@@ -38,6 +38,10 @@ | |||
namespace backend\controllers; | |||
use common\logic\Order\Order\Order; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\User\CreditHistory\CreditHistory; | |||
use common\logic\User\User\User; | |||
use Yii; | |||
use yii\filters\VerbFilter; | |||
use yii\filters\AccessControl; | |||
@@ -51,13 +55,13 @@ class CronController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
'delete' => ['post'], | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -98,8 +102,9 @@ class CronController extends BackendController | |||
} | |||
if ($activeDistribution) { | |||
$distribution = DistributionModel::initDistribution(date('Y-m-d', $dateTime), $producer->id); | |||
$distribution->active(true); | |||
$distributionManager = $this->getDistributionManager(); | |||
$distribution = $distributionManager->createDistributionIfNotExist($producer, date('Y-m-d', $dateTime)); | |||
$distributionManager->activeDistribution($distribution); | |||
} | |||
} | |||
} | |||
@@ -136,6 +141,12 @@ class CronController extends BackendController | |||
*/ | |||
public function actionProcessOrders($key = '', $forceDate = '') | |||
{ | |||
$producerManager = $this->getProducerManager(); | |||
$distributionManager = $this->getDistributionManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||
$userManager = $this->getUserManager(); | |||
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { | |||
ini_set('memory_limit', '-1'); | |||
set_time_limit(0); | |||
@@ -157,18 +168,12 @@ class CronController extends BackendController | |||
$date = date('Y-m-d', time() + 24 * 60 * 60); | |||
} | |||
} | |||
$arrayProducers = Producer::searchAll(); | |||
$arrayProducers = $producerManager->findProducers(); | |||
foreach ($arrayProducers as $producer) { | |||
$countOrders = 0; | |||
$mailOrdersSend = false; | |||
$distribution = DistributionModel::findOne([ | |||
'date' => $date, | |||
'active' => 1, | |||
'id_producer' => $producer->id, | |||
]); | |||
$distribution = $distributionManager->findOneDistribution($producer, $date, true); | |||
if ($distribution) { | |||
if ($hour == $producer->order_deadline || strlen($forceDate)) { | |||
@@ -183,18 +188,20 @@ class CronController extends BackendController | |||
'conditions' => 'date_delete IS NULL' | |||
]); | |||
$configCredit = Producer::getConfig('credit', $producer->id); | |||
$configCredit = $producerManager->getConfig('credit', $producer->id); | |||
if ($arrayOrders && is_array($arrayOrders)) { | |||
foreach ($arrayOrders as $order) { | |||
if ($order->auto_payment && $configCredit) { | |||
if ($order->getAmount(Order::AMOUNT_REMAINING) > 0) { | |||
$order->saveCreditHistory( | |||
if ($orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING) > 0) { | |||
$creditHistoryManager->createCreditHistory( | |||
CreditHistory::TYPE_PAYMENT, | |||
$order->getAmount(Order::AMOUNT_REMAINING), | |||
$order->distribution->id_producer, | |||
$order->id_user, | |||
User::ID_USER_SYSTEM | |||
$orderManager->getAmount($order, Order::AMOUNT_REMAINING), | |||
$order->distribution->producer, | |||
$order->user, | |||
$userManager->findOneUserById(User::ID_USER_SYSTEM), | |||
null, | |||
$order | |||
); | |||
$countOrders++; | |||
} | |||
@@ -206,7 +213,7 @@ class CronController extends BackendController | |||
* Envoi des commandes par email au producteur | |||
*/ | |||
if (!strlen($forceDate) && Producer::getConfig('option_notify_producer_order_summary', $producer->id)) { | |||
if (!strlen($forceDate) && $producerManager->getConfig('option_notify_producer_order_summary', $producer->id)) { | |||
$arrayOrders = Order::searchAll([ | |||
'distribution.date' => $date, | |||
'distribution.id_producer' => $producer->id | |||
@@ -226,7 +233,7 @@ class CronController extends BackendController | |||
->setFrom([Yii::$app->params['adminEmail'] => 'distrib']); | |||
if (is_array($arrayOrders) && count($arrayOrders)) { | |||
$subject = '[distrib] Commandes du ' . date('d/m', strtotime($date)); | |||
$subject = '[Opendistrib] Commandes du ' . date('d/m', strtotime($date)); | |||
// génération du pdf de commande | |||
Yii::$app->runAction('distribution/report-cron', [ | |||
@@ -239,7 +246,7 @@ class CronController extends BackendController | |||
Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $producer->id . '.pdf') | |||
); | |||
} else { | |||
$subject = '[distrib] Aucune commande'; | |||
$subject = '[Opendistrib] Aucune commande'; | |||
} | |||
$mail->setSubject($subject); |
@@ -38,7 +38,10 @@ | |||
namespace backend\controllers; | |||
use common\logic\Document\DeliveryNote\DeliveryNoteSearch; | |||
use Yii; | |||
use yii\filters\AccessControl; | |||
use yii\filters\VerbFilter; | |||
class DeliveryNoteController extends DocumentController | |||
@@ -47,12 +50,12 @@ class DeliveryNoteController extends DocumentController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -74,7 +77,7 @@ class DeliveryNoteController extends DocumentController | |||
public function actionIndex() | |||
{ | |||
$searchModel = new DeliveryNoteSearch(); | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, |
@@ -39,17 +39,18 @@ | |||
namespace backend\controllers; | |||
use common\helpers\GlobalParam; | |||
use common\helpers\Opendistrib; | |||
use common\logic\Development\Development\Development; | |||
use common\logic\Development\DevelopmentPriority\DevelopmentPriority; | |||
use Yii; | |||
use yii\data\ActiveDataProvider; | |||
use yii\web\Controller; | |||
use yii\web\NotFoundHttpException; | |||
use yii\filters\VerbFilter; | |||
use yii\filters\AccessControl; | |||
/** | |||
* DeveloppementController implements the CRUD actions for Developpement model. | |||
*/ | |||
class DevelopmentController extends Controller | |||
class DevelopmentController extends BackendController | |||
{ | |||
/** | |||
* @inheritdoc | |||
@@ -58,7 +59,7 @@ class DevelopmentController extends Controller | |||
{ | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -79,6 +80,7 @@ class DevelopmentController extends Controller | |||
*/ | |||
public function actionIndex() | |||
{ | |||
$producerManager = $this->getProducerManager(); | |||
$versionsArray = Opendistrib::getVersions(); | |||
$versionsRenderArray = []; | |||
foreach ($versionsArray as $version) { | |||
@@ -88,9 +90,8 @@ class DevelopmentController extends Controller | |||
]; | |||
} | |||
// Producer : set latest version d'Opendistrib | |||
$producer = GlobalParam::getCurrentProducer(); | |||
$producer->updateOpendistribVersion(); | |||
$producer = $this->getProducerCurrent(); | |||
$producerManager->updateOpendistribVersion($producer); | |||
return $this->render('index', [ | |||
'versionsArray' => $versionsRenderArray | |||
@@ -98,10 +99,10 @@ class DevelopmentController extends Controller | |||
} | |||
public function actionDevelopment($status = DevelopmentModel::STATUS_OPEN) | |||
public function actionDevelopment($status = Development::STATUS_OPEN) | |||
{ | |||
$dataProvider = new ActiveDataProvider([ | |||
'query' => DevelopmentModel::find() | |||
'query' => Development::find() | |||
->with(['developmentPriority', 'developmentPriorityCurrentProducer']) | |||
->where(['status' => $status]) | |||
->orderBy('date DESC'), | |||
@@ -116,17 +117,16 @@ class DevelopmentController extends Controller | |||
/** | |||
* Creates a new Developpement model. | |||
* If creation is successful, the browser will be redirected to the 'view' page. | |||
* @return mixed | |||
*/ | |||
public function actionCreate() | |||
{ | |||
$model = new Development(); | |||
if ($model->load(Yii::$app->request->post())) { | |||
if ($model->load(\Yii::$app->request->post())) { | |||
$model->date = date('Y-m-d H:i:s'); | |||
$model->setDateDelivery(); | |||
if ($model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Développement ajouté'); | |||
$this->setFlash('success', 'Développement ajouté'); | |||
return $this->redirect(['index']); | |||
} | |||
} else { | |||
@@ -147,10 +147,10 @@ class DevelopmentController extends Controller | |||
{ | |||
$model = $this->findModel($id); | |||
if ($model->load(Yii::$app->request->post())) { | |||
if ($model->load(\Yii::$app->request->post())) { | |||
$model->setDateDelivery(); | |||
if ($model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Développement modifié'); | |||
$this->setFlash('success', 'Développement modifié'); | |||
return $this->redirect(['index']); | |||
} | |||
} else { | |||
@@ -169,7 +169,7 @@ class DevelopmentController extends Controller | |||
public function actionDelete($id) | |||
{ | |||
$this->findModel($id)->delete(); | |||
Yii::$app->getSession()->setFlash('success', 'Développement supprimé'); | |||
$this->setFlash('success', 'Développement supprimé'); | |||
return $this->redirect(['index']); | |||
} | |||
@@ -182,13 +182,13 @@ class DevelopmentController extends Controller | |||
*/ | |||
public function actionPriority($idDevelopment, $priority = null) | |||
{ | |||
$develpmentPriority = DevelopmentPriorityModel::searchOne([ | |||
$develpmentPriority = DevelopmentPriority::searchOne([ | |||
'id_development' => $idDevelopment, | |||
]); | |||
if (in_array($priority, [DevelopmentPriorityModel::PRIORITY_HIGH, | |||
DevelopmentPriorityModel::PRIORITY_NORMAL, | |||
DevelopmentPriorityModel::PRIORITY_LOW])) { | |||
if (in_array($priority, [DevelopmentPriority::PRIORITY_HIGH, | |||
DevelopmentPriority::PRIORITY_NORMAL, | |||
DevelopmentPriority::PRIORITY_LOW])) { | |||
if ($develpmentPriority) { | |||
$develpmentPriority->priority = $priority; | |||
@@ -213,13 +213,10 @@ class DevelopmentController extends Controller | |||
/** | |||
* Finds the Developpement model based on its primary key value. | |||
* If the model is not found, a 404 HTTP exception will be thrown. | |||
* @param integer $id | |||
* @return Developpement the loaded model | |||
* @throws NotFoundHttpException if the model cannot be found | |||
*/ | |||
protected function findModel($id) | |||
{ | |||
if (($model = DevelopmentModel::findOne($id)) !== null) { | |||
if (($model = Development::findOne($id)) !== null) { | |||
return $model; | |||
} else { | |||
throw new NotFoundHttpException('The requested page does not exist.'); |
@@ -38,11 +38,24 @@ | |||
namespace backend\controllers; | |||
use common\helpers\CSV; | |||
use common\helpers\GlobalParam; | |||
use common\helpers\MeanPayment; | |||
use common\helpers\Password; | |||
use common\helpers\Price; | |||
use common\helpers\Tiller; | |||
use common\logic\Distribution\Distribution\Distribution; | |||
use common\logic\Distribution\PointSaleDistribution\PointSaleDistribution; | |||
use common\logic\Distribution\ProductDistribution\ProductDistribution; | |||
use common\logic\Document\DeliveryNote\DeliveryNote; | |||
use common\logic\Document\Document\Document; | |||
use common\logic\Order\Order\Order; | |||
use common\logic\PointSale\PointSale\PointSale; | |||
use common\logic\Product\Product\Product; | |||
use common\logic\User\User\User; | |||
use common\logic\User\UserProducer\UserProducer; | |||
use DateTime; | |||
use kartik\mpdf\Pdf; | |||
use yii\filters\AccessControl; | |||
class DistributionController extends BackendController | |||
@@ -63,8 +76,8 @@ class DistributionController extends BackendController | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return $this->getUserManager()->getCurrentStatus() == User::STATUS_ADMIN | |||
|| $this->getUserManager()->getCurrentStatus() == User::STATUS_PRODUCER; | |||
$userManager = $this->getUserManager(); | |||
return $userManager->isCurrentAdmin() || $userManager->isCurrentProducer(); | |||
} | |||
] | |||
], | |||
@@ -101,6 +114,13 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$distributionManager = $this->getDistributionManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$productManager = $this->getProductManager(); | |||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||
$userManager = $this->getUserManager(); | |||
$subscriptionManager = $this->getSubscriptionManager(); | |||
$json = [ | |||
'distribution' => [], | |||
'products' => [] | |||
@@ -118,7 +138,7 @@ class DistributionController extends BackendController | |||
$dateEnd = strtotime('+' . $numberOfLoadedMonthes); | |||
} | |||
$producer = GlobalParam::getCurrentProducer(); | |||
$producer = $this->getProducerCurrent(); | |||
$json['producer'] = [ | |||
'credit' => $producer->credit, | |||
'tiller' => $producer->tiller, | |||
@@ -148,8 +168,7 @@ class DistributionController extends BackendController | |||
$json['distributions'] = $distributionsArray; | |||
if ($dateObject && $dateObject->format($format) === $date) { | |||
// distribution | |||
$distribution = DistributionModel::initDistribution($date); | |||
$distribution = $distributionManager->createDistributionIfNotExist($producer, $date); | |||
$json['distribution'] = [ | |||
'id' => $distribution->id, | |||
'active' => $distribution->active, | |||
@@ -161,7 +180,6 @@ class DistributionController extends BackendController | |||
), | |||
]; | |||
// commandes | |||
$ordersArray = Order::searchAll([ | |||
'distribution.id' => $distribution->id, | |||
], [ | |||
@@ -174,7 +192,7 @@ class DistributionController extends BackendController | |||
if ($ordersArray) { | |||
foreach ($ordersArray as $order) { | |||
if (is_null($order->date_delete)) { | |||
$revenues += $order->getAmountWithTax(); | |||
$revenues += $orderManager->getAmountWithTax($order); | |||
$weight += $order->weight; | |||
} | |||
} | |||
@@ -200,12 +218,13 @@ class DistributionController extends BackendController | |||
$potentialWeight = 0; | |||
foreach ($productsArray as &$theProduct) { | |||
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray); | |||
$productObject = $productManager->findOneProductById($theProduct['id']); | |||
$quantityOrder = $orderManager->getProductQuantity($productObject, $ordersArray); | |||
$theProduct['quantity_ordered'] = $quantityOrder; | |||
if (!isset($theProduct['productDistribution'][0])) { | |||
$theProductObject = (object)$theProduct; | |||
$theProduct['productDistribution'][0] = $distribution->linkProduct($theProductObject); | |||
$theProduct['productDistribution'][0] = $distributionManager->addProduct($distribution, $productObject); | |||
} | |||
if (!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | |||
@@ -264,14 +283,14 @@ class DistributionController extends BackendController | |||
$creditHistoryArray[] = [ | |||
'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), | |||
'user' => $creditHistory->getUserObject()->getUsername(), | |||
'user_action' => $creditHistoryService->getStrUserAction($creditHistory), | |||
'wording' => $creditHistoryService->getStrWording($creditHistory), | |||
'debit' => ($creditHistoryService->isTypeDebit($creditHistory) ? '- ' . $creditHistoryService->getAmount( | |||
'user_action' => $creditHistoryManager->getStrUserAction($creditHistory), | |||
'wording' => $creditHistoryManager->getStrWording($creditHistory), | |||
'debit' => ($creditHistoryManager->isTypeDebit($creditHistory) ? '- ' . $creditHistoryManager->getAmount( | |||
$creditHistory, | |||
Order::AMOUNT_TOTAL, | |||
true | |||
) : ''), | |||
'credit' => ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmount( | |||
'credit' => ($creditHistoryManager->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryManager->getAmount( | |||
$creditHistory, | |||
Order::AMOUNT_TOTAL, | |||
true | |||
@@ -296,10 +315,10 @@ class DistributionController extends BackendController | |||
$order = array_merge($order->getAttributes(), [ | |||
'selected' => false, | |||
'weight' => $order->weight, | |||
'amount' => Price::numberTwoDecimals($order->getAmountWithTax(Order::AMOUNT_TOTAL)), | |||
'amount_paid' => Price::numberTwoDecimals($order->getAmount(Order::AMOUNT_PAID)), | |||
'amount_remaining' => Price::numberTwoDecimals($order->getAmount(Order::AMOUNT_REMAINING)), | |||
'amount_surplus' => Price::numberTwoDecimals($order->getAmount(Order::AMOUNT_SURPLUS)), | |||
'amount' => Price::numberTwoDecimals($orderManager->getOrderAmountWithTax($order, Order::AMOUNT_TOTAL)), | |||
'amount_paid' => Price::numberTwoDecimals($orderManager->getOrderAmount($order, Order::AMOUNT_PAID)), | |||
'amount_remaining' => Price::numberTwoDecimals($orderManager->getOrderAmount($order, Order::AMOUNT_REMAINING)), | |||
'amount_surplus' => Price::numberTwoDecimals($orderManager->getOrderAmount($order, Order::AMOUNT_SURPLUS)), | |||
'user' => (isset($order->user)) ? array_merge( | |||
$order->user->getAttributes(), | |||
$arrayCreditUser | |||
@@ -308,14 +327,13 @@ class DistributionController extends BackendController | |||
'productOrder' => $productOrderArray, | |||
'creditHistory' => $creditHistoryArray, | |||
'oneProductUnactivated' => $oneProductUnactivated, | |||
'isLinkedToValidDocument' => $order->isLinkedToValidDocument(), | |||
'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order), | |||
]); | |||
} | |||
} | |||
$json['orders'] = $ordersArray; | |||
// points de vente | |||
$pointsSaleArray = PointSale::find() | |||
->joinWith([ | |||
'pointSaleDistribution' => function ($q) use ($distribution) { | |||
@@ -369,7 +387,7 @@ class DistributionController extends BackendController | |||
]; | |||
// utilisateurs | |||
$usersArray = User::findBy()->all(); | |||
$usersArray = $userManager->findUsers(); | |||
$json['users'] = $usersArray; | |||
@@ -385,7 +403,7 @@ class DistributionController extends BackendController | |||
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); | |||
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); | |||
$weekDistribution = DistributionModel::find() | |||
$weekDistribution = Distribution::find() | |||
->andWhere([ | |||
'id_producer' => GlobalParam::getCurrentProducerId(), | |||
'active' => 1, | |||
@@ -414,7 +432,7 @@ class DistributionController extends BackendController | |||
} | |||
// abonnements manquants | |||
$arraySubscriptions = Subscription::searchByDate($date); | |||
$arraySubscriptions = $subscriptionManager->findSubscriptionsByDate($date); | |||
$json['missing_subscriptions'] = []; | |||
if ($distribution->active) { | |||
foreach ($arraySubscriptions as $subscription) { | |||
@@ -435,9 +453,9 @@ class DistributionController extends BackendController | |||
public function actionAjaxPointSaleFavorite($idUser) | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$user = User::findOne(['id' => $idUser]); | |||
$favoritePointSale = $user->getFavoritePointSale(); | |||
$userManager = $this->getUserManager(); | |||
$user = $userManager->findOneUserById($idUser); | |||
$favoritePointSale = $userManager->getUserFavoritePointSale($user); | |||
$idFavoritePointSale = 0; | |||
if ($favoritePointSale) { | |||
$idFavoritePointSale = $favoritePointSale->id; | |||
@@ -457,10 +475,16 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$order = Order::searchOne(['id' => $idOrder]); | |||
$distribution = DistributionModel::findOne($idDistribution); | |||
$user = User::findOne($idUser); | |||
$pointSale = PointSale::findOne($idPointSale); | |||
$distributionManager = $this->getDistributionManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$userManager = $this->getUserManager(); | |||
$pointSaleManager = $this->getPointSaleManager(); | |||
$productManager = $this->getProductManager(); | |||
$order = $orderManager->findOneOrderById($idOrder); | |||
$distribution = $distributionManager->findOneDistributionById($idDistribution); | |||
$user = $userManager->findOneUserById($idUser); | |||
$pointSale = $pointSaleManager->findOnePointSaleById($idPointSale); | |||
$productsArray = Product::find() | |||
->where([ | |||
@@ -474,7 +498,7 @@ class DistributionController extends BackendController | |||
$productOrderArray = []; | |||
foreach ($productsArray as $product) { | |||
$priceArray = $product->getPriceArray($user, $pointSale); | |||
$priceArray = $productManager->getPriceArray($product, $user, $pointSale); | |||
$quantity = 0; | |||
$invoicePrice = null; | |||
@@ -498,7 +522,7 @@ class DistributionController extends BackendController | |||
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], | |||
'prices' => $priceArray, | |||
'active' => $product->productDistribution[0]->active | |||
&& (!$pointSale || $product->isAvailableOnPointSale($pointSale)), | |||
&& (!$pointSale || $productManager->isAvailableOnPointSale($product, $pointSale)), | |||
'invoice_price' => $invoicePrice | |||
]; | |||
} | |||
@@ -508,20 +532,19 @@ class DistributionController extends BackendController | |||
public function actionAjaxUpdateInvoicePrices($idOrder) | |||
{ | |||
$order = Order::searchOne([ | |||
'id' => (int)$idOrder | |||
]); | |||
$orderManager = $this->getOrderManager(); | |||
$userProducerManager = $this->getUserProducerManager(); | |||
$productManager = $this->getProductManager(); | |||
$order = $orderManager->findOneOrderById($idOrder); | |||
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | |||
$userProducer = null; | |||
if ($order->id_user) { | |||
$userProducer = UserProducer::searchOne([ | |||
'id_user' => $order->id_user, | |||
'id_producer' => GlobalParam::getCurrentProducerId() | |||
]); | |||
$userProducer = $userProducerManager->findOneUserProducer($order->user, $this->getProducerCurrent()); | |||
} | |||
foreach ($order->productOrder as $productOrder) { | |||
$invoicePrice = $productOrder->product->getPrice([ | |||
$invoicePrice = $productManager->getPrice($productOrder->product, [ | |||
'user' => $order->user ?: null, | |||
'point_sale' => $order->pointSale, | |||
'user_producer' => $userProducer, | |||
@@ -546,7 +569,7 @@ class DistributionController extends BackendController | |||
* @param boolean $save | |||
* @param integer $idProducer | |||
* @param string $key | |||
* @return PDF|null | |||
* @return Pdf|null | |||
*/ | |||
public function actionReportCron($date = '', $save = false, $idProducer = 0, $key = '') | |||
{ | |||
@@ -562,11 +585,16 @@ class DistributionController extends BackendController | |||
* @param string $date | |||
* @param boolean $save | |||
* @param integer $idProducer | |||
* @return PDF|null | |||
* @return Pdf|null|string | |||
*/ | |||
public function actionReport($date = '', $save = false, $idProducer = 0, $type = "pdf") | |||
{ | |||
if (!Yii::$app->user->isGuest) { | |||
$productDistributionManager = $this->getProductDistributionManager(); | |||
$producerManager = $this->getProducerManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$productManager = $this->getProductManager(); | |||
if (!\Yii::$app->user->isGuest) { | |||
$idProducer = GlobalParam::getCurrentProducerId(); | |||
} | |||
@@ -581,7 +609,7 @@ class DistributionController extends BackendController | |||
] | |||
); | |||
$distribution = DistributionModel::searchOne([ | |||
$distribution = Distribution::searchOne([ | |||
'id_producer' => $idProducer | |||
], [ | |||
'conditions' => 'date LIKE :date', | |||
@@ -589,7 +617,7 @@ class DistributionController extends BackendController | |||
]); | |||
if ($distribution) { | |||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | |||
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution); | |||
$pointsSaleArray = PointSale::searchAll([ | |||
'point_sale.id_producer' => $idProducer | |||
]); | |||
@@ -628,7 +656,7 @@ class DistributionController extends BackendController | |||
'pointsSaleArray' => $pointsSaleArray, | |||
'productsArray' => $productsArray, | |||
'ordersArray' => $ordersArray, | |||
'producer' => Producer::searchOne(['id' => $idProducer]) | |||
'producer' => $producerManager->findOneProducerById($idProducer) | |||
]); | |||
$dateStr = date('d/m/Y', strtotime($date)); | |||
@@ -648,7 +676,7 @@ class DistributionController extends BackendController | |||
'orientation' => $orientationPdf, | |||
// stream to browser inline | |||
'destination' => $destination, | |||
'filename' => Yii::getAlias( | |||
'filename' => \Yii::getAlias( | |||
'@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf' | |||
), | |||
// your html content input | |||
@@ -697,8 +725,8 @@ class DistributionController extends BackendController | |||
} elseif ($type == 'csv') { | |||
$datas = []; | |||
$optionCsvExportAllProducts = Producer::getConfig('option_csv_export_all_products'); | |||
$optionCsvExportByPiece = Producer::getConfig('option_csv_export_by_piece'); | |||
$optionCsvExportAllProducts = $producerManager->getConfig('option_csv_export_all_products'); | |||
$optionCsvExportByPiece = $producerManager->getConfig('option_csv_export_by_piece'); | |||
// produits en colonne | |||
$productsNameArray = ['', 'Commentaire']; | |||
@@ -708,13 +736,13 @@ class DistributionController extends BackendController | |||
foreach ($productsArray as $product) { | |||
$productsHasQuantity[$product->id] = 0; | |||
foreach (Product::$unitsArray as $unit => $dataUnit) { | |||
$quantity = Order::getProductQuantity($product->id, $ordersArray, true, $unit); | |||
$quantity = $orderManager->getProductQuantity($product, $ordersArray, true, $unit); | |||
if ($quantity) { | |||
$productsHasQuantity[$product->id] += $quantity; | |||
} | |||
} | |||
if ($productsHasQuantity[$product->id] > 0 || $optionCsvExportAllProducts) { | |||
$productName = $product->getNameExport(); | |||
$productName = $productManager->getNameExport($product); | |||
if ($optionCsvExportByPiece) { | |||
$productUnit = 'piece'; | |||
@@ -722,7 +750,7 @@ class DistributionController extends BackendController | |||
$productUnit = $product->unit; | |||
} | |||
$productName .= ' (' . Product::strUnit($productUnit, 'wording_short', true) . ')'; | |||
$productName .= ' (' . $productManager->strUnit($productUnit, 'wording_short', true) . ')'; | |||
$productsNameArray[] = $productName; | |||
$productsIndexArray[$product->id] = $cpt++; | |||
@@ -736,12 +764,12 @@ class DistributionController extends BackendController | |||
// listing commandes | |||
$datas[] = ['> ' . $pointSale->name]; | |||
foreach ($pointSale->orders as $order) { | |||
$orderLine = [$order->getStrUser(), $order->getCommentReport()]; | |||
$orderLine = [$orderManager->getOrderUsername($order), $orderManager->getCommentReport($order)]; | |||
if ($optionCsvExportByPiece) { | |||
foreach ($order->productOrder as $productOrder) { | |||
$orderLine[$productsIndexArray[$productOrder->id_product]] = Order::getProductQuantityPieces( | |||
$productOrder->id_product, | |||
$orderLine[$productsIndexArray[$productOrder->id_product]] = $orderManager->getProductQuantityPieces( | |||
$productOrder->product, | |||
[$order] | |||
); | |||
} | |||
@@ -756,7 +784,7 @@ class DistributionController extends BackendController | |||
} | |||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; | |||
if ($productOrder->product->unit != $productOrder->unit) { | |||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= Product::strUnit( | |||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productManager->strUnit( | |||
$productOrder->unit, | |||
'wording_short', | |||
true | |||
@@ -821,11 +849,16 @@ class DistributionController extends BackendController | |||
public function actionReportGrid($date = '', $save = false, $idProducer = 0, $type = "pdf") | |||
{ | |||
if (!Yii::$app->user->isGuest) { | |||
$producerManager = $this->getProducerManager(); | |||
$productDistribution = $this->getProductDistributionManager(); | |||
$pointSaleManager = $this->getPointSaleManager(); | |||
$productCategoryManager = $this->getProductCategoryManager(); | |||
if (!\Yii::$app->user->isGuest) { | |||
$idProducer = GlobalParam::getCurrentProducerId(); | |||
} | |||
$distribution = DistributionModel::searchOne([ | |||
$distribution = Distribution::searchOne([ | |||
'id_producer' => $idProducer | |||
], [ | |||
'conditions' => 'date LIKE :date', | |||
@@ -844,13 +877,13 @@ class DistributionController extends BackendController | |||
] | |||
); | |||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | |||
$selectedProductsArray = $productDistribution->findProductDistributionsByDistribution($distribution); | |||
$pointsSaleArray = PointSale::searchAll([ | |||
'point_sale.id_producer' => $idProducer | |||
]); | |||
foreach ($pointsSaleArray as $pointSale) { | |||
$pointSale->initOrders($ordersArray); | |||
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray); | |||
} | |||
$ordersByPage = 22; | |||
@@ -880,10 +913,7 @@ class DistributionController extends BackendController | |||
} | |||
// catégories | |||
$categoriesArray = ProductCategory::searchAll( | |||
['id_producer' => $idProducer], | |||
['orderby' => 'product_category.position ASC'] | |||
); | |||
$categoriesArray = $productCategoryManager->findProductCategories(); | |||
array_unshift($categoriesArray, null); | |||
// produits | |||
@@ -917,7 +947,7 @@ class DistributionController extends BackendController | |||
'categoriesArray' => $categoriesArray, | |||
'productsArray' => $productsArray, | |||
'ordersArray' => $ordersArrayPaged, | |||
'producer' => Producer::searchOne(['id' => $idProducer]) | |||
'producer' => $producerManager->findOneProducerById($idProducer) | |||
]); | |||
$dateStr = date('d/m/Y', strtotime($date)); | |||
@@ -937,7 +967,7 @@ class DistributionController extends BackendController | |||
'orientation' => $orientationPdf, | |||
// stream to browser inline | |||
'destination' => $destination, | |||
'filename' => Yii::getAlias( | |||
'filename' => \Yii::getAlias( | |||
'@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf' | |||
), | |||
// your html content input | |||
@@ -1008,18 +1038,17 @@ class DistributionController extends BackendController | |||
/** | |||
* Génère un export des commandes au format CSV à destination du Google Drive | |||
* de Terre de pains. | |||
* | |||
* @param type $date | |||
* @return CSV | |||
*/ | |||
public function actionReportTerredepains($date, $key) | |||
{ | |||
if ($key == 'ef572cc148c001f0180c4a624189ed30') { | |||
$producer = Producer::searchOne([ | |||
'producer.slug' => 'terredepains' | |||
]); | |||
$producerManager = $this->getProducerManager(); | |||
$productDistributionManager = $this->getProductDistributionManager(); | |||
$pointSaleManager = $this->getPointSaleManager(); | |||
$productManager = $this->getProductManager(); | |||
if ($key == 'ef572cc148c001f0180c4a624189ed30') { | |||
$producer = $producerManager->findOneProducerBySlug('terredepains'); | |||
$idProducer = $producer->id; | |||
$ordersArray = Order::searchAll( | |||
@@ -1033,7 +1062,7 @@ class DistributionController extends BackendController | |||
] | |||
); | |||
$distribution = DistributionModel::searchOne([ | |||
$distribution = Distribution::searchOne([ | |||
'distribution.id_producer' => $idProducer | |||
], [ | |||
'conditions' => 'date LIKE :date', | |||
@@ -1043,13 +1072,12 @@ class DistributionController extends BackendController | |||
]); | |||
if ($distribution) { | |||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | |||
$pointsSaleArray = PointSale::searchAll([ | |||
'point_sale.id_producer' => $idProducer | |||
]); | |||
foreach ($pointsSaleArray as $pointSale) { | |||
$pointSale->initOrders($ordersArray); | |||
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray); | |||
} | |||
// produits | |||
@@ -1073,7 +1101,7 @@ class DistributionController extends BackendController | |||
$productsHasQuantity = []; | |||
$cpt = 1; | |||
foreach ($productsArray as $product) { | |||
$theUnit = Product::strUnit($product->unit, 'wording_short', true); | |||
$theUnit = $productManager->strUnit($product->unit, 'wording_short', true); | |||
$theUnit = ($theUnit == 'p.') ? '' : ' (' . $theUnit . ')'; | |||
$productsNameArray[] = $product->name . $theUnit; | |||
$productsIndexArray[$product->id] = $cpt++; | |||
@@ -1138,10 +1166,13 @@ class DistributionController extends BackendController | |||
public function _totalReportCSV($label, $ordersArray, $productsArray, $productsIndexArray) | |||
{ | |||
$orderManager = $this->getOrderManager(); | |||
$productManager = $this->getProductManager(); | |||
$totalsPointSaleArray = [$label]; | |||
foreach ($productsArray as $product) { | |||
foreach (Product::$unitsArray as $unit => $dataUnit) { | |||
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||
$quantity = $orderManager->getProductQuantity($product, $ordersArray, false, $unit); | |||
if ($quantity) { | |||
$index = $productsIndexArray[$product->id]; | |||
if (!isset($totalsPointSaleArray[$index])) { | |||
@@ -1155,7 +1186,7 @@ class DistributionController extends BackendController | |||
$totalsPointSaleArray[$index] .= $quantity; | |||
if ($product->unit != $unit) { | |||
$totalsPointSaleArray[$index] .= '' . Product::strUnit($unit, 'wording_short', true); | |||
$totalsPointSaleArray[$index] .= '' . $productManager->strUnit($unit, 'wording_short', true); | |||
} | |||
} | |||
} | |||
@@ -1165,12 +1196,13 @@ class DistributionController extends BackendController | |||
public function _totalReportPiecesCSV($label, $ordersArray, $productsArray, $productsIndexArray) | |||
{ | |||
$totalsPointSaleArray = [$label]; | |||
$orderManager = $this->getOrderManager(); | |||
$totalsPointSaleArray = [$label]; | |||
foreach ($productsArray as $product) { | |||
$quantity = 0; | |||
foreach (Product::$unitsArray as $unit => $dataUnit) { | |||
$quantityProduct = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||
$quantityProduct = $orderManager->getProductQuantity($product, $ordersArray, false, $unit); | |||
if ($unit == 'piece') { | |||
$quantity += $quantityProduct; | |||
@@ -1217,14 +1249,11 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$productDistribution = ProductDistributionModel::searchOne([ | |||
'id_distribution' => $idDistribution, | |||
'id_product' => $idProduct, | |||
]); | |||
$productDistributionManager = $this->getProductDistributionManager(); | |||
$productDistribution = $this->getProductDistribution($idProduct, $idDistribution); | |||
$productDistribution->quantity_max = (!$quantityMax) ? null : (float)$quantityMax; | |||
$productDistribution->save(); | |||
$productDistributionManager->saveUpdate($productDistribution); | |||
return ['success']; | |||
} | |||
@@ -1233,12 +1262,11 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$productDistribution = ProductDistributionModel::searchOne([ | |||
'id_distribution' => $idDistribution, | |||
'id_product' => $idProduct, | |||
]); | |||
$productDistributionManager = $this->getProductDistributionManager(); | |||
$productDistribution = $this->getProductDistribution($idProduct, $idDistribution); | |||
$productDistribution->active = $active; | |||
$productDistribution->save(); | |||
$productDistributionManager->saveUpdate($productDistribution); | |||
return ['success']; | |||
} | |||
@@ -1247,16 +1275,32 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$pointSaleDistribution = PointSaleDistributionModel::searchOne([ | |||
'id_distribution' => $idDistribution, | |||
'id_point_sale' => $idPointSale, | |||
]); | |||
$distributionManager = $this->getDistributionManager(); | |||
$pointSaleManager = $this->getPointSaleManager(); | |||
$pointSaleDistributionManager = $this->getPointSaleDistributionManager(); | |||
$pointSaleDistribution = $pointSaleDistributionManager->findOnePointSaleDistribution( | |||
$distributionManager->findOneDistributionById($idDistribution), | |||
$pointSaleManager->findOnePointSaleById($idPointSale) | |||
); | |||
$pointSaleDistribution->delivery = $delivery; | |||
$pointSaleDistribution->save(); | |||
$pointSaleDistributionManager->saveUpdate($pointSaleDistribution); | |||
return ['success']; | |||
} | |||
public function getProductDistribution(int $idProduct, int $idDistribution) | |||
{ | |||
$distributionManager = $this->getDistributionManager(); | |||
$productManager = $this->getProductManager(); | |||
$productDistributionManager = $this->getProductDistributionManager(); | |||
return $productDistributionManager->findOneProductDistribution( | |||
$distributionManager->findOneDistributionById($idDistribution), | |||
$productManager->findOneProductById($idProduct) | |||
); | |||
} | |||
/** | |||
* Active/désactive un jour de distribution. | |||
* | |||
@@ -1269,20 +1313,21 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$distributionManager = $this->getDistributionManager(); | |||
$producerCurrent = $this->getProducerCurrent(); | |||
if ($idDistribution) { | |||
$distribution = DistributionModel::searchOne([ | |||
'id' => $idDistribution | |||
]); | |||
$distribution = $distributionManager->findOneDistributionById($idDistribution); | |||
} | |||
$format = 'Y-m-d'; | |||
$dateObject = DateTime::createFromFormat($format, $date); | |||
if ($dateObject && $dateObject->format($format) === $date) { | |||
$distribution = DistributionModel::initDistribution($date); | |||
$distribution = $distributionManager->createDistributionIfNotExist($producerCurrent, $date); | |||
} | |||
if ($distribution) { | |||
$distribution->active($active); | |||
$distributionManager->activeDistribution($distribution, $active); | |||
return ['success']; | |||
} | |||
@@ -1376,7 +1421,7 @@ class DistributionController extends BackendController | |||
public function actionAjaxProcessAddSubscriptions($date) | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
Subscription::addAll($date, true); | |||
$this->getOrderManager()->createAllOrdersFromSubscriptions($date, true); | |||
return ['success']; | |||
} | |||
@@ -1388,8 +1433,13 @@ class DistributionController extends BackendController | |||
public function actionAjaxProcessSynchroTiller($date) | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$producerManager = $this->getProducerManager(); | |||
$productOrderManager = $this->getProductOrderManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$return = []; | |||
$producerTiller = Producer::getConfig('tiller'); | |||
$producerTiller = $producerManager->getConfig('tiller'); | |||
if ($producerTiller) { | |||
$tiller = new Tiller(); | |||
@@ -1411,7 +1461,7 @@ class DistributionController extends BackendController | |||
foreach ($order->productOrder as $productOrder) { | |||
$lines[] = [ | |||
'name' => $productOrder->product->name, | |||
'price' => $productOrder->getPriceWithTax() * 100 * $productOrder->quantity, | |||
'price' => $productOrderManager->getPriceWithTax($productOrder) * 100 * $productOrder->quantity, | |||
'tax' => $productOrder->taxRate->value * 100, | |||
'date' => $strDate, | |||
'quantity' => $productOrder->quantity | |||
@@ -1445,7 +1495,8 @@ class DistributionController extends BackendController | |||
'payments' => [ | |||
[ | |||
'type' => $typePaymentTiller, | |||
'amount' => $order->getAmountWithTax( | |||
'amount' => $orderManager->getOrderAmountWithTax( | |||
$order, | |||
Order::AMOUNT_TOTAL | |||
) * 100, | |||
'status' => 'ACCEPTED', | |||
@@ -1471,6 +1522,8 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$deliveryNoteManager = $this->getDeliveryNoteManager(); | |||
if (strlen($idOrders)) { | |||
$idOrders = json_decode($idOrders, true); | |||
@@ -1486,8 +1539,8 @@ class DistributionController extends BackendController | |||
]); | |||
if ($deliveryNote && $deliveryNote->isStatusDraft()) { | |||
$deliveryNote->changeStatus(Document::STATUS_VALID); | |||
$deliveryNote->save(); | |||
$deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID); | |||
$deliveryNoteManager->saveUpdate($deliveryNote); | |||
} | |||
} | |||
} | |||
@@ -1515,6 +1568,14 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$userManager = $this->getUserManager(); | |||
$userProducerManager = $this->getUserProducerManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$deliveryNoteManager = $this->getDeliveryNoteManager(); | |||
$producerCurrent = $this->getProducerCurrent(); | |||
if (strlen($idOrders)) { | |||
$idOrders = json_decode($idOrders, true); | |||
@@ -1542,7 +1603,7 @@ class DistributionController extends BackendController | |||
if (!$deliveryNote) { | |||
$deliveryNote = new DeliveryNote(); | |||
$deliveryNote->initTaxCalculationMethod(); | |||
$deliveryNoteManager->initTaxCalculationMethod($deliveryNote); | |||
$deliveryNote->id_producer = GlobalParam::getCurrentProducerId(); | |||
$deliveryNote->id_user = $order->id_user; | |||
$deliveryNote->name = 'Bon de livraison ' . $order->getUsername() . ' (' . date( | |||
@@ -1560,14 +1621,9 @@ class DistributionController extends BackendController | |||
$order->save(); | |||
// init invoice prices | |||
$user = User::searchOne([ | |||
'id' => $deliveryNote->id_user | |||
]); | |||
$userProducer = UserProducer::searchOne([ | |||
'id_user' => $deliveryNote->id_user, | |||
'id_producer' => GlobalParam::getCurrentProducerId() | |||
]); | |||
$order->initInvoicePrices([ | |||
$user = $userManager->findOneUserById($deliveryNote->id_user); | |||
$userProducer = $userProducerManager->findOneUserProducer($user, $producerCurrent); | |||
$orderManager->updateOrderInvoicePrices($order, [ | |||
'user' => $user, | |||
'user_producer' => $userProducer, | |||
'point_sale' => $order->pointSale | |||
@@ -1599,6 +1655,13 @@ class DistributionController extends BackendController | |||
{ | |||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||
$userManager = $this->getUserManager(); | |||
$userProducerManager = $this->getUserProducerManager(); | |||
$orderManager = $this->getOrderManager(); | |||
$deliveryNoteManager = $this->getDeliveryNoteManager(); | |||
$producerCurrent = $this->getProducerCurrent(); | |||
if (strlen($idOrders)) { | |||
$idOrders = json_decode($idOrders, true); | |||
@@ -1641,7 +1704,7 @@ class DistributionController extends BackendController | |||
// génération du BL | |||
if (!$deliveryNote) { | |||
$deliveryNote = new DeliveryNote; | |||
$deliveryNote->initTaxCalculationMethod(); | |||
$deliveryNoteManager->initTaxCalculationMethod($deliveryNote); | |||
$deliveryNote->name = 'Bon de livraison ' . $firstOrder->pointSale->name . ' (' . date( | |||
'd/m/Y', | |||
strtotime( | |||
@@ -1652,13 +1715,8 @@ class DistributionController extends BackendController | |||
if ($firstOrder->pointSale->id_user) { | |||
$deliveryNote->id_user = $firstOrder->pointSale->id_user; | |||
$user = User::searchOne([ | |||
'id' => $deliveryNote->id_user | |||
]); | |||
$userProducer = UserProducer::searchOne([ | |||
'id_user' => $deliveryNote->id_user, | |||
'id_producer' => GlobalParam::getCurrentProducerId() | |||
]); | |||
$user = $userManager->findOneUserById($deliveryNote->id_user); | |||
$userProducer = $userProducerManager->findOneUserProducer($user, $producerCurrent); | |||
} else { | |||
$user = new User; | |||
$user->type = User::TYPE_LEGAL_PERSON; | |||
@@ -1673,7 +1731,7 @@ class DistributionController extends BackendController | |||
} | |||
$user->save(); | |||
$userProducer = new UserProducer; | |||
$userProducer = new UserProducer(); | |||
$userProducer->id_user = $user->id; | |||
$userProducer->id_producer = GlobalParam::getCurrentProducerId(); | |||
$userProducer->credit = 0; | |||
@@ -1698,33 +1756,27 @@ class DistributionController extends BackendController | |||
} | |||
if (!isset($user) || !$user) { | |||
$user = User::searchOne([ | |||
'id' => $deliveryNote->id_user | |||
]); | |||
$userProducer = UserProducer::searchOne([ | |||
'id_user' => $deliveryNote->id_user, | |||
'id_producer' => GlobalParam::getCurrentProducerId() | |||
]); | |||
$user = $userManager->findOneUserById($deliveryNote->id_user); | |||
$userProducer = $userProducerManager->findOneUserProducer($user, $producerCurrent); | |||
} | |||
// affectation du BL aux commandes | |||
foreach ($idOrders as $idOrder) { | |||
$order = Order::searchOne([ | |||
'id' => (int)$idOrder | |||
]); | |||
$order = $orderManager->findOneOrderById((int)$idOrder); | |||
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | |||
$order->id_delivery_note = $deliveryNote->id; | |||
$order->save(); | |||
} | |||
// init invoice price | |||
$order = Order::searchOne(['id' => $idOrder]); | |||
$order = $orderManager->findOneOrderById((int)$idOrder); | |||
if ($order) { | |||
$order->initInvoicePrices([ | |||
'user' => $user, | |||
'user_producer' => $userProducer, | |||
'point_sale' => $firstOrder->pointSale | |||
]); | |||
$orderManager->updateOrderInvoicePrices($order, | |||
[ | |||
'user' => $user, | |||
'user_producer' => $userProducer, | |||
'point_sale' => $firstOrder->pointSale | |||
]); | |||
} | |||
} | |||
@@ -38,19 +38,18 @@ | |||
namespace backend\controllers; | |||
use common\models\DeliveryNote; | |||
use common\models\Invoice; | |||
use common\models\PointSale; | |||
use common\models\Product; | |||
use common\models\Quotation; | |||
use common\models\ User; | |||
use common\models\Document; | |||
use common\helpers\CSV; | |||
use common\helpers\GlobalParam; | |||
use common\models\Order; | |||
use common\logic\UserProducer\ UserProducer; | |||
use common\logic\Document\DeliveryNote\DeliveryNote; | |||
use common\logic\Document\Document\Document; | |||
use common\logic\Document\Invoice\Invoice; | |||
use common\logic\Document\Quotation\Quotation; | |||
use common\logic\Order\Order\Order; | |||
use kartik\mpdf\Pdf; | |||
use yii\base\UserException; | |||
use yii; | |||
use yii\filters\VerbFilter; | |||
use yii\filters\AccessControl; | |||
class DocumentController extends BackendController | |||
{ | |||
@@ -58,12 +57,12 @@ class DocumentController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -96,20 +95,22 @@ class DocumentController extends BackendController | |||
public function actionCreate() | |||
{ | |||
$documentManager = $this->getDocumentManager(); | |||
$class = $this->getClass(); | |||
$model = new $class(); | |||
$model->initTaxCalculationMethod(); | |||
$documentManager->initTaxCalculationMethod($model); | |||
if ($model->load(Yii::$app->request->post())) { | |||
if ($model->load(\Yii::$app->request->post())) { | |||
$model->id_producer = GlobalParam::getCurrentProducerId(); | |||
if ($model->save()) { | |||
$this->processInvoiceViaDeliveryNotes($model); | |||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('create', $model)); | |||
$this->setFlash('success', $this->getFlashMessage('create', $model)); | |||
return $this->redirect(['/' . $this->getControllerUrl() . '/update', 'id' => $model->id]); | |||
} else { | |||
Yii::$app->getSession()->setFlash('error', 'Un problème est survenu lors de la création du document.'); | |||
$this->setFlash('error', 'Un problème est survenu lors de la création du document.'); | |||
} | |||
} | |||
@@ -147,11 +148,11 @@ class DocumentController extends BackendController | |||
$model = $this->findModel($id); | |||
if (!$model) { | |||
throw new NotFoundHttpException('Le document n\'a pas été trouvé.'); | |||
throw new yii\web\NotFoundHttpException('Le document n\'a pas été trouvé.'); | |||
} | |||
if ($model && $model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('update', $model)); | |||
if ($model && $model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', $this->getFlashMessage('update', $model)); | |||
} | |||
return $this->render('/document/update', [ | |||
@@ -163,13 +164,15 @@ class DocumentController extends BackendController | |||
public function actionDelete($id) | |||
{ | |||
$documentManager = $this->getDocumentManager(); | |||
$model = $this->findModel($id); | |||
if ($model->isStatusValid()) { | |||
if ($documentManager->isStatusValid($model)) { | |||
throw new UserException('Vous ne pouvez pas supprimer un document validé.'); | |||
} | |||
$model->delete(); | |||
$documentManager->delete($model); | |||
if ($this->getClass() == 'DeliveryNote') { | |||
Order::updateAll([ | |||
@@ -195,7 +198,7 @@ class DocumentController extends BackendController | |||
]); | |||
} | |||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model)); | |||
$this->setFlash('success', $this->getFlashMessage('delete', $model)); | |||
$this->redirect([$this->getControllerUrl() . '/index']); | |||
} | |||
@@ -320,7 +323,7 @@ class DocumentController extends BackendController | |||
{ | |||
$document = $this->findModel($id); | |||
$document->downloadPdf(true); | |||
Yii::$app->getSession()->setFlash('success', 'Le document PDF a bien été regénéré.'); | |||
$this->setFlash('success', 'Le document PDF a bien été regénéré.'); | |||
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]); | |||
} | |||
@@ -331,9 +334,9 @@ class DocumentController extends BackendController | |||
$document->is_sent = true; | |||
$document->save(); | |||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('send', $document)); | |||
$this->setFlash('success', $this->getFlashMessage('send', $document)); | |||
} else { | |||
Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document)); | |||
$this->setFlash('danger', $this->getFlashMessage('send', $document)); | |||
} | |||
if ($backUpdateForm) { | |||
@@ -450,7 +453,7 @@ class DocumentController extends BackendController | |||
// génération PDF | |||
$document->generatePdf(Pdf::DEST_FILE); | |||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('validate', $document)); | |||
$this->setFlash('success', $this->getFlashMessage('validate', $document)); | |||
if ($backUpdateForm) { | |||
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]); | |||
@@ -460,7 +463,7 @@ class DocumentController extends BackendController | |||
} | |||
} | |||
Yii::$app->getSession()->setFlash('danger', 'Une erreur est survenue lors de la validation du document.'); | |||
$this->setFlash('danger', 'Une erreur est survenue lors de la validation du document.'); | |||
return $this->redirect([$this->getControllerUrl() . '/index']); | |||
} | |||
@@ -50,7 +50,7 @@ class InvoiceController extends DocumentController | |||
public function actionIndex() | |||
{ | |||
$searchModel = new InvoiceSearch(); | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, |
@@ -48,7 +48,7 @@ class OrderController extends BackendController | |||
{ | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, |
@@ -54,12 +54,12 @@ class PointSaleController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -81,7 +81,7 @@ class PointSaleController extends BackendController | |||
public function actionIndex() | |||
{ | |||
$searchModel = new PointSaleSearch(); | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, | |||
@@ -98,7 +98,7 @@ class PointSaleController extends BackendController | |||
{ | |||
$model = new PointSale(); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$model->processPointProduction(); | |||
$model->processRestrictedAccess(); | |||
DistributionModel::linkPointSaleIncomingDistributions($model); | |||
@@ -128,11 +128,11 @@ class PointSaleController extends BackendController | |||
$model->users_comment[$userPointSale->id_user] = $userPointSale->comment; | |||
} | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$model->processPointProduction(); | |||
$model->processRestrictedAccess(); | |||
DistributionModel::linkPointSaleIncomingDistributions($model); | |||
Yii::$app->getSession()->setFlash('success', 'Point de vente modifié.'); | |||
$this->setFlash('success', 'Point de vente modifié.'); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('update', array_merge($this->initForm($id), [ | |||
@@ -199,9 +199,9 @@ class PointSaleController extends BackendController | |||
} | |||
} | |||
Yii::$app->getSession()->setFlash('success', 'Point de vente <strong>' . Html::encode($pointSale->name) . '</strong> supprimé.'); | |||
$this->setFlash('success', 'Point de vente <strong>' . Html::encode($pointSale->name) . '</strong> supprimé.'); | |||
} else { | |||
Yii::$app->getSession()->setFlash('info', 'Souhaitez-vous vraiment supprimer le point de vente <strong>' . Html::encode($pointSale->name) . '</strong> ? ' | |||
$this->setFlash('info', 'Souhaitez-vous vraiment supprimer le point de vente <strong>' . Html::encode($pointSale->name) . '</strong> ? ' | |||
. Html::a('Oui', ['point-sale/delete', 'id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']) . ' ' . Html::a('Non', ['point-sale/index'], ['class' => 'btn btn-default'])); | |||
} | |||
@@ -221,9 +221,9 @@ class PointSaleController extends BackendController | |||
if (!$pointSale->default) { | |||
$pointSale->default = 1; | |||
$pointSale->save(); | |||
Yii::$app->getSession()->setFlash('success', 'Point de vente <strong>' . Html::encode($pointSale->name) . '</strong> défini par défaut.'); | |||
$this->setFlash('success', 'Point de vente <strong>' . Html::encode($pointSale->name) . '</strong> défini par défaut.'); | |||
} else { | |||
Yii::$app->getSession()->setFlash('success', 'Aucun point de vente défini par défaut'); | |||
$this->setFlash('success', 'Aucun point de vente défini par défaut'); | |||
} | |||
} | |||
@@ -56,19 +56,19 @@ class ProducerAdminController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
'delete' => ['post'], | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||
return $this->getUserManager()->isCurrentAdmin(); | |||
} | |||
] | |||
], | |||
@@ -114,8 +114,8 @@ class ProducerAdminController extends BackendController | |||
{ | |||
$model = new Producer(); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Producteur créé.'); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', 'Producteur créé.'); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('create', [ | |||
@@ -133,8 +133,8 @@ class ProducerAdminController extends BackendController | |||
{ | |||
$model = $this->findModel($id); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Producteur modifié.'); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', 'Producteur modifié.'); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('update', [ | |||
@@ -168,9 +168,9 @@ class ProducerAdminController extends BackendController | |||
} | |||
if ($count) { | |||
Yii::$app->getSession()->setFlash('success', $count . ' clients importés du producteur #' . $fromProducerId . ' vers le producteur #' . $toProducerId . '.'); | |||
$this->setFlash('success', $count . ' clients importés du producteur #' . $fromProducerId . ' vers le producteur #' . $toProducerId . '.'); | |||
} else { | |||
Yii::$app->getSession()->setFlash('error', 'Aucun client à importer.'); | |||
$this->setFlash('error', 'Aucun client à importer.'); | |||
} | |||
return $this->redirect(['producer-admin/index']); |
@@ -57,13 +57,13 @@ class ProducerController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
'delete' => ['post'], | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -95,7 +95,7 @@ class ProducerController extends BackendController | |||
$model->option_dashboard_date_end = date('d/m/Y', strtotime($model->option_dashboard_date_end)); | |||
} | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
if (strlen($model->option_dashboard_date_start)) { | |||
$model->option_dashboard_date_start = date( | |||
@@ -135,11 +135,11 @@ class ProducerController extends BackendController | |||
$model->option_stripe_endpoint_secret = ''; | |||
$model->save(); | |||
Yii::$app->getSession()->setFlash('success', 'Paramètres mis à jour.'); | |||
$this->setFlash('success', 'Paramètres mis à jour.'); | |||
return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); | |||
} else { | |||
if ($model->load(Yii::$app->request->post())) { | |||
Yii::$app->getSession()->setFlash('error', 'Le formulaire comporte des erreurs.'); | |||
if ($model->load(\Yii::$app->request->post())) { | |||
$this->setFlash('error', 'Le formulaire comporte des erreurs.'); | |||
} | |||
return $this->render('update', [ | |||
'model' => $model, | |||
@@ -166,7 +166,7 @@ class ProducerController extends BackendController | |||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | |||
if ($producer->load(Yii::$app->request->post())) { | |||
if ($producer->load(\Yii::$app->request->post())) { | |||
$producer->save(); | |||
if (!is_null($producer->free_price)) { | |||
@@ -210,6 +210,6 @@ class ProducerController extends BackendController | |||
{ | |||
$producer = GlobalParam::getCurrentProducer(); | |||
$producer->updateOpendistribVersion(); | |||
return $this->redirect(Yii::$app->request->referrer); | |||
return $this->redirect(\Yii::$app->request->referrer); | |||
} | |||
} |
@@ -54,18 +54,18 @@ class ProducerPriceRangeAdminController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
'roles' => ['@'], | |||
'matchCallback' => function ($rule, $action) { | |||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||
return $this->getUserManager()->isCurrentAdmin(); | |||
} | |||
] | |||
], | |||
@@ -98,8 +98,8 @@ class ProducerPriceRangeAdminController extends BackendController | |||
{ | |||
$model = new ProducerPriceRange(); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Tranche de prix créée.'); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', 'Tranche de prix créée.'); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('create', [ | |||
@@ -117,8 +117,8 @@ class ProducerPriceRangeAdminController extends BackendController | |||
{ | |||
$model = $this->findModel($id); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Tranche de prix éditée.'); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', 'Tranche de prix éditée.'); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('update', [ | |||
@@ -139,7 +139,7 @@ class ProducerPriceRangeAdminController extends BackendController | |||
]); | |||
$producerPriceRange->delete(); | |||
Yii::$app->getSession()->setFlash('success', 'Tranche de prix supprimée.'); | |||
$this->setFlash('success', 'Tranche de prix supprimée.'); | |||
return $this->redirect(['producer-price-range-admin/index']); | |||
} | |||
@@ -54,12 +54,12 @@ class ProductCategoryController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -81,7 +81,7 @@ class ProductCategoryController extends BackendController | |||
public function actionIndex() | |||
{ | |||
$searchModel = new ProductCategorySearch(); | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, | |||
@@ -100,8 +100,8 @@ class ProductCategoryController extends BackendController | |||
$model->id_producer = GlobalParam::getCurrentProducerId(); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', "Catégorie ajoutée."); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', "Catégorie ajoutée."); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('create', [ | |||
@@ -120,8 +120,8 @@ class ProductCategoryController extends BackendController | |||
{ | |||
$model = $this->findModel($id); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', "Catégorie modifiée."); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', "Catégorie modifiée."); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('update', [ | |||
@@ -142,7 +142,7 @@ class ProductCategoryController extends BackendController | |||
$productCategory->delete(); | |||
Product::updateAll(['id_product_category' => null], ['id_product_category' => $id]); | |||
Yii::$app->getSession()->setFlash('success', 'Catégorie <strong>' . Html::encode($productCategory->name) . '</strong> supprimée.'); | |||
$this->setFlash('success', 'Catégorie <strong>' . Html::encode($productCategory->name) . '</strong> supprimée.'); | |||
return $this->redirect(['index']); | |||
} |
@@ -68,12 +68,12 @@ class ProductController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -95,7 +95,7 @@ class ProductController extends BackendController | |||
public function actionIndex() | |||
{ | |||
$searchModel = new ProductSearch(); | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, | |||
@@ -124,7 +124,7 @@ class ProductController extends BackendController | |||
$model->sunday = 1; | |||
$model->available_on_points_sale = 1; | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$lastProductOrder = Product::find()->where('id_producer = :id_producer')->params([':id_producer' => GlobalParam::getCurrentProducerId()])->orderBy('order DESC')->one(); | |||
if ($lastProductOrder) { | |||
@@ -140,7 +140,7 @@ class ProductController extends BackendController | |||
// link product / distribution | |||
DistributionModel::linkProductIncomingDistributions($model); | |||
Yii::$app->getSession()->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> ajouté'); | |||
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> ajouté'); | |||
return $this->redirect(['index']); | |||
} else { | |||
@@ -169,7 +169,7 @@ class ProductController extends BackendController | |||
$photoFilenameOld = $model->photo; | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
Upload::uploadFile($model, 'photo', $photoFilenameOld); | |||
@@ -187,7 +187,7 @@ class ProductController extends BackendController | |||
DistributionModel::linkProductIncomingDistributions($model); | |||
} | |||
Yii::$app->getSession()->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); | |||
$this->setFlash('success', 'Produit <strong>' . Html::encode($model->name) . '</strong> modifié'); | |||
return $this->redirect(['index']); | |||
} | |||
@@ -226,7 +226,7 @@ class ProductController extends BackendController | |||
$searchModel = new ProductPriceSearch(); | |||
$searchModel->id_product = $id; | |||
$dataProvider = $searchModel->search(array_merge(Yii::$app->request->queryParams, [ | |||
$dataProvider = $searchModel->search(array_merge(\Yii::$app->request->queryParams, [ | |||
'id_product' => $id | |||
])); | |||
@@ -255,7 +255,7 @@ class ProductController extends BackendController | |||
$model->id_product = $idProduct; | |||
$modelProduct = $this->findModel($idProduct); | |||
if ($model->load(Yii::$app->request->post())) { | |||
if ($model->load(\Yii::$app->request->post())) { | |||
$conditionsProductPriceExist = [ | |||
'id_product' => $idProduct, | |||
@@ -269,11 +269,11 @@ class ProductController extends BackendController | |||
if ($productPriceExist) { | |||
$productPriceExist->delete(); | |||
Yii::$app->getSession()->setFlash('warning', 'Un prix existait déjà pour cet utilisateur / point de vente, il a été supprimé.'); | |||
$this->setFlash('warning', 'Un prix existait déjà pour cet utilisateur / point de vente, il a été supprimé.'); | |||
} | |||
if ($model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Le prix a bien été ajouté.'); | |||
$this->setFlash('success', 'Le prix a bien été ajouté.'); | |||
return $this->redirect(['product/prices-list', 'id' => $idProduct]); | |||
} | |||
} | |||
@@ -291,8 +291,8 @@ class ProductController extends BackendController | |||
$model = $this->findModelProductPrice($id); | |||
$modelProduct = $this->findModel($model->id_product); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Prix modifié'); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', 'Prix modifié'); | |||
return $this->redirect(['product/prices-list', 'id' => $model->id_product]); | |||
} | |||
@@ -307,7 +307,7 @@ class ProductController extends BackendController | |||
{ | |||
$productPrice = $this->findModelProductPrice($id); | |||
$productPrice->delete(); | |||
Yii::$app->getSession()->setFlash('success', 'Prix supprimé'); | |||
$this->setFlash('success', 'Prix supprimé'); | |||
return $this->redirect(['product/prices-list', 'id' => $productPrice->id_product]); | |||
} | |||
@@ -326,9 +326,9 @@ class ProductController extends BackendController | |||
if ($confirm) { | |||
$product->delete(); | |||
ProductDistributionModel::deleteAll(['id_product' => $id]); | |||
Yii::$app->getSession()->setFlash('success', 'Produit <strong>' . Html::encode($product->name) . '</strong> supprimé'); | |||
$this->setFlash('success', 'Produit <strong>' . Html::encode($product->name) . '</strong> supprimé'); | |||
} else { | |||
Yii::$app->getSession()->setFlash('info', 'Souhaitez-vous vraiment supprimer le produit <strong>' . Html::encode($product->name) . '</strong> ? ' | |||
$this->setFlash('info', 'Souhaitez-vous vraiment supprimer le produit <strong>' . Html::encode($product->name) . '</strong> ? ' | |||
. Html::a('Oui', ['product/delete', 'id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']) . ' ' . Html::a('Non', ['product/index'], ['class' => 'btn btn-default'])); | |||
} | |||
@@ -49,12 +49,12 @@ class QuotationController extends DocumentController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -76,7 +76,7 @@ class QuotationController extends DocumentController | |||
public function actionIndex() | |||
{ | |||
$searchModel = new QuotationSearch(); | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, | |||
@@ -104,7 +104,7 @@ class QuotationController extends DocumentController | |||
'order.id_quotation' => $id | |||
]); | |||
Yii::$app->getSession()->setFlash('success', 'Le devis <strong>' . Html::encode($quotation->name) . '</strong> a bien été transformé en facture.'); | |||
$this->setFlash('success', 'Le devis <strong>' . Html::encode($quotation->name) . '</strong> a bien été transformé en facture.'); | |||
return $this->redirect(['/' . $this->getControllerUrl() . '/index']); | |||
} else { | |||
throw new UserException('Vous ne pouvez pas transformer en facture un devis non validé.'); |
@@ -50,7 +50,7 @@ class ReportController extends BackendController | |||
{ | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, |
@@ -209,7 +209,7 @@ class SiteController extends BackendController | |||
} | |||
$model = new LoginForm(); | |||
if ($model->load(Yii::$app->request->post()) && $model->login()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->login()) { | |||
return $this->goBack(); | |||
} else { | |||
return $this->render('login', [ |
@@ -52,7 +52,7 @@ class StatsController extends BackendController | |||
{ | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, |
@@ -47,7 +47,7 @@ class SubscriptionController extends BackendController | |||
{ | |||
return [ | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -71,7 +71,7 @@ class SubscriptionController extends BackendController | |||
$this->checkProductsPointsSale(); | |||
$searchModel = new SubscriptionSearch; | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, | |||
@@ -119,9 +119,9 @@ class SubscriptionController extends BackendController | |||
'orderby' => 'product.order ASC' | |||
]); | |||
if ($model->load(Yii::$app->request->post()) && $model->validate() | |||
if ($model->load(\Yii::$app->request->post()) && $model->validate() | |||
&& $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', 'Abonnement ajouté'); | |||
$this->setFlash('success', 'Abonnement ajouté'); | |||
$subscription = Subscription::findOne($model->id); | |||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | |||
@@ -194,7 +194,7 @@ class SubscriptionController extends BackendController | |||
'orderby' => 'product.order ASC' | |||
]); | |||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->validate()) { | |||
if (!$model->date_end) { | |||
$model->date_end = null; | |||
@@ -213,7 +213,7 @@ class SubscriptionController extends BackendController | |||
} | |||
} | |||
Yii::$app->getSession()->setFlash('success', 'Abonnement modifié' . $messageOrdersDeleted); | |||
$this->setFlash('success', 'Abonnement modifié' . $messageOrdersDeleted); | |||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | |||
if (count($matchedDistributionsArray)) { | |||
@@ -243,7 +243,7 @@ class SubscriptionController extends BackendController | |||
$subscription->deleteOrdersIncomingDistributions(); | |||
$subscription->delete(); | |||
ProductSubscription::deleteAll(['id_subscription' => $id]); | |||
Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé'); | |||
$this->setFlash('success', 'Abonnement supprimé'); | |||
return $this->redirect(['subscription/index']); | |||
} | |||
@@ -259,7 +259,7 @@ class SubscriptionController extends BackendController | |||
foreach ($matchedDistributionsArray as $distribution) { | |||
$subscription->add($distribution->date); | |||
} | |||
Yii::$app->getSession()->setFlash('success', 'Commandes ' . ($update ? 're-' : '') . 'générées dans les distributions futures.'); | |||
$this->setFlash('success', 'Commandes ' . ($update ? 're-' : '') . 'générées dans les distributions futures.'); | |||
return $this->redirect(['subscription/index']); | |||
} | |||
@@ -89,7 +89,7 @@ class TaxRateAdminController extends BackendController | |||
{ | |||
$model = $this->getTaxRateManager()->createTaxRate(); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', 'Taxe créée.'); | |||
return $this->redirect(['index']); | |||
} else { | |||
@@ -103,7 +103,7 @@ class TaxRateAdminController extends BackendController | |||
{ | |||
$model = $this->findModel($id); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', 'Taxe éditée.'); | |||
return $this->redirect(['index']); | |||
} else { | |||
@@ -120,7 +120,7 @@ class TaxRateAdminController extends BackendController | |||
]); | |||
$taxeRate->delete(); | |||
Yii::$app->getSession()->setFlash('success', 'Taxe supprimé'); | |||
$this->setFlash('success', 'Taxe supprimé'); | |||
return $this->redirect(['tax-rate-admin/index']); | |||
} | |||
@@ -105,7 +105,7 @@ class UserController extends BackendController | |||
'inactive' => (int)$sectionInactiveUsers, | |||
'subscribers' => (int)$sectionSubscribers | |||
], | |||
isset(Yii::$app->request->queryParams['UserSearch']) ? | |||
isset(\Yii::$app->request->queryParams['UserSearch']) ? | |||
Yii::$app->request->queryParams['UserSearch'] : | |||
[] | |||
) | |||
@@ -208,9 +208,9 @@ class UserController extends BackendController | |||
Producer::addUser($userExist->id, GlobalParam::getCurrentProducerId()); | |||
$this->processLinkPointSale($userExist); | |||
$this->processLinkUserGroup($userExist); | |||
Yii::$app->getSession()->setFlash('success', "L'utilisateur que vous souhaitez créer possède déjà un compte sur la plateforme. Il vient d'être lié à votre établissement."); | |||
$this->setFlash('success', "L'utilisateur que vous souhaitez créer possède déjà un compte sur la plateforme. Il vient d'être lié à votre établissement."); | |||
} else { | |||
if ($model->load(Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { | |||
if ($model->load(\Yii::$app->request->post()) && $model->validate() && YII_ENV != 'demo') { | |||
// save user | |||
$password = Password::generate(); | |||
$model->id_producer = 0; | |||
@@ -236,7 +236,7 @@ class UserController extends BackendController | |||
$this->processLinkUserGroup($model); | |||
$this->processProductPricePercent($model); | |||
Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.'); | |||
$this->setFlash('success', 'Utilisateur créé.'); | |||
$model = new User(); | |||
} | |||
} | |||
@@ -262,7 +262,7 @@ class UserController extends BackendController | |||
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); | |||
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | |||
if ($userBelongToProducer) { | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
// on envoie le mail de bienvenue si le mail vient d'être défini | |||
if (!strlen($previousMail) && strlen($model->email)) { | |||
@@ -274,7 +274,7 @@ class UserController extends BackendController | |||
$this->processLinkPointSale($model); | |||
$this->processLinkUserGroup($model); | |||
$this->processProductPricePercent($model); | |||
Yii::$app->getSession()->setFlash('success', 'Utilisateur modifié.'); | |||
$this->setFlash('success', 'Utilisateur modifié.'); | |||
} | |||
} else { | |||
throw new UserException("Vous ne pouvez pas modifier cet utilisateur."); | |||
@@ -304,7 +304,7 @@ class UserController extends BackendController | |||
] | |||
]); | |||
Yii::$app->getSession()->setFlash('success', 'Nouveau mot de passe envoyé.'); | |||
$this->setFlash('success', 'Nouveau mot de passe envoyé.'); | |||
} | |||
return $this->render('update', array_merge($this->initForm($model), [ | |||
@@ -396,7 +396,7 @@ class UserController extends BackendController | |||
$userProducer->active = 0; | |||
$userProducer->bookmark = 0; | |||
$userProducer->save(); | |||
Yii::$app->getSession()->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.'); | |||
$this->setFlash('success', 'L\'utilisateur a bien été supprimé de votre établissement.'); | |||
} else { | |||
throw new \yii\web\NotFoundHttpException('L\'enregistrement UserProducer est introuvable', 404); | |||
} | |||
@@ -448,10 +448,10 @@ class UserController extends BackendController | |||
} | |||
$mailForm = new MailForm(); | |||
if ($mailForm->load(Yii::$app->request->post()) && $mailForm->validate()) { | |||
if ($mailForm->load(\Yii::$app->request->post()) && $mailForm->validate()) { | |||
$responseSendMail = $mailForm->sendEmail($users); | |||
if ($responseSendMail->success()) { | |||
Yii::$app->getSession()->setFlash('success', 'Votre email a bien été envoyé.'); | |||
$this->setFlash('success', 'Votre email a bien été envoyé.'); | |||
} else { | |||
$bodyResponseSendMail = $responseSendMail->getBody(); | |||
$emailsErrorArray = []; | |||
@@ -468,7 +468,7 @@ class UserController extends BackendController | |||
if (count($emailsErrorArray) > 0) { | |||
$messageError .= '<br />Problème détecté sur les adresses suivantes : ' . implode(',', $emailsErrorArray); | |||
} | |||
Yii::$app->getSession()->setFlash('error', $messageError); | |||
$this->setFlash('error', $messageError); | |||
} | |||
return $this->redirect(['mail', 'idPointSale' => $idPointSale]); | |||
@@ -510,7 +510,7 @@ class UserController extends BackendController | |||
if (($userProducer) || User::getCurrentStatus() == User::STATUS_ADMIN) { | |||
$creditForm = new CreditForm(); | |||
if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { | |||
if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { | |||
$creditForm->id_user = $id; | |||
$creditForm->save(); | |||
@@ -547,7 +547,7 @@ class UserController extends BackendController | |||
{ | |||
$user = User::findOne($id); | |||
$searchModel = new OrderSearch(); | |||
$dataProvider = $searchModel->search(array_merge(Yii::$app->request->queryParams, ['id_user' => $id])); | |||
$dataProvider = $searchModel->search(array_merge(\Yii::$app->request->queryParams, ['id_user' => $id])); | |||
return $this->render('orders', [ | |||
'user' => $user, |
@@ -55,12 +55,12 @@ class UserGroupController extends BackendController | |||
{ | |||
return [ | |||
'verbs' => [ | |||
'class' => VerbFilter::className(), | |||
'class' => VerbFilter::class, | |||
'actions' => [ | |||
], | |||
], | |||
'access' => [ | |||
'class' => AccessControl::className(), | |||
'class' => AccessControl::class, | |||
'rules' => [ | |||
[ | |||
'allow' => true, | |||
@@ -82,7 +82,7 @@ class UserGroupController extends BackendController | |||
public function actionIndex() | |||
{ | |||
$searchModel = new UserGroupSearch(); | |||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||
return $this->render('index', [ | |||
'searchModel' => $searchModel, | |||
@@ -101,8 +101,8 @@ class UserGroupController extends BackendController | |||
$model->id_producer = GlobalParam::getCurrentProducerId(); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', "Groupe d'utilisateur ajouté."); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', "Groupe d'utilisateur ajouté."); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('create', [ | |||
@@ -121,8 +121,8 @@ class UserGroupController extends BackendController | |||
{ | |||
$model = $this->findModel($id); | |||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||
Yii::$app->getSession()->setFlash('success', "Groupe d'utilisateur modifié."); | |||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||
$this->setFlash('success', "Groupe d'utilisateur modifié."); | |||
return $this->redirect(['index']); | |||
} else { | |||
return $this->render('update', [ | |||
@@ -143,7 +143,7 @@ class UserGroupController extends BackendController | |||
$userGroup->delete(); | |||
UserUserGroup::deleteAll(['id_user_group' => $id]); | |||
Yii::$app->getSession()->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.'); | |||
$this->setFlash('success', 'Groupe d\'utilisateur <strong>' . Html::encode($userGroup->name) . '</strong> supprimé.'); | |||
return $this->redirect(['index']); | |||
} |
@@ -98,7 +98,7 @@ class ContactForm extends Model | |||
]) | |||
->setTo($email) | |||
->setFrom([$this->email => $this->name]) | |||
->setSubject('[distrib] Contact : ' . $this->subject) | |||
->setSubject('[Opendistrib] Contact : ' . $this->subject) | |||
->send(); | |||
} | |||
@@ -46,7 +46,7 @@ class GlobalParam | |||
public static function get($key) | |||
{ | |||
if ($key == 'producer') { | |||
return $this->getCurrentProducer(); | |||
return self::getCurrentProducer(); | |||
} else { | |||
return \Yii::$app->params[$key]; | |||
@@ -75,10 +75,10 @@ class GlobalParam | |||
{ | |||
if (\Yii::$app->controller->module->id == 'app-backend') { | |||
if (!\Yii::$app->user->isGuest) { | |||
return Yii::$app->user->identity->id_producer; | |||
return \Yii::$app->user->identity->id_producer; | |||
} | |||
} else { | |||
return \Yii::$app->controller->getProducer()->id; | |||
return \Yii::$app->controller->getProducerCurrent()->id; | |||
} | |||
return false; |
@@ -51,7 +51,7 @@ class Mail | |||
$data) | |||
->setTo($email) | |||
->setFrom(['contact@opendistrib.net' => 'distrib']) | |||
->setSubject('[distrib] '.$subject) | |||
->setSubject('[Opendistrib] '.$subject) | |||
->send(); | |||
} | |||
} |
@@ -37,13 +37,17 @@ class DistributionRepository extends BaseService implements RepositoryInterface | |||
]); | |||
} | |||
public function findOneDistribution(Producer $producer, string $date): ?Distribution | |||
public function findOneDistribution(Producer $producer, string $date, bool $active = null): ?Distribution | |||
{ | |||
$paramsDistribution = [ | |||
'date' => $date, | |||
'distribution.id_producer' => $producer->id | |||
]; | |||
if(!is_null($active)) { | |||
$paramsDistribution['active'] = $active; | |||
} | |||
return Distribution::searchOne($paramsDistribution); | |||
} | |||
@@ -267,4 +267,14 @@ class ProducerRepository extends BaseService implements RepositoryInterface | |||
$pointSale->credit_functioning : | |||
$this->getConfig('credit_functioning'); | |||
} | |||
public function findProducersActive() | |||
{ | |||
return Producer::find()->where(['producer.active' => 1])->with(['contact'])->all(); | |||
} | |||
public function findProducers() | |||
{ | |||
return Producer::find()->with(['contact'])->all(); | |||
} | |||
} |
@@ -9,6 +9,13 @@ use common\logic\Producer\Producer\Producer; | |||
class UserBuilder extends BaseBuilder implements BuilderInterface | |||
{ | |||
protected UserRepository $userRepository; | |||
public function __construct() | |||
{ | |||
$this->userRepository = $this->loadService(UserRepository::class); | |||
} | |||
public function instanciateUser(): User | |||
{ | |||
$user = new User(); | |||
@@ -69,4 +76,10 @@ class UserBuilder extends BaseBuilder implements BuilderInterface | |||
$user->password_reset_token = null; | |||
} | |||
public function deleteAccess(User $user): bool | |||
{ | |||
$user->id_producer = 0; | |||
$user->status = User::STATUS_ACTIVE; | |||
return $user->save(); | |||
} | |||
} |
@@ -235,15 +235,33 @@ class UserRepository extends BaseService implements RepositoryInterface | |||
* Recherche un utilisateur via son adresse email. | |||
*/ | |||
// getOneByEmail | |||
public static function findOneUserByEmail(string $email): ?User | |||
public function findOneUserByEmail(string $email): ?User | |||
{ | |||
return User::searchOne(['email' => $email]); | |||
} | |||
// getOneByUsername | |||
public static function findOneUserByUsername(string $username): ?User | |||
public function findOneUserByUsername(string $username): ?User | |||
{ | |||
return User::searchOne(['username' => $username]); | |||
} | |||
public function findUsersByProducer(Producer $producer) | |||
{ | |||
return User::find() | |||
->where([ | |||
'id_producer' => $producer->id, | |||
'status' => User::STATUS_PRODUCER | |||
]) | |||
->all(); | |||
} | |||
public function findUsersByStatus(string $status) | |||
{ | |||
return User::find() | |||
->where([ | |||
'user.status' => $status | |||
]) | |||
->all(); | |||
} | |||
} |
@@ -88,7 +88,7 @@ class PasswordResetRequestForm extends Model | |||
return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user]) | |||
->setFrom(['contact@opendistrib.net' => 'distrib']) | |||
->setTo($this->email) | |||
->setSubject('[distrib] Mot de passe oublié') | |||
->setSubject('[Opendistrib] Mot de passe oublié') | |||
->send(); | |||
} | |||
} |
@@ -104,7 +104,7 @@ class ProducerBaseController extends CommonController | |||
/** | |||
* Retourne le producteur courant. | |||
*/ | |||
public function getProducer() : Producer | |||
public function getProducerCurrent() : Producer | |||
{ | |||
if($this->producer) { | |||
return $this->producer ; |