Browse Source

[backend] Produits : gestion des quantités max par jour de la semaine

refactoring
Guillaume Bourgeois 4 years ago
parent
commit
efb0737a7b
4 changed files with 72 additions and 6 deletions
  1. +27
    -3
      backend/views/product/_form.php
  2. +6
    -2
      common/models/Distribution.php
  3. +8
    -1
      common/models/Product.php
  4. +31
    -0
      console/migrations/m200129_162101_product_ajout_champs_quantite_max_semaine.php

+ 27
- 3
backend/views/product/_form.php View File

@@ -113,9 +113,33 @@ use common\helpers\GlobalParam;
<?= $form->field($model, 'step')->textInput()->hint('Définit ce qui est ajouté ou enlevé lors des changements de quantité.') ?>

<?= $form->field($model, 'weight')->textInput()->label('Poids (g)') ?>
<?= $form->field($model, 'quantity_max')
->hint('Renseignez ce champs si vous souhaitez limiter la quantité commandable pour une distribution.')
->textInput() ?>

<div class="col-md-3">
<?= $form->field($model, 'quantity_max')->textInput() ?>
</div>
<div class="col-md-3">
<?= $form->field($model, 'quantity_max_monday')->textInput() ?>
</div>
<div class="col-md-3">
<?= $form->field($model, 'quantity_max_tuesday')->textInput() ?>
</div>
<div class="col-md-3">
<?= $form->field($model, 'quantity_max_wednesday')->textInput() ?>
</div>
<div class="col-md-3">
<?= $form->field($model, 'quantity_max_thursday')->textInput() ?>
</div>
<div class="col-md-3">
<?= $form->field($model, 'quantity_max_friday')->textInput() ?>
</div>
<div class="col-md-3">
<?= $form->field($model, 'quantity_max_saturday')->textInput() ?>
</div>
<div class="col-md-3">
<?= $form->field($model, 'quantity_max_sunday')->textInput() ?>
</div>
<div class="clr"></div>

<?php
if (!$model->isNewRecord) {
echo $form->field($model, 'apply_distributions')

+ 6
- 2
common/models/Distribution.php View File

@@ -253,8 +253,6 @@ class Distribution extends ActiveRecordCommon
$productDistribution->id_product = $product->id;
}

$productDistribution->quantity_max = $product->quantity_max;

$dayDistribution = date('N', strtotime($this->date));
$daysArray = [
1 => 'monday',
@@ -272,6 +270,12 @@ class Distribution extends ActiveRecordCommon
$productDistribution->active = 1;
}

$productDistribution->quantity_max = $product->quantity_max;
$fieldQuantityMax = 'quantity_max_'.$day ;
if(isset($product->$fieldQuantityMax) && $product->$fieldQuantityMax > 0) {
$productDistribution->quantity_max = $product->$fieldQuantityMax ;
}

$productDistribution->save();

return $productDistribution;

+ 8
- 1
common/models/Product.php View File

@@ -119,7 +119,7 @@ class Product extends ActiveRecordCommon
{
return [
[['name', 'id_producer'], 'required'],
[['active', 'order', 'quantity_max', 'id_producer', 'id_tax_rate'], 'integer'],
[['active', 'order', 'quantity_max', 'id_producer', 'id_tax_rate', 'quantity_max_monday', 'quantity_max_tuesday', 'quantity_max_wednesday', 'quantity_max_thursday', 'quantity_max_friday', 'quantity_max_saturday', 'quantity_max_sunday'], 'integer'],
[['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable', 'apply_distributions'], 'boolean'],
[['price', 'weight', 'step'], 'number'],
[['photo'], 'file'],
@@ -158,6 +158,13 @@ class Product extends ActiveRecordCommon
'sunday' => 'Dimanche',
'order' => 'Ordre',
'quantity_max' => 'Quantité max par défaut',
'quantity_max_monday' => 'Quantité max : lundi',
'quantity_max_tuesday' => 'Quantité max : mardi',
'quantity_max_wednesday' => 'Quantité max : mercredi',
'quantity_max_thursday' => 'Quantité max : jeudi',
'quantity_max_friday' => 'Quantité max : vendredi',
'quantity_max_saturday' => 'Quantité max : samedi',
'quantity_max_sunday' => 'Quantité max : dimanche',
'unavailable' => 'Épuisé',
'apply_distributions' => 'Appliquer ces modifications dans les distributions futures',
'unit' => 'Unité',

+ 31
- 0
console/migrations/m200129_162101_product_ajout_champs_quantite_max_semaine.php View File

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

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

class m200129_162101_product_ajout_champs_quantite_max_semaine extends Migration
{
public function safeUp()
{
$this->alterColumn('product', 'quantity_max', Schema::TYPE_FLOAT.' DEFAULT NULL') ;
$this->addColumn('product', 'quantity_max_monday', Schema::TYPE_FLOAT . ' DEFAULT NULL');
$this->addColumn('product', 'quantity_max_tuesday', Schema::TYPE_FLOAT . ' DEFAULT NULL');
$this->addColumn('product', 'quantity_max_wednesday', Schema::TYPE_FLOAT.' DEFAULT NULL') ;
$this->addColumn('product', 'quantity_max_thursday', Schema::TYPE_FLOAT.' DEFAULT NULL') ;
$this->addColumn('product', 'quantity_max_friday', Schema::TYPE_FLOAT.' DEFAULT NULL') ;
$this->addColumn('product', 'quantity_max_saturday', Schema::TYPE_FLOAT.' DEFAULT NULL') ;
$this->addColumn('product', 'quantity_max_sunday', Schema::TYPE_FLOAT.' DEFAULT NULL') ;
}

public function safeDown()
{
$this->alterColumn('product', 'quantity_max', Schema::TYPE_INTEGER) ;
$this->dropColumn('product', 'quantity_max_monday');
$this->dropColumn('product', 'quantity_max_tuesday');
$this->dropColumn('product', 'quantity_max_wednesday') ;
$this->dropColumn('product', 'quantity_max_thursday') ;
$this->dropColumn('product', 'quantity_max_friday') ;
$this->dropColumn('product', 'quantity_max_saturday') ;
$this->dropColumn('product', 'quantity_max_sunday') ;
}
}

Loading…
Cancel
Save