From: Vladimir Fomichev Date: Thu, 7 Aug 2025 15:05:34 +0000 (+0300) Subject: Убрал активность X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=88a5e557acdb8825aca759a65abb5fa4ba72c063;p=erp24_rep%2Fyii-erp24%2F.git Убрал активность --- diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index 0b9070d3..0b478c09 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -111,7 +111,6 @@ class Products1cNomenclatureActualityController extends Controller ->where(['property_id' => $propIds, 'value' => $filter->$attr]) ->column(); if (empty($ids)) { - // если нет подходящих свойств — сразу пустая выборка $query->andWhere('0=1'); break; } @@ -121,20 +120,24 @@ class Products1cNomenclatureActualityController extends Controller $needJoin = $filter->onlyActive || $filter->onlyInactive || $filter->date_from || $filter->date_to; if ($needJoin) { - $query->innerJoin( - Products1cNomenclatureActuality::tableName() . ' a', - 'a.guid = n.id' - ); + if ($filter->onlyActive) { - $query->andWhere(['a.active' => 1]); + $query->innerJoin( + Products1cNomenclatureActuality::tableName() . ' a', + 'a.guid = n.id' + ); + $query->andWhere(['a.guid' => 'n.id']); } elseif ($filter->onlyInactive) { - $query->andWhere(['a.active' => 0]); + // $query->andWhere([ 'not', 'a.guid = n.id']); } if ($filter->date_from || $filter->date_to) { if (!$filter->onlyActive && !$filter->onlyInactive) { - $query->andWhere(['a.active' => 1]); + $query->innerJoin( + Products1cNomenclatureActuality::tableName() . ' a', + 'a.guid = n.id' + ); } if ($filter->date_from && $filter->date_to) { diff --git a/erp24/migrations/m250729_101715_create_products_1c_nomenclature_actuality_table.php b/erp24/migrations/m250729_101715_create_products_1c_nomenclature_actuality_table.php index a0cfdcdc..cd564110 100644 --- a/erp24/migrations/m250729_101715_create_products_1c_nomenclature_actuality_table.php +++ b/erp24/migrations/m250729_101715_create_products_1c_nomenclature_actuality_table.php @@ -21,7 +21,6 @@ class m250729_101715_create_products_1c_nomenclature_actuality_table extends Mig 'guid' => $this->string()->notNull(), 'date_from' => $this->dateTime()->notNull()->comment('Дата и время начала активности'), 'date_to' => $this->dateTime()->null()->comment('Дата и время окончания активности'), - 'active' => $this->tinyInteger()->notNull()->defaultValue(1)->comment('Активность записи'), 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'), 'updated_at' => $this->dateTime()->null()->comment('Дата обновления'), 'created_by' => $this->integer()->notNull()->comment('ИД создателя'), diff --git a/erp24/records/Products1cNomenclature.php b/erp24/records/Products1cNomenclature.php index 34527570..f48b0741 100644 --- a/erp24/records/Products1cNomenclature.php +++ b/erp24/records/Products1cNomenclature.php @@ -78,38 +78,9 @@ class Products1cNomenclature extends \yii\db\ActiveRecord ); } - /** - * Relation: единственная (первыей) активная запись актуальности - */ - public function getActiveActuality(): ActiveQuery + public function hasActuality() : bool { - return $this->hasOne( - Products1cNomenclatureActuality::class, - ['guid' => 'id'] - )->andWhere(['active' => 1]); + return $this->getActualities()->exists(); } - /** - * Проверяет, есть ли для этой номенклатуры активная запись - * @return bool - */ - public function hasActiveActuality(): bool - { - return (bool)$this->getActiveActuality()->exists(); - } - - /** - * Проверяет, есть ли для этой номенклатуры запись актуальности с active = 0 - * - * @return bool - */ - public function hasInactiveActuality(): bool - { - return (bool) Products1cNomenclatureActuality::find() - ->where([ - 'guid' => $this->id, - 'active' => 0, - ]) - ->exists(); - } } diff --git a/erp24/records/Products1cNomenclatureActuality.php b/erp24/records/Products1cNomenclatureActuality.php index e1ad21d6..34b6318f 100644 --- a/erp24/records/Products1cNomenclatureActuality.php +++ b/erp24/records/Products1cNomenclatureActuality.php @@ -11,7 +11,6 @@ use Yii; * @property string $guid * @property string $date_from Дата и время начала активности * @property string|null $date_to Дата и время окончания активности - * @property int $active Активность записи * @property string $created_at Дата создания * @property string|null $updated_at Дата обновления * @property int $created_by ИД создателя @@ -36,11 +35,10 @@ class Products1cNomenclatureActuality extends \yii\db\ActiveRecord { return [ [['date_to', 'updated_at', 'updated_by'], 'default', 'value' => null], - [['active'], 'default', 'value' => 1], [['guid', 'date_from', 'created_at', 'created_by'], 'required'], [['date_from', 'date_to', 'created_at', 'updated_at'], 'safe'], - [['active', 'created_by', 'updated_by'], 'default', 'value' => null], - [['active', 'created_by', 'updated_by'], 'integer'], + [['created_by', 'updated_by'], 'default', 'value' => null], + [['created_by', 'updated_by'], 'integer'], [['guid'], 'string', 'max' => 255], ]; } @@ -55,7 +53,6 @@ class Products1cNomenclatureActuality extends \yii\db\ActiveRecord 'guid' => 'Guid', 'date_from' => 'Date From', 'date_to' => 'Date End', - 'active' => 'Active', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'created_by' => 'Created By', diff --git a/erp24/views/products1c-nomenclature-actuality/index.php b/erp24/views/products1c-nomenclature-actuality/index.php index f0998b1f..130760a1 100644 --- a/erp24/views/products1c-nomenclature-actuality/index.php +++ b/erp24/views/products1c-nomenclature-actuality/index.php @@ -245,11 +245,7 @@ $months = monthList(); 'tableOptions' => ['class' => 'table table-bordered'], 'containerOptions' => ['style' => 'overflow:auto; max-height:500px;'], 'rowOptions' => function($model) use ($filter) { - if ($filter->onlyInactive) { - if ($model->hasInactiveActuality()) { - return ['class' => 'table-danger']; - } - } elseif ($model->hasActiveActuality()) { + if ($model->hasActuality()) { return ['class' => 'table-success']; } return []; @@ -269,29 +265,21 @@ $months = monthList(); 'format' => 'raw', 'contentOptions' => ['style'=>'white-space:nowrap; min-width:200px;'], 'value' => function ($m, $k, $i) use ($months, $filter) { - if ($filter->onlyInactive) { - $actuality = Products1cNomenclatureActuality::find() - ->where(['guid' => $m->id, 'active' => 0]) + $actuality = $m->getActualities() ->one(); $from = $actuality ? (new \DateTime($actuality->date_from))->format('Y-m') : null; $to = $actuality ? (new \DateTime($actuality->date_to))->format('Y-m') : null; - } else { - $active = $m->getActiveActuality()->one(); - $from = $active ? (new \DateTime($active->date_from))->format('Y-m') : null; - $to = $active ? (new \DateTime($active->date_to))->format('Y-m') : null; - } - return Html::hiddenInput("actuality[$i][guid]", $m->id) . Html::tag('div', Html::dropDownList("actuality[$i][from]", $from, $months, [ 'class'=>'form-select from-month form-select-sm me-1', 'prompt'=>'от', - 'disabled' => $filter->onlyInactive ? true : null + ]) . Html::dropDownList("actuality[$i][to]", $to, $months, [ 'class'=>'form-select to-month form-select-sm', 'prompt'=>'до', - 'disabled' => $filter->onlyInactive ? true : null + ]), ['class'=>'d-flex align-items-center'] ); @@ -303,7 +291,7 @@ $months = monthList(); 'contentOptions' => ['style'=>'width:60px; text-align:center;'], 'value' => function ($m, $k, $i) use ($filter){ return Html::checkbox("actuality[$i][warehouse_nn]", false, [ - 'disabled' => $filter->onlyInactive ? true : null + ]); } ], @@ -313,7 +301,7 @@ $months = monthList(); 'contentOptions' => ['style'=>'width:60px; text-align:center;'], 'value' => function ($m, $k, $i) use ($filter){ return Html::checkbox("actuality[$i][warehouse_msk]", false, [ - 'disabled' => $filter->onlyInactive ? true : null + ]); } ],