From: Vladimir Fomichev Date: Wed, 30 Jul 2025 08:14:42 +0000 (+0300) Subject: Фильтрация актуальных по датам X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=0f4945de804d04e600bcdbda86de3ff16a40a30e;p=erp24_rep%2Fyii-erp24%2F.git Фильтрация актуальных по датам --- diff --git a/erp24/controllers/Products1cNomenclatureActualityController.php b/erp24/controllers/Products1cNomenclatureActualityController.php index c7a3f3ca..24407d04 100644 --- a/erp24/controllers/Products1cNomenclatureActualityController.php +++ b/erp24/controllers/Products1cNomenclatureActualityController.php @@ -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'], diff --git a/erp24/views/products1c-nomenclature-actuality/index.php b/erp24/views/products1c-nomenclature-actuality/index.php index 8b900703..8774a8f8 100644 --- a/erp24/views/products1c-nomenclature-actuality/index.php +++ b/erp24/views/products1c-nomenclature-actuality/index.php @@ -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(); -= 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 index 00000000..4019d4b2 --- /dev/null +++ b/erp24/web/js/products1cNomenclatureActuality/index.js @@ -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