From: marina Date: Fri, 14 Feb 2025 06:58:08 +0000 (+0300) Subject: ERP-302 Редактирование букета X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f2ce9837cc862a4f942e2f034506302a30d6d4c4;p=erp24_rep%2Fyii-erp24%2F.git ERP-302 Редактирование букета --- 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']) ?>