diff --git a/app.py b/app.py index be9d6d2..a6ea346 100644 --- a/app.py +++ b/app.py @@ -6449,59 +6449,72 @@ def employee_detail(employee_index): flash('Error loading employee details. Please try again.', 'error') return redirect(url_for('employees')) -""" -Time Attendance Routes for QR Attendance Management System -========================================================== - -Routes for managing time attendance data import and display functionality. -Add these routes to your main app.py file. -""" - -from flask import render_template, request, redirect, url_for, flash, jsonify -from werkzeug.utils import secure_filename -import os -from datetime import datetime, date -from models.time_attendance import TimeAttendance -from time_attendance_import_service import TimeAttendanceImportService - -# Add this to your existing app.py imports and route definitions - @app.route('/time-attendance') @login_required @log_user_activity('time_attendance_view') def time_attendance_dashboard(): - """Display time attendance dashboard""" + """Display time attendance dashboard with table layout""" try: - # Get summary statistics - total_records = TimeAttendance.query.count() - unique_employees = db.session.query(TimeAttendance.employee_id).distinct().count() - unique_locations = db.session.query(TimeAttendance.location_name).distinct().count() + # Initialize default values + total_records = 0 + unique_employees = 0 + unique_locations = 0 + recent_imports = [] + recent_records = [] + employees = [] + locations = [] - # Get recent imports (last 10 import batches) - recent_imports = db.session.query( - TimeAttendance.import_batch_id, - TimeAttendance.import_date, - TimeAttendance.import_source, - db.func.count(TimeAttendance.id).label('record_count') - ).filter( - TimeAttendance.import_batch_id.isnot(None) - ).group_by( - TimeAttendance.import_batch_id, - TimeAttendance.import_date, - TimeAttendance.import_source - ).order_by( - TimeAttendance.import_date.desc() - ).limit(10).all() - - # Get filter options - employees = TimeAttendance.get_unique_employees() - locations = TimeAttendance.get_unique_locations() + # Try to get data from TimeAttendance model if it exists + try: + from models.time_attendance import TimeAttendance + + # Get summary statistics + total_records = TimeAttendance.query.count() + + if total_records > 0: + unique_employees = db.session.query(TimeAttendance.employee_id).distinct().count() + unique_locations = db.session.query(TimeAttendance.location_name).distinct().count() + + # Get recent records (last 20 records for table display) + recent_records = TimeAttendance.query.order_by( + TimeAttendance.attendance_date.desc(), + TimeAttendance.attendance_time.desc() + ).limit(20).all() + + # Get recent imports (last 10 import batches) + recent_imports = db.session.query( + TimeAttendance.import_batch_id, + TimeAttendance.import_date, + TimeAttendance.import_source, + db.func.count(TimeAttendance.id).label('record_count') + ).filter( + TimeAttendance.import_batch_id.isnot(None) + ).group_by( + TimeAttendance.import_batch_id, + TimeAttendance.import_date, + TimeAttendance.import_source + ).order_by( + TimeAttendance.import_date.desc() + ).limit(10).all() + + # Get filter options + employees = TimeAttendance.get_unique_employees() + locations = TimeAttendance.get_unique_locations() + + except ImportError: + # TimeAttendance model doesn't exist yet - use defaults + pass + except Exception as e: + # Database table doesn't exist yet or other error - use defaults + print(f"TimeAttendance query error: {e}") + pass return render_template('time_attendance_dashboard.html', total_records=total_records, unique_employees=unique_employees, unique_locations=unique_locations, recent_imports=recent_imports, + recent_records=recent_records, employees=employees, locations=locations) diff --git a/templates/time_attendance_dashboard.html b/templates/time_attendance_dashboard.html index e9d3d62..b07629f 100644 --- a/templates/time_attendance_dashboard.html +++ b/templates/time_attendance_dashboard.html @@ -2,30 +2,21 @@ {% block title %}Time Attendance Dashboard - {{ COMPANY_NAME }}{% endblock %} {% block extra_head %} - + {% endblock %} {% block page_title %}Time Attendance{% endblock %} {% block content %} -
+
-
- - +

- Time Attendance Management + Time Attendance Dashboard

-

- Import, manage, and analyze employee time attendance data from Excel files -

+

Manage and analyze employee time attendance data from Excel imports

@@ -36,121 +27,203 @@ {% endif %} - - View Records + + View All Records
- -
-
-
- -
-
-

{{ "{:,}".format(total_records) }}

-

Total Records

-
-
- -
-
- -
-
-

{{ "{:,}".format(unique_employees) }}

-

Unique Employees

-
-
- -
-
- -
-
-

{{ "{:,}".format(unique_locations) }}

-

Locations

-
-
- -
-
- -
-
-

{{ "{:,}".format(recent_imports|length) }}

-

Recent Imports

-
-
-
- - -
-
-

- - Quick Actions -

-
-
-
-
-

- - Search Records -

-

Find specific attendance records by employee, date, or location

- - - Search Now - + +
+
+
+
+
- - {% if session.role == 'admin' %} -
-

- - Import Excel File -

-

Upload and import time attendance data from Excel spreadsheets

- - - Import Data - +
+

{{ "{:,}".format(total_records) }}

+

Total Records

- {% endif %} - -
-

- - Generate Reports -

-

Create detailed attendance reports and analytics

- - - View Reports - +
+ +
+
+ +
+
+

{{ "{:,}".format(unique_employees) }}

+

Employees

+
+
+ +
+
+ +
+
+

{{ "{:,}".format(unique_locations) }}

+

Locations

+
+
+ +
+
+ +
+
+

{{ "{:,}".format(recent_imports|length) }}

+

Import Batches

- + + {% if recent_records %} +
+
+

+ + Recent Time Attendance Records +

+
+
+ Showing latest {{ recent_records|length }} records +
+
+
+ +
+ + + + + + + + + + + + + + + + + {% for record in recent_records %} + + + + + + + + + + + + + {% endfor %} + +
#Employee IDEmployee NameLocationActionDateTimePlatformAddressActions
{{ loop.index }} +
+ {{ record.employee_id }} +
+
+
+ + {{ record.employee_name or 'Unknown' }} +
+
+
+ + {{ record.location_name }} +
+
+
+ {% if record.action_description.lower() == 'check in' %} + + {% elif record.action_description.lower() == 'check out' %} + + {% else %} + + {% endif %} + {{ record.action_description }} +
+
+
+ + {{ record.attendance_date.strftime('%Y-%m-%d') }} +
+
+
+ + {{ record.attendance_time.strftime('%H:%M:%S') }} +
+
+
+ {% if record.platform %} + + {{ record.platform[:25] }}{% if record.platform|length > 25 %}...{% endif %} + {% else %} + - + {% endif %} +
+
+
+ {% if record.recorded_address %} + + + {{ record.recorded_address[:35] }}{% if record.recorded_address|length > 35 %}...{% endif %} + + {% else %} + - + {% endif %} +
+
+
+ + {% if session.role == 'admin' %} + + {% endif %} +
+
+
+ + + +
+ {% endif %} + + {% if recent_imports %} -
-
-

+
+
+

- Recent Imports -

-
- Last {{ recent_imports|length }} import batches + Recent Import Batches +

+
+ Last {{ recent_imports|length }} import batches
-
- +
+
@@ -163,29 +236,31 @@ {% for import_batch in recent_imports %} - - {% endfor %} @@ -195,52 +270,6 @@ {% endif %} - - {% if employees %} -
-
-

- - Employee Quick Access -

-
- Click to view employee attendance records -
-
- -
- {% for employee in employees[:12] %} -
-
- {{ employee.employee_name[0].upper() if employee.employee_name else employee.employee_id[0].upper() }} -
-
-
{{ employee.employee_name }}
-
ID: {{ employee.employee_id }}
-
- - - View Records - -
- {% endfor %} - - {% if employees|length > 12 %} -
-
- - {{ employees|length - 12 }} more employees - - View All - -
-
- {% endif %} -
-
- {% endif %} - {% if total_records == 0 %}
@@ -250,156 +279,156 @@

No Time Attendance Data

Get started by importing your first Excel file with time attendance data. - The system supports various Excel formats and will automatically process your data. + The system supports various Excel formats (.xlsx, .xls) and will automatically process your data.

{% if session.role == 'admin' %} - - - Import Your First File - + {% endif %}
{% endif %} + + {% endblock %} \ No newline at end of file
Import Date
- {{ import_batch.import_date.strftime('%Y-%m-%d %H:%M') if import_batch.import_date else 'Unknown' }} + +
+ + {{ import_batch.import_date.strftime('%Y-%m-%d %H:%M') if import_batch.import_date else 'Unknown' }} +
- + {{ import_batch.import_source or 'Excel Import' }}
- - {{ "{:,}".format(import_batch.record_count) }} records - + {{ "{:,}".format(import_batch.record_count) }} {{ import_batch.import_batch_id[:8] }}... - - - View - + +
+ + + +