quality issue solved for empty records in trigger mail
Some checks are pending
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Waiting to run
Gemini PR Review / Gemini PR Review (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Waiting to run
Laravel Larastan / larastan (pull_request) Waiting to run
Laravel Pint / pint (pull_request) Waiting to run
Some checks are pending
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Waiting to run
Gemini PR Review / Gemini PR Review (pull_request) Waiting to run
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Waiting to run
Laravel Larastan / larastan (pull_request) Waiting to run
Laravel Pint / pint (pull_request) Waiting to run
This commit is contained in:
@@ -42,7 +42,6 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
|
|
||||||
public $wfId;
|
public $wfId;
|
||||||
|
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$this->info('Approval mail job started');
|
$this->info('Approval mail job started');
|
||||||
@@ -74,165 +73,163 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
});
|
});
|
||||||
|
|
||||||
if ($records->isEmpty()) {
|
if ($records->isEmpty()) {
|
||||||
$this->info('No pending approvals');
|
$this->info('No characteristics pending approvals');
|
||||||
return;
|
}else{
|
||||||
}
|
$grouped = $records->groupBy(function ($item) {
|
||||||
|
$this->wfId = $item->work_flow_id;
|
||||||
|
return $item->plant_id . '|' . $item->machine_id . '|' . $item->aufnr . '|' . $item->work_flow_id;
|
||||||
|
});
|
||||||
|
|
||||||
$grouped = $records->groupBy(function ($item) {
|
$pendingApprovers = RequestCharacteristic::where('work_flow_id', $this->wfId)->latest()->first();
|
||||||
$this->wfId = $item->work_flow_id;
|
|
||||||
return $item->plant_id . '|' . $item->machine_id . '|' . $item->aufnr . '|' . $item->work_flow_id;
|
|
||||||
});
|
|
||||||
|
|
||||||
$pendingApprovers = RequestCharacteristic::where('work_flow_id', $this->wfId)->latest()->first();
|
$this->info($pendingApprovers->approver_status1, $pendingApprovers->approver_status2);
|
||||||
|
|
||||||
$this->info($pendingApprovers->approver_status1, $pendingApprovers->approver_status2);
|
|
||||||
|
|
||||||
|
|
||||||
$approverNameFromMaster = null;
|
$approverNameFromMaster = null;
|
||||||
if ($pendingApprovers && $pendingApprovers->characteristic_approver_master_id) {
|
if ($pendingApprovers && $pendingApprovers->characteristic_approver_master_id) {
|
||||||
$approverNameFromMaster = CharacteristicApproverMaster::find($pendingApprovers->characteristic_approver_master_id);
|
$approverNameFromMaster = CharacteristicApproverMaster::find($pendingApprovers->characteristic_approver_master_id);
|
||||||
}
|
|
||||||
|
|
||||||
$rows = [];
|
|
||||||
|
|
||||||
foreach ($grouped as $groupRecords) {
|
|
||||||
|
|
||||||
$first = $groupRecords->first();
|
|
||||||
|
|
||||||
$approver = CharacteristicApproverMaster::where('plant_id', $first->plant_id)
|
|
||||||
->where('machine_id', $first->machine_id)
|
|
||||||
->where('id', $first->characteristic_approver_master_id)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (!$approver) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$characteristics = $groupRecords->map(fn ($r) => [
|
$rows = [];
|
||||||
'work_flow_id' => $r->work_flow_id,
|
|
||||||
'characteristic_name' => $r->characteristic_name,
|
|
||||||
'current_value' => $r->current_value,
|
|
||||||
'update_value' => $r->update_value,
|
|
||||||
])->toArray();
|
|
||||||
|
|
||||||
$level = null;
|
foreach ($grouped as $groupRecords) {
|
||||||
$mail = null;
|
|
||||||
$name = null;
|
|
||||||
$updateData = [];
|
|
||||||
$now = Carbon::now();
|
|
||||||
|
|
||||||
// --- FIRST MAIL ---
|
$first = $groupRecords->first();
|
||||||
if (is_null($first->mail_status)){
|
|
||||||
$level = 1;
|
|
||||||
$mail = $approver->mail1;
|
|
||||||
$name = $approver->name1;
|
|
||||||
|
|
||||||
$updateData['mail_status'] = 'Sent';
|
$approver = CharacteristicApproverMaster::where('plant_id', $first->plant_id)
|
||||||
|
->where('machine_id', $first->machine_id)
|
||||||
|
->where('id', $first->characteristic_approver_master_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
if ($approver->duration1 > 0)
|
if (!$approver) {
|
||||||
{
|
continue;
|
||||||
|
|
||||||
$duration = number_format((float)$approver->duration1, 2, '.', '');
|
|
||||||
[$hours, $minutes] = explode('.', $duration);
|
|
||||||
|
|
||||||
$totalMinutes = ((int)$hours * 60) + (int)$minutes;
|
|
||||||
|
|
||||||
$updateData['trigger_at'] = $now
|
|
||||||
->copy()
|
|
||||||
->addMinutes($totalMinutes)
|
|
||||||
->startOfMinute();
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
$characteristics = $groupRecords->map(fn ($r) => [
|
||||||
|
'work_flow_id' => $r->work_flow_id,
|
||||||
|
'characteristic_name' => $r->characteristic_name,
|
||||||
|
'current_value' => $r->current_value,
|
||||||
|
'update_value' => $r->update_value,
|
||||||
|
])->toArray();
|
||||||
|
|
||||||
|
$level = null;
|
||||||
|
$mail = null;
|
||||||
|
$name = null;
|
||||||
|
$updateData = [];
|
||||||
|
$now = Carbon::now();
|
||||||
|
|
||||||
|
// --- FIRST MAIL ---
|
||||||
|
if (is_null($first->mail_status)){
|
||||||
|
$level = 1;
|
||||||
|
$mail = $approver->mail1;
|
||||||
|
$name = $approver->name1;
|
||||||
|
|
||||||
|
$updateData['mail_status'] = 'Sent';
|
||||||
|
|
||||||
|
if ($approver->duration1 > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
$duration = number_format((float)$approver->duration1, 2, '.', '');
|
||||||
|
[$hours, $minutes] = explode('.', $duration);
|
||||||
|
|
||||||
|
$totalMinutes = ((int)$hours * 60) + (int)$minutes;
|
||||||
|
|
||||||
|
$updateData['trigger_at'] = $now
|
||||||
|
->copy()
|
||||||
|
->addMinutes($totalMinutes)
|
||||||
|
->startOfMinute();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$updateData['trigger_at'] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- SECOND MAIL ---
|
||||||
|
elseif (
|
||||||
|
$first->mail_status == 'Sent' &&
|
||||||
|
(is_null($first->approver_status1) || $first->approver_status1 == 'Hold') &&
|
||||||
|
$first->trigger_at &&
|
||||||
|
\Carbon\Carbon::parse($first->trigger_at)->lte($now)
|
||||||
|
) {
|
||||||
|
|
||||||
|
$this->info(
|
||||||
|
"mail_status: {$first->mail_status}, ".
|
||||||
|
"approver_status1: {$first->approver_status1}, ".
|
||||||
|
"trigger_at: {$first->trigger_at}, ".
|
||||||
|
"now: {$now}"
|
||||||
|
);
|
||||||
|
|
||||||
|
$level = 2;
|
||||||
|
$mail = $approver->mail2;
|
||||||
|
$name = $approver->name2;
|
||||||
|
|
||||||
|
if ($approver->duration2 > 0) {
|
||||||
|
|
||||||
|
$duration = number_format((float)$approver->duration2, 2, '.', '');
|
||||||
|
[$hours, $minutes] = explode('.', $duration);
|
||||||
|
|
||||||
|
$totalMinutes = ((int)$hours * 60) + (int)$minutes;
|
||||||
|
|
||||||
|
$updateData['trigger_at'] = $now->copy()->addMinutes($totalMinutes);
|
||||||
|
} else {
|
||||||
|
$updateData['trigger_at'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$updateData['mail_status'] = 'Sent-Mail2';
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- THIRD MAIL ---
|
||||||
|
elseif (
|
||||||
|
$first->mail_status == 'Sent-Mail2' &&
|
||||||
|
(is_null($first->approver_status1) || $first->approver_status1 == 'Hold') &&
|
||||||
|
(is_null($first->approver_status2) || $first->approver_status2 == 'Hold') &&
|
||||||
|
$first->trigger_at &&
|
||||||
|
\Carbon\Carbon::parse($first->trigger_at)->lte($now)
|
||||||
|
) {
|
||||||
|
$level = 3;
|
||||||
|
$mail = $approver->mail3;
|
||||||
|
$name = $approver->name3;
|
||||||
|
|
||||||
$updateData['trigger_at'] = null;
|
$updateData['trigger_at'] = null;
|
||||||
|
$updateData['mail_status'] = 'Sent-Mail3';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// --- SECOND MAIL ---
|
if (!$level || !$mail) {
|
||||||
elseif (
|
continue;
|
||||||
$first->mail_status == 'Sent' &&
|
}
|
||||||
(is_null($first->approver_status1) || $first->approver_status1 == 'Hold') &&
|
|
||||||
$first->trigger_at &&
|
|
||||||
\Carbon\Carbon::parse($first->trigger_at)->lte($now)
|
|
||||||
) {
|
|
||||||
|
|
||||||
$this->info(
|
$pdfPath = 'uploads/LaserDocs/' . $first->work_flow_id . '.pdf';
|
||||||
"mail_status: {$first->mail_status}, ".
|
|
||||||
"approver_status1: {$first->approver_status1}, ".
|
$subjectLine = 'Characteristic Approval Mail';
|
||||||
"trigger_at: {$first->trigger_at}, ".
|
|
||||||
"now: {$now}"
|
Mail::to($mail)->send(
|
||||||
|
new CharacteristicApprovalMail(
|
||||||
|
$first,
|
||||||
|
$name,
|
||||||
|
$level,
|
||||||
|
$pdfPath,
|
||||||
|
$pendingApprovers,
|
||||||
|
$approverNameFromMaster,
|
||||||
|
$subjectLine,
|
||||||
|
$characteristics
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$level = 2;
|
RequestCharacteristic::whereIn('id', $groupRecords->pluck('id'))
|
||||||
$mail = $approver->mail2;
|
->update($updateData);
|
||||||
$name = $approver->name2;
|
|
||||||
|
|
||||||
if ($approver->duration2 > 0) {
|
$rows[] = [
|
||||||
|
$first->id,
|
||||||
$duration = number_format((float)$approver->duration2, 2, '.', '');
|
$first->plant_id,
|
||||||
[$hours, $minutes] = explode('.', $duration);
|
$first->machine_id,
|
||||||
|
"Level $level",
|
||||||
$totalMinutes = ((int)$hours * 60) + (int)$minutes;
|
$mail,
|
||||||
|
'SENT'
|
||||||
$updateData['trigger_at'] = $now->copy()->addMinutes($totalMinutes);
|
];
|
||||||
} else {
|
|
||||||
$updateData['trigger_at'] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$updateData['mail_status'] = 'Sent-Mail2';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- THIRD MAIL ---
|
|
||||||
elseif (
|
|
||||||
$first->mail_status == 'Sent-Mail2' &&
|
|
||||||
(is_null($first->approver_status1) || $first->approver_status1 == 'Hold') &&
|
|
||||||
(is_null($first->approver_status2) || $first->approver_status2 == 'Hold') &&
|
|
||||||
$first->trigger_at &&
|
|
||||||
\Carbon\Carbon::parse($first->trigger_at)->lte($now)
|
|
||||||
) {
|
|
||||||
$level = 3;
|
|
||||||
$mail = $approver->mail3;
|
|
||||||
$name = $approver->name3;
|
|
||||||
|
|
||||||
$updateData['trigger_at'] = null;
|
|
||||||
$updateData['mail_status'] = 'Sent-Mail3';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$level || !$mail) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pdfPath = 'uploads/LaserDocs/' . $first->work_flow_id . '.pdf';
|
|
||||||
|
|
||||||
$subjectLine = 'Characteristic Approval Mail';
|
|
||||||
|
|
||||||
Mail::to($mail)->send(
|
|
||||||
new CharacteristicApprovalMail(
|
|
||||||
$first,
|
|
||||||
$name,
|
|
||||||
$level,
|
|
||||||
$pdfPath,
|
|
||||||
$pendingApprovers,
|
|
||||||
$approverNameFromMaster,
|
|
||||||
$subjectLine,
|
|
||||||
$characteristics
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
RequestCharacteristic::whereIn('id', $groupRecords->pluck('id'))
|
|
||||||
->update($updateData);
|
|
||||||
|
|
||||||
$rows[] = [
|
|
||||||
$first->id,
|
|
||||||
$first->plant_id,
|
|
||||||
$first->machine_id,
|
|
||||||
"Level $level",
|
|
||||||
$mail,
|
|
||||||
'SENT'
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// .. Quality Mail trigger logic
|
// .. Quality Mail trigger logic
|
||||||
|
|
||||||
$qualityRecords = RequestCharacteristic::where(function ($q) {
|
$qualityRecords = RequestCharacteristic::where(function ($q) {
|
||||||
@@ -382,8 +379,8 @@ class TriggerPendingApprovalMails extends Command
|
|||||||
$pdfPath,
|
$pdfPath,
|
||||||
$pendingApprovers,
|
$pendingApprovers,
|
||||||
$approverNameFromMaster,
|
$approverNameFromMaster,
|
||||||
$subjectLine,
|
$subjectLine
|
||||||
$characteristics
|
// $characteristics
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user