65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
|
|
// Check token for security
|
|
$expectedToken = '7f3b89e902a2cdb8b5de9f2e30f14d8a245fca9b';
|
|
if (!isset($_GET['token']) || $_GET['token'] !== $expectedToken) {
|
|
header('HTTP/1.1 403 Forbidden');
|
|
die('Forbidden: Invalid Token');
|
|
}
|
|
|
|
header('Content-Type: text/plain');
|
|
|
|
echo "=========================================\n";
|
|
echo "Syncing and Correcting Paul Rei Paas Shift\n";
|
|
echo "=========================================\n\n";
|
|
|
|
try {
|
|
// Boot Laravel
|
|
require __DIR__ . '/../vendor/autoload.php';
|
|
$app = require_once __DIR__ . '/../bootstrap/app.php';
|
|
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
|
|
$kernel->bootstrap();
|
|
|
|
// 1. Find Paul Rei Paas
|
|
$employee = \App\Models\Employee::where('biometric_emp_id', '2068')->first();
|
|
if (!$employee) {
|
|
throw new \Exception("Employee Paul Rei Paas (2068) not found.");
|
|
}
|
|
|
|
$userId = $employee->user_id;
|
|
echo "Employee found: User ID $userId\n";
|
|
|
|
// 2. Update default shift to 17 in employees table
|
|
$employee->shift_id = 17;
|
|
$employee->save();
|
|
echo "Updated employee default shift_id to 17 (OPS 08:00AM-05:00PM) in employees table.\n";
|
|
|
|
// 3. Update shift_id to 17 in all attendance_records from March 1st onwards
|
|
$updatedRecords = \App\Models\AttendanceRecord::where('employee_id', $userId)
|
|
->where('date', '>=', '2026-03-01')
|
|
->update(['shift_id' => 17]);
|
|
|
|
echo "Updated shift_id to 17 for $updatedRecords attendance records (since 2026-03-01).\n";
|
|
|
|
// 4. Reprocess all these records so the status, total hours, and warnings are recalculated using shift 17
|
|
$records = \App\Models\AttendanceRecord::where('employee_id', $userId)
|
|
->where('date', '>=', '2026-03-01')
|
|
->get();
|
|
|
|
$reprocessedCount = 0;
|
|
foreach ($records as $record) {
|
|
$oldStatus = $record->status;
|
|
$record->processAttendance();
|
|
$newStatus = $record->status;
|
|
if ($oldStatus !== $newStatus) {
|
|
echo "Date: " . $record->date . " | Updated status from $oldStatus to $newStatus\n";
|
|
}
|
|
$reprocessedCount++;
|
|
}
|
|
|
|
echo "\nCompleted successfully. Reprocessed $reprocessedCount records.\n";
|
|
|
|
} catch (\Exception $e) {
|
|
echo "ERROR: " . $e->getMessage() . "\n";
|
|
}
|