Browse Source

[backen] Vente au kilo : adaptation formulaire ajout/modification commande

dev
Guillaume Bourgeois 5 years ago
parent
commit
d7f847c3e0
8 changed files with 137 additions and 43 deletions
  1. +27
    -6
      backend/controllers/DistributionController.php
  2. +8
    -2
      backend/controllers/OrderController.php
  3. +25
    -8
      backend/views/distribution/index.php
  4. +33
    -8
      backend/web/css/screen.css
  5. +7
    -4
      backend/web/js/vuejs/distribution-index.js
  6. +26
    -4
      backend/web/sass/distribution/_index.scss
  7. +6
    -6
      common/models/Order.php
  8. +5
    -5
      common/models/Product.php

+ 27
- 6
backend/controllers/DistributionController.php View File

foreach($productsArray as &$theProduct) { foreach($productsArray as &$theProduct) {
$quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ; $quantityOrder = Order::getProductQuantity($theProduct['id'], $ordersArray) ;
$theProduct['quantity_ordered'] = $quantityOrder ; $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 ; $theProduct['quantity_form'] = 0 ;
if($theProduct['productDistribution'][0]['active'] && $theProduct['productDistribution'][0]['quantity_max']) { if($theProduct['productDistribution'][0]['active'] && $theProduct['productDistribution'][0]['quantity_max']) {
// orders as array // orders as array
if($ordersArray) { 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) { foreach($productsArray as $product) {
if(!isset($productOrderArray[$product['id']])) { if(!isset($productOrderArray[$product['id']])) {
$productOrderArray[$product['id']] = 0 ;
$productOrderArray[$product['id']] = [
'quantity' => 0,
'unit' => $product['unit']
] ;
} }
} }
// order create // order create
$productOrderArray = [] ; $productOrderArray = [] ;
foreach($productsArray as $product) { foreach($productsArray as $product) {
$productOrderArray[$product['id']] = 0 ;
$productOrderArray[$product['id']] = [
'quantity' => 0,
'unit' => $product['unit']
] ;
} }
$json['order_create'] = [ $json['order_create'] = [
'id_point_sale' => $idPointSaleDefault, 'id_point_sale' => $idPointSaleDefault,

+ 8
- 2
backend/controllers/OrderController.php View File



$order->save(); $order->save();


foreach ($products as $key => $quantity) {
foreach ($products as $key => $dataProductOrder) {
$product = Product::findOne($key); $product = Product::findOne($key);
$quantity = $dataProductOrder->quantity / Product::$unitsArray[$dataProductOrder->unit]['coefficient'] ;
if ($product && $quantity) { if ($product && $quantity) {
$productOrder = new ProductOrder; $productOrder = new ProductOrder;
$productOrder->id_order = $order->id; $productOrder->id_order = $order->id;
$productOrder->id_product = $key; $productOrder->id_product = $key;
$productOrder->quantity = $quantity; $productOrder->quantity = $quantity;
$productOrder->unit = $product->unit;
$productOrder->price = $product->price; $productOrder->price = $product->price;
$productOrder->save(); $productOrder->save();
} }
$order->distribution->id_producer == Producer::getId()) { $order->distribution->id_producer == Producer::getId()) {
$products = json_decode($products); $products = json_decode($products);
foreach ($products as $key => $quantity) {
foreach ($products as $key => $dataProductOrder) {
$productOrder = ProductOrder::findOne([ $productOrder = ProductOrder::findOne([
'id_order' => $idOrder, 'id_order' => $idOrder,
'id_product' => $key 'id_product' => $key
]); ]);


$quantity = $dataProductOrder->quantity
/ Product::$unitsArray[$dataProductOrder->unit]['coefficient'] ;
if ($quantity) { if ($quantity) {
if ($productOrder) { if ($productOrder) {
$productOrder->quantity = $quantity; $productOrder->quantity = $quantity;
$productOrder->id_order = $idOrder; $productOrder->id_order = $idOrder;
$productOrder->id_product = $key; $productOrder->id_product = $key;
$productOrder->quantity = $quantity; $productOrder->quantity = $quantity;
$productOrder->unit = $product->unit;
$productOrder->price = $product->price; $productOrder->price = $product->price;
} }
} }

+ 25
- 8
backend/views/distribution/index.php View File

<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> <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>
<td>{{ product.name }}</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="&infin;" :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)') : '&empty;' }}</td>
<td class="quantity-max">
<div class="input-group">
<input type="text" class="form-control quantity-max" placeholder="&infin;" :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> </tr>
</tbody> </tbody>
</table> </table>
<td colspan="6"> <td colspan="6">
<strong><span class="glyphicon glyphicon-menu-right"></span> Produits</strong> <strong><span class="glyphicon glyphicon-menu-right"></span> Produits</strong>
<ul> <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> </li>
</ul> </ul>
<div v-if="order.comment && order.comment.length > 0" class="comment"> <div v-if="order.comment && order.comment.length > 0" class="comment">
<div class="col-md-8"> <div class="col-md-8">
<label class="control-label">Produits</label> <label class="control-label">Produits</label>
<table class="table table-condensed table-bordered table-hover table-products"> <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> <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>
<td class="quantity"> <td class="quantity">
<div class="input-group"> <div class="input-group">
<span class="input-group-btn"> <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> </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"> <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> </span>
</div> </div>
</td> </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">&infin;</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> </tr>
</tbody> </tbody>
</table> </table>

+ 33
- 8
backend/web/css/screen.css View File

} }
/* line 155, ../sass/distribution/_index.scss */ /* line 155, ../sass/distribution/_index.scss */
.distribution-index #modal-products table.table td.quantity-max { .distribution-index #modal-products table.table td.quantity-max {
width: 70px;
width: 120px;
} }
/* line 158, ../sass/distribution/_index.scss */ /* line 158, ../sass/distribution/_index.scss */
.distribution-index #modal-products table.table td.quantity-max input { .distribution-index #modal-products table.table td.quantity-max input {
} }
/* line 267, ../sass/distribution/_index.scss */ /* line 267, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity { .distribution-index .modal-form-order table.table-products td.quantity {
width: 150px;
width: 165px;
} }
/* line 270, ../sass/distribution/_index.scss */ /* line 270, ../sass/distribution/_index.scss */
.distribution-index .modal-form-order table.table-products td.quantity input { .distribution-index .modal-form-order table.table-products td.quantity input {
text-align: center; 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 { .distribution-index .modal-form-order table.table-products td.quantity-remaining {
text-align: right; 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 { .distribution-index .modal-form-order .actions-form button {
margin-left: 15px; margin-left: 15px;
} }
/* line 290, ../sass/distribution/_index.scss */
/* line 312, ../sass/distribution/_index.scss */
.distribution-index .modal-payment .info-box .info-box-icon { .distribution-index .modal-payment .info-box .info-box-icon {
width: 50px; width: 50px;
} }
/* line 292, ../sass/distribution/_index.scss */
/* line 314, ../sass/distribution/_index.scss */
.distribution-index .modal-payment .info-box .info-box-icon i { .distribution-index .modal-payment .info-box .info-box-icon i {
font-size: 30px; font-size: 30px;
} }
/* line 296, ../sass/distribution/_index.scss */
/* line 318, ../sass/distribution/_index.scss */
.distribution-index .modal-payment .info-box .info-box-content { .distribution-index .modal-payment .info-box .info-box-content {
margin-left: 50px; margin-left: 50px;
} }

+ 7
- 4
backend/web/js/vuejs/distribution-index.js View File

var countProducts = 0 ; var countProducts = 0 ;
for(var key in this.order.productOrder) { for(var key in this.order.productOrder) {
if(this.order.productOrder[key] > 0) {
if(this.order.productOrder[key].quantity > 0) {
countProducts ++ ; countProducts ++ ;
} }
} }
} }
}, },
productQuantityClick: function(id_product, quantity) { 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});
} }
} }
} }

+ 26
- 4
backend/web/sass/distribution/_index.scss View File

width: 50px ; width: 50px ;
} }
td.quantity-max { td.quantity-max {
width: 70px ;
width: 120px ;
input { input {
text-align: center ; text-align: center ;
} }
td.quantity { td.quantity {
width: 150px ;
width: 165px ;
input { input {
text-align: center ; 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 { td.quantity-remaining {
text-align: right ; text-align: right ;
&.quantity-remaining, &.infinite {
color: #00A65A ;
}
&.negative {
color: #DD4B39 ;
}
&.infinite, &.empty {
font-size: 18px ;
}
} }
} }

+ 6
- 6
common/models/Order.php View File

*/ */
public static function defaultOptionsSearch() { public static function defaultOptionsSearch() {
return [ return [
'with' => ['productOrder', 'creditHistory','creditHistory.userAction' , 'pointSale'],
'with' => ['productOrder','productOrder.product','creditHistory','creditHistory.userAction' , 'pointSale'],
'join_with' => ['distribution', 'user', 'user.userProducer'], 'join_with' => ['distribution', 'user', 'user.userProducer'],
'orderby' => 'order.date ASC', 'orderby' => 'order.date ASC',
'attribute_id_producer' => 'distribution.id_producer' 'attribute_id_producer' => 'distribution.id_producer'
public function initAmount() { public function initAmount() {
if (isset($this->productOrder)) { if (isset($this->productOrder)) {
foreach ($this->productOrder as $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)) { if(isset($productOrder->product)) {
$this->weight += ($productOrder->quantity * $productOrder->product->weight) / 1000 ; $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 ;
} }
} }
} }
foreach ($orders as $c) { foreach ($orders as $c) {
if(is_null($c->date_delete) || $ignoreCancel) { if(is_null($c->date_delete) || $ignoreCancel) {
foreach ($c->productOrder as $po) { foreach ($c->productOrder as $po) {
if ($po->id_product == $idProduct) {
if ($po->id_product == $idProduct && $po->product->unit == $po->unit) {
$quantity += $po->quantity ; $quantity += $po->quantity ;
} }
} }

+ 5
- 5
common/models/Product.php View File

var $apply_distributions = false ; var $apply_distributions = false ;
public static $unitsArray = [ 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],
]; ];
/** /**

Loading…
Cancel
Save