diff --git a/app/Console/Commands/SendLaserIdleHourReport.php b/app/Console/Commands/SendLaserIdleHourReport.php index 3ebb28e2..bc825d7b 100644 --- a/app/Console/Commands/SendLaserIdleHourReport.php +++ b/app/Console/Commands/SendLaserIdleHourReport.php @@ -112,18 +112,6 @@ class SendLaserIdleHourReport extends Command // return (float) ($record->pump_marked_physical_count ?? 0); // }); - \Log::info('Laser Idle Pump Debug', [ - 'plant_id' => $plant->id, - 'plant' => $plant->name, - 'machine' => $machineName, - 'pump_rows' => $pumpRecords->count(), - 'pump_sum' => $pumpCount, - 'pump_values' => $pumpRecords - ->pluck('pump_marked_physical_count') - ->countBy() - ->toArray(), - ]); - $namePlateCount = $machineRecords ->where('name_plate_machine_name', $machineName) ->where('name_plate_marked_status', 'Marked') @@ -140,33 +128,45 @@ class SendLaserIdleHourReport extends Command }); $totalExpectedMinutes = - $machineRecords - ->where('motor_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->motor_expected_time ?? 0)) + $machineRecords + ->where('motor_machine_name', $machineName) + ->sum(fn ($record) => (float) ($record->motor_expected_time ?? 0)) - + $machineRecords - ->where('pump_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->pump_expected_time ?? 0)) + + $machineRecords + ->where('pump_machine_name', $machineName) + ->sum(fn ($record) => (float) ($record->pump_expected_time ?? 0)) - + $machineRecords - ->where('name_plate_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->name_plate_expected_time ?? 0)) + + $machineRecords + ->where('name_plate_machine_name', $machineName) + ->sum(fn ($record) => (float) ($record->name_plate_expected_time ?? 0)) - + $machineRecords - ->where('motor_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->man_mark_expected_time ?? 0)); + + $machineRecords + ->where('motor_machine_name', $machineName) + ->sum(fn ($record) => (float) ($record->man_mark_expected_time ?? 0)); - $totalLaserOnHoursValue = $totalExpectedMinutes / 60; - $totalHours = intdiv((int) $totalExpectedMinutes, 60); - $totalMinutes = (int) $totalExpectedMinutes % 60; + // Keep only 3 decimal places + $totalExpectedMinutes = round($totalExpectedMinutes, 3); + + + // Convert total minutes into hours + minutes + $totalHours = floor($totalExpectedMinutes / 60); + + $totalMinutes = floor($totalExpectedMinutes % 60); $totalLaserOnHours = "{$totalHours} hr {$totalMinutes} min"; + + // Laser OFF + $totalLaserOnHoursValue = $totalExpectedMinutes / 60; + $totalLaserOffHoursValue = 22.5 - $totalLaserOnHoursValue; + $totalLaserOffHoursValue = max(0, $totalLaserOffHoursValue); + $offHours = floor($totalLaserOffHoursValue); - $offMinutes = round(($totalLaserOffHoursValue - $offHours) * 60); + + $offMinutes = floor(($totalLaserOffHoursValue - $offHours) * 60); $totalLaserOffHours = "{$offHours} hr {$offMinutes} min";