'quantity' => 0, | 'quantity' => 0, | ||||
'unit' => $product->unit, | 'unit' => $product->unit, | ||||
'price' => $product->getPriceWithTax([ | '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)) | |||||
]; | ]; | ||||
} | } | ||||
:users="users" | :users="users" | ||||
:products="products" | :products="products" | ||||
:producer="producer" | :producer="producer" | ||||
:loading-update-product-order="loadingUpdateProductOrder" | |||||
@close="showModalFormOrderCreate = false" | @close="showModalFormOrderCreate = false" | ||||
@ordercreatedupdated="orderCreatedUpdated" | @ordercreatedupdated="orderCreatedUpdated" | ||||
@updateproductorderprices="updateProductOrderPrices" | @updateproductorderprices="updateProductOrderPrices" | ||||
:products="products" | :products="products" | ||||
:order="ordersUpdate[key]" | :order="ordersUpdate[key]" | ||||
:producer="producer" | :producer="producer" | ||||
:loading-update-product-order="loadingUpdateProductOrder" | |||||
@close="showModalFormOrderUpdate = false" | @close="showModalFormOrderUpdate = false" | ||||
@ordercreatedupdated="orderCreatedUpdated" | @ordercreatedupdated="orderCreatedUpdated" | ||||
@updateproductorderprices="updateProductOrderPrices" | @updateproductorderprices="updateProductOrderPrices" | ||||
<tbody> | <tbody> | ||||
<tr v-for="product in products" :class="(order.productOrder[product.id] > 0) ? 'product-ordered' : ''"> | <tr v-for="product in products" :class="(order.productOrder[product.id] > 0) ? 'product-ordered' : ''"> | ||||
<td> | <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> | <span class="label label-danger" v-else>Inactif</span> | ||||
</td> | </td> | ||||
<td>{{ product.name }}</td> | <td>{{ product.name }}</td> |
<h2>Disponibilité points de vente</h2> | <h2>Disponibilité points de vente</h2> | ||||
<?= $form->field($model, 'available_on_points_sale')->radioList([1 => 'Disponible', 0 => 'Indisponible']) ?> | <?= $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() | <?php $pointSaleArray = PointSale::find() | ||||
->where(['id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['id_producer' => GlobalParam::getCurrentProducerId()]) | ||||
->orderBy('is_bread_box ASC, name ASC') | ->orderBy('is_bread_box ASC, name ASC') |
display: block; | display: block; | ||||
margin-bottom: 6px; | 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-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 { | .product-update #availability-points-sale .field-product-available_on_points_sale label.control-label { | ||||
margin-bottom: 0px; | 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-create #availability-points-sale #product-pointssale label, | ||||
.product-update #availability-points-sale #product-pointssale label { | .product-update #availability-points-sale #product-pointssale label { | ||||
display: block; | display: block; |
function opendistrib_product_availability_points_sale() { | function opendistrib_product_availability_points_sale() { | ||||
$('input[name="Product[available_on_points_sale]"]').change(function() { | $('input[name="Product[available_on_points_sale]"]').change(function() { | ||||
var available = parseInt($(this).val()); | var available = parseInt($(this).val()); | ||||
var label = 'Disponible'; | |||||
var label = 'disponible'; | |||||
if(available == 1) { | if(available == 1) { | ||||
label = 'Indisponible'; | |||||
label = 'indisponible'; | |||||
} | } | ||||
$('#label-availability-points-sale span').html(label); | $('#label-availability-points-sale span').html(label); |
checkboxSelectAllOrders: false, | checkboxSelectAllOrders: false, | ||||
messageGenerateDeliveryNoteDisplayed: false, | messageGenerateDeliveryNoteDisplayed: false, | ||||
missingSubscriptions: false, | missingSubscriptions: false, | ||||
loadingUpdateProductOrder: false, | |||||
calendar: { | calendar: { | ||||
mode: 'single', | mode: 'single', | ||||
attrs: [], | attrs: [], | ||||
this.idOrderUpdate = idOrder ; | this.idOrderUpdate = idOrder ; | ||||
this.showModalFormOrderUpdate = true ; | this.showModalFormOrderUpdate = true ; | ||||
this.initModalFormOrder() ; | this.initModalFormOrder() ; | ||||
this.updateProductOrderPrices(); | |||||
}, | }, | ||||
openModalFormOrderCreate: function() { | openModalFormOrderCreate: function() { | ||||
this.showModalFormOrderCreate = true ; | this.showModalFormOrderCreate = true ; | ||||
updateProductOrderPrices: function() { | updateProductOrderPrices: function() { | ||||
var app = this ; | var app = this ; | ||||
app.loadingUpdateProductOrder = true; | |||||
var order = null ; | var order = null ; | ||||
if(app.showModalFormOrderCreate) { | if(app.showModalFormOrderCreate) { | ||||
for (idProduct in response.data) { | for (idProduct in response.data) { | ||||
if (app.showModalFormOrderCreate) { | if (app.showModalFormOrderCreate) { | ||||
Vue.set(app.orderCreate.productOrder[idProduct], 'price', response.data[idProduct].price); | 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) { | if (app.showModalFormOrderUpdate && app.idOrderUpdate) { | ||||
for (keyOrderUpdate in app.ordersUpdate) { | for (keyOrderUpdate in app.ordersUpdate) { | ||||
if (order.id == app.idOrderUpdate) { | if (order.id == app.idOrderUpdate) { | ||||
Vue.set(app.ordersUpdate[keyOrderUpdate].productOrder[idProduct], 'price', response.data[idProduct].price); | 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; | |||||
}); | }); | ||||
} | } | ||||
} | } | ||||
}) | }) | ||||
Vue.component('order-form',{ | Vue.component('order-form',{ | ||||
props: ['date', 'pointsSale','meansPayment', 'users', 'products', 'order', 'producer'], | |||||
props: ['date', 'pointsSale','meansPayment', 'users', 'products', 'order', 'producer', 'loadingUpdateProductOrder'], | |||||
data: function() { | data: function() { | ||||
return { | return { | ||||
errors: [], | errors: [], |
#label-availability-points-sale { | #label-availability-points-sale { | ||||
display: block; | display: block; | ||||
margin-bottom: 6px; | margin-bottom: 6px; | ||||
span { | |||||
border-bottom: dotted 1px black; | |||||
} | |||||
} | } | ||||
.field-product-available_on_points_sale { | .field-product-available_on_points_sale { | ||||
label.control-label { | label.control-label { | ||||
margin-bottom: 0px; | margin-bottom: 0px; | ||||
position: relative; | |||||
top: 3px; | |||||
} | } | ||||
} | } | ||||
]; | ]; | ||||
} | } | ||||
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. | * Retourne la description du produit. | ||||
* | * |
]); | ]); | ||||
$productsArray = $productsArray->joinWith([ | $productsArray = $productsArray->joinWith([ | ||||
'productDistribution' => function ($query) use ( | |||||
$distribution | |||||
) { | |||||
'productDistribution' => function ($query) use ($distribution) { | |||||
$query->andOnCondition( | $query->andOnCondition( | ||||
'product_distribution.id_distribution = ' . $distribution->id | 'product_distribution.id_distribution = ' . $distribution->id | ||||
); | ); | ||||
}, | }, | ||||
/*'productPointSale' => function ($query) use ($pointSaleCurrent) { | |||||
$query->andOnCondition( | |||||
'product_point_sale.id_point_sale = ' . $pointSaleCurrent->id | |||||
); | |||||
},*/ | |||||
'productPrice' | 'productPrice' | ||||
]) | ]) | ||||
->orderBy('product_distribution.active DESC, order ASC') | ->orderBy('product_distribution.active DESC, order ASC') | ||||
->all(); | ->all(); | ||||
$productsArrayFilter = []; | |||||
// filtre sur les points de vente | |||||
foreach($productsArray as $product) { | |||||
if($product->isAvailableOnPointSale($pointSaleCurrent)) { | |||||
$productsArrayFilter[] = $product; | |||||
} | |||||
} | |||||
$indexProduct = 0; | $indexProduct = 0; | ||||
foreach ($productsArray as &$product) { | |||||
foreach ($productsArrayFilter as $key => &$product) { | |||||
$product = array_merge( | $product = array_merge( | ||||
$product->getAttributes(), | $product->getAttributes(), | ||||
[ | [ | ||||
'user_producer' => $userProducer, | 'user_producer' => $userProducer, | ||||
'point_sale' => $pointSaleCurrent | 'point_sale' => $pointSaleCurrent | ||||
]), | ]), | ||||
'productDistribution' => $product['productDistribution'] | |||||
'productDistribution' => $product['productDistribution'], | |||||
'productPointSale' => $product['productPointSale'], | |||||
] | ] | ||||
); | ); | ||||
$product['index'] = $indexProduct++; | $product['index'] = $indexProduct++; | ||||
} | } | ||||
$json['products'] = $productsArray; | |||||
$json['products'] = $productsArrayFilter; | |||||
} else { | } else { | ||||
$json['points_sale'] = $this->_initPointsSale($producer->id); | $json['points_sale'] = $this->_initPointsSale($producer->id); | ||||
} | } |