'update', 'show' => 'show' ]; public function render() { $this->rekening = request()->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") { $this->addError('nomor_pinjaman', 'Debitur Tidak Ditemukan'); } else { $this->validate(); // Validate the form input data DB::transaction(function () { // Prepare the data for creating a new user $data = [ 'nomor_pinjaman' => $this->nomor_pinjaman, 'kode_jenis_pinjaman' => $this->kode_jenis_pinjaman, 'kode_debitur' => $this->kode_debitur, 'nama_debitur' => $this->nama_debitur, 'alamat_debitur' => $this->alamat_debitur, 'npwp_debitur' => $this->npwp_debitur, 'kode_cabang' => $this->kode_cabang, 'kode_mata_uang' => $this->kode_mata_uang, 'tanggal_hapus_buku' => $this->tanggal_hapus_buku, 'nomor_fasilitas' => $this->nomor_fasilitas, 'kode_jenis_fasilitas' => $this->kode_jenis_fasilitas, 'nilai_plafond_awal' => $this->nilai_plafond_awal, 'suku_bunga' => $this->suku_bunga, 'baki_debet' => $this->baki_debet, 'jumlah_bunga' => $this->jumlah_bunga, 'jumlah_kewajiban_lain' => $this->jumlah_kewajiban_lain, 'total_kewajiban' => $this->total_kewajiban, 'total_bunga_extra' => $this->total_bunga_extra, 'bunga_ekstra' => $this->bunga_ekstra, 'bunga_non_ekstra' => $this->bunga_non_ekstra, 'denda' => $this->denda, 'tagihan_lain' => $this->tagihan_lain, 'biaya_lain' => $this->biaya_lain, 'total_all_kewajiban' => $this->total_all_kewajiban, 'memo_persetujuan' => $this->memo_persetujuan, 'lama_hari' => $this->lama_hari, 'proses_hukum' => $this->proses_hukum, 'komitmen_debitur' => $this->komitmen_debitur, 'keterangan' => $this->keterangan, 'status' => $this->status ]; if ($this->edit_mode) { // Emit a success event with a message $hapus_buku = HapusBuku::find($this->id); $data['updated_by'] = auth()->user()->id; $data['updated_at'] = now(); $approval = [ 'method' => 'update', 'menu' => 'Hapus Buku', 'old_request' => json_encode($hapus_buku), 'new_request' => json_encode($data), 'description' => 'Update Hapus Buku', 'status' => '0', 'ref' => $this->nomor_pinjaman ]; $is_approval = Approval::where('menu', 'Hapus Buku') ->where('ref', $this->nomor_pinjaman) ->where('status', '0') ->where('method', 'update') ->get() ->first(); if ($is_approval) { $this->dispatch('error', 'Data Sedang Menunggu Approval'); } else { Approval::create($approval); $this->dispatch('success', 'Data Berhasil Di Update, Menunggu Approval'); } } else { $data['created_by'] = auth()->user()->id; $data['created_at'] = now(); // Emit a success event with a message $approval = [ 'method' => 'create', 'menu' => 'Hapus Buku', 'new_request' => json_encode($data), 'description' => 'Create Hapus Buku', 'status' => '0', 'ref' => $this->nomor_pinjaman ]; $is_approval = Approval::where('menu', 'Hapus Buku') ->where('ref', $this->nomor_pinjaman) ->where('status', '0') ->where('method', 'create') ->get() ->first(); if ($is_approval) { $this->dispatch('error', 'Data Sedang Menunggu Approval'); $this->reset(); } else { Approval::create($approval); $this->dispatch('success', 'Data Berhasil Di Input, Menunggu Approval'); } } }); // Reset the form fields after successful submission //$this->reset(); } } public function update($id) { $this->edit_mode = true; $hapus_buku = HapusBuku::find($id); $this->id = $hapus_buku->id; $this->nomor_pinjaman = $hapus_buku->nomor_pinjaman; $this->kode_jenis_pinjaman = $hapus_buku->kode_jenis_pinjaman; $this->kode_debitur = $hapus_buku->kode_debitur; $this->nama_debitur = $hapus_buku->nama_debitur; $this->alamat_debitur = $hapus_buku->alamat_debitur; $this->npwp_debitur = $hapus_buku->npwp_debitur; $this->kode_cabang = $hapus_buku->kode_cabang; $this->kode_mata_uang = $hapus_buku->kode_mata_uang; $this->tanggal_hapus_buku = $hapus_buku->tanggal_hapus_buku; $this->nomor_fasilitas = $hapus_buku->nomor_fasilitas; $this->kode_jenis_fasilitas = $hapus_buku->kode_jenis_fasilitas; $this->nilai_plafond_awal = $hapus_buku->nilai_plafond_awal; $this->suku_bunga = $hapus_buku->suku_bunga; $this->baki_debet = $hapus_buku->baki_debet; $this->jumlah_bunga = $hapus_buku->jumlah_bunga; $this->jumlah_kewajiban_lain = $hapus_buku->jumlah_kewajiban_lain; $this->total_kewajiban = $hapus_buku->total_kewajiban; $this->total_bunga_extra = $hapus_buku->total_bunga_extra; $this->bunga_ekstra = $hapus_buku->bunga_ekstra; $this->bunga_non_ekstra = $hapus_buku->bunga_non_ekstra; $this->denda = $hapus_buku->denda; $this->tagihan_lain = $hapus_buku->tagihan_lain; $this->biaya_lain = $hapus_buku->biaya_lain; $this->total_all_kewajiban = $hapus_buku->total_all_kewajiban; $this->memo_persetujuan = $hapus_buku->memo_persetujuan; $this->lama_hari = $hapus_buku->lama_hari; $this->proses_hukum = $hapus_buku->proses_hukum; $this->komitmen_debitur = $hapus_buku->komitmen_debitur; $this->keterangan = $hapus_buku->keterangan; $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(); if ($debitur) { $this->nama_debitur = $debitur->name; } else { $this->nama_debitur = ''; $this->addError('nama_debitur', 'Debitur Tidak Ditemukan'); } } public function countLamaHari() { $date = Carbon::create($this->tanggal_hapus_buku); $now = Carbon::now(); $this->lama_hari = $date->diffInDays($now); return $this->lama_hari; } public function hydrate() { $this->resetErrorBag(); $this->resetValidation(); } protected function rules() { if ($this->edit_mode) { $request = new UpdateHapusBukuRequest(); } else { $request = new StoreHapusBukuRequest(); } return $request->rules(); } }