added approval by MIS & final approval by superadmin
This commit is contained in:
@@ -21,7 +21,16 @@ class FormOtherController extends Controller
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.other.view']);
|
||||
|
||||
$forms = FormOthers::where('user_id', auth()->user()->id)->get();
|
||||
// get user role
|
||||
$role = auth()->user()->getRoleNames()[0];
|
||||
$forms = null;
|
||||
|
||||
if($role == 'Marketing Information System' || $role == 'superadmin') {
|
||||
$forms = FormOthers::get();
|
||||
} else {
|
||||
$forms = FormOthers::where('user_id', auth()->user()->id)->get();
|
||||
}
|
||||
|
||||
return view('backend.pages.forms.other.index', [
|
||||
'forms' => $forms
|
||||
]);
|
||||
@@ -144,7 +153,8 @@ class FormOtherController extends Controller
|
||||
'bukti3' => 'nullable|file|mimes:pdf',
|
||||
]);
|
||||
|
||||
$cabang = UserHasCabang::with('cabang')->where('user_id', auth()->user()->id)->first()->cabang;
|
||||
$form = FormOthers::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('id', $request->kategori_id)->first();
|
||||
|
||||
@@ -190,7 +200,6 @@ class FormOtherController extends Controller
|
||||
}
|
||||
|
||||
// Save the form data
|
||||
$form = FormOthers::findOrfail($id);
|
||||
$form->update([
|
||||
'kategori_id' => $request->kategori_id,
|
||||
'tanggal' => $request->tanggal,
|
||||
@@ -206,6 +215,69 @@ class FormOtherController extends Controller
|
||||
return redirect()->route('forms.other');
|
||||
}
|
||||
|
||||
public function approve($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['approval.approve']);
|
||||
|
||||
$form = FormOthers::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.other');
|
||||
}
|
||||
|
||||
public function finalApprove($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
||||
|
||||
$form = FormOthers::findOrfail($id);
|
||||
if($form->approved_at == null) {
|
||||
session()->flash('error', 'Form must be approved by MIS first.');
|
||||
return redirect()->route('forms.other');
|
||||
}
|
||||
|
||||
$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.other');
|
||||
}
|
||||
|
||||
public function open($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['final_approval.approve']);
|
||||
|
||||
$form = FormOthers::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.other');
|
||||
}
|
||||
|
||||
public function reject($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['approval.approve']);
|
||||
|
||||
$form = FormOthers::findOrfail($id);
|
||||
$form->update([
|
||||
'status' => 'Rejected'
|
||||
]);
|
||||
|
||||
session()->flash('success', 'Form has been rejected.');
|
||||
return redirect()->route('forms.other');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->checkAuthorization(auth()->user(), ['forms.other.delete']);
|
||||
|
||||
Reference in New Issue
Block a user