namespace producer\controllers; | namespace producer\controllers; | ||||
use common\models\ProductDistribution ; | use common\models\ProductDistribution ; | ||||
use common\models\User ; | |||||
use DateTime; | use DateTime; | ||||
class OrderController extends ProducerBaseController | class OrderController extends ProducerBaseController | ||||
{ | { | ||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; | ||||
$json = [ | |||||
'distribution' => [], | |||||
'products' => [] | |||||
] ; | |||||
$json = [] ; | |||||
$format = 'Y-m-d' ; | $format = 'Y-m-d' ; | ||||
$dateObject = DateTime::createFromFormat($format, $date); | $dateObject = DateTime::createFromFormat($format, $date); | ||||
]) ; | ]) ; | ||||
$json['distributions'] = $distributionsArray ; | $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 ; | return $json ; | ||||
} | } | ||||
<span class="glyphicon glyphicon-chevron-right"></span> | <span class="glyphicon glyphicon-chevron-right"></span> | ||||
</li> | </li> | ||||
<li id="step-point-sale" :class="'col-md-3 '+((step == 'point-sale') ? 'active' : '')"> | <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> | <span class="glyphicon glyphicon-chevron-right"></span> | ||||
</li> | </li> | ||||
<li id="step-products" :class="'col-md-3 '+((step == 'products') ? 'active' : '')"> | <li id="step-products" :class="'col-md-3 '+((step == 'products') ? 'active' : '')"> | ||||
</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'"> | ||||
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> | ||||
<div id="content-step-products" v-if="step == 'products'"> | <div id="content-step-products" v-if="step == 'products'"> | ||||
Produits | Produits | ||||
</div> | </div> | ||||
<div class="panel-body"> | <div class="panel-body"> | ||||
<span class="glyphicon glyphicon-time"></span> {{ dateFormat }} | <span class="glyphicon glyphicon-time"></span> {{ dateFormat }} | ||||
<div v-if="pointSaleActive"> | |||||
<span class="glyphicon glyphicon-map-marker"></span> | |||||
{{ pointSaleActive.name }} | |||||
</div> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
</div> | </div> |
step: 'date', | step: 'date', | ||||
date: null, | date: null, | ||||
dateFormat: null, | dateFormat: null, | ||||
pointsSale: [], | |||||
pointSaleActive: null, | |||||
calendar: { | calendar: { | ||||
mode: 'single', | mode: 'single', | ||||
attrs: [], | attrs: [], | ||||
} | } | ||||
return false ; | return false ; | ||||
}, | }, | ||||
getPointSale: function(idPointSale) { | |||||
for(var key in this.pointsSale) { | |||||
if(this.pointsSale[key].id == idPointSale) { | |||||
return this.pointsSale[key] ; | |||||
} | |||||
} | |||||
}, | |||||
init: function() { | init: function() { | ||||
axios.get("ajax-infos",{params: {date : this.getDate()}}) | axios.get("ajax-infos",{params: {date : this.getDate()}}) | ||||
.then(response => { | .then(response => { | ||||
}) ; | }) ; | ||||
} | } | ||||
} | } | ||||
if(response.data.points_sale) { | |||||
this.pointsSale = response.data.points_sale ; | |||||
} | |||||
}); | }); | ||||
}, | }, | ||||
changeStep: function(step) { | changeStep: function(step) { | ||||
this.step = step ; | this.step = step ; | ||||
if(step == 'point-sale') { | |||||
this.init() ; | |||||
} | |||||
}, | }, | ||||
dayClick: function(day) { | dayClick: function(day) { | ||||
this.date = day.date ; | this.date = day.date ; | ||||
this.init() ; | this.init() ; | ||||
this.changeStep('point-sale') ; | 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') ; | |||||
} | |||||
} | } | ||||
}); | }); |