diff --git a/app/Http/Controllers/Api/Plugin/PlayBook/Approval/InstructionController.php b/app/Http/Controllers/Api/Plugin/PlayBook/Approval/InstructionController.php
index f9d8cdcaf..e75fe1ff4 100644
--- a/app/Http/Controllers/Api/Plugin/PlayBook/Approval/InstructionController.php
+++ b/app/Http/Controllers/Api/Plugin/PlayBook/Approval/InstructionController.php
@@ -4,7 +4,7 @@
use App\Http\Controllers\Controller;
use App\Http\Resources\ApiCollection;
-use App\Mail\Plugin\PlayBook\Approval\ApprovalRequestSent;
+use App\Mail\Plugin\PlayBook\Approval\InstructionApprovalRequestSent;
use App\Model\Master\User;
use App\Model\Plugin\PlayBook\Instruction;
use App\Model\Plugin\PlayBook\InstructionHistory;
@@ -53,13 +53,13 @@ public function sendApproval(Request $request)
'approver_id' => ['required', 'numeric'],
]);
- $instructions = Instruction::approvalNotSent()->whereIn('id', $request->ids)->update([
+ Instruction::approvalNotSent()->whereIn('id', $request->ids)->update([
'approval_request_by' => $request->user()->id,
'approval_request_at' => now(),
'approval_request_to' => $request->approver_id,
]);
- $steps = InstructionStep::approvalNotSent()->whereIn('id', $request->step_ids)->update([
+ InstructionStep::approvalNotSent()->whereIn('id', $request->step_ids)->update([
'approval_request_by' => $request->user()->id,
'approval_request_at' => now(),
'approval_request_to' => $request->approver_id,
@@ -67,15 +67,31 @@ public function sendApproval(Request $request)
$approver = User::findOrFail($request->approver_id);
- Mail::to([
- $approver->email,
- ])->queue(new ApprovalRequestSent(
- Instruction::class,
- $approver,
- $_SERVER['HTTP_REFERER']
- ));
+ // send email
+ $instructions = Instruction::with('approver', 'procedure')
+ ->approvalRequested()->orWhereHas('steps', function ($query) use ($request) {
+ $query
+ ->approvalRequested()
+ ->where('approval_request_to', $request->approver_id);
+ })->with(['steps' => function ($query) use ($request) {
+ $query->with('contents.glossary')
+ ->approvalRequested()
+ ->where('approval_request_to', $request->approver_id);;
+ }])->get();
+
+ foreach ($instructions as $key => $instruction) {
+ Mail::to([
+ $approver->email,
+ ])->queue(new InstructionApprovalRequestSent(
+ $instruction,
+ $approver,
+ $_SERVER['HTTP_REFERER']
+ ));
+ }
- return compact('instructions', 'steps');
+ return [
+ 'message' => 'good',
+ ];
}
/**
diff --git a/app/Mail/Plugin/PlayBook/Approval/InstructionApprovalRequestSent.php b/app/Mail/Plugin/PlayBook/Approval/InstructionApprovalRequestSent.php
new file mode 100644
index 000000000..97a30c1ba
--- /dev/null
+++ b/app/Mail/Plugin/PlayBook/Approval/InstructionApprovalRequestSent.php
@@ -0,0 +1,50 @@
+instruction = $instruction;
+ $this->approver = $approver;
+ $this->urlReferer = $urlReferer;
+ }
+
+ /**
+ * Build the message.
+ *
+ * @return $this
+ */
+ public function build()
+ {
+ if (@$this->urlReferer) {
+ $parsedUrl = parse_url($this->urlReferer);
+ $port = @$parsedUrl['port'] ? ":{$parsedUrl['port']}" : '';
+ $url = "{$parsedUrl['scheme']}://{$parsedUrl['host']}{$port}/plugin/play-book/approval/instruction";
+ }
+
+ return $this->subject("New Instruction")
+ ->view('emails.plugin.play-book.instruction-approval-sent', [
+ 'instruction' => $this->instruction,
+ 'name' => $this->approver->name,
+ 'url' => @$url,
+ ]);
+ }
+}
diff --git a/resources/views/emails/plugin/play-book/instruction-approval-sent.blade.php b/resources/views/emails/plugin/play-book/instruction-approval-sent.blade.php
index c33ee83d9..cacc5ab5a 100644
--- a/resources/views/emails/plugin/play-book/instruction-approval-sent.blade.php
+++ b/resources/views/emails/plugin/play-book/instruction-approval-sent.blade.php
@@ -6,15 +6,74 @@
Hello {{ $name }},
- There is a new {{ $type }} approval request just sent to you.
+ There is a new instruction approval request just sent to you.
- @if (@$url)
-
- Open
-
- @else
+
+
+ Name |
+ Action |
+ Action |
+
+
+
+
+ {{ $instruction->number }} - {{ $instruction->name }}
+ |
+ {{ $instruction->approval_action }} |
+
+ @if (!$instruction->approved_at)
+
+ @else
+ -
+ @endif
+ |
+
+ @foreach ($instruction->steps as $step)
+
+
+ ⇨
+ {{ $step->name }}
+ |
+
+ {{ $step->approval_action }}
+ |
+
+
+ |
+
+ @endforeach
+
+
+ @if (!@$url)
Open your dashboard to check.
diff --git a/routes/web.php b/routes/web.php
index dcad159e7..d32028702 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -11,21 +11,6 @@
|
*/
-use App\Mail\Plugin\PlayBook\Approval\ProcedureApprovalRequestSent;
-use App\Model\Master\User;
-use App\Model\Plugin\PlayBook\Procedure;
-
-Route::get('tes', function () {
- $approver = User::first();
- $procedure = Procedure::notApprovedYet()->firstOrFail();
-
- return new ProcedureApprovalRequestSent(
- $procedure,
- $approver,
- 'http://dev.localhost:8080'
- );
-});
-
Route::namespace('Web')->group(function () {
Route::view('/', 'welcome');