'delete', 'update' => 'update', ]; public function render() { return view('writeoff::livewire.currency.currency-modal'); } public function submit() { $this->validate(); // Validate the form input data DB::transaction(function () { // Prepare the data for creating a new user $data = [ 'kode' => $this->kode, 'name' => $this->name ]; if ($this->edit_mode) { // Emit a success event with a message $currency = Currency::find($this->id); $approval = [ 'method' => 'update', 'menu' => 'Parameter Mata Uang', 'old_request' => json_encode($currency), 'new_request' => json_encode($data), 'description' => 'Update Parameter Mata Uang', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Parameter Mata Uang') ->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 { // Emit a success event with a message $approval = [ 'method' => 'create', 'menu' => 'Parameter Mata Uang', 'new_request' => json_encode($data), 'description' => 'Create Parameter Mata Uang', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Parameter Mata Uang') ->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; $currency = Currency::find($id); $this->id = $currency->id; $this->kode = $currency->kode; $this->name = $currency->name; } public function delete($id) { $curency = Currency::find($id); $curency->delete_by = auth()->user()->id; $curency->deleted_at = now(); $approval = [ 'method' => 'delete', 'menu' => 'Parameter Mata uang', 'old_request' => json_encode($curency), 'description' => 'Delete Parameter Mata uang', 'status' => '0', 'ref' => $curency->kode ]; $is_approval = Approval::where('menu', 'Parameter Mata uang') ->where('ref', $curency->kode) ->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 UpdateCurrencyRequest(); } else { $request = new StoreCurrencyRequest(); } return $request->rules(); } }