From 27fc3e56dc38cdb628d741bb85c76aae8c04737e Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 15 Nov 2023 15:05:46 +0700 Subject: [PATCH] add module rekening --- DataTables/RekeningDataTable.php | 124 +++++++++++++ ...023_11_15_062727_create_rekening_table.php | 50 +++++ Entities/Branch.php | 6 + Entities/Rekening.php | 43 +++++ Http/Controllers/RekeningController.php | 37 ++++ .../Rekening/StoreRekeningRequest.php | 80 ++++++++ .../Rekening/UpdateRekeningRequest.php | 77 ++++++++ Livewire/Rekening/RekeningModal.php | 130 +++++++++++++ .../rekening/rekening-modal.blade.php | 171 ++++++++++++++++++ .../parameter/rekening/_actions.blade.php | 23 +++ .../views/parameter/rekening/_draw-scripts.js | 37 ++++ .../views/parameter/rekening/index.blade.php | 72 ++++++++ Resources/views/partials/menu/_app.blade.php | 8 + Routes/breadcrumbs.php | 4 + Routes/web.php | 1 + 15 files changed, 863 insertions(+) create mode 100644 DataTables/RekeningDataTable.php create mode 100644 Database/Migrations/2023_11_15_062727_create_rekening_table.php create mode 100644 Entities/Rekening.php create mode 100644 Http/Controllers/RekeningController.php create mode 100644 Http/Requests/Rekening/StoreRekeningRequest.php create mode 100644 Http/Requests/Rekening/UpdateRekeningRequest.php create mode 100644 Livewire/Rekening/RekeningModal.php create mode 100644 Resources/views/livewire/rekening/rekening-modal.blade.php create mode 100644 Resources/views/parameter/rekening/_actions.blade.php create mode 100644 Resources/views/parameter/rekening/_draw-scripts.js create mode 100644 Resources/views/parameter/rekening/index.blade.php diff --git a/DataTables/RekeningDataTable.php b/DataTables/RekeningDataTable.php new file mode 100644 index 0000000..1c0c4dc --- /dev/null +++ b/DataTables/RekeningDataTable.php @@ -0,0 +1,124 @@ +filter(function ($query) { + if (request()->has('search')) { + $search = request()->get('search'); + $query->where('nomor_rekening', 'like', "%" . $search['value'] . "%"); + } + })->addIndexColumn()->editColumn('registered_at', function ($row) { + $date = Carbon::create($row->registered_at); + return $date->locale('id')->translatedFormat('d F Y'); + })->editColumn('debitur', function ($row) { + $debitur = null; + if($row->debitur_id){ + $debitur = Debitur::find($row->debitur_id); + } + return $debitur->id ? $debitur->kode.' - '.$debitur->name : '-'; + + })->editColumn('branch', function ($row) { + $branch = null; + if($row->branch_id){ + $branch = Branch::find($row->branch_id); + } + return $branch->id ? $branch->kode.' - '.$branch->name : '-'; + })->editColumn('product', function ($row) { + $product = null; + if($row->product_id){ + $product = Product::find($row->product_id); + } + return $product->id ? $product->kode.' - '.$product->name : '-'; + })->editColumn('currency', function ($row) { + return $row->currency_id ? Currency::find($row->currency_id)->name : '-'; + })->editColumn('status', function ($row) { + $status = $row->status ? 'Aktif' : 'Tidak Aktif'; + $oto = $row->authorized_at !== null ? 'Authorised' : 'Not Authorised'; + return $status . ' ' . $oto; + })->rawColumns(['action', 'status'])->addColumn('action', function ($rekening) { + return view('writeoff::parameter.rekening._actions', compact('rekening')); + })->setRowId('id'); + } + + /** + * Get the query source of dataTable. + */ + public function query(Rekening $model) + : QueryBuilder + { + return $model->newQuery(); + } + + /** + * Optional method if you want to use the html builder. + */ + public function html() + : HtmlBuilder + { + return $this->builder() + ->setTableId('rekening-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/debitur/_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('nomor_rekening')->title('Nomor Rekening'), + Column::make('debitur')->title('Debitur'), + Column::make('branch')->title('Cabang'), + Column::make('product')->title('Produk'), + Column::make('currency')->title('Mata Uang'), + Column::make('registered_at')->title('Tanggal Buka Rekening'), + Column::make('status')->title('Status'), + Column::computed('action')->exportable(false)->printable(false)->width(60)->addClass('text-center'), + ]; + } + + /** + * Get the filename for export. + */ + protected function filename() + : string + { + return 'Rekening_' . date('YmdHis'); + } + } diff --git a/Database/Migrations/2023_11_15_062727_create_rekening_table.php b/Database/Migrations/2023_11_15_062727_create_rekening_table.php new file mode 100644 index 0000000..ad2f88d --- /dev/null +++ b/Database/Migrations/2023_11_15_062727_create_rekening_table.php @@ -0,0 +1,50 @@ +id(); + $table->foreignIdFor(Branch::class)->constrained()->onDelete('cascade'); + $table->foreignIdFor(Debitur::class)->constrained('debitur')->onDelete('cascade'); + $table->foreignIdFor(Product::class)->constrained()->onDelete('cascade'); + $table->foreignIdFor(Currency::class)->constrained()->onDelete('cascade'); + $table->string('nomor_rekening', 10)->unique(); + $table->date('registered_at')->nullable(); + + $table->string('limit_ref',10)->nullable(); + $table->boolean('status_rekening')->default(true)->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('rekening'); + } + }; diff --git a/Entities/Branch.php b/Entities/Branch.php index ad4e8b0..a40201d 100644 --- a/Entities/Branch.php +++ b/Entities/Branch.php @@ -20,4 +20,10 @@ { return $this->hasMany(Debitur::class); } + + public function rekenings() + { + return $this->hasMany(Rekening::class); + } + } diff --git a/Entities/Rekening.php b/Entities/Rekening.php new file mode 100644 index 0000000..512ad00 --- /dev/null +++ b/Entities/Rekening.php @@ -0,0 +1,43 @@ +belongsTo(Branch::class); + } + + public function debitur() + { + return $this->belongsTo(Debitur::class); + } + + public function product() + { + return $this->belongsTo(Product::class); + } + + public function currency() + { + return $this->belongsTo(Currency::class); + } + + } diff --git a/Http/Controllers/RekeningController.php b/Http/Controllers/RekeningController.php new file mode 100644 index 0000000..02cf50c --- /dev/null +++ b/Http/Controllers/RekeningController.php @@ -0,0 +1,37 @@ +middleware(function ($request, $next) { + $this->user = Auth::guard('web')->user(); + return $next($request); + }); + } + + /** + * Display a listing of the Rekenings. + * + * @param \Modules\Writeoff\DataTables\RekeningDataTable $dataTable + * + * @return mixed + */ + public function index(RekeningDataTable $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.rekening.index'); + } + } diff --git a/Http/Requests/Rekening/StoreRekeningRequest.php b/Http/Requests/Rekening/StoreRekeningRequest.php new file mode 100644 index 0000000..9bd315d --- /dev/null +++ b/Http/Requests/Rekening/StoreRekeningRequest.php @@ -0,0 +1,80 @@ + + */ + public function rules() + : array + { + return [ + 'nomor_rekening' => 'required|numeric|digits:10|unique:rekening,nomor_rekening', + 'branch_id' => 'required|integer|exists:branches,id', + 'debitur_id' => 'required|integer|exists:debitur,id', + 'product_id' => 'required|integer|exists:products,id', + 'currency_id' => 'required|integer|exists:currencies,id', + 'status' => 'nullable|boolean', + 'status_rekening' => 'nullable|boolean', + 'limit_ref' => 'nullable|string|max:10', + 'registered_at' => 'nullable|date_format:Y-m-d' + ]; + } + + 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.rekening.index')->with('error', 'Rekening 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' => 'Rekening created failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + } diff --git a/Http/Requests/Rekening/UpdateRekeningRequest.php b/Http/Requests/Rekening/UpdateRekeningRequest.php new file mode 100644 index 0000000..b34a5e9 --- /dev/null +++ b/Http/Requests/Rekening/UpdateRekeningRequest.php @@ -0,0 +1,77 @@ + + */ + public function rules() + : array + { + $this->_id = json_decode(json_decode(file_get_contents('php://input'))->components[0]->snapshot)->data->id; + + return [ + 'nomor_rekening' => 'required|numeric|digits:10|unique:rekening,nomor_rekening,' . $this->_id, + 'branch_id' => 'required|integer|exists:branches,id', + 'debitur_id' => 'required|integer|exists:debitur,id', + 'product_id' => 'required|integer|exists:products,id', + 'currency_id' => 'required|integer|exists:currencies,id', + 'status' => 'required|boolean', + 'status_rekening' => 'required|boolean', + 'limit_ref' => 'nullable|string|max:10', + 'registered_at' => 'nullable|date_format:Y-m-d' + ]; + } + + /** + * 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.rekening.index')->with('error', 'Rekening 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' => 'Rekening updated failed.' + ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); + } + } diff --git a/Livewire/Rekening/RekeningModal.php b/Livewire/Rekening/RekeningModal.php new file mode 100644 index 0000000..a74672f --- /dev/null +++ b/Livewire/Rekening/RekeningModal.php @@ -0,0 +1,130 @@ + 'delete', + 'update' => 'update', + ]; + + public function render() + { + $cabang = Branch::all(); + $debitur = Debitur::all(); + $product = Product::all(); + $currency = Currency::all(); + + return view('writeoff::livewire.rekening.rekening-modal', compact([ + 'cabang', + 'debitur', + 'product', + 'currency' + ])); + } + + public function submit() + { + $this->validate(); + + // Validate the form input data + DB::transaction(function () { + // Prepare the data for creating a new user + $data = [ + 'nomor_rekening' => $this->nomor_rekening, + 'branch_id' => $this->branch_id, + 'debitur_id' => $this->debitur_id, + 'product_id' => $this->product_id, + 'currency_id' => $this->currency_id, + 'status' => $this->status, + 'status_rekening' => $this->status_rekening, + 'limit_ref' => $this->limit_ref, + 'registered_at' => $this->registered_at + ]; + + + if ($this->edit_mode) { + // Emit a success event with a message + $rekening = Rekening::find($this->id); + $rekening->update($data); + + $this->dispatch('success', __('Rekening updated')); + } else { + // Emit a success event with a message + Rekening::create($data); + $this->dispatch('success', __('New Rekening created')); + } + }); + + // Reset the form fields after successful submission + $this->reset(); + } + + public function update($id) + { + $this->edit_mode = true; + + $rekening = Rekening::find($id); + + $this->id = $rekening->id; + $this->nomor_rekening = $rekening->nomor_rekening; + $this->branch_id = $rekening->branch_id; + $this->debitur_id = $rekening->debitur_id; + $this->product_id = $rekening->product_id; + $this->currency_id = $rekening->currency_id; + $this->status = $rekening->status == 1 ? true : false; + $this->status_rekening = $rekening->status_rekening == 1 ? true : false; + $this->limit_ref = $rekening->limit_ref; + $this->registered_at = $rekening->registered_at; + } + + public function delete($id) + { + Rekening::destroy($id); + + // Emit a success event with a message + $this->dispatch('success', 'Rekening successfully deleted'); + } + + public function hydrate() + { + $this->resetErrorBag(); + $this->resetValidation(); + } + + protected function rules() + { + if ($this->edit_mode) { + $request = new UpdateRekeningRequest(); + } else { + $request = new StoreRekeningRequest(); + } + return $request->rules(); + } + } + diff --git a/Resources/views/livewire/rekening/rekening-modal.blade.php b/Resources/views/livewire/rekening/rekening-modal.blade.php new file mode 100644 index 0000000..faec0f8 --- /dev/null +++ b/Resources/views/livewire/rekening/rekening-modal.blade.php @@ -0,0 +1,171 @@ + diff --git a/Resources/views/parameter/rekening/_actions.blade.php b/Resources/views/parameter/rekening/_actions.blade.php new file mode 100644 index 0000000..bdcd712 --- /dev/null +++ b/Resources/views/parameter/rekening/_actions.blade.php @@ -0,0 +1,23 @@ + + Actions + + + + + diff --git a/Resources/views/parameter/rekening/_draw-scripts.js b/Resources/views/parameter/rekening/_draw-scripts.js new file mode 100644 index 0000000..efae5fc --- /dev/null +++ b/Resources/views/parameter/rekening/_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['rekening-table'].ajax.reload(); +}); diff --git a/Resources/views/parameter/rekening/index.blade.php b/Resources/views/parameter/rekening/index.blade.php new file mode 100644 index 0000000..b590928 --- /dev/null +++ b/Resources/views/parameter/rekening/index.blade.php @@ -0,0 +1,72 @@ + + + @section('title') + Rekening + @endsection + + @section('breadcrumbs') + {{ Breadcrumbs::render('parameter.rekening') }} + @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 b67497c..7d9aae8 100644 --- a/Resources/views/partials/menu/_app.blade.php +++ b/Resources/views/partials/menu/_app.blade.php @@ -68,6 +68,14 @@ Debitur + + + + + + Rekening + + diff --git a/Routes/breadcrumbs.php b/Routes/breadcrumbs.php index 7452157..5455a34 100644 --- a/Routes/breadcrumbs.php +++ b/Routes/breadcrumbs.php @@ -42,3 +42,7 @@ $trail->parent('parameter'); $trail->push('Debitur', route('parameter.debitur.index')); }); + Breadcrumbs::for('parameter.rekening', function (BreadcrumbTrail $trail) { + $trail->parent('parameter'); + $trail->push('Rekening', route('parameter.rekening.index')); + }); diff --git a/Routes/web.php b/Routes/web.php index e3ccfb7..dbd4dd0 100644 --- a/Routes/web.php +++ b/Routes/web.php @@ -19,4 +19,5 @@ Route::name('parameter.')->prefix('parameter')->group(function() { Route::get('facility-types', 'FacilityTypeController@index')->name('facility_types.index'); Route::get('loan-types', 'LoanTypeController@index')->name('loan_types.index'); Route::get('debitur', 'DebiturController@index')->name('debitur.index'); + Route::get('rekening', 'RekeningController@index')->name('rekening.index'); });