Files
ihaleist/src/services/preparationChecks.js
T

41 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const HEALTH_CHECKS = [
['uts', 'ÜTS / ürün kaydı'],
['sample', 'Numune / demonstrasyon'],
['service', 'Kurulum / bakım / servis'],
['delivery', 'Teslimat ve süre'],
];
export const documentKey = d => JSON.stringify([d.document, d.mandatory !== false, d.note || '']);
export const documentRevision = file => JSON.stringify([file.id,file.olusturma,file.boyut,file.son_kullanma || null]);
export function documentLinkProblem(check, files, deadlineDate) {
const file = files.find(f=>f.id===check?.documentId);
if (!file || file.erisilebilir === false) return 'Bağlı dosya bulunamadı veya erişilemiyor.';
if (check.documentRevision !== documentRevision(file)) return 'Belge bilgisi değişti; dosyayı yeniden seçip kontrol edin.';
if (file.son_kullanma && ((!/^\d{4}-\d{2}-\d{2}$/.test(file.son_kullanma) || Number.isNaN(Date.parse(file.son_kullanma+'T00:00:00Z')) || new Date(file.son_kullanma+'T00:00:00Z').toISOString().slice(0,10) !== file.son_kullanma) ||
!deadlineDate || file.son_kullanma < deadlineDate)) return 'Belge son teklif tarihinde geçerli değil veya tarih doğrulanamadı.';
return null;
}
export function preparationBlockers(rows, documents, checks = {}, vault) {
const errors = [];
if (!documents.length) errors.push('Belge gereksinimleri belirlenmedi. Resmi dokümana göre belge ekleyin.');
for (const d of documents) {
const c = checks.documents?.[documentKey(d)] || {};
if (d.mandatory === false && c.status === 'notApplicable' && c.evidence?.trim()) continue;
if (vault) {
const problem = vault.loading ? 'Belge deposu yükleniyor.' : vault.error ? 'Belge deposu doğrulanamadı.' : documentLinkProblem(c,vault.documents || [],vault.deadlineDate);
if(problem) errors.push(`${d.document}: ${problem}`);
}
if (c.status !== 'verified' || !c.evidence?.trim()) errors.push(`${d.document}: belge ve kaynak kontrolü eksik.`);
}
for (const row of rows) {
const c = checks.products?.[row.priceKey] || {};
if (c.status !== 'suitable' || !c.product?.trim() || !c.source?.trim())
errors.push(`${row.name}: ürün/hizmet uygunluğu ve teknik kaynak eksik veya uygun değil.`);
for (const [key, label] of HEALTH_CHECKS) {
const field = c[key] || {};
if (!['verified','notApplicable'].includes(field.status) || !field.evidence?.trim())
errors.push(`${row.name}: ${label} kontrolü eksik.`);
}
}
return errors;
}