tipo = TipoIngreso::cases()[0]; } public function render(): View { return view('livewire.cajas.components.ingresos-component'); } public function save(): void { $this->validate(); if ($this->currentIngreso) { Ingreso::where('id', $this->currentIngreso)->update([ 'tipo_ingreso' => $this->tipo, 'numero' => 0, 'numero_z' => 0, 'ingreso_inicial' => $this->ingreso_inicial, 'ingreso_final' => $this->ingreso_final, 'total' => $this->total, ]); } else { $this->turno->ingresos()->create([ 'tipo_ingreso' => $this->tipo, 'numero' => 0, 'numero_z' => 0, 'ingreso_inicial' => $this->ingreso_inicial, 'ingreso_final' => $this->ingreso_final, 'total' => $this->total, ]); } if ($this->currentIngreso) { $this->toast()->success('Exito!', 'Ingreso modificado correctamente')->send(); } else { $this->toast()->success('Exito!', 'Ingreso guardado correctamente')->send(); } $this->currentIngreso = null; $this->ingreso_inicial = null; $this->ingreso_final = null; $this->total = null; } public function edit($id): void { $this->currentIngreso = $id; $ingreso = Ingreso::find($id); $this->tipo = $ingreso->tipo_ingreso; $this->ingreso_inicial = $ingreso->ingreso_inicial; $this->ingreso_final = $ingreso->ingreso_final; $this->total = $ingreso->total; } public function confirmDelete($id): void { $this->dialog()->question('¿Esta seguro de eliminar este ingreso?', 'No podrá recuperarlo') ->confirm('Eliminar Ingreso', method: 'delete', params: $id) ->cancel() ->send(); } public function delete($id): void { Ingreso::where('id', $id)->delete(); $this->toast()->success('Ingreso eliminado correctamente')->send(); } #[Computed] public function headers(): array { return [ ['index' => 'tipo_ingreso', 'label' => 'Tipo Documento'], ['index' => 'ingreso_inicial', 'label' => 'Documento Inicial'], ['index' => 'ingreso_final', 'label' => 'Documento Final'], ['index' => 'total', 'label' => 'Total'], ['index' => 'action', 'label' => 'Acciones'], ]; } #[Computed] public function rows(): Collection { return $this->turno->ingresos() ->orderBy('created_at', 'desc') ->get(); } #[Computed] public function tipos(): array { return TipoIngreso::cases(); } #[Computed] public function totalIngresos(): string { return Number::currency($this->turno->ingresos()->sum('total')); } }