diff --git a/app/Http/Controllers/PenilaiController.php b/app/Http/Controllers/PenilaiController.php index 130df75..02b983b 100644 --- a/app/Http/Controllers/PenilaiController.php +++ b/app/Http/Controllers/PenilaiController.php @@ -403,8 +403,8 @@ class PenilaiController extends Controller $jaminanId = $request->query('jaminanId'); $provinces = Province::all(); $permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId); - // $nomorLaporan = $this->generateNoLaporan($permohonan, $documentId, 'rap'); - // $basicData = $this->surveyorController->getCommonData(); + $nomorLaporan = $this->generateNoLaporan($permohonan, $documentId, 'call-report'); + $basicData = $this->surveyorController->getCommonData(); // $inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first(); // Penilai::updateOrCreate( // [ @@ -462,7 +462,7 @@ class PenilaiController extends Controller // return view('lpj::penilai.components.call-report', compact('permohonan', 'rap', 'provinces', 'cities', // 'districts', // 'villages','forminspeksi', 'noLpRAP', 'basicData','cekAlamat')); - return view('lpj::penilai.components.call-report', compact('permohonan')); + return view('lpj::penilai.components.call-report', compact('permohonan','basicData', 'nomorLaporan')); } /** @@ -1183,7 +1183,7 @@ class PenilaiController extends Controller public function generateNoLaporan($permohonan, $documentId, $type) { - $typeMapping = ['lpj' => 'LPJ', 'memo' => 'MAK', 'rap' => 'RAP']; + $typeMapping = ['lpj' => 'LPJ', 'memo' => 'MAK', 'rap' => 'RAP', 'call-report' => 'CR']; // Cek apakah data sudah ada $laporan = Laporan::where([ diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php index 76f7ce3..51e6f0e 100644 --- a/app/Http/Controllers/PermohonanController.php +++ b/app/Http/Controllers/PermohonanController.php @@ -1,407 +1,481 @@ historyService = $historyService; + } - public function __construct(PermohonanHistoryService $historyService) - { - $this->historyService = $historyService; - } + public function index() + { + return view('lpj::permohonan.index'); + } - public function index() - { - return view('lpj::permohonan.index'); - } - - public function store(PermohonanRequest $request) - { - $validate = $request->validated(); - if ($validate) { - try { - // Process file upload - $filePath = null; - if ($request->hasFile('attachment')) { - $file = $request->file('attachment'); - $fileName = time() . '_' . $file->getClientOriginalName(); - $filePath = $file->storeAs('permohonan_attachments', $fileName, 'public'); - } - - // Get keterangan if provided - $keterangan = $request->input('keterangan') ?? null; - - - // Save to database - $permohonan = Permohonan::create($validate); - - // Create history - $this->historyService->createHistory( - $permohonan, - $validate['status'], - $keterangan, - [], // beforeRequest is empty for new permohonan - $permohonan->toArray(), - $filePath, - ); - - $documents = DokumenJaminan::where('permohonan_id', $permohonan->id)->get(); - if(count($documents)<1){ - return redirect()->route('debitur.jaminan.create', array_merge(['permohonan_id'=>$permohonan->id],['id'=> $permohonan->debiture->id]))->with('success', 'Permohonan created successfully, Lengkapi data jaminan terlebih dahulu'); - } - return redirect() - ->route('permohonan.index')->with('success', 'Permohonan created successfully'); - } catch (Exception $e) { - return redirect() - ->route('permohonan.create')->with('error', 'Failed to create permohonan' . $e->getMessage()); + public function store(PermohonanRequest $request) + { + $validate = $request->validated(); + if ($validate) { + try { + // Process file upload + $filePath = null; + if ($request->hasFile('attachment')) { + $file = $request->file('attachment'); + $fileName = time() . '_' . $file->getClientOriginalName(); + $filePath = $file->storeAs('permohonan_attachments', $fileName, 'public'); + } + + // Get keterangan if provided + $keterangan = $request->input('keterangan') ?? null; + + + // Save to database + $permohonan = Permohonan::create($validate); + + // Create history + $this->historyService->createHistory( + $permohonan, + $validate['status'], + $keterangan, + [], // beforeRequest is empty for new permohonan + $permohonan->toArray(), + $filePath, + ); + + $documents = DokumenJaminan::where('permohonan_id', $permohonan->id)->get(); + if (count($documents) < 1) { + return redirect()->route('debitur.jaminan.create', array_merge(['permohonan_id' => $permohonan->id], ['id' => $permohonan->debiture->id]))->with('success', 'Permohonan created successfully, Lengkapi data jaminan terlebih dahulu'); } - } else { return redirect() - ->route('permohonan.create')->with('success', 'error naon iye')->withInput(); + ->route('permohonan.index')->with('success', 'Permohonan created successfully'); + } catch (Exception $e) { + return redirect() + ->route('permohonan.create')->with('error', 'Failed to create permohonan' . $e->getMessage()); } + } else { + return redirect() + ->route('permohonan.create')->with('success', 'error naon iye')->withInput(); } + } - public function create() - { - return view('lpj::permohonan.create'); - } + public function create() + { + return view('lpj::permohonan.create'); + } - public function createPermohonan($debitur) - { - $branches = Branch::all(); - $debitur = Debiture::find($debitur); - $tujuanPenilaian = TujuanPenilaian::all(); - $status = StatusPermohonan::all(); - $fasilitasKredit = JenisFasilitasKredit::all(); - $plafond = NilaiPlafond::all(); + public function createPermohonan($debitur) + { + $branches = Branch::all(); + $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', 'fasilitasKredit', 'plafond'), - ); - } + 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); - $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(); + public function edit($id) + { + $permohonan = Permohonan::find($id); + $branches = Branch::all(); + $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(); + $fasilitasKredit = JenisFasilitasKredit::all(); + $plafond = NilaiPlafond::all(); - return view( - 'lpj::permohonan.form', - compact( - 'permohonan', - 'branches', - 'debitur', - 'tujuanPenilaian', - 'status', - 'provinces', - 'cities', - 'districts', - 'villages', - 'documents', - 'fasilitasKredit', - 'plafond', - ), - ); - } + return view( + 'lpj::permohonan.form', + compact( + 'permohonan', + 'branches', + 'debitur', + 'tujuanPenilaian', + 'status', + 'provinces', + 'cities', + 'districts', + 'villages', + 'documents', + 'fasilitasKredit', + 'plafond', + ), + ); + } - public function update(PermohonanRequest $request, $id) - { - $permohonan = Permohonan::findOrFail($id); - $beforeRequest = $permohonan->toArray(); + public function update(PermohonanRequest $request, $id) + { + $permohonan = Permohonan::findOrFail($id); + $beforeRequest = $permohonan->toArray(); - $validate = $request->validated(); - if ($validate) { - try { - // Update in database + $validate = $request->validated(); + if ($validate) { + try { + // Update in database - if ($permohonan->status == 'revisi') { - $validate['status'] = 'order'; - } - $permohonan->update($validate); - - $documents = DokumenJaminan::where('permohonan_id', $permohonan->id)->get(); - if(count($documents)<1){ - return redirect()->route('debitur.jaminan.create', array_merge(['permohonan_id'=>$permohonan->id],['id'=> $permohonan->debiture->id]))->with('success', 'Permohonan created successfully, Lengkapi data jaminan terlebih dahulu'); - } - - return redirect() - ->route('permohonan.index')->with('success', 'Permohonan updated successfully'); - } catch (Exception $e) { - return redirect() - ->route('permohonan.edit', $id)->with('error', 'Failed to update permohonan'); + if ($permohonan->status == 'revisi') { + $validate['status'] = 'order'; } - } - } + $permohonan->update($validate); - public function destroy($id) - { - try { - // Delete from database - $permohonan = Permohonan::find($id); - $permohonan->delete(); + $documents = DokumenJaminan::where('permohonan_id', $permohonan->id)->get(); + if (count($documents) < 1) { + return redirect()->route('debitur.jaminan.create', array_merge(['permohonan_id' => $permohonan->id], ['id' => $permohonan->debiture->id]))->with('success', 'Permohonan created successfully, Lengkapi data jaminan terlebih dahulu'); + } - echo json_encode(['success' => true, 'message' => 'Permohonan deleted successfully']); + return redirect() + ->route('permohonan.index')->with('success', 'Permohonan updated successfully'); } catch (Exception $e) { - echo json_encode(['success' => false, 'message' => 'Failed to delete permohonan']); + return redirect() + ->route('permohonan.edit', $id)->with('error', 'Failed to update permohonan'); } } + } - 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.'); - } - - // Retrieve data from the database - $query = Permohonan::query(); - - if(!Auth::user()->hasAnyRole(['administrator'])) { - $query = $query->where('branch_id', Auth::user()->branch_id); - } - - $query = $query->orderBy('nomor_registrasi', 'desc'); - // 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(); - $size = $request->get('size', 10); - if ($size == 0) { - $size = 10; - } - - // 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', 'penilaian','documents'])->get(); - - // Calculate the page count - $pageCount = ceil($totalRecords / $size); - - // Calculate the current page number - $currentPage = max(1, $request->get('page', 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 export() - { - 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()->with('documents')->has('documents', '>', 0)->where('status', '=', 'order'); - - // 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'])->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) - { + public function destroy($id) + { + try { + // Delete from database $permohonan = Permohonan::find($id); - return view('lpj::permohonan.authorization.show', compact('permohonan')); + $permohonan->delete(); + + echo json_encode(['success' => true, 'message' => 'Permohonan deleted successfully']); + } catch (Exception $e) { + echo json_encode(['success' => false, 'message' => 'Failed to delete permohonan']); + } + } + + 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.'); } - public function updateAuthorization(Request $request, $id) - { + // Retrieve data from the database + $query = Permohonan::query(); + + if (!Auth::user()->hasAnyRole(['administrator'])) { + $query = $query->where('branch_id', Auth::user()->branch_id); + } + + $query = $query->orderBy('nomor_registrasi', 'desc'); + // 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(); + $size = $request->get('size', 10); + if ($size == 0) { + $size = 10; + } + + // 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', 'penilaian','documents'])->get(); + + // Calculate the page count + $pageCount = ceil($totalRecords / $size); + + // Calculate the current page number + $currentPage = max(1, $request->get('page', 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 export() + { + 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()->with('documents')->has('documents', '>', 0)->where('status', '=', 'order'); + + // 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'])->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'); + } + + public function show($id) + { + $permohonan = Permohonan::find($id); + + return view('lpj::permohonan.show', compact('permohonan')); + } + + public function print($id) + { + $permohonan = Permohonan::find($id); + return view('lpj::permohonan.print', compact('permohonan')); + + // $pdf = Pdf::loadView('lpj::permohonan.print', compact('permohonan')); + // return $pdf->stream(); + } + + public function showPembatalan($id) + { + $permohonan = Permohonan::with(['pembatalan','debiture'])->findOrFail($id); + return view('lpj::permohonan.pembatalan-form', compact('permohonan')); + } + + + public function pembatalan(Request $request) + { + // Validate the request + $validatedData = $request->validate([ + 'permohonan_id' => 'required|exists:permohonan,id', + 'alasan_pembatalan' => 'required|string', + 'file_pembatalan' => 'required|file|mimes:pdf,doc,docx|max:2048', + ]); + + // Handle file upload + if ($request->hasFile('file_pembatalan')) { + $file = $request->file('file_pembatalan'); + $filename = time() . '_' . $file->getClientOriginalName(); + $filePath = $file->storeAs('pembatalan', $filename, 'public'); + $validatedData['file_pembatalan'] = $filePath; + } + + // Add created_by + $validatedData['created_by'] = auth()->id(); + + // Create new PermohonanPembatalan + $pembatalan = PermohonanPembatalan::create($validatedData); + + return redirect()->route('permohonan.index')->with('success', 'Pembatalan Permohonan Menunggu Approval'); + } + + public function storeAproved(Request $request, $id): JsonResponse + { + $data = []; + if (request()->ajax()) { 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'); + $penilaian = Penilaian::findOrFail($id); + $penilaian->update([ + 'authorized_status' => 1, + ]); + + $permohonan = Permohonan::findOrFail($request->permohonan_id); + + $permohonan->update([ + 'status' => 'proses-survey' + ]); + + $data['status'] = 'success'; + $data['message'] = 'Jadwal '.$request->noReg.' berhasil di aprove'; + } catch (\Exception $e) { + $data['status'] = 'error'; + $data['message'] = 'Gagal membuat jadwal: ' . $e->getMessage(); } - return redirect()->route('authorization.index')->with('success', 'Permohonan updated successfully'); + } else { + $data['status'] = 'error'; + $data['message'] = "no ajax request"; } - public function show($id) - { - $permohonan = Permohonan::find($id); - - return view('lpj::permohonan.show', compact('permohonan')); - } - - public function print($id) - { - $permohonan = Permohonan::find($id); - return view('lpj::permohonan.print', compact('permohonan')); - - // $pdf = Pdf::loadView('lpj::permohonan.print', compact('permohonan')); - // return $pdf->stream(); - } - - public function showPembatalan($id) - { - $permohonan = Permohonan::with(['pembatalan','debiture'])->findOrFail($id); - return view('lpj::permohonan.pembatalan-form', compact('permohonan')); - } + return response()->json($data); + } - public function pembatalan(Request $request) - { - // Validate the request + public function storeRescheduleSurvey(Request $request, $id) + { + try { $validatedData = $request->validate([ 'permohonan_id' => 'required|exists:permohonan,id', - 'alasan_pembatalan' => 'required|string', - 'file_pembatalan' => 'required|file|mimes:pdf,doc,docx|max:2048', + 'penilaian_id' => 'nullable', + 'nomor_registrasi' => 'required', + 'reschedule_note' => 'required', + 'reschedule_date' => 'required', ]); - // Handle file upload - if ($request->hasFile('file_pembatalan')) { - $file = $request->file('file_pembatalan'); - $filename = time() . '_' . $file->getClientOriginalName(); - $filePath = $file->storeAs('pembatalan', $filename, 'public'); - $validatedData['file_pembatalan'] = $filePath; - } + DB::beginTransaction(); - // Add created_by - $validatedData['created_by'] = auth()->id(); + $permohonan = Permohonan::findOrFail($request->permohonan_id); + $permohonan->update([ + 'status' => 'request-reschedule' + ]); - // Create new PermohonanPembatalan - $pembatalan = PermohonanPembatalan::create($validatedData); + $penilaian = Penilaian::findOrFail($id); - return redirect()->route('permohonan.index')->with('success', 'Pembatalan Permohonan Menunggu Approval'); + $penilaian->update([ + 'reschedule_date' => $request->reschedule_date, + 'reschedule_note' => $request->reschedule_note, + ]); + + DB::commit(); + return response()->json([ + 'status' => 'success', + 'message' => 'Proses request reschedule permohonan Nomor registrasi '.$request->nomor_registrasi.' berhasil', + ]); + } catch (\Exception $e) { + DB::rollBack(); + return response()->json([ + 'status' => 'error', + 'message' => 'Gagal membuat request reschedule: ' . $e->getMessage(), + ]); } - } + +} diff --git a/app/Http/Controllers/SurveyorController.php b/app/Http/Controllers/SurveyorController.php index c929a95..08cca8f 100644 --- a/app/Http/Controllers/SurveyorController.php +++ b/app/Http/Controllers/SurveyorController.php @@ -929,46 +929,14 @@ class SurveyorController extends Controller ->route('surveyor.index') ->with('success', 'Jadwal berhasil dibuat.'); } catch (\Exception $e) { + \Log::error('Error sending email: ' . $e->getMessage()); return redirect() ->route('surveyor.index') - ->with('error', 'Tanggal dan catatan tidak boleh kosong'); + ->with('error', 'Internal Server Error: ' . $e->getMessage()); } } - - public function storeAproved(Request $request, $id): JsonResponse - { - $data = []; - if (request()->ajax()) { - try { - $penilaian = Penilaian::findOrFail($id); - $penilaian->update([ - 'authorized_status' => 1, - ]); - - $permohonan = Permohonan::findOrFail($request->permohonan_id); - - $permohonan->update([ - 'status' => 'survey' - ]); - - $data['status'] = 'success'; - $data['message'] = 'Jadwal '.$request->noReg.' berhasil di aprove'; - } catch (\Exception $e) { - $data['status'] = 'error'; - $data['message'] = 'Gagal membuat jadwal: ' . $e->getMessage(); - } - - } else { - $data['status'] = 'error'; - $data['message'] = "no ajax request"; - } - - return response()->json($data); - } - - public function storeFreeze($id, Request $request) { try { @@ -2048,7 +2016,7 @@ class SurveyorController extends Controller }); } - $query->whereRaw('LOWER(status) IN (?, ?)', ['assign', 'survey']); + $query->whereRaw('LOWER(status) IN (?, ?, ?, ?, ?, ? ,?)', ['assign', 'survey', 'proses-survey', 'request-reschedule', 'reschedule', 'rejected-reschedule', 'approved-reschedule' ]); if (!Auth::user()->hasRole('administrator')) { @@ -3553,5 +3521,117 @@ class SurveyorController extends Controller return $pdf->download($fileName); } + public function approveReschedule(Request $request, $id) + { + try { + // Validasi data yang diterima + $validatedData = $request->validate([ + 'permohonan_id' => 'required|exists:permohonan,id', + 'nomor_registrasi' => 'required' + ]); + // Memulai transaksi + DB::beginTransaction(); + + // Update status permohonan menjadi "reschedule" + $permohonan = Permohonan::findOrFail($validatedData['permohonan_id']); + $permohonan->update([ + 'status' => 'approved-reschedule', + ]); + + // Update data penilaian dengan waktu reschedule + $penilaian = Penilaian::findOrFail($id); + $penilaian->update([ + 'waktu_penilaian' => $penilaian->reschedule_date, + ]); + + // Commit transaksi + DB::commit(); + + return response()->json([ + 'status' => 'success', + 'message' => 'Reschedule jadwal dengan nomor registrasi ' . $validatedData['nomor_registrasi'] . ' berhasil disetujui.', + ]); + } catch (\Exception $e) { + // Rollback jika ada error + DB::rollBack(); + return response()->json([ + 'status' => 'error', + 'message' => 'Gagal menyetujui reschedule: ' . $e->getMessage(), + ], 500); + } + } + + /** + * Reject reschedule request. + */ + public function rejectReschedule(Request $request, $id) + { + try { + // Validasi data yang diterima + $validatedData = $request->validate([ + 'permohonan_id' => 'required|exists:permohonan,id', + 'rejected_note' => 'required|string|max:255', + 'nomor_registrasi' => 'required|string', + ]); + + // Memulai transaksi + DB::beginTransaction(); + + // Update status permohonan menjadi "rejected-reschedule" + $permohonan = Permohonan::findOrFail($validatedData['permohonan_id']); + $permohonan->update([ + 'status' => 'rejected-reschedule', + ]); + + // Update data penilaian dengan catatan penolakan + $penilaian = Penilaian::findOrFail($id); + $penilaian->update([ + 'rejected_note' => $validatedData['rejected_note'], + ]); + + // Commit transaksi + DB::commit(); + + return response()->json([ + 'status' => 'success', + 'message' => 'Reschedule jadwal dengan nomor registrasi ' . $validatedData['nomor_registrasi'] . ' berhasil ditolak dengan alasan: ' . $validatedData['rejected_note'], + ]); + } catch (\Exception $e) { + // Rollback jika ada error + DB::rollBack(); + return response()->json([ + 'status' => 'error', + 'message' => 'Gagal menolak reschedule: ' . $e->getMessage(), + ], 500); + } + } + + public function storeProsesSurvey(Request $request, $id) + { + try { + + $validated = $request->validate([ + 'permohonan_id' => 'required|integer|exists:permohonan,id', + ]); + + + $permohonan = Permohonan::findOrFail($id); + + $permohonan->status = 'survey'; + $permohonan->save(); + + // Berikan respons JSON + return response()->json([ + 'status' => 'success', + 'message' => 'Status permohonan berhasil diubah menjadi "survey".', + ]); + } catch (\Exception $e) { + // Tangani error + return response()->json([ + 'status' => 'error', + 'message' => $e->getMessage(), + ], 500); + } + } } diff --git a/app/Models/Penilaian.php b/app/Models/Penilaian.php index a3f02c5..7383245 100644 --- a/app/Models/Penilaian.php +++ b/app/Models/Penilaian.php @@ -19,7 +19,7 @@ class Penilaian extends Model protected $fillable = [ 'jenis_penilaian_id', 'penilaian_id', 'tanggal_kunjungan', 'keterangan','nomor_registrasi', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_at', - 'created_by', 'updated_at', 'updated_by', 'deleted_at', 'deleted_by','waktu_penilaian', 'deskripsi_penilaian' + 'created_by', 'updated_at', 'updated_by', 'deleted_at', 'deleted_by','waktu_penilaian', 'deskripsi_penilaian', 'reschedule_date','reschedule_note','rejected_note' ]; public function jenis_penilaian() diff --git a/database/migrations/2025_02_12_071426_update_penilaian_table_add_reschedule_columns.php b/database/migrations/2025_02_12_071426_update_penilaian_table_add_reschedule_columns.php new file mode 100644 index 0000000..d0db3ec --- /dev/null +++ b/database/migrations/2025_02_12_071426_update_penilaian_table_add_reschedule_columns.php @@ -0,0 +1,30 @@ +datetime('reschedule_date')->nullable()->after('waktu_penilaian'); + $table->text('reschedule_note')->nullable()->after('reschedule_date'); + $table->text('rejected_note')->nullable()->after('reschedule_note'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('penilaian', function (Blueprint $table) { + $table->dropColumn(['reschedule_date', 'reschedule_note', 'rejected_note']); + }); + } +}; diff --git a/resources/views/penilai/components/call-report.blade.php b/resources/views/penilai/components/call-report.blade.php index 6685408..f10797d 100644 --- a/resources/views/penilai/components/call-report.blade.php +++ b/resources/views/penilai/components/call-report.blade.php @@ -6,13 +6,15 @@ @section('content')
- @php + @php $senior_officer = null; + $jenisJaminan = null; if ($permohonan->debiture && $permohonan->documents) { foreach ($permohonan->documents as $dokumen) { $penilai = $permohonan->penilaian->userPenilai->where('role', 'penilai')->first(); $teams = $permohonan->region->teams; + $jenisJaminan = $dokumen->jenisJaminan->name; if ($teams) { foreach ($teams as $team) { $team_users = $team->teamsUsers; @@ -35,8 +37,8 @@ @endphp
@csrf - - + + @@ -62,7 +64,7 @@
+ value="{{ $callReport['dari'] ?? $permohonan->branch->name ?? "" }}">
@@ -92,11 +94,14 @@
+ +

Menindak lanjuti permintaan - {{$permohonan->tujuanPenilaian->name ?? ''}}, BAG CABang {{ $permohonan->branch->name }} - disampaikan hal sebagai berikut: + {{ $permohonan->tujuanPenilaian->name ?? '' }}, BAG CABang + {{ $permohonan->branch->name }} + disampaikan hal sebagai berikut:

@@ -105,72 +110,47 @@
- +
- +
- +
- +
- - +
-
- -
- -
-
-
- -
- -
-
-
- +
-
@@ -178,16 +158,14 @@
+ placeholder="Masukkan likuidasi" value="{{ old('likuidasi') }}">
- +
- +
@@ -202,7 +180,8 @@
-

Penilaian ke lokasi objek telah dilakukan oleh : +

Penilaian ke lokasi objek telah dilakukan oleh + :

@@ -215,7 +194,7 @@
+ value="{{ $penilai->userPenilaiTeam->name ?? '' }}" @readonly(true)>
@@ -224,24 +203,25 @@
+ value="{{$forminspeksi['signature']['kjjp']['name'] ?? ''}}" @readonly(true) placeholder="Masukkan Nama KJPP">
+ + placeholder="Masukkan Pihak Bag" value="{{ $permohonan->user->name ?? '' }} || {{ $permohonan->branch->name }}" + @readonly(true)>
- +
-
@@ -274,7 +254,8 @@ @else
-
@@ -302,7 +283,8 @@ @else
- diff --git a/resources/views/permohonan/index.blade.php b/resources/views/permohonan/index.blade.php index 4cf4a9c..38522d5 100644 --- a/resources/views/permohonan/index.blade.php +++ b/resources/views/permohonan/index.blade.php @@ -8,7 +8,7 @@
+ data-datatable-state-save="false" id="permohonan-table" data-api-url="{{ route('permohonan.datatables') }}">

Daftar Permohonan @@ -29,46 +29,46 @@
+ data-datatable-table="true"> - - - - - - - - - - - - + + + + + + + + + + + +
- - - Nomor Registrasi - - - Tanggal Permohonan - - - User Pemohon - - - Cabang Pemohon - - - Debitur - - - Tujuan Penilaian - - - Status - - - Keterangan - - Action
+ + + Nomor Registrasi + + + Tanggal Permohonan + + + User Pemohon + + + Cabang Pemohon + + + Debitur + + + Tujuan Penilaian + + + Status + + + Keterangan + + Action
@@ -189,7 +189,7 @@ title: 'Status', render: (item, data) => { console.log(data.documents.length); - if(data.documents.length > 0) { + if (data.documents.length > 0) { return `${data.status}`; } return `Lengkapi Aset Jaminan`; @@ -204,8 +204,15 @@ render: (item, data) => { let actionHtml = `
`; + if (data.status === 'proses-survey' || data.status == 'rejected-reschedule') { + actionHtml += ` + + + `; + } + if (data && data.penilaian && data.penilaian.waktu_penilaian !== null && data.status !== - 'done' && data.penilaian.authorized_status == null) { + 'done' && data.penilaian.authorized_status == null || data.status === 'approved-reschedule') { actionHtml += ` @@ -225,12 +232,15 @@ `; - if(data.status !== 'batal') { + if (data.status !== 'batal') { actionHtml += ` `; + } + + actionHtml += `
`; return actionHtml; @@ -241,14 +251,14 @@ let dataTable = new KTDataTable(element, dataTableOptions); // Custom search functionality - searchInput.addEventListener('input', function () { + searchInput.addEventListener('input', function() { const searchValue = this.value.trim(); dataTable.search(searchValue, true); }); @endpush diff --git a/resources/views/surveyor/components/bangunan.blade.php b/resources/views/surveyor/components/bangunan.blade.php index 0869965..7b2e2fa 100644 --- a/resources/views/surveyor/components/bangunan.blade.php +++ b/resources/views/surveyor/components/bangunan.blade.php @@ -16,7 +16,7 @@ $luas_bangunan = 'N/A'; if ($item->detail) { foreach ($item->detail as $luas) { - if (isset($luas->name) && $luas->name === 'IMB') { + if (isset($luas->name) && $luas->jenis_legalitas_jaminan_id === 10) { $details = json_decode($luas->details, true); $luas_bangunan = isset($details['luas_bangunan']) ? $details['luas_bangunan'] : 'N/A'; break; diff --git a/resources/views/surveyor/components/header.blade.php b/resources/views/surveyor/components/header.blade.php index 2c0a7ca..40d1c94 100644 --- a/resources/views/surveyor/components/header.blade.php +++ b/resources/views/surveyor/components/header.blade.php @@ -471,7 +471,7 @@
+ value="{{ isset($permohonan->debiture->city) ? strtolower($permohonan->debiture->city->name) : '' }}">
{ + // Ubah nama kota menjadi lowercase + const cityNameLowercase = city.name.toLowerCase(); + + // Tambahkan opsi ke dropdown + const option = document.createElement("option"); + option.value = city.code; + option.textContent = cityNameLowercase; // Nama dalam lowercase + citySelect.appendChild(option); + }); + } else { + console.error("Element with ID 'city_code' not found."); + } + } + document.addEventListener('DOMContentLoaded', () => { loadSavedLocationData(); + loadCities(); }); - // Fungsi untuk memuat data lokasi yang tersimpan + @include('lpj::surveyor.js.utils') diff --git a/resources/views/surveyor/components/informasi.blade.php b/resources/views/surveyor/components/informasi.blade.php index 1e0fdfd..3f837a8 100644 --- a/resources/views/surveyor/components/informasi.blade.php +++ b/resources/views/surveyor/components/informasi.blade.php @@ -217,7 +217,7 @@ } @endphp - Foto Tempat diff --git a/resources/views/surveyor/components/lingkungan.blade.php b/resources/views/surveyor/components/lingkungan.blade.php index dd62910..7119fde 100644 --- a/resources/views/surveyor/components/lingkungan.blade.php +++ b/resources/views/surveyor/components/lingkungan.blade.php @@ -23,12 +23,12 @@

-
-
@@ -40,7 +40,7 @@ $forminspeksi['lingkungan']['lebar_perkerasan_jalan'] ?? '', ); @endphp -
diff --git a/resources/views/surveyor/components/tanah.blade.php b/resources/views/surveyor/components/tanah.blade.php index a6cd298..8d132db 100644 --- a/resources/views/surveyor/components/tanah.blade.php +++ b/resources/views/surveyor/components/tanah.blade.php @@ -16,7 +16,7 @@ $luas_tanah = 'N/A'; if ($item->detail) { foreach ($item->detail as $luas) { - if (isset($luas->name) && $luas->name === 'Sertifikat') { + if (isset($luas->name) && $luas->jenis_legalitas_jaminan_id === 1) { $details = json_decode($luas->details, true); $luas_tanah = isset($details['luas_tanah']) ? $details['luas_tanah'] : 'N/A'; break; @@ -191,7 +191,7 @@ @elseif (strcasecmp($item->name, 'Lebih Rendah') == 0) @endif @@ -217,6 +217,11 @@ {{ old('kontur_jalan', isset($forminspeksi['tanah']['kontur_jalan']) ? $forminspeksi['tanah']['kontur_jalan'] : '') == 'rata' ? 'checked' : '' }}> Rata +
diff --git a/resources/views/surveyor/index.blade.php b/resources/views/surveyor/index.blade.php index c839cae..09b67fa 100644 --- a/resources/views/surveyor/index.blade.php +++ b/resources/views/surveyor/index.blade.php @@ -200,6 +200,149 @@ }); } + + function approveReschedule(penilaianId,permohonanId, noReg, debitur, reschedule_date, reschedule_note) { + Swal.fire({ + title: 'Konfirmasi', + html: ` +

Yakin akan Menyetujui atau Menolak Reschedule Jadwal Kunjungan ${noReg} untuk Debitur ${debitur} + pada waktu ${window.formatTanggalWaktuIndonesia(reschedule_date)}?

+

Catatan:
${reschedule_note}

+ `, + icon: 'warning', + showDenyButton: true, + showCancelButton: true, + confirmButtonColor: '#3085d6', + denyButtonColor: '#d33', + confirmButtonText: 'Approve', + denyButtonText: 'Reject' + }).then((result) => { + if (result.isConfirmed) { + // Approve action + let token = "{{ csrf_token() }}"; + let useURL = "{{ URL::to('/surveyor/store-approve-reschedule') }}" + "/" + penilaianId; + + var input_data = { + _token : token, + permohonan_id : permohonanId, + nomor_registrasi: noReg + } + $.ajax({ + url: useURL, + type: "PUT", + cache: false, + data: input_data, + success: function(response) { + console.log(response); + if ('success' == response.status) { + Swal.fire('Sukses!', response.message, 'success').then(() => { + location.reload(true); + }); + } else { + Swal.fire('Error!', response.message, 'error'); + } + }, + error: function(response, textStatus, errorThrown) { + console.log(response); + } + }); + } else if (result.isDenied) { + // Reject action + Swal.fire({ + title: 'Masukkan Keterangan', + input: 'textarea', + inputPlaceholder: 'Tuliskan alasan penolakan di sini...', + inputAttributes: { + 'aria-label': 'Tuliskan alasan penolakan di sini' + }, + showCancelButton: true, + confirmButtonText: 'Submit', + cancelButtonText: 'Batal' + }).then((rejectResult) => { + if (rejectResult.isConfirmed && rejectResult.value) { + let token = "{{ csrf_token() }}"; + let useURL = "{{ URL::to('/surveyor/store-rejected-reschedule') }}" + "/" + penilaianId; + + + var input_data = { + _token : token, + permohonan_id : permohonanId, + nomor_registrasi: noReg, + rejected_note : rejectResult.value + } + $.ajax({ + url: useURL, + type: "PUT", + cache: false, + data: input_data, + + success: function(response) { + console.log(response); + if ('success' == response.status) { + Swal.fire('Ditolak!', response.message, 'success').then(() => { + location.reload(true); + }); + } else { + Swal.fire('Error!', response.message, 'error'); + } + }, + error: function(response, textStatus, errorThrown) { + console.log(response); + } + }); + } else if (rejectResult.dismiss === Swal.DismissReason.cancel) { + Swal.fire('Dibatalkan', 'Aksi penolakan dibatalkan.', 'info'); + } + }); + } + }); +} + + +function prosesSurvey(permohonanId, nomor_registrasi) { + Swal.fire({ + title: 'Konfirmasi', + text: `Yakin akan Melakukan Inspeksi dengan nomor registrasi ${nomor_registrasi}?`, + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Ya, Setujui', + cancelButtonText: 'Batal', + }).then((result) => { + if (result.isConfirmed) { + // Mendefinisikan URL dan data + let token = "{{ csrf_token() }}"; + let useURL = `{{ URL::to('/surveyor/store-proses-survey') }}/${permohonanId}`; + + let input_data = { + _token: token, + permohonan_id: permohonanId + }; + + // Melakukan AJAX request + $.ajax({ + url: useURL, + type: "PUT", + cache: false, + data: input_data, + dataType: "json", + success: function(response) { + if (response.status === 'success') { + // Arahkan langsung ke halaman inspeksi + window.location.href = `surveyor/${permohonanId}/show?form=inspeksi`; + } else { + Swal.fire('Error!', response.message, 'error'); + } + }, + error: function(response) { + const errorMessage = response.responseJSON?.message || 'Terjadi kesalahan saat memproses data.'; + Swal.fire('Error!', errorMessage, 'error'); + } + }); + } + }); +}