60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\User;
|
|
use App\Models\AttendanceRecord;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SyncLegacyLateHours extends Command
|
|
{
|
|
protected $signature = 'import:legacy-late-hours';
|
|
protected $description = 'Synchronizes exact decimal late/early missing hour records securely from the old legacy attendance logs.';
|
|
|
|
public function handle()
|
|
{
|
|
$this->info("Initializing Fractional Tardiness Matrix Sync...");
|
|
|
|
// Map users
|
|
$legacyUsers = DB::connection('legacy')->table('users')->get(['id', 'name']);
|
|
$newUserIdMap = [];
|
|
foreach ($legacyUsers as $lu) {
|
|
$matchingLocal = User::where('name', $lu->name)->first();
|
|
if ($matchingLocal) {
|
|
// Key = legacy user ID, Value = local user ID
|
|
$newUserIdMap[$lu->id] = $matchingLocal->id;
|
|
}
|
|
}
|
|
|
|
// Loop target logs
|
|
$logs = DB::connection('legacy')->table('attendances')
|
|
->whereNotNull('late_hours')
|
|
->orWhereNotNull('early_hours')
|
|
->get();
|
|
|
|
$bar = $this->output->createProgressBar(count($logs));
|
|
|
|
foreach ($logs as $log) {
|
|
if (!isset($newUserIdMap[$log->user_id])) {
|
|
$bar->advance();
|
|
continue;
|
|
}
|
|
|
|
$localUserId = $newUserIdMap[$log->user_id];
|
|
|
|
AttendanceRecord::where('employee_id', $localUserId)
|
|
->where('date', $log->date)
|
|
->update([
|
|
'late_hours' => collect([$log->late_hours, 0])->max(),
|
|
'early_hours' => collect([$log->early_hours, 0])->max(),
|
|
]);
|
|
|
|
$bar->advance();
|
|
}
|
|
|
|
$bar->finish();
|
|
$this->info("\nPrecision Hour Synchronization locked directly into native Engine!");
|
|
}
|
|
}
|