No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

117 líneas
3.5KB

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