Procházet zdrojové kódy

Produits tournants : abonnements

feature/rotating_product
Guillaume Bourgeois před 3 měsíci
rodič
revize
f18e2dc50d
4 změnil soubory, kde provedl 71 přidání a 5 odebrání
  1. +12
    -2
      backend/controllers/SubscriptionController.php
  2. +38
    -0
      backend/views/subscription/_form.php
  3. +19
    -2
      backend/web/js/vuejs/subscription-form.js
  4. +2
    -1
      common/forms/SubscriptionForm.php

+ 12
- 2
backend/controllers/SubscriptionController.php Zobrazit soubor

@@ -292,8 +292,8 @@ class SubscriptionController extends BackendController
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

$rotatingModule = $this->getRotatingModule();
$unitModule = $this->getUnitModule();
$productModule = $this->getProductModule();

$productsQuery = Product::find()
->where(['id_producer' => GlobalParam::getCurrentProducerId()])
@@ -318,8 +318,18 @@ class SubscriptionController extends BackendController
}
}

// Produits tournants
$rotatingsArrayReturn = [];
$rotatingsArray = $rotatingModule->getRepository()->findRotatings();
foreach($rotatingsArray as $rotating) {
$rotatingsArrayReturn[] = array_merge($rotating->getAttributes(), [
'quantity' => ''
]);
}

return [
'products' => $productsArray
'products' => $productsArray,
'rotatings' => $rotatingsArrayReturn
];
}
}

+ 38
- 0
backend/views/subscription/_form.php Zobrazit soubor

@@ -36,6 +36,7 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

use domain\Feature\Feature\Feature;
use domain\Subscription\Subscription\Subscription;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
@@ -43,6 +44,7 @@ use yii\widgets\ActiveForm;

$userModule = $this->getUserModule();
$pointSaleModule = $this->getPointSaleModule();
$featureChecker = $this->getFeatureModule()->getChecker();

?>

@@ -120,6 +122,42 @@ $pointSaleModule = $this->getPointSaleModule();
</div>
</div>

<?php if($featureChecker->isEnabled(Feature::ALIAS_ROTATING_PRODUCT)): ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<i class="fa fa-clone"></i>
Produits tournants
</h3>
</div>
<div class="panel-body">
<div class="rotatings">
<table class="table table-bordered table-condensed table-hover" id="rotatings">
<tr v-for="rotating in rotatings">
<td>
{{ rotating.name }}
</td>
<td>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="changeQuantityRotating(rotating, false)"><span class="glyphicon glyphicon-minus"></span></button>
</span>
<input v-model="rotating.quantity" :name="'SubscriptionForm[rotatings][rotating_'+rotating.id+']'" class="form-control input-quantity" />
<div class="input-group-addon">
<span>p.</span>
</div>
<span class="input-group-btn">
<button class="btn btn-default" type="button" @click="changeQuantityRotating(rotating, true)"><span class="glyphicon glyphicon-plus"></span></button>
</span>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<?php endif; ?>

<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">

+ 19
- 2
backend/web/js/vuejs/subscription-form.js Zobrazit soubor

@@ -42,7 +42,8 @@ if($(selector).length) {
data: {
showLoading: false,
loading: true,
products: []
products: [],
rotatings: []
},

mounted: function () {
@@ -58,6 +59,7 @@ if($(selector).length) {
axios.get("ajax-infos", {params: {idSubscription: $('#subscriptionform-id').val()}})
.then(function (response) {
app.products = response.data.products;
app.rotatings = response.data.rotatings;
app.showLoading = false;
});
},
@@ -71,7 +73,22 @@ if($(selector).length) {
if (quantity + step >= 0) {
product.quantity = quantity + step;
}
if (!product.quantity) product.quantity = '';
if (!product.quantity) {
product.quantity = '';
}
},
changeQuantityRotating: function(rotating, increase) {
var step = 1;
var quantity = rotating.quantity ? parseFloat(rotating.quantity) : 0;
if (!increase) {
step = -step;
}
if (quantity + step >= 0) {
rotating.quantity = quantity + step;
}
if (!rotating.quantity) {
rotating.quantity = '';
}
}
}
});

+ 2
- 1
common/forms/SubscriptionForm.php Zobrazit soubor

@@ -65,6 +65,7 @@ class SubscriptionForm extends Model
public $sunday;
public $week_frequency;
public $products;
public $rotatings;
public $auto_payment;
public $comment ;

@@ -78,7 +79,7 @@ class SubscriptionForm extends Model
[['date_begin', 'date_end'], 'date', 'format' => 'php:d/m/Y'],
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'], 'boolean'],
[['id_point_sale', 'id_producer', 'date_begin'], 'required', 'message' => 'Champs obligatoire'],
[['products', 'id_user', 'username','comment'], 'safe'],
[['products', 'rotatings', 'id_user', 'username','comment'], 'safe'],
['id_user', function ($attribute, $params) {
if (!$this->id_user && !strlen($this->username)) {
$this->addError($attribute, 'Vous devez sélectionner ou saisir un utilisateur.');

Načítá se…
Zrušit
Uložit