More incremental import fixes

This commit is contained in:
2025-02-01 11:42:51 -05:00
parent 2d0089dc52
commit 1003ff3cf2
3 changed files with 87 additions and 55 deletions

View File

@@ -117,7 +117,12 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
WHEN r.receiving_id IS NOT NULL THEN
DATE(r.date_created)
END as date,
NULLIF(p.date_estin, '0000-00-00') as expected_date,
CASE
WHEN p.date_estin = '0000-00-00' THEN NULL
WHEN p.date_estin IS NULL THEN NULL
WHEN p.date_estin NOT REGEXP '^[0-9]{4}-[0-9]{2}-[0-9]{2}$' THEN NULL
ELSE p.date_estin
END as expected_date,
COALESCE(p.status, 50) as status,
p.short_note as notes,
p.notes as long_note
@@ -359,9 +364,12 @@ async function importPurchaseOrders(prodConnection, localConnection, incremental
function formatDate(dateStr) {
if (!dateStr) return null;
if (dateStr === '0000-00-00' || dateStr === '0000-00-00 00:00:00') return null;
if (typeof dateStr === 'string' && !dateStr.match(/^\d{4}-\d{2}-\d{2}/)) return null;
try {
const date = new Date(dateStr);
if (isNaN(date.getTime())) return null;
if (date.getFullYear() < 1900 || date.getFullYear() > 2100) return null;
return date.toISOString().split('T')[0];
} catch (e) {
return null;