fix: require explicit choice for conflicting bid item sources

This commit is contained in:
2026-09-06 09:13:26 +03:00
parent c3264149ea
commit 0d2cf584e7
4 changed files with 63 additions and 10 deletions
+15 -2
View File
@@ -1,6 +1,6 @@
// Prices belong to a specific source row, never to its current array position.
export function sourceRows(tender, results) {
const items = tender?.items?.length
export function sourceRows(tender, results, preferredSource = 'tender') {
const items = preferredSource !== 'analysis' && tender?.items?.length
? tender.items.map(k => ({ ...k, name: k.ad, quantity: `${k.miktar} ${k.birim || ''}`, keySpecs: k.keySpecs || [] }))
: (Array.isArray(results?.itemsAndSpecs) ? results.itemsAndSpecs : []);
const occurrences = new Map();
@@ -12,6 +12,18 @@ export function sourceRows(tender, results) {
});
}
export function bidSourceOptions(tender, results, selection = {}) {
const tenderRows = sourceRows(tender, {});
const analysisRows = sourceRows({}, results);
const inventory = rows => rows.map(r => JSON.stringify([r.name?.trim(),r.quantity?.trim(),r.keySpecs || []])).sort();
const signature = JSON.stringify([inventory(tenderRows), inventory(analysisRows), results?.documentVersion || null]);
const conflict = tenderRows.length > 0 && analysisRows.length > 0 &&
JSON.stringify(inventory(tenderRows)) !== JSON.stringify(inventory(analysisRows));
const selected = selection.signature === signature && ['tender','analysis'].includes(selection.source) ? selection.source : '';
return { signature, conflict, selected, tenderCount:tenderRows.length, analysisCount:analysisRows.length,
needsSelection:conflict && !selected };
}
// Exact canonical content, not a lossy hash. Reordering distinct rows is harmless;
// a changed quantity, specification, announcement or document requirement is not.
export function bidSourceSnapshot(tender, results, rows = sourceRows(tender, results)) {
@@ -20,6 +32,7 @@ export function bidSourceSnapshot(tender, results, rows = sourceRows(tender, res
announcement: tender?.aciklama || '',
deadline: [tender?.tarih || '', tender?.saat || ''],
documentVersion: results?.documentVersion ?? tender?.documentVersion ?? null,
analyzedItems: results?.itemsAndSpecs || [],
rows: rows.map(r => r.priceKey).sort(),
documents: results?.documentChecklist || [],
});