diff --git a/app/Exports/ArahMataAnginExport.php b/app/Exports/ArahMataAnginExport.php new file mode 100644 index 0000000..0571661 --- /dev/null +++ b/app/Exports/ArahMataAnginExport.php @@ -0,0 +1,47 @@ +id, + $row->name, + $row->created_at + ]; + } + + public function headings() + : array + { + return [ + 'ID', + 'Arah Mata Angin', + 'Created At' + ]; + } + + public function columnFormats() + : array + { + return [ + 'A' => NumberFormat::FORMAT_NUMBER, + 'C' => NumberFormat::FORMAT_DATE_DATETIME + ]; + } + } diff --git a/app/Http/Controllers/ArahMataAnginController.php b/app/Http/Controllers/ArahMataAnginController.php new file mode 100644 index 0000000..16050a6 --- /dev/null +++ b/app/Http/Controllers/ArahMataAnginController.php @@ -0,0 +1,149 @@ +validated(); + + if ($validate) { + try { + // Save to database + ArahMataAngin::create($validate); + return redirect() + ->route('basicdata.arah-mata-angin.index') + ->with('success', 'Arah Mata Angin created successfully'); + } catch (Exception $e) { + return redirect() + ->route('basicdata.arah-mata-angin.create') + ->with('error', 'Failed to create arah mata angin'); + } + } + } + + public function create() + { + return view('lpj::arah_mata_angin.create'); + } + + public function edit($id) + { + $arahMataAngin = ArahMataAngin::find($id); + return view('lpj::arah_mata_angin.create', compact('arahMataAngin')); + } + + public function update(ArahMataAnginRequest $request, $id) + { + $validate = $request->validated(); + + if ($validate) { + try { + // Update in database + $arahMataAngin = ArahMataAngin::find($id); + $arahMataAngin->update($validate); + return redirect() + ->route('basicdata.arah-mata-angin.index') + ->with('success', 'Arah Mata Angin updated successfully'); + } catch (Exception $e) { + return redirect() + ->route('basicdata.arah-mata-angin.edit', $id) + ->with('error', 'Failed to update arah mata angin'); + } + } + } + + public function destroy($id) + { + try { + // Delete from database + $arahMataAngin = ArahMataAngin::find($id); + $arahMataAngin->delete(); + + echo json_encode(['success' => true, 'message' => 'Arah Mata Angin deleted successfully']); + } catch (Exception $e) { + echo json_encode(['success' => false, 'message' => 'Failed to delete arah mata angin']); + } + } + + public function dataForDatatables(Request $request) + { + if (is_null($this->user) || !$this->user->can('arah_mata_angin.view')) { + //abort(403, 'Sorry! You are not allowed to view users.'); + } + + // Retrieve data from the database + $query = ArahMataAngin::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%"); + }); + } + + // 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 ArahMataAnginExport, 'arah_mata_angin.xlsx'); + } + } diff --git a/app/Http/Requests/ArahMataAnginRequest.php b/app/Http/Requests/ArahMataAnginRequest.php new file mode 100644 index 0000000..f797cb4 --- /dev/null +++ b/app/Http/Requests/ArahMataAnginRequest.php @@ -0,0 +1,30 @@ + 'required|max:255', + ]; + + return $rules; + } + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize() + : bool + { + return true; + } + } diff --git a/app/Models/ArahMataAngin.php b/app/Models/ArahMataAngin.php new file mode 100644 index 0000000..ade345b --- /dev/null +++ b/app/Models/ArahMataAngin.php @@ -0,0 +1,9 @@ +id(); + $table->string('name'); + $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('arah_mata_angin'); + } +}; diff --git a/module.json b/module.json index 50c4cd3..edcf3c5 100644 --- a/module.json +++ b/module.json @@ -166,6 +166,14 @@ "attributes": [], "permission": "", "roles": [] + }, + { + "title": "Arah Mata Angin", + "path": "basicdata.arah-mata-angin", + "classes": "", + "attributes": [], + "permission": "", + "roles": [] } ] } diff --git a/resources/views/arah_mata_angin/create.blade.php b/resources/views/arah_mata_angin/create.blade.php new file mode 100644 index 0000000..604546d --- /dev/null +++ b/resources/views/arah_mata_angin/create.blade.php @@ -0,0 +1,47 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render(request()->route()->getName()) }} +@endsection + +@section('content') +
+ @if(isset($arahMataAngin->id)) +
+ + @method('PUT') + @else + + @endif + @csrf +
+
+

+ {{ isset($arahMataAngin->id) ? 'Edit' : 'Tambah' }} Arah Mata Angin +

+
+ Back +
+
+
+
+ +
+ + @error('name') + {{ $message }} + @enderror +
+
+
+ +
+
+
+
+
+@endsection diff --git a/resources/views/arah_mata_angin/index.blade.php b/resources/views/arah_mata_angin/index.blade.php new file mode 100644 index 0000000..0ad9787 --- /dev/null +++ b/resources/views/arah_mata_angin/index.blade.php @@ -0,0 +1,140 @@ +@extends('layouts.main') + +@section('breadcrumbs') + {{ Breadcrumbs::render('basicdata.arah-mata-angin') }} +@endsection + +@section('content') +
+
+
+

+ Daftar Arah Mata Angin +

+ +
+
+
+ + + + + + + + +
+ + + Arah Mata Angin + + Action
+
+ +
+
+
+@endsection + +@push('scripts') + + + +@endpush + diff --git a/routes/breadcrumbs.php b/routes/breadcrumbs.php index 5ac8a28..6eea2fc 100644 --- a/routes/breadcrumbs.php +++ b/routes/breadcrumbs.php @@ -173,6 +173,20 @@ $trail->push('Edit Hubungan Penghuni Jaminan'); }); + Breadcrumbs::for('basicdata.arah-mata-angin', function (BreadcrumbTrail $trail) { + $trail->parent('basicdata'); + $trail->push('Arah Mata Angin', route('basicdata.arah-mata-angin.index')); + }); + + Breadcrumbs::for('basicdata.arah-mata-angin.create', function (BreadcrumbTrail $trail) { + $trail->parent('basicdata.arah-mata-angin'); + $trail->push('Tambah Arah Mata Angin', route('basicdata.arah-mata-angin.create')); + }); + + Breadcrumbs::for('basicdata.arah-mata-angin.edit', function (BreadcrumbTrail $trail) { + $trail->parent('basicdata.hubungan-penghuni-jaminan'); + $trail->push('Edit Arah Mata Angin'); + }); Breadcrumbs::for('debitur', function (BreadcrumbTrail $trail) { $trail->push('Debitur', route('debitur.index')); diff --git a/routes/web.php b/routes/web.php index 8095371..b620dba 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ name('export'); }); Route::resource('hubungan-penghuni-jaminan', HubunganPenghuniJaminanController::class); + + Route::name('arah-mata-angin.')->prefix('arah-mata-angin')->group(function () { + Route::get('restore/{id}', [ArahMataAnginController::class, 'restore'])->name('restore'); + Route::get('datatables', [ArahMataAnginController::class, 'dataForDatatables']) + ->name('datatables'); + Route::get('export', [ArahMataAnginController::class, 'export'])->name('export'); + }); + Route::resource('arah-mata-angin', ArahMataAnginController::class); }); Route::name('debitur.')->prefix('debitur')->group(function () {