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