فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
license-server
a02/strict-export-preflight-20261018
audit/a01-readonly-invoice-metadata-20261101
ci/a06-require-trusted-issuer-for-release
ci/main-postmerge-phase-a-validation-20261020
ci/phase-a-controlled-public-release
design/issue-5-commercial-corrections-adr
docs/a01-a02-a05-oct23-verified-evidence
docs/a01-cheque-endorsement-evidence-20261022
docs/a01-cheque-event-date-evidence-20261021
docs/a01-explicit-refund-reason-evidence-20261021
docs/a01-refund-auth-status-20261020
docs/a01-refund-trace-evidence-20261020
docs/a02-102-evidence-20261018
docs/a02-pr104-evidence-20261018
docs/a02-pr106-evidence-20261019
docs/a02-pr108-ten-tests-20261019
docs/a02-private-sql-backup-evidence-20261111
docs/a03-merge-status-sync-20261020
docs/a04-software-gate-acceptance-20261020
docs/feature-matrix-20261014
docs/finora-master-execution-playbook
docs/four-phase-execution-20261014
docs/four-phase-roadmap-20261014
docs/holoo-lab-stabilization-phase1-20261111
docs/holoo-runtime-schema-audit-20261111
docs/ops-142-governance-5-1-3-20261030
docs/phase-a-a01-a02-a06-a08-verified-evidence-20261023
docs/phase-a-a01-a05-a06-evidence-20261023
docs/phase-a-independent-acceptance-evidence
docs/phase-a-pr110-evidence-20261019
docs/project-status-phase-a-20261014
feat/a01-referenced-return-corrections
feat/a01-referenced-returns-on-main
feat/a02-atomic-opening-ledger-preflight
feat/a02-holoo-compatibility-preflight
feat/a02-holoo-declared-control-totals
feat/a02-holoo-explicit-csv-gate
feat/a02-holoo-safe-zip-intake-offline-webview2-20261030
feat/a02-offline-sql-server-provisioning-20261030
feat/a02-opening-balance-dry-run
feat/a02-opening-ledger-admin-ui
feat/a02-opt-in-isolated-sql-restore-executor-20261030
feat/a02-private-holoo-zip-staging-20261030
feat/a02-safe-isolated-restore-plan-20261030
feat/a02-sql-backup-header-verifyonly-20261030
feat/a03-audit-schema-atomic-events
feat/a03-complete-manual-journal-audit
feat/a05-cheque-treasury-reconciliation
feat/a06-signed-offline-license-activation
feat/a08-synthetic-performance-baseline
feat/phase-a-accounting-benchmark-return-preview
feat/phase-a-ledger-settlement-diagnostics
feature/v2-reconciliation-20261013
fix/a01-atomic-confirm-ui-one-shot-20261031
fix/a01-cheque-clearance-explicit-account-20261023
fix/a01-cheque-contractual-due-date-validity-20261023
fix/a01-cheque-endorsement-counterparty-20261022
fix/a01-cheque-event-date-open-period-20261021
fix/a01-cumulative-return-amount-cap
fix/a01-explicit-refund-reason-approval-20261021
fix/a01-manager-authorized-customer-refunds-20261020
fix/a01-no-implicit-refund
fix/a01-one-shot-confirm-on-atomic-import-20261031
fix/a01-refund-and-overcollection-net-cash
fix/a01-refund-correction-trace-20261020
fix/a02-atomic-excel-master-merge-20261031
fix/a02-canonical-mapping-contract-20261018
fix/a02-disable-destructive-excel-replace-20261031
fix/a02-holoo-invoice-line-coverage-20261023
fix/a02-holoo-preflight-required-invoice-lines-20261023
fix/a02-mapping-contract-20261018
fix/a02-opening-preflight-unbalanced-report
fix/a02-orphan-mapping-20261018
fix/a02-private-excel-import-session-20261031
fix/a02-strict-export-input-20261019
fix/a03-append-only-full-backup-import
fix/a03-append-only-write-guard
fix/a03-block-transaction-clear-append-only-20261016
fix/a03-chain-validation-20261020
fix/a03-company-scoped-audit-data-access
fix/a03-deny-direct-audit-write-20261019
fix/a03-escaped-expense-list-20261031
fix/a03-escaped-financial-record-ids-20261031
fix/a03-financial-ledger-actions-and-print-20261031
fix/a04-backup-checksum-preflight
fix/a04-company-audit-replay-stable-compare
fix/a04-company-backup-source-isolation-20261020
fix/a04-full-restore-posted-financial-integrity
fix/a04-reject-mixed-company-backup-20261019
fix/a04-replace-immutable-posted-ledger
fix/a04-restore-financial-journal-references
fix/a04-service-source-company-boundary-20261020
fix/a05-block-inactive-treasury-settlements
fix/a05-cheque-cash-evidence-reconciliation-20261023
fix/a05-cheque-ledger-and-bank-reconciliation-20261023
fix/a05-fiscal-close-invariant-gates
fix/a06-backup-restore-user-privileges
fix/a06-license-user-company-quota-20261023
fix/a06-malformed-trial-state-fail-closed
fix/a06-offline-clock-fail-closed-20261019
fix/a07-indexeddb-blocked-startup
fix/a07-offline-bundled-assets
fix/a07-version-and-startup-banner
fix/issue-7-company-backup-isolation
fix/p0-deterministic-fractional-invoice-money-20261031
fix/p0-fractional-quantity-input-20261031
fix/p0-fractional-quantity-integrated-20261031
fix/p0-invoice-posting-invariants-20261031
fix/p0-legacy-stock-and-product-inputs-20261031
fix/p0-reports-immutable-cogs-20261101
fix/p0-verified-financial-percent-20261031
fix/p0-zero-discount-report-revenue-20261101
fix/phase-a-backup-app-version
fix/phase-a-backup-integrity-checksum
fix/phase-a-backup-record-id-validation-20261014
fix/phase-a-backup-version-validation-20261014
fix/phase-a-closure-pack3-20261101
fix/phase-a-entitlement-payload-validation
fix/phase-a-gate-exact-evidence-20261019
fix/phase-a-pack4-stock-scope-20261101
fix/phase-a-pack5-integrated-evidence-20261101
fix/phase-a-pack6-atomic-legacy-20261101
fix/phase-a-restore-envelope-and-rollback
fix/phase-a-settings-admin-gate
fix/print-browser-header-footer-20261014
fix/q01-expense-security-probe-exact-option-20261031
fix/q01-financial-grid-labels-20261031
fix/q01-form-label-association-20261031
fix/q01-native-evidence-integrity-20261030
fix/q01-number-input-persian-decimal-20261031
fix/q01-responsive-dashboard-and-cheque-table-20261031
fix/q01-safe-ui-action-audit-coverage-20261031
fix/q01-visible-desktop-sidebar-and-safe-confirm-20261030
fix/roadmap-metadata-sync-20261014
gate/a03-audit-metadata-validation-20261019
integration/a02-windows-holoo-setup-candidate-20261030
license-server
main
perf/a07-lazy-load-excel
perf/a08-cheque-reconciliation-account-index-20261023
perf/a08-paginated-reports-20261101
phase1-restore-hardening
planning/holoo-execution-20261013
planning/roadmap-project-management-20261014
qa/native-click-coverage-audit-20261030
release/v2.0.0
test/a01-native-endorsement-mandatory-20261023
test/a01-native-purchase-return-guardrails
test/a01-native-sale-return-financial-guardrails
test/a01-safe-integer-boundary-20261019
test/a02-native-opening-dry-run-rejections
test/a02-native-positive-opening-ledger
test/a04-native-corrupt-fbackup-20261016
test/a04-native-encrypted-company-backup
test/a04-native-encrypted-company-backup-main
test/a04-native-late-transaction-rollback
test/a04-native-windows-backup-recovery
test/a04-real-edge-v6-v7-migration
test/a04-real-native-interrupted-restore
test/a05-native-draft-ledger-and-repeat-close-20261016
test/a05-native-fiscal-close-guardrails
test/a07-native-multipage-print-engine
test/a07-native-origin-provenance
test/a07-native-webview2-offline-routes
test/a07-windows-offline-startup-smoke
test/a08-installed-webview2-60k-baseline
test/a08-native-webview2-heap-metrics
test/a08-windows-synthetic-performance-baseline
test/github-write-access-20261009
test/native-win-ui-routes-after-finance-backup
test/phase-a-combined-a01-a05-a08-final-evidence
test/phase-a-combined-native-acceptance-matrix
test/phase-a-ledger-invariants-20261014
test/phase-a-native-all-routes-on-merged-lab
test/phase-a-native-encrypted-backup
test/phase-a-native-finance-backup-matrix
test/phase-a-native-ui-and-backup-smoke
test/phase-a-windows-native-installer-lab
work/a08-dispatch-activation-20261123
work/a08-memory-stability-20261123
work/finance-curated-20261123
| 1 | // ============================================================ |
| 2 | // SettingsView — صفحهی تنظیمات، بکاپ، شرکت و Excel |
| 3 | // ============================================================ |
| 4 | |
| 5 | import { SettingsController } from '../controllers/SettingsController.js'; |
| 6 | import { StorageService } from '../core/StorageService.js'; |
| 7 | import { Theme } from '../core/Theme.js'; |
| 8 | import { KeyboardShortcuts } from '../core/KeyboardShortcuts.js'; |
| 9 | import { Modal } from '../core/Modal.js'; |
| 10 | import { Toast } from '../core/Toast.js'; |
| 11 | import { Formatters } from '../utils/Formatters.js'; |
| 12 | import { Auth } from '../core/Auth.js'; |
| 13 | import { ExcelController } from '../controllers/ExcelController.js'; |
| 14 | |
| 15 | let cache = { company: {}, stats: {} }; |
| 16 | |
| 17 | class SettingsViewImpl { |
| 18 | async render() { |
| 19 | await this.reload(); |
| 20 | return ` |
| 21 | <div class="page-title"> |
| 22 | <h2>تنظیمات</h2> |
| 23 | <p>مدیریت اطلاعات شرکت، پشتیبانگیری، Excel و تنظیمات سیستم</p> |
| 24 | </div> |
| 25 | |
| 26 | <div class="settings-grid"> |
| 27 | ${this._renderCompanyCard()} |
| 28 | ${this._renderExcelCard()} |
| 29 | ${this._renderShortcutsCard()} |
| 30 | ${this._renderBackupCard()} |
| 31 | ${this._renderStatsCard()} |
| 32 | ${this._renderThemeCard()} |
| 33 | ${this._renderAboutCard()} |
| 34 | </div> |
| 35 | `; |
| 36 | } |
| 37 | |
| 38 | onMount() { |
| 39 | window.SettingsView = this; |
| 40 | } |
| 41 | |
| 42 | async reload() { |
| 43 | cache.company = await SettingsController.getCompanyInfo(); |
| 44 | cache.stats = await this._collectStats(); |
| 45 | } |
| 46 | |
| 47 | async _collectStats() { |
| 48 | const user = Auth.current(); |
| 49 | if (!user) return {}; |
| 50 | const stores = ['products', 'contacts', 'invoices', 'cheques', 'treasury']; |
| 51 | const stats = {}; |
| 52 | for (const s of stores) { |
| 53 | try { |
| 54 | const list = await StorageService.getByOwner(s, user.id); |
| 55 | if (s === 'treasury') { |
| 56 | stats.accounts = list.filter(x => x.recordType === 'account').length; |
| 57 | stats.transactions = list.filter(x => x.recordType === 'transaction').length; |
| 58 | } else { |
| 59 | stats[s] = list.length; |
| 60 | } |
| 61 | } catch (e) { |
| 62 | stats[s] = 0; |
| 63 | } |
| 64 | } |
| 65 | return stats; |
| 66 | } |
| 67 | |
| 68 | // ============================================================ |
| 69 | // کارت اطلاعات شرکت |
| 70 | // ============================================================ |
| 71 | _renderCompanyCard() { |
| 72 | const c = cache.company; |
| 73 | return ` |
| 74 | <div class="card settings-card"> |
| 75 | <div class="settings-card-header"> |
| 76 | <div class="settings-card-icon">🏢</div> |
| 77 | <div> |
| 78 | <h3 class="settings-card-title">اطلاعات شرکت / فروشگاه</h3> |
| 79 | <p class="settings-card-desc">این اطلاعات در سربرگ فاکتورهای چاپی نمایش داده میشود</p> |
| 80 | </div> |
| 81 | </div> |
| 82 | ${c.name ? ` |
| 83 | <div class="company-preview"> |
| 84 | <div style="font-weight:700;font-size:14px">${this._esc(c.name)}</div> |
| 85 | ${c.nationalId ? `<div style="font-size:11.5px;color:var(--text-muted);margin-top:3px">شناسه ملی: ${Formatters.toPersianDigits(c.nationalId)}</div>` : ''} |
| 86 | ${c.address ? `<div style="font-size:11.5px;color:var(--text-muted);margin-top:2px">${this._esc(c.address)}</div>` : ''} |
| 87 | ${c.phone ? `<div style="font-size:11.5px;color:var(--text-muted);margin-top:2px">تلفن: ${Formatters.phone(c.phone)}</div>` : ''} |
| 88 | </div> |
| 89 | ` : ` |
| 90 | <div class="empty-mini">هنوز اطلاعاتی وارد نشده</div> |
| 91 | `} |
| 92 | <button class="btn" onclick="window.SettingsView.openCompanyModal()"> |
| 93 | ${c.name ? '✏️ ویرایش اطلاعات' : '➕ وارد کردن اطلاعات'} |
| 94 | </button> |
| 95 | </div> |
| 96 | `; |
| 97 | } |
| 98 | |
| 99 | // ============================================================ |
| 100 | // کارت Excel (جدید) |
| 101 | // ============================================================ |
| 102 | _renderExcelCard() { |
| 103 | const s = cache.stats; |
| 104 | return ` |
| 105 | <div class="card settings-card" style="border-color:#bbf7d0;background:linear-gradient(135deg,#f0fdf4,#f8fafc)"> |
| 106 | <div class="settings-card-header"> |
| 107 | <div class="settings-card-icon" style="background:linear-gradient(135deg,#16a34a,#15803d)">📊</div> |
| 108 | <div> |
| 109 | <h3 class="settings-card-title">Excel — خروجی و ورودی</h3> |
| 110 | <p class="settings-card-desc">دادهها را به Excel ببر یا از Excel بیار</p> |
| 111 | </div> |
| 112 | </div> |
| 113 | |
| 114 | <div style="font-size:12.5px;color:var(--text-muted);line-height:1.8;margin-bottom:12px;padding:10px 12px;background:rgba(255,255,255,.6);border-radius:8px"> |
| 115 | <strong>💡 نکته:</strong> از این بخش میتونی کل دادهها رو در یه فایل Excel بگیری، یا از یه فایل Excel (که قبلاً آماده کردی) کالا و اشخاص اضافه کنی. |
| 116 | </div> |
| 117 | |
| 118 | <div style="display:flex;gap:10px;flex-wrap:wrap;margin-bottom:12px"> |
| 119 | <button class="btn" style="background:linear-gradient(135deg,#16a34a,#15803d)" onclick="window.SettingsView.exportAllExcel()"> |
| 120 | 📥 خروجی کامل (Excel) |
| 121 | </button> |
| 122 | <button class="btn btn-secondary" onclick="window.SettingsView.openExportSectionModal()"> |
| 123 | 🎯 خروجی انتخابی |
| 124 | </button> |
| 125 | </div> |
| 126 | |
| 127 | <div style="margin-top:14px;padding-top:14px;border-top:1px dashed var(--border)"> |
| 128 | <div style="font-size:12.5px;font-weight:700;margin-bottom:10px;color:#166534">📤 ورود از Excel</div> |
| 129 | <div style="display:flex;gap:10px;flex-wrap:wrap"> |
| 130 | <button class="btn btn-secondary" onclick="window.SettingsView.importProductsExcel()"> |
| 131 | 📦 ورود کالاها |
| 132 | </button> |
| 133 | <button class="btn btn-secondary" onclick="window.SettingsView.importContactsExcel()"> |
| 134 | 👥 ورود اشخاص |
| 135 | </button> |
| 136 | </div> |
| 137 | </div> |
| 138 | |
| 139 | <div style="margin-top:14px;padding-top:14px;border-top:1px dashed var(--border)"> |
| 140 | <div style="font-size:12.5px;font-weight:700;margin-bottom:10px;color:#166534">📄 قالبهای نمونه</div> |
| 141 | <div style="display:flex;gap:10px;flex-wrap:wrap"> |
| 142 | <button class="btn btn-secondary btn-inline" style="font-size:12px;min-height:34px" onclick="window.SettingsView.downloadProductsTemplate()"> |
| 143 | 📋 قالب کالاها |
| 144 | </button> |
| 145 | <button class="btn btn-secondary btn-inline" style="font-size:12px;min-height:34px" onclick="window.SettingsView.downloadContactsTemplate()"> |
| 146 | 📋 قالب اشخاص |
| 147 | </button> |
| 148 | </div> |
| 149 | </div> |
| 150 | </div> |
| 151 | `; |
| 152 | } |
| 153 | |
| 154 | async exportAllExcel() { |
| 155 | try { |
| 156 | Toast.info('در حال آمادهسازی فایل Excel...'); |
| 157 | const result = await ExcelController.exportAll(); |
| 158 | Toast.success(`فایل Excel با ${Formatters.toPersianDigits(result.sheets)} شیت دانلود شد`); |
| 159 | } catch (err) { |
| 160 | console.error(err); |
| 161 | Toast.error('خطا در خروجی: ' + err.message); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | openExportSectionModal() { |
| 166 | const body = ` |
| 167 | <p style="font-size:13px;color:var(--text-muted);margin-bottom:14px">کدوم بخش رو میخوای به Excel ببری؟</p> |
| 168 | <div style="display:grid;grid-template-columns:1fr 1fr;gap:10px"> |
| 169 | <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('products')"> |
| 170 | <div style="font-size:22px">📦</div> |
| 171 | <div style="font-size:12.5px">کالاها</div> |
| 172 | </button> |
| 173 | <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('contacts')"> |
| 174 | <div style="font-size:22px">👥</div> |
| 175 | <div style="font-size:12.5px">اشخاص</div> |
| 176 | </button> |
| 177 | <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('invoices')"> |
| 178 | <div style="font-size:22px">🧾</div> |
| 179 | <div style="font-size:12.5px">فاکتورها</div> |
| 180 | </button> |
| 181 | <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('cheques')"> |
| 182 | <div style="font-size:22px">💳</div> |
| 183 | <div style="font-size:12.5px">چکها</div> |
| 184 | </button> |
| 185 | <button class="btn btn-secondary" style="min-height:80px;flex-direction:column;gap:6px" onclick="window.SettingsView._exportSection('expenses')"> |
| 186 | <div style="font-size:22px">💰</div> |
| 187 | <div style="font-size:12.5px">هزینه و درآمد</div> |
| 188 | </button> |
| 189 | </div> |
| 190 | `; |
| 191 | const footer = `<button class="btn btn-secondary" onclick="FINORA.Modal.close()">بستن</button>`; |
| 192 | Modal.open({ title: '🎯 خروجی انتخابی به Excel', body, footer, size: 'md' }); |
| 193 | } |
| 194 | |
| 195 | async _exportSection(section) { |
| 196 | try { |
| 197 | const result = await ExcelController.exportSection(section); |
| 198 | Toast.success(`فایل دانلود شد (${Formatters.number(result.count)} مورد)`); |
| 199 | Modal.close(); |
| 200 | } catch (err) { |
| 201 | Toast.error('خطا: ' + err.message); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // ============================================================ |
| 206 | // ورودی از Excel |
| 207 | // ============================================================ |
| 208 | importProductsExcel() { |
| 209 | const input = document.createElement('input'); |
| 210 | input.type = 'file'; |
| 211 | input.accept = '.xlsx,.xls'; |
| 212 | input.onchange = async (e) => { |
| 213 | const file = e.target.files[0]; |
| 214 | if (!file) return; |
| 215 | await this._handleImportFile(file, 'products'); |
| 216 | }; |
| 217 | input.click(); |
| 218 | } |
| 219 | |
| 220 | importContactsExcel() { |
| 221 | const input = document.createElement('input'); |
| 222 | input.type = 'file'; |
| 223 | input.accept = '.xlsx,.xls'; |
| 224 | input.onchange = async (e) => { |
| 225 | const file = e.target.files[0]; |
| 226 | if (!file) return; |
| 227 | await this._handleImportFile(file, 'contacts'); |
| 228 | }; |
| 229 | input.click(); |
| 230 | } |
| 231 | |
| 232 | async _handleImportFile(file, kind) { |
| 233 | try { |
| 234 | Toast.info('در حال خواندن فایل...'); |
| 235 | const preview = await ExcelController.previewFile(file); |
| 236 | |
| 237 | const kindLabel = kind === 'products' ? 'کالاها' : 'اشخاص'; |
| 238 | const sheetsHtml = preview.sheets.map(s => ` |
| 239 | <div style="padding:8px 12px;background:var(--bg);border-radius:8px;margin-bottom:6px;font-size:12.5px"> |
| 240 | <strong>${this._esc(s.name)}</strong> |
| 241 | <span style="color:var(--text-muted);margin-right:6px">(${Formatters.number(s.count)} سطر)</span> |
| 242 | </div> |
| 243 | `).join(''); |
| 244 | |
| 245 | const body = ` |
| 246 | <p style="font-size:13px;color:var(--text-muted);margin-bottom:12px"> |
| 247 | فایل <strong>${this._esc(file.name)}</strong> خونده شد. شیتهای موجود: |
| 248 | </p> |
| 249 | ${sheetsHtml} |
| 250 | <div class="form-group" style="margin-top:14px"> |
| 251 | <label class="form-label">حالت ورود</label> |
| 252 | <select class="form-control" id="importMode"> |
| 253 | <option value="merge">🔀 ادغام (Merge) — فقط موارد جدید اضافه میشن</option> |
| 254 | <option value="replace">🔄 جایگزینی (Replace) — همهی ${kindLabel} فعلی پاک و از فایل جایگزین میشن</option> |
| 255 | </select> |
| 256 | </div> |
| 257 | `; |
| 258 | const footer = ` |
| 259 | <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button> |
| 260 | <button class="btn btn-success" onclick="window.SettingsView._confirmImport(${JSON.stringify(kind).replace(/"/g, "'")}, '${this._esc(file.name)}')">✅ شروع ایمپورت</button> |
| 261 | `; |
| 262 | Modal.open({ title: `📤 ورود ${kindLabel} از Excel`, body, footer, size: 'md' }); |
| 263 | |
| 264 | // ذخیرهی موقت داده |
| 265 | window.__importRawData = preview.raw; |
| 266 | window.__importKind = kind; |
| 267 | } catch (err) { |
| 268 | console.error(err); |
| 269 | Toast.error('خطا: ' + err.message); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | async _confirmImport(kind, fileName) { |
| 274 | const mode = document.getElementById('importMode').value; |
| 275 | const rawData = window.__importRawData; |
| 276 | |
| 277 | if (!rawData) { |
| 278 | Toast.error('دادهای برای ایمپورت نیست'); |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | try { |
| 283 | Toast.info('در حال ایمپورت...'); |
| 284 | let result; |
| 285 | if (kind === 'products') { |
| 286 | result = await ExcelController.importProducts(rawData, { mode }); |
| 287 | } else { |
| 288 | result = await ExcelController.importContacts(rawData, { mode }); |
| 289 | } |
| 290 | |
| 291 | Modal.close(); |
| 292 | Toast.success(`ایمپورت انجام شد: ${Formatters.number(result.added)} اضافه، ${Formatters.number(result.skipped)} رد شده`); |
| 293 | |
| 294 | // رفرش KPI ها |
| 295 | await this.reload(); |
| 296 | const grid = document.querySelector('.settings-grid'); |
| 297 | if (grid) grid.innerHTML = this._renderAllCards(); |
| 298 | } catch (err) { |
| 299 | console.error(err); |
| 300 | Toast.error('خطا در ایمپورت: ' + err.message); |
| 301 | } finally { |
| 302 | window.__importRawData = null; |
| 303 | window.__importKind = null; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | downloadProductsTemplate() { |
| 308 | ExcelController.downloadProductsTemplate(); |
| 309 | Toast.success('قالب کالاها دانلود شد'); |
| 310 | } |
| 311 | |
| 312 | downloadContactsTemplate() { |
| 313 | ExcelController.downloadContactsTemplate(); |
| 314 | Toast.success('قالب اشخاص دانلود شد'); |
| 315 | } |
| 316 | |
| 317 | // ============================================================ |
| 318 | // کارت میانبرهای صفحهکلید |
| 319 | // ============================================================ |
| 320 | _renderShortcutsCard() { |
| 321 | const s = KeyboardShortcuts.settings; |
| 322 | |
| 323 | const toggle = (id, checked, label, hint) => ` |
| 324 | <label style="display:flex;align-items:flex-start;gap:10px;padding:9px 0;cursor:pointer;border-bottom:1px solid var(--border)"> |
| 325 | <input type="checkbox" id="${id}" ${checked ? 'checked' : ''} style="margin-top:3px;width:16px;height:16px;cursor:pointer" /> |
| 326 | <div style="flex:1"> |
| 327 | <div style="font-size:13px;font-weight:600">${label}</div> |
| 328 | <div style="font-size:11px;color:var(--text-muted);margin-top:2px;line-height:1.6">${hint}</div> |
| 329 | </div> |
| 330 | </label> |
| 331 | `; |
| 332 | |
| 333 | return ` |
| 334 | <div class="card settings-card" style="border-color:#ddd6fe;background:linear-gradient(135deg,#faf5ff,#f8fafc)"> |
| 335 | <div class="settings-card-header"> |
| 336 | <div class="settings-card-icon" style="background:linear-gradient(135deg,#8b5cf6,#6d28d9)">⌨️</div> |
| 337 | <div> |
| 338 | <h3 class="settings-card-title">میانبرهای صفحهکلید</h3> |
| 339 | <p class="settings-card-desc">با این میانبرها کار با برنامه سریعتر میشود</p> |
| 340 | </div> |
| 341 | </div> |
| 342 | |
| 343 | ${toggle('scEnabled', s.enabled, 'فعال بودن میانبرها', 'کلاً همهی میانبرهای زیر رو روشن یا خاموش میکند')} |
| 344 | ${toggle('scEnterConfirms', s.enterConfirms, 'تأیید با Enter', 'وقتی توی فرم هستید، Enter مثل دکمهی ذخیره عمل میکند. Ctrl+Enter هم توی همهی فیلدها کار میکند')} |
| 345 | ${toggle('scEscapeCloses', s.escapeCloses, 'بستن با Escape', 'فشار دادن Escape، مودال باز را میبندد')} |
| 346 | ${toggle('scCtrlSaves', s.ctrlSaves, 'ذخیره با Ctrl+S', 'داخل مودالها، Ctrl+S فرم را ذخیره میکند')} |
| 347 | ${toggle('scPlusMinusZeros', s.plusMinusZeros, 'ضریب سریع صفر (+ و -)', 'روی فیلدهای مبلغ، کلید + صفر اضافه و کلید − صفر کم میکند')} |
| 348 | |
| 349 | <div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:14px;padding-top:14px;border-top:1px dashed var(--border)"> |
| 350 | <div class="form-group" style="margin-bottom:0"> |
| 351 | <label class="form-label">تعداد صفرهای کلید +</label> |
| 352 | <input type="text" inputmode="numeric" class="form-control" id="scPlusZeros" value="${Formatters.toPersianDigits(s.plusZeros)}" /> |
| 353 | </div> |
| 354 | <div class="form-group" style="margin-bottom:0"> |
| 355 | <label class="form-label">تعداد صفرهای کلید −</label> |
| 356 | <input type="text" inputmode="numeric" class="form-control" id="scMinusZeros" value="${Formatters.toPersianDigits(s.minusZeros)}" /> |
| 357 | </div> |
| 358 | </div> |
| 359 | |
| 360 | <div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:14px"> |
| 361 | <button class="btn" onclick="window.SettingsView.saveShortcuts()">💾 ذخیره تنظیمات</button> |
| 362 | <button class="btn btn-secondary" onclick="window.SettingsView.resetShortcuts()">↺ بازگشت به پیشفرض</button> |
| 363 | </div> |
| 364 | </div> |
| 365 | `; |
| 366 | } |
| 367 | |
| 368 | saveShortcuts() { |
| 369 | try { |
| 370 | const plusZeros = parseInt(Formatters.toLatinDigits(document.getElementById('scPlusZeros').value)) || 0; |
| 371 | const minusZeros = parseInt(Formatters.toLatinDigits(document.getElementById('scMinusZeros').value)) || 0; |
| 372 | |
| 373 | const settings = { |
| 374 | enabled: document.getElementById('scEnabled').checked, |
| 375 | enterConfirms: document.getElementById('scEnterConfirms').checked, |
| 376 | escapeCloses: document.getElementById('scEscapeCloses').checked, |
| 377 | ctrlSaves: document.getElementById('scCtrlSaves').checked, |
| 378 | plusMinusZeros: document.getElementById('scPlusMinusZeros').checked, |
| 379 | plusZeros: Math.max(0, Math.min(12, plusZeros)), |
| 380 | minusZeros: Math.max(0, Math.min(12, minusZeros)) |
| 381 | }; |
| 382 | |
| 383 | KeyboardShortcuts.saveSettings(settings); |
| 384 | Toast.success('تنظیمات میانبرهای صفحهکلید ذخیره شد'); |
| 385 | } catch (err) { |
| 386 | Toast.error('خطا: ' + err.message); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | resetShortcuts() { |
| 391 | Modal.confirm({ |
| 392 | title: 'بازگشت به پیشفرض', |
| 393 | message: 'آیا میخواهید همهی تنظیمات میانبرهای صفحهکلید به حالت پیشفرض برگردد؟', |
| 394 | confirmText: 'بازگردان', |
| 395 | onConfirm: () => { |
| 396 | KeyboardShortcuts.resetSettings(); |
| 397 | Toast.success('تنظیمات به حالت پیشفرض برگشت'); |
| 398 | const grid = document.querySelector('.settings-grid'); |
| 399 | if (grid) grid.innerHTML = this._renderAllCards(); |
| 400 | } |
| 401 | }); |
| 402 | } |
| 403 | |
| 404 | // ============================================================ |
| 405 | // کارت بکاپ |
| 406 | // ============================================================ |
| 407 | _renderBackupCard() { |
| 408 | return ` |
| 409 | <div class="card settings-card" style="border-color:#bfdbfe;background:linear-gradient(135deg,#eff6ff,#f8fafc)"> |
| 410 | <div class="settings-card-header"> |
| 411 | <div class="settings-card-icon" style="background:linear-gradient(135deg,#3b82f6,#1e40af)">💾</div> |
| 412 | <div> |
| 413 | <h3 class="settings-card-title">پشتیبانگیری JSON</h3> |
| 414 | <p class="settings-card-desc">پشتیبانگیری کامل از دیتابیس (فقط JSON، نه Excel)</p> |
| 415 | </div> |
| 416 | </div> |
| 417 | |
| 418 | <div class="backup-warning"> |
| 419 | ⚠️ <strong>مهم:</strong> قبل از هر تغییر بزرگ در برنامه، حتماً بکاپ بگیرید. |
| 420 | </div> |
| 421 | |
| 422 | <div style="display:flex;gap:10px;flex-wrap:wrap;margin-top:14px"> |
| 423 | <button class="btn" onclick="window.SettingsView.downloadBackup()"> |
| 424 | 📥 دانلود فایل بکاپ |
| 425 | </button> |
| 426 | <button class="btn btn-secondary" onclick="window.SettingsView.openRestoreModal()"> |
| 427 | 📤 بازیابی از بکاپ |
| 428 | </button> |
| 429 | </div> |
| 430 | |
| 431 | <div style="margin-top:16px;padding-top:14px;border-top:1px dashed var(--border)"> |
| 432 | <button class="btn btn-danger btn-inline" style="font-size:12px;min-height:34px" onclick="window.SettingsView.openWipeModal()"> |
| 433 | 🗑️ پاک کردن کامل دادهها |
| 434 | </button> |
| 435 | <small style="color:var(--text-muted);font-size:11px;display:block;margin-top:6px">این عمل قابل بازگشت نیست، حتماً قبلش بکاپ بگیرید</small> |
| 436 | </div> |
| 437 | </div> |
| 438 | `; |
| 439 | } |
| 440 | |
| 441 | // ============================================================ |
| 442 | // کارت آمار |
| 443 | // ============================================================ |
| 444 | _renderStatsCard() { |
| 445 | const s = cache.stats; |
| 446 | const items = [ |
| 447 | { label: 'کالا و خدمات', value: s.products || 0, icon: '📦' }, |
| 448 | { label: 'اشخاص', value: s.contacts || 0, icon: '👥' }, |
| 449 | { label: 'فاکتورها', value: s.invoices || 0, icon: '🧾' }, |
| 450 | { label: 'چکها', value: s.cheques || 0, icon: '💳' }, |
| 451 | { label: 'حسابها', value: s.accounts || 0, icon: '🏦' }, |
| 452 | { label: 'تراکنشها', value: s.transactions || 0, icon: '💸' } |
| 453 | ]; |
| 454 | return ` |
| 455 | <div class="card settings-card"> |
| 456 | <div class="settings-card-header"> |
| 457 | <div class="settings-card-icon" style="background:linear-gradient(135deg,#0ea5e9,#0369a1)">📊</div> |
| 458 | <div> |
| 459 | <h3 class="settings-card-title">آمار دادهها</h3> |
| 460 | <p class="settings-card-desc">خلاصهی دادههای ذخیرهشده در سیستم</p> |
| 461 | </div> |
| 462 | </div> |
| 463 | <div class="stats-grid"> |
| 464 | ${items.map(i => ` |
| 465 | <div class="stat-mini"> |
| 466 | <div style="font-size:18px;margin-bottom:4px">${i.icon}</div> |
| 467 | <div style="font-size:18px;font-weight:800;color:var(--primary)">${Formatters.number(i.value)}</div> |
| 468 | <div style="font-size:11px;color:var(--text-muted);margin-top:2px">${i.label}</div> |
| 469 | </div> |
| 470 | `).join('')} |
| 471 | </div> |
| 472 | </div> |
| 473 | `; |
| 474 | } |
| 475 | |
| 476 | // ============================================================ |
| 477 | // کارت تم |
| 478 | // ============================================================ |
| 479 | _renderThemeCard() { |
| 480 | const current = Theme.current(); |
| 481 | return ` |
| 482 | <div class="card settings-card"> |
| 483 | <div class="settings-card-header"> |
| 484 | <div class="settings-card-icon" style="background:linear-gradient(135deg,#8b5cf6,#6d28d9)">🎨</div> |
| 485 | <div> |
| 486 | <h3 class="settings-card-title">ظاهر و تم</h3> |
| 487 | <p class="settings-card-desc">حالت نمایش برنامه</p> |
| 488 | </div> |
| 489 | </div> |
| 490 | <div style="display:flex;gap:10px;margin-top:8px"> |
| 491 | <button class="btn ${current === 'light' ? '' : 'btn-secondary'}" onclick="window.SettingsView.setTheme('light')">☀️ روشن</button> |
| 492 | <button class="btn ${current === 'dark' ? '' : 'btn-secondary'}" onclick="window.SettingsView.setTheme('dark')">🌙 تاریک</button> |
| 493 | </div> |
| 494 | </div> |
| 495 | `; |
| 496 | } |
| 497 | |
| 498 | // ============================================================ |
| 499 | // کارت درباره |
| 500 | // ============================================================ |
| 501 | _renderAboutCard() { |
| 502 | return ` |
| 503 | <div class="card settings-card"> |
| 504 | <div class="settings-card-header"> |
| 505 | <div class="settings-card-icon">ℹ️</div> |
| 506 | <div> |
| 507 | <h3 class="settings-card-title">درباره فینورا پرو</h3> |
| 508 | <p class="settings-card-desc">نسخه ۰.۱.۰</p> |
| 509 | </div> |
| 510 | </div> |
| 511 | <div style="font-size:13px;line-height:1.9;color:var(--text-muted)"> |
| 512 | <div><strong>طراح و توسعهدهنده:</strong> داوود مهربان</div> |
| 513 | <div><strong>تماس:</strong> <span dir="ltr">0912-437-6991</span></div> |
| 514 | <div style="margin-top:8px;padding-top:10px;border-top:1px dashed var(--border)"> |
| 515 | <a href="https://wa.me/989124376991" target="_blank" class="btn btn-inline" style="background:linear-gradient(135deg,#25D366,#128C7E);font-size:12.5px;min-height:36px">💬 واتساپ پشتیبانی</a> |
| 516 | </div> |
| 517 | </div> |
| 518 | </div> |
| 519 | `; |
| 520 | } |
| 521 | |
| 522 | _renderAllCards() { |
| 523 | return this._renderCompanyCard() |
| 524 | + this._renderExcelCard() |
| 525 | + this._renderShortcutsCard() |
| 526 | + this._renderBackupCard() |
| 527 | + this._renderStatsCard() |
| 528 | + this._renderThemeCard() |
| 529 | + this._renderAboutCard(); |
| 530 | } |
| 531 | |
| 532 | // ============================================================ |
| 533 | // فرم اطلاعات شرکت |
| 534 | // ============================================================ |
| 535 | openCompanyModal() { |
| 536 | const c = cache.company; |
| 537 | const body = ` |
| 538 | <div class="form-row"> |
| 539 | <div class="form-group"> |
| 540 | <label class="form-label">نوع شخص</label> |
| 541 | <select class="form-control" id="coEntityType"> |
| 542 | <option value="legal" ${c.entityType === 'legal' ? 'selected' : ''}>حقوقی</option> |
| 543 | <option value="natural" ${c.entityType === 'natural' ? 'selected' : ''}>حقیقی</option> |
| 544 | </select> |
| 545 | </div> |
| 546 | <div class="form-group"> |
| 547 | <label class="form-label">نام شرکت / فروشگاه <span class="req">*</span></label> |
| 548 | <input type="text" class="form-control" id="coName" value="${this._esc(c.name)}" /> |
| 549 | </div> |
| 550 | </div> |
| 551 | <div class="form-row"> |
| 552 | <div class="form-group"> |
| 553 | <label class="form-label">شناسه ملی / کد ملی</label> |
| 554 | <input type="text" class="form-control" id="coNationalId" value="${this._esc(c.nationalId)}" /> |
| 555 | </div> |
| 556 | <div class="form-group"> |
| 557 | <label class="form-label">کد اقتصادی</label> |
| 558 | <input type="text" class="form-control" id="coEconomicCode" value="${this._esc(c.economicCode)}" /> |
| 559 | </div> |
| 560 | </div> |
| 561 | <div class="form-row"> |
| 562 | <div class="form-group"> |
| 563 | <label class="form-label">شماره ثبت</label> |
| 564 | <input type="text" class="form-control" id="coRegNumber" value="${this._esc(c.regNumber)}" /> |
| 565 | </div> |
| 566 | <div class="form-group"> |
| 567 | <label class="form-label">کد پستی</label> |
| 568 | <input type="text" class="form-control" id="coPostalCode" value="${this._esc(c.postalCode)}" /> |
| 569 | </div> |
| 570 | </div> |
| 571 | <div class="form-row"> |
| 572 | <div class="form-group"> |
| 573 | <label class="form-label">تلفن</label> |
| 574 | <input type="tel" class="form-control" id="coPhone" value="${this._esc(c.phone)}" /> |
| 575 | </div> |
| 576 | <div class="form-group"> |
| 577 | <label class="form-label">موبایل</label> |
| 578 | <input type="tel" class="form-control" id="coMobile" value="${this._esc(c.mobile)}" /> |
| 579 | </div> |
| 580 | </div> |
| 581 | <div class="form-group"> |
| 582 | <label class="form-label">نشانی</label> |
| 583 | <textarea class="form-control" id="coAddress" rows="2">${this._esc(c.address)}</textarea> |
| 584 | </div> |
| 585 | <div class="form-group"> |
| 586 | <label class="form-label">پاورقی فاکتور</label> |
| 587 | <textarea class="form-control" id="coFooter" rows="2" placeholder="مثلاً: از خرید شما سپاسگزاریم">${this._esc(c.footer)}</textarea> |
| 588 | </div> |
| 589 | `; |
| 590 | const footer = ` |
| 591 | <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button> |
| 592 | <button class="btn" onclick="window.SettingsView.saveCompany()">💾 ذخیره</button> |
| 593 | `; |
| 594 | Modal.open({ title: 'اطلاعات شرکت', body, footer, size: 'md' }); |
| 595 | } |
| 596 | |
| 597 | async saveCompany() { |
| 598 | const data = { |
| 599 | name: document.getElementById('coName').value, |
| 600 | entityType: document.getElementById('coEntityType').value, |
| 601 | nationalId: document.getElementById('coNationalId').value, |
| 602 | economicCode: document.getElementById('coEconomicCode').value, |
| 603 | regNumber: document.getElementById('coRegNumber').value, |
| 604 | postalCode: document.getElementById('coPostalCode').value, |
| 605 | phone: document.getElementById('coPhone').value, |
| 606 | mobile: document.getElementById('coMobile').value, |
| 607 | address: document.getElementById('coAddress').value, |
| 608 | footer: document.getElementById('coFooter').value |
| 609 | }; |
| 610 | if (!data.name.trim()) { Toast.warning('نام الزامی است'); return; } |
| 611 | try { |
| 612 | await SettingsController.saveCompanyInfo(data); |
| 613 | Toast.success('اطلاعات ذخیره شد'); |
| 614 | Modal.close(); |
| 615 | await this.reload(); |
| 616 | const grid = document.querySelector('.settings-grid'); |
| 617 | if (grid) grid.innerHTML = this._renderAllCards(); |
| 618 | } catch (err) { |
| 619 | Toast.error('خطا: ' + err.message); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | // ============================================================ |
| 624 | // بکاپ JSON |
| 625 | // ============================================================ |
| 626 | async downloadBackup() { |
| 627 | try { |
| 628 | Toast.info('در حال آمادهسازی بکاپ...'); |
| 629 | const result = await SettingsController.downloadBackup(); |
| 630 | Toast.success(`بکاپ دانلود شد (${result.filename})`, 'موفق'); |
| 631 | } catch (err) { |
| 632 | Toast.error('خطا در بکاپ: ' + err.message); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | openRestoreModal() { |
| 637 | const body = ` |
| 638 | <div class="backup-warning" style="margin-bottom:14px"> |
| 639 | ⚠️ <strong>هشدار:</strong> در حالت Merge، دادههای تکراری skip میشن. در حالت Replace، همهچیز با بکاپ جایگزین میشه. |
| 640 | </div> |
| 641 | |
| 642 | <div class="form-group"> |
| 643 | <label class="form-label">فایل بکاپ (JSON)</label> |
| 644 | <input type="file" class="form-control" id="restoreFile" accept=".json,application/json" /> |
| 645 | </div> |
| 646 | |
| 647 | <div class="form-group"> |
| 648 | <label class="form-label">حالت بازیابی</label> |
| 649 | <select class="form-control" id="restoreMode"> |
| 650 | <option value="merge">🔀 ادغام (Merge) — دادههای جدید اضافه میشن</option> |
| 651 | <option value="replace">🔄 جایگزینی (Replace) — همهچیز با بکاپ عوض میشه</option> |
| 652 | </select> |
| 653 | </div> |
| 654 | `; |
| 655 | const footer = ` |
| 656 | <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button> |
| 657 | <button class="btn" onclick="window.SettingsView.restoreBackup()">📤 بازیابی</button> |
| 658 | `; |
| 659 | Modal.open({ title: 'بازیابی از بکاپ', body, footer, size: 'md' }); |
| 660 | } |
| 661 | |
| 662 | async restoreBackup() { |
| 663 | const fileInput = document.getElementById('restoreFile'); |
| 664 | const file = fileInput.files[0]; |
| 665 | if (!file) { Toast.warning('فایل بکاپ رو انتخاب کنید'); return; } |
| 666 | |
| 667 | const mode = document.getElementById('restoreMode').value; |
| 668 | |
| 669 | try { |
| 670 | Toast.info('در حال بازیابی...'); |
| 671 | const content = await SettingsController.readFileAsText(file); |
| 672 | const counts = await SettingsController.importBackup(content, { mode }); |
| 673 | Modal.close(); |
| 674 | Toast.success(`بازیابی انجام شد: ${counts.added} مورد اضافه، ${counts.skipped} مورد skip`); |
| 675 | setTimeout(() => location.reload(), 1500); |
| 676 | } catch (err) { |
| 677 | Toast.error('خطا: ' + err.message); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | // ============================================================ |
| 682 | // پاک کردن کامل |
| 683 | // ============================================================ |
| 684 | openWipeModal() { |
| 685 | const body = ` |
| 686 | <div style="text-align:center;padding:10px 0"> |
| 687 | <div style="font-size:48px;margin-bottom:12px">⚠️</div> |
| 688 | <h3 style="color:var(--danger);margin-bottom:8px">پاک کردن کامل دادهها</h3> |
| 689 | <p style="color:var(--text-muted);font-size:13px;line-height:1.8;margin-bottom:16px"> |
| 690 | این عمل همهی کالاها، اشخاص، فاکتورها، چکها، تراکنشها و تنظیمات رو برای همیشه پاک میکند. |
| 691 | <br><strong>قابل بازگشت نیست!</strong> |
| 692 | </p> |
| 693 | <p style="font-size:12px;color:var(--danger);margin-bottom:16px"> |
| 694 | لطفاً برای تأیید، کلمهی <code style="background:var(--danger);color:#fff;padding:2px 8px;border-radius:4px">حذف</code> رو تایپ کنید |
| 695 | </p> |
| 696 | <input type="text" class="form-control" id="wipeConfirm" placeholder="حذف" style="text-align:center;max-width:200px;margin:0 auto" /> |
| 697 | </div> |
| 698 | `; |
| 699 | const footer = ` |
| 700 | <button class="btn btn-secondary" onclick="FINORA.Modal.close()">انصراف</button> |
| 701 | <button class="btn btn-danger" onclick="window.SettingsView.confirmWipe()">🗑️ پاک کن</button> |
| 702 | `; |
| 703 | Modal.open({ title: 'تأیید پاک کردن', body, footer, size: 'sm' }); |
| 704 | } |
| 705 | |
| 706 | async confirmWipe() { |
| 707 | const confirmText = document.getElementById('wipeConfirm').value.trim(); |
| 708 | if (confirmText !== 'حذف') { |
| 709 | Toast.warning('متن تأیید اشتباه است'); |
| 710 | return; |
| 711 | } |
| 712 | try { |
| 713 | await SettingsController.wipeAll(); |
| 714 | Toast.success('همهی دادهها پاک شد'); |
| 715 | setTimeout(() => location.reload(), 800); |
| 716 | } catch (err) { |
| 717 | Toast.error('خطا: ' + err.message); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | // ============================================================ |
| 722 | // Theme |
| 723 | // ============================================================ |
| 724 | setTheme(theme) { |
| 725 | Theme.apply(theme); |
| 726 | const grid = document.querySelector('.settings-grid'); |
| 727 | if (grid) grid.innerHTML = this._renderAllCards(); |
| 728 | } |
| 729 | |
| 730 | _esc(s) { |
| 731 | if (!s) return ''; |
| 732 | return String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | export const SettingsView = new SettingsViewImpl(); |
| 737 | window.SettingsView = SettingsView; |