'delete', 'update' => 'update', 'reload' => 'reload', ]; public function render() { $cabang = Branch::all(); $debitur = Debitur::all(); $loan_type = LoanType::all(); $currency = Currency::all(); return view('writeoff::livewire.rekening.rekening-modal', compact([ 'cabang', 'debitur', 'loan_type', '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, 'loan_type_id' => $this->loan_type_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); $data['updated_by'] = auth()->user()->id; $data['updated_at'] = now(); $approval = [ 'method' => 'update', 'menu' => 'Parameter Rekening', 'old_request' => json_encode($rekening), 'new_request' => json_encode($data), 'description' => 'Update Parameter Rekening', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Parameter Rekening') ->where('ref', $this->kode) ->where('status', '0') ->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' => 'Parameter Rekening', 'new_request' => json_encode($data), 'description' => 'Create Parameter Rekening', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Parameter Rekening') ->where('ref', $this->kode) ->where('status', '0') ->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; $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->loan_type_id = $rekening->loan_type_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) { $old = Rekening::find($id); unset($old->deleted_at); unset($old->delete_by); $rekening = Rekening::find($id); $rekening->delete_by = auth()->user()->id; $rekening->deleted_at = now(); $approval = [ 'method' => 'delete', 'menu' => 'Parameter Rekening', 'old_request' => json_encode($old), 'new_request' => json_encode($rekening), 'description' => 'Delete Parameter Rekening', 'status' => '0', 'ref' => $rekening->nomor_rekening ]; $is_approval = Approval::where('menu', 'Parameter Rekening') ->where('ref', $rekening->nomor_rekening) ->where('status', '0') ->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 reload() { $this->edit_mode = false; $this->reset(); } public function hydrate() { $this->resetErrorBag(); $this->resetValidation(); } protected function rules() { if ($this->edit_mode) { $request = new UpdateRekeningRequest(); } else { $request = new StoreRekeningRequest(); } return $request->rules(); } }