You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PointVenteController.php 4.5KB

8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
8 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\filters\AccessControl;
  5. use common\models\PointVente;
  6. use yii\data\ActiveDataProvider;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. use common\models\User;
  11. use common\models\PointVenteUser;
  12. /**
  13. * PointVenteController implements the CRUD actions for PointVente model.
  14. */
  15. class PointVenteController extends BackendController {
  16. public function behaviors() {
  17. return [
  18. 'verbs' => [
  19. 'class' => VerbFilter::className(),
  20. 'actions' => [
  21. ],
  22. ],
  23. 'access' => [
  24. 'class' => AccessControl::className(),
  25. 'rules' => [
  26. [
  27. 'allow' => true,
  28. 'roles' => ['@'],
  29. 'matchCallback' => function ($rule, $action) {
  30. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  31. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  32. }
  33. ],
  34. ],
  35. ],
  36. ];
  37. }
  38. /**
  39. * Lists all PointVente models.
  40. * @return mixed
  41. */
  42. public function actionIndex() {
  43. $dataProvider = new ActiveDataProvider([
  44. 'query' => PointVente::find()->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  45. ]);
  46. return $this->render('index', [
  47. 'dataProvider' => $dataProvider,
  48. ]);
  49. }
  50. /**
  51. * Displays a single PointVente model.
  52. * @param integer $id
  53. * @return mixed
  54. */
  55. public function actionView($id) {
  56. return $this->render('view', [
  57. 'model' => $this->findModel($id),
  58. ]);
  59. }
  60. /**
  61. * Creates a new PointVente model.
  62. * If creation is successful, the browser will be redirected to the 'view' page.
  63. * @return mixed
  64. */
  65. public function actionCreate() {
  66. $model = new PointVente();
  67. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  68. $model->gestionPointFabrication();
  69. $model->gestionAccesRestreint();
  70. return $this->redirect(['index']);
  71. } else {
  72. return $this->render('update', array_merge($this->initForm(), [
  73. 'model' => $model,
  74. ]));
  75. }
  76. }
  77. /**
  78. * Updates an existing PointVente model.
  79. * If update is successful, the browser will be redirected to the 'view' page.
  80. * @param integer $id
  81. * @return mixed
  82. */
  83. public function actionUpdate($id) {
  84. $model = PointVente::find()
  85. ->with('pointVenteUser')
  86. ->where(['id' => $id])
  87. ->one();
  88. foreach ($model->pointVenteUser as $u) {
  89. $model->users[] = $u->id_user;
  90. $model->users_commentaire[$u->id_user] = $u->commentaire;
  91. }
  92. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  93. $model->gestionPointFabrication();
  94. $model->gestionAccesRestreint();
  95. return $this->redirect(['index']);
  96. } else {
  97. return $this->render('update', array_merge($this->initForm($id), [
  98. 'model' => $model,
  99. ]));
  100. }
  101. }
  102. public function initForm($id = 0) {
  103. $users = User::findBy()
  104. ->orderBy('nom ASC')
  105. ->all();
  106. return [
  107. 'users' => $users
  108. ];
  109. }
  110. /**
  111. * Deletes an existing PointVente model.
  112. * If deletion is successful, the browser will be redirected to the 'index' page.
  113. * @param integer $id
  114. * @return mixed
  115. */
  116. public function actionDelete($id) {
  117. $this->findModel($id)->delete();
  118. PointVenteUser::deleteAll(['id_point_vente' => $id]);
  119. ProductionPointVente::deleteAll(['id_point_vente' => $id]) ;
  120. return $this->redirect(['index']);
  121. }
  122. /**
  123. * Finds the PointVente model based on its primary key value.
  124. * If the model is not found, a 404 HTTP exception will be thrown.
  125. * @param integer $id
  126. * @return PointVente the loaded model
  127. * @throws NotFoundHttpException if the model cannot be found
  128. */
  129. protected function findModel($id) {
  130. if (($model = PointVente::findOne($id)) !== null) {
  131. return $model;
  132. } else {
  133. throw new NotFoundHttpException('The requested page does not exist.');
  134. }
  135. }
  136. }