diff --git a/servicios2.html b/servicios2.html
index af878ba..5265377 100644
--- a/servicios2.html
+++ b/servicios2.html
@@ -178,7 +178,15 @@
¿Es de Compañía de Seguros?
-
+
+
+
+
+
+
+
⚠️ Referencia ya existente
@@ -1198,6 +1206,38 @@
} catch(e) {}
}
+ // 🛑 NUEVO: Función para registrar compañías "al vuelo"
+ async function promptNewCompany() {
+ const newName = prompt("Escribe el nombre de la NUEVA COMPAÑÍA a registrar:");
+ if (!newName || newName.trim() === "") return;
+
+ try {
+ const res = await fetch(`${API_URL}/companies`, {
+ method: 'POST',
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
+ body: JSON.stringify({ name: newName.trim().toUpperCase() })
+ });
+
+ if (res.ok) {
+ showToast("✅ Compañía registrada con éxito");
+ await loadCompaniesForManual(); // Recargamos la lista silenciosamente
+
+ // Auto-seleccionamos la nueva compañía en el desplegable
+ const sel = document.getElementById('nCompanySelect');
+ for (let i = 0; i < sel.options.length; i++) {
+ if (sel.options[i].value === newName.trim().toUpperCase()) {
+ sel.selectedIndex = i;
+ break;
+ }
+ }
+ } else {
+ alert("Error al añadir la compañía a la base de datos.");
+ }
+ } catch (e) {
+ alert("Error de conexión al guardar.");
+ }
+ }
+
function toggleCompanyFields(show) {
const fields = document.getElementById('companyFields');
fields.classList.toggle('hidden', !show);