const buildCreditedDaysByEmployee = useCallback((records = []) => { const d = new Date(); const selectedYear = d.getFullYear(); const selectedMonth = d.getMonth() + 1; // current month return records.reduce((totals, record) => { const dateMatch = String(record.attendance_date || '').match(/^(\d{4})-(\d{2})-(\d{2})/); if (!dateMatch) return totals; const [, year, month, day] = dateMatch.map(Number); if (year !== selectedYear || month !== selectedMonth) return totals; const employeeId = record.employee_id; if (!employeeId) return totals; if (!totals[employeeId]) { totals[employeeId] = { firstHalfDays: 0, secondHalfDays: 0 }; } const credit = Number.parseFloat(record.days_credited) || 0; if (day <= 15) { totals[employeeId].firstHalfDays += credit; } else { totals[employeeId].secondHalfDays += credit; } return totals; }, {}); }, []); const fetchEmployees = useCallback(async (options = {}) => {