]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Фильтрация актуальных по датам
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 30 Jul 2025 08:14:42 +0000 (11:14 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 30 Jul 2025 08:14:42 +0000 (11:14 +0300)
erp24/controllers/Products1cNomenclatureActualityController.php
erp24/views/products1c-nomenclature-actuality/index.php
erp24/web/js/products1cNomenclatureActuality/index.js [new file with mode: 0644]

index c7a3f3ca40074dc20c9f8d19d3aa5b45922a97e4..24407d04f3a4cf9b59919e788d92ee36135be2de 100644 (file)
@@ -94,22 +94,35 @@ class Products1cNomenclatureActualityController extends Controller
 
             if ($filter->date_from || $filter->date_to) {
                 $query->innerJoin(
-                    Products1cNomenclatureActuality::tableName() . ' a',
+                    Products1cNomenclatureActuality::tableName().' a',
                     'a.guid = n.id AND a.active = 1'
                 );
-                if ($filter->date_from) {
+
+                if ($filter->date_from && $filter->date_to) {
+                    $dfObj = \DateTime::createFromFormat('Y-m', $filter->date_from);
+                    $dtObj = \DateTime::createFromFormat('Y-m', $filter->date_to);
+                    $dfObj->setTime(0,0,0);
+                    $dtObj->modify('last day of this month')->setTime(23,59,59);
+
+                    $query->andWhere(['<=', 'a.date_from', $dtObj->format('Y-m-d H:i:s')])
+                        ->andWhere(['>=', 'a.date_end',   $dfObj->format('Y-m-d H:i:s')]);
+                }
+
+                elseif ($filter->date_from) {
                     $df = \DateTime::createFromFormat('Y-m', $filter->date_from)
                         ->format('Y-m-01 00:00:00');
-                    $query->andWhere(['>=', 'a.date_from', $df]);
+                    $query->andWhere(['>=', 'a.date_end', $df]);
                 }
-                if ($filter->date_to) {
+
+                elseif ($filter->date_to) {
                     $dt = \DateTime::createFromFormat('Y-m', $filter->date_to);
                     $dt->modify('last day of this month')->setTime(23,59,59);
-                    $query->andWhere(['<=', 'a.date_end', $dt->format('Y-m-d H:i:s')]);
+                    $query->andWhere(['<=', 'a.date_from', $dt->format('Y-m-d H:i:s')]);
                 }
             }
 
 
+
             $attrMap = [
                 'type'  => ['type','тип'],
                 'color' => ['цвет','color'],
index 8b9007037d5c214b56bc9b0ab3717709eb6b55ac..8774a8f8935434af0a6b80c388b67cde32ce2df0 100644 (file)
@@ -3,6 +3,7 @@
 use kartik\form\ActiveForm;
 use kartik\grid\GridView;
 use yii\helpers\Html;
+use yii\web\View;
 
 
 /* @var $this yii\web\View */
@@ -18,7 +19,7 @@ use yii\helpers\Html;
 
 $this->title = 'Актуализация номенклатуры';
 $this->params['breadcrumbs'][] = $this->title;
-
+$this->registerJsFile('/js/products1cNomenclatureActuality/index.js', ['position' => View::POS_END]);
 // Список месяцев-годов для выпадающих списков
 function monthList()
 {
@@ -295,38 +296,3 @@ $months = monthList();
 
 </div>
 
-<?php
-$js = <<<JS
-$('.from-month').on('change', function(){
-    var from = $(this).val(),
-        to   = $(this).closest('td').find('.to-month');
-    to.find('option').each(function(){
-        $(this).toggle($(this).val() >= from);
-    });
-    if (to.val() < from) {
-        to.val(from);
-    }
-});
-
-    $('#filter-date-from').on('change', function(){
-        var from = $(this).val();
-        var to = $('#filter-date-to');
-        to.find('option').each(function(){
-            var val = $(this).val();
-            if (val === '' || val >= from) {
-                $(this).show();
-            } else {
-                $(this).hide();
-            }
-        });
-        if (to.val() && to.val() < from) {
-            to.val(from);
-        }
-    });
-$('.clear-btn').on('click', function(){
-    var target = $(this).data('target');
-    $('#' + target).val(null).trigger('change');
-});
-JS;
-$this->registerJs($js);
-?>
diff --git a/erp24/web/js/products1cNomenclatureActuality/index.js b/erp24/web/js/products1cNomenclatureActuality/index.js
new file mode 100644 (file)
index 0000000..4019d4b
--- /dev/null
@@ -0,0 +1,33 @@
+document.addEventListener("DOMContentLoaded", () => {
+$('.from-month').on('change', function(){
+    var from = $(this).val(),
+        to   = $(this).closest('td').find('.to-month');
+    to.find('option').each(function(){
+        $(this).toggle($(this).val() >= from);
+    });
+    if (to.val() < from) {
+        to.val(from);
+    }
+});
+
+$('#filter-date-from').on('change', function(){
+    var from = $(this).val();
+    var to = $('#filter-date-to');
+    to.find('option').each(function(){
+        var val = $(this).val();
+        if (val === '' || val >= from) {
+            $(this).show();
+        } else {
+            $(this).hide();
+        }
+    });
+    if (to.val() && to.val() < from) {
+        to.val(from);
+    }
+});
+$('.clear-btn').on('click', function(){
+    var target = $(this).data('target');
+    $('#' + target).val(null).trigger('change');
+});
+
+});
\ No newline at end of file