|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?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;
-
- /**
- * UserController implements the CRUD actions for User model.
- */
- 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.');
- }
- }
-
- }
|