Update ShowPlanes.php
This commit is contained in:
@@ -222,8 +222,9 @@ class ShowPlanes extends Component
|
||||
|
||||
public function calcularFechas()
|
||||
{
|
||||
$this->fecha_final_renovar = Carbon::parse($this->fecha_final_renovar)->addDays(30)->format('Y-m-d');
|
||||
$this->tiempo_usuario = 30;
|
||||
$this->fecha_inicial_renovar = now()->format('Y-m-d');
|
||||
$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([
|
||||
'correo' => $this->usuario_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,
|
||||
]);
|
||||
|
||||
@@ -281,23 +280,6 @@ class ShowPlanes extends Component
|
||||
$id = $this->id_cuentaVer;
|
||||
|
||||
$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);
|
||||
|
||||
@@ -325,38 +307,77 @@ class ShowPlanes extends Component
|
||||
}
|
||||
public function noRenovar()
|
||||
{
|
||||
// Corrección 1: Calcula la diferencia de días directamente
|
||||
$this->tiempo_usuario = $this->fecha_inicial_renovar->diffInDays($this->fecha_inicial_renovar);
|
||||
|
||||
$id = $this->id_cuentaVer;
|
||||
|
||||
Cuentas::where('id', $id)->update([
|
||||
'correo' => $this->usuario_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,
|
||||
]);
|
||||
|
||||
$historial = Historial_cuenta::where('cuenta_id', $id)->first();
|
||||
|
||||
if ($historial) {
|
||||
Historiale::where('id', $historial->historial_id)->update([
|
||||
'fecha_final' => date('Y-m-d', strtotime(strval($this->fecha_final_renovar))),
|
||||
// Corrección 2: Verifica que la cuenta exista antes de intentar actualizarla
|
||||
$cuenta = Cuentas::find($id);
|
||||
if ($cuenta) {
|
||||
$cuenta->update([
|
||||
'correo' => $this->usuario_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,
|
||||
]);
|
||||
|
||||
$id_historiales = Historial_cuenta::where('cuenta_id', $id)->pluck('historial_id')->toArray();
|
||||
|
||||
$historiales = Historiale::whereIn('id', $id_historiales)->get();
|
||||
|
||||
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
|
||||
]);
|
||||
}
|
||||
|
||||
// Corrección 7: Asumiendo que el método alert() y las variables de estado están correctamente implementadas
|
||||
$this->alert('success', 'Cuenta renovada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->renovar = false;
|
||||
$this->ver = false;
|
||||
}
|
||||
|
||||
$cuenta_renovar = Cuentas::find($id);
|
||||
|
||||
Log_historial::create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'detalle' => 'El usuario ha renovado la cuenta ' . $cuenta_renovar->correo
|
||||
]);
|
||||
|
||||
$this->alert('success', 'Cuenta renovada correctamente!', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
|
||||
$this->renovar = false;
|
||||
$this->ver = false;
|
||||
}
|
||||
|
||||
/* ------------- CREAR ------------- */
|
||||
public function createNewCuenta()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user