]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-302 Редактирование букета feature_zozirova_erp-302_bouquets_tz
authormarina <m.zozirova@gmail.com>
Fri, 14 Feb 2025 06:58:08 +0000 (09:58 +0300)
committermarina <m.zozirova@gmail.com>
Fri, 14 Feb 2025 06:58:08 +0000 (09:58 +0300)
erp24/controllers/BouquetController.php
erp24/migrations/m250213_095313_create_bouquet_matrix_type_history_table.php
erp24/records/BouquetComposition.php
erp24/records/BouquetCompositionMatrixTypeHistory.php
erp24/views/bouquet/_form.php

index d9922bc70a7465e0d49596455654c93be176d426..ac9425b1b1d2241b8a133631012907785e3aa0e8 100644 (file)
@@ -118,6 +118,7 @@ class BouquetController extends Controller
             $year = $data['year'];
 
             if ($data['matrix_type_id']) {
+
                 BouquetCompositionMatrixTypeHistory::setData($data['matrix_type_id'], $model->id);
             }
 
index e7b157bd7467af7a093ee0a15dad9c4f8569972a..0fa2985646c9921bcf1f1fa5735438482ba459da 100644 (file)
@@ -16,8 +16,8 @@ class m250213_095313_create_bouquet_matrix_type_history_table extends Migration
             'id' => $this->primaryKey(),
             'bouquet_id' => $this->integer()->comment('Букет ИД'),
             'matrix_type_id' => $this->integer()->comment('Тип матрицы ИД'),
-            'date_from' =>  $this->integer()->comment('Дата установки'),
-            'date_to' =>  $this->integer()->comment('Дата изменения'),
+            'date_from' =>  $this->dateTime()->comment('Дата установки'),
+            'date_to' =>  $this->dateTime()->comment('Дата изменения'),
             'is_active' => $this->boolean()->defaultValue(true)->comment('Активна ли запись'),
             'created_at' => $this->dateTime()->comment('Дата создания'),
             'updated_at' => $this->dateTime()->comment('Дата обновления'),
index ef0bd49a4248c52968e532848cae1228244527ed..83cddaf6d6e8dc4a36cc8b50848ade6ecaeeb3fb 100644 (file)
@@ -91,4 +91,9 @@ class BouquetComposition extends ActiveRecord
             ->andWhere(['is_active' => BouquetCompositionMatrixTypeHistory::IS_ACTIVE]);
     }
 
+    public function getForecastMonthAndYear()
+    {
+//        var_dump($this->hasOne(BouquetForecast::class, ['bouquet_id' => 'id'])->createCommand()->getRawSql());die();
+        return $this->hasMany(BouquetForecast::class, ['bouquet_id' => 'id']);
+    }
 }
index 9d8e492d72d250f1d2972c4a7dd14f40a237957f..58a2bbb7f0d9afcdb03a0fac958d8ffb2133e306 100644 (file)
@@ -2,7 +2,10 @@
 namespace yii_app\records;
 
 use Yii;
+use yii\behaviors\BlameableBehavior;
+use yii\behaviors\TimestampBehavior;
 use yii\db\ActiveRecord;
+use yii\db\Expression;
 
 /**
  * This is the model class for table "erp24.bouquet_composition_matrix_type_history".
@@ -22,6 +25,24 @@ class BouquetCompositionMatrixTypeHistory extends ActiveRecord
 {
     public const IS_ACTIVE = true;
 
+    public function behaviors()
+    {
+        return [
+            [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new Expression('NOW()'),
+            ],
+            [
+                'class' => BlameableBehavior::class,
+                'createdByAttribute' => 'created_by',
+                'updatedByAttribute' => 'updated_by',
+            ],
+        ];
+    }
+
+
     /**
      * {@inheritdoc}
      */
@@ -36,8 +57,8 @@ class BouquetCompositionMatrixTypeHistory extends ActiveRecord
     public function rules()
     {
         return [
-            [['bouquet_id', 'matrix_type_id', 'date_from', 'created_by', 'updated_by'], 'integer'],
-            [['created_at', 'updated_at','date_to'], 'safe'],
+            [['bouquet_id', 'matrix_type_id', 'created_by', 'updated_by'], 'integer'],
+            [['created_at', 'updated_at','date_to', 'date_from'], 'safe'],
             [['is_active'], 'boolean']
         ];
     }
@@ -63,14 +84,18 @@ class BouquetCompositionMatrixTypeHistory extends ActiveRecord
 
     public static function setData($value, $bouquetId) {
         if (self::findOne(['bouquet_id' => $bouquetId])) {
+            var_dump(1);die();
             BouquetCompositionMatrixTypeHistory::updateAll(['date_to' => date('Y-m-d H:i:s'), 'bouquet_id' => $bouquetId, 'date_from' => null, 'is_active' => self::IS_ACTIVE]);
         }
+
         $matrixHistoryType = new BouquetCompositionMatrixTypeHistory([
             'bouquet_id' => $bouquetId,
             'matrix_type_id' => $value,
-            'date_from' => date('Y-m-d H:i:s'),
+            'date_from' => new Expression('now()'),
         ]);
-        $matrixHistoryType->save();
+        if(!$matrixHistoryType->save()) {
+            var_dump($matrixHistoryType->getErrors(), $matrixHistoryType->date_from);
+        }
     }
 
     /**
index cd0b26fdcc2391437be43107715511d5b3d89043..8d16ddf13979d3c667cfb24496f6283e6b2f6914 100644 (file)
@@ -178,7 +178,6 @@ $form = ActiveForm::begin([
                     ])->label(false) ?>
                 </div>
             </div>
-
         </div>
 
         <div class="col-md-3">
@@ -186,11 +185,11 @@ $form = ActiveForm::begin([
             <div class="row">
                 <div class="col-md-5">
                     <div class="col-md-3"><?= Html::label("Год", null, ['class' => 'font-weight-bold pt-3 h6']) ?></div>
-                    <div class="col-md-9"> <?= Html::dropDownList("year", null, [2024 => 2024, 2025 => 2025], ['class' => 'form-control']) ?></div>
+                    <div class="col-md-9"> <?= Html::dropDownList("year", $model?->forecastMonthAndYear->year ?? null, [2024 => 2024, 2025 => 2025], ['class' => 'form-control']) ?></div>
                 </div>
                 <div class="col-md-7">
                     <div class="col-md-3"><?= Html::label("Месяц", null, ['class' => 'font-weight-bold pt-3 h6']) ?></div>
-                    <div class="col-md-9"> <?= Html::dropDownList("month", null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control']) ?></div>
+                    <div class="col-md-9"> <?= Html::dropDownList("month", $model?->forecastMonthAndYear->month ?? null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control']) ?></div>
                 </div>
             </div>
             <div class="row">