'delete', 'update' => 'update', ]; public function render() { $this->pinjaman = request()->segment(3); $this->nomor_pinjaman = $this->pinjaman; return view('writeoff::livewire.detail-pembayaran.detail-pembayaran-modal'); } public function submit() { $this->validate(); session_start(); // Validate the form input data DB::transaction(function () { // Prepare the data for creating a new user $data = [ 'nomor_pinjaman' => $_SESSION['nomor_pinjaman'], 'kode' => round(microtime(true) * 100), 'tanggal_pembayaran' => $this->tanggal_pembayaran, 'nominal' => $this->nominal, 'keterangan' => $this->keterangan, 'status' => $this->status, ]; if ($this->edit_mode) { // Emit a success event with a message $detail_pembayaran = DetailPembayaran::find($this->id); $data['updated_by'] = auth()->user()->id; $data['updated_at'] = now(); $approval = [ 'method' => 'update', 'menu' => 'Detail Pembayaran', 'old_request' => json_encode($detail_pembayaran), 'new_request' => json_encode($data), 'description' => 'Update Detail Pembayaran', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Detail Pembayaran') ->where('ref', $this->kode) ->where('status', '0') ->get() ->first(); if ($is_approval) { $this->dispatch('error', 'Data Detail Jaminan Sedang Menunggu Approval'); } else { Approval::create($approval); $this->dispatch('success', 'Data Detail Jaminan Berhasil Di Update, Menunggu Approval'); } } else { // Emit a success event with a message $data['created_by'] = auth()->user()->id; $data['created_at'] = now(); $approval = [ 'method' => 'create', 'menu' => 'Detail Pembayaran', 'new_request' => json_encode($data), 'description' => 'Create Detail Pembayaran', 'status' => '0', 'ref' => $this->kode ]; $is_approval = Approval::where('menu', 'Detail Pembayaran') ->where('ref', $this->kode) ->where('status', '0') ->get() ->first(); if ($is_approval) { $this->dispatch('error', 'Data Detail Pembayaran Sedang Menunggu Approval'); $this->reset(); } else { Approval::create($approval); $this->dispatch('success', 'Data Detail Pembayaran Berhasil Di Input, Menunggu Approval'); } } }); // Reset the form fields after successful submission $this->reset(); $this->nomor_pinjaman = request()->segment(3); } public function update($id) { $this->edit_mode = true; $detail_pembayaran = DetailPembayaran::find($id); $this->id = $id; $this->nomor_pinjaman = $detail_pembayaran->nomor_pinjaman; $this->tanggal_pembayaran = $detail_pembayaran->tanggal_pembayaran; $this->nominal = $detail_pembayaran->nominal; $this->keterangan = $detail_pembayaran->keterangan; $this->status = $detail_pembayaran->status; } public function delete($id) { $detailpembayaran = DetailPembayaran::find($id); $detailpembayaran->delete_by = auth()->user()->id; $detailpembayaran->deleted_at = now(); $approval = [ 'method' => 'delete', 'menu' => 'Detail Pembayaran', 'old_request' => json_encode($detailpembayaran), 'description' => 'Delete Detail Pembayaran', 'status' => '0', 'ref' => $detailpembayaran->kode ]; $is_approval = Approval::where('menu', 'Detail Pembayaran') ->where('ref', $detailpembayaran->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() { $request = new StoreDetailPembayaranRequest(); return $request->rules(); } }