});
});
-$('.subcategory .list-group-item').on('click', function (e) {
- e.preventDefault();
- window.getSelection()?.removeAllRanges();
- this.blur();
-
- if (!$('#week').val() || !$('#year').val()) {
- alert('Необходимо выбрать год и неделю для отображения планограммы');
- return;
- }
-
- const $link = $(this);
- const category = $link.data('category');
- const subcategory = $link.data('subcategory');
- const $row = $link.closest('tr');
- const filters = getFilterData();
- filters['month'] = getMonthByWeek(filters['week'], filters['year'], true);
- filters.category = category;
- filters.subcategory = subcategory;
-
- $('.loader-overlay').removeClass('d-none');
-
- $.get('/auto-plannogramma/get-products', filters, response => {
- $row.nextAll('tr.inserted-row').remove();
-
- if (!response || response.length === 0) {
- alert('Нет планограммы для выбранного периода');
+response.forEach(item => {
+ const tr = $('<tr class="inserted-row"></tr>');
+
+ const subcategoryTd = $(`
+ <td class="subcategory d-flex justify-content-end">
+ <span class="list-group-item list-group-item-action subcategory-link w-90"
+ data-category="${category}" data-subcategory="${subcategory}">
+ ${item.name}
+ </span>
+ </td>
+ `);
+ tr.append(subcategoryTd);
+
+ const valuesMap = Object.fromEntries(item.values.map(val => [
+ val.store_id,
+ {
+ quantity: val.quantity,
+ id: val.id,
+ title: val.title || {}
}
+ ]));
- // Функция генерации текста для title
- function generateTitleString(titleObj) {
- if (!titleObj || typeof titleObj !== 'object') return '';
- let parts = [];
+ $('table thead th').each(function (index) {
+ const $th = $(this);
+ const storeId = $th.data('store-id');
- for (const [type, groups] of Object.entries(titleObj)) {
- if (typeof groups !== 'object') continue;
- let groupParts = [];
- for (const [group, value] of Object.entries(groups)) {
- groupParts.push(`${group}: ${value}`);
- }
- parts.push(`${type} — ${groupParts.join(', ')}`);
- }
+ if (storeId === undefined) return;
- return parts.join(' | ');
- }
+ const isVisible = $(`table tbody tr:first td:eq(${index})`).is(':visible');
+ if (!isVisible) return;
- response.forEach(item => {
- const tr = $('<tr class="inserted-row"></tr>');
-
- const subcategoryTd = $(`
- <td class="subcategory d-flex justify-content-end">
- <span class="list-group-item list-group-item-action subcategory-link w-90"
- data-category="${category}" data-subcategory="${subcategory}">
- ${item.name}
- </span>
- </td>
- `);
- tr.append(subcategoryTd);
-
- const valuesMap = Object.fromEntries(item.values.map(val => [
- val.store_id,
- {
- quantity: val.quantity,
- id: val.id,
- title: val.title || {}
- }
- ]));
-
- $('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 tooltipTitle = generateTitleString(val.title);
- const encodedTooltip = $('<div>').text(tooltipTitle).html(); // безопасно экранируем
-
- const td = $(`
- <td data-store-id="${storeId}">
- <div class="d-flex align-items-center">
- <input type="number" class="btn btn-primary input w-100"
- value="${val.quantity}"
- data-id="${val.id}"
- data-guid="${item.product_id}"
- data-store_id="${storeId}"
- title="${encodedTooltip}"
- data-bs-toggle="tooltip"
- data-bs-placement="top"
- data-original-value="${val.quantity}">
- <button class="reject-btn border-0 bg-transparent cursor-pointer">
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
- <path d="M20 11v5a1 1 0 0 1-2 0v-4H7.414l1.293 1.293a1 1 0 0 1-1.414 1.414l-3-3a1 1 0 0 1 0-1.416l3-3a1 1 0 1 1 1.414 1.416L7.414 10H19a1 1 0 0 1 1 1z"
- fill="grey" stroke="none"/>
- </svg>
- </button>
- </div>
- </td>
- `);
-
- tr.append(td);
- });
+ const val = valuesMap[storeId];
+ if (!val) {
+ tr.append(`<td data-store-id="${storeId}"></td>`);
+ return;
+ }
- $row.after(tr);
- });
+ const tooltipTitle = generateTitleString(val.title);
+ const encodedTooltip = $('<div>').text(tooltipTitle).html();
+
+ const td = $(`
+ <td data-store-id="${storeId}">
+ <div class="d-flex align-items-center">
+ <input type="number" class="btn btn-primary input w-100"
+ value="${val.quantity}"
+ data-id="${val.id}"
+ data-guid="${item.product_id}"
+ data-store_id="${storeId}"
+ title="${encodedTooltip}"
+ data-bs-toggle="tooltip"
+ data-bs-placement="top"
+ data-original-value="${val.quantity}">
+ <button class="reject-btn border-0 bg-transparent cursor-pointer">
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <path d="M20 11v5a1 1 0 0 1-2 0v-4H7.414l1.293 1.293a1 1 0 0 1-1.414 1.414l-3-3a1 1 0 0 1 0-1.416l3-3a1 1 0 1 1 1.414 1.416L7.414 10H19a1 1 0 0 1 1 1z"
+ fill="grey" stroke="none"/>
+ </svg>
+ </button>
+ </div>
+ </td>
+ `);
+
+ tr.append(td);
+ });
- // Инициализация Bootstrap tooltips
- $('[data-bs-toggle="tooltip"]').tooltip();
- })
- .fail(xhr => alert('Ошибка: ' + xhr.responseText))
- .always(() => {
- $('.loader-overlay').addClass('d-none');
- });
+ $row.after(tr);
});
$('.category .list-group-item').on('click', function () {