poluser commited on
Commit
23ae29e
·
verified ·
1 Parent(s): 01e1b6e

Add 2 files

Browse files
Files changed (2) hide show
  1. index.html +833 -814
  2. prompts.txt +3 -1
index.html CHANGED
@@ -66,6 +66,14 @@
66
  transform: scale(0.9);
67
  pointer-events: none;
68
  }
 
 
 
 
 
 
 
 
69
  </style>
70
  </head>
71
  <body class="bg-gray-100">
@@ -183,7 +191,7 @@
183
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
184
  <div>
185
  <label for="lastName" class="block text-sm font-medium text-gray-700 mb-1">Last Name</label>
186
- <input type="text" id="lastName" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" required>
187
  </div>
188
  <div>
189
  <label for="email" class="table text-sm font-medium text-gray-700 mb-1">Email</label>
@@ -225,17 +233,17 @@
225
  </div>
226
  <div>
227
  <label for="hireDate" class="block text-sm font-medium text-gray-700 mb-1">Hire Date</label>
228
- <input type="date" id="hireDate" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
229
  </div>
230
  </div>
231
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
232
  <div>
233
  <label for="salary" class="block text-sm font-medium text-gray-700 mb-1">Salary</label>
234
- <input type="number" id="salary" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
235
  </div>
236
  <div>
237
  <label for="status" class="block text-sm font-medium text-gray-700 mb-1">Status</label>
238
- <select id="status" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
239
  <option value="Active">Active</option>
240
  <option value="Inactive">Inactive</option>
241
  <option value="On Leave">On Leave</option>
@@ -249,41 +257,41 @@
249
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
250
  <div>
251
  <label for="sssNumber" class="block text-sm font-medium text-gray-700 mb-1">SSS Number</label>
252
- <input type="text" id="sssNumber" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX-XXXXXXX-X">
253
  </div>
254
  <div>
255
  <label for="philhealthNumber" class="block text-sm font-medium text-gray-700 mb-1">PhilHealth Number</label>
256
- <input type="text" id="philhealthNumber" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX-XXXXXXXXX-X">
257
  </div>
258
  </div>
259
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
260
  <div>
261
  <label for="pagibigNumber" class="block text-sm font-medium text-gray-700 mb-1">Pag-IBIG Number</label>
262
- <input type="text" id="pagibigNumber" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XXXX-XXXX-XXXX">
263
  </div>
264
  <div>
265
  <label for="tinNumber" class="block text-sm font-medium text-gray-700 mb-1">TIN Number</label>
266
- <input type="text" id="tinNumber" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XXX-XXX-XXX-XXX">
267
  </div>
268
  </div>
269
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
270
  <div>
271
  <label for="passportNumber" class="block text-sm font-medium text-gray-700 mb-1">Philippine Passport</label>
272
- <input type="text" id="passportNumber" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX1234567">
273
  </div>
274
  <div>
275
  <label for="passportExpiry" class="block text-sm font-medium text-gray-700 mb-1">Passport Expiry</label>
276
- <input type="date" id="passportExpiry" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
277
  </div>
278
  </div>
279
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
280
  <div>
281
  <label for="nationalId" class="block text-sm font-medium text-gray-700 mb-1">Philippine National ID</label>
282
- <input type="text" id="nationalId" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XXXX-XXXX-XXXX-XXXX">
283
  </div>
284
  <div>
285
  <label for="driversLicense" class="block text-sm font-medium text-gray-700 mb-1">Driver's License</label>
286
- <input type="text" id="driversLicense" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX-XX-XXXXXX">
287
  </div>
288
  </div>
289
  </div>
@@ -331,7 +339,7 @@
331
  </div>
332
 
333
  <!-- Clear All Confirmation Modal -->
334
- <div id="clearAllConfirmationModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 flex items-center justify-center z-50 confirmation-modal hidden">
335
  <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
336
  <div class="flex justify-between items-center border-b px-6 py-4">
337
  <h3 class="text-lg font-semibold">Confirm Clear All</h3>
@@ -345,883 +353,894 @@
345
  <button id="cancelClearAll" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50">
346
  Cancel
347
  </button>
348
- <button id="confirmClearAll" class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700">
349
  Clear All Data
350
  </button>
351
- </div>
352
  </div>
353
  </div>
354
  </div>
 
355
 
356
- <!-- Employee List -->
357
- <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-200 mb-6">
358
- <div class="flex justify-between items-center mb-4">
359
- <h2 class="text-lg font-semibold">All Employees</h2>
360
- <div class="flex items-center space-x-2">
361
- <select id="departmentFilter" class="border rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
362
- <option value="">All Departments</option>
363
- </select>
364
- <select id="statusFilter" class="border rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
365
- <option value="">All Statuses</option>
366
- <option value="Active">Active</option>
367
- <option value="Inactive">Inactive</option>
368
- <option value="On Leave">On Leave</option>
369
- </select>
370
- </div>
371
  </div>
372
- <div class="overflow-x-auto">
373
- <table class="min-w-full divide-y divide-gray-200">
374
- <thead class="bg-gray-50">
375
- <tr>
376
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Employee ID</th>
377
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
378
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Department</th>
379
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Position</th>
380
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">SSS</th>
381
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">PhilHealth</th>
382
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
383
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
384
- </tr>
385
- </thead>
386
- <tbody class="bg-white divide-y divide-gray-200" id="employeeTableBody">
387
- <!-- Rows will be inserted by JavaScript -->
388
- </tbody>
389
- </table>
 
 
 
 
 
390
  </div>
391
- <div class="mt-4 flex items-center justify-between">
392
- <div class="text-sm text-gray-500">
393
- Showing <span id="startEmployee">1</span> to <span id="endEmployee">10</span> of <span id="totalEmployees">0</span> employees
394
- </div>
395
- <div class="flex space-x-2">
396
- <button id="prevEmployeePage" class="px-3 py-1 border rounded-lg text-sm hover:bg-gray-50 disabled:opacity-50" disabled>
397
- Previous
398
- </button>
399
- <button id="nextEmployeePage", class="px-3 py-1 border rounded-lg text-sm hover:bg-gray-50 disabled:opacity-50">
400
- Next
401
- </button>
402
- </div>
403
  </div>
404
  </div>
405
  </div>
406
  </div>
 
407
 
408
- <script>
409
- // Storage keys
410
- const STORAGE_KEY = 'steelcraft_payroll_employees';
411
- const DEPARTMENTS_KEY = 'steelcraft_payroll_departments';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
 
413
- // Employee data - initially load from localStorage
414
- let employees = loadEmployees();
415
- let allDepartments = loadDepartments();
416
 
417
- // If no data in localStorage, initialize with default values
418
- if (employees.length === 0) {
419
- employees = [
420
- {
421
- id: 1,
422
- employeeId: "EMP-1001",
423
- firstName: "Juan",
424
- lastName: "Dela Cruz",
425
- email: "juan.delacruz@steelcraft.com",
426
- phone: "09171234567",
427
- department: "Fabrication",
428
- position: "Welder",
429
- hireDate: "2020-05-15",
430
- birthDate: "1985-03-12",
431
- salary: 25000,
432
- status: "Active"
433
- }
434
- ];
435
- saveEmployees();
436
- }
437
-
438
- // If no departments in localStorage, initialize from employees
439
- if (allDepartments.length === 0) {
440
- extractDepartmentsFromEmployees();
441
- saveDepartments();
442
- }
443
-
444
- // Pagination
445
- let currentPage = 1;
446
- const rowsPerPage = 20;
447
- let filteredEmployees = [...employees];
448
-
449
- // File import variables
450
- let importFileContent = null;
451
-
452
- // DOM elements
453
- const employeeTableBody = document.getElementById('employeeTableBody');
454
- const departmentInput = document.getElementById('departmentInput');
455
- const departmentSuggestions = document.getElementById('departmentSuggestions');
456
- const departmentFilter = document.getElementById('departmentFilter');
457
- const statusFilter = document.getElementById('statusFilter');
458
- const employeeSearch = document.getElementById('employeeSearch');
459
- const addEmployeeBtn = document.getElementById('addEmployeeBtn');
460
- const clearAllBtn = document.getElementById('clearAllBtn');
461
- const exportCSVBtn = document.getElementById('exportCSVBtn');
462
- const importCSVBtn = document.getElementById('importCSVBtn');
463
- const fileInput = document.getElementById('fileInput');
464
- const employeeModal = document.getElementById('employeeModal');
465
- const employeeForm = document.getElementById('employeeForm');
466
- const closeModal = document.getElementById('closeModal');
467
- const cancelEmployee = document.getElementById('cancelEmployee');
468
- const modalTitle = document.getElementById('modalTitle');
469
- const employeeIdInput = document.getElementById('employeeId');
470
- const employeeIdDisplayInput = document.getElementById('employeeIdInput');
471
- const prevEmployeePage = document.getElementById('prevEmployeePage');
472
- const nextEmployeePage = document.getElementById('nextEmployeePage');
473
- const startEmployee = document.getElementById('startEmployee');
474
- const endEmployee = document.getElementById('endEmployee');
475
- const totalEmployees = document.getElementById('totalEmployees');
476
- const tabButtons = document.querySelectorAll('.tab-button');
477
- const tabContents = document.querySelectorAll('.tab-content');
478
 
479
- // Import confirmation modal elements
480
- const importConfirmationModal = document.getElementById('importConfirmationModal');
481
- const closeImportConfirmationModal = document.getElementById('closeImportConfirmationModal');
482
- const appendDataBtn = document.getElementById('appendDataBtn');
483
- const mergeDataBtn = document.getElementById('mergeDataBtn');
484
- const replaceDataBtn = document.getElementById('replaceDataBtn');
485
 
486
- // Clear all confirmation modal elements
487
- const clearAllConfirmationModal = document.getElementById('clearAllConfirmationModal');
488
- const closeClearAllConfirmationModal = document.getElementById('closeClearAllConfirmationModal');
489
- const cancelClearAll = document.getElementById('cancelClearAll');
490
- const confirmClearAll = document.getElementById('confirmClearAll');
491
-
492
- // Storage functions
493
- function saveEmployees() {
494
- localStorage.setItem(STORAGE_KEY, JSON.stringify(employees));
495
- }
496
-
497
- function loadEmployees() {
498
- const data = localStorage.getItem(STORAGE_KEY);
499
- return data ? JSON.parse(data) : [];
500
- }
501
-
502
- function saveDepartments() {
503
- localStorage.setItem(DEPARTMENTS_KEY, JSON.stringify(allDepartments));
504
- }
505
-
506
- function loadDepartments() {
507
- const data = localStorage.getItem(DEPARTMENTS_KEY);
508
- return data ? JSON.parse(data) : [];
509
- }
510
-
511
- // Initialize
512
- document.addEventListener('DOMContentLoaded', () => {
513
- updateDepartmentFilterOptions();
514
- renderEmployeeTable();
515
- setupEventListeners();
516
- setupTabs();
517
- });
518
-
519
- function setupTabs() {
520
- tabButtons.forEach(button => {
521
- button.addEventListener('click', () => {
522
- const tabId = button.getAttribute('data-tab');
523
-
524
- // Update active tab button
525
- tabButtons.forEach(btn => btn.classList.remove('active'));
526
- button.classList.add('active');
527
-
528
- // Update active tab content
529
- tabContents.forEach(content => {
530
- content.classList.remove('active');
531
- if (content.id === `${tabId}-tab`) {
532
- content.classList.add('active');
533
- }
534
- });
535
- });
536
- });
537
- }
538
-
539
- function extractDepartmentsFromEmployees() {
540
- const departmentsSet = new Set();
541
- employees.forEach(emp => departmentsSet.add(emp.department));
542
- allDepartments = Array.from(departmentsSet);
543
- }
544
-
545
- function updateDepartmentFilterOptions() {
546
- departmentFilter.innerHTML = '<option value="">All Departments</option>';
547
- allDepartments.forEach(dep => {
548
- const option = document.createElement('option');
549
- option.value = dep;
550
- option.textContent = dep;
551
- departmentFilter.appendChild(option);
552
- });
553
- }
554
-
555
- function setupEventListeners() {
556
- addEmployeeBtn.addEventListener('click', () => openEmployeeModal());
557
-
558
- clearAllBtn.addEventListener('click', () => openClearAllConfirmationModal());
559
- exportCSVBtn.addEventListener('click', exportToCSV);
560
- importCSVBtn.addEventListener('click', () => fileInput.click());
561
- fileInput.addEventListener('change', handleFileImport);
562
- closeModal.addEventListener('click', closeEmployeeModal);
563
- cancelEmployee.addEventListener('click', closeEmployeeModal);
564
- employeeForm.addEventListener('submit', (e) => {
565
- e.preventDefault();
566
- saveEmployee();
567
- });
568
- employeeSearch.addEventListener('input', filterEmployees);
569
- departmentFilter.addEventListener('change', filterEmployees);
570
- statusFilter.addEventListener('change', filterEmployees);
571
- departmentInput.addEventListener('input', handleDepartmentInput);
572
- prevEmployeePage.addEventListener('click', () => {
573
- if (currentPage > 1) {
574
- currentPage--;
575
- renderEmployeeTable();
576
- }
577
- });
578
- nextEmployeePage.addEventListener('click', () => {
579
- if (currentPage * rowsPerPage < filteredEmployees.length) {
580
- currentPage++;
581
- renderEmployeeTable();
582
- }
583
- });
584
-
585
- // Import confirmation modal events
586
- closeImportConfirmationModal.addEventListener('click', () => importConfirmationModal.classList.add('hidden'));
587
- appendDataBtn.addEventListener('click', () => processImport('append'));
588
- mergeDataBtn.addEventListener('click', () => processImport('merge'));
589
- replaceDataBtn.addEventListener('click', () => processImport('replace'));
590
-
591
- // Clear all confirmation modal events
592
- closeClearAllConfirmationModal.addEventListener('click', () => clearAllConfirmationModal.classList.add('hidden'));
593
- cancelClearAll.addEventListener('click', () => clearAllConfirmationModal.classList.add('hidden'));
594
- confirmClearAll.addEventListener('click', clearAllEmployees);
595
- }
596
-
597
- function handleDepartmentInput(e) {
598
- const value = e.target.value.trim().toLowerCase();
599
- departmentSuggestions.innerHTML = '';
600
- departmentSuggestions.classList.add('hidden');
601
-
602
- if (value.length > 0) {
603
- const matches = allDepartments.filter(dep => dep.toLowerCase().includes(value));
604
-
605
- if (matches.length > 0) {
606
- departmentSuggestions.classList.remove('hidden');
607
- matches.forEach(dep => {
608
- const li = document.createElement('li');
609
- li.textContent = dep;
610
- li.className = 'px-3 py-2 cursor-pointer hover:bg-blue-100';
611
- li.addEventListener('click', () => {
612
- departmentInput.value = dep;
613
- departmentSuggestions.classList.add('hidden');
614
- });
615
- departmentSuggestions.appendChild(li);
616
- });
617
- }
618
-
619
- const isCustom = !allDepartments.includes(departmentInput.value) && departmentInput.value.trim() !== '';
620
- if (isCustom) {
621
  const li = document.createElement('li');
622
- li.textContent = `Add "${departmentInput.value}"`;
623
- li.className = 'px-3 py-2 cursor-pointer hover:bg-green-100 text-green-700';
624
  li.addEventListener('click', () => {
625
- const newDep = departmentInput.value.trim();
626
- if (!allDepartments.includes(newDep)) {
627
- allDepartments.push(newDep);
628
- saveDepartments();
629
- departmentInput.value = newDep;
630
- updateDepartmentFilterOptions();
631
- departmentSuggestions.classList.add('hidden');
632
- }
633
  });
634
  departmentSuggestions.appendChild(li);
635
- }
636
  }
637
- }
638
-
639
- function filterEmployees() {
640
- const searchTerm = employeeSearch.value.toLowerCase();
641
- const department = departmentFilter.value;
642
- const status = statusFilter.value;
643
-
644
- filteredEmployees = employees.filter(emp => {
645
- const fullName = `${emp.firstName} ${emp.lastName}`.toLowerCase();
646
- const matchesSearch = fullName.includes(searchTerm) || emp.employeeId.toLowerCase().includes(searchTerm);
647
- const matchesDepartment = department ? emp.department === department : true;
648
- const matchesStatus = status ? emp.status === status : true;
649
-
650
- return matchesSearch && matchesDepartment && matchesStatus;
651
- });
652
 
653
- currentPage = 1;
654
- renderEmployeeTable();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
  }
 
656
 
657
- function renderEmployeeTable() {
658
- const start = (currentPage - 1) * rowsPerPage;
659
- const end = start + rowsPerPage;
660
- const paginatedEmployees = filteredEmployees.slice(start, end);
661
 
662
- employeeTableBody.innerHTML = '';
 
 
 
 
663
 
664
- if (paginatedEmployees.length === 0) {
665
- employeeTableBody.innerHTML = `
666
- <tr>
667
- <td colspan="8" class="px-6 py-4 text-center text-gray-500">No employees found</td>
668
- </tr>
669
- `;
670
- } else {
671
- paginatedEmployees.forEach(emp => {
672
- const row = document.createElement('tr');
673
- row.innerHTML = `
674
- <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${emp.employeeId}</td>
675
- <td class="px-6 py-4 whitespace-nowrap">
676
- <div class="flex items-center">
677
- <div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center">
678
- <i class="fas fa-user text-blue-600"></i>
679
- </div>
680
- <div class="ml-4">
681
- <div class="text-sm font-medium text-gray-900">${emp.firstName} ${emp.lastName}</div>
682
- <div class="text-sm text-gray-500">${emp.email || 'No email'}</div>
683
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
684
  </div>
685
- </td>
686
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${emp.department}</td>
687
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${emp.position}</td>
688
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${emp.sssNumber || 'N/A'}</td>
689
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${emp.philhealthNumber || 'N/A'}</td>
690
- <td class="px-6 py-4 whitespace-nowrap">
691
- <span class="px-2 inline-flex text-xs leading-5 font-semibell rounded-full ${getStatusClass(emp.status)}">
692
- ${emp.status}
693
- </span>
694
- </td>
695
- <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
696
- <button class="text-blue-600 hover:text-blue-900 mr-3 edit-btn" data-id="${emp.id}">Edit</button>
697
- <button class="text-red-600 hover:text-red-900 delete-btn" data-id="${emp.id}">Delete</button>
698
- </td>
699
- `;
700
- employeeTableBody.appendChild(row);
 
 
 
 
 
 
 
 
 
701
  });
 
702
 
703
- // Add event listeners to edit and delete buttons
704
- document.querySelectorAll('.edit-btn').forEach(btn => {
705
- btn.addEventListener('click', (e) => {
706
- const id = parseInt(e.target.getAttribute('data-id'));
707
- openEmployeeModal(id);
708
- });
709
  });
 
710
 
711
- document.querySelectorAll('.delete-btn').forEach(btn => {
712
- btn.addEventListener('click', (e) => {
713
- const id = parseInt(e.target.getAttribute('data-id'));
714
- deleteEmployee(id);
715
- });
716
  });
717
- }
718
-
719
- startEmployee.textContent = filteredEmployees.length > 0 ? start + 1 : 0;
720
- endEmployee.textContent = Math.min(end, filteredEmployees.length);
721
- totalEmployees.textContent = filteredEmployees.length;
722
- prevEmployeePage.disabled = currentPage === 1;
723
- nextEmployeePage.disabled = end >= filteredEmployees.length;
724
  }
725
 
726
- function deleteEmployee(id) {
727
- if (confirm("Are you sure you want to delete this employee?")) {
728
- const index = employees.findIndex(emp => emp.id === id);
729
-
730
- if (index !== -1) {
731
- employees.splice(index, 1);
732
- saveEmployees();
733
- extractDepartmentsFromEmployees();
734
- saveDepartments();
735
- updateDepartmentFilterOptions();
736
- filterEmployees();
737
- alert('Employee deleted successfully.');
738
- }
 
 
 
 
 
 
739
  }
740
  }
 
741
 
742
- function openEmployeeModal(id = null) {
743
- console.log('Opening modal for employee ID:', id);
 
 
 
 
744
 
745
- if (id) {
746
- const employee = employees.find(e => e.id === id);
747
- console.log('Found employee:', employee);
 
 
 
 
 
 
 
 
 
 
 
 
748
 
749
- if (employee) {
750
- modalTitle.textContent = 'Edit Employee';
751
- employeeIdInput.value = employee.id;
752
- employeeIdDisplayInput.value = employee.employeeId;
753
- document.getElementById('firstName').value = employee.firstName;
754
- document.getElementById('lastName').value = employee.lastName;
755
- document.getElementById('email').value = employee.email || '';
756
- document.getElementById('phone').value = employee.phone || '';
757
- document.getElementById('birthDate').value = employee.birthDate || '';
758
- document.getElementById('civilStatus').value = employee.civilStatus || '';
759
- departmentInput.value = employee.department;
760
- document.getElementById('position').value = employee.position;
761
- document.getElementById('hireDate').value = employee.hireDate;
762
- document.getElementById('salary').value = employee.salary;
763
- document.getElementById('status').value = employee.status;
764
-
765
- // Philippine Government data
766
- document.getElementById('sssNumber').value = employee.sssNumber || '';
767
- document.getElementById('philhealthNumber').value = employee.philhealthNumber || '';
768
- document.getElementById('pagibigNumber').value = employee.pagibigNumber || '';
769
- document.getElementById('tinNumber').value = employee.tinNumber || '';
770
- document.getElementById('passportNumber').value = employee.passportNumber || '';
771
- document.getElementById('passportExpiry').value = employee.passportExpiry || '';
772
- document.getElementById('nationalId').value = employee.nationalId || '';
773
- document.getElementById('driversLicense').value = employee.driversLicense || '';
774
- }
775
- } else {
776
- modalTitle.textContent = 'Add New Employee';
777
- employeeForm.reset();
778
- employeeIdInput.value = '';
779
- employeeIdDisplayInput.value = '';
780
- departmentInput.value = '';
781
-
782
- // Generate new employee ID for new employees
783
- const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
784
- employeeIdDisplayInput.value = `EMP-${1000 + newId}`;
785
  }
786
-
787
- employeeModal.classList.remove('hidden');
 
 
 
 
 
 
 
 
788
  }
789
 
790
- function closeEmployeeModal() {
791
- employeeModal.classList.add('hidden');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
792
  }
793
 
794
- function saveEmployee() {
795
- const id = employeeIdInput.value ? parseInt(employeeIdInput.value) : null;
796
- const employeeId = employeeIdDisplayInput.value.trim();
797
- const firstName = document.getElementById('firstName').value;
798
- const lastName = document.getElementById('lastName').value;
799
- const email = document.getElementById('email').value || null;
800
- const phone = document.getElementById('phone').value || null;
801
- const birthDate = document.getElementById('birthDate').value || null;
802
- const civilStatus = document.getElementById('civilStatus').value || null;
803
- const department = departmentInput.value.trim();
804
- const position = document.getElementById('position').value || null;
805
- const hireDate = document.getElementById('hireDate').value || null;
806
- const salary = document.getElementById('salary').value ? parseFloat(document.getElementById('salary').value) : 0;
807
- const status = document.getElementById('status').value || 'Active';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
808
 
809
- // Philippine Government data
810
- const sssNumber = document.getElementById('sssNumber').value || null;
811
- const philhealthNumber = document.getElementById('philhealthNumber').value || null;
812
- const pagibigNumber = document.getElementById('pagibigNumber').value || null;
813
- const tinNumber = document.getElementById('tinNumber').value || null;
814
- const passportNumber = document.getElementById('passportNumber').value || null;
815
- const passportExpiry = document.getElementById('passportExpiry').value || null;
816
- const nationalId = document.getElementById('nationalId').value || null;
817
- const driversLicense = document.getElementById('driversLicense').value || null;
818
-
819
- if (!employeeId || !firstName || !lastName) {
820
- alert("Employee ID, first name and last name are required.");
821
- return;
822
- }
823
-
824
- if (id) {
825
- // Editing existing employee
826
- const index = employees.findIndex(e => e.id === id);
827
- employees[index] = {
828
- id,
829
- employeeId,
830
- firstName,
831
- lastName,
832
- email,
833
- phone,
834
- birthDate,
835
- civilStatus,
836
- department,
837
- position,
838
- hireDate,
839
- salary,
840
- status,
841
- sssNumber,
842
- philhealthNumber,
843
- pagibigNumber,
844
- tinNumber,
845
- passportNumber,
846
- passportExpiry,
847
- nationalId,
848
- driversLicense
849
- };
850
- } else {
851
- // Adding new employee
852
- const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
853
-
854
- employees.push({
855
- id: newId,
856
- employeeId,
857
- firstName,
858
- lastName,
859
- email,
860
- phone,
861
- birthDate,
862
- civilStatus,
863
- department,
864
- position,
865
- hireDate,
866
- salary,
867
- status,
868
- sssNumber,
869
- philhealthNumber,
870
- pagibigNumber,
871
- tinNumber,
872
- passportNumber,
873
- passportExpiry,
874
- nationalId,
875
- driversLicense
876
- });
877
-
878
- if (!allDepartments.includes(department)) {
879
- allDepartments.push(department);
880
- saveDepartments();
881
- updateDepartmentFilterOptions();
882
- }
883
- }
884
 
885
- // Save to localStorage
886
- saveEmployees();
887
- closeEmployeeModal();
888
- extractDepartmentsFromEmployees();
889
  updateDepartmentFilterOptions();
890
- filterEmployees();
891
- }
892
-
893
- function getStatusClass(status) {
894
- switch(status) {
895
- case 'Active': return 'bg-green-100 text-green-800';
896
- case 'Inactive': return 'bg-red-100 text-red-800';
897
- case 'On Leave': return 'bg-yellow-100 text-yellow-800';
898
- default: return 'bg-gray-100 text-gray-800';
899
- }
900
  }
 
 
 
 
 
 
 
 
 
901
 
902
- function formatDate(dateString) {
903
- const options = { year: 'numeric', month: 'short', day: 'numeric' };
904
- return new Date(dateString).toLocaleDateString('en-US', options);
905
- }
 
 
 
 
906
 
907
- // FIXED: Export to CSV - Now includes the internal ID
908
- function exportToCSV() {
909
- const headers = ['ID', 'Employee ID', 'First Name', 'Last Name', 'Email', 'Phone', 'Birth Date', 'Civil Status', 'Department', 'Position', 'Hire Date', 'Salary', 'Status', 'SSS Number', 'PhilHealth Number', 'Pag-IBIG Number', 'TIN Number', 'Passport Number', 'Passport Expiry', 'National ID', 'Driver\'s License'];
910
- const csvContent = [
911
- headers.join(','),
912
- ...employees.map(emp => [
913
- `"${emp.id}"`,
914
- `"${emp.employeeId}"`,
915
- `"${emp.firstName}"`,
916
- `"${emp.lastName}"`,
917
- `"${emp.email || ''}"`,
918
- `"${emp.phone || ''}"`,
919
- `"${emp.birthDate || ''}"`,
920
- `"${emp.civilStatus || ''}"`,
921
- `"${emp.department}"`,
922
- `"${emp.position || ''}"`,
923
- `"${emp.hireDate || ''}"`,
924
- emp.salary,
925
- `"${emp.status}"`,
926
- `"${emp.sssNumber || ''}"`,
927
- `"${emp.philhealthNumber || ''}"`,
928
- `"${emp.pagibigNumber || ''}"`,
929
- `"${emp.tinNumber || ''}"`,
930
- `"${emp.passportNumber || ''}"`,
931
- `"${emp.passportExpiry || ''}"`,
932
- `"${emp.nationalId || ''}"`,
933
- `"${emp.driversLicense || ''}"`
934
- ].join(','))
935
- ].join('\n');
936
-
937
- // Create download link
938
- const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
939
- const url = URL.createObjectURL(blob);
940
- const link = document.createElement('a');
941
- link.setAttribute('href', url);
942
- link.setAttribute('download', `steelcraft_employees_${new Date().toISOString().slice(0, 10)}.csv`);
943
- link.style.visibility = 'hidden';
944
- document.body.appendChild(link);
945
- link.click();
946
- document.body.removeChild(link);
947
- }
948
 
949
- // Handle file import
950
- function handleFileImport(event) {
951
- const file = event.target.files[0];
952
- if (!file) return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
 
954
- const reader = new FileReader();
955
- reader.onload = function(e) {
956
- importFileContent = e.target.result;
957
- importConfirmationModal.classList.remove('hidden');
958
- };
959
- reader.readAsText(file);
960
- }
 
 
 
 
 
961
 
962
- // FIXED: Process import based on selected option with proper ID handling
963
- function processImport(mode) {
964
- if (!importFileContent) {
965
- alert('No file content to import');
966
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
967
  }
968
 
969
- // Improved CSV parsing
970
- const lines = importFileContent.split(/\r?\n/).filter(line => line.trim() !== '');
971
-
972
- if (lines.length < 2) {
973
- alert("CSV file must contain at least one header row and one data row");
974
- return;
975
  }
976
-
977
- // Parse headers and create mapping
978
- const headers = parseCSVLine(lines[0]).map(h => h.trim());
979
- const headerMap = createHeaderMap();
980
-
981
- // Skip header row and process data
982
- const importedEmployees = [];
983
- for (let i = 1; i < lines.length; i++) {
984
- if (!lines[i].trim()) continue;
985
-
986
- try {
987
- const values = parseCSVLine(lines[i]);
988
- if (values.length !== headers.length) {
989
- console.warn(`Skipping line ${i+1}: number of values doesn't match headers`);
990
- continue;
991
- }
992
-
993
- const employee = mapValuesToEmployee(values, headers, headerMap);
994
- if (!employee.firstName || !employee.lastName) {
995
- console.warn(`Skipping line ${i+1}: missing required fields (firstName or lastName)`);
996
- continue;
997
- }
998
 
999
- // Generate employee ID if not provided
1000
- if (!employee.employeeId) {
1001
- const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1002
- employee.employeeId = `EMP-${1000 + newId}`;
1003
- }
1004
-
1005
- importedEmployees.push(employee);
1006
- } catch (error) {
1007
- console.error(`Error processing line ${i+1}:`, error);
1008
- }
1009
- }
1010
-
1011
- // Process based on selected mode
1012
- let added = 0;
1013
- let updated = 0;
1014
-
1015
- switch(mode) {
1016
- case 'append':
1017
- // Add all imported employees as new records
1018
- importedEmployees.forEach(importedEmp => {
1019
- // Check if an employee with the same employeeId already exists
1020
- const existingIndex = employees.findIndex(e => e.employeeId === importedEmp.employeeId);
1021
- if (existingIndex >= 0) {
1022
- // If it exists, generate a new unique employeeId
1023
- const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1024
- importedEmp.employeeId = `EMP-${1000 + newId}`;
1025
- }
1026
-
1027
- // Assign a new unique id
1028
- importedEmp.id = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1029
- employees.push(importedEmp);
1030
- added++;
1031
- });
1032
- break;
1033
-
1034
- case 'merge':
1035
- // Merge - update existing and add new
1036
- importedEmployees.forEach(importedEmp => {
1037
- const existingIndex = employees.findIndex(e => e.employeeId === importedEmp.employeeId);
1038
- if (existingIndex >= 0) {
1039
- // Update existing, preserve the internal ID
1040
- const originalId = employees[existingIndex].id;
1041
- employees[existingIndex] = {
1042
- ...importedEmp,
1043
- id: originalId // Preserve internal ID
1044
- };
1045
- updated++;
1046
- } else {
1047
- // Add new with a fresh internal ID
1048
- importedEmp.id = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1049
- employees.push(importedEmp);
1050
- added++;
1051
- }
1052
- });
1053
- break;
1054
-
1055
- case 'replace':
1056
- // Replace all existing with imported, assigning new IDs
1057
- let idCounter = 1;
1058
- importedEmployees.forEach(emp => {
1059
- if (!emp.id) {
1060
- emp.id = idCounter++;
1061
- }
1062
- });
1063
- employees = importedEmployees;
1064
- added = importedEmployees.length;
1065
- break;
1066
  }
1067
 
1068
- // Save to localStorage and update UI
1069
- saveEmployees();
1070
- extractDepartmentsFromEmployees();
1071
- saveDepartments();
1072
- updateDepartmentFilterOptions();
1073
- filterEmployees();
1074
-
1075
- // Close modal and reset
1076
- importConfirmationModal.classList.add('hidden');
1077
- fileInput.value = '';
1078
- importFileContent = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1079
 
1080
- // Show results
1081
- let message = `Import completed successfully. `;
1082
- if (mode === 'merge') {
1083
- message += `${added} new employees added, ${updated} existing employees updated.`;
1084
- } else {
1085
- message += `${added} employees imported.`;
1086
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
1087
 
1088
- alert(message);
1089
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1090
 
1091
- // FIXED: Updated createHeaderMap to include the internal ID
1092
- function createHeaderMap() {
1093
- return {
1094
- 'ID': 'id',
1095
- 'Employee ID': 'employeeId',
1096
- 'First Name': 'firstName',
1097
- 'Last Name': 'lastName',
1098
- 'Email': 'email',
1099
- 'Phone': 'phone',
1100
- 'Birth Date': 'birthDate',
1101
- 'Civil Status': 'civilStatus',
1102
- 'Department': 'department',
1103
- 'Position': 'position',
1104
- 'Hire Date': 'hireDate',
1105
- 'Salary': 'salary',
1106
- 'Status': 'status',
1107
- 'SSS Number': 'sssNumber',
1108
- 'PhilHealth Number': 'philhealthNumber',
1109
- 'Pag-IBIG Number': 'pagibigNumber',
1110
- 'TIN Number': 'tinNumber',
1111
- 'Passport Number': 'passportNumber',
1112
- 'Passport Expiry': 'passportExpiry',
1113
- 'National ID': 'nationalId',
1114
- 'Driver\'s License': 'driversLicense',
1115
- 'EmployeeId': 'employeeId',
1116
- 'Firstname': 'firstName',
1117
- 'Lastname': 'lastName',
1118
- 'SSS': 'sssNumber',
1119
- 'Philhealth': 'philhealthNumber',
1120
- 'Pag-ibig': 'pagibigNumber',
1121
- 'TIN': 'tinNumber'
1122
- };
1123
- }
1124
 
1125
- // FIXED: Updated mapValuesToEmployee function to handle the ID properly
1126
- function mapValuesToEmployee(values, headers, headerMap) {
1127
- const employee = {};
1128
 
1129
- for (let j = 0; j < headers.length; j++) {
1130
- const header = headers[j].trim();
1131
- let value = values[j] || '';
1132
-
1133
- if (!headerMap[header] || value === '') continue;
1134
-
1135
- const propName = headerMap[header];
1136
-
1137
- // Type conversion
1138
- if (propName === 'salary') {
1139
- value = parseFloat(value.replace(/[^\d.]/g, '')) || 0;
1140
- } else if (propName === 'id') {
1141
- // Convert id to integer
1142
- value = parseInt(value) || null;
1143
- } else if (propName === 'hireDate' || propName === 'birthDate' || propName === 'passportExpiry') {
1144
- // Date formatting
1145
- if (/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(value)) {
1146
- const [month, day, year] = value.split('/');
1147
- value = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
1148
- }
1149
- const date = new Date(value);
1150
- if (!isNaN(date.getTime())) {
1151
- value = date.toISOString().split('T')[0];
1152
- }
1153
- }
1154
-
1155
- employee[propName] = value;
1156
  }
1157
-
1158
- return employee;
1159
  }
 
 
 
1160
 
1161
- // Improved CSV line parsing that handles quoted values with commas
1162
- function parseCSVLine(line) {
1163
- const values = [];
1164
- let current = '';
1165
- let inQuotes = false;
1166
- let inEscape = false;
1167
-
1168
- for (let i = 0; i < line.length; i++) {
1169
- const char = line[i];
1170
 
1171
- if (inEscape) {
1172
- current += char;
1173
- inEscape = false;
1174
- continue;
1175
- }
 
1176
 
1177
- if (char === '\\') {
1178
- inEscape = true;
1179
- continue;
1180
- }
1181
 
1182
- if (char === '"') {
1183
- inQuotes = !inQuotes;
1184
- continue;
1185
- }
 
1186
 
1187
- if (char === ',' && !inQuotes) {
1188
- values.push(current);
1189
- current = '';
1190
- continue;
1191
- }
1192
 
1193
- current += char;
1194
- }
 
 
1195
 
1196
- // Add the last value
1197
  values.push(current);
1198
-
1199
- // Trim whitespace and remove surrounding quotes if present
1200
- return values.map(val => {
1201
- val = val.trim();
1202
- if (val.startsWith('"') && val.endsWith('"')) {
1203
- return val.slice(1, -1);
1204
- }
1205
- return val;
1206
- });
1207
  }
1208
 
1209
- // Clear all confirmation modal
1210
- function openClearAllConfirmationModal() {
1211
- clearAllConfirmationModal.classList.remove('hidden');
1212
- }
1213
 
1214
- // Clear all employees
1215
- function clearAllEmployees() {
1216
- employees = [];
1217
- saveEmployees();
1218
- extractDepartmentsFromEmployees();
1219
- saveDepartments();
1220
- updateDepartmentFilterOptions();
1221
- filterEmployees();
1222
- clearAllConfirmationModal.classList.add('hidden');
1223
- alert('All employee data has been cleared.');
1224
  }
1225
- </script>
1226
- <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=poluser/hr-test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
1227
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  transform: scale(0.9);
67
  pointer-events: none;
68
  }
69
+ /* New style for hover effect on table rows */
70
+ .employee-row {
71
+ transition: background-color 0.2s ease;
72
+ }
73
+ .employee-row:hover {
74
+ background-color: #f8fafc;
75
+ cursor: pointer;
76
+ }
77
  </style>
78
  </head>
79
  <body class="bg-gray-100">
 
191
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
192
  <div>
193
  <label for="lastName" class="block text-sm font-medium text-gray-700 mb-1">Last Name</label>
194
+ <input type="text" id="lastName", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" required>
195
  </div>
196
  <div>
197
  <label for="email" class="table text-sm font-medium text-gray-700 mb-1">Email</label>
 
233
  </div>
234
  <div>
235
  <label for="hireDate" class="block text-sm font-medium text-gray-700 mb-1">Hire Date</label>
236
+ <input type="date", id="hireDate" class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
237
  </div>
238
  </div>
239
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
240
  <div>
241
  <label for="salary" class="block text-sm font-medium text-gray-700 mb-1">Salary</label>
242
+ <input type="number" id="salary", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
243
  </div>
244
  <div>
245
  <label for="status" class="block text-sm font-medium text-gray-700 mb-1">Status</label>
246
+ <select id="status", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
247
  <option value="Active">Active</option>
248
  <option value="Inactive">Inactive</option>
249
  <option value="On Leave">On Leave</option>
 
257
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
258
  <div>
259
  <label for="sssNumber" class="block text-sm font-medium text-gray-700 mb-1">SSS Number</label>
260
+ <input type="text" id="sssNumber", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX-XXXXXXX-X">
261
  </div>
262
  <div>
263
  <label for="philhealthNumber" class="block text-sm font-medium text-gray-700 mb-1">PhilHealth Number</label>
264
+ <input type="text" id="philhealthNumber", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX-XXXXXXXXX-X">
265
  </div>
266
  </div>
267
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
268
  <div>
269
  <label for="pagibigNumber" class="block text-sm font-medium text-gray-700 mb-1">Pag-IBIG Number</label>
270
+ <input type="text" id="pagibigNumber", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XXXX-XXXX-XXXX">
271
  </div>
272
  <div>
273
  <label for="tinNumber" class="block text-sm font-medium text-gray-700 mb-1">TIN Number</label>
274
+ <input type="text" id="tinNumber", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XXX-XXX-XXX-XXX">
275
  </div>
276
  </div>
277
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
278
  <div>
279
  <label for="passportNumber" class="block text-sm font-medium text-gray-700 mb-1">Philippine Passport</label>
280
+ <input type="text" id="passportNumber", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX1234567">
281
  </div>
282
  <div>
283
  <label for="passportExpiry" class="block text-sm font-medium text-gray-700 mb-1">Passport Expiry</label>
284
+ <input type="date" id="passportExpiry", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
285
  </div>
286
  </div>
287
  <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
288
  <div>
289
  <label for="nationalId" class="block text-sm font-medium text-gray-700 mb-1">Philippine National ID</label>
290
+ <input type="text" id="nationalId", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XXXX-XXXX-XXXX-XXXX">
291
  </div>
292
  <div>
293
  <label for="driversLicense" class="block text-sm font-medium text-gray-700 mb-1">Driver's License</label>
294
+ <input type="text" id="driversLicense", class="w-full border rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="XX-XX-XXXXXX">
295
  </div>
296
  </div>
297
  </div>
 
339
  </div>
340
 
341
  <!-- Clear All Confirmation Modal -->
342
+ <div id="clearAllConfirmationModal", class="fixed inset-0 bg-gray-600 bg-opacity-50 flex items-center justify-center z-50 confirmation-modal hidden">
343
  <div class="bg-white rounded-lg shadow-xl w-full max-w-md">
344
  <div class="flex justify-between items-center border-b px-6 py-4">
345
  <h3 class="text-lg font-semibold">Confirm Clear All</h3>
 
353
  <button id="cancelClearAll" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50">
354
  Cancel
355
  </button>
356
+ <button id="confirmClearAll", class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700">
357
  Clear All Data
358
  </button>
 
359
  </div>
360
  </div>
361
  </div>
362
+ </div>
363
 
364
+ <!-- Employee List -->
365
+ <div class="bg-white p-6 rounded-xl shadow-sm border border-gray-200 mb-6">
366
+ <div class="flex justify-between items-center mb-4">
367
+ <h2 class="text-lg font-semibold">All Employees</h2>
368
+ <div class="flex items-center space-x-2">
369
+ <select id="departmentFilter" class="border rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
370
+ <option value="">All Departments</option>
371
+ </select>
372
+ <select id="statusFilter" class="border rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
373
+ <option value="">All Statuses</option>
374
+ <option value="Active">Active</option>
375
+ <option value="Inactive">Inactive</option>
376
+ <option value="On Leave">On Leave</option>
377
+ </select>
 
378
  </div>
379
+ </div>
380
+ <div class="overflow-x-auto">
381
+ <table class="min-w-full divide-y divide-gray-200">
382
+ <thead class="bg-gray-50">
383
+ <tr>
384
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Employee ID</th>
385
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
386
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Department</th>
387
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Position</th>
388
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">SSS</th>
389
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">PhilHealth</th>
390
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
391
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
392
+ </tr>
393
+ </thead>
394
+ <tbody class="bg-white divide-y divide-gray-200" id="employeeTableBody">
395
+ <!-- Rows will be inserted by JavaScript -->
396
+ </tbody>
397
+ </table>
398
+ </div>
399
+ <div class="mt-4 flex items-center justify-between">
400
+ <div class="text-sm text-gray-500">
401
+ Showing <span id="startEmployee">1</span> to <span id="endEmployee">10</span> of <span id="totalEmployees">0</span> employees
402
  </div>
403
+ <div class="flex space-x=2">
404
+ <button id="prevEmployeePage" class="px-3 py-1 border rounded-lg text-sm hover:bg-gray-50 disabled:opacity-50" disabled>
405
+ Previous
406
+ </button>
407
+ <button id="nextEmployeePage", class="px-3 py-1 border rounded-lg text-sm hover:bg-gray-50 disabled:opacity-50">
408
+ Next
409
+ </button>
 
 
 
 
 
410
  </div>
411
  </div>
412
  </div>
413
  </div>
414
+ </div>
415
 
416
+ <script>
417
+ // Storage keys
418
+ const STORAGE_KEY = 'steelcraft_payroll_employees';
419
+ const DEPARTMENTS_KEY = 'steelcraft_payroll_departments';
420
+
421
+ // Employee data - initially load from localStorage
422
+ let employees = loadEmployees();
423
+ let allDepartments = loadDepartments();
424
+
425
+ // If no data in localStorage, initialize with default values
426
+ if (employees.length === 0) {
427
+ employees = [
428
+ {
429
+ id: 1,
430
+ employeeId: "EMP-1001",
431
+ firstName: "Juan",
432
+ lastName: "Dela Cruz",
433
+ email: "juan.delacruz@steelcraft.com",
434
+ phone: "09171234567",
435
+ department: "Fabrication",
436
+ position: "Welder",
437
+ hireDate: "2020-05-15",
438
+ birthDate: "1985-03-12",
439
+ salary: 25000,
440
+ status: "Active"
441
+ }
442
+ ];
443
+ saveEmployees();
444
+ }
445
+
446
+ // If no departments in localStorage, initialize from employees
447
+ if (allDepartments.length === 0) {
448
+ extractDepartmentsFromEmployees();
449
+ saveDepartments();
450
+ }
451
+
452
+ // Pagination
453
+ let currentPage = 1;
454
+ const rowsPerPage = 20;
455
+ let filteredEmployees = [...employees];
456
+
457
+ // File import variables
458
+ let importFileContent = null;
459
+
460
+ // DOM elements
461
+ const employeeTableBody = document.getElementById('employeeTableBody');
462
+ const departmentInput = document.getElementById('departmentInput');
463
+ const departmentSuggestions = document.getElementById('departmentSuggestions');
464
+ const departmentFilter = document.getElementById('departmentFilter');
465
+ const statusFilter = document.getElementById('statusFilter');
466
+ const employeeSearch = document.getElementById('employeeSearch');
467
+ const addEmployeeBtn = document.getElementById('addEmployeeBtn');
468
+ const clearAllBtn = document.getElementById('clearAllBtn');
469
+ const exportCSVBtn = document.getElementById('exportCSVBtn');
470
+ const importCSVBtn = document.getElementById('importCSVBtn');
471
+ const fileInput = document.getElementById('fileInput');
472
+ const employeeModal = document.getElementById('employeeModal');
473
+ const employeeForm = document.getElementById('employeeForm');
474
+ const closeModal = document.getElementById('closeModal');
475
+ const cancelEmployee = document.getElementById('cancelEmployee');
476
+ const modalTitle = document.getElementById('modalTitle');
477
+ const employeeIdInput = document.getElementById('employeeId');
478
+ const employeeIdDisplayInput = document.getElementById('employeeIdInput');
479
+ const prevEmployeePage = document.getElementById('prevEmployeePage');
480
+ const nextEmployeePage = document.getElementById('nextEmployeePage');
481
+ const startEmployee = document.getElementById('startEmployee');
482
+ const endEmployee = document.getElementById('endEmployee');
483
+ const totalEmployees = document.getElementById('totalEmployees');
484
+ const tabButtons = document.querySelectorAll('.tab-button');
485
+ const tabContents = document.querySelectorAll('.tab-content');
486
+
487
+ // Import confirmation modal elements
488
+ const importConfirmationModal = document.getElementById('importConfirmationModal');
489
+ const closeImportConfirmationModal = document.getElementById('closeImportConfirmationModal');
490
+ const appendDataBtn = document.getElementById('appendDataBtn');
491
+ const mergeDataBtn = document.getElementById('mergeDataBtn');
492
+ const replaceDataBtn = document.getElementById('replaceDataBtn');
493
+
494
+ // Clear all confirmation modal elements
495
+ const clearAllConfirmationModal = document.getElementById('clearAllConfirmationModal');
496
+ const closeClearAllConfirmationModal = document.getElementById('closeClearAllConfirmationModal');
497
+ const cancelClearAll = document.getElementById('cancelClearAll');
498
+ const confirmClearAll = document.getElementById('confirmClearAll');
499
+
500
+ // Storage functions
501
+ function saveEmployees() {
502
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(employees));
503
+ }
504
+
505
+ function loadEmployees() {
506
+ const data = localStorage.getItem(STORAGE_KEY);
507
+ return data ? JSON.parse(data) : [];
508
+ }
509
+
510
+ function saveDepartments() {
511
+ localStorage.setItem(DEPARTMENTS_KEY, JSON.stringify(allDepartments));
512
+ }
513
+
514
+ function loadDepartments() {
515
+ const data = localStorage.getItem(DEPARTMENTS_KEY);
516
+ return data ? JSON.parse(data) : [];
517
+ }
518
+
519
+ // Initialize
520
+ document.addEventListener('DOMContentLoaded', () => {
521
+ updateDepartmentFilterOptions();
522
+ renderEmployeeTable();
523
+ setupEventListeners();
524
+ setupTabs();
525
+ });
526
+
527
+ function setupTabs() {
528
+ tabButtons.forEach(button => {
529
+ button.addEventListener('click', () => {
530
+ const tabId = button.getAttribute('data-tab');
531
+
532
+ // Update active tab button
533
+ tabButtons.forEach(btn => btn.classList.remove('active'));
534
+ button.classList.add('active');
535
+
536
+ // Update active tab content
537
+ tabContents.forEach(content => {
538
+ content.classList.remove('active');
539
+ if (content.id === `${tabId}-tab`) {
540
+ content.classList.add('active');
541
+ }
542
+ });
543
+ });
544
+ });
545
+ }
546
+
547
+ function extractDepartmentsFromEmployees() {
548
+ const departmentsSet = new Set();
549
+ employees.forEach(emp => departmentsSet.add(emp.department));
550
+ allDepartments = Array.from(departmentsSet);
551
+ }
552
+
553
+ function updateDepartmentFilterOptions() {
554
+ departmentFilter.innerHTML = '<option value="">All Departments</option>';
555
+ allDepartments.forEach(dep => {
556
+ const option = document.createElement('option');
557
+ option.value = dep;
558
+ option.textContent = dep;
559
+ departmentFilter.appendChild(option);
560
+ });
561
+ }
562
 
563
+ function setupEventListeners() {
564
+ addEmployeeBtn.addEventListener('click', () => openEmployeeModal());
 
565
 
566
+ clearAllBtn.addEventListener('click', () => openClearAllConfirmationModal());
567
+ exportCSVBtn.addEventListener('click', exportToCSV);
568
+ importCSVBtn.addEventListener('click', () => fileInput.click());
569
+ fileInput.addEventListener('change', handleFileImport);
570
+ closeModal.addEventListener('click', closeEmployeeModal);
571
+ cancelEmployee.addEventListener('click', closeEmployeeModal);
572
+ employeeForm.addEventListener('submit', (e) => {
573
+ e.preventDefault();
574
+ saveEmployee();
575
+ });
576
+ employeeSearch.addEventListener('input', filterEmployees);
577
+ departmentFilter.addEventListener('change', filterEmployees);
578
+ statusFilter.addEventListener('change', filterEmployees);
579
+ departmentInput.addEventListener('input', handleDepartmentInput);
580
+ prevEmployeePage.addEventListener('click', () => {
581
+ if (currentPage > 1) {
582
+ currentPage--;
583
+ renderEmployeeTable();
584
+ }
585
+ });
586
+ nextEmployeePage.addEventListener('click', () => {
587
+ if (currentPage * rowsPerPage < filteredEmployees.length) {
588
+ currentPage++;
589
+ renderEmployeeTable();
590
+ }
591
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
592
 
593
+ // Import confirmation modal events
594
+ closeImportConfirmationModal.addEventListener('click', () => importConfirmationModal.classList.add('hidden'));
595
+ appendDataBtn.addEventListener('click', () => processImport('append'));
596
+ mergeDataBtn.addEventListener('click', () => processImport('merge'));
597
+ replaceDataBtn.addEventListener('click', () => processImport('replace'));
 
598
 
599
+ // Clear all confirmation modal events
600
+ closeClearAllConfirmationModal.addEventListener('click', () => clearAllConfirmationModal.classList.add('hidden'));
601
+ cancelClearAll.addEventListener('click', () => clearAllConfirmationModal.classList.add('hidden'));
602
+ confirmClearAll.addEventListener('click', clearAllEmployees);
603
+ }
604
+
605
+ function handleDepartmentInput(e) {
606
+ const value = e.target.value.trim().toLowerCase();
607
+ departmentSuggestions.innerHTML = '';
608
+ departmentSuggestions.classList.add('hidden');
609
+
610
+ if (value.length > 0) {
611
+ const matches = allDepartments.filter(dep => dep.toLowerCase().includes(value));
612
+
613
+ if (matches.length > 0) {
614
+ departmentSuggestions.classList.remove('hidden');
615
+ matches.forEach(dep => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  const li = document.createElement('li');
617
+ li.textContent = dep;
618
+ li.className = 'px-3 py-2 cursor-pointer hover:bg-blue-100';
619
  li.addEventListener('click', () => {
620
+ departmentInput.value = dep;
621
+ departmentSuggestions.classList.add('hidden');
 
 
 
 
 
 
622
  });
623
  departmentSuggestions.appendChild(li);
624
+ });
625
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
626
 
627
+ const isCustom = !allDepartments.includes(departmentInput.value) && departmentInput.value.trim() !== '';
628
+ if (isCustom) {
629
+ const li = document.createElement('li');
630
+ li.textContent = `Add "${departmentInput.value}"`;
631
+ li.className = 'px-3 py-2 cursor-pointer hover:bg-green-100 text-green-700';
632
+ li.addEventListener('click', () => {
633
+ const newDep = departmentInput.value.trim();
634
+ if (!allDepartments.includes(newDep)) {
635
+ allDepartments.push(newDep);
636
+ saveDepartments();
637
+ departmentInput.value = newDep;
638
+ updateDepartmentFilterOptions();
639
+ departmentSuggestions.classList.add('hidden');
640
+ }
641
+ });
642
+ departmentSuggestions.appendChild(li);
643
+ }
644
  }
645
+ }
646
 
647
+ function filterEmployees() {
648
+ const searchTerm = employeeSearch.value.toLowerCase();
649
+ const department = departmentFilter.value;
650
+ const status = statusFilter.value;
651
 
652
+ filteredEmployees = employees.filter(emp => {
653
+ const fullName = `${emp.firstName} ${emp.lastName}`.toLowerCase();
654
+ const matchesSearch = fullName.includes(searchTerm) || emp.employeeId.toLowerCase().includes(searchTerm);
655
+ const matchesDepartment = department ? emp.department === department : true;
656
+ const matchesStatus = status ? emp.status === status : true;
657
 
658
+ return matchesSearch && matchesDepartment && matchesStatus;
659
+ });
660
+
661
+ currentPage = 1;
662
+ renderEmployeeTable();
663
+ }
664
+
665
+ function renderEmployeeTable() {
666
+ const start = (currentPage - 1) * rowsPerPage;
667
+ const end = start + rowsPerPage;
668
+ const paginatedEmployees = filteredEmployees.slice(start, end);
669
+
670
+ employeeTableBody.innerHTML = '';
671
+
672
+ if (paginatedEmployees.length === 0) {
673
+ employeeTableBody.innerHTML = `
674
+ <tr>
675
+ <td colspan="8" class="px-6 py-4 text-center text-gray-500">No employees found</td>
676
+ </tr>
677
+ `;
678
+ } else {
679
+ paginatedEmployees.forEach(emp => {
680
+ const row = document.createElement('tr');
681
+ row.className = 'employee-row';
682
+ row.dataset.id = emp.id;
683
+ row.innerHTML = `
684
+ <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${emp.employeeId}</td>
685
+ <td class="px=6 py-4 whitespace-nowrap">
686
+ <div class="flex items-center">
687
+ <div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center">
688
+ <i class="fas fa-user text-blue-600"></i>
689
+ </div>
690
+ <div class="ml-4">
691
+ <div class="text-sm font-medium text-gray-900">${emp.firstName} ${emp.lastName}</div>
692
+ <div class="text-sm text-gray-500">${emp.email || 'No email'}</div>
693
  </div>
694
+ </div>
695
+ </td>
696
+ <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${emp.department}</td>
697
+ <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">${emp.position}</td>
698
+ <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${emp.sssNumber || 'N/A'}</td>
699
+ <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${emp.philhealthNumber || 'N/A'}</td>
700
+ <td class="px-6 py-4 whitespace-nowrap">
701
+ <span class="px-2 inline-flex text-xs leading-5 font-semibell rounded-full ${getStatusClass(emp.status)}">
702
+ ${emp.status}
703
+ </span>
704
+ </td>
705
+ <td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
706
+ <button class="text-blue-600 hover:text-blue-900 mr-3 edit-btn" data-id="${emp.id}">Edit</button>
707
+ <button class="text-red-600 hover:text-red-900 delete-btn" data-id="${emp.id}">Delete</button>
708
+ </td>
709
+ `;
710
+ employeeTableBody.appendChild(row);
711
+
712
+ // Add double click listener to the row
713
+ row.addEventListener('dblclick', (e) => {
714
+ // Don't trigger if clicking on action buttons
715
+ if (e.target.tagName === 'BUTTON' || e.target.closest('button')) {
716
+ return;
717
+ }
718
+ openEmployeeModal(emp.id);
719
  });
720
+ });
721
 
722
+ // Add event listeners to edit and delete buttons
723
+ document.querySelectorAll('.edit-btn').forEach(btn => {
724
+ btn.addEventListener('click', (e) => {
725
+ const id = parseInt(e.target.getAttribute('data-id'));
726
+ openEmployeeModal(id);
 
727
  });
728
+ });
729
 
730
+ document.querySelectorAll('.delete-btn').forEach(btn => {
731
+ btn.addEventListener('click', (e) => {
732
+ const id = parseInt(e.target.getAttribute('data-id'));
733
+ deleteEmployee(id);
 
734
  });
735
+ });
 
 
 
 
 
 
736
  }
737
 
738
+ startEmployee.textContent = filteredEmployees.length > 0 ? start + 1 : 0;
739
+ endEmployee.textContent = Math.min(end, filteredEmployees.length);
740
+ totalEmployees.textContent = filteredEmployees.length;
741
+ prevEmployeePage.disabled = currentPage === 1;
742
+ nextEmployeePage.disabled = end >= filteredEmployees.length;
743
+ }
744
+
745
+ function deleteEmployee(id) {
746
+ if (confirm("Are you sure you want to delete this employee?")) {
747
+ const index = employees.findIndex(emp => emp.id === id);
748
+
749
+ if (index !== -1) {
750
+ employees.splice(index, 1);
751
+ saveEmployees();
752
+ extractDepartmentsFromEmployees();
753
+ saveDepartments();
754
+ updateDepartmentFilterOptions();
755
+ filterEmployees();
756
+ alert('Employee deleted successfully.');
757
  }
758
  }
759
+ }
760
 
761
+ function openEmployeeModal(id = null) {
762
+ console.log('Opening modal for employee ID:', id);
763
+
764
+ if (id) {
765
+ const employee = employees.find(e => e.id === id);
766
+ console.log('Found employee:', employee);
767
 
768
+ if (employee) {
769
+ modalTitle.textContent = 'Edit Employee';
770
+ employeeIdInput.value = employee.id;
771
+ employeeIdDisplayInput.value = employee.employeeId;
772
+ document.getElementById('firstName').value = employee.firstName;
773
+ document.getElementById('lastName').value = employee.lastName;
774
+ document.getElementById('email').value = employee.email || '';
775
+ document.getElementById('phone').value = employee.phone || '';
776
+ document.getElementById('birthDate').value = employee.birthDate || '';
777
+ document.getElementById('civilStatus').value = employee.civilStatus || '';
778
+ departmentInput.value = employee.department;
779
+ document.getElementById('position').value = employee.position;
780
+ document.getElementById('hireDate').value = employee.hireDate;
781
+ document.getElementById('salary').value = employee.salary;
782
+ document.getElementById('status').value = employee.status;
783
 
784
+ // Philippine Government data
785
+ document.getElementById('sssNumber').value = employee.sssNumber || '';
786
+ document.getElementById('philhealthNumber').value = employee.philhealthNumber || '';
787
+ document.getElementById('pagibigNumber').value = employee.pagibigNumber || '';
788
+ document.getElementById('tinNumber').value = employee.tinNumber || '';
789
+ document.getElementById('passportNumber').value = employee.passportNumber || '';
790
+ document.getElementById('passportExpiry').value = employee.passportExpiry || '';
791
+ document.getElementById('nationalId').value = employee.nationalId || '';
792
+ document.getElementById('driversLicense').value = employee.driversLicense || '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
793
  }
794
+ } else {
795
+ modalTitle.textContent = 'Add New Employee';
796
+ employeeForm.reset();
797
+ employeeIdInput.value = '';
798
+ employeeIdDisplayInput.value = '';
799
+ departmentInput.value = '';
800
+
801
+ // Generate new employee ID for new employees
802
+ const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
803
+ employeeIdDisplayInput.value = `EMP-${1000 + newId}`;
804
  }
805
 
806
+ employeeModal.classList.remove('hidden');
807
+ }
808
+
809
+ function closeEmployeeModal() {
810
+ employeeModal.classList.add('hidden');
811
+ }
812
+
813
+ function saveEmployee() {
814
+ const id = employeeIdInput.value ? parseInt(employeeIdInput.value) : null;
815
+ const employeeId = employeeIdDisplayInput.value.trim();
816
+ const firstName = document.getElementById('firstName').value;
817
+ const lastName = document.getElementById('lastName').value;
818
+ const email = document.getElementById('email').value || null;
819
+ const phone = document.getElementById('phone').value || null;
820
+ const birthDate = document.getElementById('birthDate').value || null;
821
+ const civilStatus = document.getElementById('civilStatus').value || null;
822
+ const department = departmentInput.value.trim();
823
+ const position = document.getElementById('position').value || null;
824
+ const hireDate = document.getElementById('hireDate').value || null;
825
+ const salary = document.getElementById('salary').value ? parseFloat(document.getElementById('salary').value) : 0;
826
+ const status = document.getElementById('status').value || 'Active';
827
+
828
+ // Philippine Government data
829
+ const sssNumber = document.getElementById('sssNumber').value || null;
830
+ const philhealthNumber = document.getElementById('philhealthNumber').value || null;
831
+ const pagibigNumber = document.getElementById('pagibigNumber').value || null;
832
+ const tinNumber = document.getElementById('tinNumber').value || null;
833
+ const passportNumber = document.getElementById('passportNumber').value || null;
834
+ const passportExpiry = document.getElementById('passportExpiry').value || null;
835
+ const nationalId = document.getElementById('nationalId').value || null;
836
+ const driversLicense = document.getElementById('driversLicense').value || null;
837
+
838
+ if (!employeeId || !firstName || !lastName) {
839
+ alert("Employee ID, first name and last name are required.");
840
+ return;
841
  }
842
 
843
+ if (id) {
844
+ // Editing existing employee
845
+ const index = employees.findIndex(e => e.id === id);
846
+ employees[index] = {
847
+ id,
848
+ employeeId,
849
+ firstName,
850
+ lastName,
851
+ email,
852
+ phone,
853
+ birthDate,
854
+ civilStatus,
855
+ department,
856
+ position,
857
+ hireDate,
858
+ salary,
859
+ status,
860
+ sssNumber,
861
+ philhealthNumber,
862
+ pagibigNumber,
863
+ tinNumber,
864
+ passportNumber,
865
+ passportExpiry,
866
+ nationalId,
867
+ driversLicense
868
+ };
869
+ } else {
870
+ // Adding new employee
871
+ const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
872
 
873
+ employees.push({
874
+ id: newId,
875
+ employeeId,
876
+ firstName,
877
+ lastName,
878
+ email,
879
+ phone,
880
+ birthDate,
881
+ civilStatus,
882
+ department,
883
+ position,
884
+ hireDate,
885
+ salary,
886
+ status,
887
+ sssNumber,
888
+ philhealthNumber,
889
+ pagibigNumber,
890
+ tinNumber,
891
+ passportNumber,
892
+ passportExpiry,
893
+ nationalId,
894
+ driversLicense
895
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
896
 
897
+ if (!allDepartments.includes(department)) {
898
+ allDepartments.push(department);
899
+ saveDepartments();
 
900
  updateDepartmentFilterOptions();
 
 
 
 
 
 
 
 
 
 
901
  }
902
+ }
903
+
904
+ // Save to localStorage
905
+ saveEmployees();
906
+ closeEmployeeModal();
907
+ extractDepartmentsFromEmployees();
908
+ updateDepartmentFilterOptions();
909
+ filterEmployees();
910
+ }
911
 
912
+ function getStatusClass(status) {
913
+ switch(status) {
914
+ case 'Active': return 'bg-green-100 text-green-800';
915
+ case 'Inactive': return 'bg-red-100 text-red-800';
916
+ case 'On Leave': return 'bg-yellow-100 text-yellow-800';
917
+ default: return 'bg-gray-100 text-gray-800';
918
+ }
919
+ }
920
 
921
+ function formatDate(dateString) {
922
+ const options = { year: 'numeric', month: 'short', day: 'numeric' };
923
+ return new Date(dateString).toLocaleDateString('en-US', options);
924
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
925
 
926
+ // FIXED: Export to CSV - Now includes the internal ID
927
+ function exportToCSV() {
928
+ const headers = ['ID', 'Employee ID', 'First Name', 'Last Name', 'Email', 'Phone', 'Birth Date', 'Civil Status', 'Department', 'Position', 'Hire Date', 'Salary', 'Status', 'SSS Number', 'PhilHealth Number', 'Pag-IBIG Number', 'TIN Number', 'Passport Number', 'Passport Expiry', 'National ID', 'Driver\'s License'];
929
+ const csvContent = [
930
+ headers.join(','),
931
+ ...employees.map(emp => [
932
+ `"${emp.id}"`,
933
+ `"${emp.employeeId}"`,
934
+ `"${emp.firstName}"`,
935
+ `"${emp.lastName}"`,
936
+ `"${emp.email || ''}"`,
937
+ `"${emp.phone || ''}"`,
938
+ `"${emp.birthDate || ''}"`,
939
+ `"${emp.civilStatus || ''}"`,
940
+ `"${emp.department}"`,
941
+ `"${emp.position || ''}"`,
942
+ `"${emp.hireDate || ''}"`,
943
+ emp.salary,
944
+ `"${emp.status}"`,
945
+ `"${emp.sssNumber || ''}"`,
946
+ `"${emp.philhealthNumber || ''}"`,
947
+ `"${emp.pagibigNumber || ''}"`,
948
+ `"${emp.tinNumber || ''}"`,
949
+ `"${emp.passportNumber || ''}"`,
950
+ `"${emp.passportExpiry || ''}"`,
951
+ `"${emp.nationalId || ''}"`,
952
+ `"${emp.driversLicense || ''}"`
953
+ ].join(','))
954
+ ].join('\n');
955
+
956
+ // Create download link
957
+ const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
958
+ const url = URL.createObjectURL(blob);
959
+ const link = document.createElement('a');
960
+ link.setAttribute('href', url);
961
+ link.setAttribute('download', `steelcraft_employees_${new Date().toISOString().slice(0, 10)}.csv`);
962
+ link.style.visibility = 'hidden';
963
+ document.body.appendChild(link);
964
+ link.click();
965
+ document.body.removeChild(link);
966
+ }
967
 
968
+ // Handle file import
969
+ function handleFileImport(event) {
970
+ const file = event.target.files[0];
971
+ if (!file) return;
972
+
973
+ const reader = new FileReader();
974
+ reader.onload = function(e) {
975
+ importFileContent = e.target.result;
976
+ importConfirmationModal.classList.remove('hidden');
977
+ };
978
+ reader.readAsText(file);
979
+ }
980
 
981
+ // FIXED: Process import based on selected option with proper ID handling
982
+ function processImport(mode) {
983
+ if (!importFileContent) {
984
+ alert('No file content to import');
985
+ return;
986
+ }
987
+
988
+ // Improved CSV parsing
989
+ const lines = importFileContent.split(/\r?\n/).filter(line => line.trim() !== '');
990
+
991
+ if (lines.length < 2) {
992
+ alert("CSV file must contain at least one header row and one data row");
993
+ return;
994
+ }
995
+
996
+ // Parse headers and create mapping
997
+ const headers = parseCSVLine(lines[0]).map(h => h.trim());
998
+ const headerMap = createHeaderMap();
999
+
1000
+ // Skip header row and process data
1001
+ const importedEmployees = [];
1002
+ for (let i = 1; i < lines.length; i++) {
1003
+ if (!lines[i].trim()) continue;
1004
+
1005
+ try {
1006
+ const values = parseCSVLine(lines[i]);
1007
+ if (values.length !== headers.length) {
1008
+ console.warn(`Skipping line ${i+1}: number of values doesn't match headers`);
1009
+ continue;
1010
  }
1011
 
1012
+ const employee = mapValuesToEmployee(values, headers, headerMap);
1013
+ if (!employee.firstName || !employee.lastName) {
1014
+ console.warn(`Skipping line ${i+1}: missing required fields (firstName or lastName)`);
1015
+ continue;
 
 
1016
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
 
1018
+ // Generate employee ID if not provided
1019
+ if (!employee.employeeId) {
1020
+ const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1021
+ employee.employeeId = `EMP-${1000 + newId}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022
  }
1023
 
1024
+ importedEmployees.push(employee);
1025
+ } catch (error) {
1026
+ console.error(`Error processing line ${i+1}:`, error);
1027
+ }
1028
+ }
1029
+
1030
+ // Process based on selected mode
1031
+ let added = 0;
1032
+ let updated = 0;
1033
+
1034
+ switch(mode) {
1035
+ case 'append':
1036
+ // Add all imported employees as new records
1037
+ importedEmployees.forEach(importedEmp => {
1038
+ // Check if an employee with the same employeeId already exists
1039
+ const existingIndex = employees.findIndex(e => e.employeeId === importedEmp.employeeId);
1040
+ if (existingIndex >= 0) {
1041
+ // If it exists, generate a new unique employeeId
1042
+ const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1043
+ importedEmp.employeeId = `EMP-${1000 + newId}`;
1044
+ }
1045
+
1046
+ // Assign a new unique id
1047
+ importedEmp.id = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1048
+ employees.push(importedEmp);
1049
+ added++;
1050
+ });
1051
+ break;
1052
 
1053
+ case 'merge':
1054
+ // Merge - update existing and add new
1055
+ importedEmployees.forEach(importedEmp => {
1056
+ const existingIndex = employees.findIndex(e => e.employeeId === importedEmp.employeeId);
1057
+ if (existingIndex >= 0) {
1058
+ // Update existing, preserve the internal ID
1059
+ const originalId = employees[existingIndex].id;
1060
+ employees[existingIndex] = {
1061
+ ...importedEmp,
1062
+ id: originalId // Preserve internal ID
1063
+ };
1064
+ updated++;
1065
+ } else {
1066
+ // Add new with a fresh internal ID
1067
+ importedEmp.id = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
1068
+ employees.push(importedEmp);
1069
+ added++;
1070
+ }
1071
+ });
1072
+ break;
1073
 
1074
+ case 'replace':
1075
+ // Replace all existing with imported, assigning new IDs
1076
+ let idCounter = 1;
1077
+ importedEmployees.forEach(emp => {
1078
+ if (!emp.id) {
1079
+ emp.id = idCounter++;
1080
+ }
1081
+ });
1082
+ employees = importedEmployees;
1083
+ added = importedEmployees.length;
1084
+ break;
1085
+ }
1086
+
1087
+ // Save to localStorage and update UI
1088
+ saveEmployees();
1089
+ extractDepartmentsFromEmployees();
1090
+ saveDepartments();
1091
+ updateDepartmentFilterOptions();
1092
+ filterEmployees();
1093
+
1094
+ // Close modal and reset
1095
+ importConfirmationModal.classList.add('hidden');
1096
+ fileInput.value = '';
1097
+ importFileContent = null;
1098
+
1099
+ // Show results
1100
+ let message = `Import completed successfully. `;
1101
+ if (mode === 'merge') {
1102
+ message += `${added} new employees added, ${updated} existing employees updated.`;
1103
+ } else {
1104
+ message += `${added} employees imported.`;
1105
+ }
1106
+
1107
+ alert(message);
1108
+ }
1109
 
1110
+ // FIXED: Updated createHeaderMap to include the internal ID
1111
+ function createHeaderMap() {
1112
+ return {
1113
+ 'ID': 'id',
1114
+ 'Employee ID': 'employeeId',
1115
+ 'First Name': 'firstName',
1116
+ 'Last Name': 'lastName',
1117
+ 'Email': 'email',
1118
+ 'Phone': 'phone',
1119
+ 'Birth Date': 'birthDate',
1120
+ 'Civil Status': 'civilStatus',
1121
+ 'Department': 'department',
1122
+ 'Position': 'position',
1123
+ 'Hire Date': 'hireDate',
1124
+ 'Salary': 'salary',
1125
+ 'Status': 'status',
1126
+ 'SSS Number': 'sssNumber',
1127
+ 'PhilHealth Number': 'philhealthNumber',
1128
+ 'Pag-IBIG Number': 'pagibigNumber',
1129
+ 'TIN Number': 'tinNumber',
1130
+ 'Passport Number': 'passportNumber',
1131
+ 'Passport Expiry': 'passportExpiry',
1132
+ 'National ID': 'nationalId',
1133
+ 'Driver\'s License': 'driversLicense',
1134
+ 'EmployeeId': 'employeeId',
1135
+ 'Firstname': 'firstName',
1136
+ 'Lastname': 'lastName',
1137
+ 'SSS': 'sssNumber',
1138
+ 'Philhealth': 'philhealthNumber',
1139
+ 'Pag-ibig': 'pagibigNumber',
1140
+ 'TIN': 'tinNumber'
1141
+ };
1142
+ }
1143
 
1144
+ // FIXED: Updated mapValuesToEmployee function to handle the ID properly
1145
+ function mapValuesToEmployee(values, headers, headerMap) {
1146
+ const employee = {};
1147
 
1148
+ for (let j = 0; j < headers.length; j++) {
1149
+ const header = headers[j].trim();
1150
+ let value = values[j] || '';
1151
+
1152
+ if (!headerMap[header] || value === '') continue;
1153
+
1154
+ const propName = headerMap[header];
1155
+
1156
+ // Type conversion
1157
+ if (propName === 'salary') {
1158
+ value = parseFloat(value.replace(/[^\d.]/g, '')) || 0;
1159
+ } else if (propName === 'id') {
1160
+ // Convert id to integer
1161
+ value = parseInt(value) || null;
1162
+ } else if (propName === 'hireDate' || propName === 'birthDate' || propName === 'passportExpiry') {
1163
+ // Date formatting
1164
+ if (/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(value)) {
1165
+ const [month, day, year] = value.split('/');
1166
+ value = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
1167
+ }
1168
+ const date = new Date(value);
1169
+ if (!isNaN(date.getTime())) {
1170
+ value = date.toISOString().split('T')[0];
 
 
 
 
1171
  }
 
 
1172
  }
1173
+
1174
+ employee[propName] = value;
1175
+ }
1176
 
1177
+ return employee;
1178
+ }
 
 
 
 
 
 
 
1179
 
1180
+ // Improved CSV line parsing that handles quoted values with commas
1181
+ function parseCSVLine(line) {
1182
+ const values = [];
1183
+ let current = '';
1184
+ let inQuotes = false;
1185
+ let inEscape = false;
1186
 
1187
+ for (let i = 0; i < line.length; i++) {
1188
+ const char = line[i];
 
 
1189
 
1190
+ if (inEscape) {
1191
+ current += char;
1192
+ inEscape = false;
1193
+ continue;
1194
+ }
1195
 
1196
+ if (char === '\\') {
1197
+ inEscape = true;
1198
+ continue;
1199
+ }
 
1200
 
1201
+ if (char === '"') {
1202
+ inQuotes = !inQuotes;
1203
+ continue;
1204
+ }
1205
 
1206
+ if (char === ',' && !inQuotes) {
1207
  values.push(current);
1208
+ current = '';
1209
+ continue;
 
 
 
 
 
 
 
1210
  }
1211
 
1212
+ current += char;
1213
+ }
 
 
1214
 
1215
+ // Add the last value
1216
+ values.push(current);
1217
+
1218
+ // Trim whitespace and remove surrounding quotes if present
1219
+ return values.map(val => {
1220
+ val = val.trim();
1221
+ if (val.startsWith('"') && val.endsWith('"')) {
1222
+ return val.slice(1, -1);
 
 
1223
  }
1224
+ return val;
1225
+ });
1226
+ }
1227
+
1228
+ // Clear all confirmation modal
1229
+ function openClearAllConfirmationModal() {
1230
+ clearAllConfirmationModal.classList.remove('hidden');
1231
+ }
1232
+
1233
+ // Clear all employees
1234
+ function clearAllEmployees() {
1235
+ employees = [];
1236
+ saveEmployees();
1237
+ extractDepartmentsFromEmployees();
1238
+ saveDepartments();
1239
+ updateDepartmentFilterOptions();
1240
+ filterEmployees();
1241
+ clearAllConfirmationModal.classList.add('hidden');
1242
+ alert('All employee data has been cleared.');
1243
+ }
1244
+ </script>
1245
+ <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=poluser/hr-test" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
1246
+ </html>
prompts.txt CHANGED
@@ -2,4 +2,6 @@ make this work with a database that can change when changes are made.
2
  add an export and import function to a csv format
3
  when importing, add the ability to append, replace or merge.
4
  retain the whole code, just edit the edit function to not only edit the top entry but to edit the row data where edit was cliked. make it so that when anywhere in the row data is double clicked it would enter into edit mode.
5
- this code works, except for the edit function that only edits the top of the row data. it should not do that. retain the rest of the code the fix the Edit Function for each row not for a single row
 
 
 
2
  add an export and import function to a csv format
3
  when importing, add the ability to append, replace or merge.
4
  retain the whole code, just edit the edit function to not only edit the top entry but to edit the row data where edit was cliked. make it so that when anywhere in the row data is double clicked it would enter into edit mode.
5
+ this code works, except for the edit function that only edits the top of the row data. it should not do that. retain the rest of the code the fix the Edit Function for each row not for a single row
6
+ I want to add a capability to double click an entry and immediately enter edit mode
7
+ retain all code, implement double-click row functionality for your SteelCraft Payroll System. This feature will allow users to edit an employee record by simply double-clicking anywhere on the row.