diff --git a/DataTables/GuaranteeTypeDataTable.php b/DataTables/GuaranteeTypeDataTable.php new file mode 100644 index 0000000..6cca64e --- /dev/null +++ b/DataTables/GuaranteeTypeDataTable.php @@ -0,0 +1,90 @@ +filter(function ($query) { + if (request()->has('search')) { + $search = request()->get('search'); + $query->where('kode', 'like', "%" . $search['value'] . "%") + ->orWhere('name', 'like', "%" . $search['value'] . "%"); + } + })->addIndexColumn()->editColumn('updated_at', function ($row) { + return $row->updated_at->format('d-m-Y H:i:s'); + })->rawColumns(['action'])->addColumn('action', function ($guarantee_type) { + return view('writeoff::parameter.guarantee_types._actions', compact('guarantee_type')); + })->setRowId('id'); + } + + /** + * Get the query source of dataTable. + */ + public function query(GuaranteeType $model) + : QueryBuilder + { + return $model->newQuery(); + } + + /** + * Optional method if you want to use the html builder. + */ + public function html() + : HtmlBuilder + { + return $this->builder() + ->setTableId('guarantee-type-table') + ->columns($this->getColumns()) + ->minifiedAjax() + ->stateSave(false) + ->responsive() + ->autoWidth(true) + ->orderBy(1) + ->parameters([ + 'scrollX' => false, + 'drawCallback' => 'function() { KTMenu.createInstances(); }', + ]) + ->addTableClass('align-middle table-row-dashed fs-6 gy-5') + ->drawCallback("function() {" . file_get_contents(Module::getModulePath('writeoff').'Resources/views/parameter/guarantee_types/_draw-scripts.js') . "}"); + } + + /** + * Get the dataTable columns definition. + */ + public function getColumns() + : array + { + return [ + Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), + Column::make('kode')->title('Kode GuaranteeType'), + Column::make('name')->title('Nama GuaranteeType'), + Column::make('updated_at')->title('Last Update')->visible(false), + Column::computed('action')->exportable(false)->printable(false)->width(60)->addClass('text-center'), + ]; + } + + /** + * Get the filename for export. + */ + protected function filename() + : string + { + return 'GuaranteeType_' . date('YmdHis'); + } + } diff --git a/Database/Migrations/2023_10_10_034538_create_currencies_table.php b/Database/Migrations/2023_10_10_034538_create_currencies_table.php index ff539c1..440e712 100644 --- a/Database/Migrations/2023_10_10_034538_create_currencies_table.php +++ b/Database/Migrations/2023_10_10_034538_create_currencies_table.php @@ -15,7 +15,7 @@ return new class extends Migration { Schema::create('currencies', function (Blueprint $table) { $table->id(); - $table->string('kode',9)->unique(); + $table->string('kode',3)->unique(); $table->string('name'); $table->timestamps(); $table->softDeletes(); diff --git a/Database/Migrations/2023_10_10_042307_create_guarantee_types_table.php b/Database/Migrations/2023_10_10_042307_create_guarantee_types_table.php new file mode 100644 index 0000000..74d7a90 --- /dev/null +++ b/Database/Migrations/2023_10_10_042307_create_guarantee_types_table.php @@ -0,0 +1,39 @@ +id(); + $table->string('kode',3)->unique(); + $table->string('name'); + $table->string('status', 1)->default('A'); + $table->timestamps(); + $table->softDeletes(); + + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('guarantee_types'); + } +}; diff --git a/Entities/GuaranteeType.php b/Entities/GuaranteeType.php new file mode 100644 index 0000000..7d7f6ee --- /dev/null +++ b/Entities/GuaranteeType.php @@ -0,0 +1,16 @@ +middleware(function ($request, $next) { + $this->user = Auth::guard('web')->user(); + return $next($request); + }); + } + + /** + * Display a listing of the GuaranteeTypes. + * + * @param \Modules\Writeoff\DataTables\GuaranteeTypeDataTable $dataTable + * + * @return mixed + */ + public function index(GuaranteeTypeDataTable $dataTable, Request $request) + { + if (is_null($this->user) || !$this->user->can('master.read')) { + abort(403, 'Sorry !! You are Unauthorized to view any master data !'); + } + + return $dataTable->render('writeoff::parameter.guarantee_types.index'); + } + + /** + * Store a newly created GuaranteeType in storage. + * + * @param \Illuminate\Http\Request $request + * + * @return mixed + */ + public function store(Request $request) + { + } + + /** + * Show the form for creating a new GuaranteeType. + */ + public function create() + { + + } + + /** + * Display the specified GuaranteeType. + * + * @param \Modules\Writeoff\Entities\GuaranteeType $branch + */ + public function show(GuaranteeType $branch) + { + + } + + /** + * Show the form for editing the specified GuaranteeType. + * + * @param $id + */ + public function edit($id) + { + + } + + /** + * Update the specified GuaranteeType in storage. + * + * @param \Illuminate\Http\Request $request + * @param \Modules\Writeoff\Entities\GuaranteeType $branch + * + * @return mixed + */ + public function update(Request $request, GuaranteeType $branch) + { + + } + + /** + * Remove the specified GuaranteeType from storage. + * + * @param \Modules\Writeoff\Entities\GuaranteeType $branch + * + * @return void + */ + public function destroy(GuaranteeType $branch) + { + + } + } diff --git a/Http/Requests/GuaranteeType/StoreGuaranteeTypeRequest.php b/Http/Requests/GuaranteeType/StoreGuaranteeTypeRequest.php new file mode 100644 index 0000000..705dc6f --- /dev/null +++ b/Http/Requests/GuaranteeType/StoreGuaranteeTypeRequest.php @@ -0,0 +1,75 @@ + + */ + public function rules() + : array + { + return [ + 'kode' => 'required|string|max:3|min:3|unique:guarantee_types,kode', + 'name' => 'required|string|max:100' + ]; + } + + public function ignored() + : string + { + return $this->id; + } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator) + : void + { + $validator->after(function (Validator $validator) { + if ($validator->errors()->any()) { + $errors = json_decode($validator->errors()->toJson(), true); + + + foreach ($errors as $key => $value) { + flash($value[0]); + } + return redirect() + ->route('parameter.guarantee_types.index') + ->with('error', 'Guarante Type created failed.'); + } + + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Guarante Type created failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + } diff --git a/Http/Requests/GuaranteeType/UpdateGuaranteeTypeRequest.php b/Http/Requests/GuaranteeType/UpdateGuaranteeTypeRequest.php new file mode 100644 index 0000000..d4b26c5 --- /dev/null +++ b/Http/Requests/GuaranteeType/UpdateGuaranteeTypeRequest.php @@ -0,0 +1,73 @@ + + */ + public function rules() + : array + { + $this->_id = json_decode(json_decode(file_get_contents('php://input'))->components[0]->snapshot)->data->id; + + return [ + 'kode' => 'required|string|max:3|min:3|unique:guarantee_types,kode,' . $this->_id, + 'name' => 'required|string|max:100' + ]; + } + + /** + * 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('parameter.guarantee_types.index') + ->with('error', 'Guarante Type updated failed.'); + } + }); + } + + protected function failedValidation(Validator|\Illuminate\Contracts\Validation\Validator $validator) + : JsonResponse + { + $errors = (new ValidationException($validator))->errors(); + + throw new HttpResponseException(response()->json([ + 'success' => false, + 'errors' => $errors, + 'messages' => 'Guarante Type updated failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + + } diff --git a/Livewire/Currency/CurrencyModal.php b/Livewire/Currency/CurrencyModal.php index 60c7315..5c730ee 100644 --- a/Livewire/Currency/CurrencyModal.php +++ b/Livewire/Currency/CurrencyModal.php @@ -5,8 +5,8 @@ use Illuminate\Support\Facades\DB; use Livewire\Component; use Modules\Writeoff\Entities\Currency; - use Modules\Writeoff\Http\Requests\Currency\StoreCurrencyRequest; - use Modules\Writeoff\Http\Requests\Currency\UpdateCurrencyRequest; + use Modules\Writeoff\Http\Requests\Currency\StoreGuaranteeTypeRequest; + use Modules\Writeoff\Http\Requests\Currency\UpdateGuaranteeTypeRequest; class CurrencyModal extends Component { @@ -29,9 +29,9 @@ protected function rules() { if ($this->edit_mode) { - $request = new UpdateCurrencyRequest(); + $request = new UpdateGuaranteeTypeRequest(); } else { - $request = new StoreCurrencyRequest(); + $request = new StoreGuaranteeTypeRequest(); } return $request->rules(); diff --git a/Livewire/GuaranteeType/GuaranteeTypeModal.php b/Livewire/GuaranteeType/GuaranteeTypeModal.php new file mode 100644 index 0000000..e04423c --- /dev/null +++ b/Livewire/GuaranteeType/GuaranteeTypeModal.php @@ -0,0 +1,94 @@ + 'delete', + 'update' => 'update', + ]; + + public function render() + { + return view('writeoff::livewire.guarantee-type.guarantee-type-modal'); + } + + protected function rules() + { + if ($this->edit_mode) { + $request = new UpdateGuaranteeTypeRequest(); + } else { + $request = new StoreGuaranteeTypeRequest(); + } + + return $request->rules(); + } + + public function submit() + { + $this->validate(); + + // Validate the form input data + DB::transaction(function () { + // Prepare the data for creating a new user + $data = [ + 'kode' => $this->kode, + 'name' => $this->name + ]; + + if ($this->edit_mode) { + // Emit a success event with a message + $guarantee_type = GuaranteeType::find($this->id); + $guarantee_type->update($data); + + $this->dispatch('success', __('Guarante Type updated')); + } else { + // Emit a success event with a message + GuaranteeType::create($data); + $this->dispatch('success', __('New Guarante Type created')); + } + }); + + // Reset the form fields after successful submission + $this->reset(); + } + + public function delete($id) + { + GuaranteeType::destroy($id); + + // Emit a success event with a message + $this->dispatch('success', 'Guarante Type successfully deleted'); + } + + public function update($id) + { + $this->edit_mode = true; + + $guarantee_type = GuaranteeType::find($id); + + $this->id = $guarantee_type->id; + $this->kode = $guarantee_type->kode; + $this->name = $guarantee_type->name; + } + + public function hydrate() + { + $this->resetErrorBag(); + $this->resetValidation(); + } + } + diff --git a/Resources/views/livewire/guarantee-type/guarantee-type-modal.blade.php b/Resources/views/livewire/guarantee-type/guarantee-type-modal.blade.php new file mode 100644 index 0000000..783653d --- /dev/null +++ b/Resources/views/livewire/guarantee-type/guarantee-type-modal.blade.php @@ -0,0 +1,72 @@ + diff --git a/Resources/views/parameter/guarantee_types/_actions.blade.php b/Resources/views/parameter/guarantee_types/_actions.blade.php new file mode 100644 index 0000000..0b4ebf6 --- /dev/null +++ b/Resources/views/parameter/guarantee_types/_actions.blade.php @@ -0,0 +1,23 @@ + + Actions + + + + + diff --git a/Resources/views/parameter/guarantee_types/_draw-scripts.js b/Resources/views/parameter/guarantee_types/_draw-scripts.js new file mode 100644 index 0000000..b9c8298 --- /dev/null +++ b/Resources/views/parameter/guarantee_types/_draw-scripts.js @@ -0,0 +1,37 @@ +// Initialize KTMenu +KTMenu.init(); + +// Add click event listener to delete buttons +document.querySelectorAll('[data-kt-action="delete_row"]').forEach(function (element) { + element.addEventListener('click', function () { + Swal.fire({ + text: 'Are you sure you want to remove?', + icon: 'warning', + buttonsStyling: false, + showCancelButton: true, + confirmButtonText: 'Yes', + cancelButtonText: 'No', + customClass: { + confirmButton: 'btn btn-danger', + cancelButton: 'btn btn-secondary', + } + }).then((result) => { + if (result.isConfirmed) { + Livewire.dispatch('delete', { id : this.getAttribute('data-kt-id') }); + } + }); + }); +}); + +// Add click event listener to update buttons +document.querySelectorAll('[data-kt-action="update_row"]').forEach(function (element) { + element.addEventListener('click', function () { + Livewire.dispatch('update', { id : this.getAttribute('data-kt-id') }); + }); +}); + +// Listen for 'success' event emitted by Livewire +Livewire.on('success', (message) => { + // Reload the users-table datatable + LaravelDataTables['guarantee-type-table'].ajax.reload(); +}); diff --git a/Resources/views/parameter/guarantee_types/index.blade.php b/Resources/views/parameter/guarantee_types/index.blade.php new file mode 100644 index 0000000..a1cdc96 --- /dev/null +++ b/Resources/views/parameter/guarantee_types/index.blade.php @@ -0,0 +1,72 @@ + + + @section('title') + Jenis Jaminan + @endsection + + @section('breadcrumbs') + {{ Breadcrumbs::render('parameter.guarantee-types') }} + @endsection + +
+ +
+ +
+ +
+ {!! getIcon('magnifier', 'fs-3 position-absolute ms-5') !!} + +
+ +
+ + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + +
+ +
+ {{ $dataTable->table() }} +
+ +
+ +
+ + @push('scripts') + {{ $dataTable->scripts() }} + + @endpush + +
diff --git a/Resources/views/partials/menu/_app.blade.php b/Resources/views/partials/menu/_app.blade.php index fb40132..7f2e0a9 100644 --- a/Resources/views/partials/menu/_app.blade.php +++ b/Resources/views/partials/menu/_app.blade.php @@ -25,7 +25,15 @@ - Currency + Mata Uang + + + + + + + + Jenis Jaminan diff --git a/Routes/breadcrumbs.php b/Routes/breadcrumbs.php index 138aa57..b2e7257 100644 --- a/Routes/breadcrumbs.php +++ b/Routes/breadcrumbs.php @@ -17,3 +17,8 @@ $trail->parent('parameter'); $trail->push('Mata Uang', route('parameter.currencies.index')); }); + + Breadcrumbs::for('parameter.guarantee-types', function (BreadcrumbTrail $trail) { + $trail->parent('parameter'); + $trail->push('Jenis Jaminan', route('parameter.guarantee_types.index')); + }); diff --git a/Routes/web.php b/Routes/web.php index 23d6194..f63b6a2 100644 --- a/Routes/web.php +++ b/Routes/web.php @@ -14,4 +14,5 @@ Route::name('parameter.')->prefix('parameter')->group(function() { Route::get('branches', 'BranchController@index')->name('branches.index'); Route::get('currencies', 'CurrencyController@index')->name('currencies.index'); + Route::get('guarantee-types', 'GuaranteeTypeController@index')->name('guarantee_types.index'); });