@davoodmehraban89 / Factor-easy / commits / c452dfd
Fork 0

سامانه صدور فاکتور و حسابداری

fix(invoices): route posted invoice corrections through reversal RPC

davoodmehraban89 committed Nov 17, 2026 at 21:54 UTC c452dfd0c892908e954f265e7bfc3bffdd5644a7
1 file changed +3 -3
js/invoices.js
+3 -3
@@ -460,8 +460,8 @@ async function reopenPostedInvoiceAsDraft(invoiceId,reason){
460 correctsInvoiceId:inv.id,correctsVoucherId:v.id,correctionReason:why,
461 correctionOriginalNumber:inv.number};
462 for(const key of ['journalVoucherId','accountingPostedAt','documentPostedAt','documentPostedBy','postedAt','postedBy','reversalVoucherId'])delete draft[key];
463 - // jeReverse records a balanced linked reversal; historical source and lines stay immutable.
464 - const reversal=jeReverse(v.id,getJalaliNumeric(),why);
463 + // The reversal RPC creates the compensating voucher without mutating posted journal rows.
464 + const reversal=await jeRpcReverse(v.id,getJalaliNumeric(),why);
465 draft.correctionReversalId=reversal.id;
466 datastore.invoices.push(draft);saveDatastore();
467 await invoicePilotAwaitSync(['journalVouchers|'+v.id,'journalVouchers|'+reversal.id,'invoices|'+draft.id]);
@@ -472,7 +472,7 @@ async function cancelPostedInvoicePilot(invoiceId,reason){
472 const inv=getMyInvoices().find(x=>x.id===invoiceId);
473 const v=invoicePilotCorrectionEligible(inv);
474 const why=String(reason||'').trim();if(!why)throw new Error('دلیل ابطال الزامی است.');
475 - const reversal=jeReverse(v.id,getJalaliNumeric(),'ابطال پایلوت: '+why);
475 + const reversal=await jeRpcReverse(v.id,getJalaliNumeric(),'ابطال پایلوت: '+why);
476 await invoicePilotAwaitSync(['journalVouchers|'+v.id,'journalVouchers|'+reversal.id]);
477 refreshAllSurfaces();return reversal.id;
478 }