From abc7b72d0be405e41607fa56e3f4ff28f87ed2d0 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Tue, 19 Aug 2025 14:34:09 +0300 Subject: [PATCH] =?utf8?q?=D0=A4=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D1=8B=20?= =?utf8?q?=D0=B8=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ...ducts1cNomenclatureActualityController.php | 67 +++++++--- .../index.php | 4 +- .../products1cNomenclatureActuality/index.js | 117 ++++++++++++++++-- 3 files changed, 164 insertions(+), 24 deletions(-) diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index 222cde25..641c335a 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -118,13 +118,13 @@ class Products1cNomenclatureActualityController extends Controller } } - if ($filter->onlyActive) { + if (!empty($filter->onlyActive)) { $query->andWhere(['exists', Products1cNomenclatureActuality::find() ->where('guid = n.id') ->select(new \yii\db\Expression('1')) ]); - } elseif ($filter->onlyInactive) { + } elseif (!empty($filter->onlyInactive)) { $query->andWhere(['not exists', Products1cNomenclatureActuality::find() ->where('guid = n.id') @@ -133,23 +133,62 @@ class Products1cNomenclatureActualityController extends Controller } if ($filter->date_from || $filter->date_to) { - $query->with(['actualities' => function ($q) use ($filter) { - if ($filter->date_from) { - $df = (new \DateTime("{$filter->date_from}-01")) - ->setTime(0, 0, 0)->format('Y-m-d H:i:s'); - $q->andWhere(['>=', 'date_to', $df]); - } - if ($filter->date_to) { - $dt = (new \DateTime("{$filter->date_to}-01")) - ->modify('last day of this month')->setTime(23, 59, 59) - ->format('Y-m-d H:i:s'); - $q->andWhere(['<=', 'date_from', $dt]); + $hasDf = !empty($filter->date_from); + $hasDt = !empty($filter->date_to); + + $df = null; + $dt = null; + + if ($hasDf) { + $df = (new \DateTime("{$filter->date_from}-01")) + ->setTime(0, 0, 0)->format('Y-m-d H:i:s'); + } + if ($hasDt) { + $dt = (new \DateTime("{$filter->date_to}-01")) + ->modify('last day of this month')->setTime(23, 59, 59) + ->format('Y-m-d H:i:s'); + } + + $dateExists = Products1cNomenclatureActuality::find() + ->alias('a') + ->where('a.guid = n.id'); + + if ($hasDf && !$hasDt) { + $dateExists->andWhere(['a.date_from' => $df]); + } elseif (!$hasDf && $hasDt) { + $dateExists->andWhere(['a.date_to' => $dt]); + } else { + $dateExists + ->andWhere(['>=', 'a.date_from', $df]) + ->andWhere(['<=', 'a.date_to', $dt]); + } + + if (!empty($filter->onlyInactive)) { + $query->andWhere(['not exists', $dateExists->select(new \yii\db\Expression('1'))]); + } else { + $query->andWhere(['exists', $dateExists->select(new \yii\db\Expression('1'))]); + } + + $query->with(['actualities' => function ($q) use ($hasDf, $hasDt, $df, $dt) { + if ($hasDf && !$hasDt) { + $q->andWhere(['date_from' => $df]); + } elseif (!$hasDf && $hasDt) { + $q->andWhere(['date_to' => $dt]); + } else { + $q->andWhere(['>=', 'date_from', $df]) + ->andWhere(['<=', 'date_to', $dt]); } + $q->orderBy(['date_from' => SORT_ASC]); }]); } else { - $query->with('actualities'); + $query->with(['actualities' => function ($q) { + $q->orderBy(['date_from' => SORT_ASC]); + }]); } + + + $products = $query->orderBy(['n.name' => SORT_ASC])->all(); $rows = []; diff --git a/erp24/views/products1c-nomenclature-actuality/index.php b/erp24/views/products1c-nomenclature-actuality/index.php index a8be5ac6..fba62078 100644 --- a/erp24/views/products1c-nomenclature-actuality/index.php +++ b/erp24/views/products1c-nomenclature-actuality/index.php @@ -26,7 +26,7 @@ function monthList() { $list = []; $start = new DateTime('2021-01'); - $end = new DateTime('2025-12'); + $end = new DateTime('2026-12'); while ($start <= $end) { $key = $start->format('Y-m'); $list[$key] = $start->format('Y‑m'); @@ -290,11 +290,13 @@ foreach ($months as $k => $v) { Html::dropDownList("actuality[$i][from]", $from, $months, [ 'class'=>'form-select from-month form-select-sm me-1', 'prompt'=>'от', + 'data-actuality' => $actuality ? 1 : 0, 'style' => 'width:auto;display:inline-block' ]) . Html::dropDownList("actuality[$i][to]", $to, $months, [ 'class'=>'form-select to-month form-select-sm', 'prompt'=>'до', + 'data-actuality' => $actuality ? 1 : 0, 'style' => 'width:auto;display:inline-block' ]), ['class'=>'d-flex align-items-center'] diff --git a/erp24/web/js/products1cNomenclatureActuality/index.js b/erp24/web/js/products1cNomenclatureActuality/index.js index ccfb2f43..8d8ec792 100644 --- a/erp24/web/js/products1cNomenclatureActuality/index.js +++ b/erp24/web/js/products1cNomenclatureActuality/index.js @@ -4,6 +4,10 @@ document.addEventListener("DOMContentLoaded", () => { ([k, v]) => `` ).join(''); + const baseMonths = getMonthsMap(); + const monthsForNewRows = extendMonthsMap({ ...baseMonths }, 0); + const monthsForExisting = baseMonths; + let actualIdx = $('#actuality-form table tbody tr').length || 0; $(document).on('click', '.add-actuality-row', function(){ @@ -26,7 +30,7 @@ document.addEventListener("DOMContentLoaded", () => {
- ${monthOptions}