From 1cc78f8e68561b6340323c50436b5e03cd996904 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 6 Oct 2026 11:31:17 +0530 Subject: [PATCH] changed logic in laser idle report --- .../Commands/SendLaserIdleHourReport.php | 113 +++++++++++++----- 1 file changed, 85 insertions(+), 28 deletions(-) diff --git a/app/Console/Commands/SendLaserIdleHourReport.php b/app/Console/Commands/SendLaserIdleHourReport.php index bc825d7b..4d4041ba 100644 --- a/app/Console/Commands/SendLaserIdleHourReport.php +++ b/app/Console/Commands/SendLaserIdleHourReport.php @@ -127,48 +127,105 @@ class SendLaserIdleHourReport extends Command return (float) ($record->man_marked_status ?? 0); }); - $totalExpectedMinutes = - $machineRecords - ->where('motor_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->motor_expected_time ?? 0)) + $totalExpectedMilliseconds = + $machineRecords + ->where('motor_machine_name', $machineName) + ->sum(function ($record) { - + $machineRecords - ->where('pump_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->pump_expected_time ?? 0)) + $value = (string) ($record->motor_expected_time ?? '0'); - + $machineRecords - ->where('name_plate_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->name_plate_expected_time ?? 0)) + [$seconds, $milliseconds] = array_pad( + explode('.', $value, 2), + 2, + '0' + ); - + $machineRecords - ->where('motor_machine_name', $machineName) - ->sum(fn ($record) => (float) ($record->man_mark_expected_time ?? 0)); + // Keep exactly 3 digits for milliseconds + $milliseconds = substr(str_pad($milliseconds, 3, '0'), 0, 3); + + return ((int) $seconds * 1000) + (int) $milliseconds; + }) + + + $machineRecords + ->where('pump_machine_name', $machineName) + ->sum(function ($record) { + + $value = (string) ($record->pump_expected_time ?? '0'); + + [$seconds, $milliseconds] = array_pad( + explode('.', $value, 2), + 2, + '0' + ); + + $milliseconds = substr(str_pad($milliseconds, 3, '0'), 0, 3); + + return ((int) $seconds * 1000) + (int) $milliseconds; + }) + + + $machineRecords + ->where('name_plate_machine_name', $machineName) + ->sum(function ($record) { + + $value = (string) ($record->name_plate_expected_time ?? '0'); + + [$seconds, $milliseconds] = array_pad( + explode('.', $value, 2), + 2, + '0' + ); + + $milliseconds = substr(str_pad($milliseconds, 3, '0'), 0, 3); + + return ((int) $seconds * 1000) + (int) $milliseconds; + }) + + + $machineRecords + ->where('motor_machine_name', $machineName) + ->sum(function ($record) { + + $value = (string) ($record->man_mark_expected_time ?? '0'); + + [$seconds, $milliseconds] = array_pad( + explode('.', $value, 2), + 2, + '0' + ); + + $milliseconds = substr(str_pad($milliseconds, 3, '0'), 0, 3); + + return ((int) $seconds * 1000) + (int) $milliseconds; + }); - // Keep only 3 decimal places - $totalExpectedMinutes = round($totalExpectedMinutes, 3); +// Convert total milliseconds to total seconds +$totalExpectedSeconds = $totalExpectedMilliseconds / 1000; - // Convert total minutes into hours + minutes - $totalHours = floor($totalExpectedMinutes / 60); - - $totalMinutes = floor($totalExpectedMinutes % 60); - - $totalLaserOnHours = "{$totalHours} hr {$totalMinutes} min"; +// Convert seconds to minutes +$totalExpectedMinutes = $totalExpectedSeconds / 60; - // Laser OFF - $totalLaserOnHoursValue = $totalExpectedMinutes / 60; +// Convert minutes to hours + minutes +$totalHours = floor($totalExpectedMinutes / 60); - $totalLaserOffHoursValue = 22.5 - $totalLaserOnHoursValue; +$totalMinutes = floor($totalExpectedMinutes % 60); - $totalLaserOffHoursValue = max(0, $totalLaserOffHoursValue); +$totalLaserOnHours = "{$totalHours} hr {$totalMinutes} min"; - $offHours = floor($totalLaserOffHoursValue); - $offMinutes = floor(($totalLaserOffHoursValue - $offHours) * 60); +// Laser OFF +$totalLaserOnHoursValue = $totalExpectedMinutes / 60; - $totalLaserOffHours = "{$offHours} hr {$offMinutes} min"; +$totalLaserOffHoursValue = max(0, 22.5 - $totalLaserOnHoursValue); + +$offHours = floor($totalLaserOffHoursValue); + +$offMinutes = floor( + ($totalLaserOffHoursValue - $offHours) * 60 +); + +$totalLaserOffHours = "{$offHours} hr {$offMinutes} min"; $tableData[] = [ 'no' => $no++,