-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
170 lines (147 loc) · 7.31 KB
/
index.html
File metadata and controls
170 lines (147 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Payroll Management System</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-5">
<h2 class="mb-4 text-center">Payroll System</h2>
<div class="card mb-4 shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0" id="formTitle">Add New Employee</h5>
</div>
<div class="card-body">
<form id="employeeForm">
<input type="hidden" id="editEmployeeNumber">
<div class="row g-3">
<div class="col-md-4"><input type="text" id="firstName" class="form-control" placeholder="First Name" required></div>
<div class="col-md-4"><input type="text" id="lastName" class="form-control" placeholder="Last Name" required></div>
<div class="col-md-4"><input type="text" id="middleName" class="form-control" placeholder="Middle Name"></div>
<div class="col-md-4"><input type="date" id="dob" class="form-control" required></div>
<div class="col-md-4"><input type="number" id="dailyRate" class="form-control" placeholder="Daily Rate (e.g. 2000)" required></div>
<div class="col-md-4">
<select id="workingDays" class="form-select" required>
<option value="">Select Schedule...</option>
<option value="MWF">MWF (Mon, Wed, Fri)</option>
<option value="TTHS">TTHS (Tue, Thu, Sat)</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-success mt-3 w-100">Save Employee</button>
</form>
</div>
</div>
<div class="card mb-4 shadow-sm border-info">
<div class="card-body row align-items-center">
<div class="col-auto"><strong>Payroll Period for Computation:</strong></div>
<div class="col-auto"><input type="date" id="computeStart" class="form-control" value="2011-05-16"></div>
<div class="col-auto">to</div>
<div class="col-auto"><input type="date" id="computeEnd" class="form-control" value="2011-05-20"></div>
</div>
</div>
<div class="card shadow-sm">
<div class="card-body">
<table class="table table-hover align-middle">
<thead class="table-dark">
<tr>
<th>Emp. Number</th>
<th>Name</th>
<th>Rate</th>
<th>Schedule</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody id="employeeTableBody">
</tbody>
</table>
</div>
</div>
</div>
<script>
const API_BASE_URL = 'http://localhost:5000/api/Employees';
document.addEventListener('DOMContentLoaded', loadEmployees);
async function loadEmployees() {
const response = await fetch(API_BASE_URL);
const employees = await response.json();
const tbody = document.getElementById('employeeTableBody');
tbody.innerHTML = '';
employees.forEach(emp => {
tbody.innerHTML += `
<tr>
<td><strong>${emp.employeeNumber}</strong></td>
<td>${emp.lastName}, ${emp.firstName}</td>
<td>₱${emp.dailyRate.toLocaleString()}</td>
<td>${emp.workingDays}</td>
<td class="text-end">
<button class="btn btn-sm btn-info text-white" onclick="computePay('${emp.employeeNumber}')">Compute Pay</button>
<button class="btn btn-sm btn-warning" onclick="editEmployee('${emp.employeeNumber}')">Edit</button>
<button class="btn btn-sm btn-danger" onclick="deleteEmployee('${emp.employeeNumber}')">Delete</button>
</td>
</tr>
`;
});
}
document.getElementById('employeeForm').addEventListener('submit', async (e) => {
e.preventDefault();
const employeeData = {
firstName: document.getElementById('firstName').value,
lastName: document.getElementById('lastName').value,
middleName: document.getElementById('middleName').value,
dateOfBirth: document.getElementById('dob').value,
dailyRate: parseFloat(document.getElementById('dailyRate').value),
workingDays: document.getElementById('workingDays').value
};
const empNumber = document.getElementById('editEmployeeNumber').value;
const method = empNumber ? 'PUT' : 'POST';
const url = empNumber ? `${API_BASE_URL}/${empNumber}` : API_BASE_URL;
const response = await fetch(url, {
method: method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(employeeData)
});
if (response.ok) {
document.getElementById('employeeForm').reset();
document.getElementById('editEmployeeNumber').value = '';
document.getElementById('formTitle').innerText = 'Add New Employee';
loadEmployees();
} else {
alert('Error saving employee. Check the console.');
}
});
async function editEmployee(empNumber) {
const response = await fetch(`${API_BASE_URL}/${empNumber}`);
const emp = await response.json();
document.getElementById('firstName').value = emp.firstName;
document.getElementById('lastName').value = emp.lastName;
document.getElementById('middleName').value = emp.middleName;
document.getElementById('dob').value = emp.dateOfBirth.split('T')[0];
document.getElementById('dailyRate').value = emp.dailyRate;
document.getElementById('workingDays').value = emp.workingDays;
document.getElementById('editEmployeeNumber').value = emp.employeeNumber;
document.getElementById('formTitle').innerText = `Edit Employee: ${emp.employeeNumber}`;
window.scrollTo(0, 0);
}
async function deleteEmployee(empNumber) {
if (confirm(`Are you sure you want to delete ${empNumber}?`)) {
await fetch(`${API_BASE_URL}/${empNumber}`, { method: 'DELETE' });
loadEmployees();
}
}
async function computePay(empNumber) {
const start = document.getElementById('computeStart').value;
const end = document.getElementById('computeEnd').value;
if(!start || !end) return alert("Please set the Payroll Period dates first.");
const response = await fetch(`${API_BASE_URL}/${empNumber}/compute?startDate=${start}&endDate=${end}`);
if(response.ok) {
const result = await response.json();
alert(`Pay for ${result.employeeName}\nFrom: ${result.startingDate}\nTo: ${result.endingDate}\n\nTake-Home Pay: ₱${result.takeHomePay.toLocaleString()}`);
} else {
alert("Error computing pay. Ensure dates are valid.");
}
}
</script>
</body>
</html>