Browse Source

[producer] Vente au kilo : adaptation formulaire de commande

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
32e1fe6c3e
10 changed files with 109 additions and 27 deletions
  1. +6
    -0
      backend/controllers/OrderController.php
  2. +6
    -1
      common/models/Order.php
  3. +2
    -0
      common/models/Subscription.php
  4. +15
    -0
      console/migrations/m190510_074749_ajout_champs_product_order_step.php
  5. +24
    -7
      producer/controllers/OrderController.php
  6. +4
    -1
      producer/views/order/_form.php
  7. +8
    -7
      producer/views/order/order.php
  8. +21
    -7
      producer/web/css/screen.css
  9. +9
    -3
      producer/web/js/vuejs/order-order.js
  10. +14
    -1
      producer/web/sass/order/_order.scss

+ 6
- 0
backend/controllers/OrderController.php View File

@@ -105,6 +105,8 @@ class OrderController extends BackendController
$productOrder->id_product = $product->id;
$productOrder->quantity = $quantity;
$productOrder->price = $p->price;
$productOrder->unit = $p->unit;
$productOrder->step = $p->step;
$productOrder->save();
}
}
@@ -138,6 +140,8 @@ class OrderController extends BackendController
$productOrder->id_product = $product->id;
$productOrder->quantity = $quantity;
$productOrder->price = $p->price;
$productOrder->unit = $p->unit;
$productOrder->step = $p->step;
$productOrder->save();
}
}
@@ -869,6 +873,7 @@ class OrderController extends BackendController
$productOrder->id_product = $key;
$productOrder->quantity = $quantity;
$productOrder->unit = $product->unit;
$productOrder->step = $product->step;
$productOrder->price = $product->price;
$productOrder->save();
}
@@ -929,6 +934,7 @@ class OrderController extends BackendController
$productOrder->id_product = $key;
$productOrder->quantity = $quantity;
$productOrder->unit = $product->unit;
$productOrder->step = $product->step;
$productOrder->price = $product->price;
}
}

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

@@ -667,7 +667,12 @@ class Order extends ActiveRecordCommon
$count = 0 ;
if($this->productOrder && is_array($this->productOrder)) {
foreach($this->productOrder as $productOrder) {
$count += $productOrder->quantity ;
if($productOrder->unit == 'piece') {
$count ++ ;
}
else {
$count += $productOrder->quantity ;
}
}
}
return $count ;

+ 2
- 0
common/models/Subscription.php View File

@@ -240,6 +240,8 @@ class Subscription extends ActiveRecordCommon
$productOrder->id_product = $productSubscription->product->id;
$productOrder->quantity = $productSubscription->quantity;
$productOrder->price = $productSubscription->product->price;
$productOrder->unit = $productSubscription->product->unit;
$productOrder->step = $productSubscription->product->step;
$productOrder->save();
$productsAdd = true;
}

+ 15
- 0
console/migrations/m190510_074749_ajout_champs_product_order_step.php View File

@@ -0,0 +1,15 @@
<?php

use yii\db\Migration;
use yii\db\mysql\Schema;

class m190510_074749_ajout_champs_product_order_step extends Migration {

public function up() {
$this->addColumn('product_order', 'step', Schema::TYPE_FLOAT.' DEFAULT 1') ;
}

public function down() {
$this->dropColumn('product_order','step') ;
}
}

+ 24
- 7
producer/controllers/OrderController.php View File

@@ -43,6 +43,7 @@ use common\models\User ;
use common\models\Producer ;
use common\models\Order ;
use common\models\UserPointSale ;
use common\models\Product ;
use DateTime;

class OrderController extends ProducerBaseController
@@ -228,7 +229,6 @@ class OrderController extends ProducerBaseController
}
}

// date
$errorDate = false;
if (isset($order->id_distribution)) {
@@ -303,6 +303,13 @@ class OrderController extends ProducerBaseController
// suppression de tous les enregistrements ProductOrder
if (!is_null($order)) {
ProductOrder::deleteAll(['id_order' => $order->id]);
$stepsArray = [] ;
if(isset($order->productOrder)) {
foreach($order->productOrder as $productOrder) {
$unitsArray[$productOrder->id_product] = $productOrder->unit;
}
}
}

// produits dispos
@@ -317,14 +324,16 @@ class OrderController extends ProducerBaseController

$productOrder->price = $product->price;

$quantity = (int) $posts['products'][$product->id] ;
$unit = (!is_null($order) && isset($unitsArray[$product->id])) ? $unitsArray[$product->id] : $product->unit ;
$coefficient = Product::$unitsArray[$unit]['coefficient'] ;
$quantity = ((int) $posts['products'][$product->id]) / $coefficient ;
if ($availableProducts[$product->id]['quantity_max'] && $quantity > $availableProducts[$product->id]['quantity_remaining']) {
$quantity = $availableProducts[$product->id]['quantity_remaining'];
}
$productOrder->quantity = $quantity;
$productOrder->sale_mode = Product::SALE_MODE_UNIT ;
$productOrder->unit = $product->unit ;
$productOrder->step = $product->step ;
$productOrder->save();
}
}
@@ -600,6 +609,8 @@ class OrderController extends ProducerBaseController
$indexProduct = 0 ;
foreach($productsArray as &$product) {
$coefficient_unit = Product::$unitsArray[$product['unit']]['coefficient'] ;
if(is_null($product['photo'])) {
$product['photo'] = '' ;
}
@@ -613,17 +624,23 @@ class OrderController extends ProducerBaseController
$quantityOrderUser = Order::getProductQuantity($product['id'], [$orderUser], true) ;
$product['quantity_ordered'] = $quantityOrder ;
$product['quantity_remaining'] = $product['quantity_max'] - $quantityOrder + $quantityOrderUser ;
$product['quantity_form'] = $quantityOrderUser ;
$product['quantity_form'] = $quantityOrderUser * $coefficient_unit ;
foreach($orderUser->productOrder as $productOrder) {
if($productOrder->id_product == $product['id']) {
$product['wording_unit'] = Product::strUnit($productOrder->unit,'wording_unit', true) ;
$product['step'] = $productOrder->step ;
}
}
}
else {
$product['quantity_form'] = 0 ;
$product['wording_unit'] = Product::strUnit($product['unit'],'wording_unit', true) ;
}
$product['coefficient_unit'] = $coefficient_unit ;
if($product['quantity_remaining'] < 0) $product['quantity_remaining'] = 0 ;
$product['index'] = $indexProduct ++ ;
}
$json['products'] = $productsArray;
}

+ 4
- 1
producer/views/order/_form.php View File

@@ -37,6 +37,7 @@ termes.
*/

use yii\widgets\ActiveForm;
use common\models\Product;

?>
<div class="order-form">
@@ -216,7 +217,9 @@ use yii\widgets\ActiveForm;
<span class="name"><?= Html::encode($product->name); ?></span> - <span class="description"><?= Html::encode($product->getDescription()); ?></span><br />
<span class="recipe"><?= Html::encode($product->recipe); ?></span>
</td>
<td class="price-unit"><span class="price"><?= number_format($product->price, 2); ?></span> €</td>
<td class="price-unit">
<span class="price"><?= Price::format($product->price); ?></span> €
</td>
<td class="column-quantity">
<div class="input-group" <?php if (isset($availableProducts[$product->id]) && $availableProducts[$product->id]['quantity_remaining'] == 0 && $quantity == 0): ?>style="display:none;"<?php endif; ?>>
<span class="input-group-btn">

+ 8
- 7
producer/views/order/order.php View File

@@ -186,33 +186,34 @@ $this->setTitle('Commander') ;
<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 v-if="product.unit == 'piece' && product.weight">({{ product.weight }}g)</span>
</span>
<span v-if="product.quantity_form == product.quantity_remaining && product.quantity_max > 0" class="label label-danger">
<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">
{{ formatPrice(product.price) }}
{{ formatPrice(product.price) }}<br /><span class="unit">{{ product.wording_unit }}</span>
</td>
<td class="td-quantity">
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product, -1)" :disabled="product.quantity_form == 0"><span class="glyphicon glyphicon-minus"></span></button>
<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, 1)" :disabled="product.quantity_form == product.quantity_remaining && product.quantity_max > 0"><span class="glyphicon glyphicon-plus"></span></button>
<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>
</td>
<td class="price-total">
{{ formatPrice(product.price * product.quantity_form) }}
{{ formatPrice(product.price * (product.quantity_form / product.coefficient_unit )) }}
</td>
</tr>
<tr class="total">
<td colspan="3"></td>
<td colspan="4"></td>
<td class="price-total">{{ priceTotal(true) }}</td>
</tr>
</tbody>

+ 21
- 7
producer/web/css/screen.css View File

@@ -1486,31 +1486,45 @@ termes.
text-align: center;
}
/* line 224, ../sass/order/_order.scss */
.order-order #app-order-order table#products .price-unit .unit, .order-order #app-order-order table#products .price-total .unit {
color: gray;
font-size: 13px;
}
/* line 229, ../sass/order/_order.scss */
.order-order #app-order-order table#products .td-quantity {
width: 150px;
width: 175px;
}
/* line 226, ../sass/order/_order.scss */
/* line 231, ../sass/order/_order.scss */
.order-order #app-order-order table#products .td-quantity input.quantity {
text-align: center;
border-right: 0px none;
}
/* line 232, ../sass/order/_order.scss */
/* line 235, ../sass/order/_order.scss */
.order-order #app-order-order table#products .td-quantity .input-group-addon {
padding: 5px;
padding-left: 0px;
margin: 0px;
border-left: 0px none;
border-right: 0px none;
}
/* line 245, ../sass/order/_order.scss */
.order-order #app-order-order table#products tr.total .price-total {
font-size: 23px;
}
/* line 240, ../sass/order/_order.scss */
/* line 253, ../sass/order/_order.scss */
.order-order #app-order-order #content-step-payment .credit .info {
margin-left: 20px;
color: gray;
}
/* line 246, ../sass/order/_order.scss */
/* line 259, ../sass/order/_order.scss */
.order-order #app-order-order #content-step-payment .comment {
margin-bottom: 20px;
}
/* line 251, ../sass/order/_order.scss */
/* line 264, ../sass/order/_order.scss */
.order-order #app-order-order #infos {
margin-top: 30px;
}
/* line 253, ../sass/order/_order.scss */
/* line 266, ../sass/order/_order.scss */
.order-order #app-order-order #infos .panel-body {
padding-top: 0px;
white-space: pre-line;

+ 9
- 3
producer/web/js/vuejs/order-order.js View File

@@ -255,8 +255,9 @@ var app = new Vue({
this.changeStep('products') ;
},
productQuantityClick: function(product, quantity) {
console.log(this.products[product.index].quantity_remaining) ;
if( this.products[product.index].quantity_form + quantity >= 0 &&
(this.products[product.index].quantity_form + quantity <= this.products[product.index].quantity_remaining ||
(this.products[product.index].quantity_form + quantity <= (this.products[product.index].quantity_remaining * this.products[product.index].coefficient_unit) ||
!this.products[product.index].quantity_max)
) {
this.products[product.index].quantity_form += quantity ;
@@ -274,7 +275,12 @@ var app = new Vue({
var count = 0 ;
for(var key in this.products) {
if(this.products[key].quantity_form > 0) {
count += this.products[key].quantity_form ;
if(this.products[key].unit != 'piece') {
count ++ ;
}
else {
count += this.products[key].quantity_form ;
}
}
}
return count ;
@@ -283,7 +289,7 @@ var app = new Vue({
var price = 0 ;
for(var key in this.products) {
if(this.products[key].quantity_form > 0) {
price += this.products[key].quantity_form * this.products[key].price ;
price += (this.products[key].quantity_form / this.products[key].coefficient_unit) * this.products[key].price ;
}
}
if(format) {

+ 14
- 1
producer/web/sass/order/_order.scss View File

@@ -220,11 +220,24 @@
.price-unit, .price-total {
width: 100px ;
text-align: center ;
.unit {
color: gray ;
font-size: 13px ;
}
}
.td-quantity {
width: 150px ;
width: 175px ;
input.quantity {
text-align: center ;
border-right: 0px none ;
}
.input-group-addon {
padding: 5px ;
padding-left: 0px ;
margin: 0px ;
border-left: 0px none ;
border-right: 0px none ;
}
}

Loading…
Cancel
Save