Changed logic for sending invoice report mail for aginst based on plants #582

Merged
jothi merged 1 commits from ranjith-dev into master 2026-05-11 09:25:55 +00:00

View File

@@ -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) : ''));
}