Переглянути джерело

Correction : modification et annulation de commande hors délai

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.
master
keun 7 роки тому
джерело
коміт
e9a76f40ca
4 змінених файлів з 69 додано та 24 видалено
  1. +10
    -0
      backend/views/etablissement/update.php
  2. +31
    -1
      common/models/Commande.php
  3. +12
    -0
      frontend/controllers/CommandeController.php
  4. +16
    -23
      frontend/views/commande/index.php

+ 10
- 0
backend/views/etablissement/update.php Переглянути файл

@@ -50,6 +50,16 @@ $this->params['breadcrumbs'][] = 'Paramètres';
20 => '20h',
19 => '19h',
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 />'
. '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.') ; ?>

+ 31
- 1
common/models/Commande.php Переглянути файл

@@ -4,6 +4,7 @@ namespace common\models;

use Yii;
use yii\helpers\Html ;
use common\models\Etablissement ;

/**
* This is the model class for table "commande".
@@ -32,7 +33,10 @@ class Commande extends \yii\db\ActiveRecord
const STATUT_IMPAYEE = 'impayee' ;
const STATUT_SURPLUS = 'surplus' ;
const ETAT_MODIFIABLE = 'ouverte' ;
const ETAT_PREPARATION = 'preparation' ;
const ETAT_LIVREE = 'livree' ;
/**
* @inheritdoc
*/
@@ -380,4 +384,30 @@ class Commande extends \yii\db\ActiveRecord
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 ;
}
}

+ 12
- 0
frontend/controllers/CommandeController.php Переглянути файл

@@ -18,6 +18,7 @@ use common\models\UserEtablissement;
use common\models\CreditHistorique ;
use yii\web\NotFoundHttpException ;
use common\models\ProductionPointVente ;
use yii\base\UserException ;

class CommandeController extends \yii\web\Controller {

@@ -286,6 +287,11 @@ class CommandeController extends \yii\web\Controller {
->where(['id' => $id])
->one();

if($commande->getEtat() != Commande::ETAT_MODIFIABLE)
{
throw new UserException('Cette commande n\'est pas modifiable.') ;
}
$this->_verifEtablissementActif($commande->production->id_etablissement) ;
if ($commande && $commande->load(Yii::$app->request->post()))
@@ -485,6 +491,12 @@ class CommandeController extends \yii\web\Controller {
->with('production','creditHistorique','commandeProduits')
->where(['id' => $id])
->one();
if($commande->getEtat() != Commande::ETAT_MODIFIABLE)
{
throw new UserException('Vous ne pouvez plus annuler cette commande.') ;
}
$commande->init() ;
if ($commande && Yii::$app->user->id == $commande->id_user) {
// remboursement

+ 16
- 23
frontend/views/commande/index.php Переглянути файл

@@ -93,29 +93,22 @@ $this->title = 'Commande' ;
<td><?= $c->getResumePointVente(); ?></td>
<td class="montant"><?= $c->getResumeMontant(); ?></td>
<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>
</tr>

Завантаження…
Відмінити
Зберегти