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.

EtablissementController.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use common\models\User;
  5. use backend\models\MailForm;
  6. use yii\data\ActiveDataProvider;
  7. use yii\web\Controller;
  8. use yii\web\NotFoundHttpException;
  9. use yii\filters\VerbFilter;
  10. use yii\filters\AccessControl;
  11. use common\helpers\Upload;
  12. use common\models\Etablissement;
  13. use common\models\Facture;
  14. /**
  15. * UserController implements the CRUD actions for User model.
  16. */
  17. class EtablissementController extends BackendController {
  18. public function behaviors() {
  19. return [
  20. 'verbs' => [
  21. 'class' => VerbFilter::className(),
  22. 'actions' => [
  23. 'delete' => ['post'],
  24. ],
  25. ],
  26. 'access' => [
  27. 'class' => AccessControl::className(),
  28. 'rules' => [
  29. [
  30. 'allow' => true,
  31. 'roles' => ['@'],
  32. 'matchCallback' => function ($rule, $action) {
  33. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  34. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  35. }
  36. ]
  37. ],
  38. ],
  39. ];
  40. }
  41. public function actionUpdate() {
  42. $request = Yii::$app->request;
  43. $model = $this->findModel(Yii::$app->user->identity->id_etablissement);
  44. $logo_filename_old = $model->logo;
  45. $photo_filename_old = $model->photo;
  46. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  47. Upload::uploadFile($model, 'logo', $logo_filename_old);
  48. Upload::uploadFile($model, 'photo', $photo_filename_old);
  49. $delete_logo = $request->post('delete_logo', 0);
  50. if ($delete_logo) {
  51. $model->logo = '';
  52. $model->save();
  53. }
  54. $delete_photo = $request->post('delete_photo', 0);
  55. if ($delete_photo) {
  56. $model->photo = '';
  57. $model->save();
  58. }
  59. return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
  60. } else {
  61. return $this->render('update', [
  62. 'model' => $model,
  63. ]);
  64. }
  65. }
  66. public function actionFacturation() {
  67. $datas_factures = new ActiveDataProvider([
  68. 'query' => Facture::find()
  69. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  70. ->orderBy('reference DESC'),
  71. 'pagination' => [
  72. 'pageSize' => 1000,
  73. ],
  74. ]);
  75. $etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement);
  76. if ($etablissement->load(Yii::$app->request->post())) {
  77. $etablissement->save();
  78. if (!is_null($etablissement->prix_libre))
  79. $alert_prix_libre = true;
  80. }
  81. return $this->render('facturation', [
  82. 'datas_factures' => $datas_factures,
  83. 'etablissement' => $etablissement,
  84. 'alert_prix_libre' => (isset($alert_prix_libre)) ? true : false
  85. ]);
  86. }
  87. protected function findModel($id) {
  88. if (($model = Etablissement::findOne($id)) !== null) {
  89. return $model;
  90. } else {
  91. throw new NotFoundHttpException('The requested page does not exist.');
  92. }
  93. }
  94. }