@davoodmehraban89 / Factor-easy / commits / 774acca
Fork 0

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

fix: reconcile posted voucher link back to its source record

davoodmehraban89 committed Nov 17, 2026 at 14:02 UTC 774acca98b5fd50358bab2703e06545da473821f
1 file changed +20 -1
js/journal-rpc.js
+20 -1
@@ -207,7 +207,15 @@ async function jeRpcAutoPost(kind,sourceId){
207 throw new Error('رکورد منبع برای شرکت فعال پیدا نشد.');
208 if(source.journalVoucherId){
209 const existing=getMyJournalVouchers().find(v=>v.id===source.journalVoucherId);
210 - if(existing?.status==='posted')return existing;
210 + if(existing?.status==='posted'){
211 + source.accountingVersion=Number(source.accountingVersion||1);
212 + source.accountingStatus='posted';source.accountingPostedAt=existing.postedAt||new Date().toISOString();
213 + source.documentStatus='posted';source.documentPostedAt=existing.postedAt||new Date().toISOString();
214 + source.documentPostedBy=existing.postedBy||currentUser.id;
215 + source.documentVersion=Number(source.documentVersion||1);
216 + await jeRpcPersistSourceRecord(collection,sourceId);
217 + return existing;
218 + }
219 throw new Error('رکورد منبع از قبل به سندی متصل است؛ وضعیت اتصال باید بررسی شود.');
220 }
221 if(!Number.isSafeInteger(Number(source.grandTotal))||Number(source.grandTotal)<=0)
@@ -231,5 +239,16 @@ async function jeRpcAutoPost(kind,sourceId){
239 if(!voucher?.id||voucher.status!=='posted')
240 throw new Error('پاسخ ثبت خودکار سرور فاقد سند قطعی معتبر است؛ وضعیت منبع را پیش از تکرار بررسی کنید.');
241 await jeRpcRefresh(org);
242 + const reconciledSource=jeRpcSourceRecord(collection,sourceId);
243 + if(!reconciledSource)throw new Error('سند قطعی ثبت شد اما رکورد منبع پس از بازخوانی پیدا نشد؛ وضعیت را بررسی کنید.');
244 + reconciledSource.journalVoucherId=voucher.id;
245 + reconciledSource.accountingVersion=Number(reconciledSource.accountingVersion||1);
246 + reconciledSource.accountingStatus='posted';
247 + reconciledSource.accountingPostedAt=voucher.postedAt||new Date().toISOString();
248 + reconciledSource.documentStatus='posted';
249 + reconciledSource.documentPostedAt=voucher.postedAt||new Date().toISOString();
250 + reconciledSource.documentPostedBy=voucher.postedBy||currentUser.id;
251 + reconciledSource.documentVersion=Number(reconciledSource.documentVersion||1);
252 + await jeRpcPersistSourceRecord(collection,sourceId);
253 return voucher;
254 }