diff --git a/app/Console/Commands/TriggerPendingApprovalMails.php b/app/Console/Commands/TriggerPendingApprovalMails.php index 627135e..97d2781 100644 --- a/app/Console/Commands/TriggerPendingApprovalMails.php +++ b/app/Console/Commands/TriggerPendingApprovalMails.php @@ -38,15 +38,40 @@ class TriggerPendingApprovalMails extends Command public $pdfPath; + public $subjectLine; + + public $wfId; + public function handle() { $this->info('Approval mail job started'); - $records = RequestCharacteristic::whereNull('approver_status1') - ->whereNull('approver_status2') - ->whereNull('approver_status3') - ->get(); + // .. Characteristic Mail trigger logic + + // $records = RequestCharacteristic::whereNull('approver_status1') + // ->whereNull('approver_status2') + // ->whereNull('approver_status3') + // ->get(); + + $records = RequestCharacteristic::where(function ($q) { + $q->whereNull('approver_status1') + ->orWhere('approver_status1', 'Hold'); + }) + ->where(function ($q) { + $q->whereNull('approver_status2') + ->orWhere('approver_status2', 'Hold'); + }) + ->where(function ($q) { + $q->whereNull('approver_status3') + ->orWhere('approver_status3', 'Hold'); + }) + ->get(); + + $records = $records->filter(function ($item) { + $approver = CharacteristicApproverMaster::find($item->characteristic_approver_master_id); + return $approver && $approver->approver_type == 'Characteristic'; + }); if ($records->isEmpty()) { $this->info('No pending approvals'); @@ -54,9 +79,20 @@ class TriggerPendingApprovalMails extends Command } $grouped = $records->groupBy(function ($item) { + $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); + + + $approverNameFromMaster = null; + if ($pendingApprovers && $pendingApprovers->characteristic_approver_master_id) { + $approverNameFromMaster = CharacteristicApproverMaster::find($pendingApprovers->characteristic_approver_master_id); + } + $rows = []; foreach ($grouped as $groupRecords) { @@ -92,9 +128,6 @@ class TriggerPendingApprovalMails extends Command $name = $approver->name1; $updateData['mail_status'] = 'Sent'; - // $updateData['trigger_at'] = $approver->duration1 > 0 - // ? $now->copy()->addMinutes($approver->duration1 * 10) - // : null; if ($approver->duration1 > 0) { @@ -118,19 +151,184 @@ class TriggerPendingApprovalMails extends Command // --- SECOND MAIL --- elseif ( $first->mail_status == 'Sent' && - is_null($first->approver_status1) && + (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['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 + + $qualityRecords = RequestCharacteristic::where(function ($q) { + $q->whereNull('approver_status1') + ->orWhere('approver_status1', 'Hold'); + }) + ->where(function ($q) { + $q->whereNull('approver_status2') + ->orWhere('approver_status2', 'Hold'); + }) + ->where(function ($q) { + $q->whereNull('approver_status3') + ->orWhere('approver_status3', 'Hold'); + }) + ->get(); + + $qualityRecords = $qualityRecords->filter(function ($item) { + $approver = CharacteristicApproverMaster::find($item->characteristic_approver_master_id); + return $approver && $approver->approver_type == 'Quality'; + }); + + if ($qualityRecords->isEmpty()) { + $this->info('No quality pending approvals'); + return; + } + + $grouped = $qualityRecords->groupBy(function ($item) { + $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(); + + $approverNameFromMaster = null; + if ($pendingApprovers && $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; + } + + $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) - // $first->trigger_at <= $now ) { $level = 2; $mail = $approver->mail2; $name = $approver->name2; - // $updateData['trigger_at'] = $approver->duration2 > 0 - // ? $now->copy()->addMinutes($approver->duration2 * 10) - // : null; - - // $updateData['mail_status'] = 'Sent-Mail2'; if ($approver->duration2 > 0) { @@ -151,10 +349,9 @@ class TriggerPendingApprovalMails extends Command // --- THIRD MAIL --- elseif ( $first->mail_status == 'Sent-Mail2' && - is_null($first->approver_status1) && - is_null($first->approver_status2) && + (is_null($first->approver_status1) || $first->approver_status1 == 'Hold') && + (is_null($first->approver_status2) || $first->approver_status2 == 'Hold') && $first->trigger_at && - // $first->trigger_at <= $now \Carbon\Carbon::parse($first->trigger_at)->lte($now) ) { $level = 3; @@ -169,7 +366,13 @@ class TriggerPendingApprovalMails extends Command continue; } - $pdfPath = 'uploads/LaserDocs/' . $first->work_flow_id . '.pdf'; + $pdfPath = ($f = glob(storage_path('app/private/uploads/LaserDocs/' . $first->work_flow_id . '.*'))) + ? 'uploads/LaserDocs/' . basename($f[0]) + : null; + + $this->info( $pdfPath); + + $subjectLine = 'Quality Approval Mail'; Mail::to($mail)->send( new CharacteristicApprovalMail( @@ -177,6 +380,9 @@ class TriggerPendingApprovalMails extends Command $name, $level, $pdfPath, + $pendingApprovers, + $approverNameFromMaster, + $subjectLine, $characteristics ) ); diff --git a/resources/views/approval/already-processed.blade.php b/resources/views/approval/already-processed.blade.php index 87e6dda..83612ea 100644 --- a/resources/views/approval/already-processed.blade.php +++ b/resources/views/approval/already-processed.blade.php @@ -1,4 +1,4 @@ - +{{-- @@ -67,25 +67,149 @@ font-size: 14px; color: #666; } + + .approvelevel { + /* color: red; */ + font-size: 18px; + font-weight: bold; + } -
-
-
⚠️
-

Action Already Taken

+
+
⚠️ Action Already Taken
-
+
Status: {{ $status }} -
+
-

+

+
+ + + --}} + + + + + Action Taken + + + + +
+
⚠️ Action Already Taken
+ + {{--
+ Status: {{ $status }} +
--}} + +
+ Status: {{ $message ?? $status }} +
+ +

This request has already been processed.
No further action is required. -

+

+ +
+ + diff --git a/resources/views/approval/hold-form.blade.php b/resources/views/approval/hold-form.blade.php index 9ccfcc8..dc62aab 100644 --- a/resources/views/approval/hold-form.blade.php +++ b/resources/views/approval/hold-form.blade.php @@ -13,13 +13,13 @@ -
🟠
-

Request On Hold

+ {{--
--}} +

🟠 Request On Hold

-

+ {{--

Your request has been temporarily put on hold. -

+

--}}
diff --git a/resources/views/approval/hold-success.blade.php b/resources/views/approval/hold-success.blade.php index 3ae2cc1..d25f6fb 100644 --- a/resources/views/approval/hold-success.blade.php +++ b/resources/views/approval/hold-success.blade.php @@ -1,36 +1,77 @@ - Request On Hold + On Hold + - - - - - -
- - - - - - - - - -
- -
🟠
-

Request On Hold

- -

- Your request has been temporarily put on hold. -

-
- CRI Digital Manufacturing Solutions
- © 2026 All Rights Reserved -
-
+ + +
+
🟠 Hold Successfully
+

Your request has been temporarily put on hold.

+ + + +
+ diff --git a/resources/views/approval/reject-form.blade.php b/resources/views/approval/reject-form.blade.php index 75d416b..0b73069 100644 --- a/resources/views/approval/reject-form.blade.php +++ b/resources/views/approval/reject-form.blade.php @@ -13,13 +13,13 @@ -
🟠
-

Request On Reject

+
+

❌ Request On Reject

-

- Your request has been temporarily put on reject. -

+ {{--

+ Your request has been put on reject. +

--}}
@@ -42,7 +42,6 @@ Save Remark
- diff --git a/resources/views/approval/reject-success.blade.php b/resources/views/approval/reject-success.blade.php index eaace85..3e5b75f 100644 --- a/resources/views/approval/reject-success.blade.php +++ b/resources/views/approval/reject-success.blade.php @@ -19,7 +19,7 @@ } .rejected { color: red; - font-size: 20px; + font-size: 18px; font-weight: bold; } .footer { @@ -38,14 +38,33 @@ border-radius: 5px; font-weight: bold; } + .pulse-darkred { + color: DarkRed; /* #8B0000 */ + background-color: #fff; /* White bg for contrast */ + display: inline-block; + padding: 0.5em 0.75em; + border-radius: 4px; + font-size: 1em; + line-height: 1; + animation: pulse 1.5s ease-in-out infinite; /* Duration, easing, infinite loop */ + } + + @keyframes pulse { + 0%, 100% { + transform: scale(1); + } + 50% { + transform: scale(1.2); /* Gentle 5% expansion */ + } + }
-
❌ Rejected Successfully
-

The rejection has been recorded.

-

You may now close this tab.

+
Rejected Successfully
+ {{-- 🔴 --}} +

Your request has been rejected successfully.