From c35847f86c99c01b5e5d6b28e2ca232669ca45c1 Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 27 Jul 2023 11:35:46 -0500 Subject: [PATCH] suma os dias a la cuenta --- app/Http/Livewire/ShowClientes.php | 27 +++++++++++++------ .../views/livewire/show-clientes.blade.php | 2 -- .../views/livewire/show-planes.blade.php | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Http/Livewire/ShowClientes.php b/app/Http/Livewire/ShowClientes.php index 1b39ce9..a83c803 100644 --- a/app/Http/Livewire/ShowClientes.php +++ b/app/Http/Livewire/ShowClientes.php @@ -265,22 +265,33 @@ class ShowClientes extends Component public function renovar($id) { - $historiale = Historiale::with('tarifa')->find($id); - + $historiale = Historiale::with('tarifa','cuentas')->find($id); if (!$historiale) { return; } - $newFechaInicio = Carbon::parse($historiale->fecha_inicio)->addDays($historiale->tarifa->dias); - $newFechaFinal = Carbon::parse($historiale->fecha_final)->addDays($historiale->tarifa->dias); + $tarifa = $historiale->tarifa; + $diasTarifa = $tarifa->dias; + $valorTarifa = $tarifa->valor; + + $cuenta = $historiale->cuentas->first(); + $vencimientoCuenta = Carbon::parse($cuenta->vencimiento); + $nuevaFechaVencimiento = $vencimientoCuenta->addDays($diasTarifa); + + $newFechaInicio = Carbon::parse($historiale->fecha_inicio)->addDays($diasTarifa); + $newFechaFinal = Carbon::parse($historiale->fecha_final)->addDays($diasTarifa); - $historiale->fecha_inicio = $newFechaInicio; - $historiale->fecha_final = $newFechaFinal; - $historiale->save(); + $nuevoHistorial = $historiale->replicate(); + $nuevoHistorial->fecha_inicio = $newFechaInicio; + $nuevoHistorial->fecha_final = $newFechaFinal; + $nuevoHistorial->save(); + + $cuenta->vencimiento = $nuevaFechaVencimiento; + $cuenta->save(); $user = Auth::user(); - $user->saldo->valor -= $historiale->tarifa->valor; + $user->saldo->valor -= $valorTarifa; $user->saldo->save(); $this->alert('success', 'Registro renovado con éxito. Nuevas fechas aplicadas.', [ diff --git a/resources/views/livewire/show-clientes.blade.php b/resources/views/livewire/show-clientes.blade.php index bfeb8da..01f7866 100644 --- a/resources/views/livewire/show-clientes.blade.php +++ b/resources/views/livewire/show-clientes.blade.php @@ -126,8 +126,6 @@ @endif - {{$cliente->tarifa->valor}} - @if (!empty($cliente->tarifa_id))