return $this->hasMany(ProductDistribution::className(), ['id_distribution' => 'id']); | return $this->hasMany(ProductDistribution::className(), ['id_distribution' => 'id']); | ||||
} | } | ||||
public function getPointSaleDistribution() | |||||
{ | |||||
return $this->hasMany(PointSaleDistribution::className(), ['id_distribution' => 'id']) ; | |||||
} | |||||
/** | /** | ||||
* Retourne les options de base nécessaires à la fonction de recherche. | * Retourne les options de base nécessaires à la fonction de recherche. | ||||
* | * | ||||
$pointSaleDistribution->save(); | $pointSaleDistribution->save(); | ||||
} | } | ||||
public function isPointSaleActive($distribution, $pointSaleId) | |||||
{ | |||||
$pointSaleActive = false ; | |||||
if($distribution->pointSaleDistribution) { | |||||
foreach($distribution->pointSaleDistribution as $pointSaleDistribution) { | |||||
if($pointSaleDistribution->id_point_sale == $pointSaleId && $pointSaleDistribution->delivery) { | |||||
$pointSaleActive = true ; | |||||
} | |||||
} | |||||
} | |||||
return $pointSaleActive ; | |||||
} | |||||
/** | /** | ||||
* Active ou désactive la distribution. | * Active ou désactive la distribution. | ||||
*/ | */ |
'use_credit_checked_default' => $producer->use_credit_checked_default, | 'use_credit_checked_default' => $producer->use_credit_checked_default, | ||||
'credit_limit' => is_numeric($producer->credit_limit) ? $producer->credit_limit : null, | 'credit_limit' => is_numeric($producer->credit_limit) ? $producer->credit_limit : null, | ||||
'option_allow_order_guest' => $producer->option_allow_order_guest, | 'option_allow_order_guest' => $producer->option_allow_order_guest, | ||||
'option_order_entry_point' => $producer->option_order_entry_point, | |||||
]; | ]; | ||||
// Distributions | // Distributions | ||||
], [ | ], [ | ||||
'conditions' => ['date > :date'], | 'conditions' => ['date > :date'], | ||||
'params' => [':date' => $dateMini], | 'params' => [':date' => $dateMini], | ||||
'join_with' => ['pointSaleDistribution'], | |||||
]); | ]); | ||||
$distributionsArray = Distribution::filterDistributionsByDateDelay($distributionsArray) ; | $distributionsArray = Distribution::filterDistributionsByDateDelay($distributionsArray) ; | ||||
$json['distributions'] = $distributionsArray; | |||||
// Filtre par point de vente | |||||
if($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { | |||||
$distributionsArrayFilterPointSale = [] ; | |||||
for($i = 0; $i < count($distributionsArray) ; $i++) { | |||||
$distribution = $distributionsArray[$i] ; | |||||
if(Distribution::isPointSaleActive($distribution, $pointSaleId)) { | |||||
$distributionsArrayFilterPointSale[] = $distribution ; | |||||
} | |||||
} | |||||
$json['distributions'] = $distributionsArrayFilterPointSale; | |||||
} | |||||
else { | |||||
$json['distributions'] = $distributionsArray; | |||||
} | |||||
// Commandes de l'utilisateur | // Commandes de l'utilisateur | ||||
$ordersUserArray = [] ; | $ordersUserArray = [] ; | ||||
if(User::getCurrentId()) { | if(User::getCurrentId()) { | ||||
$conditionsOrdersUser = [ | |||||
'distribution.date > :date' | |||||
] ; | |||||
$paramsOrdersUser = [ | |||||
':date' => $dateMini | |||||
] ; | |||||
if($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { | |||||
$conditionsOrdersUser[] = 'order.id_point_sale = :id_point_sale' ; | |||||
$paramsOrdersUser[':id_point_sale'] = $pointSaleId ; | |||||
} | |||||
$ordersUserArray = Order::searchAll([ | $ordersUserArray = Order::searchAll([ | ||||
'id_user' => User::getCurrentId() | 'id_user' => User::getCurrentId() | ||||
], [ | ], [ | ||||
'conditions' => [ | |||||
'distribution.date > :date' | |||||
], | |||||
'params' => [ | |||||
':date' => $dateMini | |||||
] | |||||
'conditions' => $conditionsOrdersUser, | |||||
'params' => $paramsOrdersUser | |||||
]); | ]); | ||||
} | } | ||||
// Commande de l'utilisateur | // Commande de l'utilisateur | ||||
$orderUser = false ; | $orderUser = false ; | ||||
if(User::getCurrentId()) { | if(User::getCurrentId()) { | ||||
$orderUser = Order::searchOne([ | |||||
$conditionOrderUser = [ | |||||
'distribution.date' => $date, | 'distribution.date' => $date, | ||||
'id_user' => User::getCurrentId(), | 'id_user' => User::getCurrentId(), | ||||
]); | |||||
] ; | |||||
//if($pointSaleId && $producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_POINT_SALE) { | |||||
if($pointSaleId) { | |||||
$conditionOrderUser['id_point_sale'] = $pointSaleId ; | |||||
} | |||||
$orderUser = Order::searchOne($conditionOrderUser); | |||||
} | } | ||||
if ($orderUser) { | if ($orderUser) { | ||||
$distribution = Distribution::initDistribution($date); | $distribution = Distribution::initDistribution($date); | ||||
$json['distribution'] = $distribution; | $json['distribution'] = $distribution; | ||||
$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]) | |||||
->andWhere('restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0)') | |||||
->params([':id_user' => User::getCurrentId()]) | |||||
->all(); | |||||
$creditFunctioningProducer = Producer::getConfig('credit_functioning'); | |||||
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] : '') | |||||
]); | |||||
if ($pointSale['code'] && strlen($pointSale['code'])) { | |||||
$pointSale['code'] = '***'; | |||||
} | |||||
if (!strlen($pointSale['credit_functioning'])) { | |||||
$pointSale['credit_functioning'] = $creditFunctioningProducer; | |||||
} | |||||
} | |||||
$favoritePointSale = false ; | |||||
if(User::getCurrent()) { | |||||
$favoritePointSale = User::getCurrent()->getFavoritePointSale(); | |||||
} | |||||
if ($favoritePointSale) { | |||||
for ($i = 0; $i < count($pointsSaleArray); $i++) { | |||||
if ($pointsSaleArray[$i]['id'] == $favoritePointSale->id) { | |||||
$theFavoritePointSale = $pointsSaleArray[$i]; | |||||
unset($pointsSaleArray[$i]); | |||||
} | |||||
} | |||||
if (isset($theFavoritePointSale)) { | |||||
$pointsSaleArray = array_reverse($pointsSaleArray, false); | |||||
$pointsSaleArray[] = $theFavoritePointSale; | |||||
$pointsSaleArray = array_reverse($pointsSaleArray, false); | |||||
} | |||||
} | |||||
$json['points_sale'] = $pointsSaleArray; | |||||
// Points de vente | |||||
$json['points_sale'] = $this->_initPointsSale($producer->id, $distribution); | |||||
// Commandes totales | // Commandes totales | ||||
$ordersArray = Order::searchAll([ | $ordersArray = Order::searchAll([ | ||||
$json['products'] = $productsArray; | $json['products'] = $productsArray; | ||||
} | } | ||||
else { | |||||
$json['points_sale'] = $this->_initPointsSale($producer->id) ; | |||||
} | |||||
return $json; | return $json; | ||||
} | } | ||||
private function _initPointsSale($idProducer, $distribution = false) | |||||
{ | |||||
$pointsSaleArray = PointSale::find() ; | |||||
if($distribution) { | |||||
$pointsSaleArray = $pointsSaleArray->joinWith(['pointSaleDistribution' => function ($query) use ($distribution) { | |||||
$query->where(['id_distribution' => $distribution->id]); | |||||
} | |||||
]) ; | |||||
} | |||||
if(User::getCurrentId()) { | |||||
$pointsSaleArray = $pointsSaleArray->with(['userPointSale' => function ($query) { | |||||
$query->onCondition(['id_user' => User::getCurrentId()]); | |||||
}]) ; | |||||
} | |||||
$pointsSaleArray = $pointsSaleArray->where(['id_producer' => $idProducer]) | |||||
->andWhere('restricted_access = 0 OR (restricted_access = 1 AND (SELECT COUNT(*) FROM user_point_sale WHERE point_sale.id = user_point_sale.id_point_sale AND user_point_sale.id_user = :id_user) > 0)') | |||||
->params([':id_user' => User::getCurrentId()]) | |||||
->all(); | |||||
$creditFunctioningProducer = Producer::getConfig('credit_functioning'); | |||||
foreach ($pointsSaleArray as &$pointSale) { | |||||
$pointSale = array_merge($pointSale->getAttributes(), [ | |||||
'pointSaleDistribution' => [ | |||||
'id_distribution' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->id_distribution : false, | |||||
'id_point_sale' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->id_point_sale : false, | |||||
'delivery' => $pointSale->pointSaleDistribution ? $pointSale->pointSaleDistribution[0]->delivery : false, | |||||
], | |||||
'userPointSale' => ($pointSale->userPointSale ? $pointSale->userPointSale[0] : '') | |||||
]); | |||||
if ($pointSale['code'] && strlen($pointSale['code'])) { | |||||
$pointSale['code'] = '***'; | |||||
} | |||||
if (!strlen($pointSale['credit_functioning'])) { | |||||
$pointSale['credit_functioning'] = $creditFunctioningProducer; | |||||
} | |||||
} | |||||
$favoritePointSale = false ; | |||||
if(User::getCurrent()) { | |||||
$favoritePointSale = User::getCurrent()->getFavoritePointSale(); | |||||
} | |||||
if ($favoritePointSale) { | |||||
for ($i = 0; $i < count($pointsSaleArray); $i++) { | |||||
if ($pointsSaleArray[$i]['id'] == $favoritePointSale->id) { | |||||
$theFavoritePointSale = $pointsSaleArray[$i]; | |||||
unset($pointsSaleArray[$i]); | |||||
} | |||||
} | |||||
if (isset($theFavoritePointSale)) { | |||||
$pointsSaleArray = array_reverse($pointsSaleArray, false); | |||||
$pointsSaleArray[] = $theFavoritePointSale; | |||||
$pointsSaleArray = array_reverse($pointsSaleArray, false); | |||||
} | |||||
} | |||||
return $pointsSaleArray ; | |||||
} | |||||
public function actionConfirm($idOrder) | public function actionConfirm($idOrder) | ||||
{ | { | ||||
$order = Order::searchOne(['id' => $idOrder]); | $order = Order::searchOne(['id' => $idOrder]); |
?> | ?> | ||||
<script> | |||||
var appInitValues = { | |||||
}; | |||||
</script> | |||||
<div id="app-order-order" :class="{'loaded': !loadingInit}"> | <div id="app-order-order" :class="{'loaded': !loadingInit}"> | ||||
<?php if(isset($order)): ?> | <?php if(isset($order)): ?> | ||||
<span id="order-distribution-date"><?= $order->distribution->date; ?></span> | <span id="order-distribution-date"><?= $order->distribution->date; ?></span> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<div> | <div> | ||||
<div id="steps"> | <div id="steps"> | ||||
<ul> | <ul> | ||||
<li id="step-date" :class="'col-md-3 '+((step == 'date') ? 'active' : '')"> | |||||
<button @click="changeStep('date')" :class="'btn '+ (step == 'date' ? 'btn-primary' : 'btn-default')"> | |||||
<span class="button-content"><span class="glyphicon glyphicon-time"></span> Date</span></span> | |||||
</button> | |||||
<div class="info-step" v-if="dateFormat"> | |||||
{{ dateFormat }} | |||||
</div> | |||||
</li> | |||||
<li id="step-point-sale" :class="'col-md-3 '+((step == 'point-sale') ? 'active ' : '')"> | |||||
<button @click="changeStep('point-sale')" :class="'btn '+ (step == 'point-sale' ? 'btn-primary' : 'btn-default')" :disabled="step == 'date'"> | |||||
<span class="button-content"><span class="glyphicon glyphicon-map-marker"></span> Points de vente</span> | |||||
</button> | |||||
<div class="info-step" v-if="pointSaleActive"> | |||||
{{ pointSaleActive.name }} | |||||
</div> | |||||
</li> | |||||
<?php if($producer->option_order_entry_point == Producer::ORDER_ENTRY_POINT_DATE): ?> | |||||
<step-date | |||||
first="true" | |||||
:step="step" | |||||
:point-sale-active="pointSaleActive" | |||||
:date-format="dateFormat" | |||||
:change-step="changeStep" | |||||
:producer="producer" | |||||
></step-date> | |||||
<step-point-sale | |||||
:step="step" | |||||
:point-sale-active="pointSaleActive" | |||||
:change-step="changeStep" | |||||
:producer="producer" | |||||
></step-point-sale> | |||||
<?php else: ?> | |||||
<step-point-sale | |||||
first="true" | |||||
:step="step" | |||||
:point-sale-active="pointSaleActive" | |||||
:change-step="changeStep" | |||||
:producer="producer" | |||||
></step-point-sale> | |||||
<step-date | |||||
:step="step" | |||||
:point-sale-active="pointSaleActive" | |||||
:date-format="dateFormat" | |||||
:change-step="changeStep" | |||||
:producer="producer" | |||||
></step-date> | |||||
<?php endif; ?> | |||||
<li id="step-products" :class="'col-md-3 '+((step == 'products') ? 'active ' : '')"> | <li id="step-products" :class="'col-md-3 '+((step == 'products') ? 'active ' : '')"> | ||||
<button @click="changeStep('products')" :class="'btn '+ (step == 'products' ? 'btn-primary' : 'btn-default')" :disabled="step == 'date' || step == 'point-sale'"> | <button @click="changeStep('products')" :class="'btn '+ (step == 'products' ? 'btn-primary' : 'btn-default')" :disabled="step == 'date' || step == 'point-sale'"> | ||||
<span class="button-content"><span class="glyphicon glyphicon-th-list"></span> Produits</span> | <span class="button-content"><span class="glyphicon glyphicon-th-list"></span> Produits</span> | ||||
</li> | </li> | ||||
</ul> | </ul> | ||||
</div> | </div> | ||||
<div v-if="loading && !step"> | |||||
Chargement ... | |||||
</div> | |||||
<transition name="slide"> | <transition name="slide"> | ||||
<div id="content-step-date" v-if="step == 'date'"> | <div id="content-step-date" v-if="step == 'date'"> | ||||
<div v-if="loading"> | |||||
Chargement ... | |||||
</div> | |||||
<div v-else> | |||||
<?php if($producer->behavior_order_select_distribution == Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?> | <?php if($producer->behavior_order_select_distribution == Producer::BEHAVIOR_ORDER_SELECT_DISTRIBUTION_LIST ): ?> | ||||
<div style="display:none ;"> | <div style="display:none ;"> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
<?php endforeach; ?> | <?php endforeach; ?> | ||||
</div> | </div> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
</div> | |||||
</div> | </div> | ||||
</transition> | </transition> | ||||
<transition name="slide"> | <transition name="slide"> | ||||
</tr> | </tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
<tr v-for="pointSale in orderedPointsSale" v-if="pointSale && pointSale.pointSaleDistribution.delivery" :class="(pointSaleActive && pointSale.id == pointSaleActive.id) ? 'selected' : ''"> | |||||
<tr v-for="pointSale in orderedPointsSale" v-if="pointSale && (producer.option_order_entry_point == 'point-sale' || (producer.option_order_entry_point == 'date' && 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"> | ||||
</transition> | </transition> | ||||
<transition name="slide"> | <transition name="slide"> | ||||
<div id="content-step-products" v-if="step == 'products'"> | <div id="content-step-products" v-if="step == 'products'"> | ||||
<div v-if="products.length"> | |||||
<table id="products" class="table table-bordered" > | |||||
<thead> | |||||
<tr> | |||||
<th>Photo</th> | |||||
<th>Nom</th> | |||||
<th>Prix unitaire</th> | |||||
<th>Quantité</th> | |||||
<th>Total</th> | |||||
</tr> | |||||
</thead> | |||||
<tbody> | |||||
<template v-for="category in categories"> | |||||
<tr v-if="category.id && countProductsByCategory(category)"> | |||||
<td class="category-name" colspan="5" @click="setCategoryCurrent(category)"> | |||||
<span v-if="categoryCurrent && categoryCurrent.id == category.id" class="glyphicon glyphicon-triangle-bottom"></span> | |||||
<span v-else class="glyphicon glyphicon-triangle-right"></span> | |||||
{{ category.name }} | |||||
<span class="label label-default">{{ countProductsByCategory(category) }} produit<template v-if="countProductsByCategory(category) > 1">s</template></span> | |||||
<span v-if="countSelectedProductsByCategory(category) > 0" class="label label-success">{{ countSelectedProductsByCategory(category) }} produit<template v-if="countSelectedProductsByCategory(category) > 1">s</template> sélectionné<template v-if="countSelectedProductsByCategory(category) > 1">s</template></span> | |||||
</td> | |||||
<div v-if="loading"> | |||||
Chargement ... | |||||
</div> | |||||
<div v-else> | |||||
<div v-if="products.length"> | |||||
<table id="products" class="table table-bordered" > | |||||
<thead> | |||||
<tr> | |||||
<th>Photo</th> | |||||
<th>Nom</th> | |||||
<th>Prix unitaire</th> | |||||
<th>Quantité</th> | |||||
<th>Total</th> | |||||
</tr> | </tr> | ||||
<template v-if="(categoryCurrent && categoryCurrent.id == category.id) || category.id == null"> | |||||
<tr v-for="product in products" v-if="product.id_product_category == category.id && product.productDistribution && product.productDistribution[0] && product.productDistribution[0].active == 1"> | |||||
<td class="photo"> | |||||
<img v-if="product.photo.length" class="photo-product" :src="'<?php echo Yii::$app->urlManager->getBaseUrl(); ?>/uploads/'+product.photo" /> | |||||
</td> | |||||
<td class="name"> | |||||
<span class="name">{{ product.name }}</span> | |||||
<span class="other"> | |||||
<span v-if="product.description.length">/</span> | |||||
<span class="description">{{ product.description }}</span> | |||||
<span v-if="product.weight">({{ product.weight }} g)</span> | |||||
</span> | |||||
<span v-if="product.quantity_max > 0 && ((product.quantity_form / product.coefficient_unit == product.quantity_remaining) || ((product.quantity_remaining * product.coefficient_unit) - product.quantity_form) < product.step)" class="label label-danger"> | |||||
Épuisé | |||||
</span> | |||||
<div class="recipe" v-if="product.recipe.length">{{ product.recipe }}</div> | |||||
</td> | |||||
<td class="price-unit"> | |||||
<template v-if="product.price_with_tax > 0">{{ formatPrice(product.price_with_tax) }}<br /><span class="unit">{{ product.wording_unit }}</span></template> | |||||
</td> | |||||
<td class="td-quantity"> | |||||
<template v-if="product.price_with_tax > 0"> | |||||
<div class="input-group"> | |||||
<span class="input-group-btn"> | |||||
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product, product.unit == 'piece' ? -1 : -parseFloat(product.step))" :disabled="product.quantity_form == 0"><span class="glyphicon glyphicon-minus"></span></button> | |||||
</span> | |||||
<input type="text" v-model="product.quantity_form" class="form-control quantity" readonly="readonly" /> | |||||
<span class="input-group-addon">{{ product.unit == 'piece' ? 'p.' : product.unit }}</span> | |||||
<span class="input-group-btn"> | |||||
<button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product, product.unit == 'piece' ? 1 : parseFloat(product.step))" :disabled="product.quantity_form == product.quantity_remaining && product.quantity_max > 0"><span class="glyphicon glyphicon-plus"></span></button> | |||||
</span> | |||||
</div> | |||||
</template> | |||||
</td> | |||||
<td class="price-total"> | |||||
<template v-if="product.price_with_tax > 0 && product.quantity_form > 0"> | |||||
{{ formatPrice(product.price_with_tax * (product.quantity_form / product.coefficient_unit )) }} | |||||
</template> | |||||
</thead> | |||||
<tbody> | |||||
<template v-for="category in categories"> | |||||
<tr v-if="category.id && countProductsByCategory(category)"> | |||||
<td class="category-name" colspan="5" @click="setCategoryCurrent(category)"> | |||||
<span v-if="categoryCurrent && categoryCurrent.id == category.id" class="glyphicon glyphicon-triangle-bottom"></span> | |||||
<span v-else class="glyphicon glyphicon-triangle-right"></span> | |||||
{{ category.name }} | |||||
<span class="label label-default">{{ countProductsByCategory(category) }} produit<template v-if="countProductsByCategory(category) > 1">s</template></span> | |||||
<span v-if="countSelectedProductsByCategory(category) > 0" class="label label-success">{{ countSelectedProductsByCategory(category) }} produit<template v-if="countSelectedProductsByCategory(category) > 1">s</template> sélectionné<template v-if="countSelectedProductsByCategory(category) > 1">s</template></span> | |||||
</td> | </td> | ||||
</tr> | </tr> | ||||
</template> | |||||
</template> | |||||
<tr class="total"> | |||||
<td class="summary" colspan="4"> | |||||
<template v-if="priceTotal() > 0"> | |||||
<h3>> Résumé</h3> | |||||
<ul> | |||||
<li v-for="product in products" v-if="product.quantity_form > 0"> | |||||
<span class="quantity">{{ product.quantity_form }} x</span> | |||||
<template v-if="(categoryCurrent && categoryCurrent.id == category.id) || category.id == null"> | |||||
<tr v-for="product in products" v-if="product.id_product_category == category.id && product.productDistribution && product.productDistribution[0] && product.productDistribution[0].active == 1"> | |||||
<td class="photo"> | |||||
<img v-if="product.photo.length" class="photo-product" :src="'<?php echo Yii::$app->urlManager->getBaseUrl(); ?>/uploads/'+product.photo" /> | |||||
</td> | |||||
<td class="name"> | |||||
<span class="name">{{ product.name }}</span> | <span class="name">{{ product.name }}</span> | ||||
<span class="other"> | <span class="other"> | ||||
<span v-if="product.description.length">/</span> | <span v-if="product.description.length">/</span> | ||||
<span class="description">{{ product.description }}</span> | <span class="description">{{ product.description }}</span> | ||||
<span v-if="product.weight">({{ product.weight }} g)</span> | <span v-if="product.weight">({{ product.weight }} g)</span> | ||||
</li> | |||||
</ul> | |||||
</span> | |||||
<span v-if="product.quantity_max > 0 && ((product.quantity_form / product.coefficient_unit == product.quantity_remaining) || ((product.quantity_remaining * product.coefficient_unit) - product.quantity_form) < product.step)" class="label label-danger"> | |||||
Épuisé | |||||
</span> | |||||
<div class="recipe" v-if="product.recipe.length">{{ product.recipe }}</div> | |||||
</td> | |||||
<td class="price-unit"> | |||||
<template v-if="product.price_with_tax > 0">{{ formatPrice(product.price_with_tax) }}<br /><span class="unit">{{ product.wording_unit }}</span></template> | |||||
</td> | |||||
<td class="td-quantity"> | |||||
<template v-if="product.price_with_tax > 0"> | |||||
<div class="input-group"> | |||||
<span class="input-group-btn"> | |||||
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product, product.unit == 'piece' ? -1 : -parseFloat(product.step))" :disabled="product.quantity_form == 0"><span class="glyphicon glyphicon-minus"></span></button> | |||||
</span> | |||||
<input type="text" v-model="product.quantity_form" class="form-control quantity" readonly="readonly" /> | |||||
<span class="input-group-addon">{{ product.unit == 'piece' ? 'p.' : product.unit }}</span> | |||||
<span class="input-group-btn"> | |||||
<button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product, product.unit == 'piece' ? 1 : parseFloat(product.step))" :disabled="product.quantity_form == product.quantity_remaining && product.quantity_max > 0"><span class="glyphicon glyphicon-plus"></span></button> | |||||
</span> | |||||
</div> | |||||
</template> | |||||
</td> | |||||
<td class="price-total"> | |||||
<template v-if="product.price_with_tax > 0 && product.quantity_form > 0"> | |||||
{{ formatPrice(product.price_with_tax * (product.quantity_form / product.coefficient_unit )) }} | |||||
</template> | |||||
</td> | |||||
</tr> | |||||
</template> | </template> | ||||
</td> | |||||
<td class="price-total">{{ priceTotal(true) }}</td> | |||||
</tr> | |||||
</tbody> | |||||
</table> | |||||
<div class="block-actions"> | |||||
<button class="btn btn-primary" @click="changeStep('payment')">Valider</button> | |||||
</template> | |||||
<tr class="total"> | |||||
<td class="summary" colspan="4"> | |||||
<template v-if="priceTotal() > 0"> | |||||
<h3>> Résumé</h3> | |||||
<ul> | |||||
<li v-for="product in products" v-if="product.quantity_form > 0"> | |||||
<span class="quantity">{{ product.quantity_form }} {{ product.unit == 'piece' ? 'p.' : product.unit }} x</span> | |||||
<span class="name">{{ product.name }}</span> | |||||
<span class="other"> | |||||
<span v-if="product.description.length">/</span> | |||||
<span class="description">{{ product.description }}</span> | |||||
<span v-if="product.weight">({{ product.weight }} g)</span> | |||||
</li> | |||||
</ul> | |||||
</template> | |||||
</td> | |||||
<td class="price-total">{{ priceTotal(true) }}</td> | |||||
</tr> | |||||
</tbody> | |||||
</table> | |||||
<div class="block-actions"> | |||||
<button class="btn btn-primary" @click="changeStep('payment')">Valider</button> | |||||
</div> | |||||
</div> | |||||
<div class="alert alert-warning" v-else> | |||||
Aucun produit disponible | |||||
</div> | </div> | ||||
</div> | |||||
<div class="alert alert-warning" v-else> | |||||
Aucun produit disponible | |||||
</div> | </div> | ||||
</div> | </div> | ||||
</transition> | </transition> | ||||
</div> | </div> | ||||
<?php endif; ?> | <?php endif; ?> | ||||
</div> | </div> | ||||
</div> | |||||
</div> | |||||
<script type="text/x-template" id="template-step-date"> | |||||
<li id="step-date" :class="'col-md-3'+((step == 'date') ? ' active' : '')+(first ? ' first' : '')"> | |||||
<button @click="changeStep('date')" :class="'btn '+ (step == 'date' ? 'btn-primary' : 'btn-default')" :disabled="producer && producer.option_order_entry_point == 'point-sale' && !pointSaleActive"> | |||||
<span class="button-content"><span class="glyphicon glyphicon-time"></span> Date</span></span> | |||||
</button> | |||||
<div class="info-step" v-if="dateFormat"> | |||||
{{ dateFormat }} | |||||
</div> | |||||
</li> | |||||
</script> | |||||
<script type="text/x-template" id="template-step-point-sale"> | |||||
<li id="step-point-sale" :class="'col-md-3'+((step == 'point-sale') ? ' active ' : '')+(first ? ' first' : '')"> | |||||
<button @click="changeStep('point-sale')" :class="'btn '+ (step == 'point-sale' ? 'btn-primary' : 'btn-default')" :disabled="producer && (producer.option_order_entry_point == 'date' && step == 'date')"> | |||||
<span class="button-content"><span class="glyphicon glyphicon-map-marker"></span> Points de vente</span> | |||||
</button> | |||||
<div class="info-step" v-if="pointSaleActive"> | |||||
{{ pointSaleActive.name }} | |||||
</div> | |||||
</li> | |||||
</script> |
top: 10px; | top: 10px; | ||||
} | } | ||||
/* line 61, ../sass/order/_order.scss */ | /* line 61, ../sass/order/_order.scss */ | ||||
.order-order #main #app-order-order #steps ul li#step-date { | |||||
.order-order #main #app-order-order #steps ul li.first { | |||||
padding-left: 0px; | padding-left: 0px; | ||||
} | } | ||||
/* line 65, ../sass/order/_order.scss */ | /* line 65, ../sass/order/_order.scss */ | ||||
padding-right: 0px; | padding-right: 0px; | ||||
} | } | ||||
/* line 69, ../sass/order/_order.scss */ | /* line 69, ../sass/order/_order.scss */ | ||||
.order-order #main #app-order-order #steps ul li#step-payment .btn::after, .order-order #main #app-order-order #steps ul li#step-date .btn::before { | |||||
.order-order #main #app-order-order #steps ul li#step-payment .btn::after, .order-order #main #app-order-order #steps ul li.first .btn::before { | |||||
display: none; | display: none; | ||||
} | } | ||||
/* line 74, ../sass/order/_order.scss */ | /* line 74, ../sass/order/_order.scss */ |
var app = new Vue({ | var app = new Vue({ | ||||
el: '#app-order-order', | el: '#app-order-order', | ||||
data: { | |||||
loading: false, | |||||
loadingInit: true, | |||||
step: 'date', | |||||
producer: null, | |||||
user: null, | |||||
date: null, | |||||
dateFormat: null, | |||||
distributions: [], | |||||
distribution: null, | |||||
pointsSale: [], | |||||
pointSaleActive: null, | |||||
pointsSaleCodes: [], | |||||
products: [], | |||||
categories: [], | |||||
categoryCurrent: null, | |||||
comment: '', | |||||
creditCheckbox: false, | |||||
useCredit: false, | |||||
errors: [], | |||||
disableConfirmButton: false, | |||||
calendar: { | |||||
mode: 'single', | |||||
attrs: [], | |||||
availableDates: [], | |||||
themeStyles: { | |||||
wrapper: { | |||||
background: '#F7F7F7', | |||||
color: '#333', | |||||
border: 'solid 1px #e0e0e0' | |||||
}, | |||||
header: { | |||||
padding: '10px 10px', | |||||
}, | |||||
headerHorizontalDivider: { | |||||
borderTop: 'solid rgba(255, 255, 255, 0.2) 1px', | |||||
width: '80%', | |||||
}, | |||||
weekdays: { | |||||
color: 'gray', | |||||
fontWeight: '600', | |||||
padding: '10px 10px', | |||||
fontSize: '2rem' | |||||
}, | |||||
weeks: { | |||||
padding: '0 15px 15px 15px', | |||||
}, | |||||
dayContent: function(object) { | |||||
var style = { | |||||
fontSize: '1.5rem', | |||||
padding: '20px', | |||||
}; | |||||
return style ; | |||||
data() { | |||||
return Object.assign({ | |||||
loading: false, | |||||
loadingInit: true, | |||||
step: null, | |||||
producer: null, | |||||
user: null, | |||||
date: null, | |||||
dateFormat: null, | |||||
distributions: [], | |||||
distribution: null, | |||||
pointsSale: [], | |||||
pointSaleActive: null, | |||||
pointsSaleCodes: [], | |||||
products: [], | |||||
categories: [], | |||||
categoryCurrent: null, | |||||
comment: '', | |||||
creditCheckbox: false, | |||||
useCredit: false, | |||||
errors: [], | |||||
disableConfirmButton: false, | |||||
calendar: { | |||||
mode: 'single', | |||||
attrs: [], | |||||
availableDates: [], | |||||
themeStyles: { | |||||
wrapper: { | |||||
background: '#F7F7F7', | |||||
color: '#333', | |||||
border: 'solid 1px #e0e0e0' | |||||
}, | |||||
header: { | |||||
padding: '10px 10px', | |||||
}, | |||||
headerHorizontalDivider: { | |||||
borderTop: 'solid rgba(255, 255, 255, 0.2) 1px', | |||||
width: '80%', | |||||
}, | |||||
weekdays: { | |||||
color: 'gray', | |||||
fontWeight: '600', | |||||
padding: '10px 10px', | |||||
fontSize: '2rem' | |||||
}, | |||||
weeks: { | |||||
padding: '0 15px 15px 15px', | |||||
}, | |||||
dayContent: function (object) { | |||||
var style = { | |||||
fontSize: '1.5rem', | |||||
padding: '20px', | |||||
}; | |||||
return style; | |||||
}, | |||||
}, | }, | ||||
}, | |||||
formats: { | |||||
dayPopover: 'DD/MM/YYYY' | |||||
formats: { | |||||
dayPopover: 'DD/MM/YYYY' | |||||
} | |||||
} | } | ||||
}, | |||||
}, window.appInitValues); | |||||
}, | }, | ||||
mounted: function() { | |||||
mounted: function() { | |||||
if($('#order-distribution-date').size() || $('#distribution-date').size()) { | if($('#order-distribution-date').size() || $('#distribution-date').size()) { | ||||
if($('#order-distribution-date').size()) { | if($('#order-distribution-date').size()) { | ||||
this.date = new Date($('#order-distribution-date').html()) ; | this.date = new Date($('#order-distribution-date').html()) ; | ||||
this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/' | this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/' | ||||
+ ('0' + (this.date.getMonth() +1)).slice(-2) + '/' | + ('0' + (this.date.getMonth() +1)).slice(-2) + '/' | ||||
+ this.date.getFullYear() ; | + this.date.getFullYear() ; | ||||
this.changeStep('point-sale') ; | |||||
if(this.producer.option_order_entry_point == 'date') { | |||||
this.changeStep('point-sale') ; | |||||
} | |||||
} | } | ||||
this.init() ; | |||||
this.init('first') ; | |||||
this.loadingInit = false ; | this.loadingInit = false ; | ||||
}, | }, | ||||
methods: { | methods: { | ||||
} | } | ||||
} | } | ||||
}, | }, | ||||
init: function(updateOnlyProducts) { | |||||
init: function(type) { | |||||
var app = this ; | var app = this ; | ||||
this.loading = true ; | this.loading = true ; | ||||
axios.get("ajax-infos",{params: { | axios.get("ajax-infos",{params: { | ||||
date : this.getDate(), | date : this.getDate(), | ||||
pointSaleId: this.pointSaleActive ? this.pointSaleActive.id : 0 | pointSaleId: this.pointSaleActive ? this.pointSaleActive.id : 0 | ||||
}}) | }}) | ||||
.then(function(response) { | .then(function(response) { | ||||
if(!updateOnlyProducts) { | |||||
app.producer = response.data.producer; | |||||
app.user = response.data.user; | |||||
app.useCredit = response.data.producer.use_credit_checked_default; | |||||
app.calendar.attrs = []; | |||||
app.calendar.availableDates = []; | |||||
var distributions = response.data.distributions; | |||||
if (distributions.length) { | |||||
app.distributions = distributions; | |||||
var arrayDate; | |||||
for (var i = 0; i < distributions.length; i++) { | |||||
var distributions = response.data.distributions; | |||||
app.calendar.attrs = []; | |||||
app.calendar.availableDates = []; | |||||
if (distributions.length) { | |||||
app.distributions = distributions; | |||||
var arrayDate; | |||||
for (var i = 0; i < distributions.length; i++) { | |||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
backgroundColor: '#5cb85c', | |||||
}, | |||||
contentStyle: { | |||||
color: 'white', | |||||
}, | |||||
dates: distributions[i].date, | |||||
}); | |||||
arrayDate = distributions[i].date.split('-'); | |||||
app.calendar.availableDates.push({ | |||||
start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]), | |||||
end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) | |||||
}); | |||||
} | |||||
} | |||||
if (response.data.distribution) { | |||||
app.distribution = response.data.distribution; | |||||
} | |||||
var orders = []; | |||||
if (response.data.orders) { | |||||
orders = response.data.orders; | |||||
} | |||||
if (orders.length) { | |||||
for (var i = 0; i < orders.length; i++) { | |||||
arrayDate = orders[i].date_distribution.split('-'); | |||||
var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]); | |||||
if (app.isAvailableDate(dateOrder)) { | |||||
app.calendar.attrs.push({ | app.calendar.attrs.push({ | ||||
highlight: { | highlight: { | ||||
backgroundColor: '#5cb85c', | |||||
backgroundColor: '#FF7F00' | |||||
}, | }, | ||||
contentStyle: { | contentStyle: { | ||||
color: 'white', | |||||
color: 'white' | |||||
}, | }, | ||||
dates: distributions[i].date, | |||||
}); | |||||
arrayDate = distributions[i].date.split('-'); | |||||
app.calendar.availableDates.push({ | |||||
start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]), | |||||
end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]) | |||||
popover: { | |||||
label: orders[i].pointSale.name + ' / ' + app.formatPrice(orders[i].amount_total), | |||||
hideIndicator: true | |||||
}, | |||||
dates: orders[i].date_distribution, | |||||
}); | }); | ||||
} | } | ||||
} | } | ||||
var orders = []; | |||||
if (response.data.orders) { | |||||
orders = response.data.orders; | |||||
} | |||||
} | |||||
if (orders.length) { | |||||
for (var i = 0; i < orders.length; i++) { | |||||
arrayDate = orders[i].date_distribution.split('-'); | |||||
var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]); | |||||
if (app.isAvailableDate(dateOrder)) { | |||||
app.calendar.attrs.push({ | |||||
highlight: { | |||||
backgroundColor: '#FF7F00' | |||||
}, | |||||
contentStyle: { | |||||
color: 'white' | |||||
}, | |||||
popover: { | |||||
label: orders[i].pointSale.name + ' / ' + app.formatPrice(orders[i].amount_total), | |||||
hideIndicator: true | |||||
}, | |||||
dates: orders[i].date_distribution, | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
if(response.data.products) { | |||||
app.products = response.data.products ; | |||||
} | |||||
if (response.data.distribution) { | |||||
app.distribution = response.data.distribution; | |||||
} | |||||
if(response.data.categories) { | |||||
app.categories = response.data.categories ; | |||||
app.setCategoryCurrent(response.data.categories[0]) ; | |||||
} | |||||
if(type != 'products') { | |||||
app.producer = response.data.producer; | |||||
app.user = response.data.user; | |||||
app.useCredit = response.data.producer.use_credit_checked_default; | |||||
if (response.data.points_sale) { | if (response.data.points_sale) { | ||||
app.pointsSale = []; | app.pointsSale = []; | ||||
Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, ''); | Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, ''); | ||||
} | } | ||||
} | } | ||||
} | |||||
if(response.data.products) { | |||||
app.products = response.data.products ; | |||||
} | |||||
if(response.data.categories) { | |||||
app.categories = response.data.categories ; | |||||
console.log(response.data.categories[0]) ; | |||||
app.setCategoryCurrent(response.data.categories[0]) ; | |||||
} | |||||
if(!updateOnlyProducts) { | |||||
app.order = null ; | app.order = null ; | ||||
if(response.data.order) { | if(response.data.order) { | ||||
app.order = response.data.order ; | app.order = response.data.order ; | ||||
} | } | ||||
} | } | ||||
if(type == 'first') { | |||||
if(app.producer.option_order_entry_point == 'point-sale') { | |||||
app.step = 'point-sale' ; | |||||
} | |||||
else { | |||||
app.step = 'date' ; | |||||
} | |||||
} | |||||
app.loading = false ; | app.loading = false ; | ||||
}); | }); | ||||
}, | }, | ||||
nextStep: function() { | |||||
this.errors = [] ; | |||||
var oldStep = this.step ; | |||||
var nextStep = null ; | |||||
// par point de vente | |||||
if(this.producer && this.producer.option_order_entry_point == 'point-sale') { | |||||
if(oldStep == 'point-sale') { | |||||
nextStep = 'date' ; | |||||
} | |||||
else if(oldStep == 'date') { | |||||
nextStep = 'products' ; | |||||
} | |||||
} | |||||
// par date | |||||
else { | |||||
if(oldStep == 'date') { | |||||
nextStep = 'point-sale' ; | |||||
} | |||||
else if(oldStep == 'point-sale') { | |||||
nextStep = 'products' ; | |||||
} | |||||
} | |||||
if(nextStep) { | |||||
this.changeStep(nextStep) ; | |||||
} | |||||
}, | |||||
changeStep: function(step) { | changeStep: function(step) { | ||||
this.errors = [] ; | this.errors = [] ; | ||||
var oldStep = this.step ; | var oldStep = this.step ; | ||||
if(!this.errors.length) { | if(!this.errors.length) { | ||||
this.step = step ; | this.step = step ; | ||||
window.scroll(0, $('#page-title').position().top - 25) ; | window.scroll(0, $('#page-title').position().top - 25) ; | ||||
if(oldStep == 'date' && step == 'point-sale') { | if(oldStep == 'date' && step == 'point-sale') { | ||||
this.init() ; | |||||
this.init('basic') ; | |||||
} | |||||
if((oldStep == 'date' && step == 'products') | |||||
|| (oldStep == 'point-sale' && step == 'products') | |||||
|| (oldStep == 'point-sale' && step == 'date')) { | |||||
this.init('products') ; | |||||
} | } | ||||
} | } | ||||
}, | }, | ||||
this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/' | this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/' | ||||
+ ('0' + (this.date.getMonth() +1)).slice(-2) + '/' | + ('0' + (this.date.getMonth() +1)).slice(-2) + '/' | ||||
+ this.date.getFullYear() ; | + this.date.getFullYear() ; | ||||
this.changeStep('point-sale') ; | |||||
this.nextStep() ; | |||||
}, | }, | ||||
isAvailableDate: function(date) { | isAvailableDate: function(date) { | ||||
for(var key in this.calendar.availableDates) { | for(var key in this.calendar.availableDates) { | ||||
else { | else { | ||||
this.validatePointSale(idPointSale) ; | this.validatePointSale(idPointSale) ; | ||||
} | } | ||||
app.init(true) ; | |||||
}, | }, | ||||
validatePointSale: function(idPointSale) { | validatePointSale: function(idPointSale) { | ||||
if(this.pointSaleActive.credit_functioning == 'mandatory' || (this.pointSaleActive.credit_functioning == 'user' && this.user.credit_active)) { | if(this.pointSaleActive.credit_functioning == 'mandatory' || (this.pointSaleActive.credit_functioning == 'user' && this.user.credit_active)) { | ||||
this.useCredit = true ; | this.useCredit = true ; | ||||
} | } | ||||
this.changeStep('products') ; | |||||
this.nextStep() ; | |||||
}, | }, | ||||
productQuantityClick: function(product, quantity) { | productQuantityClick: function(product, quantity) { | ||||
if( this.products[product.index].quantity_form + quantity >= 0 && | if( this.products[product.index].quantity_form + quantity >= 0 && | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
}); | |||||
}); | |||||
Vue.component('step-date',{ | |||||
props: [ | |||||
'step', | |||||
'pointSaleActive', | |||||
'dateFormat', | |||||
'changeStep', | |||||
'producer', | |||||
'first', | |||||
], | |||||
data: function() { | |||||
return { | |||||
} ; | |||||
}, | |||||
template: '#template-step-date', | |||||
methods: { | |||||
} | |||||
}) ; | |||||
Vue.component('step-point-sale',{ | |||||
props: [ | |||||
'step', | |||||
'pointSaleActive', | |||||
'changeStep', | |||||
'producer', | |||||
'first', | |||||
], | |||||
data: function() { | |||||
return { | |||||
} ; | |||||
}, | |||||
template: '#template-step-point-sale', | |||||
methods: { | |||||
} | |||||
}) ; |
position: relative ; | position: relative ; | ||||
top: 10px ; | top: 10px ; | ||||
} | } | ||||
&#step-date { | |||||
&.first { | |||||
padding-left: 0px ; | padding-left: 0px ; | ||||
} | } | ||||
} | } | ||||
&#step-payment .btn::after, | &#step-payment .btn::after, | ||||
&#step-date .btn::before { | |||||
&.first .btn::before { | |||||
display: none ; | display: none ; | ||||
} | } | ||||