diff --git a/servicios.html b/servicios.html index ee81af2..0853175 100644 --- a/servicios.html +++ b/servicios.html @@ -129,120 +129,101 @@
-
- -
- -
-

- Datos del Cliente -

- -
-
- - - - - - -
-
- - -
-
-
- - -
-
- -
-

- Detalles de la Avería -

- - -
- +
+ +
+
+

+ Datos del Cliente +

+
+
+ +
- -
- -
-

- Asignación -

- -
- -
- - -
-
- -
-
- -
- - -
-
-
- -
- - -
-
-
-
- -
- - -
- - Opciones Automáticas -
- - -
- +
+ +
- +
+ + + +
+ +
+ + + +
+
+ +
+ + +
+
+ +
+
+

+ Gestión +

+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+ +
+ + +
+
+
+
@@ -915,8 +896,54 @@ async function searchClientByPhone(phone) { } function closeDetailModal() { document.getElementById('detailModal').classList.add('hidden'); } - function openCreateModal() { document.getElementById('createModal').classList.remove('hidden'); } - function closeCreateModal() { document.getElementById('createModal').classList.add('hidden'); } +// Al abrir el modal, cargamos las compañías configuradas +async function openCreateModal() { + document.getElementById('createModal').classList.remove('hidden'); + // Limpiamos campos + document.getElementById('isCompanyCheck').checked = false; + toggleCompanyFields(false); + + // Cargar compañías desde tu ruta de configuración + try { + const res = await fetch(`${API_URL}/companies`, { + headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } + }); + const data = await res.json(); + const sel = document.getElementById('nCompanySelect'); + sel.innerHTML = ''; + data.companies.forEach(c => { + sel.innerHTML += ``; + }); + } catch(e) {} + lucide.createIcons(); +} + +function toggleCompanyFields(show) { + const fields = document.getElementById('companyFields'); + fields.classList.toggle('hidden', !show); + if(!show) { + document.getElementById('nExpRef').value = ""; + document.getElementById('refAlert').classList.add('hidden'); + } +} + +async function checkDuplicateRef(ref) { + if(!ref) return; + const res = await fetch(`${API_URL}/services/check-ref?ref=${ref}`, { + headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } + }); + const data = await res.json(); + const alertEl = document.getElementById('refAlert'); + const inputEl = document.getElementById('nExpRef'); + + if(data.exists) { + alertEl.classList.remove('hidden'); + inputEl.classList.add('border-red-500', 'bg-red-50'); + } else { + alertEl.classList.add('hidden'); + inputEl.classList.remove('border-red-500', 'bg-red-50'); + } +} function closeCreateModal() { document.getElementById('createModal').classList.add('hidden'); } async function loadGuilds() { const res = await fetch(`${API_URL}/guilds`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });