Added characteristic approval function for testing purpose
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
This commit is contained in:
51
app/Jobs/SendApprover1MailJob.php
Normal file
51
app/Jobs/SendApprover1MailJob.php
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Mail\CharacteristicApprovalMail;
|
||||||
|
use App\Models\CharacteristicApproverMaster;
|
||||||
|
use App\Models\RequestCharacteristic;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class SendApprover1MailJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct(public RequestCharacteristic $request) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
// Already approved? stop
|
||||||
|
if (!is_null($this->request->approver_status1)) return;
|
||||||
|
|
||||||
|
if ($this->request->approver1_mail_sent) return;
|
||||||
|
|
||||||
|
$approver = CharacteristicApproverMaster::where('plant_id', $this->request->plant_id)
|
||||||
|
->where('machine_id', $this->request->machine_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $approver || ! $approver->mail1) return;
|
||||||
|
|
||||||
|
Mail::to($approver->mail1)
|
||||||
|
->queue(new CharacteristicApprovalMail(
|
||||||
|
$this->request,
|
||||||
|
$approver->name1,
|
||||||
|
1
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->request->update(['approver1_mail_sent' => 1]);
|
||||||
|
|
||||||
|
SendApprover2MailJob::dispatch($this->request)
|
||||||
|
->delay(now()->addMinutes(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Jobs/SendApprover2MailJob.php
Normal file
58
app/Jobs/SendApprover2MailJob.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Mail\CharacteristicApprovalMail;
|
||||||
|
use App\Models\CharacteristicApproverMaster;
|
||||||
|
use App\Models\RequestCharacteristic;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class SendApprover2MailJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
// public function __construct()
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function __construct(public RequestCharacteristic $request) {}
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
// If approver-1 approved → STOP
|
||||||
|
if (!is_null($this->request->approver_status1)) return;
|
||||||
|
|
||||||
|
// If approver-2 already approved → STOP
|
||||||
|
if (!is_null($this->request->approver_status2)) return;
|
||||||
|
|
||||||
|
if ($this->request->approver2_mail_sent) return;
|
||||||
|
|
||||||
|
$approver = CharacteristicApproverMaster::where('plant_id', $this->request->plant_id)
|
||||||
|
->where('machine_id', $this->request->machine_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $approver || ! $approver->mail2) return;
|
||||||
|
|
||||||
|
Mail::to($approver->mail2)
|
||||||
|
->queue(new CharacteristicApprovalMail(
|
||||||
|
$this->request,
|
||||||
|
$approver->name2,
|
||||||
|
2
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->request->update(['approver2_mail_sent' => 1]);
|
||||||
|
|
||||||
|
// Schedule Approver-3 after 5 minutes
|
||||||
|
SendApprover3MailJob::dispatch($this->request)
|
||||||
|
->delay(now()->addMinutes(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
56
app/Jobs/SendApprover3MailJob.php
Normal file
56
app/Jobs/SendApprover3MailJob.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Mail\CharacteristicApprovalMail;
|
||||||
|
use App\Models\CharacteristicApproverMaster;
|
||||||
|
use App\Models\RequestCharacteristic;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Queue\Queueable;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
class SendApprover3MailJob implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
// public function __construct()
|
||||||
|
// {
|
||||||
|
// //
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function __construct(public RequestCharacteristic $request) {}
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
!is_null($this->request->approver_status1) ||
|
||||||
|
!is_null($this->request->approver_status2) ||
|
||||||
|
!is_null($this->request->approver_status3)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->request->approver3_mail_sent) return;
|
||||||
|
|
||||||
|
$approver = CharacteristicApproverMaster::where('plant_id', $this->request->plant_id)
|
||||||
|
->where('machine_id', $this->request->machine_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $approver || ! $approver->mail3) return;
|
||||||
|
|
||||||
|
Mail::to($approver->mail3)
|
||||||
|
->queue(new CharacteristicApprovalMail(
|
||||||
|
$this->request,
|
||||||
|
$approver->name3,
|
||||||
|
3
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->request->update(['approver3_mail_sent' => 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user