added approval by MIS & final approval by superadmin
This commit is contained in:
@@ -20,8 +20,17 @@ class FormMeetingSeminarController extends Controller
|
||||
public function index()
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.meeting.view']);
|
||||
|
||||
// get user role
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
$forms = null;
|
||||
|
||||
if($role == 'Marketing Information System' || $role == 'superadmin') {
|
||||
$forms = FormMeetingSeminar::get();
|
||||
} else {
|
||||
$forms = FormMeetingSeminar::where('user_id', auth()->user()->id)->get();
|
||||
}
|
||||
|
||||
$forms = FormMeetingSeminar::where('user_id', auth()->user()->id)->get();
|
||||
return view('backend.pages.forms.meeting.index', [
|
||||
'forms' => $forms
|
||||
]);
|
||||
@@ -139,7 +148,8 @@ class FormMeetingSeminarController extends Controller
|
||||
'bukti3' => 'nullable|file|mimes:pdf',
|
||||
]);
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
$form = FormMeetingSeminar::findOrfail($id);
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', $form->user_id)->first()->cabang;
|
||||
$region = Region::where('id', $cabang->region_id)->first();
|
||||
$kategori = Kategori::where('name', 'Meeting & Seminar')->first();
|
||||
|
||||
@@ -185,7 +195,6 @@ class FormMeetingSeminarController extends Controller
|
||||
}
|
||||
|
||||
// Save the form data
|
||||
$form = FormMeetingSeminar::findOrfail($id);
|
||||
$form->update([
|
||||
'allowance' => $request->allowance,
|
||||
'transport_ankot' => $request->transport_ankot,
|
||||
@@ -201,6 +210,69 @@ class FormMeetingSeminarController extends Controller
|
||||
return redirect()->route('forms.meeting');
|
||||
}
|
||||
|
||||
public function approve($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['approval.approve']);
|
||||
|
||||
$form = FormMeetingSeminar::findOrfail($id);
|
||||
$form->update([
|
||||
'approved_at' => now(),
|
||||
'approved_by' => auth()->user()->id,
|
||||
'status' => 'Approved'
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Form has been approved.');
|
||||
return redirect()->route('forms.meeting');
|
||||
}
|
||||
|
||||
public function finalApprove($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
||||
|
||||
$form = FormMeetingSeminar::findOrfail($id);
|
||||
if($form->approved_at == null) {
|
||||
session()->flash('error', 'Form must be approved by MIS first.');
|
||||
return redirect()->route('forms.meeting');
|
||||
}
|
||||
|
||||
$form->update([
|
||||
'final_approved_at' => now(),
|
||||
'final_approved_by' => auth()->user()->id,
|
||||
'status' => 'Closed'
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Form has been final approved.');
|
||||
return redirect()->route('forms.meeting');
|
||||
}
|
||||
|
||||
public function open($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
||||
|
||||
$form = FormMeetingSeminar::findOrfail($id);
|
||||
$form->update([
|
||||
'final_approved_at' => null,
|
||||
'final_approved_by' => null,
|
||||
'status' => 'Approved'
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Form has been opened.');
|
||||
return redirect()->route('forms.meeting');
|
||||
}
|
||||
|
||||
public function reject($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['approval.approve']);
|
||||
|
||||
$form = FormMeetingSeminar::findOrfail($id);
|
||||
$form->update([
|
||||
'status' => 'Rejected'
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->route('forms.meeting');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.meeting.delete']);
|
||||
|
||||
Reference in New Issue
Block a user