diff --git a/app/Console/Commands/SendProductionReport.php b/app/Console/Commands/SendProductionReport.php index 965ae89f..0fc7d580 100644 --- a/app/Console/Commands/SendProductionReport.php +++ b/app/Console/Commands/SendProductionReport.php @@ -33,13 +33,10 @@ class SendProductionReport extends Command */ public function handle() { - // ini_set('max_execution_time', 0); // disable limit - // set_time_limit(0); $scheduleType = $this->argument('schedule_type'); - $plantId = (int) $this->argument('plant'); // cast to int for safety + $plantId = (int) $this->argument('plant'); - // Fetch mail rules based on schedule type $mailRules = \App\Models\AlertMailRule::where('module', 'ProductionQuantities') ->where('rule_name', 'ProductionMail') ->where('schedule_type', $scheduleType) @@ -190,53 +187,11 @@ class SendProductionReport extends Command $dailyTarget = round($dailyTarget, 2); - $leaveDatesString = ProductionPlan::where('plant_id', $plant->id) - ->where('line_id', $line->id) - ->whereMonth('created_at', $month) - ->whereYear('created_at', $year) - ->value('leave_dates'); - - $leaveDates = $leaveDatesString ? explode(',', $leaveDatesString) : []; - - $monthStart = $startDate->copy()->startOfMonth(); - $yesterday = $startDate->copy()->subDay(); - - $completedDays = 0; - $currentDate = $monthStart->copy(); - - while ($currentDate->lte($yesterday)) { - - if (!in_array($currentDate->format('Y-m-d'), $leaveDates)) { - $completedDays++; - } - - $currentDate->addDay(); - } - - $expectedTillYesterday = $dailyTarget * $completedDays; - - if (strtolower($line->type) == 'fg line') { - - $producedTillYesterday = \App\Models\QualityValidation::where('plant_id', $plant->id) - ->where('line_id', $line->id) - ->whereMonth('created_at', $month) - ->whereYear('created_at', $year) - ->where('created_at', '<', $startDate) - ->count(); - - } else { - - $producedTillYesterday = ProductionQuantity::where('plant_id', $plant->id) - ->where('line_id', $line->id) - ->whereMonth('created_at', $month) - ->whereYear('created_at', $year) - ->where('created_at', '<', $startDate) - ->count(); - } - - $previousRemaining = max(0, $expectedTillYesterday - $producedTillYesterday); - - $totalTargetQuantity = round($dailyTarget + $previousRemaining, 2); + // $leaveDatesString = ProductionPlan::where('plant_id', $plant->id) + // ->where('line_id', $line->id) + // ->whereMonth('created_at', $month) + // ->whereYear('created_at', $year) + // ->value('leave_dates'); $itemIds = ProductionPlan::where('plant_id', $plant->id) ->where('line_id', $line->id) @@ -245,15 +200,70 @@ class SendProductionReport extends Command ->distinct() ->pluck('item_id'); - $totalHourlyQuantity = Item::whereIn('id', $itemIds) - ->sum('hourly_quantity'); + // $leaveDates = $leaveDatesString ? explode(',', $leaveDatesString) : []; - $capacityQuan = $totalHourlyQuantity * 22.5; + // $monthStart = $startDate->copy()->startOfMonth(); + // $monthStart = $startDate->copy()->startOfMonth()->setTime(8, 0, 0); + + // $yesterday = $startDate->copy()->subDay()->setTime(8, 0, 0); + + // $completedDays = 0; + // $currentDate = $monthStart->copy(); + + // while ($currentDate->lte($yesterday)) { + + // if (!in_array($currentDate->format('Y-m-d'), $leaveDates)) { + // $completedDays++; + // } + + // $currentDate->addDay(); + // } + + // $expectedTillYesterday = $dailyTarget * $completedDays; + + // if (strtolower($line->type) == 'fg line') { + + // $producedTillYesterday = \App\Models\QualityValidation::where('plant_id', $plant->id) + // ->where('line_id', $line->id) + // ->whereIn('item_id', $itemIds) + // ->whereMonth('created_at', $month) + // ->whereYear('created_at', $year) + // ->where('created_at', '<', $startDate) + // ->count(); + + // } else { + + // $producedTillYesterday = ProductionQuantity::where('plant_id', $plant->id) + // ->where('line_id', $line->id) + // ->whereIn('item_id', $itemIds) + // ->whereMonth('created_at', $month) + // ->whereYear('created_at', $year) + // ->where('created_at', '<', $startDate) + // ->count(); + // } + + // $previousRemaining = max(0, $expectedTillYesterday - $producedTillYesterday); + + // $totalTargetQuantity = round($dailyTarget + $previousRemaining, 2); + + $totalTargetQuantity = round($dailyTarget, 2); + + // $totalHourlyQuantity = Item::whereIn('id', $itemIds) + // ->sum('hourly_quantity'); + + // $capacityQuan = $totalHourlyQuantity * 22.5; if (strtolower($line->type) == 'fg line') { $productionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id) ->where('line_id', $line->id) + ->whereIn('item_id', $itemIds) + ->whereBetween('created_at', [$startDate, $endDate]) + ->count(); + + $nonPlannedproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id) + ->where('line_id', $line->id) + ->whereNotIn('item_id', $itemIds) ->whereBetween('created_at', [$startDate, $endDate]) ->count(); @@ -286,6 +296,7 @@ class SendProductionReport extends Command $dayproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id) ->where('line_id', $line->id) + ->whereIn('item_id', $itemIds) ->whereBetween('created_at', [ $startDate->copy()->setTime(8, 0, 0), $startDate->copy()->setTime(19, 30, 0), @@ -294,6 +305,7 @@ class SendProductionReport extends Command $nightproductionQuantity = \App\Models\QualityValidation::where('plant_id', $plant->id) ->where('line_id', $line->id) + ->whereIn('item_id', $itemIds) ->whereBetween('created_at', [ $startDate->copy()->setTime(19, 30, 0), $endDate->copy()->setTime(8, 0, 0), @@ -331,7 +343,7 @@ class SendProductionReport extends Command 'plant' => $plant->name, 'type' => $line->type, 'line' => $line->name, - 'capacityQuantity' => floor($capacityQuan), + // 'capacityQuantity' => floor($capacityQuan), 'dayShiftPlanQuantity' => floor($dayShiftPlanQuan), 'dayShiftActualQuantity' => floor($dayproductionQuantity), 'dayShiftEfficiency' => floor($dayShiftEfficiency) . '%', @@ -342,6 +354,7 @@ class SendProductionReport extends Command 'productionQuantity' => $productionQuantity, 'uom' => $line->uom, 'efficiency' => $efficiency . '%', + 'nonPlannedQuantity' => $nonPlannedproductionQuantity, ]; } }