Page des boulangeries avec la possibilité de générer les factures. Page listant toutes les factures. Page facturation boulanger avec une estimation de sa facture + liste des dernières factures.master
use common\helpers\Upload ; | use common\helpers\Upload ; | ||||
use common\models\Etablissement ; | use common\models\Etablissement ; | ||||
use yii\data\ActiveDataProvider ; | use yii\data\ActiveDataProvider ; | ||||
use common\models\Facture ; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
]); | ]); | ||||
} | } | ||||
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 <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() ; | |||||
} | |||||
$this->redirect(['etablissement-admin/index']) ; | |||||
} | |||||
public function actionFacturation() | public function actionFacturation() | ||||
{ | { | ||||
return $this->render('facturation') ; | |||||
$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) | protected function findModel($id) |
use yii\filters\AccessControl; | use yii\filters\AccessControl; | ||||
use common\helpers\Upload ; | use common\helpers\Upload ; | ||||
use common\models\Etablissement ; | use common\models\Etablissement ; | ||||
use common\models\Facture ; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
public function actionFacturation() | public function actionFacturation() | ||||
{ | { | ||||
return $this->render('facturation') ; | |||||
$datas_factures = new ActiveDataProvider([ | |||||
'query' => Facture::find() | |||||
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->orderBy('reference DESC'), | |||||
'pagination' => [ | |||||
'pageSize' => 1000, | |||||
], | |||||
]); | |||||
$etablissement = Etablissement::findOne(Yii::$app->user->identity->id_etablissement) ; | |||||
return $this->render('facturation', [ | |||||
'datas_factures' => $datas_factures, | |||||
'etablissement' => $etablissement | |||||
]); | |||||
} | } | ||||
protected function findModel($id) | protected function findModel($id) |
<?php | <?php | ||||
use yii\helpers\Html; | |||||
use yii\grid\GridView; | |||||
use common\models\User ; | |||||
use common\models\Etablissement ; | |||||
$this->title = 'Facturation'; | |||||
$this->params['breadcrumbs'][] = 'Administration' ; | |||||
$this->params['breadcrumbs'][] = $this->title; | |||||
?> | ?> | ||||
<h1>Facturation</h1> | <h1>Facturation</h1> | ||||
<?= GridView::widget([ | |||||
'dataProvider' => $datas_factures, | |||||
'columns' => [ | |||||
[ | |||||
'attribute' => 'reference', | |||||
'label' => 'Référence', | |||||
], | |||||
[ | |||||
'attribute' => 'id_etablissement', | |||||
'label' => 'Établissement', | |||||
'value' => function($model) { | |||||
return Html::encode($model->etablissement->nom) ; | |||||
} | |||||
], | |||||
'libelle', | |||||
[ | |||||
'attribute' => 'montant_ht', | |||||
'label' => 'Montant', | |||||
'value' => function($model) { | |||||
return number_format($model->montant_ht,2).' €' ; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'paye', | |||||
'label' => 'Payé', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
if($model->paye) | |||||
{ | |||||
return '<span class="label label-success">Oui</span>' ; | |||||
} | |||||
else { | |||||
return '<span class="label label-danger">Non</span>' ; | |||||
} | |||||
} | |||||
] | |||||
], | |||||
]); ?> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User ; | use common\models\User ; | ||||
use common\models\Etablissement ; | |||||
$this->title = 'Boulangeries'; | $this->title = 'Boulangeries'; | ||||
$this->params['breadcrumbs'][] = 'Administration' ; | $this->params['breadcrumbs'][] = 'Administration' ; | ||||
return '' ; | return '' ; | ||||
} | } | ||||
], | ], | ||||
[ | |||||
'attribute' => 'Facture', | |||||
'label' => 'Facture mois dernier', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
$periode = date('Y-m', strtotime('-1 month')) ; | |||||
$ca = $model->getCA($periode) ; | |||||
$html = '' ; | |||||
$html .= 'CA : '.number_format($ca,2).' €<br />' ; | |||||
$montant_facturer = $model->getMontantFacturer($periode, $ca) ; | |||||
$facture = $model->getFacture($periode) ; | |||||
if($facture) | |||||
{ | |||||
$html .= '<span class="label label-success">Facturé</span> <strong>'.number_format($facture->montant_ht,2).' €</strong>' ; | |||||
} | |||||
else { | |||||
if($montant_facturer == 0) { | |||||
$html .= '<span class="label label-default">Gratuit</span>' ; | |||||
} | |||||
else { | |||||
$html .= Html::a('Facturer <strong>'.$model->getMontantFacturer($periode, $ca, true).'</strong>', ['etablissement-admin/facturer','id_etablissement' => $model->id], ['class' => 'btn btn-default']) ; | |||||
} | |||||
} | |||||
return $html ; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'Cours', | |||||
'label' => 'Mois en cours', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
$ca = $model->getCA(date('Y-m')) ; | |||||
$html = '' ; | |||||
$html .= 'CA : '.number_format($ca,2).' €<br />' ; | |||||
return $html ; | |||||
} | |||||
], | |||||
], | ], | ||||
]); ?> | ]); ?> |
<?php | <?php | ||||
use yii\helpers\Html; | |||||
use yii\grid\GridView; | |||||
use common\models\User ; | |||||
use common\models\Etablissement ; | |||||
$this->title = 'Facturation'; | |||||
$this->params['breadcrumbs'][] = 'Administration' ; | |||||
$this->params['breadcrumbs'][] = $this->title; | |||||
?> | ?> | ||||
<h1>Facturation</h1> | |||||
<h1>Facturation</h1> | |||||
<p class="alert alert-warning">Suivez ici l'évolution de votre facture tout au long du mois.<br /> | |||||
Les factures sont générées au début de chaque mois en fonction du chiffre d'affaire du mois précédent. <br /> | |||||
→ S'il est inférieur à 500€, rien n'est facturé. <br /> | |||||
→ S'il est supérieur à 500€, une commission de 1% du chiffre d'affaire est facturée.</p> | |||||
<div id="estimation-facture"> | |||||
<div class="col-md-6"> | |||||
<h2>Chiffre d'affaire<br />du mois en cours</h2> | |||||
<div class="montant"><span><?= number_format($etablissement->getCA(date('Y-m')), 2); ?> €</span></div> | |||||
</div> | |||||
<div class="col-md-6"> | |||||
<?php $montant = $etablissement->getMontantFacturer(date('Y-m'), 0); ?> | |||||
<h2>Commission<br /><em>La boîte à pain</em> (1%)</h2> | |||||
<div class="montant"><span><?php if($montant): echo number_format($montant,2).' €' ; else: echo 'Gratuit' ; endif; ?></span></div> | |||||
</div> | |||||
<div class="clr"></div> | |||||
</div> | |||||
<h2>Dernières factures</h2> | |||||
<?= GridView::widget([ | |||||
'dataProvider' => $datas_factures, | |||||
'columns' => [ | |||||
[ | |||||
'attribute' => 'reference', | |||||
'label' => 'Référence', | |||||
], | |||||
[ | |||||
'attribute' => 'date', | |||||
'value' => function($model) { | |||||
return date('d/m/Y', strtotime($model->date)) ; | |||||
} | |||||
], | |||||
'libelle', | |||||
[ | |||||
'attribute' => 'montant_ht', | |||||
'label' => 'Montant', | |||||
'value' => function($model) { | |||||
return number_format($model->montant_ht,2).' €' ; | |||||
} | |||||
], | |||||
[ | |||||
'attribute' => 'paye', | |||||
'label' => 'Payé', | |||||
'format' => 'raw', | |||||
'value' => function($model) { | |||||
if($model->paye) | |||||
{ | |||||
return '<span class="label label-success">Oui</span>' ; | |||||
} | |||||
else { | |||||
return '<span class="label label-danger">Non</span>' ; | |||||
} | |||||
} | |||||
] | |||||
], | |||||
]); ?> |
clear: both ; | clear: both ; | ||||
} | } | ||||
h1, h2, h3, h4, h5, h6 { | |||||
font-family: 'myriadpro-light' ; | |||||
} | |||||
a { | a { | ||||
color: $color1; | color: $color1; | ||||
text-align: center ; | text-align: center ; | ||||
} | } | ||||
} | } | ||||
} | |||||
/* facturation */ | |||||
#estimation-facture { | |||||
text-align: center ; | |||||
margin-bottom: 30px ; | |||||
padding-bottom: 20px ; | |||||
background-color: #F9F9F9 ; | |||||
h2 { | |||||
font-family: 'myriadpro-it' ; | |||||
} | |||||
.montant { | |||||
span { | |||||
font-size: 25px ; | |||||
color: white ; | |||||
background-color: $color1 ; | |||||
@include border-radius(5px) ; | |||||
padding: 3px 10px ; | |||||
padding-top: 7px ; | |||||
font-family: 'myriadpro-regular' ; | |||||
} | |||||
} | |||||
} | } |
} | } | ||||
} | } | ||||
} | } | ||||
public function getCA($periode = '', $format = false) | |||||
{ | |||||
if(!$periode) | |||||
$periode = date('Y-m') ; | |||||
$connection = Yii::$app->getDb(); | |||||
$command = $connection->createCommand(' | |||||
SELECT SUM(IF(produit.vrac,0,commande_produit.prix * commande_produit.quantite)) AS CA | |||||
FROM commande, commande_produit, production, produit | |||||
WHERE commande.id = commande_produit.id_commande | |||||
AND production.id_etablissement = :id_etablissement | |||||
AND commande.id_production = production.id | |||||
AND commande_produit.id_produit = produit.id | |||||
AND production.date > :date_debut | |||||
AND production.date < :date_fin', | |||||
[ | |||||
':date_debut' => date('Y-m-31', strtotime("-1 month", strtotime($periode))), | |||||
':date_fin' => date('Y-m-01', strtotime("+1 month", strtotime($periode))), | |||||
':id_etablissement' => $this->id | |||||
]); | |||||
$result = $command->queryOne(); | |||||
$ca = $result['CA'] ; | |||||
if($format) | |||||
return number_format($ca, 2).' €' ; | |||||
else | |||||
return $ca ; | |||||
} | |||||
public function getMontantFacturer($periode = '', $ca = 0, $format = false) | |||||
{ | |||||
if(!$periode) | |||||
$periode = date('Y-m') ; | |||||
if(!$ca) | |||||
$ca = $this->getCA($periode) ; | |||||
if($ca < 500) | |||||
{ | |||||
$montant = 0 ; | |||||
} | |||||
else { | |||||
$montant = $ca * 0.01 ; | |||||
} | |||||
if($format) | |||||
{ | |||||
return number_format($montant, 2).' €' ; | |||||
} | |||||
else { | |||||
return $montant ; | |||||
} | |||||
} | |||||
public function getFacture($periode = '') | |||||
{ | |||||
if(!$periode) | |||||
$periode = date('Y-m', strtotime('-1 month')) ; | |||||
$facture = Facture::find() | |||||
->where('id_etablissement = :id_etablissement') | |||||
->andWhere('periode = :periode') | |||||
->addParams([ | |||||
':id_etablissement' => $this->id, | |||||
':periode' => $periode, | |||||
]) | |||||
->one() ; | |||||
return $facture ; | |||||
} | |||||
public function factureMoisDernier() | |||||
{ | |||||
return $this->getFacture(date('Y-m', strtotime('-1 month'))) ; | |||||
} | |||||
} | } |
<?php | |||||
namespace common\models; | |||||
use Yii; | |||||
/** | |||||
* This is the model class for table "facture". | |||||
* | |||||
* @property integer $id | |||||
* @property integer $id_etablissement | |||||
* @property string $date | |||||
* @property string $reference | |||||
* @property string $libelle | |||||
* @property string $texte | |||||
* @property double $montant_ht | |||||
* @property integer $paye | |||||
* @property string $date_paiement | |||||
* @property string $methode_paiement | |||||
*/ | |||||
class Facture extends \yii\db\ActiveRecord | |||||
{ | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public static function tableName() | |||||
{ | |||||
return 'facture'; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function rules() | |||||
{ | |||||
return [ | |||||
[['id_etablissement', 'paye'], 'integer'], | |||||
[['date', 'date_paiement'], 'safe'], | |||||
[['texte'], 'string'], | |||||
[['montant_ht','ca'], 'number'], | |||||
[['reference', 'libelle', 'methode_paiement'], 'string', 'max' => 255], | |||||
]; | |||||
} | |||||
public function getEtablissement() | |||||
{ | |||||
return $this->hasOne(Etablissement::className(), ['id' => 'id_etablissement']) ; | |||||
} | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function attributeLabels() | |||||
{ | |||||
return [ | |||||
'id' => 'ID', | |||||
'id_etablissement' => 'Id Etablissement', | |||||
'date' => 'Date', | |||||
'reference' => 'Reference', | |||||
'libelle' => 'Libelle', | |||||
'texte' => 'Texte', | |||||
'montant_ht' => 'Montant Ht', | |||||
'paye' => 'Paye', | |||||
'date_paiement' => 'Date Paiement', | |||||
'methode_paiement' => 'Methode Paiement', | |||||
'ca' => 'CA' | |||||
]; | |||||
} | |||||
public static function getLastFacture() | |||||
{ | |||||
return Facture::find() | |||||
->orderBy('reference DESC') | |||||
->one() ; | |||||
} | |||||
} |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
class m161219_135239_champs_facture_periode extends Migration | |||||
{ | |||||
public function up() | |||||
{ | |||||
$this->addColumn('facture', 'periode', Schema::TYPE_STRING) ; | |||||
} | |||||
public function down() | |||||
{ | |||||
$this->dropColumn('facture', 'periode') ; | |||||
} | |||||
} |
<?php | |||||
use yii\db\Migration; | |||||
use yii\db\Schema; | |||||
class m161219_144530_champs_facture_ca extends Migration | |||||
{ | |||||
public function up() | |||||
{ | |||||
$this->addColumn('facture', 'ca', Schema::TYPE_FLOAT) ; | |||||
} | |||||
public function down() | |||||
{ | |||||
$this->dropColumn('facture', 'ca') ; | |||||
} | |||||
} |