public function actionDeleteCommande($date, $id_commande) { | 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) { | 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(); | $commande->delete(); | ||||
CommandeProduit::deleteAll(['id_commande' => $id_commande]); | CommandeProduit::deleteAll(['id_commande' => $id_commande]); | ||||
} | } | ||||
$this->redirect(['index', 'date' => $date]); | $this->redirect(['index', 'date' => $date]); |
$model->vendredi = $commandeauto->vendredi ; | $model->vendredi = $commandeauto->vendredi ; | ||||
$model->samedi = $commandeauto->samedi ; | $model->samedi = $commandeauto->samedi ; | ||||
$model->dimanche = $commandeauto->dimanche ; | $model->dimanche = $commandeauto->dimanche ; | ||||
$model->paiement_automatique = $commandeauto->paiement_automatique ; | |||||
// produits | // produits | ||||
$commandeauto_produits = CommandeAutoProduit::find()->where(['id_commande_auto' => $model->id])->all() ; | $commandeauto_produits = CommandeAutoProduit::find()->where(['id_commande_auto' => $model->id])->all() ; |
$mois = date('m/Y',strtotime($c->production->date)) ; | $mois = date('m/Y',strtotime($c->production->date)) ; | ||||
if(isset($data_pain[$mois])) | if(isset($data_pain[$mois])) | ||||
{ | { | ||||
if($mois == '06/2016') { | |||||
//print_r($c) ; | |||||
} | |||||
$data_pain[$mois] += $c->montant_pain ; | $data_pain[$mois] += $c->montant_pain ; | ||||
} | } | ||||
} | } | ||||
$data_pain_noindex = [] ; | $data_pain_noindex = [] ; | ||||
foreach($data_pain as $key => $val) | foreach($data_pain as $key => $val) | ||||
{ | { | ||||
$data_pain_noindex[] = $val ; | |||||
$data_pain_noindex[] = $val ; | |||||
} | } | ||||
return $this->render('index', [ | return $this->render('index', [ |
<div class="clr"></div> | <div class="clr"></div> | ||||
<?= $form->field($model, 'periodicite_semaine')->dropDownList([1=>1, 2=>2, 3=>3, 4=>4]) ?> | <?= $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"> | <div class="produits"> | ||||
<h2>Produits</h2> | <h2>Produits</h2> | ||||
<?php if(isset($model->errors['produits']) && count($model->errors['produits'])) | <?php if(isset($model->errors['produits']) && count($model->errors['produits'])) |
return 'Toutes les '.$model->periodicite_semaine.' semaines' ; | 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', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{update} {delete}', | 'template' => '{update} {delete}', |
* @property integer $dimanche | * @property integer $dimanche | ||||
* @property integer $periodicite_semaine | * @property integer $periodicite_semaine | ||||
* @property string $username | * @property string $username | ||||
* @property string $paiement_automatique | |||||
*/ | */ | ||||
class CommandeAuto extends \yii\db\ActiveRecord | class CommandeAuto extends \yii\db\ActiveRecord | ||||
{ | { | ||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
return [ | return [ | ||||
[['id_etablissement', 'id_point_vente'], 'required'], | [['id_etablissement', 'id_point_vente'], 'required'], | ||||
[['id_user', 'id_etablissement', 'id_point_vente', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi', 'dimanche', 'periodicite_semaine'], 'integer'], | [['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'], | [['date_debut', 'date_fin','username'], 'safe'], | ||||
]; | ]; | ||||
} | } | ||||
'samedi' => 'Samedi', | 'samedi' => 'Samedi', | ||||
'dimanche' => 'Dimanche', | 'dimanche' => 'Dimanche', | ||||
'periodicite_semaine' => 'Périodicité', | 'periodicite_semaine' => 'Périodicité', | ||||
'paiement_automatique' => 'Paiement automatique' | |||||
]; | ]; | ||||
} | } | ||||
$commande->save() ; | $commande->save() ; | ||||
// produits | // produits | ||||
$montant_total = 0 ; | |||||
foreach($this->commandeAutoProduit as $commande_auto_produit) | foreach($this->commandeAutoProduit as $commande_auto_produit) | ||||
{ | { | ||||
$commande_produit = new CommandeProduit ; | $commande_produit = new CommandeProduit ; | ||||
$commande_produit->prix = $commande_auto_produit->produit->prix ; | $commande_produit->prix = $commande_auto_produit->produit->prix ; | ||||
$commande_produit->save() ; | $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 | |||||
) ; | |||||
} | |||||
} | } | ||||
public $dimanche ; | public $dimanche ; | ||||
public $periodicite_semaine ; | public $periodicite_semaine ; | ||||
public $produits ; | public $produits ; | ||||
public $paiement_automatique ; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
return [ | return [ | ||||
[['id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'], | [['id_etablissement', 'periodicite_semaine', 'id_point_vente'], 'integer'], | ||||
[['date_debut', 'date_fin'], 'date', 'format' => 'php:d/m/Y'], | [['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'], | [['id_point_vente', 'id_etablissement', 'date_debut'],'required', 'message' => 'Champs obligatoire'], | ||||
[['produits','id_user','username'], 'safe'], | [['produits','id_user','username'], 'safe'], | ||||
['id_user', function ($attribute, $params) { | ['id_user', function ($attribute, $params) { | ||||
'dimanche' => 'Dimanche', | 'dimanche' => 'Dimanche', | ||||
'periodicite_semaine' => 'Périodicité (semaines)', | 'periodicite_semaine' => 'Périodicité (semaines)', | ||||
'username' => 'Nom d\'utilisateur', | 'username' => 'Nom d\'utilisateur', | ||||
'paiement_automatique' => 'Paiement automatique' | |||||
]; | ]; | ||||
} | } | ||||
$commandeauto->samedi = $this->samedi ; | $commandeauto->samedi = $this->samedi ; | ||||
$commandeauto->dimanche = $this->dimanche ; | $commandeauto->dimanche = $this->dimanche ; | ||||
$commandeauto->periodicite_semaine = $this->periodicite_semaine ; | $commandeauto->periodicite_semaine = $this->periodicite_semaine ; | ||||
$commandeauto->paiement_automatique = $this->paiement_automatique ; | |||||
$commandeauto->save() ; | $commandeauto->save() ; | ||||
<?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') ; | |||||
} | |||||
} |