Gestion de la validation du code d'accès au point de vente. Amélioration du style.dev
* @param string $code | * @param string $code | ||||
* @return boolean | * @return boolean | ||||
*/ | */ | ||||
public function actionValidateCodePointSale($idPointSale, $code) | |||||
public function actionAjaxValidateCodePointSale($idPointSale, $code) | |||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | |||||
$pointSale = PointSale::findOne($idPointSale); | $pointSale = PointSale::findOne($idPointSale); | ||||
if ($pointSale) { | if ($pointSale) { | ||||
if ($pointSale->validateCode($code)) { | if ($pointSale->validateCode($code)) { | ||||
return true; | |||||
return 1; | |||||
} | } | ||||
} | } | ||||
return false; | |||||
return 0; | |||||
} | } | ||||
public function actionAjaxInfos($date = '') | public function actionAjaxInfos($date = '') | ||||
foreach($pointsSaleArray as &$pointSale) { | foreach($pointsSaleArray as &$pointSale) { | ||||
$pointSale = array_merge($pointSale->getAttributes(),[ | $pointSale = array_merge($pointSale->getAttributes(),[ | ||||
'code_form' => '', | |||||
'pointSaleDistribution' => [ | 'pointSaleDistribution' => [ | ||||
'id_distribution' => $pointSale->pointSaleDistribution[0]->id_distribution, | 'id_distribution' => $pointSale->pointSaleDistribution[0]->id_distribution, | ||||
'id_point_sale' => $pointSale->pointSaleDistribution[0]->id_point_sale, | 'id_point_sale' => $pointSale->pointSaleDistribution[0]->id_point_sale, |
</div> | </div> | ||||
</div> | </div> | ||||
<div id="content-step-point-sale" v-if="step == 'point-sale'"> | <div id="content-step-point-sale" v-if="step == 'point-sale'"> | ||||
<table class="table table-bordered" v-if="pointsSale.length"> | |||||
<table id="points-sale" class="table table-bordered" v-if="pointsSale.length"> | |||||
<thead> | <thead> | ||||
<tr> | <tr> | ||||
<th>Nom</th> | <th>Nom</th> | ||||
</tr> | </tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
<tr v-for="pointSale in pointsSale" v-if="pointSale.pointSaleDistribution.delivery"> | |||||
<tr v-for="pointSale in pointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery"> | |||||
<td class="name"> | <td class="name"> | ||||
<span class="glyphicon glyphicon-lock" v-if="pointSale.code.length > 0"></span> {{ pointSale.name }} | |||||
<span class="the-name">{{ pointSale.name }}</span> | |||||
<div class="comment" v-if="pointSale.userPointSale"> | <div class="comment" v-if="pointSale.userPointSale"> | ||||
{{ pointSale.userPointSale.comment }} | {{ pointSale.userPointSale.comment }} | ||||
</div> | </div> | ||||
</td> | </td> | ||||
<td>{{ pointSale.locality }}</td> | |||||
<td> | |||||
<input v-if="pointSale.code.length > 0" v-model="codePointSale" type="password" placeholder="Code" class="form-control input-code" /> | |||||
<button class="btn btn-default" @click="pointSaleClick" :data-id-point-sale="pointSale.id"> | |||||
<td class="locality">{{ pointSale.locality }}</td> | |||||
<td class="actions"> | |||||
<div :class="'form-group' + (pointSale.invalid_code ? ' has-error' : '')"> | |||||
<div class="input-group" v-if="pointSale.code.length > 0"> | |||||
<span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span> | |||||
<input v-model="pointsSaleCodes[pointSale.id]" type="password" placeholder="Code" class="form-control input-code" /> | |||||
</div> | |||||
</div> | |||||
<button class="btn btn-primary" @click="pointSaleClick" :data-code="pointSale.code.length > 0" :data-id-point-sale="pointSale.id"> | |||||
<span class="glyphicon glyphicon-map-marker"></span> | <span class="glyphicon glyphicon-map-marker"></span> | ||||
Choisir | |||||
Choisir | |||||
</button> | </button> | ||||
</td> | </td> | ||||
</tr> | </tr> |
margin-top: 20px; | margin-top: 20px; | ||||
} | } | ||||
/* line 148, ../sass/order/_order.scss */ | /* line 148, ../sass/order/_order.scss */ | ||||
.order-order #app-order-order table#points-sale td.name .the-name { | |||||
text-transform: uppercase; | |||||
font-family: "myriadpro-regular"; | |||||
color: black; | |||||
font-size: 16px; | |||||
} | |||||
/* line 156, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#points-sale td.actions { | |||||
width: 150px; | |||||
} | |||||
/* line 158, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#points-sale td.actions button { | |||||
width: 100%; | |||||
} | |||||
/* line 166, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products td.name .name { | .order-order #app-order-order table#products td.name .name { | ||||
text-transform: uppercase; | text-transform: uppercase; | ||||
font-family: "myriadpro-regular"; | font-family: "myriadpro-regular"; | ||||
color: black; | color: black; | ||||
font-size: 16px; | font-size: 16px; | ||||
} | } | ||||
/* line 154, ../sass/order/_order.scss */ | |||||
/* line 172, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products td.name .other { | .order-order #app-order-order table#products td.name .other { | ||||
font-size: 14px; | font-size: 14px; | ||||
color: #333; | color: #333; | ||||
} | } | ||||
/* line 158, ../sass/order/_order.scss */ | |||||
/* line 176, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products td.name .recipe { | .order-order #app-order-order table#products td.name .recipe { | ||||
color: gray; | color: gray; | ||||
} | } | ||||
/* line 162, ../sass/order/_order.scss */ | |||||
/* line 180, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products .price-unit, .order-order #app-order-order table#products .price-total { | .order-order #app-order-order table#products .price-unit, .order-order #app-order-order table#products .price-total { | ||||
width: 100px; | width: 100px; | ||||
text-align: center; | text-align: center; | ||||
} | } | ||||
/* line 166, ../sass/order/_order.scss */ | |||||
/* line 184, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products .td-quantity { | .order-order #app-order-order table#products .td-quantity { | ||||
width: 150px; | width: 150px; | ||||
} | } | ||||
/* line 168, ../sass/order/_order.scss */ | |||||
/* line 186, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order table#products .td-quantity input.quantity { | .order-order #app-order-order table#products .td-quantity input.quantity { | ||||
text-align: center; | text-align: center; | ||||
} | } | ||||
/* line 175, ../sass/order/_order.scss */ | |||||
/* line 193, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #content-step-payment .credit { | .order-order #app-order-order #content-step-payment .credit { | ||||
margin-top: 20px; | margin-top: 20px; | ||||
} | } | ||||
/* line 178, ../sass/order/_order.scss */ | |||||
/* line 196, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #content-step-payment .credit .info { | .order-order #app-order-order #content-step-payment .credit .info { | ||||
margin-left: 20px; | margin-left: 20px; | ||||
color: gray; | color: gray; | ||||
} | } | ||||
/* line 185, ../sass/order/_order.scss */ | |||||
/* line 203, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #infos { | .order-order #app-order-order #infos { | ||||
margin-top: 30px; | margin-top: 30px; | ||||
} | } | ||||
/* line 187, ../sass/order/_order.scss */ | |||||
/* line 205, ../sass/order/_order.scss */ | |||||
.order-order #app-order-order #infos .panel-body { | .order-order #app-order-order #infos .panel-body { | ||||
padding-top: 0px; | padding-top: 0px; | ||||
white-space: pre-line; | white-space: pre-line; |
distribution: null, | distribution: null, | ||||
pointsSale: [], | pointsSale: [], | ||||
pointSaleActive: null, | pointSaleActive: null, | ||||
codePointSale: '', | |||||
pointsSaleCodes: [], | |||||
products: [], | products: [], | ||||
comment: '', | comment: '', | ||||
creditCheckbox: false, | creditCheckbox: false, | ||||
}, | }, | ||||
dates: orders[i].date_distribution, | dates: orders[i].date_distribution, | ||||
}) ; | }) ; | ||||
//console.log(orders[i].pointSale.name + ' / '+this.formatPrice(orders[i].amount_total)) ; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
if(response.data.points_sale) { | if(response.data.points_sale) { | ||||
this.pointsSale = response.data.points_sale ; | |||||
this.pointsSale = [] ; | |||||
for(var key in response.data.points_sale) { | |||||
this.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key] ; | |||||
this.pointsSaleCodes[response.data.points_sale[key].id] = '' ; | |||||
Vue.set(this.pointsSaleCodes, response.data.points_sale[key].id, ''); | |||||
} | |||||
} | } | ||||
if(response.data.products) { | if(response.data.products) { | ||||
}); | }); | ||||
}, | }, | ||||
changeStep: function(step) { | changeStep: function(step) { | ||||
var oldStep = this.step ; | |||||
this.step = step ; | this.step = step ; | ||||
if(step == 'point-sale') { | |||||
if(oldStep == 'date' && step == 'point-sale') { | |||||
this.init() ; | this.init() ; | ||||
} | } | ||||
}, | }, | ||||
return false ; | return false ; | ||||
}, | }, | ||||
pointSaleClick: function(event) { | pointSaleClick: function(event) { | ||||
this.pointSaleActive = this.getPointSale(event.currentTarget.getAttribute('data-id-point-sale')) ; | |||||
var idPointSale = event.currentTarget.getAttribute('data-id-point-sale') ; | |||||
var hasCode = event.currentTarget.getAttribute('data-code') ; | |||||
if(hasCode) { | |||||
axios.get('ajax-validate-code-point-sale',{params: { | |||||
idPointSale: idPointSale, | |||||
code: this.pointsSaleCodes[idPointSale] | |||||
}}).then(response => { | |||||
if(response.data) { | |||||
this.pointsSale[idPointSale].invalid_code = false ; | |||||
this.validatePointSale(idPointSale) ; | |||||
} | |||||
else { | |||||
this.pointsSale[idPointSale].invalid_code = true ; | |||||
Vue.set(this.pointsSaleCodes, idPointSale, ''); | |||||
} | |||||
}) ; | |||||
} | |||||
else { | |||||
this.validatePointSale(idPointSale) ; | |||||
} | |||||
}, | |||||
validatePointSale: function(idPointSale) { | |||||
this.pointSaleActive = this.getPointSale(idPointSale) ; | |||||
this.changeStep('products') ; | this.changeStep('products') ; | ||||
}, | }, | ||||
productQuantityClick: function(product, quantity) { | productQuantityClick: function(product, quantity) { | ||||
id_point_sale: this.pointSaleActive.id, | id_point_sale: this.pointSaleActive.id, | ||||
comment: this.comment | comment: this.comment | ||||
}, | }, | ||||
code_point_sale: this.codePointSale, | |||||
code_point_sale: this.codePointsSale[this.pointSaleActive.id], | |||||
products: productsArray, | products: productsArray, | ||||
use_credit: this.creditCheckbox | use_credit: this.creditCheckbox | ||||
}).then(response => { | }).then(response => { |
margin-top: 20px ; | margin-top: 20px ; | ||||
} | } | ||||
table#points-sale { | |||||
td.name { | |||||
.the-name { | |||||
text-transform: uppercase ; | |||||
font-family: 'myriadpro-regular' ; | |||||
color: black ; | |||||
font-size: 16px ; | |||||
} | |||||
} | |||||
td.actions { | |||||
width: 150px ; | |||||
button { | |||||
width: 100% ; | |||||
} | |||||
} | |||||
} | |||||
table#products { | table#products { | ||||
td.name { | td.name { | ||||
.name { | .name { |