return 0; | return 0; | ||||
} | } | ||||
/** | |||||
* Retourne le point de vente favoris d'un utilisateur : le point de vente auquel le client est lié, | |||||
* le point de vente de la dernière commande sinon. | |||||
* | |||||
* @return PointSale | |||||
*/ | |||||
public function getFavoritePointSale() | |||||
{ | |||||
$arrayUserPointSale = UserPointSale::find()->where(['id_user' => $this->id])->all() ; | |||||
if(count($arrayUserPointSale) == 1) { | |||||
$pointSale = PointSale::findOne(['id' => $arrayUserPointSale[0]->id_point_sale]) ; | |||||
} | |||||
else { | |||||
$lastOrder = Order::find()->innerJoinWith('pointSale', true)->where([ | |||||
'id_user' => $this->id, | |||||
'point_sale.id_producer' => Producer::getId() | |||||
]) | |||||
->orderBy('order.id DESC') | |||||
->one() ; | |||||
if($lastOrder) { | |||||
$pointSale = PointSale::findOne(['id' => $lastOrder->id_point_sale]) ; | |||||
} | |||||
} | |||||
if($pointSale) { | |||||
return $pointSale ; | |||||
} | |||||
return false ; | |||||
} | |||||
/** | /** | ||||
* Met à jour la date de dernière connexion de l'utilisateur. | * Met à jour la date de dernière connexion de l'utilisateur. |
} | } | ||||
} | } | ||||
$json['points_sale'] = $pointsSaleArray; | |||||
$favoritePointSale = User::getCurrent()->getFavoritePointSale() ; | |||||
if($favoritePointSale) { | |||||
$newPointSaleArray = [] ; | |||||
foreach($pointsSaleArray as $pointSale) { | |||||
if($pointSale['id'] != $favoritePointSale->id) { | |||||
$newPointSaleArray[] = $pointSale ; | |||||
} | |||||
else { | |||||
$theFavoritePointSale = $pointSale ; | |||||
} | |||||
} | |||||
if(isset($theFavoritePointSale)) { | |||||
array_unshift($newPointSaleArray, $theFavoritePointSale) ; | |||||
} | |||||
} | |||||
else { | |||||
$newPointSaleArray = $pointsSaleArray ; | |||||
} | |||||
$json['points_sale'] = $newPointSaleArray; | |||||
// Commandes totales | // Commandes totales | ||||
$ordersArray = Order::searchAll([ | $ordersArray = Order::searchAll([ |
</tr> | </tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
<tr v-for="pointSale in pointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery" :class="(pointSaleActive && pointSale.id == pointSaleActive.id) ? 'selected' : ''"> | |||||
<tr v-for="pointSale in orderedPointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery" :class="(pointSaleActive && pointSale.id == pointSaleActive.id) ? 'selected' : ''"> | |||||
<td class="name"> | <td class="name"> | ||||
<span class="the-name">{{ pointSale.name }}</span> | <span class="the-name">{{ pointSale.name }}</span> | ||||
<div class="comment" v-if="pointSale.userPointSale"> | <div class="comment" v-if="pointSale.userPointSale"> |
} | } | ||||
} | } | ||||
}, | }, | ||||
getPointSaleKey: function(idPointSale) { | |||||
for(var key in this.pointsSale) { | |||||
if(this.pointsSale[key].id == idPointSale) { | |||||
return key ; | |||||
} | |||||
} | |||||
}, | |||||
init: function() { | init: function() { | ||||
var app = this ; | var app = this ; | ||||
this.loading = true ; | this.loading = true ; | ||||
if(response.data.distribution) { | if(response.data.distribution) { | ||||
app.distribution = response.data.distribution ; | app.distribution = response.data.distribution ; | ||||
} | } | ||||
if(response.data.points_sale) { | if(response.data.points_sale) { | ||||
app.pointsSale = [] ; | app.pointsSale = [] ; | ||||
var orderPointSale = 0 ; | |||||
for(var key in response.data.points_sale) { | for(var key in response.data.points_sale) { | ||||
response.data.points_sale[key].order = orderPointSale ++ ; | |||||
app.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key] ; | app.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key] ; | ||||
app.pointsSaleCodes[response.data.points_sale[key].id] = '' ; | app.pointsSaleCodes[response.data.points_sale[key].id] = '' ; | ||||
Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, ''); | Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, ''); | ||||
code: this.pointsSaleCodes[idPointSale] | code: this.pointsSaleCodes[idPointSale] | ||||
}}).then(function(response) { | }}).then(function(response) { | ||||
if(response.data) { | if(response.data) { | ||||
app.pointsSale[idPointSale].invalid_code = false ; | |||||
app.pointsSale[app.getPointSaleKey(idPointSale)].invalid_code = false ; | |||||
app.validatePointSale(idPointSale) ; | app.validatePointSale(idPointSale) ; | ||||
} | } | ||||
else { | else { | ||||
app.pointsSale[idPointSale].invalid_code = true ; | |||||
app.pointsSale[app.getPointSaleKey(idPointSale)].invalid_code = true ; | |||||
Vue.set(app.pointsSaleCodes, idPointSale, ''); | Vue.set(app.pointsSaleCodes, idPointSale, ''); | ||||
} | } | ||||
}) ; | }) ; | ||||
} | } | ||||
return this.producer.credit_limit == null || (this.producer.credit_limit != null && (this.user.credit - total >= this.producer.credit_limit)) ; | return this.producer.credit_limit == null || (this.producer.credit_limit != null && (this.user.credit - total >= this.producer.credit_limit)) ; | ||||
} | } | ||||
}, | |||||
computed : { | |||||
orderedPointsSale: function() { | |||||
var orderedPointsSaleArray = this.pointsSale.sort(function(a, b) { | |||||
if(a.order > b.order) { | |||||
return 1 ; | |||||
} | |||||
else { | |||||
return -1 ; | |||||
} | |||||
}) ; | |||||
return orderedPointsSaleArray ; | |||||
} | |||||
} | } | ||||
}); | }); |