connect(); if ($connected) { echo "SUCCESS: Connected to ZKTeco machine!\n"; $zk->disableDevice(); echo "Fetching all attendance logs...\n"; $attendance = $zk->getAttendance(); $totalRecords = count($attendance); echo "Total records on device: {$totalRecords}\n"; $records2026 = []; $otherYears = []; foreach ($attendance as $record) { if (isset($record['timestamp'])) { $year = substr($record['timestamp'], 0, 4); if ($year === '2026') { $records2026[] = $record; } else { if (!isset($otherYears[$year])) { $otherYears[$year] = 0; } $otherYears[$year]++; } } } echo "Records in 2026: " . count($records2026) . "\n"; echo "Records in other years:\n"; foreach ($otherYears as $yr => $cnt) { echo " Year {$yr}: {$cnt} records\n"; } if (count($records2026) > 0) { // Group by employee code (id) $byEmployee = []; foreach ($records2026 as $rec) { $empId = $rec['id']; if (!isset($byEmployee[$empId])) { $byEmployee[$empId] = []; } $byEmployee[$empId][] = $rec['timestamp']; } echo "\nSummary of 2026 punches by Employee ID:\n"; echo str_repeat("-", 45) . "\n"; foreach ($byEmployee as $empId => $punches) { echo "Employee ID: {$empId} -> " . count($punches) . " punches (First: " . min($punches) . " | Last: " . max($punches) . ")\n"; } echo str_repeat("-", 45) . "\n"; // Sample of non-ID 2 records if any $nonId2 = array_filter($records2026, function($r) { return $r['id'] != 2; }); echo "Non-Employee ID 2 records in 2026: " . count($nonId2) . "\n"; if (count($nonId2) > 0) { echo "Sample of non-ID 2 records:\n"; $sampleNonId2 = array_slice($nonId2, 0, 10); foreach ($sampleNonId2 as $s) { echo "Emp ID: {$s['id']} | Time: {$s['timestamp']} | State: {$s['state']} | Type: {$s['type']}\n"; } } } $zk->enableDevice(); $zk->disconnect(); } else { echo "FAILED: Could not connect to ZKTeco machine.\n"; } } catch (\Exception $e) { echo "ERROR: " . $e->getMessage() . "\n"; }