use backend\models\AccessUserProducerForm; | use backend\models\AccessUserProducerForm; | ||||
use common\logic\Document\DeliveryNote\DeliveryNoteManager; | use common\logic\Document\DeliveryNote\DeliveryNoteManager; | ||||
use common\logic\Producer\Producer\ProducerManager; | 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. | * UserController implements the CRUD actions for User model. | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$userSearch = new UserSearch; | |||||
$userSearch = new UserSearch(); | |||||
$usersArray = $userSearch->search()->query->all(); | $usersArray = $userSearch->search()->query->all(); | ||||
$modelAccessUserProducerForm = new AccessUserProducerForm; | $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', [ | return $this->render('index', [ | ||||
'usersArray' => $usersArray, | 'usersArray' => $usersArray, | ||||
public function actionDelete($idUser) | public function actionDelete($idUser) | ||||
{ | { | ||||
$user = User::searchOne([ | |||||
'id' => $idUser | |||||
]); | |||||
$userManager = $this->getUserManager(); | |||||
$user = $userManager->findOneUserById($idUser); | |||||
if ($user) { | 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']); | return $this->redirect(['index']); | ||||
} | } | ||||
} | } |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\logic\PointSale\PointSale\PointSale; | use common\logic\PointSale\PointSale\PointSale; | ||||
use common\logic\Producer\Producer\Producer; | |||||
use common\logic\Product\Product\Product; | use common\logic\Product\Product\Product; | ||||
use common\controllers\CommonController; | use common\controllers\CommonController; | ||||
} | } | ||||
} | } | ||||
public function getProducerCurrent(): Producer | |||||
{ | |||||
return Producer::searchOne(); | |||||
} | |||||
} | } | ||||
?> | ?> |
namespace backend\controllers; | namespace backend\controllers; | ||||
use backend\models\MailForm; | use backend\models\MailForm; | ||||
use common\logic\User\User\User; | |||||
use yii\filters\AccessControl; | |||||
use yii\filters\VerbFilter; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use common\models\ User; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
'delete' => ['post'], | 'delete' => ['post'], | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||||
return $this->getUserManager()->isCurrentAdmin(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
]; | ]; | ||||
} | } | ||||
/** | |||||
* | |||||
* | |||||
* @return mixed | |||||
*/ | |||||
public function actionIndex($section = 'producers') | public function actionIndex($section = 'producers') | ||||
{ | { | ||||
$producerManager = $this->getProducerManager(); | |||||
$userManager = $this->getUserManager(); | |||||
if ($section == 'producers') { | if ($section == 'producers') { | ||||
$producers = Producer::find()->where(['producer.active' => 1])->with(['contact'])->all(); | |||||
$producers = $producerManager->findProducersActive(); | |||||
$usersArray = []; | $usersArray = []; | ||||
$users = []; | $users = []; | ||||
foreach ($producers as $producer) { | foreach ($producers as $producer) { | ||||
} | } | ||||
} | } | ||||
} elseif ($section == 'users') { | } elseif ($section == 'users') { | ||||
$users = User::find() | |||||
->where([ | |||||
'user.status' => User::STATUS_ACTIVE | |||||
]) | |||||
->all(); | |||||
$users = $userManager->findUsersByStatus(User::STATUS_ACTIVE); | |||||
$usersArray = []; | $usersArray = []; | ||||
foreach ($users as $user) { | foreach ($users as $user) { | ||||
if (isset($user['email']) && strlen($user['email'])) { | if (isset($user['email']) && strlen($user['email'])) { | ||||
} | } | ||||
$mailForm = new MailForm(); | $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); | $resultSendEmail = $mailForm->sendEmail($users, false); | ||||
if ($resultSendEmail) { | if ($resultSendEmail) { | ||||
Yii::$app->getSession()->setFlash('success', 'Votre email a bien été envoyé.'); | |||||
$this->setFlash('success', 'Votre email a bien été envoyé.'); | |||||
} else { | } 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->subject = ''; | ||||
$mailForm->message = ''; | $mailForm->message = ''; |
namespace backend\controllers; | namespace backend\controllers; | ||||
use kartik\mpdf\Pdf; | |||||
use yii\filters\AccessControl; | |||||
use yii\filters\VerbFilter; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
'delete' => ['post'], | 'delete' => ['post'], | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
/** | /** | ||||
* Affiche la page d'accueil de la section avec un aperçu du mpde d'emploi | * Affiche la page d'accueil de la section avec un aperçu du mpde d'emploi | ||||
* à imprimer. | * à imprimer. | ||||
* | |||||
* @return string | |||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$producer = Producer::searchOne(); | |||||
$pointsSaleArray = PointSale::searchAll(); | |||||
$producer = $this->getProducerCurrent(); | |||||
$pointsSaleArray = $this->getPointSaleManager()->findPointSales(); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
*/ | */ | ||||
public function actionInstructions() | public function actionInstructions() | ||||
{ | { | ||||
$producer = Producer::searchOne(); | |||||
$producer = $this->getProducerCurrent(); | |||||
// get your HTML raw content without any layouts or scripts | // get your HTML raw content without any layouts or scripts | ||||
$content = $this->renderPartial('instructions_multi', [ | $content = $this->renderPartial('instructions_multi', [ |
namespace backend\controllers; | 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; | ||||
use yii\filters\VerbFilter; | use yii\filters\VerbFilter; | ||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
'delete' => ['post'], | 'delete' => ['post'], | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
} | } | ||||
if ($activeDistribution) { | 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); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
public function actionProcessOrders($key = '', $forceDate = '') | public function actionProcessOrders($key = '', $forceDate = '') | ||||
{ | { | ||||
$producerManager = $this->getProducerManager(); | |||||
$distributionManager = $this->getDistributionManager(); | |||||
$orderManager = $this->getOrderManager(); | |||||
$creditHistoryManager = $this->getCreditHistoryManager(); | |||||
$userManager = $this->getUserManager(); | |||||
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { | if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { | ||||
ini_set('memory_limit', '-1'); | ini_set('memory_limit', '-1'); | ||||
set_time_limit(0); | set_time_limit(0); | ||||
$date = date('Y-m-d', time() + 24 * 60 * 60); | $date = date('Y-m-d', time() + 24 * 60 * 60); | ||||
} | } | ||||
} | } | ||||
$arrayProducers = Producer::searchAll(); | |||||
$arrayProducers = $producerManager->findProducers(); | |||||
foreach ($arrayProducers as $producer) { | foreach ($arrayProducers as $producer) { | ||||
$countOrders = 0; | $countOrders = 0; | ||||
$mailOrdersSend = false; | $mailOrdersSend = false; | ||||
$distribution = DistributionModel::findOne([ | |||||
'date' => $date, | |||||
'active' => 1, | |||||
'id_producer' => $producer->id, | |||||
]); | |||||
$distribution = $distributionManager->findOneDistribution($producer, $date, true); | |||||
if ($distribution) { | if ($distribution) { | ||||
if ($hour == $producer->order_deadline || strlen($forceDate)) { | if ($hour == $producer->order_deadline || strlen($forceDate)) { | ||||
'conditions' => 'date_delete IS NULL' | 'conditions' => 'date_delete IS NULL' | ||||
]); | ]); | ||||
$configCredit = Producer::getConfig('credit', $producer->id); | |||||
$configCredit = $producerManager->getConfig('credit', $producer->id); | |||||
if ($arrayOrders && is_array($arrayOrders)) { | if ($arrayOrders && is_array($arrayOrders)) { | ||||
foreach ($arrayOrders as $order) { | foreach ($arrayOrders as $order) { | ||||
if ($order->auto_payment && $configCredit) { | 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, | 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++; | $countOrders++; | ||||
} | } | ||||
* Envoi des commandes par email au producteur | * 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([ | $arrayOrders = Order::searchAll([ | ||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'distribution.id_producer' => $producer->id | 'distribution.id_producer' => $producer->id | ||||
->setFrom([Yii::$app->params['adminEmail'] => 'distrib']); | ->setFrom([Yii::$app->params['adminEmail'] => 'distrib']); | ||||
if (is_array($arrayOrders) && count($arrayOrders)) { | 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 | // génération du pdf de commande | ||||
Yii::$app->runAction('distribution/report-cron', [ | Yii::$app->runAction('distribution/report-cron', [ | ||||
Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $producer->id . '.pdf') | Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $producer->id . '.pdf') | ||||
); | ); | ||||
} else { | } else { | ||||
$subject = '[distrib] Aucune commande'; | |||||
$subject = '[Opendistrib] Aucune commande'; | |||||
} | } | ||||
$mail->setSubject($subject); | $mail->setSubject($subject); |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\logic\Document\DeliveryNote\DeliveryNoteSearch; | |||||
use Yii; | use Yii; | ||||
use yii\filters\AccessControl; | |||||
use yii\filters\VerbFilter; | |||||
class DeliveryNoteController extends DocumentController | class DeliveryNoteController extends DocumentController | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$searchModel = new DeliveryNoteSearch(); | $searchModel = new DeliveryNoteSearch(); | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\Opendistrib; | |||||
use common\logic\Development\Development\Development; | |||||
use common\logic\Development\DevelopmentPriority\DevelopmentPriority; | |||||
use Yii; | use Yii; | ||||
use yii\data\ActiveDataProvider; | use yii\data\ActiveDataProvider; | ||||
use yii\web\Controller; | |||||
use yii\web\NotFoundHttpException; | use yii\web\NotFoundHttpException; | ||||
use yii\filters\VerbFilter; | |||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
/** | /** | ||||
* DeveloppementController implements the CRUD actions for Developpement model. | * DeveloppementController implements the CRUD actions for Developpement model. | ||||
*/ | */ | ||||
class DevelopmentController extends Controller | |||||
class DevelopmentController extends BackendController | |||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
{ | { | ||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
*/ | */ | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$producerManager = $this->getProducerManager(); | |||||
$versionsArray = Opendistrib::getVersions(); | $versionsArray = Opendistrib::getVersions(); | ||||
$versionsRenderArray = []; | $versionsRenderArray = []; | ||||
foreach ($versionsArray as $version) { | foreach ($versionsArray as $version) { | ||||
]; | ]; | ||||
} | } | ||||
// Producer : set latest version d'Opendistrib | |||||
$producer = GlobalParam::getCurrentProducer(); | |||||
$producer->updateOpendistribVersion(); | |||||
$producer = $this->getProducerCurrent(); | |||||
$producerManager->updateOpendistribVersion($producer); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'versionsArray' => $versionsRenderArray | 'versionsArray' => $versionsRenderArray | ||||
} | } | ||||
public function actionDevelopment($status = DevelopmentModel::STATUS_OPEN) | |||||
public function actionDevelopment($status = Development::STATUS_OPEN) | |||||
{ | { | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => DevelopmentModel::find() | |||||
'query' => Development::find() | |||||
->with(['developmentPriority', 'developmentPriorityCurrentProducer']) | ->with(['developmentPriority', 'developmentPriorityCurrentProducer']) | ||||
->where(['status' => $status]) | ->where(['status' => $status]) | ||||
->orderBy('date DESC'), | ->orderBy('date DESC'), | ||||
/** | /** | ||||
* Creates a new Developpement model. | * Creates a new Developpement model. | ||||
* If creation is successful, the browser will be redirected to the 'view' page. | * If creation is successful, the browser will be redirected to the 'view' page. | ||||
* @return mixed | |||||
*/ | */ | ||||
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$model = new Development(); | $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->date = date('Y-m-d H:i:s'); | ||||
$model->setDateDelivery(); | $model->setDateDelivery(); | ||||
if ($model->save()) { | if ($model->save()) { | ||||
Yii::$app->getSession()->setFlash('success', 'Développement ajouté'); | |||||
$this->setFlash('success', 'Développement ajouté'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
} else { | } else { | ||||
{ | { | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
if ($model->load(Yii::$app->request->post())) { | |||||
if ($model->load(\Yii::$app->request->post())) { | |||||
$model->setDateDelivery(); | $model->setDateDelivery(); | ||||
if ($model->save()) { | if ($model->save()) { | ||||
Yii::$app->getSession()->setFlash('success', 'Développement modifié'); | |||||
$this->setFlash('success', 'Développement modifié'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
} else { | } else { | ||||
public function actionDelete($id) | public function actionDelete($id) | ||||
{ | { | ||||
$this->findModel($id)->delete(); | $this->findModel($id)->delete(); | ||||
Yii::$app->getSession()->setFlash('success', 'Développement supprimé'); | |||||
$this->setFlash('success', 'Développement supprimé'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} | } | ||||
*/ | */ | ||||
public function actionPriority($idDevelopment, $priority = null) | public function actionPriority($idDevelopment, $priority = null) | ||||
{ | { | ||||
$develpmentPriority = DevelopmentPriorityModel::searchOne([ | |||||
$develpmentPriority = DevelopmentPriority::searchOne([ | |||||
'id_development' => $idDevelopment, | '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) { | if ($develpmentPriority) { | ||||
$develpmentPriority->priority = $priority; | $develpmentPriority->priority = $priority; | ||||
/** | /** | ||||
* Finds the Developpement model based on its primary key value. | * Finds the Developpement model based on its primary key value. | ||||
* If the model is not found, a 404 HTTP exception will be thrown. | * 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) | protected function findModel($id) | ||||
{ | { | ||||
if (($model = DevelopmentModel::findOne($id)) !== null) { | |||||
if (($model = Development::findOne($id)) !== null) { | |||||
return $model; | return $model; | ||||
} else { | } else { | ||||
throw new NotFoundHttpException('The requested page does not exist.'); | throw new NotFoundHttpException('The requested page does not exist.'); |
namespace backend\controllers; | namespace backend\controllers; | ||||
use common\helpers\CSV; | |||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use common\helpers\MeanPayment; | use common\helpers\MeanPayment; | ||||
use common\helpers\Password; | |||||
use common\helpers\Price; | use common\helpers\Price; | ||||
use common\helpers\Tiller; | |||||
use common\logic\Distribution\Distribution\Distribution; | 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 DateTime; | ||||
use kartik\mpdf\Pdf; | |||||
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
class DistributionController extends BackendController | class DistributionController extends BackendController | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | '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(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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 = [ | $json = [ | ||||
'distribution' => [], | 'distribution' => [], | ||||
'products' => [] | 'products' => [] | ||||
$dateEnd = strtotime('+' . $numberOfLoadedMonthes); | $dateEnd = strtotime('+' . $numberOfLoadedMonthes); | ||||
} | } | ||||
$producer = GlobalParam::getCurrentProducer(); | |||||
$producer = $this->getProducerCurrent(); | |||||
$json['producer'] = [ | $json['producer'] = [ | ||||
'credit' => $producer->credit, | 'credit' => $producer->credit, | ||||
'tiller' => $producer->tiller, | 'tiller' => $producer->tiller, | ||||
$json['distributions'] = $distributionsArray; | $json['distributions'] = $distributionsArray; | ||||
if ($dateObject && $dateObject->format($format) === $date) { | if ($dateObject && $dateObject->format($format) === $date) { | ||||
// distribution | |||||
$distribution = DistributionModel::initDistribution($date); | |||||
$distribution = $distributionManager->createDistributionIfNotExist($producer, $date); | |||||
$json['distribution'] = [ | $json['distribution'] = [ | ||||
'id' => $distribution->id, | 'id' => $distribution->id, | ||||
'active' => $distribution->active, | 'active' => $distribution->active, | ||||
), | ), | ||||
]; | ]; | ||||
// commandes | |||||
$ordersArray = Order::searchAll([ | $ordersArray = Order::searchAll([ | ||||
'distribution.id' => $distribution->id, | 'distribution.id' => $distribution->id, | ||||
], [ | ], [ | ||||
if ($ordersArray) { | if ($ordersArray) { | ||||
foreach ($ordersArray as $order) { | foreach ($ordersArray as $order) { | ||||
if (is_null($order->date_delete)) { | if (is_null($order->date_delete)) { | ||||
$revenues += $order->getAmountWithTax(); | |||||
$revenues += $orderManager->getAmountWithTax($order); | |||||
$weight += $order->weight; | $weight += $order->weight; | ||||
} | } | ||||
} | } | ||||
$potentialWeight = 0; | $potentialWeight = 0; | ||||
foreach ($productsArray as &$theProduct) { | foreach ($productsArray as &$theProduct) { | ||||
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray); | |||||
$productObject = $productManager->findOneProductById($theProduct['id']); | |||||
$quantityOrder = $orderManager->getProductQuantity($productObject, $ordersArray); | |||||
$theProduct['quantity_ordered'] = $quantityOrder; | $theProduct['quantity_ordered'] = $quantityOrder; | ||||
if (!isset($theProduct['productDistribution'][0])) { | if (!isset($theProduct['productDistribution'][0])) { | ||||
$theProductObject = (object)$theProduct; | $theProductObject = (object)$theProduct; | ||||
$theProduct['productDistribution'][0] = $distribution->linkProduct($theProductObject); | |||||
$theProduct['productDistribution'][0] = $distributionManager->addProduct($distribution, $productObject); | |||||
} | } | ||||
if (!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | if (!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | ||||
$creditHistoryArray[] = [ | $creditHistoryArray[] = [ | ||||
'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), | 'date' => date('d/m/Y H:i:s', strtotime($creditHistory->date)), | ||||
'user' => $creditHistory->getUserObject()->getUsername(), | '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, | $creditHistory, | ||||
Order::AMOUNT_TOTAL, | Order::AMOUNT_TOTAL, | ||||
true | true | ||||
) : ''), | ) : ''), | ||||
'credit' => ($creditHistoryService->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryService->getAmount( | |||||
'credit' => ($creditHistoryManager->isTypeCredit($creditHistory) ? '+ ' . $creditHistoryManager->getAmount( | |||||
$creditHistory, | $creditHistory, | ||||
Order::AMOUNT_TOTAL, | Order::AMOUNT_TOTAL, | ||||
true | true | ||||
$order = array_merge($order->getAttributes(), [ | $order = array_merge($order->getAttributes(), [ | ||||
'selected' => false, | 'selected' => false, | ||||
'weight' => $order->weight, | '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( | 'user' => (isset($order->user)) ? array_merge( | ||||
$order->user->getAttributes(), | $order->user->getAttributes(), | ||||
$arrayCreditUser | $arrayCreditUser | ||||
'productOrder' => $productOrderArray, | 'productOrder' => $productOrderArray, | ||||
'creditHistory' => $creditHistoryArray, | 'creditHistory' => $creditHistoryArray, | ||||
'oneProductUnactivated' => $oneProductUnactivated, | 'oneProductUnactivated' => $oneProductUnactivated, | ||||
'isLinkedToValidDocument' => $order->isLinkedToValidDocument(), | |||||
'isLinkedToValidDocument' => $orderManager->isLinkedToValidDocument($order), | |||||
]); | ]); | ||||
} | } | ||||
} | } | ||||
$json['orders'] = $ordersArray; | $json['orders'] = $ordersArray; | ||||
// points de vente | |||||
$pointsSaleArray = PointSale::find() | $pointsSaleArray = PointSale::find() | ||||
->joinWith([ | ->joinWith([ | ||||
'pointSaleDistribution' => function ($q) use ($distribution) { | 'pointSaleDistribution' => function ($q) use ($distribution) { | ||||
]; | ]; | ||||
// utilisateurs | // utilisateurs | ||||
$usersArray = User::findBy()->all(); | |||||
$usersArray = $userManager->findUsers(); | |||||
$json['users'] = $usersArray; | $json['users'] = $usersArray; | ||||
$dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); | $dateSaturday = date('Y-m-d', strtotime('Saturday', $start)); | ||||
$dateSunday = date('Y-m-d', strtotime('Sunday', $start)); | $dateSunday = date('Y-m-d', strtotime('Sunday', $start)); | ||||
$weekDistribution = DistributionModel::find() | |||||
$weekDistribution = Distribution::find() | |||||
->andWhere([ | ->andWhere([ | ||||
'id_producer' => GlobalParam::getCurrentProducerId(), | 'id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'active' => 1, | 'active' => 1, | ||||
} | } | ||||
// abonnements manquants | // abonnements manquants | ||||
$arraySubscriptions = Subscription::searchByDate($date); | |||||
$arraySubscriptions = $subscriptionManager->findSubscriptionsByDate($date); | |||||
$json['missing_subscriptions'] = []; | $json['missing_subscriptions'] = []; | ||||
if ($distribution->active) { | if ($distribution->active) { | ||||
foreach ($arraySubscriptions as $subscription) { | foreach ($arraySubscriptions as $subscription) { | ||||
public function actionAjaxPointSaleFavorite($idUser) | public function actionAjaxPointSaleFavorite($idUser) | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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; | $idFavoritePointSale = 0; | ||||
if ($favoritePointSale) { | if ($favoritePointSale) { | ||||
$idFavoritePointSale = $favoritePointSale->id; | $idFavoritePointSale = $favoritePointSale->id; | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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() | $productsArray = Product::find() | ||||
->where([ | ->where([ | ||||
$productOrderArray = []; | $productOrderArray = []; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$priceArray = $product->getPriceArray($user, $pointSale); | |||||
$priceArray = $productManager->getPriceArray($product, $user, $pointSale); | |||||
$quantity = 0; | $quantity = 0; | ||||
$invoicePrice = null; | $invoicePrice = null; | ||||
'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], | 'unit_coefficient' => Product::$unitsArray[$product->unit]['coefficient'], | ||||
'prices' => $priceArray, | 'prices' => $priceArray, | ||||
'active' => $product->productDistribution[0]->active | 'active' => $product->productDistribution[0]->active | ||||
&& (!$pointSale || $product->isAvailableOnPointSale($pointSale)), | |||||
&& (!$pointSale || $productManager->isAvailableOnPointSale($product, $pointSale)), | |||||
'invoice_price' => $invoicePrice | 'invoice_price' => $invoicePrice | ||||
]; | ]; | ||||
} | } | ||||
public function actionAjaxUpdateInvoicePrices($idOrder) | 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()) { | if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | ||||
$userProducer = null; | $userProducer = null; | ||||
if ($order->id_user) { | 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) { | foreach ($order->productOrder as $productOrder) { | ||||
$invoicePrice = $productOrder->product->getPrice([ | |||||
$invoicePrice = $productManager->getPrice($productOrder->product, [ | |||||
'user' => $order->user ?: null, | 'user' => $order->user ?: null, | ||||
'point_sale' => $order->pointSale, | 'point_sale' => $order->pointSale, | ||||
'user_producer' => $userProducer, | 'user_producer' => $userProducer, | ||||
* @param boolean $save | * @param boolean $save | ||||
* @param integer $idProducer | * @param integer $idProducer | ||||
* @param string $key | * @param string $key | ||||
* @return PDF|null | |||||
* @return Pdf|null | |||||
*/ | */ | ||||
public function actionReportCron($date = '', $save = false, $idProducer = 0, $key = '') | public function actionReportCron($date = '', $save = false, $idProducer = 0, $key = '') | ||||
{ | { | ||||
* @param string $date | * @param string $date | ||||
* @param boolean $save | * @param boolean $save | ||||
* @param integer $idProducer | * @param integer $idProducer | ||||
* @return PDF|null | |||||
* @return Pdf|null|string | |||||
*/ | */ | ||||
public function actionReport($date = '', $save = false, $idProducer = 0, $type = "pdf") | 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(); | $idProducer = GlobalParam::getCurrentProducerId(); | ||||
} | } | ||||
] | ] | ||||
); | ); | ||||
$distribution = DistributionModel::searchOne([ | |||||
$distribution = Distribution::searchOne([ | |||||
'id_producer' => $idProducer | 'id_producer' => $idProducer | ||||
], [ | ], [ | ||||
'conditions' => 'date LIKE :date', | 'conditions' => 'date LIKE :date', | ||||
]); | ]); | ||||
if ($distribution) { | if ($distribution) { | ||||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | |||||
$selectedProductsArray = $productDistributionManager->findProductDistributionsByDistribution($distribution); | |||||
$pointsSaleArray = PointSale::searchAll([ | $pointsSaleArray = PointSale::searchAll([ | ||||
'point_sale.id_producer' => $idProducer | 'point_sale.id_producer' => $idProducer | ||||
]); | ]); | ||||
'pointsSaleArray' => $pointsSaleArray, | 'pointsSaleArray' => $pointsSaleArray, | ||||
'productsArray' => $productsArray, | 'productsArray' => $productsArray, | ||||
'ordersArray' => $ordersArray, | 'ordersArray' => $ordersArray, | ||||
'producer' => Producer::searchOne(['id' => $idProducer]) | |||||
'producer' => $producerManager->findOneProducerById($idProducer) | |||||
]); | ]); | ||||
$dateStr = date('d/m/Y', strtotime($date)); | $dateStr = date('d/m/Y', strtotime($date)); | ||||
'orientation' => $orientationPdf, | 'orientation' => $orientationPdf, | ||||
// stream to browser inline | // stream to browser inline | ||||
'destination' => $destination, | 'destination' => $destination, | ||||
'filename' => Yii::getAlias( | |||||
'filename' => \Yii::getAlias( | |||||
'@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf' | '@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf' | ||||
), | ), | ||||
// your html content input | // your html content input | ||||
} elseif ($type == 'csv') { | } elseif ($type == 'csv') { | ||||
$datas = []; | $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 | // produits en colonne | ||||
$productsNameArray = ['', 'Commentaire']; | $productsNameArray = ['', 'Commentaire']; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$productsHasQuantity[$product->id] = 0; | $productsHasQuantity[$product->id] = 0; | ||||
foreach (Product::$unitsArray as $unit => $dataUnit) { | foreach (Product::$unitsArray as $unit => $dataUnit) { | ||||
$quantity = Order::getProductQuantity($product->id, $ordersArray, true, $unit); | |||||
$quantity = $orderManager->getProductQuantity($product, $ordersArray, true, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$productsHasQuantity[$product->id] += $quantity; | $productsHasQuantity[$product->id] += $quantity; | ||||
} | } | ||||
} | } | ||||
if ($productsHasQuantity[$product->id] > 0 || $optionCsvExportAllProducts) { | if ($productsHasQuantity[$product->id] > 0 || $optionCsvExportAllProducts) { | ||||
$productName = $product->getNameExport(); | |||||
$productName = $productManager->getNameExport($product); | |||||
if ($optionCsvExportByPiece) { | if ($optionCsvExportByPiece) { | ||||
$productUnit = 'piece'; | $productUnit = 'piece'; | ||||
$productUnit = $product->unit; | $productUnit = $product->unit; | ||||
} | } | ||||
$productName .= ' (' . Product::strUnit($productUnit, 'wording_short', true) . ')'; | |||||
$productName .= ' (' . $productManager->strUnit($productUnit, 'wording_short', true) . ')'; | |||||
$productsNameArray[] = $productName; | $productsNameArray[] = $productName; | ||||
$productsIndexArray[$product->id] = $cpt++; | $productsIndexArray[$product->id] = $cpt++; | ||||
// listing commandes | // listing commandes | ||||
$datas[] = ['> ' . $pointSale->name]; | $datas[] = ['> ' . $pointSale->name]; | ||||
foreach ($pointSale->orders as $order) { | foreach ($pointSale->orders as $order) { | ||||
$orderLine = [$order->getStrUser(), $order->getCommentReport()]; | |||||
$orderLine = [$orderManager->getOrderUsername($order), $orderManager->getCommentReport($order)]; | |||||
if ($optionCsvExportByPiece) { | if ($optionCsvExportByPiece) { | ||||
foreach ($order->productOrder as $productOrder) { | 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] | [$order] | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; | $orderLine[$productsIndexArray[$productOrder->id_product]] .= $productOrder->quantity; | ||||
if ($productOrder->product->unit != $productOrder->unit) { | if ($productOrder->product->unit != $productOrder->unit) { | ||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= Product::strUnit( | |||||
$orderLine[$productsIndexArray[$productOrder->id_product]] .= $productManager->strUnit( | |||||
$productOrder->unit, | $productOrder->unit, | ||||
'wording_short', | 'wording_short', | ||||
true | true | ||||
public function actionReportGrid($date = '', $save = false, $idProducer = 0, $type = "pdf") | 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(); | $idProducer = GlobalParam::getCurrentProducerId(); | ||||
} | } | ||||
$distribution = DistributionModel::searchOne([ | |||||
$distribution = Distribution::searchOne([ | |||||
'id_producer' => $idProducer | 'id_producer' => $idProducer | ||||
], [ | ], [ | ||||
'conditions' => 'date LIKE :date', | 'conditions' => 'date LIKE :date', | ||||
] | ] | ||||
); | ); | ||||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | |||||
$selectedProductsArray = $productDistribution->findProductDistributionsByDistribution($distribution); | |||||
$pointsSaleArray = PointSale::searchAll([ | $pointsSaleArray = PointSale::searchAll([ | ||||
'point_sale.id_producer' => $idProducer | 'point_sale.id_producer' => $idProducer | ||||
]); | ]); | ||||
foreach ($pointsSaleArray as $pointSale) { | foreach ($pointsSaleArray as $pointSale) { | ||||
$pointSale->initOrders($ordersArray); | |||||
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray); | |||||
} | } | ||||
$ordersByPage = 22; | $ordersByPage = 22; | ||||
} | } | ||||
// catégories | // catégories | ||||
$categoriesArray = ProductCategory::searchAll( | |||||
['id_producer' => $idProducer], | |||||
['orderby' => 'product_category.position ASC'] | |||||
); | |||||
$categoriesArray = $productCategoryManager->findProductCategories(); | |||||
array_unshift($categoriesArray, null); | array_unshift($categoriesArray, null); | ||||
// produits | // produits | ||||
'categoriesArray' => $categoriesArray, | 'categoriesArray' => $categoriesArray, | ||||
'productsArray' => $productsArray, | 'productsArray' => $productsArray, | ||||
'ordersArray' => $ordersArrayPaged, | 'ordersArray' => $ordersArrayPaged, | ||||
'producer' => Producer::searchOne(['id' => $idProducer]) | |||||
'producer' => $producerManager->findOneProducerById($idProducer) | |||||
]); | ]); | ||||
$dateStr = date('d/m/Y', strtotime($date)); | $dateStr = date('d/m/Y', strtotime($date)); | ||||
'orientation' => $orientationPdf, | 'orientation' => $orientationPdf, | ||||
// stream to browser inline | // stream to browser inline | ||||
'destination' => $destination, | 'destination' => $destination, | ||||
'filename' => Yii::getAlias( | |||||
'filename' => \Yii::getAlias( | |||||
'@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf' | '@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf' | ||||
), | ), | ||||
// your html content input | // your html content input | ||||
/** | /** | ||||
* Génère un export des commandes au format CSV à destination du Google Drive | * Génère un export des commandes au format CSV à destination du Google Drive | ||||
* de Terre de pains. | * de Terre de pains. | ||||
* | |||||
* @param type $date | |||||
* @return CSV | |||||
*/ | */ | ||||
public function actionReportTerredepains($date, $key) | 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; | $idProducer = $producer->id; | ||||
$ordersArray = Order::searchAll( | $ordersArray = Order::searchAll( | ||||
] | ] | ||||
); | ); | ||||
$distribution = DistributionModel::searchOne([ | |||||
$distribution = Distribution::searchOne([ | |||||
'distribution.id_producer' => $idProducer | 'distribution.id_producer' => $idProducer | ||||
], [ | ], [ | ||||
'conditions' => 'date LIKE :date', | 'conditions' => 'date LIKE :date', | ||||
]); | ]); | ||||
if ($distribution) { | if ($distribution) { | ||||
$selectedProductsArray = ProductDistributionModel::searchByDistribution($distribution->id); | |||||
$pointsSaleArray = PointSale::searchAll([ | $pointsSaleArray = PointSale::searchAll([ | ||||
'point_sale.id_producer' => $idProducer | 'point_sale.id_producer' => $idProducer | ||||
]); | ]); | ||||
foreach ($pointsSaleArray as $pointSale) { | foreach ($pointsSaleArray as $pointSale) { | ||||
$pointSale->initOrders($ordersArray); | |||||
$pointSaleManager->initPointSaleOrders($pointSale, $ordersArray); | |||||
} | } | ||||
// produits | // produits | ||||
$productsHasQuantity = []; | $productsHasQuantity = []; | ||||
$cpt = 1; | $cpt = 1; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$theUnit = Product::strUnit($product->unit, 'wording_short', true); | |||||
$theUnit = $productManager->strUnit($product->unit, 'wording_short', true); | |||||
$theUnit = ($theUnit == 'p.') ? '' : ' (' . $theUnit . ')'; | $theUnit = ($theUnit == 'p.') ? '' : ' (' . $theUnit . ')'; | ||||
$productsNameArray[] = $product->name . $theUnit; | $productsNameArray[] = $product->name . $theUnit; | ||||
$productsIndexArray[$product->id] = $cpt++; | $productsIndexArray[$product->id] = $cpt++; | ||||
public function _totalReportCSV($label, $ordersArray, $productsArray, $productsIndexArray) | public function _totalReportCSV($label, $ordersArray, $productsArray, $productsIndexArray) | ||||
{ | { | ||||
$orderManager = $this->getOrderManager(); | |||||
$productManager = $this->getProductManager(); | |||||
$totalsPointSaleArray = [$label]; | $totalsPointSaleArray = [$label]; | ||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
foreach (Product::$unitsArray as $unit => $dataUnit) { | foreach (Product::$unitsArray as $unit => $dataUnit) { | ||||
$quantity = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
$quantity = $orderManager->getProductQuantity($product, $ordersArray, false, $unit); | |||||
if ($quantity) { | if ($quantity) { | ||||
$index = $productsIndexArray[$product->id]; | $index = $productsIndexArray[$product->id]; | ||||
if (!isset($totalsPointSaleArray[$index])) { | if (!isset($totalsPointSaleArray[$index])) { | ||||
$totalsPointSaleArray[$index] .= $quantity; | $totalsPointSaleArray[$index] .= $quantity; | ||||
if ($product->unit != $unit) { | if ($product->unit != $unit) { | ||||
$totalsPointSaleArray[$index] .= '' . Product::strUnit($unit, 'wording_short', true); | |||||
$totalsPointSaleArray[$index] .= '' . $productManager->strUnit($unit, 'wording_short', true); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
public function _totalReportPiecesCSV($label, $ordersArray, $productsArray, $productsIndexArray) | public function _totalReportPiecesCSV($label, $ordersArray, $productsArray, $productsIndexArray) | ||||
{ | { | ||||
$totalsPointSaleArray = [$label]; | |||||
$orderManager = $this->getOrderManager(); | |||||
$totalsPointSaleArray = [$label]; | |||||
foreach ($productsArray as $product) { | foreach ($productsArray as $product) { | ||||
$quantity = 0; | $quantity = 0; | ||||
foreach (Product::$unitsArray as $unit => $dataUnit) { | foreach (Product::$unitsArray as $unit => $dataUnit) { | ||||
$quantityProduct = Order::getProductQuantity($product->id, $ordersArray, false, $unit); | |||||
$quantityProduct = $orderManager->getProductQuantity($product, $ordersArray, false, $unit); | |||||
if ($unit == 'piece') { | if ($unit == 'piece') { | ||||
$quantity += $quantityProduct; | $quantity += $quantityProduct; | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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->quantity_max = (!$quantityMax) ? null : (float)$quantityMax; | ||||
$productDistribution->save(); | |||||
$productDistributionManager->saveUpdate($productDistribution); | |||||
return ['success']; | return ['success']; | ||||
} | } | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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->active = $active; | ||||
$productDistribution->save(); | |||||
$productDistributionManager->saveUpdate($productDistribution); | |||||
return ['success']; | return ['success']; | ||||
} | } | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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->delivery = $delivery; | ||||
$pointSaleDistribution->save(); | |||||
$pointSaleDistributionManager->saveUpdate($pointSaleDistribution); | |||||
return ['success']; | 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. | * Active/désactive un jour de distribution. | ||||
* | * | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$distributionManager = $this->getDistributionManager(); | |||||
$producerCurrent = $this->getProducerCurrent(); | |||||
if ($idDistribution) { | if ($idDistribution) { | ||||
$distribution = DistributionModel::searchOne([ | |||||
'id' => $idDistribution | |||||
]); | |||||
$distribution = $distributionManager->findOneDistributionById($idDistribution); | |||||
} | } | ||||
$format = 'Y-m-d'; | $format = 'Y-m-d'; | ||||
$dateObject = DateTime::createFromFormat($format, $date); | $dateObject = DateTime::createFromFormat($format, $date); | ||||
if ($dateObject && $dateObject->format($format) === $date) { | if ($dateObject && $dateObject->format($format) === $date) { | ||||
$distribution = DistributionModel::initDistribution($date); | |||||
$distribution = $distributionManager->createDistributionIfNotExist($producerCurrent, $date); | |||||
} | } | ||||
if ($distribution) { | if ($distribution) { | ||||
$distribution->active($active); | |||||
$distributionManager->activeDistribution($distribution, $active); | |||||
return ['success']; | return ['success']; | ||||
} | } | ||||
public function actionAjaxProcessAddSubscriptions($date) | public function actionAjaxProcessAddSubscriptions($date) | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
Subscription::addAll($date, true); | |||||
$this->getOrderManager()->createAllOrdersFromSubscriptions($date, true); | |||||
return ['success']; | return ['success']; | ||||
} | } | ||||
public function actionAjaxProcessSynchroTiller($date) | public function actionAjaxProcessSynchroTiller($date) | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$producerManager = $this->getProducerManager(); | |||||
$productOrderManager = $this->getProductOrderManager(); | |||||
$orderManager = $this->getOrderManager(); | |||||
$return = []; | $return = []; | ||||
$producerTiller = Producer::getConfig('tiller'); | |||||
$producerTiller = $producerManager->getConfig('tiller'); | |||||
if ($producerTiller) { | if ($producerTiller) { | ||||
$tiller = new Tiller(); | $tiller = new Tiller(); | ||||
foreach ($order->productOrder as $productOrder) { | foreach ($order->productOrder as $productOrder) { | ||||
$lines[] = [ | $lines[] = [ | ||||
'name' => $productOrder->product->name, | 'name' => $productOrder->product->name, | ||||
'price' => $productOrder->getPriceWithTax() * 100 * $productOrder->quantity, | |||||
'price' => $productOrderManager->getPriceWithTax($productOrder) * 100 * $productOrder->quantity, | |||||
'tax' => $productOrder->taxRate->value * 100, | 'tax' => $productOrder->taxRate->value * 100, | ||||
'date' => $strDate, | 'date' => $strDate, | ||||
'quantity' => $productOrder->quantity | 'quantity' => $productOrder->quantity | ||||
'payments' => [ | 'payments' => [ | ||||
[ | [ | ||||
'type' => $typePaymentTiller, | 'type' => $typePaymentTiller, | ||||
'amount' => $order->getAmountWithTax( | |||||
'amount' => $orderManager->getOrderAmountWithTax( | |||||
$order, | |||||
Order::AMOUNT_TOTAL | Order::AMOUNT_TOTAL | ||||
) * 100, | ) * 100, | ||||
'status' => 'ACCEPTED', | 'status' => 'ACCEPTED', | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$deliveryNoteManager = $this->getDeliveryNoteManager(); | |||||
if (strlen($idOrders)) { | if (strlen($idOrders)) { | ||||
$idOrders = json_decode($idOrders, true); | $idOrders = json_decode($idOrders, true); | ||||
]); | ]); | ||||
if ($deliveryNote && $deliveryNote->isStatusDraft()) { | if ($deliveryNote && $deliveryNote->isStatusDraft()) { | ||||
$deliveryNote->changeStatus(Document::STATUS_VALID); | |||||
$deliveryNote->save(); | |||||
$deliveryNoteManager->changeStatus($deliveryNote, Document::STATUS_VALID); | |||||
$deliveryNoteManager->saveUpdate($deliveryNote); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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)) { | if (strlen($idOrders)) { | ||||
$idOrders = json_decode($idOrders, true); | $idOrders = json_decode($idOrders, true); | ||||
if (!$deliveryNote) { | if (!$deliveryNote) { | ||||
$deliveryNote = new DeliveryNote(); | $deliveryNote = new DeliveryNote(); | ||||
$deliveryNote->initTaxCalculationMethod(); | |||||
$deliveryNoteManager->initTaxCalculationMethod($deliveryNote); | |||||
$deliveryNote->id_producer = GlobalParam::getCurrentProducerId(); | $deliveryNote->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$deliveryNote->id_user = $order->id_user; | $deliveryNote->id_user = $order->id_user; | ||||
$deliveryNote->name = 'Bon de livraison ' . $order->getUsername() . ' (' . date( | $deliveryNote->name = 'Bon de livraison ' . $order->getUsername() . ' (' . date( | ||||
$order->save(); | $order->save(); | ||||
// init invoice prices | // 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' => $user, | ||||
'user_producer' => $userProducer, | 'user_producer' => $userProducer, | ||||
'point_sale' => $order->pointSale | 'point_sale' => $order->pointSale | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \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)) { | if (strlen($idOrders)) { | ||||
$idOrders = json_decode($idOrders, true); | $idOrders = json_decode($idOrders, true); | ||||
// génération du BL | // génération du BL | ||||
if (!$deliveryNote) { | if (!$deliveryNote) { | ||||
$deliveryNote = new DeliveryNote; | $deliveryNote = new DeliveryNote; | ||||
$deliveryNote->initTaxCalculationMethod(); | |||||
$deliveryNoteManager->initTaxCalculationMethod($deliveryNote); | |||||
$deliveryNote->name = 'Bon de livraison ' . $firstOrder->pointSale->name . ' (' . date( | $deliveryNote->name = 'Bon de livraison ' . $firstOrder->pointSale->name . ' (' . date( | ||||
'd/m/Y', | 'd/m/Y', | ||||
strtotime( | strtotime( | ||||
if ($firstOrder->pointSale->id_user) { | if ($firstOrder->pointSale->id_user) { | ||||
$deliveryNote->id_user = $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 { | } else { | ||||
$user = new User; | $user = new User; | ||||
$user->type = User::TYPE_LEGAL_PERSON; | $user->type = User::TYPE_LEGAL_PERSON; | ||||
} | } | ||||
$user->save(); | $user->save(); | ||||
$userProducer = new UserProducer; | |||||
$userProducer = new UserProducer(); | |||||
$userProducer->id_user = $user->id; | $userProducer->id_user = $user->id; | ||||
$userProducer->id_producer = GlobalParam::getCurrentProducerId(); | $userProducer->id_producer = GlobalParam::getCurrentProducerId(); | ||||
$userProducer->credit = 0; | $userProducer->credit = 0; | ||||
} | } | ||||
if (!isset($user) || !$user) { | 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 | // affectation du BL aux commandes | ||||
foreach ($idOrders as $idOrder) { | foreach ($idOrders as $idOrder) { | ||||
$order = Order::searchOne([ | |||||
'id' => (int)$idOrder | |||||
]); | |||||
$order = $orderManager->findOneOrderById((int)$idOrder); | |||||
if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | if ($order && $order->distribution->id_producer == GlobalParam::getCurrentProducerId()) { | ||||
$order->id_delivery_note = $deliveryNote->id; | $order->id_delivery_note = $deliveryNote->id; | ||||
$order->save(); | $order->save(); | ||||
} | } | ||||
// init invoice price | // init invoice price | ||||
$order = Order::searchOne(['id' => $idOrder]); | |||||
$order = $orderManager->findOneOrderById((int)$idOrder); | |||||
if ($order) { | 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 | |||||
]); | |||||
} | } | ||||
} | } | ||||
namespace backend\controllers; | 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\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 kartik\mpdf\Pdf; | ||||
use yii\base\UserException; | use yii\base\UserException; | ||||
use yii; | use yii; | ||||
use yii\filters\VerbFilter; | |||||
use yii\filters\AccessControl; | |||||
class DocumentController extends BackendController | class DocumentController extends BackendController | ||||
{ | { | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
public function actionCreate() | public function actionCreate() | ||||
{ | { | ||||
$documentManager = $this->getDocumentManager(); | |||||
$class = $this->getClass(); | $class = $this->getClass(); | ||||
$model = new $class(); | $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(); | $model->id_producer = GlobalParam::getCurrentProducerId(); | ||||
if ($model->save()) { | if ($model->save()) { | ||||
$this->processInvoiceViaDeliveryNotes($model); | $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]); | return $this->redirect(['/' . $this->getControllerUrl() . '/update', 'id' => $model->id]); | ||||
} else { | } 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.'); | |||||
} | } | ||||
} | } | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
if (!$model) { | 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', [ | return $this->render('/document/update', [ | ||||
public function actionDelete($id) | public function actionDelete($id) | ||||
{ | { | ||||
$documentManager = $this->getDocumentManager(); | |||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
if ($model->isStatusValid()) { | |||||
if ($documentManager->isStatusValid($model)) { | |||||
throw new UserException('Vous ne pouvez pas supprimer un document validé.'); | throw new UserException('Vous ne pouvez pas supprimer un document validé.'); | ||||
} | } | ||||
$model->delete(); | |||||
$documentManager->delete($model); | |||||
if ($this->getClass() == 'DeliveryNote') { | if ($this->getClass() == 'DeliveryNote') { | ||||
Order::updateAll([ | Order::updateAll([ | ||||
]); | ]); | ||||
} | } | ||||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('delete', $model)); | |||||
$this->setFlash('success', $this->getFlashMessage('delete', $model)); | |||||
$this->redirect([$this->getControllerUrl() . '/index']); | $this->redirect([$this->getControllerUrl() . '/index']); | ||||
} | } | ||||
{ | { | ||||
$document = $this->findModel($id); | $document = $this->findModel($id); | ||||
$document->downloadPdf(true); | $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]); | return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]); | ||||
} | } | ||||
$document->is_sent = true; | $document->is_sent = true; | ||||
$document->save(); | $document->save(); | ||||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('send', $document)); | |||||
$this->setFlash('success', $this->getFlashMessage('send', $document)); | |||||
} else { | } else { | ||||
Yii::$app->getSession()->setFlash('danger', $this->getFlashMessage('send', $document)); | |||||
$this->setFlash('danger', $this->getFlashMessage('send', $document)); | |||||
} | } | ||||
if ($backUpdateForm) { | if ($backUpdateForm) { | ||||
// génération PDF | // génération PDF | ||||
$document->generatePdf(Pdf::DEST_FILE); | $document->generatePdf(Pdf::DEST_FILE); | ||||
Yii::$app->getSession()->setFlash('success', $this->getFlashMessage('validate', $document)); | |||||
$this->setFlash('success', $this->getFlashMessage('validate', $document)); | |||||
if ($backUpdateForm) { | if ($backUpdateForm) { | ||||
return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]); | return $this->redirect([$this->getControllerUrl() . '/update', 'id' => $id]); | ||||
} | } | ||||
} | } | ||||
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']); | return $this->redirect([$this->getControllerUrl() . '/index']); | ||||
} | } | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$searchModel = new InvoiceSearch(); | $searchModel = new InvoiceSearch(); | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, |
{ | { | ||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, |
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$searchModel = new PointSaleSearch(); | $searchModel = new PointSaleSearch(); | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
{ | { | ||||
$model = new PointSale(); | $model = new PointSale(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | |||||
if ($model->load(\Yii::$app->request->post()) && $model->save()) { | |||||
$model->processPointProduction(); | $model->processPointProduction(); | ||||
$model->processRestrictedAccess(); | $model->processRestrictedAccess(); | ||||
DistributionModel::linkPointSaleIncomingDistributions($model); | DistributionModel::linkPointSaleIncomingDistributions($model); | ||||
$model->users_comment[$userPointSale->id_user] = $userPointSale->comment; | $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->processPointProduction(); | ||||
$model->processRestrictedAccess(); | $model->processRestrictedAccess(); | ||||
DistributionModel::linkPointSaleIncomingDistributions($model); | DistributionModel::linkPointSaleIncomingDistributions($model); | ||||
Yii::$app->getSession()->setFlash('success', 'Point de vente modifié.'); | |||||
$this->setFlash('success', 'Point de vente modifié.'); | |||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', array_merge($this->initForm($id), [ | return $this->render('update', array_merge($this->initForm($id), [ | ||||
} | } | ||||
} | } | ||||
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 { | } 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'])); | . Html::a('Oui', ['point-sale/delete', 'id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']) . ' ' . Html::a('Non', ['point-sale/index'], ['class' => 'btn btn-default'])); | ||||
} | } | ||||
if (!$pointSale->default) { | if (!$pointSale->default) { | ||||
$pointSale->default = 1; | $pointSale->default = 1; | ||||
$pointSale->save(); | $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 { | } 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'); | |||||
} | } | ||||
} | } | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
'delete' => ['post'], | 'delete' => ['post'], | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||||
return $this->getUserManager()->isCurrentAdmin(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
{ | { | ||||
$model = new Producer(); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
{ | { | ||||
$model = $this->findModel($id); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
} | } | ||||
if ($count) { | 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 { | } else { | ||||
Yii::$app->getSession()->setFlash('error', 'Aucun client à importer.'); | |||||
$this->setFlash('error', 'Aucun client à importer.'); | |||||
} | } | ||||
return $this->redirect(['producer-admin/index']); | return $this->redirect(['producer-admin/index']); |
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
'delete' => ['post'], | 'delete' => ['post'], | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
$model->option_dashboard_date_end = date('d/m/Y', strtotime($model->option_dashboard_date_end)); | $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)) { | if (strlen($model->option_dashboard_date_start)) { | ||||
$model->option_dashboard_date_start = date( | $model->option_dashboard_date_start = date( | ||||
$model->option_stripe_endpoint_secret = ''; | $model->option_stripe_endpoint_secret = ''; | ||||
$model->save(); | $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]); | return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]); | ||||
} else { | } 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', [ | return $this->render('update', [ | ||||
'model' => $model, | 'model' => $model, | ||||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | $producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | ||||
if ($producer->load(Yii::$app->request->post())) { | |||||
if ($producer->load(\Yii::$app->request->post())) { | |||||
$producer->save(); | $producer->save(); | ||||
if (!is_null($producer->free_price)) { | if (!is_null($producer->free_price)) { | ||||
{ | { | ||||
$producer = GlobalParam::getCurrentProducer(); | $producer = GlobalParam::getCurrentProducer(); | ||||
$producer->updateOpendistribVersion(); | $producer->updateOpendistribVersion(); | ||||
return $this->redirect(Yii::$app->request->referrer); | |||||
return $this->redirect(\Yii::$app->request->referrer); | |||||
} | } | ||||
} | } |
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return User::getCurrentStatus() == User::STATUS_ADMIN; | |||||
return $this->getUserManager()->isCurrentAdmin(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
{ | { | ||||
$model = new ProducerPriceRange(); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
{ | { | ||||
$model = $this->findModel($id); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
]); | ]); | ||||
$producerPriceRange->delete(); | $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']); | return $this->redirect(['producer-price-range-admin/index']); | ||||
} | } | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$searchModel = new ProductCategorySearch(); | $searchModel = new ProductCategorySearch(); | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
$model->id_producer = GlobalParam::getCurrentProducerId(); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
{ | { | ||||
$model = $this->findModel($id); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
$productCategory->delete(); | $productCategory->delete(); | ||||
Product::updateAll(['id_product_category' => null], ['id_product_category' => $id]); | 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']); | return $this->redirect(['index']); | ||||
} | } |
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$searchModel = new ProductSearch(); | $searchModel = new ProductSearch(); | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
$model->sunday = 1; | $model->sunday = 1; | ||||
$model->available_on_points_sale = 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(); | $lastProductOrder = Product::find()->where('id_producer = :id_producer')->params([':id_producer' => GlobalParam::getCurrentProducerId()])->orderBy('order DESC')->one(); | ||||
if ($lastProductOrder) { | if ($lastProductOrder) { | ||||
// link product / distribution | // link product / distribution | ||||
DistributionModel::linkProductIncomingDistributions($model); | 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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
$photoFilenameOld = $model->photo; | $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); | Upload::uploadFile($model, 'photo', $photoFilenameOld); | ||||
DistributionModel::linkProductIncomingDistributions($model); | 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']); | return $this->redirect(['index']); | ||||
} | } | ||||
$searchModel = new ProductPriceSearch(); | $searchModel = new ProductPriceSearch(); | ||||
$searchModel->id_product = $id; | $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 | 'id_product' => $id | ||||
])); | ])); | ||||
$model->id_product = $idProduct; | $model->id_product = $idProduct; | ||||
$modelProduct = $this->findModel($idProduct); | $modelProduct = $this->findModel($idProduct); | ||||
if ($model->load(Yii::$app->request->post())) { | |||||
if ($model->load(\Yii::$app->request->post())) { | |||||
$conditionsProductPriceExist = [ | $conditionsProductPriceExist = [ | ||||
'id_product' => $idProduct, | 'id_product' => $idProduct, | ||||
if ($productPriceExist) { | if ($productPriceExist) { | ||||
$productPriceExist->delete(); | $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()) { | 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]); | return $this->redirect(['product/prices-list', 'id' => $idProduct]); | ||||
} | } | ||||
} | } | ||||
$model = $this->findModelProductPrice($id); | $model = $this->findModelProductPrice($id); | ||||
$modelProduct = $this->findModel($model->id_product); | $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]); | return $this->redirect(['product/prices-list', 'id' => $model->id_product]); | ||||
} | } | ||||
{ | { | ||||
$productPrice = $this->findModelProductPrice($id); | $productPrice = $this->findModelProductPrice($id); | ||||
$productPrice->delete(); | $productPrice->delete(); | ||||
Yii::$app->getSession()->setFlash('success', 'Prix supprimé'); | |||||
$this->setFlash('success', 'Prix supprimé'); | |||||
return $this->redirect(['product/prices-list', 'id' => $productPrice->id_product]); | return $this->redirect(['product/prices-list', 'id' => $productPrice->id_product]); | ||||
} | } | ||||
if ($confirm) { | if ($confirm) { | ||||
$product->delete(); | $product->delete(); | ||||
ProductDistributionModel::deleteAll(['id_product' => $id]); | 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 { | } 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'])); | . Html::a('Oui', ['product/delete', 'id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']) . ' ' . Html::a('Non', ['product/index'], ['class' => 'btn btn-default'])); | ||||
} | } | ||||
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$searchModel = new QuotationSearch(); | $searchModel = new QuotationSearch(); | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
'order.id_quotation' => $id | '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']); | return $this->redirect(['/' . $this->getControllerUrl() . '/index']); | ||||
} else { | } else { | ||||
throw new UserException('Vous ne pouvez pas transformer en facture un devis non validé.'); | throw new UserException('Vous ne pouvez pas transformer en facture un devis non validé.'); |
{ | { | ||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, |
} | } | ||||
$model = new LoginForm(); | $model = new LoginForm(); | ||||
if ($model->load(Yii::$app->request->post()) && $model->login()) { | |||||
if ($model->load(\Yii::$app->request->post()) && $model->login()) { | |||||
return $this->goBack(); | return $this->goBack(); | ||||
} else { | } else { | ||||
return $this->render('login', [ | return $this->render('login', [ |
{ | { | ||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, |
{ | { | ||||
return [ | return [ | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
$this->checkProductsPointsSale(); | $this->checkProductsPointsSale(); | ||||
$searchModel = new SubscriptionSearch; | $searchModel = new SubscriptionSearch; | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
'orderby' => 'product.order ASC' | 'orderby' => 'product.order ASC' | ||||
]); | ]); | ||||
if ($model->load(Yii::$app->request->post()) && $model->validate() | |||||
if ($model->load(\Yii::$app->request->post()) && $model->validate() | |||||
&& $model->save()) { | && $model->save()) { | ||||
Yii::$app->getSession()->setFlash('success', 'Abonnement ajouté'); | |||||
$this->setFlash('success', 'Abonnement ajouté'); | |||||
$subscription = Subscription::findOne($model->id); | $subscription = Subscription::findOne($model->id); | ||||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | $matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | ||||
'orderby' => 'product.order ASC' | '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) { | if (!$model->date_end) { | ||||
$model->date_end = null; | $model->date_end = null; | ||||
} | } | ||||
} | } | ||||
Yii::$app->getSession()->setFlash('success', 'Abonnement modifié' . $messageOrdersDeleted); | |||||
$this->setFlash('success', 'Abonnement modifié' . $messageOrdersDeleted); | |||||
$matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | $matchedDistributionsArray = $subscription->searchMatchedIncomingDistributions(); | ||||
if (count($matchedDistributionsArray)) { | if (count($matchedDistributionsArray)) { | ||||
$subscription->deleteOrdersIncomingDistributions(); | $subscription->deleteOrdersIncomingDistributions(); | ||||
$subscription->delete(); | $subscription->delete(); | ||||
ProductSubscription::deleteAll(['id_subscription' => $id]); | ProductSubscription::deleteAll(['id_subscription' => $id]); | ||||
Yii::$app->getSession()->setFlash('success', 'Abonnement supprimé'); | |||||
$this->setFlash('success', 'Abonnement supprimé'); | |||||
return $this->redirect(['subscription/index']); | return $this->redirect(['subscription/index']); | ||||
} | } | ||||
foreach ($matchedDistributionsArray as $distribution) { | foreach ($matchedDistributionsArray as $distribution) { | ||||
$subscription->add($distribution->date); | $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']); | return $this->redirect(['subscription/index']); | ||||
} | } | ||||
{ | { | ||||
$model = $this->getTaxRateManager()->createTaxRate(); | $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.'); | $this->setFlash('success', 'Taxe créée.'); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
{ | { | ||||
$model = $this->findModel($id); | $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.'); | $this->setFlash('success', 'Taxe éditée.'); | ||||
return $this->redirect(['index']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
]); | ]); | ||||
$taxeRate->delete(); | $taxeRate->delete(); | ||||
Yii::$app->getSession()->setFlash('success', 'Taxe supprimé'); | |||||
$this->setFlash('success', 'Taxe supprimé'); | |||||
return $this->redirect(['tax-rate-admin/index']); | return $this->redirect(['tax-rate-admin/index']); | ||||
} | } | ||||
'inactive' => (int)$sectionInactiveUsers, | 'inactive' => (int)$sectionInactiveUsers, | ||||
'subscribers' => (int)$sectionSubscribers | 'subscribers' => (int)$sectionSubscribers | ||||
], | ], | ||||
isset(Yii::$app->request->queryParams['UserSearch']) ? | |||||
isset(\Yii::$app->request->queryParams['UserSearch']) ? | |||||
Yii::$app->request->queryParams['UserSearch'] : | Yii::$app->request->queryParams['UserSearch'] : | ||||
[] | [] | ||||
) | ) | ||||
Producer::addUser($userExist->id, GlobalParam::getCurrentProducerId()); | Producer::addUser($userExist->id, GlobalParam::getCurrentProducerId()); | ||||
$this->processLinkPointSale($userExist); | $this->processLinkPointSale($userExist); | ||||
$this->processLinkUserGroup($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 { | } 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 | // save user | ||||
$password = Password::generate(); | $password = Password::generate(); | ||||
$model->id_producer = 0; | $model->id_producer = 0; | ||||
$this->processLinkUserGroup($model); | $this->processLinkUserGroup($model); | ||||
$this->processProductPricePercent($model); | $this->processProductPricePercent($model); | ||||
Yii::$app->getSession()->setFlash('success', 'Utilisateur créé.'); | |||||
$this->setFlash('success', 'Utilisateur créé.'); | |||||
$model = new User(); | $model = new User(); | ||||
} | } | ||||
} | } | ||||
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); | $user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); | ||||
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | $userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => GlobalParam::getCurrentProducerId()]); | ||||
if ($userBelongToProducer) { | 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 | // on envoie le mail de bienvenue si le mail vient d'être défini | ||||
if (!strlen($previousMail) && strlen($model->email)) { | if (!strlen($previousMail) && strlen($model->email)) { | ||||
$this->processLinkPointSale($model); | $this->processLinkPointSale($model); | ||||
$this->processLinkUserGroup($model); | $this->processLinkUserGroup($model); | ||||
$this->processProductPricePercent($model); | $this->processProductPricePercent($model); | ||||
Yii::$app->getSession()->setFlash('success', 'Utilisateur modifié.'); | |||||
$this->setFlash('success', 'Utilisateur modifié.'); | |||||
} | } | ||||
} else { | } else { | ||||
throw new UserException("Vous ne pouvez pas modifier cet utilisateur."); | throw new UserException("Vous ne pouvez pas modifier cet utilisateur."); | ||||
] | ] | ||||
]); | ]); | ||||
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), [ | return $this->render('update', array_merge($this->initForm($model), [ | ||||
$userProducer->active = 0; | $userProducer->active = 0; | ||||
$userProducer->bookmark = 0; | $userProducer->bookmark = 0; | ||||
$userProducer->save(); | $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 { | } else { | ||||
throw new \yii\web\NotFoundHttpException('L\'enregistrement UserProducer est introuvable', 404); | throw new \yii\web\NotFoundHttpException('L\'enregistrement UserProducer est introuvable', 404); | ||||
} | } | ||||
} | } | ||||
$mailForm = new MailForm(); | $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); | $responseSendMail = $mailForm->sendEmail($users); | ||||
if ($responseSendMail->success()) { | if ($responseSendMail->success()) { | ||||
Yii::$app->getSession()->setFlash('success', 'Votre email a bien été envoyé.'); | |||||
$this->setFlash('success', 'Votre email a bien été envoyé.'); | |||||
} else { | } else { | ||||
$bodyResponseSendMail = $responseSendMail->getBody(); | $bodyResponseSendMail = $responseSendMail->getBody(); | ||||
$emailsErrorArray = []; | $emailsErrorArray = []; | ||||
if (count($emailsErrorArray) > 0) { | if (count($emailsErrorArray) > 0) { | ||||
$messageError .= '<br />Problème détecté sur les adresses suivantes : ' . implode(',', $emailsErrorArray); | $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]); | return $this->redirect(['mail', 'idPointSale' => $idPointSale]); | ||||
if (($userProducer) || User::getCurrentStatus() == User::STATUS_ADMIN) { | if (($userProducer) || User::getCurrentStatus() == User::STATUS_ADMIN) { | ||||
$creditForm = new CreditForm(); | $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->id_user = $id; | ||||
$creditForm->save(); | $creditForm->save(); | ||||
{ | { | ||||
$user = User::findOne($id); | $user = User::findOne($id); | ||||
$searchModel = new OrderSearch(); | $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', [ | return $this->render('orders', [ | ||||
'user' => $user, | 'user' => $user, |
{ | { | ||||
return [ | return [ | ||||
'verbs' => [ | 'verbs' => [ | ||||
'class' => VerbFilter::className(), | |||||
'class' => VerbFilter::class, | |||||
'actions' => [ | 'actions' => [ | ||||
], | ], | ||||
], | ], | ||||
'access' => [ | 'access' => [ | ||||
'class' => AccessControl::className(), | |||||
'class' => AccessControl::class, | |||||
'rules' => [ | 'rules' => [ | ||||
[ | [ | ||||
'allow' => true, | 'allow' => true, | ||||
public function actionIndex() | public function actionIndex() | ||||
{ | { | ||||
$searchModel = new UserGroupSearch(); | $searchModel = new UserGroupSearch(); | ||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |||||
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams); | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'searchModel' => $searchModel, | 'searchModel' => $searchModel, | ||||
$model->id_producer = GlobalParam::getCurrentProducerId(); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('create', [ | return $this->render('create', [ | ||||
{ | { | ||||
$model = $this->findModel($id); | $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']); | return $this->redirect(['index']); | ||||
} else { | } else { | ||||
return $this->render('update', [ | return $this->render('update', [ | ||||
$userGroup->delete(); | $userGroup->delete(); | ||||
UserUserGroup::deleteAll(['id_user_group' => $id]); | 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']); | return $this->redirect(['index']); | ||||
} | } |
]) | ]) | ||||
->setTo($email) | ->setTo($email) | ||||
->setFrom([$this->email => $this->name]) | ->setFrom([$this->email => $this->name]) | ||||
->setSubject('[distrib] Contact : ' . $this->subject) | |||||
->setSubject('[Opendistrib] Contact : ' . $this->subject) | |||||
->send(); | ->send(); | ||||
} | } | ||||
public static function get($key) | public static function get($key) | ||||
{ | { | ||||
if ($key == 'producer') { | if ($key == 'producer') { | ||||
return $this->getCurrentProducer(); | |||||
return self::getCurrentProducer(); | |||||
} else { | } else { | ||||
return \Yii::$app->params[$key]; | return \Yii::$app->params[$key]; | ||||
{ | { | ||||
if (\Yii::$app->controller->module->id == 'app-backend') { | if (\Yii::$app->controller->module->id == 'app-backend') { | ||||
if (!\Yii::$app->user->isGuest) { | if (!\Yii::$app->user->isGuest) { | ||||
return Yii::$app->user->identity->id_producer; | |||||
return \Yii::$app->user->identity->id_producer; | |||||
} | } | ||||
} else { | } else { | ||||
return \Yii::$app->controller->getProducer()->id; | |||||
return \Yii::$app->controller->getProducerCurrent()->id; | |||||
} | } | ||||
return false; | return false; |
$data) | $data) | ||||
->setTo($email) | ->setTo($email) | ||||
->setFrom(['contact@opendistrib.net' => 'distrib']) | ->setFrom(['contact@opendistrib.net' => 'distrib']) | ||||
->setSubject('[distrib] '.$subject) | |||||
->setSubject('[Opendistrib] '.$subject) | |||||
->send(); | ->send(); | ||||
} | } | ||||
} | } |
]); | ]); | ||||
} | } | ||||
public function findOneDistribution(Producer $producer, string $date): ?Distribution | |||||
public function findOneDistribution(Producer $producer, string $date, bool $active = null): ?Distribution | |||||
{ | { | ||||
$paramsDistribution = [ | $paramsDistribution = [ | ||||
'date' => $date, | 'date' => $date, | ||||
'distribution.id_producer' => $producer->id | 'distribution.id_producer' => $producer->id | ||||
]; | ]; | ||||
if(!is_null($active)) { | |||||
$paramsDistribution['active'] = $active; | |||||
} | |||||
return Distribution::searchOne($paramsDistribution); | return Distribution::searchOne($paramsDistribution); | ||||
} | } | ||||
$pointSale->credit_functioning : | $pointSale->credit_functioning : | ||||
$this->getConfig('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(); | |||||
} | |||||
} | } |
class UserBuilder extends BaseBuilder implements BuilderInterface | class UserBuilder extends BaseBuilder implements BuilderInterface | ||||
{ | { | ||||
protected UserRepository $userRepository; | |||||
public function __construct() | |||||
{ | |||||
$this->userRepository = $this->loadService(UserRepository::class); | |||||
} | |||||
public function instanciateUser(): User | public function instanciateUser(): User | ||||
{ | { | ||||
$user = new User(); | $user = new User(); | ||||
$user->password_reset_token = null; | $user->password_reset_token = null; | ||||
} | } | ||||
public function deleteAccess(User $user): bool | |||||
{ | |||||
$user->id_producer = 0; | |||||
$user->status = User::STATUS_ACTIVE; | |||||
return $user->save(); | |||||
} | |||||
} | } |
* Recherche un utilisateur via son adresse email. | * Recherche un utilisateur via son adresse email. | ||||
*/ | */ | ||||
// getOneByEmail | // getOneByEmail | ||||
public static function findOneUserByEmail(string $email): ?User | |||||
public function findOneUserByEmail(string $email): ?User | |||||
{ | { | ||||
return User::searchOne(['email' => $email]); | return User::searchOne(['email' => $email]); | ||||
} | } | ||||
// getOneByUsername | // getOneByUsername | ||||
public static function findOneUserByUsername(string $username): ?User | |||||
public function findOneUserByUsername(string $username): ?User | |||||
{ | { | ||||
return User::searchOne(['username' => $username]); | 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(); | |||||
} | |||||
} | } |
return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user]) | return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user]) | ||||
->setFrom(['contact@opendistrib.net' => 'distrib']) | ->setFrom(['contact@opendistrib.net' => 'distrib']) | ||||
->setTo($this->email) | ->setTo($this->email) | ||||
->setSubject('[distrib] Mot de passe oublié') | |||||
->setSubject('[Opendistrib] Mot de passe oublié') | |||||
->send(); | ->send(); | ||||
} | } | ||||
} | } |
/** | /** | ||||
* Retourne le producteur courant. | * Retourne le producteur courant. | ||||
*/ | */ | ||||
public function getProducer() : Producer | |||||
public function getProducerCurrent() : Producer | |||||
{ | { | ||||
if($this->producer) { | if($this->producer) { | ||||
return $this->producer ; | return $this->producer ; |