changed logic in process order report
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
This commit is contained in:
@@ -86,6 +86,28 @@ class SendProcessOrderReport extends Command
|
|||||||
// ->with(['line', 'item'])
|
// ->with(['line', 'item'])
|
||||||
// ->get();
|
// ->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()
|
$latestRecords = ProcessOrder::query()
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plant->id)
|
||||||
->whereBetween('created_at', [$startDate, $endDate])
|
->whereBetween('created_at', [$startDate, $endDate])
|
||||||
@@ -102,6 +124,22 @@ class SendProcessOrderReport extends Command
|
|||||||
|
|
||||||
foreach ($latestRecords as $order) {
|
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[] = [
|
$tableData[] = [
|
||||||
'no' => $no++,
|
'no' => $no++,
|
||||||
'plant' => $plant->name,
|
'plant' => $plant->name,
|
||||||
@@ -114,79 +152,82 @@ class SendProcessOrderReport extends Command
|
|||||||
'recQuan' => $receivedSummary[$order->process_order] ?? 0,
|
'recQuan' => $receivedSummary[$order->process_order] ?? 0,
|
||||||
'scrapQuan' => $order->scrap_quantity,
|
'scrapQuan' => $order->scrap_quantity,
|
||||||
'sfgNo' => $order->sfg_number,
|
'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 . '%',
|
'NotOkPerc' => $notOkPerc . '%',
|
||||||
'OkPerc' => $okPerc . '%',
|
'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;
|
$contentVars = $mail->content()->with;
|
||||||
|
|
||||||
foreach ($mailRules as $rule)
|
foreach ($mailRules as $rule)
|
||||||
|
|||||||
Reference in New Issue
Block a user