Przeglądaj źródła

Backend : système de facturation

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
keun 7 lat temu
rodzic
commit
acbf9ffd28
12 zmienionych plików z 634 dodań i 165 usunięć
  1. +50
    -1
      backend/controllers/EtablissementAdminController.php
  2. +16
    -1
      backend/controllers/EtablissementController.php
  3. +47
    -0
      backend/views/etablissement-admin/facturation.php
  4. +46
    -0
      backend/views/etablissement-admin/index.php
  5. +68
    -1
      backend/views/etablissement/facturation.php
  6. BIN
      backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc
  7. +192
    -162
      backend/web/css/screen.css
  8. +28
    -0
      backend/web/sass/screen.scss
  9. +77
    -0
      common/models/Etablissement.php
  10. +76
    -0
      common/models/Facture.php
  11. +17
    -0
      console/migrations/m161219_135239_champs_facture_periode.php
  12. +17
    -0
      console/migrations/m161219_144530_champs_facture_ca.php

+ 50
- 1
backend/controllers/EtablissementAdminController.php Wyświetl plik

@@ -10,6 +10,7 @@ use yii\filters\AccessControl;
use common\helpers\Upload ;
use common\models\Etablissement ;
use yii\data\ActiveDataProvider ;
use common\models\Facture ;

/**
* UserController implements the CRUD actions for User model.
@@ -56,9 +57,57 @@ class EtablissementAdminController extends BackendController
]);
}
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()
{
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)

+ 16
- 1
backend/controllers/EtablissementController.php Wyświetl plik

@@ -12,6 +12,7 @@ use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\helpers\Upload ;
use common\models\Etablissement ;
use common\models\Facture ;

/**
* UserController implements the CRUD actions for User model.
@@ -77,7 +78,21 @@ class EtablissementController extends BackendController
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)

+ 47
- 0
backend/views/etablissement-admin/facturation.php Wyświetl plik

@@ -1,6 +1,53 @@
<?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>

<?= 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>' ;
}
}
]
],
]); ?>

+ 46
- 0
backend/views/etablissement-admin/index.php Wyświetl plik

@@ -3,6 +3,7 @@
use yii\helpers\Html;
use yii\grid\GridView;
use common\models\User ;
use common\models\Etablissement ;

$this->title = 'Boulangeries';
$this->params['breadcrumbs'][] = 'Administration' ;
@@ -97,5 +98,50 @@ $this->params['breadcrumbs'][] = $this->title;
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 ;
}
],
],
]); ?>

+ 68
- 1
backend/views/etablissement/facturation.php Wyświetl plik

@@ -1,5 +1,72 @@
<?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 />
&RightArrow; S'il est inférieur à 500€, rien n'est facturé. <br />
&RightArrow; 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>' ;
}
}
]
],
]); ?>

BIN
backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc Wyświetl plik


+ 192
- 162
backend/web/css/screen.css
Plik diff jest za duży
Wyświetl plik


+ 28
- 0
backend/web/sass/screen.scss Wyświetl plik

@@ -15,6 +15,10 @@ $color2: #F8F1DD ;
clear: both ;
}

h1, h2, h3, h4, h5, h6 {
font-family: 'myriadpro-light' ;
}

a {
color: $color1;
@@ -1001,4 +1005,28 @@ a {
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' ;
}
}
}

+ 77
- 0
common/models/Etablissement.php Wyświetl plik

@@ -148,4 +148,81 @@ class Etablissement extends \yii\db\ActiveRecord
}
}
}
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'))) ;
}
}

+ 76
- 0
common/models/Facture.php Wyświetl plik

@@ -0,0 +1,76 @@
<?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() ;
}
}

+ 17
- 0
console/migrations/m161219_135239_champs_facture_periode.php Wyświetl plik

@@ -0,0 +1,17 @@
<?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') ;
}
}

+ 17
- 0
console/migrations/m161219_144530_champs_facture_ca.php Wyświetl plik

@@ -0,0 +1,17 @@
<?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') ;
}
}

Ładowanie…
Anuluj
Zapisz