Skip to content

Commit

Permalink
email instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnujakaria committed Jun 9, 2020
1 parent fd82180 commit 12c7065
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,29 +53,45 @@ 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,
]);

$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',
];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Mail\Plugin\PlayBook\Approval;

use App\Model\Plugin\PlayBook\Instruction;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class InstructionApprovalRequestSent extends Mailable
{
use Queueable, SerializesModels;

public $instruction;
public $approver;
public $urlReferer;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Instruction $instruction, $approver, $urlReferer)
{
$this->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,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,74 @@
<div class="body-text">
Hello {{ $name }},
<br>
There is a new {{ $type }} approval request just sent to you.
There is a new instruction approval request just sent to you.
<br>
@if (@$url)
<a
href="{{ $url }}"
style="background-color: #4CAF50; border: none; color: white; margin:8px 0; padding: 8px 16px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; ">
Open
</a>
@else
<table
style="width: 100%; border-collapse: collapse;
margin-top: 2rem; margin-bottom: 2rem"
border="1">
<tr>
<th style="padding: .5rem">Name</th>
<th style="padding: .5rem">Action</th>
<th style="padding: .5rem">Action</th>
</tr>
<tbody>
<tr>
<td style="padding: .5rem">
{{ $instruction->number }} - {{ $instruction->name }}
</td>
<td style="padding: .5rem">{{ $instruction->approval_action }}</td>
<td style="padding: .5rem; text-align: center">
@if (!$instruction->approved_at)
<div>
<a
href="{{ $url }}?id={{ $instruction->id }}&action=approve"
target="_blank"
style="background-color: #4CAF50; border: none; color: white; margin:4px 0; padding: 3px 5px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; ">
Review
</a>
{{-- <a
href="{{ $url }}?id={{ $instruction->id }}&action=reject"
target="_blank"
style="background-color: rgb(238, 238, 238); border: none; color: rgb(83, 83, 83); margin: 4px 0; padding: 3px 5px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; ">
Reject
</a> --}}
</div>
@else
-
@endif
</td>
</tr>
@foreach ($instruction->steps as $step)
<tr>
<td style="padding: .5rem">
{{ $step->name }}
</td>
<td style="padding: .5rem">
{{ $step->approval_action }}
</td>
<td class="text-center">
<div style="text-align: center">
<a
href="{{ $url }}?step_id={{ $step->id }}&action=approve"
target="_blank"
style="background-color: #4CAF50; border: none; color: white; margin:4px 0; padding: 3px 5px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; ">
Review
</a>
{{-- <a
href="{{ $url }}?step_id={{ $step->id }}&action=reject"
target="_blank"
style="background-color: rgb(238, 238, 238); border: none; color: rgb(83, 83, 83); margin: 4px 0; padding: 3px 5px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; ">
Reject
</a> --}}
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
@if (!@$url)
<p>
Open your dashboard to check.
</p>
Expand Down
15 changes: 0 additions & 15 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 12c7065

Please sign in to comment.