From 61dba7a35c6df7f96c535602d8a2ce69f5d2c4db Mon Sep 17 00:00:00 2001 From: "daeng.deni@dharma.or.id" Date: Mon, 17 Apr 2023 22:24:38 +0700 Subject: [PATCH] add module document types --- app/DataTables/DocumentTypeDataTable.php | 89 ++++++++++++ .../Controllers/DocumentTypeController.php | 118 +++++++++++++++ .../Requests/StoreDocumentTypeRequest.php | 47 ++++++ .../Requests/UpdateDocumentTypeRequest.php | 47 ++++++ .../Requests/UpdateSpecialCodeRequest.php | 2 +- .../sidebar-layout/sidebar/_menu.blade.php | 14 +- .../masters/document-type/_action.blade.php | 13 ++ .../masters/document-type/_form.blade.php | 71 +++++++++ .../masters/document-type/_table.blade.php | 117 +++++++++++++++ .../masters/document-type/index.blade.php | 136 ++++++++++++++++++ routes/web.php | 2 + 11 files changed, 654 insertions(+), 2 deletions(-) create mode 100644 app/DataTables/DocumentTypeDataTable.php create mode 100644 app/Http/Controllers/DocumentTypeController.php create mode 100644 app/Http/Requests/StoreDocumentTypeRequest.php create mode 100644 app/Http/Requests/UpdateDocumentTypeRequest.php create mode 100644 resources/views/pages/masters/document-type/_action.blade.php create mode 100644 resources/views/pages/masters/document-type/_form.blade.php create mode 100644 resources/views/pages/masters/document-type/_table.blade.php create mode 100644 resources/views/pages/masters/document-type/index.blade.php diff --git a/app/DataTables/DocumentTypeDataTable.php b/app/DataTables/DocumentTypeDataTable.php new file mode 100644 index 0000000..8d1c679 --- /dev/null +++ b/app/DataTables/DocumentTypeDataTable.php @@ -0,0 +1,89 @@ +filter(function ($query) { + if (request()->has('search')) { + $search = request()->get('search'); + $query->where('kode', 'like', "%" . $search['value'] . "%") + ->orWhere('name', 'like', "%" . $search['value'] . "%"); + } + }) + ->addIndexColumn() + ->addColumn('action', 'pages.masters.document-type._action') + ->setRowId('id'); + } + + /** + * Get the query source of dataTable. + */ + public function query(DocumentType $model): QueryBuilder + { + return $model->newQuery(); + } + + /** + * Optional method if you want to use the html builder. + */ + public function html(): HtmlBuilder + { + return $this->builder() + ->setTableId('document-type-table') + ->columns($this->getColumns()) + ->minifiedAjax() + ->stateSave(false) + ->responsive() + ->autoWidth(true) + ->orderBy(1) + ->parameters([ + 'scrollX' => true, + 'drawCallback' => 'function() { KTMenu.createInstances(); }', + ]) + ->addTableClass('align-middle table-row-dashed fs-6 gy-5'); + } + + /** + * Get the dataTable columns definition. + */ + public function getColumns(): array + { + return [ + Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), + Column::make('kode'), + Column::make('name'), + Column::computed('action') + ->exportable(false) + ->printable(false) + ->width(60) + ->addClass('text-center'), + ]; + } + + /** + * Get the filename for export. + */ + protected function filename(): string + { + return 'Document_Type_' . date('YmdHis'); + } +} diff --git a/app/Http/Controllers/DocumentTypeController.php b/app/Http/Controllers/DocumentTypeController.php new file mode 100644 index 0000000..966026c --- /dev/null +++ b/app/Http/Controllers/DocumentTypeController.php @@ -0,0 +1,118 @@ +middleware(function ($request, $next) { + //$this->user = Auth::guard('web')->user(); + return $next($request); + }); + + //CauserResolver::setCauser($this->user); + } + + /** + * Display a listing of the resource. + */ + public function index(DocumentTypeDataTable $dataTable) + { + /*if (is_null($this->user) || !$this->user->can('masters.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any master data !'); + }*/ + + return $dataTable->render('pages.masters.document-type.index'); + } + + /** + * Show the form for creating a new resource. + */ + public function create(){} + + /** + * Store a newly created resource in storage. + */ + public function store(StoreDocumentTypeRequest $request) + { + /*if (is_null($this->user) || !$this->user->can('masters.create')) { + abort(403, 'Sorry !! You are Unauthorized to create any master data !'); + }*/ + + + // Validate the request... + $validated = $request->validated(); + + // Store the Document Type... + if($validated){ + try{ + DocumentType::create($validated); + echo json_encode(['status' => 'success', 'message' => 'Document Type created successfully.']); + }catch(\Exception $e){ + echo json_encode(['status' => 'error', 'message' => 'Document Type created failed.']); + } + } + + return false; + } + + /** + * Display the specified resource. + */ + public function show(DocumentType $document_type) + { + + } + + /** + * Show the form for editing the specified resource. + */ + public function edit($id){ + $document_type = DocumentType::find($id); + echo json_encode($document_type); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateDocumentTypeRequest $request, DocumentType $document_type) + { + /*if (is_null($this->user) || !$this->user->can('masters.update')) { + abort(403, 'Sorry !! You are Unauthorized to update any master data !'); + }*/ + + // Validate the request... + $validated = $request->validated(); + + // Update the Directorat... + if($validated){ + try{ + $document_type->update($validated); + + echo json_encode(['status' => 'success', 'message' => 'Document Type updated successfully.']); + }catch(\Exception $e){ + echo json_encode(['status' => 'error', 'message' => 'Document Type updated failed.']); + } + } + + return false; + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(DocumentType $document_type){ + $document_type->delete(); + echo json_encode(['status' => 'success', 'message' => 'Document Type deleted successfully.']); + } +} diff --git a/app/Http/Requests/StoreDocumentTypeRequest.php b/app/Http/Requests/StoreDocumentTypeRequest.php new file mode 100644 index 0000000..962e2c2 --- /dev/null +++ b/app/Http/Requests/StoreDocumentTypeRequest.php @@ -0,0 +1,47 @@ + + */ + public function rules(): array + { + return [ + 'kode' => 'required|string|max:2|min:2|unique:document_types,kode', + 'name' => 'required|string|max:50' + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator): void + { + $validator->after(function (Validator $validator) { + if($validator->errors()->any()) { + $error = json_decode($validator->errors()->toJson(), true); + foreach ($error as $key => $value) { + flash( $value[0]); + } + + return redirect()->route('document-type.index')->with('error', 'Document Type created failed.'); + } + }); + } +} diff --git a/app/Http/Requests/UpdateDocumentTypeRequest.php b/app/Http/Requests/UpdateDocumentTypeRequest.php new file mode 100644 index 0000000..b52bfdb --- /dev/null +++ b/app/Http/Requests/UpdateDocumentTypeRequest.php @@ -0,0 +1,47 @@ + + */ + public function rules(): array + { + return [ + 'kode' => 'required|string|max:2|min:2|unique:document_types,kode,'.$this->id, + 'name' => 'required|string|max:50' + ]; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator): void + { + $validator->after(function (Validator $validator) { + if($validator->errors()->any()) { + $error = json_decode($validator->errors()->toJson(), true); + foreach ($error as $key => $value) { + flash( $value[0]); + } + + return redirect()->route('document-type.index')->with('error', 'Document Type updated failed.'); + } + }); + } +} diff --git a/app/Http/Requests/UpdateSpecialCodeRequest.php b/app/Http/Requests/UpdateSpecialCodeRequest.php index 5cb8e6f..41c231b 100644 --- a/app/Http/Requests/UpdateSpecialCodeRequest.php +++ b/app/Http/Requests/UpdateSpecialCodeRequest.php @@ -40,7 +40,7 @@ class UpdateSpecialCodeRequest extends FormRequest flash( $value[0]); } - return redirect()->route('special_code.index')->with('error', 'Special Code updated failed.'); + return redirect()->route('special-code.index')->with('error', 'Special Code updated failed.'); } }); } diff --git a/resources/views/layout/partials/sidebar-layout/sidebar/_menu.blade.php b/resources/views/layout/partials/sidebar-layout/sidebar/_menu.blade.php index f0bc4e7..8ffe1ab 100644 --- a/resources/views/layout/partials/sidebar-layout/sidebar/_menu.blade.php +++ b/resources/views/layout/partials/sidebar-layout/sidebar/_menu.blade.php @@ -216,7 +216,7 @@ - diff --git a/resources/views/pages/masters/document-type/_action.blade.php b/resources/views/pages/masters/document-type/_action.blade.php new file mode 100644 index 0000000..c90e6d7 --- /dev/null +++ b/resources/views/pages/masters/document-type/_action.blade.php @@ -0,0 +1,13 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp +
+ + {!! getIcon("pencil", "fs-1 text-info","duotune") !!} + + + {!! Form::open(['method' => 'DELETE','route' => [$route[0].'.destroy', $model->id],'class'=>'']) !!} + {{ Form::button(getIcon("trash", "fs-1 text-danger","duotune"), ['type' => 'submit', 'class' => 'delete btn btn-icon btn-bg-light btn-active-light-danger btn-sm'] ) }} + {!! Form::close() !!} +
diff --git a/resources/views/pages/masters/document-type/_form.blade.php b/resources/views/pages/masters/document-type/_form.blade.php new file mode 100644 index 0000000..6c5616e --- /dev/null +++ b/resources/views/pages/masters/document-type/_form.blade.php @@ -0,0 +1,71 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + + + + diff --git a/resources/views/pages/masters/document-type/_table.blade.php b/resources/views/pages/masters/document-type/_table.blade.php new file mode 100644 index 0000000..da5f014 --- /dev/null +++ b/resources/views/pages/masters/document-type/_table.blade.php @@ -0,0 +1,117 @@ + +{{ $dataTable->table() }} + + +{{-- Inject Scripts --}} +@section('scripts') + {{ $dataTable->scripts() }} +@endsection + +@push('customscript') + @php + $route = explode('.', Route::currentRouteName()); + @endphp + + +@endpush + +@section('styles') + +@endsection diff --git a/resources/views/pages/masters/document-type/index.blade.php b/resources/views/pages/masters/document-type/index.blade.php new file mode 100644 index 0000000..7c5ca8b --- /dev/null +++ b/resources/views/pages/masters/document-type/index.blade.php @@ -0,0 +1,136 @@ + + + @php + $route = explode('.', Route::currentRouteName()); + @endphp + + +
+ +
+
+
+ + + + + + + + + +
+ + +
+ + +
+ +
+ + + + + + + +
+ + +
+
+
+ @include('pages.masters.document-type._table') + @include('pages.masters.document-type._form') +
+ +
+ + @push('customscript') + + @endpush +
diff --git a/routes/web.php b/routes/web.php index e63b41e..543e8a6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\DashboardController; use App\Http\Controllers\DirectoratController; + use App\Http\Controllers\DocumentTypeController; use App\Http\Controllers\JobController; use App\Http\Controllers\Logs\AuditLogsController; use App\Http\Controllers\Logs\SystemLogsController; @@ -41,6 +42,7 @@ Route::group(['middleware' => ['auth', 'verified']], function () { Route::resource('sub-job', SubJobController::class); Route::resource('sub-sub-job', SubSubJobController::class); Route::resource('special-code', SpecialCodeController::class); + Route::resource('document-type', DocumentTypeController::class); // Users Management Route::prefix('user')->name('user.')->group(function(){