Преглед на файлове

[producer/backend] Vente au kilo : adaptation formulaire d'abonnements

refactoring
Guillaume Bourgeois преди 5 години
родител
ревизия
3bf31a1e4f
променени са 13 файла, в които са добавени 154 реда и са изтрити 38 реда
  1. +6
    -0
      backend/controllers/SubscriptionController.php
  2. +1
    -0
      backend/views/subscription/_form.php
  3. +7
    -2
      backend/views/subscription/index.php
  4. +1
    -0
      backend/web/js/vuejs/subscription-form.js
  5. +19
    -0
      common/models/Subscription.php
  6. +33
    -11
      common/models/SubscriptionForm.php
  7. +27
    -0
      console/migrations/m190515_122438_ajout_champs_price_product_subscription.php
  8. +17
    -11
      producer/controllers/SubscriptionController.php
  9. +7
    -4
      producer/views/subscription/_form.php
  10. +2
    -1
      producer/views/subscription/index.php
  11. +20
    -6
      producer/web/css/screen.css
  12. +1
    -1
      producer/web/js/vuejs/subscription-form.js
  13. +13
    -2
      producer/web/sass/subscription/_form.scss

+ 6
- 0
backend/controllers/SubscriptionController.php Целия файл

@@ -39,6 +39,7 @@ namespace backend\controllers;

use common\models\Order ;
use common\models\Product ;
use common\models\SubscriptionSearch ;

class SubscriptionController extends BackendController
{
@@ -89,6 +90,7 @@ class SubscriptionController extends BackendController
{
// form
$model = new SubscriptionForm;
$model->isAdmin = true ;
$model->id_producer = Producer::getId();

if($idOrder) {
@@ -149,6 +151,7 @@ class SubscriptionController extends BackendController
{
// form
$model = new SubscriptionForm;
$model->isAdmin = true ;
$subscription = Subscription::findOne($id);
if ($subscription) {
$model->id = $id;
@@ -272,6 +275,7 @@ class SubscriptionController extends BackendController
'unit' => $theProduct['unit'],
'wording_unit' => Product::strUnit($theProduct['unit'], 'wording_short'),
'step' => $theProduct['step'],
'price' => $theProduct['price']
] ;
if(isset($theProduct['productSubscription'][0])) {
@@ -280,9 +284,11 @@ class SubscriptionController extends BackendController
'unit' => $theProduct['productSubscription'][0]['unit'],
'wording_unit' => Product::strUnit($theProduct['productSubscription'][0]['unit'], 'wording_short'),
'step' => $theProduct['productSubscription'][0]['step'],
'price' => $theProduct['productSubscription'][0]['price'],
] ;
$theProduct['unit'] = $theProduct['productSubscription'][0]['unit'] ;
$theProduct['step'] = $theProduct['productSubscription'][0]['step'] ;
$theProduct['price'] = $theProduct['productSubscription'][0]['price'] ;
}
$theProduct['quantity'] = $theProduct['productSubscription'][0]['quantity'] * Product::$unitsArray[$theProduct['unit']]['coefficient'] ;
}

+ 1
- 0
backend/views/subscription/_form.php Целия файл

@@ -101,6 +101,7 @@ use common\models\PointSale ;
<td>{{ product.name }}</td>
<td>
<input type="hidden" :value="product.step" :name="'product_step_'+product.step" />
<input type="hidden" :value="product.price" :name="'product_price_'+product.price" />
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="changeQuantityProductSubscription(false, product)"><span class="glyphicon glyphicon-minus"></span></button>

+ 7
- 2
backend/views/subscription/index.php Целия файл

@@ -77,7 +77,7 @@ $this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon
foreach($model->productSubscription as $productSubscription)
{
if(isset($productSubscription->product)) {
$html .= Html::encode($productSubscription->product->name).' ('.$productSubscription->quantity.'&nbsp;'.Product::strUnit($productSubscription->unit, 'wording_short').')<br />' ;
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->unit]['coefficient']).'&nbsp;'.Product::strUnit($productSubscription->unit, 'wording_short').')<br />' ;
}
else {
$html .= 'Produit non défini<br />' ;
@@ -87,7 +87,12 @@ $this->addButton(['label' => 'Nouvel abonnement <span class="glyphicon glyphicon
// aucun produit
if(!count($model->productSubscription))
{
$html .= '<span class="glyphicon glyphicon-warning-sign"></span> Aucun produit' ;
$html .= '<span class="glyphicon glyphicon-warning-sign"></span> Aucun produit<br />' ;
}
// des unités ne correspondent pas
if($model->hasUnitsNotMatch()) {
$html .= '<span class="glyphicon glyphicon-warning-sign" title="Des unités ne correspondent pas"></span>' ;
}
return $html ;

+ 1
- 0
backend/web/js/vuejs/subscription-form.js Целия файл

@@ -68,6 +68,7 @@ var app = new Vue({
for(var j = 0; j < this.products[i].units.length ; j ++) {
if(this.products[i].unit == this.products[i].units[j].unit) {
this.products[i].step = this.products[i].units[j].step ;
this.products[i].price = this.products[i].units[j].price ;
}
}
}

+ 19
- 0
common/models/Subscription.php Целия файл

@@ -455,4 +455,23 @@ class Subscription extends ActiveRecordCommon
}
}
}
/**
* Retourne true si des unités des ProductSubscription ne correspondent pas
* aux Product.
*
* @return boolean
*/
public function hasUnitsNotMatch()
{
if(isset($this->productSubscription) && is_array($this->productSubscription)) {
foreach($this->productSubscription as $productSubscription) {
if(isset($productSubscription->product) && $productSubscription->unit != $productSubscription->product->unit) {
return true ;
}
}
}
return false ;
}
}

+ 33
- 11
common/models/SubscriptionForm.php Целия файл

@@ -48,7 +48,7 @@ use common\models\SubscriptionProduct;
*/
class SubscriptionForm extends Model
{
public $isAdmin = false ;
public $id;
public $id_user;
public $username;
@@ -151,6 +151,7 @@ class SubscriptionForm extends Model

// produits
if ($this->id) {
$productsSubscriptionsArray = ProductSubscription::findAll(['id_subscription' => $this->id]) ;
ProductSubscription::deleteAll(['id_subscription' => $this->id]);
}

@@ -159,19 +160,40 @@ class SubscriptionForm extends Model
$idProduct = (int) str_replace('product_', '', $nameInput);
$product = Product::findOne($idProduct) ;

$subscriptionProduct = new ProductSubscription;
$subscriptionProduct->id_subscription = $subscription->id;
$subscriptionProduct->id_product = $idProduct;
$newProductSubscription = new ProductSubscription;
$newProductSubscription->id_subscription = $subscription->id;
$newProductSubscription->id_product = $idProduct;
$unit = (Yii::$app->getRequest()->post('product_unit_'.$idProduct)) ? Yii::$app->getRequest()->post('product_unit_'.$idProduct) : $product->unit ;
$subscriptionProduct->unit = $unit;

$step = (Yii::$app->getRequest()->post('product_step_'.$idProduct)) ? Yii::$app->getRequest()->post('product_step_'.$idProduct) : $product->step ;
$subscriptionProduct->step = $step;
if($this->isAdmin) {
$unit = (Yii::$app->getRequest()->post('product_unit_'.$idProduct)) ? Yii::$app->getRequest()->post('product_unit_'.$idProduct) : $product->unit ;
$newProductSubscription->unit = $unit;
$step = (Yii::$app->getRequest()->post('product_step_'.$idProduct)) ? Yii::$app->getRequest()->post('product_step_'.$idProduct) : $product->step ;
$newProductSubscription->step = $step;
$price = (Yii::$app->getRequest()->post('product_price_'.$idProduct)) ? Yii::$app->getRequest()->post('product_price_'.$idProduct) : $product->price ;
$newProductSubscription->price = $price;
}
else {
foreach($productsSubscriptionsArray as $productSubscription) {
if($productSubscription->id_product == $idProduct) {
$newProductSubscription->unit = $productSubscription->unit ;
$newProductSubscription->step = $productSubscription->step ;
$newProductSubscription->price = $productSubscription->price ;
}
}
if(!$newProductSubscription->unit) {
$newProductSubscription->unit = $product->unit ;
}
if(!$newProductSubscription->step) {
$newProductSubscription->step = $product->step;
}
if(!$newProductSubscription->price) {
$newProductSubscription->price = $product->price;
}
}
$subscriptionProduct->quantity = $quantity / Product::$unitsArray[$unit]['coefficient'];
$newProductSubscription->quantity = $quantity / Product::$unitsArray[$newProductSubscription->unit]['coefficient'];

$subscriptionProduct->save();
$newProductSubscription->save();
}
}

+ 27
- 0
console/migrations/m190515_122438_ajout_champs_price_product_subscription.php Целия файл

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

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

class m190515_122438_ajout_champs_price_product_subscription extends Migration {

public function up() {
$this->addColumn('product_subscription', 'price', Schema::TYPE_FLOAT. ' DEFAULT 0') ;
$productsSubscriptionsArray = common\models\ProductSubscription::find()->all() ;
$productsArray = common\models\Product::find()->all() ;
foreach($productsSubscriptionsArray as $productSubscription) {
foreach($productsArray as $product) {
if($productSubscription->id_product == $product->id) {
$productSubscription->price = $product->price ;
$productSubscription->save() ;
}
}
}
}

public function down() {
$this->dropColumn('product_subscription', 'price') ;
}
}

+ 17
- 11
producer/controllers/SubscriptionController.php Целия файл

@@ -40,6 +40,7 @@ namespace producer\controllers;

use common\models\SubscriptionForm ;
use common\models\SubscriptionSearch ;
use common\models\Product ;

class SubscriptionController extends ProducerBaseController
{
@@ -221,33 +222,38 @@ class SubscriptionController extends ProducerBaseController
if($idSubscription > 0) {
// Quantités produit de l'abonnement
$productQuantitiesArray = [] ;
$arrayProductsSubscription = ProductSubscription::searchAll([
'id_subscription' => $idSubscription
]) ;
if(count($arrayProductsSubscription)) {
foreach ($arrayProductsSubscription as $productSubscription) {
$productQuantitiesArray[$productSubscription->id_product] = $productSubscription->quantity;
}
}
}
// Produits
$productsArray = Product::searchAll() ;
$indexProduct = 0 ;
foreach($productsArray as &$product) {
$quantity = 0 ;
if(isset($productQuantitiesArray) && count($productQuantitiesArray) && isset($productQuantitiesArray[$product->id])) {
$quantity = $productQuantitiesArray[$product->id] ;
$coefficientUnit = Product::$unitsArray[$product->unit]['coefficient'] ;
if(isset($arrayProductsSubscription) && count($arrayProductsSubscription)) {
foreach ($arrayProductsSubscription as $productSubscription) {
if($product->id == $productSubscription->id_product) {
$coefficientUnit = Product::$unitsArray[$productSubscription->unit]['coefficient'] ;
$quantity = $productSubscription->quantity * $coefficientUnit;
$product->step = $productSubscription->step;
$product->unit = $productSubscription->unit;
$product->price = $productSubscription->price;
}
}
}
$product = array_merge(
$product->getAttributes(),
[
'index' => $indexProduct ++,
'quantity_form' => $quantity
'quantity_form' => $quantity,
'coefficient_unit' => $coefficientUnit,
'wording_unit' => Product::strUnit($product->unit, 'wording_unit', true),
'wording_short' => Product::strUnit($product->unit, 'wording_short'),
]
) ;
}

+ 7
- 4
producer/views/subscription/_form.php Целия файл

@@ -215,21 +215,24 @@ use common\models\PointSale ;
<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="quantity">
<div class="input-group">
<input type="hidden" :value="product.step" :name="'product_step_'+product.step" />
<input type="hidden" :value="product.unit" :name="'product_unit_'+product.unit" />
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="productQuantityClick(product, -1)"><span class="glyphicon glyphicon-minus"></span></button>
<button class="btn btn-default" type="button" @click="productQuantityClick(product, -product.step)"><span class="glyphicon glyphicon-minus"></span></button>
</span>
<input type="text" v-model="product.quantity_form" :class="'form-control '+((product.quantity_form > 0) ? 'has-quantity' : '')">
<span class="input-group-addon">{{ product.wording_short }}</span>
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="productQuantityClick(product, 1)"><span class="glyphicon glyphicon-plus"></span></button>
<button class="btn btn-default" type="button" @click="productQuantityClick(product, product.step)"><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">

+ 2
- 1
producer/views/subscription/index.php Целия файл

@@ -38,6 +38,7 @@ termes.

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Product ;

$this->setTitle('Abonnements') ;
$this->addButton(['label' => '<span class="glyphicon glyphicon-plus"></span> Ajouter', 'url' => 'subscription/form', 'class' => 'btn btn-primary']) ;
@@ -52,7 +53,7 @@ $columns = [
foreach($model->productSubscription as $productSubscription)
{
if(isset($productSubscription->product)) {
$html .= $productSubscription->quantity . '&nbsp;x&nbsp;'.Html::encode($productSubscription->product->name).'<br />' ;
$html .= Html::encode($productSubscription->product->name).' ('.($productSubscription->quantity * Product::$unitsArray[$productSubscription->unit]['coefficient']) . '&nbsp'.Product::strUnit($productSubscription->unit, 'wording_short').')<br />' ;
}
else {
$html .= 'Produit non défini<br />' ;

+ 20
- 6
producer/web/css/screen.css Целия файл

@@ -1677,43 +1677,57 @@ termes.
/* line 73, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products td.quantity,
.subscription-update .subscription-form .products td.quantity {
width: 150px;
width: 180px;
}
/* line 76, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products td.quantity input,
.subscription-update .subscription-form .products td.quantity input {
text-align: center;
border-right: 0px none;
}
/* line 79, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products td.quantity input.has-quantity,
.subscription-update .subscription-form .products td.quantity input.has-quantity {
font-weight: bold;
}
/* line 85, ../sass/subscription/_form.scss */
/* line 84, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products td.quantity .input-group-addon,
.subscription-update .subscription-form .products td.quantity .input-group-addon {
background-color: white;
padding-left: 0px;
border-left: 0px none;
}
/* line 91, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products .name,
.subscription-update .subscription-form .products .name {
font-family: "capsuularegular";
font-size: 20px;
color: black;
}
/* line 91, ../sass/subscription/_form.scss */
/* line 97, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products .description,
.subscription-update .subscription-form .products .description {
font-style: italic;
}
/* line 95, ../sass/subscription/_form.scss */
/* line 101, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products .recipe,
.subscription-update .subscription-form .products .recipe {
font-size: 12px;
}
/* line 99, ../sass/subscription/_form.scss */
/* line 105, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products .price-unit, .subscription-create .subscription-form .products .price-total,
.subscription-update .subscription-form .products .price-unit,
.subscription-update .subscription-form .products .price-total {
text-align: center;
width: 150px;
}
/* line 104, ../sass/subscription/_form.scss */
/* line 110, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products .unit,
.subscription-update .subscription-form .products .unit {
color: gray;
font-size: 13px;
}
/* line 115, ../sass/subscription/_form.scss */
.subscription-create .subscription-form .products tr.total .price-total,
.subscription-update .subscription-form .products tr.total .price-total {
text-align: center;

+ 1
- 1
producer/web/js/vuejs/subscription-form.js Целия файл

@@ -179,7 +179,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) {

+ 13
- 2
producer/web/sass/subscription/_form.scss Целия файл

@@ -71,15 +71,21 @@
}
td.quantity {
width: 150px ;
width: 180px ;
input {
text-align: center ;
border-right: 0px none ;
&.has-quantity {
font-weight: bold ;
}
}
.input-group-addon {
background-color: white ;
padding-left: 0px ;
border-left: 0px none ;
}
}
.name {
@@ -101,6 +107,11 @@
width: 150px ;
}
.unit {
color: gray ;
font-size: 13px ;
}
tr.total .price-total {
text-align: center ;
font-size: 20px ;

Loading…
Отказ
Запис