1063 lines
41 KiB
TypeScript
1063 lines
41 KiB
TypeScript
// ==============================================================================
|
|
// Vista Principal del Puesto de Control Web (Cockpit Garita)
|
|
// Optimizado para uso intensivo táctil en Samsung Galaxy Tab A9/A11 (4GB RAM)
|
|
// ==============================================================================
|
|
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
|
import { useAuth } from '../context/AuthContext';
|
|
import { workstationApi } from '../api/workstationApi';
|
|
import { accessApi } from '../api/accessApi';
|
|
import { hardwareApi } from '../api/hardwareApi';
|
|
import { useWebSocket } from '../hooks/useWebSocket';
|
|
import { CameraScannerModal } from '../components/scanner/CameraScannerModal';
|
|
import {
|
|
WorkstationConfig,
|
|
ActiveTicket,
|
|
EntryFormData,
|
|
DNIParsedResult,
|
|
LotSearchItem,
|
|
} from '../types';
|
|
|
|
export const ControlPostView: React.FC = () => {
|
|
const { user, workstation, logout } = useAuth();
|
|
|
|
// Configuración de Estación y Módulos
|
|
const [config, setConfig] = useState<WorkstationConfig | null>(null);
|
|
const [selectedEntryModuleId, setSelectedEntryModuleId] = useState<number>(0);
|
|
const [selectedExitModuleId, setSelectedExitModuleId] = useState<number>(0);
|
|
|
|
// Tickets activos y movimientos registrados en BD
|
|
const [activeTickets, setActiveTickets] = useState<ActiveTicket[]>([]);
|
|
const [recentMovements, setRecentMovements] = useState<any[]>([]);
|
|
const [viewTab, setViewTab] = useState<'active' | 'movements'>('active');
|
|
const [filterQuery, setFilterQuery] = useState<string>('');
|
|
const [isLoadingTickets, setIsLoadingTickets] = useState<boolean>(false);
|
|
|
|
// Estado del formulario de Ingreso
|
|
const [form, setForm] = useState<EntryFormData>({
|
|
modulo_ingreso_id: 0,
|
|
documento: '',
|
|
apellido: '',
|
|
nombre: '',
|
|
sexo: 'M',
|
|
patente: '',
|
|
lote_id: null,
|
|
lote_codigo: '',
|
|
motivo: 'VISITA',
|
|
cantidad_ocupantes: 1,
|
|
cantidad_menores: 0,
|
|
cacheo_salida: false,
|
|
abrir_barrera: true,
|
|
integrantes: [],
|
|
});
|
|
|
|
// Autocompletado de Lotes
|
|
const [lotSuggestions, setLotSuggestions] = useState<LotSearchItem[]>([]);
|
|
const [showLotSuggestions, setShowLotSuggestions] = useState<boolean>(false);
|
|
|
|
// Modales y Alertas
|
|
const [scannerOpen, setScannerOpen] = useState<boolean>(false);
|
|
const [actionSuccess, setActionSuccess] = useState<string | null>(null);
|
|
const [actionError, setActionError] = useState<string | null>(null);
|
|
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
|
|
const [clock, setClock] = useState<string>('');
|
|
|
|
// Reloj digital en tiempo real
|
|
useEffect(() => {
|
|
const timer = setInterval(() => {
|
|
const now = new Date();
|
|
setClock(now.toLocaleTimeString('es-AR', { hour12: false }));
|
|
}, 1000);
|
|
return () => clearInterval(timer);
|
|
}, []);
|
|
|
|
// Carga de configuración de estación
|
|
const loadConfig = useCallback(async () => {
|
|
try {
|
|
const wksConfig = await workstationApi.getConfig(workstation);
|
|
setConfig(wksConfig);
|
|
if (wksConfig.entry_modules && wksConfig.entry_modules.length > 0) {
|
|
setSelectedEntryModuleId(wksConfig.entry_modules[0].id);
|
|
setForm((prev) => ({ ...prev, modulo_ingreso_id: wksConfig.entry_modules[0].id }));
|
|
}
|
|
if (wksConfig.exit_modules && wksConfig.exit_modules.length > 0) {
|
|
setSelectedExitModuleId(wksConfig.exit_modules[0].id);
|
|
}
|
|
} catch (err: any) {
|
|
console.warn(`Configuración de ${workstation}:`, err);
|
|
}
|
|
}, [workstation]);
|
|
|
|
// Carga de tickets activos y movimientos reales
|
|
const loadActiveTickets = useCallback(async () => {
|
|
setIsLoadingTickets(true);
|
|
try {
|
|
const [tickets, movements] = await Promise.all([
|
|
accessApi.getActiveTickets(),
|
|
accessApi.getRecentMovements(30).catch(() => []),
|
|
]);
|
|
setActiveTickets(tickets);
|
|
setRecentMovements(movements);
|
|
} catch (err: any) {
|
|
console.error('Error al listar tickets:', err);
|
|
} finally {
|
|
setIsLoadingTickets(false);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
loadConfig();
|
|
loadActiveTickets();
|
|
}, [loadConfig, loadActiveTickets]);
|
|
|
|
// WebSockets para recepción de eventos en tiempo real
|
|
const handleWsEvent = useCallback(
|
|
(event: any) => {
|
|
if (event.type === 'ticket_created' || event.type === 'ticket_closed') {
|
|
loadActiveTickets();
|
|
}
|
|
if (event.type === 'barrier_opened') {
|
|
setActionSuccess(`Barrera de módulo ${event.modulo_id} accionada (${event.motivo || 'Apertura'})`);
|
|
setTimeout(() => setActionSuccess(null), 4000);
|
|
}
|
|
},
|
|
[loadActiveTickets]
|
|
);
|
|
|
|
const { isConnected: wsConnected } = useWebSocket({
|
|
stationName: workstation,
|
|
onMessage: handleWsEvent,
|
|
});
|
|
|
|
// Búsqueda autocompletada de Lotes
|
|
const handleLotSearch = async (val: string) => {
|
|
setForm((prev) => ({ ...prev, lote_codigo: val.toUpperCase() }));
|
|
if (val.trim().length >= 1) {
|
|
try {
|
|
const results = await accessApi.searchLots(val.trim());
|
|
setLotSuggestions(results);
|
|
setShowLotSuggestions(true);
|
|
} catch {
|
|
setLotSuggestions([]);
|
|
}
|
|
} else {
|
|
setLotSuggestions([]);
|
|
setShowLotSuggestions(false);
|
|
}
|
|
};
|
|
|
|
const selectLot = (lot: LotSearchItem) => {
|
|
setForm((prev) => ({
|
|
...prev,
|
|
lote_id: lot.lote_id,
|
|
lote_codigo: lot.codigo,
|
|
}));
|
|
setShowLotSuggestions(false);
|
|
};
|
|
|
|
// Callback al escanear DNI con cámara
|
|
const handleDniScanned = (data: DNIParsedResult) => {
|
|
setForm((prev) => ({
|
|
...prev,
|
|
documento: data.documento,
|
|
apellido: data.apellido,
|
|
nombre: data.nombre,
|
|
sexo: data.sexo || 'M',
|
|
}));
|
|
setActionSuccess(`DNI escaneado exitosamente: ${data.apellido}, ${data.nombre} (${data.documento})`);
|
|
setTimeout(() => setActionSuccess(null), 4000);
|
|
};
|
|
|
|
// Envío del formulario de Ingreso
|
|
const handleRegisterEntry = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (!form.documento.trim()) {
|
|
setActionError('El número de documento es obligatorio.');
|
|
return;
|
|
}
|
|
if (!selectedEntryModuleId) {
|
|
setActionError('Debe seleccionar un módulo de entrada.');
|
|
return;
|
|
}
|
|
|
|
setIsSubmitting(true);
|
|
setActionError(null);
|
|
setActionSuccess(null);
|
|
|
|
try {
|
|
const payload: EntryFormData = {
|
|
...form,
|
|
modulo_ingreso_id: selectedEntryModuleId,
|
|
documento: form.documento.trim(),
|
|
apellido: form.apellido.trim().toUpperCase(),
|
|
nombre: form.nombre.trim().toUpperCase(),
|
|
patente: form.patente.trim().toUpperCase() || '',
|
|
};
|
|
|
|
const res = await accessApi.registerEntry(payload);
|
|
setActionSuccess(`Ingreso registrado con éxito (Ticket #${res.ticket_id}) - ${res.barrier_opened ? 'Barrera Abierta' : ''}`);
|
|
setTimeout(() => setActionSuccess(null), 5000);
|
|
|
|
// Limpiar formulario para el siguiente vehículo
|
|
setForm({
|
|
modulo_ingreso_id: selectedEntryModuleId,
|
|
documento: '',
|
|
apellido: '',
|
|
nombre: '',
|
|
sexo: 'M',
|
|
patente: '',
|
|
lote_id: null,
|
|
lote_codigo: '',
|
|
motivo: 'VISITA',
|
|
cantidad_ocupantes: 1,
|
|
cantidad_menores: 0,
|
|
cacheo_salida: false,
|
|
abrir_barrera: true,
|
|
integrantes: [],
|
|
});
|
|
|
|
loadActiveTickets();
|
|
} catch (err: any) {
|
|
setActionError(err.message || 'Error al registrar ingreso.');
|
|
} finally {
|
|
setIsSubmitting(false);
|
|
}
|
|
};
|
|
|
|
// Registrar salida de un ticket activo
|
|
const handleRegisterExit = async (ticket: ActiveTicket) => {
|
|
if (!selectedExitModuleId) {
|
|
setActionError('Seleccione un módulo de salida para habilitar la barrera de egreso.');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await accessApi.registerExit({
|
|
ticket_id: ticket.ticket_id,
|
|
modulo_salida_id: selectedExitModuleId,
|
|
persona_id: ticket.persona_id,
|
|
patente_salida: ticket.patente || '',
|
|
abrir_barrera: true,
|
|
});
|
|
|
|
setActionSuccess(`Salida registrada para ${ticket.apellido} (${ticket.patente || 'Peatón'}) - Barrera Abierta`);
|
|
setTimeout(() => setActionSuccess(null), 4000);
|
|
loadActiveTickets();
|
|
} catch (err: any) {
|
|
setActionError(`Error al registrar salida: ${err.message}`);
|
|
}
|
|
};
|
|
|
|
// Apertura manual forzada de barrera
|
|
const handleManualOpen = async (moduloId: number, descripcion: string) => {
|
|
try {
|
|
const res = await hardwareApi.manualOpen(moduloId, `APERTURA_MANUAL_GUARDIA_${user?.username || 'OP'}`);
|
|
setActionSuccess(`Pulso de apertura enviado a ${descripcion} (Latencia: ${res.latencia_ms} ms)`);
|
|
setTimeout(() => setActionSuccess(null), 4000);
|
|
} catch (err: any) {
|
|
setActionError(`Error en apertura manual: ${err.message}`);
|
|
}
|
|
};
|
|
|
|
// Filtro de tickets activos
|
|
const filteredTickets = useMemo(() => {
|
|
if (!filterQuery.trim()) return activeTickets;
|
|
const q = filterQuery.toLowerCase().trim();
|
|
return activeTickets.filter(
|
|
(t) =>
|
|
t.documento.toLowerCase().includes(q) ||
|
|
t.apellido.toLowerCase().includes(q) ||
|
|
t.nombre.toLowerCase().includes(q) ||
|
|
(t.patente && t.patente.toLowerCase().includes(q)) ||
|
|
(t.lote_codigo && t.lote_codigo.toLowerCase().includes(q))
|
|
);
|
|
}, [activeTickets, filterQuery]);
|
|
|
|
// Filtro de movimientos historicos de la BD
|
|
const filteredMovements = useMemo(() => {
|
|
if (!filterQuery.trim()) return recentMovements;
|
|
const q = filterQuery.toLowerCase().trim();
|
|
return recentMovements.filter(
|
|
(m: any) =>
|
|
(m.documento && m.documento.toLowerCase().includes(q)) ||
|
|
(m.apellido && m.apellido.toLowerCase().includes(q)) ||
|
|
(m.nombre && m.nombre.toLowerCase().includes(q)) ||
|
|
(m.patente && m.patente.toLowerCase().includes(q)) ||
|
|
(m.modulo_nombre && m.modulo_nombre.toLowerCase().includes(q))
|
|
);
|
|
}, [recentMovements, filterQuery]);
|
|
|
|
const toggleFullscreen = () => {
|
|
if (!document.fullscreenElement) {
|
|
document.documentElement.requestFullscreen().catch(() => {});
|
|
} else {
|
|
document.exitFullscreen().catch(() => {});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
height: '100%',
|
|
backgroundColor: 'var(--bg-app)',
|
|
color: 'var(--text-primary)',
|
|
overflow: 'hidden',
|
|
}}
|
|
>
|
|
{/* =========================================================================
|
|
Barra Superior de Control (Garita Cockpit)
|
|
========================================================================= */}
|
|
<header
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
padding: '0.6rem 1.25rem',
|
|
backgroundColor: 'var(--bg-surface)',
|
|
borderBottom: '1px solid var(--border-subtle)',
|
|
minHeight: '60px',
|
|
}}
|
|
>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
<span style={{ fontSize: '1.4rem' }}>🛡️</span>
|
|
<div>
|
|
<h1 style={{ fontSize: '1.1rem', fontWeight: 700, margin: 0, lineHeight: 1.2 }}>
|
|
OnEverControl
|
|
</h1>
|
|
<span style={{ fontSize: '0.75rem', color: 'var(--text-muted)' }}>
|
|
{workstation} • {clock}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Estado de WebSocket / Enlace en tiempo real */}
|
|
<span
|
|
className={`badge ${wsConnected ? 'badge-success' : 'badge-danger'}`}
|
|
title="Estado del bus en tiempo real"
|
|
style={{ fontSize: '0.75rem', padding: '0.25rem 0.5rem' }}
|
|
>
|
|
{wsConnected ? '● Online' : '○ Reconectando...'}
|
|
</span>
|
|
</div>
|
|
|
|
{/* Acciones de Operador */}
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem' }}>
|
|
<span style={{ fontSize: '0.85rem', color: 'var(--text-secondary)' }}>
|
|
👤 Operador: <strong>{user?.username}</strong>
|
|
</span>
|
|
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary"
|
|
onClick={toggleFullscreen}
|
|
style={{ minHeight: '38px', padding: '0 0.75rem', fontSize: '0.85rem' }}
|
|
title="Pantalla Completa"
|
|
>
|
|
⛶
|
|
</button>
|
|
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary"
|
|
onClick={logout}
|
|
style={{ minHeight: '38px', padding: '0 0.85rem', fontSize: '0.85rem', color: 'var(--status-danger)' }}
|
|
>
|
|
Salir
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
{/* Banner de Mensajes y Alertas */}
|
|
{actionSuccess && (
|
|
<div
|
|
style={{
|
|
backgroundColor: 'var(--status-success-bg)',
|
|
color: 'var(--status-success)',
|
|
padding: '0.6rem 1.25rem',
|
|
fontSize: '0.9rem',
|
|
fontWeight: 600,
|
|
borderBottom: '1px solid var(--status-success)',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
}}
|
|
>
|
|
<span>✓ {actionSuccess}</span>
|
|
<button
|
|
onClick={() => setActionSuccess(null)}
|
|
style={{ background: 'none', border: 'none', color: 'inherit', cursor: 'pointer', fontSize: '1rem' }}
|
|
>
|
|
✕
|
|
</button>
|
|
</div>
|
|
)}
|
|
|
|
{actionError && (
|
|
<div
|
|
style={{
|
|
backgroundColor: 'var(--status-danger-bg)',
|
|
color: 'var(--status-danger)',
|
|
padding: '0.6rem 1.25rem',
|
|
fontSize: '0.9rem',
|
|
fontWeight: 600,
|
|
borderBottom: '1px solid var(--status-danger)',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
}}
|
|
>
|
|
<span>⚠️ {actionError}</span>
|
|
<button
|
|
onClick={() => setActionError(null)}
|
|
style={{ background: 'none', border: 'none', color: 'inherit', cursor: 'pointer', fontSize: '1rem' }}
|
|
>
|
|
✕
|
|
</button>
|
|
</div>
|
|
)}
|
|
|
|
{/* =========================================================================
|
|
Cuerpo Principal de Garita (Layout de 2 Columnas Táctil)
|
|
========================================================================= */}
|
|
<div
|
|
style={{
|
|
display: 'grid',
|
|
gridTemplateColumns: 'minmax(380px, 460px) 1fr',
|
|
flex: 1,
|
|
overflow: 'hidden',
|
|
}}
|
|
>
|
|
{/* =======================================================================
|
|
COLUMNA 1: FORMULARIO DE INGRESO RÁPIDO
|
|
======================================================================= */}
|
|
<section
|
|
style={{
|
|
backgroundColor: 'var(--bg-surface)',
|
|
borderRight: '1px solid var(--border-subtle)',
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
overflowY: 'auto',
|
|
padding: '1.25rem',
|
|
}}
|
|
>
|
|
{/* Botón Gigante de Escaneo con Cámara */}
|
|
<button
|
|
type="button"
|
|
className="btn btn-primary"
|
|
onClick={() => setScannerOpen(true)}
|
|
style={{
|
|
width: '100%',
|
|
minHeight: '56px',
|
|
fontSize: '1.1rem',
|
|
fontWeight: 700,
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
gap: '0.75rem',
|
|
marginBottom: '1rem',
|
|
backgroundColor: 'var(--accent-primary)',
|
|
}}
|
|
>
|
|
<span style={{ fontSize: '1.4rem' }}>📷</span>
|
|
ESCANEAR DNI CON CÁMARA
|
|
</button>
|
|
|
|
<form onSubmit={handleRegisterEntry} style={{ display: 'flex', flexDirection: 'column', gap: '0.85rem' }}>
|
|
{/* Selector de Módulo de Entrada */}
|
|
{config && config.entry_modules.length > 0 && (
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
MÓDULO DE ENTRADA:
|
|
</label>
|
|
<select
|
|
className="input-touch"
|
|
value={selectedEntryModuleId}
|
|
onChange={(e) => {
|
|
const id = Number(e.target.value);
|
|
setSelectedEntryModuleId(id);
|
|
setForm((prev) => ({ ...prev, modulo_ingreso_id: id }));
|
|
}}
|
|
style={{ width: '100%', marginTop: '0.25rem' }}
|
|
>
|
|
{config.entry_modules.map((m) => (
|
|
<option key={m.id} value={m.id}>
|
|
{m.name} (Addr {m.address})
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
)}
|
|
|
|
{/* Documento y Sexo */}
|
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 90px', gap: '0.5rem' }}>
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
DOCUMENTO / DNI:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
className="input-touch"
|
|
value={form.documento}
|
|
onChange={(e) => setForm((prev) => ({ ...prev, documento: e.target.value }))}
|
|
placeholder="Ej: 30123456"
|
|
required
|
|
style={{ width: '100%', marginTop: '0.25rem' }}
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
SEXO:
|
|
</label>
|
|
<select
|
|
className="input-touch"
|
|
value={form.sexo}
|
|
onChange={(e) => setForm((prev) => ({ ...prev, sexo: e.target.value }))}
|
|
style={{ width: '100%', marginTop: '0.25rem' }}
|
|
>
|
|
<option value="M">M</option>
|
|
<option value="F">F</option>
|
|
<option value="X">X</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Apellido y Nombre */}
|
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0.5rem' }}>
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
APELLIDO:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
className="input-touch"
|
|
value={form.apellido}
|
|
onChange={(e) => setForm((prev) => ({ ...prev, apellido: e.target.value }))}
|
|
placeholder="Ej: PEREZ"
|
|
style={{ width: '100%', marginTop: '0.25rem', textTransform: 'uppercase' }}
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
NOMBRE:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
className="input-touch"
|
|
value={form.nombre}
|
|
onChange={(e) => setForm((prev) => ({ ...prev, nombre: e.target.value }))}
|
|
placeholder="Ej: JUAN"
|
|
style={{ width: '100%', marginTop: '0.25rem', textTransform: 'uppercase' }}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Patente y Lote de Destino con Autocomplete */}
|
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0.5rem' }}>
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
PATENTE VEHÍCULO:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
className="input-touch"
|
|
value={form.patente}
|
|
onChange={(e) => setForm((prev) => ({ ...prev, patente: e.target.value.toUpperCase() }))}
|
|
placeholder="Ej: AB123CD"
|
|
style={{ width: '100%', marginTop: '0.25rem', textTransform: 'uppercase' }}
|
|
/>
|
|
</div>
|
|
|
|
<div style={{ position: 'relative' }}>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
LOTE / DESTINO:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
className="input-touch"
|
|
value={form.lote_codigo}
|
|
onChange={(e) => handleLotSearch(e.target.value)}
|
|
onFocus={() => {
|
|
if (lotSuggestions.length > 0) setShowLotSuggestions(true);
|
|
}}
|
|
placeholder="Ej: 142"
|
|
style={{ width: '100%', marginTop: '0.25rem' }}
|
|
/>
|
|
{/* Desplegable de sugerencias de Lotes */}
|
|
{showLotSuggestions && lotSuggestions.length > 0 && (
|
|
<div
|
|
style={{
|
|
position: 'absolute',
|
|
top: '100%',
|
|
left: 0,
|
|
right: 0,
|
|
backgroundColor: 'var(--bg-card)',
|
|
border: '1px solid var(--border-subtle)',
|
|
borderRadius: 'var(--radius-sm)',
|
|
boxShadow: 'var(--shadow-md)',
|
|
zIndex: 100,
|
|
maxHeight: '160px',
|
|
overflowY: 'auto',
|
|
}}
|
|
>
|
|
{lotSuggestions.map((lot) => (
|
|
<div
|
|
key={lot.lote_id}
|
|
onClick={() => selectLot(lot)}
|
|
style={{
|
|
padding: '0.6rem 0.75rem',
|
|
cursor: 'pointer',
|
|
fontSize: '0.9rem',
|
|
borderBottom: '1px solid var(--border-subtle)',
|
|
}}
|
|
>
|
|
Lote <strong>{lot.codigo}</strong>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Motivo de Visita y Ocupantes Stepper */}
|
|
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0.5rem', alignItems: 'center' }}>
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
MOTIVO:
|
|
</label>
|
|
<select
|
|
className="input-touch"
|
|
value={form.motivo}
|
|
onChange={(e) => setForm((prev) => ({ ...prev, motivo: e.target.value }))}
|
|
style={{ width: '100%', marginTop: '0.25rem' }}
|
|
>
|
|
<option value="VISITA">VISITA</option>
|
|
<option value="PROVEEDOR">PROVEEDOR</option>
|
|
<option value="SERVICIO">SERVICIO</option>
|
|
<option value="TRABAJADOR">TRABAJADOR</option>
|
|
<option value="MUDANZA">MUDANZA</option>
|
|
<option value="OTRO">OTRO</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div>
|
|
<label style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
OCUPANTES:
|
|
</label>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.25rem', marginTop: '0.25rem' }}>
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary"
|
|
onClick={() =>
|
|
setForm((prev) => ({ ...prev, cantidad_ocupantes: Math.max(1, prev.cantidad_ocupantes - 1) }))
|
|
}
|
|
style={{ minHeight: '44px', width: '44px', fontSize: '1.2rem', padding: 0 }}
|
|
>
|
|
-
|
|
</button>
|
|
<div
|
|
style={{
|
|
flex: 1,
|
|
textAlign: 'center',
|
|
fontSize: '1.2rem',
|
|
fontWeight: 700,
|
|
backgroundColor: 'var(--bg-card)',
|
|
borderRadius: 'var(--radius-sm)',
|
|
padding: '0.4rem 0',
|
|
}}
|
|
>
|
|
{form.cantidad_ocupantes}
|
|
</div>
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary"
|
|
onClick={() =>
|
|
setForm((prev) => ({ ...prev, cantidad_ocupantes: prev.cantidad_ocupantes + 1 }))
|
|
}
|
|
style={{ minHeight: '44px', width: '44px', fontSize: '1.2rem', padding: 0 }}
|
|
>
|
|
+
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Switch Abrir Barrera */}
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.75rem',
|
|
backgroundColor: 'var(--bg-card)',
|
|
padding: '0.75rem',
|
|
borderRadius: 'var(--radius-sm)',
|
|
marginTop: '0.25rem',
|
|
}}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
id="abrir_barrera_check"
|
|
checked={form.abrir_barrera}
|
|
onChange={(e) => setForm((prev) => ({ ...prev, abrir_barrera: e.target.checked }))}
|
|
style={{ width: '22px', height: '22px', cursor: 'pointer' }}
|
|
/>
|
|
<label
|
|
htmlFor="abrir_barrera_check"
|
|
style={{ fontSize: '0.9rem', fontWeight: 600, cursor: 'pointer', flex: 1 }}
|
|
>
|
|
Abrir barrera física al confirmar
|
|
</label>
|
|
</div>
|
|
|
|
{/* Botón Principal de Envío */}
|
|
<button
|
|
type="submit"
|
|
disabled={isSubmitting}
|
|
className="btn"
|
|
style={{
|
|
width: '100%',
|
|
minHeight: '60px',
|
|
fontSize: '1.15rem',
|
|
fontWeight: 700,
|
|
marginTop: '0.5rem',
|
|
backgroundColor: 'var(--status-success)',
|
|
color: '#fff',
|
|
borderRadius: 'var(--radius-md)',
|
|
boxShadow: 'var(--shadow-md)',
|
|
}}
|
|
>
|
|
{isSubmitting ? 'Registrando...' : '✓ REGISTRAR INGRESO Y ABRIR'}
|
|
</button>
|
|
</form>
|
|
</section>
|
|
|
|
{/* =======================================================================
|
|
COLUMNA 2: TICKETS ACTIVOS Y EGRESOS DEL PREDIO
|
|
======================================================================= */}
|
|
<section
|
|
style={{
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
backgroundColor: 'var(--bg-app)',
|
|
overflow: 'hidden',
|
|
}}
|
|
>
|
|
{/* Pestañas de Selección: Activos vs Historial BD */}
|
|
<div
|
|
style={{
|
|
padding: '0.5rem 1.25rem 0',
|
|
backgroundColor: 'var(--bg-surface)',
|
|
borderBottom: '1px solid var(--border-subtle)',
|
|
display: 'flex',
|
|
gap: '0.75rem',
|
|
}}
|
|
>
|
|
<button
|
|
type="button"
|
|
onClick={() => setViewTab('active')}
|
|
style={{
|
|
padding: '0.65rem 1.25rem',
|
|
border: 'none',
|
|
borderBottom: viewTab === 'active' ? '3px solid var(--brand-primary)' : '3px solid transparent',
|
|
backgroundColor: 'transparent',
|
|
fontWeight: viewTab === 'active' ? 700 : 500,
|
|
color: viewTab === 'active' ? 'var(--brand-primary)' : 'var(--text-secondary)',
|
|
cursor: 'pointer',
|
|
fontSize: '0.95rem',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.5rem',
|
|
}}
|
|
>
|
|
<span>🟢 En Predio (Activos)</span>
|
|
<span className="badge badge-info" style={{ fontSize: '0.8rem' }}>
|
|
{activeTickets.length}
|
|
</span>
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => setViewTab('movements')}
|
|
style={{
|
|
padding: '0.65rem 1.25rem',
|
|
border: 'none',
|
|
borderBottom: viewTab === 'movements' ? '3px solid var(--brand-primary)' : '3px solid transparent',
|
|
backgroundColor: 'transparent',
|
|
fontWeight: viewTab === 'movements' ? 700 : 500,
|
|
color: viewTab === 'movements' ? 'var(--brand-primary)' : 'var(--text-secondary)',
|
|
cursor: 'pointer',
|
|
fontSize: '0.95rem',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
gap: '0.5rem',
|
|
}}
|
|
>
|
|
<span>📜 Historial Movimientos BD</span>
|
|
<span className="badge badge-neutral" style={{ fontSize: '0.8rem' }}>
|
|
{recentMovements.length}
|
|
</span>
|
|
</button>
|
|
</div>
|
|
|
|
{/* Barra de Filtros y Módulo de Salida */}
|
|
<div
|
|
style={{
|
|
padding: '0.75rem 1.25rem',
|
|
backgroundColor: 'var(--bg-surface)',
|
|
borderBottom: '1px solid var(--border-subtle)',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
gap: '1rem',
|
|
}}
|
|
>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem', flex: 1 }}>
|
|
<input
|
|
type="text"
|
|
className="input-touch"
|
|
placeholder={viewTab === 'active' ? "🔍 Filtrar por patente, DNI o apellido..." : "🔍 Filtrar historial..."}
|
|
value={filterQuery}
|
|
onChange={(e) => setFilterQuery(e.target.value)}
|
|
style={{ maxWidth: '380px' }}
|
|
/>
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary"
|
|
onClick={() => loadActiveTickets()}
|
|
title="Refrescar datos de la Base de Datos"
|
|
style={{ minHeight: '40px', padding: '0 0.8rem', fontSize: '0.85rem' }}
|
|
>
|
|
🔄 Actualizar
|
|
</button>
|
|
<span className="badge badge-info" style={{ fontSize: '0.85rem', padding: '0.35rem 0.7rem' }}>
|
|
{viewTab === 'active' ? `${filteredTickets.length} ocupantes` : `${filteredMovements.length} registros`}
|
|
</span>
|
|
</div>
|
|
|
|
{/* Módulo de Salida para Egresos (solo visible en pestaña Activos) */}
|
|
{viewTab === 'active' && config && config.exit_modules.length > 0 && (
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
|
|
<span style={{ fontSize: '0.75rem', fontWeight: 600, color: 'var(--text-secondary)' }}>
|
|
BARRERA SALIDA:
|
|
</span>
|
|
<select
|
|
className="input-touch"
|
|
value={selectedExitModuleId}
|
|
onChange={(e) => setSelectedExitModuleId(Number(e.target.value))}
|
|
style={{ minHeight: '40px' }}
|
|
>
|
|
{config.exit_modules.map((m) => (
|
|
<option key={m.id} value={m.id}>
|
|
{m.name} (Addr {m.address})
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Grilla / Lista de Contenido Según Pestaña */}
|
|
<div style={{ flex: 1, overflowY: 'auto', padding: '1.25rem' }}>
|
|
{isLoadingTickets && activeTickets.length === 0 && recentMovements.length === 0 ? (
|
|
<div style={{ textAlign: 'center', padding: '2rem', color: 'var(--text-muted)' }}>
|
|
Cargando datos desde la base de datos...
|
|
</div>
|
|
) : viewTab === 'active' ? (
|
|
/* TAB 1: TICKETS ACTIVOS EN PREDIO */
|
|
filteredTickets.length === 0 ? (
|
|
<div style={{ textAlign: 'center', padding: '3rem', color: 'var(--text-muted)' }}>
|
|
{filterQuery ? 'No se encontraron coincidencias para la búsqueda.' : 'No hay visitas ni vehículos activos en el predio actualmente.'}
|
|
</div>
|
|
) : (
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>
|
|
{filteredTickets.map((t) => (
|
|
<div
|
|
key={t.ticket_id}
|
|
className="card"
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
padding: '0.85rem 1.25rem',
|
|
backgroundColor: 'var(--bg-surface)',
|
|
borderRadius: 'var(--radius-md)',
|
|
boxShadow: 'var(--shadow-sm)',
|
|
border: '1px solid var(--border-subtle)',
|
|
}}
|
|
>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '1.25rem' }}>
|
|
<div
|
|
style={{
|
|
backgroundColor: t.patente ? 'var(--status-info-bg)' : 'var(--status-warning-bg)',
|
|
color: t.patente ? 'var(--status-info)' : 'var(--status-warning)',
|
|
padding: '0.5rem 0.75rem',
|
|
borderRadius: '8px',
|
|
fontWeight: 700,
|
|
fontSize: '1.1rem',
|
|
minWidth: '95px',
|
|
textAlign: 'center',
|
|
}}
|
|
>
|
|
{t.patente || 'PEATÓN'}
|
|
</div>
|
|
|
|
<div>
|
|
<div style={{ fontSize: '1rem', fontWeight: 600 }}>
|
|
{t.apellido}, {t.nombre}{' '}
|
|
<span style={{ fontSize: '0.8rem', fontWeight: 400, color: 'var(--text-muted)' }}>
|
|
(DNI: {t.documento})
|
|
</span>
|
|
</div>
|
|
<div style={{ fontSize: '0.8rem', color: 'var(--text-secondary)', marginTop: '0.2rem' }}>
|
|
Destino: <strong>Lote {t.lote_codigo || 'S/D'}</strong> • Ingreso:{' '}
|
|
{t.fecha_ingreso} ({t.modulo_ingreso})
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<button
|
|
type="button"
|
|
className="btn"
|
|
onClick={() => handleRegisterExit(t)}
|
|
style={{
|
|
backgroundColor: 'var(--status-danger)',
|
|
color: '#fff',
|
|
fontWeight: 600,
|
|
minHeight: '48px',
|
|
padding: '0 1.25rem',
|
|
fontSize: '0.95rem',
|
|
}}
|
|
>
|
|
DAR SALIDA
|
|
</button>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)
|
|
) : (
|
|
/* TAB 2: HISTORIAL DE MOVIMIENTOS REALES EN BASE DE DATOS */
|
|
filteredMovements.length === 0 ? (
|
|
<div style={{ textAlign: 'center', padding: '3rem', color: 'var(--text-muted)' }}>
|
|
{filterQuery ? 'No se encontraron movimientos que coincidan.' : 'No hay movimientos registrados en la base de datos.'}
|
|
</div>
|
|
) : (
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.75rem' }}>
|
|
{filteredMovements.map((m: any, idx: number) => {
|
|
const isIngreso = (m.sentido || '').toUpperCase() === 'INGRESO' || (m.sentido || '').toUpperCase() === 'ENTRADA';
|
|
return (
|
|
<div
|
|
key={`${m.hist_id || idx}-${m.fecha_hora}`}
|
|
className="card"
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
padding: '0.85rem 1.25rem',
|
|
backgroundColor: 'var(--bg-surface)',
|
|
borderRadius: 'var(--radius-md)',
|
|
boxShadow: 'var(--shadow-sm)',
|
|
border: '1px solid var(--border-subtle)',
|
|
}}
|
|
>
|
|
<div style={{ display: 'flex', alignItems: 'center', gap: '1.25rem' }}>
|
|
<span
|
|
className={isIngreso ? 'badge badge-success' : 'badge badge-warning'}
|
|
style={{ fontSize: '0.85rem', fontWeight: 700, minWidth: '85px', textAlign: 'center' }}
|
|
>
|
|
{m.sentido || 'MOVIMIENTO'}
|
|
</span>
|
|
|
|
<div
|
|
style={{
|
|
backgroundColor: m.patente ? 'var(--status-info-bg)' : 'var(--border-subtle)',
|
|
color: m.patente ? 'var(--status-info)' : 'var(--text-secondary)',
|
|
padding: '0.4rem 0.65rem',
|
|
borderRadius: '6px',
|
|
fontWeight: 700,
|
|
fontSize: '0.95rem',
|
|
minWidth: '85px',
|
|
textAlign: 'center',
|
|
}}
|
|
>
|
|
{m.patente || 'PEATÓN'}
|
|
</div>
|
|
|
|
<div>
|
|
<div style={{ fontSize: '0.95rem', fontWeight: 600 }}>
|
|
{m.apellido || m.nombre ? `${m.apellido || ''}, ${m.nombre || ''}` : 'S/D'}{' '}
|
|
{m.documento && (
|
|
<span style={{ fontSize: '0.8rem', fontWeight: 400, color: 'var(--text-muted)' }}>
|
|
(DNI: {m.documento})
|
|
</span>
|
|
)}
|
|
</div>
|
|
<div style={{ fontSize: '0.8rem', color: 'var(--text-secondary)', marginTop: '0.15rem' }}>
|
|
Módulo: <strong>{m.modulo_nombre || `ID ${m.modulo_id}`}</strong> • Motivo: {m.motivo || 'N/A'}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div style={{ textAlign: 'right' }}>
|
|
<span style={{ fontSize: '0.85rem', fontWeight: 600, color: 'var(--text-primary)' }}>
|
|
{m.fecha_hora ? new Date(m.fecha_hora).toLocaleString('es-AR') : 'S/F'}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
)
|
|
)}
|
|
</div>
|
|
|
|
{/* Barra Inferior de Aperturas Manuales de Emergencia */}
|
|
<footer
|
|
style={{
|
|
padding: '0.75rem 1.25rem',
|
|
backgroundColor: 'var(--bg-surface)',
|
|
borderTop: '1px solid var(--border-subtle)',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'space-between',
|
|
gap: '1rem',
|
|
}}
|
|
>
|
|
<div style={{ fontSize: '0.8rem', color: 'var(--text-muted)' }}>
|
|
Acciones Rápidas de Emergencia (Auditoría inmediata):
|
|
</div>
|
|
<div style={{ display: 'flex', gap: '0.75rem' }}>
|
|
{selectedEntryModuleId > 0 && (
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary"
|
|
onClick={() => handleManualOpen(selectedEntryModuleId, 'Entrada')}
|
|
style={{ minHeight: '44px', fontSize: '0.85rem' }}
|
|
>
|
|
⚡ Abrir Barrera Entrada
|
|
</button>
|
|
)}
|
|
{selectedExitModuleId > 0 && (
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary"
|
|
onClick={() => handleManualOpen(selectedExitModuleId, 'Salida')}
|
|
style={{ minHeight: '44px', fontSize: '0.85rem' }}
|
|
>
|
|
⚡ Abrir Barrera Salida
|
|
</button>
|
|
)}
|
|
</div>
|
|
</footer>
|
|
</section>
|
|
</div>
|
|
|
|
{/* Modal de Escaneo con Cámara */}
|
|
<CameraScannerModal
|
|
isOpen={scannerOpen}
|
|
onClose={() => setScannerOpen(false)}
|
|
onScanSuccess={handleDniScanned}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|