From f7dbb7e646fd99271a1b1ccd2b65648283c805b1 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 17 Jun 2025 11:12:25 +0300 Subject: [PATCH] =?utf8?q?ERP-360=20=D0=A1=D0=B1=D0=BE=D1=80=D0=BA=D0=B0?= =?utf8?q?=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D0=B0?= =?utf8?q?=D0=B2=D1=82=D0=BE=D0=BF=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../js/autoplannogramma/autoplannogramma.js | 193 ++++++++++++------ 1 file changed, 133 insertions(+), 60 deletions(-) diff --git a/erp24/web/js/autoplannogramma/autoplannogramma.js b/erp24/web/js/autoplannogramma/autoplannogramma.js index 0fd2b4e7..23671642 100644 --- a/erp24/web/js/autoplannogramma/autoplannogramma.js +++ b/erp24/web/js/autoplannogramma/autoplannogramma.js @@ -42,74 +42,147 @@ document.addEventListener("DOMContentLoaded", () => { }); }); -response.forEach(item => { - const tr = $(''); - - const subcategoryTd = $(` - - - ${item.name} - - - `); - tr.append(subcategoryTd); - - const valuesMap = Object.fromEntries(item.values.map(val => [ - val.store_id, - { - quantity: val.quantity, - id: val.id, - title: val.title || {} - } - ])); +$('.subcategory .list-group-item').on('click', function (e) { + e.preventDefault(); - $('table thead th').each(function (index) { - const $th = $(this); - const storeId = $th.data('store-id'); + window.getSelection()?.removeAllRanges(); + $(this).blur(); - if (storeId === undefined) return; + const week = $('#week').val(); + const year = $('#year').val(); + if (!week || !year || isNaN(week) || isNaN(year)) { + alert('Необходимо выбрать действительные значения года и недели'); + return; + } - const isVisible = $(`table tbody tr:first td:eq(${index})`).is(':visible'); - if (!isVisible) return; + const $link = $(this); + const category = $link.data('category'); + const subcategory = $link.data('subcategory'); + const $row = $link.closest('tr'); - const val = valuesMap[storeId]; - if (!val) { - tr.append(``); - return; - } + // Get filter data + const filters = getFilterData(); + filters.month = getMonthByWeek(week, year, true); + filters.category = category; + filters.subcategory = subcategory; - const tooltipTitle = generateTitleString(val.title); - const encodedTooltip = $('
').text(tooltipTitle).html(); - - const td = $(` - -
- - -
- - `); - - tr.append(td); - }); + // Show loading overlay + $('.loader-overlay').removeClass('d-none'); + + $.ajax({ + url: '/auto-plannogramma/get-products', + method: 'GET', + data: filters, + success: function (response) { + // Remove existing inserted rows + $row.nextAll('tr.inserted-row').remove(); + + if (!response || !Array.isArray(response) || response.length === 0) { + alert('Нет планограммы для выбранного периода'); + return; + } + + // Generate title string function + const generateTitleString = (titleObj) => { + if (!titleObj || typeof titleObj !== 'object') return ''; + return Object.entries(titleObj) + .map(([type, groups]) => { + if (typeof groups !== 'object') return ''; + const groupParts = Object.entries(groups) + .map(([group, value]) => `${group}: ${value}`); + return `${type} — ${groupParts.join(', ')}`; + }) + .filter(Boolean) + .join(' | '); + }; + + // Create document fragment for better performance + const fragment = document.createDocumentFragment(); + + response.forEach(item => { + const tr = $('').addClass('inserted-row'); + + // Create subcategory cell + const subcategoryTd = $(` + + + ${item.name || ''} + + + `); + tr.append(subcategoryTd); + + // Map values for easier access + const valuesMap = new Map(item.values?.map(val => [ + val.store_id, + { + quantity: val.quantity || 0, + id: val.id || '', + title: val.title || {} + } + ]) || []); + + // Process table headers + $('table thead th').each(function (index) { + const $th = $(this); + const storeId = $th.data('store-id'); + + if (storeId === undefined) return; + + const isVisible = $(`table tbody tr:first td:eq(${index})`).is(':visible'); + if (!isVisible) return; + + const val = valuesMap.get(storeId) || {quantity: 0, id: '', title: {}}; + const tooltipTitle = generateTitleString(val.title); + const encodedTooltip = $('
').text(tooltipTitle).html(); + + const td = $(` + +
+ + +
+ + `); + + tr.append(td); + }); + + fragment.appendChild(tr[0]); + }); + + // Append all rows at once + $row.after(fragment); - $row.after(tr); + // Initialize Bootstrap tooltips + $('[data-bs-toggle="tooltip"]').tooltip(); + }, + error: function (xhr) { + alert('Ошибка: ' + (xhr.responseText || 'Неизвестная ошибка сервера')); + }, + complete: function () { + $('.loader-overlay').addClass('d-none'); + } + }); }); + $('.category .list-group-item').on('click', function () { const $categorySpan = $(this); const category = $categorySpan.text().trim(); -- 2.39.5