41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\AttendanceRecord;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class RecalculateAttendance extends Command
|
|
{
|
|
protected $signature = 'attendance:recalculate';
|
|
protected $description = 'Natively recalculate tardiness, undertime, and total hours based on local clock-in data.';
|
|
|
|
public function handle()
|
|
{
|
|
$this->info("Initializing Native Attendance Recalculation...");
|
|
|
|
$records = AttendanceRecord::whereNotNull('clock_in')->get();
|
|
$bar = $this->output->createProgressBar(count($records));
|
|
|
|
$lateCount = 0;
|
|
$earlyCount = 0;
|
|
|
|
foreach ($records as $record) {
|
|
// Process attendance will calculate late_hours, early_hours, total_hours
|
|
// We pass false to not overwrite the user's manual status if any.
|
|
$record->processAttendance(false);
|
|
|
|
if ($record->is_late) $lateCount++;
|
|
if ($record->is_early_departure) $earlyCount++;
|
|
|
|
$bar->advance();
|
|
}
|
|
|
|
$bar->finish();
|
|
|
|
$this->info("\nRecalculation Complete!");
|
|
$this->info("Found {$lateCount} late records and {$earlyCount} early departure records.");
|
|
}
|
|
}
|