|
- <?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\Producer;
- use yii\data\ActiveDataProvider;
- use common\models\Invoice;
-
-
- class ProducerAdminController 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 User::getCurrentStatus() == USER::STATUS_ADMIN;
- }
- ]
- ],
- ],
- ];
- }
-
-
-
- public function actionIndex()
- {
- $dataProviderProducer = new ActiveDataProvider([
- 'query' => Producer::find()
- ->with('userProducer', 'user')
- ->orderBy('date_creation DESC'),
- 'pagination' => [
- 'pageSize' => 1000,
- ],
- ]);
-
- return $this->render('index', [
- 'dataProviderProducer' => $dataProviderProducer,
- ]);
- }
-
-
-
- public function actionBill($idProducer)
- {
- $producer = Producer::findOne($idProducer);
-
- if ($producer) {
- $period = date('Y-m', strtotime('-1 month'));
-
- $last_invoice = Invoice::getLastInvoice() ;
- if (!$last_invoice) {
- $reference = 'BAP000001';
- } else {
- $reference = str_replace('BAP', '', $last_invoice->reference);
- $reference ++;
- $reference = 'BAP' . $reference;
- }
-
- $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>.';
- $invoice->paid = 0;
- $invoice->period = $period;
- $invoice->save();
- }
-
- $this->redirect(['producer-admin/index']);
- }
-
-
-
- public function actionBilling()
- {
- $dataProviderInvoice = new ActiveDataProvider([
- 'query' => Invoice::find()
- ->with('producer')
- ->orderBy('reference DESC'),
- 'pagination' => [
- 'pageSize' => 1000,
- ],
- ]);
-
- return $this->render('billing', [
- 'dataProviderInvoice' => $dataProviderInvoice,
- ]);
- }
-
-
-
- protected function findModel($id) {
- if (($model = Producer::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- }
|