mohadese-dashboards/cockpit.html

3140 lines
137 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ExecCockpit | سیستم عامل مدیریت اجرایی حامد فلاحی</title>
<!-- Vazirmatn Font -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<style>
:root {
--bg-base: #090a0f;
--bg-surface: #11131a;
--bg-surface-elevated: #181b24;
--bg-surface-hover: #222634;
--border-subtle: #252a38;
--border-strong: #384054;
--text-main: #f1f5f9;
--text-muted: #94a3b8;
--text-faint: #64748b;
--primary: #3b82f6;
--primary-hover: #2563eb;
--primary-glow: rgba(59, 130, 246, 0.25);
--accent-green: #10b981;
--accent-amber: #f59e0b;
--accent-rose: #f43f5e;
--accent-purple: #8b5cf6;
--radius-sm: 8px;
--radius-md: 12px;
--radius-lg: 16px;
--transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
font-feature-settings: "tnum" 1;
}
body {
background-color: var(--bg-base);
color: var(--text-main);
min-height: 100vh;
display: flex;
flex-direction: column;
overflow-x: hidden;
line-height: 1.6;
}
/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
/* Top Header */
header {
background: rgba(17, 19, 26, 0.9);
backdrop-filter: blur(12px);
border-bottom: 1px solid var(--border-subtle);
position: sticky;
top: 0;
z-index: 50;
padding: 0.75rem 1.5rem;
}
.header-inner {
max-width: 1440px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
.brand {
display: flex;
align-items: center;
gap: 0.75rem;
text-decoration: none;
color: inherit;
}
.brand-logo {
width: 36px;
height: 36px;
background: linear-gradient(135deg, #3b82f6, #8b5cf6);
border-radius: var(--radius-sm);
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
color: white;
font-size: 1.15rem;
box-shadow: 0 0 16px var(--primary-glow);
}
.brand-title {
font-size: 1.05rem;
font-weight: 700;
letter-spacing: -0.02em;
}
.brand-subtitle {
font-size: 0.75rem;
color: var(--text-muted);
}
.user-pill {
display: flex;
align-items: center;
gap: 0.6rem;
background: var(--bg-surface-elevated);
border: 1px solid var(--border-subtle);
padding: 0.35rem 0.85rem;
border-radius: 20px;
font-size: 0.82rem;
color: var(--text-main);
}
.sync-status {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.8rem;
padding: 0.35rem 0.75rem;
border-radius: 20px;
background: var(--bg-surface-elevated);
border: 1px solid var(--border-subtle);
color: var(--text-muted);
}
.sync-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent-green);
box-shadow: 0 0 8px var(--accent-green);
}
.sync-dot.syncing {
background: var(--accent-amber);
box-shadow: 0 0 8px var(--accent-amber);
animation: pulse 1s infinite alternate;
}
@keyframes pulse {
0% { opacity: 0.4; transform: scale(0.9); }
100% { opacity: 1; transform: scale(1.1); }
}
/* Master Tabs */
.nav-tabs {
display: flex;
gap: 0.5rem;
overflow-x: auto;
padding: 0.65rem 1.5rem;
background: var(--bg-surface);
border-bottom: 1px solid var(--border-subtle);
max-width: 1440px;
margin: 0 auto;
width: 100%;
}
.tab-btn {
padding: 0.45rem 0.9rem;
border-radius: var(--radius-sm);
border: 1px solid transparent;
background: transparent;
color: var(--text-muted);
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
white-space: nowrap;
transition: var(--transition);
display: flex;
align-items: center;
gap: 0.45rem;
}
.tab-btn:hover {
background: var(--bg-surface-hover);
color: var(--text-main);
}
.tab-btn.active {
background: var(--bg-surface-elevated);
border-color: var(--border-strong);
color: var(--primary);
font-weight: 600;
}
/* Badges */
.badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.15rem 0.45rem;
border-radius: 12px;
font-size: 0.72rem;
font-weight: 700;
line-height: 1;
}
.badge-primary { background: rgba(59, 130, 246, 0.18); color: #60a5fa; }
.badge-rose { background: rgba(244, 63, 94, 0.18); color: #fb7185; }
.badge-amber { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.badge-green { background: rgba(16, 185, 129, 0.18); color: #34d399; }
.badge-purple { background: rgba(139, 92, 246, 0.18); color: #c084fc; }
/* Main Container */
main {
flex: 1;
max-width: 1440px;
width: 100%;
margin: 0 auto;
padding: 1.5rem;
}
/* Gateway Landing Screen */
.gateway-container {
max-width: 960px;
margin: 2.5rem auto;
padding: 1rem;
}
.gateway-header {
text-align: center;
margin-bottom: 2.5rem;
}
.gateway-title {
font-size: 1.8rem;
font-weight: 800;
margin-bottom: 0.5rem;
background: linear-gradient(135deg, #ffffff, #94a3b8);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.gateway-desc {
font-size: 0.95rem;
color: var(--text-muted);
max-width: 600px;
margin: 0 auto;
}
.gateway-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.5rem;
}
.gateway-card {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-lg);
padding: 1.75rem 1.5rem;
display: flex;
flex-direction: column;
justify-content: space-between;
transition: var(--transition);
cursor: pointer;
position: relative;
overflow: hidden;
}
.gateway-card::before {
content: '';
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 4px;
background: var(--border-strong);
transition: var(--transition);
}
.gateway-card:hover {
border-color: var(--primary);
transform: translateY(-4px);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}
.gateway-card.card-hamed:hover::before { background: #3b82f6; }
.gateway-card.card-mohadese:hover::before { background: #8b5cf6; }
.gateway-card.card-team:hover::before { background: #10b981; }
.gateway-icon {
width: 48px;
height: 48px;
border-radius: var(--radius-md);
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
margin-bottom: 1.25rem;
background: var(--bg-surface-elevated);
border: 1px solid var(--border-strong);
}
.gateway-card-title {
font-size: 1.2rem;
font-weight: 700;
margin-bottom: 0.35rem;
}
.gateway-card-desc {
font-size: 0.85rem;
color: var(--text-muted);
line-height: 1.6;
margin-bottom: 1.5rem;
flex-grow: 1;
}
/* Cards & Containers */
.card {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
border-radius: var(--radius-md);
padding: 1.25rem;
transition: var(--transition);
position: relative;
}
.card:hover {
border-color: var(--border-strong);
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--border-subtle);
}
.card-title {
font-size: 1rem;
font-weight: 700;
display: flex;
align-items: center;
gap: 0.5rem;
}
/* Info Tooltip Icon */
.info-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
border-radius: 50%;
background: var(--bg-surface-elevated);
color: var(--text-muted);
border: 1px solid var(--border-strong);
font-size: 0.75rem;
font-style: normal;
cursor: help;
transition: var(--transition);
position: relative;
}
.info-icon:hover {
color: var(--primary);
border-color: var(--primary);
}
.info-icon[data-tooltip]::after {
content: attr(data-tooltip);
position: absolute;
bottom: 125%;
right: 50%;
transform: translateX(50%);
background: #1e2230;
color: #f1f5f9;
padding: 0.5rem 0.75rem;
border-radius: var(--radius-sm);
font-size: 0.75rem;
font-weight: 400;
white-space: normal;
width: 240px;
line-height: 1.4;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
border: 1px solid var(--border-strong);
pointer-events: none;
opacity: 0;
visibility: hidden;
transition: opacity 0.2s ease, visibility 0.2s;
z-index: 100;
text-align: right;
}
.info-icon:hover::after {
opacity: 1;
visibility: visible;
}
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
gap: 0.4rem;
padding: 0.5rem 1rem;
border-radius: var(--radius-sm);
border: 1px solid var(--border-strong);
background: var(--bg-surface-elevated);
color: var(--text-main);
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
transition: var(--transition);
text-decoration: none;
}
.btn:hover {
background: var(--bg-surface-hover);
border-color: var(--text-faint);
}
.btn-primary {
background: var(--primary);
border-color: var(--primary);
color: white;
}
.btn-primary:hover {
background: var(--primary-hover);
box-shadow: 0 0 12px var(--primary-glow);
}
.btn-success {
background: rgba(16, 185, 129, 0.15);
border-color: rgba(16, 185, 129, 0.3);
color: #34d399;
}
.btn-success:hover {
background: var(--accent-green);
color: white;
}
.btn-danger {
background: rgba(244, 63, 94, 0.15);
border-color: rgba(244, 63, 94, 0.3);
color: #fb7185;
}
.btn-danger:hover {
background: var(--accent-rose);
color: white;
}
.btn-sm {
padding: 0.3rem 0.65rem;
font-size: 0.78rem;
}
/* Forms & Inputs */
.form-group {
margin-bottom: 1rem;
}
.form-label {
display: block;
font-size: 0.8rem;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 0.4rem;
}
.form-control {
width: 100%;
padding: 0.6rem 0.85rem;
background: var(--bg-base);
border: 1px solid var(--border-strong);
border-radius: var(--radius-sm);
color: var(--text-main);
font-size: 0.9rem;
transition: var(--transition);
}
.form-control:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea.form-control {
resize: vertical;
min-height: 80px;
}
/* Grids */
.grid-2 {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
gap: 1.25rem;
}
.grid-3 {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.25rem;
}
/* Tables */
.table-container {
overflow-x: auto;
border-radius: var(--radius-sm);
border: 1px solid var(--border-subtle);
}
table {
width: 100%;
border-collapse: collapse;
text-align: right;
font-size: 0.85rem;
}
th {
background: var(--bg-surface-elevated);
color: var(--text-muted);
padding: 0.75rem 1rem;
font-weight: 600;
border-bottom: 1px solid var(--border-subtle);
white-space: nowrap;
}
td {
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--border-subtle);
color: var(--text-main);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-surface-hover); }
/* Action bar */
.action-bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1.25rem;
flex-wrap: wrap;
}
.search-box {
flex: 1;
min-width: 240px;
position: relative;
}
.search-input {
width: 100%;
padding: 0.55rem 2.2rem 0.55rem 0.85rem;
background: var(--bg-surface);
border: 1px solid var(--border-strong);
border-radius: var(--radius-sm);
color: var(--text-main);
font-size: 0.85rem;
}
.search-icon {
position: absolute;
right: 0.75rem;
top: 50%;
transform: translateY(-50%);
color: var(--text-faint);
}
/* Modals */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.78);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
padding: 1rem;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}
.modal-overlay.active {
opacity: 1;
pointer-events: auto;
}
.modal-content {
background: var(--bg-surface);
border: 1px solid var(--border-strong);
border-radius: var(--radius-lg);
width: 100%;
max-width: 550px;
max-height: 90vh;
overflow-y: auto;
padding: 1.5rem;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1.25rem;
padding-bottom: 0.75rem;
border-bottom: 1px solid var(--border-subtle);
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close {
background: none;
border: none;
color: var(--text-muted);
cursor: pointer;
font-size: 1.25rem;
line-height: 1;
}
.modal-close:hover { color: var(--text-main); }
/* Toast */
.toast-container {
position: fixed;
bottom: 1.5rem;
left: 1.5rem;
z-index: 200;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.toast {
background: var(--bg-surface-elevated);
border: 1px solid var(--border-strong);
color: var(--text-main);
padding: 0.75rem 1.25rem;
border-radius: var(--radius-sm);
box-shadow: 0 4px 20px rgba(0,0,0,0.4);
display: flex;
align-items: center;
gap: 0.6rem;
font-size: 0.85rem;
animation: slideIn 0.2s ease;
}
@keyframes slideIn {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
/* Footer */
footer {
border-top: 1px solid var(--border-subtle);
padding: 1.25rem 1.5rem;
background: var(--bg-surface);
font-size: 0.8rem;
color: var(--text-muted);
margin-top: auto;
}
.footer-inner {
max-width: 1440px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1rem;
}
/* Responsive */
@media (max-width: 768px) {
.header-inner { flex-direction: column; align-items: stretch; }
.nav-tabs { padding: 0.5rem 1rem; }
main { padding: 1rem; }
.action-bar { flex-direction: column; align-items: stretch; }
}
.badge-blue { background: rgba(14, 165, 233, 0.18); color: #38bdf8; }
.pulse-urgent { animation: pulseUrgent 1.8s infinite; }
@keyframes pulseUrgent { 0% { opacity: 1; } 50% { opacity: 0.45; } 100% { opacity: 1; } }
.filter-btn-group { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.filter-chip {
background: var(--bg-surface);
border: 1px solid var(--border-subtle);
color: var(--text-muted);
border-radius: 20px;
padding: 0.3rem 0.75rem;
font-size: 0.78rem;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
}
.filter-chip:hover { border-color: var(--border-strong); color: var(--text-main); }
.filter-chip.active {
background: rgba(59, 130, 246, 0.15);
border-color: #3b82f6;
color: #60a5fa;
font-weight: 700;
}
</style>
</head>
<body>
<!-- Top Header -->
<header>
<div class="header-inner">
<div class="brand">
<div class="brand-logo">H</div>
<div>
<div class="brand-title">ExecCockpit | سیستم عامل مدیریت اجرایی حامد فلاحی</div>
<div class="brand-subtitle" id="topSubtitle">پورتال هماهنگی عملیات و تصمیمات راهبردی</div>
</div>
</div>
<!-- User & Status Bar -->
<div style="display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;">
<div class="user-pill" id="userPill" style="display: none;">
<span id="userNameLabel">کاربر فعال</span>
<button class="btn btn-sm" onclick="logout()" style="padding: 0.2rem 0.5rem; font-size: 0.75rem; border-color: var(--border-strong);">
خروج 🚪
</button>
</div>
<div class="sync-status">
<span class="sync-dot" id="syncDot"></span>
<span id="syncText">🟢 اصالت داده: PostgreSQL 17 زنده (/api/db/state)</span>
<i class="info-icon" data-tooltip="این سیستم داده‌ها را بدون وابستگی به localStorage مستقیماً در جدول دائمی ekeepa_bi.dashboard_app_storage ذخیره و همگام می‌کند.">ⓘ</i>
</div>
</div>
</div>
</header>
<!-- Master Sub-navigation (Only in Mohadese Master View) -->
<nav class="nav-tabs" id="masterNav" style="display: none;">
<button class="tab-btn active" onclick="switchMasterTab('approvals')">
⚡ صف تاییدیه‌ها <span class="badge badge-rose" id="badgeApprovals">0</span>
<i class="info-icon" data-tooltip="درخواست‌های ارسالی همکاران یا مواردی که منتظر تایید نهایی حامد هستند.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchMasterTab('meetings')">
📅 جلسات و تردد <span class="badge badge-primary" id="badgeMeetings">0</span>
<i class="info-icon" data-tooltip="تفکیک ۳ گانه: آنلاین با لینک میت، حضوری خارج از دفتر با بافر ترافیک تهران و نشان، و حضوری در دفتر اکیپا بدون تردد.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchMasterTab('tasks')">
📋 تسک‌های اجرایی <span class="badge badge-amber" id="badgeTasks">0</span>
<i class="info-icon" data-tooltip="مدیریت تسک‌های تیم با تفکیک اولویت، مسئول و مهلت تحویل.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchMasterTab('finance')">
💳 رادار مالی و اقساط <span class="badge badge-green" id="badgeFinance">0</span>
<i class="info-icon" data-tooltip="سررسید اقساط تسهیلات بانکی، تنخواه‌ها و واریزی‌های معین.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchMasterTab('contacts')">
📇 مخاطبین VIP <span class="badge badge-purple" id="badgeContacts">0</span>
<i class="info-icon" data-tooltip="دفترچه راهبردی تفکیک‌شده: اکیپا، مایندرو، شخصی و سرمایه‌گذاران.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchMasterTab('vault')">
📁 آرشیو و اسناد درایو
<i class="info-icon" data-tooltip="لینک‌های دسترسی سریع به فولدرهای گوگل‌درایو، مدارک شرکتی، هویتی و قراردادها.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchMasterTab('recycle')">
🗑️ سطل بازیافت و بکاپ <span class="badge badge-primary" id="badgeRecycle">0</span>
<i class="info-icon" data-tooltip="تمامی آیتم‌های حذف‌شده در اینجا نگهداری می‌شوند و قابل بازگردانی کامل هستند.">ⓘ</i>
</button>
</nav>
<!-- Hamed Sub-navigation (Only in Hamed View) -->
<nav class="nav-tabs" id="hamedNav" style="display: none;">
<button class="tab-btn active" onclick="switchHamedTab('today')">
⚡ تصمیمات و جلسات امروز
<i class="info-icon" data-tooltip="تاییدیه‌های فوری P0 و لیست جلسات آنلاین و حضوری امروز با دسترسی سریع.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchHamedTab('finance')">
💳 سررسید اقساط و چک‌ها <span class="badge badge-amber" id="badgeHamedFinance">0</span>
<i class="info-icon" data-tooltip="جزئیات تعهدات مالی و اقساط ۷ روز آینده و ماهانه همراه با روزشمار باقی‌مانده.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchHamedTab('contacts')">
📇 مخاطبین VIP
<i class="info-icon" data-tooltip="دفترچه مخاطبین مهم کاری، شرکا و سرمایه‌گذاران با امکان تماس مستقیم.">ⓘ</i>
</button>
<button class="tab-btn" onclick="switchHamedTab('vault')">
📁 آرشیو و اسناد درایو
<i class="info-icon" data-tooltip="دسترسی سریع به پوشه‌های اسناد حقوقی، مدارک هویتی و قراردادهای شرکت.">ⓘ</i>
</button>
</nav>
<!-- Main Viewports -->
<main>
<!-- ==================== 1. GATEWAY SCREEN ==================== -->
<section id="viewGateway" class="gateway-container">
<div class="gateway-header">
<h1 class="gateway-title">دروازه ورود به سامانه ExecCockpit</h1>
<p class="gateway-desc">لطفاً پروفایل مورد نظر خود را جهت ورود به میز کار اختصاصی یا ثبت درخواست انتخاب نمایید.</p>
</div>
<div class="gateway-cards">
<!-- Card 1: Hamed -->
<div class="gateway-card card-hamed" onclick="openLoginModal('hamed')">
<div>
<div class="gateway-icon">👤</div>
<div class="gateway-card-title">حامد فلاحی</div>
<span class="badge badge-primary" style="margin-bottom: 0.75rem;">ورود مدیریت (Executive Focus)</span>
<p class="gateway-card-desc">
نمای اختصاصی و متمرکز؛ دسترسی سریع به تاییدیه‌های فوری، جلسات امروز، سررسید اقساط، مخاطبین VIP و اسناد درایو.
</p>
</div>
<button class="btn btn-primary" style="width: 100%; justify-content: center;">
ورود به میز کار حامد 🔒
</button>
</div>
<!-- Card 2: Mohadese -->
<div class="gateway-card card-mohadese" onclick="openLoginModal('mohadese')">
<div>
<div class="gateway-icon">⚙️</div>
<div class="gateway-card-title">محدثه معصومی</div>
<span class="badge badge-purple" style="margin-bottom: 0.75rem;">سرپرست عملیات (Master Ops)</span>
<p class="gateway-card-desc">
پنل مدیریت جامع فرآیندها؛ کنترل کامل CRUD، مدیریت جلسات، تسک‌ها، رادار مالی، سطل بازیافت و دانلود بکاپ آفلاین.
</p>
</div>
<button class="btn btn-primary" style="width: 100%; justify-content: center; background: #8b5cf6; border-color: #8b5cf6;">
ورود به پنل مستر محدثه 🔒
</button>
</div>
<!-- Card 3: Team Intake -->
<div class="gateway-card card-team" onclick="openGuestTeamPortal()">
<div>
<div class="gateway-icon">📥</div>
<div class="gateway-card-title">ثبت تسک‌های نیاز به تایید</div>
<span class="badge badge-green" style="margin-bottom: 0.75rem;">پرتال اعضای تیم (ورودی امن)</span>
<p class="gateway-card-desc">
ارسال مستقیم درخواست تاییدیه یا موضوع کاری به کارتابل حامد فلاحی؛ بدون نیاز به رمز و بدون دسترسی به سایر اطلاعات سیستم.
</p>
</div>
<button class="btn btn-success" style="width: 100%; justify-content: center;">
ورود به فرم ثبت درخواست 🚀
</button>
</div>
</div>
</section>
<!-- ==================== 2. HAMED VIEW ==================== -->
<section id="viewHamed" style="display: none;">
<!-- Welcome Banner -->
<div style="background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1)); border: 1px solid rgba(59, 130, 246, 0.3); border-radius: var(--radius-md); padding: 1.25rem 1.5rem; margin-bottom: 1.5rem; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem;">
<div>
<h2 style="font-size: 1.25rem; margin-bottom: 0.3rem;">درود حامد عزیز؛ میز کار تصمیم‌گیری و برنامه‌ریزی</h2>
<p style="color: var(--text-muted); font-size: 0.85rem;">این نما برای حفظ تمرکز شما بر اولویت‌های اجرایی، جلسات، بدهی‌ها و اسناد کلیدی بهینه‌سازی شده است.</p>
</div>
<div style="display: flex; gap: 0.5rem;">
<button class="btn btn-sm btn-primary" onclick="exportFullBackup()">📥 دانلود بکاپ آفلاین</button>
<button class="btn btn-sm btn-danger" onclick="logout()">خروج از حساب</button>
</div>
</div>
<!-- KPI Ribbon -->
<div class="grid-3" style="margin-bottom: 1.5rem;">
<div class="card" style="padding: 1rem;">
<div style="font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.3rem;">
⚡ تاییدیه‌های فوری معطل اقدام شما
<i class="info-icon" data-tooltip="نحوه محاسبه: شمارش درخواست‌های تیم با وضعیت pending و اولویت‌های P0/P1 که نیازمند تصمیم فوری حامد هستند.">ⓘ</i>
</div>
<div style="font-size: 1.8rem; font-weight: 800; color: var(--accent-rose);" id="kpiHamedApprovals">0</div>
</div>
<div class="card" style="padding: 1rem;">
<div style="font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.3rem;">
📅 جلسات زمان‌بندی‌شده امروز
<i class="info-icon" data-tooltip="نحوه محاسبه: تعداد جلسات آنلاین، حضوری دفتر و خارج از دفتر ثبت‌شده برای تاریخ روز جاری با احتساب بافرها.">ⓘ</i>
</div>
<div style="font-size: 1.8rem; font-weight: 800; color: var(--primary);" id="kpiHamedMeetings">0</div>
</div>
<div class="card" style="padding: 1rem;">
<div style="font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.3rem;">
💳 اقساط و چک‌های در انتظار پرداخت
<i class="info-icon" data-tooltip="نحوه محاسبه: مجموع تعهدات مالی دارای وضعیت pending که هنوز تسویه نشده‌اند.">ⓘ</i>
</div>
<div style="font-size: 1.8rem; font-weight: 800; color: var(--accent-amber);" id="kpiHamedFinance">0</div>
</div>
</div>
<!-- Hamed Tab: Today Focus -->
<div id="hamedTabToday" class="hamed-tab-content">
<div class="grid-2">
<!-- Approvals Queue -->
<div class="card">
<div class="card-header">
<div class="card-title">
⚡ کارتابل تاییدیه فوری حامد
<i class="info-icon" data-tooltip="درخواست‌های ارسالی همکاران؛ با یک کلیک تایید یا رد کنید.">ⓘ</i>
</div>
<span class="badge badge-rose">نیاز به تصمیم</span>
</div>
<div id="hamedApprovalsList" style="display: flex; flex-direction: column; gap: 0.75rem;"></div>
</div>
<!-- Today Meetings -->
<div class="card">
<div class="card-header">
<div class="card-title">
📅 جلسات امروز و دسترسی سریع
<i class="info-icon" data-tooltip="تفکیک ۳ گانه: آنلاین با لینک میت، حضوری خارج از دفتر با بافر تردد نشان، و حضوری در دفتر اکیپا بدون تردد حامد.">ⓘ</i>
</div>
<span class="badge badge-primary">برنامه امروز</span>
</div>
<div id="hamedMeetingsList" style="display: flex; flex-direction: column; gap: 0.75rem;"></div>
</div>
</div>
</div>
<!-- Hamed Tab: Detailed Finance -->
<div id="hamedTabFinance" class="hamed-tab-content" style="display: none;">
<!-- Smart Finance KPI Summary for Hamed -->
<div class="kpi-grid" style="margin-bottom: 1rem;">
<div class="kpi-card">
<div class="kpi-header">
<span class="kpi-label">مجموع تعهدات در انتظار پرداخت <i class="info-icon" data-tooltip="فرمول محاسبه: جمع ریالی تمام رکوردهای مالی با وضعیت pending بدون در نظر گرفتن تفکیک نهاد.">ⓘ</i></span>
<span class="badge badge-amber" id="statHamedFinPendingCount">۰ مورد</span>
</div>
<div class="kpi-value" id="statHamedFinPending" style="color: #fbbf24; font-size: 1.45rem;">۰ تومان</div>
<div class="kpi-subtext">تسهیلات و چک‌های جاری نیازمند تامین نقدینگی</div>
</div>
<div class="kpi-card">
<div class="kpi-header">
<span class="kpi-label">تعهدات فوری (۷ روز آینده) <i class="info-icon" data-tooltip="فرمول محاسبه: جمع مبالغ اقساط pending که روزشمار کمتر از ۷ روز دارند یا برچسب فوری دارند.">ⓘ</i></span>
<span class="badge badge-rose" id="statHamedFinUrgentCount">۰ مورد</span>
</div>
<div class="kpi-value" id="statHamedFinUrgent" style="color: #f87171; font-size: 1.45rem;">۰ تومان</div>
<div class="kpi-subtext">سررسیدهای بحرانی با اولویت واریز آنی</div>
</div>
<div class="kpi-card">
<div class="kpi-header">
<span class="kpi-label">تسویه‌شده‌های این دوره <i class="info-icon" data-tooltip="فرمول محاسبه: جمع مبالغ رکوردهای مالی دارای وضعیت paid (پرداخت شده قطعی).">ⓘ</i></span>
<span class="badge badge-green" id="statHamedFinPaidCount">۰ مورد</span>
</div>
<div class="kpi-value" id="statHamedFinPaid" style="color: #34d399; font-size: 1.45rem;">۰ تومان</div>
<div class="kpi-subtext">مبالغ پرداخت‌شده با وضعیت قطعی</div>
</div>
</div>
<div class="card">
<div class="card-header" style="flex-wrap: wrap; gap: 0.75rem;">
<div class="card-title">
💳 جزئیات سررسید اقساط، چک‌ها و تعهدات مالی
<i class="info-icon" data-tooltip="فهرست تسهیلات، مبالغ به تومان، تفکیک شرکت‌ها و محاسبه هوشمند سرجمع‌ها.">ⓘ</i>
</div>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center;">
<div class="search-box" style="max-width: 270px;">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در اقساط، بانک و یادداشت..." oninput="filterHamedFinance(this.value)">
</div>
</div>
</div>
<!-- Filter chips for entity / status -->
<div style="padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-subtle); display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; background: rgba(255,255,255,0.01);">
<span style="font-size: 0.78rem; color: var(--text-muted); margin-left: 0.4rem;">فیلتر هوشمند:</span>
<button class="filter-chip active fin-filter-btn" data-filter="all" onclick="setFinanceFilter('all')">همه موارد</button>
<button class="filter-chip fin-filter-btn" data-filter="اکیپا" onclick="setFinanceFilter('اکیپا')">🏢 اکیپا</button>
<button class="filter-chip fin-filter-btn" data-filter="مایندرو" onclick="setFinanceFilter('مایندرو')">🧠 مایندرو</button>
<button class="filter-chip fin-filter-btn" data-filter="شخصی حامد" onclick="setFinanceFilter('شخصی حامد')">👤 شخصی حامد</button>
<button class="filter-chip fin-filter-btn" data-filter="pending" onclick="setFinanceFilter('pending')">⏳ فقط در انتظار</button>
<button class="filter-chip fin-filter-btn" data-filter="paid" onclick="setFinanceFilter('paid')">✅ فقط پرداخت‌شده</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>موضوع تسهیلات / تعهد</th>
<th>مجموعه</th>
<th>بانک / مرجع</th>
<th>مبلغ (تومان)</th>
<th>تاریخ سررسید</th>
<th>روزشمار باقی‌مانده</th>
<th>شماره قرارداد / یادداشت</th>
<th>وضعیت</th>
<th>اقدام</th>
</tr>
</thead>
<tbody id="tableBodyHamedFinance"></tbody>
</table>
</div>
</div>
</div>
<!-- Hamed Tab: Contacts VIP -->
<div id="hamedTabContacts" class="hamed-tab-content" style="display: none;">
<div class="card">
<div class="card-header">
<div class="card-title">
📇 دفترچه مخاطبین کلیدی و VIP
<i class="info-icon" data-tooltip="فهرست شماره تماس‌ها و آیدی‌های تلگرام همکاران، شرکا و سرمایه‌گذاران.">ⓘ</i>
</div>
<div class="search-box" style="max-width: 320px;">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجوی نام یا سازمان..." oninput="filterHamedContacts(this.value)">
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>نام و نام خانوادگی</th>
<th>دسته‌بندی</th>
<th>سازمان و سمت</th>
<th>شماره تماس</th>
<th>آیدی تلگرام</th>
<th>نکات و ترجیحات</th>
<th>ارتباط مستقیم</th>
</tr>
</thead>
<tbody id="tableBodyHamedContacts"></tbody>
</table>
</div>
</div>
</div>
<!-- Hamed Tab: Vault Drive -->
<div id="hamedTabVault" class="hamed-tab-content" style="display: none;">
<div class="card">
<div class="card-header">
<div class="card-title">
📁 آرشیو اسناد و پوشه‌های گوگل درایو
<i class="info-icon" data-tooltip="دسترسی سریع و مستقیم به فولدرهای حقوقی، مالی، مدارک هویتی و قراردادها.">ⓘ</i>
</div>
<div class="search-box" style="max-width: 280px;">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در اسناد و درایو..." oninput="filterHamedVault(this.value)">
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان پوشه یا سند</th>
<th>دسته‌بندی</th>
<th>سطح محرمانگی</th>
<th>توضیحات و محتویات</th>
<th>لینک مستقیم</th>
</tr>
</thead>
<tbody id="tableBodyHamedVault"></tbody>
</table>
</div>
</div>
</div>
</section>
<!-- ==================== 3. MOHADESE MASTER VIEW ==================== -->
<section id="viewMaster" style="display: none;">
<!-- Sub Tab: Approvals -->
<div id="tabContentApprovals" class="master-tab-content">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در تاییدیه‌ها..." oninput="filterData('approvals', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openNewModal('approval')">+ تاییدیه جدید برای حامد</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان تصمیم / درخواست</th>
<th>درخواست‌کننده</th>
<th>فوریت</th>
<th>پیشنهاد / توضیحات</th>
<th>پیوست</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyApprovals"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Meetings -->
<div id="tabContentMeetings" class="master-tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در جلسات..." oninput="filterData('meetings', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openNewModal('meeting')">+ ثبت جلسه جدید</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان جلسه</th>
<th>نوع جلسه</th>
<th>تاریخ و ساعت</th>
<th>طرفین جلسه</th>
<th>بافر تردد / اتاق و پذیرایی</th>
<th>لینک میت / لوکیشن</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyMeetings"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Tasks -->
<div id="tabContentTasks" class="master-tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در تسک‌ها..." oninput="filterData('tasks', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openNewModal('task')">+ افزودن تسک اجرایی</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان تسک</th>
<th>مسئول</th>
<th>دسته</th>
<th>اولویت</th>
<th>مهلت تحویل</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyTasks"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Finance -->
<div id="tabContentFinance" class="master-tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در تسهیلات و اقساط..." oninput="filterData('finance', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openNewModal('finance')">+ ثبت تسهیلات یا قسط</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>موضوع تسهیلات / قسط</th>
<th>مجموعه</th>
<th>بانک / مرجع</th>
<th>مبلغ (تومان)</th>
<th>تاریخ سررسید</th>
<th>شماره قرارداد / یادداشت</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyFinance"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Contacts -->
<div id="tabContentContacts" class="master-tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در مخاطبین..." oninput="filterData('contacts', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openNewModal('contact')">+ افزودن مخاطب VIP</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>نام و نام خانوادگی</th>
<th>دسته‌بندی</th>
<th>سازمان و سمت</th>
<th>شماره تماس</th>
<th>آیدی تلگرام</th>
<th>نکات و ترجیحات</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyContacts"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Vault -->
<div id="tabContentVault" class="master-tab-content" style="display: none;">
<div class="action-bar">
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در اسناد و درایو..." oninput="filterData('vault', this.value)">
</div>
<button class="btn btn-primary btn-sm" onclick="openNewModal('vault')">+ افزودن سند یا لینک درایو</button>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>عنوان سند یا فولدر</th>
<th>دسته‌بندی</th>
<th>لینک درایو / دسترسی</th>
<th>سطح محرمانگی</th>
<th>توضیحات</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyVault"></tbody>
</table>
</div>
</div>
<!-- Sub Tab: Recycle Bin -->
<div id="tabContentRecycle" class="master-tab-content" style="display: none;">
<div class="action-bar">
<div style="display: flex; gap: 0.5rem; align-items: center;">
<button class="btn btn-primary btn-sm" onclick="exportFullBackup()">📥 دانلود بکاپ جامع (JSON)</button>
<button class="btn btn-sm" onclick="restoreFromBackupFile()">📤 بازیابی از فایل بکاپ</button>
</div>
<div class="search-box">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" placeholder="جستجو در سطل بازیافت..." oninput="filterData('recycle', this.value)">
</div>
</div>
<div class="card" style="margin-bottom: 1rem;">
<div style="font-size: 0.85rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.5rem;">
🛡️ <strong>قانون عدم ابطال اطلاعات:</strong> تمامی داده‌های حذف‌شده از همه بخش‌ها به این سطل منتقل می‌شوند و تاریخ دقیق حذف ثبت می‌گردد. با دکمه «بازیابی» در هر زمان قابل بازگرداندن هستند.
</div>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>نوع آیتم</th>
<th>عنوان / محتوا</th>
<th>تاریخ حذف</th>
<th>جزئیات داده قبلی</th>
<th>عملیات</th>
</tr>
</thead>
<tbody id="tableBodyRecycle"></tbody>
</table>
</div>
</div>
</section>
<!-- ==================== 4. ISOLATED TEAM INTAKE PORTAL ==================== -->
<section id="viewTeamGuest" style="display: none;">
<div style="max-width: 640px; margin: 1.5rem auto;">
<div style="display: flex; justify-content: flex-end; margin-bottom: 1rem;">
<button class="btn btn-sm" onclick="logout()">
بازگشت به صفحه اصلی ↩️
</button>
</div>
<!-- Success Box with Tracking Code -->
<div id="tgSuccessBox" style="display: none; background: rgba(16, 185, 129, 0.08); border: 1px solid rgba(16, 185, 129, 0.3); border-radius: var(--radius-sm); padding: 1.5rem; text-align: center; margin-bottom: 1.25rem;">
<div style="font-size: 2.2rem; margin-bottom: 0.5rem;">✅</div>
<div style="font-weight: 700; font-size: 1.1rem; color: #34d399; margin-bottom: 0.5rem;">درخواست شما با موفقیت در کارتابل حامد فلاحی ثبت گردید.</div>
<div style="font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.75rem;">
کد پیگیری اختصاصی:
<strong id="tgTrackingCodeDisplay" style="color: #60a5fa; font-size: 1.2rem; letter-spacing: 1px; font-feature-settings: 'tnum' 0; background: rgba(59, 130, 246, 0.15); padding: 0.2rem 0.6rem; border-radius: 6px;">EKP-0000</strong>
</div>
<p style="font-size: 0.82rem; color: var(--text-faint); margin-bottom: 1.25rem; line-height: 1.6;">
این مورد در صف تصمیم‌گیری مدیریت اجرایی قرار گرفت. پیگیری وضعیت از طریق سرکار خانم معصومی با ارائه این کد امکان‌پذیر است.
</p>
<button type="button" class="btn btn-primary" onclick="resetTeamPortal()">
➕ ثبت یک درخواست جدید
</button>
</div>
<div class="card" id="tgCardForm">
<div class="card-header">
<div class="card-title">
📥 پرتال ثبت تسک‌های نیاز به تایید
<i class="info-icon" data-tooltip="فرم ایزوله جهت ثبت درخواست تاییدیه یا موضوع کاری در کارتابل حامد فلاحی.">ⓘ</i>
</div>
<span class="badge badge-green">ورودی امن همکاران</span>
</div>
<form id="teamGuestForm" onsubmit="handleTeamGuestSubmit(event)">
<div class="form-group">
<label class="form-label">نام و سمت سازمانی شما *</label>
<input type="text" class="form-control" id="tgRequester" required placeholder="مثال: سارا محمدی - مدیر محصول">
</div>
<div class="form-group">
<label class="form-label">موضوع درخواست یا تصمیم نیازمند تایید *</label>
<input type="text" class="form-control" id="tgTitle" required placeholder="مثال: تایید قرارداد تامین‌کننده جدید یا پرداخت فاکتور سرور">
</div>
<div class="form-group">
<label class="form-label">درجه فوریت *</label>
<select class="form-control" id="tgPriority">
<option value="P0">⚡ P0 - فوری (کار متوقف است)</option>
<option value="P1" selected>⏳ P1 - مهم (تا ۲۴ ساعت آینده)</option>
<option value="P2">🟢 P2 - عادی (تا پایان هفته)</option>
</select>
</div>
<div class="form-group">
<label class="form-label">توضیح کوتاه و پیشنهاد شما *</label>
<textarea class="form-control" id="tgDescription" required placeholder="شرح مختصر دلیل، مبلغ احتمالی و پیشنهاد اجرایی خود را بنویسید..."></textarea>
</div>
<div class="form-group">
<label class="form-label">لینک سند یا فایل ضمیمه (در صورت وجود)</label>
<input type="text" class="form-control" id="tgLink" placeholder="https://docs.google.com/...">
</div>
<button type="submit" id="tgSubmitBtn" class="btn btn-primary" style="width: 100%; justify-content: center; padding: 0.75rem;">
🚀 ثبت قطعی در کارتابل حامد فلاحی
</button>
</form>
</div>
</div>
</section>
</main>
<!-- Modal Reject Approval Feedback -->
<div class="modal-overlay" id="modalRejectApproval" style="display: none;">
<div class="modal-content" style="max-width: 480px;">
<div class="modal-header">
<div class="modal-title" style="color: #fb7185;">❌ ثبت بازخورد و علت رد تاییدیه</div>
<button class="modal-close" onclick="closeModal('modalRejectApproval')">&times;</button>
</div>
<form id="formRejectApproval" onsubmit="submitRejectionFeedback(event)">
<input type="hidden" id="rejectApprovalId">
<div class="form-group">
<label class="form-label">موضوع تاییدیه</label>
<div id="rejectApprovalTitle" style="font-weight: 700; color: var(--text-main); margin-bottom: 0.5rem; background: var(--bg-surface); padding: 0.6rem; border-radius: 6px; font-size: 0.88rem;"></div>
</div>
<div class="form-group">
<label class="form-label">علت رد، اصلاحات مورد نیاز یا نکات حامد فلاحی *</label>
<textarea class="form-control" id="rejectFeedbackInput" rows="3" required placeholder="مثال: هزینه برآورد بالا است، لطفاً از دو تامین‌کننده دیگر استعلام بگیرید یا زمان اجرا موکول شود..."></textarea>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalRejectApproval')">انصراف</button>
<button type="submit" class="btn btn-danger">ثبت رد همراه با بازخورد</button>
</div>
</form>
</div>
</div>
<!-- Login Modal -->
<div class="modal-overlay" id="modalLogin">
<div class="modal-content" style="max-width: 420px;">
<div class="modal-header">
<div class="modal-title" id="loginModalTitle">ورود امن</div>
<button class="modal-close" onclick="closeModal('modalLogin')">&times;</button>
</div>
<form onsubmit="handleLoginSubmit(event)">
<input type="hidden" id="loginTargetUser">
<div class="form-group">
<label class="form-label">نام کاربری</label>
<input type="text" class="form-control" id="loginUsername" required autocomplete="username">
</div>
<div class="form-group">
<label class="form-label">رمز عبور</label>
<input type="password" class="form-control" id="loginPassword" required autocomplete="current-password">
</div>
<div id="loginError" style="color: var(--accent-rose); font-size: 0.8rem; margin-bottom: 0.75rem; display: none;"></div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalLogin')">انصراف</button>
<button type="submit" class="btn btn-primary">تایید و ورود 🔑</button>
</div>
</form>
</div>
</div>
<!-- CRUD Modals for Master Operations -->
<!-- 1. Modal Approval -->
<div class="modal-overlay" id="modalApproval">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalApprovalTitle">ثبت تاییدیه جدید برای حامد</div>
<button class="modal-close" onclick="closeModal('modalApproval')">&times;</button>
</div>
<form id="formApproval" onsubmit="saveMasterItem(event, 'approvals')">
<input type="hidden" id="approvalId">
<div class="form-group">
<label class="form-label">عنوان تصمیم / درخواست *</label>
<input type="text" class="form-control" id="approvalTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">درخواست‌کننده *</label>
<input type="text" class="form-control" id="approvalRequesterInput" required>
</div>
<div class="form-group">
<label class="form-label">فوریت</label>
<select class="form-control" id="approvalPriorityInput">
<option value="P0">P0 - فوری</option>
<option value="P1" selected>P1 - مهم</option>
<option value="P2">P2 - عادی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">پیشنهاد / توضیحات *</label>
<textarea class="form-control" id="approvalDescriptionInput" required></textarea>
</div>
<div class="form-group">
<label class="form-label">لینک پیوست</label>
<input type="url" class="form-control" id="approvalLinkInput">
</div>
<div class="form-group">
<label class="form-label">وضعیت</label>
<select class="form-control" id="approvalStatusInput">
<option value="pending">در انتظار تایید حامد</option>
<option value="approved">تایید شده ✅</option>
<option value="rejected">رد شده / نیاز به اصلاح ❌</option>
</select>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalApproval')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره تاییدیه</button>
</div>
</form>
</div>
</div>
<!-- 2. Modal Meeting -->
<div class="modal-overlay" id="modalMeeting">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalMeetingTitle">ثبت جلسه جدید</div>
<button class="modal-close" onclick="closeModal('modalMeeting')">&times;</button>
</div>
<form id="formMeeting" onsubmit="saveMasterItem(event, 'meetings')">
<input type="hidden" id="meetingId">
<div class="form-group">
<label class="form-label">عنوان جلسه *</label>
<input type="text" class="form-control" id="meetingTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">نوع جلسه *</label>
<select class="form-control" id="meetingTypeInput" onchange="handleMeetingTypeChange()">
<option value="online">💻 آنلاین (گوگل‌میت / ادوبی)</option>
<option value="in_person_external">🚗 حضوری خارج از دفتر (همراه با تردد و بافر ترافیک)</option>
<option value="in_person_office">🏢 حضوری در دفتر اکیپا (بدون تردد حامد / میزبانی مهمان)</option>
</select>
</div>
<div class="form-group">
<label class="form-label">تاریخ و ساعت *</label>
<input type="text" class="form-control" id="meetingTimeInput" required>
</div>
<div class="form-group">
<label class="form-label">افراد حاضر و طرفین جلسه</label>
<input type="text" class="form-control" id="meetingAttendeesInput" placeholder="مثال: حامد فلاحی، آقای احمدی (مهمان)">
</div>
<div class="form-group" id="meetingBufferGroup">
<label class="form-label" id="meetingBufferLabel">بافر ترافیک / هماهنگی اتاق و پذیرایی</label>
<input type="text" class="form-control" id="meetingBufferInput" placeholder="مثال: خروج ساعت ۱۴:۱۵ یا رزرو اتاق اصلی">
</div>
<div class="form-group" id="meetingLinkGroup">
<label class="form-label" id="meetingLinkLabel">لینک میت / لوکیشن نشان / اتاق دفتر</label>
<input type="text" class="form-control" id="meetingLinkInput" placeholder="لینک آنلاین یا نشان">
</div>
<div class="form-group">
<label class="form-label">یادداشت پیش از جلسه، دستور کار و فایل‌ها</label>
<textarea class="form-control" id="meetingNotesInput"></textarea>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalMeeting')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره جلسه</button>
</div>
</form>
</div>
</div>
<!-- 3. Modal Task -->
<div class="modal-overlay" id="modalTask">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalTaskTitle">ثبت تسک اجرایی جدید</div>
<button class="modal-close" onclick="closeModal('modalTask')">&times;</button>
</div>
<form id="formTask" onsubmit="saveMasterItem(event, 'tasks')">
<input type="hidden" id="taskId">
<div class="form-group">
<label class="form-label">عنوان تسک *</label>
<input type="text" class="form-control" id="taskTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">مسئول انجام</label>
<input type="text" class="form-control" id="taskAssigneeInput">
</div>
<div class="form-group">
<label class="form-label">دسته‌بندی</label>
<select class="form-control" id="taskCategoryInput">
<option value="اکیپا">اکیپا</option>
<option value="مایندرو">مایندرو</option>
<option value="مالی و وام">مالی و وام</option>
<option value="حقوقی و ثنا">حقوقی و ثنا</option>
<option value="شخصی">شخصی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">اولویت</label>
<select class="form-control" id="taskPriorityInput">
<option value="P0">P0 - بحرانی</option>
<option value="P1" selected>P1 - بالا</option>
<option value="P2">P2 - عادی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">مهلت تحویل (ددلاین)</label>
<input type="text" class="form-control" id="taskDeadlineInput">
</div>
<div class="form-group">
<label class="form-label">وضعیت</label>
<select class="form-control" id="taskStatusInput">
<option value="todo">در صف انجام</option>
<option value="in_progress">در حال اقدام</option>
<option value="waiting_approval">منتظر تایید حامد</option>
<option value="done">تکمیل شده</option>
</select>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalTask')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره تسک</button>
</div>
</form>
</div>
</div>
<!-- 4. Modal Finance -->
<div class="modal-overlay" id="modalFinance">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalFinanceTitle">ثبت موعد قسط یا تسهیلات</div>
<button class="modal-close" onclick="closeModal('modalFinance')">&times;</button>
</div>
<form id="formFinance" onsubmit="saveMasterItem(event, 'finance')">
<input type="hidden" id="financeId">
<div class="form-group">
<label class="form-label">موضوع قسط یا واریزی *</label>
<input type="text" class="form-control" id="financeTitleInput" required placeholder="مثال: قسط تسهیلات دیجی‌شهر">
</div>
<div class="form-group">
<label class="form-label">مجموعه / تگ سازمان *</label>
<select class="form-control" id="financeEntityInput">
<option value="اکیپا">🏢 اکیپا</option>
<option value="مایندرو">🧠 مایندرو</option>
<option value="شخصی حامد">👤 شخصی حامد</option>
</select>
</div>
<div class="form-group">
<label class="form-label">بانک یا مرجع پرداخت</label>
<input type="text" class="form-control" id="financeBankInput" placeholder="مثال: بانک شهر / بلوبانک / دیجی‌پی">
</div>
<div class="form-group">
<label class="form-label">مبلغ (تومان) *</label>
<input type="text" class="form-control" id="financeAmountInput" required placeholder="مثال: ۱۴,۸۰۰,۰۰۰ یا 14800000">
</div>
<div class="form-group">
<label class="form-label">تاریخ دقیق سررسید *</label>
<input type="text" class="form-control" id="financeDueDateInput" required placeholder="مثال: ۲۸ آبان ماه یا ۱۴۰۳/۰۸/۲۸">
</div>
<div class="form-group">
<label class="form-label">روزشمار / موعد باقی‌مانده</label>
<input type="text" class="form-control" id="financeDaysLeftInput" placeholder="مثال: ۳ روز مانده یا فوری">
</div>
<div class="form-group">
<label class="form-label">شماره تسهیلات / شبا یا یادداشت</label>
<input type="text" class="form-control" id="financeNotesInput" placeholder="تسهیلات شماره ۴۸۸۹۲...">
</div>
<div class="form-group">
<label class="form-label">وضعیت پرداخت</label>
<select class="form-control" id="financeStatusInput">
<option value="pending">در انتظار پرداخت ⏳</option>
<option value="paid">پرداخت شده ✅</option>
<option value="overdue">معوق / اخطار ⚠️</option>
</select>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalFinance')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره رکورد مالی</button>
</div>
</form>
</div>
</div>
<!-- 5. Modal Contact -->
<div class="modal-overlay" id="modalContact">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalContactTitle">ثبت مخاطب کلیدی VIP</div>
<button class="modal-close" onclick="closeModal('modalContact')">&times;</button>
</div>
<form id="formContact" onsubmit="saveMasterItem(event, 'contacts')">
<input type="hidden" id="contactId">
<div class="form-group">
<label class="form-label">نام و نام خانوادگی *</label>
<input type="text" class="form-control" id="contactNameInput" required>
</div>
<div class="form-group">
<label class="form-label">دسته‌بندی</label>
<select class="form-control" id="contactCategoryInput">
<option value="اکیپا">اکیپا</option>
<option value="مایندرو">مایندرو</option>
<option value="سرمایه‌گذار و استراتژیک">سرمایه‌گذار و استراتژیک</option>
<option value="بانکی و حقوقی">بانکی و حقوقی</option>
<option value="شخصی">شخصی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">سازمان و سمت</label>
<input type="text" class="form-control" id="contactRoleInput">
</div>
<div class="form-group">
<label class="form-label">شماره همراه *</label>
<input type="text" class="form-control" id="contactPhoneInput" required>
</div>
<div class="form-group">
<label class="form-label">آیدی تلگرام / واتس‌اپ</label>
<input type="text" class="form-control" id="contactSocialInput">
</div>
<div class="form-group">
<label class="form-label">ترجیحات، سوابق و نکات حساسیت</label>
<textarea class="form-control" id="contactNotesInput"></textarea>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalContact')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره مخاطب</button>
</div>
</form>
</div>
</div>
<!-- 6. Modal Vault -->
<div class="modal-overlay" id="modalVault">
<div class="modal-content">
<div class="modal-header">
<div class="modal-title" id="modalVaultTitle">ثبت سند یا پوشه درایو</div>
<button class="modal-close" onclick="closeModal('modalVault')">&times;</button>
</div>
<form id="formVault" onsubmit="saveMasterItem(event, 'vault')">
<input type="hidden" id="vaultId">
<div class="form-group">
<label class="form-label">عنوان پوشه یا سند *</label>
<input type="text" class="form-control" id="vaultTitleInput" required>
</div>
<div class="form-group">
<label class="form-label">دسته‌بندی</label>
<select class="form-control" id="vaultCategoryInput">
<option value="اسناد حقوقی و ثنا">اسناد حقوقی و ثنا</option>
<option value="مدارک هویتی شرکت و حامد">مدارک هویتی شرکت و حامد</option>
<option value="قراردادها و NDA">قراردادها و NDA</option>
<option value="امور شعب و مایندرو">امور شعب و مایندرو</option>
<option value="مالی و وام‌ها">مالی و وام‌ها</option>
</select>
</div>
<div class="form-group">
<label class="form-label">لینک دسترسی گوگل درایو *</label>
<input type="url" class="form-control" id="vaultLinkInput" required>
</div>
<div class="form-group">
<label class="form-label">سطح محرمانگی</label>
<select class="form-control" id="vaultSecInput">
<option value="محرمانه (فقط حامد و محدثه)">محرمانه (فقط حامد و محدثه)</option>
<option value="تیم داخلی">تیم داخلی</option>
<option value="عمومی">عمومی</option>
</select>
</div>
<div class="form-group">
<label class="form-label">توضیحات و محتویات</label>
<textarea class="form-control" id="vaultDescInput"></textarea>
</div>
<div style="display: flex; gap: 0.5rem; justify-content: flex-end;">
<button type="button" class="btn" onclick="closeModal('modalVault')">انصراف</button>
<button type="submit" class="btn btn-primary">ذخیره سند</button>
</div>
</form>
</div>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<!-- Footer with Data Provenance -->
<footer>
<div class="footer-inner">
<div>
<span>🟢 <strong>اصالت داده (Data Provenance):</strong> متصل مستقیم به PostgreSQL 17</span>
<span style="margin: 0 0.5rem;">|</span>
<span>جدول: <code>ekeepa_bi.dashboard_app_storage</code></span>
<span style="margin: 0 0.5rem;">|</span>
<span>کلید دیتابیس: <code>exec_cockpit_state</code></span>
</div>
<div>
<span>سیستم حفاظت از داده‌ها: سطل بازیافت فعال (Soft-Delete & Full Audit Log)</span>
</div>
</div>
</footer>
<!-- Application Logic -->
<script>
// Initial Seed Data
const defaultData = {
approvals: [
{
id: "app_1",
title: "تایید قرارداد NDA با شریک راهبردی باغ کتاب",
requester: "صالح اسکندرزاده (حقوقی)",
priority: "P0",
description: "بند عدم رقابت به ۳ سال تقلیل یافت؛ در صورت موافقت تایید کنید تا نسخه نهایی پرینت شود.",
link: "https://drive.google.com",
status: "pending",
createdAt: "۱۴۰۴/۰۸/۲۲"
},
{
id: "app_2",
title: "تخصیص بودجه ادز بلک‌فرایدی اکیپا",
requester: "الهه فلاحی (مارکتینگ)",
priority: "P1",
description: "برآورد ۳۵ میلیون تومان برای کمپین ریتارگتینگ؛ پیش‌بینی ROI ۳.۴ برابری.",
link: "https://drive.google.com",
status: "pending",
createdAt: "۱۴۰۴/۰۸/۲۲"
}
],
meetings: [
{
id: "meet_1",
title: "جلسه هماهنگی بازاریابی و پکیج‌های جدید مایندرو",
type: "online",
time: "امروز ۱۰:۳۰ تا ۱۱:۳۰",
attendees: "حامد، سارا محمودزاده، غزاله مددی",
buffer: "آنلاین (بدون بافر تردد)",
link: "https://meet.google.com/abc-defg-hij",
notes: "بررسی قیمت‌گذاری سانس‌های آخر هفته نیایش مال و بازی چهارم"
},
{
id: "meet_2",
title: "جلسه حضوری با مدیران باغ کتاب تهران",
type: "in_person_external",
time: "امروز ۱۵:۰۰ تا ۱۶:۳۰",
attendees: "حامد فلاحی، خانم ارشادی",
buffer: "خروج ساعت ۱۴:۱۵ (۴۵ دقیقه بافر ترافیک همت)",
link: "https://neshan.org",
notes: "تحویل وسایل و نهایی‌سازی تسویه‌حساب تابستان؛ هماهنگی ورود با پارکینگ شماره ۱"
},
{
id: "meet_3",
title: "جلسه حضوری با سرمایه‌گذار در دفتر اکیپا",
type: "in_person_office",
time: "فردا ساعت ۱۱:۰۰",
attendees: "مهندس رضوانی (سرمایه‌گذار)",
buffer: "رزرو اتاق جلسات اصلی + پذیرایی چای و قهوه",
link: "",
notes: "بررسی شرایط تمدید و دور دوم سرمایه‌گذاری؛ بدون تردد حامد (مهمان می‌آید دفتر)"
}
],
tasks: [
{
id: "task_1",
title: "ارسال مدارک تکمیلی وام دیجی‌شهر به شعبه",
assignee: "حامد فلاحی / محدثه",
category: "مالی و وام",
priority: "P0",
deadline: "امروز ساعت ۱۴",
status: "in_progress"
},
{
id: "task_2",
title: "بررسی کارکرد و حقوق ماهانه پرسنل مایندرو با پورصمد",
assignee: "محدثه معصومی",
category: "مایندرو",
priority: "P1",
deadline: "چهارشنبه",
status: "todo"
}
],
finance: [
{
id: "fin_1",
title: "قسط تسهیلات دیجی‌شهر (حامد و آقای فلاحی)",
entity: "شخصی حامد",
bank: "بانک شهر",
amount: "14,800,000",
dueDate: "۲۸ آبان ماه",
daysLeft: "۶ روز مانده",
notes: "تسهیلات شماره ۴۸۸۹۲ - حساب بانک شهر",
status: "pending"
},
{
id: "fin_2",
title: "تسویه تنخواه هفتگی بلوبانک مایندرو",
entity: "مایندرو",
bank: "بلو بانک",
amount: "8,500,000",
dueDate: "پایان هفته",
daysLeft: "۳ روز مانده",
notes: "حساب مشترک هزینه‌های جاری شعب",
status: "pending"
},
{
id: "fin_3",
title: "قسط طرح توسعه دیجی‌پی",
entity: "اکیپا",
bank: "دیجی‌پی",
amount: "11,200,000",
dueDate: "۰۵ آذر ماه",
daysLeft: "۱۳ روز مانده",
notes: "اقساط سرورها و زیرساخت فنی",
status: "pending"
}
],
contacts: [
{
id: "cnt_1",
name: "ایمان پورصمد",
category: "مایندرو",
role: "توسعه و حسابرسی مالی",
phone: "09120000000",
social: "iman_pour",
notes: "هماهنگی روزهای سه‌شنبه و چهارشنبه؛ حساسیت روی تطابق ریالی واریزی‌ها"
},
{
id: "cnt_2",
name: "سارا محمودزاده",
category: "اکیپا",
role: "Product & Operations Lead",
phone: "09121111111",
social: "sara_m",
notes: "فیلتر اصلی مسائل محصول و تیم فنی؛ هماهنگی روتین روزانه"
},
{
id: "cnt_3",
name: "فدیا ارشادی",
category: "مایندرو",
role: "سوپروایزر باغ کتاب",
phone: "09122222222",
social: "f_ershadi",
notes: "امور هماهنگی تخلیه، تحویل تجهیزات و تسویه‌های پرسنلی"
},
{
id: "cnt_4",
name: "الهه فلاحی",
category: "اکیپا",
role: "Lead Growth & Marketing",
phone: "09123333333",
social: "elaheh_flh",
notes: "مدیریت کمپین‌ها، بودجه ادز و جذب کاربر"
}
],
vault: [
{
id: "vlt_1",
title: "پوشه مدارک هویتی، آگهی تاسیس و روزنامه رسمی",
category: "مدارک هویتی شرکت و حامد",
link: "https://drive.google.com",
sec: "محرمانه (فقط حامد و محدثه)",
desc: "شناسنامه‌ها، کارت‌های ملی، نمونه امضاها و آخرین آگهی تغییرات هلدینگ"
},
{
id: "vlt_2",
title: "قراردادهای شعب نیایش و باغ کتاب مایندرو",
category: "امور شعب و مایندرو",
link: "https://drive.google.com",
sec: "محرمانه (فقط حامد و محدثه)",
desc: "اجاره‌نامه‌ها، الحاقیه‌ها و نسخه‌های اسکن‌شده امضاشده"
},
{
id: "vlt_3",
title: "پرونده وام‌ها و معرفی‌نامه‌های بانکی",
category: "مالی و وام‌ها",
link: "https://drive.google.com",
sec: "محرمانه (فقط حامد و محدثه)",
desc: "مدارک دیجی‌شهر، دیجی‌پی و مکاتبات بانک شهر"
}
],
recycle: []
};
let appState = JSON.parse(JSON.stringify(defaultData));
let currentUser = null; // 'hamed' | 'mohadese' | 'team_guest' | null
let currentMasterTab = 'approvals';
let currentHamedTab = 'today';
let saveTimeout = null;
let activeFinanceFilter = 'all';
let queryFinanceHamed = '';
let queryVaultHamed = '';
// Smart Helpers
function parseAmount(val) {
if (!val) return 0;
const clean = String(val).replace(/[^0-9]/g, '');
return parseInt(clean, 10) || 0;
}
function normalizeUrl(url) {
if (!url) return '';
url = url.trim();
if (!url) return '';
if (!/^https?:\/\//i.test(url)) {
return 'https://' + url;
}
return url;
}
function resetTeamPortal() {
const box = document.getElementById('tgSuccessBox');
const card = document.getElementById('tgCardForm');
if (box) box.style.display = 'none';
if (card) card.style.display = 'block';
const form = document.getElementById('teamGuestForm');
if (form) form.reset();
}
function copyMeetingInvite(id) {
const m = appState.meetings.find(x => x.id === id);
if (!m) return;
const inviteText = `با سلام و احترام
جلسه حضوری شما با جناب آقای حامد فلاحی به شرح زیر هماهنگ گردید:
📌 موضوع جلسه: ${m.title}
⏰ زمان: ${m.time}
🏢 مکان: تهران، دفتر مرکزی اکیپا
👥 طرفین جلسه: ${m.attendees || 'جناب‌عالی و حامد فلاحی'}
${m.buffer ? `☕ تمهیدات: ${m.buffer}\n` : ''}
📍 لوکیشن در نشان: https://neshan.org
(در بدو ورود به ساختمان، جهت راهنمایی به اتاق جلسات با واحد پذیرش هماهنگ بفرمایید)
با احترام،
دفتر مدیریت اجرایی اکیپا`;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(inviteText).then(() => {
showToast('📋 متن رسمی دعوت مهمان در کلیپ‌بورد کپی شد.');
}).catch(() => {
prompt('متن دعوت مهمان (Ctrl+C را بزنید):', inviteText);
});
} else {
prompt('متن دعوت مهمان (Ctrl+C را بزنید):', inviteText);
}
}
function convertApprovalToTask(id) {
const appr = appState.approvals.find(a => a.id === id);
if (!appr) return;
const newTask = {
id: 'task_' + Date.now(),
title: 'پیگیری مصوبه: ' + appr.title,
assignee: 'محدثه معصومی',
category: 'عملیات',
priority: appr.priority || 'P1',
deadline: 'ظرف ۴۸ ساعت',
status: 'todo',
notes: `ارجاع از تاییدیه حامد فلاحی. متقاضی اولیه: ${appr.requester}. ${appr.link ? 'پیوست: ' + appr.link : ''}`
};
if (!appState.tasks) appState.tasks = [];
appState.tasks.unshift(newTask);
appr.convertedToTask = true;
showToast('⚡ تاییدیه با موفقیت به تسک اجرایی محدثه تبدیل شد.');
triggerStateChange();
}
function openRejectModal(id) {
const appr = appState.approvals.find(a => a.id === id);
if (!appr) return;
document.getElementById('rejectApprovalId').value = id;
document.getElementById('rejectApprovalTitle').innerText = appr.title + ' (متقاضی: ' + appr.requester + ')';
document.getElementById('rejectFeedbackInput').value = appr.feedback || '';
openModal('modalRejectApproval');
}
function submitRejectionFeedback(e) {
e.preventDefault();
const id = document.getElementById('rejectApprovalId').value;
const feedback = document.getElementById('rejectFeedbackInput').value.trim();
const appr = appState.approvals.find(a => a.id === id);
if (appr) {
appr.status = 'rejected';
appr.feedback = feedback;
appr.rejectedAt = new Date().toLocaleDateString('fa-IR');
closeModal('modalRejectApproval');
showToast('❌ تاییدیه همراه با بازخورد اصلاحی ثبت گردید.');
triggerStateChange();
}
}
function setFinanceFilter(filterVal) {
activeFinanceFilter = filterVal;
document.querySelectorAll('.fin-filter-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.filter === filterVal);
});
renderHamedFinanceTable();
}
function filterHamedFinance(query) {
queryFinanceHamed = query.trim().toLowerCase();
renderHamedFinanceTable();
}
function filterHamedVault(query) {
queryVaultHamed = query.trim().toLowerCase();
renderHamedVaultTable();
}
function updateFinanceSummaryStats() {
if (!appState || !appState.finance) return;
const pendingItems = appState.finance.filter(f => f.status === 'pending');
const paidItems = appState.finance.filter(f => f.status === 'paid');
let totalPending = 0;
pendingItems.forEach(f => totalPending += parseAmount(f.amount));
let totalPaid = 0;
paidItems.forEach(f => totalPaid += parseAmount(f.amount));
const urgentItems = pendingItems.filter(f => {
const d = f.daysLeft || '';
return d.includes('۱') || d.includes('۲') || d.includes('۳') || d.includes('۴') || d.includes('۵') || d.includes('۶') || d.includes('۷') || d.includes('فوری') || d.includes('هفته');
});
let totalUrgent = 0;
urgentItems.forEach(f => totalUrgent += parseAmount(f.amount));
const elPending = document.getElementById('statHamedFinPending');
if (elPending) elPending.innerText = totalPending.toLocaleString('fa-IR') + ' تومان';
const elUrgent = document.getElementById('statHamedFinUrgent');
if (elUrgent) elUrgent.innerText = totalUrgent.toLocaleString('fa-IR') + ' تومان';
const elPaid = document.getElementById('statHamedFinPaid');
if (elPaid) elPaid.innerText = totalPaid.toLocaleString('fa-IR') + ' تومان';
const elPendingCount = document.getElementById('statHamedFinPendingCount');
if (elPendingCount) elPendingCount.innerText = pendingItems.length + ' مورد';
const elUrgentCount = document.getElementById('statHamedFinUrgentCount');
if (elUrgentCount) elUrgentCount.innerText = urgentItems.length + ' مورد';
const elPaidCount = document.getElementById('statHamedFinPaidCount');
if (elPaidCount) elPaidCount.innerText = paidItems.length + ' مورد';
}
// Database Sync
async function loadFromPostgres() {
const syncDot = document.getElementById('syncDot');
const syncText = document.getElementById('syncText');
syncDot.className = 'sync-dot syncing';
syncText.innerText = 'در حال بازیابی اطلاعات از PostgreSQL 17...';
try {
const res = await fetch('/api/db/state?key=exec_cockpit_state');
if (res.ok) {
const json = await res.json();
if (json && json.data && typeof json.data === 'object' && json.data.approvals) {
appState = json.data;
} else {
await saveToPostgres();
}
}
} catch (err) {
console.warn('PostgreSQL fetch error, using cache:', err);
} finally {
syncDot.className = 'sync-dot';
syncText.innerText = '🟢 اصالت داده: PostgreSQL 17 زنده (/api/db/state)';
renderAll();
}
}
async function saveToPostgres() {
const syncDot = document.getElementById('syncDot');
const syncText = document.getElementById('syncText');
syncDot.className = 'sync-dot syncing';
syncText.innerText = 'در حال ذخیره‌سازی ابری...';
try {
const payload = {
state_key: 'exec_cockpit_state',
data: appState
};
const res = await fetch('/api/db/state', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (res.ok) {
syncDot.className = 'sync-dot';
syncText.innerText = '🟢 اصالت داده: PostgreSQL 17 ذخیره شد';
}
} catch (err) {
console.error('Error saving state:', err);
syncDot.className = 'sync-dot';
syncText.innerText = '⚠️ خطای ذخیره‌سازی ابری؛ کش فعال';
}
}
function triggerStateChange() {
if (saveTimeout) clearTimeout(saveTimeout);
saveTimeout = setTimeout(saveToPostgres, 400);
renderAll();
}
// Auth & Navigation
function openLoginModal(role) {
document.getElementById('loginTargetUser').value = role;
document.getElementById('loginUsername').value = (role === 'hamed') ? 'hamed' : 'mohadese';
document.getElementById('loginPassword').value = '';
document.getElementById('loginError').style.display = 'none';
document.getElementById('loginModalTitle').innerText = (role === 'hamed') ? 'ورود به میز کار حامد فلاحی' : 'ورود به پنل مستر محدثه معصومی';
openModal('modalLogin');
}
function handleLoginSubmit(e) {
e.preventDefault();
const role = document.getElementById('loginTargetUser').value;
const u = document.getElementById('loginUsername').value.trim().toLowerCase();
const p = document.getElementById('loginPassword').value.trim();
const errBox = document.getElementById('loginError');
// Accepted default credentials
const isValidHamed = (role === 'hamed') && (u === 'hamed' || u === 'hamed.fallahi') && (p === '123' || p === 'Hamed@1404');
const isValidMohadese = (role === 'mohadese') && (u === 'mohadese' || u === 'mohadese.masoumi') && (p === '123' || p === 'Mohadese@1404');
if (isValidHamed || isValidMohadese) {
closeModal('modalLogin');
currentUser = role;
try { sessionStorage.setItem('exec_cockpit_user', role); } catch (e) {}
showToast('✅ ورود موفقیت‌آمیز بود.');
updateViewVisibility();
} else {
errBox.innerText = 'نام کاربری یا رمز عبور اشتباه است. (پیش‌فرض: 123)';
errBox.style.display = 'block';
}
}
function openGuestTeamPortal() {
currentUser = 'team_guest';
updateViewVisibility();
}
function logout() {
currentUser = null;
try { sessionStorage.removeItem('exec_cockpit_user'); } catch (e) {}
updateViewVisibility();
showToast('از حساب کاربری خارج شدید.');
}
function updateViewVisibility() {
const viewGateway = document.getElementById('viewGateway');
const viewHamed = document.getElementById('viewHamed');
const viewMaster = document.getElementById('viewMaster');
const viewTeamGuest = document.getElementById('viewTeamGuest');
const masterNav = document.getElementById('masterNav');
const hamedNav = document.getElementById('hamedNav');
const userPill = document.getElementById('userPill');
const userNameLabel = document.getElementById('userNameLabel');
const topSubtitle = document.getElementById('topSubtitle');
// Hide all
viewGateway.style.display = 'none';
viewHamed.style.display = 'none';
viewMaster.style.display = 'none';
viewTeamGuest.style.display = 'none';
masterNav.style.display = 'none';
hamedNav.style.display = 'none';
userPill.style.display = 'none';
if (!currentUser) {
viewGateway.style.display = 'block';
topSubtitle.innerText = 'پورتال هماهنگی عملیات و تصمیمات راهبردی';
} else if (currentUser === 'hamed') {
viewHamed.style.display = 'block';
hamedNav.style.display = 'flex';
userPill.style.display = 'flex';
userNameLabel.innerText = '👤 حامد فلاحی';
topSubtitle.innerText = 'میز کار اختصاصی و متمرکز مدیر ارشد';
} else if (currentUser === 'mohadese') {
viewMaster.style.display = 'block';
masterNav.style.display = 'flex';
userPill.style.display = 'flex';
userNameLabel.innerText = '⚙️ محدثه معصومی (Master Ops)';
topSubtitle.innerText = 'پنل مستر سرپرست عملیات و فرآیندها';
} else if (currentUser === 'team_guest') {
viewTeamGuest.style.display = 'block';
topSubtitle.innerText = 'پرتال ثبت تسک‌های نیاز به تایید همکاران';
}
renderAll();
}
function switchMasterTab(tab) {
currentMasterTab = tab;
document.querySelectorAll('#masterNav .tab-btn').forEach(btn => btn.classList.remove('active'));
const activeBtn = Array.from(document.querySelectorAll('#masterNav .tab-btn')).find(b => b.innerText.includes(getTabPersianName(tab)));
if (activeBtn) activeBtn.classList.add('active');
document.querySelectorAll('.master-tab-content').forEach(tc => tc.style.display = 'none');
const target = document.getElementById('tabContent' + capitalize(tab));
if (target) target.style.display = 'block';
}
function switchHamedTab(tab) {
currentHamedTab = tab;
document.querySelectorAll('#hamedNav .tab-btn').forEach(btn => btn.classList.remove('active'));
const activeBtn = Array.from(document.querySelectorAll('#hamedNav .tab-btn')).find(b => b.innerText.includes(getHamedTabPersianName(tab)));
if (activeBtn) activeBtn.classList.add('active');
document.querySelectorAll('.hamed-tab-content').forEach(tc => tc.style.display = 'none');
const target = document.getElementById('hamedTab' + capitalize(tab));
if (target) target.style.display = 'block';
}
function getTabPersianName(t) {
const map = { approvals: 'تاییدیه‌ها', meetings: 'جلسات', tasks: 'تسک‌های', finance: 'مالی', contacts: 'مخاطبین', vault: 'آرشیو', recycle: 'سطل' };
return map[t] || '';
}
function getHamedTabPersianName(t) {
const map = { today: 'تصمیمات', finance: 'اقساط', contacts: 'مخاطبین', vault: 'آرشیو' };
return map[t] || '';
}
function capitalize(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}
// Modal Control & Bugfix: Clear forms when adding new
function openModal(id) {
document.getElementById(id).classList.add('active');
}
function closeModal(id) {
document.getElementById(id).classList.remove('active');
}
function openNewModal(entity) {
const form = document.getElementById('form' + capitalize(entity));
if (form) form.reset();
const idField = document.getElementById(entity + 'Id');
if (idField) idField.value = '';
const titleMap = {
approval: 'ثبت تاییدیه جدید برای حامد',
meeting: 'ثبت جلسه جدید',
task: 'ثبت تسک اجرایی جدید',
finance: 'ثبت موعد قسط یا تسهیلات جدید',
contact: 'ثبت مخاطب کلیدی VIP جدید',
vault: 'ثبت سند یا پوشه درایو جدید'
};
const titleEl = document.getElementById('modal' + capitalize(entity) + 'Title');
if (titleEl) titleEl.innerText = titleMap[entity] || 'ثبت آیتم جدید';
if (entity === 'meeting') {
document.getElementById('meetingTypeInput').value = 'online';
handleMeetingTypeChange();
} else if (entity === 'finance') {
const entEl = document.getElementById('financeEntityInput');
if (entEl) entEl.value = 'اکیپا';
const daysEl = document.getElementById('financeDaysLeftInput');
if (daysEl) daysEl.value = '';
}
openModal('modal' + capitalize(entity));
}
// Toast
function showToast(msg) {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = 'toast';
toast.innerHTML = `<span>${msg}</span>`;
container.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
toast.style.transition = 'opacity 0.3s ease';
setTimeout(() => toast.remove(), 300);
}, 3000);
}
// Render Logic
function renderAll() {
updateBadges();
if (currentUser === 'hamed') {
renderHamedApprovals();
renderHamedMeetings();
renderHamedFinanceTable();
renderHamedContactsTable();
renderHamedVaultTable();
} else if (currentUser === 'mohadese') {
renderMasterApprovals();
renderMasterMeetings();
renderMasterTasks();
renderMasterFinance();
renderMasterContacts();
renderMasterVault();
renderRecycleBin();
}
}
function updateBadges() {
const pApprovals = appState.approvals.filter(a => a.status === 'pending').length;
const mCount = appState.meetings.length;
const tCount = appState.tasks.filter(t => t.status !== 'done').length;
const fCount = appState.finance.filter(f => f.status === 'pending').length;
const cCount = appState.contacts.length;
const rCount = appState.recycle.length;
document.getElementById('badgeApprovals').innerText = pApprovals;
document.getElementById('badgeMeetings').innerText = mCount;
document.getElementById('badgeTasks').innerText = tCount;
document.getElementById('badgeFinance').innerText = fCount;
document.getElementById('badgeContacts').innerText = cCount;
document.getElementById('badgeRecycle').innerText = rCount;
document.getElementById('kpiHamedApprovals').innerText = pApprovals;
document.getElementById('kpiHamedMeetings').innerText = mCount;
document.getElementById('kpiHamedFinance').innerText = fCount;
document.getElementById('badgeHamedFinance').innerText = fCount;
}
// Hamed Renderers
function renderHamedApprovals() {
const list = document.getElementById('hamedApprovalsList');
if (!list) return;
const pending = appState.approvals.filter(a => a.status === 'pending');
if (!pending.length) {
list.innerHTML = `<div style="padding: 1.5rem; text-align: center; color: var(--text-muted); font-size: 0.88rem;">✨ تمامی موارد بررسی شده و موردی در صف انتظار تصمیم شما نیست.</div>`;
return;
}
list.innerHTML = pending.map(appr => `
<div style="background: var(--bg-surface-elevated); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 1rem;">
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem;">
<div style="font-weight: 700; font-size: 0.95rem;">${appr.title}</div>
<div style="display: flex; gap: 0.35rem; align-items: center;">
${appr.trackingCode ? `<span class="badge badge-blue" style="font-size: 0.72rem; font-feature-settings: 'tnum' 0;">${appr.trackingCode}</span>` : ''}
<span class="badge ${appr.priority === 'P0' ? 'badge-rose' : 'badge-amber'}">${appr.priority}</span>
</div>
</div>
<div style="font-size: 0.8rem; color: var(--primary); margin-bottom: 0.4rem;">👤 درخواست‌کننده: <strong>${appr.requester}</strong></div>
<p style="font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 0.75rem;">${appr.description}</p>
${appr.link ? `<div style="margin-bottom: 0.75rem;"><a href="${appr.link}" target="_blank" class="btn btn-sm" style="font-size: 0.75rem;">🔗 مشاهده فایل / سند ضمیمه</a></div>` : ''}
<div style="display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap;">
<button class="btn btn-sm btn-danger" onclick="openRejectModal('${appr.id}')">❌ رد / اصلاح</button>
<button class="btn btn-sm btn-success" onclick="setApprovalStatus('${appr.id}', 'approved')">✅ تایید فوری</button>
</div>
</div>
`).join('');
}
function handleMeetingTypeChange() {
const type = document.getElementById('meetingTypeInput').value;
const bufferLabel = document.getElementById('meetingBufferLabel');
const bufferInput = document.getElementById('meetingBufferInput');
const linkLabel = document.getElementById('meetingLinkLabel');
const linkInput = document.getElementById('meetingLinkInput');
if (type === 'online') {
bufferLabel.innerText = 'بستر آنلاین / تمهیدات فنی';
bufferInput.placeholder = 'مثال: لینک گوگل‌میت / ادوبی کانکت';
linkLabel.innerText = 'لینک ورود به جلسه آنلاین';
linkInput.placeholder = 'https://meet.google.com/...';
} else if (type === 'in_person_office') {
bufferLabel.innerText = 'هماهنگی اتاق جلسه و پذیرایی در دفتر اکیپا';
bufferInput.placeholder = 'مثال: رزرو اتاق جلسات اصلی + پذیرایی چای/قهوه';
linkLabel.innerText = 'اتاق جلسه / هماهنگی ورود مهمان';
linkInput.placeholder = 'مثال: اتاق کنفرانس / هماهنگی با نگهبانی و لابی';
} else {
// in_person_external or fallback in_person
bufferLabel.innerText = 'بافر ترافیک / زمان خروج پیشنهادی (تهران)';
bufferInput.placeholder = 'مثال: خروج ساعت ۱۴:۱۵ (۴۵ دقیقه بافر ترافیک همت)';
linkLabel.innerText = 'آدرس و لوکیشن در نشان / گوگل‌مپ';
linkInput.placeholder = 'https://neshan.org/...';
}
}
function renderHamedMeetings() {
const list = document.getElementById('hamedMeetingsList');
if (!appState.meetings.length) {
list.innerHTML = `<div style="padding: 1.5rem; text-align: center; color: var(--text-muted); font-size: 0.88rem;">جلسه‌ای برای امروز در تقویم ثبت نشده است.</div>`;
return;
}
list.innerHTML = appState.meetings.map(m => {
const isOnline = (m.type === 'online');
const isOffice = (m.type === 'in_person_office');
const isExternal = (!isOnline && !isOffice);
let badgeHtml = '';
if (isOnline) {
badgeHtml = '<span class="badge badge-primary">💻 آنلاین</span>';
} else if (isOffice) {
badgeHtml = '<span class="badge badge-green">🏢 حضوری (دفتر اکیپا)</span>';
} else {
badgeHtml = '<span class="badge badge-amber">🚗 حضوری (خارج از دفتر)</span>';
}
let logisticHtml = '';
if (isOffice) {
logisticHtml = `
<div style="font-size: 0.82rem; color: #34d399; margin-bottom: 0.35rem; display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap;">
<span>🏢 <strong>میزبانی در دفتر اکیپا (بدون تردد برای حامد)</strong></span>
${m.attendees ? `<span style="color: var(--text-muted);">| مهمان: <strong>${m.attendees}</strong></span>` : ''}
</div>
${m.buffer ? `<div style="font-size: 0.78rem; color: var(--text-faint); margin-bottom: 0.4rem;">☕ ${m.buffer}</div>` : ''}
`;
} else if (isExternal) {
logisticHtml = `
${m.buffer ? `<div style="font-size: 0.78rem; color: #fbbf24; margin-bottom: 0.35rem;">⚠️ ${m.buffer}</div>` : ''}
<div style="font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem;">👥 طرفین جلسه: ${m.attendees || 'بدون لیست حاضرین'}</div>
`;
} else {
logisticHtml = `<div style="font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem;">👥 حاضرین: ${m.attendees || 'بدون لیست حاضرین'}</div>`;
}
let actionHtml = '';
if (isOnline && m.link) {
actionHtml = `<a href="${m.link}" target="_blank" class="btn btn-sm btn-primary" style="flex: 1; justify-content: center;">🚀 ورود مستقیم به میت</a>`;
} else if (isExternal && m.link) {
actionHtml = `<a href="${m.link}" target="_blank" class="btn btn-sm btn-primary" style="flex: 1; justify-content: center; background: #f59e0b; border-color: #f59e0b;">📍 مسیریابی لوکیشن در نشان</a>`;
} else if (isOffice) {
actionHtml = `
<div style="display: flex; gap: 0.5rem; width: 100%; flex-wrap: wrap;">
<div style="font-size: 0.8rem; color: var(--accent-green); background: rgba(16, 185, 129, 0.1); padding: 0.4rem 0.75rem; border-radius: var(--radius-sm); border: 1px solid rgba(16, 185, 129, 0.25); flex: 1; text-align: center;">✅ میزبانی در دفتر اکیپا — عدم نیاز به تردد حامد</div>
<button class="btn btn-sm" onclick="copyMeetingInvite('${m.id}')" style="background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.35); color: #34d399;">📋 کپی متن دعوت مهمان</button>
</div>
`;
}
return `
<div style="background: var(--bg-surface-elevated); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 1rem;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.4rem;">
<div style="font-weight: 700; font-size: 0.95rem;">${m.title}</div>
${badgeHtml}
</div>
<div style="font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.35rem;">⏰ زمان: <strong>${m.time}</strong></div>
${logisticHtml}
${m.notes ? `<div style="font-size: 0.8rem; background: var(--bg-base); padding: 0.5rem; border-radius: 6px; margin-bottom: 0.6rem; color: var(--text-muted);">${m.notes}</div>` : ''}
${actionHtml ? `<div style="display: flex; gap: 0.5rem; margin-top: 0.4rem;">${actionHtml}</div>` : ''}
</div>
`;
}).join('');
}
function renderHamedFinanceTable() {
const tbody = document.getElementById('tableBodyHamedFinance');
if (!tbody) return;
updateFinanceSummaryStats();
let filtered = appState.finance.filter(f => {
if (activeFinanceFilter === 'pending' && f.status !== 'pending') return false;
if (activeFinanceFilter === 'paid' && f.status !== 'paid') return false;
if (['اکیپا', 'مایندرو', 'شخصی حامد'].includes(activeFinanceFilter)) {
if ((f.entity || 'اکیپا') !== activeFinanceFilter) return false;
}
if (queryFinanceHamed) {
const text = [f.title, f.bank, f.amount, f.dueDate, f.notes, f.entity].join(' ').toLowerCase();
if (!text.includes(queryFinanceHamed)) return false;
}
return true;
});
if (!filtered.length) {
tbody.innerHTML = `<tr><td colspan="9" style="text-align: center; color: var(--text-muted); padding: 1.5rem;">موردی با این فیلتر یا جستجو یافت نشد.</td></tr>`;
return;
}
tbody.innerHTML = filtered.map(f => {
const entity = f.entity || 'اکیپا';
let entityBadge = '<span class="badge badge-primary">🏢 اکیپا</span>';
if (entity === 'مایندرو') {
entityBadge = '<span class="badge badge-purple">🧠 مایندرو</span>';
} else if (entity === 'شخصی حامد') {
entityBadge = '<span class="badge badge-blue">👤 شخصی</span>';
}
let daysBadge = '';
const d = f.daysLeft || '';
const isUrgent = d.includes('۱') || d.includes('۲') || d.includes('۳') || d.includes('فوری');
if (f.status === 'paid') {
daysBadge = '<span class="badge badge-green">تسویه شد ✅</span>';
} else if (isUrgent) {
daysBadge = `<span class="badge badge-rose pulse-urgent">🚨 ${f.daysLeft || 'فوری'}</span>`;
} else {
daysBadge = `<span class="badge badge-amber">⏳ ${f.daysLeft || 'معین'}</span>`;
}
return `
<tr>
<td><strong>${f.title}</strong></td>
<td>${entityBadge}</td>
<td>${f.bank || '-'}</td>
<td style="font-weight: 700; color: var(--accent-green); font-size: 0.95rem; white-space: nowrap;">${f.amount}</td>
<td>${f.dueDate}</td>
<td>${daysBadge}</td>
<td style="font-size: 0.8rem; color: var(--text-muted); max-width: 200px;">${f.notes || '-'}</td>
<td>
<span class="badge ${f.status === 'paid' ? 'badge-green' : (f.status === 'overdue' ? 'badge-rose' : 'badge-amber')}">
${f.status === 'paid' ? 'پرداخت شد ✅' : 'در انتظار پرداخت'}
</span>
</td>
<td>
<button class="btn btn-sm ${f.status === 'paid' ? '' : 'btn-success'}" onclick="toggleFinanceStatus('${f.id}')">
${f.status === 'paid' ? 'بازنشانی' : 'ثبت پرداخت'}
</button>
</td>
</tr>
`;
}).join('');
}
function toggleFinanceStatus(id) {
const item = appState.finance.find(f => f.id === id);
if (!item) return;
const willBePaid = (item.status !== 'paid');
const confirmMsg = willBePaid ?
`آیا از ثبت پرداخت مبلغ «${item.amount} تومان» برای «${item.title}» اطمینان دارید؟` :
`آیا می‌خواهید وضعیت «${item.title}» را به در انتظار پرداخت بازگردانید؟`;
if (confirm(confirmMsg)) {
item.status = willBePaid ? 'paid' : 'pending';
showToast(willBePaid ? '✅ وضعیت قسط به پرداخت‌شده تغییر یافت.' : 'وضعیت به در انتظار بازگردانده شد.');
triggerStateChange();
}
}
function renderHamedContactsTable() {
const tbody = document.getElementById('tableBodyHamedContacts');
tbody.innerHTML = appState.contacts.map(c => `
<tr>
<td><strong>${c.name}</strong></td>
<td><span class="badge badge-purple">${c.category}</span></td>
<td>${c.role || '-'}</td>
<td style="direction: ltr; text-align: right;"><a href="tel:${c.phone}" style="color: var(--primary); text-decoration: none;">${c.phone}</a></td>
<td style="direction: ltr; text-align: right;">${c.social ? `<a href="https://t.me/${c.social.replace('@','')}" target="_blank" style="color: #60a5fa; text-decoration: none;">@${c.social.replace('@','')}</a>` : '-'}</td>
<td style="max-width: 250px; font-size: 0.8rem; color: var(--text-muted);">${c.notes || '-'}</td>
<td>
<div style="display: flex; gap: 0.35rem;">
<a href="tel:${c.phone}" class="btn btn-sm">📞 تماس</a>
${c.social ? `<a href="https://t.me/${c.social.replace('@','')}" target="_blank" class="btn btn-sm btn-primary">💬 تلگرام</a>` : ''}
</div>
</td>
</tr>
`).join('');
}
function filterHamedContacts(q) {
const query = q.trim().toLowerCase();
const rows = document.querySelectorAll('#tableBodyHamedContacts tr');
rows.forEach(r => {
r.style.display = r.innerText.toLowerCase().includes(query) ? '' : 'none';
});
}
function renderHamedVaultTable() {
const tbody = document.getElementById('tableBodyHamedVault');
if (!tbody) return;
let items = appState.vault;
if (queryVaultHamed) {
items = items.filter(v => [v.title, v.category, v.desc, v.sec].join(' ').toLowerCase().includes(queryVaultHamed));
}
if (!items.length) {
tbody.innerHTML = `<tr><td colspan="5" style="text-align: center; color: var(--text-muted); padding: 1.5rem;">سندی یافت نشد.</td></tr>`;
return;
}
tbody.innerHTML = items.map(v => `
<tr>
<td><strong>${v.title}</strong></td>
<td><span class="badge badge-primary">${v.category}</span></td>
<td><span class="badge badge-rose">${v.sec}</span></td>
<td style="font-size: 0.8rem; color: var(--text-muted);">${v.desc || '-'}</td>
<td><a href="${v.link}" target="_blank" class="btn btn-sm btn-primary">🔗 باز کردن پوشه درایو</a></td>
</tr>
`).join('');
}
function setApprovalStatus(id, status) {
const appr = appState.approvals.find(a => a.id === id);
if (appr) {
appr.status = status;
showToast(status === 'approved' ? '✅ تاییدیه صادر شد.' : '❌ درخواست جهت اصلاح ارجاع شد.');
triggerStateChange();
}
}
// Master Renderers
function renderMasterApprovals() {
const tbody = document.getElementById('tableBodyApprovals');
if (!tbody) return;
tbody.innerHTML = appState.approvals.map(appr => {
let convertBtn = '';
if (appr.status === 'approved') {
convertBtn = `<button class="btn btn-sm btn-primary" onclick="convertApprovalToTask('${appr.id}')" ${appr.convertedToTask ? 'disabled style="opacity: 0.6;"' : ''}>${appr.convertedToTask ? '✅ در تسک‌ها' : '⚡ تبدیل به تسک'}</button>`;
}
return `
<tr>
<td>
<strong>${appr.title}</strong>
${appr.trackingCode ? `<div style="font-size: 0.72rem; color: #60a5fa; font-feature-settings: 'tnum' 0; margin-top: 0.2rem;">کد پیگیری: ${appr.trackingCode}</div>` : ''}
${appr.feedback ? `<div style="font-size: 0.75rem; color: #fb7185; margin-top: 0.3rem; background: rgba(239, 68, 68, 0.08); padding: 0.3rem 0.5rem; border-radius: 4px; border-right: 2px solid #ef4444;">✍️ بازخورد حامد: ${appr.feedback}</div>` : ''}
</td>
<td>${appr.requester}</td>
<td><span class="badge ${appr.priority === 'P0' ? 'badge-rose' : 'badge-amber'}">${appr.priority}</span></td>
<td style="max-width: 250px; font-size: 0.82rem;">${appr.description}</td>
<td>${appr.link ? `<a href="${appr.link}" target="_blank" class="btn btn-sm">لینک ضمیمه</a>` : '-'}</td>
<td>
<span class="badge ${appr.status === 'approved' ? 'badge-green' : (appr.status === 'rejected' ? 'badge-rose' : 'badge-primary')}">
${appr.status === 'approved' ? 'تایید شد' : (appr.status === 'rejected' ? 'رد / اصلاح' : 'در انتظار')}
</span>
</td>
<td>
<div style="display: flex; gap: 0.3rem; flex-wrap: wrap;">
${convertBtn}
<button class="btn btn-sm" onclick="editMasterItem('approval', '${appr.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteMasterItem('approvals', '${appr.id}')">🗑️</button>
</div>
</td>
</tr>
`;}).join('');
}
function renderMasterMeetings() {
const tbody = document.getElementById('tableBodyMeetings');
if (!tbody) return;
tbody.innerHTML = appState.meetings.map(m => {
const isOnline = (m.type === 'online');
const isOffice = (m.type === 'in_person_office');
let badgeType = '';
if (isOnline) {
badgeType = '<span class="badge badge-primary">💻 آنلاین</span>';
} else if (isOffice) {
badgeType = '<span class="badge badge-green">🏢 دفتر اکیپا</span>';
} else {
badgeType = '<span class="badge badge-amber">🚗 خارج از دفتر</span>';
}
let inviteBtn = '';
if (isOffice) {
inviteBtn = `<button class="btn btn-sm" onclick="copyMeetingInvite('${m.id}')" style="background: rgba(16, 185, 129, 0.15); border: 1px solid rgba(16, 185, 129, 0.35); color: #34d399;" title="کپی متن رسمی دعوت مهمان">📋 دعوت</button>`;
}
return `
<tr>
<td><strong>${m.title}</strong></td>
<td>${badgeType}</td>
<td>${m.time}</td>
<td>${m.attendees || '-'}</td>
<td>${m.buffer || (isOffice ? 'بدون تردد (دفتر اکیپا)' : '-')}</td>
<td>${m.link ? `<a href="${m.link}" target="_blank" class="btn btn-sm">مشاهده / ورود</a>` : (isOffice ? '<span style="color: var(--accent-green); font-size: 0.8rem;">دفتر مرکزی اکیپا</span>' : '-')}</td>
<td>
<div style="display: flex; gap: 0.3rem;">
${inviteBtn}
<button class="btn btn-sm" onclick="editMasterItem('meeting', '${m.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteMasterItem('meetings', '${m.id}')">🗑️</button>
</div>
</td>
</tr>
`;}).join('');
}
function renderMasterTasks() {
const tbody = document.getElementById('tableBodyTasks');
tbody.innerHTML = appState.tasks.map(t => `
<tr>
<td><strong>${t.title}</strong></td>
<td>${t.assignee || '-'}</td>
<td><span class="badge badge-primary">${t.category}</span></td>
<td><span class="badge ${t.priority === 'P0' ? 'badge-rose' : (t.priority === 'P1' ? 'badge-amber' : 'badge-green')}">${t.priority}</span></td>
<td>${t.deadline || '-'}</td>
<td>
<span class="badge ${t.status === 'done' ? 'badge-green' : (t.status === 'waiting_approval' ? 'badge-rose' : 'badge-primary')}">
${t.status === 'done' ? 'تکمیل' : (t.status === 'waiting_approval' ? 'منتظر تایید' : (t.status === 'in_progress' ? 'در اقدام' : 'در صف'))}
</span>
</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editMasterItem('task', '${t.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteMasterItem('tasks', '${t.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
function renderMasterFinance() {
const tbody = document.getElementById('tableBodyFinance');
if (!tbody) return;
tbody.innerHTML = appState.finance.map(f => {
const entity = f.entity || 'اکیپا';
let entityBadge = '<span class="badge badge-primary">🏢 اکیپا</span>';
if (entity === 'مایندرو') {
entityBadge = '<span class="badge badge-purple">🧠 مایندرو</span>';
} else if (entity === 'شخصی حامد') {
entityBadge = '<span class="badge badge-blue">👤 شخصی</span>';
}
return `
<tr>
<td><strong>${f.title}</strong></td>
<td>${entityBadge}</td>
<td>${f.bank || '-'}</td>
<td style="font-weight: 700; color: var(--accent-green); white-space: nowrap;">${f.amount}</td>
<td>${f.dueDate}</td>
<td style="font-size: 0.8rem; color: var(--text-muted);">${f.notes || '-'}</td>
<td>
<span class="badge ${f.status === 'paid' ? 'badge-green' : (f.status === 'overdue' ? 'badge-rose' : 'badge-amber')}">
${f.status === 'paid' ? 'پرداخت شد ✅' : (f.status === 'overdue' ? 'معوق' : 'در انتظار')}
</span>
</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editMasterItem('finance', '${f.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteMasterItem('finance', '${f.id}')">🗑️</button>
</div>
</td>
</tr>
`;}).join('');
}
function renderMasterContacts() {
const tbody = document.getElementById('tableBodyContacts');
tbody.innerHTML = appState.contacts.map(c => `
<tr>
<td><strong>${c.name}</strong></td>
<td><span class="badge badge-purple">${c.category}</span></td>
<td>${c.role || '-'}</td>
<td style="direction: ltr; text-align: right;">${c.phone}</td>
<td style="direction: ltr; text-align: right;">${c.social || '-'}</td>
<td style="max-width: 250px;">${c.notes || '-'}</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editMasterItem('contact', '${c.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteMasterItem('contacts', '${c.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
function renderMasterVault() {
const tbody = document.getElementById('tableBodyVault');
tbody.innerHTML = appState.vault.map(v => `
<tr>
<td><strong>${v.title}</strong></td>
<td><span class="badge badge-primary">${v.category}</span></td>
<td><a href="${v.link}" target="_blank" class="btn btn-sm btn-primary">🔗 باز کردن درایو</a></td>
<td><span class="badge badge-rose">${v.sec}</span></td>
<td>${v.desc || '-'}</td>
<td>
<div style="display: flex; gap: 0.3rem;">
<button class="btn btn-sm" onclick="editMasterItem('vault', '${v.id}')">✏️</button>
<button class="btn btn-sm btn-danger" onclick="deleteMasterItem('vault', '${v.id}')">🗑️</button>
</div>
</td>
</tr>
`).join('');
}
function renderRecycleBin() {
const tbody = document.getElementById('tableBodyRecycle');
if (!appState.recycle || !appState.recycle.length) {
tbody.innerHTML = `<tr><td colspan="5" style="text-align: center; color: var(--text-muted); padding: 1.5rem;">سطل بازیافت خالی است؛ هیچ آیتم حذف‌شده‌ای وجود ندارد.</td></tr>`;
return;
}
tbody.innerHTML = appState.recycle.map((item, idx) => `
<tr>
<td><span class="badge badge-primary">${item.entityType}</span></td>
<td><strong>${item.title || item.name || 'بدون عنوان'}</strong></td>
<td>${item.deletedAt}</td>
<td style="max-width: 300px; font-size: 0.75rem; color: var(--text-muted); direction: ltr; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
${JSON.stringify(item.data)}
</td>
<td>
<div style="display: flex; gap: 0.4rem;">
<button class="btn btn-sm btn-success" onclick="restoreItem(${idx})">♻️ بازگردانی</button>
<button class="btn btn-sm btn-danger" onclick="permanentDeleteItem(${idx})">حذف قطعی</button>
</div>
</td>
</tr>
`).join('');
}
// CRUD Handlers
function saveMasterItem(event, entity) {
event.preventDefault();
const entitySingle = (entity === 'approvals') ? 'approval' : (entity === 'meetings') ? 'meeting' : (entity === 'tasks') ? 'task' : (entity === 'finance') ? 'finance' : (entity === 'contacts') ? 'contact' : 'vault';
const idField = document.getElementById(entitySingle + 'Id');
const isEdit = idField && idField.value;
const itemId = isEdit ? idField.value : (entity + '_' + Date.now());
let itemObj = { id: itemId };
if (entity === 'approvals') {
itemObj.title = document.getElementById('approvalTitleInput').value.trim();
itemObj.requester = document.getElementById('approvalRequesterInput').value.trim();
itemObj.priority = document.getElementById('approvalPriorityInput').value;
itemObj.description = document.getElementById('approvalDescriptionInput').value.trim();
itemObj.link = normalizeUrl(document.getElementById('approvalLinkInput').value);
itemObj.status = document.getElementById('approvalStatusInput').value;
itemObj.createdAt = new Date().toLocaleDateString('fa-IR');
closeModal('modalApproval');
} else if (entity === 'meetings') {
itemObj.title = document.getElementById('meetingTitleInput').value.trim();
itemObj.type = document.getElementById('meetingTypeInput').value;
itemObj.time = document.getElementById('meetingTimeInput').value.trim();
itemObj.attendees = document.getElementById('meetingAttendeesInput').value.trim();
itemObj.buffer = document.getElementById('meetingBufferInput').value.trim();
itemObj.link = normalizeUrl(document.getElementById('meetingLinkInput').value);
itemObj.notes = document.getElementById('meetingNotesInput').value.trim();
closeModal('modalMeeting');
} else if (entity === 'tasks') {
itemObj.title = document.getElementById('taskTitleInput').value.trim();
itemObj.assignee = document.getElementById('taskAssigneeInput').value.trim();
itemObj.category = document.getElementById('taskCategoryInput').value;
itemObj.priority = document.getElementById('taskPriorityInput').value;
itemObj.deadline = document.getElementById('taskDeadlineInput').value.trim();
itemObj.status = document.getElementById('taskStatusInput').value;
closeModal('modalTask');
} else if (entity === 'finance') {
itemObj.title = document.getElementById('financeTitleInput').value.trim();
itemObj.entity = document.getElementById('financeEntityInput') ? document.getElementById('financeEntityInput').value : 'اکیپا';
itemObj.bank = document.getElementById('financeBankInput').value.trim();
itemObj.amount = document.getElementById('financeAmountInput').value.trim();
itemObj.dueDate = document.getElementById('financeDueDateInput').value.trim();
itemObj.daysLeft = document.getElementById('financeDaysLeftInput') ? document.getElementById('financeDaysLeftInput').value.trim() : '';
itemObj.notes = document.getElementById('financeNotesInput').value.trim();
itemObj.status = document.getElementById('financeStatusInput').value;
closeModal('modalFinance');
} else if (entity === 'contacts') {
itemObj.name = document.getElementById('contactNameInput').value.trim();
itemObj.category = document.getElementById('contactCategoryInput').value;
itemObj.role = document.getElementById('contactRoleInput').value.trim();
itemObj.phone = document.getElementById('contactPhoneInput').value.trim();
itemObj.social = document.getElementById('contactSocialInput').value.trim();
itemObj.notes = document.getElementById('contactNotesInput').value.trim();
closeModal('modalContact');
} else if (entity === 'vault') {
itemObj.title = document.getElementById('vaultTitleInput').value.trim();
itemObj.category = document.getElementById('vaultCategoryInput').value;
itemObj.link = normalizeUrl(document.getElementById('vaultLinkInput').value);
itemObj.sec = document.getElementById('vaultSecInput').value;
itemObj.desc = document.getElementById('vaultDescInput').value.trim();
closeModal('modalVault');
}
if (isEdit) {
const idx = appState[entity].findIndex(i => i.id === itemId);
if (idx !== -1) appState[entity][idx] = itemObj;
showToast('✏️ اطلاعات ویرایش و ذخیره شد.');
} else {
appState[entity].unshift(itemObj);
showToast('✅ رکورد جدید با موفقیت ایجاد شد.');
}
triggerStateChange();
}
function editMasterItem(entitySingle, id) {
const entityPlural = (entitySingle === 'approval') ? 'approvals' : (entitySingle === 'meeting') ? 'meetings' : (entitySingle === 'task') ? 'tasks' : (entitySingle === 'finance') ? 'finance' : (entitySingle === 'contact') ? 'contacts' : 'vault';
const item = appState[entityPlural].find(i => i.id === id);
if (!item) return;
if (entitySingle === 'approval') {
document.getElementById('approvalId').value = item.id;
document.getElementById('approvalTitleInput').value = item.title;
document.getElementById('approvalRequesterInput').value = item.requester;
document.getElementById('approvalPriorityInput').value = item.priority;
document.getElementById('approvalDescriptionInput').value = item.description;
document.getElementById('approvalLinkInput').value = item.link || '';
document.getElementById('approvalStatusInput').value = item.status;
document.getElementById('modalApprovalTitle').innerText = 'ویرایش تاییدیه حامد';
openModal('modalApproval');
} else if (entitySingle === 'meeting') {
document.getElementById('meetingId').value = item.id;
document.getElementById('meetingTitleInput').value = item.title;
document.getElementById('meetingTypeInput').value = (item.type === 'in_person') ? 'in_person_external' : (item.type || 'online');
document.getElementById('meetingTimeInput').value = item.time;
document.getElementById('meetingAttendeesInput').value = item.attendees || '';
document.getElementById('meetingBufferInput').value = item.buffer || '';
document.getElementById('meetingLinkInput').value = item.link || '';
document.getElementById('meetingNotesInput').value = item.notes || '';
handleMeetingTypeChange();
document.getElementById('modalMeetingTitle').innerText = 'ویرایش جلسه';
openModal('modalMeeting');
} else if (entitySingle === 'task') {
document.getElementById('taskId').value = item.id;
document.getElementById('taskTitleInput').value = item.title;
document.getElementById('taskAssigneeInput').value = item.assignee || '';
document.getElementById('taskCategoryInput').value = item.category;
document.getElementById('taskPriorityInput').value = item.priority;
document.getElementById('taskDeadlineInput').value = item.deadline || '';
document.getElementById('taskStatusInput').value = item.status;
document.getElementById('modalTaskTitle').innerText = 'ویرایش تسک';
openModal('modalTask');
} else if (entitySingle === 'finance') {
document.getElementById('financeId').value = item.id;
document.getElementById('financeTitleInput').value = item.title;
if (document.getElementById('financeEntityInput')) {
document.getElementById('financeEntityInput').value = item.entity || 'اکیپا';
}
document.getElementById('financeBankInput').value = item.bank || '';
document.getElementById('financeAmountInput').value = item.amount;
document.getElementById('financeDueDateInput').value = item.dueDate;
if (document.getElementById('financeDaysLeftInput')) {
document.getElementById('financeDaysLeftInput').value = item.daysLeft || '';
}
document.getElementById('financeNotesInput').value = item.notes || '';
document.getElementById('financeStatusInput').value = item.status;
document.getElementById('modalFinanceTitle').innerText = 'ویرایش قسط / تعهد';
openModal('modalFinance');
} else if (entitySingle === 'contact') {
document.getElementById('contactId').value = item.id;
document.getElementById('contactNameInput').value = item.name;
document.getElementById('contactCategoryInput').value = item.category;
document.getElementById('contactRoleInput').value = item.role || '';
document.getElementById('contactPhoneInput').value = item.phone;
document.getElementById('contactSocialInput').value = item.social || '';
document.getElementById('contactNotesInput').value = item.notes || '';
document.getElementById('modalContactTitle').innerText = 'ویرایش مخاطب VIP';
openModal('modalContact');
} else if (entitySingle === 'vault') {
document.getElementById('vaultId').value = item.id;
document.getElementById('vaultTitleInput').value = item.title;
document.getElementById('vaultCategoryInput').value = item.category;
document.getElementById('vaultLinkInput').value = item.link;
document.getElementById('vaultSecInput').value = item.sec;
document.getElementById('vaultDescInput').value = item.desc || '';
document.getElementById('modalVaultTitle').innerText = 'ویرایش سند درایو';
openModal('modalVault');
}
}
function deleteMasterItem(entity, id) {
const idx = appState[entity].findIndex(i => i.id === id);
if (idx === -1) return;
const item = appState[entity][idx];
const rec = {
recycleId: 'rec_' + Date.now(),
entityType: entity,
title: item.title || item.name || 'بدون عنوان',
deletedAt: new Date().toLocaleDateString('fa-IR') + ' ' + new Date().toLocaleTimeString('fa-IR'),
data: item
};
if (!appState.recycle) appState.recycle = [];
appState.recycle.unshift(rec);
appState[entity].splice(idx, 1);
showToast('🗑️ به سطل بازیافت منتقل شد (قابل بازگردانی است).');
triggerStateChange();
}
function restoreItem(index) {
const rec = appState.recycle[index];
if (!rec) return;
const entity = rec.entityType;
if (!appState[entity]) appState[entity] = [];
appState[entity].unshift(rec.data);
appState.recycle.splice(index, 1);
showToast(`♻️ «${rec.title}» بازگردانده شد.`);
triggerStateChange();
}
function permanentDeleteItem(index) {
if (confirm('آیا از حذف دائمی این رکورد اطمینان دارید؟ این عمل غیرقابل بازگشت است.')) {
appState.recycle.splice(index, 1);
showToast('حذف قطعی شد.');
triggerStateChange();
}
}
// Team Guest Intake - Atomic, Race-Safe & Sanitized
async function handleTeamGuestSubmit(e) {
e.preventDefault();
const submitBtn = document.getElementById('tgSubmitBtn');
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.innerText = 'در حال ثبت امن در دیتابیس...';
}
const req = document.getElementById('tgRequester').value.trim();
const title = document.getElementById('tgTitle').value.trim();
const priority = document.getElementById('tgPriority').value;
const desc = document.getElementById('tgDescription').value.trim();
let link = document.getElementById('tgLink').value.trim();
if (link) link = normalizeUrl(link);
const trackingCode = 'EKP-' + Math.floor(1000 + Math.random() * 9000);
const newApproval = {
id: 'team_' + Date.now(),
trackingCode: trackingCode,
title: title,
requester: req,
priority: priority,
description: desc,
link: link || '',
status: 'pending',
createdAt: new Date().toLocaleDateString('fa-IR')
};
try {
// Fetch freshest PostgreSQL state to prevent race conditions or overwriting stale data
let latestState = appState;
const fetchRes = await fetch('/api/db/state?key=exec_cockpit_state');
if (fetchRes.ok) {
const json = await fetchRes.json();
if (json && json.data && json.data.approvals) {
latestState = json.data;
}
}
if (!latestState.approvals) latestState.approvals = [];
latestState.approvals.unshift(newApproval);
const saveRes = await fetch('/api/db/state', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
state_key: 'exec_cockpit_state',
data: latestState
})
});
if (saveRes.ok) {
appState = latestState;
document.getElementById('teamGuestForm').reset();
document.getElementById('tgCardForm').style.display = 'none';
document.getElementById('tgSuccessBox').style.display = 'block';
document.getElementById('tgTrackingCodeDisplay').innerText = trackingCode;
showToast(`🚀 درخواست شما با کد پیگیری ${trackingCode} ثبت گردید.`);
} else {
throw new Error('Save status not OK');
}
} catch (err) {
console.error('Guest submit error:', err);
alert('خطا در ذخیره‌سازی ابری. لطفاً مجدداً تلاش فرمایید.');
} finally {
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.innerText = '🚀 ثبت قطعی در کارتابل حامد فلاحی';
}
}
}
// Backups
function exportFullBackup() {
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(appState, null, 2));
const downloadAnchor = document.createElement('a');
downloadAnchor.setAttribute("href", dataStr);
downloadAnchor.setAttribute("download", `ExecCockpit_Backup_${new Date().toISOString().slice(0,10)}.json`);
document.body.appendChild(downloadAnchor);
downloadAnchor.click();
downloadAnchor.remove();
showToast('📥 فایل بکاپ کامل JSON دانلود شد.');
}
function restoreFromBackupFile() {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json';
input.onchange = e => {
const file = e.target.files[0];
const reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = readerEvent => {
try {
const content = JSON.parse(readerEvent.target.result);
if (content.approvals && content.meetings) {
appState = content;
triggerStateChange();
showToast('✅ بازگردانی از بکاپ انجام شد.');
} else {
alert('فایل نامعتبر است.');
}
} catch (err) {
alert('خطا در خواندن فایل.');
}
}
}
input.click();
}
function filterData(entity, query) {
const q = query.trim().toLowerCase();
const rows = document.querySelectorAll(`#tableBody${capitalize(entity)} tr`);
rows.forEach(r => {
r.style.display = r.innerText.toLowerCase().includes(q) ? '' : 'none';
});
}
// Init
window.addEventListener('DOMContentLoaded', () => {
try {
const savedUser = sessionStorage.getItem('exec_cockpit_user');
if (savedUser && ['hamed', 'mohadese', 'team_guest'].includes(savedUser)) {
currentUser = savedUser;
}
} catch (e) {}
updateViewVisibility();
loadFromPostgres();
// Silent Auto-Sync Polling every 45s for Hamed and Mohadese
setInterval(async () => {
if (currentUser === 'hamed' || currentUser === 'mohadese') {
try {
const res = await fetch('/api/db/state?key=exec_cockpit_state');
if (res.ok) {
const json = await res.json();
if (json && json.data && json.data.approvals) {
const newHash = JSON.stringify(json.data).length;
const oldHash = JSON.stringify(appState).length;
if (newHash !== oldHash) {
appState = json.data;
renderAll();
showToast('🔄 اطلاعات به‌روزرسانی شد.');
}
}
}
} catch (e) {}
}
}, 45000);
});
</script>
</body>
</html>