From 4d63100a0e5872af7198f92d2c092a41da91e69d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 17 Nov 2026 15:58:42 +0530 Subject: [PATCH 1/2] changed logic in process order report --- .../Commands/SendProcessOrderReport.php | 175 +++++++++++------- 1 file changed, 108 insertions(+), 67 deletions(-) diff --git a/app/Console/Commands/SendProcessOrderReport.php b/app/Console/Commands/SendProcessOrderReport.php index c8117b4f..f422c2b7 100644 --- a/app/Console/Commands/SendProcessOrderReport.php +++ b/app/Console/Commands/SendProcessOrderReport.php @@ -86,6 +86,28 @@ class SendProcessOrderReport extends Command // ->with(['line', 'item']) // ->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'); + + // OK and Not OK counts grouped by process order + $statusCounts = DB::table('characteristic_values') + ->where('plant_id', $plant->id) + ->whereBetween('created_at', [$startDate, $endDate]) + ->selectRaw(" + process_order, + SUM(CASE WHEN status = 'NotOk' THEN 1 ELSE 0 END) AS notok_count, + SUM(CASE WHEN status = 'Ok' THEN 1 ELSE 0 END) AS ok_count + ") + ->groupBy('process_order') + ->get() + ->keyBy('process_order'); + $latestRecords = ProcessOrder::query() ->where('plant_id', $plant->id) ->whereBetween('created_at', [$startDate, $endDate]) @@ -102,6 +124,22 @@ class SendProcessOrderReport extends Command foreach ($latestRecords as $order) { + $processOrder = $order->process_order; + + $total = $processOrderTotals[$processOrder]->total_count ?? 0; + + $notOk = $statusCounts[$processOrder]->notok_count ?? 0; + $ok = $statusCounts[$processOrder]->ok_count ?? 0; + + // Calculate percentages + $notOkPerc = $total > 0 + ? round(($notOk / $total) * 100, 2) + : 0; + + $okPerc = $total > 0 + ? round(($ok / $total) * 100, 2) + : 0; + $tableData[] = [ 'no' => $no++, 'plant' => $plant->name, @@ -114,79 +152,82 @@ class SendProcessOrderReport extends Command 'recQuan' => $receivedSummary[$order->process_order] ?? 0, 'scrapQuan' => $order->scrap_quantity, 'sfgNo' => $order->sfg_number, - ]; - } - } - - $noNotOk = 1; - - $NotOkData = []; - - foreach ($plants as $plant) { - - $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'); - - $statusCounts = DB::table('characteristic_values') - ->where('plant_id', $plant->id) - ->whereBetween('created_at', [$startDate, $endDate]) - ->selectRaw(" - process_order, - SUM(CASE WHEN status = 'NotOk' THEN 1 ELSE 0 END) AS notok_count, - SUM(CASE WHEN status = 'Ok' THEN 1 ELSE 0 END) AS ok_count - ") - ->groupBy('process_order') - ->get() - ->keyBy('process_order'); - - $latestRecords = CharacteristicValue::query() - ->where('plant_id', $plant->id) - ->whereBetween('created_at', [$startDate, $endDate]) - ->orderBy('process_order') - ->orderByDesc('created_at') - ->distinct('process_order') - ->with(['line', 'item']) - ->get(); - - foreach ($latestRecords as $order) { - - $processOrder = $order->process_order; - - $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) - : 0; - - $okPerc = $total > 0 - ? round(($ok / $total) * 100, 2) - : 0; - - - $NotOkData[] = [ - 'no' => $noNotOk++, - 'plant' => $plant->name, - 'line' => $order->line?->name ?? '-', - 'machineName' => $order->machine_name, - 'item' => $order->item?->code ?? '-', - 'processOrder' => $order->process_order, 'NotOkPerc' => $notOkPerc . '%', 'OkPerc' => $okPerc . '%', ]; } } - $mail = new ProcessOrderMail($scheduleType, $tableData, $NotOkData); + // $noNotOk = 1; + + // $NotOkData = []; + + // foreach ($plants as $plant) { + + // $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'); + + // $statusCounts = DB::table('characteristic_values') + // ->where('plant_id', $plant->id) + // ->whereBetween('created_at', [$startDate, $endDate]) + // ->selectRaw(" + // process_order, + // SUM(CASE WHEN status = 'NotOk' THEN 1 ELSE 0 END) AS notok_count, + // SUM(CASE WHEN status = 'Ok' THEN 1 ELSE 0 END) AS ok_count + // ") + // ->groupBy('process_order') + // ->get() + // ->keyBy('process_order'); + + // $latestRecords = CharacteristicValue::query() + // ->where('plant_id', $plant->id) + // ->whereBetween('created_at', [$startDate, $endDate]) + // ->orderBy('process_order') + // ->orderByDesc('created_at') + // ->distinct('process_order') + // ->with(['line', 'item']) + // ->get(); + + // foreach ($latestRecords as $order) { + + // $processOrder = $order->process_order; + + // $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) + // : 0; + + // $okPerc = $total > 0 + // ? round(($ok / $total) * 100, 2) + // : 0; + + + // $NotOkData[] = [ + // 'no' => $noNotOk++, + // 'plant' => $plant->name, + // 'line' => $order->line?->name ?? '-', + // 'machineName' => $order->machine_name, + // 'item' => $order->item?->code ?? '-', + // 'processOrder' => $order->process_order, + // 'NotOkPerc' => $notOkPerc . '%', + // 'OkPerc' => $okPerc . '%', + // ]; + // } + // } + + // $mail = new ProcessOrderMail($scheduleType, $tableData, $NotOkData); + $mail = new ProcessOrderMail($scheduleType, $tableData); $contentVars = $mail->content()->with; foreach ($mailRules as $rule) -- 2.49.1 From 8d2aacee80697f4cafe8dc292b115fcfd6c8b535 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 17 Nov 2026 15:59:36 +0530 Subject: [PATCH 2/2] Changed logic in process order mail report page --- app/Mail/ProcessOrderMail.php | 12 +++++++++--- resources/views/mail/process_order_report.blade.php | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Mail/ProcessOrderMail.php b/app/Mail/ProcessOrderMail.php index 4a401b9b..51181122 100644 --- a/app/Mail/ProcessOrderMail.php +++ b/app/Mail/ProcessOrderMail.php @@ -23,11 +23,17 @@ class ProcessOrderMail extends Mailable /** * Create a new message instance. */ - public function __construct($scheduleType,$tableData = [], $NotOkData) + // public function __construct($scheduleType,$tableData = [], $NotOkData) + // { + // $this->scheduleType = $scheduleType; + // $this->tableData = $tableData ?? []; + // $this->NotOkData = $NotOkData ?? []; + // } + + public function __construct($scheduleType,$tableData = []) { $this->scheduleType = $scheduleType; $this->tableData = $tableData ?? []; - $this->NotOkData = $NotOkData ?? []; } /** @@ -62,7 +68,7 @@ class ProcessOrderMail extends Mailable 'company' => "CRI Digital Manufacturing Solutions", 'greeting' => $greeting, 'tableData' => $this->tableData, - 'NotOkData' => $this->NotOkData, + // 'NotOkData' => $this->NotOkData, 'wishes' => "Thanks & Regards,
CRI Digital Manufacturing Solutions" ], ); diff --git a/resources/views/mail/process_order_report.blade.php b/resources/views/mail/process_order_report.blade.php index c93f34ae..90daadb7 100644 --- a/resources/views/mail/process_order_report.blade.php +++ b/resources/views/mail/process_order_report.blade.php @@ -37,6 +37,8 @@ Total Quantity Scrap Quantity SFG Number + Not Ok Status (%) + Ok Status (%) @@ -52,12 +54,14 @@ {{ $row['recQuan'] }} {{ $row['scrapQuan'] }} {{ $row['sfgNo'] }} + {{ $row['NotOkPerc'] }} + {{ $row['OkPerc'] }} @endforeach
-

Process Order Not Ok Report

+{{--

Process Order Not Ok Report

@@ -85,7 +89,7 @@ @endforeach -
+ --}}

{!! $wishes !!}

-- 2.49.1