From f2ce9837cc862a4f942e2f034506302a30d6d4c4 Mon Sep 17 00:00:00 2001 From: marina Date: Fri, 14 Feb 2025 09:58:08 +0300 Subject: [PATCH] =?utf8?q?ERP-302=20=D0=A0=D0=B5=D0=B4=D0=B0=D0=BA=D1=82?= =?utf8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B1=D1=83?= =?utf8?q?=D0=BA=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/BouquetController.php | 1 + ...eate_bouquet_matrix_type_history_table.php | 4 +-- erp24/records/BouquetComposition.php | 5 +++ .../BouquetCompositionMatrixTypeHistory.php | 33 ++++++++++++++++--- erp24/views/bouquet/_form.php | 5 ++- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index d9922bc7..ac9425b1 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -118,6 +118,7 @@ class BouquetController extends Controller $year = $data['year']; if ($data['matrix_type_id']) { + BouquetCompositionMatrixTypeHistory::setData($data['matrix_type_id'], $model->id); } diff --git a/erp24/migrations/m250213_095313_create_bouquet_matrix_type_history_table.php b/erp24/migrations/m250213_095313_create_bouquet_matrix_type_history_table.php index e7b157bd..0fa29856 100644 --- a/erp24/migrations/m250213_095313_create_bouquet_matrix_type_history_table.php +++ b/erp24/migrations/m250213_095313_create_bouquet_matrix_type_history_table.php @@ -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('Дата обновления'), diff --git a/erp24/records/BouquetComposition.php b/erp24/records/BouquetComposition.php index ef0bd49a..83cddaf6 100644 --- a/erp24/records/BouquetComposition.php +++ b/erp24/records/BouquetComposition.php @@ -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']); + } } diff --git a/erp24/records/BouquetCompositionMatrixTypeHistory.php b/erp24/records/BouquetCompositionMatrixTypeHistory.php index 9d8e492d..58a2bbb7 100644 --- a/erp24/records/BouquetCompositionMatrixTypeHistory.php +++ b/erp24/records/BouquetCompositionMatrixTypeHistory.php @@ -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); + } } /** diff --git a/erp24/views/bouquet/_form.php b/erp24/views/bouquet/_form.php index cd0b26fd..8d16ddf1 100644 --- a/erp24/views/bouquet/_form.php +++ b/erp24/views/bouquet/_form.php @@ -178,7 +178,6 @@ $form = ActiveForm::begin([ ])->label(false) ?> -
@@ -186,11 +185,11 @@ $form = ActiveForm::begin([
'font-weight-bold pt-3 h6']) ?>
-
2024, 2025 => 2025], ['class' => 'form-control']) ?>
+
forecastMonthAndYear->year ?? null, [2024 => 2024, 2025 => 2025], ['class' => 'form-control']) ?>
'font-weight-bold pt-3 h6']) ?>
-
'form-control']) ?>
+
forecastMonthAndYear->month ?? null, \yii_app\helpers\DateHelper::MONTH_NUMBER_NAMES, ['class' => 'form-control']) ?>
-- 2.39.5