From fec80bfa1c0eed5170937b8f0dd9452fc0b9988b Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Sat, 24 Aug 2024 21:17:32 +0700 Subject: [PATCH] Feature #17 : Module Permohonan --- app/Exports/DebitureExport.php | 2 +- app/Exports/PermohonanExport.php | 67 ++++++ app/Http/Controllers/PermohonanController.php | 201 ++++++++++++++++++ app/Http/Requests/PermohonanRequest.php | 50 +++++ app/Models/Permohonan.php | 45 ++++ ...4_08_22_080122_create_permohonan_table.php | 46 ++++ module.json | 2 +- resources/views/debitur/index.blade.php | 2 +- resources/views/permohonan/form.blade.php | 145 +++++++++++++ resources/views/permohonan/index.blade.php | 195 +++++++++++++++++ routes/breadcrumbs.php | 14 ++ routes/web.php | 9 +- 12 files changed, 774 insertions(+), 4 deletions(-) create mode 100644 app/Exports/PermohonanExport.php create mode 100644 app/Http/Controllers/PermohonanController.php create mode 100644 app/Http/Requests/PermohonanRequest.php create mode 100644 app/Models/Permohonan.php create mode 100644 database/migrations/2024_08_22_080122_create_permohonan_table.php create mode 100644 resources/views/permohonan/form.blade.php create mode 100644 resources/views/permohonan/index.blade.php diff --git a/app/Exports/DebitureExport.php b/app/Exports/DebitureExport.php index 37cbc8c..83bea98 100644 --- a/app/Exports/DebitureExport.php +++ b/app/Exports/DebitureExport.php @@ -21,7 +21,7 @@ { return [ $row->id, - $row->branch->name . + $row->branch->name, $row->cif, $row->nomor_rekening, $row->name, diff --git a/app/Exports/PermohonanExport.php b/app/Exports/PermohonanExport.php new file mode 100644 index 0000000..07b83fe --- /dev/null +++ b/app/Exports/PermohonanExport.php @@ -0,0 +1,67 @@ +id, + $row->nomor_registrasi, + $row->tanggal_permohonan, + $row->user->name, + $row->branch->name, + $row->tujuanPenilaian->name, + $row->debiture->name, + $row->status, + $row->authorized_at, + $row->authorized_status, + $row->authorized_by, + $row->created_at + ]; + } + + public function headings() + : array + { + return [ + 'ID', + 'Nomor Registrasi', + 'Tanggal Permohonan', + 'User Pemohon', + 'Branch Pemohon', + 'Tujuan Penilaian', + 'Debitur', + 'Status', + 'Tanggal Pengesahan', + 'Status Pengesahan', + 'Pengesah', + 'Tanggal Dibuat' + ]; + } + + public function columnFormats() + : array + { + return [ + 'A' => NumberFormat::FORMAT_NUMBER, + 'C' => NumberFormat::FORMAT_DATE_DATETIME, + 'L' => NumberFormat::FORMAT_DATE_DATETIME + ]; + } + } diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php new file mode 100644 index 0000000..d45c873 --- /dev/null +++ b/app/Http/Controllers/PermohonanController.php @@ -0,0 +1,201 @@ +validated(); + + if ($validate) { + try { + // Save to database + Permohonan::create($validate); + 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()); + } + } else { + return redirect() + ->route('permohonan.create') + ->with('success', 'error naon iye') + ->withInput(); + } + } + + public function create() + { + $branches = Branch::all(); + $debitures = Debiture::all(); + $tujuanPenilaian = TujuanPenilaian::all(); + $status = [ + 'order' => 'Order', + 'revisi' => 'Revisi', + 'register' => 'Register', + 'assign' => 'Assign', + 'survey' => 'Survey', + 'finalisasi' => 'Proses Laporan', + 'approved' => 'Diterima', + 'rejected' => 'Ditolak', + 'cancel' => 'Dibatalkan', + 'finished' => 'Selesai', + 'not_started' => 'Belum dimulai', + ]; + + return view('lpj::permohonan.form', compact('branches', 'debitures', 'tujuanPenilaian','status')); + } + + public function edit($id) + { + $permohonan = Permohonan::find($id); + $branches = Branch::all(); + $debitures = Debiture::all(); + $tujuanPenilaian = TujuanPenilaian::all(); + $status = [ + 'order' => 'Order', + 'revisi' => 'Revisi', + 'register' => 'Register', + 'assign' => 'Assign', + 'survey' => 'Survey', + 'finalisasi' => 'Proses Laporan', + 'approved' => 'Diterima', + 'rejected' => 'Ditolak', + 'cancel' => 'Dibatalkan', + 'finished' => 'Selesai', + 'not_started' => 'Belum dimulai', + ]; + + return view( + 'lpj::permohonan.form', + compact('permohonan', 'branches', 'debitures', 'tujuanPenilaian','status'), + ); + } + + public function update(PermohonanRequest $request, $id) + { + $validate = $request->validated(); + + if ($validate) { + try { + // Update in database + $permohonan = Permohonan::find($id); + $permohonan->update($validate); + 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'); + } + } + } + + public function destroy($id) + { + try { + // Delete from database + $permohonan = Permohonan::find($id); + $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.'); + } + + // 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'])->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 export() + { + return Excel::download(new PermohonanExport, 'permohonan.xlsx'); + } + } diff --git a/app/Http/Requests/PermohonanRequest.php b/app/Http/Requests/PermohonanRequest.php new file mode 100644 index 0000000..5a576dd --- /dev/null +++ b/app/Http/Requests/PermohonanRequest.php @@ -0,0 +1,50 @@ + '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', + ]; + + return $rules; + } + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize() + : bool + { + return true; + } + + public function prepareForValidation() + { + if (!$this->id) { + $this->merge([ + 'nomor_registrasi' => IdGenerator::generate( + ['table' => 'permohonan', 'length' => 10, 'prefix'=>'REG', 'field' => 'nomor_registrasi'], + ), + 'tanggal_permohonan' => date('Y-m-d'), + 'user_id' => auth()->user()->id, + ]); + } + } + } diff --git a/app/Models/Permohonan.php b/app/Models/Permohonan.php new file mode 100644 index 0000000..28b6de5 --- /dev/null +++ b/app/Models/Permohonan.php @@ -0,0 +1,45 @@ +belongsTo(User::class); + } + + public function branch(){ + return $this->belongsTo(Branch::class); + } + + public function tujuanPenilaian(){ + return $this->belongsTo(TujuanPenilaian::class); + } + + public function debiture(){ + return $this->belongsTo(Debiture::class); + } + + public function documents(){ + return $this->hasMany(DokumenJaminan::class); + } +} diff --git a/database/migrations/2024_08_22_080122_create_permohonan_table.php b/database/migrations/2024_08_22_080122_create_permohonan_table.php new file mode 100644 index 0000000..c31814f --- /dev/null +++ b/database/migrations/2024_08_22_080122_create_permohonan_table.php @@ -0,0 +1,46 @@ +id(); + $table->string('nomor_registrasi')->unique(); + $table->date('tanggal_permohonan'); + $table->foreignIdFor(User::class)->constrained(); + $table->foreignIdFor(Branch::class)->constrained(); + $table->foreignIdFor(TujuanPenilaian::class)->constrained('tujuan_penilaian')->onDelete('cascade'); + $table->foreignIdFor(Debiture::class)->constrained('debitures')->onDelete('cascade'); + $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('permohonan'); + } +}; diff --git a/module.json b/module.json index 22769ea..40ce5bd 100644 --- a/module.json +++ b/module.json @@ -13,7 +13,7 @@ "main": [ { "title": "Permohonan", - "path": "", + "path": "permohonan", "icon": "ki-filled ki-questionnaire-tablet text-lg", "classes": "", "attributes": [], diff --git a/resources/views/debitur/index.blade.php b/resources/views/debitur/index.blade.php index a3b0994..a36b711 100644 --- a/resources/views/debitur/index.blade.php +++ b/resources/views/debitur/index.blade.php @@ -157,7 +157,7 @@ branch: { title: 'Cabang', render: (item, data, context) => { - return `${data.branch_name}`; + return `${data.branch.name}`; }, }, nomor_id: { diff --git a/resources/views/permohonan/form.blade.php b/resources/views/permohonan/form.blade.php new file mode 100644 index 0000000..091c4d5 --- /dev/null +++ b/resources/views/permohonan/form.blade.php @@ -0,0 +1,145 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render(request()->route()->getName()) }} +@endsection + +@section('content') +
+ +
+
+

+ {{ isset($permohonan->id) ? 'Edit' : 'Tambah' }} Permohonan +

+
+ Back +
+
+
+
+ @if(isset($permohonan->id)) + @method('PUT') + @endif + @csrf + +
+ +
+ + @error('debiture_id') + {{ $message }} + @enderror +
+
+ +
+ +
+ + @error('branch_id') + {{ $message }} + @enderror +
+
+ +
+ +
+ + @error('tujuan_penilaian_id') + {{ $message }} + @enderror +
+
+ +
+ +
+ + @error('status') + {{ $message }} + @enderror +
+
+ + +
+ +
+
+ +
+
+
+@endsection diff --git a/resources/views/permohonan/index.blade.php b/resources/views/permohonan/index.blade.php new file mode 100644 index 0000000..50f3e19 --- /dev/null +++ b/resources/views/permohonan/index.blade.php @@ -0,0 +1,195 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render(request()->route()->getName()) }} +@endsection + +@section('content') +
+ +
+
+

+ Daftar Permohonan +

+ +
+
+
+ + + + + + + + + + + + + + +
+ + + Nomor Registrasi + + + Tanggal Permohonan + + + User Pemohon + + + Cabang Pemohon + + + Debitur + + + Tujuan Penilaian + + + Status + + Action
+
+ +
+
+
+@endsection + +@push('scripts') + + + +@endpush diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index 6747322..76419cc 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -248,3 +248,17 @@ $trail->push('Edit Data Pemilik Jaminan Debitur'); }); + Breadcrumbs::for('permohonan.index', function (BreadcrumbTrail $trail) { + $trail->push('Permohonan', route('permohonan.index')); + }); + + Breadcrumbs::for('permohonan.create', function (BreadcrumbTrail $trail) { + $trail->parent('permohonan.index'); + $trail->push('Tambah Permohonan', route('permohonan.create')); + }); + + Breadcrumbs::for('permohonan.edit', function (BreadcrumbTrail $trail) { + $trail->parent('permohonan.index'); + $trail->push('Data Permohonan'); + }); + diff --git a/routes/web.php b/routes/web.php index 85c7139..ed86d4a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -159,9 +159,16 @@ }); Route::resource('status-permohonan', StatusPermohonanController::class); }); + + Route::name('permohonan.')->prefix('permohonan')->group(function () { + Route::get('download/{id}', [PermohonanController::class, 'download'])->name('download'); + Route::get('restore/{id}', [PermohonanController::class, 'restore'])->name('restore'); + Route::get('datatables', [PermohonanController::class, 'dataForDatatables']) + ->name('datatables'); + Route::get('export', [PermohonanController::class, 'export'])->name('export'); }); - Route::resource('permohonan', PermohonanController::class); + Route::resource('permohonan', PermohonanController::class); Route::name('debitur.')->prefix('debitur')->group(function () { Route::get('download/{id}', [DebitureController::class, 'download'])->name('download');