Servicios: botones Finalizar/Anular en la ficha sin necesidad de gremio ni operario
- Nuevo panel panelCierreDirecto en el modal de detalle con botones Finalizar servicio y Anular servicio. - cerrarServicioDirecto(): pide confirmación, para la bolsa si estaba buscando operario y pone status_operativo al estado Finalizado/Anulado vía PUT /providers/scraped/:id. - Los botones se ocultan si el servicio ya está cerrado. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WWFY395YKdGaAzwkwy3St4
This commit is contained in:
@@ -376,6 +376,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ✅ NUEVO: Cierre directo del servicio, sin tener que asignar gremio ni operario -->
|
||||
<div id="panelCierreDirecto" class="flex gap-2 shrink-0">
|
||||
<button type="button" onclick="cerrarServicioDirecto('finalizar')" class="flex-1 flex items-center justify-center gap-1.5 bg-emerald-600 hover:bg-emerald-700 text-white text-[11px] font-black uppercase tracking-wider py-2.5 rounded-xl shadow-sm transition"><i data-lucide="check-circle-2" class="w-4 h-4"></i> Finalizar servicio</button>
|
||||
<button type="button" onclick="cerrarServicioDirecto('anular')" class="flex-1 flex items-center justify-center gap-1.5 bg-slate-200 hover:bg-red-600 hover:text-white text-slate-700 text-[11px] font-black uppercase tracking-wider py-2.5 rounded-xl shadow-sm transition"><i data-lucide="x-circle" class="w-4 h-4"></i> Anular servicio</button>
|
||||
</div>
|
||||
|
||||
<div id="panelAsignado" class="bg-blue-50/40 p-4 rounded-[1rem] border border-blue-100 flex flex-col shadow-sm shrink-0 hidden">
|
||||
<div class="grid grid-cols-2 gap-4 items-center">
|
||||
<div>
|
||||
@@ -1077,6 +1083,9 @@ const grid = document.getElementById('servicesGrid');
|
||||
const dbStat = raw.status_operativo;
|
||||
const statusObj = systemStatuses.find(st => String(st.id) === String(dbStat)) || systemStatuses[0];
|
||||
const stName = (statusObj?.name || "").toLowerCase();
|
||||
// ✅ NUEVO: los botones de cierre directo solo tienen sentido si el servicio sigue abierto
|
||||
const cierreBar = document.getElementById('panelCierreDirecto');
|
||||
if (cierreBar) cierreBar.classList.toggle('hidden', !!(statusObj && statusObj.is_final) || s.status === 'archived');
|
||||
|
||||
if (s.automation_status === 'in_progress') {
|
||||
document.getElementById('panelEnBolsa').classList.remove('hidden');
|
||||
@@ -1347,6 +1356,41 @@ const grid = document.getElementById('servicesGrid');
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ NUEVO: Finalizar / Anular directamente desde la ficha, sin asignar gremio ni operario
|
||||
async function cerrarServicioDirecto(tipo) {
|
||||
const id = document.getElementById('detId').value;
|
||||
if (!id) return;
|
||||
const clave = tipo === 'finalizar' ? 'finalizado' : 'anulado';
|
||||
const st = systemStatuses.find(x => (x.name || '').toLowerCase().includes(clave));
|
||||
if (!st) return alert('No encuentro el estado "' + clave + '" en la configuración de estados.');
|
||||
const s = localData.find(x => String(x.id) === String(id));
|
||||
const accion = tipo === 'finalizar' ? 'FINALIZAR' : 'ANULAR';
|
||||
if (!confirm('¿Seguro que quieres ' + accion + ' este servicio? No hace falta gremio ni operario.')) return;
|
||||
|
||||
const headers = { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` };
|
||||
try {
|
||||
// Si estaba en la bolsa buscando operario, la paramos para que no siga ofreciéndolo
|
||||
if (s && (s.automation_status === 'in_progress' || s.automation_status === 'failed')) {
|
||||
await fetch(`${API_URL}/providers/scraped/${id}`, { method: 'PUT', headers, body: JSON.stringify({ automation_status: 'completed' }) });
|
||||
}
|
||||
const res = await fetch(`${API_URL}/providers/scraped/${id}`, {
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: JSON.stringify({ status_operativo: String(st.id) })
|
||||
});
|
||||
if (res.ok) {
|
||||
closeDetailModal();
|
||||
showToast(tipo === 'finalizar' ? 'Servicio finalizado' : 'Servicio anulado');
|
||||
refreshData();
|
||||
} else {
|
||||
alert("Error en el servidor al guardar.");
|
||||
}
|
||||
} catch (e) {
|
||||
alert("Error al cerrar el servicio: " + e.message);
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function sendToAutomate() {
|
||||
const id = document.getElementById('detId').value;
|
||||
const guild_id = document.getElementById('reGremio').value;
|
||||
|
||||
Reference in New Issue
Block a user