Updated the Time Attendance Record page, filtering by Project

This commit is contained in:
2025-10-13 12:18:12 -04:00
parent 08b814d294
commit 0a24bee3bb
3 changed files with 29 additions and 5 deletions
+11 -1
View File
@@ -7164,6 +7164,7 @@ def export_time_attendance():
start_date = request.args.get('start_date')
end_date = request.args.get('end_date')
import_batch = request.args.get('import_batch')
project_filter = request.args.get('project_id')
# Build query with same filters as the view
from models.time_attendance import TimeAttendance
@@ -7195,6 +7196,9 @@ def export_time_attendance():
if import_batch:
query = query.filter(TimeAttendance.import_batch_id == import_batch)
if project_filter:
query = query.filter(TimeAttendance.project_id == project_filter)
# Order by date and time (most recent first)
records = query.order_by(
TimeAttendance.attendance_date.desc(),
@@ -7410,6 +7414,7 @@ def time_attendance_records():
location_filter = request.args.get('location_name')
start_date = request.args.get('start_date')
end_date = request.args.get('end_date')
project_filter = request.args.get('project_id')
page = request.args.get('page', 1, type=int)
per_page = 50 # Records per page
@@ -7423,6 +7428,9 @@ def time_attendance_records():
if location_filter:
query = query.filter(TimeAttendance.location_name == location_filter)
if project_filter:
query = query.filter(TimeAttendance.project_id == project_filter)
if start_date:
try:
start_date_obj = datetime.strptime(start_date, '%Y-%m-%d').date()
@@ -7477,12 +7485,14 @@ def time_attendance_records():
# Get unique employees and locations for filters
unique_employees = TimeAttendance.get_unique_employees()
unique_locations = TimeAttendance.get_unique_locations()
projects = Project.query.filter_by(active_status=True).order_by(Project.name).all()
return render_template(
'time_attendance_records.html',
records=records,
unique_employees=unique_employees,
unique_locations=unique_locations
unique_locations=unique_locations,
projects=projects
)
except Exception as e:
+2 -2
View File
@@ -371,7 +371,7 @@ body.has-sidebar .time-attendance-page {
.filter-form {
display: grid;
grid-template-columns: repeat(4, 1fr); /* 4 equal columns */
grid-template-columns: repeat(5, 1fr); /* 5 equal columns */
gap: 1rem;
align-items: end;
}
@@ -401,7 +401,7 @@ body.has-sidebar .time-attendance-page {
/* Responsive */
@media (max-width: 1200px) {
.filter-form {
grid-template-columns: repeat(2, 1fr); /* 2 columns on medium screens */
grid-template-columns: repeat(3, 1fr); /* 2 columns on medium screens */
}
}
+16 -2
View File
@@ -80,6 +80,18 @@
</select>
</div>
<div class="form-group">
<label for="project_id" class="form-label">Project</label>
<select id="project_id" name="project_id" class="form-select">
<option value="">All Projects</option>
{% for project in projects %}
<option value="{{ project.id }}" {% if request.args.get('project_id') == project.id|string %}selected{% endif %}>
{{ project.name }}
</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="location_name" class="form-label">Location</label>
<select id="location_name" name="location_name" class="form-select">
@@ -355,8 +367,9 @@ function exportRecords(format) {
document.getElementById('exportMenu').style.display = 'none';
// Get current filter values
const employeeId = document.querySelector('input[name="employee_id"]')?.value || '';
const locationName = document.querySelector('input[name="location_name"]')?.value || '';
const employeeId = document.querySelector('select[name="employee_id"]')?.value || '';
const locationName = document.querySelector('select[name="location_name"]')?.value || '';
const projectId = document.querySelector('select[name="project_id"]')?.value || ''; // ADD THIS LINE
const startDate = document.querySelector('input[name="start_date"]')?.value || '';
const endDate = document.querySelector('input[name="end_date"]')?.value || '';
@@ -364,6 +377,7 @@ function exportRecords(format) {
const params = new URLSearchParams();
if (employeeId) params.append('employee_id', employeeId);
if (locationName) params.append('location_name', locationName);
if (projectId) params.append('project_id', projectId); // ADD THIS LINE
if (startDate) params.append('start_date', startDate);
if (endDate) params.append('end_date', endDate);
params.append('format', format);