[
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return User::getCurrentStatus() == USER::STATUS_ADMIN;
}
]
],
],
];
}
/**
* Liste les producteurs.
*
* @return mixed
*/
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,
]);
}
/**
* Génère la facture mensuelle d'un producteur.
*
* @param integer $idProducer
*/
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 La boîte à pain pour le mois : ' . date('m/Y', strtotime('-1 month')) . '
'
. 'Chiffre d\'affaire réalisé sur la plateforme : ' . number_format($facture->ca, 2) . ' € commissionné à 1%.';
$invoice->paid = 0;
$invoice->period = $period;
$invoice->save();
}
$this->redirect(['producer-admin/index']);
}
/**
* Liste les factures des producteurs.
*
* @return mxied
*/
public function actionBilling()
{
$dataProviderInvoice = new ActiveDataProvider([
'query' => Invoice::find()
->with('producer')
->orderBy('reference DESC'),
'pagination' => [
'pageSize' => 1000,
],
]);
return $this->render('billing', [
'dataProviderInvoice' => $dataProviderInvoice,
]);
}
/**
* Recherche un établissement.
*
* @param integer $id
* @return Etablissement
* @throws NotFoundHttpException
*/
protected function findModel($id) {
if (($model = Producer::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}