diff --git a/DataTables/HapusBukuDataTable.php b/DataTables/HapusBukuDataTable.php index f53d51c..0cef990 100644 --- a/DataTables/HapusBukuDataTable.php +++ b/DataTables/HapusBukuDataTable.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Builder as QueryBuilder; use Illuminate\Support\Number; use Modules\Writeoff\Entities\Branch; + use Modules\Writeoff\Entities\Debitur; use Modules\Writeoff\Entities\FacilityType; use Modules\Writeoff\Entities\LoanType; use Modules\Writeoff\Entities\HapusBuku; @@ -61,6 +62,8 @@ })->addIndexColumn()->editColumn('tanggal_hapus_buku', function ($row) { $date = Carbon::create($row->tanggal_hapus_buku); return $date->locale('id')->translatedFormat('d F Y'); + })->editColumn('debitur', function ($row) { + return Debitur::where('kode', $row->kode_debitur)->first()->name; })->editColumn('cabang', function ($row) { return Branch::where('kode', $row->kode_cabang)->first()->name; })->editColumn('jenis_pinjaman', function ($row) { diff --git a/Database/Migrations/2023_12_14_065323_create_detail_jaminan_table.php b/Database/Migrations/2023_12_14_065323_create_detail_jaminan_table.php new file mode 100644 index 0000000..795910d --- /dev/null +++ b/Database/Migrations/2023_12_14_065323_create_detail_jaminan_table.php @@ -0,0 +1,41 @@ +id(); + $table->string('nomor_pinjaman'); + $table->foreignIdFor(GuaranteeType::class); + $table->string('nomor_jaminan'); + $table->double('nilai_jaminan', 20, 2); + $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('detail_jaminan'); + } + }; diff --git a/Entities/Rekening.php b/Entities/Rekening.php index 793c46c..547d0fd 100644 --- a/Entities/Rekening.php +++ b/Entities/Rekening.php @@ -30,9 +30,9 @@ return $this->belongsTo(Debitur::class); } - public function product() + public function loan_type() { - return $this->belongsTo(Product::class); + return $this->belongsTo(LoanType::class); } public function currency() diff --git a/Http/Controllers/CurrencyController.php b/Http/Controllers/CurrencyController.php index 3dba43b..21fc622 100644 --- a/Http/Controllers/CurrencyController.php +++ b/Http/Controllers/CurrencyController.php @@ -1,5 +1,4 @@ rekening){ + if ($request->rekening) { return redirect()->route('pencatatan.hapus_buku.create', ['rekening' => $request->rekening]); - }else{ + } else { return $dataTable->render('writeoff::pencatatan.hapus_buku.index', ['add' => false]); } } @@ -69,20 +71,30 @@ $totalbayar = 0; - $rekening = Rekening::with('product', 'debitur','branch','currency') - ->where('nomor_rekening', $request->rekening) - ->whereDoesntHave('hapusBuku') - ->whereHas('product', function ($query) { - $query->whereBetween('kode', [3000, 3999]); - }) - ->get() - ->first(); + $rekening = Rekening::with('loan_type', 'debitur', 'branch', 'currency') + ->where('nomor_rekening', $request->rekening) + ->whereDoesntHave('hapusBuku') + ->whereHas('loan_type', function ($query) { + $query->whereBetween('kode', [3000, 3999]); + }) + ->get() + ->first(); - return view('writeoff::pencatatan.hapus_buku.add', compact('branch', 'loan_type', 'facility_type', 'currency','rekening','totalbayar')); + return view('writeoff::pencatatan.hapus_buku.add', compact('branch', 'loan_type', 'facility_type', 'currency', 'rekening', 'totalbayar')); } - public function store(Request $request) + public function store(StoreHapusBukuRequest $request) { - dd($request->all()); + $validated = $request->validated(); + + + if ($validated) { + try { + HapusBuku::create($validated); + echo json_encode(['status' => 'success', 'message' => 'Hapus Buku created successfully.']); + } catch (Exception $e) { + echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); + } + } } } diff --git a/Http/Requests/HapusBuku/StoreHapusBukuRequest.php b/Http/Requests/HapusBuku/StoreHapusBukuRequest.php index db7031b..c21f060 100644 --- a/Http/Requests/HapusBuku/StoreHapusBukuRequest.php +++ b/Http/Requests/HapusBuku/StoreHapusBukuRequest.php @@ -28,9 +28,9 @@ : array { return [ - 'nomor_pinjaman' => 'required|integer', - 'kode_jenis_pinjaman' => 'required|integer', - 'kode_debitur' => 'required|integer', + 'nomor_pinjaman' => 'required|numeric|unique:hapus_buku,nomor_pinjaman', + 'kode_jenis_pinjaman' => 'required|numeric', + 'kode_debitur' => 'required|numeric', 'nama_debitur' => 'required|string', 'alamat_debitur' => 'nullable|string', 'npwp_debitur' => 'nullable|string', @@ -38,22 +38,22 @@ 'kode_mata_uang' => 'required|string', 'tanggal_hapus_buku' => 'required|date|before:tomorrow', 'nomor_fasilitas' => 'required|string', - 'kode_jenis_fasilitas' => 'required|integer', + 'kode_jenis_fasilitas' => 'required|numeric', 'nilai_plafond_awal' => 'required|numeric', - 'suku_bunga' => 'required|integer', + 'suku_bunga' => 'required|numeric', 'baki_debet' => 'required|numeric', 'jumlah_bunga' => 'required|numeric', 'jumlah_kewajiban_lain' => 'nullable|numeric', 'total_kewajiban' => 'nullable|numeric', 'total_bunga_extra' => 'required|numeric', 'bunga_ekstra' => 'nullable|numeric', - 'bunga_non_ekstra' => 'required|numeric', + 'bunga_non_ekstra' => 'nullable|numeric', 'denda' => 'nullable|numeric', - 'tagihan_lain' => 'required|numeric', + 'tagihan_lain' => 'nullable|numeric', 'biaya_lain' => 'required|numeric', 'total_all_kewajiban' => 'nullable|numeric', 'memo_persetujuan' => 'nullable|string', - 'lama_hari' => 'nullable|integer', + 'lama_hari' => 'nullable|numeric', 'proses_hukum' => 'nullable|string', 'komitmen_debitur' => 'nullable|string', 'keterangan' => 'nullable|string', @@ -82,7 +82,7 @@ flash($value[0]); } return redirect() - ->route('pencatatan.hapus_buku.index') + ->route('pencatatan.hapus_buku.create') ->with('error', 'Hapus Buku created failed.'); } @@ -100,4 +100,13 @@ 'messages' => 'Hapus Buku created failed.' ], JsonResponse::HTTP_UNPROCESSABLE_ENTITY)); } + + protected function prepareForValidation() + : void + { + + $this->merge([ + 'status' => $this->status=='on' ? 1 : 0, + ]); + } } diff --git a/Livewire/HapusBuku/NomorPinjamanModal.php b/Livewire/HapusBuku/NomorPinjamanModal.php index eee70fa..f66b147 100644 --- a/Livewire/HapusBuku/NomorPinjamanModal.php +++ b/Livewire/HapusBuku/NomorPinjamanModal.php @@ -3,12 +3,17 @@ namespace Modules\Writeoff\Livewire\HapusBuku; use Livewire\Component; + use Modules\Writeoff\Entities\HapusBuku; use Modules\Writeoff\Entities\Rekening; class NomorPinjamanModal extends Component { public $nomor_pinjaman; + protected $listeners = [ + 'delete' => 'delete' + ]; + public function render() { return view('writeoff::livewire.hapus-buku.nomor-pinjaman-modal'); @@ -20,16 +25,16 @@ 'nomor_pinjaman' => 'required', ]); - $rekenings = Rekening::with('product', 'debitur') + $rekenings = Rekening::with('loan_type', 'debitur') ->where('nomor_rekening', $this->nomor_pinjaman) ->whereDoesntHave('hapusBuku') - ->whereHas('product', function ($query) { + ->whereHas('loan_type', function ($query) { $query->whereBetween('kode', [3000, 3999]); }) ->get() ->first(); - if ($rekenings->count() > 0) { + if ($rekenings) { $this->dispatch('success', __('Nomor Pinjaman ditemukan')); $this->redirect(route('pencatatan.hapus_buku.index', ['rekening' => $this->nomor_pinjaman])); } else { @@ -37,7 +42,14 @@ } //$this->dispatch('showHapusBuku'); + } + public function delete($id) + { + HapusBuku::destroy($id); + + // Emit a success event with a message + $this->dispatch('success', 'Hapus Buku successfully deleted'); } } diff --git a/Resources/views/pencatatan/hapus_buku/add.blade.php b/Resources/views/pencatatan/hapus_buku/add.blade.php index edf8fa1..dad953c 100644 --- a/Resources/views/pencatatan/hapus_buku/add.blade.php +++ b/Resources/views/pencatatan/hapus_buku/add.blade.php @@ -43,11 +43,11 @@ - @foreach($loan_type as $item) @php $selected = ''; @endphp - @if($item->kode == $rekening->product->kode) + @if($item->kode == $rekening->loan_type->kode) @php $selected = 'selected'; @endphp @endif @@ -114,7 +114,7 @@ - @foreach($branch as $item) @php $selected = ''; @endphp @@ -133,7 +133,7 @@ - @foreach($currency as $item) @php $selected = ''; @endphp @@ -382,7 +382,7 @@
- + @@ -421,6 +421,30 @@ }); $(function () { + $("#kt_modal_add_hapus_buku_form").submit(function (e) { + e.preventDefault(); // avoid to execute the actual submit of the form. + + var form = $(this); + var actionUrl = form.attr('action'); + + $.ajax({ + type: "POST", + url: actionUrl, + data: form.serialize(), + success: function (data) { + var _data = JSON.parse(data); + toastr.success(_data.message); + window.location.href = "{{ route('pencatatan.hapus_buku.index') }}"; + }, + error: function (data, textStatus, errorThrown) { + var errors = data.responseJSON.errors; + $.each(errors, function (key, value) { + toastr.error(value); + }); + } + }); + }); + $('#baki_debet,#suku_bunga,#jumlah_bunga,#jumlah_kewajiban_lain,#lama_hari').on('change', function () { calcTotKewajiban(); }) @@ -482,8 +506,8 @@ function calcTotAllKewajiban() { var total; - var biaya_lain = $('#biaya_lain').val() ?? 0; - var denda = $('#denda').val() ?? 0; + var biaya_lain = $('#biaya_lain').val() === '' ? 0 : $('#biaya_lain').val(); + var denda = $('#denda').val() === '' ? 0 : $('#denda').val(); total = parseFloat($('#total_kewajiban').val()) + parseFloat($('#total_bunga_extra').val()) + parseFloat($('#bunga_extra').val()) + parseFloat(denda) + parseFloat(biaya_lain); diff --git a/Resources/views/pencatatan/hapus_buku/index.blade.php b/Resources/views/pencatatan/hapus_buku/index.blade.php index 4128b75..208ca0a 100644 --- a/Resources/views/pencatatan/hapus_buku/index.blade.php +++ b/Resources/views/pencatatan/hapus_buku/index.blade.php @@ -66,7 +66,6 @@ }); document.addEventListener('livewire:initialized', function () { Livewire.on('success', function () { - $('#kt_modal_add_hapus_buku').modal('show'); $('#kt_modal_nomor_pinjaman').modal('hide'); window.LaravelDataTables['hapus-buku-table'].ajax.reload(); });