ishash commited on
Commit
3383bbb
·
verified ·
1 Parent(s): 531c768

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +912 -19
index.html CHANGED
@@ -1,19 +1,912 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>SalesForce ERP - Goal Tracker</title>
7
+ <!-- Importing Google Fonts for modern typography -->
8
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
9
+ <!-- Importing FontAwesome for Icons -->
10
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
11
+
12
+ <style>
13
+ :root {
14
+ /* Color Palette - Modern Enterprise Dark/Light Theme */
15
+ --primary: #4f46e5; /* Indigo */
16
+ --primary-hover: #4338ca;
17
+ --secondary: #64748b;
18
+ --bg-body: #f1f5f9;
19
+ --bg-card: #ffffff;
20
+ --text-main: #1e293b;
21
+ --text-muted: #64748b;
22
+ --border: #e2e8f0;
23
+ --success: #10b981;
24
+ --warning: #f59e0b;
25
+ --danger: #ef4444;
26
+ --radius: 12px;
27
+ --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
28
+ --transition: all 0.3s ease;
29
+ }
30
+
31
+ * {
32
+ box-sizing: border-box;
33
+ margin: 0;
34
+ padding: 0;
35
+ font-family: 'Inter', sans-serif;
36
+ }
37
+
38
+ body {
39
+ background-color: var(--bg-body);
40
+ color: var(--text-main);
41
+ min-height: 100vh;
42
+ display: flex;
43
+ flex-direction: column;
44
+ }
45
+
46
+ /* --- Header --- */
47
+ header {
48
+ background-color: var(--bg-card);
49
+ border-bottom: 1px solid var(--border);
50
+ padding: 1rem 2rem;
51
+ display: flex;
52
+ justify-content: space-between;
53
+ align-items: center;
54
+ position: sticky;
55
+ top: 0;
56
+ z-index: 100;
57
+ }
58
+
59
+ .brand {
60
+ display: flex;
61
+ align-items: center;
62
+ gap: 0.75rem;
63
+ }
64
+
65
+ .brand i {
66
+ font-size: 1.5rem;
67
+ color: var(--primary);
68
+ }
69
+
70
+ .brand h1 {
71
+ font-size: 1.25rem;
72
+ font-weight: 700;
73
+ color: var(--text-main);
74
+ }
75
+
76
+ .built-with {
77
+ font-size: 0.8rem;
78
+ color: var(--text-muted);
79
+ text-decoration: none;
80
+ padding: 0.5rem 1rem;
81
+ background: #f8fafc;
82
+ border-radius: 20px;
83
+ transition: var(--transition);
84
+ }
85
+
86
+ .built-with:hover {
87
+ background: var(--primary);
88
+ color: white;
89
+ }
90
+
91
+ /* --- Layout --- */
92
+ .container {
93
+ flex: 1;
94
+ max-width: 1200px;
95
+ margin: 0 auto;
96
+ width: 100%;
97
+ padding: 2rem;
98
+ }
99
+
100
+ /* --- Navigation Tabs --- */
101
+ .tabs {
102
+ display: flex;
103
+ gap: 1rem;
104
+ margin-bottom: 2rem;
105
+ border-bottom: 2px solid var(--border);
106
+ padding-bottom: 0.5rem;
107
+ overflow-x: auto;
108
+ }
109
+
110
+ .tab-btn {
111
+ background: none;
112
+ border: none;
113
+ padding: 0.75rem 1.5rem;
114
+ font-size: 1rem;
115
+ font-weight: 600;
116
+ color: var(--text-muted);
117
+ cursor: pointer;
118
+ position: relative;
119
+ transition: var(--transition);
120
+ white-space: nowrap;
121
+ }
122
+
123
+ .tab-btn:hover {
124
+ color: var(--primary);
125
+ }
126
+
127
+ .tab-btn.active {
128
+ color: var(--primary);
129
+ }
130
+
131
+ .tab-btn.active::after {
132
+ content: '';
133
+ position: absolute;
134
+ bottom: -0.5rem; /* Align with border-bottom */
135
+ left: 0;
136
+ width: 100%;
137
+ height: 3px;
138
+ background-color: var(--primary);
139
+ border-radius: 3px 3px 0 0;
140
+ }
141
+
142
+ /* --- Content Sections --- */
143
+ .tab-content {
144
+ display: none;
145
+ animation: fadeIn 0.4s ease-out;
146
+ }
147
+
148
+ .tab-content.active {
149
+ display: block;
150
+ }
151
+
152
+ @keyframes fadeIn {
153
+ from { opacity: 0; transform: translateY(10px); }
154
+ to { opacity: 1; transform: translateY(0); }
155
+ }
156
+
157
+ /* --- Tab 1: Goal Setting --- */
158
+ .goal-grid {
159
+ display: grid;
160
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
161
+ gap: 1.5rem;
162
+ }
163
+
164
+ .card {
165
+ background: var(--bg-card);
166
+ border-radius: var(--radius);
167
+ padding: 1.5rem;
168
+ box-shadow: var(--shadow);
169
+ border: 1px solid var(--border);
170
+ }
171
+
172
+ .card-header {
173
+ display: flex;
174
+ justify-content: space-between;
175
+ align-items: center;
176
+ margin-bottom: 1.5rem;
177
+ }
178
+
179
+ .card-title {
180
+ font-size: 1.1rem;
181
+ font-weight: 600;
182
+ }
183
+
184
+ .form-group {
185
+ margin-bottom: 1rem;
186
+ }
187
+
188
+ .form-label {
189
+ display: block;
190
+ font-size: 0.875rem;
191
+ color: var(--text-muted);
192
+ margin-bottom: 0.5rem;
193
+ }
194
+
195
+ .form-control {
196
+ width: 100%;
197
+ padding: 0.75rem;
198
+ border: 1px solid var(--border);
199
+ border-radius: 8px;
200
+ font-size: 1rem;
201
+ transition: var(--transition);
202
+ }
203
+
204
+ .form-control:focus {
205
+ outline: none;
206
+ border-color: var(--primary);
207
+ box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
208
+ }
209
+
210
+ .btn {
211
+ display: inline-flex;
212
+ align-items: center;
213
+ justify-content: center;
214
+ gap: 0.5rem;
215
+ padding: 0.75rem 1.5rem;
216
+ border-radius: 8px;
217
+ font-weight: 500;
218
+ cursor: pointer;
219
+ border: none;
220
+ transition: var(--transition);
221
+ }
222
+
223
+ .btn-primary {
224
+ background-color: var(--primary);
225
+ color: white;
226
+ }
227
+
228
+ .btn-primary:hover {
229
+ background-color: var(--primary-hover);
230
+ }
231
+
232
+ .btn-danger {
233
+ background-color: #fee2e2;
234
+ color: var(--danger);
235
+ padding: 0.4rem 0.8rem;
236
+ font-size: 0.8rem;
237
+ }
238
+
239
+ .btn-danger:hover {
240
+ background-color: #fecaca;
241
+ }
242
+
243
+ .goal-list {
244
+ list-style: none;
245
+ margin-top: 1rem;
246
+ }
247
+
248
+ .goal-item {
249
+ display: flex;
250
+ justify-content: space-between;
251
+ align-items: center;
252
+ padding: 1rem;
253
+ border-bottom: 1px solid var(--border);
254
+ }
255
+
256
+ .goal-item:last-child {
257
+ border-bottom: none;
258
+ }
259
+
260
+ .goal-info h4 {
261
+ font-size: 0.95rem;
262
+ margin-bottom: 0.25rem;
263
+ }
264
+
265
+ .goal-info p {
266
+ font-size: 0.8rem;
267
+ color: var(--text-muted);
268
+ }
269
+
270
+ /* --- Tab 2: Tracking --- */
271
+ .tracking-layout {
272
+ display: grid;
273
+ grid-template-columns: 2fr 1fr;
274
+ gap: 1.5rem;
275
+ }
276
+
277
+ @media (max-width: 768px) {
278
+ .tracking-layout {
279
+ grid-template-columns: 1fr;
280
+ }
281
+ }
282
+
283
+ .sales-entry-form {
284
+ display: flex;
285
+ flex-direction: column;
286
+ gap: 1rem;
287
+ }
288
+
289
+ .reps-select {
290
+ display: flex;
291
+ gap: 1rem;
292
+ flex-wrap: wrap;
293
+ }
294
+
295
+ .rep-badge {
296
+ padding: 0.5rem 1rem;
297
+ border-radius: 20px;
298
+ background: #f1f5f9;
299
+ cursor: pointer;
300
+ border: 2px solid transparent;
301
+ font-size: 0.9rem;
302
+ font-weight: 500;
303
+ transition: var(--transition);
304
+ }
305
+
306
+ .rep-badge.selected {
307
+ background: #e0e7ff;
308
+ color: var(--primary);
309
+ border-color: var(--primary);
310
+ }
311
+
312
+ .entry-row {
313
+ display: grid;
314
+ grid-template-columns: 2fr 1fr auto;
315
+ gap: 1rem;
316
+ align-items: end;
317
+ }
318
+
319
+ .live-summary {
320
+ display: flex;
321
+ flex-direction: column;
322
+ gap: 1rem;
323
+ }
324
+
325
+ .summary-card {
326
+ background: var(--bg-card);
327
+ padding: 1.5rem;
328
+ border-radius: var(--radius);
329
+ box-shadow: var(--shadow);
330
+ border-left: 4px solid var(--primary);
331
+ }
332
+
333
+ .summary-card.success { border-left-color: var(--success); }
334
+ .summary-card.warning { border-left-color: var(--warning); }
335
+
336
+ .summary-label {
337
+ font-size: 0.85rem;
338
+ color: var(--text-muted);
339
+ text-transform: uppercase;
340
+ letter-spacing: 0.5px;
341
+ }
342
+
343
+ .summary-value {
344
+ font-size: 1.75rem;
345
+ font-weight: 700;
346
+ margin-top: 0.25rem;
347
+ }
348
+
349
+ /* --- Tab 3: Reports --- */
350
+ .report-controls {
351
+ display: flex;
352
+ justify-content: space-between;
353
+ margin-bottom: 1.5rem;
354
+ align-items: center;
355
+ }
356
+
357
+ .chart-container {
358
+ height: 400px;
359
+ width: 100%;
360
+ position: relative;
361
+ }
362
+
363
+ /* --- Toast Notification --- */
364
+ #toast-container {
365
+ position: fixed;
366
+ bottom: 2rem;
367
+ right: 2rem;
368
+ z-index: 1000;
369
+ display: flex;
370
+ flex-direction: column;
371
+ gap: 1rem;
372
+ }
373
+
374
+ .toast {
375
+ background: var(--text-main);
376
+ color: white;
377
+ padding: 1rem 1.5rem;
378
+ border-radius: 8px;
379
+ box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
380
+ display: flex;
381
+ align-items: center;
382
+ gap: 0.75rem;
383
+ animation: slideIn 0.3s ease-out;
384
+ min-width: 300px;
385
+ }
386
+
387
+ .toast.success { border-left: 4px solid var(--success); }
388
+ .toast.error { border-left: 4px solid var(--danger); }
389
+
390
+ @keyframes slideIn {
391
+ from { transform: translateX(100%); opacity: 0; }
392
+ to { transform: translateX(0); opacity: 1; }
393
+ }
394
+
395
+ /* --- Canvas Chart Styles --- */
396
+ canvas {
397
+ width: 100%;
398
+ height: 100%;
399
+ }
400
+
401
+ /* --- Empty State --- */
402
+ .empty-state {
403
+ text-align: center;
404
+ padding: 3rem;
405
+ color: var(--text-muted);
406
+ }
407
+ .empty-state i {
408
+ font-size: 3rem;
409
+ margin-bottom: 1rem;
410
+ opacity: 0.5;
411
+ }
412
+ </style>
413
+ </head>
414
+ <body>
415
+
416
+ <header>
417
+ <div class="brand">
418
+ <i class="fa-solid fa-chart-line"></i>
419
+ <h1>SalesForce ERP</h1>
420
+ </div>
421
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="built-with">
422
+ Built with anycoder
423
+ </a>
424
+ </header>
425
+
426
+ <div class="container">
427
+ <!-- Navigation -->
428
+ <nav class="tabs">
429
+ <button class="tab-btn active" onclick="switchTab('goals')">1. Set Goals</button>
430
+ <button class="tab-btn" onclick="switchTab('tracking')">2. Track Sales</button>
431
+ <button class="tab-btn" onclick="switchTab('reports')">3. Analytics</button>
432
+ </nav>
433
+
434
+ <!-- Tab 1: Goal Setting -->
435
+ <section id="goals" class="tab-content active">
436
+ <div class="card">
437
+ <div class="card-header">
438
+ <h2 class="card-title">Define Targets</h2>
439
+ <button class="btn btn-primary" onclick="openGoalModal()">
440
+ <i class="fa-solid fa-plus"></i> New Goal
441
+ </button>
442
+ </div>
443
+
444
+ <div id="goals-container">
445
+ <!-- Goals will be injected here via JS -->
446
+ <div class="empty-state">
447
+ <i class="fa-solid fa-bullseye"></i>
448
+ <p>No goals set yet. Click "New Goal" to start.</p>
449
+ </div>
450
+ </div>
451
+ </div>
452
+ </section>
453
+
454
+ <!-- Tab 2: Tracking -->
455
+ <section id="tracking" class="tab-content">
456
+ <div class="tracking-layout">
457
+ <!-- Left: Entry Form -->
458
+ <div class="card">
459
+ <div class="card-header">
460
+ <h2 class="card-title">Record Sales</h2>
461
+ </div>
462
+ <form id="sales-form" class="sales-entry-form">
463
+ <div class="form-group">
464
+ <label class="form-label">Select Sales Rep</label>
465
+ <div class="reps-select" id="rep-selector">
466
+ <!-- Reps injected via JS -->
467
+ </div>
468
+ </div>
469
+
470
+ <div class="entry-row">
471
+ <div class="form-group">
472
+ <label class="form-label">Select Goal Category</label>
473
+ <select id="entry-goal-select" class="form-control">
474
+ <option value="">Choose a goal...</option>
475
+ </select>
476
+ </div>
477
+ <div class="form-group">
478
+ <label class="form-label">Quantity / Amount</label>
479
+ <input type="number" id="entry-value" class="form-control" placeholder="0" min="0">
480
+ </div>
481
+ <button type="submit" class="btn btn-primary">
482
+ <i class="fa-solid fa-check"></i> Log
483
+ </button>
484
+ </div>
485
+ </form>
486
+ </div>
487
+
488
+ <!-- Right: Live Status -->
489
+ <div class="live-summary">
490
+ <div class="summary-card" id="current-status-card">
491
+ <div class="summary-label">Selected Rep Status</div>
492
+ <div class="summary-value" id="current-value">--</div>
493
+ <div style="font-size: 0.8rem; color: var(--text-muted);" id="current-label">Select a rep to view</div>
494
+ </div>
495
+
496
+ <div class="card">
497
+ <div class="card-header">
498
+ <h3 class="card-title" style="font-size: 0.95rem;">Recent Activity</h3>
499
+ </div>
500
+ <ul class="goal-list" id="recent-activity-list">
501
+ <li class="empty-state" style="padding: 1rem; font-size: 0.85rem;">No recent activity.</li>
502
+ </ul>
503
+ </div>
504
+ </div>
505
+ </div>
506
+ </section>
507
+
508
+ <!-- Tab 3: Reports -->
509
+ <section id="reports" class="tab-content">
510
+ <div class="report-controls">
511
+ <h2 class="card-title">Performance Report</h2>
512
+ <div>
513
+ <select id="report-filter" class="form-control" style="width: auto;" onchange="renderReport()">
514
+ <option value="all">All Reps</option>
515
+ </select>
516
+ </div>
517
+ </div>
518
+
519
+ <div class="card">
520
+ <div class="chart-container">
521
+ <canvas id="reportChart"></canvas>
522
+ </div>
523
+ </div>
524
+ </section>
525
+ </div>
526
+
527
+ <!-- Toast Container -->
528
+ <div id="toast-container"></div>
529
+
530
+ <script>
531
+ // --- State Management ---
532
+ const state = {
533
+ reps: ['Alice Smith', 'Bob Jones', 'Charlie Day'],
534
+ goals: [
535
+ { id: 1, name: 'Q1 Software Licenses', target: 50, unit: 'Units', type: 'quantity' },
536
+ { id: 2, name: 'Q1 Consulting Hours', target: 100, unit: 'Hours', type: 'quantity' },
537
+ { id: 3, name: 'Q1 Revenue', target: 50000, unit: '$', type: 'monetary' }
538
+ ],
539
+ sales: [
540
+ { id: 1, rep: 'Alice Smith', goalId: 1, value: 10, date: new Date().toISOString() },
541
+ { id: 2, rep: 'Bob Jones', goalId: 3, value: 12000, date: new Date().toISOString() },
542
+ { id: 3, rep: 'Alice Smith', goalId: 2, value: 15, date: new Date().toISOString() }
543
+ ]
544
+ };
545
+
546
+ // --- Initialization ---
547
+ document.addEventListener('DOMContentLoaded', () => {
548
+ loadFromStorage();
549
+ renderGoals();
550
+ renderRepSelector();
551
+ updateEntryGoalSelect();
552
+ renderRecentActivity();
553
+ renderReport(); // Initial chart render
554
+ });
555
+
556
+ // --- Navigation Logic ---
557
+ function switchTab(tabId) {
558
+ // Update buttons
559
+ document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
560
+ event.target.classList.add('active');
561
+
562
+ // Update content
563
+ document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
564
+ document.getElementById(tabId).classList.add('active');
565
+
566
+ // Trigger specific renders if needed
567
+ if (tabId === 'reports') {
568
+ setTimeout(renderReport, 50); // Slight delay for canvas resize
569
+ }
570
+ }
571
+
572
+ // --- Goal Management Logic ---
573
+ function renderGoals() {
574
+ const container = document.getElementById('goals-container');
575
+ container.innerHTML = '';
576
+
577
+ if (state.goals.length === 0) {
578
+ container.innerHTML = `
579
+ <div class="empty-state">
580
+ <i class="fa-solid fa-bullseye"></i>
581
+ <p>No goals set yet. Click "New Goal" to start.</p>
582
+ </div>`;
583
+ return;
584
+ }
585
+
586
+ const ul = document.createElement('ul');
587
+ ul.className = 'goal-list';
588
+
589
+ state.goals.forEach(goal => {
590
+ const li = document.createElement('li');
591
+ li.className = 'goal-item';
592
+ li.innerHTML = `
593
+ <div class="goal-info">
594
+ <h4>${goal.name}</h4>
595
+ <p>Target: ${goal.target} ${goal.unit} (${goal.type})</p>
596
+ </div>
597
+ <button class="btn btn-danger" onclick="deleteGoal(${goal.id})">
598
+ <i class="fa-solid fa-trash"></i>
599
+ </button>
600
+ `;
601
+ ul.appendChild(li);
602
+ });
603
+
604
+ container.appendChild(ul);
605
+ updateEntryGoalSelect();
606
+ }
607
+
608
+ function openGoalModal() {
609
+ // Simple prompt implementation for this demo to keep it single-file
610
+ const name = prompt("Enter Goal Name (e.g., 'Q1 Software Licenses'):");
611
+ if (!name) return;
612
+
613
+ const target = prompt("Enter Target Value (e.g., 50):");
614
+ if (!target || isNaN(target)) return alert("Invalid target value");
615
+
616
+ const unit = prompt("Enter Unit (e.g., 'Units', '$', 'Hours'):", "Units");
617
+
618
+ const type = confirm("Is this a Monetary Goal (Revenue) or Quantity?") ? 'monetary' : 'quantity';
619
+
620
+ const newGoal = {
621
+ id: Date.now(),
622
+ name: name,
623
+ target: parseFloat(target),
624
+ unit: unit || 'Units',
625
+ type: type
626
+ };
627
+
628
+ state.goals.push(newGoal);
629
+ saveToStorage();
630
+ renderGoals();
631
+ showToast('Goal created successfully', 'success');
632
+ }
633
+
634
+ function deleteGoal(id) {
635
+ if(confirm("Are you sure you want to delete this goal?")) {
636
+ state.goals = state.goals.filter(g => g.id !== id);
637
+ saveToStorage();
638
+ renderGoals();
639
+ showToast('Goal deleted', 'error');
640
+ }
641
+ }
642
+
643
+ // --- Tracking Logic ---
644
+ function renderRepSelector() {
645
+ const container = document.getElementById('rep-selector');
646
+ container.innerHTML = '';
647
+
648
+ state.reps.forEach(rep => {
649
+ const div = document.createElement('div');
650
+ div.className = 'rep-badge';
651
+ div.textContent = rep;
652
+ div.onclick = () => selectRep(rep, div);
653
+ container.appendChild(div);
654
+ });
655
+ }
656
+
657
+ let selectedRep = null;
658
+
659
+ function selectRep(repName, element) {
660
+ selectedRep = repName;
661
+
662
+ // Visual feedback
663
+ document.querySelectorAll('.rep-badge').forEach(b => b.classList.remove('selected'));
664
+ element.classList.add('selected');
665
+
666
+ updateLiveStatus();
667
+ renderRecentActivity();
668
+ }
669
+
670
+ function updateEntryGoalSelect() {
671
+ const select = document.getElementById('entry-goal-select');
672
+ select.innerHTML = '<option value="">Choose a goal...</option>';
673
+
674
+ state.goals.forEach(goal => {
675
+ const opt = document.createElement('option');
676
+ opt.value = goal.id;
677
+ opt.textContent = `${goal.name} (${goal.unit})`;
678
+ select.appendChild(opt);
679
+ });
680
+ }
681
+
682
+ document.getElementById('sales-form').addEventListener('submit', (e) => {
683
+ e.preventDefault();
684
+
685
+ const goalId = parseInt(document.getElementById('entry-goal-select').value);
686
+ const value = parseFloat(document.getElementById('entry-value').value);
687
+
688
+ if (!selectedRep) return showToast("Please select a Sales Rep first", "error");
689
+ if (!goalId) return showToast("Please select a Goal Category", "error");
690
+ if (!value || value <= 0) return showToast("Please enter a valid value", "error");
691
+
692
+ const goal = state.goals.find(g => g.id === goalId);
693
+ const goalType = goal.type; // 'monetary' or 'quantity'
694
+
695
+ const sale = {
696
+ id: Date.now(),
697
+ rep: selectedRep,
698
+ goalId: goalId,
699
+ value: value,
700
+ date: new Date().toISOString()
701
+ };
702
+
703
+ state.sales.push(sale);
704
+ saveToStorage();
705
+
706
+ // Reset form
707
+ document.getElementById('entry-value').value = '';
708
+
709
+ showToast(`Logged ${value} ${goal.unit} for ${selectedRep}`, 'success');
710
+ updateLiveStatus();
711
+ renderRecentActivity();
712
+ });
713
+
714
+ function updateLiveStatus() {
715
+ if (!selectedRep) return;
716
+
717
+ // Calculate totals for selected rep
718
+ let totalQty = 0;
719
+ let totalMon = 0;
720
+
721
+ state.sales.filter(s => s.rep === selectedRep).forEach(s => {
722
+ const g = state.goals.find(x => x.id === s.goalId);
723
+ if (g.type === 'quantity') totalQty += s.value;
724
+ if (g.type === 'monetary') totalMon += s.value;
725
+ });
726
+
727
+ const card = document.getElementById('current-status-card');
728
+ const valEl = document.getElementById('current-value');
729
+ const labelEl = document.getElementById('current-label');
730
+
731
+ // Determine primary metric based on last entry
732
+ const lastSale = state.sales.filter(s => s.rep === selectedRep).sort((a,b) => new Date(b.date) - new Date(a.date))[0];
733
+ const currentGoal = lastSale ? state.goals.find(g => g.id === lastSale.goalId) : null;
734
+
735
+ if (currentGoal) {
736
+ valEl.textContent = totalMon > 0 ? `$${totalMon.toLocaleString()}` : `${totalQty} ${currentGoal.unit}`;
737
+ labelEl.textContent = `Current: ${currentGoal.name} (Target: ${currentGoal.target} ${currentGoal.unit})`;
738
+
739
+ // Visual feedback on card
740
+ card.className = 'summary-card'; // Reset
741
+ const percent = (totalMon > 0 ? totalMon : totalQty) / currentGoal.target;
742
+ if (percent >= 1) card.classList.add('success');
743
+ else if (percent >= 0.5) card.classList.add('warning');
744
+ } else {
745
+ valEl.textContent = "0";
746
+ labelEl.textContent = "No sales recorded yet";
747
+ }
748
+ }
749
+
750
+ function renderRecentActivity() {
751
+ const list = document.getElementById('recent-activity-list');
752
+ list.innerHTML = '';
753
+
754
+ const recent = state.sales.sort((a,b) => new Date(b.date) - new Date(a.date)).slice(0, 5);
755
+
756
+ if (recent.length === 0) {
757
+ list.innerHTML = '<li class="empty-state" style="padding: 1rem; font-size: 0.85rem;">No recent activity.</li>';
758
+ return;
759
+ }
760
+
761
+ recent.forEach(sale => {
762
+ const g = state.goals.find(x => x.id === sale.goalId);
763
+ const li = document.createElement('li');
764
+ li.className = 'goal-item';
765
+ li.style.padding = '0.75rem';
766
+ li.innerHTML = `
767
+ <div>
768
+ <div style="font-weight: 600; font-size: 0.9rem;">${sale.rep}</div>
769
+ <div style="font-size: 0.8rem; color: var(--text-muted);">${g ? g.name : 'Unknown Goal'}: ${sale.value} ${g ? g.unit : ''}</div>
770
+ </div>
771
+ <div style="font-size: 0.8rem; color: var(--text-muted);">${new Date(sale.date).toLocaleDateString()}</div>
772
+ `;
773
+ list.appendChild(li);
774
+ });
775
+ }
776
+
777
+ // --- Reporting & Charting Logic (Custom Canvas) ---
778
+ function renderReport() {
779
+ const canvas = document.getElementById('reportChart');
780
+ const ctx = canvas.getContext('2d');
781
+ const filter = document.getElementById('report-filter').value;
782
+
783
+ // Fix canvas resolution
784
+ const dpr = window.devicePixelRatio || 1;
785
+ const rect = canvas.getBoundingClientRect();
786
+ canvas.width = rect.width * dpr;
787
+ canvas.height = rect.height * dpr;
788
+ ctx.scale(dpr, dpr);
789
+
790
+ // Clear canvas
791
+ ctx.clearRect(0, 0, rect.width, rect.height);
792
+
793
+ // Prepare Data
794
+ // We will aggregate sales by Rep
795
+ const repData = {};
796
+ state.reps.forEach(r => repData[r] = 0);
797
+
798
+ state.sales.forEach(s => {
799
+ if (filter === 'all' || s.rep === filter) {
800
+ repData[s.rep] += s.value;
801
+ }
802
+ });
803
+
804
+ const labels = Object.keys(repData);
805
+ const data = Object.values(repData);
806
+
807
+ if (data.every(v => v === 0)) {
808
+ ctx.fillStyle = "#94a3b8";
809
+ ctx.font = "16px Inter";
810
+ ctx.textAlign = "center";
811
+ ctx.fillText("No sales data available for this filter.", rect.width/2, rect.height/2);
812
+ return;
813
+ }
814
+
815
+ // Drawing Settings
816
+ const padding = 40;
817
+ const chartWidth = rect.width - (padding * 2);
818
+ const chartHeight = rect.height - (padding * 2);
819
+ const maxVal = Math.max(...data) * 1.1; // 10% headroom
820
+
821
+ // Draw Bars
822
+ const barWidth = Math.min(60, chartWidth / labels.length - 20);
823
+ const gap = (chartWidth - (barWidth * labels.length)) / (labels.length + 1);
824
+
825
+ labels.forEach((label, i) => {
826
+ const val = data[i];
827
+ const barHeight = (val / maxVal) * chartHeight;
828
+ const x = padding + gap + (i * (barWidth + gap));
829
+ const y = rect.height - padding - barHeight;
830
+
831
+ // Bar
832
+ const gradient = ctx.createLinearGradient(x, y, x, y + barHeight);
833
+ gradient.addColorStop(0, '#4f46e5');
834
+ gradient.addColorStop(1, '#818cf8');
835
+
836
+ ctx.fillStyle = gradient;
837
+
838
+ // Rounded top corners logic
839
+ ctx.beginPath();
840
+ ctx.roundRect(x, y, barWidth, barHeight, [8, 8, 0, 0]);
841
+ ctx.fill();
842
+
843
+ // Value Label
844
+ ctx.fillStyle = "#1e293b";
845
+ ctx.font = "bold 12px Inter";
846
+ ctx.textAlign = "center";
847
+ ctx.fillText(val.toLocaleString(), x + barWidth/2, y - 10);
848
+
849
+ // X Axis Label
850
+ ctx.fillStyle = "#64748b";
851
+ ctx.font = "12px Inter";
852
+ // Truncate name if too long
853
+ const shortName = label.length > 10 ? label.substring(0,8) + '..' : label;
854
+ ctx.fillText(shortName, x + barWidth/2, rect.height - padding + 20);
855
+ });
856
+
857
+ // Draw Axes Lines
858
+ ctx.beginPath();
859
+ ctx.strokeStyle = "#e2e8f0";
860
+ ctx.lineWidth = 1;
861
+ // Y Axis
862
+ ctx.moveTo(padding, padding);
863
+ ctx.lineTo(padding, rect.height - padding);
864
+ // X Axis
865
+ ctx.lineTo(rect.width - padding, rect.height - padding);
866
+ ctx.stroke();
867
+ }
868
+
869
+ // --- Utilities ---
870
+ function showToast(message, type = 'success') {
871
+ const container = document.getElementById('toast-container');
872
+ const toast = document.createElement('div');
873
+ toast.className = `toast ${type}`;
874
+
875
+ const icon = type === 'success' ? '<i class="fa-solid fa-check-circle"></i>' : '<i class="fa-solid fa-exclamation-circle"></i>';
876
+
877
+ toast.innerHTML = `${icon} <span>${message}</span>`;
878
+
879
+ container.appendChild(toast);
880
+
881
+ setTimeout(() => {
882
+ toast.style.opacity = '0';
883
+ toast.style.transform = 'translateX(100%)';
884
+ setTimeout(() => toast.remove(), 300);
885
+ }, 3000);
886
+ }
887
+
888
+ function saveToStorage() {
889
+ localStorage.setItem('erp_sales_data', JSON.stringify(state));
890
+ }
891
+
892
+ function loadFromStorage() {
893
+ const saved = localStorage.getItem('erp_sales_data');
894
+ if (saved) {
895
+ const parsed = JSON.parse(saved);
896
+ // Merge to ensure structure integrity
897
+ state.reps = parsed.reps || state.reps;
898
+ state.goals = parsed.goals || state.goals;
899
+ state.sales = parsed.sales || state.sales;
900
+ }
901
+ }
902
+
903
+ // Handle window resize for chart
904
+ window.addEventListener('resize', () => {
905
+ if(document.getElementById('reports').classList.contains('active')) {
906
+ renderReport();
907
+ }
908
+ });
909
+
910
+ </script>
911
+ </body>
912
+ </html>