Update payroll export
This commit is contained in:
@@ -4454,8 +4454,8 @@ def export_payroll_excel():
|
||||
flash('Invalid date format. Please use YYYY-MM-DD format.', 'error')
|
||||
return redirect(url_for('payroll_dashboard'))
|
||||
|
||||
# Get attendance records with project filter
|
||||
query = db.session.query(AttendanceData).join(QRCode, AttendanceData.qr_code_id == QRCode.id)
|
||||
# Get attendance records with project filter and QR code data
|
||||
query = db.session.query(AttendanceData, QRCode).join(QRCode, AttendanceData.qr_code_id == QRCode.id)
|
||||
|
||||
# Apply date filter
|
||||
query = query.filter(
|
||||
@@ -4470,7 +4470,16 @@ def export_payroll_excel():
|
||||
|
||||
query = query.order_by(AttendanceData.employee_id, AttendanceData.check_in_date, AttendanceData.check_in_time)
|
||||
|
||||
attendance_records = query.all()
|
||||
# Get the results and attach QR code data to attendance records
|
||||
query_results = query.all()
|
||||
attendance_records = []
|
||||
|
||||
for attendance_data, qr_code in query_results:
|
||||
# Attach the QR code object to the attendance record
|
||||
attendance_data.qr_code = qr_code
|
||||
attendance_records.append(attendance_data)
|
||||
|
||||
print(f"📊 Export: Found {len(attendance_records)} records with QR data")
|
||||
|
||||
if not attendance_records:
|
||||
flash('No attendance records found for the selected date range and project.', 'warning')
|
||||
@@ -4518,6 +4527,21 @@ def export_payroll_excel():
|
||||
start_date, end_date, attendance_records, employee_names, include_travel_time
|
||||
)
|
||||
filename_prefix = 'detailed_hours_report'
|
||||
elif report_type == 'template':
|
||||
# Get project name for the template
|
||||
project_name = None
|
||||
if project_filter:
|
||||
try:
|
||||
project = Project.query.get(int(project_filter))
|
||||
if project:
|
||||
project_name = project.name
|
||||
except Exception as e:
|
||||
print(f"⚠️ Error getting project name for template: {e}")
|
||||
|
||||
excel_file = exporter.create_template_format_report(
|
||||
start_date, end_date, attendance_records, employee_names, include_travel_time, project_name
|
||||
)
|
||||
filename_prefix = 'template_hours_report'
|
||||
else:
|
||||
excel_file = exporter.create_payroll_report(
|
||||
start_date, end_date, attendance_records, employee_names, include_travel_time
|
||||
@@ -4544,7 +4568,9 @@ def export_payroll_excel():
|
||||
|
||||
# Log successful export
|
||||
logger_handler.logger.info(f"Payroll Excel export generated by user {session.get('username', 'unknown')}: {filename}")
|
||||
|
||||
if report_type == 'template':
|
||||
logger_handler.logger.info(f"Template format hours export generated by user {session.get('username', 'unknown')}: {filename}")
|
||||
|
||||
return send_file(
|
||||
excel_file,
|
||||
as_attachment=True,
|
||||
|
||||
Reference in New Issue
Block a user