forked from Aryansabasana/bringcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager_dashboard.html
More file actions
846 lines (754 loc) · 25.5 KB
/
manager_dashboard.html
File metadata and controls
846 lines (754 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Manager Dashboard - ExpenseEase</title>
<style>
body {
font-family: 'Montserrat', sans-serif;
background-color: #f0f4f8;
padding: 20px;
margin: 0;
}
h2 {
color: #4CAF50;
margin-bottom: 20px;
text-align: center;
}
.container {
display: flex;
flex-direction: column;
max-width: 1000px;
margin: auto;
}
.card {
background: #fff;
padding: 20px;
margin-bottom: 15px;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
cursor: pointer;
transition: background 0.3s, transform 0.2s;
}
.card:hover {
background: #e0f7fa;
transform: translateY(-2px);
}
h3 {
margin: 0;
}
/* Modal Styles */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
}
.modal-content {
background-color: #fff;
margin: 5% auto;
padding: 20px;
border-radius: 8px;
width: 80%;
max-width: 600px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: #000;
}
/* Form Styles */
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, select, textarea {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 15px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin-right: 10px;
}
button:hover {
background-color: #45a049;
}
button.secondary {
background-color: #6c757d;
}
button.secondary:hover {
background-color: #5a6268;
}
button.approve {
background-color: #28a745;
}
button.approve:hover {
background-color: #218838;
}
button.decline {
background-color: #dc3545;
}
button.decline:hover {
background-color: #c82333;
}
/* Request Styles */
.request-item {
background: #fff;
padding: 15px;
margin-bottom: 10px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
border-left: 4px solid #4CAF50;
}
.request-item.pending {
border-left-color: #ffc107;
}
.request-item.approved {
border-left-color: #28a745;
}
.request-item.declined {
border-left-color: #dc3545;
}
.request-header {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
.request-title {
font-weight: bold;
font-size: 18px;
}
.request-status {
padding: 3px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: bold;
}
.status-pending {
background-color: #fff3cd;
color: #856404;
}
.status-approved {
background-color: #d4edda;
color: #155724;
}
.status-declined {
background-color: #f8d7da;
color: #721c24;
}
.request-details {
color: #666;
margin-bottom: 5px;
}
.request-actions {
margin-top: 10px;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
/* Tabs */
.tabs {
display: flex;
margin-bottom: 20px;
border-bottom: 1px solid #ddd;
flex-wrap: wrap;
}
.tab {
padding: 10px 20px;
cursor: pointer;
border-bottom: 3px solid transparent;
}
.tab.active {
border-bottom: 3px solid #4CAF50;
font-weight: bold;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
/* Stats Cards */
.stats-container {
display: flex;
gap: 15px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.stat-card {
background: #fff;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
flex: 1;
min-width: 150px;
text-align: center;
}
.stat-value {
font-size: 24px;
font-weight: bold;
margin: 10px 0;
}
.stat-pending { border-top: 4px solid #ffc107; }
.stat-approved { border-top: 4px solid #28a745; }
.stat-declined { border-top: 4px solid #dc3545; }
.stat-total { border-top: 4px solid #4CAF50; }
/* Manager-specific styles */
.manager-note {
background-color: #e7f3ff;
border-left: 4px solid #007bff;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
}
/* Team Assignment Styles */
.team-member {
background: #fff;
padding: 15px;
margin-bottom: 10px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
display: flex;
justify-content: space-between;
align-items: center;
}
.member-info {
flex: 1;
}
.member-name {
font-weight: bold;
font-size: 16px;
margin-bottom: 5px;
}
.member-details {
color: #666;
font-size: 14px;
}
/* Empty State */
.empty-state {
text-align: center;
padding: 40px 20px;
color: #6c757d;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<h2>Manager Dashboard - ExpenseEase</h2>
<div class="tabs">
<div class="tab active" onclick="switchTab('dashboard')">Dashboard</div>
<div class="tab" onclick="switchTab('pending')">Pending Requests</div>
<div class="tab" onclick="switchTab('team')">Team Requests</div>
<div class="tab" onclick="switchTab('all')">All Requests</div>
<div class="tab" onclick="switchTab('teamMembers')">My Team</div>
</div>
<div class="container">
<div id="dashboard" class="tab-content active">
<div class="stats-container">
<div class="stat-card stat-pending">
<div>Pending</div>
<div class="stat-value" id="pendingCount">0</div>
<div>Requests</div>
</div>
<div class="stat-card stat-approved">
<div>Approved</div>
<div class="stat-value" id="approvedCount">0</div>
<div>Requests</div>
</div>
<div class="stat-card stat-declined">
<div>Declined</div>
<div class="stat-value" id="declinedCount">0</div>
<div>Requests</div>
</div>
<div class="stat-card stat-total">
<div>My Decisions</div>
<div class="stat-value" id="myDecisionsCount">0</div>
<div>Requests</div>
</div>
</div>
<div class="manager-note">
<strong>Manager Note:</strong> As a manager, you can approve or decline expense requests from employees in your team.
You can also view all requests but can only take action on pending ones from your team members.
</div>
<div class="card" onclick="location.href='expenses.html'"><h3>Add Expense</h3></div>
<div class="card" onclick="location.href='reports.html'"><h3>View Reports</h3></div>
<div class="card" onclick="logout()"><h3>Logout</h3></div>
</div>
<div id="pending" class="tab-content">
<h3>Pending Expense Requests - My Team</h3>
<div id="pendingRequestsList">
<!-- Pending requests will be loaded here -->
</div>
</div>
<div id="team" class="tab-content">
<h3>My Team's Requests</h3>
<div id="teamRequestsList">
<!-- Team requests will be loaded here -->
</div>
</div>
<div id="all" class="tab-content">
<h3>All Expense Requests</h3>
<div class="manager-note">
<strong>Note:</strong> You can view all requests but can only approve/decline requests from your team members.
</div>
<div id="allRequestsList">
<!-- All requests will be loaded here -->
</div>
</div>
<div id="teamMembers" class="tab-content">
<h3>My Team Members</h3>
<div id="teamMembersList">
<!-- Team members will be loaded here -->
</div>
</div>
</div>
<!-- Decision Modal -->
<div id="decisionModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeDecisionModal()">×</span>
<h3 id="decisionTitle">Approve/Decline Request</h3>
<div id="requestDetails">
<!-- Request details will be loaded here -->
</div>
<div class="form-group">
<label for="decisionNotes">Notes (Optional)</label>
<textarea id="decisionNotes" rows="3" placeholder="Add any notes for the employee..."></textarea>
</div>
<div class="request-actions">
<button class="approve" onclick="approveRequest()">Approve</button>
<button class="decline" onclick="declineRequest()">Decline</button>
<button class="secondary" onclick="closeDecisionModal()">Cancel</button>
</div>
</div>
</div>
<script>
// Global variable to track the current request being reviewed
let currentRequestId = null;
// Initialize the app
document.addEventListener('DOMContentLoaded', function() {
// Verify role
const user = JSON.parse(localStorage.getItem('loggedInUser'));
if (!user || user.role !== 'manager') {
alert('Access denied.');
window.location.href = 'index.html';
return;
}
// Initialize data in localStorage if not exists
if (!localStorage.getItem('expenseRequests')) {
localStorage.setItem('expenseRequests', JSON.stringify([]));
}
if (!localStorage.getItem('users')) {
localStorage.setItem('users', JSON.stringify([]));
}
if (!localStorage.getItem('teamAssignments')) {
// Create sample team assignments
initializeTeamAssignments();
}
// Load dashboard stats and requests
updateDashboardStats();
loadPendingRequests();
loadTeamRequests();
loadAllRequests();
loadTeamMembers();
});
// Initialize team assignments
function initializeTeamAssignments() {
const users = JSON.parse(localStorage.getItem('users')) || [];
const teamAssignments = {};
// Find current manager
const currentUser = JSON.parse(localStorage.getItem('loggedInUser'));
// Assign employees to this manager
const employees = users.filter(user => user.role === 'employee');
if (employees.length > 0) {
teamAssignments[currentUser.id] = employees.map(emp => emp.id);
}
localStorage.setItem('teamAssignments', JSON.stringify(teamAssignments));
}
// Tab switching function
function switchTab(tabName) {
// Update tabs
document.querySelectorAll('.tab').forEach(tab => {
tab.classList.remove('active');
});
document.querySelector(`.tab[onclick="switchTab('${tabName}')"]`).classList.add('active');
// Update tab content
document.querySelectorAll('.tab-content').forEach(content => {
content.classList.remove('active');
});
document.getElementById(tabName).classList.add('active');
// Refresh data when switching to these tabs
if (tabName === 'pending') {
loadPendingRequests();
} else if (tabName === 'team') {
loadTeamRequests();
} else if (tabName === 'all') {
loadAllRequests();
} else if (tabName === 'teamMembers') {
loadTeamMembers();
} else if (tabName === 'dashboard') {
updateDashboardStats();
}
}
// Get current manager's team members
function getMyTeamMembers() {
const user = JSON.parse(localStorage.getItem('loggedInUser'));
const teamAssignments = JSON.parse(localStorage.getItem('teamAssignments'));
return teamAssignments[user.id] || [];
}
// Update dashboard statistics
function updateDashboardStats() {
const user = JSON.parse(localStorage.getItem('loggedInUser'));
const allRequests = JSON.parse(localStorage.getItem('expenseRequests'));
const myTeamMembers = getMyTeamMembers();
// Filter requests for manager's team only
const teamRequests = allRequests.filter(request =>
myTeamMembers.includes(request.employeeId)
);
const pendingCount = teamRequests.filter(request => request.status === 'pending').length;
const approvedCount = teamRequests.filter(request => request.status === 'approved').length;
const declinedCount = teamRequests.filter(request => request.status === 'declined').length;
// Count requests decided by this manager
const myDecisionsCount = allRequests.filter(request =>
(request.approvedBy === user.name || request.declinedBy === user.name)
).length;
document.getElementById('pendingCount').textContent = pendingCount;
document.getElementById('approvedCount').textContent = approvedCount;
document.getElementById('declinedCount').textContent = declinedCount;
document.getElementById('myDecisionsCount').textContent = myDecisionsCount;
}
// Load pending requests for manager's team
function loadPendingRequests() {
const allRequests = JSON.parse(localStorage.getItem('expenseRequests'));
const myTeamMembers = getMyTeamMembers();
const pendingRequests = allRequests.filter(request =>
request.status === 'pending' && myTeamMembers.includes(request.employeeId)
);
const pendingList = document.getElementById('pendingRequestsList');
pendingList.innerHTML = '';
if (pendingRequests.length === 0) {
pendingList.innerHTML = '<div class="empty-state">No pending expense requests for your team.</div>';
return;
}
// Sort requests by date (oldest first)
pendingRequests.sort((a, b) => new Date(a.submittedDate) - new Date(b.submittedDate));
pendingRequests.forEach(request => {
const requestItem = document.createElement('div');
requestItem.className = 'request-item pending';
requestItem.innerHTML = `
<div class="request-header">
<div class="request-title">${request.title}</div>
<div class="request-status status-pending">Pending</div>
</div>
<div class="request-details">
<strong>Employee:</strong> ${request.employeeName} |
<strong>Amount:</strong> $${request.amount.toFixed(2)} |
<strong>Category:</strong> ${request.category}
</div>
<div class="request-details">
<strong>Description:</strong> ${request.description}
</div>
<div class="request-details">
<strong>Date:</strong> ${request.date} |
<strong>Submitted:</strong> ${request.submittedDate}
</div>
<div class="request-actions">
<button class="approve" onclick="openDecisionModal('${request.id}', 'approve')">Approve</button>
<button class="decline" onclick="openDecisionModal('${request.id}', 'decline')">Decline</button>
</div>
`;
pendingList.appendChild(requestItem);
});
}
// Load all requests for manager's team
function loadTeamRequests() {
const allRequests = JSON.parse(localStorage.getItem('expenseRequests'));
const myTeamMembers = getMyTeamMembers();
const teamRequests = allRequests.filter(request =>
myTeamMembers.includes(request.employeeId)
);
const teamList = document.getElementById('teamRequestsList');
teamList.innerHTML = '';
if (teamRequests.length === 0) {
teamList.innerHTML = '<div class="empty-state">No expense requests from your team members.</div>';
return;
}
// Sort requests by date (newest first)
teamRequests.sort((a, b) => new Date(b.submittedDate) - new Date(a.submittedDate));
teamRequests.forEach(request => {
const requestItem = document.createElement('div');
requestItem.className = `request-item ${request.status}`;
let statusClass = 'status-pending';
let statusText = 'Pending';
if (request.status === 'approved') {
statusClass = 'status-approved';
statusText = 'Approved';
} else if (request.status === 'declined') {
statusClass = 'status-declined';
statusText = 'Declined';
}
requestItem.innerHTML = `
<div class="request-header">
<div class="request-title">${request.title}</div>
<div class="request-status ${statusClass}">${statusText}</div>
</div>
<div class="request-details">
<strong>Employee:</strong> ${request.employeeName} |
<strong>Amount:</strong> $${request.amount.toFixed(2)} |
<strong>Category:</strong> ${request.category}
</div>
<div class="request-details">
<strong>Description:</strong> ${request.description}
</div>
<div class="request-details">
<strong>Date:</strong> ${request.date} |
<strong>Submitted:</strong> ${request.submittedDate}
</div>
${request.status !== 'pending' ? `
<div class="request-details">
<strong>${request.status === 'approved' ? 'Approved' : 'Declined'} by:</strong> ${request.status === 'approved' ? request.approvedBy : request.declinedBy} on ${request.decisionDate}
${request.notes ? `<br><strong>Notes:</strong> ${request.notes}` : ''}
</div>
` : ''}
${request.status === 'pending' ? `
<div class="request-actions">
<button class="approve" onclick="openDecisionModal('${request.id}', 'approve')">Approve</button>
<button class="decline" onclick="openDecisionModal('${request.id}', 'decline')">Decline</button>
</div>
` : ''}
`;
teamList.appendChild(requestItem);
});
}
// Load all requests (read-only for manager except for their team)
function loadAllRequests() {
const allRequests = JSON.parse(localStorage.getItem('expenseRequests'));
const myTeamMembers = getMyTeamMembers();
const allList = document.getElementById('allRequestsList');
allList.innerHTML = '';
if (allRequests.length === 0) {
allList.innerHTML = '<div class="empty-state">No expense requests found.</div>';
return;
}
// Sort requests by date (newest first)
allRequests.sort((a, b) => new Date(b.submittedDate) - new Date(a.submittedDate));
allRequests.forEach(request => {
const isMyTeam = myTeamMembers.includes(request.employeeId);
const requestItem = document.createElement('div');
requestItem.className = `request-item ${request.status}`;
let statusClass = 'status-pending';
let statusText = 'Pending';
if (request.status === 'approved') {
statusClass = 'status-approved';
statusText = 'Approved';
} else if (request.status === 'declined') {
statusClass = 'status-declined';
statusText = 'Declined';
}
requestItem.innerHTML = `
<div class="request-header">
<div class="request-title">${request.title}</div>
<div class="request-status ${statusClass}">${statusText}</div>
</div>
<div class="request-details">
<strong>Employee:</strong> ${request.employeeName} |
<strong>Amount:</strong> $${request.amount.toFixed(2)} |
<strong>Category:</strong> ${request.category}
</div>
<div class="request-details">
<strong>Description:</strong> ${request.description}
</div>
<div class="request-details">
<strong>Date:</strong> ${request.date} |
<strong>Submitted:</strong> ${request.submittedDate}
</div>
${request.status !== 'pending' ? `
<div class="request-details">
<strong>${request.status === 'approved' ? 'Approved' : 'Declined'} by:</strong> ${request.status === 'approved' ? request.approvedBy : request.declinedBy} on ${request.decisionDate}
${request.notes ? `<br><strong>Notes:</strong> ${request.notes}` : ''}
</div>
` : ''}
${request.status === 'pending' && isMyTeam ? `
<div class="request-actions">
<button class="approve" onclick="openDecisionModal('${request.id}', 'approve')">Approve</button>
<button class="decline" onclick="openDecisionModal('${request.id}', 'decline')">Decline</button>
</div>
` : ''}
${request.status === 'pending' && !isMyTeam ? `
<div class="request-details">
<em>This request belongs to another team</em>
</div>
` : ''}
`;
allList.appendChild(requestItem);
});
}
// Load team members
function loadTeamMembers() {
const allUsers = JSON.parse(localStorage.getItem('users'));
const myTeamMembers = getMyTeamMembers();
const teamMembersList = document.getElementById('teamMembersList');
teamMembersList.innerHTML = '';
if (myTeamMembers.length === 0) {
teamMembersList.innerHTML = '<div class="empty-state">No team members assigned to you.</div>';
return;
}
myTeamMembers.forEach(memberId => {
const member = allUsers.find(user => user.id === memberId);
if (member) {
const memberItem = document.createElement('div');
memberItem.className = 'team-member';
memberItem.innerHTML = `
<div class="member-info">
<div class="member-name">${member.name || member.username}</div>
<div class="member-details">
Username: ${member.username} | Email: ${member.email || 'N/A'} | Role: Employee
</div>
</div>
`;
teamMembersList.appendChild(memberItem);
}
});
}
// Open decision modal
function openDecisionModal(requestId, action) {
currentRequestId = requestId;
const allRequests = JSON.parse(localStorage.getItem('expenseRequests'));
const request = allRequests.find(req => req.id === requestId);
if (!request) {
alert('Request not found.');
return;
}
// Verify this manager can approve/decline this request
const myTeamMembers = getMyTeamMembers();
if (!myTeamMembers.includes(request.employeeId)) {
alert('You can only approve/decline requests from your team members.');
return;
}
document.getElementById('decisionTitle').textContent =
action === 'approve' ? 'Approve Expense Request' : 'Decline Expense Request';
document.getElementById('requestDetails').innerHTML = `
<div class="request-details">
<strong>Employee:</strong> ${request.employeeName}
</div>
<div class="request-details">
<strong>Title:</strong> ${request.title}
</div>
<div class="request-details">
<strong>Amount:</strong> $${request.amount.toFixed(2)}
</div>
<div class="request-details">
<strong>Category:</strong> ${request.category}
</div>
<div class="request-details">
<strong>Description:</strong> ${request.description}
</div>
<div class="request-details">
<strong>Date:</strong> ${request.date}
</div>
<div class="request-details">
<strong>Submitted:</strong> ${request.submittedDate}
</div>
`;
document.getElementById('decisionNotes').value = '';
document.getElementById('decisionModal').style.display = 'block';
}
// Close decision modal
function closeDecisionModal() {
document.getElementById('decisionModal').style.display = 'none';
currentRequestId = null;
}
// Approve request
function approveRequest() {
if (!currentRequestId) return;
const user = JSON.parse(localStorage.getItem('loggedInUser'));
const allRequests = JSON.parse(localStorage.getItem('expenseRequests'));
const requestIndex = allRequests.findIndex(req => req.id === currentRequestId);
if (requestIndex === -1) {
alert('Request not found.');
return;
}
// Final verification that manager can approve this request
const myTeamMembers = getMyTeamMembers();
if (!myTeamMembers.includes(allRequests[requestIndex].employeeId)) {
alert('You can only approve requests from your team members.');
return;
}
allRequests[requestIndex].status = 'approved';
allRequests[requestIndex].approvedBy = user.name || user.username;
allRequests[requestIndex].declinedBy = null;
allRequests[requestIndex].decisionDate = new Date().toISOString().split('T')[0];
allRequests[requestIndex].notes = document.getElementById('decisionNotes').value;
localStorage.setItem('expenseRequests', JSON.stringify(allRequests));
alert('Request approved successfully!');
closeDecisionModal();
// Refresh all views
updateDashboardStats();
loadPendingRequests();
loadTeamRequests();
loadAllRequests();
}
// Decline request
function declineRequest() {
if (!currentRequestId) return;
const user = JSON.parse(localStorage.getItem('loggedInUser'));
const allRequests = JSON.parse(localStorage.getItem('expenseRequests'));
const requestIndex = allRequests.findIndex(req => req.id === currentRequestId);
if (requestIndex === -1) {
alert('Request not found.');
return;
}
// Final verification that manager can decline this request
const myTeamMembers = getMyTeamMembers();
if (!myTeamMembers.includes(allRequests[requestIndex].employeeId)) {
alert('You can only decline requests from your team members.');
return;
}
allRequests[requestIndex].status = 'declined';
allRequests[requestIndex].declinedBy = user.name || user.username;
allRequests[requestIndex].approvedBy = null;
allRequests[requestIndex].decisionDate = new Date().toISOString().split('T')[0];
allRequests[requestIndex].notes = document.getElementById('decisionNotes').value;
localStorage.setItem('expenseRequests', JSON.stringify(allRequests));
alert('Request declined.');
closeDecisionModal();
// Refresh all views
updateDashboardStats();
loadPendingRequests();
loadTeamRequests();
loadAllRequests();
}
// Logout function
function logout() {
localStorage.removeItem('loggedInUser');
alert('Logged out successfully.');
window.location.href = 'index.html';
}
</script>
</body>
</html>