-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreports.php
More file actions
451 lines (416 loc) · 21.1 KB
/
Copy pathreports.php
File metadata and controls
451 lines (416 loc) · 21.1 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
<?php
/**
* NewUI v4.0 - Reports
*
* Reporting page with multiple report types, period filtering,
* sortable tables, summary cards, CSV export, and print view.
*/
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/inc/i18n.php';
require_once __DIR__ . '/inc/rbac.php';
// 2026-07-04 (GH #13) — pick the session profile matching the
// client's cookie (TCADMOBILE vs PHPSESSID). Without this, a
// browser holding a mobile cookie opens an empty desktop session
// here and bounces to login -> redirect loop.
require_once __DIR__ . '/inc/session-bootstrap.php';
sess_bootstrap_auto();
session_start();
if (empty($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
rbac_require_screen('screen.reports');
require_once __DIR__ . '/inc/force-pw-change.php';
force_pw_change_redirect();
// GH#51 — the After Action filter takes the dispatcher's own case
// number, not the internal ticket id. Build a sample from the live
// template so the placeholder shows what THEIR numbers actually look
// like, not a generic example.
require_once __DIR__ . '/inc/incident-number.php';
$incidentNumberSample = incnum_render(incnum_get_template(), 91);
$incidentNumberLabel = incnum_get_label();
$user = e($_SESSION['user']);
$level = current_role_name();
$theme = $_SESSION['day_night'] ?? 'Day';
$bs_theme = ($theme === 'Night') ? 'dark' : 'light';
$csrf = csrf_token();
?>
<!DOCTYPE html>
<html lang="<?php echo e(i18n_lang()); ?>" data-bs-theme="<?php echo $bs_theme; ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="<?php echo e($csrf); ?>">
<title><?php echo e(t('page.reports', 'Reports')); ?> — <?php echo e(t('login.title', 'Tickets NewUI')); ?> <?php echo newui_version(); ?></title>
<!-- Vendor CSS -->
<link rel="stylesheet" href="assets/vendor/bootstrap/bootstrap.min.css">
<link rel="stylesheet" href="assets/vendor/bootstrap/bootstrap-icons.min.css">
<!-- App CSS -->
<link rel="stylesheet" href="assets/css/dashboard.css?v=<?php echo newui_version(); ?>">
<link rel="stylesheet" href="assets/css/reports.css?v=<?php echo newui_version(); ?>">
</head>
<body>
<?php include_once NEWUI_ROOT . '/inc/navbar.php'; ?>
</header>
<!-- Page Content -->
<div class="container-fluid p-3">
<!-- Page title + export buttons -->
<div class="d-flex align-items-center justify-content-between mb-3">
<h5 class="mb-0">
<i class="bi bi-bar-chart-line text-primary me-2"></i><?php echo e(t('page.reports', 'Reports')); ?>
</h5>
<div class="d-flex gap-2 align-items-center">
<button type="button" class="btn btn-sm btn-outline-success" id="btnExportCSV" disabled>
<i class="bi bi-filetype-csv me-1"></i>Export CSV
</button>
<button type="button" class="btn btn-sm btn-outline-secondary" id="btnPrint" disabled>
<i class="bi bi-printer me-1"></i>Print
</button>
<a href="index.php" class="btn btn-sm btn-outline-secondary">
<i class="bi bi-arrow-left me-1"></i>Dashboard
</a>
</div>
</div>
<!-- Report Type Tabs -->
<div class="card mb-3">
<div class="card-body py-2">
<div class="d-flex flex-wrap align-items-center gap-2">
<span class="text-body-secondary small fw-semibold me-1">Report:</span>
<div class="btn-group btn-group-sm" role="group" id="reportTypeBtns">
<button type="button" class="btn btn-primary" data-report="incident_report">
<i class="bi bi-file-earmark-text me-1"></i>Incidents
</button>
<button type="button" class="btn btn-outline-primary" data-report="incident_summary">
<i class="bi bi-graph-up me-1"></i>Summary
</button>
<button type="button" class="btn btn-outline-primary" data-report="dispatch_log">
<i class="bi bi-broadcast me-1"></i>Dispatch Log
</button>
<button type="button" class="btn btn-outline-primary" data-report="unit_log">
<i class="bi bi-truck me-1"></i>Unit Log
</button>
<button type="button" class="btn btn-outline-primary" data-report="interval_report" title="Response / scene / transport time intervals over the dispatch milestones">
<i class="bi bi-stopwatch me-1"></i>Intervals
</button>
<button type="button" class="btn btn-outline-primary" data-report="facility_log">
<i class="bi bi-hospital me-1"></i>Facility Log
</button>
<button type="button" class="btn btn-outline-primary" data-report="facility_bed_adjustments" title="Who moved a facility's bed count and why -- automatic decrements vs. facility self-releases (GH#102)">
<i class="bi bi-clipboard-data me-1"></i>Bed Adjustments
</button>
<button type="button" class="btn btn-outline-primary" data-report="mileage_report" title="Trip log: organization, vehicle, driver, odometer, miles">
<i class="bi bi-speedometer2 me-1"></i>Mileage Log
</button>
<button type="button" class="btn btn-outline-primary" data-report="notes_log">
<i class="bi bi-sticky me-1"></i>Notes Log
</button>
<button type="button" class="btn btn-outline-primary" data-report="after_action">
<i class="bi bi-journal-text me-1"></i>After Action
</button>
<a href="par-reports.php" class="btn btn-outline-primary" title="PAR (Personnel Accountability) compliance + per-incident timeline">
<i class="bi bi-shield-check me-1"></i>PAR
</a>
</div>
<span class="text-body-secondary small fw-semibold ms-2 me-1">Personnel:</span>
<div class="btn-group btn-group-sm" role="group" id="personnelReportBtns">
<button type="button" class="btn btn-outline-primary" data-report="roster_snapshot">
<i class="bi bi-people me-1"></i>Roster
</button>
<button type="button" class="btn btn-outline-primary" data-report="time_summary">
<i class="bi bi-clock-history me-1"></i>Time Summary
</button>
<button type="button" class="btn btn-outline-primary" data-report="license_expirations">
<i class="bi bi-card-checklist me-1"></i>Expirations
</button>
<button type="button" class="btn btn-outline-primary" data-report="membership_due">
<i class="bi bi-cash-coin me-1"></i>Dues Due
</button>
<button type="button" class="btn btn-outline-primary" data-report="inactive_members">
<i class="bi bi-person-dash me-1"></i>Inactive
</button>
<button type="button" class="btn btn-outline-primary" data-report="dmr_inventory">
<i class="bi bi-broadcast-pin me-1"></i>DMR IDs
</button>
</div>
</div>
</div>
</div>
<!-- Filters Row -->
<div class="card mb-3">
<div class="card-body py-2">
<div class="row g-2 align-items-end">
<!-- Period Selector -->
<div class="col-auto">
<label class="form-label small mb-1" for="periodSelect">Period</label>
<select class="form-select form-select-sm" id="periodSelect" style="width: auto;">
<option value="today">Today</option>
<option value="this_week">This Week</option>
<option value="last_week">Last Week</option>
<option value="this_month" selected>This Month</option>
<option value="last_month">Last Month</option>
<option value="this_year">This Year</option>
<option value="last_year">Last Year</option>
<option value="custom">Custom Range</option>
</select>
</div>
<!-- Custom Date Range (hidden by default) -->
<div class="col-auto d-none" id="customDateRange">
<label class="form-label small mb-1" for="startDate">From</label>
<input type="date" class="form-control form-control-sm" id="startDate">
</div>
<div class="col-auto d-none" id="customDateRange2">
<label class="form-label small mb-1" for="endDate">To</label>
<input type="date" class="form-control form-control-sm" id="endDate">
</div>
<!-- Responder Filter -->
<div class="col-auto" id="responderFilterCol">
<label class="form-label small mb-1" for="responderFilter">Responder</label>
<select class="form-select form-select-sm" id="responderFilter" style="width: auto;">
<option value="0">All Responders</option>
</select>
</div>
<!-- Incident Filter (for after-action) -->
<div class="col-auto d-none" id="incidentFilterCol">
<label class="form-label small mb-1" for="incidentFilter"><?php echo e($incidentNumberLabel); ?> #</label>
<input type="text" class="form-control form-control-sm" id="incidentFilter"
placeholder="e.g. <?php echo e($incidentNumberSample); ?>"
title="Enter the incident number as shown on the incident (not the internal database id)."
style="width: 150px;">
</div>
<!-- Member Filter (for Personnel reports -- a person, not a unit) -->
<div class="col-auto d-none" id="memberFilterCol">
<label class="form-label small mb-1" for="memberFilter">Member</label>
<select class="form-select form-select-sm" id="memberFilter" style="width: auto;">
<option value="0">All Members</option>
</select>
</div>
<!-- Driver Filter (Mileage Log only -- a login/user account,
distinct from both Responder/Vehicle and Member above) -->
<div class="col-auto d-none" id="driverFilterCol">
<label class="form-label small mb-1" for="driverFilter">Driver</label>
<select class="form-select form-select-sm" id="driverFilter" style="width: auto;">
<option value="0">All Drivers</option>
</select>
</div>
<!-- Organization Filter (Mileage Log only). Options are
populated purely from whatever the caller is authorized
to see (api/reports.php's server-side org-visibility) --
a caller who can only see one org gets a single-option
selector with no separate JS logic required. -->
<div class="col-auto d-none" id="mileageOrgFilterCol">
<label class="form-label small mb-1" for="mileageOrgFilter">Organization</label>
<select class="form-select form-select-sm" id="mileageOrgFilter" style="width: auto;">
<option value="0">All Organizations</option>
</select>
</div>
<!-- Run Button -->
<div class="col-auto">
<button type="button" class="btn btn-sm btn-primary" id="btnRunReport">
<i class="bi bi-play-fill me-1"></i>Run Report
</button>
</div>
</div>
</div>
</div>
<!-- Summary Cards -->
<div class="row g-2 mb-3 d-none" id="summaryCards">
<!-- Populated by JS -->
</div>
<!-- Report Title & Period Label -->
<div class="d-flex align-items-center justify-content-between mb-2 d-none" id="reportHeader">
<div>
<h6 class="mb-0" id="reportTitle">—</h6>
<small class="text-body-secondary" id="periodLabel">—</small>
</div>
<small class="text-body-secondary" id="rowCount">—</small>
</div>
<!-- Results Table -->
<div class="card">
<div class="card-body p-0">
<!-- Loading spinner -->
<div class="text-center py-5 d-none" id="loadingSpinner">
<div class="spinner-border text-primary" role="status"></div>
<div class="mt-2 text-body-secondary">Loading report...</div>
</div>
<!-- Empty state -->
<div class="text-center py-5" id="emptyState">
<i class="bi bi-bar-chart-line" style="font-size: 2rem; opacity: 0.3;"></i>
<div class="mt-2 text-body-secondary">Select a report type and click Run Report</div>
</div>
<!-- Table -->
<div class="table-responsive d-none" id="reportTableWrap">
<table class="table table-sm table-striped table-hover mb-0" id="reportTable">
<thead class="sticky-top">
<tr id="reportTableHead"></tr>
</thead>
<tbody id="reportTableBody"></tbody>
</table>
</div>
<!-- No data -->
<div class="text-center py-4 d-none" id="noDataState">
<i class="bi bi-inbox" style="font-size: 2rem; opacity: 0.3;"></i>
<div class="mt-2 text-body-secondary">No data found for the selected period</div>
</div>
</div>
</div>
<!-- After Action: Incident Info Panel (shown only for after_action report) -->
<div class="card mt-3 d-none" id="afterActionPanel">
<div class="card-header py-1">
<i class="bi bi-info-circle me-2"></i>
<span class="fw-semibold small">Incident Information</span>
</div>
<div class="card-body py-2 small" id="afterActionInfo">
</div>
</div>
<!-- Interval Report: aggregate breakdown (shown only for interval_report) -->
<div class="row g-3 mt-1 d-none" id="intervalBreakdownPanel">
<div class="col-md-6">
<div class="card">
<div class="card-header py-1">
<i class="bi bi-tags me-2"></i>
<span class="fw-semibold small">Average Response Time by Incident Type</span>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm mb-0">
<thead>
<tr>
<th class="small">Type</th>
<th class="small text-end">Count</th>
<th class="small text-end">Avg Response</th>
<th class="small text-end">Avg Scene</th>
</tr>
</thead>
<tbody id="intervalByTypeBody"></tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header py-1">
<i class="bi bi-truck me-2"></i>
<span class="fw-semibold small">Average Response Time by Unit</span>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm mb-0">
<thead>
<tr>
<th class="small">Unit</th>
<th class="small text-end">Count</th>
<th class="small text-end">Avg Response</th>
<th class="small text-end">Avg Scene</th>
</tr>
</thead>
<tbody id="intervalByUnitBody"></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Incident Summary: severity/disposition breakdown (shown only for incident_summary) -->
<div class="row g-3 mt-1 d-none" id="incidentSummaryBreakdownPanel">
<div class="col-md-6">
<div class="card">
<div class="card-header py-1">
<i class="bi bi-exclamation-diamond me-2"></i>
<span class="fw-semibold small">Incidents by Severity</span>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm mb-0">
<thead>
<tr>
<th class="small">Severity</th>
<th class="small text-end">Count</th>
</tr>
</thead>
<tbody id="severityBreakdownBody"></tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header py-1">
<i class="bi bi-clipboard-check me-2"></i>
<span class="fw-semibold small">Incidents by Disposition</span>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm mb-0">
<thead>
<tr>
<th class="small">Disposition</th>
<th class="small text-end">Total</th>
</tr>
</thead>
<tbody id="dispositionBreakdownBody"></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Mileage Log: by-org/by-vehicle breakdown (shown only for mileage_report) -->
<div class="row g-3 mt-1 d-none" id="mileageBreakdownPanel">
<div class="col-md-6">
<div class="card">
<div class="card-header py-1">
<i class="bi bi-diagram-3 me-2"></i>
<span class="fw-semibold small">Mileage by Organization</span>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm mb-0">
<thead>
<tr>
<th class="small">Organization</th>
<th class="small text-end">Trips</th>
<th class="small text-end">Miles</th>
</tr>
</thead>
<tbody id="mileageByOrgBody"></tbody>
</table>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header py-1">
<i class="bi bi-truck me-2"></i>
<span class="fw-semibold small">Mileage by Vehicle</span>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-sm mb-0">
<thead>
<tr>
<th class="small">Vehicle</th>
<th class="small text-end">Trips</th>
<th class="small text-end">Miles</th>
</tr>
</thead>
<tbody id="mileageByUnitBody"></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- CSRF token for JS -->
<input type="hidden" id="csrfToken" value="<?php echo e($csrf); ?>">
<!-- Vendor JS -->
<script src="assets/vendor/bootstrap/bootstrap.bundle.min.js"></script>
<script src="assets/js/toolbar.js?v=<?php echo newui_version(); ?>"></script>
<!-- App JS -->
<script src="assets/js/theme-manager.js"></script>
<script src="assets/js/reports.js?v=<?php echo newui_version(); ?>"></script>
</body>
</html>