import { Link } from 'react-router-dom' import { formatDate, formatDatetime, formatTime, calculateWorkMinutes, formatMinutes, getLeaveTypeName, getLeaveTypeBadgeClass } from '../utils/attendanceHelpers' interface ProjectLog { id?: number project_id?: number project_name?: string started_at?: string ended_at?: string | null hours?: string | number | null minutes?: string | number | null } interface AttendanceRecord { id: number shift_date: string user_name: string leave_type?: string leave_hours?: number arrival_time?: string | null departure_time?: string | null break_start?: string | null break_end?: string | null arrival_lat?: number | string | null arrival_lng?: number | string | null departure_lat?: number | string | null departure_lng?: number | string | null project_name?: string project_logs?: ProjectLog[] notes?: string | null } interface AttendanceShiftTableProps { records: AttendanceRecord[] onEdit: (record: AttendanceRecord) => void onDelete: (record: AttendanceRecord) => void } function formatBreak(record: AttendanceRecord): string { if (record.break_start && record.break_end) { return `${formatTime(record.break_start)} - ${formatTime(record.break_end)}` } if (record.break_start) { return `${formatTime(record.break_start)} - ?` } return '\u2014' } function renderProjectCell(record: AttendanceRecord): React.ReactNode { if (record.project_logs && record.project_logs.length > 0) { return (
{record.project_logs.map((log, i) => { let h: number, m: number, isActive = false if (log.hours !== null && log.hours !== undefined) { h = parseInt(String(log.hours)) || 0 m = parseInt(String(log.minutes)) || 0 } else { isActive = !log.ended_at const end = log.ended_at ? new Date(log.ended_at) : new Date() const mins = Math.floor((end.getTime() - new Date(log.started_at!).getTime()) / 60000) h = Math.floor(mins / 60) m = mins % 60 } return ( {log.project_name || `#${log.project_id}`} ({h}:{String(m).padStart(2, '0')}h{isActive ? ' \u25B8' : ''}) ) })}
) } if (record.project_name) { return {record.project_name} } return '\u2014' } export default function AttendanceShiftTable({ records, onEdit, onDelete }: AttendanceShiftTableProps) { if (records.length === 0) { return (

Za tento měsíc nejsou žádné záznamy.

) } return (
{records.map((record) => { const leaveType = record.leave_type || 'work' const isLeave = leaveType !== 'work' const workMinutes = isLeave ? (Number(record.leave_hours) || 8) * 60 : calculateWorkMinutes(record) const hasLocation = (record.arrival_lat && record.arrival_lng) || (record.departure_lat && record.departure_lng) return ( ) })}
Datum Zaměstnanec Typ Příchod Pauza Odchod Hodiny Projekt GPS Poznámka Akce
{formatDate(record.shift_date)} {record.user_name} {getLeaveTypeName(leaveType)} {isLeave ? '\u2014' : formatDatetime(record.arrival_time)} {isLeave ? '\u2014' : formatBreak(record)} {isLeave ? '\u2014' : formatDatetime(record.departure_time)} {workMinutes > 0 ? `${formatMinutes(workMinutes)} h` : '\u2014'} {renderProjectCell(record)} {hasLocation ? ( {'\uD83D\uDCCD'} ) : '\u2014'} {record.notes || ''}
) }