Spaces:
Running
Running
File size: 46,108 Bytes
2aa58f9 | 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MDC Warehouse Hazard Tracker</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
body {
font-family: 'Roboto', sans-serif;
}
.logo-container {
height: 100px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
margin-bottom: 20px;
border: 1px solid #ddd;
background-color: #f8f8f8;
}
.logo-container img {
width: 100%;
height: 100%;
object-fit: contain;
}
.title {
color: #006400;
font-weight: 700;
font-size: 28px;
text-align: center;
margin-bottom: 20px;
}
.chart-container {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 20px;
margin-bottom: 20px;
}
.status-open {
background-color: #ffcccc;
}
.status-closed {
background-color: #ccffcc;
}
.status-pending {
background-color: #ffffcc;
}
.status-ongoing {
background-color: #ccccff;
}
.summary-card {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 15px;
margin-bottom: 20px;
}
.summary-title {
font-weight: 700;
font-size: 18px;
margin-bottom: 10px;
color: #006400;
}
.summary-value {
font-size: 24px;
font-weight: 700;
}
.form-input {
border: 1px solid #ddd;
border-radius: 4px;
padding: 8px 12px;
width: 100%;
}
.form-select {
border: 1px solid #ddd;
border-radius: 4px;
padding: 8px 12px;
width: 100%;
background-color: white;
}
.btn {
padding: 8px 16px;
border-radius: 4px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s;
}
.btn-primary {
background-color: #006400;
color: white;
border: none;
}
.btn-primary:hover {
background-color: #004d00;
}
.btn-secondary {
background-color: #4a5568;
color: white;
border: none;
}
.btn-secondary:hover {
background-color: #2d3748;
}
.btn-danger {
background-color: #e53e3e;
color: white;
border: none;
}
.btn-danger:hover {
background-color: #c53030;
}
.table-container {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px 12px;
text-align: left;
}
th {
background-color: #006400;
color: white;
font-weight: 500;
}
tr:nth-child(even) {
background-color: #f8f8f8;
}
.filter-container {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 15px;
margin-bottom: 20px;
}
.filter-title {
font-weight: 700;
margin-bottom: 10px;
color: #006400;
}
.file-input-container {
position: relative;
overflow: hidden;
display: inline-block;
}
.file-input {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.file-input-btn {
display: inline-block;
padding: 8px 16px;
background-color: #4a5568;
color: white;
border-radius: 4px;
cursor: pointer;
}
.file-input-btn:hover {
background-color: #2d3748;
}
</style>
</head>
<body class="bg-gray-100 p-4">
<div class="container mx-auto">
<div class="flex items-center justify-between mb-6">
<div class="logo-container w-1/4">
<img id="logo-img" src="" alt="Company Logo">
</div>
<div class="file-input-container">
<button class="file-input-btn">Upload Logo</button>
<input type="file" id="logo-upload" class="file-input" accept="image/*">
</div>
<h1 class="title">MDC Warehouse Hazard Tracker</h1>
<div class="flex space-x-2">
<button id="export-excel" class="btn btn-secondary">Export Excel</button>
<button id="export-pdf" class="btn btn-secondary">Export PDF</button>
</div>
</div>
<div class="filter-container">
<h2 class="filter-title">Filters</h2>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label for="start-date" class="block mb-1">Start Date</label>
<input type="date" id="start-date" class="form-input">
</div>
<div>
<label for="end-date" class="block mb-1">End Date</label>
<input type="date" id="end-date" class="form-input">
</div>
<div>
<label for="status-filter" class="block mb-1">Status</label>
<select id="status-filter" class="form-select">
<option value="all">All Status</option>
<option value="Open">Open</option>
<option value="Closed">Closed</option>
<option value="Pending">Pending</option>
<option value="Ongoing">Ongoing</option>
</select>
</div>
<div>
<label for="area-filter" class="block mb-1">Area</label>
<select id="area-filter" class="form-select">
<option value="all">All Areas</option>
<option value="Domestic">Domestic</option>
<option value="Export">Export</option>
<option value="QMS">QMS</option>
<option value="Security">Security</option>
<option value="PMD">PMD</option>
<option value="Others">Others</option>
</select>
</div>
</div>
<div class="mt-4 flex justify-end">
<button id="apply-filter" class="btn btn-primary mr-2">Apply Filter</button>
<button id="reset-filter" class="btn btn-secondary">Reset Filter</button>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
<div class="chart-container">
<h2 class="text-lg font-bold mb-4">Top 3 Reported Hazards</h2>
<canvas id="topHazardsChart"></canvas>
</div>
<div class="chart-container">
<h2 class="text-lg font-bold mb-4">Hazards by Area</h2>
<canvas id="hazardsByAreaChart"></canvas>
</div>
<div class="chart-container">
<h2 class="text-lg font-bold mb-4">Status Distribution by Area</h2>
<canvas id="statusByAreaChart"></canvas>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
<div class="chart-container">
<h2 class="text-lg font-bold mb-4">Areas with Most Reports</h2>
<canvas id="areasMostReportsChart"></canvas>
</div>
<div class="chart-container">
<h2 class="text-lg font-bold mb-4">Areas with Most Corrected Hazards</h2>
<canvas id="areasMostCorrectedChart"></canvas>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
<div class="summary-card">
<div class="summary-title">Total Reports</div>
<div class="summary-value" id="total-reports">0</div>
</div>
<div class="summary-card">
<div class="summary-title">Open</div>
<div class="summary-value" id="total-open">0</div>
</div>
<div class="summary-card">
<div class="summary-title">Closed</div>
<div class="summary-value" id="total-closed">0</div>
</div>
<div class="summary-card">
<div class="summary-title">Pending/Ongoing</div>
<div class="summary-value" id="total-pending-ongoing">0</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6 mb-6">
<h2 class="text-xl font-bold mb-4">Add New Hazard Report</h2>
<form id="hazard-form" class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label for="report-date" class="block mb-1">Date of Report</label>
<input type="date" id="report-date" class="form-input" required>
</div>
<div>
<label for="hazard-type" class="block mb-1">Hazard/Issue Observed</label>
<select id="hazard-type" class="form-select" required>
<option value="">Select Hazard Type</option>
<option value="MHE Related">MHE Related</option>
<option value="Fire Hazard">Fire Hazard</option>
<option value="WEM Related">WEM Related</option>
<option value="GWP Related">GWP Related</option>
<option value="Not wearing Personal protective Equipment">Not wearing Personal protective Equipment</option>
<option value="Performing Specialized activity without work permit">Performing Specialized activity without work permit</option>
<option value="Dilapidated Pallet">Dilapidated Pallet</option>
<option value="Kissing Product">Kissing Product</option>
<option value="Over-extended stacks">Over-extended stacks</option>
<option value="Unauthorized Operation of MHE">Unauthorized Operation of MHE</option>
<option value="Unsecured Stacks">Unsecured Stacks</option>
<option value="Push-Pull Spotter without tool">Push-Pull Spotter without tool</option>
<option value="Improper placement / Unattended Jack pallet">Improper placement / Unattended Jack pallet</option>
<option value="Uncleared Rack Guards">Uncleared Rack Guards</option>
<option value="Maximum Pallet Stacking">Maximum Pallet Stacking</option>
<option value="Emergency Preparedness (EPRT) Related">Emergency Preparedness (EPRT) Related</option>
<option value="Spillage / Leakage">Spillage / Leakage</option>
<option value="Others">Others</option>
<option value="Put away without Stretch film">Put away without Stretch film</option>
<option value="Electrocution Hazard">Electrocution Hazard</option>
<option value="Unattended Safety Tools and Equipment">Unattended Safety Tools and Equipment</option>
</select>
</div>
<div>
<label for="hazard-area" class="block mb-1">Area</label>
<select id="hazard-area" class="form-select" required>
<option value="">Select Area</option>
<option value="Domestic">Domestic</option>
<option value="Export">Export</option>
<option value="QMS">QMS</option>
<option value="Security">Security</option>
<option value="PMD">PMD</option>
<option value="Others">Others</option>
</select>
</div>
<div>
<label for="hazard-status" class="block mb-1">Status</label>
<select id="hazard-status" class="form-select" required>
<option value="">Select Status</option>
<option value="Open">Open</option>
<option value="Closed">Closed</option>
<option value="Pending">Pending</option>
<option value="Ongoing">Ongoing</option>
</select>
</div>
<div class="md:col-span-2">
<label for="hazard-details" class="block mb-1">Complete Details of Hazard</label>
<textarea id="hazard-details" class="form-input" rows="3" required></textarea>
</div>
<div class="md:col-span-2 flex justify-end">
<button type="submit" class="btn btn-primary">Add Hazard Report</button>
</div>
</form>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-bold mb-4">Hazard Reports</h2>
<div class="table-container">
<table id="hazard-table">
<thead>
<tr>
<th>Date</th>
<th>Hazard Type</th>
<th>Area</th>
<th>Details</th>
<th>Status</th>
<th>Aging Days</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="hazard-table-body">
<!-- Reports will be added here -->
</tbody>
</table>
</div>
</div>
</div>
<script>
// Initialize data storage
let hazardReports = JSON.parse(localStorage.getItem('hazardReports')) || [];
// DOM elements
const hazardForm = document.getElementById('hazard-form');
const hazardTableBody = document.getElementById('hazard-table-body');
const logoUpload = document.getElementById('logo-upload');
const logoImg = document.getElementById('logo-img');
const exportExcelBtn = document.getElementById('export-excel');
const exportPdfBtn = document.getElementById('export-pdf');
const applyFilterBtn = document.getElementById('apply-filter');
const resetFilterBtn = document.getElementById('reset-filter');
const startDateFilter = document.getElementById('start-date');
const endDateFilter = document.getElementById('end-date');
const statusFilter = document.getElementById('status-filter');
const areaFilter = document.getElementById('area-filter');
// Chart variables
let topHazardsChart, hazardsByAreaChart, statusByAreaChart, areasMostReportsChart, areasMostCorrectedChart;
// Initialize the application
document.addEventListener('DOMContentLoaded', function() {
// Load logo from localStorage if exists
const savedLogo = localStorage.getItem('companyLogo');
if (savedLogo) {
logoImg.src = savedLogo;
}
// Render initial data
renderHazardTable();
updateCharts();
updateSummary();
// Set default dates for filters
const today = new Date();
const oneMonthAgo = new Date();
oneMonthAgo.setMonth(oneMonthAgo.getMonth() - 1);
startDateFilter.valueAsDate = oneMonthAgo;
endDateFilter.valueAsDate = today;
});
// Event listeners
hazardForm.addEventListener('submit', function(e) {
e.preventDefault();
const reportDate = document.getElementById('report-date').value;
const hazardType = document.getElementById('hazard-type').value;
const hazardArea = document.getElementById('hazard-area').value;
const hazardStatus = document.getElementById('hazard-status').value;
const hazardDetails = document.getElementById('hazard-details').value;
const newReport = {
id: Date.now(),
date: reportDate,
type: hazardType,
area: hazardArea,
details: hazardDetails,
status: hazardStatus,
createdAt: new Date().toISOString()
};
hazardReports.push(newReport);
saveData();
renderHazardTable();
updateCharts();
updateSummary();
// Reset form
hazardForm.reset();
});
logoUpload.addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
logoImg.src = event.target.result;
localStorage.setItem('companyLogo', event.target.result);
};
reader.readAsDataURL(file);
}
});
exportExcelBtn.addEventListener('click', exportToExcel);
exportPdfBtn.addEventListener('click', exportToPdf);
applyFilterBtn.addEventListener('click', applyFilters);
resetFilterBtn.addEventListener('click', resetFilters);
// Functions
function renderHazardTable(filteredReports = null) {
const reportsToRender = filteredReports || hazardReports;
hazardTableBody.innerHTML = '';
if (reportsToRender.length === 0) {
const row = document.createElement('tr');
row.innerHTML = `<td colspan="7" class="text-center py-4">No hazard reports found</td>`;
hazardTableBody.appendChild(row);
return;
}
reportsToRender.forEach(report => {
const row = document.createElement('tr');
// Calculate aging days
const reportDate = new Date(report.date);
const today = new Date();
const diffTime = Math.abs(today - reportDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// Apply status-based background color
let statusClass = '';
if (report.status === 'Open') statusClass = 'status-open';
else if (report.status === 'Closed') statusClass = 'status-closed';
else if (report.status === 'Pending') statusClass = 'status-pending';
else if (report.status === 'Ongoing') statusClass = 'status-ongoing';
row.innerHTML = `
<td>${formatDate(report.date)}</td>
<td>${report.type}</td>
<td>${report.area}</td>
<td>${report.details}</td>
<td class="${statusClass}">${report.status}</td>
<td>${diffDays}</td>
<td>
<button onclick="editReport(${report.id})" class="btn btn-secondary btn-sm">Edit</button>
<button onclick="deleteReport(${report.id})" class="btn btn-danger btn-sm">Delete</button>
</td>
`;
hazardTableBody.appendChild(row);
});
}
function editReport(id) {
const report = hazardReports.find(r => r.id === id);
if (!report) return;
document.getElementById('report-date').value = report.date;
document.getElementById('hazard-type').value = report.type;
document.getElementById('hazard-area').value = report.area;
document.getElementById('hazard-status').value = report.status;
document.getElementById('hazard-details').value = report.details;
// Remove the report from the array
hazardReports = hazardReports.filter(r => r.id !== id);
saveData();
renderHazardTable();
updateCharts();
updateSummary();
}
function deleteReport(id) {
if (confirm('Are you sure you want to delete this report?')) {
hazardReports = hazardReports.filter(r => r.id !== id);
saveData();
renderHazardTable();
updateCharts();
updateSummary();
}
}
function saveData() {
localStorage.setItem('hazardReports', JSON.stringify(hazardReports));
}
function formatDate(dateString) {
const options = { year: 'numeric', month: 'short', day: 'numeric' };
return new Date(dateString).toLocaleDateString(undefined, options);
}
function updateCharts() {
updateTopHazardsChart();
updateHazardsByAreaChart();
updateStatusByAreaChart();
updateAreasMostReportsChart();
updateAreasMostCorrectedChart();
}
function updateTopHazardsChart() {
// Count occurrences of each hazard type
const hazardCounts = {};
hazardReports.forEach(report => {
hazardCounts[report.type] = (hazardCounts[report.type] || 0) + 1;
});
// Sort hazards by count and get top 3
const sortedHazards = Object.entries(hazardCounts)
.sort((a, b) => b[1] - a[1])
.slice(0, 3);
const labels = sortedHazards.map(item => item[0]);
const data = sortedHazards.map(item => item[1]);
const ctx = document.getElementById('topHazardsChart').getContext('2d');
if (topHazardsChart) {
topHazardsChart.destroy();
}
topHazardsChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Number of Reports',
data: data,
backgroundColor: 'rgba(0, 100, 0, 0.2)',
borderColor: 'rgba(0, 100, 0, 1)',
borderWidth: 2,
tension: 0.1,
fill: true
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Top 3 Reported Hazards'
}
},
scales: {
y: {
beginAtZero: true,
ticks: {
stepSize: 1
}
}
}
}
});
}
function updateHazardsByAreaChart() {
// Group reports by area and status
const areaStatusCounts = {};
hazardReports.forEach(report => {
if (!areaStatusCounts[report.area]) {
areaStatusCounts[report.area] = {
Open: 0,
Closed: 0,
Pending: 0,
Ongoing: 0
};
}
areaStatusCounts[report.area][report.status]++;
});
const areas = Object.keys(areaStatusCounts);
const statuses = ['Open', 'Closed', 'Pending', 'Ongoing'];
const datasets = statuses.map(status => {
return {
label: status,
data: areas.map(area => areaStatusCounts[area][status]),
backgroundColor: getStatusColor(status)
};
});
const ctx = document.getElementById('hazardsByAreaChart').getContext('2d');
if (hazardsByAreaChart) {
hazardsByAreaChart.destroy();
}
hazardsByAreaChart = new Chart(ctx, {
type: 'bar',
data: {
labels: areas,
datasets: datasets
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Hazards by Area'
}
},
scales: {
x: {
stacked: true,
},
y: {
stacked: true,
beginAtZero: true
}
}
}
});
}
function updateStatusByAreaChart() {
// Count reports by status
const statusCounts = {
Open: 0,
Closed: 0,
Pending: 0,
Ongoing: 0
};
hazardReports.forEach(report => {
statusCounts[report.status]++;
});
const ctx = document.getElementById('statusByAreaChart').getContext('2d');
if (statusByAreaChart) {
statusByAreaChart.destroy();
}
statusByAreaChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: Object.keys(statusCounts),
datasets: [{
data: Object.values(statusCounts),
backgroundColor: [
'rgba(255, 99, 132, 0.7)',
'rgba(75, 192, 192, 0.7)',
'rgba(255, 206, 86, 0.7)',
'rgba(153, 102, 255, 0.7)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(75, 192, 192, 1)',
'rgba(255, 206, 86, 1)',
'rgba(153, 102, 255, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Status Distribution'
}
}
}
});
}
function updateAreasMostReportsChart() {
// Count reports by area
const areaCounts = {};
hazardReports.forEach(report => {
areaCounts[report.area] = (areaCounts[report.area] || 0) + 1;
});
const sortedAreas = Object.entries(areaCounts)
.sort((a, b) => b[1] - a[1]);
const labels = sortedAreas.map(item => item[0]);
const data = sortedAreas.map(item => item[1]);
const ctx = document.getElementById('areasMostReportsChart').getContext('2d');
if (areasMostReportsChart) {
areasMostReportsChart.destroy();
}
areasMostReportsChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Number of Reports',
data: data,
backgroundColor: 'rgba(54, 162, 235, 0.7)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: false,
},
title: {
display: true,
text: 'Areas with Most Reports'
}
},
scales: {
y: {
beginAtZero: true
}
}
}
});
}
function updateAreasMostCorrectedChart() {
// Count closed reports by area
const areaClosedCounts = {};
hazardReports.forEach(report => {
if (report.status === 'Closed') {
areaClosedCounts[report.area] = (areaClosedCounts[report.area] || 0) + 1;
}
});
const sortedAreas = Object.entries(areaClosedCounts)
.sort((a, b) => b[1] - a[1]);
const labels = sortedAreas.map(item => item[0]);
const data = sortedAreas.map(item => item[1]);
const ctx = document.getElementById('areasMostCorrectedChart').getContext('2d');
if (areasMostCorrectedChart) {
areasMostCorrectedChart.destroy();
}
areasMostCorrectedChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Number of Corrected Hazards',
data: data,
backgroundColor: 'rgba(75, 192, 192, 0.7)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: false,
},
title: {
display: true,
text: 'Areas with Most Corrected Hazards'
}
},
scales: {
y: {
beginAtZero: true
}
}
}
});
}
function updateSummary() {
const totalReports = hazardReports.length;
const totalOpen = hazardReports.filter(r => r.status === 'Open').length;
const totalClosed = hazardReports.filter(r => r.status === 'Closed').length;
const totalPendingOngoing = hazardReports.filter(r => r.status === 'Pending' || r.status === 'Ongoing').length;
document.getElementById('total-reports').textContent = totalReports;
document.getElementById('total-open').textContent = totalOpen;
document.getElementById('total-closed').textContent = totalClosed;
document.getElementById('total-pending-ongoing').textContent = totalPendingOngoing;
}
function getStatusColor(status) {
switch(status) {
case 'Open': return 'rgba(255, 99, 132, 0.7)';
case 'Closed': return 'rgba(75, 192, 192, 0.7)';
case 'Pending': return 'rgba(255, 206, 86, 0.7)';
case 'Ongoing': return 'rgba(153, 102, 255, 0.7)';
default: return 'rgba(201, 203, 207, 0.7)';
}
}
function exportToExcel() {
// Prepare data for export
const data = hazardReports.map(report => {
const reportDate = new Date(report.date);
const today = new Date();
const diffTime = Math.abs(today - reportDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
return {
'Date': formatDate(report.date),
'Hazard Type': report.type,
'Area': report.area,
'Details': report.details,
'Status': report.status,
'Aging Days': diffDays
};
});
// Create worksheet
const ws = XLSX.utils.json_to_sheet(data);
// Create workbook
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Hazard Reports");
// Export to Excel
XLSX.writeFile(wb, "MDC_Warehouse_Hazard_Reports.xlsx");
}
function exportToPdf() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Add title
doc.setFontSize(18);
doc.setTextColor(0, 100, 0);
doc.text('MDC Warehouse Hazard Reports', 105, 15, { align: 'center' });
// Add date
doc.setFontSize(12);
doc.setTextColor(0, 0, 0);
doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 105, 25, { align: 'center' });
// Add charts (simplified for PDF)
let yPos = 35;
// Summary section
doc.setFontSize(14);
doc.text('Summary', 14, yPos);
yPos += 10;
const totalReports = hazardReports.length;
const totalOpen = hazardReports.filter(r => r.status === 'Open').length;
const totalClosed = hazardReports.filter(r => r.status === 'Closed').length;
const totalPendingOngoing = hazardReports.filter(r => r.status === 'Pending' || r.status === 'Ongoing').length;
doc.setFontSize(12);
doc.text(`Total Reports: ${totalReports}`, 20, yPos);
yPos += 7;
doc.text(`Open: ${totalOpen}`, 20, yPos);
yPos += 7;
doc.text(`Closed: ${totalClosed}`, 20, yPos);
yPos += 7;
doc.text(`Pending/Ongoing: ${totalPendingOngoing}`, 20, yPos);
yPos += 15;
// Top hazards
doc.setFontSize(14);
doc.text('Top Reported Hazards', 14, yPos);
yPos += 10;
const hazardCounts = {};
hazardReports.forEach(report => {
hazardCounts[report.type] = (hazardCounts[report.type] || 0) + 1;
});
const sortedHazards = Object.entries(hazardCounts)
.sort((a, b) => b[1] - a[1])
.slice(0, 3);
doc.setFontSize(12);
sortedHazards.forEach(([hazard, count], index) => {
doc.text(`${index + 1}. ${hazard}: ${count} reports`, 20, yPos);
yPos += 7;
});
yPos += 10;
// Table data
doc.setFontSize(14);
doc.text('Hazard Reports', 14, yPos);
yPos += 10;
// Table headers
doc.setFontSize(10);
doc.text('Date', 14, yPos);
doc.text('Hazard Type', 50, yPos);
doc.text('Area', 100, yPos);
doc.text('Status', 130, yPos);
doc.text('Aging Days', 160, yPos);
yPos += 7;
// Table rows
hazardReports.forEach(report => {
const reportDate = new Date(report.date);
const today = new Date();
const diffTime = Math.abs(today - reportDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (yPos > 270) {
doc.addPage();
yPos = 20;
// Repeat headers on new page
doc.text('Date', 14, yPos);
doc.text('Hazard Type', 50, yPos);
doc.text('Area', 100, yPos);
doc.text('Status', 130, yPos);
doc.text('Aging Days', 160, yPos);
yPos += 7;
}
doc.text(formatDate(report.date), 14, yPos);
doc.text(report.type, 50, yPos);
doc.text(report.area, 100, yPos);
doc.text(report.status, 130, yPos);
doc.text(diffDays.toString(), 160, yPos);
yPos += 7;
});
// Save PDF
doc.save('MDC_Warehouse_Hazard_Reports.pdf');
}
function applyFilters() {
const startDate = startDateFilter.value;
const endDate = endDateFilter.value;
const status = statusFilter.value;
const area = areaFilter.value;
let filteredReports = [...hazardReports];
// Filter by date range
if (startDate && endDate) {
filteredReports = filteredReports.filter(report => {
const reportDate = new Date(report.date);
const start = new Date(startDate);
const end = new Date(endDate);
return reportDate >= start && reportDate <= end;
});
}
// Filter by status
if (status !== 'all') {
filteredReports = filteredReports.filter(report => report.status === status);
}
// Filter by area
if (area !== 'all') {
filteredReports = filteredReports.filter(report => report.area === area);
}
renderHazardTable(filteredReports);
// Update charts with filtered data
updateChartsWithFilteredData(filteredReports);
updateSummaryWithFilteredData(filteredReports);
}
function resetFilters() {
startDateFilter.value = '';
endDateFilter.value = '';
statusFilter.value = 'all';
areaFilter.value = 'all';
renderHazardTable();
updateCharts();
updateSummary();
}
function updateChartsWithFilteredData(filteredReports) {
// Update top hazards chart
const hazardCounts = {};
filteredReports.forEach(report => {
hazardCounts[report.type] = (hazardCounts[report.type] || 0) + 1;
});
const sortedHazards = Object.entries(hazardCounts)
.sort((a, b) => b[1] - a[1])
.slice(0, 3);
const labels = sortedHazards.map(item => item[0]);
const data = sortedHazards.map(item => item[1]);
topHazardsChart.data.labels = labels;
topHazardsChart.data.datasets[0].data = data;
topHazardsChart.update();
// Update hazards by area chart
const areaStatusCounts = {};
filteredReports.forEach(report => {
if (!areaStatusCounts[report.area]) {
areaStatusCounts[report.area] = {
Open: 0,
Closed: 0,
Pending: 0,
Ongoing: 0
};
}
areaStatusCounts[report.area][report.status]++;
});
const areas = Object.keys(areaStatusCounts);
const statuses = ['Open', 'Closed', 'Pending', 'Ongoing'];
hazardsByAreaChart.data.labels = areas;
hazardsByAreaChart.data.datasets = statuses.map(status => {
return {
label: status,
data: areas.map(area => areaStatusCounts[area][status] || 0),
backgroundColor: getStatusColor(status)
};
});
hazardsByAreaChart.update();
// Update status distribution chart
const statusCounts = {
Open: 0,
Closed: 0,
Pending: 0,
Ongoing: 0
};
filteredReports.forEach(report => {
statusCounts[report.status]++;
});
statusByAreaChart.data.datasets[0].data = Object.values(statusCounts);
statusByAreaChart.update();
// Update areas with most reports chart
const areaCounts = {};
filteredReports.forEach(report => {
areaCounts[report.area] = (areaCounts[report.area] || 0) + 1;
});
const sortedAreas = Object.entries(areaCounts)
.sort((a, b) => b[1] - a[1]);
areasMostReportsChart.data.labels = sortedAreas.map(item => item[0]);
areasMostReportsChart.data.datasets[0].data = sortedAreas.map(item => item[1]);
areasMostReportsChart.update();
// Update areas with most corrected hazards chart
const areaClosedCounts = {};
filteredReports.forEach(report => {
if (report.status === 'Closed') {
areaClosedCounts[report.area] = (areaClosedCounts[report.area] || 0) + 1;
}
});
const sortedClosedAreas = Object.entries(areaClosedCounts)
.sort((a, b) => b[1] - a[1]);
areasMostCorrectedChart.data.labels = sortedClosedAreas.map(item => item[0]);
areasMostCorrectedChart.data.datasets[0].data = sortedClosedAreas.map(item => item[1]);
areasMostCorrectedChart.update();
}
function updateSummaryWithFilteredData(filteredReports) {
const totalReports = filteredReports.length;
const totalOpen = filteredReports.filter(r => r.status === 'Open').length;
const totalClosed = filteredReports.filter(r => r.status === 'Closed').length;
const totalPendingOngoing = filteredReports.filter(r => r.status === 'Pending' || r.status === 'Ongoing').length;
document.getElementById('total-reports').textContent = totalReports;
document.getElementById('total-open').textContent = totalOpen;
document.getElementById('total-closed').textContent = totalClosed;
document.getElementById('total-pending-ongoing').textContent = totalPendingOngoing;
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=froilan1262/version-3" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |