import type { DayInfo, Person } from './types' import { getCzechHolidays } from './holidays' const MONTH_NAMES: Record = { 1:'Leden',2:'Únor',3:'Březen',4:'Duben',5:'Květen',6:'Červen', 7:'Červenec',8:'Srpen',9:'Září',10:'Říjen',11:'Listopad',12:'Prosinec', } interface FpdResult { personId: string name: string note?: string workedHours: number fpd: number diff: number // positive = over, negative = under } function getHoursForValue(v: string): number { if (v === 'A' || v === 'B') return 12 const num = parseFloat(v) if (!isNaN(num) && num > 0) return num return 0 } export function computeFpd( month: number, year: number, dayIndex: DayInfo[], people: Person[], ): { fpd: number; workDays: number; results: FpdResult[] } { const holidays = getCzechHolidays(year) const holidaySet = new Set(holidays.filter(h => h.month === month).map(h => h.day)) // Count working days in month const monthDays = dayIndex.filter(d => d.month === month && d.year === year) let workDays = 0 for (const d of monthDays) { if (!d.weekend && !holidaySet.has(d.day)) workDays++ } const fpd = workDays * 8 // Check TKB people only const tkbPeople = people.filter(p => p.group === 'TKB') const results: FpdResult[] = [] for (const person of tkbPeople) { let workedHours = 0 for (const d of monthDays) { const cellData = person.data[String(d.idx)] const value = cellData?.v if (value) { workedHours += getHoursForValue(value) } } const diff = workedHours - fpd results.push({ personId: person.id, name: person.name, note: person.note, workedHours, fpd, diff, }) } return { fpd, workDays, results } } interface FpdModalProps { month: number year: number dayIndex: DayInfo[] people: Person[] onClose: () => void onExportDochazka?: () => void } export function FpdModal({ month, year, dayIndex, people, onClose, onExportDochazka }: FpdModalProps) { const { fpd, workDays, results } = computeFpd(month, year, dayIndex, people) const under = results.filter(r => r.diff < 0) const okOrOver = results.filter(r => r.diff >= 0) return (
e.stopPropagation()}>

Kontrola FPD — {MONTH_NAMES[month]} {year}

Pracovních dnů: {workDays} | FPD: {fpd} h | Pohotovost TKB: {results.length} osob
{under.length === 0 ? (
✓ Nikdo nemá nedostatek hodin
) : ( <>
Chybí hodiny ({under.length})
{under.map(r => (
{r.name} {r.note && ({r.note})} {r.workedHours}h / {r.fpd}h {r.diff}h
))}
)}
Ostatní ({okOrOver.length})
{okOrOver.map(r => (
0 ? 'bg-slate-700/30 border border-slate-600/50' : 'bg-green-900/20 border border-green-700/30'}`} > {r.name} {r.note && ({r.note})} {r.workedHours}h / {r.fpd}h 0 ? 'text-slate-300' : 'text-green-400'}`}> {r.diff > 0 ? `+${r.diff}h` : '✓'}
))}
{onExportDochazka && (
)}
) }