Spaces:
Running
Running
Download index.html from poluser/Employee-Management: direct link, hf CLI and curl.
- Browser
- Download file 68.2 kB
-
https://huggingface.co/spaces/poluser/Employee-Management/resolve/main/index.html
- Command line
-
hf download hf://spaces/poluser/Employee-Management/index.html
-
curl -L -o index.html https://huggingface.co/spaces/poluser/Employee-Management/resolve/main/index.html
68.2 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>SteelCraft Payroll System - Employee Management</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
<style>
.sidebar {
transition: all 0.3s;
}
.sidebar.collapsed {
width: 70px;
}
.sidebar.collapsed .nav-text {
display: none;
}
.sidebar.collapsed ~ .main-content {
margin-left: 70px;
}
.main-content {
transition: all 0.3s;
margin-left: 250px;
}
.highlight-row {
background-color: #f0f9ff;
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
height: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: #f1f1f1;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: #888;
border-radius: 3px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: #555;
}
[x-cloak] { display: none !important; }
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.tab-button {
transition: all 0.3s;
}
.tab-button.active {
background-color: #f3f4f6;
border-bottom: 2px solid #3b82f6;
color: #3b82f6;
}
#fileInput {
display: none;
}
.confirmation-modal {
transition: opacity 0.3s, transform 0.3s;
}
.confirmation-modal.hidden {
opacity: 0;
transform: scale(0.9);
pointer-events: none;
}
.employee-row {
transition: background-color 0.2s ease;
}
.employee-row:hover {
background-color: #f8fafc;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 200px;
background-color: white;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 0.5rem;
z-index: 50;
max-height: 300px;
overflow-y: auto;
}
.dropdown:hover .dropdown-content {
display: block;
}
.col-employeeId { width: 120px; min-width: 120px; }
.col-name { width: 180px; min-width: 180px; }
.col-department { width: 140px; min-width: 140px; }
.col-position { width: 140px; min-width: 140px; }
.col-status { width: 100px; min-width: 100px; }
.col-actions { width: 120px; min-width: 120px; }
.col-default { width: 140px; min-width: 140px; }
</style>
</head>
<body class="bg-gray-100">
<div class="flex h-screen overflow-hidden">
<!-- Sidebar -->
<div class="sidebar bg-blue-900 text-white w-64 h-full fixed overflow-y-auto">
<div class="p-4 flex items-center justify-between border-b border-blue-800">
<div class="flex items-center">
<i class="fas fa-industry text-2xl mr-3"></i>
<span class="nav-text font-bold text-xl">SteelCraft Payroll</span>
</div>
</div>
<nav class="mt-4">
<div class="px-4 py-2 text-blue-200 uppercase text-xs font-semibold nav-text">Main</div>
<a href="#" class="flex items-center px-4 py-3 text-white hover:bg-blue-800 transition">
<i class="fas fa-tachometer-alt mr-3"></i>
<span class="nav-text">Dashboard</span>
</a>
<div class="px-4 py-2 text-blue-200 uppercase text-xs font-semibold nav-text">Employees</div>
<a href="#" class="flex items-center px-4 py-3 bg-blue-800 text-white transition">
<i class="fas fa-users mr-3"></i>
<span class="nav-text">Employee Management</span>
</a>
<a href="#" class="flex items-center px-4 py-3 text-white hover:bg-blue-800 transition">
<i class="fas fa-calendar-check mr-3"></i>
<span class="nav-text">Attendance</span>
</a>
<div class="px-4 py-2 text-blue-200 uppercase text-xs font-semibold nav-text">Payroll</div>
<a href="#" class="flex items-center px-4 py-3 text-white hover:bg-blue-800 transition">
<i class="fas fa-calculator mr-3"></i>
<span class="nav-text">Process Payroll</span>
</a>
<a href="#" class="flex items-center px-4 py-3 text-white hover:bg-blue-800 transition">
<i class="fas fa-file-alt mr-3"></i>
<span class="nav-text">Reports</span>
</a>
<div class="px-4 py-2 text-blue-200 uppercase text-xs font-semibold nav-text">Settings</div>
<a href="#" class="flex items-center px-4 py-3 text-white hover:bg-blue-800 transition">
<i class="fas fa-cog mr-3"></i>
<span class="nav-text">System Settings</span>
</a>
</nav>
<div class="absolute bottom-0 w-full p-4 border-t border-blue-800">
<div class="flex items-center">
<div class="w-8 h-8 rounded-full bg-blue-700 flex items-center justify-center">
<i class="fas fa-user text-sm"></i>
</div>
<div class="ml-3 nav-text">
<div class="text-sm font-medium">Admin User</div>
<div class="text-xs">Administrator</div>
</div>
</div>
</div>
</div>
<!-- Main Content -->
<div class="main-content flex-1 overflow-auto custom-scrollbar">
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-800">Employee Management</h1>
<div class="flex items-center space-x-4">
<button id="addEmployeeBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-plus mr-2"></i>
<span>Add Employee</span>
</button>
<div class="dropdown relative">
<button id="columnsBtn" class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-columns mr-2"></i>
<span>Columns</span>
<i class="fas fa-chevron-down ml-2 text-xs"></i>
</button>
<div class="dropdown-content right-0 mt-1 p-2 w-64">
<div class="font-medium text-gray-700 mb-2">Select columns to display:</div>
<div class="space-y-2">
<!-- Columns will be added dynamically by JavaScript -->
</div>
<div class="flex mt-3 pt-2 border-t">
<button id="resetColumnsBtn" class="text-xs text-gray-500 hover:text-blue-600">Reset to Default</button>
</div>
</div>
</div>
<button id="clearAllBtn" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-trash-alt mr-2"></i>
<span>Clear All</span>
</button>
<button id="exportCSVBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-file-export mr-2"></i>
<span>Export CSV</span>
</button>
<button id="importCSVBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-lg flex items-center">
<i class="fas fa-file-import mr-2"></i>
<span>Import CSV</span>
</button>
<input type="file" id="fileInput" accept=".csv">
<div class="relative">
<input type="text" id="employeeSearch" placeholder="Search employees..." class="pl-10 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<i class="fas fa-search absolute left-3 top-3 text-gray-400"></i>
</div>
</div>
</div>
<!-- Employee Modal -->
<div id="employeeModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 flex items-center justify-center z-50 hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-4xl max-h-[90vh] overflow-y-auto">
<div class="flex justify-between items-center border-b px-6 py-4">
<h3 id="modalTitle" class="text-xl font-semibold text-gray-800">Add New Employee</h3>
<button id="closeModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<form id="employeeForm" class="p-6">
<input type="hidden" id="employeeId">
<div class="flex border-b mb-4">
<button type="button" class="tab-button active px-4 py-2 font-medium" data-tab="basic">Basic Info</button>
<button type="button" class="tab-button px-4 py-2 font-medium" data-tab="government">Gov't Records</button>
<button type="button" class="tab-button px-4 py-2 font-medium" data-tab="employment">Employment</button>
</div>
<div id="basic-tab" class="tab-content active">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label for="employeeIdInput" class="block text-sm font-medium text-gray-700 mb-1">Employee ID</label>
<input type="text" id="employeeIdInput" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div>
<div>
<label for="firstName" class="block text-sm font-medium text-gray-700 mb-1">First Name</label>
<input type="text" id="firstName" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div>
<div>
<label for="lastName" class="block text-sm font-medium text-gray-700 mb-1">Last Name</label>
<input type="text" id="lastName" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div>
<div>
<label for="email" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
<input type="email" id="email" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="phone" class="block text-sm font-medium text-gray-700 mb-1">Phone</label>
<input type="tel" id="phone" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="birthDate" class="block text-sm font-medium text-gray-700 mb-1">Birth Date</label>
<input type="date" id="birthDate" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="civilStatus" class="block text-sm font-medium text-gray-700 mb-1">Civil Status</label>
<select id="civilStatus" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="">Select</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Separated">Separated</option>
<option value="Widowed">Widowed</option>
</select>
</div>
</div>
</div>
<div id="government-tab" class="tab-content">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label for="sssNumber" class="block text-sm font-medium text-gray-700 mb-1">SSS Number</label>
<input type="text" id="sssNumber" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="philhealthNumber" class="block text-sm font-medium text-gray-700 mb-1">PhilHealth Number</label>
<input type="text" id="philhealthNumber" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="pagibigNumber" class="block text-sm font-medium text-gray-700 mb-1">Pag-IBIG Number</label>
<input type="text" id="pagibigNumber" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="tinNumber" class="block text-sm font-medium text-gray-700 mb-1">TIN Number</label>
<input type="text" id="tinNumber" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="passportNumber" class="block text-sm font-medium text-gray-700 mb-1">Passport Number</label>
<input type="text" id="passportNumber" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="passportExpiry" class="block text-sm font-medium text-gray-700 mb-1">Passport Expiry</label>
<input type="date" id="passportExpiry" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="nationalId" class="block text-sm font-medium text-gray-700 mb-1">National ID</label>
<input type="text" id="nationalId" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="driversLicense" class="block text-sm font-medium text-gray-700 mb-1">Driver's License</label>
<input type="text" id="driversLicense" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
</div>
</div>
<div id="employment-tab" class="tab-content">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label for="departmentInput" class="block text-sm font-medium text-gray-700 mb-1">Department</label>
<div class="relative">
<input type="text" id="departmentInput" list="departmentSuggestions" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<ul id="departmentSuggestions" class="hidden absolute z-10 w-full mt-1 bg-white border border-gray-300 rounded-lg shadow-lg"></ul>
</div>
</div>
<div>
<label for="position" class="block text-sm font-medium text-gray-700 mb-1">Position</label>
<input type="text" id="position" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div>
<div>
<label for="hireDate" class="block text-sm font-medium text-gray-700 mb-1">Hire Date</label>
<input type="date" id="hireDate" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="salary" class="block text-sm font-medium text-gray-700 mb-1">Basic Salary (₱)</label>
<input type="number" id="salary" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="status" class="block text-sm font-medium text-gray-700 mb-1">Employment Status</label>
<select id="status" class="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
<option value="On Leave">On Leave</option>
</select>
</div>
</div>
</div>
<div class="flex justify-end space-x-3 mt-6 pt-4 border-t">
<button type="button" id="cancelEmployee" class="px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50">Cancel</button>
<button type="submit" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700">Save Employee</button>
</div>
</form>
</div>
</div>
<!-- Import Confirmation Modal -->
<div id="importConfirmationModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 flex items-center justify-center z-50 confirmation-modal hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md">
<div class="flex justify-between items-center border-b px-6 py-4">
<h3 class="text-lg font-semibold text-gray-800">Import Employees</h3>
<button id="closeImportConfirmationModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="p-6">
<p class="text-gray-700 mb-6">How would you like to import the employee data?</p>
<div class="space-y-4">
<div class="flex">
<div>
<button id="appendDataBtn" type="button" class="font-semibold text-left hover:text-blue-700 text-blue-600 mb-1">
Append New Records
</button>
<p class="text-sm text-gray-500">Import all records as new employees. Will generate new IDs for duplicates.</p>
</div>
</div>
<div class="flex">
<div>
<button id="mergeDataBtn" type="button" class="font-semibold text-left hover:text-blue-700 text-blue-600 mb-1">
Merge with Existing
</button>
<p class="text-sm text-gray-500">Update existing employees (matched by ID) and add new ones.</p>
</div>
</div>
<div class="flex">
<div>
<button id="replaceDataBtn" type="button" class="font-semibold text-left hover:text-blue-700 text-blue-600 mb-1">
Replace All Data
</button>
<p class="text-sm text-gray-500">Replace all existing employees with the imported data.</p>
</div>
</div>
</div>
</div>
<div class="flex justify-end border-t px-6 py-3">
<button type="button" id="cancelImportBtn" class="px-4 py-2 text-gray-700 hover:text-gray-900 mr-3">
Cancel
</button>
</div>
</div>
</div>
<!-- Clear All Confirmation Modal -->
<div id="clearAllConfirmationModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 flex items-center justify-center z-50 confirmation-modal hidden">
<div class="bg-white rounded-lg shadow-xl w-full max-w-md">
<div class="flex justify-between items-center border-b px-6 py-4">
<h3 class="text-lg font-semibold text-gray-800">Confirm Clear All</h3>
<button id="closeClearAllConfirmationModal" class="text-gray-500 hover:text-gray-700">
<i class="fas fa-times"></i>
</button>
</div>
<div class="p-6">
<div class="flex items-start">
<div class="flex-shrink-0 pt-0.5">
<i class="fas fa-exclamation-circle text-red-500 text-xl"></i>
</div>
<div class="ml-3">
<h3 class="text-lg font-medium text-gray-900">Are you sure?</h3>
<div class="mt-2">
<p class="text-sm text-gray-500">
This will permanently delete all employee records. This action cannot be undone.
</p>
</div>
</div>
</div>
</div>
<div class="flex justify-end border-t px-6 py-3">
<button type="button" id="cancelClearAll" class="px-4 py-2 text-gray-700 hover:text-gray-900 mr-3">
Cancel
</button>
<button type="button" id="confirmClearAll" class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700">
Delete All
</button>
</div>
</div>
</div>
<!-- Employee List -->
<div class="bg-white p-6 rounded-xl shadow-sm border border-gray-200 mb-6">
<div class="flex justify-between items-center mb-4">
<div>
<h2 class="text-lg font-semibold inline-block mr-4">All Employees</h2>
<span id="columnsDisplayInfo" class="text-sm text-gray-500">Showing 7 of 15 columns</span>
</div>
<div class="flex items-center space-x-2">
<select id="departmentFilter" class="border rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="">All Departments</option>
</select>
<select id="statusFilter" class="border rounded-lg px-3 py-1 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="">All Statuses</option>
<option value="Active">Active</option>
<option value="Inactive">Inactive</option>
<option value="On Leave">On Leave</option>
</select>
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr id="employeeTableHeader">
<!-- Headers will be inserted by JavaScript based on column selection -->
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200" id="employeeTableBody">
<!-- Rows will be inserted by JavaScript -->
</tbody>
</table>
</div>
<div class="mt-4 flex items-center justify-between">
<div class="text-sm text-gray-500">
Showing <span id="startEmployee">1</span> to <span id="endEmployee">10</span> of <span id="totalEmployees">0</span> employees
</div>
<div class="flex space-x-2">
<button id="prevEmployeePage" class="px-3 py-1 border rounded-lg text-sm hover:bg-gray-50 disabled:opacity-50" disabled>
Previous
</button>
<button id="nextEmployeePage" class="px-3 py-1 border rounded-lg text-sm hover:bg-gray-50 disabled:opacity-50">
Next
</button>
</div>
</div>
</div>
</div>
</div>
<script>
// ====== Column Configuration ======
const COLUMNS_CONFIG = {
employeeId: {
key: 'employeeId',
label: 'Employee ID',
visible: true,
locked: true,
className: 'col-employeeId',
order: 1,
default: true
},
name: {
key: 'name',
label: 'Name',
visible: true,
locked: true,
className: 'col-name',
order: 2,
default: true
},
department: {
key: 'department',
label: 'Department',
visible: true,
locked: false,
className: 'col-department',
order: 3,
default: true
},
position: {
key: 'position',
label: 'Position',
visible: true,
locked: false,
className: 'col-position',
order: 4,
default: true
},
status: {
key: 'status',
label: 'Status',
visible: true,
locked: false,
className: 'col-status',
order: 5,
default: true
},
salary: {
key: 'salary',
label: 'Salary',
visible: false,
locked: false,
className: 'col-default',
order: 6,
default: false
},
sssNumber: {
key: 'sssNumber',
label: 'SSS Number',
visible: false,
locked: false,
className: 'col-default',
order: 7,
default: false
},
philhealthNumber: {
key: 'philhealthNumber',
label: 'PhilHealth',
visible: false,
locked: false,
className: 'col-default',
order: 8,
default: false
},
pagibigNumber: {
key: 'pagibigNumber',
label: 'Pag-IBIG',
visible: false,
locked: false,
className: 'col-default',
order: 9,
default: false
},
tinNumber: {
key: 'tinNumber',
label: 'TIN',
visible: false,
locked: false,
className: 'col-default',
order: 10,
default: false
},
email: {
key: 'email',
label: 'Email',
visible: false,
locked: false,
className: 'col-default',
order: 11,
default: false
},
phone: {
key: 'phone',
label: 'Phone',
visible: false,
locked: false,
className: 'col-default',
order: 12,
default: false
},
hireDate: {
key: 'hireDate',
label: 'Hire Date',
visible: false,
locked: false,
className: 'col-default',
order: 13,
default: false
},
birthDate: {
key: 'birthDate',
label: 'Birth Date',
visible: false,
locked: false,
className: 'col-default',
order: 14,
default: false
},
civilStatus: {
key: 'civilStatus',
label: 'Civil Status',
visible: false,
locked: false,
className: 'col-default',
order: 15,
default: false
},
actions: {
key: 'actions',
label: 'Actions',
visible: true,
locked: true,
className: 'col-actions',
order: 99,
default: true
}
};
// Storage keys
const STORAGE_KEY = 'steelcraft_payroll_employees';
const DEPARTMENTS_KEY = 'steelcraft_payroll_departments';
const COLUMNS_PREFERENCES_KEY = 'steelcraft_payroll_columns_prefs';
// Employee data - initially load from localStorage
let employees = loadEmployees();
let allDepartments = loadDepartments();
let columnsConfig = loadColumnsPreferences();
// If no data in localStorage, initialize with default values
if (employees.length === 0) {
employees = [
{
id: 1,
employeeId: "EMP-1001",
firstName: "Juan",
lastName: "Dela Cruz",
email: "juan.delacruz@steelcraft.com",
phone: "09171234567",
department: "Fabrication",
position: "Welder",
hireDate: "2020-05-15",
birthDate: "1985-03-12",
salary: 25000,
status: "Active",
sssNumber: "34-1234567-8",
philhealthNumber: "34-123456789-0",
pagibigNumber: "1234-5678-9012",
tinNumber: "123-456-789-000",
civilStatus: "Married"
}
];
saveEmployees();
}
// If no departments in localStorage, initialize from employees
if (allDepartments.length === 0) {
extractDepartmentsFromEmployees();
saveDepartments();
}
// Pagination
let currentPage = 1;
const rowsPerPage = 20;
let filteredEmployees = [...employees];
// File import variables
let importFileContent = null;
// DOM elements
const employeeTableBody = document.getElementById('employeeTableBody');
const employeeTableHeader = document.getElementById('employeeTableHeader');
const departmentInput = document.getElementById('departmentInput');
const departmentSuggestions = document.getElementById('departmentSuggestions');
const departmentFilter = document.getElementById('departmentFilter');
const statusFilter = document.getElementById('statusFilter');
const employeeSearch = document.getElementById('employeeSearch');
const addEmployeeBtn = document.getElementById('addEmployeeBtn');
const clearAllBtn = document.getElementById('clearAllBtn');
const exportCSVBtn = document.getElementById('exportCSVBtn');
const importCSVBtn = document.getElementById('importCSVBtn');
const fileInput = document.getElementById('fileInput');
const employeeModal = document.getElementById('employeeModal');
const employeeForm = document.getElementById('employeeForm');
const closeModal = document.getElementById('closeModal');
const cancelEmployee = document.getElementById('cancelEmployee');
const modalTitle = document.getElementById('modalTitle');
const employeeIdInput = document.getElementById('employeeId');
const employeeIdDisplayInput = document.getElementById('employeeIdInput');
const prevEmployeePage = document.getElementById('prevEmployeePage');
const nextEmployeePage = document.getElementById('nextEmployeePage');
const startEmployee = document.getElementById('startEmployee');
const endEmployee = document.getElementById('endEmployee');
const totalEmployees = document.getElementById('totalEmployees');
const tabButtons = document.querySelectorAll('.tab-button');
const tabContents = document.querySelectorAll('.tab-content');
const columnsBtn = document.getElementById('columnsBtn');
const columnsDisplayInfo = document.getElementById('columnsDisplayInfo');
const resetColumnsBtn = document.getElementById('resetColumnsBtn');
const columnsDropdownContent = document.querySelector('.dropdown-content');
// Import confirmation modal elements
const importConfirmationModal = document.getElementById('importConfirmationModal');
const closeImportConfirmationModal = document.getElementById('closeImportConfirmationModal');
const appendDataBtn = document.getElementById('appendDataBtn');
const mergeDataBtn = document.getElementById('mergeDataBtn');
const replaceDataBtn = document.getElementById('replaceDataBtn');
const cancelImportBtn = document.getElementById('cancelImportBtn');
// Clear all confirmation modal elements
const clearAllConfirmationModal = document.getElementById('clearAllConfirmationModal');
const closeClearAllConfirmationModal = document.getElementById('closeClearAllConfirmationModal');
const cancelClearAll = document.getElementById('cancelClearAll');
const confirmClearAll = document.getElementById('confirmClearAll');
// ====== Column Management Functions ======
function loadColumnsPreferences() {
const savedPrefs = localStorage.getItem(COLUMNS_PREFERENCES_KEY);
if (savedPrefs) {
try {
const prefs = JSON.parse(savedPrefs);
// Merge with default config
const mergedConfig = JSON.parse(JSON.stringify(COLUMNS_CONFIG));
for (const key in prefs) {
if (mergedConfig[key]) {
mergedConfig[key].visible = prefs[key].visible;
}
}
return mergedConfig;
} catch (e) {
console.error("Error loading column preferences:", e);
}
}
return JSON.parse(JSON.stringify(COLUMNS_CONFIG)); // Return a deep copy
}
function saveColumnsPreferences() {
const saveData = {};
for (const key in columnsConfig) {
saveData[key] = { visible: columnsConfig[key].visible };
}
localStorage.setItem(COLUMNS_PREFERENCES_KEY, JSON.stringify(saveData));
}
function resetColumnsToDefault() {
for (const key in columnsConfig) {
columnsConfig[key].visible = columnsConfig[key].default;
}
saveColumnsPreferences();
renderColumnSelector();
renderEmployeeTable();
}
function toggleColumnVisibility(columnKey) {
if (columnsConfig[columnKey] && !columnsConfig[columnKey].locked) {
columnsConfig[columnKey].visible = !columnsConfig[columnKey].visible;
saveColumnsPreferences();
renderColumnSelector();
renderEmployeeTable();
}
}
function renderColumnSelector() {
const container = columnsDropdownContent.querySelector('.space-y-2');
container.innerHTML = '';
// Get all columns ordered by their display order
const orderedColumns = Object.values(columnsConfig).sort((a, b) => a.order - b.order);
orderedColumns.forEach(col => {
if (col.locked) return; // Skip locked columns
const div = document.createElement('div');
div.className = 'flex items-center';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.id = `col-${col.key}`;
checkbox.checked = col.visible;
checkbox.className = 'mr-2 rounded text-blue-600 focus:ring-blue-500';
checkbox.addEventListener('change', () => toggleColumnVisibility(col.key));
const label = document.createElement('label');
label.htmlFor = `col-${col.key}`;
label.className = 'text-sm text-gray-700';
label.textContent = col.label;
div.appendChild(checkbox);
div.appendChild(label);
container.appendChild(div);
});
// Update the "Showing X of Y columns" info
const visibleCount = Object.values(columnsConfig).filter(c => c.visible).length;
const totalCount = Object.keys(columnsConfig).length;
columnsDisplayInfo.textContent = `Showing ${visibleCount} of ${totalCount} columns`;
}
function getTableHeaders() {
// Get visible columns in correct order
const visibleColumns = Object.values(columnsConfig)
.filter(col => col.visible)
.sort((a, b) => a.order - b.order);
let headers = '';
visibleColumns.forEach(col => {
headers += `
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider ${col.className}">
${col.label}
</th>
`;
});
return headers;
}
function getTableRow(employee) {
// Get visible columns in correct order
const visibleColumns = Object.values(columnsConfig)
.filter(col => col.visible)
.sort((a, b) => a.order - b.order);
let rowCells = '';
visibleColumns.forEach(col => {
if (col.key === 'name') {
rowCells += `
<td class="px-6 py-4 whitespace-nowrap ${col.className}">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-blue-100 flex items-center justify-center">
<i class="fas fa-user text-blue-600"></i>
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">${employee.firstName} ${employee.lastName}</div>
<div class="text-sm text-gray-500">${employee.email || 'No email'}</div>
</div>
</div>
</td>
`;
} else if (col.key === 'status') {
rowCells += `
<td class="px-6 py-4 whitespace-nowrap ${col.className}">
<span class="px-2 inline-flex text-xs leading-5 font-semibell rounded-full ${getStatusClass(employee.status)}">
${employee.status}
</span>
</td>
`;
} else if (col.key === 'actions') {
rowCells += `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium ${col.className}">
<button class="text-blue-600 hover:text-blue-900 mr-3 edit-btn" data-id="${employee.id}">Edit</button>
<button class="text-red-600 hover:text-red-900 delete-btn" data-id="${employee.id}">Delete</button>
</td>
`;
} else if (col.key === 'salary') {
rowCells += `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 ${col.className}">
₱${employee.salary ? employee.salary.toLocaleString('en-PH', { minimumFractionDigits: 2, maximumFractionDigits: 2 }) : '0.00'}
</td>
`;
} else if (col.key === 'hireDate' || col.key === 'birthDate') {
rowCells += `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 ${col.className}">
${employee[col.key] ? formatDate(employee[col.key]) : 'N/A'}
</td>
`;
} else {
rowCells += `
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 ${col.className}">
${employee[col.key] || 'N/A'}
</td>
`;
}
});
return rowCells;
}
// ====== Core Functions ======
function saveEmployees() {
localStorage.setItem(STORAGE_KEY, JSON.stringify(employees));
}
function loadEmployees() {
const data = localStorage.getItem(STORAGE_KEY);
return data ? JSON.parse(data) : [];
}
function saveDepartments() {
localStorage.setItem(DEPARTMENTS_KEY, JSON.stringify(allDepartments));
}
function loadDepartments() {
const data = localStorage.getItem(DEPARTMENTS_KEY);
return data ? JSON.parse(data) : [];
}
// Initialize
document.addEventListener('DOMContentLoaded', () => {
updateDepartmentFilterOptions();
renderColumnSelector(); // Initialize column selector
renderEmployeeTable();
setupEventListeners();
setupTabs();
});
function setupTabs() {
tabButtons.forEach(button => {
button.addEventListener('click', () => {
const tabId = button.getAttribute('data-tab');
// Update active tab button
tabButtons.forEach(btn => btn.classList.remove('active'));
button.classList.add('active');
// Update active tab content
tabContents.forEach(content => {
content.classList.remove('active');
if (content.id === `${tabId}-tab`) {
content.classList.add('active');
}
});
});
});
}
function extractDepartmentsFromEmployees() {
const departmentsSet = new Set();
employees.forEach(emp => {
if (emp.department) departmentsSet.add(emp.department);
});
allDepartments = Array.from(departmentsSet).sort();
}
function updateDepartmentFilterOptions() {
departmentFilter.innerHTML = '<option value="">All Departments</option>';
allDepartments.forEach(dep => {
const option = document.createElement('option');
option.value = dep;
option.textContent = dep;
departmentFilter.appendChild(option);
});
}
function setupEventListeners() {
addEmployeeBtn.addEventListener('click', () => openEmployeeModal());
clearAllBtn.addEventListener('click', () => openClearAllConfirmationModal());
exportCSVBtn.addEventListener('click', exportToCSV);
importCSVBtn.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', handleFileImport);
closeModal.addEventListener('click', closeEmployeeModal);
cancelEmployee.addEventListener('click', closeEmployeeModal);
employeeForm.addEventListener('submit', (e) => {
e.preventDefault();
saveEmployee();
});
employeeSearch.addEventListener('input', filterEmployees);
departmentFilter.addEventListener('change', filterEmployees);
statusFilter.addEventListener('change', filterEmployees);
departmentInput.addEventListener('input', handleDepartmentInput);
prevEmployeePage.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
renderEmployeeTable();
}
});
nextEmployeePage.addEventListener('click', () => {
const maxPage = Math.ceil(filteredEmployees.length / rowsPerPage);
if (currentPage < maxPage) {
currentPage++;
renderEmployeeTable();
}
});
resetColumnsBtn.addEventListener('click', resetColumnsToDefault);
// Import confirmation modal events
closeImportConfirmationModal.addEventListener('click', () => importConfirmationModal.classList.add('hidden'));
cancelImportBtn.addEventListener('click', () => importConfirmationModal.classList.add('hidden'));
appendDataBtn.addEventListener('click', () => processImport('append'));
mergeDataBtn.addEventListener('click', () => processImport('merge'));
replaceDataBtn.addEventListener('click', () => processImport('replace'));
// Clear all confirmation modal events
closeClearAllConfirmationModal.addEventListener('click', () => clearAllConfirmationModal.classList.add('hidden'));
cancelClearAll.addEventListener('click', () => clearAllConfirmationModal.classList.add('hidden'));
confirmClearAll.addEventListener('click', clearAllEmployees);
// Close dropdown when clicking outside
document.addEventListener('click', (e) => {
if (!columnsBtn.contains(e.target) && !columnsDropdownContent.contains(e.target)) {
columnsDropdownContent.style.display = 'none';
}
});
// Toggle dropdown when clicking the columns button
columnsBtn.addEventListener('click', () => {
const isOpen = columnsDropdownContent.style.display === 'block';
columnsDropdownContent.style.display = isOpen ? 'none' : 'block';
});
}
function handleDepartmentInput(e) {
const value = e.target.value.trim().toLowerCase();
departmentSuggestions.innerHTML = '';
departmentSuggestions.classList.add('hidden');
if (value.length > 0) {
const matches = allDepartments.filter(dep => dep.toLowerCase().includes(value));
if (matches.length > 0) {
departmentSuggestions.classList.remove('hidden');
matches.forEach(dep => {
const li = document.createElement('li');
li.textContent = dep;
li.className = 'px-3 py-2 cursor-pointer hover:bg-blue-100';
li.addEventListener('click', () => {
departmentInput.value = dep;
departmentSuggestions.classList.add('hidden');
});
departmentSuggestions.appendChild(li);
});
}
const isCustom = !allDepartments.includes(departmentInput.value) && departmentInput.value.trim() !== '';
if (isCustom) {
const li = document.createElement('li');
li.textContent = `Add "${departmentInput.value}"`;
li.className = 'px-3 py-2 cursor-pointer hover:bg-green-100 text-green-700';
li.addEventListener('click', () => {
const newDep = departmentInput.value.trim();
if (!allDepartments.includes(newDep)) {
allDepartments.push(newDep);
saveDepartments();
departmentInput.value = newDep;
updateDepartmentFilterOptions();
departmentSuggestions.classList.add('hidden');
}
});
departmentSuggestions.appendChild(li);
}
}
}
function filterEmployees() {
const searchTerm = employeeSearch.value.toLowerCase();
const department = departmentFilter.value;
const status = statusFilter.value;
filteredEmployees = employees.filter(emp => {
const fullName = `${emp.firstName} ${emp.lastName}`.toLowerCase();
const matchesSearch = fullName.includes(searchTerm) ||
emp.employeeId.toLowerCase().includes(searchTerm) ||
(emp.email && emp.email.toLowerCase().includes(searchTerm)) ||
(emp.position && emp.position.toLowerCase().includes(searchTerm));
const matchesDepartment = department ? emp.department === department : true;
const matchesStatus = status ? emp.status === status : true;
return matchesSearch && matchesDepartment && matchesStatus;
});
currentPage = 1;
renderEmployeeTable();
}
function renderEmployeeTable() {
const start = (currentPage - 1) * rowsPerPage;
const end = start + rowsPerPage;
const paginatedEmployees = filteredEmployees.slice(start, end);
// Set table headers based on visible columns
employeeTableHeader.innerHTML = getTableHeaders();
employeeTableBody.innerHTML = '';
if (paginatedEmployees.length === 0) {
const colSpan = Object.values(columnsConfig).filter(col => col.visible).length;
employeeTableBody.innerHTML = `
<tr>
<td colspan="${colSpan}" class="px-6 py-4 text-center text-gray-500">No employees found</td>
</tr>
`;
} else {
paginatedEmployees.forEach(emp => {
const row = document.createElement('tr');
row.className = 'employee-row';
row.dataset.id = emp.id;
row.innerHTML = getTableRow(emp);
employeeTableBody.appendChild(row);
// Add double click listener to the row
row.addEventListener('dblclick', (e) => {
// Don't trigger if clicking on action buttons
if (e.target.tagName === 'BUTTON' || e.target.closest('button')) {
return;
}
openEmployeeModal(emp.id);
});
});
// Add event listeners to edit and delete buttons
document.querySelectorAll('.edit-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const id = parseInt(e.target.getAttribute('data-id'));
openEmployeeModal(id);
});
});
document.querySelectorAll('.delete-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const id = parseInt(e.target.getAttribute('data-id'));
deleteEmployee(id);
});
});
}
const totalVisible = filteredEmployees.length;
const maxPage = Math.ceil(totalVisible / rowsPerPage);
startEmployee.textContent = totalVisible > 0 ? start + 1 : 0;
endEmployee.textContent = Math.min(end, totalVisible);
totalEmployees.textContent = totalVisible;
prevEmployeePage.disabled = currentPage <= 1;
nextEmployeePage.disabled = currentPage >= maxPage || maxPage === 0;
}
function deleteEmployee(id) {
if (confirm("Are you sure you want to delete this employee?")) {
const index = employees.findIndex(emp => emp.id === id);
if (index !== -1) {
employees.splice(index, 1);
saveEmployees();
extractDepartmentsFromEmployees();
saveDepartments();
updateDepartmentFilterOptions();
filterEmployees();
alert('Employee deleted successfully.');
}
}
}
function openEmployeeModal(id = null) {
if (id) {
const employee = employees.find(e => e.id === id);
if (employee) {
modalTitle.textContent = 'Edit Employee';
employeeIdInput.value = employee.id;
employeeIdDisplayInput.value = employee.employeeId;
document.getElementById('firstName').value = employee.firstName;
document.getElementById('lastName').value = employee.lastName;
document.getElementById('email').value = employee.email || '';
document.getElementById('phone').value = employee.phone || '';
document.getElementById('birthDate').value = employee.birthDate || '';
document.getElementById('civilStatus').value = employee.civilStatus || 'Single';
departmentInput.value = employee.department || '';
document.getElementById('position').value = employee.position || '';
document.getElementById('hireDate').value = employee.hireDate || '';
document.getElementById('salary').value = employee.salary || '';
document.getElementById('status').value = employee.status || 'Active';
// Philippine Government data
document.getElementById('sssNumber').value = employee.sssNumber || '';
document.getElementById('philhealthNumber').value = employee.philhealthNumber || '';
document.getElementById('pagibigNumber').value = employee.pagibigNumber || '';
document.getElementById('tinNumber').value = employee.tinNumber || '';
document.getElementById('passportNumber').value = employee.passportNumber || '';
document.getElementById('passportExpiry').value = employee.passportExpiry || '';
document.getElementById('nationalId').value = employee.nationalId || '';
document.getElementById('driversLicense').value = employee.driversLicense || '';
}
} else {
modalTitle.textContent = 'Add New Employee';
employeeForm.reset();
employeeIdInput.value = '';
employeeIdDisplayInput.value = '';
departmentInput.value = '';
document.getElementById('status').value = 'Active';
document.getElementById('civilStatus').value = 'Single';
// Generate new employee ID for new employees
const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
employeeIdDisplayInput.value = `EMP-${1000 + newId}`;
}
// Reset tabs to first tab
tabButtons.forEach((btn, index) => {
btn.classList.toggle('active', index === 0);
});
tabContents.forEach((content, index) => {
content.classList.toggle('active', index === 0);
});
employeeModal.classList.remove('hidden');
}
function closeEmployeeModal() {
employeeModal.classList.add('hidden');
}
function saveEmployee() {
const id = employeeIdInput.value ? parseInt(employeeIdInput.value) : null;
const employeeId = employeeIdDisplayInput.value.trim();
const firstName = document.getElementById('firstName').value.trim();
const lastName = document.getElementById('lastName').value.trim();
const email = document.getElementById('email').value.trim() || null;
const phone = document.getElementById('phone').value.trim() || null;
const birthDate = document.getElementById('birthDate').value || null;
const civilStatus = document.getElementById('civilStatus').value || null;
const department = departmentInput.value.trim();
const position = document.getElementById('position').value.trim() || null;
const hireDate = document.getElementById('hireDate').value || null;
const salary = document.getElementById('salary').value ? parseFloat(document.getElementById('salary').value) : 0;
const status = document.getElementById('status').value || 'Active';
// Philippine Government data
const sssNumber = document.getElementById('sssNumber').value.trim() || null;
const philhealthNumber = document.getElementById('philhealthNumber').value.trim() || null;
const pagibigNumber = document.getElementById('pagibigNumber').value.trim() || null;
const tinNumber = document.getElementById('tinNumber').value.trim() || null;
const passportNumber = document.getElementById('passportNumber').value.trim() || null;
const passportExpiry = document.getElementById('passportExpiry').value || null;
const nationalId = document.getElementById('nationalId').value.trim() || null;
const driversLicense = document.getElementById('driversLicense').value.trim() || null;
if (!employeeId || !firstName || !lastName) {
alert("Employee ID, first name and last name are required.");
return;
}
if (id) {
// Editing existing employee
const index = employees.findIndex(e => e.id === id);
employees[index] = {
...employees[index], // Preserve existing data
employeeId,
firstName,
lastName,
email,
phone,
birthDate,
civilStatus,
department,
position,
hireDate,
salary,
status,
sssNumber,
philhealthNumber,
pagibigNumber,
tinNumber,
passportNumber,
passportExpiry,
nationalId,
driversLicense
};
} else {
// Adding new employee
const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
employees.push({
id: newId,
employeeId,
firstName,
lastName,
email,
phone,
birthDate,
civilStatus,
department,
position,
hireDate,
salary,
status,
sssNumber,
philhealthNumber,
pagibigNumber,
tinNumber,
passportNumber,
passportExpiry,
nationalId,
driversLicense
});
if (!allDepartments.includes(department) && department) {
allDepartments.push(department);
saveDepartments();
updateDepartmentFilterOptions();
}
}
// Save to localStorage
saveEmployees();
closeEmployeeModal();
extractDepartmentsFromEmployees();
updateDepartmentFilterOptions();
filterEmployees();
}
function getStatusClass(status) {
switch(status) {
case 'Active': return 'bg-green-100 text-green-800';
case 'Inactive': return 'bg-red-100 text-red-800';
case 'On Leave': return 'bg-yellow-100 text-yellow-800';
default: return 'bg-gray-100 text-gray-800';
}
}
function formatDate(dateString) {
if (!dateString) return 'N/A';
const options = { year: 'numeric', month: 'short', day: 'numeric' };
return new Date(dateString).toLocaleDateString('en-US', options);
}
function exportToCSV() {
// Get visible columns ordered by their display order
const visibleColumns = Object.values(columnsConfig)
.filter(col => col.visible && col.key !== 'actions') // Don't export actions column
.sort((a, b) => a.order - b.order);
// Create headers
const headers = visibleColumns.map(col => {
if (col.key === 'name') return 'First Name,Last Name';
return col.label;
}).join(',');
// Create CSV rows
const csvContent = [
headers,
...employees.map(emp => {
return visibleColumns.map(col => {
let value = '';
if (col.key === 'name') {
value = `"${emp.firstName}","${emp.lastName}"`;
} else if (col.key === 'salary') {
value = emp.salary || 0;
} else {
value = emp[col.key] || '';
// Escape quotes and wrap in quotes if the value contains commas
if (typeof value === 'string' && (value.includes(',') || value.includes('"'))) {
value = `"${value.replace(/"/g, '""')}"`;
}
}
return value;
}).join(',');
})
].join('\n');
// Create download link
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.setAttribute('href', url);
link.setAttribute('download', `steelcraft_employees_${new Date().toISOString().slice(0, 10)}.csv`);
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function handleFileImport(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
importFileContent = e.target.result;
importConfirmationModal.classList.remove('hidden');
};
reader.readAsText(file);
}
function processImport(mode) {
if (!importFileContent) {
alert('No file content to import');
return;
}
const lines = importFileContent.split(/\r?\n/).filter(line => line.trim() !== '');
if (lines.length < 2) {
alert("CSV file must contain at least one header row and one data row");
return;
}
// Parse headers and create mapping
const headers = parseCSVLine(lines[0]).map(h => h.trim());
const headerMap = createHeaderMap();
// Skip header row and process data
const importedEmployees = [];
for (let i = 1; i < lines.length; i++) {
if (!lines[i].trim()) continue;
try {
const values = parseCSVLine(lines[i]);
if (values.length !== headers.length) {
console.warn(`Skipping line ${i+1}: number of values doesn't match headers`);
continue;
}
const employee = mapValuesToEmployee(values, headers, headerMap);
if (!employee.firstName || !employee.lastName) {
console.warn(`Skipping line ${i+1}: missing required fields (firstName or lastName)`);
continue;
}
// Generate employee ID if not provided
if (!employee.employeeId) {
const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
employee.employeeId = `EMP-${1000 + newId}`;
}
importedEmployees.push(employee);
} catch (error) {
console.error(`Error processing line ${i+1}:`, error);
}
}
// Process based on selected mode
let added = 0;
let updated = 0;
switch(mode) {
case 'append':
// Add all imported employees as new records
importedEmployees.forEach(importedEmp => {
// Check if an employee with the same employeeId already exists
const existingIndex = employees.findIndex(e => e.employeeId === importedEmp.employeeId);
if (existingIndex >= 0) {
// If it exists, generate a new unique employeeId
const newId = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
importedEmp.employeeId = `EMP-${1000 + newId}`;
}
// Assign a new unique id
importedEmp.id = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
employees.push(importedEmp);
added++;
});
break;
case 'merge':
// Merge - update existing and add new
importedEmployees.forEach(importedEmp => {
const existingIndex = employees.findIndex(e => e.employeeId === importedEmp.employeeId);
if (existingIndex >= 0) {
// Update existing, preserve the internal ID
const originalId = employees[existingIndex].id;
employees[existingIndex] = {
...importedEmp,
id: originalId // Preserve internal ID
};
updated++;
} else {
// Add new with a fresh internal ID
importedEmp.id = employees.length > 0 ? Math.max(...employees.map(e => e.id)) + 1 : 1;
employees.push(importedEmp);
added++;
}
});
break;
case 'replace':
// Replace all existing with imported, assigning new IDs
let idCounter = 1;
importedEmployees.forEach(emp => {
if (!emp.id) {
emp.id = idCounter++;
}
});
employees = importedEmployees;
added = importedEmployees.length;
break;
}
// Save to localStorage and update UI
saveEmployees();
extractDepartmentsFromEmployees();
saveDepartments();
updateDepartmentFilterOptions();
filterEmployees();
// Close modal and reset
importConfirmationModal.classList.add('hidden');
fileInput.value = '';
importFileContent = null;
// Show results
let message = `Import completed successfully. `;
if (mode === 'merge') {
message += `${added} new employees added, ${updated} existing employees updated.`;
} else {
message += `${added} employees imported.`;
}
alert(message);
}
function createHeaderMap() {
return {
'ID': 'id',
'Employee ID': 'employeeId',
'First Name': 'firstName',
'Last Name': 'lastName',
'Email': 'email',
'Phone': 'phone',
'Birth Date': 'birthDate',
'Civil Status': 'civilStatus',
'Department': 'department',
'Position': 'position',
'Hire Date': 'hireDate',
'Salary': 'salary',
'Status': 'status',
'SSS Number': 'sssNumber',
'PhilHealth Number': 'philhealthNumber',
'Pag-IBIG Number': 'pagibigNumber',
'TIN Number': 'tinNumber',
'Passport Number': 'passportNumber',
'Passport Expiry': 'passportExpiry',
'National ID': 'nationalId',
'Driver\'s License': 'driversLicense',
'EmployeeId': 'employeeId',
'Firstname': 'firstName',
'Lastname': 'lastName',
'SSS': 'sssNumber',
'Philhealth': 'philhealthNumber',
'Pag-ibig': 'pagibigNumber',
'TIN': 'tinNumber'
};
}
function mapValuesToEmployee(values, headers, headerMap) {
const employee = {};
for (let j = 0; j < headers.length; j++) {
const header = headers[j].trim();
let value = values[j] || '';
if (!headerMap[header] || value === '') continue;
const propName = headerMap[header];
// Type conversion
if (propName === 'salary') {
value = parseFloat(value.replace(/[^\d.]/g, '')) || 0;
} else if (propName === 'id') {
// Convert id to integer
value = parseInt(value) || null;
} else if (propName === 'hireDate' || propName === 'birthDate' || propName === 'passportExpiry') {
// Date formatting
if (/^\d{1,2}\/\d{1,2}\/\d{4}$/.test(value)) {
const [month, day, year] = value.split('/');
value = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
}
const date = new Date(value);
if (!isNaN(date.getTime())) {
value = date.toISOString().split('T')[0];
}
}
employee[propName] = value;
}
return employee;
}
function parseCSVLine(line) {
const values = [];
let current = '';
let inQuotes = false;
let inEscape = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (inEscape) {
current += char;
inEscape = false;
continue;
}
if (char === '\\') {
inEscape = true;
continue;
}
if (char === '"') {
inQuotes = !inQuotes;
continue;
}
if (char === ',' && !inQuotes) {
values.push(current);
current = '';
continue;
}
current += char;
}
// Add the last value
values.push(current);
// Trim whitespace and remove surrounding quotes if present
return values.map(val => {
val = val.trim();
if (val.startsWith('"') && val.endsWith('"')) {
return val.slice(1, -1);
}
return val;
});
}
function openClearAllConfirmationModal() {
clearAllConfirmationModal.classList.remove('hidden');
}
function clearAllEmployees() {
employees = [];
saveEmployees();
allDepartments = [];
saveDepartments();
updateDepartmentFilterOptions();
filterEmployees();
clearAllConfirmationModal.classList.add('hidden');
alert('All employee data has been cleared.');
}
</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=poluser/Employee-Management" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>SteelCraft Payroll System - Employee Management</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
<style>
.sidebar {
transition: all 0.3s;
}
.sidebar.collapsed {
width: 70px;
}
.sidebar.collapsed .nav-text {
display: none;
}
.sidebar.collapsed ~ .main-content {
margin-left: 70px;
}
.main-content {
transition: all 0.3s;
margin-left: 250px;
}
.highlight-row {
background-color: #f0f9ff;
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
height: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: #f1f1f1;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: #888;
border-radius: 3px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: #555;
}
[x-cloak] { display: none ; }
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
.tab-button {
transition: all 0.3s;
}
.tab-button.active {
background-color: #f3f4f6;
border-bottom: 2px solid #3b82f6;
color: #3b82f6;
}
#fileInput {
display: none;
}
.confirmation-modal {
transition: opacity 0.3s, transform 0.3s;
}
.confirmation-modal.hidden {
opacity: 0;
transform: scale(0.9);
pointer-events: none;
}
.employee-row {
transition: background-color 0.2s ease;
}
.employee-row:hover {
background-color: #f8fafc;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 200px;
background-color: white;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 0.5rem;
z-index: 50;
max-height: 300px;
overflow-y: auto;
}
.dropdown:hover .dropdown-content {
display: block;
}
.col-employeeId { width: 120px; min-width: 120px; }
.col-name { width: 180px; min-width: 180px; }
.col-department { width: 140px; min-width: 140px; }
.col-position { width: 140px; min-width: 140px; }
.col-status { width: 100px; min-width: 100px; }
.col-actions { width: 120px; min-width: 120px; }
.col-default { width: 140px; min-width: 140px; }
</style>
</head>
<body class="bg-gray-100">
<div class="flex h-screen overflow-hidden">