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.

108 lines
3.2KB

  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. return $this->render('facturation', [
  81. 'datas_factures' => $datas_factures,
  82. 'etablissement' => $etablissement
  83. ]);
  84. }
  85. protected function findModel($id)
  86. {
  87. if (($model = Etablissement::findOne($id)) !== null) {
  88. return $model;
  89. } else {
  90. throw new NotFoundHttpException('The requested page does not exist.');
  91. }
  92. }
  93. }