'delete', 'update' => 'update', ]; public function render() { return view('writeoff::livewire.subrogasi-jamkrindo.subrogasi-jamkrindo-modal'); } public function submit() { $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_debitur' => $this->kode_debitur, 'nama_debitur' => $this->nama_debitur, 'kode_cabang' => $this->kode_cabang, 'nama_cabang' => $this->nama_cabang, 'nomor_rekening' => $this->nomor_rekening, 'nama_rekening' => $this->nama_rekening, 'plafond' => $this->plafond, 'tenor' => $this->tenor, 'tanggal_pengajuan_klaim' => $this->tanggal_pengajuan_klaim, 'piutang_subrogasi' => $this->piutang_subrogasi, 'total_bayar_subrogasi' => $this->total_bayar_subrogasi, 'sisa_piutang_subrogasi' => $this->sisa_piutang_subrogasi, 'is_lunas_subrogasi' => $this->is_lunas_subrogasi, 'keterangan' => $this->keterangan, 'status' => $this->status ]; if ($this->edit_mode) { // Emit a success event with a message $subrogasi_jamkrindo = SubrogasiJamkrindo::find($this->id); $subrogasi_jamkrindo->update($data); $this->dispatch('success', __('Subrogasi Jamkrindo updated')); } else { // Emit a success event with a message SubrogasiJamkrindo::create($data); $this->dispatch('success', __('New Subrogasi Jamkrindo created')); } if ($this->edit_mode) { // Emit a success event with a message $subrogasi_jamkrindo = SubrogasiJamkrindo::find($this->id); $data['updated_by'] = auth()->user()->id; $data['updated_at'] = now(); $approval = [ 'method' => 'update', 'menu' => 'Subrogasi Jamkrindo', 'old_request' => json_encode($subrogasi_jamkrindo), 'new_request' => json_encode($data), 'description' => 'Update Subrogasi Jamkrindo', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Subrogasi Jamkrindo') ->where('ref', $this->kode) ->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' => 'Subrogasi Jamkrindo', 'new_request' => json_encode($data), 'description' => 'Create Subrogasi Jamkrindo', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Subrogasi Jamkrindo') ->where('ref', $this->kode) ->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; $subrogasi_jamkrindo = SubrogasiJamkrindo::find($id); $this->id = $subrogasi_jamkrindo->id; $this->nomor_pinjaman = $subrogasi_jamkrindo->nomor_pinjaman; $this->kode_debitur = $subrogasi_jamkrindo->kode_debitur; $this->nama_debitur = $subrogasi_jamkrindo->nama_debitur; $this->kode_cabang = $subrogasi_jamkrindo->kode_cabang; $this->nama_cabang = $subrogasi_jamkrindo->nama_cabang; $this->nomor_rekening = $subrogasi_jamkrindo->nomor_rekening; $this->nama_rekening = $subrogasi_jamkrindo->nama_rekening; $this->plafond = $subrogasi_jamkrindo->plafond; $this->tenor = $subrogasi_jamkrindo->tenor; $this->tanggal_pengajuan_klaim = $subrogasi_jamkrindo->tanggal_pengajuan_klaim; $this->piutang_subrogasi = $subrogasi_jamkrindo->piutang_subrogasi; $this->total_bayar_subrogasi = $subrogasi_jamkrindo->total_bayar_subrogasi; $this->sisa_piutang_subrogasi = $subrogasi_jamkrindo->sisa_piutang_subrogasi; $this->is_lunas_subrogasi = $subrogasi_jamkrindo->is_lunas_subrogasi == 1; $this->keterangan = $subrogasi_jamkrindo->keterangan; $this->status = $subrogasi_jamkrindo->status == 1; } 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 getBranch() { $branch = Branch::where('kode', $this->kode_cabang)->first(); if ($branch) { $this->nama_cabang = $branch->name; } else { $this->nama_cabang = ''; $this->addError('nama_cabang', 'Cabang Tidak Ditemukan'); } } public function getRekening() { $rekening = Rekening::where('nomor_rekening', $this->nomor_rekening)->first(); if ($rekening) { $debitur = Debitur::where('id', $rekening->debitur_id)->first(); if ($debitur) { $this->nama_rekening = $debitur->name; } else { $this->nama_rekening = ''; $this->addError('nama_rekening', 'Nomor Rekening Tidak Ditemukan'); } } else { $this->nama_rekening = ''; $this->addError('nama_rekening', 'Nomor Rekening Tidak Ditemukan'); } } public function delete($id) { $old = SubrogasiJamkrindo::find($id); unset($old->deleted_at); unset($old->deleted_by); $subrogasi = SubrogasiJamkrindo::find($id); $subrogasi->delete_by = auth()->user()->id; $subrogasi->deleted_at = now(); $approval = [ 'method' => 'delete', 'menu' => 'Subrogasi Jamkrindo', 'old_request' => json_encode($subrogasi), 'description' => 'Delete Data Subrogasi Jamkrindo', 'status' => '0', 'ref' => $subrogasi->nomor_pinjaman ]; $is_approval = Approval::where('menu', 'Subrogasi Jamkrindo') ->where('ref', $subrogasi->nomor_pinjaman) ->where('status', '0') ->where('method', 'delete') ->get() ->first(); if ($is_approval) { $this->dispatch('error', 'Data Sedang Menunggu Approval'); } else { Approval::create($approval); $this->dispatch('success', 'Data Berhasil Di Hapus, Menunggu Approval'); } } public function hydrate() { $this->resetErrorBag(); $this->resetValidation(); } protected function rules() { if ($this->edit_mode) { $request = new UpdateHapusBukuRequest(); } else { $request = new StoreHapusBukuRequest(); } return $request->rules(); } }