Browse Source

Adaptations refactoring/traduction backend/controllers/EtablissementAdminController > ProducerAdminController

refactoring
Guillaume Bourgeois 6 years ago
parent
commit
8af75ba90c
1 changed files with 32 additions and 32 deletions
  1. +32
    -32
      backend/controllers/ProducerAdminController.php

backend/controllers/EtablissementAdminController.php → backend/controllers/ProducerAdminController.php View File

use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use common\helpers\Upload; use common\helpers\Upload;
use common\models\Etablissement;
use common\models\Producer;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use common\models\Facture;
use common\models\Invoice;


/** /**
* UserController implements the CRUD actions for User model. * UserController implements the CRUD actions for User model.
'allow' => true, 'allow' => true,
'roles' => ['@'], 'roles' => ['@'],
'matchCallback' => function ($rule, $action) { 'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN;
return User::getStatus() == USER::STATUS_ADMIN;
} }
] ]
], ],
*/ */
public function actionIndex() public function actionIndex()
{ {
$datas_etablissements = new ActiveDataProvider([
'query' => Etablissement::find()
$dataProviderProducer = new ActiveDataProvider([
'query' => Producer::find()
->with('userEtablissement', 'user') ->with('userEtablissement', 'user')
->orderBy('date_creation DESC'), ->orderBy('date_creation DESC'),
'pagination' => [ 'pagination' => [
]); ]);


return $this->render('index', [ return $this->render('index', [
'datas_etablissements' => $datas_etablissements,
'dataProviderProducer' => $dataProviderProducer,
]); ]);
} }


/** /**
* Génère la facture mensuelle d'un producteur. * Génère la facture mensuelle d'un producteur.
* *
* @param integer $id_etablissement
* @param integer $idProducer
*/ */
public function actionFacturer($id_etablissement)
public function actionBill($idProducer)
{ {
$etablissement = Etablissement::findOne($id_etablissement);
$producer = Producer::findOne($idProducer);


if ($etablissement) {
$periode = date('Y-m', strtotime('-1 month'));
if ($producer) {
$period = date('Y-m', strtotime('-1 month'));


$last_facture = Facture::getLastFacture();
if (!$last_facture) {
$last_invoice = Invoice::getLastInvoice() ;
if (!$last_invoice) {
$reference = 'BAP000001'; $reference = 'BAP000001';
} else { } else {
$reference = str_replace('BAP', '', $last_facture->reference);
$reference = str_replace('BAP', '', $last_invoice->reference);
$reference ++; $reference ++;
$reference = 'BAP' . $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 />'
$invoice = new Invoice;
$invoice->id_producer = $idProducer;
$invoice->date = date('Y-m-d H:i:s');
$invoice->reference = $reference;
$invoice->turnover = $producer->getTurnover($period);
$invoice->amount_ht = $producer->getFreePrice() ;
$invoice->wording = 'Facture ' . date('m/Y', strtotime('-1 month'));
$invoice->text = '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>.'; . '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();
$invoice->paid = 0;
$invoice->period = $period;
$invoice->save();
} }


$this->redirect(['etablissement-admin/index']);
$this->redirect(['producer-admin/index']);
} }


/** /**
* *
* @return mxied * @return mxied
*/ */
public function actionFacturation()
public function actionBilling()
{ {
$datas_factures = new ActiveDataProvider([
'query' => Facture::find()
->with('etablissement')
$dataProviderInvoice = new ActiveDataProvider([
'query' => Invoice::find()
->with('producer')
->orderBy('reference DESC'), ->orderBy('reference DESC'),
'pagination' => [ 'pagination' => [
'pageSize' => 1000, 'pageSize' => 1000,
]); ]);


return $this->render('facturation', [ return $this->render('facturation', [
'datas_factures' => $datas_factures,
'dataProviderInvoice' => $dataProviderInvoice,
]); ]);
} }


* @throws NotFoundHttpException * @throws NotFoundHttpException
*/ */
protected function findModel($id) { protected function findModel($id) {
if (($model = Etablissement::findOne($id)) !== null) {
if (($model = Producer::findOne($id)) !== null) {
return $model; return $model;
} else { } else {
throw new NotFoundHttpException('The requested page does not exist.'); throw new NotFoundHttpException('The requested page does not exist.');

Loading…
Cancel
Save