|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
-
- namespace backend\controllers;
-
- use Yii;
- use common\models\User;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii\filters\AccessControl;
- use common\helpers\Upload ;
- use common\models\Etablissement ;
- use yii\data\ActiveDataProvider ;
- use common\models\Facture ;
-
-
- class EtablissementAdminController 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 ;
- }
- ]
- ],
- ],
- ];
- }
-
- public function actionIndex()
- {
- $datas_etablissements = new ActiveDataProvider([
- 'query' => Etablissement::find()
- ->with('userEtablissement','user')
- ->orderBy('date_creation DESC'),
- 'pagination' => [
- 'pageSize' => 1000,
- ],
- ]);
-
- return $this->render('index', [
- 'datas_etablissements' => $datas_etablissements,
- ]);
- }
-
- public function actionFacturer($id_etablissement)
- {
-
- $etablissement = Etablissement::findOne($id_etablissement) ;
-
- if($etablissement)
- {
- $periode = date('Y-m', strtotime('-1 month')) ;
-
- $last_facture = Facture::getLastFacture() ;
- if(!$last_facture)
- {
- $reference = 'BAP000001' ;
- }
- else {
- $reference = str_replace('BAP','',$last_facture->reference) ;
- $reference ++ ;
- $reference = 'BAP'.$reference ;
- }
-
- $facture = new Facture ;
- $facture->id_etablissement = $id_etablissement ;
- $facture->date = date('Y-m-d H:i:s') ;
- $facture->reference = $reference ;
- $facture->ca = $etablissement->getCA($periode) ;
- $facture->montant_ht = $etablissement->getMontantFacturer($periode) ;
- $facture->libelle = 'Facture '.date('m/Y', strtotime('-1 month')) ;
- $facture->texte = 'Utilisation de la plateforme <strong>La boîte à pain</strong> pour le mois : '.date('m/Y', strtotime('-1 month')).'<br />'
- . 'Chiffre d\'affaire réalisé sur la plateforme : <strong>'.number_format($facture->ca,2).' €</strong> commissionné à <strong>1%</strong>.' ;
- $facture->paye = 0 ;
- $facture->periode = $periode ;
- $facture->save() ;
- }
-
- $this->redirect(['etablissement-admin/index']) ;
- }
-
- public function actionFacturation()
- {
- $datas_factures = new ActiveDataProvider([
- 'query' => Facture::find()
- ->with('etablissement')
- ->orderBy('reference DESC'),
- 'pagination' => [
- 'pageSize' => 1000,
- ],
- ]);
-
- return $this->render('facturation', [
- 'datas_factures' => $datas_factures,
- ]);
- }
-
- protected function findModel($id)
- {
- if (($model = Etablissement::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|