Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

111 linhas
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 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. }