Added mail logic for to and cc for quality validation #754

Merged
jothi merged 1 commits from ranjith-dev into master 2026-06-15 03:54:09 +00:00

View File

@@ -3529,14 +3529,80 @@ class QualityValidationResource extends Resource
$mPlantName = $mailData['plant_name']; $mPlantName = $mailData['plant_name'];
$emails = $mailData['emails']; $emails = $mailData['emails'];
$ccEmails = $mailData['cc_emails'] ?? [];
$mUserName = Filament::auth()->user()->name; $mUserName = Filament::auth()->user()->name;
if (! empty($emails)) { // if (! empty($emails)) {
// Mail::to($emails)->send(new InvalidSerialMail($serNo, $invoiceNumber, $mPlantName, $mInvoiceType)); // if (is_array($emails)) {
Mail::to($emails)->send( // $emailList = collect($emails)
new InvalidQualityMail($state, $mPorder, $mPlantName, $mLinePart, $mUserName, $mExpectedValue, 'InvalidPartNumber') // ->flatMap(fn ($email) => explode(',', $email))
); // ->map(fn ($email) => trim($email))
} else { // ->filter()
// ->toArray();
// } else {
// $emailList = array_map('trim', explode(',', $emails));
// }
// $ccList = [];
// if (!empty($cc_emails)) {
// if (is_array($cc_emails)) {
// $ccList = collect($cc_emails)
// ->flatMap(fn ($email) => explode(',', $email))
// ->map(fn ($email) => trim($email))
// ->filter()
// ->toArray();
// } else {
// $ccList = collect(explode(',', $cc_emails))
// ->map(fn ($email) => trim($email))
// ->filter()
// ->toArray();
// }
// }
// Mail::to($emailList)
// ->cc($ccList)
// ->send(
// new InvalidQualityMail(
// $state,
// $mPorder,
// $mPlantName,
// $mLinePart,
// $mUserName,
// $mExpectedValue,
// 'InvalidPartNumber'
// )
// );
// }
if (!empty($emails)) {
$emailList = collect(is_array($emails) ? $emails : explode(',', $emails))
->flatMap(fn ($email) => explode(',', $email))
->map(fn ($email) => trim($email))
->filter()
->toArray();
$ccList = collect(is_array($ccEmails) ? $ccEmails : explode(',', $ccEmails))
->flatMap(fn ($email) => explode(',', $email))
->map(fn ($email) => trim($email))
->filter()
->toArray();
Mail::to($emailList)
->cc($ccList)
->send(
new InvalidQualityMail(
$state,
$mPorder,
$mPlantName,
$mLinePart,
$mUserName,
$mExpectedValue,
'InvalidPartNumber'
)
);
}
else {
\Log::warning("No recipients found for plant {$mPlantName}, module Serial, rule invalid_serial."); \Log::warning("No recipients found for plant {$mPlantName}, module Serial, rule invalid_serial.");
} }
$set('part_validation1', null); $set('part_validation1', null);
@@ -3978,6 +4044,7 @@ class QualityValidationResource extends Resource
->where('module', 'QualityValidation') ->where('module', 'QualityValidation')
->where('rule_name', 'QualityMail') ->where('rule_name', 'QualityMail')
->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', '')) ->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', ''))
// ->get()
->pluck('email') ->pluck('email')
->toArray(); ->toArray();
@@ -3995,13 +4062,16 @@ class QualityValidationResource extends Resource
->where('module', 'QualityValidation') ->where('module', 'QualityValidation')
->where('rule_name', 'QualityMail') ->where('rule_name', 'QualityMail')
->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', '')) ->where(fn ($q) => $q->whereNull('schedule_type')->orWhere('schedule_type', ''))
->pluck('email') ->get(['email', 'cc_emails']);
->toArray(); // ->pluck('email')
// ->toArray();
return [ return [
'plant_id' => $plantId, 'plant_id' => $plantId,
'plant_name' => $mPlantName, 'plant_name' => $mPlantName,
'emails' => $emails, 'emails' => $emails->pluck('email')->filter()->toArray(),
'cc_emails' => $emails->pluck('cc_emails')->filter()->toArray(),
// 'emails' => $emails,
]; ];
} }