From c714b08de95239bed28418f6de0eabeaec97e37d Mon Sep 17 00:00:00 2001 From: daengdeni Date: Mon, 11 Dec 2023 14:46:21 +0700 Subject: [PATCH] update hapus buku --- Http/Controllers/HapusBukuController.php | 16 +- Livewire/HapusBuku/HapusBukuModal.php | 62 +- Livewire/HapusBuku/NomorPinjamanModal.php | 7 +- .../hapus-buku/hapus-buku-modal.blade.php | 770 +++++++++--------- .../views/pencatatan/hapus_buku/add.blade.php | 442 ++++++++-- 5 files changed, 818 insertions(+), 479 deletions(-) diff --git a/Http/Controllers/HapusBukuController.php b/Http/Controllers/HapusBukuController.php index 60c1cf5..69d4b47 100644 --- a/Http/Controllers/HapusBukuController.php +++ b/Http/Controllers/HapusBukuController.php @@ -6,6 +6,11 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Modules\Writeoff\DataTables\HapusBukuDataTable; + use Modules\Writeoff\Entities\Branch; + use Modules\Writeoff\Entities\Currency; + use Modules\Writeoff\Entities\FacilityType; + use Modules\Writeoff\Entities\LoanType; + use function Termwind\render; class HapusBukuController extends Controller { @@ -33,8 +38,7 @@ } if($request->rekening){ - $this->dispatch('show', $request->rekening); - return $dataTable->render('writeoff::pencatatan.hapus_buku.add', ['add' => true]); + return redirect()->route('pencatatan.hapus_buku.create', ['rekening' => $request->rekening]); }else{ return $dataTable->render('writeoff::pencatatan.hapus_buku.index', ['add' => false]); } @@ -53,6 +57,12 @@ abort(403, 'Sorry !! You are Unauthorized to view any master data !'); } - return $dataTable->render('writeoff::pencatatan.hapus_buku.add'); + $branch = Branch::all(); + $loan_type = LoanType::all(); + $facility_type = FacilityType::all(); + $currency = Currency::all(); + $rekening = $request->rekening; + + return view('writeoff::pencatatan.hapus_buku.add', compact('branch', 'loan_type', 'facility_type', 'currency','rekening')); } } diff --git a/Livewire/HapusBuku/HapusBukuModal.php b/Livewire/HapusBuku/HapusBukuModal.php index b2426b7..a261b0a 100644 --- a/Livewire/HapusBuku/HapusBukuModal.php +++ b/Livewire/HapusBuku/HapusBukuModal.php @@ -11,6 +11,7 @@ use Modules\Writeoff\Entities\FacilityType; use Modules\Writeoff\Entities\HapusBuku; use Modules\Writeoff\Entities\LoanType; + use Modules\Writeoff\Entities\Rekening; use Modules\Writeoff\Http\Requests\HapusBuku\StoreHapusBukuRequest; use Modules\Writeoff\Http\Requests\HapusBuku\UpdateHapusBukuRequest; @@ -47,34 +48,35 @@ public $komitmen_debitur; public $keterangan; public $status; + public $rekening; public $edit_mode = false; protected $listeners = [ 'delete' => 'delete', 'update' => 'update', - 'show' => 'show' + 'show' => 'show' ]; - public function render($rekenings = null) + public function render() { - $rekening=''; - if($rekenings) { - $rekening = $rekenings->first(); - } - $branch = Branch::all(); - $loan_type = LoanType::all(); - $facility_type = FacilityType::all(); - $currency = Currency::all(); + $this->rekening = request()->rekening; - return view('writeoff::livewire.hapus-buku.hapus-buku-modal', compact('branch', 'loan_type', 'facility_type', 'currency','rekening')); + $branch = Branch::all(); + $loan_type = LoanType::all(); + $facility_type = FacilityType::all(); + $currency = Currency::all(); + + + $this->dispatch('show'); + return view('writeoff::livewire.hapus-buku.hapus-buku-modal', compact('branch', 'loan_type', 'facility_type', 'currency')); } public function submit() { - if($this->action=="continue"){ + if ($this->action == "continue") { $this->addError('nomor_pinjaman', 'Debitur Tidak Ditemukan'); - }else { + } else { $this->validate(); @@ -134,13 +136,6 @@ } - public function show($rekening) - { - $rekening = json_decode($rekening); - $this->nomor_pinjaman = $rekening->nomor_rekening; - - } - public function update($id) { $this->edit_mode = true; @@ -180,6 +175,24 @@ $this->status = $hapus_buku->status == 1; } + public function show() + { + + $rekenings = Rekening::with('product', 'debitur') + ->where('nomor_rekening', $this->rekening) + ->whereDoesntHave('hapusBuku') + ->whereHas('product', function ($query) { + $query->whereBetween('kode', [3000, 3999]); + }) + ->get() + ->first(); + if($rekenings) { + $this->rekening = $rekenings->nomor_rekening; + $this->nomor_pinjaman = $rekenings->nomor_rekening; + } + + } + public function getDebitur() { $debitur = Debitur::where('kode', $this->kode_debitur)->first(); @@ -191,9 +204,10 @@ } } - public function countLamaHari(){ - $date = Carbon::create($this->tanggal_hapus_buku); - $now = Carbon::now(); + public function countLamaHari() + { + $date = Carbon::create($this->tanggal_hapus_buku); + $now = Carbon::now(); $this->lama_hari = $date->diffInDays($now); return $this->lama_hari; } @@ -214,14 +228,12 @@ protected function rules() { - if ($this->edit_mode) { $request = new UpdateHapusBukuRequest(); } else { $request = new StoreHapusBukuRequest(); } - return $request->rules(); } } diff --git a/Livewire/HapusBuku/NomorPinjamanModal.php b/Livewire/HapusBuku/NomorPinjamanModal.php index f264a22..eee70fa 100644 --- a/Livewire/HapusBuku/NomorPinjamanModal.php +++ b/Livewire/HapusBuku/NomorPinjamanModal.php @@ -26,11 +26,12 @@ ->whereHas('product', function ($query) { $query->whereBetween('kode', [3000, 3999]); }) - ->get()->first(); + ->get() + ->first(); + if ($rekenings->count() > 0) { - $this->dispatch('show', json_encode($rekenings)); $this->dispatch('success', __('Nomor Pinjaman ditemukan')); - $this->redirect(route('pencatatan.hapus_buku.index', ['rekening' => json_encode($rekenings)])); + $this->redirect(route('pencatatan.hapus_buku.index', ['rekening' => $this->nomor_pinjaman])); } else { $this->addError('nomor_pinjaman', 'Nomor Pinjaman Salah Atau Nomor Pinjaman sudah terdaftar'); diff --git a/Resources/views/livewire/hapus-buku/hapus-buku-modal.blade.php b/Resources/views/livewire/hapus-buku/hapus-buku-modal.blade.php index eb0b884..967acb3 100644 --- a/Resources/views/livewire/hapus-buku/hapus-buku-modal.blade.php +++ b/Resources/views/livewire/hapus-buku/hapus-buku-modal.blade.php @@ -1,399 +1,389 @@ @php use Carbon\Carbon; @endphp -