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.

113 satır
3.4KB

  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 $enableCsrfValidation = false;
  19. public function behaviors() {
  20. return [
  21. 'verbs' => [
  22. 'class' => VerbFilter::className(),
  23. 'actions' => [
  24. 'delete' => ['post'],
  25. ],
  26. ],
  27. 'access' => [
  28. 'class' => AccessControl::className(),
  29. 'rules' => [
  30. [
  31. 'allow' => true,
  32. 'roles' => ['@'],
  33. 'matchCallback' => function ($rule, $action) {
  34. return Yii::$app->user->identity->status == USER::STATUS_ADMIN
  35. || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
  36. }
  37. ]
  38. ],
  39. ],
  40. ];
  41. }
  42. public function actionUpdate() {
  43. $request = Yii::$app->request;
  44. $model = $this->findModel(Yii::$app->user->identity->id_etablissement);
  45. $logo_filename_old = $model->logo;
  46. $photo_filename_old = $model->photo;
  47. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  48. Upload::uploadFile($model, 'logo', $logo_filename_old);
  49. Upload::uploadFile($model, 'photo', $photo_filename_old);
  50. $delete_logo = $request->post('delete_logo', 0);
  51. if ($delete_logo) {
  52. $model->logo = '';
  53. $model->save();
  54. }
  55. $delete_photo = $request->post('delete_photo', 0);
  56. if ($delete_photo) {
  57. $model->photo = '';
  58. $model->save();
  59. }
  60. return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
  61. } else {
  62. return $this->render('update', [
  63. 'model' => $model,
  64. ]);
  65. }
  66. }
  67. public function actionFacturation() {
  68. $datas_factures = new ActiveDataProvider([
  69. 'query' => Facture::find()
  70. ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
  71. ->orderBy('reference DESC'),
  72. 'pagination' => [
  73. 'pageSize' => 1000,
  74. ],
  75. ]);
  76. $etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement);
  77. if ($etablissement->load(Yii::$app->request->post())) {
  78. $etablissement->save();
  79. if (!is_null($etablissement->prix_libre))
  80. $alert_prix_libre = true;
  81. }
  82. return $this->render('facturation', [
  83. 'datas_factures' => $datas_factures,
  84. 'etablissement' => $etablissement,
  85. 'alert_prix_libre' => (isset($alert_prix_libre)) ? true : false
  86. ]);
  87. }
  88. protected function findModel($id) {
  89. if (($model = Etablissement::findOne($id)) !== null) {
  90. return $model;
  91. } else {
  92. throw new NotFoundHttpException('The requested page does not exist.');
  93. }
  94. }
  95. }