@@ -423,10 +423,12 @@ class DistributionController extends BackendController | |||
'quantity' => 0, | |||
'unit' => $product->unit, | |||
'price' => $product->getPriceWithTax([ | |||
'user' => $user, | |||
'user_producer' => $userProducer, | |||
'point_sale' => $pointSale | |||
]), | |||
'user' => $user, | |||
'user_producer' => $userProducer, | |||
'point_sale' => $pointSale | |||
]), | |||
'active' => $product->productDistribution[0]->active | |||
&& (!$pointSale || $product->isAvailableOnPointSale($pointSale)) | |||
]; | |||
} | |||
@@ -229,6 +229,7 @@ $this->setPageTitle('Distributions') ; | |||
:users="users" | |||
:products="products" | |||
:producer="producer" | |||
:loading-update-product-order="loadingUpdateProductOrder" | |||
@close="showModalFormOrderCreate = false" | |||
@ordercreatedupdated="orderCreatedUpdated" | |||
@updateproductorderprices="updateProductOrderPrices" | |||
@@ -401,6 +402,7 @@ $this->setPageTitle('Distributions') ; | |||
:products="products" | |||
:order="ordersUpdate[key]" | |||
:producer="producer" | |||
:loading-update-product-order="loadingUpdateProductOrder" | |||
@close="showModalFormOrderUpdate = false" | |||
@ordercreatedupdated="orderCreatedUpdated" | |||
@updateproductorderprices="updateProductOrderPrices" | |||
@@ -606,7 +608,7 @@ $this->setPageTitle('Distributions') ; | |||
<tbody> | |||
<tr v-for="product in products" :class="(order.productOrder[product.id] > 0) ? 'product-ordered' : ''"> | |||
<td> | |||
<span class="label label-success" v-if="product.productDistribution[0].active == 1">Actif</span> | |||
<span class="label label-success" v-if="loadingUpdateProductOrder || order.productOrder[product.id].active">Actif</span> | |||
<span class="label label-danger" v-else>Inactif</span> | |||
</td> | |||
<td>{{ product.name }}</td> |
@@ -138,7 +138,7 @@ use common\helpers\GlobalParam; | |||
<h2>Disponibilité points de vente</h2> | |||
<?= $form->field($model, 'available_on_points_sale')->radioList([1 => 'Disponible', 0 => 'Indisponible']) ?> | |||
<strong id="label-availability-points-sale"><span><?php if($model->available_on_points_sale): ?>Indisponible<?php else: ?>Disponible<?php endif; ?></span> sur les points de vente</strong> | |||
<strong id="label-availability-points-sale">Et <span><?php if($model->available_on_points_sale): ?>indisponible<?php else: ?>disponible<?php endif; ?></span> sur les points de vente</strong> | |||
<?php $pointSaleArray = PointSale::find() | |||
->where(['id_producer' => GlobalParam::getCurrentProducerId()]) | |||
->orderBy('is_bread_box ASC, name ASC') |
@@ -1850,12 +1850,19 @@ body.login-page .login-box .login-box-body a:hover { | |||
display: block; | |||
margin-bottom: 6px; | |||
} | |||
/* line 32, ../sass/product/_form.scss */ | |||
/* line 30, ../sass/product/_form.scss */ | |||
.product-create #availability-points-sale #label-availability-points-sale span, | |||
.product-update #availability-points-sale #label-availability-points-sale span { | |||
border-bottom: dotted 1px black; | |||
} | |||
/* line 36, ../sass/product/_form.scss */ | |||
.product-create #availability-points-sale .field-product-available_on_points_sale label.control-label, | |||
.product-update #availability-points-sale .field-product-available_on_points_sale label.control-label { | |||
margin-bottom: 0px; | |||
position: relative; | |||
top: 3px; | |||
} | |||
/* line 38, ../sass/product/_form.scss */ | |||
/* line 44, ../sass/product/_form.scss */ | |||
.product-create #availability-points-sale #product-pointssale label, | |||
.product-update #availability-points-sale #product-pointssale label { | |||
display: block; |
@@ -61,9 +61,9 @@ var UrlManager = { | |||
function opendistrib_product_availability_points_sale() { | |||
$('input[name="Product[available_on_points_sale]"]').change(function() { | |||
var available = parseInt($(this).val()); | |||
var label = 'Disponible'; | |||
var label = 'disponible'; | |||
if(available == 1) { | |||
label = 'Indisponible'; | |||
label = 'indisponible'; | |||
} | |||
$('#label-availability-points-sale span').html(label); |
@@ -76,6 +76,7 @@ var app = new Vue({ | |||
checkboxSelectAllOrders: false, | |||
messageGenerateDeliveryNoteDisplayed: false, | |||
missingSubscriptions: false, | |||
loadingUpdateProductOrder: false, | |||
calendar: { | |||
mode: 'single', | |||
attrs: [], | |||
@@ -364,6 +365,7 @@ var app = new Vue({ | |||
this.idOrderUpdate = idOrder ; | |||
this.showModalFormOrderUpdate = true ; | |||
this.initModalFormOrder() ; | |||
this.updateProductOrderPrices(); | |||
}, | |||
openModalFormOrderCreate: function() { | |||
this.showModalFormOrderCreate = true ; | |||
@@ -569,6 +571,7 @@ var app = new Vue({ | |||
updateProductOrderPrices: function() { | |||
var app = this ; | |||
app.loadingUpdateProductOrder = true; | |||
var order = null ; | |||
if(app.showModalFormOrderCreate) { | |||
@@ -595,17 +598,21 @@ var app = new Vue({ | |||
for (idProduct in response.data) { | |||
if (app.showModalFormOrderCreate) { | |||
Vue.set(app.orderCreate.productOrder[idProduct], 'price', response.data[idProduct].price); | |||
Vue.set(app.orderCreate.productOrder[idProduct], 'active', response.data[idProduct].active); | |||
} | |||
if (app.showModalFormOrderUpdate && app.idOrderUpdate) { | |||
for (keyOrderUpdate in app.ordersUpdate) { | |||
if (order.id == app.idOrderUpdate) { | |||
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'price', response.data[idProduct].price); | |||
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'active', response.data[idProduct].active); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
app.loadingUpdateProductOrder = false; | |||
}); | |||
} | |||
} | |||
@@ -617,7 +624,7 @@ Vue.component('modal', { | |||
}) | |||
Vue.component('order-form',{ | |||
props: ['date', 'pointsSale','meansPayment', 'users', 'products', 'order', 'producer'], | |||
props: ['date', 'pointsSale','meansPayment', 'users', 'products', 'order', 'producer', 'loadingUpdateProductOrder'], | |||
data: function() { | |||
return { | |||
errors: [], |
@@ -26,11 +26,17 @@ | |||
#label-availability-points-sale { | |||
display: block; | |||
margin-bottom: 6px; | |||
span { | |||
border-bottom: dotted 1px black; | |||
} | |||
} | |||
.field-product-available_on_points_sale { | |||
label.control-label { | |||
margin-bottom: 0px; | |||
position: relative; | |||
top: 3px; | |||
} | |||
} | |||
@@ -237,6 +237,34 @@ class Product extends ActiveRecordCommon | |||
]; | |||
} | |||
public function isAvailableOnPointSale($pointSale) | |||
{ | |||
// disponible par défaut | |||
if($this->available_on_points_sale) { | |||
foreach($this->productPointSale as $productPointSale) { | |||
if($pointSale->id == $productPointSale->id_point_sale | |||
//&& $productPointSale->id_product == $this->id | |||
&& !$productPointSale->available) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
// indisponible par défaut | |||
else { | |||
foreach($this->productPointSale as $productPointSale) { | |||
if($pointSale->id == $productPointSale->id_point_sale | |||
//&& $productPointSale->id_product == $this->id | |||
&& $productPointSale->available) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
} | |||
/** | |||
* Retourne la description du produit. | |||
* |
@@ -810,20 +810,32 @@ class OrderController extends ProducerBaseController | |||
]); | |||
$productsArray = $productsArray->joinWith([ | |||
'productDistribution' => function ($query) use ( | |||
$distribution | |||
) { | |||
'productDistribution' => function ($query) use ($distribution) { | |||
$query->andOnCondition( | |||
'product_distribution.id_distribution = ' . $distribution->id | |||
); | |||
}, | |||
/*'productPointSale' => function ($query) use ($pointSaleCurrent) { | |||
$query->andOnCondition( | |||
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id | |||
); | |||
},*/ | |||
'productPrice' | |||
]) | |||
->orderBy('product_distribution.active DESC, order ASC') | |||
->all(); | |||
$productsArrayFilter = []; | |||
// filtre sur les points de vente | |||
foreach($productsArray as $product) { | |||
if($product->isAvailableOnPointSale($pointSaleCurrent)) { | |||
$productsArrayFilter[] = $product; | |||
} | |||
} | |||
$indexProduct = 0; | |||
foreach ($productsArray as &$product) { | |||
foreach ($productsArrayFilter as $key => &$product) { | |||
$product = array_merge( | |||
$product->getAttributes(), | |||
[ | |||
@@ -832,7 +844,8 @@ class OrderController extends ProducerBaseController | |||
'user_producer' => $userProducer, | |||
'point_sale' => $pointSaleCurrent | |||
]), | |||
'productDistribution' => $product['productDistribution'] | |||
'productDistribution' => $product['productDistribution'], | |||
'productPointSale' => $product['productPointSale'], | |||
] | |||
); | |||
@@ -870,7 +883,7 @@ class OrderController extends ProducerBaseController | |||
$product['index'] = $indexProduct++; | |||
} | |||
$json['products'] = $productsArray; | |||
$json['products'] = $productsArrayFilter; | |||
} else { | |||
$json['points_sale'] = $this->_initPointsSale($producer->id); | |||
} |