tipo = TipoDocumento::cases()[0]; } public function render(): View { return view('livewire.cajas.components.documentos-component'); } public function save(): void { $this->validate(); if ($this->currentDocumento) { Documento::where('id', $this->currentDocumento)->update([ 'tipo_documento' => $this->tipo, 'descripcion' => $this->descripcion, 'valor' => $this->valor, ]); } else { $this->turno->documentos()->create([ 'tipo_documento' => $this->tipo, 'descripcion' => $this->descripcion, 'valor' => $this->valor, ]); } if ($this->currentDocumento) { $this->toast()->success('Exito!', 'Documento modificado correctamente')->send(); } else { $this->toast()->success('Exito!', 'Documento guardado correctamente')->send(); } $this->currentDocumento = null; $this->descripcion = null; $this->valor = null; $this->dispatch('updated_totals'); } public function edit($id): void { $this->currentDocumento = $id; $documento = Documento::find($id); $this->tipo = $documento->tipo_documento; $this->descripcion = $documento->descripcion; $this->valor = $documento->valor; } public function confirmDelete($id): void { $this->dialog()->question('¿Esta seguro de eliminar este documento?', 'No podrá recuperarlo') ->confirm('Eliminar Documento', method: 'delete', params: $id) ->cancel() ->send(); } public function delete($id): void { Documento::where('id', $id)->delete(); $this->toast()->success('Documento eliminado correctamente')->send(); $this->dispatch('updated_totals'); } #[Computed] public function headers(): array { return [ ['index' => 'tipo_documento', 'label' => 'Tipo Documento'], ['index' => 'descripcion', 'label' => 'Descripción'], ['index' => 'valor', 'label' => 'Total'], ['index' => 'action', 'label' => 'Acciones'], ]; } #[Computed] public function rows(): Collection { return $this->turno->documentos() ->orderBy('created_at', 'asc') ->get(); } #[Computed] public function tipos(): array { return TipoDocumento::cases(); } #[Computed] public function totalDocumentos(): string { return Number::currency($this->turno->documentos()->sum('valor')); } }