+
+
+
+
Elige fecha o busca algo
+
Este buscador cubre TODO el histórico de la empresa. Pon un rango de fechas arriba, o escribe un nombre/teléfono/referencia, y pulsa "Buscar".
+
`;
+ lucide.createIcons();
+ return;
+ }
+
const filteredData = allServices.filter(s => {
if (s._scope !== currentTab) return false;
+ // 🆕 Chip de estado (solo aplica en la pestaña "Buscar")
+ if (currentTab === 'mine' && statusChipSelected !== 'all') {
+ const info = getServiceStateInfo(s);
+ if (String(info.id) !== String(statusChipSelected)) return false;
+ }
+
const raw = s.raw_data || {};
const name = (raw["Nombre Cliente"] || raw["CLIENTE"] || "").toLowerCase();
const addr = (raw["Dirección"] || raw["DOMICILIO"] || "").toLowerCase();
@@ -404,6 +584,10 @@
return name.includes(term) || ref.includes(term) || addr.includes(term) || pop.includes(term) || phone.includes(term) || comp.includes(term);
});
+ // 🆕 "Cargar Más" depende de si el servidor aún tiene más páginas, no de si el filtro
+ // actual (chip/texto) tiene resultados: puede que haya más coincidencias en la página siguiente.
+ document.getElementById('btnLoadMore').classList.toggle('hidden', !(currentTab === 'mine' && hasSearchedOnce && searchHasMore));
+
if (filteredData.length === 0) {
container.innerHTML = `
@@ -424,7 +608,7 @@
const pop = raw["Población"] || "";
const isUrgent = s.is_urgent;
const company = raw["Compañía"] || raw["Procedencia"] || "Particular";
-
+
const rawPhone = raw["Teléfono"] || raw["TELEFONOS"] || raw["TELEFONO"] || "";
const matchPhone = String(rawPhone).match(/[6789]\d{8}/);
const safePhone = matchPhone ? matchPhone[0] : "";
@@ -433,6 +617,7 @@
const colorData = colorDict[stateInfo.color] || colorDict['gray'];
const isScheduled = !!raw.scheduled_date;
const citaText = isScheduled ? `${raw.scheduled_date} | ${raw.scheduled_time}` : 'Sin Cita';
+ const expedienteDate = s.created_at ? new Date(s.created_at).toLocaleDateString('es-ES') : '';
// Generación Dinámica de Botones según el Estado
let actionButtons = `
@@ -452,22 +637,38 @@
`;
+ // 🆕 En "Buscar" (histórico de toda la empresa) el servicio puede ser mío, de otro
+ // técnico, o seguir sin asignar. Los botones de acción cambian según cada caso.
+ const isMineItem = !!(myUserId && String(s.assigned_to) === String(myUserId));
+ const isUnassignedItem = !s.assigned_to;
+ let techBadge = '';
+
if (currentTab === 'mine') {
- if (!isScheduled) {
+ if (isUnassignedItem) {
actionButtons = `
-