fix: require explicit choice for conflicting bid item sources
This commit is contained in:
@@ -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 || [],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user