->where(['property_id' => $propIds, 'value' => $filter->$attr])
->column();
if (empty($ids)) {
- // если нет подходящих свойств — сразу пустая выборка
$query->andWhere('0=1');
break;
}
$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) {
'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('ИД создателя'),
);
}
- /**
- * 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();
- }
}
* @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 ИД создателя
{
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],
];
}
'guid' => 'Guid',
'date_from' => 'Date From',
'date_to' => 'Date End',
- 'active' => 'Active',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
'created_by' => 'Created By',
'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 [];
'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']
);
'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
+
]);
}
],
'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
+
]);
}
],