سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 23:15 UTC
feat(accounting): expose immutable ATF and temporary document number in UI
davoodmehraban89 committed
Nov 18, 2026 at 09:09 UTC
35468f5a215a094e8baacf5c95c4367dd8e74116
1 file changed
+6
-6
js/journal-ui.js
+6
-6
@@ -2,10 +2,10 @@
2
3
function ensureJournalView(){
4
if(document.getElementById('view-journal'))return;const s=document.createElement('section');s.id='view-journal';s.className='view-pane';s.innerHTML=`<div class="af-head"><div><h1>اسناد حسابداری</h1><p>ثبت دوبل، ابعاد تحلیلی، قطعیسازی و برگشت اسناد</p></div></div>
5
- <div class="card" data-finora-task="new"><h3>ثبت سند حسابداری</h3><div class="form-row"><div class="form-group"><label>شماره سند</label><input id="je-number" class="form-control" value="پس از قطعیسازی توسط سرور تخصیص مییابد" readonly></div><div class="form-group"><label>تاریخ</label><input id="je-date" class="form-control"></div><div class="form-group"><label>نوع سند</label><select id="je-voucher-type" class="form-control"><option value="manual">عادی</option><option value="adjustment">اصلاحی</option><option value="opening">افتتاحیه</option><option value="closing">اختتامیه</option></select></div><div class="form-group"><label>مرجع</label><input id="je-reference" class="form-control" placeholder="شماره فاکتور/قرارداد/نامه"></div></div>
5
+ <div class="card" data-finora-task="new"><h3>ثبت سند حسابداری</h3><div class="form-row"><div class="form-group"><label>شماره عطف</label><input id="je-atf-number" class="form-control" value="پس از ذخیره موقت تخصیص مییابد" readonly></div><div class="form-group"><label>شماره سند موقت/قطعی</label><input id="je-number" class="form-control" value="پس از ذخیره موقت تخصیص مییابد" readonly></div><div class="form-group"><label>تاریخ</label><input id="je-date" class="form-control"></div><div class="form-group"><label>نوع سند</label><select id="je-voucher-type" class="form-control"><option value="manual">عادی</option><option value="adjustment">اصلاحی</option><option value="opening">افتتاحیه</option><option value="closing">اختتامیه</option></select></div><div class="form-group"><label>مرجع</label><input id="je-reference" class="form-control" placeholder="شماره فاکتور/قرارداد/نامه"></div></div>
6
<div class="form-row"><div class="form-group" style="flex:1"><label>شرح سند</label><input id="je-desc" class="form-control"></div></div><div id="je-lines"></div>
7
<div id="je-totals" class="af-hint" style="margin:10px 0;font-weight:700"></div><input type="hidden" id="je-edit-voucher-id" value=""><div style="display:flex;gap:8px;flex-wrap:wrap"><button class="btn btn-secondary" onclick="jeAddRow()">+ آرتیکل</button><button id="je-save-draft-button" class="btn btn-success" onclick="jeSaveManual()">ثبت پیشنویس</button><button id="je-cancel-edit-button" class="btn btn-secondary" onclick="jeClearManualForm()" style="display:none">انصراف از ویرایش</button></div></div>
8
- <div class="card" data-finora-task="register"><h3>فهرست اسناد حسابداری</h3><div class="table-responsive"><table><thead><tr><th>شماره</th><th>تاریخ</th><th>نوع</th><th>مرجع</th><th>شرح</th><th>وضعیت</th><th>بدهکار</th><th>بستانکار</th><th>منبع</th><th>عملیات</th></tr></thead><tbody id="je-vouchers"></tbody></table></div></div>
8
+ <div class="card" data-finora-task="register"><h3>فهرست اسناد حسابداری</h3><div class="table-responsive"><table><thead><tr><th>عطف</th><th>شماره سند</th><th>تاریخ</th><th>نوع</th><th>مرجع</th><th>شرح</th><th>وضعیت</th><th>بدهکار</th><th>بستانکار</th><th>منبع</th><th>عملیات</th></tr></thead><tbody id="je-vouchers"></tbody></table></div></div>
9
<div class="card" data-finora-task="documents"><h3>مدیریت اسناد — فروش، خرید، دریافت و پرداخت</h3>
10
<p class="af-hint">«اصلاح» همان سند را در فرم اصلی باز میکند. هنگام ذخیره، سابقه حسابداری بهصورت قابلردیابی حفظ میشود؛ بازکردن یا انصراف هیچ ثبت جدیدی ایجاد نمیکند. دریافت/پرداختِ دارای تخصیص به فاکتور یا چک، ابتدا نیازمند تطبیق مستقل است. ابطال فقط ثبت نرمافزاری را خنثی میکند و تراکنش واقعی بانکی را برگشت نمیدهد.</p>
11
<label for="document-status-filter">نمایش وضعیت</label> <select id="document-status-filter" class="form-control" style="max-width:200px" onchange="renderDocumentManagement()"><option value="all">همه</option><option value="draft">پیشنویس</option><option value="posted">قطعی</option><option value="reversed">ابطال/برگشتشده</option><option value="legacy_review">قدیمی و نیازمند تطبیق</option></select>
@@ -32,7 +32,7 @@ function jeLoadDraftUi(id){
32
try{
33
const {voucher:v,lines}=jeVoucherDraftInput(id);
34
if(v.status!=='draft'||v.sourceType!=='manual'||v.sourceId)throw new Error('این سند موقت از نوع قابلویرایش دستی نیست.');
35
- const values=[['je-edit-voucher-id',v.id],['je-number',v.number],['je-date',v.date],['je-voucher-type',v.voucherType],['je-reference',v.reference||''],['je-desc',v.description||'']];
35
+ const values=[['je-edit-voucher-id',v.id],['je-atf-number',v.atfNumber||'در انتظار تخصیص سرور'],['je-number',v.temporaryNumber||v.number||'در انتظار تخصیص سرور'],['je-date',v.date],['je-voucher-type',v.voucherType],['je-reference',v.reference||''],['je-desc',v.description||'']];
36
values.forEach(([name,value])=>{const el=document.getElementById(name);if(el)el.value=value});
37
const box=document.getElementById('je-lines');if(box)box.innerHTML='';
38
lines.forEach(l=>jeAddRow(l));
@@ -49,7 +49,7 @@ async function jeCancelPostedUi(id){
49
if(!confirm('سند قطعی بدون حذف سابقه، با سند برگشتی خنثی شود؟'))return;
50
try{await jeRpcReverse(id,getJalaliNumeric(),'ابطال: '+why);renderJournal()}catch(e){alert(e.message)}
51
}
52
-async function jeSaveManual(){try{const input={date:document.getElementById('je-date').value||getJalaliNumeric(),voucherType:document.getElementById('je-voucher-type').value,reference:document.getElementById('je-reference').value,description:document.getElementById('je-desc').value,lines:jeCollectRows()};const editId=document.getElementById('je-edit-voucher-id')?.value;const v=editId?await jeRpcUpdateDraft(editId,input):await jeRpcCreateDraft(input);alert('پیشنویس سند در سرور ذخیره شد. شماره پس از قطعیسازی تخصیص مییابد.');jeClearManualForm();renderJournal()}catch(e){alert(e.message)}}
52
+async function jeSaveManual(){try{const input={date:document.getElementById('je-date').value||getJalaliNumeric(),voucherType:document.getElementById('je-voucher-type').value,reference:document.getElementById('je-reference').value,description:document.getElementById('je-desc').value,lines:jeCollectRows()};const editId=document.getElementById('je-edit-voucher-id')?.value;const v=editId?await jeRpcUpdateDraft(editId,input):await jeRpcCreateDraft(input);alert('پیشنویس سند در سرور ذخیره شد؛ شماره عطف و شماره موقت آن ثبت شده و تا قطعیشدن ثابت میمانند.');jeClearManualForm();renderJournal()}catch(e){alert(e.message)}}
53
async function jePostUi(id){try{await jeRpcPost(id);renderJournal()}catch(e){alert(e.message)}}
54
async function jeReverseUi(id){const why=prompt('علت برگشت سند:','اصلاح ثبت');if(why===null)return;try{await jeRpcReverse(id,getJalaliNumeric(),why);renderJournal()}catch(e){alert(e.message)}}
55
async function jeCopyVoucherUi(id){try{const v=await jeRpcCopyVoucher(id,getJalaliNumeric());alert('کپی سند در سرور بهصورت پیشنویس ایجاد شد.');renderJournal()}catch(e){alert(e.message)}}
@@ -74,11 +74,11 @@ function renderJournal(options={}){
74
if(typeof afEnsureAccountingP0Compatibility==='function')afEnsureAccountingP0Compatibility();
75
jeEnsureDefaultProfiles();
76
const body=document.getElementById('je-vouchers'),vs=getMyJournalVouchers().slice().sort((a,b)=>String(b.createdAt).localeCompare(String(a.createdAt)));
77
- if(body)body.innerHTML=vs.length?vs.map(v=>{const status=typeof jeRpcEffectiveStatus==='function'?jeRpcEffectiveStatus(v):v.status;return '<tr data-voucher-id="'+esc(v.id)+'"><td>'+esc(v.number||'پس از قطعیسازی')+'</td><td>'+esc(v.date)+'</td><td>'+esc(jeTypeLabel(v.voucherType))+'</td><td>'+esc(v.reference||'—')+'</td><td>'+esc(v.description)+'</td><td data-status-cell>'+esc(jeStatusLabel(status))+'</td><td>'+Number(v.totalDebit||0).toLocaleString('fa-IR')+'</td><td>'+Number(v.totalCredit||0).toLocaleString('fa-IR')+'</td><td>'+esc(v.sourceType||'manual')+'</td><td data-actions-cell>'+jeJournalActions(v,status)+'</td></tr>'}).join(''):'<tr><td colspan="10" class="af-empty">سندی ثبت نشده است.</td></tr>';
77
+ if(body)body.innerHTML=vs.length?vs.map(v=>{const status=typeof jeRpcEffectiveStatus==='function'?jeRpcEffectiveStatus(v):v.status;return '<tr data-voucher-id="'+esc(v.id)+'"><td>'+esc(v.atfNumber||'—')+'</td><td>'+esc(v.temporaryNumber||v.number||'—')+'</td><td>'+esc(v.date)+'</td><td>'+esc(jeTypeLabel(v.voucherType))+'</td><td>'+esc(v.reference||'—')+'</td><td>'+esc(v.description)+'</td><td data-status-cell>'+esc(jeStatusLabel(status))+'</td><td>'+Number(v.totalDebit||0).toLocaleString('fa-IR')+'</td><td>'+Number(v.totalCredit||0).toLocaleString('fa-IR')+'</td><td>'+esc(v.sourceType||'manual')+'</td><td data-actions-cell>'+jeJournalActions(v,status)+'</td></tr>'}).join(''):'<tr><td colspan="10" class="af-empty">سندی ثبت نشده است.</td></tr>';
78
const tb=document.getElementById('je-trial'),rows=jeTrialBalance();
79
if(tb)tb.innerHTML=rows.length?rows.map(x=>'<tr><td>'+esc(x.code)+'</td><td>'+esc(x.title)+'</td><td>'+x.debit.toLocaleString('fa-IR')+'</td><td>'+x.credit.toLocaleString('fa-IR')+'</td><td>'+x.balance.toLocaleString('fa-IR')+'</td></tr>').join(''):'<tr><td colspan="5" class="af-empty">گردشی وجود ندارد.</td></tr>';
80
const d=document.getElementById('je-date');if(d&&!d.value)d.value=getJalaliNumeric();
81
- const n=document.getElementById('je-number');if(n)n.value='پس از قطعیسازی توسط سرور تخصیص مییابد';
81
+ const n=document.getElementById('je-number');if(n)n.value='پس از ذخیره موقت تخصیص مییابد';const atf=document.getElementById('je-atf-number');if(atf)atf.value='پس از ذخیره موقت تخصیص مییابد';
82
if(!document.querySelector('#je-lines .je-line')){jeAddRow();jeAddRow()}
83
jeUpdateTotals();if(typeof renderDocumentManagement==='function')renderDocumentManagement();
84
if(!options.skipStatusRefresh&¤tUser?.organizationId&&typeof jeRpcRefreshEffectiveStatuses==='function'){