Add new items section to price changes modal

Track positions added to a pricelist (not present in the previous one)
and display them in a separate "Новые позиции" section in the price
changes modal on both pricelists and admin_pricing pages.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-03-12 11:39:47 +03:00
parent d067a5890a
commit c0fecde34e
4 changed files with 46 additions and 12 deletions

View File

@@ -1982,18 +1982,18 @@ function formatPricelistChangePrice(value) {
return Number(value).toLocaleString('ru-RU', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
}
function renderPricelistChangesTable(items, { showDiff = true } = {}) {
function renderPricelistChangesTable(items, { showOldPrice = true, showDiff = true } = {}) {
if (!items || items.length === 0) return '<div class="text-sm text-gray-500">Нет данных</div>';
const rows = items.map(item => {
const t = item.change_type || '';
const rowClass = t === 'increased' ? 'bg-red-50' : (t === 'decreased' ? 'bg-green-50' : '');
const rowClass = t === 'increased' ? 'bg-red-50' : (t === 'decreased' ? 'bg-green-50' : (t === 'added' ? 'bg-blue-50' : ''));
const diffValue = Number(item.diff || 0);
const diffClass = diffValue > 0 ? 'text-red-700' : (diffValue < 0 ? 'text-green-700' : 'text-gray-700');
const diffText = (showDiff && item.diff != null) ? `${diffValue > 0 ? '+' : ''}${formatPricelistChangePrice(diffValue)}` : '-';
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">${formatPricelistChangePrice(item.old_price)}</td>
${showOldPrice ? `<td class="px-3 py-2 text-right">${formatPricelistChangePrice(item.old_price)}</td>` : ''}
<td class="px-3 py-2 text-right">${item.new_price == null ? '-' : formatPricelistChangePrice(item.new_price)}</td>
<td class="px-3 py-2 text-right ${diffClass}">${diffText}</td>
</tr>
@@ -2005,7 +2005,7 @@ function renderPricelistChangesTable(items, { showDiff = true } = {}) {
<thead class="bg-gray-50">
<tr>
<th class="px-3 py-2 text-left">Позиция</th>
<th class="px-3 py-2 text-right">Было</th>
${showOldPrice ? '<th class="px-3 py-2 text-right">Было</th>' : ''}
<th class="px-3 py-2 text-right">Стало</th>
<th class="px-3 py-2 text-right">Изм.</th>
</tr>
@@ -2020,9 +2020,10 @@ function openPricelistPriceChangesModal(pricelist) {
const changes = pricelist?.price_changes || {};
const changed = Array.isArray(changes.changed) ? changes.changed : [];
const missing = Array.isArray(changes.missing) ? changes.missing : [];
const added = Array.isArray(changes.added) ? changes.added : [];
const prevVersion = changes.previous_pricelist_version || null;
document.getElementById('pricelist-price-changes-summary').innerHTML = prevVersion
? `Сравнение с прайслистом <span class="font-mono">${escapeHtml(prevVersion)}</span>. Изменилось: <b>${changed.length}</b>, пропало (нет котировок): <b>${missing.length}</b>.`
? `Сравнение с прайслистом <span class="font-mono">${escapeHtml(prevVersion)}</span>. Изменилось: <b>${changed.length}</b>, пропало: <b>${missing.length}</b>, добавлено: <b>${added.length}</b>.`
: 'Предыдущий прайслист для сравнения не найден.';
document.getElementById('pricelist-price-changes-content').innerHTML = `
<div>
@@ -2033,6 +2034,10 @@ function openPricelistPriceChangesModal(pricelist) {
<h3 class="font-semibold mb-2">Пропали котировки (цена была раньше)</h3>
${renderPricelistChangesTable(missing, { showDiff: false })}
</div>
<div>
<h3 class="font-semibold mb-2">Новые позиции</h3>
${renderPricelistChangesTable(added, { showOldPrice: false, showDiff: false })}
</div>
`;
document.getElementById('pricelist-price-changes-modal').classList.remove('hidden');
document.getElementById('pricelist-price-changes-modal').classList.add('flex');