Actualizar servicios.html
This commit is contained in:
@@ -1137,20 +1137,20 @@
|
|||||||
const id = document.getElementById('detId').value;
|
const id = document.getElementById('detId').value;
|
||||||
const date = document.getElementById('dateInput').value;
|
const date = document.getElementById('dateInput').value;
|
||||||
const time = document.getElementById('timeInput').value;
|
const time = document.getElementById('timeInput').value;
|
||||||
let statusMap = document.getElementById('detStatusMap').value; // 👈 CAMBIADO A LET
|
let statusMap = document.getElementById('detStatusMap').value;
|
||||||
|
|
||||||
// 🛑 EL FIX MÁGICO: Si pones fecha pero el desplegable se quedó en "Asignado", lo pasamos a "Citado" automáticamente.
|
// Auto-Citado Mágico
|
||||||
const currentSt = systemStatuses.find(st => String(st.id) === String(statusMap));
|
const currentSt = systemStatuses.find(st => String(st.id) === String(statusMap));
|
||||||
if (date && currentSt && currentSt.name.toLowerCase() === 'asignado') {
|
if (date && currentSt && currentSt.name.toLowerCase().includes('asignado')) {
|
||||||
const citadoSt = systemStatuses.find(st => st.name.toLowerCase().includes('citado'));
|
const citadoSt = systemStatuses.find(st => st.name.toLowerCase().includes('citado'));
|
||||||
if (citadoSt) {
|
if (citadoSt) statusMap = String(citadoSt.id);
|
||||||
statusMap = String(citadoSt.id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedSt = systemStatuses.find(st => String(st.id) === String(statusMap));
|
const selectedSt = systemStatuses.find(st => String(st.id) === String(statusMap));
|
||||||
if (selectedSt && !selectedSt.is_final && !date && !selectedSt.name.toLowerCase().includes('pausa') && !selectedSt.name.toLowerCase().includes('asignar')) {
|
|
||||||
if(!confirm("No has asignado Fecha para este estado. ¿Deseas continuar?")) return;
|
// 🛑 SOLO avisamos si intenta poner "Citado" sin fecha
|
||||||
|
if (selectedSt && selectedSt.name.toLowerCase().includes('citado') && !date) {
|
||||||
|
if(!confirm("⚠️ Estás marcando el servicio como CITADO pero no has puesto la fecha. ¿Deseas continuar?")) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const btn = document.getElementById('btnSaveAppt');
|
const btn = document.getElementById('btnSaveAppt');
|
||||||
@@ -1159,17 +1159,28 @@
|
|||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetch(`${API_URL}/services/set-appointment/${id}`, {
|
const res = await fetch(`${API_URL}/services/set-appointment/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
|
||||||
body: JSON.stringify({ date, time, status_operativo: statusMap })
|
body: JSON.stringify({ date, time, status_operativo: statusMap })
|
||||||
});
|
});
|
||||||
closeDetailModal(); showToast("Estado actualizado"); refreshData();
|
|
||||||
} catch (e) {
|
if (res.ok) {
|
||||||
alert("🔍 ERROR DETECTADO:\n" + e.message);
|
closeDetailModal();
|
||||||
console.error("Traza completa del error:", e);
|
showToast("Estado actualizado");
|
||||||
|
refreshData();
|
||||||
|
} else {
|
||||||
|
alert("Error en el servidor al guardar.");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
alert("🔍 ERROR JAVASCRIPT: " + e.message);
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
btn.innerHTML = originalContent;
|
||||||
|
btn.disabled = false;
|
||||||
|
lucide.createIcons();
|
||||||
}
|
}
|
||||||
finally { btn.innerHTML = originalContent; btn.disabled = false; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendToAutomate() {
|
async function sendToAutomate() {
|
||||||
|
|||||||
Reference in New Issue
Block a user