530 lines
17 KiB
HTML
530 lines
17 KiB
HTML
{% extends "base_authenticated.html" %}
|
|
{% block title %}Payroll Dashboard - Working Hours{% endblock %}
|
|
|
|
{% block extra_head %}
|
|
<style>
|
|
.payroll-page {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 2rem 0;
|
|
}
|
|
|
|
.payroll-container {
|
|
max-width: 1400px;
|
|
margin: 0 auto;
|
|
padding: 0 1rem;
|
|
}
|
|
|
|
.payroll-header {
|
|
background: rgba(255, 255, 255, 0.95);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 15px;
|
|
padding: 2rem;
|
|
margin-bottom: 2rem;
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
text-align: center;
|
|
}
|
|
|
|
.payroll-header h1 {
|
|
color: #2d3748;
|
|
font-size: 2.5rem;
|
|
font-weight: 700;
|
|
margin: 0 0 1rem 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.payroll-header h1 i {
|
|
color: #48bb78;
|
|
}
|
|
|
|
.filters-section {
|
|
background: rgba(255, 255, 255, 0.95);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 15px;
|
|
padding: 2rem;
|
|
margin-bottom: 2rem;
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.filters-form {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
gap: 1.5rem;
|
|
align-items: end;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
font-weight: 600;
|
|
color: #4a5568;
|
|
margin-bottom: 0.5rem;
|
|
}
|
|
|
|
.form-group input,
|
|
.form-group select {
|
|
width: 100%;
|
|
padding: 0.75rem;
|
|
border: 2px solid #e2e8f0;
|
|
border-radius: 8px;
|
|
font-size: 1rem;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.form-group input:focus,
|
|
.form-group select:focus {
|
|
outline: none;
|
|
border-color: #4299e1;
|
|
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
|
|
}
|
|
|
|
.checkbox-group {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
margin-top: 1.5rem;
|
|
}
|
|
|
|
.checkbox-group input[type="checkbox"] {
|
|
width: auto;
|
|
transform: scale(1.2);
|
|
}
|
|
|
|
.btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
padding: 0.75rem 1.5rem;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-weight: 600;
|
|
text-decoration: none;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #4299e1, #3182ce);
|
|
color: white;
|
|
}
|
|
|
|
.btn-success {
|
|
background: linear-gradient(135deg, #48bb78, #38a169);
|
|
color: white;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: linear-gradient(135deg, #a0aec0, #718096);
|
|
color: white;
|
|
}
|
|
|
|
.results-section {
|
|
background: rgba(255, 255, 255, 0.95);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 15px;
|
|
padding: 2rem;
|
|
margin-bottom: 2rem;
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.summary-cards {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 1.5rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.summary-card {
|
|
background: linear-gradient(135deg, #f7fafc, #edf2f7);
|
|
border: 2px solid #e2e8f0;
|
|
border-radius: 12px;
|
|
padding: 1.5rem;
|
|
text-align: center;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.summary-card:hover {
|
|
border-color: #4299e1;
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 16px rgba(66, 153, 225, 0.15);
|
|
}
|
|
|
|
.summary-card h3 {
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
color: #2d3748;
|
|
margin: 0 0 0.5rem 0;
|
|
}
|
|
|
|
.summary-card p {
|
|
color: #718096;
|
|
font-weight: 600;
|
|
margin: 0;
|
|
}
|
|
|
|
.employees-table {
|
|
overflow-x: auto;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
background: white;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.table th {
|
|
background: linear-gradient(135deg, #4299e1, #3182ce);
|
|
color: white;
|
|
padding: 1rem;
|
|
text-align: left;
|
|
font-weight: 600;
|
|
border-bottom: 2px solid #2b6cb0;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.table td {
|
|
padding: 0.75rem 1rem;
|
|
border-bottom: 1px solid #e2e8f0;
|
|
color: #4a5568;
|
|
}
|
|
|
|
.table tbody tr:hover {
|
|
background-color: #f7fafc;
|
|
}
|
|
|
|
.hours-badge {
|
|
display: inline-block;
|
|
padding: 0.25rem 0.75rem;
|
|
border-radius: 20px;
|
|
font-size: 0.875rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.hours-regular {
|
|
background: #e6fffa;
|
|
color: #38a169;
|
|
}
|
|
|
|
.hours-overtime {
|
|
background: #fff5f5;
|
|
color: #e53e3e;
|
|
}
|
|
|
|
.hours-total {
|
|
background: #ebf8ff;
|
|
color: #3182ce;
|
|
}
|
|
|
|
.miss-punch {
|
|
background: #feb2b2;
|
|
color: #c53030;
|
|
}
|
|
|
|
.no-data {
|
|
text-align: center;
|
|
padding: 3rem;
|
|
color: #a0aec0;
|
|
font-style: italic;
|
|
font-size: 1.1rem;
|
|
}
|
|
|
|
.export-actions {
|
|
display: flex;
|
|
gap: 1rem;
|
|
margin-top: 2rem;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.back-nav {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
color: white;
|
|
text-decoration: none;
|
|
font-weight: 600;
|
|
margin-bottom: 1rem;
|
|
opacity: 0.9;
|
|
transition: opacity 0.3s ease;
|
|
}
|
|
|
|
.back-nav:hover {
|
|
opacity: 1;
|
|
color: white;
|
|
text-decoration: none;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.payroll-header h1 {
|
|
font-size: 2rem;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.filters-form {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
|
|
.summary-cards {
|
|
grid-template-columns: repeat(2, 1fr);
|
|
}
|
|
|
|
.export-actions {
|
|
flex-direction: column;
|
|
}
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="payroll-page">
|
|
<div class="payroll-container">
|
|
<!-- Back Navigation -->
|
|
<a href="{{ url_for('dashboard') }}" class="back-nav">
|
|
<i class="fas fa-arrow-left"></i>
|
|
<span>Back to Dashboard</span>
|
|
</a>
|
|
|
|
<!-- Page Header -->
|
|
<div class="payroll-header">
|
|
<h1>
|
|
<i class="fas fa-calculator"></i>
|
|
Payroll Dashboard
|
|
</h1>
|
|
<p>Calculate employee working hours and generate payroll reports</p>
|
|
</div>
|
|
|
|
<!-- Filters Section -->
|
|
<div class="filters-section">
|
|
<h3 style="margin-bottom: 1.5rem; color: #2d3748;">
|
|
<i class="fas fa-filter" style="color: #4299e1; margin-right: 0.5rem;"></i>
|
|
Calculation Parameters
|
|
</h3>
|
|
|
|
<form method="GET" action="{{ url_for('payroll_dashboard') }}" class="filters-form">
|
|
<div class="form-group">
|
|
<label for="date_from">Start Date</label>
|
|
<input type="date" id="date_from" name="date_from" value="{{ date_from }}" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="date_to">End Date</label>
|
|
<input type="date" id="date_to" name="date_to" value="{{ date_to }}" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="project_filter">Filter by Project</label>
|
|
<select id="project_filter" name="project_filter">
|
|
<option value="">All Projects</option>
|
|
{% for project in projects %}
|
|
<option value="{{ project.id }}" {% if project_filter == project.id|string %}selected{% endif %}>
|
|
{{ project.name }}
|
|
</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary">
|
|
<i class="fas fa-calculator"></i>
|
|
Calculate Hours
|
|
</button>
|
|
</div>
|
|
|
|
<div class="checkbox-group">
|
|
<input type="checkbox" id="include_travel_time" name="include_travel_time"
|
|
value="true" {% if include_travel_time %}checked{% endif %}>
|
|
<label for="include_travel_time">Include travel time between locations</label>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Results Section -->
|
|
{% if working_hours_data %}
|
|
<div class="results-section">
|
|
<h3 style="margin-bottom: 1.5rem; color: #2d3748;">
|
|
<i class="fas fa-chart-bar" style="color: #48bb78; margin-right: 0.5rem;"></i>
|
|
Working Hours Summary
|
|
</h3>
|
|
|
|
<!-- Summary Cards -->
|
|
<div class="summary-cards">
|
|
<div class="summary-card">
|
|
<h3>{{ working_hours_data.employee_count }}</h3>
|
|
<p>Total Employees</p>
|
|
</div>
|
|
<div class="summary-card">
|
|
<h3>{{ "%.1f"|format(working_hours_data.employees.values() | map(attribute='grand_totals.total_hours') | sum) }}</h3>
|
|
<p>Total Hours</p>
|
|
</div>
|
|
<div class="summary-card">
|
|
<h3>{{ "%.1f"|format(working_hours_data.employees.values() | map(attribute='grand_totals.regular_hours') | sum) }}</h3>
|
|
<p>Regular Hours</p>
|
|
</div>
|
|
<div class="summary-card">
|
|
<h3>{{ "%.1f"|format(working_hours_data.employees.values() | map(attribute='grand_totals.overtime_hours') | sum) }}</h3>
|
|
<p>Overtime Hours</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Employee Details Table -->
|
|
<div class="employees-table">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Employee ID</th>
|
|
<th>Employee Name</th>
|
|
<th>Total Hours</th>
|
|
<th>Regular Hours</th>
|
|
<th>Overtime Hours</th>
|
|
<th>Working Days</th>
|
|
<th>Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for employee_id, emp_data in working_hours_data.employees.items() %}
|
|
<tr>
|
|
<td>{{ employee_id }}</td>
|
|
<td>{{ employee_names.get(employee_id, 'Employee ' + employee_id) }}</td>
|
|
<td>
|
|
<span class="hours-badge hours-total">
|
|
{{ "%.2f"|format(emp_data.grand_totals.total_hours) }} hrs
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span class="hours-badge hours-regular">
|
|
{{ "%.2f"|format(emp_data.grand_totals.regular_hours) }} hrs
|
|
</span>
|
|
</td>
|
|
<td>
|
|
{% if emp_data.grand_totals.overtime_hours > 0 %}
|
|
<span class="hours-badge hours-overtime">
|
|
{{ "%.2f"|format(emp_data.grand_totals.overtime_hours) }} hrs
|
|
</span>
|
|
{% else %}
|
|
<span class="hours-badge" style="background: #f0f0f0; color: #666;">
|
|
0.00 hrs
|
|
</span>
|
|
{% endif %}
|
|
</td>
|
|
<td>
|
|
{% set working_days = emp_data.daily_hours.values() | selectattr('total_hours', '>', 0) | list | length %}
|
|
{{ working_days }} days
|
|
</td>
|
|
<td>
|
|
{% set miss_punches = emp_data.daily_hours.values() | selectattr('is_miss_punch', 'equalto', true) | list | length %}
|
|
{% if miss_punches > 0 %}
|
|
<span class="hours-badge miss-punch">
|
|
{{ miss_punches }} miss punch(es)
|
|
</span>
|
|
{% else %}
|
|
<span class="hours-badge" style="background: #e6fffa; color: #38a169;">
|
|
Complete
|
|
</span>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Export Actions -->
|
|
<div class="export-actions">
|
|
<form method="POST" action="{{ url_for('export_payroll_excel') }}" style="display: inline;">
|
|
<input type="hidden" name="date_from" value="{{ date_from }}">
|
|
<input type="hidden" name="date_to" value="{{ date_to }}">
|
|
<input type="hidden" name="include_travel_time" value="{{ include_travel_time|lower }}">
|
|
<input type="hidden" name="report_type" value="payroll">
|
|
<button type="submit" class="btn btn-success">
|
|
<i class="fas fa-file-excel"></i>
|
|
Export Payroll Report
|
|
</button>
|
|
</form>
|
|
|
|
<form method="POST" action="{{ url_for('export_payroll_excel') }}" style="display: inline;">
|
|
<input type="hidden" name="date_from" value="{{ date_from }}">
|
|
<input type="hidden" name="date_to" value="{{ date_to }}">
|
|
<input type="hidden" name="include_travel_time" value="{{ include_travel_time|lower }}">
|
|
<input type="hidden" name="report_type" value="detailed">
|
|
<button type="submit" class="btn btn-secondary">
|
|
<i class="fas fa-list-alt"></i>
|
|
Export Detailed Hours
|
|
</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div style="margin-top: 1rem; padding: 1rem; background: #f7fafc; border-radius: 8px; color: #4a5568; font-size: 0.9rem;">
|
|
<strong>Report Details:</strong><br>
|
|
Period: {{ working_hours_data.period_start }} to {{ working_hours_data.period_end }}<br>
|
|
Travel Time: {{ "Included" if working_hours_data.include_travel_time else "Excluded" }}<br>
|
|
Generated: {{ working_hours_data.calculation_date }}
|
|
</div>
|
|
</div>
|
|
{% else %}
|
|
<div class="results-section">
|
|
<div class="no-data">
|
|
<i class="fas fa-clock" style="font-size: 3rem; margin-bottom: 1rem; opacity: 0.5;"></i><br>
|
|
{% if date_from and date_to %}
|
|
No attendance records found for the selected date range.<br>
|
|
Please try a different date range or check if attendance data has been recorded.
|
|
{% else %}
|
|
Please select a date range to calculate working hours.
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Auto-submit form when travel time checkbox changes
|
|
const travelTimeCheckbox = document.getElementById('include_travel_time');
|
|
if (travelTimeCheckbox) {
|
|
travelTimeCheckbox.addEventListener('change', function() {
|
|
// Only auto-submit if we have dates
|
|
const dateFrom = document.getElementById('date_from').value;
|
|
const dateTo = document.getElementById('date_to').value;
|
|
|
|
if (dateFrom && dateTo) {
|
|
this.form.submit();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Set max date to today for date inputs
|
|
const today = new Date().toISOString().split('T')[0];
|
|
document.getElementById('date_from').setAttribute('max', today);
|
|
document.getElementById('date_to').setAttribute('max', today);
|
|
|
|
// Validate date range
|
|
const dateFromInput = document.getElementById('date_from');
|
|
const dateToInput = document.getElementById('date_to');
|
|
|
|
function validateDateRange() {
|
|
const dateFrom = new Date(dateFromInput.value);
|
|
const dateTo = new Date(dateToInput.value);
|
|
|
|
if (dateFrom && dateTo && dateFrom > dateTo) {
|
|
dateToInput.setCustomValidity('End date must be after start date');
|
|
} else {
|
|
dateToInput.setCustomValidity('');
|
|
}
|
|
}
|
|
|
|
dateFromInput.addEventListener('change', validateDateRange);
|
|
dateToInput.addEventListener('change', validateDateRange);
|
|
});
|
|
</script>
|
|
{% endblock %} |