@davoodmehraban89 / Aram-2 Mirror · read-only / commits / 46cb24f
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 3, 20:45 UTC

Add initial index.html provided by user with file upload functionality

Co-authored-by: davoodmehraban89 <57283229+davoodmehraban89@users.noreply.github.com>

google-labs-jules[bot] committed Aug 16, 2026 at 18:23 UTC 46cb24f8568c769d7a71f9ad9673a67347a6365a
1 file changed +927
index.html new
+927
@@ -0,0 +1,927 @@
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>سیستم جامع صورت‌های مالی (Jules Master Engine)</title>
7 + <!-- Tailwind CSS برای استایل‌دهی -->
8 + <script src="https://cdn.tailwindcss.com"></script>
9 + <!-- PapaParse برای خواندن فایل‌های اکسل/CSV -->
10 + <script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.4.1/papaparse.min.js"></script>
11 +
12 + <style>
13 + @import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css');
14 + * { font-family: 'Vazirmatn', sans-serif; }
15 + ::-webkit-scrollbar { width: 6px; height: 6px; }
16 + ::-webkit-scrollbar-track { background: #0f172a; }
17 + ::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
18 +
19 + /* =========================================
20 + موتور پرینت قطعی و تضمینی A4
21 + ========================================= */
22 + @media print {
23 + @page { size: A4 portrait; margin: 12mm; }
24 + body { background-color: white !important; color: black !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-size: 11pt; }
25 +
26 + /* مخفی کردن اپلیکیشن وب هنگام چاپ */
27 + .no-print, #app-wrapper, .print-controls { display: none !important; }
28 +
29 + /* نمایش کانتینر پرینت */
30 + #print-wrapper { display: block !important; width: 100%; direction: rtl; background: white !important; }
31 +
32 + .print-page { page-break-after: always; clear: both; padding: 10mm 0; position: relative; min-height: 250mm; }
33 + .print-page:last-child { page-break-after: auto; }
34 +
35 + h2 { font-size: 16pt; text-align: center; font-weight: bold; margin-bottom: 15px; color: black !important; }
36 + h3 { font-size: 14pt; text-align: center; font-weight: bold; margin-bottom: 15px; color: black !important; border-bottom: 2px solid #000; padding-bottom: 10px;}
37 + h4 { font-size: 12pt; font-weight: bold; margin-bottom: 10px; color: black !important; }
38 +
39 + table { width: 100%; border-collapse: collapse; margin-bottom: 25px; font-size: 10pt; page-break-inside: avoid; }
40 + th, td { border: 1px solid #000 !important; padding: 8px !important; color: black !important; text-align: center;}
41 + th { background-color: #e5e7eb !important; font-weight: bold; }
42 + td:first-child { text-align: right; }
43 +
44 + /* کادر امضا */
45 + .sign-grid { display: flex; justify-content: space-around; margin-top: 60px; text-align: center; font-size: 11pt; gap: 20px; flex-wrap: wrap;}
46 + .sign-box { border-top: 1px dashed #000; padding-top: 15px; flex: 1; min-width: 150px; font-weight: bold; margin-bottom: 30px;}
47 + .sign-role { font-size: 9pt; font-weight: normal; margin-top: 5px; display: block; color: #333 !important;}
48 +
49 + /* المان‌های AI */
50 + .ai-grid { display: flex; justify-content: space-between; gap: 15px; margin-bottom: 20px; margin-top: 20px;}
51 + .ai-card { border: 2px solid #4f46e5 !important; padding: 15px; flex: 1; text-align: center; border-radius: 8px; background-color: #f8fafc !important; }
52 + .ai-val { font-size: 16pt; font-weight: bold; margin-top: 10px; direction: ltr; color: #1e1b4b !important;}
53 + .ai-title { font-size: 10pt; font-weight: bold; color: #334155 !important;}
54 + .ai-analysis { border: 2px solid #10b981 !important; padding: 15px; border-radius: 8px; background-color: #f0fdf4 !important; text-align: justify; line-height: 2; font-size: 11pt;}
55 + }
56 +
57 + /* استایل حالت پیش‌نمایش پرینت روی مانیتور */
58 + .preview-mode #app-wrapper { display: none; }
59 + .preview-mode #print-wrapper { display: block; background: #525659; min-height: 100vh; padding-bottom: 50px; }
60 + #print-wrapper { display: none; }
61 +
62 + .paper-sheet {
63 + background: white; color: black; width: 210mm; min-height: 297mm;
64 + margin: 20px auto; padding: 20mm; box-shadow: 0 0 15px rgba(0,0,0,0.5);
65 + direction: rtl;
66 + }
67 +
68 + /* لودینگ برای پردازش فایل CSV */
69 + #loader { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15,23,42,0.9); z-index: 9999; justify-content: center; align-items: center; flex-direction: column; }
70 + </style>
71 +</head>
72 +<body class="bg-slate-950 text-slate-100 antialiased min-h-screen">
73 +
74 + <!-- صفحه لودینگ پردازش -->
75 + <div id="loader">
76 + <svg class="animate-spin h-16 w-16 text-emerald-500 mb-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>
77 + <h2 class="text-white text-xl font-bold font-mono" id="loader-text">در حال پردازش تراز آزمایشی و موتور نگاشت (O/Oe/E)...</h2>
78 + </div>
79 +
80 + <!-- ==========================================
81 + محیط کاربری اپلیکیشن وب
82 + ========================================== -->
83 + <div id="app-wrapper" class="flex flex-col min-h-screen">
84 + <header class="bg-slate-900 border-b border-slate-800 p-3 md:p-4 sticky top-0 z-50 shadow-2xl">
85 + <div class="max-w-7xl mx-auto space-y-3">
86 +
87 + <!-- عنوان و دکمه‌ها -->
88 + <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 border-b border-slate-800/80 pb-2.5">
89 + <div class="flex items-center gap-2.5">
90 + <div class="p-2 bg-indigo-600 text-white rounded-lg shadow-md">
91 + <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
92 + </div>
93 + <div>
94 + <h1 class="font-bold text-white text-xs md:text-sm">هسته یکپارچه صدور صورت‌های مالی (Jules Ready)</h1>
95 + <p class="text-[10px] text-emerald-400">بستر قطعی ۱۴۰۲ تا ۱۴۰۴ - آماده تحلیل فایل‌های ۱۴۰۵</p>
96 + </div>
97 + </div>
98 + <div class="flex items-center gap-2">
99 + <span class="text-[11px] font-mono font-bold text-slate-300 bg-slate-800 border border-slate-700 px-2.5 py-1.5 rounded-lg">واحد: میلیون ریال</span>
100 + <!-- دکمه ورود به محیط پرینت -->
101 + <button onclick="openPrintPreview()" class="flex items-center gap-1.5 bg-emerald-600 hover:bg-emerald-500 text-white text-[11px] font-bold px-4 py-2 rounded-lg transition-all shadow-md ring-2 ring-emerald-400/50">
102 + 🖨️ تولید پکیج چاپ (مدیریتی)
103 + </button>
104 + </div>
105 + </div>
106 +
107 + <!-- انتخابگرها -->
108 + <div class="grid grid-cols-1 md:grid-cols-2 gap-2.5 bg-slate-950 p-2.5 rounded-xl border border-slate-800">
109 + <div class="space-y-1">
110 + <label class="text-[11px] font-bold text-blue-400">انتخاب شرکت:</label>
111 + <select id="companySelector" onchange="onCompanyChange(this.value)" class="bg-slate-900 border border-slate-700 text-white text-xs font-semibold rounded-lg px-2.5 py-2 w-full outline-none">
112 + <option value="C_GAS_TRANS">🏭 شرکت انتقال گاز ایران (سهامی خاص)</option>
113 + <option value="C_SISTAN">🏬 شرکت گاز استان سیستان و بلوچستان</option>
114 + </select>
115 + </div>
116 + <div class="space-y-1">
117 + <label class="text-[11px] font-bold text-emerald-400">انتخاب سال مالی:</label>
118 + <select id="yearSelector" onchange="onYearChange(this.value)" class="bg-slate-900 border border-slate-700 text-white text-xs font-semibold rounded-lg px-2.5 py-2 w-full outline-none font-mono">
119 + <option value="1405" class="text-emerald-400 font-bold">📅 سال ۱۴۰۵ (سال جدید / درحال کار)</option>
120 + <option value="1404">📅 سال ۱۴۰۴ (گزارش نهایی حسابرسی شده)</option>
121 + <option value="1403">📅 سال ۱۴۰۳ (گزارش نهایی حسابرسی شده)</option>
122 + <option value="1402">📅 سال ۱۴۰۲ (گزارش نهایی حسابرسی شده)</option>
123 + </select>
124 + </div>
125 + </div>
126 +
127 + <!-- تب‌ها -->
128 + <div class="flex items-center gap-1.5 overflow-x-auto pb-1 pt-0.5 scrollbar-none border-t border-slate-800">
129 + <button onclick="switchTab('UPLOAD')" id="tab-UPLOAD" class="report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap text-emerald-400 hover:bg-slate-800 border border-emerald-800/50 bg-emerald-950/20">➕ تولید صورت مالی ۱۴۰۵</button>
130 + <button onclick="switchTab('AUDITOR')" id="tab-AUDITOR" class="report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap bg-indigo-600 text-white shadow-md">⚖️ گزارش حسابرس و AI</button>
131 + <button onclick="switchTab('BS')" id="tab-BS" class="report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap text-slate-300 hover:bg-slate-800">📋 ترازنامه</button>
132 + <button onclick="switchTab('IS')" id="tab-IS" class="report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap text-slate-300 hover:bg-slate-800">📈 سود و زیان</button>
133 + <button onclick="switchTab('EQUITY')" id="tab-EQUITY" class="report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap text-slate-300 hover:bg-slate-800">📊 حقوق مالکانه</button>
134 + <button onclick="switchTab('CF')" id="tab-CF" class="report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap text-slate-300 hover:bg-slate-800">🔄 جریان‌های نقدی</button>
135 + <button onclick="switchTab('MAPPING')" id="tab-MAPPING" class="report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap text-purple-400 hover:bg-slate-800">🔗 موتور نگاشت (O/Oe/E)</button>
136 + </div>
137 + </div>
138 + </header>
139 +
140 + <main class="flex-1 p-3 md:p-6 max-w-7xl mx-auto w-full space-y-4">
141 + <div id="tabContent" class="min-h-[400px]"></div>
142 + </main>
143 + </div>
144 +
145 + <!-- ==========================================
146 + محیط پیش‌نمایش و چاپ (Print Wrapper)
147 + ========================================== -->
148 + <div id="print-wrapper">
149 + <div class="print-controls bg-slate-900 p-4 sticky top-0 z-50 flex justify-between items-center shadow-2xl border-b-4 border-emerald-500">
150 + <div class="text-white font-bold flex items-center gap-2">
151 + <span class="text-2xl">🖨️</span>
152 + <span>پیش‌نمایش پکیج نهایی - آماده ارسال به پرینتر</span>
153 + </div>
154 + <div class="flex gap-3">
155 + <button onclick="closePrintPreview()" class="bg-rose-600 hover:bg-rose-500 text-white px-5 py-2 rounded-lg font-bold transition-all shadow-md">✖ لغو و بازگشت</button>
156 + <!-- دکمه تایید نهایی که دستور پرینت ویندوز را صدا میزند -->
157 + <button onclick="window.print()" class="bg-emerald-600 hover:bg-emerald-500 text-white px-6 py-2 rounded-lg font-bold transition-all shadow-lg ring-2 ring-emerald-400">✓ تایید و چاپ (Print)</button>
158 + </div>
159 + </div>
160 +
161 + <!-- صفحات A4 به صورت داینامیک در اینجا ساخته می‌شوند -->
162 + <div id="print-pages-container"></div>
163 + </div>
164 +
165 + <!-- ==========================================
166 + Core JavaScript & Database
167 + ========================================== -->
168 + <script>
169 + // State
170 + let currentCompanyId = 'C_GAS_TRANS';
171 + let currentYear = '1404';
172 + let currentTab = 'AUDITOR';
173 +
174 + // متغیر موقت برای نگهداری دیتای ۱۴۰۵ (پس از آپلود فایل)
175 + let dynYear1405Data = null;
176 +
177 + // ---------------------------------------------------------
178 + // DATABASE (The Single Source of Truth from PDFs & CSVs)
179 + // ---------------------------------------------------------
180 + const DB = {
181 + 'C_GAS_TRANS': {
182 + '1404': {
183 + hasRealData: true,
184 + auditorOpinion: 'مقبول (با بندهای تاکید بر مطلب خاص)',
185 + auditorClauses: [
186 + { type: 'تاکید بر مطلب خاص', title: 'بند ۴: مطالبات و بدهی‌ها', desc: 'همانگونه که در یادداشت ۱۸ منعکس است، تعیین تکلیف قطعی صورت‌حساب‌های متقابل با شرکت ملی گاز نیازمند تسویه نهایی است.' },
187 + { type: 'تاکید بر مطلب خاص', title: 'بند ۵: وضعیت مالیاتی', desc: 'برگ تشخیص مالیات عملکرد و ارزش افزوده سال‌های ۱۴۰۰ و ۱۴۰۱ صادر شده و شرکت در حال پیگیری در هیات‌های حل اختلاف مالیاتی می‌باشد.' },
188 + { type: 'تاکید بر مطلب خاص', title: 'بند ۶: اموال طرح‌های عمرانی', desc: 'انتقال اموال مرتبط با خط لوله ششم سراسری (BOT) از طرف شرکت مهندسی توسعه گاز قطعی شده و به عنوان تعدیلات سنواتی در حقوق مالکانه اعمال گردید.' }
189 + ],
190 + signatures: [
191 + { name: 'پیمان خضرایی', role: 'نایب رئیس هیئت مدیره و مدیرعامل' },
192 + { name: 'مسعود زردویان', role: 'رئیس هیئت مدیره' },
193 + { name: 'سعید نفری اقدم', role: 'عضو هیئت مدیره و مدیر مالی' }
194 + ],
195 + BS: {
196 + '101': { title: 'دارایی‌های ثابت مشهود', ycur: 673740637, ycomp1: 502938206, ycomp2: 429540560 },
197 + '102': { title: 'دارایی‌های نامشهود', ycur: 242194, ycomp1: 216237, ycomp2: 214276 },
198 + '103': { title: 'دریافتنی‌های بلندمدت', ycur: 8310168, ycomp1: 10811230, ycomp2: 6652479 },
199 + '201': { title: 'پیش‌پرداخت‌ها', ycur: 6839535, ycomp1: 3354446, ycomp2: 8000766 },
200 + '202': { title: 'موجودی مواد و کالا', ycur: 11273650, ycomp1: 8305043, ycomp2: 6818189 },
201 + '203': { title: 'دریافتنی‌های کوتاه‌مدت', ycur: 13386398, ycomp1: 14980468, ycomp2: 15993056 },
202 + '204': { title: 'موجودی نقد', ycur: 19951136, ycomp1: 3368287, ycomp2: 2134188 },
203 + '301': { title: 'سرمایه ثبت شده', ycur: 20000000, ycomp1: 20000000, ycomp2: 20000000 },
204 + '302': { title: 'افزایش سرمایه در جریان', ycur: 0, ycomp1: 0, ycomp2: 14069826 },
205 + '303': { title: 'اندوخته قانونی', ycur: 1614, ycomp1: 1614, ycomp2: 1614 },
206 + '304': { title: 'زیان انباشته', ycur: -203887074, ycomp1: -124518176, ycomp2: -110226573 },
207 + '401': { title: 'پرداختنی‌های بلندمدت', ycur: 630414220, ycomp1: 466724525, ycomp2: 419375071 },
208 + '402': { title: 'ذخیره مزایای پایان خدمت', ycur: 133078121, ycomp1: 94199107, ycomp2: 77644296 },
209 + '501': { title: 'پرداختنی‌های جاری', ycur: 145341976, ycomp1: 83315373, ycomp2: 46997254 },
210 + '502': { title: 'مالیات پرداختنی', ycur: 8833412, ycomp1: 4285509, ycomp2: 1363294 },
211 + '503': { title: 'پیش‌دریافت‌ها', ycur: 61449, ycomp1: 65965, ycomp2: 135627 }
212 + },
213 + IS: {
214 + '601': { title: 'درآمدهای عملیاتی', cur: 243097686, comp: 174585508 },
215 + '602': { title: 'بهای تمام شده درآمدهای عملیاتی', cur: -245897444, comp: -176383618 },
216 + '603': { title: 'هزینه‌های فروش، اداری و عمومی', cur: -62814143, comp: -25354498 },
217 + '604': { title: 'سایر درآمدهای عملیاتی', cur: 1543514, comp: 1085594 },
218 + '605': { title: 'سایر درآمدها و هزینه‌های غیرعملیاتی', cur: -10601182, comp: 627800 },
219 + '606': { title: 'هزینه مالیات بر درآمد', cur: -4697329, comp: -2922215 }
220 + },
221 + CF: {
222 + '701': { title: 'نقد حاصل از عملیات', cur: 99230533, comp: 83057773 },
223 + '801': { title: 'خرید دارایی‌های ثابت مشهود', cur: -82458602, comp: -81875240 }
224 + },
225 + EQ: [
226 + { title: 'مانده در ۱۴۰۳/۰۱/۰۱', c1: '-', c2: 14069826, c3: -38949540, total: -23264098 },
227 + { title: 'اصلاح اشتباهات (خط ۶ BOT)', c1: '-', c2: '-', c3: -73020980, total: -73020980 },
228 + { title: 'مانده تجدید ارائه شده در ۱۴۰۳/۰۱/۰۱', c1: '-', c2: 14069826, c3: -110226573, total: -76155133, highlight: true },
229 + { title: 'زیان خالص تجدید ارائه شده سال ۱۴۰۳', c1: '-', c2: '-', c3: -28361429, total: -28361429 },
230 + { title: 'ثبت افزایش سرمایه', c1: 20000000, c2: -14069826, c3: '-', total: 5930174 },
231 + { title: 'مانده در ۱۴۰۳/۱۲/۳۰', c1: 20000000, c2: '-', c3: -124518176, total: -104516562, highlight: true },
232 + { title: 'زیان خالص سال مالی ۱۴۰۴', c1: '-', c2: '-', c3: -79368898, total: -79368898 },
233 + { title: 'مانده در پایان سال مالی ۱۴۰۴/۱۲/۲۹', c1: 20000000, c2: '-', c3: -203887074, total: -183885460, highlight: true }
234 + ]
235 + },
236 + '1403': {
237 + hasRealData: true,
238 + auditorOpinion: 'مقبول (با بند تاکید)',
239 + auditorClauses: [{ type: 'تاکید بر مطلب خاص', title: 'بند ۴', desc: 'مغایرت حساب‌های فی‌مابین با شرکت ملی گاز نیازمند رفع می‌باشد.' }],
240 + signatures: [
241 + { name: 'مسعود زردویان', role: 'رئیس هیئت مدیره' },
242 + { name: 'پیمان خضرایی', role: 'نایب رئیس هیئت مدیره و مدیرعامل' },
243 + { name: 'سعید نفری اقدم', role: 'عضو هیئت مدیره و مدیر مالی' }
244 + ],
245 + BS: {
246 + '101': { title: 'دارایی‌های ثابت مشهود', ycur: 502938206, ycomp1: 429540560, ycomp2: 380000000 },
247 + '102': { title: 'دارایی‌های نامشهود', ycur: 216237, ycomp1: 214276, ycomp2: 200000 },
248 + '103': { title: 'دریافتنی‌های بلندمدت', ycur: 10811230, ycomp1: 6652479, ycomp2: 5000000 },
249 + '201': { title: 'پیش‌پرداخت‌ها', ycur: 3354446, ycomp1: 8000766, ycomp2: 6000000 },
250 + '202': { title: 'موجودی مواد و کالا', ycur: 8305043, ycomp1: 6818189, ycomp2: 5500000 },
251 + '203': { title: 'دریافتنی‌های کوتاه‌مدت', ycur: 14980468, ycomp1: 15993056, ycomp2: 12000000 },
252 + '204': { title: 'موجودی نقد', ycur: 3368287, ycomp1: 2134188, ycomp2: 1800000 },
253 + '301': { title: 'سرمایه ثبت شده', ycur: 20000000, ycomp1: 20000000, ycomp2: 20000000 },
254 + '302': { title: 'افزایش سرمایه در جریان', ycur: 0, ycomp1: 14069826, ycomp2: 0 },
255 + '303': { title: 'اندوخته قانونی', ycur: 1614, ycomp1: 1614, ycomp2: 1614 },
256 + '304': { title: 'زیان انباشته', ycur: -124518176, ycomp1: -110226573, ycomp2: -95000000 },
257 + '401': { title: 'پرداختنی‌های بلندمدت', ycur: 466724525, ycomp1: 419375071, ycomp2: 380000000 },
258 + '402': { title: 'ذخیره مزایای پایان خدمت', ycur: 94199107, ycomp1: 77644296, ycomp2: 65000000 },
259 + '501': { title: 'پرداختنی‌های جاری', ycur: 83315373, ycomp1: 46997254, ycomp2: 38000000 },
260 + '502': { title: 'مالیات پرداختنی', ycur: 4285509, ycomp1: 1363294, ycomp2: 1000000 },
261 + '503': { title: 'پیش‌دریافت‌ها', ycur: 65965, ycomp1: 135627, ycomp2: 100000 }
262 + },
263 + IS: {
264 + '601': { title: 'درآمدهای عملیاتی', cur: 174585508, comp: 123297650 },
265 + '602': { title: 'بهای تمام شده درآمدهای عملیاتی', cur: -157476581, comp: -123355486 },
266 + '603': { title: 'هزینه‌های فروش، اداری و عمومی', cur: -25354498, comp: -19618654 },
267 + '604': { title: 'سایر درآمدهای عملیاتی', cur: 1085594, comp: 1421110 },
268 + '605': { title: 'سایر درآمدها و هزینه‌های غیرعملیاتی', cur: 1713394, comp: 2545735 },
269 + '606': { title: 'هزینه مالیات بر درآمد', cur: -2922215, comp: 0 }
270 + },
271 + CF: {
272 + '701': { title: 'نقد حاصل از عملیات', cur: 83057772, comp: 29242666 },
273 + '801': { title: 'خرید دارایی‌های ثابت مشهود', cur: -81875239, comp: -33462659 }
274 + },
275 + EQ: [
276 + { title: 'مانده تجدید ارائه شده در ۱۴۰۲/۰۱/۰۱', c1: 20000000, c2: '-', c3: -100552844, total: -80551230 },
277 + { title: 'زیان خالص سال ۱۴۰۲', c1: '-', c2: '-', c3: -15709645, total: -15709645 },
278 + { title: 'مانده در ۱۴۰۲/۱۲/۲۹', c1: 20000000, c2: 14069826, c3: -110226573, total: -76156747 },
279 + { title: 'زیان خالص سال ۱۴۰۳', c1: '-', c2: '-', c3: -9454392, total: -9454392 },
280 + { title: 'مانده پایان سال ۱۴۰۳/۱۲/۳۰', c1: 20000000, c2: '-', c3: -124518176, total: -104518176 }
281 + ]
282 + },
283 + '1402': {
284 + hasRealData: true,
285 + auditorOpinion: 'مقبول',
286 + signatures: [
287 + { name: 'ابوالفضل وروانی فراهانی', role: 'رئیس هیئت مدیره' },
288 + { name: 'غلامعباس حسینی', role: 'نایب رئیس هیئت مدیره و مدیرعامل' }
289 + ],
290 + BS: {
291 + '101': { title: 'دارایی‌های ثابت مشهود', ycur: 429540560, ycomp1: 380000000, ycomp2: null },
292 + '102': { title: 'دارایی‌های نامشهود', ycur: 214276, ycomp1: 200000, ycomp2: null },
293 + '103': { title: 'دریافتنی‌های بلندمدت', ycur: 6652479, ycomp1: 5000000, ycomp2: null },
294 + '201': { title: 'پیش‌پرداخت‌ها', ycur: 8000766, ycomp1: 6000000, ycomp2: null },
295 + '202': { title: 'موجودی مواد و کالا', ycur: 6818189, ycomp1: 5500000, ycomp2: null },
296 + '203': { title: 'دریافتنی‌های کوتاه‌مدت', ycur: 15993056, ycomp1: 12000000, ycomp2: null },
297 + '204': { title: 'موجودی نقد', ycur: 2134188, ycomp1: 1800000, ycomp2: null },
298 + '301': { title: 'سرمایه ثبت شده', ycur: 20000000, ycomp1: 20000000, ycomp2: null },
299 + '302': { title: 'افزایش سرمایه در جریان', ycur: 14069826, ycomp1: 0, ycomp2: null },
300 + '303': { title: 'اندوخته قانونی', ycur: 1614, ycomp1: 1614, ycomp2: null },
301 + '304': { title: 'زیان انباشته', ycur: -110226573, ycomp1: -95000000, ycomp2: null },
302 + '401': { title: 'پرداختنی‌های بلندمدت', ycur: 419375071, ycomp1: 380000000, ycomp2: null },
303 + '402': { title: 'ذخیره مزایای پایان خدمت', ycur: 77644296, ycomp1: 65000000, ycomp2: null },
304 + '501': { title: 'پرداختنی‌های جاری', ycur: 46997254, ycomp1: 38000000, ycomp2: null },
305 + '502': { title: 'مالیات پرداختنی', ycur: 1363294, ycomp1: 1000000, ycomp2: null },
306 + '503': { title: 'پیش‌دریافت‌ها', ycur: 135627, ycomp1: 100000, ycomp2: null }
307 + },
308 + IS: {
309 + '601': { title: 'درآمدهای عملیاتی', cur: 123297650, comp: 110816554 },
310 + '602': { title: 'بهای تمام شده درآمدهای عملیاتی', cur: -123355486, comp: -105604143 },
311 + '603': { title: 'هزینه‌های فروش، اداری و عمومی', cur: -19618654, comp: -16066043 },
312 + '604': { title: 'سایر درآمدهای عملیاتی', cur: 1421110, comp: 222669 },
313 + '605': { title: 'سایر درآمدها و هزینه‌های غیرعملیاتی', cur: 2545735, comp: 1109158 },
314 + '606': { title: 'هزینه مالیات بر درآمد', cur: 0, comp: -1068664 }
315 + },
316 + CF: {
317 + '701': { title: 'نقد حاصل از عملیات', cur: 29242666, comp: 26068197 },
318 + '801': { title: 'خرید دارایی‌های ثابت مشهود', cur: -33462659, comp: -21323048 }
319 + },
320 + EQ: [
321 + { title: 'مانده تجدید ارائه شده ۱۴۰۱/۰۱/۰۱', c1: 20000000, c2: '-', c3: -46720866, total: -26719252 },
322 + { title: 'زیان خالص سال ۱۴۰۲', c1: '-', c2: '-', c3: -15709645, total: -15709645 },
323 + { title: 'مانده در ۱۴۰۲/۱۲/۲۹', c1: 20000000, c2: 14069826, c3: -110226573, total: -76156747 }
324 + ]
325 + }
326 + },
327 + 'C_SISTAN': {
328 + '1402': {
329 + hasRealData: true,
330 + auditorOpinion: 'مقبول',
331 + auditorClauses: [{ type: 'تاکید بر مطلب', title: 'بند ۴', desc: 'عدم تحقق بودجه تخصیصی گازرسانی چابهار در سال مورد گزارش.' }],
332 + signatures: [
333 + { name: 'حسین سلیمی', role: 'رئیس هیئت مدیره' },
334 + { name: 'محمدرضا میرشکاری', role: 'نایب رئیس هیئت مدیره و مدیرعامل' },
335 + { name: 'علی خسروی', role: 'عضو هیئت مدیره' }
336 + ],
337 + BS: {
338 + '101': { title: 'دارایی‌های ثابت مشهود', ycur: 6785191, ycomp1: 5214080, ycomp2: null },
339 + '102': { title: 'دارایی‌های نامشهود', ycur: 210, ycomp1: 210, ycomp2: null },
340 + '103': { title: 'دریافتنی‌های بلندمدت', ycur: 0, ycomp1: 0, ycomp2: null },
341 + '201': { title: 'پیش‌پرداخت‌ها', ycur: 399120, ycomp1: 280000, ycomp2: null },
342 + '202': { title: 'موجودی مواد و کالا', ycur: 74200, ycomp1: 65000, ycomp2: null },
343 + '203': { title: 'دریافتنی‌های کوتاه‌مدت', ycur: 2765672, ycomp1: 2100000, ycomp2: null },
344 + '204': { title: 'موجودی نقد', ycur: 43730, ycomp1: 31000, ycomp2: null },
345 + '301': { title: 'سرمایه ثبت شده', ycur: 10000, ycomp1: 10000, ycomp2: null },
346 + '302': { title: 'افزایش سرمایه در جریان', ycur: 0, ycomp1: 0, ycomp2: null },
347 + '303': { title: 'اندوخته قانونی', ycur: 0, ycomp1: 0, ycomp2: null },
348 + '304': { title: 'زیان انباشته', ycur: -1949156, ycomp1: -1529841, ycomp2: null },
349 + '401': { title: 'پرداختنی‌های بلندمدت', ycur: 5319747, ycomp1: 4100000, ycomp2: null },
350 + '402': { title: 'ذخیره مزایای پایان خدمت', ycur: 111860, ycomp1: 85000, ycomp2: null },
351 + '501': { title: 'پرداختنی‌های جاری', ycur: 6575672, ycomp1: 5025131, ycomp2: null },
352 + '502': { title: 'مالیات پرداختنی', ycur: 0, ycomp1: 0, ycomp2: null },
353 + '503': { title: 'پیش‌دریافت‌ها', ycur: 0, ycomp1: 0, ycomp2: null }
354 + },
355 + IS: {
356 + '601': { title: 'درآمدهای عملیاتی', cur: 1880816, comp: 1420000 },
357 + '602': { title: 'بهای تمام شده درآمدهای عملیاتی', cur: -1950000, comp: -1480000 },
358 + '603': { title: 'هزینه‌های عمومی و اداری', cur: -350131, comp: -280000 },
359 + '604': { title: 'سایر درآمدهای عملیاتی', cur: 0, comp: 0 },
360 + '605': { title: 'سایر درآمدها و هزینه‌های غیرعملیاتی', cur: 0, comp: 0 },
361 + '606': { title: 'هزینه مالیات بر درآمد', cur: 0, comp: 0 }
362 + },
363 + CF: {
364 + '701': { title: 'نقد حاصل از عملیات', cur: 80000, comp: 50000 },
365 + '801': { title: 'خرید دارایی‌های ثابت مشهود', cur: -60000, comp: -40000 }
366 + },
367 + EQ: [
368 + { title: 'مانده در ۱۴۰۱/۱۲/۲۹', c1: 10000, c2: '-', c3: -1529841, total: -1519841 },
369 + { title: 'زیان خالص سال ۱۴۰۲', c1: '-', c2: '-', c3: -419315, total: -419315 },
370 + { title: 'مانده پایان سال ۱۴۰۲/۱۲/۲۹', c1: 10000, c2: '-', c3: -1949156, total: -1939156, highlight: true }
371 + ]
372 + }
373 + }
374 + };
375 +
376 + const MAPPING_RULES = [
377 + { code: '1101', name: 'بهای تمام شده درآمدهای عملیاتی', note: '6', type: 'O (مبدأ)' },
378 + { code: '8348', name: 'پرداختنی های تجاری و غیر تجاری (جاری)', note: '19-1', type: 'E (ورود)' },
379 + { code: '8348', name: 'پرداختنی بلند مدت (اشخاص وابسته)', note: '19-2', type: 'Oe (خروج)' },
380 + { code: '8161', name: 'پیش پرداخت های سرمایه ای', note: '10', type: 'O (مبدأ)' },
381 + { code: '118901', name: 'پروژه‌های در جریان تکمیل (BOT)', note: '22', type: 'E (ورود)' }
382 + ];
383 +
384 + const COMPANIES_INFO = {
385 + 'C_GAS_TRANS': 'شرکت انتقال گاز ایران (سهامی خاص)',
386 + 'C_SISTAN': 'شرکت گاز استان سیستان و بلوچستان (سهامی خاص)'
387 + };
388 +
389 + // --- UTILS ---
390 + function fmt(num) {
391 + if (num === null || num === undefined || num === '-' || num === 0) return num === 0 ? '۰' : '-';
392 + const absFormatted = Math.abs(num).toLocaleString('fa-IR');
393 + return num < 0 ? `(${absFormatted})` : absFormatted;
394 + }
395 +
396 + function checkDataAvailable(compId, year) {
397 + if(year === '1405') return !!dynYear1405Data;
398 + return !!(DB[compId] && DB[compId][year] && DB[compId][year].hasRealData);
399 + }
400 +
401 + function getActiveData() {
402 + if(currentYear === '1405') return dynYear1405Data;
403 + return DB[currentCompanyId]?.[currentYear];
404 + }
405 +
406 + // ---------------------------------------------------------
407 + // UI RENDER ENGINE
408 + // ---------------------------------------------------------
409 + function render() {
410 + document.getElementById('companySelector').value = currentCompanyId;
411 + document.getElementById('yearSelector').value = currentYear;
412 +
413 + const tabs = ['AUDITOR', 'BS', 'IS', 'EQUITY', 'CF', 'MAPPING', 'UPLOAD'];
414 + tabs.forEach(t => {
415 + const btn = document.getElementById(`tab-${t}`);
416 + if (!btn) return;
417 +
418 + if (t === currentTab) {
419 + btn.className = "report-tab px-3 py-1.5 rounded-lg text-[11px] font-bold transition-all whitespace-nowrap text-white shadow-md " +
420 + (t === 'AUDITOR' ? 'bg-indigo-600' : (t === 'MAPPING' ? 'bg-purple-600' : (t === 'UPLOAD' ? 'bg-emerald-600' : 'bg-blue-600')));
421 + } else {
422 + btn.className = "report-tab px-3 py-1.5 rounded-lg text-[11px] font-medium transition-all whitespace-nowrap hover:bg-slate-800 border border-transparent " +
423 + (t === 'MAPPING' ? 'text-purple-400 bg-purple-950/20' : (t === 'UPLOAD' ? 'text-emerald-400 bg-emerald-950/20' : 'text-slate-300'));
424 + }
425 + });
426 +
427 + const target = document.getElementById('tabContent');
428 + const isDataVerified = checkDataAvailable(currentCompanyId, currentYear);
429 +
430 + if (!isDataVerified && currentTab !== 'UPLOAD' && currentTab !== 'MAPPING') {
431 + target.innerHTML = `
432 + <div class="bg-slate-900 border border-slate-800 rounded-2xl p-8 text-center space-y-4 my-6 shadow-2xl">
433 + <div class="p-4 bg-amber-500/10 rounded-2xl text-amber-400 w-16 h-16 mx-auto flex items-center justify-center text-3xl">⚠️</div>
434 + <h3 class="font-bold text-white text-lg">اطلاعات مالی قطعی سال ${currentYear} بارگذاری نشده است!</h3>
435 + <p class="text-xs text-slate-400">لطفا برای سال جدید، فایل تراز خام را در تب "ایجاد سال جدید" آپلود کنید تا سیستم آن را بسازد.</p>
436 + <button onclick="switchTab('UPLOAD')" class="mt-4 bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-xs px-5 py-2.5 rounded-xl transition-all shadow-md">
437 + تولید صورت مالی ${currentYear}
438 + </button>
439 + </div>
440 + `;
441 + return;
442 + }
443 +
444 + const data = getActiveData();
445 +
446 + if (currentTab === 'AUDITOR') renderAuditorAndAI(target, data);
447 + else if (currentTab === 'BS') renderBS(target, data);
448 + else if (currentTab === 'IS') renderIS(target, data);
449 + else if (currentTab === 'EQUITY') renderEquity(target, data);
450 + else if (currentTab === 'CF') renderCF(target, data);
451 + else if (currentTab === 'MAPPING') renderMapping(target);
452 + else if (currentTab === 'UPLOAD') renderUploadForm(target);
453 + }
454 +
455 + // --- WEB VIEWS ---
456 +
457 + function renderAuditorAndAI(target, data) {
458 + const bs = data.BS; const is = data.IS;
459 +
460 + const curAssets = (bs['201'].ycur||0) + (bs['202'].ycur||0) + (bs['203'].ycur||0) + (bs['204'].ycur||0);
461 + const curLiab = (bs['501'].ycur||0) + (bs['502'].ycur||0) + (bs['503'].ycur||0);
462 + const totalAssets = curAssets + (bs['101'].ycur||0) + (bs['102'].ycur||0) + (bs['103'].ycur||0);
463 + const totalLiab = curLiab + (bs['401'].ycur||0) + (bs['402'].ycur||0);
464 + const revenue = is['601'].cur + (is['604']?.cur||0);
465 + const netProfit = revenue + is['602'].cur + is['603'].cur + (is['605']?.cur||0) + (is['606']?.cur||0);
466 +
467 + const currentRatio = curLiab ? (curAssets / curLiab).toFixed(2) : 0;
468 + const debtRatio = totalAssets ? ((totalLiab / totalAssets) * 100).toFixed(1) : 0;
469 + const netMargin = revenue ? ((netProfit / revenue) * 100).toFixed(1) : 0;
470 +
471 + const crColor = currentRatio >= 1 ? 'emerald' : 'rose';
472 + const drColor = debtRatio < 60 ? 'emerald' : (debtRatio < 80 ? 'amber' : 'rose');
473 + const nmColor = netMargin > 0 ? 'emerald' : 'rose';
474 +
475 + let aiText = `بر اساس پایش هوشمند ترازنامه، نسبت جاری شرکت معادل <b>${currentRatio}</b> می‌باشد که نشان‌دهنده ${currentRatio >= 1 ? 'پوشش مناسب' : 'ریسک در'} نقدینگی است. نسبت بدهی به دارایی <b>${debtRatio}٪</b> است که بیانگر سطح ${debtRatio > 80 ? 'بالای' : 'متعادل'} اهرم مالی می‌باشد. با توجه به ساختار درآمدهای عملیاتی، حاشیه سود خالص <b>${netMargin}٪</b> برآورد شده که نیازمند ${netMargin < 0 ? 'مدیریت هزینه‌ها' : 'حفظ ثبات رویه'} است.`;
476 +
477 + target.innerHTML = `
478 + <div class="grid grid-cols-1 lg:grid-cols-12 gap-4">
479 + <div class="lg:col-span-7 bg-slate-900 border border-slate-800 rounded-xl p-5 shadow-xl">
480 + <div class="border-b border-slate-800 pb-4 mb-4 flex items-center justify-between">
481 + <div>
482 + <h2 class="font-bold text-white text-sm">گزارش حسابرس مستقل و بازرس قانونی</h2>
483 + <h3 class="text-[11px] text-slate-400 mt-1">به مجمع عمومی صاحبان سهام ${COMPANIES_INFO[currentCompanyId]}</h3>
484 + </div>
485 + <span class="text-xs font-mono bg-indigo-950 text-indigo-300 px-2 py-1 rounded">سال ${currentYear}</span>
486 + </div>
487 +
488 + <div class="bg-slate-950 border border-slate-800 p-4 rounded-lg mb-4">
489 + <h4 class="font-bold text-indigo-400 text-xs mb-2 flex items-center gap-1.5"><div class="w-1.5 h-1.5 rounded-full bg-indigo-400"></div> اظهارنظر حسابرس:</h4>
490 + <p class="text-[11px] leading-6 text-slate-300 text-justify">به نظر این سازمان، صورت‌های مالی یاد شده، وضعیت مالی شرکت را در تاریخ پایان اسفند ${currentYear}، از تمام جنبه‌های بااهمیت، طبق استانداردهای حسابداری به نحو مطلوب نشان می‌دهد.</p>
491 + <div class="mt-3 inline-block bg-emerald-950/40 border border-emerald-800 text-emerald-400 px-3 py-1.5 rounded font-bold text-xs">
492 + نتیجه نهایی: ${data.auditorOpinion}
493 + </div>
494 + </div>
495 +
496 + ${data.auditorClauses ? `
497 + <div class="space-y-2">
498 + <h4 class="font-bold text-amber-400 text-xs mb-2">مبانی اظهارنظر مشروط و تاکید بر مطلب خاص:</h4>
499 + ${data.auditorClauses.map(c => `
500 + <div class="border-r-2 border-amber-500 bg-slate-950/50 p-3 rounded-l-lg">
501 + <h5 class="font-bold text-white text-[11px] mb-1">${c.title}</h5>
502 + <p class="text-[11px] text-slate-400 leading-5 text-justify">${c.desc}</p>
503 + </div>
504 + `).join('')}
505 + </div>
506 + ` : ''}
507 + </div>
508 +
509 + <!-- AI Dashboard -->
510 + <div class="lg:col-span-5 bg-slate-900 border border-slate-800 rounded-xl p-5 shadow-xl flex flex-col">
511 + <div class="border-b border-slate-800 pb-3 mb-4 flex items-center gap-2">
512 + <div class="p-1.5 bg-purple-600/20 text-purple-400 rounded-lg"><svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg></div>
513 + <h2 class="font-bold text-white text-sm">داشبورد تحلیلی هوش مصنوعی (AI)</h2>
514 + </div>
515 + <div class="space-y-4 flex-1">
516 + <div class="bg-slate-950 p-3 rounded-lg border border-slate-800/50 flex justify-between items-center">
517 + <span class="text-[11px] text-slate-300 font-bold">نسبت نقدینگی (جاری)</span>
518 + <span class="text-lg font-mono font-bold text-${crColor}-400">${currentRatio}</span>
519 + </div>
520 + <div class="bg-slate-950 p-3 rounded-lg border border-slate-800/50 flex justify-between items-center">
521 + <span class="text-[11px] text-slate-300 font-bold">نسبت بدهی به دارایی</span>
522 + <span class="text-lg font-mono font-bold text-${drColor}-400">${debtRatio}٪</span>
523 + </div>
524 + <div class="bg-slate-950 p-3 rounded-lg border border-slate-800/50 flex justify-between items-center">
525 + <span class="text-[11px] text-slate-300 font-bold">حاشیه سود خالص</span>
526 + <span class="text-lg font-mono font-bold text-${nmColor}-400">${netMargin}٪</span>
527 + </div>
528 + <div class="bg-purple-950/20 border border-purple-900/30 p-3.5 rounded-lg mt-4 flex-1">
529 + <p class="text-[11px] text-slate-300 leading-6 text-justify">${aiText}</p>
530 + </div>
531 + </div>
532 + </div>
533 + </div>
534 + `;
535 + }
536 +
537 + function renderBS(target, data) {
538 + const bs = data.BS;
539 + const is3Col = bs['101'].ycomp2 !== null && bs['101'].ycomp2 !== undefined;
540 + const sumGr = (keys, col) => keys.reduce((a, k) => a + (bs[k][col] || 0), 0);
541 +
542 + const ncAs = ['101','102','103']; const cAs = ['201','202','203','204'];
543 + const eq = ['301','302','303','304']; const ncLi = ['401','402']; const cLi = ['501','502','503'];
544 +
545 + target.innerHTML = `
546 + <div class="space-y-4">
547 + <div class="bg-slate-900 border border-slate-800 p-4 rounded-xl flex justify-between items-center shadow-lg">
548 + <h2 class="font-bold text-sm text-white">صورت وضعیت مالی (ترازنامه) - سال ${currentYear}</h2>
549 + </div>
550 +
551 + <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
552 + <div class="bg-slate-900 border border-slate-800 rounded-xl p-4 shadow-xl overflow-x-auto">
553 + <div class="border-b border-slate-800 pb-2 mb-3 flex justify-between min-w-[320px]">
554 + <h3 class="font-bold text-blue-400 text-sm">دارایی‌ها</h3>
555 + <div class="flex gap-2 text-[10px] font-mono text-slate-400 text-center">
556 + <span class="w-20 text-emerald-400">سال ${currentYear}</span><span class="w-20 text-amber-300">سال قبل</span>${is3Col ? `<span class="w-20">دو سال قبل</span>` : ''}
557 + </div>
558 + </div>
559 + <div class="text-[10px] font-bold text-slate-500 bg-slate-950 px-2 py-1 mb-1 rounded min-w-[320px]">دارایی‌های غیرجاری</div>
560 + ${ncAs.map(k => renderBSRow(bs[k], is3Col)).join('')}
561 + <div class="flex justify-between text-xs font-bold text-blue-400 mt-1 mb-3 bg-blue-950/20 p-2 rounded min-w-[320px]">
562 + <span>جمع دارایی غیرجاری</span>
563 + <div class="flex gap-2 text-center font-mono"><span class="w-20">${fmt(sumGr(ncAs, 'ycur'))}</span><span class="w-20 text-amber-300">${fmt(sumGr(ncAs, 'ycomp1'))}</span>${is3Col ? `<span class="w-20 text-slate-300">${fmt(sumGr(ncAs, 'ycomp2'))}</span>` : ''}</div>
564 + </div>
565 + <div class="text-[10px] font-bold text-slate-500 bg-slate-950 px-2 py-1 mb-1 rounded min-w-[320px]">دارایی‌های جاری</div>
566 + ${cAs.map(k => renderBSRow(bs[k], is3Col)).join('')}
567 + <div class="flex justify-between text-xs font-bold text-blue-400 mt-1 bg-blue-950/20 p-2 rounded min-w-[320px]">
568 + <span>جمع دارایی جاری</span>
569 + <div class="flex gap-2 text-center font-mono"><span class="w-20">${fmt(sumGr(cAs, 'ycur'))}</span><span class="w-20 text-amber-300">${fmt(sumGr(cAs, 'ycomp1'))}</span>${is3Col ? `<span class="w-20 text-slate-300">${fmt(sumGr(cAs, 'ycomp2'))}</span>` : ''}</div>
570 + </div>
571 + <div class="flex justify-between text-sm font-bold text-emerald-400 mt-4 bg-emerald-950/20 border border-emerald-900/50 p-3 rounded-lg min-w-[320px]">
572 + <span>جمع کل دارایی‌ها</span>
573 + <div class="flex gap-2 text-center font-mono"><span class="w-20">${fmt(sumGr([...ncAs, ...cAs], 'ycur'))}</span><span class="w-20 text-amber-300">${fmt(sumGr([...ncAs, ...cAs], 'ycomp1'))}</span>${is3Col ? `<span class="w-20 text-slate-300">${fmt(sumGr([...ncAs, ...cAs], 'ycomp2'))}</span>` : ''}</div>
574 + </div>
575 + </div>
576 +
577 + <div class="bg-slate-900 border border-slate-800 rounded-xl p-4 shadow-xl overflow-x-auto">
578 + <div class="border-b border-slate-800 pb-2 mb-3 flex justify-between min-w-[320px]">
579 + <h3 class="font-bold text-indigo-400 text-sm">حقوق مالکانه و بدهی‌ها</h3>
580 + <div class="flex gap-2 text-[10px] font-mono text-slate-400 text-center">
581 + <span class="w-20 text-emerald-400">سال ${currentYear}</span><span class="w-20 text-amber-300">سال قبل</span>${is3Col ? `<span class="w-20">دو سال قبل</span>` : ''}
582 + </div>
583 + </div>
584 + <div class="text-[10px] font-bold text-slate-500 bg-slate-950 px-2 py-1 mb-1 rounded min-w-[320px]">حقوق مالکانه</div>
585 + ${eq.map(k => renderBSRow(bs[k], is3Col)).join('')}
586 + <div class="flex justify-between text-xs font-bold text-rose-400 mt-1 mb-3 bg-rose-950/20 p-2 rounded min-w-[320px]">
587 + <span>جمع حقوق مالکانه</span>
588 + <div class="flex gap-2 text-center font-mono"><span class="w-20">${fmt(sumGr(eq, 'ycur'))}</span><span class="w-20 text-rose-400/80">${fmt(sumGr(eq, 'ycomp1'))}</span>${is3Col ? `<span class="w-20 text-rose-400/60">${fmt(sumGr(eq, 'ycomp2'))}</span>` : ''}</div>
589 + </div>
590 + <div class="text-[10px] font-bold text-slate-500 bg-slate-950 px-2 py-1 mb-1 rounded min-w-[320px]">بدهی‌های غیرجاری</div>
591 + ${ncLi.map(k => renderBSRow(bs[k], is3Col)).join('')}
592 + <div class="flex justify-between text-xs font-bold text-indigo-400 mt-1 mb-3 bg-indigo-950/20 p-2 rounded min-w-[320px]">
593 + <span>جمع بدهی غیرجاری</span>
594 + <div class="flex gap-2 text-center font-mono"><span class="w-20">${fmt(sumGr(ncLi, 'ycur'))}</span><span class="w-20 text-amber-300">${fmt(sumGr(ncLi, 'ycomp1'))}</span>${is3Col ? `<span class="w-20 text-slate-300">${fmt(sumGr(ncLi, 'ycomp2'))}</span>` : ''}</div>
595 + </div>
596 + <div class="text-[10px] font-bold text-slate-500 bg-slate-950 px-2 py-1 mb-1 rounded min-w-[320px]">بدهی‌های جاری</div>
597 + ${cLi.map(k => renderBSRow(bs[k], is3Col)).join('')}
598 + <div class="flex justify-between text-xs font-bold text-indigo-400 mt-1 bg-indigo-950/20 p-2 rounded min-w-[320px]">
599 + <span>جمع بدهی جاری</span>
600 + <div class="flex gap-2 text-center font-mono"><span class="w-20">${fmt(sumGr(cLi, 'ycur'))}</span><span class="w-20 text-amber-300">${fmt(sumGr(cLi, 'ycomp1'))}</span>${is3Col ? `<span class="w-20 text-slate-300">${fmt(sumGr(cLi, 'ycomp2'))}</span>` : ''}</div>
601 + </div>
602 + <div class="flex justify-between text-sm font-bold text-emerald-400 mt-4 bg-emerald-950/20 border border-emerald-900/50 p-3 rounded-lg min-w-[320px]">
603 + <span>جمع حقوق و بدهی‌ها</span>
604 + <div class="flex gap-2 text-center font-mono"><span class="w-20">${fmt(sumGr([...eq, ...ncLi, ...cLi], 'ycur'))}</span><span class="w-20 text-amber-300">${fmt(sumGr([...eq, ...ncLi, ...cLi], 'ycomp1'))}</span>${is3Col ? `<span class="w-20 text-slate-300">${fmt(sumGr([...eq, ...ncLi, ...cLi], 'ycomp2'))}</span>` : ''}</div>
605 + </div>
606 + </div>
607 + </div>
608 + </div>
609 + `;
610 + }
611 +
612 + function renderBSRow(row, is3Col) {
613 + if (!row) return '';
614 + return `
615 + <div class="flex justify-between text-[11px] py-1.5 px-1 border-b border-slate-800/50 min-w-[320px]">
616 + <span class="text-slate-300">${row.title}</span>
617 + <div class="flex gap-2 text-center font-mono font-bold">
618 + <span class="w-20 ${row.ycur < 0 ? 'text-rose-400' : 'text-white'}">${fmt(row.ycur)}</span>
619 + <span class="w-20 ${row.ycomp1 < 0 ? 'text-rose-400/80' : 'text-amber-300/90'}">${fmt(row.ycomp1)}</span>
620 + ${is3Col ? `<span class="w-20 ${row.ycomp2 < 0 ? 'text-rose-400/60' : 'text-slate-400'}">${fmt(row.ycomp2)}</span>` : ''}
621 + </div>
622 + </div>
623 + `;
624 + }
625 +
626 + function renderIS(target, data) {
627 + const is = data.IS;
628 + const grossCur = is['601'].cur + is['602'].cur;
629 + const grossComp = is['601'].comp + is['602'].comp;
630 + const opCur = grossCur + is['603'].cur + (is['604']?.cur||0);
631 + const opComp = grossComp + is['603'].comp + (is['604']?.comp||0);
632 + const netCur = opCur + (is['605']?.cur||0) + (is['606']?.cur||0);
633 + const netComp = opComp + (is['605']?.comp||0) + (is['606']?.comp||0);
634 +
635 + target.innerHTML = `
636 + <div class="bg-slate-900 border border-slate-800 rounded-xl p-4 md:p-6 max-w-3xl mx-auto shadow-xl">
637 + <div class="border-b border-slate-800 pb-3 mb-4 flex justify-between">
638 + <h3 class="font-bold text-white text-sm">صورت سود و زیان جامع</h3>
639 + <div class="flex gap-4 text-xs font-mono text-slate-400"><span class="w-24 text-emerald-400 text-left">سال ${currentYear}</span><span class="w-24 text-amber-300 text-left">سال قبل</span></div>
640 + </div>
641 + <div class="space-y-2 text-xs">
642 + <div class="flex justify-between py-2 border-b border-slate-800"><span>${is['601'].title}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-emerald-400">${fmt(is['601'].cur)}</span><span class="w-24 text-left text-amber-300">${fmt(is['601'].comp)}</span></div></div>
643 + <div class="flex justify-between py-2 border-b border-slate-800"><span>${is['602'].title}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-rose-400">${fmt(is['602'].cur)}</span><span class="w-24 text-left text-rose-400/80">${fmt(is['602'].comp)}</span></div></div>
644 + <div class="flex justify-between py-2.5 bg-slate-950 px-3 rounded-lg border border-slate-800 font-bold"><span class="text-blue-400">سود (زیان) ناخالص</span><div class="flex gap-4 font-mono"><span class="w-24 text-left ${grossCur<0?'text-rose-400':'text-blue-400'}">${fmt(grossCur)}</span><span class="w-24 text-left ${grossComp<0?'text-rose-400/80':'text-amber-300'}">${fmt(grossComp)}</span></div></div>
645 +
646 + <div class="flex justify-between py-2 border-b border-slate-800 mt-2"><span>${is['603'].title}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-rose-400">${fmt(is['603'].cur)}</span><span class="w-24 text-left text-rose-400/80">${fmt(is['603'].comp)}</span></div></div>
647 + <div class="flex justify-between py-2 border-b border-slate-800"><span>${is['604']?.title||'-'}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-emerald-400">${fmt(is['604']?.cur)}</span><span class="w-24 text-left text-amber-300">${fmt(is['604']?.comp)}</span></div></div>
648 + <div class="flex justify-between py-2.5 bg-blue-950/30 px-3 rounded-lg border border-blue-900/50 font-bold"><span class="text-blue-300">سود (زیان) عملیاتی</span><div class="flex gap-4 font-mono"><span class="w-24 text-left ${opCur<0?'text-rose-400':'text-blue-300'}">${fmt(opCur)}</span><span class="w-24 text-left ${opComp<0?'text-rose-400/80':'text-amber-300'}">${fmt(opComp)}</span></div></div>
649 +
650 + <div class="flex justify-between py-2 border-b border-slate-800 mt-2"><span>${is['605']?.title||'-'}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left ${is['605']?.cur<0?'text-rose-400':'text-emerald-400'}">${fmt(is['605']?.cur)}</span><span class="w-24 text-left ${is['605']?.comp<0?'text-rose-400/80':'text-amber-300'}">${fmt(is['605']?.comp)}</span></div></div>
651 + <div class="flex justify-between py-2 border-b border-slate-800"><span>${is['606']?.title||'-'}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-rose-400">${fmt(is['606']?.cur)}</span><span class="w-24 text-left text-rose-400/80">${fmt(is['606']?.comp)}</span></div></div>
652 +
653 + <div class="flex justify-between py-4 bg-rose-950/30 px-4 rounded-xl border border-rose-500/40 font-bold mt-4 text-sm"><span class="text-rose-400">زیان خالص سال مالی</span><div class="flex gap-4 font-mono"><span class="w-24 text-left text-rose-400">${fmt(netCur)}</span><span class="w-24 text-left text-rose-400/80">${fmt(netComp)}</span></div></div>
654 + </div>
655 + </div>
656 + `;
657 + }
658 +
659 + function renderEquity(target, data) {
660 + const eqData = data.EQ;
661 + target.innerHTML = `
662 + <div class="bg-slate-900 border border-slate-800 rounded-xl p-5 max-w-5xl mx-auto shadow-xl overflow-x-auto">
663 + <h3 class="font-bold text-white text-sm mb-4">صورت تغییرات در حقوق مالکانه (سال ${currentYear})</h3>
664 + <table class="w-full text-right text-xs min-w-[600px]">
665 + <thead class="bg-slate-950 text-slate-400 border-b border-slate-800 font-bold">
666 + <tr><th class="p-2">شرح</th><th class="p-2">سرمایه</th><th class="p-2">در جریان</th><th class="p-2">زیان انباشته</th><th class="p-2 text-emerald-400">جمع کل</th></tr>
667 + </thead>
668 + <tbody class="divide-y divide-slate-800 font-mono text-slate-300">
669 + ${eqData.map(row => `
670 + <tr class="${row.highlight ? 'bg-slate-950/80 font-bold text-white' : 'hover:bg-slate-800/50'}">
671 + <td class="p-2 font-sans ${row.highlight ? 'text-amber-400' : ''}">${row.title}</td>
672 + <td class="p-2 ${row.c1 !== '-' ? 'text-emerald-400' : ''}">${fmt(row.c1)}</td>
673 + <td class="p-2">${fmt(row.c2)}</td>
674 + <td class="p-2 text-rose-400">${fmt(row.c3)}</td>
675 + <td class="p-2 ${row.total < 0 ? 'text-rose-400' : 'text-emerald-400'} font-bold">${fmt(row.total)}</td>
676 + </tr>
677 + `).join('')}
678 + </tbody>
679 + </table>
680 + </div>
681 + `;
682 + }
683 +
684 + function renderCF(target, data) {
685 + const cf = data.CF;
686 + const netOpCur = cf['701'].cur + (cf['702']?.cur||0);
687 + const netOpComp = cf['701'].comp + (cf['702']?.comp||0);
688 + const netInvCur = cf['801'].cur + (cf['802']?.cur||0);
689 + const netInvComp = cf['801'].comp + (cf['802']?.comp||0);
690 +
691 + target.innerHTML = `
692 + <div class="bg-slate-900 border border-slate-800 rounded-xl p-6 max-w-3xl mx-auto shadow-xl">
693 + <h3 class="font-bold text-white text-sm mb-4 border-b border-slate-800 pb-2">صورت جریان‌های نقدی</h3>
694 + <div class="space-y-4 text-xs">
695 + <div class="space-y-2">
696 + <div class="font-bold text-blue-400 bg-slate-950 p-2 rounded">فعالیت‌های عملیاتی</div>
697 + <div class="flex justify-between py-1 px-2 border-b border-slate-800/50"><span>${cf['701'].title}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left">${fmt(cf['701'].cur)}</span><span class="w-24 text-left text-amber-300/80">${fmt(cf['701'].comp)}</span></div></div>
698 + ${cf['702'] ? `<div class="flex justify-between py-1 px-2 border-b border-slate-800/50"><span>${cf['702'].title}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-rose-400">${fmt(cf['702'].cur)}</span><span class="w-24 text-left text-rose-400/80">${fmt(cf['702'].comp)}</span></div></div>` : ''}
699 + <div class="flex justify-between py-2 px-2 bg-blue-950/20 font-bold text-emerald-400 rounded"><span>خالص جریان عملیاتی</span><div class="flex gap-4 font-mono"><span class="w-24 text-left">${fmt(netOpCur)}</span><span class="w-24 text-left">${fmt(netOpComp)}</span></div></div>
700 + </div>
701 + <div class="space-y-2">
702 + <div class="font-bold text-indigo-400 bg-slate-950 p-2 rounded">فعالیت‌های سرمایه‌گذاری</div>
703 + <div class="flex justify-between py-1 px-2 border-b border-slate-800/50"><span>${cf['801'].title}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-rose-400">${fmt(cf['801'].cur)}</span><span class="w-24 text-left text-rose-400/80">${fmt(cf['801'].comp)}</span></div></div>
704 + ${cf['802'] ? `<div class="flex justify-between py-1 px-2 border-b border-slate-800/50"><span>${cf['802'].title}</span><div class="flex gap-4 font-mono font-bold"><span class="w-24 text-left text-rose-400">${fmt(cf['802'].cur)}</span><span class="w-24 text-left text-rose-400/80">${fmt(cf['802'].comp)}</span></div></div>` : ''}
705 + <div class="flex justify-between py-2 px-2 bg-indigo-950/20 font-bold text-rose-400 rounded"><span>خالص جریان سرمایه‌گذاری</span><div class="flex gap-4 font-mono"><span class="w-24 text-left">${fmt(netInvCur)}</span><span class="w-24 text-left">${fmt(netInvComp)}</span></div></div>
706 + </div>
707 + <div class="flex justify-between py-3 px-4 bg-emerald-950/30 border border-emerald-800/50 rounded-lg mt-4 font-bold text-sm">
708 + <span class="text-white">مانده موجودی نقد در پایان سال</span>
709 + <div class="flex gap-4 font-mono text-emerald-400"><span class="w-24 text-left">${fmt(data.BS['204'].ycur)}</span><span class="w-24 text-left text-amber-300">${fmt(data.BS['204'].ycomp1)}</span></div>
710 + </div>
711 + </div>
712 + </div>
713 + `;
714 + }
715 +
716 + function renderMapping(target) {
717 + target.innerHTML = `
718 + <div class="bg-slate-900 border border-slate-800 rounded-xl p-6 max-w-4xl mx-auto space-y-6 shadow-xl">
719 + <div class="text-center space-y-2 border-b border-slate-800 pb-4">
720 + <div class="text-4xl">🔗</div>
721 + <h2 class="font-bold text-purple-400 text-lg">کدینگ و منطق نگاشت برای سال ۱۴۰۵</h2>
722 + <p class="text-xs text-slate-400 max-w-xl mx-auto leading-6">این فرمول‌ها جهت پردازش O، Oe و E از فایل Data.csv استخراج و در سیستم Jules قفل شده‌اند.</p>
723 + </div>
724 + <table class="w-full text-right text-xs border border-slate-800">
725 + <thead class="bg-slate-950 text-slate-400">
726 + <tr><th class="p-3">کد حساب</th><th class="p-3">شرح</th><th class="p-3">نوع نگاشت</th><th class="p-3">یادداشت مقصد</th></tr>
727 + </thead>
728 + <tbody class="divide-y divide-slate-800 font-mono text-slate-300">
729 + ${MAPPING_RULES.map(m => `
730 + <tr>
731 + <td class="p-3 font-bold text-blue-400">${m.code}</td>
732 + <td class="p-3 font-sans">${m.name}</td>
733 + <td class="p-3 text-purple-400 font-bold">${m.type}</td>
734 + <td class="p-3 text-amber-400">${m.note}</td>
735 + </tr>
736 + `).join('')}
737 + </tbody>
738 + </table>
739 + </div>
740 + `;
741 + }
742 +
743 + function renderUploadForm(target) {
744 + target.innerHTML = `
745 + <div class="bg-slate-900 border border-slate-800 rounded-xl p-8 max-w-lg mx-auto shadow-xl text-center">
746 + <h3 class="font-bold text-emerald-400 text-base mb-6">➕ ایجاد صورت‌های مالی سال ۱۴۰۵ در محیط Jules</h3>
747 +
748 + <input type="file" id="csvFileInput" accept=".csv" class="hidden" onchange="handleFileUpload(event)">
749 +
750 + <div onclick="document.getElementById('csvFileInput').click()" class="border-2 border-dashed border-slate-600 bg-slate-950/50 rounded-xl p-10 cursor-pointer hover:border-emerald-500 transition-colors">
751 + <div class="text-5xl mb-4">📂</div>
752 + <h4 class="font-bold text-white mb-2">فایل ترازنامه آزمایشی ۱۴۰۵ را انتخاب کنید</h4>
753 + <p class="text-xs text-slate-500">پشتیبانی از فرمت CSV (شامل سطوح T1 تا T5)</p>
754 + </div>
755 + <div class="mt-4 text-[10px] text-slate-500">
756 + پس از آپلود، کتابخانه PapaParse فایل را خوانده و با عبور از موتور نگاشت O/Oe/E صورت مالی را تولید می‌کند.
757 + </div>
758 + </div>
759 + `;
760 + }
761 +
762 + // ---------------------------------------------------------
763 + // FLAWLESS PRINT ENGINE (In-App Preview Overlay)
764 + // ---------------------------------------------------------
765 + function openPrintPreview() {
766 + const data = getActiveData();
767 + if(!data || !data.hasRealData) return alert('خطا: گزارش مالی این سال هنوز قطعی و بارگذاری نشده است.');
768 +
769 + const container = document.getElementById('print-pages-container');
770 + const bs = data.BS; const is = data.IS; const cf = data.CF;
771 + const is3Col = bs['101'].ycomp2 !== null && bs['101'].ycomp2 !== undefined;
772 +
773 + const sumGr = (keys, col) => keys.reduce((a, k) => a + (bs[k][col] || 0), 0);
774 + const curAssets = sumGr(['201','202','203','204'], 'ycur');
775 + const curLiab = sumGr(['501','502','503'], 'ycur');
776 + const totalAssets = curAssets + sumGr(['101','102','103'], 'ycur');
777 + const totalLiab = curLiab + sumGr(['401','402'], 'ycur');
778 + const revenue = is['601'].cur + (is['604']?.cur||0);
779 + const netProfit = revenue + is['602'].cur + is['603'].cur + (is['605']?.cur||0) + (is['606']?.cur||0);
780 +
781 + const currentRatio = curLiab ? (curAssets / curLiab).toFixed(2) : 0;
782 + const debtRatio = totalAssets ? ((totalLiab / totalAssets) * 100).toFixed(1) : 0;
783 + const netMargin = revenue ? ((netProfit / revenue) * 100).toFixed(1) : 0;
784 +
785 + let html = ``;
786 +
787 + // PAGE 1: Signatures
788 + html += `
789 + <div class="paper-sheet print-page first-page">
790 + <div style="text-align:center; margin-bottom:50px;">
791 + <h2>مجمع عمومی عادی صاحبان سهام</h2>
792 + <h2 style="font-size: 18pt;">${COMPANIES_INFO[currentCompanyId]}</h2>
793 + <h3 style="border:none;">صورت‌های مالی سال مالی منتهی به اسفند ${currentYear}</h3>
794 + </div>
795 + <p style="text-align:justify; line-height:2.5; font-size:12pt; margin-bottom: 50px;">
796 + <b>با احترام،</b><br>
797 + به پیوست صورت‌های مالی ${COMPANIES_INFO[currentCompanyId]} مربوط به سال مالی منتهی به ۲۹ اسفند ${currentYear} تقدیم می‌شود.
798 + اجزای تشکیل‌دهنده صورت‌های مالی شامل ترازنامه، صورت سود و زیان جامع، صورت تغییرات در حقوق مالکانه و صورت جریان‌های نقدی می‌باشد.
799 + این صورت‌های مالی طبق استانداردهای حسابداری تهیه شده و در تاریخ مقرر به تایید هیئت مدیره شرکت رسیده است.
800 + </p>
801 + <div class="sign-grid">
802 + ${data.signatures ? data.signatures.map(s => `
803 + <div class="sign-box">
804 + ${s.name}
805 + <span class="sign-role">${s.role}</span>
806 + </div>
807 + `).join('') : '<div class="sign-box">امضا محفوظ</div>'}
808 + </div>
809 + </div>
810 + `;
811 +
812 + // PAGE 2: Auditor Report
813 + html += `
814 + <div class="paper-sheet print-page">
815 + <h3>گزارش حسابرس مستقل و بازرس قانونی</h3>
816 + <p style="text-align:center; font-size:11pt; margin-bottom: 30px;">شرکت ${COMPANIES_INFO[currentCompanyId]} - منتهی به اسفند ${currentYear}</p>
817 + <p style="line-height:2.5; text-align:justify; font-size:12pt;">
818 + <b>اظهارنظر:</b> به نظر این سازمان، صورت‌های مالی یاد شده، وضعیت مالی شرکت را در تاریخ پایان اسفند ${currentYear}، و عملکرد مالی و جریان‌های نقدی آن را از تمام جنبه‌های بااهمیت، طبق استانداردهای حسابداری به نحو مطلوب نشان می‌دهد. <b>(${data.auditorOpinion})</b>
819 + </p>
820 + `;
821 + if(data.auditorClauses && data.auditorClauses.length > 0) {
822 + data.auditorClauses.forEach(c => { html += `<p style="margin-top:20px; text-align:justify; line-height:2; font-size:11pt;"><b>${c.title}:</b> ${c.desc}</p>`; });
823 + }
824 + html += `</div>`;
825 +
826 + // PAGE 3: AI Dashboard Infographic
827 + html += `
828 + <div class="paper-sheet print-page">
829 + <h3 style="margin-bottom:30px;">داشبورد تحلیلی هوش مصنوعی (AI)</h3>
830 + <div class="ai-grid">
831 + <div class="ai-card">
832 + <div class="ai-title">نسبت جاری (نقدینگی)</div>
833 + <div class="ai-val">${currentRatio}</div>
834 + </div>
835 + <div class="ai-card">
836 + <div class="ai-title">نسبت بدهی به دارایی</div>
837 + <div class="ai-val">${debtRatio} ٪</div>
838 + </div>
839 + <div class="ai-card">
840 + <div class="ai-title">حاشیه سود خالص</div>
841 + <div class="ai-val">${netMargin} ٪</div>
842 + </div>
843 + </div>
844 + <div class="ai-analysis">
845 + <b>تحلیل سیستم مدیریتی:</b><br>
846 + بر اساس ارقام حسابرسی شده سال ${currentYear}، شاخص نقدینگی شرکت معادل ${currentRatio} ارزیابی می‌گردد.
847 + سطح اهرم مالی معادل ${debtRatio} درصد از کل دارایی‌هاست. عملکرد سودآوری شرکت پس از کسر تمامی هزینه‌ها، نشان‌دهنده حاشیه سود خالص ${netMargin} درصدی نسبت به درآمدهای عملیاتی می‌باشد.
848 + </div>
849 + </div>
850 + `;
851 +
852 + // PAGE 4: Balance Sheet
853 + html += `<div class="paper-sheet print-page"><h3>صورت وضعیت مالی (ترازنامه)</h3><table style="width:100%; text-align:right;"><tr><th>دارایی‌ها</th><th>سال ${currentYear}</th><th>سال قبل</th>${is3Col ? '<th>دو سال قبل</th>' : ''}<th>حقوق و بدهی‌ها</th><th>سال ${currentYear}</th><th>سال قبل</th>${is3Col ? '<th>دو سال قبل</th>' : ''}</tr>`;
854 + html += `<tr><td>جمع دارایی غیرجاری</td><td>${fmt(sumGr(['101','102','103'],'ycur'))}</td><td>${fmt(sumGr(['101','102','103'],'ycomp1'))}</td>${is3Col ? `<td>${fmt(sumGr(['101','102','103'],'ycomp2'))}</td>` : ''}<td>جمع حقوق مالکانه</td><td>${fmt(sumGr(['301','302','303','304'],'ycur'))}</td><td>${fmt(sumGr(['301','302','303','304'],'ycomp1'))}</td>${is3Col ? `<td>${fmt(sumGr(['301','302','303','304'],'ycomp2'))}</td>` : ''}</tr>`;
855 + html += `<tr><td>جمع دارایی جاری</td><td>${fmt(sumGr(['201','202','203','204'],'ycur'))}</td><td>${fmt(sumGr(['201','202','203','204'],'ycomp1'))}</td>${is3Col ? `<td>${fmt(sumGr(['201','202','203','204'],'ycomp2'))}</td>` : ''}<td>جمع بدهی‌ها</td><td>${fmt(sumGr(['401','402','501','502','503'],'ycur'))}</td><td>${fmt(sumGr(['401','402','501','502','503'],'ycomp1'))}</td>${is3Col ? `<td>${fmt(sumGr(['401','402','501','502','503'],'ycomp2'))}</td>` : ''}</tr>`;
856 + html += `<tr><td><b>جمع کل دارایی‌ها</b></td><td><b>${fmt(totalAssets)}</b></td><td><b>${fmt(sumGr(['101','102','103','201','202','203','204'],'ycomp1'))}</b></td>${is3Col ? `<td><b>${fmt(sumGr(['101','102','103','201','202','203','204'],'ycomp2'))}</b></td>` : ''}<td><b>جمع حقوق و بدهی‌ها</b></td><td><b>${fmt(sumGr(['301','302','303','304','401','402','501','502','503'],'ycur'))}</b></td><td><b>${fmt(sumGr(['301','302','303','304','401','402','501','502','503'],'ycomp1'))}</b></td>${is3Col ? `<td><b>${fmt(sumGr(['301','302','303','304','401','402','501','502','503'],'ycomp2'))}</b></td>` : ''}</tr></table></div>`;
857 +
858 + // PAGE 5: IS & CF
859 + const netComp = is['601'].comp+is['602'].comp+is['603'].comp+(is['604']?.comp||0)+(is['605']?.comp||0)+(is['606']?.comp||0);
860 + html += `<div class="paper-sheet print-page"><h3>صورت سود و زیان جامع</h3><table><tr><th>شرح</th><th>سال ${currentYear}</th><th>سال قبل</th></tr>`;
861 + html += `<tr><td>درآمدهای عملیاتی</td><td>${fmt(is['601'].cur)}</td><td>${fmt(is['601'].comp)}</td></tr>`;
862 + html += `<tr><td>بهای تمام شده درآمدهای عملیاتی</td><td>${fmt(is['602'].cur)}</td><td>${fmt(is['602'].comp)}</td></tr>`;
863 + html += `<tr><td>سود (زیان) ناخالص</td><td>${fmt(is['601'].cur+is['602'].cur)}</td><td>${fmt(is['601'].comp+is['602'].comp)}</td></tr>`;
864 + html += `<tr><td>هزینه‌های عمومی و اداری</td><td>${fmt(is['603'].cur)}</td><td>${fmt(is['603'].comp)}</td></tr>`;
865 + html += `<tr><td>سود (زیان) عملیاتی</td><td>${fmt(is['601'].cur+is['602'].cur+is['603'].cur+(is['604'].cur||0))}</td><td>${fmt(is['601'].comp+is['602'].comp+is['603'].comp+(is['604'].comp||0))}</td></tr>`;
866 + html += `<tr><td><b>زیان خالص سال مالی</b></td><td><b>${fmt(netProfit)}</b></td><td><b>${fmt(netComp)}</b></td></tr></table>`;
867 +
868 + html += `<h3 style="margin-top:40px;">صورت جریان‌های نقدی</h3><table><tr><th>شرح</th><th>سال ${currentYear}</th><th>سال قبل</th></tr>`;
869 + html += `<tr><td>نقد حاصل از عملیات</td><td>${fmt(cf['701'].cur)}</td><td>${fmt(cf['701'].comp)}</td></tr>`;
870 + html += `<tr><td><b>مانده موجودی نقد پایان سال</b></td><td><b>${fmt(bs['204'].ycur)}</b></td><td><b>${fmt(bs['204'].ycomp1)}</b></td></tr></table></div>`;
871 +
872 + container.innerHTML = html;
873 +
874 + // نمایش محیط پیش‌نمایش
875 + document.body.classList.add('preview-mode');
876 + }
877 +
878 + function closePrintPreview() {
879 + document.body.classList.remove('preview-mode');
880 + }
881 +
882 + // --- CSV PROCESSING ENGINE FOR JULES ---
883 + function handleFileUpload(event) {
884 + const file = event.target.files[0];
885 + if (!file) return;
886 +
887 + document.getElementById('loader').style.display = 'flex';
888 +
889 + // PapaParse برای خواندن فایل اکسل/CSV در مرورگر
890 + Papa.parse(file, {
891 + complete: function(results) {
892 + // در پروژه واقعی، برنامه‌نویس شما باید نتایج (results.data) را با فرمول‌های O/Oe/E نگاشت کند.
893 + // اینجا برای شبیه‌سازی قدرت سیستم، یک دیتای مجازی بر اساس سال 1404 تولید می‌کنیم:
894 + setTimeout(() => {
895 + const base = DB['C_GAS_TRANS']['1404'];
896 + dynYear1405Data = JSON.parse(JSON.stringify(base));
897 +
898 + dynYear1405Data.auditorOpinion = 'در حال بررسی (پیش‌نویس اولیه سیستم)';
899 + dynYear1405Data.auditorClauses = [];
900 + dynYear1405Data.IS['601'].cur = Math.floor(base.IS['601'].cur * 1.15);
901 + dynYear1405Data.IS['602'].cur = Math.floor(base.IS['602'].cur * 1.12);
902 + dynYear1405Data.BS['204'].ycur = Math.floor(base.BS['204'].ycur * 1.05);
903 +
904 + document.getElementById('loader').style.display = 'none';
905 +
906 + currentYear = '1405';
907 + currentCompanyId = 'C_GAS_TRANS';
908 + switchTab('BS');
909 +
910 + alert('✅ فایل CSV توسط سیستم پارس شد و با عبور از موتور نگاشت O/Oe/E، صورت‌های مالی سال ۱۴۰۵ به صورت خودکار ایجاد گردید.');
911 + }, 1500);
912 + }
913 + });
914 + }
915 +
916 + // --- ACTIONS ---
917 + function switchTab(tab) { currentTab = tab; render(); }
918 + function onCompanyChange(val) { currentCompanyId = val; render(); }
919 + function onYearChange(yr) { currentYear = yr; render(); }
920 +
921 + // --- INIT ---
922 + function bootstrap() { render(); }
923 + if (document.readyState === 'complete') bootstrap();
924 + else document.addEventListener('DOMContentLoaded', bootstrap);
925 + </script>
926 +</body>
927 +</html>
\ No newline at end of file