سامانه صدور فاکتور و حسابداری
feat: route purchase finalization through server autopost RPC
davoodmehraban89 committed
Nov 17, 2026 at 13:53 UTC
27b78038a41c49fe0a2b5e645faf871db1ce5f2f
1 file changed
+14
-2
js/purchases.js
+14
-2
@@ -171,8 +171,20 @@
171
if(!fy||fy.status==='locked')throw new Error('تاریخ خرید در سال مالی باز نیست.');
172
if(!p.supplierId||!p.items?.length||!Number.isFinite(p.grandTotal)||p.grandTotal<=0)
173
throw new Error('اطلاعات تأمینکننده و مبلغ خرید نامعتبر است.');
174
- const voucher=jePostSourceRecord('purchase',p);p.documentStatus='posted';p.documentPostedAt=voucher.postedAt;
175
- saveDatastore();await invoicePilotAwaitSync(['journalVouchers|'+voucher.id,'purchases|'+id]);
174
+ // Persist the purchase draft first; the server derives and posts the
175
+ // accounting lines atomically. Generic sync only persists the source link.
176
+ const voucher=await jeRpcAutoPost('purchase',id);
177
+ const savedPurchase=myPurchases().find(x=>x.id===id);
178
+ if(!savedPurchase)throw new Error('خرید پس از ثبت حسابداری از سرور بارگذاری نشد؛ پیش از تکرار وضعیت سند را بررسی کنید.');
179
+ savedPurchase.journalVoucherId=voucher.id;
180
+ savedPurchase.accountingVersion=Number(savedPurchase.accountingVersion||1);
181
+ savedPurchase.accountingStatus='posted';
182
+ savedPurchase.accountingPostedAt=voucher.postedAt||new Date().toISOString();
183
+ savedPurchase.documentStatus='posted';
184
+ savedPurchase.documentPostedAt=voucher.postedAt||new Date().toISOString();
185
+ savedPurchase.documentPostedBy=currentUser.id;
186
+ savedPurchase.documentVersion=Number(savedPurchase.documentVersion||1);
187
+ await jeRpcPersistSourceRecord('purchases',id);
188
refreshAllSurfaces();return voucher.id;
189
};
190
window.deletePurchasePilotDraft=function(id){