@@ -164,8 +164,13 @@ class DistributionController extends BackendController | |||
foreach($productsArray as &$theProduct) { | |||
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ; | |||
$theProduct['quantity_ordered'] = $quantityOrder ; | |||
$theProduct['quantity_remaining'] = $theProduct['quantity_max'] - $quantityOrder ; | |||
if($theProduct['quantity_remaining'] < 0) $theProduct['quantity_remaining'] = 0 ; | |||
if(!is_numeric($theProduct['productDistribution'][0]['quantity_max'])) { | |||
$theProduct['quantity_remaining'] = null ; | |||
} | |||
else { | |||
$theProduct['quantity_remaining'] = $theProduct['productDistribution'][0]['quantity_max'] - $quantityOrder ; | |||
} | |||
$theProduct['quantity_form'] = 0 ; | |||
if($theProduct['productDistribution'][0]['active'] && $theProduct['productDistribution'][0]['quantity_max']) { | |||
@@ -181,11 +186,24 @@ class DistributionController extends BackendController | |||
// orders as array | |||
if($ordersArray) { | |||
foreach($ordersArray as &$order) { | |||
$productOrderArray = \yii\helpers\ArrayHelper::map($order->productOrder, 'id_product', 'quantity') ; | |||
foreach($ordersArray as &$order) { | |||
$productOrderArray = [] ; | |||
foreach($order->productOrder as $productOrder) { | |||
$productOrderArray[$productOrder->id_product] = [ | |||
'quantity' => $productOrder->quantity * Product::$unitsArray[$productOrder->unit]['coefficient'], | |||
'unit' => $productOrder->unit, | |||
] ; | |||
} | |||
/*$productOrderArray = \yii\helpers\ArrayHelper::map($order->productOrder, 'id_product', 'quantity') ; | |||
*/ | |||
foreach($productsArray as $product) { | |||
if(!isset($productOrderArray[$product['id']])) { | |||
$productOrderArray[$product['id']] = 0 ; | |||
$productOrderArray[$product['id']] = [ | |||
'quantity' => 0, | |||
'unit' => $product['unit'] | |||
] ; | |||
} | |||
} | |||
@@ -254,7 +272,10 @@ class DistributionController extends BackendController | |||
// order create | |||
$productOrderArray = [] ; | |||
foreach($productsArray as $product) { | |||
$productOrderArray[$product['id']] = 0 ; | |||
$productOrderArray[$product['id']] = [ | |||
'quantity' => 0, | |||
'unit' => $product['unit'] | |||
] ; | |||
} | |||
$json['order_create'] = [ | |||
'id_point_sale' => $idPointSaleDefault, |
@@ -860,13 +860,15 @@ class OrderController extends BackendController | |||
$order->save(); | |||
foreach ($products as $key => $quantity) { | |||
foreach ($products as $key => $dataProductOrder) { | |||
$product = Product::findOne($key); | |||
$quantity = $dataProductOrder->quantity / Product::$unitsArray[$dataProductOrder->unit]['coefficient'] ; | |||
if ($product && $quantity) { | |||
$productOrder = new ProductOrder; | |||
$productOrder->id_order = $order->id; | |||
$productOrder->id_product = $key; | |||
$productOrder->quantity = $quantity; | |||
$productOrder->unit = $product->unit; | |||
$productOrder->price = $product->price; | |||
$productOrder->save(); | |||
} | |||
@@ -906,12 +908,15 @@ class OrderController extends BackendController | |||
$order->distribution->id_producer == Producer::getId()) { | |||
$products = json_decode($products); | |||
foreach ($products as $key => $quantity) { | |||
foreach ($products as $key => $dataProductOrder) { | |||
$productOrder = ProductOrder::findOne([ | |||
'id_order' => $idOrder, | |||
'id_product' => $key | |||
]); | |||
$quantity = $dataProductOrder->quantity | |||
/ Product::$unitsArray[$dataProductOrder->unit]['coefficient'] ; | |||
if ($quantity) { | |||
if ($productOrder) { | |||
$productOrder->quantity = $quantity; | |||
@@ -923,6 +928,7 @@ class OrderController extends BackendController | |||
$productOrder->id_order = $idOrder; | |||
$productOrder->id_product = $key; | |||
$productOrder->quantity = $quantity; | |||
$productOrder->unit = $product->unit; | |||
$productOrder->price = $product->price; | |||
} | |||
} |
@@ -119,8 +119,14 @@ $this->setPageTitle('Distributions') ; | |||
<button class="btn btn-default" v-else data-active-product="0" :data-id-product="product.id" @click="productActiveClick"><span class="glyphicon glyphicon-remove"></span></button> | |||
</td> | |||
<td>{{ product.name }}</td> | |||
<td class="quantity-ordered">{{ product.quantity_ordered ? product.quantity_ordered : '-' }}</td> | |||
<td class="quantity-max"><input type="text" class="form-control quantity-max" placeholder="∞" :data-id-product="product.id" v-model="product.productDistribution[0].quantity_max" @keyup="productQuantityMaxChange" /></td> | |||
<td class="quantity-ordered">{{ product.quantity_ordered ? product.quantity_ordered + ' '+ ((product.unit == 'piece') ? ' p.' : ' '+(product.unit == 'g' || product.unit == 'kg') ? 'kg' : 'litre(s)') : '∅' }}</td> | |||
<td class="quantity-max"> | |||
<div class="input-group"> | |||
<input type="text" class="form-control quantity-max" placeholder="∞" :data-id-product="product.id" v-model="product.productDistribution[0].quantity_max" @keyup="productQuantityMaxChange" /> | |||
<span class="input-group-addon">{{ (product.unit == 'piece') ? 'p.' : ' '+((product.unit == 'g' || product.unit == 'kg') ? 'kg' : 'litre(s)') }}</span> | |||
</div> | |||
</td> | |||
</tr> | |||
</tbody> | |||
</table> | |||
@@ -415,8 +421,8 @@ $this->setPageTitle('Distributions') ; | |||
<td colspan="6"> | |||
<strong><span class="glyphicon glyphicon-menu-right"></span> Produits</strong> | |||
<ul> | |||
<li v-for="product in products" v-if="order.productOrder[product.id] > 0"> | |||
{{ order.productOrder[product.id] }} x {{ product.name }} <span v-if="product.productDistribution[0].active == 0" class="glyphicon glyphicon-warning-sign" title="Ce produit n'est pas activé"></span> | |||
<li v-for="product in products" v-if="order.productOrder[product.id].quantity > 0"> | |||
{{ product.name }} : {{ order.productOrder[product.id].quantity }} {{ order.productOrder[product.id].unit == 'piece' ? ' pièce(s)' : ' '+order.productOrder[product.id].unit }} <span v-if="product.productDistribution[0].active == 0" class="glyphicon glyphicon-warning-sign" title="Ce produit n'est pas activé"></span> | |||
</li> | |||
</ul> | |||
<div v-if="order.comment && order.comment.length > 0" class="comment"> | |||
@@ -468,6 +474,14 @@ $this->setPageTitle('Distributions') ; | |||
<div class="col-md-8"> | |||
<label class="control-label">Produits</label> | |||
<table class="table table-condensed table-bordered table-hover table-products"> | |||
<thead> | |||
<tr> | |||
<th></th> | |||
<th>Nom</th> | |||
<th>Quantité</th> | |||
<th>Reste</th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
<tr v-for="product in products" :class="(order.productOrder[product.id] > 0) ? 'product-ordered' : ''"> | |||
<td> | |||
@@ -478,15 +492,18 @@ $this->setPageTitle('Distributions') ; | |||
<td class="quantity"> | |||
<div class="input-group"> | |||
<span class="input-group-btn"> | |||
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product.id, -1)"><span class="glyphicon glyphicon-minus"></span></button> | |||
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product.id, order.productOrder[product.id].unit == 'piece' ? -1 : -parseFloat(product.step))"><span class="glyphicon glyphicon-minus"></span></button> | |||
</span> | |||
<input type="text" v-model="order.productOrder[product.id]" class="form-control" /> | |||
<input type="text" v-model="order.productOrder[product.id].quantity" class="form-control" /> | |||
<span class="input-group-addon">{{ order.productOrder[product.id].unit == 'piece' ? 'p.' : order.productOrder[product.id].unit }}</span> | |||
<span class="input-group-btn"> | |||
<button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product.id, 1)"><span class="glyphicon glyphicon-plus"></span></button> | |||
<button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product.id, order.productOrder[product.id].unit == 'piece' ? 1 : parseFloat(product.step))"><span class="glyphicon glyphicon-plus"></span></button> | |||
</span> | |||
</div> | |||
</td> | |||
<td class="quantity-remaining">/ {{ product.quantity_remaining }}</td> | |||
<td class="quantity-remaining infinite" v-if="product.quantity_remaining === null || order.productOrder[product.id].unit != product.unit">∞</td> | |||
<td class="quantity-remaining negative" v-else-if="product.quantity_remaining <= 0">{{ product.quantity_remaining }} {{ order.productOrder[product.id].unit == 'piece' ? ' p.' : ' '+(order.productOrder[product.id].unit == 'g' || order.productOrder[product.id].unit == 'kg') ? 'kg' : 'litre(s)' }}</td> | |||
<td class="quantity-remaining has-quantity" v-else>{{ product.quantity_remaining }} {{ order.productOrder[product.id].unit == 'piece' ? ' p.' : ' '+(order.productOrder[product.id].unit == 'g' || order.productOrder[product.id].unit == 'kg') ? 'kg' : 'litre(s)' }}</td> | |||
</tr> | |||
</tbody> | |||
</table> |
@@ -1892,7 +1892,7 @@ termes. | |||
} | |||
/* line 155, ../sass/distribution/_index.scss */ | |||
.distribution-index #modal-products table.table td.quantity-max { | |||
width: 70px; | |||
width: 120px; | |||
} | |||
/* line 158, ../sass/distribution/_index.scss */ | |||
.distribution-index #modal-products table.table td.quantity-max input { | |||
@@ -1988,30 +1988,55 @@ termes. | |||
} | |||
/* line 267, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity { | |||
width: 150px; | |||
width: 165px; | |||
} | |||
/* line 270, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity input { | |||
text-align: center; | |||
color: gray; | |||
color: black; | |||
} | |||
/* line 276, ../sass/distribution/_index.scss */ | |||
/* line 274, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity .form-control { | |||
border-right: 0px none; | |||
padding-right: 4px; | |||
} | |||
/* line 278, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity .input-group-addon { | |||
padding: 5px; | |||
padding-left: 0px; | |||
margin: 0px; | |||
border-left: 0px none; | |||
border-right: 0px none; | |||
} | |||
/* line 286, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity-remaining { | |||
text-align: right; | |||
} | |||
/* line 282, ../sass/distribution/_index.scss */ | |||
/* line 289, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity-remaining.quantity-remaining, .distribution-index .modal-form-order table.table-products td.quantity-remaining.infinite { | |||
color: #00A65A; | |||
} | |||
/* line 293, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity-remaining.negative { | |||
color: #DD4B39; | |||
} | |||
/* line 297, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order table.table-products td.quantity-remaining.infinite, .distribution-index .modal-form-order table.table-products td.quantity-remaining.empty { | |||
font-size: 18px; | |||
} | |||
/* line 304, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-form-order .actions-form button { | |||
margin-left: 15px; | |||
} | |||
/* line 290, ../sass/distribution/_index.scss */ | |||
/* line 312, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-payment .info-box .info-box-icon { | |||
width: 50px; | |||
} | |||
/* line 292, ../sass/distribution/_index.scss */ | |||
/* line 314, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-payment .info-box .info-box-icon i { | |||
font-size: 30px; | |||
} | |||
/* line 296, ../sass/distribution/_index.scss */ | |||
/* line 318, ../sass/distribution/_index.scss */ | |||
.distribution-index .modal-payment .info-box .info-box-content { | |||
margin-left: 50px; | |||
} |
@@ -428,7 +428,7 @@ Vue.component('order-form',{ | |||
var countProducts = 0 ; | |||
for(var key in this.order.productOrder) { | |||
if(this.order.productOrder[key] > 0) { | |||
if(this.order.productOrder[key].quantity > 0) { | |||
countProducts ++ ; | |||
} | |||
} | |||
@@ -502,9 +502,12 @@ Vue.component('order-form',{ | |||
} | |||
}, | |||
productQuantityClick: function(id_product, quantity) { | |||
if(this.order.productOrder[id_product] + quantity >= 0) { | |||
var theQuantity = this.order.productOrder[id_product] + quantity ; | |||
Vue.set(this.order.productOrder, id_product, theQuantity); | |||
if(!this.order.productOrder[id_product].quantity) { | |||
this.order.productOrder[id_product].quantity = 0 ; | |||
} | |||
if(parseFloat(this.order.productOrder[id_product].quantity) + quantity >= 0) { | |||
var theQuantity = parseFloat(this.order.productOrder[id_product].quantity) + parseFloat(quantity) ; | |||
Vue.set(this.order.productOrder, id_product, {quantity: theQuantity, unit: this.order.productOrder[id_product].unit}); | |||
} | |||
} | |||
} |
@@ -153,7 +153,7 @@ termes. | |||
width: 50px ; | |||
} | |||
td.quantity-max { | |||
width: 70px ; | |||
width: 120px ; | |||
input { | |||
text-align: center ; | |||
@@ -265,16 +265,38 @@ termes. | |||
} | |||
td.quantity { | |||
width: 150px ; | |||
width: 165px ; | |||
input { | |||
text-align: center ; | |||
color: gray ; | |||
color: black ; | |||
} | |||
.form-control { | |||
border-right: 0px none ; | |||
padding-right: 4px ; | |||
} | |||
.input-group-addon { | |||
padding: 5px ; | |||
padding-left: 0px ; | |||
margin: 0px ; | |||
border-left: 0px none ; | |||
border-right: 0px none ; | |||
} | |||
} | |||
td.quantity-remaining { | |||
text-align: right ; | |||
&.quantity-remaining, &.infinite { | |||
color: #00A65A ; | |||
} | |||
&.negative { | |||
color: #DD4B39 ; | |||
} | |||
&.infinite, &.empty { | |||
font-size: 18px ; | |||
} | |||
} | |||
} | |||
@@ -160,7 +160,7 @@ class Order extends ActiveRecordCommon | |||
*/ | |||
public static function defaultOptionsSearch() { | |||
return [ | |||
'with' => ['productOrder', 'creditHistory','creditHistory.userAction' , 'pointSale'], | |||
'with' => ['productOrder','productOrder.product','creditHistory','creditHistory.userAction' , 'pointSale'], | |||
'join_with' => ['distribution', 'user', 'user.userProducer'], | |||
'orderby' => 'order.date ASC', | |||
'attribute_id_producer' => 'distribution.id_producer' | |||
@@ -186,14 +186,14 @@ class Order extends ActiveRecordCommon | |||
public function initAmount() { | |||
if (isset($this->productOrder)) { | |||
foreach ($this->productOrder as $productOrder) { | |||
if ($productOrder->sale_mode == Product::SALE_MODE_UNIT) { | |||
$this->amount += $productOrder->price * $productOrder->quantity ; | |||
$this->amount += $productOrder->price * $productOrder->quantity ; | |||
if ($productOrder->unit == 'piece') { | |||
if(isset($productOrder->product)) { | |||
$this->weight += ($productOrder->quantity * $productOrder->product->weight) / 1000 ; | |||
} | |||
} | |||
elseif ($productOrder->sale_mode == Product::SALE_MODE_WEIGHT) { | |||
$this->amount += $productOrder->price * $productOrder->quantity / 1000; | |||
else { | |||
$this->weight += $productOrder->quantity ; | |||
} | |||
} | |||
} | |||
@@ -606,7 +606,7 @@ class Order extends ActiveRecordCommon | |||
foreach ($orders as $c) { | |||
if(is_null($c->date_delete) || $ignoreCancel) { | |||
foreach ($c->productOrder as $po) { | |||
if ($po->id_product == $idProduct) { | |||
if ($po->id_product == $idProduct && $po->product->unit == $po->unit) { | |||
$quantity += $po->quantity ; | |||
} | |||
} |
@@ -61,11 +61,11 @@ class Product extends ActiveRecordCommon | |||
var $apply_distributions = false ; | |||
public static $unitsArray = [ | |||
['unit' => 'piece', 'wording' => 'pièce', 'coefficient' => 1], | |||
['unit' => 'g', 'wording' => 'g', 'coefficient' => 1000], | |||
['unit' => 'kg', 'wording' => 'kg', 'coefficient' => 1], | |||
['unit' => 'mL', 'wording' => 'mL', 'coefficient' => 1000], | |||
['unit' => 'L', 'wording' => 'L', 'coefficient' => 1], | |||
'piece' => ['unit' => 'piece', 'wording' => 'pièce', 'coefficient' => 1], | |||
'g' => ['unit' => 'g', 'wording' => 'g', 'coefficient' => 1000], | |||
'kg' => ['unit' => 'kg', 'wording' => 'kg', 'coefficient' => 1], | |||
'mL' => ['unit' => 'mL', 'wording' => 'mL', 'coefficient' => 1000], | |||
'L' => ['unit' => 'L', 'wording' => 'L', 'coefficient' => 1], | |||
]; | |||
/** |