namespace backend\controllers; | namespace backend\controllers; | ||||
use common\models\User ; | |||||
/** | /** | ||||
* UserController implements the CRUD actions for User model. | * UserController implements the CRUD actions for User model. | ||||
*/ | */ | ||||
'allow' => true, | 'allow' => true, | ||||
'roles' => ['@'], | 'roles' => ['@'], | ||||
'matchCallback' => function ($rule, $action) { | 'matchCallback' => function ($rule, $action) { | ||||
return Yii::$app->user->identity->status == USER::STATUS_ADMIN | |||||
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER; | |||||
return User::hasAccessBackend(); | |||||
} | } | ||||
] | ] | ||||
], | ], | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionIndex( | public function actionIndex( | ||||
$id_point_vente = 0, $section_clients_inactifs = false) | |||||
$idPointSale = 0, $sectionInactiveUsers = false) | |||||
{ | { | ||||
$params = Yii::$app->request->queryParams; | $params = Yii::$app->request->queryParams; | ||||
if($id_point_vente) | |||||
$params['id_point_vente'] = $id_point_vente ; | |||||
if($section_clients_inactifs) | |||||
$params['inactifs'] = true ; | |||||
if($idPointSale) { | |||||
$params['id_point_sale'] = $idPointSale ; | |||||
} | |||||
if($sectionInactiveUsers) { | |||||
$params['inactive'] = true ; | |||||
} | |||||
$query = User::findBy($params); | $query = User::findBy($params); | ||||
$dataProvider = new ActiveDataProvider([ | $dataProvider = new ActiveDataProvider([ | ||||
'query' => $query, | 'query' => $query, | ||||
'sort' => ['attributes' => ['nom','prenom']], | |||||
'sort' => ['attributes' => ['lastname','name']], | |||||
]); | ]); | ||||
$etablissement = Etablissement::find() | |||||
->where(['id' => Yii::$app->user->identity->id_etablissement]) | |||||
->one(); | |||||
$producer = Producer::searchOne([ | |||||
'id' => Producer::getId() | |||||
]) ; | |||||
$points_vente = PointVente::find()->where(['id_etablissement' => $etablissement->id])->all() ; | |||||
$pointsSaleArray = PointSale::searchAll() ; | |||||
return $this->render('index', [ | return $this->render('index', [ | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'etablissement' => $etablissement, | |||||
'id_point_vente_active' => $id_point_vente, | |||||
'points_vente' => $points_vente, | |||||
'section_clients_inactifs' => $section_clients_inactifs, | |||||
'producer' => $producer, | |||||
'idPointSaleActive' => $idPointSale, | |||||
'pointsSaleArray' => $pointsSaleArray, | |||||
'sectionInactiveUsers' => $sectionInactiveUsers, | |||||
]); | ]); | ||||
} | } | ||||
$model->setPassword($password); | $model->setPassword($password); | ||||
$model->generateAuthKey(); | $model->generateAuthKey(); | ||||
$model->username = $model->email; | $model->username = $model->email; | ||||
$model->confiance = 1; | |||||
if (!strlen($model->email)) | |||||
if (!strlen($model->email)) { | |||||
$model->username = 'inconnu@laboiteapain.net'; | $model->username = 'inconnu@laboiteapain.net'; | ||||
} | |||||
$model->save(); | $model->save(); | ||||
// liaison etablissement / user | // liaison etablissement / user | ||||
$user_etablissement = new UserEtablissement(); | |||||
$user_etablissement->id_user = $model->id; | |||||
$user_etablissement->id_etablissement = Yii::$app->user->identity->id_etablissement; | |||||
$user_etablissement->credit = 0; | |||||
$user_etablissement->actif = 1; | |||||
$user_etablissement->save(); | |||||
$useProducer = new UserProducer(); | |||||
$useProducer->id_user = $model->id; | |||||
$useProducer->id_producer = Producer::getId(); | |||||
$useProducer->credit = 0; | |||||
$useProducer->active = 1; | |||||
$useProducer->save(); | |||||
$model->sendMailWelcome($password) ; | $model->sendMailWelcome($password) ; | ||||
{ | { | ||||
$model = $this->findModel($id); | $model = $this->findModel($id); | ||||
$previous_mail = $model->email ; | |||||
$previousMail = $model->email ; | |||||
$user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one(); | |||||
$user_appartient_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); | |||||
if (($user_appartient_etablissement && count($user->userEtablissement) == 1) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||||
$user = User::find()->with('userProducer')->where(['id' => $model['id']])->one(); | |||||
$userBelongToProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => Producer::getId()]); | |||||
if (($userBelongToProducer && count($user->userProducer) == 1) || User::getStatus() == USER::STATUS_ADMIN) { | |||||
if ($model->load(Yii::$app->request->post()) && $model->save()) { | if ($model->load(Yii::$app->request->post()) && $model->save()) { | ||||
// on envoie le mail de bienvenue si le mail vient d'être défini | // on envoie le mail de bienvenue si le mail vient d'être défini | ||||
if(!strlen($previous_mail) && strlen($model->email)) { | |||||
if(!strlen($previousMail) && strlen($model->email)) { | |||||
$password = Password::generate(); | $password = Password::generate(); | ||||
$model->setPassword($password); | $model->setPassword($password); | ||||
$model->username = $model->email; | $model->username = $model->email; | ||||
*/ | */ | ||||
public function actionDelete($id) | public function actionDelete($id) | ||||
{ | { | ||||
$user_etablissement = UserEtablissement::findOne([ | |||||
$userProducer = UserProducer::findOne([ | |||||
'id_user' => $id, | 'id_user' => $id, | ||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement | |||||
'id_producer' => Producer::getId() | |||||
]) ; | ]) ; | ||||
if($user_etablissement) { | |||||
$user_etablissement->actif = 0 ; | |||||
$user_etablissement->favoris = 0 ; | |||||
$user_etablissement->save() ; | |||||
if($userProducer) { | |||||
$userProducer->active = 0 ; | |||||
$userProducer->bookmark = 0 ; | |||||
$userProducer->save() ; | |||||
} | } | ||||
else { | else { | ||||
throw new \yii\web\NotFoundHttpException('L\'enregistrement UserEtablissement est introuvable', 404) ; | throw new \yii\web\NotFoundHttpException('L\'enregistrement UserEtablissement est introuvable', 404) ; | ||||
* Affiche la liste des emails des utilisateurs liés à un point de vente | * Affiche la liste des emails des utilisateurs liés à un point de vente | ||||
* donné. | * donné. | ||||
* | * | ||||
* @param integer $id_point_vente | |||||
* @param integer $idPointSale | |||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionMail($id_point_vente = 0) | |||||
public function actionMail($idPointSale = 0) | |||||
{ | { | ||||
$users = User::findBy([ | $users = User::findBy([ | ||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement, | |||||
'id_point_vente' => $id_point_vente | |||||
'id_producer' => Producer::getId(), | |||||
'id_point_sale' => $idPointSale | |||||
])->all() ; | ])->all() ; | ||||
$arr_users = []; | |||||
foreach ($users as $u) { | |||||
if (isset($u['email']) && strlen($u['email'])) | |||||
$arr_users[] = $u['email']; | |||||
$usersArray = []; | |||||
foreach ($usersArray as $user) { | |||||
if (isset($user['email']) && strlen($user['email'])) | |||||
$usersArray[] = $user['email']; | |||||
} | } | ||||
$points_vente = PointVente::find()->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])->all() ; | |||||
$pointsSaleArray = PointSale::find()->where(['id_producer' => Producer::getId()])->all() ; | |||||
$point_vente = null ; | |||||
if($id_point_vente) { | |||||
$point_vente = PointVente::findOne(['id' => $id_point_vente, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]) ; | |||||
$pointSale = null ; | |||||
if($idPointSale) { | |||||
$pointSale = PointSale::findOne(['id' => $idPointSale, 'id_producer' => Producer::getId()]) ; | |||||
} | } | ||||
return $this->render('liste_mails', [ | |||||
'users' => $arr_users, | |||||
'points_vente' => $points_vente, | |||||
'point_vente' => $point_vente | |||||
return $this->render('emails', [ | |||||
'usersArray' => $usersArray, | |||||
'pointsSaleArray' => $pointsSaleArray, | |||||
'pointSale' => $pointSale | |||||
]); | ]); | ||||
} | } | ||||
*/ | */ | ||||
public function actionCredit($id) | public function actionCredit($id) | ||||
{ | { | ||||
$user = User::find()->with('userEtablissement')->where(['id' => $id])->one(); | |||||
$user_etablissement = UserEtablissement::findOne(['id_user' => $id, 'id_etablissement' => Yii::$app->user->identity->id_etablissement]); | |||||
$user = User::find()->with('userProducer')->where(['id' => $id])->one(); | |||||
$userProducer = UserProducer::findOne(['id_user' => $id, 'id_producer' => Producer::getId()]); | |||||
if (($user_etablissement) || Yii::$app->user->identity->status == USER::STATUS_ADMIN) { | |||||
if (($userProducer) || User::getStatus() == User::STATUS_ADMIN) { | |||||
$credit_form = new CreditForm; | |||||
if ($credit_form->load(Yii::$app->request->post()) && $credit_form->validate()) { | |||||
$credit_form->id_user = $id ; | |||||
$credit_form->save(); | |||||
$credit_form = new CreditForm; | |||||
$creditForm = new CreditForm; | |||||
if ($creditForm->load(Yii::$app->request->post()) && $creditForm->validate()) { | |||||
$creditForm->id_user = $id ; | |||||
$creditForm->save(); | |||||
$creditForm = new CreditForm; | |||||
} | } | ||||
$historique = CreditHistorique::find() | |||||
->with(['commande', 'userAction']) | |||||
$history = CreditHistory::find() | |||||
->with(['order', 'userAction']) | |||||
->where([ | ->where([ | ||||
'id_user' => $user->id, | 'id_user' => $user->id, | ||||
'id_etablissement' => Yii::$app->user->identity->id_etablissement, | |||||
'id_producer' => Producer::getId(), | |||||
]) | ]) | ||||
->orderBy('date DESC') | ->orderBy('date DESC') | ||||
->all(); | ->all(); | ||||
return $this->render('credit', [ | return $this->render('credit', [ | ||||
'user' => $user, | 'user' => $user, | ||||
'credit_form' => $credit_form, | |||||
'historique' => $historique | |||||
'creditForm' => $creditForm, | |||||
'history' => $history | |||||
]); | ]); | ||||
} | } | ||||
else { | else { | ||||
* @param integer $id | * @param integer $id | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function actionCommandes($id) | |||||
public function actionOrders($id) | |||||
{ | { | ||||
$user = User::findOne($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(); | |||||
$orders = Order::searchAll([ | |||||
'id_user' => $id | |||||
], ['orderby' => 'distribution.date DESC']) ; | |||||
return $this->render('commandes', [ | return $this->render('commandes', [ | ||||
'commandes' => $commandes, | |||||
'ordersArray' => $ordersArray, | |||||
'user' => $user | 'user' => $user | ||||
]); | ]); | ||||
} | } |
<?php $form = ActiveForm::begin(); ?> | <?php $form = ActiveForm::begin(); ?> | ||||
<?= $form->field($model, 'nom')->textInput() ?> | |||||
<?= $form->field($model, 'prenom')->textInput() ?> | |||||
<?= $form->field($model, 'telephone')->textInput() ?> | |||||
<?= $form->field($model, 'lastname')->textInput() ?> | |||||
<?= $form->field($model, 'name')->textInput() ?> | |||||
<?= $form->field($model, 'phone')->textInput() ?> | |||||
<?= $form->field($model, 'email')->textInput() ?> | <?= $form->field($model, 'email')->textInput() ?> | ||||
<?= $form->field($model, 'adresse')->textarea() ?> | |||||
<?= $form->field($model, 'address')->textarea() ?> | |||||
<div class="form-group"> | <div class="form-group"> | ||||
<?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> |
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use common\models\CreditHistorique; | |||||
use common\models\Etablissement; | |||||
use common\models\CreditHistory; | |||||
use common\models\Producer; | |||||
$this->title = 'Créditer <small>'.Html::encode($user->nom.' '.$user->prenom).'</small>'; | |||||
$this->title = 'Créditer <small>'.Html::encode($user->lastname.' '.$user->name).'</small>'; | |||||
$this->params['breadcrumbs'][] = ['label' => 'Clients', 'url' => ['index']]; | $this->params['breadcrumbs'][] = ['label' => 'Clients', 'url' => ['index']]; | ||||
$this->params['breadcrumbs'][] = ['label' => Html::encode($user->nom.' '.$user->prenom)]; | |||||
$this->params['breadcrumbs'][] = ['label' => Html::encode($user->lastname.' '.$user->name)]; | |||||
$this->params['breadcrumbs'][] = 'Créditer'; | $this->params['breadcrumbs'][] = 'Créditer'; | ||||
?> | ?> | ||||
<div class="user-credit"> | <div class="user-credit"> | ||||
<?php | <?php | ||||
$etablissement = Etablissement::find() | |||||
->where(['id' => Yii::$app->user->identity->id_etablissement]) | |||||
->one() ; | |||||
if(!$etablissement->credit_pain) | |||||
$producer = Producer::searchOne([ | |||||
'id' => Producer::getId() | |||||
]); | |||||
if(!$producer->credit) | |||||
{ | { | ||||
echo '<div class="alert alert-warning">Attention, la fonctionnalité <strong>Crédit Pain</strong> est désactivée dans vos <a href="'.Yii::$app->urlManager->createurl(['etablissement/update']).'">paramètres</a>.' | |||||
echo '<div class="alert alert-warning">Attention, la fonctionnalité <strong>Crédit</strong> est désactivée dans vos <a href="'.Yii::$app->urlManager->createurl(['producer/update']).'">paramètres</a>.' | |||||
. ' Pensez à l\'activer si vous souhaitez qu\'elle soit visible de vos clients.</div>' ; | . ' Pensez à l\'activer si vous souhaitez qu\'elle soit visible de vos clients.</div>' ; | ||||
} | } | ||||
?> | ?> | ||||
<div class="col-md-12"> | <div class="col-md-12"> | ||||
<h1><?= $this->title ?></h1> | <h1><?= $this->title ?></h1> | ||||
<?php $form = ActiveForm::begin(); ?> | <?php $form = ActiveForm::begin(); ?> | ||||
<?= $form->field($credit_form, 'type')->dropDownList([ | |||||
CreditHistorique::TYPE_CREDIT => 'Crédit', | |||||
CreditHistorique::TYPE_DEBIT => 'Débit', | |||||
<?= $form->field($creditForm, 'type')->dropDownList([ | |||||
CreditHistory::TYPE_CREDIT => 'Crédit', | |||||
CreditHistory::TYPE_DEBIT => 'Débit', | |||||
]) ?> | ]) ?> | ||||
<?= $form->field($credit_form, 'montant')->textInput() ?> | |||||
<?= $form->field($credit_form, 'moyen_paiement')->dropDownList([ | |||||
CreditHistorique::MOYEN_ESPECES => 'Espèces', | |||||
CreditHistorique::MOYEN_CB => 'Carte bancaire', | |||||
CreditHistorique::MOYEN_CHEQUE => 'Chèque', | |||||
CreditHistorique::MOYEN_AUTRE => 'Autre', | |||||
<?= $form->field($creditForm, 'amount')->textInput() ?> | |||||
<?= $form->field($creditForm, 'mean_payment')->dropDownList([ | |||||
CreditHistory::MEAN_PAYMENT_MONEYS => CreditHistory::getStrMeanPaymentBy(CreditHistory::MEAN_PAYMENT_MONEYS), | |||||
CreditHistory::MOYEN_CB => CreditHistory::getStrMeanPaymentBy(CreditHistory::MOYEN_CB), | |||||
CreditHistory::MOYEN_CHEQUE => CreditHistory::getStrMeanPaymentBy(CreditHistory::MOYEN_CHEQUE), | |||||
CreditHistory::MOYEN_AUTRE => CreditHistory::getStrMeanPaymentBy(CreditHistory::MOYEN_AUTRE), | |||||
]) ?> | ]) ?> | ||||
<?= $form->field($credit_form, 'commentaire')->textarea() ?> | |||||
<?= $form->field($credit_form, 'send_mail')->checkbox() ?> | |||||
<?= $form->field($creditForm, 'comment')->textarea() ?> | |||||
<?= $form->field($creditForm, 'sendMail')->checkbox() ?> | |||||
<div class="form-group"> | <div class="form-group"> | ||||
<?= Html::submitButton( 'Créditer', ['class' => 'btn btn-primary']) ?> | <?= Html::submitButton( 'Créditer', ['class' => 'btn btn-primary']) ?> | ||||
</div> | </div> | ||||
<div class="col-md-12"> | <div class="col-md-12"> | ||||
<h2>Historique <span class="the-credit"><?= number_format($user->getCredit($etablissement->id), 2); ?> €</span></h2> | |||||
<h2>Historique <span class="the-credit"><?= number_format($user->getCredit($producer->id), 2); ?> €</span></h2> | |||||
<table class="table table-bordered"> | <table class="table table-bordered"> | ||||
<thead> | <thead> | ||||
<tr> | <tr> | ||||
</tr> | </tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
<?php if(count($historique)): ?> | |||||
<?php foreach($historique as $ch): ?> | |||||
<?php if(count($history)): ?> | |||||
<?php foreach($history as $creditHistory): ?> | |||||
<tr> | <tr> | ||||
<td><?= $ch->getDate(true) ; ?></td> | |||||
<td><?= Html::encode($ch->strUserAction()); ?></td> | |||||
<td><?= $ch->getStrLibelle(); ?></td> | |||||
<td><?= $creditHistory->getDate(true) ; ?></td> | |||||
<td><?= Html::encode($creditHistory->strUserAction()); ?></td> | |||||
<td><?= $creditHistory->getStrWording(); ?></td> | |||||
<td> | <td> | ||||
<?php if($ch->isTypeDebit()): ?> | |||||
- <?= $ch->getMontant(true); ?> | |||||
<?php if($creditHistory->isTypeDebit()): ?> | |||||
- <?= $creditHistory->getAmount(true); ?> | |||||
<?php endif; ?> | <?php endif; ?> | ||||
</td> | </td> | ||||
<td> | <td> | ||||
<?php if($ch->isTypeCredit()): ?> | |||||
+ <?= $ch->getMontant(true); ?> | |||||
<?php if($creditHistory->isTypeCredit()): ?> | |||||
+ <?= $creditHistory->getAmount(true); ?> | |||||
<?php endif; ?> | <?php endif; ?> | ||||
</td> | </td> | ||||
<td> | <td> | ||||
<?= $ch->getStrMoyenPaiement() ?> | |||||
<?= $creditHistory->getStrMeanPayment() ?> | |||||
</td> | </td> | ||||
<td> | <td> | ||||
<?php if(strlen($ch->commentaire)): ?> | |||||
<?= nl2br($ch->commentaire) ; ?> | |||||
<?php if(strlen($creditHistory->comment)): ?> | |||||
<?= nl2br($creditHistory->comment) ; ?> | |||||
<?php endif; ?> | <?php endif; ?> | ||||
</td> | </td> | ||||
</tr> | </tr> |
use yii\helpers\Html ; | use yii\helpers\Html ; | ||||
$this->title = 'Liste des emails'; | $this->title = 'Liste des emails'; | ||||
$this->params['breadcrumbs'][] = ['label' => 'Clients', | |||||
$this->params['breadcrumbs'][] = ['label' => 'Utilisateurs', | |||||
'url' => ['user/index']] ; | 'url' => ['user/index']] ; | ||||
$this->params['breadcrumbs'][] = $this->title; | $this->params['breadcrumbs'][] = $this->title; | ||||
?> | ?> | ||||
<h1><?php if(isset($point_vente) && $point_vente): echo Html::encode($point_vente->nom).' : '; endif; ?><?= count($users); ?> clients</h1> | |||||
<h1><?php if(isset($pointSale) && $pointSale): echo Html::encode($pointSale->name).' : '; endif; ?><?= count($usersArray); ?> utilisateurs</h1> | |||||
<ul id="tabs-points-vente" class="nav nav-tabs" role="tablist"> | |||||
<li class="<?php if(!isset($point_vente)): ?>active<?php endif; ?>"> | |||||
<ul id="tabs-points-sale" class="nav nav-tabs" role="tablist"> | |||||
<li class="<?php if(!isset($pointSale)): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail']); ?>">Tous</a> | <a href="<?= Yii::$app->urlManager->createUrl(['user/mail']); ?>">Tous</a> | ||||
</li> | </li> | ||||
<?php foreach($points_vente as $pv): ?> | |||||
<li class="<?php if(isset($point_vente) && $point_vente->id == $pv->id): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail','id_point_vente'=>$pv->id]); ?>"><?= Html::encode($pv->nom) ?></a> | |||||
<?php foreach($pointsSaleArray as $pointSale): ?> | |||||
<li class="<?php if(isset($pointSale) && $pointSale->id == $pointSale->id): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/mail','idPointSale'=>$pointSale->id]); ?>"><?= Html::encode($pointSale->name) ?></a> | |||||
</li> | </li> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
</ul> | </ul> | ||||
<?= implode(', ', $users); ?> | |||||
<?= implode(', ', $usersArray); ?> | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\grid\GridView; | use yii\grid\GridView; | ||||
use common\models\User ; | use common\models\User ; | ||||
use common\models\Commande ; | |||||
use common\models\Order ; | |||||
/* @var $this yii\web\View */ | /* @var $this yii\web\View */ | ||||
/* @var $dataProvider yii\data\ActiveDataProvider */ | /* @var $dataProvider yii\data\ActiveDataProvider */ | ||||
$this->title = 'Clients'; | |||||
$this->title = 'Utilisateurs'; | |||||
$this->params['breadcrumbs'][] = $this->title; | $this->params['breadcrumbs'][] = $this->title; | ||||
?> | ?> | ||||
</h1> | </h1> | ||||
<ul id="tabs-points-vente" class="nav nav-tabs" role="tablist"> | <ul id="tabs-points-vente" class="nav nav-tabs" role="tablist"> | ||||
<li class="<?php if(!$id_point_vente_active && !$section_clients_inactifs): ?>active<?php endif; ?>"> | |||||
<li class="<?php if(!$idPointSaleActive && !$sectionInactiveUsers): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/index']); ?>">Tous</a> | <a href="<?= Yii::$app->urlManager->createUrl(['user/index']); ?>">Tous</a> | ||||
</li> | </li> | ||||
<?php foreach($points_vente as $pv): ?> | |||||
<li class="<?php if($id_point_vente_active == $pv->id): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','id_point_vente'=>$pv->id]); ?>"><?= Html::encode($pv->nom) ?></a> | |||||
<?php foreach($pointsSaleArray as $pointSale): ?> | |||||
<li class="<?php if($idPointSaleActive == $pointSale->id): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','idPointSale' => $pointSale->id]); ?>"><?= Html::encode($pointSale->name) ?></a> | |||||
</li> | </li> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
<li class="<?php if($section_clients_inactifs): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','section_clients_inactifs' => 1]); ?>">Inactifs</a> | |||||
<li class="<?php if($sectionInactiveUsers): ?>active<?php endif; ?>"> | |||||
<a href="<?= Yii::$app->urlManager->createUrl(['user/index','sectionInactiveUsers' => 1]); ?>">Inactifs</a> | |||||
</li> | </li> | ||||
</ul> | </ul> | ||||
<?= Html::a('<span class="glyphicon glyphicon-envelope"></span> Liste des emails', ['mail', 'id_point_vente' => $id_point_vente_active], ['class' => 'btn btn-default btn-liste-emails']) ?> | |||||
<?= Html::a('<span class="glyphicon glyphicon-envelope"></span> Liste des emails', ['mail', 'idPointSale' => $idPointSaleActive], ['class' => 'btn btn-default btn-liste-emails']) ?> | |||||
<?= GridView::widget([ | <?= GridView::widget([ | ||||
'dataProvider' => $dataProvider, | 'dataProvider' => $dataProvider, | ||||
'filterModel' => true, | 'filterModel' => true, | ||||
'columns' => [ | 'columns' => [ | ||||
[ | [ | ||||
'attribute' => 'nom', | |||||
'attribute' => 'lastname', | |||||
'filter' => Html::input( | 'filter' => Html::input( | ||||
'string', | 'string', | ||||
'nom', | |||||
isset(Yii::$app->request->queryParams['nom']) ? Html::encode(Yii::$app->request->queryParams['nom']) : '', | |||||
'lastname', | |||||
isset(Yii::$app->request->queryParams['lastname']) ? Html::encode(Yii::$app->request->queryParams['lastname']) : '', | |||||
[ 'class' => 'form-control'] | [ 'class' => 'form-control'] | ||||
) | ) | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'prenom', | |||||
'attribute' => 'name', | |||||
'filter' => Html::input( | 'filter' => Html::input( | ||||
'string', | 'string', | ||||
'prenom', | |||||
isset(Yii::$app->request->queryParams['prenom']) ? Html::encode(Yii::$app->request->queryParams['prenom']) : '', | |||||
'name', | |||||
isset(Yii::$app->request->queryParams['name']) ? Html::encode(Yii::$app->request->queryParams['name']) : '', | |||||
['class' => 'form-control'] | ['class' => 'form-control'] | ||||
) | ) | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'telephone', | |||||
'attribute' => 'phone', | |||||
'filter' => Html::input( | 'filter' => Html::input( | ||||
'string', | 'string', | ||||
'telephone', | |||||
isset(Yii::$app->request->queryParams['telephone']) ? Html::encode(Yii::$app->request->queryParams['telephone']) : '', | |||||
'phone', | |||||
isset(Yii::$app->request->queryParams['phone']) ? Html::encode(Yii::$app->request->queryParams['phone']) : '', | |||||
['class' => 'form-control'] | ['class' => 'form-control'] | ||||
) | ) | ||||
], | ], | ||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'date_derniere_connexion', | |||||
'attribute' => 'date_last_connection', | |||||
'label' => 'Dernière connexion', | 'label' => 'Dernière connexion', | ||||
'value' => function($model) { | 'value' => function($model) { | ||||
if(isset($model['date_derniere_connexion'])) | |||||
return date('d/m/Y à H:i', strtotime($model['date_derniere_connexion'])); | |||||
if(isset($model['date_last_connection'])) | |||||
return date('d/m/Y à H:i', strtotime($model['date_last_connection'])); | |||||
else | else | ||||
return '' ; | return '' ; | ||||
} | } | ||||
], | ], | ||||
[ | [ | ||||
'class' => 'yii\grid\ActionColumn', | 'class' => 'yii\grid\ActionColumn', | ||||
'template' => '{commandes}', | |||||
'template' => '{orders}', | |||||
'headerOptions' => ['class' => 'actions'], | 'headerOptions' => ['class' => 'actions'], | ||||
'buttons' => [ | 'buttons' => [ | ||||
'commandes' => function ($url, $model) { | |||||
$url = Yii::$app->urlManager->createUrl(['user/commandes','id' => $model['user_id']]) ; | |||||
$count_commandes = Commande::find() | |||||
->joinWith('production') | |||||
->where([ | |||||
'id_user' => $model['user_id'], | |||||
'production.id_etablissement' => Yii::$app->user->identity->id_etablissement]) | |||||
->andWhere('date_delete IS NULL') | |||||
->count() ; | |||||
'orders' => function ($url, $model) { | |||||
$url = Yii::$app->urlManager->createUrl(['user/orders','id' => $model['user_id']]) ; | |||||
$countOrders = Order::searchCount([ | |||||
'id_user' => $model['user_id'] | |||||
], ['conditions' => 'date_delete IS NULL']) ; | |||||
$html = '' ; | $html = '' ; | ||||
if($count_commandes) | |||||
{ | |||||
if($countOrders) { | |||||
$s = '' ; | $s = '' ; | ||||
if($count_commandes > 1) $s = 's' ; | |||||
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$count_commandes.' commande'.$s, $url, [ | |||||
if($countOrders > 1) $s = 's' ; | |||||
$html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$countOrders.' commande'.$s, $url, [ | |||||
'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default ' | 'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default ' | ||||
]); ; | ]); ; | ||||
} | } | ||||
[ | [ | ||||
'attribute' => 'credit', | 'attribute' => 'credit', | ||||
'format' => 'raw', | 'format' => 'raw', | ||||
'value' => function($model) use($etablissement) { | |||||
'value' => function($model) use($producer) { | |||||
if(!isset($model['credit'])) $model['credit'] = 0 ; | if(!isset($model['credit'])) $model['credit'] = 0 ; | ||||
$user = User::findOne($model['user_id']) ; | $user = User::findOne($model['user_id']) ; | ||||
$html = '<div class="input-group"> | $html = '<div class="input-group"> | ||||
<input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($user->getCredit($etablissement->id),2).' €" placeholder=""> | |||||
<input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($user->getCredit($producer->id),2).' €" placeholder=""> | |||||
<span class="input-group-btn"> | <span class="input-group-btn"> | ||||
'.Html::a( | '.Html::a( | ||||
'<span class="glyphicon glyphicon-euro"></span> Crédit', | '<span class="glyphicon glyphicon-euro"></span> Crédit', | ||||
'buttons' => [ | 'buttons' => [ | ||||
'update' => function ($url, $model) { | 'update' => function ($url, $model) { | ||||
$url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['user_id']]) ; | $url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['user_id']]) ; | ||||
$user = User::find()->with('userEtablissement')->where(['id' => $model['user_id']])->one() ; | |||||
if(count($user->userEtablissement) <= 1) | |||||
$user = User::find()->with('userProducer')->where(['id' => $model['user_id']])->one() ; | |||||
if(count($user->userProducer) <= 1) | |||||
{ | { | ||||
return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [ | return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [ | ||||
'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default' | ||||
} | } | ||||
}, | }, | ||||
'delete' => function($url, $model) { | 'delete' => function($url, $model) { | ||||
if($model['actif']) { | |||||
if($model['active']) { | |||||
return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(array_merge(['user/delete','id' => $model['user_id']], Yii::$app->getRequest()->getQueryParams())), [ | return Html::a('<span class="glyphicon glyphicon-trash"></span> Supprimer', Yii::$app->urlManager->createUrl(array_merge(['user/delete','id' => $model['user_id']], Yii::$app->getRequest()->getQueryParams())), [ | ||||
'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default' | 'title' => Yii::t('app', 'Supprimer'), 'class' => 'btn btn-default' | ||||
]); | ]); |
<?php | |||||
/** | |||||
Copyright La boîte à pain (2018) | |||||
contact@laboiteapain.net | |||||
Ce logiciel est un programme informatique servant à aider les producteurs | |||||
à distribuer leur production en circuits courts. | |||||
Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
sur le site "http://www.cecill.info". | |||||
En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
de modification et de redistribution accordés par cette licence, il n'est | |||||
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
titulaire des droits patrimoniaux et les concédants successifs. | |||||
A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
associés au chargement, à l'utilisation, à la modification et/ou au | |||||
développement et à la reproduction du logiciel par l'utilisateur étant | |||||
donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
avertis possédant des connaissances informatiques approfondies. Les | |||||
utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
termes. | |||||
*/ | |||||
use yii\helpers\Html; | |||||
use yii\bootstrap\ActiveForm; | |||||
/* | |||||
* To change this license header, choose License Headers in Project Properties. | |||||
* To change this template file, choose Tools | Templates | |||||
* and open the template in the editor. | |||||
*/ | |||||
$this->title = 'Envoi d\'un email à tous les utilisateurs'; | |||||
?> | |||||
<h1><?= Html::encode($this->title) ?></h1> | |||||
<?php | |||||
$form = ActiveForm::begin(['id' => 'email-masse-form','enableClientValidation' => false]); ?> | |||||
<?= $form->field($model, 'subject') ?> | |||||
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?> | |||||
<div class="form-group"> | |||||
<label class="control-label">Envoyer à</label> | |||||
<p>Cliquer sur les utilisateurs pour modifier leur état.<br /> | |||||
Légende : <span class="label label-default">à envoyer</span> <span class="label label-danger">ne pas envoyer</span> <span class="label label-success">envoyé</span></p> | |||||
<div id="ids-users"> | |||||
<?php foreach($users as $u): ?> | |||||
<a href="javascript:void(0);" class="label <?php if($u->no_mail): ?>label-danger<?php else: ?>label-default<?php endif; ?>" data-send="0" data-id="<?php echo $u->id; ?>"><?php echo Html::encode($u->prenom.' '.$u->nom); ?></a> | |||||
<?php endforeach; ?> | |||||
</div> | |||||
<input name="id_user" type="hidden" value="" /> | |||||
</div> | |||||
<br /> | |||||
<div class="form-group"> | |||||
<?= Html::submitButton('Envoyer', ['class' => 'btn btn-default', 'name' => 'email-masse-button']) ?> | |||||
</div> | |||||
<?php ActiveForm::end(); ?> | |||||
use yii\helpers\Html; | use yii\helpers\Html; | ||||
use yii\widgets\ActiveForm; | use yii\widgets\ActiveForm; | ||||
use common\models\CreditHistorique; | |||||
use common\models\Etablissement; | |||||
use common\models\Commande; | |||||
use common\models\CreditHistory; | |||||
use common\models\Producer; | |||||
use common\models\Order; | |||||
$this->title = 'Commandes <small>'.Html::encode($user->nom.' '.$user->prenom).'</small>'; | |||||
$this->title = 'Commandes <small>'.Html::encode($user->lastname.' '.$user->name).'</small>'; | |||||
$this->params['breadcrumbs'][] = ['label' => 'Clients', 'url' => ['index']]; | $this->params['breadcrumbs'][] = ['label' => 'Clients', 'url' => ['index']]; | ||||
$this->params['breadcrumbs'][] = ['label' => Html::encode($user->nom.' '.$user->prenom)]; | |||||
$this->params['breadcrumbs'][] = ['label' => Html::encode($user->lastname.' '.$user->name)]; | |||||
$this->params['breadcrumbs'][] = 'Créditer'; | $this->params['breadcrumbs'][] = 'Créditer'; | ||||
?> | ?> | ||||
<div class="user-commandes"> | |||||
<div class="user-orders"> | |||||
<h1><?= $this->title ?> </h1> | <h1><?= $this->title ?> </h1> | ||||
$this->title = 'Modifier un client' ; | $this->title = 'Modifier un client' ; | ||||
$this->params['breadcrumbs'][] = ['label' => 'Clients', 'url' => ['index']]; | $this->params['breadcrumbs'][] = ['label' => 'Clients', 'url' => ['index']]; | ||||
$this->params['breadcrumbs'][] = ['label' => Html::encode($model->nom.' '.$model->prenom)]; | |||||
$this->params['breadcrumbs'][] = ['label' => Html::encode($model->lastname.' '.$model->name)]; | |||||
$this->params['breadcrumbs'][] = 'Modifier'; | $this->params['breadcrumbs'][] = 'Modifier'; | ||||
?> | ?> | ||||
<div class="user-update"> | <div class="user-update"> |
<?php | |||||
/** | |||||
Copyright La boîte à pain (2018) | |||||
contact@laboiteapain.net | |||||
Ce logiciel est un programme informatique servant à aider les producteurs | |||||
à distribuer leur production en circuits courts. | |||||
Ce logiciel est régi par la licence CeCILL soumise au droit français et | |||||
respectant les principes de diffusion des logiciels libres. Vous pouvez | |||||
utiliser, modifier et/ou redistribuer ce programme sous les conditions | |||||
de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA | |||||
sur le site "http://www.cecill.info". | |||||
En contrepartie de l'accessibilité au code source et des droits de copie, | |||||
de modification et de redistribution accordés par cette licence, il n'est | |||||
offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, | |||||
seule une responsabilité restreinte pèse sur l'auteur du programme, le | |||||
titulaire des droits patrimoniaux et les concédants successifs. | |||||
A cet égard l'attention de l'utilisateur est attirée sur les risques | |||||
associés au chargement, à l'utilisation, à la modification et/ou au | |||||
développement et à la reproduction du logiciel par l'utilisateur étant | |||||
donné sa spécificité de logiciel libre, qui peut le rendre complexe à | |||||
manipuler et qui le réserve donc à des développeurs et des professionnels | |||||
avertis possédant des connaissances informatiques approfondies. Les | |||||
utilisateurs sont donc invités à charger et tester l'adéquation du | |||||
logiciel à leurs besoins dans des conditions permettant d'assurer la | |||||
sécurité de leurs systèmes et ou de leurs données et, plus généralement, | |||||
à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. | |||||
Le fait que vous puissiez accéder à cet en-tête signifie que vous avez | |||||
pris connaissance de la licence CeCILL, et que vous en avez accepté les | |||||
termes. | |||||
*/ | |||||
use yii\helpers\Html; | |||||
use yii\widgets\DetailView; | |||||
/* @var $this yii\web\View */ | |||||
/* @var $model common\models\User */ | |||||
$this->title = $model->id; | |||||
$this->params['breadcrumbs'][] = ['label' => 'Clients', 'url' => ['index']]; | |||||
$this->params['breadcrumbs'][] = $this->title; | |||||
?> | |||||
<div class="user-view"> | |||||
<h1><?= Html::encode($this->title) ?></h1> | |||||
<p> | |||||
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> | |||||
<?= Html::a('Delete', ['delete', 'id' => $model->id], [ | |||||
'class' => 'btn btn-danger', | |||||
'data' => [ | |||||
'confirm' => 'Are you sure you want to delete this item?', | |||||
'method' => 'post', | |||||
], | |||||
]) ?> | |||||
</p> | |||||
<?= DetailView::widget([ | |||||
'model' => $model, | |||||
'attributes' => [ | |||||
'id', | |||||
'username', | |||||
'auth_key', | |||||
'password_hash', | |||||
'password_reset_token', | |||||
'email:email', | |||||
'status', | |||||
'created_at', | |||||
'updated_at', | |||||
'nom', | |||||
'prenom', | |||||
'telephone', | |||||
'confiance', | |||||
], | |||||
]) ?> | |||||
</div> |
* @property double $amount | * @property double $amount | ||||
* @property string $type | * @property string $type | ||||
* @property integer $id_producer | * @property integer $id_producer | ||||
* @property string $means_payement | |||||
* @property string $mean_payement | |||||
*/ | */ | ||||
class CreditHistory extends ActiveRecord | class CreditHistory extends ActiveRecord | ||||
{ | { | ||||
const TYPE_REFUND = 'refund'; | const TYPE_REFUND = 'refund'; | ||||
const TYPE_DEBIT = 'debit'; | const TYPE_DEBIT = 'debit'; | ||||
const MEANS_PAYMENT_CREDIT_CARD = 'credit-card'; | |||||
const MEANS_PAYMENT_MONEY = 'money'; | |||||
const MEANS_PAYMENT_CHEQUE = 'cheque'; | |||||
const MEANS_PAYMENT_OTHER = 'other'; | |||||
const MEAN_PAYMENT_CREDIT_CARD = 'credit-card'; | |||||
const MEAN_PAYMENT_MONEY = 'money'; | |||||
const MEAN_PAYMENT_CHEQUE = 'cheque'; | |||||
const MEAN_PAYMENT_OTHER = 'other'; | |||||
/** | /** | ||||
* @inheritdoc | * @inheritdoc | ||||
[['id_user', 'id_user_action', 'id_order', 'id_producer'], 'integer'], | [['id_user', 'id_user_action', 'id_order', 'id_producer'], 'integer'], | ||||
[['date'], 'safe'], | [['date'], 'safe'], | ||||
[['amount'], 'double'], | [['amount'], 'double'], | ||||
[['type', 'means_payment', 'comment'], 'string', 'max' => 255], | |||||
[['type', 'mean_payment', 'comment'], 'string', 'max' => 255], | |||||
]; | ]; | ||||
} | } | ||||
'amount' => 'Montant', | 'amount' => 'Montant', | ||||
'type' => 'Type', | 'type' => 'Type', | ||||
'id_producer' => 'Producteur', | 'id_producer' => 'Producteur', | ||||
'means_payment' => 'Moyen de paiement', | |||||
'mean_payment' => 'Moyen de paiement', | |||||
'comment' => 'Commentaire', | 'comment' => 'Commentaire', | ||||
]; | ]; | ||||
} | } | ||||
*/ | */ | ||||
public function getAmount($format = false) | public function getAmount($format = false) | ||||
{ | { | ||||
if($format) | |||||
if($format) { | |||||
return number_format($this->amount,2) .' €' ; | return number_format($this->amount,2) .' €' ; | ||||
else | |||||
} | |||||
else { | |||||
return $this->amount ; | return $this->amount ; | ||||
} | |||||
} | } | ||||
/** | /** | ||||
} | } | ||||
/** | /** | ||||
* Retourne le moyen de paiement. | |||||
* Retourne le libellé du moyen de paiement du CreditHistory courant. | |||||
* | |||||
* @return string | |||||
*/ | |||||
public function getStrMeanPayment() | |||||
{ | |||||
self::getStrMeanPaymentBy($this->mean_payement) ; | |||||
} | |||||
/** | |||||
* Retourne le libellé du moyen de paiement. | |||||
* | * | ||||
* @param string $meanPayment | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
public function getStrMeansPayment() | |||||
public static function getStrMeanPaymentBy($meanPayment) | |||||
{ | { | ||||
switch($this->means_payment) { | |||||
case CreditHistory::MEANS_PAYMENT_MONEY : return 'Espèces' ; | |||||
case CreditHistory::MEANS_PAYMENT_CHEQUE : return 'Chèque' ; | |||||
case CreditHistory::MEANS_PAYMENT_CREDIT_CARD : return 'Carte bancaire' ; | |||||
case CreditHistory::MEANS_PAYMENT_OTHER : return 'Autre' ; | |||||
default: return 'Crédit pain' ; | |||||
switch($meanPayment) { | |||||
case CreditHistory::MEAN_PAYMENT_MONEY : return 'Espèces' ; | |||||
case CreditHistory::MEAN_PAYMENT_CHEQUE : return 'Chèque' ; | |||||
case CreditHistory::MEAN_PAYMENT_CREDIT_CARD : return 'Carte bancaire' ; | |||||
case CreditHistory::MEAN_PAYMENT_OTHER : return 'Autre' ; | |||||
default: return 'Crédit' ; | |||||
} | } | ||||
} | } | ||||