Fix vendor mapping delete behavior and update docs

This commit is contained in:
Mikhail Chusavitin
2026-02-25 19:06:28 +03:00
parent a4457a0a28
commit 63454554c1
10 changed files with 497 additions and 99 deletions

View File

@@ -54,6 +54,18 @@
</div>
</div>
<!-- Price Changes Modal -->
<div id="price-changes-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
<div class="bg-white rounded-lg p-6 max-w-4xl w-full mx-4 max-h-[85vh] overflow-hidden flex flex-col">
<div class="flex items-center justify-between mb-4">
<h2 class="text-xl font-bold">Изменения цен</h2>
<button type="button" onclick="closePriceChangesModal()" class="text-gray-500 hover:text-gray-700">Закрыть</button>
</div>
<div id="price-changes-summary" class="text-sm text-gray-600 mb-4"></div>
<div id="price-changes-content" class="overflow-auto space-y-4"></div>
</div>
</div>
<script>
let canWrite = false;
let currentPage = 1;
@@ -190,6 +202,74 @@
document.getElementById('create-modal').classList.remove('flex');
}
function closePriceChangesModal() {
document.getElementById('price-changes-modal').classList.add('hidden');
document.getElementById('price-changes-modal').classList.remove('flex');
}
function formatPrice(value) {
if (value === null || value === undefined || Number.isNaN(Number(value))) return '-';
return Number(value).toLocaleString('ru-RU', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
}
function renderPriceChangesTable(items, { showNewPrice = true, showDiff = true } = {}) {
if (!items || items.length === 0) return '<div class="text-sm text-gray-500">Нет данных</div>';
const rows = items.map(item => {
const changeType = item.change_type || '';
const rowClass = changeType === 'increased'
? 'bg-red-50'
: (changeType === 'decreased' ? 'bg-green-50' : '');
const diffValue = Number(item.diff || 0);
const diffText = showDiff && item.diff !== null && item.diff !== undefined
? `${diffValue > 0 ? '+' : ''}${formatPrice(diffValue)}`
: '-';
const diffClass = diffValue > 0 ? 'text-red-700' : (diffValue < 0 ? 'text-green-700' : 'text-gray-700');
return `
<tr class="${rowClass}">
<td class="px-3 py-2 font-mono text-xs">${escapeHtml(item.lot_name || '')}</td>
<td class="px-3 py-2 text-right">${formatPrice(item.old_price)}</td>
${showNewPrice ? `<td class="px-3 py-2 text-right">${item.new_price == null ? '-' : formatPrice(item.new_price)}</td>` : ''}
${showDiff ? `<td class="px-3 py-2 text-right ${diffClass}">${diffText}</td>` : ''}
</tr>
`;
}).join('');
return `
<div class="border rounded-lg overflow-hidden">
<table class="min-w-full text-sm">
<thead class="bg-gray-50">
<tr>
<th class="px-3 py-2 text-left">Позиция</th>
<th class="px-3 py-2 text-right">Было</th>
${showNewPrice ? '<th class="px-3 py-2 text-right">Стало</th>' : ''}
${showDiff ? '<th class="px-3 py-2 text-right">Изм.</th>' : ''}
</tr>
</thead>
<tbody>${rows}</tbody>
</table>
</div>
`;
}
function openPriceChangesModal(pl) {
const changes = pl?.price_changes || {};
const changed = Array.isArray(changes.changed) ? changes.changed : [];
const missing = Array.isArray(changes.missing) ? changes.missing : [];
const prevVersion = changes.previous_pricelist_version || null;
document.getElementById('price-changes-summary').innerHTML = prevVersion
? `Сравнение с прайслистом <span class="font-mono">${escapeHtml(prevVersion)}</span>. Изменилось: <b>${changed.length}</b>, пропало (нет котировок): <b>${missing.length}</b>.`
: 'Предыдущий прайслист для сравнения не найден.';
let html = '';
html += `<div><h3 class="font-semibold mb-2">Изменившиеся цены</h3>${renderPriceChangesTable(changed)}</div>`;
html += `<div><h3 class="font-semibold mb-2">Пропали котировки (цена была раньше)</h3>${renderPriceChangesTable(missing, { showNewPrice: true, showDiff: false })}</div>`;
document.getElementById('price-changes-content').innerHTML = html;
document.getElementById('price-changes-modal').classList.remove('hidden');
document.getElementById('price-changes-modal').classList.add('flex');
}
async function createPricelist() {
const resp = await fetch('/api/pricelists', {
method: 'POST',
@@ -234,6 +314,7 @@
const pl = await createPricelist();
closeCreateModal();
showToast(`Прайслист ${pl.version} создан (${pl.item_count} позиций)`, 'success');
openPriceChangesModal(pl);
loadPricelists(1);
} catch (e) {
showToast('Ошибка: ' + e.message, 'error');