From 48849bc395d6d6e4222c6e2bbcdbf7063b094e76 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 17 Nov 2026 16:48:39 +0530 Subject: [PATCH] changed logic in process order report --- .../Commands/SendProcessOrderReport.php | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/app/Console/Commands/SendProcessOrderReport.php b/app/Console/Commands/SendProcessOrderReport.php index aadb5eca..fcec2755 100644 --- a/app/Console/Commands/SendProcessOrderReport.php +++ b/app/Console/Commands/SendProcessOrderReport.php @@ -87,13 +87,13 @@ class SendProcessOrderReport extends Command // ->get(); // Total coils grouped by process order - // $processOrderTotals = DB::table('process_orders') - // ->where('plant_id', $plant->id) - // ->where('coil_number', '!=', 0) - // ->selectRaw('process_order, COUNT(*) AS total_count') - // ->groupBy('process_order') - // ->get() - // ->keyBy('process_order'); + $processOrderTotals = DB::table('process_orders') + ->where('plant_id', $plant->id) + ->where('coil_number', '!=', 0) + ->selectRaw('process_order, COUNT(*) AS total_count') + ->groupBy('process_order') + ->get() + ->keyBy('process_order'); // OK and Not OK counts grouped by process order $statusCounts = DB::table('characteristic_values') @@ -126,17 +126,20 @@ class SendProcessOrderReport extends Command $processOrder = $order->process_order; - $total = $statusCounts[$processOrder]->total_count ?? 0; + $total = $processOrderTotals[$processOrder]->total_count ?? 0; $notOk = $statusCounts[$processOrder]->notok_count ?? 0; $ok = $statusCounts[$processOrder]->ok_count ?? 0; - $notOkPerc = $total > 0 - ? round(($notOk / $total) * 100, 2) + // Calculate percentages using OK + Not OK records + $validTotal = $ok + $notOk; + + $notOkPerc = $validTotal > 0 + ? round(($notOk / $validTotal) * 100, 2) : 0; - $okPerc = $total > 0 - ? round(($ok / $total) * 100, 2) + $okPerc = $validTotal > 0 + ? round(($ok / $validTotal) * 100, 2) : 0; $tableData[] = [ -- 2.49.1