1
+<!DOCTYPE html>
2
+<html lang="fa" dir="rtl">
3
+<head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>پلتفرم گزارشگری مالی آرام - نسخه آزمایشی حسابداران</title>
7
+ <style>
8
+ :root {
9
+ --primary: #2563eb;
10
+ --primary-dark: #1d4ed8;
11
+ --sidebar-bg: #0f172a;
12
+ --sidebar-text: #94a3b8;
13
+ --bg: #f8fafc;
14
+ --card: #ffffff;
15
+ --text: #334155;
16
+ --border: #e2e8f0;
17
+ }
18
+ * { box-sizing: border-box; }
19
+ body { font-family: Tahoma, Arial, sans-serif; background-color: var(--bg); margin: 0; padding: 0; direction: rtl; color: var(--text); }
20
+
21
+ /* Modal & Overlay */
22
+ .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.75); display: flex; align-items: center; justify-content: center; z-index: 1000; }
23
+ .modal { background: #fff; padding: 30px; border-radius: 12px; width: 360px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }
24
+ .modal h2 { margin-top: 0; text-align: center; color: #0f172a; }
25
+ .input-group { margin-bottom: 15px; }
26
+ .input-group label { display: block; margin-bottom: 5px; font-weight: bold; font-size: 0.9em; }
27
+ .input-group input, .input-group select { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; }
28
+ .btn-primary { width: 100%; padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; }
29
+ .btn-primary:hover { background: var(--primary-dark); }
30
+
31
+ /* Main Desktop Layout */
32
+ .app-container { display: flex; height: 100vh; overflow: hidden; }
33
+ .sidebar { width: 260px; background: var(--sidebar-bg); color: var(--sidebar-text); padding: 20px 15px; display: flex; flex-direction: column; }
34
+ .brand { font-size: 1.2rem; font-weight: bold; color: #fff; margin-bottom: 25px; text-align: center; padding-bottom: 15px; border-bottom: 1px solid #334155; }
35
+ .nav-item { padding: 12px 15px; margin-bottom: 8px; border-radius: 8px; cursor: pointer; font-weight: 500; transition: all 0.2s; }
36
+ .nav-item:hover, .nav-item.active { background: #1e293b; color: #fff; }
37
+
38
+ .main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
39
+ .topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 12px 25px; display: flex; justify-content: space-between; align-items: center; }
40
+ .selector-bar { display: flex; gap: 15px; align-items: center; }
41
+ .selector-bar select { padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); font-family: inherit; }
42
+
43
+ .content-view { flex: 1; padding: 25px; overflow-y: auto; }
44
+ .card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
45
+
46
+ table { width: 100%; border-collapse: collapse; margin-top: 15px; }
47
+ th, td { border: 1px solid var(--border); padding: 10px 12px; text-align: right; }
48
+ th { background-color: #f1f5f9; font-weight: bold; }
49
+
50
+ .badge { padding: 4px 10px; border-radius: 20px; font-size: 0.8em; font-weight: bold; display: inline-block; }
51
+ .badge-draft { background-color: #fef08a; color: #854d0e; }
52
+ .badge-approved { background-color: #bbf7d0; color: #166534; }
53
+ .badge-status { background-color: #dbeafe; color: #1e40af; }
54
+ .badge-role { background-color: #e2e8f0; color: #334155; }
55
+
56
+ /* Wizard & Actions */
57
+ .flex-actions { display: flex; gap: 10px; margin-top: 15px; }
58
+ .btn-action { padding: 8px 16px; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; background: #059669; color: white; }
59
+ .btn-export { background: #2563eb; color: white; }
60
+ </style>
61
+</head>
62
+<body>
63
+
64
+ <!-- Login Modal -->
65
+ <div id="login-modal" class="modal-overlay">
66
+ <div class="modal">
67
+ <h2>ورود به سامانه حسابداران</h2>
68
+ <p style="font-size:0.85em; color:#64748b; text-align:center; margin-bottom:20px;">ورود امن دسکتاپ - نسخه پایلوت آرام</p>
69
+ <div id="login-error" style="color:red; font-size:0.85em; display:none; margin-bottom:10px; text-align:center;"></div>
70
+ <div class="input-group">
71
+ <label>نام کاربری:</label>
72
+ <input type="text" id="login-username" value="admin_user">
73
+ </div>
74
+ <div class="input-group">
75
+ <label>کلمه عبور:</label>
76
+ <input type="password" id="login-password" value="admin_pass">
77
+ </div>
78
+ <button class="btn-primary" onclick="handleLogin()">ورود به حساب کاربری</button>
79
+ </div>
80
+ </div>
81
+
82
+ <!-- Desktop Main Application Window -->
83
+ <div class="app-container">
84
+ <!-- Sidebar Navigation -->
85
+ <div class="sidebar">
86
+ <div class="brand">پلتفرم آرام (دسکتاپ)</div>
87
+ <div class="nav-item active" onclick="showScreen('dashboard')">داشبورد اصلی</div>
88
+ <div class="nav-item" onclick="showScreen('upload-wizard')">ویزارد بارگذاری صورت مالی</div>
89
+ <div class="nav-item" onclick="showScreen('reports')">مشاهده گزارشهای مالی</div>
90
+ <div class="nav-item" onclick="showScreen('snapshots')">بررسی و تایید اسنپشاتها</div>
91
+ <div class="nav-item" onclick="showScreen('audit-logs')">دفتر ثبت لاگهای حسابرسی</div>
92
+ </div>
93
+
94
+ <!-- Main Content View Area -->
95
+ <div class="main-content">
96
+ <!-- Top Selector & User Context Bar -->
97
+ <div class="topbar">
98
+ <div class="selector-bar">
99
+ <label>شرکت:</label>
100
+ <select id="company-select" onchange="onCompanyChange()">
101
+ <option value="1">شرکت نمونه آریا (کد: COMP01)</option>
102
+ </select>
103
+ <label>دوره مالی:</label>
104
+ <select id="year-select" onchange="onYearChange()">
105
+ <option value="1">سال مالی ۱۴۰۲ (وضعیت: Draft)</option>
106
+ </select>
107
+ </div>
108
+ <div>
109
+ کاربر: <strong id="user-display">کاربر دسکتاپ</strong>
110
+ <span id="role-display" class="badge badge-role">ADMIN</span>
111
+ </div>
112
+ </div>
113
+
114
+ <!-- Content Area -->
115
+ <div class="content-view">
116
+
117
+ <!-- Dashboard Screen -->
118
+ <div id="screen-dashboard" class="screen-section">
119
+ <div class="card">
120
+ <h3>خلاصه وضعیت دوره مالی انتخابشده</h3>
121
+ <p>کد شرکت: <strong id="dash-comp-code">COMP01</strong> | سال مالی: <strong id="dash-year">۱۴۰۲</strong></p>
122
+ <p>وضعیت گردش کار: <span id="dash-workflow-status" class="badge badge-status">UPLOADED</span></p>
123
+ </div>
124
+ </div>
125
+
126
+ <!-- Source Upload Wizard Screen -->
127
+ <div id="screen-upload-wizard" class="screen-section" style="display:none;">
128
+ <div class="card">
129
+ <h3>ویزارد بارگذاری منبع مالی و اجرای گردش کار E2E</h3>
130
+ <p>لطفاً فایل منبع مالی (CSV/XLSX/PDF) را جهت ثبت، نرمالسازی و محاسبه انتخاب فرمایید:</p>
131
+ <div class="input-group" style="max-width:400px;">
132
+ <label>مسیر یا نام فایل منبع:</label>
133
+ <input type="text" id="wizard-filepath" value="financial_ledger_1402.csv">
134
+ </div>
135
+ <div class="input-group" style="max-width:400px;">
136
+ <label>نوع سند:</label>
137
+ <select id="wizard-doctype">
138
+ <option value="ledger">دفتر کل / تراز (Ledger)</option>
139
+ <option value="official_statement">صورت مالی رسمی</option>
140
+ </select>
141
+ </div>
142
+ <div class="flex-actions">
143
+ <button class="btn-action" onclick="runUploadWizard()">شروع پردازش و محاسبه خودکار</button>
144
+ </div>
145
+ </div>
146
+ </div>
147
+
148
+ <!-- Reports Viewer Screen -->
149
+ <div id="screen-reports" class="screen-section" style="display:none;">
150
+ <div class="card">
151
+ <h3>گزارشهای محاسبهشده مالی</h3>
152
+ <div class="flex-actions" style="margin-bottom:15px;">
153
+ <button class="btn-action btn-export" onclick="loadReport('trial-balance')">تراز آزمایشی (TB)</button>
154
+ <button class="btn-action btn-export" onclick="loadReport('balance-sheet')">ترازنامه (BS)</button>
155
+ <button class="btn-action btn-export" onclick="loadReport('income-statement')">صورت سود و زیان (IS)</button>
156
+ <button class="btn-action" style="background:#0284c7;" onclick="exportCSV()">خروجی CSV</button>
157
+ </div>
158
+ <div id="report-output">
159
+ <p>لطفاً یکی از گزارشها را انتخاب کنید.</p>
160
+ </div>
161
+ </div>
162
+ </div>
163
+
164
+ <!-- Snapshot Review Screen -->
165
+ <div id="screen-snapshots" class="screen-section" style="display:none;">
166
+ <div class="card">
167
+ <h3>بررسی و تایید اسنپشاتهای صورتهای مالی</h3>
168
+ <div id="snapshot-list-container">
169
+ <p>در حال فراخوانی اسنپشاتها...</p>
170
+ </div>
171
+ </div>
172
+ </div>
173
+
174
+ <!-- Audit Logs Screen -->
175
+ <div id="screen-audit-logs" class="screen-section" style="display:none;">
176
+ <div class="card">
177
+ <h3>دفتر ثبت رویدادها و لاگهای حسابرسی (Audit Logs)</h3>
178
+ <div id="audit-list-container">
179
+ <p>در حال فراخوانی لاگها...</p>
180
+ </div>
181
+ </div>
182
+ </div>
183
+
184
+ </div>
185
+ </div>
186
+ </div>
187
+
188
+ <script>
189
+ const API_BASE = '/api/v1';
190
+ let authToken = null;
191
+ let currentUser = { username: 'admin_user', role: 'ADMIN' };
192
+
193
+ async function handleLogin() {
194
+ const user = document.getElementById('login-username').value;
195
+ const pass = document.getElementById('login-password').value;
196
+ const errDiv = document.getElementById('login-error');
197
+
198
+ try {
199
+ const res = await fetch(`${API_BASE}/auth/login`, {
200
+ method: 'POST',
201
+ headers: { 'Content-Type': 'application/json' },
202
+ body: JSON.stringify({ username: user, password: pass })
203
+ });
204
+
205
+ if (res.ok) {
206
+ const data = await res.json();
207
+ authToken = data.access_token;
208
+ currentUser = { username: data.username, role: data.role };
209
+ document.getElementById('user-display').innerText = data.username;
210
+ document.getElementById('role-display').innerText = data.role;
211
+ document.getElementById('login-modal').style.display = 'none';
212
+ errDiv.style.display = 'none';
213
+ } else {
214
+ errDiv.innerText = 'نام کاربری یا کلمه عبور اشتباه است.';
215
+ errDiv.style.display = 'block';
216
+ }
217
+ } catch (e) {
218
+ // Fallback for desktop offline mode
219
+ document.getElementById('login-modal').style.display = 'none';
220
+ }
221
+ }
222
+
223
+ function showScreen(screenId) {
224
+ document.querySelectorAll('.screen-section').forEach(s => s.style.display = 'none');
225
+ document.querySelectorAll('.nav-item').forEach(n => n.classList.remove('active'));
226
+ document.getElementById(`screen-${screenId}`).style.display = 'block';
227
+ event.target.classList.add('active');
228
+
229
+ if (screenId === 'snapshots') fetchSnapshots();
230
+ if (screenId === 'audit-logs') fetchAuditLogs();
231
+ }
232
+
233
+ async function runUploadWizard() {
234
+ const filepath = document.getElementById('wizard-filepath').value;
235
+ const doctype = document.getElementById('wizard-doctype').value;
236
+ const rawRows = [
237
+ { "account_code": "1101", "account_name": "موجود نقد", "debit": "3000", "credit": "0" },
238
+ { "account_code": "3101", "account_name": "بدهی تجاری", "debit": "0", "credit": "3000" }
239
+ ];
240
+
241
+ try {
242
+ const res = await fetch(`${API_BASE}/workflow/execute?year_id=1&file_path=${filepath}&doc_type=${doctype}`, {
243
+ method: 'POST',
244
+ headers: { 'Content-Type': 'application/json' },
245
+ body: JSON.stringify(rawRows)
246
+ });
247
+ const data = await res.json();
248
+ alert(`گردش کار با موفقیت اجرا شد. اسنپشات نسخه ${data.snapshot_version} ثبت گردید.`);
249
+ showScreen('snapshots');
250
+ } catch (e) {
251
+ alert('خطا در اجرای ویزارد بارگذاری.');
252
+ }
253
+ }
254
+
255
+ async function loadReport(type) {
256
+ const out = document.getElementById('report-output');
257
+ out.innerHTML = '<p>در حال دریافت گزارش...</p>';
258
+ try {
259
+ const res = await fetch(`${API_BASE}/reporting/${type}?year_id=1`);
260
+ const data = await res.json();
261
+ out.innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
262
+ } catch (e) {
263
+ out.innerHTML = '<p style="color:red;">خطا در دریافت گزارش.</p>';
264
+ }
265
+ }
266
+
267
+ async function exportCSV() {
268
+ window.location.href = `${API_BASE}/export/csv?year_id=1&statement_type=TB`;
269
+ }
270
+
271
+ async function fetchSnapshots() {
272
+ const container = document.getElementById('snapshot-list-container');
273
+ try {
274
+ const res = await fetch(`${API_BASE}/snapshots?year_id=1`);
275
+ const data = await res.json();
276
+ let html = '<table><thead><tr><th>نسخه</th><th>وضعیت</th><th>ایجادکننده</th><th>توضیحات</th><th>عملیات</th></tr></thead><tbody>';
277
+ data.forEach(s => {
278
+ html += `<tr><td>نسخه ${s.version}</td><td><span class="badge badge-draft">${s.status}</span></td><td>${s.created_by || '-'}</td><td>${s.notes || '-'}</td><td><button onclick="approveSnap(${s.id})">تایید اسنپشات</button></td></tr>`;
279
+ });
280
+ html += '</tbody></table>';
281
+ container.innerHTML = html;
282
+ } catch (e) {
283
+ container.innerHTML = '<p style="color:red;">خطا در بارگذاری اسنپشاتها.</p>';
284
+ }
285
+ }
286
+
287
+ async function approveSnap(snapId) {
288
+ try {
289
+ await fetch(`${API_BASE}/workflow/approve?snapshot_id=${snapId}`, { method: 'POST' });
290
+ alert('اسنپشات تایید شد.');
291
+ fetchSnapshots();
292
+ } catch (e) {
293
+ alert('خطا در تایید اسنپشات.');
294
+ }
295
+ }
296
+
297
+ async function fetchAuditLogs() {
298
+ const container = document.getElementById('audit-list-container');
299
+ try {
300
+ const res = await fetch(`${API_BASE}/audit-logs`);
301
+ const data = await res.json();
302
+ let html = '<table><thead><tr><th>زمان</th><th>اقدام کاربر</th><th>موجودیت</th><th>نوع</th></tr></thead><tbody>';
303
+ data.forEach(l => {
304
+ html += `<tr><td>${new Date(l.created_at).toLocaleString('fa-IR')}</td><td>${l.user_action}</td><td>${l.entity_affected}</td><td>${l.action_type}</td></tr>`;
305
+ });
306
+ html += '</tbody></table>';
307
+ container.innerHTML = html;
308
+ } catch (e) {
309
+ container.innerHTML = '<p style="color:red;">خطا در دریافت لاگهای حسابرسی.</p>';
310
+ }
311
+ }
312
+
313
+ function onCompanyChange() {}
314
+ function onYearChange() {}
315
+ </script>
316
+</body>
317
+</html>