diff --git a/app/Http/Controllers/PembatalanController.php b/app/Http/Controllers/PembatalanController.php new file mode 100644 index 0000000..af65cde --- /dev/null +++ b/app/Http/Controllers/PembatalanController.php @@ -0,0 +1,147 @@ +historyService = $historyService; + } + + public function index() + { + return view('lpj::pembatalan.index'); + } + + public function edit($id) + { + $pembatalan = PermohonanPembatalan::with(['permohonan.debiture','permohonan.branch'])->find($id); + + return view( + 'lpj::pembatalan.form', + compact( + 'pembatalan' + ), + ); + } + + public function update(Request $request, $id) + { + $pembatalan = PermohonanPembatalan::findOrFail($id); + $permohonan = Permohonan::find($pembatalan->permohonan_id); + $beforeRequest = $permohonan->toArray(); + + try { + // Update Permohonan Pembatalan + if($request->status=='approved'){ + $pembatalan->status = 'approved'; + $pembatalan->save(); + + $permohonan->status = 'batal'; + $permohonan->save(); + } else{ + $pembatalan->status = 'rejected'; + $pembatalan->save(); + } + + return redirect() + ->route('pembatalan.index')->with('success', 'Permohonan Pembatalan updated successfully'); + } catch (Exception $e) { + return redirect() + ->route('pembatalan.edit', $id)->with('error', 'Failed to update permohonan Pembatalan'); + } + } + + 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 = PermohonanPembatalan::query(); + $query = $query->orderBy('created_at', '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->orWhereRelation('permohonan', 'nomor_registrasi', 'LIKE', '%' . $search . '%'); + $q->orWhereRelation('permohonan.debiture', 'name', 'LIKE', '%' . $search . '%'); + $q->orWhere('alasan_pembatalan', '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(['permohonan.debiture','permohonan.branch','creator'])->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, + ]); + } + } diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php index 8cf40fb..8774786 100644 --- a/app/Http/Controllers/PermohonanController.php +++ b/app/Http/Controllers/PermohonanController.php @@ -11,6 +11,7 @@ use Modules\Location\Models\District; use Modules\Location\Models\Province; use Modules\Location\Models\Village; + use Modules\Lpj\Models\PermohonanPembatalan; use Modules\Lpj\Exports\PermohonanExport; use Modules\Lpj\Http\Requests\PermohonanRequest; use Modules\Lpj\Models\Branch; @@ -25,7 +26,7 @@ class PermohonanController extends Controller { - public $user; + public $user; protected $historyService; public function __construct(PermohonanHistoryService $historyService) @@ -46,7 +47,7 @@ // Process file upload $filePath = null; if ($request->hasFile('attachment')) { - $file = $request->file('attachment'); + $file = $request->file('attachment'); $fileName = time() . '_' . $file->getClientOriginalName(); $filePath = $file->storeAs('permohonan_attachments', $fileName, 'public'); } @@ -65,7 +66,7 @@ $keterangan, [], // beforeRequest is empty for new permohonan $permohonan->toArray(), - $filePath + $filePath, ); return redirect() ->route('permohonan.index')->with('success', 'Permohonan created successfully'); @@ -136,7 +137,7 @@ public function update(PermohonanRequest $request, $id) { - $permohonan = Permohonan::findOrFail($id); + $permohonan = Permohonan::findOrFail($id); $beforeRequest = $permohonan->toArray(); $validate = $request->validated(); @@ -203,10 +204,10 @@ // Get the total count of records $totalRecords = $query->count(); - $size = $request->get('size', 10); - if ($size == 0) { - $size = 10; - } + $size = $request->get('size', 10); + if ($size == 0) { + $size = 10; + } // Apply pagination if provided if ($request->has('page') && $request->has('size')) { @@ -221,7 +222,7 @@ $filteredRecords = $query->count(); // Get the data for the current page - $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian','penilaian'])->get(); + $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian'])->get(); // Calculate the page count $pageCount = ceil($totalRecords / $size); diff --git a/module.json b/module.json index bf39dc9..456bd9d 100644 --- a/module.json +++ b/module.json @@ -26,6 +26,18 @@ "pemohon-eo" ] }, + { + "title": "Pembatalan", + "path": "pembatalan", + "icon": "ki-filled ki-file-deleted text-lg text-danger", + "classes": "", + "attributes": [], + "permission": "", + "roles": [ + "administrator", + "pemohon-eo" + ] + }, { "title": "Persetujuan Penawaran", "path": "persetujuan-penawaran", @@ -167,7 +179,7 @@ { "title": "Authorization", "path": "authorization", - "icon": "ki-filled ki-security-user text-lg text-primary", + "icon": "ki-filled ki-security-user text-lg text-info", "classes": "", "attributes": [], "permission": "", diff --git a/resources/views/pembatalan/form.blade.php b/resources/views/pembatalan/form.blade.php new file mode 100644 index 0000000..78a4f26 --- /dev/null +++ b/resources/views/pembatalan/form.blade.php @@ -0,0 +1,80 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render(request()->route()->getName()) }} +@endsection + +@section('content') +
+
+
+

Form Pembatalan Permohonan

+
+ Back +
+
+
+
+ @method('PUT') + @csrf + +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+ + @error('alasan_pembatalan') + {{ $message }} + @enderror +
+
+ +
+ +
+ @if($pembatalan->file_pembatalan) + + @endif + @error('file_pembatalan') + {{ $message }} + @enderror +
+
+ +
+ + +
+
+
+
+
+@endsection diff --git a/resources/views/pembatalan/index.blade.php b/resources/views/pembatalan/index.blade.php new file mode 100644 index 0000000..5078d9f --- /dev/null +++ b/resources/views/pembatalan/index.blade.php @@ -0,0 +1,185 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render('pembatalan') }} +@endsection + +@section('content') +
+
+
+

+ Daftar Pembatalan Permohonan +

+
+
+ +
+ +
+
+ + +
+
+ + + + + + + + + + + + + + + +
+ + + Nomor Registrasi + + + Nama Debitur + + + Cabang + + + User Pemohon + + + Alasan Pembatalan + + + Dokumen Pendukung + + + Status + + Action
+
+ +
+
+ @endsection + + @push('scripts') + + @endpush diff --git a/resources/views/permohonan/index.blade.php b/resources/views/permohonan/index.blade.php index eccb166..deaf27a 100644 --- a/resources/views/permohonan/index.blade.php +++ b/resources/views/permohonan/index.blade.php @@ -31,44 +31,44 @@ - - - - - - - - - - - - + + + + + + + + + + + +
- - - 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
@@ -186,7 +186,10 @@ }, }, status: { - title: 'Status' + title: 'Status', + render: (item, data) => { + return `${data.status}`; + } }, keterangan: { title: 'Keterangan' @@ -194,7 +197,7 @@ actions: { title: 'Actions', render: (item, data) => { - let actionHtml = `
`; + let actionHtml = `
`; if (data && data.penilaian && data.penilaian.waktu_penilaian !== null && data.status !== 'done' && data.penilaian.authorized_status == null) { @@ -233,7 +236,7 @@ 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); @@ -267,19 +270,19 @@ cache: false, data: input_data, dataType: "json", - success: function(response) { + success: function (response) { console.log(response); if ('success' == response.status) { swal.fire('Sukses Menyetujui!', response.message, 'success').then( - () => { - location.reload(true); - }); + () => { + location.reload(true); + }); } else { Swal.fire('Error!', response.message, 'error'); } }, - error: function(response, textStatus, errorThrown) { + error: function (response, textStatus, errorThrown) { // var errors = response.responseJSON.errors; // console.log(errors); console.log(response); diff --git a/routes/web.php b/routes/web.php index 51b8f81..83fd7df 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,6 +18,7 @@ use Modules\Lpj\Http\Controllers\KJPPController; use Modules\Lpj\Http\Controllers\LaporanController; use Modules\Lpj\Http\Controllers\NilaiPlafondController; use Modules\Lpj\Http\Controllers\NocController; + use Modules\Lpj\Http\Controllers\PembatalanController; use Modules\Lpj\Http\Controllers\PemilikJaminanController; use Modules\Lpj\Http\Controllers\PenilaianController; use Modules\Lpj\Http\Controllers\PenilaiController; @@ -372,6 +373,11 @@ Route::middleware(['auth'])->group(function () { Route::resource('permohonan', PermohonanController::class); + Route::name('pembatalan.')->prefix('pembatalan')->group(function () { + Route::get('datatables', [PembatalanController::class, 'dataForDatatables'])->name('datatables'); + }); + Route::resource('pembatalan', PembatalanController::class); + Route::get('authorization', [PermohonanController::class, 'authorization'])->name('authorization.index'); Route::get('authorization/datatables', [PermohonanController::class, 'dataForAuthorization'])->name( 'authorization.datatables',