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

Add accessible admin reconciliation tab with discrepancy table and CSV export

davoodmehraban89 committed Oct 13, 2026 at 13:21 UTC c7487587e8601d82b8166a36085fff9dd914f3ac
1 file changed +48
src/views/AccountingView.js
+48
@@ -43,6 +43,7 @@ class AccountingViewImpl {
43 ['periods', 'دوره‌های مالی'],
44 ['trial', 'تراز آزمایشی'],
45 ['reports', 'گزارش‌های مالی'],
46 + ...(Auth.isAdmin() ? [['reconciliation','کنترل مغایرت']] : []),
47 ['integration', 'عملیات یکپارچه و انبار']
48 ];
49 return `<div class="page-title"><h2>حسابداری دوبل</h2>
@@ -72,6 +73,7 @@ class AccountingViewImpl {
73 case 'periods': return this.renderPeriods();
74 case 'trial': return this.renderTrial();
75 case 'reports': return this.renderReports();
76 + case 'reconciliation': return this.renderReconciliation();
77 case 'integration': return this.renderIntegration();
78 default: return this.renderJournals();
79 }
@@ -164,6 +166,52 @@ class AccountingViewImpl {
166 setTimeout(()=>URL.revokeObjectURL(url),3000);
167 } catch(error) { Toast.error(error.message); }
168 }
169 + async renderReconciliation() {
170 + if (!Auth.isAdmin()) return '<div class="card">دسترسی به کنترل مغایرت فقط برای مدیر مجاز است.</div>';
171 + const report = await Ledger.reconciliationReport();
172 + const counts = report.counts, totals = report.totals;
173 + const rows = report.issues.slice(0,200).map(item => `<tr>
174 + <td>${html(item.code)}</td><td>${html(item.reference||'—')}</td>
175 + <td>${html(item.message)}</td>
176 + <td>${html(item.expected === null ? '—' : Formatters.number(item.expected))}</td>
177 + <td>${html(item.actual === null ? '—' : Formatters.number(item.actual))}</td></tr>`).join('');
178 + return `<div class="card">
179 + <div class="toolbar"><strong>کنترل مغایرت اسناد، تسویه‌ها و موجودی</strong>
180 + <button class="btn btn-secondary" onclick="window.AccountingView.exportReconciliation()">خروجی CSV</button>
181 + <button class="btn btn-secondary" onclick="window.AccountingView.refresh()">بررسی مجدد</button>
182 + </div>
183 + <p style="margin:10px 0;line-height:1.9">این بررسی فقط خواندنی است و هیچ مبلغ یا سندی را اصلاح نمی‌کند.
184 + ${report.integrated ? 'مغایرت حساب موجودی (۱۰۳) نیز بررسی شده است.' : 'حسابداری یکپارچه غیرفعال است؛ تطبیق انبار و دفتر کل انجام نمی‌شود.'}</p>
185 + <p><strong>اسناد قطعی:</strong> ${Formatters.number(counts.journals)} |
186 + <strong>فاکتورهای مالی:</strong> ${Formatters.number(counts.invoices)} |
187 + <strong>تسویه‌ها:</strong> ${Formatters.number(counts.settlements)} |
188 + <strong>مغایرت‌های شناسایی‌شده:</strong> ${Formatters.number(counts.issues)}</p>
189 + ${report.integrated ? `<p>ارزش موجودی انبار: ${Formatters.number(totals.inventoryBook)} ریال |
190 + مانده دفتر کل موجودی: ${Formatters.number(totals.inventoryLedger)} ریال</p>` : ''}
191 + ${!rows ? '<p style="margin:14px 0;color:var(--text-muted)">در کنترل‌های فعلی مغایرتی مشاهده نشد. این نتیجه جایگزین حسابرسی مستقل نیست.</p>' : ''}
192 + <div class="table-wrap"><table><thead><tr>
193 + <th>نوع کنترل</th><th>مرجع</th><th>شرح مغایرت</th><th>انتظار</th><th>مقدار فعلی</th>
194 + </tr></thead><tbody>${rows}</tbody></table></div>
195 + ${counts.issues>200 ? '<p>فقط ۲۰۰ ردیف نخست نمایش داده شده‌اند؛ برای همه ردیف‌ها خروجی CSV بگیرید.</p>' : ''}
196 + </div>`;
197 + }
198 +
199 + async exportReconciliation() {
200 + try {
201 + if (!Auth.isAdmin()) throw Error('دسترسی مجاز نیست');
202 + const result = await Ledger.reconciliationReport();
203 + const esc = v => '"'+String(v??'').replace(/"/g,'""')+'"';
204 + const rows = [['code','reference','message','expected','actual'],
205 + ...result.issues.map(x=>[x.code,x.reference,x.message,x.expected,x.actual])];
206 + const csv = rows.map(line=>line.map(esc).join(',')).join('\r\n');
207 + const blob = new Blob(['\ufeff',csv],{type:'text/csv;charset=utf-8'});
208 + const url=URL.createObjectURL(blob);
209 + const a=document.createElement('a');a.href=url;a.download='factor-easypro-reconciliation.csv';
210 + document.body.appendChild(a);a.click();a.remove();
211 + setTimeout(()=>URL.revokeObjectURL(url),3000);
212 + } catch(error){Toast.error('خروجی مغایرت: '+error.message);}
213 + }
214 +
215 setTrialPeriod(id) { this.selectedTrialPeriod = id; return this.refresh(); }
216 openPeriodModal() {
217 const body = `<div class="form-group"><label class="form-label">نام دوره</label>