Browse Source

Points de vente : code d'accès

Ajouter la possibilité de mettre en place un code d'accès pour les points de vente (en parallèle des accès restreints).
master
keun 7 years ago
parent
commit
932ef0b5bf
7 changed files with 195 additions and 43 deletions
  1. +7
    -0
      backend/views/point-vente/_form.php
  2. +10
    -4
      backend/views/point-vente/index.php
  3. +20
    -2
      common/models/PointVente.php
  4. +17
    -0
      console/migrations/m170201_074937_champs_code_point_vente.php
  5. +28
    -2
      frontend/controllers/CommandeController.php
  6. +44
    -2
      frontend/views/commande/_form.php
  7. +69
    -33
      frontend/web/js/lechatdesnoisettes.js

+ 7
- 0
backend/views/point-vente/_form.php View File

<?= $form->field($model, 'horaires_dimanche')->textarea(['rows' => 3]) ?> <?= $form->field($model, 'horaires_dimanche')->textarea(['rows' => 3]) ?>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<?= $form->field($model, 'code')
->label('Code d\'accès')
->hint('Renseignez ce champs si vous souhaitez protéger ce point de vente par un code.')
?>
<?= $form->field($model, 'acces_restreint') <?= $form->field($model, 'acces_restreint')
->checkbox() ->checkbox()
->hint('Cochez cette case si seulement un groupe restreint d\'utilisateurs peuvent accéder à ce point de vente.<br />' ->hint('Cochez cette case si seulement un groupe restreint d\'utilisateurs peuvent accéder à ce point de vente.<br />'

+ 10
- 4
backend/views/point-vente/index.php View File

'format' => 'raw', 'format' => 'raw',
'value' => function($model) { 'value' => function($model) {
$count = PointVenteUser::find()->where(['id_point_vente' => $model->id])->count(); $count = PointVenteUser::find()->where(['id_point_vente' => $model->id])->count();
$html = '' ;
if($model->acces_restreint) if($model->acces_restreint)
{ {
$html = '<span class="glyphicon glyphicon-lock"></span> ' ;
$html .= '<span class="glyphicon glyphicon-lock"></span> ' ;
if($count == 1) if($count == 1)
{ {
$html .= '1 utilisateur' ; $html .= '1 utilisateur' ;
else { else {
$html .= $count.' utilisateurs' ; $html .= $count.' utilisateurs' ;
} }
return $html ;
} }
else {
return '' ;
if(strlen($model->code))
{
if(strlen($html)) $html .= '<br />' ;
$html .= 'Code : <strong>'.Html::encode($model->code).'</strong>' ;
} }
return $html ;
} }
], ],
[ [

+ 20
- 2
common/models/PointVente.php View File

return [ return [
[['nom'], 'required'], [['nom'], 'required'],
[['acces_restreint'], 'boolean'], [['acces_restreint'], 'boolean'],
[['nom'], 'string', 'max' => 255],
[['nom','code'], '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', 'credit_pain','livraison_lundi','livraison_mardi','livraison_mercredi','livraison_jeudi','livraison_vendredi','livraison_samedi','livraison_dimanche'], 'boolean'], [['point_fabrication','vrac','pain', 'credit_pain','livraison_lundi','livraison_mardi','livraison_mercredi','livraison_jeudi','livraison_vendredi','livraison_samedi','livraison_dimanche'], 'boolean'],
['point_fabrication', 'default','value'=>0], ['point_fabrication', 'default','value'=>0],
['id_etablissement','integer'], ['id_etablissement','integer'],
['id_etablissement','required'], ['id_etablissement','required'],
[['users','users_commentaire'],'safe']
[['users','users_commentaire','code'],'safe']
]; ];
} }


'livraison_vendredi' => 'Vendredi', 'livraison_vendredi' => 'Vendredi',
'livraison_samedi' => 'Samedi', 'livraison_samedi' => 'Samedi',
'livraison_dimanche' => 'Dimanche', 'livraison_dimanche' => 'Dimanche',
'code' => 'Code',
]; ];
} }
]) ])
->count() ; ->count() ;
} }
public function verifCode($code)
{
if(strlen($this->code))
{
if(trim(strtolower($code)) == trim(strtolower($this->code)))
{
return true ;
}
else {
return false ;
}
}
else {
return true ;
}
}
} }

+ 17
- 0
console/migrations/m170201_074937_champs_code_point_vente.php View File

<?php

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

class m170201_074937_champs_code_point_vente extends Migration
{
public function up()
{
$this->addColumn('point_vente', 'code', Schema::TYPE_STRING) ;
}

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

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

'id_point_vente' => $posts['Commande']['id_point_vente'] 'id_point_vente' => $posts['Commande']['id_point_vente']
]) ])
->one() ; ->one() ;
//print_r($ppv) ;
//die() ;
if(!$ppv || !$ppv->livraison) if(!$ppv || !$ppv->livraison)
{ {
$err_point_vente = true ; $err_point_vente = true ;
} }
$point_vente = PointVente::findOne($posts['Commande']['id_point_vente']) ;
if($point_vente)
{
if(strlen($point_vente->code) && !$point_vente->verifCode($posts['code_point_vente_'.$point_vente->id]))
{
$err_point_vente = true ;
}
}
else {
$err_point_vente = true ;
}
} }
if ($commande->validate() && count($produits) && !$err_nb_produits && !$err_date && !$err_point_vente) { if ($commande->validate() && count($produits) && !$err_nb_produits && !$err_date && !$err_point_vente) {
->one() ; ->one() ;
if($pv && strlen($pv->getCommentaire())) if($pv && strlen($pv->getCommentaire()))
$commande->commentaire_point_vente = $pv->getCommentaire() ; $commande->commentaire_point_vente = $pv->getCommentaire() ;
else
$commande->commentaire_point_vente = '' ;
// sauvegarde de la commande // sauvegarde de la commande
$commande->save(); $commande->save();


$this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'annule_ok' => true])); $this->redirect(Yii::$app->urlManager->createUrl(['commande/index', 'annule_ok' => true]));
} }
public function actionVerifCodePointVente($id_point_vente, $code)
{
$point_vente = PointVente::findOne($id_point_vente) ;
if($point_vente)
{
if($point_vente->verifCode($code))
{
return true ;
}
}
return false ;
}


} }

+ 44
- 2
frontend/views/commande/_form.php View File

} }
} }
echo '<li class="bloc point-vente point-vente-' . $pv->id . '" data-vrac="' . (int) $pv->vrac . '" data-pain="' . (int) $pv->pain . '" data-credit-pain="'.(int) $pv->credit_pain.'"><div class="contenu">' .
$html_code = '' ;
$data_code = '0' ;
if(strlen($pv->code))
{
if(!isset($model->id_point_vente) || $model->id_point_vente != $pv->id)
{
$html_code .= '<span class="glyphicon glyphicon-lock"></span> ' ;
$data_code = '1' ;
}
}
echo '<li class="bloc point-vente point-vente-' . $pv->id . '" data-code="'.$data_code.'" data-vrac="' . (int) $pv->vrac . '" data-pain="' . (int) $pv->pain . '" data-credit-pain="'.(int) $pv->credit_pain.'"><div class="contenu">' .
'<span style="display:none;" class="id">' . $pv->id . '</span>' . '<span style="display:none;" class="id">' . $pv->id . '</span>' .
'<div class="nom">' . Html::encode($pv->nom) . '</div>' .
'<div class="nom">' .$html_code. Html::encode($pv->nom) . '</div>' .
'<div class="adresse">à ' . Html::encode($pv->localite) . '</div>' . '<div class="adresse">à ' . Html::encode($pv->localite) . '</div>' .
'<div class="horaires">' . '<div class="horaires">' .
'<div class="jour jour-1">' . (strlen($pv->horaires_lundi) ? nl2br(Html::encode($pv->horaires_lundi)) : 'Fermé') . '</div>' . '<div class="jour jour-1">' . (strlen($pv->horaires_lundi) ? nl2br(Html::encode($pv->horaires_lundi)) : 'Fermé') . '</div>' .
'<div class="jour jour-0">' . (strlen($pv->horaires_dimanche) ? nl2br(Html::encode($pv->horaires_dimanche)) : 'Fermé') . '</div>' . '<div class="jour jour-0">' . (strlen($pv->horaires_dimanche) ? nl2br(Html::encode($pv->horaires_dimanche)) : 'Fermé') . '</div>' .
'</div>' '</div>'
. $commentaire . . $commentaire .
'<input type="hidden" name="code_point_vente_'.$pv->id.'" value="" />'.
'</div></li>'; '</div></li>';
} }
?> ?>
</ul> </ul>
<div class="clr"></div> <div class="clr"></div>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
<!-- modal code point de vente -->
<div class="modal fade" id="modal-code" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Code d'accès</h4>
</div>
<div class="modal-body">
<div class="alert alert-warning">
Ce point de vente nécessite un code d'accès.
</div>
<form action="index.php?r=commande/verif-code" method="post">
<input type="hidden" value="" name="id_point_vente" id="id-point-vente" />
<div class="form-group field-code required">
<label class="control-label" for="code">Code d'accès :</label>
<input type="password" class="form-control" id="code" name="code" />
<p class="help-block help-block-error" style="display:none;">Code incorrect</p>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Valider</button>
</div>
</form>
</div>
</div>
</div>
</div>


</div><!-- commande-form --> </div><!-- commande-form -->

+ 69
- 33
frontend/web/js/lechatdesnoisettes.js View File

} }


function chat_event_click_point_vente(id, force) { function chat_event_click_point_vente(id, force) {
$('#commande-id_point_vente').val(id) ;
$('#points-vente .point-vente').removeClass('selected') ;
$('.point-vente-'+id).addClass('selected') ;
$('.point-vente-'+id).hide().fadeIn('fast') ;
var pain = parseInt($('.point-vente-'+id).data('pain')) ;
var vrac = parseInt($('.point-vente-'+id).data('vrac')) ;
if(pain) {
$('#pain .table').show() ;
$('#pain .indisponible').hide() ;
}
else {
$('#pain .table').hide() ;
$('#pain .indisponible').show() ;
}
if($('.point-vente-'+id).data('code') == 1) {
$('#modal-code #id-point-vente').val(id) ;
$('#modal-code').modal('show') ;
}
else {
$('#commande-id_point_vente').val(id) ;
if(vrac) {
$('#vrac .table').show() ;
$('#vrac .indisponible').hide() ;
}
else {
$('#vrac .table').hide() ;
$('#vrac .indisponible').show() ;
}
$('#points-vente .point-vente').removeClass('selected') ;
$('.point-vente-'+id).addClass('selected') ;
$('.point-vente-'+id).hide().fadeIn('fast') ;

var pain = parseInt($('.point-vente-'+id).data('pain')) ;
var vrac = parseInt($('.point-vente-'+id).data('vrac')) ;

if(pain) {
$('#pain .table').show() ;
$('#pain .indisponible').hide() ;
}
else {
$('#pain .table').hide() ;
$('#pain .indisponible').show() ;
}

if(vrac) {
$('#vrac .table').show() ;
$('#vrac .indisponible').hide() ;
}
else {
$('#vrac .table').hide() ;
$('#vrac .indisponible').show() ;
}

$('#produits, .valider-commande, .btn-commentaire, #bar-fixed').fadeIn() ;

// credit pain
chat_systeme_commande_credit_pain_event(chat_systeme_commande_maj_table_prix()) ;

// scroll
if(!force)
boulange_scroll('step-choix-produits') ;

}
$('#produits, .valider-commande, .btn-commentaire, #bar-fixed').fadeIn() ;
// credit pain
chat_systeme_commande_credit_pain_event(chat_systeme_commande_maj_table_prix()) ;
// scroll
if(!force)
boulange_scroll('step-choix-produits') ;
} }


function chat_init_horaire_point_vente(date) { function chat_init_horaire_point_vente(date) {
$('#produits, .valider-commande, .btn-commentaire, #bar-fixed').hide() ; $('#produits, .valider-commande, .btn-commentaire, #bar-fixed').hide() ;
} }
// points de vente
if($('#commande-id_point_vente').val()) if($('#commande-id_point_vente').val())
chat_event_click_point_vente($('#commande-id_point_vente').val(), true) ; chat_event_click_point_vente($('#commande-id_point_vente').val(), true) ;
$('#modal-code form').submit(function() {
var id_pv = $('#modal-code #id-point-vente').val() ;
var code = $('#modal-code #code').val() ;
$.get('index.php',{
r: 'commande/verif-code-point-vente',
id_point_vente: id_pv,
code: code
}, function(ok) {
if(ok) {
$('.point-vente-'+id_pv).data('code',0) ;
$('.point-vente-'+id_pv+' .glyphicon').remove() ;
$('input[name="code_point_vente_'+id_pv+'"]').val(code) ;
$('#modal-code').modal('hide') ;
chat_event_click_point_vente($('#modal-code #id-point-vente').val()) ;
}
else {
$('#modal-code .field-code').addClass('has-error') ;
$('#modal-code .help-block-error').hide().fadeIn() ;
}
}) ;
return false ;
}) ;
$('#points-vente .point-vente').click(function() { $('#points-vente .point-vente').click(function() {
var id = parseInt($(this).find('.id').html()) ; var id = parseInt($(this).find('.id').html()) ;
chat_event_click_point_vente(id) ; chat_event_click_point_vente(id) ;

Loading…
Cancel
Save