From 3a7104513c55dc4a60aefac16321544c1a183e96 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 11 May 2026 14:55:40 +0530 Subject: [PATCH] Changed logic for sending invoice report mail for aginst based on plants --- app/Console/Commands/SendInvoiceReport.php | 90 +++++++++++++++++++++- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/SendInvoiceReport.php b/app/Console/Commands/SendInvoiceReport.php index 8e1f6aa..6b08157 100644 --- a/app/Console/Commands/SendInvoiceReport.php +++ b/app/Console/Commands/SendInvoiceReport.php @@ -91,6 +91,7 @@ class SendInvoiceReport extends Command $serialTableData[] = [ 'no' => $no, + 'plant_id' => $plantId, 'plant' => $plantName, 'totalInvoice' => $totalSerialCount, 'scannedInvoice' => $scannedSerialCount, @@ -127,6 +128,7 @@ class SendInvoiceReport extends Command $materialTableData[] = [ 'no' => $no, + 'plant_id' => $plantId, 'plant' => $plantName, 'totalInvoice' => $totalMatCount, 'scannedInvoice' => $scannedMatCount, @@ -163,6 +165,7 @@ class SendInvoiceReport extends Command $bundleTableData[] = [ 'no' => $no, + 'plant_id' => $plantId, 'plant' => $plantName, 'totalInvoice' => $totalBundleCount, 'scannedInvoice' => $scannedBundleCount, @@ -206,7 +209,26 @@ class SendInvoiceReport extends Command continue; } - \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, [], [], $schedule)); + if ($rule->plant == 0) { + $filteredSerialData = $serialTableData; + + } else { + $filteredSerialData = collect($serialTableData) + ->where('plant_id', $rule->plant) + ->values() + ->toArray(); + } + + \Mail::to($toEmails) + ->cc($ccEmails) + ->send(new test( + $filteredSerialData, + [], + [], + $schedule + )); + + // \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, [], [], $schedule)); $this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : '')); } @@ -240,7 +262,35 @@ class SendInvoiceReport extends Command continue; } - \Mail::to($toEmails)->cc($ccEmails)->send(new test([], $materialTableData, $bundleTableData, $schedule)); + // FILTER DATA + if ($rule->plant == 0) { + + $filteredMaterialData = $materialTableData; + $filteredBundleData = $bundleTableData; + + } else { + + $filteredMaterialData = collect($materialTableData) + ->where('plant_id', $rule->plant) + ->values() + ->toArray(); + + $filteredBundleData = collect($bundleTableData) + ->where('plant_id', $rule->plant) + ->values() + ->toArray(); + } + + \Mail::to($toEmails) + ->cc($ccEmails) + ->send(new test( + [], + $filteredMaterialData, + $filteredBundleData, + $schedule + )); + + // \Mail::to($toEmails)->cc($ccEmails)->send(new test([], $materialTableData, $bundleTableData, $schedule)); $this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : '')); } @@ -275,7 +325,41 @@ class SendInvoiceReport extends Command continue; } - \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule)); + // FILTER DATA + if ($rule->plant == 0) { + + $filteredSerialData = $serialTableData; + $filteredMaterialData = $materialTableData; + $filteredBundleData = $bundleTableData; + + } else { + + $filteredSerialData = collect($serialTableData) + ->where('plant_id', $rule->plant) + ->values() + ->toArray(); + + $filteredMaterialData = collect($materialTableData) + ->where('plant_id', $rule->plant) + ->values() + ->toArray(); + + $filteredBundleData = collect($bundleTableData) + ->where('plant_id', $rule->plant) + ->values() + ->toArray(); + } + + \Mail::to($toEmails) + ->cc($ccEmails) + ->send(new test( + $filteredSerialData, + $filteredMaterialData, + $filteredBundleData, + $schedule + )); + + // \Mail::to($toEmails)->cc($ccEmails)->send(new test($serialTableData, $materialTableData, $bundleTableData, $schedule)); $this->info("Mail sent for rule ID {$rule->id} → To: ".implode(', ', $toEmails).($ccEmails ? ' | CC: '.implode(', ', $ccEmails) : '')); } -- 2.49.1