ソースを参照

Débit automatique du client lors des commandes récurrentes

master
keun 7年前
コミット
366efd2865
8個のファイルの変更81行の追加7行の削除
  1. +19
    -1
      backend/controllers/CommandeController.php
  2. +1
    -0
      backend/controllers/CommandeautoController.php
  3. +1
    -4
      backend/controllers/StatsController.php
  4. +5
    -0
      backend/views/commandeauto/_form.php
  5. +10
    -0
      backend/views/commandeauto/index.php
  6. +24
    -0
      common/models/CommandeAuto.php
  7. +4
    -2
      common/models/CommandeAutoForm.php
  8. +17
    -0
      console/migrations/m170427_061857_add_champs_paiement_automatique_commande_recurrente.php

+ 19
- 1
backend/controllers/CommandeController.php ファイルの表示

@@ -145,10 +145,28 @@ class CommandeController extends BackendController {

public function actionDeleteCommande($date, $id_commande) {

$commande = Commande::find()->where(['id' => $id_commande])->one();
$commande = Commande::find()
->with(['production','commandeProduits'])
->where(['id' => $id_commande])
->one();
if ($commande) {
$commande->init() ;
// remboursement de la commande
if($commande->id_user && $commande->getMontantPaye() && Etablissement::getConfig('credit_pain'))
{
$commande->creditHistorique(
CreditHistorique::TYPE_REMBOURSEMENT,
$commande->getMontantPaye(),
$commande->production->id_etablissement,
$commande->id_user
) ;
}
$commande->delete();
CommandeProduit::deleteAll(['id_commande' => $id_commande]);
}

$this->redirect(['index', 'date' => $date]);

+ 1
- 0
backend/controllers/CommandeautoController.php ファイルの表示

@@ -108,6 +108,7 @@ class CommandeautoController extends BackendController {
$model->vendredi = $commandeauto->vendredi ;
$model->samedi = $commandeauto->samedi ;
$model->dimanche = $commandeauto->dimanche ;
$model->paiement_automatique = $commandeauto->paiement_automatique ;
// produits
$commandeauto_produits = CommandeAutoProduit::find()->where(['id_commande_auto' => $model->id])->all() ;

+ 1
- 4
backend/controllers/StatsController.php ファイルの表示

@@ -71,9 +71,6 @@ class StatsController extends BackendController {
$mois = date('m/Y',strtotime($c->production->date)) ;
if(isset($data_pain[$mois]))
{
if($mois == '06/2016') {
//print_r($c) ;
}
$data_pain[$mois] += $c->montant_pain ;
}
}
@@ -82,7 +79,7 @@ class StatsController extends BackendController {
$data_pain_noindex = [] ;
foreach($data_pain as $key => $val)
{
$data_pain_noindex[] = $val ;
$data_pain_noindex[] = $val ;
}
return $this->render('index', [

+ 5
- 0
backend/views/commandeauto/_form.php ファイルの表示

@@ -42,6 +42,11 @@ use common\models\PointVente ;
<div class="clr"></div>
<?= $form->field($model, 'periodicite_semaine')->dropDownList([1=>1, 2=>2, 3=>3, 4=>4]) ?>

<?= $form->field($model, 'paiement_automatique')
->checkbox()
->hint('Cochez cette case si vous souhaitez que le crédit pain du client soit automatiquement débité lors de la création de la commande.<br />'
. 'Attention, un compte client existant doit être spécifié en haut de ce formulaire.') ?>
<div class="produits">
<h2>Produits</h2>
<?php if(isset($model->errors['produits']) && count($model->errors['produits']))

+ 10
- 0
backend/views/commandeauto/index.php ファイルの表示

@@ -107,6 +107,16 @@ $this->params['breadcrumbs'][] = $this->title;
return 'Toutes les '.$model->periodicite_semaine.' semaines' ;
}
],
[
'attribute' => 'paiement_automatique',
'format' => 'raw',
'value' => function($model) {
if($model->paiement_automatique)
return '<span class="label label-success">Oui</span>' ;
else
return '<span class="label label-danger">Non</span>' ;
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',

+ 24
- 0
common/models/CommandeAuto.php ファイルの表示

@@ -28,9 +28,11 @@ use common\models\CommandeProduit ;
* @property integer $dimanche
* @property integer $periodicite_semaine
* @property string $username
* @property string $paiement_automatique
*/
class CommandeAuto extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
@@ -47,6 +49,7 @@ class CommandeAuto extends \yii\db\ActiveRecord
return [
[['id_etablissement', 'id_point_vente'], 'required'],
[['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'],
[['paiement_automatique'], 'boolean'],
[['date_debut', 'date_fin','username'], 'safe'],
];
}
@@ -71,6 +74,7 @@ class CommandeAuto extends \yii\db\ActiveRecord
'samedi' => 'Samedi',
'dimanche' => 'Dimanche',
'periodicite_semaine' => 'Périodicité',
'paiement_automatique' => 'Paiement automatique'
];
}
@@ -201,6 +205,7 @@ class CommandeAuto extends \yii\db\ActiveRecord
$commande->save() ;
// produits
$montant_total = 0 ;
foreach($this->commandeAutoProduit as $commande_auto_produit)
{
$commande_produit = new CommandeProduit ;
@@ -210,6 +215,25 @@ class CommandeAuto extends \yii\db\ActiveRecord
$commande_produit->prix = $commande_auto_produit->produit->prix ;
$commande_produit->save() ;
}
// on débite automatiquement le crédit pain du client
if($commande->id_user && $this->paiement_automatique && Etablissement::getConfig('credit_pain'))
{
$commande = Commande::find()
->with('commandeProduits')
->where(['id' => $commande->id])
->one() ;
$commande->init() ;
$commande->creditHistorique(
CreditHistorique::TYPE_PAIEMENT,
$commande->getMontant(),
$production->id_etablissement,
$commande->id_user
) ;
}
}

+ 4
- 2
common/models/CommandeAutoForm.php ファイルの表示

@@ -27,6 +27,7 @@ class CommandeAutoForm extends Model
public $dimanche ;
public $periodicite_semaine ;
public $produits ;
public $paiement_automatique ;
/**
* @inheritdoc
@@ -36,7 +37,7 @@ class CommandeAutoForm extends Model
return [
[['id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'],
[['date_debut', 'date_fin'], 'date', 'format' => 'php:d/m/Y'],
[['lundi','mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche'], 'boolean'],
[['lundi','mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche','paiement_automatique'], 'boolean'],
[['id_point_vente', 'id_etablissement', 'date_debut'],'required', 'message' => 'Champs obligatoire'],
[['produits','id_user','username'], 'safe'],
['id_user', function ($attribute, $params) {
@@ -66,6 +67,7 @@ class CommandeAutoForm extends Model
'dimanche' => 'Dimanche',
'periodicite_semaine' => 'Périodicité (semaines)',
'username' => 'Nom d\'utilisateur',
'paiement_automatique' => 'Paiement automatique'
];
}
@@ -98,7 +100,7 @@ class CommandeAutoForm extends Model
$commandeauto->samedi = $this->samedi ;
$commandeauto->dimanche = $this->dimanche ;
$commandeauto->periodicite_semaine = $this->periodicite_semaine ;
$commandeauto->paiement_automatique = $this->paiement_automatique ;
$commandeauto->save() ;

+ 17
- 0
console/migrations/m170427_061857_add_champs_paiement_automatique_commande_recurrente.php ファイルの表示

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

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

class m170427_061857_add_champs_paiement_automatique_commande_recurrente extends Migration
{
public function up()
{
$this->addColumn('commande_auto', 'paiement_automatique', Schema::TYPE_BOOLEAN.' DEFAULT 0') ;
}

public function down()
{
$this->dropColumn('commande_auto', 'paiement_automatique') ;
}
}

読み込み中…
キャンセル
保存