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