Skip to content

Commit

Permalink
Modified workflow order
Browse files Browse the repository at this point in the history
  • Loading branch information
orkit committed Nov 29, 2023
1 parent a6d7a66 commit 1eb0e02
Show file tree
Hide file tree
Showing 26 changed files with 147 additions and 107 deletions.
17 changes: 17 additions & 0 deletions app/Http/Controllers/FOController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ public function __construct()
$this->middleware('fo');
}

/**
* Show the TravelRequest form for a given user.
*
* @param int $id
* @return \Statamic\View\View
*/
public function show($id)
{
$tr = TravelRequest::find($id);
$formtype = 'show';

return (new \Statamic\View\View)
->template('requests.travel.show')
->layout('mylayout')
->with(['tr' => $tr, 'formtype' => $formtype]);
}

public function list()
{
return (new \Statamic\View\View)
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Livewire/Indicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function checkDashboard()
//Check dashboard
//Tasks
$manager = collect(Dashboard::where('state', 'submitted')->where('manager_id', $this->auth_user)->get());
$fo = collect(Dashboard::where('state', 'manager_approved')->where('fo_id', $this->auth_user)->get());
$head = collect(Dashboard::where('state', 'fo_approved')->where('head_id', $this->auth_user)->get());
$head = collect(Dashboard::where('state', 'manager_approved')->where('head_id', $this->auth_user)->get());
$fo = collect(Dashboard::where('state', 'head_approved')->where('fo_id', $this->auth_user)->get());
//User
$manager_return = collect(Dashboard::where('state', 'manager_returned')->where('user_id', $this->auth_user)->where('status', 'unread')->get());
$manager_deny = collect(Dashboard::where('state', 'manager_denied')->where('user_id', $this->auth_user)->where('status', 'unread')->get());
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Livewire/Mobileindicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function checkDashboard()
//Check dashboard
//Tasks
$manager = collect(Dashboard::where('state', 'submitted')->where('manager_id', $this->auth_user)->get());
$fo = collect(Dashboard::where('state', 'manager_approved')->where('fo_id', $this->auth_user)->get());
$head = collect(Dashboard::where('state', 'fo_approved')->where('head_id', $this->auth_user)->get());
$head = collect(Dashboard::where('state', 'manager_approved')->where('head_id', $this->auth_user)->get());
$fo = collect(Dashboard::where('state', 'head_approved')->where('fo_id', $this->auth_user)->get());
//User
$manager_return = collect(Dashboard::where('state', 'manager_returned')->where('user_id', $this->auth_user)->where('status', 'unread')->get());
$manager_deny = collect(Dashboard::where('state', 'manager_denied')->where('user_id', $this->auth_user)->where('status', 'unread')->get());
Expand Down
1 change: 1 addition & 0 deletions app/Http/Livewire/RequestSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function render()
})
->orWhereHas('travel', function ($query) use ($searchTerm) {
$query->where('project', 'LIKE', $searchTerm ?? '')
->orWhere('country', 'LIKE', $searchTerm ?? '')
->orWhere('purpose', 'LIKE', $searchTerm ?? '');
})
->get();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Livewire/Requestnotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public function mount()
public function getRequests()
{
$manager = collect(Dashboard::where('state', 'submitted')->where('manager_id', $this->auth_user)->get());
$fo = collect(Dashboard::where('state', 'manager_approved')->where('fo_id', $this->auth_user)->get());
$head = collect(Dashboard::where('state', 'fo_approved')->where('head_id', $this->auth_user)->get());
$head = collect(Dashboard::where('state', 'manager_approved')->where('head_id', $this->auth_user)->get());
$fo = collect(Dashboard::where('state', 'head_approved')->where('fo_id', $this->auth_user)->get());
$this->requests = $manager->merge($fo)->merge($head);
}

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Middleware/EnsureUserForReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public function handle(Request $request, Closure $next): Response
}
break;
case('manager_approved'):
if($user->id == $dashboard->fo_id) {
if($user->id == $dashboard->head_id) {
return $next($request);
}
break;
case('fo_approved'):
if($user->id == $dashboard->head_id) {
case('head_approved'):
if($user->id == $dashboard->fo_id) {
return $next($request);
}
break;
Expand Down
5 changes: 3 additions & 2 deletions app/Mail/NotifyRequestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class NotifyRequestManager extends Mailable
/**
* Create a new message instance.
*/
public $user, $dashboard;
public $user, $manager, $dashboard;

public function __construct(User $user, Dashboard $dashboard)
public function __construct(User $user, User $manager, Dashboard $dashboard)
{
$this->user = $user;
$this->dashboard = $dashboard;
$this->manager = $manager;
}

/**
Expand Down
11 changes: 6 additions & 5 deletions app/Services/Review/RequestReviewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ private function getRole()
}
break;
case('manager_approved'):
if ($this->dashboard->fo_id == $this->reviewer->id) {
$role = 'fo';
}
break;
case('fo_approved'):
if ($this->dashboard->head_id == $this->reviewer->id) {
$role = 'head';
}
break;

case('head_approved'):
if ($this->dashboard->fo_id == $this->reviewer->id) {
$role = 'fo';
}

}
return $role;
Expand Down
10 changes: 5 additions & 5 deletions app/Workflows/Notifications/NewRequestNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public function execute($recipent, $request)
//Send email to recipent
switch($recipent) {
case('manager'):
Mail::to($manager->email)->send(new NotifyRequestManager($user, $this->dashboard));
break;
case('fo'):
Mail::to($fo->email)->send(new NotifyRequestFO($user, $manager, $this->dashboard));
Mail::to($manager->email)->send(new NotifyRequestManager($user, $manager, $this->dashboard));
break;
case('head'):
Mail::to($head->email)->send(new NotifyRequestHead($user, $manager, $this->dashboard));
Mail::to($head->email)->send(new NotifyRequestHead($user, $head, $this->dashboard));
break;
case('fo'):
Mail::to($fo->email)->send(new NotifyRequestFO($user, $fo, $this->dashboard));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Workflows/Notifications/StateUpdateNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function execute($request)
//Notify
Mail::to($user->email)->send(new NotifyUserChangedState($user, $head, $this->dashboard));
break;
case('head_approved'):
case('fo_approved'):
//Approved Request
//Notify
Mail::to($user->email)->send(new NotifyRequestApproved($user, $this->dashboard));
Expand Down
61 changes: 31 additions & 30 deletions app/Workflows/TravelRequestWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ public function __construct(
$this->stateMachine->addTransition('managerreturn', 'submitted', 'manager_returned');
$this->stateMachine->addTransition('managerdeny', 'submitted', 'manager_denied');

//FO
$this->stateMachine->addTransition('foapprove', 'manager_approved', 'fo_approved');
$this->stateMachine->addTransition('foreturn', 'manager_approved', 'fo_returned');
$this->stateMachine->addTransition('fodeny', 'manager_approved', 'fo_denied');

//Head
$this->stateMachine->addTransition('headapprove', 'fo_approved', 'head_approved');
$this->stateMachine->addTransition('headreturn', 'fo_approved', 'head_returned');
$this->stateMachine->addTransition('headdeny', 'fo_approved', 'head_denied');
$this->stateMachine->addTransition('headapprove', 'manager_approved', 'head_approved');
$this->stateMachine->addTransition('headreturn', 'manager_approved', 'head_returned');
$this->stateMachine->addTransition('headdeny', 'manager_approved', 'head_denied');

//FO
$this->stateMachine->addTransition('foapprove', 'head_approved', 'fo_approved');
$this->stateMachine->addTransition('foreturn', 'head_approved', 'fo_returned');
$this->stateMachine->addTransition('fodeny', 'head_approved', 'fo_denied');

//Initialize
$this->stateMachine->setObject($this);
Expand All @@ -214,8 +214,8 @@ public function execute($travelRequest)
case('manager_approved'):
//Request has been approved by manager
yield ActivityStub::make(StateUpdateTransition::class, $new_state, $travelRequest);
//Fire email to FO
yield ActivityStub::make(NewRequestNotification::class, 'fo', $travelRequest);
//Notify Head
yield ActivityStub::make(NewRequestNotification::class, 'head', $travelRequest);
break;
case('manager_returned'):
//Request had been returned by manager
Expand All @@ -233,52 +233,53 @@ public function execute($travelRequest)
break;
}

//Wait for financialofficer to process request
yield WorkflowStub::await(fn () => $this->FOApproved() || $this->FODenied() || $this->FOReturned());
//Wait for Head to process request
yield WorkflowStub::await(fn () => $this->HeadApproved() || $this->HeadDenied() || $this->HeadReturned());

//Handle FO decision
//Handle Head decision
switch ($new_state = $this->stateMachine->getCurrentState()->getName()) {
case('fo_approved'):
//Request has been approved by fo
case('head_approved'):
//Request has been approved by head
yield ActivityStub::make(StateUpdateTransition::class, $new_state, $travelRequest);
//Fire email to Head
yield ActivityStub::make(NewRequestNotification::class, 'head', $travelRequest);
//Notify FO
yield ActivityStub::make(NewRequestNotification::class, 'fo', $travelRequest);
break;
case('fo_returned'):
//Request has been returned by fo
case('head_returned'):
//Request had been returned by head
yield ActivityStub::make(StateUpdateTransition::class, $new_state, $travelRequest);
//Notify requester
yield ActivityStub::make(StateUpdateNotification::class, $travelRequest);
return $this->stateMachine->getCurrentState()->getName();
break;
case('fo_denied'):
//Request has been denied by fo
case('head_denied'):
//Request has been denied by head
yield ActivityStub::make(StateUpdateTransition::class, $new_state, $travelRequest);
//Notify requester
yield ActivityStub::make(StateUpdateNotification::class, $travelRequest);
return $this->stateMachine->getCurrentState()->getName();
break;
}

//Wait for Head to process request
yield WorkflowStub::await(fn () => $this->HeadApproved() || $this->HeadDenied() || $this->HeadReturned());
//Wait for financialofficer to process request
yield WorkflowStub::await(fn () => $this->FOApproved() || $this->FODenied() || $this->FOReturned());

//Handle Head decision
//Handle FO decision
switch ($new_state = $this->stateMachine->getCurrentState()->getName()) {
case('head_approved'):
//Request has been approved
case('fo_approved'):
//Request has been approved by fo
yield ActivityStub::make(StateUpdateTransition::class, $new_state, $travelRequest);
//Approved request - Notify user
yield ActivityStub::make(StateUpdateNotification::class, $travelRequest);
break;
case('head_returned'):
//Request had been returned by head
case('fo_returned'):
//Request has been returned by fo
yield ActivityStub::make(StateUpdateTransition::class, $new_state, $travelRequest);
//Notify requester
yield ActivityStub::make(StateUpdateNotification::class, $travelRequest);
return $this->stateMachine->getCurrentState()->getName();
break;
case('head_denied'):
//Request has been denied by head
case('fo_denied'):
//Request has been denied by fo
yield ActivityStub::make(StateUpdateTransition::class, $new_state, $travelRequest);
//Notify requester
yield ActivityStub::make(StateUpdateNotification::class, $travelRequest);
Expand Down
4 changes: 2 additions & 2 deletions resources/views/emails/request/newtofo.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[DSV Intranet - Test]<br><br>
Dear FO
Dear {{$manager->name}},
<br><br>
A new <strong>{{$dashboard->type}}</strong> has been submitted and approved from the project leader/manager that requires your immediate consideration.
A new <strong>{{$dashboard->type}}</strong> has been submitted and approved from the project leader/manager and unit head which needs to be checked and approved.
Brief details in the request are as follows:
<br><br>
Requester: {{$user->name}}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/request/newtohead.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[DSV Intranet - Test]<br><br>
Dear Unit head
Dear {{$manager->name}},
<br><br>
A new <strong>{{$dashboard->type}}</strong> has been submitted and approved from the project leader/manager and financial officer that requires your immediate consideration.
Brief details in the request are as follows:
Expand Down
4 changes: 2 additions & 2 deletions resources/views/emails/request/newtomanager.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[DSV Intranet - Test]<br><br>
Dear Manager
Dear {{$manager->name}},
<br><br>
A new <strong>{{$dashboard->type}}</strong> has been submitted that requires your immediate consideration.
A new <strong>{{$dashboard->type}}</strong> has been submitted that requires your immediate consideration as project manager for the project.
Brief details in the request are as follows:
<br><br>
Requester: {{$user->name}}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/userconfirmation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Dear <b>{{$user->name}}</b>,
<br><br>
We are excited to confirm your successful first time registration for the intranet platform. Welcome!
We are excited to confirm your successful first time registration for the DSV intranet platform. Welcome!
<br><br>
With access to our intranet, you will be able to:
<br><br>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/emails/userroleupdate.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@elseif ($role->title == 'staff_it')
IT - Create, edit, and publish digital content, including articles, news posts, images, and other assets within it.
@elseif ($role->title == 'financial_officer')
FINACIAL OFFICER - Review, grant, deny or return user requests for the entire institution.
FINACIAL OFFICER - Review, grant, deny or return user requests for the DSV department.
@elseif ($role->title == 'project_leader')
PROJECT LEADER - Review, grant, deny or return user requests within your project group.
@elseif ($role->title == 'unit_head')
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/indicator.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div wire:poll.keep-alive>
<div wire:poll.visible>
@if(count($dashboard) > 0)
<span class="hidden md:block relative flex h-3 w-3 -mt-3 -mr-3">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"></span>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/mobileindicator.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div wire:poll.keep-alive>
<div wire:poll.visible>
@if(count($dashboard) > 0)
<span class="md:hidden relative flex h-2 w-2 -mt-3 ml-32">
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"></span>
Expand Down
Loading

0 comments on commit 1eb0e02

Please sign in to comment.