|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?php
-
- namespace backend\controllers;
-
- class CommandeautoController extends BackendController {
-
- var $enableCsrfValidation = false;
-
- public function behaviors() {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
- }
- ]
- ],
- ],
- ];
- }
-
- public function actionIndex() {
- $dataProvider = new ActiveDataProvider([
- 'query' => CommandeAuto::find()
- ->with(['user', 'etablissement', 'pointVente', 'commandeAutoProduit'])
- ->joinWith(['user'])
- ->where(['commande_auto.id_etablissement' => Yii::$app->user->identity->id_etablissement])
- ->orderBy('commande_auto.id_point_vente ASC, CASE `commande_auto`.`username` WHEN "" THEN `user`.`nom` ELSE `commande_auto`.`username` END ASC'),
- 'pagination' => [
- 'pageSize' => 1000,
- ],
- ]);
-
- return $this->render('index', [
- 'dataProvider' => $dataProvider
- ]);
- }
-
- public function actionCreate() {
- // form
- $model = new CommandeAutoForm;
- $model->id_etablissement = Yii::$app->user->identity->id_etablissement;
-
- // produits
- $produits = Produit::find()
- ->where(['id_etablissement' => $model->id_etablissement])
- ->orderBy('order ASC')
- ->all();
-
- if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) {
-
- $this->redirect(['commandeauto/index']);
- }
-
- return $this->render('create', [
- 'model' => $model,
- 'produits' => $produits
- ]);
- }
-
- public function actionUpdate($id) {
- // form
- $model = new CommandeAutoForm;
- $commandeauto = CommandeAuto::findOne($id);
- if ($commandeauto) {
- $model->id = $id;
- $model->id_etablissement = $commandeauto->id_etablissement;
- $model->id_user = $commandeauto->id_user;
- $model->username = $commandeauto->username;
- $model->id_point_vente = $commandeauto->id_point_vente;
- $model->date_debut = date('d/m/Y', strtotime($commandeauto->date_debut));
- if (strlen($commandeauto->date_fin))
- $model->date_fin = date('d/m/Y', strtotime($commandeauto->date_fin));
- $model->lundi = $commandeauto->lundi;
- $model->lundi = $commandeauto->lundi;
- $model->mardi = $commandeauto->mardi;
- $model->mercredi = $commandeauto->mercredi;
- $model->jeudi = $commandeauto->jeudi;
- $model->vendredi = $commandeauto->vendredi;
- $model->samedi = $commandeauto->samedi;
- $model->dimanche = $commandeauto->dimanche;
- $model->paiement_automatique = $commandeauto->paiement_automatique;
- $model->periodicite_semaine = $commandeauto->periodicite_semaine;
-
-
- // produits
- $commandeauto_produits = CommandeAutoProduit::find()->where(['id_commande_auto' => $model->id])->all();
- foreach ($commandeauto_produits as $commandeauto_produit) {
- $model->produits['produit_' . $commandeauto_produit->id_produit] = $commandeauto_produit->quantite;
- }
- } else {
- throw new NotFoundHttpException('La commande récurrente est introuvable.', 404);
- }
-
- // produits
- $produits = Produit::find()
- ->where(['id_etablissement' => $model->id_etablissement])
- ->orderBy('order ASC')
- ->all();
-
- if ($model->load(Yii::$app->request->post()) && $model->validate()) {
-
- if (!strlen($model->date_fin)) {
- $model->date_fin = null;
- }
-
- if ($model->save()) {
- $this->redirect(['commandeauto/index']);
- }
- }
-
- return $this->render('update', [
- 'model' => $model,
- 'produits' => $produits
- ]);
- }
-
- public function actionDelete($id) {
- CommandeAutoProduit::deleteAll(['id_commande_auto' => $id]);
- CommandeAuto::findOne($id)->delete();
- $this->redirect(['commandeauto/index']);
- }
-
- }
|