|
- <?php
-
- namespace backend\controllers;
-
- use Yii;
- use common\models\User;
- use backend\models\MailForm;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- use common\helpers\Upload ;
- use common\models\Etablissement ;
- use common\models\Facture ;
-
-
- class EtablissementController extends BackendController
- {
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['post'],
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return Yii::$app->user->identity->status == USER::STATUS_ADMIN
- || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
- }
- ]
- ],
- ],
- ];
- }
-
- public function actionUpdate()
- {
- $request = Yii::$app->request ;
- $model = $this->findModel(Yii::$app->user->identity->id_etablissement);
- $logo_filename_old = $model->logo ;
- $photo_filename_old = $model->photo ;
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- Upload::uploadFile($model, 'logo', $logo_filename_old) ;
- Upload::uploadFile($model, 'photo', $photo_filename_old) ;
-
- $delete_logo = $request->post('delete_logo',0) ;
- if($delete_logo) {
- $model->logo = '' ;
- $model->save() ;
- }
-
- $delete_photo = $request->post('delete_photo',0) ;
- if($delete_photo) {
- $model->photo = '' ;
- $model->save() ;
- }
-
- return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
-
- }
-
- public function actionFacturation()
- {
- $datas_factures = new ActiveDataProvider([
- 'query' => Facture::find()
- ->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
- ->orderBy('reference DESC'),
- 'pagination' => [
- 'pageSize' => 1000,
- ],
- ]);
-
- $etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement) ;
-
- if ($etablissement->load(Yii::$app->request->post()))
- {
- $etablissement->save() ;
-
- if(!is_null($etablissement->prix_libre))
- $alert_prix_libre = true ;
- }
-
- return $this->render('facturation', [
- 'datas_factures' => $datas_factures,
- 'etablissement' => $etablissement,
- 'alert_prix_libre' => (isset($alert_prix_libre)) ? true : false
- ]);
- }
-
- protected function findModel($id)
- {
- if (($model = Etablissement::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|