سامانه صدور فاکتور و حسابداری

Update index.html

davoodmehraban89 committed Sep 24, 2026 at 22:54 UTC 4578fd9d568f6030edabdcb2b47435985ad41e70
1 file changed +149 -4
index.html
+149 -4
@@ -36,6 +36,15 @@ body{background-color:var(--bg);color:var(--text);font-size:14px}
36 .whatsapp-support svg{width:22px;height:22px;flex-shrink:0}
37 .card{background:var(--card-bg);border:1px solid var(--border);border-radius:12px;padding:18px;margin-bottom:18px;box-shadow:0 1px 3px rgba(0,0,0,.03);width:100%;max-width:100%;overflow:hidden}
38 .grid-kpi{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:14px;margin-bottom:18px}
39 +.kpi-gradient{box-shadow:0 4px 14px rgba(0,0,0,.12);border:none}
40 +.quick-actions-row{display:flex;gap:10px;flex-wrap:wrap;margin-bottom:16px}
41 +.qa-btn{display:flex;align-items:center;gap:6px;border:none;color:#fff;padding:11px 16px;border-radius:12px;font-size:13px;font-weight:600;cursor:pointer;box-shadow:0 3px 10px rgba(0,0,0,.15);flex:1;min-width:130px;justify-content:center}
42 +.qa-btn:hover{filter:brightness(1.08)}
43 +.report-bar-wrap{display:flex;align-items:flex-end;gap:6px;height:160px;padding:10px 4px;overflow-x:auto}
44 +.report-bar-col{display:flex;flex-direction:column;align-items:center;gap:4px;min-width:38px}
45 +.report-bar{width:26px;border-radius:6px 6px 0 0;background:linear-gradient(180deg,#8b5cf6,#6d28d9);transition:height .3s}
46 +.report-bar-label{font-size:10px;color:var(--text-muted);white-space:nowrap}
47 +.report-bar-value{font-size:10px;font-weight:bold;color:var(--text)}
48 .kpi-unit{background:var(--card-bg);border:1px solid var(--border);border-radius:10px;padding:16px;display:flex;align-items:center;gap:14px}
49 .kpi-icon{width:44px;height:44px;border-radius:10px;display:flex;align-items:center;justify-content:center;font-size:20px}
50 .kpi-val{font-size:17px;font-weight:bold;margin-top:4px}
@@ -154,6 +163,7 @@ html,body{background:#fff!important;color:#000!important;margin:0!important;padd
163 </div>
164 <ul class="sidebar-menu">
165 <li><a href="#" class="nav-link" data-view="view-dashboard" onclick="switchView('view-dashboard');return false">📊 داشبورد تحلیلی</a></li>
166 +<li><a href="#" class="nav-link" data-view="view-reports" onclick="switchView('view-reports');return false">📈 گزارشات مالی</a></li>
167 <li><a href="#" class="nav-link" data-view="view-invoices" onclick="switchView('view-invoices');return false">🧾 صدور فاکتور و اسناد</a></li>
168 <li><a href="#" class="nav-link" data-view="view-products" onclick="switchView('view-products');return false">📦 کالاها و خدمات</a></li>
169 <li><a href="#" class="nav-link" data-view="view-contacts" onclick="switchView('view-contacts');return false">👥 طرف‌حساب‌ها و معین</a></li>
@@ -164,6 +174,7 @@ html,body{background:#fff!important;color:#000!important;margin:0!important;padd
174 </ul>
175 <div class="sidebar-footer">
176 <span id="logged-user-label">کاربر</span>
177 +<span style="opacity:.6;font-size:10.5px">فینورا — نسخه ۱.۰</span>
178 <button class="btn btn-danger btn-inline" style="padding:4px 10px;font-size:11px;min-height:28px;width:100%;margin-top:4px" onclick="handleLogout()">🚪 خروج از حساب کاربری</button>
179 </div>
180 </aside>
@@ -185,11 +196,18 @@ html,body{background:#fff!important;color:#000!important;margin:0!important;padd
196 </div>
197 <div id="dashboard-license-details"></div>
198
199 +<div class="quick-actions-row no-print">
200 +<button class="qa-btn" style="background:linear-gradient(135deg,#f97316,#ea580c)" onclick="startNewInvoice()"><span>➕</span>فاکتور جدید</button>
201 +<button class="qa-btn" style="background:linear-gradient(135deg,#8b5cf6,#6d28d9)" onclick="switchView('view-contacts')"><span>👤</span>مشتری جدید</button>
202 +<button class="qa-btn" style="background:linear-gradient(135deg,#0ea5e9,#0369a1)" onclick="switchView('view-cheques')"><span>💳</span>ثبت چک</button>
203 +<button class="qa-btn" style="background:linear-gradient(135deg,#10b981,#047857)" onclick="switchView('view-reports')"><span>📈</span>گزارش مالی</button>
204 +</div>
205 +
206 <div class="grid-kpi">
189 -<div class="kpi-unit"><div class="kpi-icon" style="background:#eff6ff;color:var(--primary)">💰</div><div><div class="kpi-lbl">مجموع فروش ثبت‌شده (<span class="cur-label">ریال</span>)</div><div class="kpi-val" id="kpi-sales-sum">۰ ریال</div></div></div>
190 -<div class="kpi-unit"><div class="kpi-icon" style="background:#ecfdf5;color:var(--success)">📥</div><div><div class="kpi-lbl">دریافت وصول شده</div><div class="kpi-val" id="kpi-settled-sum">۰ ریال</div></div></div>
191 -<div class="kpi-unit"><div class="kpi-icon" style="background:#fffbeb;color:var(--warning)">⏳</div><div><div class="kpi-lbl">مانده مطالبات نسیه</div><div class="kpi-val" id="kpi-debtors-sum">۰ ریال</div></div></div>
192 -<div class="kpi-unit"><div class="kpi-icon" style="background:#fef2f2;color:var(--danger)">💳</div><div><div class="kpi-lbl">چک‌های باز صیادی</div><div class="kpi-val" id="kpi-cheques-count">۰ فقره</div></div></div>
207 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#3b82f6,#1d4ed8)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">💰</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">مجموع فروش ثبت‌شده (<span class="cur-label">ریال</span>)</div><div class="kpi-val" style="color:#fff" id="kpi-sales-sum">۰ ریال</div></div></div>
208 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#10b981,#059669)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">📥</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">دریافت وصول شده</div><div class="kpi-val" style="color:#fff" id="kpi-settled-sum">۰ ریال</div></div></div>
209 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#f59e0b,#d97706)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">⏳</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">مانده مطالبات نسیه</div><div class="kpi-val" style="color:#fff" id="kpi-debtors-sum">۰ ریال</div></div></div>
210 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#ef4444,#b91c1c)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">💳</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">چک‌های باز صیادی</div><div class="kpi-val" style="color:#fff" id="kpi-cheques-count">۰ فقره</div></div></div>
211 </div>
212
213 <div class="card">
@@ -215,6 +233,43 @@ html,body{background:#fff!important;color:#000!important;margin:0!important;padd
233 </div>
234 </section>
235
236 +<section id="view-reports" class="view-pane">
237 +<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:14px;flex-wrap:wrap;gap:10px">
238 +<h1 style="font-size:20px;font-weight:bold">📈 گزارشات مالی</h1>
239 +<select id="report-year-select" class="form-control" style="max-width:160px" onchange="renderFinancialReports()"></select>
240 +</div>
241 +
242 +<div class="grid-kpi">
243 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#6366f1,#4338ca)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">💵</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">مجموع فروش سال</div><div class="kpi-val" style="color:#fff" id="rep-year-total">۰</div></div></div>
244 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#ec4899,#be185d)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">📊</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">میانگین فروش ماهانه</div><div class="kpi-val" style="color:#fff" id="rep-year-avg">۰</div></div></div>
245 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#14b8a6,#0f766e)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">🏆</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">پرفروش‌ترین ماه</div><div class="kpi-val" style="color:#fff" id="rep-best-month">—</div></div></div>
246 +<div class="kpi-unit kpi-gradient" style="background:linear-gradient(135deg,#f97316,#c2410c)"><div class="kpi-icon" style="background:rgba(255,255,255,.2);color:#fff">🧾</div><div><div class="kpi-lbl" style="color:rgba(255,255,255,.85)">تعداد فاکتور صادرشده</div><div class="kpi-val" style="color:#fff" id="rep-invoice-count">۰</div></div></div>
247 +</div>
248 +
249 +<div class="card">
250 +<h3 style="font-size:15px;margin-bottom:6px">روند فروش ماهانه</h3>
251 +<div class="report-bar-wrap" id="report-monthly-chart"></div>
252 +</div>
253 +
254 +<div class="card">
255 +<h3 style="font-size:15px;margin-bottom:12px">مشتریان برتر (بر اساس مبلغ خرید)</h3>
256 +<div class="table-responsive">
257 +<table>
258 +<thead><tr><th>مشتری</th><th>تعداد فاکتور</th><th>جمع خرید (<span class="cur-label">ریال</span>)</th></tr></thead>
259 +<tbody id="report-top-customers"><tr><td colspan="3" style="text-align:center;color:var(--text-muted);padding:20px">داده‌ای برای نمایش وجود ندارد.</td></tr></tbody>
260 +</table>
261 +</div>
262 +</div>
263 +
264 +<div class="card">
265 +<h3 style="font-size:15px;margin-bottom:12px">تفکیک نوع فاکتور</h3>
266 +<div style="display:flex;gap:24px;flex-wrap:wrap">
267 +<div>🔴 رسمی: <strong id="rep-formal-count">۰</strong> فقره — <strong id="rep-formal-sum">۰</strong></div>
268 +<div>🟢 غیررسمی: <strong id="rep-informal-count">۰</strong> فقره — <strong id="rep-informal-sum">۰</strong></div>
269 +</div>
270 +</div>
271 +</section>
272 +
273 <section id="view-invoices" class="view-pane">
274 <div class="card no-print">
275 <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:14px">
@@ -1150,6 +1205,7 @@ function switchView(viewId){
1205 const dockViews=['view-dashboard','view-invoices','view-products','view-contacts','view-cheques','view-settings'];
1206 document.querySelectorAll('.dock-tab').forEach((dock,idx)=>{dock.classList.toggle('active',dockViews[idx]===viewId);});
1207 if(viewId==='view-admin')renderAdminPanel();
1208 + if(viewId==='view-reports')renderFinancialReports();
1209 window.scrollTo({top:0,behavior:'smooth'});
1210 }
1211 function toggleAccordion(headerEl){headerEl.parentElement.classList.toggle('open');}
@@ -2702,6 +2758,95 @@ window.addEventListener('DOMContentLoaded',()=>{initAuthSystem();});
2758 };
2759 })();
2760
2761 +// ============== گزارشات مالی ==============
2762 +function toEnglishDigits(str){
2763 + if(str===null||str===undefined)return '';
2764 + const map={'۰':'0','۱':'1','۲':'2','۳':'3','۴':'4','۵':'5','۶':'6','۷':'7','۸':'8','۹':'9'};
2765 + return String(str).replace(/[۰-۹]/g,d=>map[d]);
2766 +}
2767 +const persianMonthNames=['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند'];
2768 +function populateReportYearSelect(years){
2769 + const sel=document.getElementById('report-year-select');
2770 + if(!sel)return;
2771 + const current=sel.value;
2772 + sel.innerHTML=years.map(y=>`<option value="${y}">سال ${toPersianDigits(y)}</option>`).join('');
2773 + if(current&&years.includes(parseInt(current)))sel.value=current;
2774 +}
2775 +function renderFinancialReports(){
2776 + const cur=(typeof getCurrencyLabel==='function')?getCurrencyLabel():'ریال';
2777 + const invoices=(typeof getMyInvoices==='function')?getMyInvoices():[];
2778 + const parsed=invoices.map(inv=>{
2779 + const d=toEnglishDigits(inv.date||'');
2780 + const parts=d.split('/');
2781 + if(parts.length<2)return null;
2782 + const y=parseInt(parts[0]),m=parseInt(parts[1]);
2783 + if(!y||!m)return null;
2784 + return {year:y,month:m,inv};
2785 + }).filter(Boolean);
2786 +
2787 + let years=[...new Set(parsed.map(p=>p.year))].sort((a,b)=>b-a);
2788 + if(years.length===0){
2789 + const fallback=parseInt(toEnglishDigits((typeof getJalaliNumeric==='function'?getJalaliNumeric():'').split('/')[0]))||1404;
2790 + years=[fallback];
2791 + }
2792 + populateReportYearSelect(years);
2793 + const sel=document.getElementById('report-year-select');
2794 + const selectedYear=(sel&&sel.value)?parseInt(sel.value):years[0];
2795 +
2796 + const yearInvoices=parsed.filter(p=>p.year===selectedYear);
2797 + const monthTotals=Array(12).fill(0);
2798 + yearInvoices.forEach(p=>{ if(p.month>=1&&p.month<=12) monthTotals[p.month-1]+=(p.inv.grandTotal||0); });
2799 + const yearTotal=monthTotals.reduce((a,b)=>a+b,0);
2800 + const avg=yearTotal/12;
2801 + const maxVal=Math.max(...monthTotals,1);
2802 + const maxIdx=monthTotals.indexOf(maxVal);
2803 +
2804 + const setTxt=(id,txt)=>{const el=document.getElementById(id);if(el)el.innerText=txt;};
2805 + setTxt('rep-year-total',yearTotal.toLocaleString('fa-IR')+' '+cur);
2806 + setTxt('rep-year-avg',Math.round(avg).toLocaleString('fa-IR')+' '+cur);
2807 + setTxt('rep-best-month',monthTotals[maxIdx]>0?persianMonthNames[maxIdx]:'—');
2808 + setTxt('rep-invoice-count',yearInvoices.length.toLocaleString('fa-IR'));
2809 +
2810 + const chartEl=document.getElementById('report-monthly-chart');
2811 + if(chartEl){
2812 + chartEl.innerHTML=monthTotals.map((v,i)=>{
2813 + const h=Math.max(4,Math.round((v/maxVal)*130));
2814 + return `<div class="report-bar-col">
2815 + <div class="report-bar-value">${v>0?(v/1000000).toLocaleString('fa-IR',{maximumFractionDigits:1})+'M':''}</div>
2816 + <div class="report-bar" style="height:${h}px"></div>
2817 + <div class="report-bar-label">${persianMonthNames[i].slice(0,3)}</div>
2818 + </div>`;
2819 + }).join('');
2820 + }
2821 +
2822 + const byCustomer={};
2823 + yearInvoices.forEach(p=>{
2824 + const key=p.inv.contactId||p.inv.contactName||'—';
2825 + if(!byCustomer[key])byCustomer[key]={name:p.inv.contactName||'—',count:0,sum:0};
2826 + byCustomer[key].count++;
2827 + byCustomer[key].sum+=(p.inv.grandTotal||0);
2828 + });
2829 + const topList=Object.values(byCustomer).sort((a,b)=>b.sum-a.sum).slice(0,10);
2830 + const tbody=document.getElementById('report-top-customers');
2831 + if(tbody){
2832 + if(topList.length===0){
2833 + tbody.innerHTML='<tr><td colspan="3" style="text-align:center;color:var(--text-muted);padding:20px">داده‌ای برای نمایش وجود ندارد.</td></tr>';
2834 + }else{
2835 + tbody.innerHTML=topList.map(c=>`<tr><td>${(typeof esc==='function'?esc(c.name):c.name)}</td><td>${c.count.toLocaleString('fa-IR')}</td><td>${c.sum.toLocaleString('fa-IR')}</td></tr>`).join('');
2836 + }
2837 + }
2838 +
2839 + let formalCount=0,formalSum=0,informalCount=0,informalSum=0;
2840 + yearInvoices.forEach(p=>{
2841 + if(p.inv.kind==='formal'){formalCount++;formalSum+=(p.inv.grandTotal||0);}
2842 + else{informalCount++;informalSum+=(p.inv.grandTotal||0);}
2843 + });
2844 + setTxt('rep-formal-count',formalCount.toLocaleString('fa-IR'));
2845 + setTxt('rep-formal-sum',formalSum.toLocaleString('fa-IR')+' '+cur);
2846 + setTxt('rep-informal-count',informalCount.toLocaleString('fa-IR'));
2847 + setTxt('rep-informal-sum',informalSum.toLocaleString('fa-IR')+' '+cur);
2848 +}
2849 +
2850 // ============== تغییر/تعیین رمز عبور از داخل تنظیمات (برای کاربران گوگل هم کار می‌کند) ==============
2851 async function changeAccountPassword(){
2852 const p1=document.getElementById('acct-newpass').value;