Update ShowPlanes.php
This commit is contained in:
@@ -222,8 +222,9 @@ class ShowPlanes extends Component
|
|||||||
|
|
||||||
public function calcularFechas()
|
public function calcularFechas()
|
||||||
{
|
{
|
||||||
$this->fecha_final_renovar = Carbon::parse($this->fecha_final_renovar)->addDays(30)->format('Y-m-d');
|
$this->fecha_inicial_renovar = now()->format('Y-m-d');
|
||||||
$this->tiempo_usuario = 30;
|
$this->fecha_final_renovar = now()->addDays(30)->format('Y-m-d');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -256,8 +257,6 @@ class ShowPlanes extends Component
|
|||||||
Cuentas::where('id', $this->id_cuentaVer)->update([
|
Cuentas::where('id', $this->id_cuentaVer)->update([
|
||||||
'correo' => $this->usuario_renovar,
|
'correo' => $this->usuario_renovar,
|
||||||
'password' => $this->password_renovar,
|
'password' => $this->password_renovar,
|
||||||
'inicio' => date('Y-m-d', strtotime(strval($this->fecha_inicial_renovar))),
|
|
||||||
'vencimiento' => date('Y-m-d', strtotime(strval($this->fecha_final_renovar))),
|
|
||||||
'estado' => $this->estado,
|
'estado' => $this->estado,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -281,23 +280,6 @@ class ShowPlanes extends Component
|
|||||||
$id = $this->id_cuentaVer;
|
$id = $this->id_cuentaVer;
|
||||||
|
|
||||||
$historial = Historial_cuenta::where('cuenta_id', $id)->first();
|
$historial = Historial_cuenta::where('cuenta_id', $id)->first();
|
||||||
if ($historial) {
|
|
||||||
$consultaFechaFinal = Historiale::find($historial->historial_id)->fecha_final;
|
|
||||||
|
|
||||||
// Convertir cadena a objeto fecha usando Carbon
|
|
||||||
$consultaFechaFinal = \Carbon\Carbon::parse($consultaFechaFinal);
|
|
||||||
|
|
||||||
// Ahora puedes realizar operaciones con fechas
|
|
||||||
$nuevaFecha = $consultaFechaFinal->addDays($this->tiempo_usuario);
|
|
||||||
} else {
|
|
||||||
$this->alert('warning', 'Error en el proceso de renovación. ', [
|
|
||||||
'position' => 'top'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Historiale::where('id', $historial->historial_id)->update([
|
|
||||||
'fecha_final' => date('Y-m-d', strtotime(strval($nuevaFecha))),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$cuenta_renovar = Cuentas::find($id);
|
$cuenta_renovar = Cuentas::find($id);
|
||||||
|
|
||||||
@@ -325,9 +307,14 @@ class ShowPlanes extends Component
|
|||||||
}
|
}
|
||||||
public function noRenovar()
|
public function noRenovar()
|
||||||
{
|
{
|
||||||
$id = $this->id_cuentaVer;
|
// Corrección 1: Calcula la diferencia de días directamente
|
||||||
|
$this->tiempo_usuario = $this->fecha_inicial_renovar->diffInDays($this->fecha_inicial_renovar);
|
||||||
|
|
||||||
Cuentas::where('id', $id)->update([
|
$id = $this->id_cuentaVer;
|
||||||
|
// Corrección 2: Verifica que la cuenta exista antes de intentar actualizarla
|
||||||
|
$cuenta = Cuentas::find($id);
|
||||||
|
if ($cuenta) {
|
||||||
|
$cuenta->update([
|
||||||
'correo' => $this->usuario_renovar,
|
'correo' => $this->usuario_renovar,
|
||||||
'password' => $this->password_renovar,
|
'password' => $this->password_renovar,
|
||||||
'inicio' => date('Y-m-d', strtotime(strval($this->fecha_inicial_renovar))),
|
'inicio' => date('Y-m-d', strtotime(strval($this->fecha_inicial_renovar))),
|
||||||
@@ -335,21 +322,53 @@ class ShowPlanes extends Component
|
|||||||
'estado' => $this->estado,
|
'estado' => $this->estado,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$historial = Historial_cuenta::where('cuenta_id', $id)->first();
|
$id_historiales = Historial_cuenta::where('cuenta_id', $id)->pluck('historial_id')->toArray();
|
||||||
|
|
||||||
if ($historial) {
|
$historiales = Historiale::whereIn('id', $id_historiales)->get();
|
||||||
Historiale::where('id', $historial->historial_id)->update([
|
|
||||||
'fecha_final' => date('Y-m-d', strtotime(strval($this->fecha_final_renovar))),
|
foreach ($historiales as $historial) {
|
||||||
|
// Corrección 3: Usa la fecha final original del historial para calcular la nueva fecha final
|
||||||
|
$nueva_fecha_final = $historial->fecha_final->addDays($this->tiempo_usuario)->format('Y-m-d');
|
||||||
|
|
||||||
|
$historial_guardar = new Historiale;
|
||||||
|
$historial_guardar->fecha_inicio = $historial->fecha_final;
|
||||||
|
$historial_guardar->fecha_final = $nueva_fecha_final;
|
||||||
|
$historial_guardar->valor = 0;
|
||||||
|
$historial_guardar->tipo_pago = 'manual';
|
||||||
|
$historial_guardar->estado = 'activo';
|
||||||
|
$historial_guardar->vendedor_id = $historial->vendedor_id;
|
||||||
|
$historial_guardar->tarifa_id = $historial->tarifa_id;
|
||||||
|
$historial_guardar->cliente_id = $historial->usuario_id;
|
||||||
|
$historial_guardar->cantidad = 1;
|
||||||
|
$historial_guardar->nombre_cliente = $historial->nombre_cliente;
|
||||||
|
$historial_guardar->utilidad = 0;
|
||||||
|
$historial_guardar->save();
|
||||||
|
|
||||||
|
// Corrección 4: Verifica si el historial se guardó correctamente antes de actualizar Historial_cuenta
|
||||||
|
if ($historial_guardar->id) {
|
||||||
|
Historial_cuenta::where('cuenta_id', $id)->update(['historial_id' => $historial_guardar->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$servicioNombre = $historial_guardar->tarifa->servicio->nombre;
|
||||||
|
|
||||||
|
// Corrección 5: Verifica si el usuario está autenticado antes de acceder a Auth::user()
|
||||||
|
if (Auth::check()) {
|
||||||
|
$logsGeneral = new Log_general();
|
||||||
|
$logsGeneral->user_id = Auth::user()->id;
|
||||||
|
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha renovado el servicio:' . $servicioNombre . ' con cuenta ' . $cuenta->correo . ' para el cliente: ' . $historial->cliente->name;
|
||||||
|
$logsGeneral->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Corrección 6: Verifica si el usuario está autenticado antes de acceder a Auth::user()
|
||||||
|
if (Auth::check()) {
|
||||||
|
Log_historial::create([
|
||||||
|
'user_id' => Auth::user()->id,
|
||||||
|
'detalle' => 'El usuario ha renovado la cuenta ' . $cuenta->correo
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cuenta_renovar = Cuentas::find($id);
|
// Corrección 7: Asumiendo que el método alert() y las variables de estado están correctamente implementadas
|
||||||
|
|
||||||
Log_historial::create([
|
|
||||||
'user_id' => Auth::user()->id,
|
|
||||||
'detalle' => 'El usuario ha renovado la cuenta ' . $cuenta_renovar->correo
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->alert('success', 'Cuenta renovada correctamente!', [
|
$this->alert('success', 'Cuenta renovada correctamente!', [
|
||||||
'position' => 'top'
|
'position' => 'top'
|
||||||
]);
|
]);
|
||||||
@@ -357,6 +376,8 @@ class ShowPlanes extends Component
|
|||||||
$this->renovar = false;
|
$this->renovar = false;
|
||||||
$this->ver = false;
|
$this->ver = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------- CREAR ------------- */
|
/* ------------- CREAR ------------- */
|
||||||
public function createNewCuenta()
|
public function createNewCuenta()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user