diff --git a/src/App.tsx b/src/App.tsx index d635a2f..1a17d0f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -168,10 +168,22 @@ export default function App() { // Only preserve Supabase values if there's a PENDING or EDITED edit for this article if (synced && (synced.status === 'pending' || synced.status === 'edited' || synced.status === 'synced')) { - // Keep the manually edited values from Supabase + // DETECT COLUMN SHIFT: If the saved data uses the old structure (where index 12 was a numeric date), + // we need to shift all indices from 12 onwards by +1 to match today's Excel structure. + const oldData = synced.data; + const valAt12 = oldData[12]; + // Launch Date was index 12 yesterday and it's always a numeric serial. + // PM Classification is index 12 today and it's a string or empty. + const needsShift = typeof valAt12 === 'number' || (typeof valAt12 === 'string' && /^[0-9.]+$/.test(valAt12)); + editableColumns.forEach(idx => { - if (synced.data[idx] !== undefined && synced.data[idx] !== null) { - finalRow[idx] = synced.data[idx]; + let mergeIdx = idx; + if (needsShift && idx >= 12) { + mergeIdx = idx - 1; + } + + if (oldData[mergeIdx] !== undefined && oldData[mergeIdx] !== null) { + finalRow[idx] = oldData[mergeIdx]; } }); setRowStatuses(prev => ({ ...prev, [articleNo]: 'synced' }));