Update ShowServicios.php

This commit is contained in:
lizandrogd
2025-07-07 17:36:45 -05:00
parent a2239647ce
commit 3e7f9542c7
+40 -9
View File
@@ -174,7 +174,6 @@ class ShowServicios extends Component
});
})
->count();
} else {
$cantidad_solicitada = (int) $this->cantidad_tarjetaPlan * (int) $this->pantallas_tarjetaPlan;
$cantidad_restante = $servicio_tarifa->pantallas - $cantidad_solicitada;
@@ -210,7 +209,6 @@ class ShowServicios extends Component
} else {
$this->disponibles = $cuentas_pantallas;
}
}
//dd($this->tarjetaPlan);
@@ -222,7 +220,6 @@ class ShowServicios extends Component
$this->cantidad_tarjetaPlan = 1;
$this->tarjetaPlan = false;
$this->tarifa_id = '';
}
public function notificacionPocas($servicio, $restantes)
@@ -344,7 +341,6 @@ class ShowServicios extends Component
->orderBy('inicio', 'ASC')
->get();
}
} elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) {
//Cuentas completas
@@ -357,8 +353,6 @@ class ShowServicios extends Component
->where('estado', 'pendiente')
->doesntHave('perfil')
->get();
} elseif ((int) $pantalla_servicio < (int) $cantidad_solicitada) {
$suma2 = $pantalla_servicio - $pantallas;
@@ -375,8 +369,6 @@ class ShowServicios extends Component
->where('historiales_count', '<=', $suma2)
->orderBy('inicio', 'ASC')
->get();
} else {
$cuenta = null;
$cantidad_necesaria = null;
@@ -453,7 +445,6 @@ class ShowServicios extends Component
'position' => 'top'
]);
}
} else {
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
@@ -468,6 +459,46 @@ class ShowServicios extends Component
]);
}
// Verificar si hay perfiles duplicados en historial_cuenta recién creados
$perfilesDuplicados = Historial_cuenta::select('cuenta_id', 'perfil')
->where('historial_id', $historial->id)
->groupBy('cuenta_id', 'perfil')
->havingRaw('COUNT(*) > 1')
->get();
if ($perfilesDuplicados->isNotEmpty()) {
// Eliminar historial_cuenta
Historial_cuenta::where('historial_id', $historial->id)->delete();
// Cancelar historial
$historial->update(['estado' => 'cancelado']);
// Registrar en log_general
$detalleError = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email
. ' tuvo un error por perfiles duplicados en la compra del servicio '
. $servicioNombre . ' - ' . $cuentasMostar
. ', cantidad de ' . $this->cantidad_tarjetaPlan
. ', valor: $' . $total_valor
. '. Se canceló la operación y se eliminaron los perfiles duplicados.';
$logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = $detalleError;
$logsGeneral->tipo = 'compra_error';
$logsGeneral->historial_id = $historial->id;
$logsGeneral->save();
$this->alert('warning', 'Error: Se detectaron perfiles duplicados. Se canceló la compra.', [
'position' => 'top'
]);
// Salir antes de confirmar la transacción
DB::rollBack();
return;
}
DB::commit();
$this->tarjetaPlan = false;