Selaa lähdekoodia

Step points de vente

dev
Guillaume Bourgeois 6 vuotta sitten
vanhempi
commit
54467709a0
3 muutettua tiedostoa jossa 90 lisäystä ja 7 poistoa
  1. +33
    -4
      producer/controllers/OrderController.php
  2. +35
    -3
      producer/views/order/order.php
  3. +22
    -0
      producer/web/js/vuejs/order-order.js

+ 33
- 4
producer/controllers/OrderController.php Näytä tiedosto

@@ -39,6 +39,7 @@ termes.
namespace producer\controllers;

use common\models\ProductDistribution ;
use common\models\User ;
use DateTime;

class OrderController extends ProducerBaseController
@@ -584,10 +585,7 @@ class OrderController extends ProducerBaseController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$json = [
'distribution' => [],
'products' => []
] ;
$json = [] ;
$format = 'Y-m-d' ;
$dateObject = DateTime::createFromFormat($format, $date);
@@ -600,6 +598,37 @@ class OrderController extends ProducerBaseController
]) ;
$json['distributions'] = $distributionsArray ;
if($dateObject && $dateObject->format($format) === $date) {
// distribution
$distribution = Distribution::initDistribution($date) ;
$pointsSaleArray = PointSale::find()
->joinWith(['pointSaleDistribution' => function($query) use ($distribution) {
$query->where(['id_distribution' => $distribution->id]);
}
])
->with(['userPointSale' => function($query) {
$query->onCondition(['id_user' => User::getCurrentId()]) ;
}])
->where([
'id_producer' => $distribution->id_producer,
])
->all();

foreach($pointsSaleArray as &$pointSale) {
$pointSale = array_merge($pointSale->getAttributes(),[
'pointSaleDistribution' => [
'id_distribution' => $pointSale->pointSaleDistribution[0]->id_distribution,
'id_point_sale' => $pointSale->pointSaleDistribution[0]->id_point_sale,
'delivery' => $pointSale->pointSaleDistribution[0]->delivery
],
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '')
]) ;
}
$json['points_sale'] = $pointsSaleArray;
}
return $json ;
}


+ 35
- 3
producer/views/order/order.php Näytä tiedosto

@@ -52,7 +52,8 @@ $this->setTitle('Commander') ;
<span class="glyphicon glyphicon-chevron-right"></span>
</li>
<li id="step-point-sale" :class="'col-md-3 '+((step == 'point-sale') ? 'active' : '')">
Point de vente
<a v-if="pointSaleActive" @click="changeStep('point-sale')" href="javascript:void(0);">Points de vente</a>
<span v-else>Points de vente</span>
<span class="glyphicon glyphicon-chevron-right"></span>
</li>
<li id="step-products" :class="'col-md-3 '+((step == 'products') ? 'active' : '')">
@@ -81,7 +82,35 @@ $this->setTitle('Commander') ;
</div>
</div>
<div id="content-step-point-sale" v-if="step == 'point-sale'">
Points de vente
<table class="table table-bordered" v-if="pointsSale.length">
<thead>
<tr>
<th>Nom</th>
<th>Localité</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="pointSale in pointsSale" v-if="pointSale.pointSaleDistribution.delivery">
<td class="name">
{{ pointSale.name }}
<div class="comment" v-if="pointSale.userPointSale">
{{ pointSale.userPointSale.comment }}
</div>
</td>
<td>{{ pointSale.locality }}</td>
<td>
<button class="btn btn-default" @click="pointSaleClick" :data-id-point-sale="pointSale.id">
<span class="glyphicon glyphicon-map-marker"></span>
Choisir
</button>
</td>
</tr>
</tbody>
</table>
<div class="alert alert-warning" v-else>
Aucun point de vente disponible pour ce jour de distribution.
</div>
</div>
<div id="content-step-products" v-if="step == 'products'">
Produits
@@ -98,7 +127,10 @@ $this->setTitle('Commander') ;
</div>
<div class="panel-body">
<span class="glyphicon glyphicon-time"></span> {{ dateFormat }}
<div v-if="pointSaleActive">
<span class="glyphicon glyphicon-map-marker"></span>
{{ pointSaleActive.name }}
</div>
</div>
</div>
</div>

+ 22
- 0
producer/web/js/vuejs/order-order.js Näytä tiedosto

@@ -5,6 +5,8 @@ var app = new Vue({
step: 'date',
date: null,
dateFormat: null,
pointsSale: [],
pointSaleActive: null,
calendar: {
mode: 'single',
attrs: [],
@@ -69,6 +71,13 @@ var app = new Vue({
}
return false ;
},
getPointSale: function(idPointSale) {
for(var key in this.pointsSale) {
if(this.pointsSale[key].id == idPointSale) {
return this.pointsSale[key] ;
}
}
},
init: function() {
axios.get("ajax-infos",{params: {date : this.getDate()}})
.then(response => {
@@ -84,10 +93,17 @@ var app = new Vue({
}) ;
}
}
if(response.data.points_sale) {
this.pointsSale = response.data.points_sale ;
}
});
},
changeStep: function(step) {
this.step = step ;
if(step == 'point-sale') {
this.init() ;
}
},
dayClick: function(day) {
this.date = day.date ;
@@ -97,5 +113,11 @@ var app = new Vue({
this.init() ;
this.changeStep('point-sale') ;
},
pointSaleClick: function(event) {
this.pointSaleActive = this.getPointSale(event.currentTarget.getAttribute('data-id-point-sale')) ;
console.log(event.currentTarget.getAttribute('data-id-point-sale')) ;
console.log(this.getPointSale(10)) ;
this.changeStep('products') ;
}
}
});

Loading…
Peruuta
Tallenna