Browse Source

Refactoring cron process commande

Déclenchement des paiements des commandes juste avant d'envoyer le récap au producteur de manière à ce qu'il ait les bonnes infos relatives au crédit pain du client.
prodstable
keun 7 years ago
parent
commit
800deebd2e
2 changed files with 34 additions and 29 deletions
  1. +33
    -29
      backend/controllers/CronController.php
  2. +1
    -0
      common/models/Commande.php

+ 33
- 29
backend/controllers/CronController.php View File

} }
} }


public function actionSendCommandes($key = '') {
public function actionProcessCommandes($key = '') {
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') { if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
$heure = date('H'); $heure = date('H');


]); ]);


if ($production && $heure == $e['heure_limite_commande']) { if ($production && $heure == $e['heure_limite_commande']) {
/*
* Paiement des commandes (paiement automatique)
*/
$commandes = Commande::find()
->with('commandeProduits', 'user')
->joinWith('production')
->where(['production.date' => $date])
->orderBy('date ASC')
->all();

foreach($commandes as $c) {
if($c->paiement_automatique && Etablissement::getConfig('credit_pain', $c->production->id_etablissement)) {
$c->init() ;

if ($c->getMontantRestant() > 0) {
$c->creditHistorique(
CreditHistorique::TYPE_PAIEMENT,
$c->getMontantRestant(),
$c->production->id_etablissement,
$c->id_user,
User::ID_USER_SYSTEM
);
}
}
}
/*
* Envoi des commandes par email au producteur
*/
$commandes = Commande::find() $commandes = Commande::find()
->with('commandeProduits', 'user') ->with('commandeProduits', 'user')
->joinWith('production') ->joinWith('production')
} }
} }
} }
public function actionPaiementAutoCommandes($key = '') {
if ($key == '64ac0bdab7e9f5e48c4d991ec5201d57') {
$commandes = Commande::find()
->with('commandeProduits', 'user')
->joinWith('production')
->where(['production.date' => date('Y-m-d')])
->orderBy('date ASC')
->all();
foreach($commandes as $c) {
if($c->paiement_automatique && Etablissement::getConfig('credit_pain', $c->production->id_etablissement)) {
$c->init() ;
if ($c->getMontant() > 0) {
$c->creditHistorique(
CreditHistorique::TYPE_PAIEMENT,
$c->getMontant(),
$c->production->id_etablissement,
$c->id_user,
User::ID_USER_SYSTEM
);
}
}
}
}
}


} }

+ 1
- 0
common/models/Commande.php View File

return [ return [
[['id_user', 'date', 'id_point_vente', 'id_production'], 'required', 'message' => ''], [['id_user', 'date', 'id_point_vente', 'id_production'], 'required', 'message' => ''],
[['id_user', 'id_point_vente', 'id_production'], 'integer'], [['id_user', 'id_point_vente', 'id_production'], 'integer'],
[['paiement_automatique'], 'boolean'],
[['date', 'date_update', 'commentaire', 'commentaire_point_vente'], 'safe'] [['date', 'date_update', 'commentaire', 'commentaire_point_vente'], 'safe']
]; ];
} }

Loading…
Cancel
Save