Просмотр исходного кода

Crédit pain : gestion du paiement/remboursement des commandes dans le backend

Ajout du statut payé ou non payé dans l'affichage de la commande.
Boutons de paiement et de remboursement, affichage du crédit pain de l'utilisateur.
Affichage d'un historique répertoriant tous les mouvements de crédits en lien avec la commande.
master
keun 8 лет назад
Родитель
Сommit
b58667db51
11 измененных файлов: 427 добавлений и 136 удалений
  1. +134
    -17
      backend/controllers/CommandeController.php
  2. +1
    -0
      backend/controllers/UserController.php
  3. +5
    -2
      backend/views/commande/index.php
  4. +5
    -3
      backend/views/user/credit.php
  5. Двоичные данные
      backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc
  6. +100
    -91
      backend/web/css/screen.css
  7. +50
    -11
      backend/web/js/lechatdesnoisettes.js
  8. +14
    -3
      backend/web/sass/screen.scss
  9. +66
    -3
      common/models/Commande.php
  10. +35
    -6
      common/models/CreditHistorique.php
  11. +17
    -0
      console/migrations/m161209_104907_champs_credit_historique_user_action.php

+ 134
- 17
backend/controllers/CommandeController.php Просмотреть файл

@@ -18,6 +18,9 @@ use common\models\User;
use kartik\mpdf\Pdf;
use common\models\CommandeAutoForm ;
use common\models\CommandeAuto ;
use common\models\CreditHistorique;
use common\models\UserEtablissement;
use yii\helpers\Html ;

class CommandeController extends BackendController {

@@ -272,7 +275,7 @@ class CommandeController extends BackendController {

// commandes
$commandes = Commande::find()
->with('commandeProduits', 'user')
->with('commandeProduits', 'user', 'creditHistorique')
->joinWith('production')
->where(['production.date' => $date])
->andWhere(['production.id_etablissement' => Yii::$app->user->identity->id_etablissement])
@@ -319,7 +322,9 @@ class CommandeController extends BackendController {
$data_options_commandes[$c->id] = [] ;
$array_options = [] ;
$array_options[$c->id]['montant'] = number_format($c->montant, 2, ',', '') ;
$array_options[$c->id]['montant'] = $c->montant ;
$array_options[$c->id]['str_montant'] = number_format($c->montant, 2, ',', '').' €' ;
$array_options[$c->id]['montant_paye'] = $c->montant_paye ;
$array_options[$c->id]['produits'] = [] ;
foreach($c->commandeProduits as $cp)
{
@@ -821,11 +826,12 @@ class CommandeController extends BackendController {
public function actionAjaxUpdate($id_commande, $produits, $date)
{
$commande = Commande::find()->with('production')->where(['id' => $id_commande])->one() ;
$commande = Commande::find()->with('production','creditHistorique','user')->where(['id' => $id_commande])->one() ;
if($commande &&
$commande->production->id_etablissement == Yii::$app->user->identity->id_etablissement)
{
$commande->init() ;
$produits = json_decode($produits) ;
foreach($produits as $key => $quantite)
{
@@ -861,21 +867,13 @@ class CommandeController extends BackendController {
if($commande_produit)
$commande_produit->delete() ;
}
}
$commande->date_update = date('Y-m-d H:i:s') ;
$commande->save() ;
// total commande
$commande = Commande::find()->with('commandeProduits')->where(['id' => $id_commande])->one() ;
$commande->init() ;
$json_commande = ['produits'=> [], 'montant' => number_format($commande->montant, 2)] ;
foreach($commande->commandeProduits as $commande_produit)
{
$json_commande['produits'][$commande_produit->id_produit] = $commande_produit->quantite ;
}
// data commande
$json_commande = $commande->getDataJson() ;
// total point de vente
$point_vente = PointVente::findOne($commande->id_point_vente) ;
@@ -889,12 +887,9 @@ class CommandeController extends BackendController {
foreach($commandes as $c) $c->init() ;
$point_vente->initCommandes($commandes) ;
echo json_encode([
'total_commande' => number_format($commande->montant, 2).' €',
'total_pv' => number_format($point_vente->recettes, 2).' €',
'json_commande' => json_encode($json_commande)
'json_commande' => $json_commande
]) ;
die() ;
@@ -908,6 +903,20 @@ class CommandeController extends BackendController {
// delete
if ($commande) {
// remboursement si l'utilisateur a payé pour cette commande
$montant_paye = $commande->getMontantPaye() ;
if($montant_paye > 0.01)
{
$credit_historique = new CreditHistorique ;
$credit_historique->id_user = $commande->id_user ;
$credit_historique->id_commande = $id_commande ;
$credit_historique->montant = $montant_paye ;
$credit_historique->type = CreditHistorique::TYPE_REMBOURSEMENT ;
$credit_historique->id_etablissement = Yii::$app->user->identity->id_etablissement ;
$credit_historique->id_user_action = Yii::$app->user->identity->id ;
$credit_historique->save() ;
}
$commande->delete();
CommandeProduit::deleteAll(['id_commande' => $id_commande]);
}
@@ -1112,5 +1121,113 @@ class CommandeController extends BackendController {
die() ;
}
public function actionStatutPaiement($id_commande)
{
$commande = Commande::find()
->with('commandeProduits','production')
->where(['id' => $id_commande])
->one() ;
if($commande)
{
$commande->init() ;
$html = '' ;
if($commande->id_user)
{
$user_etablissement = UserEtablissement::find()
->where([
'id_user' => $commande->id_user,
'id_etablissement' => $commande->production->id_etablissement
])
->one() ;
$montant_paye = $commande->getMontantPaye() ;
//$html .= $commande->montant.' | '.$montant_paye ;
if(abs($commande->montant - $montant_paye) < 0.0001)
{
$html .= '<span class="label label-success">Payé</span>' ;
$buttons_credit = Html::a('Rembourser '.$commande->getMontantFormat(), 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser','data-montant' => $commande->montant,'data-type' => 'remboursement']) ;
}
elseif($commande->montant > $montant_paye)
{
$montant_payer = $commande->montant - $montant_paye ;
$html .= '<span class="label label-danger">Non payé</span> reste <strong>'.number_format($montant_payer,2).' €</strong> à payer' ;
$buttons_credit = Html::a('Payer '.number_format($montant_payer,2).' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs payer','data-montant' => $montant_payer,'data-type' => 'paiement']) ;
}
elseif($commande->montant < $montant_paye)
{
$montant_rembourser = $montant_paye - $commande->montant ;
$html .= ' <span class="label label-success">Payé</span> <strong>'.number_format($montant_rembourser,2).' €</strong> à rembourser' ;
$buttons_credit = Html::a('Rembourser '.number_format($montant_rembourser,2).' €', 'javascript:void(0);', ['class' => 'btn btn-default btn-xs rembourser','data-montant' => $montant_rembourser,'data-type' => 'remboursement']) ;
}
$html .= '<span class="buttons-credit">'
. 'Crédit pain : <strong>'.number_format($user_etablissement->credit,2).' €</strong><br />'
. $buttons_credit
. '</span>' ;

// historique
$historique = CreditHistorique::find()
->with('userAction')
->where(['id_commande' => $id_commande])
->all() ;

$html .= '<br /><br /><strong>Historique</strong><br /><table class="table table-condensed table-bordered">'
. '<thead><tr><th>Date</th><th>Utilisateur</th><th>Action</th><th>Montant</th></tr></thead>'
. '<tbody>' ;

if($historique && is_array($historique) && count($historique))
{
foreach($historique as $h)
{
$html .= '<tr>'
. '<td>'.date('d/m/Y H:i:s',strtotime($h->date)).'</td>'
. '<td>'.Html::encode($h->userAction->nom.' '.$h->userAction->prenom).'</td>'
. '<td>'.$h->getLibelleType().'</td>'
. '<td>'.number_format($h->montant,2).' €</td>'
. '</tr>' ;
}
}
else {
$html .= '<tr><td colspan="4">Aucun résultat</td></tr>' ;
}

$html .= '</tbody></table>' ;
}
else {
$html .= '<div class="alert alert-warning">Pas de gestion de crédit pain pour cette commande car elle n\'est pas liée à un compte utilisateur.</div>' ;
}
echo json_encode([
'html_statut_paiement' => $html,
'json_commande' => $commande->getDataJson()
]);
}
die() ;
}
public function actionPaiement($id_commande, $type, $montant)
{
$commande = Commande::findOne($id_commande) ;
if($commande)
{
$credit_historique = new CreditHistorique ;
$credit_historique->id_user = $commande->id_user ;
$credit_historique->id_commande = $id_commande ;
$credit_historique->montant = $montant ;
$credit_historique->type = $type ;
$credit_historique->id_etablissement = Yii::$app->user->identity->id_etablissement ;
$credit_historique->id_user_action = Yii::$app->user->identity->id ;
$credit_historique->save() ;
}
return $this->actionStatutPaiement($id_commande) ;
}

}

+ 1
- 0
backend/controllers/UserController.php Просмотреть файл

@@ -236,6 +236,7 @@ PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compt
}
$historique = CreditHistorique::find()
->with('commande')
->where([
'id_user' => $user->id,
'id_etablissement' => Yii::$app->user->identity->id_etablissement,

+ 5
- 2
backend/views/commande/index.php Просмотреть файл

@@ -174,7 +174,10 @@ foreach ($produits as $p) {
<?php foreach($pv->commandes as $c): ?>
<li>
<a href="javascript:void(0);" class="btn btn-default" data-pv-id="<?= $pv->id ?>" data-id-commande="<?= $c->id ?>" data-commande='<?= $pv->data_options_commandes[$c->id]['data-commande'] ?>' data-commentaire="<?= Html::encode($c->commentaire) ?>" data-date="<?= date('d/m à H:i',strtotime($c->date)); ?>">
<span class="montant"><?= Html::encode(number_format($c->montant, 2)); ?> €</span>
<span class="montant <?php if($c->montant_paye >= $c->montant): ?>paye<?php endif; ?>">
<?= Html::encode(number_format($c->montant, 2)); ?> €
<?php if($c->montant_paye - $c->montant > 0.01): ?><span class="glyphicon glyphicon-warning-sign"></span><?php endif; ?>
</span>
<span class="user">
<?php if(isset($c->user)): ?>
<?= Html::encode($c->user->nom.' '.$c->user->prenom); ?>
@@ -233,7 +236,7 @@ foreach ($produits as $p) {
<?php endforeach; ?>
<tr class="tr-total">
<td class="td-total"></td>
<td></td>
<td class="td-paiement"></td>
</tr>
</tbody>
</table>

+ 5
- 3
backend/views/user/credit.php Просмотреть файл

@@ -13,7 +13,7 @@ $this->params['breadcrumbs'][] = 'Créditer';

<div class="user-credit">

<div class="col-md-6">
<div class="col-md-12">
<h1><?= $this->title ?></h1>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($credit_historique, 'montant')->textInput() ?>
@@ -28,7 +28,7 @@ $this->params['breadcrumbs'][] = 'Créditer';
<?php ActiveForm::end(); ?>
</div>
<div class="col-md-6">
<div class="col-md-12">
<h2>Historique</h2>
<table class="table table-bordered">
<thead>
@@ -47,7 +47,8 @@ $this->params['breadcrumbs'][] = 'Créditer';
<td>
<?php if($ch->type == CreditHistorique::TYPE_CREDIT_INITIAL): ?>Crédit initial<?php endif; ?>
<?php if($ch->type == CreditHistorique::TYPE_CREDIT): ?>Crédit<?php endif; ?>
<?php if($ch->type == CreditHistorique::TYPE_PAIEMENT_COMMANDE): ?>Paiement commande<?php endif; ?>
<?php if($ch->type == CreditHistorique::TYPE_PAIEMENT): ?>Paiement commande du <?= date('d/m/Y',strtotime($ch->commande->date)) ?><?php endif; ?>
<?php if($ch->type == CreditHistorique::TYPE_REMBOURSEMENT): ?>Remboursement commande du <?= date('d/m/Y',strtotime($ch->commande->date)) ?><?php endif; ?>
</td>
<td>
<?= $ch->montant ; ?> €
@@ -56,6 +57,7 @@ $this->params['breadcrumbs'][] = 'Créditer';
<?php if($ch->moyen_paiement == CreditHistorique::MOYEN_ESPECES): ?>Espèces<?php endif; ?>
<?php if($ch->moyen_paiement == CreditHistorique::MOYEN_CB): ?>Carte bancaire<?php endif; ?>
<?php if($ch->moyen_paiement == CreditHistorique::MOYEN_CHEQUE): ?>Chèque<?php endif; ?>
<?php if(!$ch->moyen_paiement): ?>Crédit pain<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>

Двоичные данные
backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc Просмотреть файл


+ 100
- 91
backend/web/css/screen.css Просмотреть файл

@@ -466,11 +466,16 @@ a:hover, a:focus, a:active {
color: #BB8757;
font-weight: bold;
}
/* line 446, ../sass/screen.scss */
/* line 445, ../sass/screen.scss */
#page-commande #commandes-points-vente ul.liste-commandes li a .montant.paye {
color: #5cb85c;
color: #519951;
}
/* line 451, ../sass/screen.scss */
#page-commande #commandes-points-vente ul.liste-commandes li a .glyphicon-comment {
color: #BB8757;
}
/* line 450, ../sass/screen.scss */
/* line 455, ../sass/screen.scss */
#page-commande #commandes-points-vente ul.liste-commandes li a:hover, #page-commande #commandes-points-vente ul.liste-commandes li a:active, #page-commande #commandes-points-vente ul.liste-commandes li a.active {
text-decoration: none;
background-color: #FCF8E3;
@@ -481,113 +486,117 @@ a:hover, a:focus, a:active {
-webkit-transition: all 0.1s;
transition: all 0.1s;
}
/* line 464, ../sass/screen.scss */
/* line 469, ../sass/screen.scss */
#page-commande #commandes-points-vente .creer-commande,
#page-commande #commandes-points-vente .commandes-auto {
width: 100%;
margin-bottom: 10px;
}
/* line 470, ../sass/screen.scss */
/* line 475, ../sass/screen.scss */
#page-commande #commandes-points-vente .bloc-commande {
padding-top: 20px;
margin-top: 20px;
display: none;
}
/* line 476, ../sass/screen.scss */
/* line 481, ../sass/screen.scss */
#page-commande #commandes-points-vente .title-user {
display: none;
font-size: 19px;
margin-top: 0px;
}
/* line 481, ../sass/screen.scss */
/* line 486, ../sass/screen.scss */
#page-commande #commandes-points-vente .title-user .btn-edit, #page-commande #commandes-points-vente .title-user .btn-remove,
#page-commande #commandes-points-vente .title-user .btn-cancel, #page-commande #commandes-points-vente .title-user .btn-save {
float: right;
position: relative;
top: -6px;
}
/* line 488, ../sass/screen.scss */
/* line 493, ../sass/screen.scss */
#page-commande #commandes-points-vente .title-user .btn-edit, #page-commande #commandes-points-vente .title-user .btn-cancel {
margin-right: 10px;
}
/* line 492, ../sass/screen.scss */
/* line 497, ../sass/screen.scss */
#page-commande #commandes-points-vente .title-user .buttons-save-cancel {
display: none;
}
/* line 496, ../sass/screen.scss */
/* line 501, ../sass/screen.scss */
#page-commande #commandes-points-vente .title-user .choix-user {
display: none;
}
/* line 499, ../sass/screen.scss */
/* line 504, ../sass/screen.scss */
#page-commande #commandes-points-vente .title-user .choix-user .form-control {
width: 200px;
display: inline;
}
/* line 507, ../sass/screen.scss */
/* line 512, ../sass/screen.scss */
#page-commande #commandes-points-vente table.table-produits .td-commande {
text-align: center;
}
/* line 510, ../sass/screen.scss */
/* line 515, ../sass/screen.scss */
#page-commande #commandes-points-vente table.table-produits input.form-control {
text-align: center;
}
/* line 516, ../sass/screen.scss */
/* line 521, ../sass/screen.scss */
#page-commande #commandes-points-vente .td-produit,
#page-commande #commandes-points-vente .th-produit {
width: 70%;
}
/* line 521, ../sass/screen.scss */
/* line 526, ../sass/screen.scss */
#page-commande #commandes-points-vente .td-commande,
#page-commande #commandes-points-vente .th-commande {
width: 30%;
text-align: center;
}
/* line 527, ../sass/screen.scss */
/* line 532, ../sass/screen.scss */
#page-commande #commandes-points-vente .td-produit {
text-transform: uppercase;
}
/* line 531, ../sass/screen.scss */
/* line 536, ../sass/screen.scss */
#page-commande #commandes-points-vente .td-commande {
font-weight: bold;
}
/* line 535, ../sass/screen.scss */
/* line 540, ../sass/screen.scss */
#page-commande #commandes-points-vente .td-total {
font-size: 20px;
font-size: 18px;
text-align: center;
}
/* line 539, ../sass/screen.scss */
/* line 544, ../sass/screen.scss */
#page-commande #commandes-points-vente .td-total span {
padding: 5px 10px;
padding: 2px 10px;
background-color: #BB8757;
color: white;
font-weight: bold;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
}
/* line 554, ../sass/screen.scss */
#page-commande #commandes-points-vente .td-paiement .buttons-credit {
float: right;
}
/* line 549, ../sass/screen.scss */
/* line 560, ../sass/screen.scss */
#page-commande #commandes-points-vente .panel-commande-automatique .field-commandeautoform-id_user,
#page-commande #commandes-points-vente .panel-commande-automatique .field-commandeautoform-id_etablissement {
display: none;
}
/* line 556, ../sass/screen.scss */
/* line 567, ../sass/screen.scss */
#page-commande #commandes-points-vente .panel-commande-automatique .jours .form-group {
float: left;
margin-right: 10px;
}
/* line 565, ../sass/screen.scss */
/* line 576, ../sass/screen.scss */
#page-commande #old-commandes {
display: none;
}
/* line 569, ../sass/screen.scss */
/* line 580, ../sass/screen.scss */
#page-commande .form-commandes-point-vente {
margin-top: 20px;
}
/* line 573, ../sass/screen.scss */
/* line 584, ../sass/screen.scss */
#page-commande .form-commandes-point-vente table {
border-bottom: solid 1px #e0e0e0;
}
/* line 577, ../sass/screen.scss */
/* line 588, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .title-point-vente {
background-color: #fff8e2;
border-left: solid 3px #BB8757;
@@ -595,76 +604,76 @@ a:hover, a:focus, a:active {
text-align: left;
padding: 10px;
}
/* line 585, ../sass/screen.scss */
/* line 596, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .title-totaux {
text-align: center;
}
/* line 589, ../sass/screen.scss */
/* line 600, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .border-left {
border-left: solid 1px #e0e0e0;
}
/* line 593, ../sass/screen.scss */
/* line 604, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .border-right {
border-right: solid 1px #e0e0e0;
}
/* line 597, ../sass/screen.scss */
/* line 608, ../sass/screen.scss */
#page-commande .form-commandes-point-vente input.quantite {
width: 30px;
background-color: white;
border: solid 1px #e0e0e0;
text-align: center;
}
/* line 605, ../sass/screen.scss */
/* line 616, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .td-produit {
text-align: center;
}
/* line 609, ../sass/screen.scss */
/* line 620, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .submit-pv {
float: right;
}
/* line 613, ../sass/screen.scss */
/* line 624, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .select-user {
background-color: #F9F9F9;
border: solid 1px #e0e0e0;
}
/* line 618, ../sass/screen.scss */
/* line 629, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .date-commande {
font-size: 12px;
}
/* line 622, ../sass/screen.scss */
/* line 633, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .datepicker, #page-commande .form-commandes-point-vente .text {
background-color: white;
border: solid 1px #e0e0e0;
margin-top: 3px;
width: 100px;
}
/* line 630, ../sass/screen.scss */
/* line 641, ../sass/screen.scss */
#page-commande .form-commandes-point-vente td.center {
text-align: center;
}
/* line 636, ../sass/screen.scss */
/* line 647, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .depasse {
color: #b32815;
}
/* line 640, ../sass/screen.scss */
/* line 651, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .total strong span {
font-weight: normal;
font-size: 13px;
}
/* line 645, ../sass/screen.scss */
/* line 656, ../sass/screen.scss */
#page-commande .form-commandes-point-vente .vrac {
display: none;
}
/* line 649, ../sass/screen.scss */
/* line 660, ../sass/screen.scss */
#page-commande .form-commandes-point-vente td.client {
text-align: left;
padding: 3px;
}
/* line 652, ../sass/screen.scss */
/* line 663, ../sass/screen.scss */
#page-commande .form-commandes-point-vente td.client .date-commande {
color: gray;
}
/* line 659, ../sass/screen.scss */
/* line 670, ../sass/screen.scss */
#page-commande .table-header-rotated {
border-top: 0px;
border-left: 0px;
@@ -672,15 +681,15 @@ a:hover, a:focus, a:active {
width: 100%;
width: auto;
}
/* line 666, ../sass/screen.scss */
/* line 677, ../sass/screen.scss */
#page-commande .table-header-rotated .total strong {
border-bottom: solid 1px gray;
}
/* line 671, ../sass/screen.scss */
/* line 682, ../sass/screen.scss */
#page-commande .table-header-rotated th.row-header {
width: auto;
}
/* line 675, ../sass/screen.scss */
/* line 686, ../sass/screen.scss */
#page-commande .table-header-rotated td {
width: 40px;
border-top: 1px solid #dddddd;
@@ -689,7 +698,7 @@ a:hover, a:focus, a:active {
vertical-align: middle;
text-align: center;
}
/* line 684, ../sass/screen.scss */
/* line 695, ../sass/screen.scss */
#page-commande .table-header-rotated th.rotate-45 {
font-weight: normal;
height: 80px;
@@ -703,7 +712,7 @@ a:hover, a:focus, a:active {
line-height: 1;
border: 0px none;
}
/* line 698, ../sass/screen.scss */
/* line 709, ../sass/screen.scss */
#page-commande .table-header-rotated th.rotate-45 > div {
background-color: #F5F5F5;
position: relative;
@@ -721,7 +730,7 @@ a:hover, a:focus, a:active {
border-right: 1px solid #dddddd;
border-top: 1px solid #dddddd;
}
/* line 715, ../sass/screen.scss */
/* line 726, ../sass/screen.scss */
#page-commande .table-header-rotated th.rotate-45 span {
-ms-transform: skew(45deg, 0deg) rotate(315deg);
-moz-transform: skew(45deg, 0deg) rotate(315deg);
@@ -739,51 +748,51 @@ a:hover, a:focus, a:active {
text-align: left;
}

/* line 736, ../sass/screen.scss */
/* line 747, ../sass/screen.scss */
#email-masse-form #ids-users {
line-height: 30px;
}
/* line 738, ../sass/screen.scss */
/* line 749, ../sass/screen.scss */
#email-masse-form #ids-users .label {
text-transform: capitalize;
}

/* line 746, ../sass/screen.scss */
/* line 757, ../sass/screen.scss */
.produit-create #jours-production .form-group, .produit-update #jours-production .form-group {
float: left;
margin-right: 15px;
}
/* line 750, ../sass/screen.scss */
/* line 761, ../sass/screen.scss */
.produit-create #jours-production .form-group label, .produit-update #jours-production .form-group label {
font-weight: normal;
}
/* line 755, ../sass/screen.scss */
/* line 766, ../sass/screen.scss */
.produit-create .field-produit-id_etablissement, .produit-update .field-produit-id_etablissement {
display: none;
}

/* line 760, ../sass/screen.scss */
/* line 771, ../sass/screen.scss */
.table-striped > tbody > tr:nth-of-type(2n) {
background-color: white;
}

/* line 765, ../sass/screen.scss */
/* line 776, ../sass/screen.scss */
.wrap .produit-index .td-photo {
max-width: 100px;
width: 100px;
}
/* line 769, ../sass/screen.scss */
/* line 780, ../sass/screen.scss */
.wrap .produit-index .photo-produit {
max-width: 100px;
}
/* line 773, ../sass/screen.scss */
/* line 784, ../sass/screen.scss */
.wrap .produit-index .ui-state-highlight {
height: 75px;
background-color: #F8F1DD;
}

/* communiquer */
/* line 781, ../sass/screen.scss */
/* line 792, ../sass/screen.scss */
.communiquer-mode-emploi {
border: solid 1px #e0e0e0;
padding: 10px;
@@ -793,18 +802,18 @@ a:hover, a:focus, a:active {
margin-bottom: 30px;
font-family: "myriadpro-regular";
}
/* line 789, ../sass/screen.scss */
/* line 800, ../sass/screen.scss */
.communiquer-mode-emploi .header .logo {
float: left;
width: 75px;
padding-right: 20px;
padding-top: 10px;
}
/* line 795, ../sass/screen.scss */
/* line 806, ../sass/screen.scss */
.communiquer-mode-emploi .header .logo img {
width: 75px;
}
/* line 801, ../sass/screen.scss */
/* line 812, ../sass/screen.scss */
.communiquer-mode-emploi .header h1 {
font-family: "comfortaaregular";
font-size: 40px;
@@ -812,7 +821,7 @@ a:hover, a:focus, a:active {
margin-bottom: 0px;
font-weight: normal;
}
/* line 809, ../sass/screen.scss */
/* line 820, ../sass/screen.scss */
.communiquer-mode-emploi .header h2 {
margin-top: 0px;
font-family: "myriadpro-regular";
@@ -822,7 +831,7 @@ a:hover, a:focus, a:active {
left: 2px;
font-weight: normal;
}
/* line 820, ../sass/screen.scss */
/* line 831, ../sass/screen.scss */
.communiquer-mode-emploi h3 {
font-family: "comfortaalight";
font-family: "myriadpro-regular";
@@ -832,45 +841,45 @@ a:hover, a:focus, a:active {
margin-bottom: 0px;
}

/* line 830, ../sass/screen.scss */
/* line 841, ../sass/screen.scss */
.communiquer-mode-emploi-encart {
width: 420px;
margin-top: 20px;
}
/* line 834, ../sass/screen.scss */
/* line 845, ../sass/screen.scss */
.communiquer-mode-emploi-encart .header .logo {
width: 60px;
margin-right: 20px;
padding-top: 5px;
}
/* line 839, ../sass/screen.scss */
/* line 850, ../sass/screen.scss */
.communiquer-mode-emploi-encart .header .logo img {
width: 60px;
}
/* line 845, ../sass/screen.scss */
/* line 856, ../sass/screen.scss */
.communiquer-mode-emploi-encart .header h1 {
margin-bottom: 3px;
}
/* line 854, ../sass/screen.scss */
/* line 865, ../sass/screen.scss */
.communiquer-mode-emploi-encart h3 {
margin-top: 15px;
margin-bottom: 15px;
}

/* line 860, ../sass/screen.scss */
/* line 871, ../sass/screen.scss */
.bloc-mode-emploi-pdf {
width: 49.9%;
float: left;
border-bottom: dotted 1px gray;
}

/* line 866, ../sass/screen.scss */
/* line 877, ../sass/screen.scss */
.bloc-mode-emploi-border {
border-right: dotted 1px gray;
border-bottom: dotted 1px gray;
}

/* line 871, ../sass/screen.scss */
/* line 882, ../sass/screen.scss */
.communiquer-mode-emploi-pdf {
border: 0px none;
-moz-border-radius: 0px;
@@ -879,88 +888,88 @@ a:hover, a:focus, a:active {
margin-bottom: 0px;
padding: 20px 0px 20px 30px;
}
/* line 879, ../sass/screen.scss */
/* line 890, ../sass/screen.scss */
.communiquer-mode-emploi-pdf .header .logo {
float: left;
width: 55px;
padding-right: 15px;
padding-top: 10px;
}
/* line 885, ../sass/screen.scss */
/* line 896, ../sass/screen.scss */
.communiquer-mode-emploi-pdf .header .logo img {
width: 55px;
}
/* line 889, ../sass/screen.scss */
/* line 900, ../sass/screen.scss */
.communiquer-mode-emploi-pdf .header h1 {
font-size: 32px;
}
/* line 892, ../sass/screen.scss */
/* line 903, ../sass/screen.scss */
.communiquer-mode-emploi-pdf .header h2 {
font-size: 16px;
}
/* line 897, ../sass/screen.scss */
/* line 908, ../sass/screen.scss */
.communiquer-mode-emploi-pdf h3 {
font-weight: normal;
}

/* line 902, ../sass/screen.scss */
/* line 913, ../sass/screen.scss */
.bloc-mode-emploi-bottom {
border-bottom: 0px none;
border-bottom: solid 1px white;
}

/* commandes auto */
/* line 912, ../sass/screen.scss */
/* line 923, ../sass/screen.scss */
.commandeauto-form #bloc-select-user {
padding-left: 0px;
}
/* line 916, ../sass/screen.scss */
/* line 927, ../sass/screen.scss */
.commandeauto-form #or-user {
font-size: 20px;
text-align: center;
}
/* line 919, ../sass/screen.scss */
/* line 930, ../sass/screen.scss */
.commandeauto-form #or-user span {
position: relative;
top: 24px;
}
/* line 925, ../sass/screen.scss */
/* line 936, ../sass/screen.scss */
.commandeauto-form .field-commandeautoform-id_etablissement {
display: none;
}
/* line 929, ../sass/screen.scss */
/* line 940, ../sass/screen.scss */
.commandeauto-form .jours .form-group {
float: left;
margin-right: 20px;
}
/* line 936, ../sass/screen.scss */
/* line 947, ../sass/screen.scss */
.commandeauto-form .produits .table {
width: 500px;
}
/* line 939, ../sass/screen.scss */
/* line 950, ../sass/screen.scss */
.commandeauto-form .produits .quantite {
text-align: center;
}

/* points de vente */
/* line 948, ../sass/screen.scss */
/* line 959, ../sass/screen.scss */
.point-vente-form #pointvente-users {
display: none;
height: 500px;
overflow-y: scroll;
}
/* line 952, ../sass/screen.scss */
/* line 963, ../sass/screen.scss */
.point-vente-form #pointvente-users label {
font-weight: normal;
display: block;
}

/* utilisateurs */
/* line 962, ../sass/screen.scss */
/* line 973, ../sass/screen.scss */
.user-index .input-group {
width: 180px;
}
/* line 965, ../sass/screen.scss */
/* line 976, ../sass/screen.scss */
.user-index .input-group .input-credit {
text-align: center;
}

+ 50
- 11
backend/web/js/lechatdesnoisettes.js Просмотреть файл

@@ -179,9 +179,11 @@ function chat_index_commandes_points_vente() {
produits: JSON.stringify(tab_produits),
date: $('#date-production').val()
}, function(data) {
$('#point-vente-'+id_pv+' .btn-save').removeAttr('disabled') ;
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').data('commande',data.json_commande);
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html(data.total_commande) ;
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande);
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html(data.json_commande.str_montant) ;
chat_index_commandes_affiche_commande(id_commande) ;
chat_index_commandes_maj_recap_pv(id_pv, data.total_pv) ;

@@ -318,12 +320,8 @@ function chat_btn_plus_moins() {
}

function chat_index_commandes_affiche_commande(id_commande) {


var link = $("a[data-id-commande="+id_commande+"]") ;

var id_pv = link.data('pv-id') ;
$('#point-vente-'+id_pv+' .bloc-commande').hide() ;
@@ -331,6 +329,25 @@ function chat_index_commandes_affiche_commande(id_commande) {
$('#point-vente-'+id_pv+' .liste-commandes a').removeClass('active') ;
link.addClass('active') ;
var commande = link.attr('data-commande') ;
if(!$.isPlainObject(link.attr('data-commande'))) {
commande = JSON.parse(link.attr('data-commande')) ;
}
// maj ligne commande
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').removeClass('paye') ;
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant .glyphicon').remove() ;
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html() ;
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').html(commande.str_montant) ;
if(commande.montant_paye >= commande.montant) {
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').addClass('paye') ;
if(commande.montant_paye > commande.montant) {
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+'] .montant').append(' <span class="glyphicon glyphicon-warning-sign"></span>') ;
}
}
// set id_commande
$('#point-vente-'+id_pv+' .btn-cancel').data('id-commande',id_commande) ;
$('#point-vente-'+id_pv+' .btn-save').data('id-commande',id_commande) ;
@@ -347,16 +364,12 @@ function chat_index_commandes_affiche_commande(id_commande) {
$('#point-vente-'+id_pv+' .td-commande').html('') ;
$('#point-vente-'+id_pv+' .td-total').html('') ;
$('#point-vente-'+id_pv+' tr').removeClass('active') ;
var commande = link.data('commande') ;
if(!$.isPlainObject(link.data('commande'))) {
commande = JSON.parse(link.data('commande')) ;
}
$.each(commande.produits, function(i, item) {
$('#point-vente-'+id_pv+' .produit-'+i+' .td-commande').html(item) ;
$('#point-vente-'+id_pv+' .produit-'+i).addClass('active') ;
}) ;
$('#point-vente-'+id_pv+' .td-total').html('<span>'+commande.montant+'</span>') ;
$('#point-vente-'+id_pv+' .td-total').html('<span>'+commande.str_montant+'</span>') ;
$('#point-vente-'+id_pv+' .tr-total').show() ;

var commentaire = link.data('commentaire') ;
@@ -373,6 +386,32 @@ function chat_index_commandes_affiche_commande(id_commande) {
$('#point-vente-'+id_pv+' .title-user').show() ;
$('#point-vente-'+id_pv+' .tr-total').show() ;
// paiement
$.get('index.php',{
r: 'commande/statut-paiement',
id_commande: id_commande
}, function(data) {
$('#point-vente-'+id_pv+' .bloc-commande .td-paiement').html(data.html_statut_paiement) ;
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande) ;
chat_index_commandes_boutons_paiement(id_pv, id_commande) ;
},'json') ;
}

function chat_index_commandes_boutons_paiement(id_pv, id_commande) {
// boutons paiement/remboursement
$('#point-vente-'+id_pv+' .payer, #point-vente-'+id_pv+' .rembourser').click(function() {
$.get('index.php',{
r: 'commande/paiement',
id_commande: id_commande,
type: $(this).data('type'),
montant: $(this).data('montant')
}, function(data) {
$('#point-vente-'+id_pv+' .bloc-commande .td-paiement').html(data.html_statut_paiement) ;
$('#point-vente-'+id_pv+' a[data-id-commande='+id_commande+']').attr('data-commande',data.json_commande) ;
chat_index_commandes_affiche_commande(id_commande) ;
chat_index_commandes_boutons_paiement(id_pv, id_commande) ;
}, 'json') ;
}) ;
}

function chat_index_commandes_liste_produits() {

+ 14
- 3
backend/web/sass/screen.scss Просмотреть файл

@@ -441,6 +441,11 @@ a {
float: right ;
color: $color1 ;
font-weight: bold ;
&.paye {
color: #5cb85c ;
color: #519951 ;
}
}
.glyphicon-comment {
@@ -533,15 +538,21 @@ a {
}
.td-total {
font-size: 20px ;
font-size: 18px ;
text-align: center ;
span {
padding: 5px 10px ;
padding: 2px 10px ;
background-color: $color1 ;
color: white ;
font-weight: bold ;
@include border-radius(15px ) ;
@include border-radius(8px) ;
}
}
.td-paiement {
.buttons-credit {
float: right ;
}
}

+ 66
- 3
common/models/Commande.php Просмотреть файл

@@ -20,6 +20,7 @@ class Commande extends \yii\db\ActiveRecord
var $montant = 0 ;
var $montant_pain = 0 ;
var $montant_vrac = 0 ;
var $montant_paye = 0 ;
var $poids_pain = 0 ;
var $poids_vrac = 0 ;
@@ -37,10 +38,13 @@ class Commande extends \yii\db\ActiveRecord
}
public function init() {
if(isset($this->commandeProduits)) {
foreach($this->commandeProduits as $p) {
if(isset($this->commandeProduits))
{
foreach($this->commandeProduits as $p)
{
if(isset($p->produit) && $p->produit->vrac) {
if(isset($p->produit) && $p->produit->vrac)
{
$this->montant_vrac += $p->prix * $p->quantite/1000 ;
$this->poids_vrac += $p->quantite/1000 ;
}
@@ -53,6 +57,16 @@ class Commande extends \yii\db\ActiveRecord
$this->montant = $this->montant_vrac + $this->montant_pain ;
}
if(isset($this->creditHistorique))
{
foreach($this->creditHistorique as $ch)
{
if($ch->type == CreditHistorique::TYPE_PAIEMENT)
$this->montant_paye += $ch->montant ;
elseif($ch->type == CreditHistorique::TYPE_REMBOURSEMENT)
$this->montant_paye -= $ch->montant ;
}
}
}
public static function getQuantiteProduit($id_produit, $commandes) {
@@ -90,6 +104,11 @@ class Commande extends \yii\db\ActiveRecord
public function getPointVente() {
return $this->hasOne(PointVente::className(), ['id'=>'id_point_vente']) ;
}
public function getCreditHistorique()
{
return $this->hasMany(CreditHistorique::className(), ['id_commande'=>'id']) ;
}

/**
* @inheritdoc
@@ -131,4 +150,48 @@ class Commande extends \yii\db\ActiveRecord
return substr($str, 0, strlen($str) - 2) ;
}
public function getMontantPaye()
{
$historique = CreditHistorique::find()
->where(['id_commande' => $this->id])
->all() ;
$montant = 0 ;
foreach($historique as $ch)
{
if($ch->type == CreditHistorique::TYPE_PAIEMENT)
$montant += $ch->montant ;
elseif($ch->type == CreditHistorique::TYPE_REMBOURSEMENT)
$montant -= $ch->montant ;
}
return $montant ;
}
public function getMontantFormat()
{
return number_format($this->montant,2).' €' ;
}
public function getDataJson()
{
$commande = Commande::find()->with('commandeProduits')->where(['id' => $this->id])->one() ;
$commande->init() ;
$json_commande = [
'produits'=> [],
'montant' => $commande->montant,
'str_montant' => $commande->getMontantFormat(),
'montant_paye' => $commande->getMontantPaye()
] ;
foreach($commande->commandeProduits as $commande_produit)
{
$json_commande['produits'][$commande_produit->id_produit] = $commande_produit->quantite ;
}
return json_encode($json_commande) ;
}
}

+ 35
- 6
common/models/CreditHistorique.php Просмотреть файл

@@ -5,6 +5,7 @@ namespace common\models;
use Yii;
use yii\db\ActiveRecord ;
use common\models\User ;
use common\models\Commande ;

/**
* This is the model class for table "credit_historique".
@@ -22,7 +23,8 @@ class CreditHistorique extends ActiveRecord
{
const TYPE_CREDIT_INITIAL = 'credit-initial' ;
const TYPE_CREDIT = 'credit' ;
const TYPE_PAIEMENT_COMMANDE = 'paiement-commande' ;
const TYPE_PAIEMENT = 'paiement' ;
const TYPE_REMBOURSEMENT = 'remboursement' ;
const MOYEN_CB = 'cb' ;
const MOYEN_ESPECES = 'especes' ;
@@ -42,8 +44,8 @@ class CreditHistorique extends ActiveRecord
public function rules()
{
return [
[['montant', 'moyen_paiement'], 'required'],
[['id_user', 'id_commande', 'id_etablissement'], 'integer'],
[['montant'], 'required'],
[['id_user','id_user_action', 'id_commande', 'id_etablissement'], 'integer'],
[['date'], 'safe'],
[['montant'], 'number'],
[['type', 'moyen_paiement'], 'string', 'max' => 255],
@@ -58,6 +60,7 @@ class CreditHistorique extends ActiveRecord
return [
'id' => 'ID',
'id_user' => 'Utilisateur',
'id_user_action' => 'Utilisateur',
'id_commande' => 'Commande',
'date' => 'Date',
'montant' => 'Montant',
@@ -67,6 +70,30 @@ class CreditHistorique extends ActiveRecord
];
}
public function getUser()
{
return $this->hasOne(User::className(),['id' => 'id_user']) ;
}
public function getUserAction()
{
return $this->hasOne(User::className(),['id' => 'id_user_action']) ;
}
public function getCommande()
{
return $this->hasOne(Commande::className(),['id' => 'id_commande']) ;
}
public function getLibelleType()
{
if($this->type == 'paiement')
return 'Paiement' ;
elseif($this->type == 'remboursement')
return 'Remboursement' ;
}
public function save($runValidation = true, $attributeNames = NULL) {
parent::save($runValidation, $attributeNames) ;
@@ -77,16 +104,18 @@ class CreditHistorique extends ActiveRecord
if($user_etablissement)
{
if($this->type == self::TYPE_CREDIT ||
$this->type == self::TYPE_CREDIT_INITIAL)
$this->type == self::TYPE_CREDIT_INITIAL ||
$this->type == self::TYPE_REMBOURSEMENT)
{
$user_etablissement->credit += $this->montant ;
$user_etablissement->save() ;
}
elseif($this->type == self::TYPE_PAIEMENT_COMMANDE)
elseif($this->type == self::TYPE_PAIEMENT)
{
$user_etablissement->credit -= $this->montant ;
$user_etablissement->save() ;
}
$user_etablissement->save() ;
}
}
}

+ 17
- 0
console/migrations/m161209_104907_champs_credit_historique_user_action.php Просмотреть файл

@@ -0,0 +1,17 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

class m161209_104907_champs_credit_historique_user_action extends Migration
{
public function up()
{
$this->addColumn('credit_historique','id_user_action',Schema::TYPE_INTEGER) ;
}

public function down()
{
$this->dropColumn('credit_historique','id_user_action') ;
}
}

Загрузка…
Отмена
Сохранить