[
'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 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%.';
$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.');
}
}
}