فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix: ordered audit replay

davoodmehraban89 committed Oct 20, 2026 at 08:41 UTC 1d986c1b23f01eff562c2819a7f34153e7fc1fe6
1 file changed +4 -1
src/core/CompanyBackupService.js
+4 -1
@@ -57,7 +57,10 @@ export async function restoreCompanyBackup(data, { companyId, userId, mode = 'me
57 // Reads, ownership validation, foreign-key validation and writes share one IndexedDB transaction.
58 return StorageService.transaction([...COMPANY_BACKUP_STORES, 'settings'], async tx => {
59 for (const store of COMPANY_BACKUP_STORES) {
60 - for (const incoming of data[store] || []) {
60 + const incomingRows = store === 'audit_events'
61 + ? [...(data[store] || [])].sort((a,b) => (a.chainIndex ?? 0) - (b.chainIndex ?? 0))
62 + : data[store] || [];
63 + for (const incoming of incomingRows) {
64 const immutable = store === 'audit_events' || store === 'document_corrections';
65 // Historical audit/correction events cannot be reassigned to a new company.
66 if (immutable && incoming.companyId !== companyId) {