This commit is contained in:
2025-11-16 10:45:41 +03:30
parent 068b6037c7
commit 6c41296f22
9 changed files with 105 additions and 32 deletions

View File

@@ -4,10 +4,11 @@ namespace App\Console\Commands;
use App\Enums\ActivityMachineType;
use App\Models\Mission;
use App\Models\AssignmentFails;
use App\Models\MissionViolation;
use App\Services\CMMS\DailyMovingMachinesService;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
class DailyMovingMachineCommand extends Command
{
@@ -34,7 +35,7 @@ class DailyMovingMachineCommand extends Command
$vehiclesInfo = $dailyMovingMachines->run();
$response = collect($vehiclesInfo['vehiclesInfo']);
$date = now()->toDateString();
$date = Carbon::yesterday()->toDateString();
$cmms = $response->pluck('machineCode');
@@ -46,27 +47,27 @@ class DailyMovingMachineCommand extends Command
$missionOnly = $mission->diff($cmms);
foreach ($cmmsOnly as $code) {
$cmm = $response->firstWhere('machineCode', $code);
$cmm = $response->firstWhere('machineCode', '=', $code);
AssignmentFails::query()->create([
MissionViolation::query()->create([
'machine_code' => $code,
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->label(),
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->value,
'request_date' => $date,
'mileage' => $cmm['mileageKM'],
'exit_time' => $cmm['exit_time'],
'enter_time' => $cmm['enter_time'],
// 'exit_time' => $cmm['exit_time'],
// 'enter_time' => $cmm['enter_time'],
]);
}
foreach ($missionOnly as $code) {
$missionId = Mission::query()->where('machine_code', $code)
->whereDate('start_time', today())
->whereDate('start_time', $date)
->value('id');
AssignmentFails::query()->create([
MissionViolation::query()->create([
'machine_code' => $code,
'mission_id' => $missionId,
'type' => ActivityMachineType::ADAM_TAHAROK->label(),
'type' => ActivityMachineType::ADAM_TAHAROK->value,
'request_date' => $date,
]);
}