|
|
@@ -44,9 +44,9 @@ use yii\web\NotFoundHttpException; |
|
|
|
use yii\filters\VerbFilter; |
|
|
|
use yii\filters\AccessControl; |
|
|
|
use common\helpers\Upload; |
|
|
|
use common\models\Etablissement; |
|
|
|
use common\models\Producer; |
|
|
|
use yii\data\ActiveDataProvider; |
|
|
|
use common\models\Facture; |
|
|
|
use common\models\Invoice; |
|
|
|
|
|
|
|
/** |
|
|
|
* UserController implements the CRUD actions for User model. |
|
|
@@ -70,7 +70,7 @@ class EtablissementAdminController extends BackendController |
|
|
|
'allow' => true, |
|
|
|
'roles' => ['@'], |
|
|
|
'matchCallback' => function ($rule, $action) { |
|
|
|
return Yii::$app->user->identity->status == USER::STATUS_ADMIN; |
|
|
|
return User::getStatus() == USER::STATUS_ADMIN; |
|
|
|
} |
|
|
|
] |
|
|
|
], |
|
|
@@ -85,8 +85,8 @@ class EtablissementAdminController extends BackendController |
|
|
|
*/ |
|
|
|
public function actionIndex() |
|
|
|
{ |
|
|
|
$datas_etablissements = new ActiveDataProvider([ |
|
|
|
'query' => Etablissement::find() |
|
|
|
$dataProviderProducer = new ActiveDataProvider([ |
|
|
|
'query' => Producer::find() |
|
|
|
->with('userEtablissement', 'user') |
|
|
|
->orderBy('date_creation DESC'), |
|
|
|
'pagination' => [ |
|
|
@@ -95,46 +95,46 @@ class EtablissementAdminController extends BackendController |
|
|
|
]); |
|
|
|
|
|
|
|
return $this->render('index', [ |
|
|
|
'datas_etablissements' => $datas_etablissements, |
|
|
|
'dataProviderProducer' => $dataProviderProducer, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 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'; |
|
|
|
} else { |
|
|
|
$reference = str_replace('BAP', '', $last_facture->reference); |
|
|
|
$reference = str_replace('BAP', '', $last_invoice->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 />' |
|
|
|
$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>.'; |
|
|
|
$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']); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -142,11 +142,11 @@ class EtablissementAdminController extends BackendController |
|
|
|
* |
|
|
|
* @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'), |
|
|
|
'pagination' => [ |
|
|
|
'pageSize' => 1000, |
|
|
@@ -154,7 +154,7 @@ class EtablissementAdminController extends BackendController |
|
|
|
]); |
|
|
|
|
|
|
|
return $this->render('facturation', [ |
|
|
|
'datas_factures' => $datas_factures, |
|
|
|
'dataProviderInvoice' => $dataProviderInvoice, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
@@ -166,7 +166,7 @@ class EtablissementAdminController extends BackendController |
|
|
|
* @throws NotFoundHttpException |
|
|
|
*/ |
|
|
|
protected function findModel($id) { |
|
|
|
if (($model = Etablissement::findOne($id)) !== null) { |
|
|
|
if (($model = Producer::findOne($id)) !== null) { |
|
|
|
return $model; |
|
|
|
} else { |
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |