Feature #18 : Module Approval Permohonan

This commit is contained in:
Daeng Deni Mardaeni
2024-09-12 11:03:00 +07:00
parent 1b1d00a730
commit ed425c4b21
7 changed files with 463 additions and 1 deletions

View File

@@ -179,4 +179,94 @@
{
return Excel::download(new PermohonanExport, 'permohonan.xlsx');
}
public function authorization()
{
return view('lpj::permohonan.authorization.index');
}
public function dataForAuthorization(Request $request)
{
if (is_null($this->user) || !$this->user->can('debitur.view')) {
//abort(403, 'Sorry! You are not allowed to view users.');
}
// Retrieve data from the database
$query = Permohonan::query();
// Apply search filter if provided
if ($request->has('search') && !empty($request->get('search'))) {
$search = $request->get('search');
$query->where(function ($q) use ($search) {
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%');
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
$q->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%');
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
$q->orWhere('status', 'LIKE', '%' . $search . '%');
});
}
// Apply sorting if provided
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
$order = $request->get('sortOrder');
$column = $request->get('sortField');
$query->orderBy($column, $order);
}
// Get the total count of records
$totalRecords = $query->count();
// Apply pagination if provided
if ($request->has('page') && $request->has('size')) {
$page = $request->get('page');
$size = $request->get('size');
$offset = ($page - 1) * $size; // Calculate the offset
$query->skip($offset)->take($size);
}
// Get the filtered count of records
$filteredRecords = $query->count();
// Get the data for the current page
$data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian'])->where('status','=','order')->get();
// Calculate the page count
$pageCount = ceil($totalRecords / $request->get('size'));
// Calculate the current page number
$currentPage = 0 + 1;
// Return the response data as a JSON object
return response()->json([
'draw' => $request->get('draw'),
'recordsTotal' => $totalRecords,
'recordsFiltered' => $filteredRecords,
'pageCount' => $pageCount,
'page' => $currentPage,
'totalCount' => $totalRecords,
'data' => $data,
]);
}
public function showAuthorization($id)
{
$permohonan = Permohonan::find($id);
return view('lpj::permohonan.authorization.show',compact('permohonan'));
}
public function updateAuthorization(Request $request, $id){
try {
$permohonan = Permohonan::find($id);
$permohonan->status = $request->status;
$permohonan->keterangan = $request->keterangan;
$permohonan->save();
}catch (Exception $e) {
return redirect()->route('authorization.show', $id)->with('error', 'Failed to update permohonan');
}
return redirect()->route('authorization.index')->with('success', 'Permohonan updated successfully');
}
}

View File

@@ -17,10 +17,12 @@ class Permohonan extends Base
'branch_id',
'tujuan_penilaian_id',
'debiture_id',
'keterangan',
'status',
'authorized_at',
'authorized_status',
'authorized_by',
];
public function user(){