diff --git a/app/Exports/StatusPermohonanExport.php b/app/Exports/StatusPermohonanExport.php new file mode 100644 index 0000000..b7ebb63 --- /dev/null +++ b/app/Exports/StatusPermohonanExport.php @@ -0,0 +1,51 @@ +id, + $row->name, + $row->description, + $row->status, + $row->created_at + ]; + } + + public function headings() + : array + { + return [ + 'ID', + 'Name', + 'Description', + 'Status', + 'Created At' + ]; + } + + public function columnFormats() + : array + { + return [ + 'A' => NumberFormat::FORMAT_NUMBER, + 'E' => NumberFormat::FORMAT_DATE_DATETIME + ]; + } + } diff --git a/app/Http/Controllers/StatusPermohonanController.php b/app/Http/Controllers/StatusPermohonanController.php new file mode 100644 index 0000000..afcb128 --- /dev/null +++ b/app/Http/Controllers/StatusPermohonanController.php @@ -0,0 +1,150 @@ +validated(); + + if ($validate) { + try { + // Save to database + StatusPermohonan::create($validate); + return redirect() + ->route('basicdata.status-permohonan.index') + ->with('success', 'Status Permohonan created successfully'); + } catch (Exception $e) { + return redirect() + ->route('basicdata.status-permohonan.create') + ->with('error', 'Failed to create status permohonan'); + } + } + } + + public function create() + { + return view('lpj::status_permohonan.form'); + } + + public function edit($id) + { + $statusPermohonan = StatusPermohonan::find($id); + return view('lpj::status_permohonan.form', compact('statusPermohonan')); + } + + public function update(StatusPermohonanRequest $request, $id) + { + $validate = $request->validated(); + + if ($validate) { + try { + // Update in database + $statusPermohonan = StatusPermohonan::find($id); + $statusPermohonan->update($validate); + return redirect() + ->route('basicdata.status-permohonan.index') + ->with('success', 'Status Permohonan updated successfully'); + } catch (Exception $e) { + return redirect() + ->route('basicdata.status-permohonan.edit', $id) + ->with('error', 'Failed to update status permohonan'); + } + } + } + + public function destroy($id) + { + try { + // Delete from database + $statusPermohonan = StatusPermohonan::find($id); + $statusPermohonan->delete(); + + echo json_encode(['success' => true, 'message' => 'Status Permohonan deleted successfully']); + } catch (Exception $e) { + echo json_encode(['success' => false, 'message' => 'Failed to delete status permohonan']); + } + } + + public function dataForDatatables(Request $request) + { + if (is_null($this->user) || !$this->user->can('status_permohonan.view')) { + //abort(403, 'Sorry! You are not allowed to view users.'); + } + + // Retrieve data from the database + $query = StatusPermohonan::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('name', 'LIKE', "%$search%"); + $q->orWhere('description', '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->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 StatusPermohonanExport, 'status_permohonan.xlsx'); + } + } diff --git a/app/Http/Requests/StatusPermohonanRequest.php b/app/Http/Requests/StatusPermohonanRequest.php new file mode 100644 index 0000000..4bc118f --- /dev/null +++ b/app/Http/Requests/StatusPermohonanRequest.php @@ -0,0 +1,43 @@ + 'nullable|max:255', + 'status' => 'required|boolean', + ]; + + if ($this->method() == 'PUT') { + $rules['name'] = 'required|max:50|unique:status_permohonan,name,' . $this->id; + } else { + $rules['name'] = 'required|max:50|unique:status_permohonan,name'; + } + return $rules; + } + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize() + : bool + { + return true; + } + + public function prepareForValidation() + { + $this->merge([ + 'status' => isset($this->status) ? 1 : 0, + ]); + } + } diff --git a/app/Models/StatusPermohonan.php b/app/Models/StatusPermohonan.php new file mode 100644 index 0000000..d4e244d --- /dev/null +++ b/app/Models/StatusPermohonan.php @@ -0,0 +1,9 @@ +id(); + $table->string('name')->unique(); + $table->string('description')->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('status_permohonan'); + } +}; diff --git a/module.json b/module.json index edcf3c5..22769ea 100644 --- a/module.json +++ b/module.json @@ -174,6 +174,14 @@ "attributes": [], "permission": "", "roles": [] + }, + { + "title": "Status Permohonan", + "path": "basicdata.status-permohonan", + "classes": "", + "attributes": [], + "permission": "", + "roles": [] } ] } diff --git a/resources/views/status_permohonan/form.blade.php b/resources/views/status_permohonan/form.blade.php new file mode 100644 index 0000000..a216493 --- /dev/null +++ b/resources/views/status_permohonan/form.blade.php @@ -0,0 +1,71 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render(request()->route()->getName()) }} +@endsection + +@section('content') +
+
+ @if(isset($statusPermohonan->id)) + @method('PUT') + + @endif + @csrf +
+
+

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

+
+ Back +
+
+
+
+ +
+ + @error('name') + {{ $message }} + @enderror +
+
+
+ +
+ + @error('description') + {{ $message }} + @enderror +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+
+@endsection diff --git a/resources/views/status_permohonan/index.blade.php b/resources/views/status_permohonan/index.blade.php new file mode 100644 index 0000000..d684445 --- /dev/null +++ b/resources/views/status_permohonan/index.blade.php @@ -0,0 +1,162 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render('basicdata.status-permohonan') }} +@endsection + +@section('content') +
+
+
+

+ Daftar Status Permohonan +

+ +
+
+
+ + + + + + + + + + + +
+ + + Code + + + Status Permohonan + + + Deskripsi + + + Status + + Action
+
+ +
+
+
+@endsection + +@push('scripts') + + + +@endpush + diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index d2cdf88..6747322 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -188,6 +188,21 @@ $trail->push('Edit Arah Mata Angin'); }); + Breadcrumbs::for('basicdata.status-permohonan', function (BreadcrumbTrail $trail) { + $trail->parent('basicdata'); + $trail->push('Status Permohonan', route('basicdata.status-permohonan.index')); + }); + + Breadcrumbs::for('basicdata.status-permohonan.create', function (BreadcrumbTrail $trail) { + $trail->parent('basicdata.status-permohonan'); + $trail->push('Tambah Status Permohonan', route('basicdata.status-permohonan.create')); + }); + + Breadcrumbs::for('basicdata.status-permohonan.edit', function (BreadcrumbTrail $trail) { + $trail->parent('basicdata.status-permohonan'); + $trail->push('Edit Status Permohonan'); + }); + Breadcrumbs::for('debitur', function (BreadcrumbTrail $trail) { $trail->push('Debitur', route('debitur.index')); }); diff --git a/routes/web.php b/routes/web.php index 7e1e4d5..85c7139 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,6 +16,7 @@ use Modules\Lpj\Http\Controllers\NilaiPlafondController; use Modules\Lpj\Http\Controllers\PemilikJaminanController; use Modules\Lpj\Http\Controllers\PermohonanController; + use Modules\Lpj\Http\Controllers\StatusPermohonanController; use Modules\Lpj\Http\Controllers\TujuanPenilaianController; /* @@ -148,6 +149,16 @@ Route::get('export', [ArahMataAnginController::class, 'export'])->name('export'); }); Route::resource('arah-mata-angin', ArahMataAnginController::class); + + + Route::name('status-permohonan.')->prefix('status-permohonan')->group(function () { + Route::get('restore/{id}', [StatusPermohonanController::class, 'restore'])->name('restore'); + Route::get('datatables', [StatusPermohonanController::class, 'dataForDatatables']) + ->name('datatables'); + Route::get('export', [StatusPermohonanController::class, 'export'])->name('export'); + }); + Route::resource('status-permohonan', StatusPermohonanController::class); + }); }); Route::resource('permohonan', PermohonanController::class);