Browse Source

Allouer les points de vente à tout ou partie des utilisateurs

Mettre en place un système permettant de définir un accès restreint pour
les points de vente. Utile pour les amaps et autres points de vente dédié
à un certain groupe de personnes.
master
keun 8 years ago
parent
commit
6b695f2777
13 changed files with 220 additions and 25 deletions
  1. +27
    -6
      backend/controllers/PointVenteController.php
  2. +26
    -14
      backend/views/point-vente/_form.php
  3. +1
    -0
      backend/views/point-vente/create.php
  4. +23
    -0
      backend/views/point-vente/index.php
  5. +1
    -0
      backend/views/point-vente/update.php
  6. BIN
      backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc
  7. +13
    -0
      backend/web/css/screen.css
  8. +17
    -1
      backend/web/js/lechatdesnoisettes.js
  9. +15
    -4
      backend/web/sass/screen.scss
  10. +27
    -0
      common/models/PointVente.php
  11. +44
    -0
      common/models/PointVenteUser.php
  12. +24
    -0
      console/migrations/m161205_125942_point_vente_acces_restreint.php
  13. +2
    -0
      frontend/controllers/CommandeController.php

+ 27
- 6
backend/controllers/PointVenteController.php View File

use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use common\models\User; use common\models\User;
use common\models\PointVenteUser ;


/** /**
* PointVenteController implements the CRUD actions for PointVente model. * PointVenteController implements the CRUD actions for PointVente model.


if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->gestionPointFabrication() ; $model->gestionPointFabrication() ;
$model->gestionAccesRestreint() ;
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('create', [
return $this->render('update', array_merge($this->initForm(),[
'model' => $model, 'model' => $model,
]);
]));
} }
} }


*/ */
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id);

$model = PointVente::find()
->with('pointVenteUser')
->where(['id' => $id])
->one() ;
foreach($model->pointVenteUser as $u)
{
$model->users[] = $u->id_user ;
}
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->gestionPointFabrication() ; $model->gestionPointFabrication() ;
$model->gestionAccesRestreint() ;
return $this->redirect(['index']); return $this->redirect(['index']);
} else { } else {
return $this->render('update', [
return $this->render('update', array_merge($this->initForm($id),[
'model' => $model, 'model' => $model,
]);
]));
} }
} }
public function initForm($id = 0)
{
$users = User::find()->orderBy('nom ASC')->all() ;
return [
'users' => $users
] ;
}


/** /**
* Deletes an existing PointVente model. * Deletes an existing PointVente model.
public function actionDelete($id) public function actionDelete($id)
{ {
$this->findModel($id)->delete(); $this->findModel($id)->delete();
PointVenteUser::deleteAll(['id_point_vente' => $id]) ;


return $this->redirect(['index']); return $this->redirect(['index']);
} }

+ 26
- 14
backend/views/point-vente/_form.php View File



use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper ;


/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model backend\models\PointVente */ /* @var $model backend\models\PointVente */


<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>


<?= $form->field($model, 'point_fabrication')->checkbox()->hint('Cochez cette case si ce point de vente correspond à votre lieu de production.') ?>
<?= $form->field($model, 'nom')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'localite')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'adresse')->textarea(['rows' => 6]) ?>
<div class="col-md-8">
<?= $form->field($model, 'point_fabrication')->checkbox()->hint('Cochez cette case si ce point de vente correspond à votre lieu de production.') ?>
<?= $form->field($model, 'nom')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'localite')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'adresse')->textarea(['rows' => 6]) ?>

<h2>Horaires</h2>
<div class="alert alert-info">Laisser vide si le point de vente est fermé</div>
<?= $form->field($model, 'horaires_lundi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_mardi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_mercredi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_jeudi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_vendredi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_samedi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_dimanche')->textarea(['rows' => 3]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'acces_restreint')->checkbox()->hint('Cochez cette case si seulement un groupe restreint d\'utilisateurs peuvent accéder à ce point de vente.') ?>
<div id="users">
<?= Html::activeCheckboxList($model, 'users', ArrayHelper::map($users, 'id', function($model, $defaultValue) {
return Html::encode($model->nom.' '.$model->prenom) ;
} )) ?>
</div>
</div>
<div class="clr"></div>
<h2>Horaires</h2>
<div class="alert alert-info">Laisser vide si le point de vente est fermé</div>
<?= $form->field($model, 'horaires_lundi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_mardi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_mercredi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_jeudi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_vendredi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_samedi')->textarea(['rows' => 3]) ?>
<?= $form->field($model, 'horaires_dimanche')->textarea(['rows' => 3]) ?>

<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']) ?>
</div> </div>

+ 1
- 0
backend/views/point-vente/create.php View File



<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'users' => $users,
]) ?> ]) ?>


</div> </div>

+ 23
- 0
backend/views/point-vente/index.php View File



use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use common\models\PointVenteUser ;


/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */ /* @var $dataProvider yii\data\ActiveDataProvider */
} }
], ],
[
'attribute' => 'acces_restreint',
'format' => 'raw',
'value' => function($model) {
$count = PointVenteUser::find()->where(['id_point_vente' => $model->id])->count();
if($model->acces_restreint)
{
$html = '<span class="glyphicon glyphicon-lock"></span> ' ;
if($count == 1)
{
$html .= '1 utilisateur' ;
}
else {
$html .= $count.' utilisateurs' ;
}
return $html ;
}
else {
return '' ;
}
}
],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}', 'template' => '{update} {delete}',

+ 1
- 0
backend/views/point-vente/update.php View File



<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
'users' => $users
]) ?> ]) ?>


</div> </div>

BIN
backend/web/.sass-cache/c8fef7d48da4dc7f024edc2b0fada9d8d6de5dac/screen.scssc View File


+ 13
- 0
backend/web/css/screen.css View File

.commandeauto-form .produits .quantite { .commandeauto-form .produits .quantite {
text-align: center; text-align: center;
} }

/* points de vente */
/* line 883, ../sass/screen.scss */
.point-vente-form #pointvente-users {
display: none;
height: 500px;
overflow-y: scroll;
}
/* line 887, ../sass/screen.scss */
.point-vente-form #pointvente-users label {
font-weight: normal;
display: block;
}

+ 17
- 1
backend/web/js/lechatdesnoisettes.js View File

chat_index_commandes_points_vente() ; chat_index_commandes_points_vente() ;
chat_btn_plus_moins() ; chat_btn_plus_moins() ;
chat_commandeauto() ; chat_commandeauto() ;
chat_points_vente_acces() ;
// admin // admin
chat_select_etablissement() ; chat_select_etablissement() ;
}) ; }) ;


function chat_points_vente_acces() {
$('#pointvente-acces_restreint').change(function() {
chat_points_vente_acces_event() ;
}) ;
chat_points_vente_acces_event() ;
}

function chat_points_vente_acces_event() {
if($('#pointvente-acces_restreint').prop('checked')) {
$('#pointvente-users').fadeIn() ;
}
else {
$('#pointvente-users').hide() ;
}
}

function chat_select_etablissement() { function chat_select_etablissement() {
$('select[name="select_etablissement"]').change(function() { $('select[name="select_etablissement"]').change(function() {
window.location.href = 'index.php?r=site/change-etablissement&id='+$(this).val() ; window.location.href = 'index.php?r=site/change-etablissement&id='+$(this).val() ;

+ 15
- 4
backend/web/sass/screen.scss View File

text-align: center ; text-align: center ;
} }
} }
}
}

/* points de vente */

.point-vente-form {
#pointvente-users {
display: none ;
height: 500px ;
overflow-y: scroll ;
label {
font-weight: normal ;
display: block ;
}
}
}

+ 27
- 0
common/models/PointVente.php View File



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


/** /**
* This is the model class for table "point_vente". * This is the model class for table "point_vente".
var $recettes_vrac = 0 ; var $recettes_vrac = 0 ;
var $data_select_commandes ; var $data_select_commandes ;
var $data_options_commandes ; var $data_options_commandes ;
var $users = [] ;
/** /**
* @inheritdoc * @inheritdoc
{ {
return [ return [
[['nom'], 'required'], [['nom'], 'required'],
[['acces_restreint'], 'boolean'],
[['nom'], 'string', 'max' => 255], [['nom'], 'string', 'max' => 255],
[['adresse','localite','horaires_lundi','horaires_mardi','horaires_mercredi','horaires_jeudi','horaires_vendredi','horaires_samedi','horaires_dimanche'], 'string'], [['adresse','localite','horaires_lundi','horaires_mardi','horaires_mercredi','horaires_jeudi','horaires_vendredi','horaires_samedi','horaires_dimanche'], 'string'],
[['point_fabrication','vrac','pain'], 'boolean'], [['point_fabrication','vrac','pain'], 'boolean'],
['point_fabrication', 'default','value'=>0], ['point_fabrication', 'default','value'=>0],
['id_etablissement','integer'], ['id_etablissement','integer'],
['id_etablissement','required'], ['id_etablissement','required'],
['users','safe']
]; ];
} }


'horaires_dimanche' => 'Dimanche', 'horaires_dimanche' => 'Dimanche',
'vrac' => 'Livraison de vrac', 'vrac' => 'Livraison de vrac',
'pain' => 'Livraison de pain', 'pain' => 'Livraison de pain',
'acces_restreint' => 'Accès restreint'
]; ];
} }
public function getPointVenteUser()
{
return $this->hasMany(PointVenteUser::className(), ['id_point_vente'=>'id']) ;
}
public function initCommandes($commandes) { public function initCommandes($commandes) {
$this->commandes = [] ; $this->commandes = [] ;
$this->save() ; $this->save() ;
} }
} }
public function gestionAccesRestreint()
{
PointVenteUser::deleteAll(['id_point_vente' => $this->id]) ;
foreach($this->users as $key => $val)
{
$user = User::findOne($val) ;
if($user)
{
$point_vente_user = new PointVenteUser ;
$point_vente_user->id_user = $val ;
$point_vente_user->id_point_vente = $this->id ;
$point_vente_user->save() ;
}
}
}
} }

+ 44
- 0
common/models/PointVenteUser.php View File

<?php

namespace common\models;

use Yii;

/**
* This is the model class for table "point_vente_user".
*
* @property integer $id_point_vente
* @property integer $id_user
*/
class PointVenteUser extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'point_vente_user';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_point_vente', 'id_user'], 'required'],
[['id_point_vente', 'id_user'], 'integer'],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_point_vente' => 'Id Point Vente',
'id_user' => 'Id User',
];
}
}

+ 24
- 0
console/migrations/m161205_125942_point_vente_acces_restreint.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

class m161205_125942_point_vente_acces_restreint extends Migration
{
public function up()
{
$this->addColumn('point_vente', 'acces_restreint', Schema::TYPE_BOOLEAN.' DEFAULT 0') ;
$this->createTable('point_vente_user', [
'id_point_vente' => Schema::TYPE_INTEGER.' NOT NULL',
'id_user' => Schema::TYPE_INTEGER.' NOT NULL',
]);
$this->addPrimaryKey('point_vente_user_pk', 'point_vente_user', ['id_point_vente', 'id_user']);
}

public function down()
{
$this->dropColumn('point_vente', 'acces_restreint') ;
$this->dropTable('point_vente_user') ;
}
}

+ 2
- 0
frontend/controllers/CommandeController.php View File

// points de vente // points de vente
$points_vente = PointVente::find() $points_vente = PointVente::find()
->where(['id_etablissement'=>$id_etablissement]) ->where(['id_etablissement'=>$id_etablissement])
->andWhere('acces_restreint = 0 OR (acces_restreint = 1 AND (SELECT COUNT(*) FROM point_vente_user WHERE point_vente.id = point_vente_user.id_point_vente AND point_vente_user.id_user = :id_user) > 0)')
->params([':id_user' => Yii::$app->user->identity->id])
->all(); ->all();
$arr_points_vente = $points_vente; $arr_points_vente = $points_vente;



Loading…
Cancel
Save