diff --git a/app/Exports/JenisPenilaianExport.php b/app/Exports/JenisPenilaianExport.php new file mode 100644 index 0000000..7d633eb --- /dev/null +++ b/app/Exports/JenisPenilaianExport.php @@ -0,0 +1,46 @@ +id, + $row->code, + $row->name, + $row->created_at + ]; + } + + public function headings(): array + { + return [ + 'ID', + 'Code', + 'Jenis Penilaian', + 'Created At' + ]; + } + + public function columnFormats(): array + { + return [ + 'A' => NumberFormat::FORMAT_NUMBER, + 'D' => NumberFormat::FORMAT_DATE_DATETIME + ]; + } +} diff --git a/app/Exports/PermohonanExport.php b/app/Exports/PermohonanExport.php index 07b83fe..c6ce0a2 100644 --- a/app/Exports/PermohonanExport.php +++ b/app/Exports/PermohonanExport.php @@ -28,6 +28,8 @@ $row->branch->name, $row->tujuanPenilaian->name, $row->debiture->name, + $row->fasilitasKredit->name, + $row->plafond->name, $row->status, $row->authorized_at, $row->authorized_status, @@ -47,7 +49,9 @@ 'Branch Pemohon', 'Tujuan Penilaian', 'Debitur', - 'Status', + 'Jenis Fasilitas Kredit', + 'Nilai Plafond', + 'Status Permohonan', 'Tanggal Pengesahan', 'Status Pengesahan', 'Pengesah', @@ -61,7 +65,8 @@ return [ 'A' => NumberFormat::FORMAT_NUMBER, 'C' => NumberFormat::FORMAT_DATE_DATETIME, - 'L' => NumberFormat::FORMAT_DATE_DATETIME + 'K' => NumberFormat::FORMAT_DATE_DATETIME, + 'N' => NumberFormat::FORMAT_DATE_DATETIME ]; } } diff --git a/app/Exports/TeamPenilaianExport.php b/app/Exports/TeamPenilaianExport.php new file mode 100644 index 0000000..3fdc1f7 --- /dev/null +++ b/app/Exports/TeamPenilaianExport.php @@ -0,0 +1,57 @@ +join('regions', 'teams.regions_id', '=', 'regions.id') + ->leftJoin('teams_users', 'teams.id', '=', 'teams_users.teams_id') + ->leftJoin('users', 'teams_users.user_id', '=', 'users.id') + ->groupBy('teams.id', 'teams.name', 'regions.name') + ->get(); + } + + public function map($row): array + { + return [ + $row->team_name, + $row->region_name, + $row->team_group, + ]; + } + + public function headings(): array + { + return [ + 'Name', + 'Region', + 'Anggota Team', + ]; + } + + public function columnFormats(): array + { + return [ + 'A' => NumberFormat::FORMAT_TEXT, + 'B' => NumberFormat::FORMAT_TEXT, + 'C' => NumberFormat::FORMAT_TEXT, + ]; + } +} diff --git a/app/Http/Controllers/DebitureController.php b/app/Http/Controllers/DebitureController.php index 7929578..b429265 100644 --- a/app/Http/Controllers/DebitureController.php +++ b/app/Http/Controllers/DebitureController.php @@ -71,6 +71,7 @@ public function update(DebitureRequest $request, $id) { + //print_r($request->all());exit; $validate = $request->validated(); if ($validate) { @@ -174,10 +175,4 @@ { return Excel::download(new DebitureExport, 'debitur.xlsx'); } - - public function download($id) - { - $document = DokumenJaminan::find($id); - return response()->download(storage_path('app/public/' . $document->dokumen_jaminan)); - } } diff --git a/app/Http/Controllers/DokumenJaminanController.php b/app/Http/Controllers/DokumenJaminanController.php index 520c20e..dca91a5 100644 --- a/app/Http/Controllers/DokumenJaminanController.php +++ b/app/Http/Controllers/DokumenJaminanController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use Exception; use Illuminate\Support\Facades\DB; + use Illuminate\Support\Facades\Storage; use Modules\Location\Models\City; use Modules\Location\Models\District; use Modules\Location\Models\Province; @@ -25,7 +26,7 @@ public function index($id) { $debitur = Debiture::find($id); - $documents = DokumenJaminan::with('pemilik')->where('debiture_id', $id)->get(); + $documents = DokumenJaminan::with('pemilik', 'detail')->where('debiture_id', $id)->get(); return view( 'lpj::debitur.edit', @@ -68,7 +69,6 @@ $document = DokumenJaminan::create($validate); try { - foreach ($request->dokumen_jaminan as $key => $value) { $file_name = $value->getClientOriginalName(); @@ -77,7 +77,7 @@ $file_name = $value->getClientOriginalName(); $value->storeAs( 'public/jaminan/' . $debitur->id . '/' . $document->id . '/', - $file_name + $file_name, ); $detail = [ @@ -92,17 +92,17 @@ DB::rollBack(); return redirect()->route('debitur.jaminan.index', $id)->with( 'error', - 'Gagal upload file dokumen jaminan '. $key. ': '. $e->getMessage(), + 'Gagal upload file dokumen jaminan ' . $key . ': ' . $e->getMessage(), ); } } } DB::commit(); - }catch (Exception $e) { + } catch (Exception $e) { DB::rollBack(); return redirect()->route('debitur.jaminan.index', $id)->with( 'error', - 'gg'.$e->getMessage(), + 'gg' . $e->getMessage(), ); } @@ -112,7 +112,7 @@ ); } catch (Exception $e) { DB::rollBack(); - return redirect()->route('debitur.jaminan.index', $id)->with('error','ggl'. $e->getMessage()); + return redirect()->route('debitur.jaminan.index', $id)->with('error', 'ggl' . $e->getMessage()); } } } @@ -138,6 +138,7 @@ $validate = $request->validated(); if ($validate) { try { + DB::beginTransaction(); $validate['debiture_id'] = $id; if ($validate['pemilik_jaminan_id'] == 0) { @@ -160,29 +161,77 @@ ], $pemilik_jaminan); } - if ($request->hasFile('dokumen_jaminan')) { - $file = $request->file('dokumen_jaminan'); - $file_name = $file->getClientOriginalName(); - $file->storeAs('public/jaminan/' . $debitur->id, $file_name); - $validate['dokumen_jaminan'] = 'jaminan/' . $debitur->id . '/' . $file_name; - } - $document = DokumenJaminan::find($jaminan); $document->update($validate); + if ($request->detail_dokumen_jaminan_id) { + foreach ($request->detail_dokumen_jaminan_id as $key => $value) { + if (isset($request->dokumen_jaminan[$key])) { + $file = $request->dokumen_jaminan[$key]; + if ($file) { + $file_name = $file->getClientOriginalName(); + } + + if (isset($file_name)) { + $file->storeAs( + 'public/jaminan/' . $debitur->id . '/' . $document->id . '/', + $file_name, + ); + + $detail = [ + 'dokumen_jaminan_id' => $document->id, + 'jenis_legalitas_jaminan_id' => $request->jenis_legalitas_jaminan_id[$key], + 'dokumen_jaminan' => 'jaminan/' . $debitur->id . '/' . $document->id . '/' . $file_name, + 'name' => $request->name[$key], + 'keterangan' => $request->keterangan[$key], + ]; + if (isset($request->detail_dokumen_jaminan_id[$key])) { + $detailDocument = DetailDokumenJaminan::find( + $request->detail_dokumen_jaminan_id[$key], + ); + + $detailDocument->update($detail); + $detailDocument->save(); + } + } + } else { + $detail = [ + 'dokumen_jaminan_id' => $document->id, + 'jenis_legalitas_jaminan_id' => $request->jenis_legalitas_jaminan_id[$key], + 'name' => $request->name[$key], + 'keterangan' => $request->keterangan[$key], + ]; + + if (isset($request->detail_dokumen_jaminan_id[$key])) { + $detailDocument = DetailDokumenJaminan::find( + $request->detail_dokumen_jaminan_id[$key], + ); + $detailDocument->update($detail); + } + } + } + } + + DB::commit(); return redirect()->route('debitur.jaminan.index', $id)->with( 'success', 'Dokumen Jaminan berhasil diubah', ); - } catch (Exception $e) { + } catch + (Exception $e) { + DB::rollBack(); return redirect()->route('debitur.jaminan.index', $id)->with('error', $e->getMessage()); } } } - public function edit($id, $jaminan) - { + public + function edit( + $id, + $jaminan, + ) { $document = DokumenJaminan::find($jaminan); + $details = DetailDokumenJaminan::where('dokumen_jaminan_id', $document->id)->get(); $debitur = Debiture::find($document->debiture_id); $provinces = Province::all(); $cities = City::where('province_code', $document->province_code)->get(); @@ -200,6 +249,7 @@ 'jenisJaminan', 'jenisLegalitasJaminan', 'document', + 'details', 'cities', 'districts', 'villages', @@ -208,14 +258,30 @@ ); } - public function destroy($id, $jaminan_id) - { + public + function destroy( + $id, + $jaminan_id, + ) { try { $jaminan = DokumenJaminan::find($jaminan_id); + $details = DetailDokumenJaminan::where('dokumen_jaminan_id',$jaminan->id)->get(); + foreach ($details as $detail){ + Storage::delete('public/'. $detail->dokumen_jaminan); + $detail->delete(); + } $jaminan->delete(); echo json_encode(['success' => true, 'message' => 'Dokumen Jaminan deleted successfully']); } catch (Exception $e) { echo json_encode(['success' => false, 'message' => 'Failed to delete Dokumen Jaminan']); } } + + public + function download( + $id, + ) { + $document = DetailDokumenJaminan::find($id); + return response()->download(storage_path('app/public/' . $document->dokumen_jaminan)); + } } diff --git a/app/Http/Controllers/JenisPenilaianController.php b/app/Http/Controllers/JenisPenilaianController.php index c38f673..e70fcdb 100644 --- a/app/Http/Controllers/JenisPenilaianController.php +++ b/app/Http/Controllers/JenisPenilaianController.php @@ -6,15 +6,13 @@ use Exception; use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Http\Response; use Modules\Lpj\Models\JenisPenilaian; - use Modules\Lpj\Http\Requests\JenisPenilaianRequest; - +use Modules\Lpj\Exports\JenisPenilaianExport; +use Maatwebsite\Excel\Facades\Excel; class JenisPenilaianController extends Controller { - public $user; /** * Display a listing of the resource. @@ -62,15 +60,13 @@ class JenisPenilaianController extends Controller public function update(JenisPenilaianRequest $request, $id) { + $validated = $request->validated(); - $validate = $request->validate(); - // dump($validate); - - if ($validate) { + if ($validated) { try { $jenisPenilaian = JenisPenilaian::find($id); - $jenisPenilaian->update($validate); + $jenisPenilaian->update($validated); return redirect()->route('basicdata.jenis-penilaian.index')->with('success', 'Jenis Penilaian updated successfully'); } catch (Exception $e) { return redirect()->route('basicdata.jenis-penilaian.edit', $id)->with('error', $e->getMessage()); @@ -96,8 +92,6 @@ class JenisPenilaianController extends Controller public function dataForDatatables(Request $request) { - - if (is_null($this->user) || !$this->user->can('jenis_penilaian.view')) { //abort(403, 'Sorry! You are not allowed to view users.'); } @@ -112,7 +106,7 @@ class JenisPenilaianController extends Controller }); } - if($request->has('sortOrder') && !empty($request->get('sortOrder'))){ + if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) { $order = $request->get('sortOrder'); $column = $request->get('sortField'); $query->orderBy($column, $order); @@ -153,4 +147,10 @@ class JenisPenilaianController extends Controller 'data' => $data ]); } + + + public function export() + { + return Excel::download(new JenisPenilaianExport(), 'jenis-penilaian.xlsx'); + } } diff --git a/app/Http/Controllers/PenilaianController.php b/app/Http/Controllers/PenilaianController.php new file mode 100644 index 0000000..dadfd09 --- /dev/null +++ b/app/Http/Controllers/PenilaianController.php @@ -0,0 +1,203 @@ +validated(); + + if ($validatedData) { + try { + $penilaian = Penilaian::create($validatedData); + + $permohonan = Permohonan::findOrFail($request->permohonan_id); + $permohonan->update([ + 'status' => 'assign', + ]); + + return redirect()->route('penilaian.index')->with('success', 'Penilaian berhasil disimpan'); + } catch (Exception $e) { + return redirect()->route('penilaian.index')->with('error', $e->getMessage()); + } + } + } + + /** + * Show the form for creating a new resource. + */ + public function create($id) + { + return view('lpj::penilaian.form'); + } + + /** + * Update the specified resource in storage. + */ + public function update(PenilaianRequest $request, $id) + { + $validate = $request->validated(); + + if ($validate) { + try { + $penilaian = Penilaian::where('permohonan_id', $id)->firstOrFail(); + + $penilaian->update($validate); + $permohonan = Permohonan::findOrFail($id); + $permohonan->update([ + 'status' => 'assign', + ]); + + return redirect()->route('penilaian.index', $id)->with('success', 'Penilaian berhasil diubah'); + } catch (Exception $e) { + return redirect()->route('penilaian.index', $id)->with('error', $e->getMessage()); + } + } + } + + /** + * Show the specified resource. + */ + public function show($id) + { + return view('lpj::show'); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit($id) + { + $permohonan = Permohonan::with( + [ + 'user', + 'debiture.province', + 'debiture.city', + 'debiture.district', + 'debiture.village', + 'branch', + 'tujuanPenilaian', + ], + )->findOrFail($id); + + $jenisPenilaian = JenisPenilaian::all(); + $teamPenilai = Teams::with(['regions', 'teamsUsers'])->get(); + + $penilaian = Penilaian::where('permohonan_id', $id)->first(); + + return view('lpj::penilaian.form', compact('permohonan', 'teamPenilai', 'jenisPenilaian', 'penilaian')); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy($id) + { + // + } + + public function dataForDatatables(Request $request) + { + if (is_null($this->user) || !$this->user->can('debitur.view')) { + // abort(403, 'Sorry! You are not allowed to view users.'); + } + + + $query = Permohonan::query(); + + 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 . '%'); + }); + } + + // Filter to show only records with status 'register' + $query->where('status', 'register'); + + + if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) { + $order = $request->get('sortOrder'); + $column = $request->get('sortField'); + $query->orderBy($column, $order); + } + + $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); + } + + $filteredRecords = $query->count(); + + $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian'])->get(); + + $pageCount = ceil($totalRecords / $request->get('size')); + + $currentPage = $page; + + + return response()->json([ + 'draw' => $request->get('draw'), + 'recordsTotal' => $totalRecords, + 'recordsFiltered' => $filteredRecords, + 'pageCount' => $pageCount, + 'page' => $currentPage, + 'totalCount' => $totalRecords, + 'data' => $data, + ]); + } + + + public function getUserTeams($id) + { + $teamsUser = TeamsUsers::where('teams_id', $id)->get(); + $userIds = $teamsUser->pluck('user_id'); + $users = User::whereIn('id', $userIds)->get(); + + if ($users->isNotEmpty()) { + return response()->json($users, 200); + } + + return response()->json([], 200); + } + + + } diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php index a6b3276..2cd35d0 100644 --- a/app/Http/Controllers/PermohonanController.php +++ b/app/Http/Controllers/PermohonanController.php @@ -6,10 +6,17 @@ use Exception; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; + use Modules\Location\Models\City; + use Modules\Location\Models\District; + use Modules\Location\Models\Province; + use Modules\Location\Models\Village; use Modules\Lpj\Exports\PermohonanExport; use Modules\Lpj\Http\Requests\PermohonanRequest; use Modules\Lpj\Models\Branch; use Modules\Lpj\Models\Debiture; + use Modules\Lpj\Models\DokumenJaminan; + use Modules\Lpj\Models\JenisFasilitasKredit; + use Modules\Lpj\Models\NilaiPlafond; use Modules\Lpj\Models\Permohonan; use Modules\Lpj\Models\StatusPermohonan; use Modules\Lpj\Models\TujuanPenilaian; @@ -25,11 +32,11 @@ public function store(PermohonanRequest $request) { - $validate = $request->validated(); + $validate = $request->validated(); if ($validate) { try { - // Save to database qq + // Save to database Permohonan::create($validate); return redirect() ->route('permohonan.index') @@ -47,8 +54,8 @@ } } - public function create(){ - + public function create() + { return view('lpj::permohonan.create'); } @@ -58,21 +65,47 @@ $debitur = Debiture::find($debitur); $tujuanPenilaian = TujuanPenilaian::all(); $status = StatusPermohonan::all(); + $fasilitasKredit = JenisFasilitasKredit::all(); + $plafond = NilaiPlafond::all(); - return view('lpj::permohonan.form', compact('branches', 'debitur', 'tujuanPenilaian', 'status')); + return view( + 'lpj::permohonan.form', + compact('branches', 'debitur', 'tujuanPenilaian', 'status', 'fasilitasKredit', 'plafond'), + ); } public function edit($id) { $permohonan = Permohonan::find($id); $branches = Branch::all(); - $debitur = Debiture::find($permohonan->debiture_id); + $debitur = Debiture::find($permohonan->debiture_id); $tujuanPenilaian = TujuanPenilaian::all(); $status = StatusPermohonan::all(); + $provinces = Province::all(); + $cities = City::where('province_code', $debitur->province_code)->get(); + $districts = District::where('city_code', $debitur->city_code)->get(); + $villages = Village::where('district_code', $debitur->district_code)->get(); + $documents = DokumenJaminan::with('pemilik', 'detail')->where('debiture_id', $id)->get(); + + $fasilitasKredit = JenisFasilitasKredit::all(); + $plafond = NilaiPlafond::all(); return view( 'lpj::permohonan.form', - compact('permohonan', 'branches', 'debitur', 'tujuanPenilaian', 'status'), + compact( + 'permohonan', + 'branches', + 'debitur', + 'tujuanPenilaian', + 'status', + 'provinces', + 'cities', + 'districts', + 'villages', + 'documents', + 'fasilitasKredit', + 'plafond', + ), ); } @@ -179,4 +212,96 @@ { 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'); + } } diff --git a/app/Http/Controllers/TeamsController.php b/app/Http/Controllers/TeamsController.php index fa6fbe7..bf0a39b 100644 --- a/app/Http/Controllers/TeamsController.php +++ b/app/Http/Controllers/TeamsController.php @@ -12,6 +12,8 @@ use Modules\Lpj\Models\Teams; use Modules\Lpj\Models\TeamsUsers; use Modules\Lpj\Http\Requests\TeamsRequest; use Illuminate\Support\Facades\DB; +use Modules\Lpj\Exports\TeamPenilaianExport; +use Maatwebsite\Excel\Facades\Excel; class TeamsController extends Controller { @@ -30,8 +32,15 @@ class TeamsController extends Controller public function create() { - $region = Regions::all(); - $user = User::all(); + // cek region apakah sudah ada di tabel teams + $regionTeam = Teams::pluck('regions_id')->toArray(); + $region = Regions::whereNotIn('id', $regionTeam)->get(); + + // cek user apakah sudah ada di tabel teams_users + $userTeam = TeamsUsers::pluck('user_id')->toArray(); + $user = User::whereNotIn('id', $userTeam) + ->with('roles') + ->get(); return view('lpj::teams.form', compact('region', 'user')); } @@ -86,8 +95,14 @@ class TeamsController extends Controller public function edit($id) { $teams = Teams::find($id); + + $region = Regions::all(); - $user = User::all(); + $usedUsers = TeamsUsers::where('teams_id', '!=', $id)->pluck('user_id')->toArray(); + $user = User::whereNotIn('id', $usedUsers) + ->with('roles') + ->get(); + // Ambil user yang sudah ada di tim ini $selectedUsers = $teams->teamsUsers->pluck('user_id')->toArray(); return view('lpj::teams.form', compact('teams', 'region', 'user', 'selectedUsers')); @@ -149,32 +164,28 @@ class TeamsController extends Controller DB::commit(); - return redirect() - ->route('basicdata.teams.index') - ->with('success', 'Team has been deleted successfully.'); + echo json_encode(['success' => true, 'message' => 'Team has been deleted successfully']); + } catch (Exception $e) { DB::rollBack(); - - return redirect() - ->route('basicdata.teams.index') - ->with('error', 'Failed to delete team. '); + echo json_encode(['success' => false, 'message' => 'Failed to delete Team']); } } - public function dataForDatatables(Request $request) { - if (is_null($this->user) || !$this->user->can('debitur.view')) { + if (is_null($this->user) || !$this->user->can('teams.view')) { //abort(403, 'Sorry! You are not allowed to view users.'); } + // Inisialisasi query $query = Teams::select('teams.id as id', 'teams.name as team_name', 'regions.name as region_name') ->join('regions', 'teams.regions_id', '=', 'regions.id') ->leftJoin('teams_users', 'teams.id', '=', 'teams_users.teams_id') ->leftJoin('users', 'teams_users.user_id', '=', 'users.id') - ->addSelect('users.name as user_name'); + ->addSelect('users.id as user_id', 'users.name as user_name'); - // search filter + // Filter pencarian if ($request->has('search') && !empty($request->get('search'))) { $search = $request->get('search'); $query->where(function ($q) use ($search) { @@ -184,41 +195,43 @@ class TeamsController extends Controller }); } - // sorting + // Sorting if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) { $order = $request->get('sortOrder'); $column = $request->get('sortField'); $query->orderBy($column, $order); } + // Hitung total records $totalRecords = $query->count(); - $size = $request->get('size'); - $pageCount = 1; + // Pagination + $size = $request->get('size', 10); + $page = $request->get('page', 1); + $offset = ($page - 1) * $size; - if ($size > 0) { - if ($request->has('page') && $request->has('size')) { - $page = $request->get('page'); - $offset = ($page - 1) * $size; - $query->skip($offset)->take($size); - $filteredRecords = $query->count(); - $pageCount = ceil($totalRecords / $size); - } + // Ambil data dengan pagination + $data = $query->skip($offset)->take($size)->get(); + $filteredRecords = $data->count(); + $pageCount = ceil($totalRecords / $size); - $data = $query->get(); - } else { - $filteredRecords = $totalRecords; - $data = $query->get(); - } + // Ambil ID pengguna dari hasil query + $userIds = $data->pluck('user_id')->unique(); - $currentPage = $request->get('page') ?? 1; + // Ambil data pengguna dengan peran mereka + $users = User::whereIn('id', $userIds) + ->with('roles') + ->get() + ->keyBy('id'); - $formattedData = $data->groupBy('id')->map(function ($group) { + // Format data + $formattedData = $data->groupBy('id')->map(function ($group) use ($users) { $team = $group->first(); - $team->user_team = $group->map(function ($item) { + $team->user_team = $group->map(function ($item) use ($users) { + $user = $users->get($item->user_id); return [ 'nama' => $item->user_name, - // 'role' => $item->role_name, + 'roles' => $user ? $user->roles->pluck('name')->toArray() : [], ]; })->toArray(); return $team; @@ -229,7 +242,7 @@ class TeamsController extends Controller 'recordsTotal' => $totalRecords, 'recordsFiltered' => $filteredRecords, 'pageCount' => $pageCount, - 'page' => $currentPage, + 'page' => $page, 'totalCount' => $totalRecords, 'data' => $formattedData ]); @@ -238,4 +251,10 @@ class TeamsController extends Controller + public function export() + { + return Excel::download(new TeamPenilaianExport(), 'team-penilai.xlsx'); + } + + } diff --git a/app/Http/Requests/DebitureRequest.php b/app/Http/Requests/DebitureRequest.php index ff87263..7f83fbb 100644 --- a/app/Http/Requests/DebitureRequest.php +++ b/app/Http/Requests/DebitureRequest.php @@ -3,6 +3,7 @@ namespace Modules\Lpj\Http\Requests; use Illuminate\Foundation\Http\FormRequest; + use Modules\Lpj\Rules\UniqueCifExceptZero; class DebitureRequest extends FormRequest { @@ -21,7 +22,7 @@ 'nomor_rekening' => 'nullable|string|max:50', 'name' => 'required', 'registered_at' => 'nullable|date', - 'npwp' => 'nullable|string|max:16', + 'npwp' => 'nullable|string|min:15|max:16', 'email' => 'nullable|email', 'phone' => 'nullable|string|max:15', 'address' => 'nullable|string', @@ -29,10 +30,10 @@ 'status' => 'nullable|boolean' ]; - if ($this->method() == 'PUT') { - $rules['cif'] = 'nullable|unique:debitures,cif,' . $this->id; - } else { - $rules['cif'] = 'nullable|unique:debitures,cif'; + if($this->method() == 'PUT'){ + $rules['cif'] = ['required', new UniqueCifExceptZero($this->id)]; + }else{ + $rules['cif'] = ['required', new UniqueCifExceptZero(null)]; } return $rules; diff --git a/app/Http/Requests/JenisPenilaianRequest.php b/app/Http/Requests/JenisPenilaianRequest.php index 58562ea..f8479f0 100644 --- a/app/Http/Requests/JenisPenilaianRequest.php +++ b/app/Http/Requests/JenisPenilaianRequest.php @@ -22,8 +22,7 @@ class JenisPenilaianRequest extends FormRequest if ($this->method() == 'PUT') { - $rules['code'] = 'required|string|max:3|unique:jenis_penilaian,code,' . $this->route('id'); - + $rules['code'] = 'required|string|max:3|unique:jenis_penilaian,code,' . $this->id; } else { $rules['code'] = 'required|string|max:3|unique:jenis_penilaian,code'; diff --git a/app/Http/Requests/PenilaianRequest.php b/app/Http/Requests/PenilaianRequest.php new file mode 100644 index 0000000..6be90ac --- /dev/null +++ b/app/Http/Requests/PenilaianRequest.php @@ -0,0 +1,40 @@ + 'required|max:255', + 'teams_id' => 'required|max:255', + 'user_id' => 'required|max:255', + 'tanggal_kunjungan' => 'required|max:255', + 'status' => 'required|max:10', + 'keterangan' => 'nullable', + 'permohonan_id' => 'required', + ]; + } + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize(): bool + { + return true; + } + + protected function prepareForValidation() + { + // Menetapkan nilai default untuk 'status' jika tidak ada dalam request + $this->merge([ + 'status' => $this->status ?? 'assign', + ]); + } +} diff --git a/app/Http/Requests/PermohonanRequest.php b/app/Http/Requests/PermohonanRequest.php index e4c4bd8..edd4169 100644 --- a/app/Http/Requests/PermohonanRequest.php +++ b/app/Http/Requests/PermohonanRequest.php @@ -14,13 +14,15 @@ : array { $rules = [ - 'nomor_registrasi' => 'nullable|string|max:10', - 'tanggal_permohonan' => 'nullable|date', - 'user_id' => 'nullable|exists:users,id', - 'branch_id' => 'required|exists:branches,id', - 'tujuan_penilaian_id' => 'required|exists:tujuan_penilaian,id', - 'debiture_id' => 'required|exists:debitures,id', - 'status' => 'required|string', + 'nomor_registrasi' => 'nullable|string|max:10', + 'tanggal_permohonan' => 'nullable|date', + 'user_id' => 'nullable|exists:users,id', + 'branch_id' => 'required|exists:branches,id', + 'tujuan_penilaian_id' => 'required|exists:tujuan_penilaian,id', + 'debiture_id' => 'required|exists:debitures,id', + 'status' => 'required|string', + 'jenis_fasilitas_kredit_id' => 'required|exists:jenis_fasilitas_kredit,id', + 'nilai_plafond_id' => 'required|exists:nilai_plafond,id', ]; return $rules; diff --git a/app/Http/Requests/StatusPermohonanRequest.php b/app/Http/Requests/StatusPermohonanRequest.php index 21bd8e5..d0a9ac6 100644 --- a/app/Http/Requests/StatusPermohonanRequest.php +++ b/app/Http/Requests/StatusPermohonanRequest.php @@ -16,6 +16,7 @@ $rules = [ 'description' => 'nullable|max:255', 'status' => 'required|boolean', + 'slug' => 'nullable|max:255', ]; if ($this->method() == 'PUT') { @@ -37,9 +38,9 @@ public function prepareForValidation() { - $this->merge([ + return $this->merge([ 'status' => isset($this->status) ? 1 : 0, - 'slug'=> Str::slug($this->name) + 'slug' => Str::slug($this->name), ]); } } diff --git a/app/Http/Requests/TeamsRequest.php b/app/Http/Requests/TeamsRequest.php index 0f1be4b..c77f4a5 100644 --- a/app/Http/Requests/TeamsRequest.php +++ b/app/Http/Requests/TeamsRequest.php @@ -14,7 +14,7 @@ class TeamsRequest extends FormRequest $rules = [ 'name' => 'required|string|max:255', 'status' => 'nullable|boolean', - 'regions_id' => 'nullable|exists:regions,id', + 'regions_id' => 'required|nullable|exists:regions,id', 'user.*' => 'nullable|exists:users,id', 'authorized_at' => 'nullable|datetime', 'authorized_status' => 'nullable|string|max:1', diff --git a/app/Models/Debiture.php b/app/Models/Debiture.php index df5b9d2..8980513 100644 --- a/app/Models/Debiture.php +++ b/app/Models/Debiture.php @@ -56,4 +56,8 @@ return $this->belongsTo(Village::class, 'village_code', 'code'); } + public function documents(){ + return $this->hasMany(DokumenJaminan::class); + } + } diff --git a/app/Models/DokumenJaminan.php b/app/Models/DokumenJaminan.php index 274f3c8..3454dc9 100644 --- a/app/Models/DokumenJaminan.php +++ b/app/Models/DokumenJaminan.php @@ -63,4 +63,8 @@ public function permohonan(){ return $this->belongsTo(Permohonan::class, 'permohonan_id', 'id'); } + + public function detail(){ + return $this->hasMany(DetailDokumenJaminan::class, 'dokumen_jaminan_id', 'id'); + } } diff --git a/app/Models/Penilaian.php b/app/Models/Penilaian.php index e4d6bdd..34a5098 100644 --- a/app/Models/Penilaian.php +++ b/app/Models/Penilaian.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Modules\Lpj\Database\Factories\PenilaianFactory; use Modules\Lpj\Models\JenisPenilaian; use Modules\Lpj\Models\Teams; -// use Modules\Usermanagement\Models\User; +use Modules\Usermanagement\Models\User; class Penilaian extends Model { @@ -17,7 +17,7 @@ class Penilaian extends Model */ protected $table = 'penilaian'; protected $fillable = [ - 'jenis_penilaian_id', 'team_id', 'user_id', 'tanggal_kunjungan', 'keterangan', + 'jenis_penilaian_id', 'teams_id', 'user_id', 'tanggal_kunjungan', 'keterangan','permohonan_id', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_at', 'created_by', 'updated_at', 'updated_by', 'deleted_at', 'deleted_by' ]; @@ -27,12 +27,12 @@ class Penilaian extends Model } public function teams(){ - return $this->belongsTo(Teams::class, 'team_id', 'id'); + return $this->belongsTo(Teams::class, 'teams_id', 'id'); } - // public function users(){ - // return $this->belongsTo(User::class, 'user_id', 'id'); - // } + public function users(){ + return $this->belongsTo(User::class, 'user_id', 'id'); + } } diff --git a/app/Models/Permohonan.php b/app/Models/Permohonan.php index 28b6de5..cf6d5e6 100644 --- a/app/Models/Permohonan.php +++ b/app/Models/Permohonan.php @@ -17,10 +17,14 @@ class Permohonan extends Base 'branch_id', 'tujuan_penilaian_id', 'debiture_id', + 'keterangan', + 'jenis_fasilitas_kredit_id', + 'nilai_plafond_id', 'status', 'authorized_at', 'authorized_status', 'authorized_by', + ]; public function user(){ @@ -42,4 +46,12 @@ class Permohonan extends Base public function documents(){ return $this->hasMany(DokumenJaminan::class); } + + public function nilaiPlafond(){ + return $this->belongsTo(NilaiPlafond::class); + } + + public function jenisFasilitasKredit(){ + return $this->belongsTo(JenisFasilitasKredit::class); + } } diff --git a/app/Rules/UniqueCifExceptZero.php b/app/Rules/UniqueCifExceptZero.php new file mode 100644 index 0000000..e7236ce --- /dev/null +++ b/app/Rules/UniqueCifExceptZero.php @@ -0,0 +1,25 @@ +id = $id; + } + + public function validate($attribute, $value, $fail): void + { + if (Debiture::where($attribute, $value) + ->where('id', '!=', $this->id) + ->where($attribute, '!=', '000000') + ->exists()) { + $fail('The :attribute field must be uniquse.'.$this->id); + } + } +} diff --git a/database/migrations/2024_08_12_023807_create_debitures_table.php b/database/migrations/2024_08_12_023807_create_debitures_table.php deleted file mode 100644 index 583c859..0000000 --- a/database/migrations/2024_08_12_023807_create_debitures_table.php +++ /dev/null @@ -1,54 +0,0 @@ -id(); - $table->foreignIdFor(Branch::class)->constrained()->onDelete('cascade'); - $table->string('cif', 10)->unique(); - $table->string('name'); - $table->date('registered_at')->nullable(); - $table->string('npwp', 16)->nullable(); - $table->string('nomor_id', 16)->nullable(); - $table->string('email', 100)->nullable(); - $table->string('phone', 15)->nullable(); - $table->string('nomor_rekening', 50)->nullable(); - $table->string('province_code')->nullable()->index(); - $table->string('city_code')->nullable()->index(); - $table->string('district_code')->nullable()->index(); - $table->string('village_code')->nullable()->index(); - $table->string('postal_code', 5)->nullable(); - $table->text('address')->nullable(); - - $table->boolean('status')->default(true)->nullable(); - $table->timestamps(); - $table->timestamp('authorized_at')->nullable(); - $table->char('authorized_status', 1)->nullable(); - $table->softDeletes(); - - $table->unsignedBigInteger('created_by')->nullable(); - $table->unsignedBigInteger('updated_by')->nullable(); - $table->unsignedBigInteger('deleted_by')->nullable(); - $table->unsignedBigInteger('authorized_by')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down() - : void - { - Schema::dropIfExists('debitures'); - } - }; diff --git a/database/migrations/2024_09_04_082059_update_jenis_jaminan_table.php b/database/migrations/2024_09_04_082059_update_jenis_jaminan_table.php index 0f96b67..f148718 100644 --- a/database/migrations/2024_09_04_082059_update_jenis_jaminan_table.php +++ b/database/migrations/2024_09_04_082059_update_jenis_jaminan_table.php @@ -12,6 +12,7 @@ return new class extends Migration public function up(): void { Schema::table('jenis_jaminan', function (Blueprint $table) { + $table->string('slug')->after('name'); $table->string('jenis_legalitas_jaminan_id')->nullable()->after('slug'); }); } @@ -22,6 +23,7 @@ return new class extends Migration public function down(): void { Schema::table('jenis_jaminan', function (Blueprint $table) { + $table->dropColumn('slug'); $table->dropColumn('jenis_legalitas_jaminan_id'); }); } diff --git a/database/migrations/2024_09_05_070712_create_penilaian_table.php b/database/migrations/2024_09_05_070712_create_penilaian_table.php index 9764f04..da22785 100644 --- a/database/migrations/2024_09_05_070712_create_penilaian_table.php +++ b/database/migrations/2024_09_05_070712_create_penilaian_table.php @@ -6,8 +6,7 @@ use Illuminate\Support\Facades\Schema; use Modules\Lpj\Models\JenisPenilaian; use Modules\Lpj\Models\Teams; -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. */ @@ -19,8 +18,9 @@ return new class extends Migration $table->foreignIdFor(Teams::class); $table->unsignedBigInteger('user_id'); $table->datetime('tanggal_kunjungan'); - $table->text('keterangan'); + $table->text('keterangan')->nullable(); $table->char('status'); + $table->integer('permohonan_id'); $table->timestamps(); $table->char('authorized_status', 1)->nullable(); $table->timestamp('authorized_at')->nullable(); diff --git a/database/migrations/2024_09_13_030119_update_permohonan_table.php b/database/migrations/2024_09_13_030119_update_permohonan_table.php new file mode 100644 index 0000000..1906224 --- /dev/null +++ b/database/migrations/2024_09_13_030119_update_permohonan_table.php @@ -0,0 +1,33 @@ +foreignIdFor(JenisFasilitasKredit::class)->nullable()->onDelete('cascade'); + $table->foreignIdFor(NilaiPlafond::class)->nullable()->onDelete('cascade'); + $table->string('status')->default('order')->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('permohonan', function (Blueprint $table) { + $table->dropForeign(['fasilitas_kredit_id']); + $table->dropForeign(['nilai_plafond_id']); + }); + } +}; diff --git a/module.json b/module.json index 568f490..f2c4211 100644 --- a/module.json +++ b/module.json @@ -20,6 +20,7 @@ "permission": "", "roles": [ "Administrator" + ] }, { @@ -46,7 +47,18 @@ }, { "title": "Authorization", - "path": "", + "path": "authorization", + "icon": "ki-filled ki-some-files text-lg", + "classes": "", + "attributes": [], + "permission": "", + "roles": [ + "Administrator" + ] + }, + { + "title": "Assignment", + "path": "penilaian", "icon": "ki-filled ki-some-files text-lg", "classes": "", "attributes": [], @@ -111,17 +123,9 @@ "permission": "", "roles": [] }, - { - "title": "Jenis Jaminan", - "path": "basicdata.jenis-jaminan", - "classes": "", - "attributes": [], - "permission": "", - "roles": [] - }, { "title": "Jenis Aset", - "path": "basicdata.jenis-aset", + "path": "basicdata.jenis-jaminan", "classes": "", "attributes": [], "permission": "", @@ -201,7 +205,7 @@ }, { "title": "Jenis Penilaian", - "path": "basicdata.jenispenilaian", + "path": "basicdata.jenis-penilaian", "classes": "", "attributes": [], "permission": "", diff --git a/resources/views/debitur/components/debitur.blade.php b/resources/views/debitur/components/debitur.blade.php index 8170af7..157ad1b 100644 --- a/resources/views/debitur/components/debitur.blade.php +++ b/resources/views/debitur/components/debitur.blade.php @@ -1,5 +1,6 @@