Ne pas pouvoir annuler ou modifier une commande hors délai de la même manière qu'on ne peut commander la veille pour le lendemain quand le délai démandé est de 2 jours. Ajout d'horaires supplémentaires pour l'heure limite.prodstable
20 => '20h', | 20 => '20h', | ||||
19 => '19h', | 19 => '19h', | ||||
18 => '18h', | 18 => '18h', | ||||
17 => '17h', | |||||
16 => '16h', | |||||
15 => '15h', | |||||
14 => '14h', | |||||
13 => '13h', | |||||
12 => '12h', | |||||
11 => '11h', | |||||
10 => '10h', | |||||
9 => '9h', | |||||
8 => '8h', | |||||
], []) | ], []) | ||||
->hint('Heure limite jusqu\'à laquelle les clients peuvent commander pour satisfaire le délai de commande.<br />' | ->hint('Heure limite jusqu\'à laquelle les clients peuvent commander pour satisfaire le délai de commande.<br />' | ||||
. 'Par exemple, si <strong>2 jours</strong> est sélectionné dans le délai de commande, le client devra commander l\'avant-veille de la production avant l\'heure précisée ici.') ; ?> | . 'Par exemple, si <strong>2 jours</strong> est sélectionné dans le délai de commande, le client devra commander l\'avant-veille de la production avant l\'heure précisée ici.') ; ?> |
use Yii; | use Yii; | ||||
use yii\helpers\Html ; | use yii\helpers\Html ; | ||||
use common\models\Etablissement ; | |||||
/** | /** | ||||
* This is the model class for table "commande". | * This is the model class for table "commande". | ||||
const STATUT_IMPAYEE = 'impayee' ; | const STATUT_IMPAYEE = 'impayee' ; | ||||
const STATUT_SURPLUS = 'surplus' ; | const STATUT_SURPLUS = 'surplus' ; | ||||
const ETAT_MODIFIABLE = 'ouverte' ; | |||||
const ETAT_PREPARATION = 'preparation' ; | |||||
const ETAT_LIVREE = 'livree' ; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
*/ | */ | ||||
return $commandes ; | return $commandes ; | ||||
} | } | ||||
public function getEtat() | |||||
{ | |||||
$delai_commande = Etablissement::getConfig('delai_commande') ; | |||||
$heure_limite = Etablissement::getConfig('heure_limite_commande') ; | |||||
$date_commande = strtotime($this->date) ; | |||||
$date_today = strtotime(date('Y-m-d')); | |||||
$heure_today = date('G') ; | |||||
$nb_jours = (int) (($date_commande - $date_today) / (24 * 60 * 60)) ; | |||||
if($nb_jours <= 0) | |||||
{ | |||||
return self::ETAT_LIVREE ; | |||||
} | |||||
elseif($nb_jours >= $delai_commande && | |||||
($nb_jours != $delai_commande || | |||||
($nb_jours == $delai_commande && $heure_today < $heure_limite))) | |||||
{ | |||||
return self::ETAT_MODIFIABLE ; | |||||
} | |||||
return self::ETAT_PREPARATION ; | |||||
} | |||||
} | } |
use common\models\CreditHistorique ; | use common\models\CreditHistorique ; | ||||
use yii\web\NotFoundHttpException ; | use yii\web\NotFoundHttpException ; | ||||
use common\models\ProductionPointVente ; | use common\models\ProductionPointVente ; | ||||
use yii\base\UserException ; | |||||
class CommandeController extends \yii\web\Controller { | class CommandeController extends \yii\web\Controller { | ||||
->where(['id' => $id]) | ->where(['id' => $id]) | ||||
->one(); | ->one(); | ||||
if($commande->getEtat() != Commande::ETAT_MODIFIABLE) | |||||
{ | |||||
throw new UserException('Cette commande n\'est pas modifiable.') ; | |||||
} | |||||
$this->_verifEtablissementActif($commande->production->id_etablissement) ; | $this->_verifEtablissementActif($commande->production->id_etablissement) ; | ||||
if ($commande && $commande->load(Yii::$app->request->post())) | if ($commande && $commande->load(Yii::$app->request->post())) | ||||
->with('production','creditHistorique','commandeProduits') | ->with('production','creditHistorique','commandeProduits') | ||||
->where(['id' => $id]) | ->where(['id' => $id]) | ||||
->one(); | ->one(); | ||||
if($commande->getEtat() != Commande::ETAT_MODIFIABLE) | |||||
{ | |||||
throw new UserException('Vous ne pouvez plus annuler cette commande.') ; | |||||
} | |||||
$commande->init() ; | $commande->init() ; | ||||
if ($commande && Yii::$app->user->id == $commande->id_user) { | if ($commande && Yii::$app->user->id == $commande->id_user) { | ||||
// remboursement | // remboursement |
<td><?= $c->getResumePointVente(); ?></td> | <td><?= $c->getResumePointVente(); ?></td> | ||||
<td class="montant"><?= $c->getResumeMontant(); ?></td> | <td class="montant"><?= $c->getResumeMontant(); ?></td> | ||||
<td class="statut"> | <td class="statut"> | ||||
<?php | |||||
if(date('H') > 20) { | |||||
$date_limite = date('Y-m-d',strtotime(date('Y-m-d')) + 60*60*24) ; | |||||
} | |||||
else { | |||||
$date_limite = date('Y-m-d') ; | |||||
} | |||||
?> | |||||
<?php if($c->production->date < date('Y-m-d') || ($c->production->date == date('Y-m-d') && date('H') > 13)): ?>Livrée | |||||
<?php elseif($c->production->date <= $date_limite): ?>En cours de préparation | |||||
<?php else: ?> | |||||
<div class="btn-group"> | |||||
<a href="<?php echo Yii::$app->urlManager->createUrl(['commande/update','id'=>$c->id, 'id_etablissement'=>$c->production->etablissement->id]) ; ?>" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a> | |||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> | |||||
<span class="caret"></span> | |||||
<span class="sr-only">Toggle Dropdown</span> | |||||
</button> | |||||
<ul class="dropdown-menu" role="menu"> | |||||
<li><a href="<?php echo Yii::$app->urlManager->createUrl(['commande/annuler','id'=>$c->id]) ; ?>"><span class="glyphicon glyphicon-trash"></span> Annuler la commande</a></li> | |||||
</ul> | |||||
</div> | |||||
<?php endif; ?> | |||||
<?php if($c->getEtat() == Commande::ETAT_LIVREE): ?> | |||||
Livrée | |||||
<?php elseif($c->getEtat() == Commande::ETAT_PREPARATION): ?> | |||||
En préparation | |||||
<?php elseif($c->getEtat() == Commande::ETAT_MODIFIABLE): ?> | |||||
<div class="btn-group"> | |||||
<a href="<?php echo Yii::$app->urlManager->createUrl(['commande/update','id'=>$c->id, 'id_etablissement'=>$c->production->etablissement->id]) ; ?>" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span> Modifier</a> | |||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> | |||||
<span class="caret"></span> | |||||
<span class="sr-only">Toggle Dropdown</span> | |||||
</button> | |||||
<ul class="dropdown-menu" role="menu"> | |||||
<li><a href="<?php echo Yii::$app->urlManager->createUrl(['commande/annuler','id'=>$c->id]) ; ?>"><span class="glyphicon glyphicon-trash"></span> Annuler la commande</a></li> | |||||
</ul> | |||||
</div> | |||||
<?php endif; ?> | |||||
</td> | </td> | ||||
</tr> | </tr> |