Ajout d'une page affichant les commandes d'un utilisateur. Un bouton y menant a été ajouté au niveau de la liste des utilisateurs.master
@@ -16,6 +16,7 @@ use common\models\UserEtablissement ; | |||
use common\models\Etablissement ; | |||
use yii\base\UserException ; | |||
use common\models\CreditHistorique; | |||
use common\models\Commande; | |||
/** | |||
* UserController implements the CRUD actions for User model. | |||
@@ -42,7 +43,8 @@ class UserController extends BackendController | |||
$action->actionMethod == 'actionCreate' || | |||
$action->actionMethod == 'actionUpdate' || | |||
$action->actionMethod == 'actionCredit' || | |||
$action->actionMethod == 'actionMail') | |||
$action->actionMethod == 'actionMail' || | |||
$action->actionMethod == 'actionCommandes') | |||
{ | |||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER ; | |||
@@ -180,41 +182,7 @@ class UserController extends BackendController | |||
} | |||
} | |||
/** | |||
* Deletes an existing User model. | |||
* If deletion is successful, the browser will be redirected to the 'index' page. | |||
* @param integer $id | |||
* @return mixed | |||
*/ | |||
/*public function actionDelete($id) | |||
{ | |||
$this->findModel($id)->delete(); | |||
return $this->redirect(['index']); | |||
}*/ | |||
public function actionMail() { | |||
/*$model = new MailForm() ; | |||
$model->subject = '[Le Chat des Noisettes] ' ; | |||
$model->body = | |||
"Bonjour, | |||
PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compte sur www.lechatdesnoisettes.com." ; | |||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |||
$id_user = Yii::$app->request->post('id_user') ; | |||
$user = User::findIdentity($id_user) ; | |||
if($user) | |||
{ | |||
$model->sendEmail($user->email) ; | |||
} | |||
}*/ | |||
$users = (new \yii\db\Query()) | |||
->select('*') | |||
@@ -274,6 +242,30 @@ PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compt | |||
} | |||
} | |||
public function actionCommandes($id) | |||
{ | |||
$user = User::findOne($id) ; | |||
$commandes = Commande::find() | |||
->with('commandeProduits', 'pointVente', 'creditHistorique') | |||
->joinWith('production','production.etablissement') | |||
->where([ | |||
'id_user' => $id, | |||
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement | |||
]) | |||
->orderBy('production.date DESC') | |||
->all(); | |||
foreach ($commandes as $c) | |||
$c->init(); | |||
return $this->render('commandes', [ | |||
'commandes' => $commandes, | |||
'user' => $user | |||
]) ; | |||
} | |||
/** | |||
* Finds the User model based on its primary key value. | |||
* If the model is not found, a 404 HTTP exception will be thrown. |
@@ -0,0 +1,44 @@ | |||
<?php | |||
use yii\helpers\Html; | |||
use yii\widgets\ActiveForm; | |||
use common\models\CreditHistorique; | |||
use common\models\Etablissement; | |||
use common\models\Commande; | |||
$this->title = 'Commandes <small>'.Html::encode($user->nom.' '.$user->prenom).'</small>'; | |||
$this->params['breadcrumbs'][] = ['label' => 'Utilisateurs', 'url' => ['index']]; | |||
$this->params['breadcrumbs'][] = ['label' => Html::encode($user->nom.' '.$user->prenom)]; | |||
$this->params['breadcrumbs'][] = 'Créditer'; | |||
?> | |||
<div class="user-commandes"> | |||
<h1><?= $this->title ?> </h1> | |||
<?php if(count($commandes)): ?> | |||
<table id="historique-commandes" class="table table-striped table-bordered"> | |||
<thead> | |||
<tr> | |||
<th>Date livraison</th> | |||
<th>Résumé</th> | |||
<th>Point de vente</th> | |||
<th class="montant">Montant</th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<?php foreach($commandes as $c): ?> | |||
<tr> | |||
<td><?php echo date('d/m/Y',strtotime($c->production->date)); ?></td> | |||
<td class="resume"><?= $c->getResumePanier() ; ?></td> | |||
<td><?= $c->getResumePointVente(); ?></td> | |||
<td class="montant"><?= $c->getResumeMontant(); ?></td> | |||
</tr> | |||
<?php endforeach; ?> | |||
</tbody> | |||
</table> | |||
<?php else: ?> | |||
<div class="alert alert-warning">Aucune commande passée par cet utilisateur</div> | |||
<?php endif; ?> | |||
</div> |
@@ -3,6 +3,7 @@ | |||
use yii\helpers\Html; | |||
use yii\grid\GridView; | |||
use common\models\User ; | |||
use common\models\Commande ; | |||
/* @var $this yii\web\View */ | |||
/* @var $dataProvider yii\data\ActiveDataProvider */ | |||
@@ -58,6 +59,31 @@ $this->params['breadcrumbs'][] = $this->title; | |||
['class' => 'form-control'] | |||
) | |||
], | |||
[ | |||
'class' => 'yii\grid\ActionColumn', | |||
'template' => '{commandes}', | |||
'headerOptions' => ['class' => 'actions'], | |||
'buttons' => [ | |||
'commandes' => function ($url, $model) { | |||
$url = Yii::$app->urlManager->createUrl(['user/commandes','id' => $model['id']]) ; | |||
$count_commandes = Commande::find()->joinWith('production')->where(['id_user' => $model['id'], 'production.id_etablissement' => Yii::$app->user->identity->id_etablissement])->count() ; | |||
$html = '' ; | |||
if($count_commandes) | |||
{ | |||
$s = '' ; | |||
if($count_commandes > 1) $s = 's' ; | |||
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$count_commandes.' commande'.$s, $url, [ | |||
'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default ' | |||
]); ; | |||
} | |||
else { | |||
$html .= 'Aucune commande' ; | |||
} | |||
return $html ; | |||
}, | |||
], | |||
], | |||
[ | |||
'attribute' => 'credit', | |||
'format' => 'raw', |
@@ -262,4 +262,75 @@ class Commande extends \yii\db\ActiveRecord | |||
return self::STATUT_SURPLUS ; | |||
} | |||
} | |||
public function getResumePanier() | |||
{ | |||
if(!isset($this->commandeProduits)) | |||
$this->commandeProduits = CommandeProduit::find()->where(['id_commande' => $this->id])->all() ; | |||
$html = '' ; | |||
$count = count($this->commandeProduits); | |||
$i = 0; | |||
foreach($this->commandeProduits as $p) | |||
{ | |||
if(isset($p->produit)) | |||
{ | |||
$html .= $p->quantite.' x '.Html::encode($p->produit->nom) ; | |||
if(++$i != $count) $html .= '<br />' ; | |||
} | |||
} | |||
return $html ; | |||
} | |||
public function getResumePointVente() | |||
{ | |||
$html = '' ; | |||
if(isset($this->pointVente)) | |||
{ | |||
$html .= '<span class="nom-point-vente">'.Html::encode($this->pointVente->nom) .'</span>' | |||
. '<br /><span class="localite">'.Html::encode($this->pointVente->localite).'</span>' ; | |||
if(strlen($this->commentaire_point_vente)) | |||
{ | |||
$html .= '<div class="commentaire"><span>'.Html::encode($this->commentaire_point_vente).'</span></div>' ; | |||
} | |||
} | |||
else { | |||
$html .= 'Point de vente supprimé' ; | |||
} | |||
return $html ; | |||
} | |||
public function getResumeMontant() | |||
{ | |||
$html = '' ; | |||
$html .= number_format($this->montant,2).' €<br />' ; | |||
if($this->montant_paye) | |||
{ | |||
if($this->getStatutPaiement() == Commande::STATUT_PAYEE) | |||
{ | |||
$html .= '<span class="label label-success">Payée</span>' ; | |||
} | |||
elseif($this->getStatutPaiement() == Commande::STATUT_IMPAYEE) | |||
{ | |||
$html .= '<span class="label label-danger">Non payée</span><br /> | |||
Reste <strong>'.$this->getMontantRestant(true).'</strong> à payer' ; | |||
} | |||
elseif($this->getStatutPaiement() == Commande::STATUT_SURPLUS) | |||
{ | |||
$html .= '<span class="label label-success">Payée</span>' ; | |||
} | |||
} | |||
else { | |||
$html .= '<span class="label label-default">À régler sur place</span>' ; | |||
} | |||
return $html ; | |||
} | |||
} |
@@ -89,44 +89,9 @@ $this->title = 'Commande' ; | |||
<tr> | |||
<td><?= Html::encode($c->production->etablissement->nom) ?></td> | |||
<td><?php echo date('d/m/Y',strtotime($c->production->date)); ?></td> | |||
<td class="resume"><?php | |||
$count = count($c->commandeProduits); | |||
$i = 0; | |||
foreach($c->commandeProduits as $p): ?> | |||
<?php if(isset($p->produit)): ?> | |||
<?php if($p->produit->vrac): ?> | |||
<?php echo $p->quantite; ?>g de <?php echo Html::encode($p->produit->nom) ; ?><?php if(++$i != $count): ?>, <?php endif; ?> | |||
<?php else: ?> | |||
<?php echo $p->quantite; ?> x <?php echo Html::encode($p->produit->nom) ; ?><?php if(++$i != $count): ?>, <?php endif; ?> | |||
<?php endif; ?> | |||
<?php endif; ?> | |||
<?php endforeach; ?></td> | |||
<td> | |||
<?php if(isset($c->pointVente)): ?> | |||
<?php echo '<span class="nom-point-vente">'.Html::encode($c->pointVente->nom) .'</span>' | |||
. '<br /><span class="localite">'.Html::encode($c->pointVente->localite).'</span>' ; ?> | |||
<?php if(strlen($c->commentaire_point_vente)): ?> | |||
<div class="commentaire"><span><?= Html::encode($c->commentaire_point_vente) ?></span></div> | |||
<?php endif; ?> | |||
<?php else: ?> | |||
Point de vente supprimé | |||
<?php endif; ?> | |||
</td> | |||
<td class="montant"> | |||
<?php echo number_format($c->montant,2) ; ?> €<br /> | |||
<?php if($c->montant_paye): ?> | |||
<?php if($c->getStatutPaiement() == Commande::STATUT_PAYEE): ?> | |||
<span class="label label-success">Payée</span> | |||
<?php elseif($c->getStatutPaiement() == Commande::STATUT_IMPAYEE): ?> | |||
<span class="label label-danger">Non payée</span><br /> | |||
Reste <strong><?= $c->getMontantRestant(true); ?></strong> à payer | |||
<?php elseif($c->getStatutPaiement() == Commande::STATUT_SURPLUS): ?> | |||
<span class="label label-success">Payée</span> | |||
<?php endif; ?> | |||
<?php else: ?> | |||
<span class="label label-default">À régler sur place</span> | |||
<?php endif; ?> | |||
</td> | |||
<td class="resume"><?= $c->getResumePanier() ; ?></td> | |||
<td><?= $c->getResumePointVente(); ?></td> | |||
<td class="montant"><td class="montant"><?= $c->getResumeMontant(); ?></td></td> | |||
<td class="statut"> | |||
<?php | |||
if(date('H') > 20) { |