|
- <?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\Producer;
- use common\models\Invoice;
-
-
- class ProducerController extends BackendController
- {
-
- public $enableCsrfValidation = false;
-
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['post'],
- ],
- ],
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'allow' => true,
- 'roles' => ['@'],
- 'matchCallback' => function ($rule, $action) {
- return User::hasAccessBackend();
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionUpdate()
- {
- $request = Yii::$app->request;
- $model = $this->findModel(Producer::getId());
- $model->secret_key_payplug = $model->getSecretKeyPayplug() ;
-
- $logoFilenameOld = $model->logo;
- $photoFilenameOld = $model->photo;
-
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- Upload::uploadFile($model, 'logo', $logoFilenameOld);
- Upload::uploadFile($model, 'photo', $photoFilenameOld);
-
- $deleteLogo = $request->post('delete_logo', 0);
- if ($deleteLogo) {
- $model->logo = '';
- $model->save();
- }
-
- $deletePhoto = $request->post('delete_photo', 0);
- if ($deletePhoto) {
- $model->photo = '';
- $model->save();
- }
-
- $model->saveSecretKeyPayplug() ;
-
- Yii::$app->getSession()->setFlash('success', 'Paramètres mis à jour.');
- return $this->redirect(['update', 'id' => $model->id, 'edit_ok' => true]);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
-
-
-
- public function actionBilling()
- {
- $datasInvoices = new ActiveDataProvider([
- 'query' => Invoice::find()
- ->where(['id_producer' => Producer::getId()])
- ->orderBy('reference DESC'),
- 'pagination' => [
- 'pageSize' => 1000,
- ],
- ]);
-
- $producer = Producer::findOne(Producer::getId());
-
- if ($producer->load(Yii::$app->request->post())) {
- $producer->save();
-
- if (!is_null($producer->free_price)) {
- $alertFreeprice = true;
- }
- }
-
- return $this->render('billing', [
- 'datasInvoices' => $datasInvoices,
- 'producer' => $producer,
- 'alertFreePrice' => (isset($alertFreeprice)) ? true : false
- ]);
- }
-
-
-
- protected function findModel($id)
- {
- if (($model = Producer::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|