modal = true; $this->fecha = now()->format('Y-m-d'); $this->caja = 1; if (Turno::where('fecha', $this->fecha)->exists()) { $this->turno = Turno::where('fecha', $this->fecha)->max('numero_turno') + 1; } else { $this->turno = 1; } } public function storeTurno(): void { $this->validate([ 'fecha' => 'required|date', 'caja' => 'required|gte:1|lte:10', 'turno' => 'required|gte:1|lte:10', ]); $exists = Turno::where('fecha', $this->fecha) ->where('numero_caja', $this->caja) ->where('numero_turno', $this->turno) ->exists(); if ($exists) { throw ValidationException::withMessages(['fecha' => 'Ya hay un registro para esta fecha, caja y turno']); } $turno = Turno::create([ 'fecha' => $this->fecha, 'numero_caja' => $this->caja, 'numero_turno' => $this->turno, ]); $turno->efectivo()->create([ 'veinte_mil' => 0, 'diez_mil' => 0, 'cinco_mil' => 0, 'dos_mil' => 0, 'mil' => 0, 'quinientos' => 0, 'cien' => 0, 'cincuenta' => 0, 'diez' => 0, ]); Session::flash('toast', ['type' => 'success', 'message' => 'Caja registrada correctamente']); $this->redirectRoute('cajas.edit', $turno); } public function closeTurnoModal(): void { $this->modal = false; $this->fecha = null; $this->caja = null; $this->turno = null; $this->clearValidation(); } public function confirmDelete($id): void { $this->dialog()->question('¿Esta seguro de eliminar este turno?', 'Se eliminara este junto a los ingresos y egresos registrados') ->confirm('Eliminar Turno', method: 'doDelete', params: $id) ->cancel() ->send(); } public function doDelete($id): void { Turno::find($id)->delete(); $this->toast()->success('Turno eliminado correctamente')->send(); } #[Computed] public function headers(): array { return [ ['index' => 'fecha', 'label' => 'Fecha'], ['index' => 'numero_caja', 'label' => 'Caja'], ['index' => 'numero_turno', 'label' => 'Turno'], ['index' => 'ingresos', 'label' => 'Ingresos'], ['index' => 'egresos', 'label' => 'Egresos'], ['index' => 'arqueo', 'label' => 'Arqueo'], ['index' => 'action', 'label' => 'Acciones'], ]; } #[Computed] public function rows(): LengthAwarePaginator { return Turno::orderBy('fecha', 'desc') ->orderBy('numero_caja', 'asc') ->orderBy('numero_turno', 'asc') ->when($this->searchFecha, function ($query) { if (!$this->searchFecha) { return; } try { $fecha = Carbon::parse($this->searchFecha); $query->whereDate('fecha', $fecha); } catch (Exception $exception) { // Pass nada que hacer } }) ->paginate(); } }