fix(turnero): dos correcciones de estado y redirección
1. App::bacteDefaultUrl() ahora busca también por token cookie (antes solo buscaba por IP), consistente con login.php y lugar.php. 2. cambiarEstadoTurno(): cuando el servidor devuelve 422 (transición inválida porque otro operador cambió el estado), muestra mensaje claro y refresca la UI en lugar de mostrar el error técnico bruto "Transición 'en_recepcion' → 'finalizado' no está permitida". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
88fd0e4151
commit
70fda3dacc
+19
-14
@@ -162,25 +162,30 @@ class App
|
||||
$base = '/erp.php?m=turnero&v=lugar&lugar_id=';
|
||||
try {
|
||||
$pdo = Database::getInstance()->getConnection();
|
||||
$ip = self::clientIp();
|
||||
// ¿IP registrada?
|
||||
$dev = $pdo->prepare(
|
||||
"SELECT lugar_id FROM turnero_dispositivos WHERE ip = ? AND activo = 1 LIMIT 1"
|
||||
);
|
||||
$dev->execute([$ip]);
|
||||
$row = $dev->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row) {
|
||||
return $base . (int)$row['lugar_id'];
|
||||
// 1. Por token de navegador
|
||||
$tok = trim($_COOKIE['turnero_token'] ?? '');
|
||||
if ($tok) {
|
||||
$s = $pdo->prepare(
|
||||
"SELECT lugar_id FROM turnero_dispositivos WHERE token = ? AND activo = 1 LIMIT 1"
|
||||
);
|
||||
$s->execute([$tok]);
|
||||
$row = $s->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row) return $base . (int)$row['lugar_id'];
|
||||
}
|
||||
// Primer lugar de toma de muestras
|
||||
// 2. Por IP
|
||||
$ip = self::clientIp();
|
||||
$s = $pdo->prepare(
|
||||
"SELECT lugar_id FROM turnero_dispositivos WHERE ip = ? AND token IS NULL AND activo = 1 LIMIT 1"
|
||||
);
|
||||
$s->execute([$ip]);
|
||||
$row = $s->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row) return $base . (int)$row['lugar_id'];
|
||||
// 3. Primer lugar de toma de muestras
|
||||
$first = $pdo->query(
|
||||
"SELECT id FROM turnero_lugares WHERE activo=1 AND tipo='muestras' ORDER BY sort_order LIMIT 1"
|
||||
)->fetch(PDO::FETCH_ASSOC);
|
||||
if ($first) {
|
||||
return $base . (int)$first['id'];
|
||||
}
|
||||
if ($first) return $base . (int)$first['id'];
|
||||
} catch (\Throwable $_) {}
|
||||
// Fallback: turnero sin vista específica
|
||||
return '/erp.php?m=turnero';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user