diff --git a/servicios.html b/servicios.html index 422c48b..749a581 100644 --- a/servicios.html +++ b/servicios.html @@ -130,12 +130,9 @@
-
-

- Datos del Cliente -

+

Datos del Cliente

@@ -147,83 +144,42 @@
- - - + + +
- -
-
-
-

- Gestión y Tiempo -

- +

Asignación y Tiempo

+ +
- - -
- -
- - -
- -
- - + +
- -
- - -
+ +
@@ -881,25 +837,40 @@ async function searchClientByPhone(phone) { } async function saveNewService(e) { - e.preventDefault(); - const action = e.submitter.value; - const data = { - phone: document.getElementById('nPhone').value, - name: document.getElementById('nName').value, - address: document.getElementById('nAddr').value, - description: document.getElementById('nDesc').value, - guild_id: document.getElementById('nGuild').value, - assigned_to: document.getElementById('nWorker').value || null, - duration_minutes: document.getElementById('nDuration').value // <--- CAPTURA DE DURACIÓN - }; - try { - const res = await fetch(`${API_URL}/services/manual-high`, { - method: 'POST', headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, - body: JSON.stringify({ ...data, mode: action }) - }); - if (res.ok) { closeCreateModal(); refreshPanel(); } - } catch(e) { alert("Error al guardar"); } + e.preventDefault(); + const action = e.submitter.value; + const is_company = document.getElementById('isCompanyCheck').checked; + + const data = { + phone: document.getElementById('nPhone').value, + name: document.getElementById('nName').value, + address: document.getElementById('nAddr').value, + description: document.getElementById('nDesc').value, + guild_id: document.getElementById('nGuild').value, + assigned_to: document.getElementById('nWorker').value || null, + duration_minutes: document.getElementById('nDuration').value, + is_company: is_company, + company_name: is_company ? document.getElementById('nCompanySelect').value : 'Particular', + company_ref: is_company ? document.getElementById('nExpRef').value : null, + mode: action + }; + + try { + const res = await fetch(`${API_URL}/services/manual-high`, { + method: 'POST', + headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, + body: JSON.stringify(data) + }); + if (res.ok) { + showToast("✅ Expediente creado con éxito"); + closeCreateModal(); + refreshPanel(); + } else { + const err = await res.json(); + alert("Error: " + (err.error || "No se pudo guardar")); } + } catch(e) { alert("Error de conexión"); } +} function closeDetailModal() { document.getElementById('detailModal').classList.add('hidden'); } // Al abrir el modal, cargamos las compañías configuradas