certimine/views/lookup.php
remaster ff0fd6a89d API Peñasquito: ticket persistente, company y mejor flujo de búsqueda
- Renombrado «DC3» a «API Peñasquito» (URL base del documento) en UI/docs;
  rutas y claves de config conservadas por compatibilidad.
- Persistencia de ticket_id en nueva tabla `penasquito_tickets`:
  POST /search/ guarda el ticket y los siguientes requests retoman
  GET /result/<ticket_id>/ sin reencolar.
- Polling acotado por request HTTP (~6 s) con `PenasquitoPendingException`
  y caja «reintentar» en lookup; ticket queda válido 1 h.
- `users_cache.company` nuevo (con migración idempotente); persistResult
  guarda empresa + competencias en transacción y aplica source distinto.
- Mensajes HTTP específicos (400/401/403/404/408/429/5xx) y `/` final
  forzado en rutas (DRF), FOLLOWLOCATION habilitado.
- Vista de perfil muestra «Empresa» y aviso cuando no hay competencias.
- Auth::login evita doble fetch cuando ya tenemos el `result` del API.
- i18n ES/EN actualizados; lookup_pending_*; limpieza de archivos lang.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 19:43:37 -06:00

98 lines
4.6 KiB
PHP

<?php
declare(strict_types=1);
use CertiMine\Config;
use CertiMine\I18n;
use CertiMine\Security;
use CertiMine\Util;
/** @var string|null $error */
/** @var string|null $lookupErrorDetail */
/** @var array{passport:string,ticket_id:string,status:string,posicion:?int}|null $lookupPending */
/** @var bool $penasquitoApiOk */
/** @var bool $penasquitoApiTokenFromEnv */
/** @var bool $lookupUsingExample */
/** @var string $penasquitoApiBaseUrl */
require __DIR__ . '/partials/header.php';
?>
<h1 class="h3 mb-3"><?= Util::h(I18n::t('lookup_title')) ?></h1>
<p class="text-muted"><?= Util::h(I18n::t('lookup_intro')) ?></p>
<?php if (!$penasquitoApiOk): ?>
<div class="alert alert-warning border-0 shadow-sm" role="status">
<span class="material-symbols-outlined align-middle">warning</span>
<strong><?= Util::h(I18n::t('lookup_need_dc3_title')) ?></strong><br>
<?= Util::h(I18n::t('lookup_need_dc3_body')) ?>
<?php if ($lookupUsingExample): ?>
<br><span class="small text-muted"><?= Util::h(I18n::t('lookup_using_example_config')) ?></span>
<?php endif; ?>
</div>
<?php else: ?>
<div class="alert alert-success border-0 shadow-sm py-2" role="status">
<span class="material-symbols-outlined align-middle">cloud_done</span>
<?= Util::h(I18n::t('lookup_dc3_ready')) ?>
<span class="small text-muted d-block mt-1">
<?= Util::h($penasquitoApiBaseUrl) ?>
<?php if ($penasquitoApiTokenFromEnv): ?> — <?= Util::h(I18n::t('lookup_token_env')) ?><?php else: ?> — <?= Util::h(I18n::t('lookup_token_config')) ?><?php endif; ?>
</span>
</div>
<?php endif; ?>
<?php if (Config::debugMode()): ?>
<div class="alert alert-secondary small"><?= Util::h(I18n::t('lookup_debug_hint')) ?></div>
<?php endif; ?>
<?php if (!empty($lookupPending)): ?>
<div class="alert alert-info border-0 shadow-sm">
<div class="d-flex align-items-center gap-2 mb-2">
<span class="material-symbols-outlined">hourglass_top</span>
<strong><?= Util::h(I18n::t('lookup_pending_title')) ?></strong>
</div>
<p class="mb-2"><?= Util::h(I18n::t('lookup_pending_body')) ?></p>
<ul class="small text-muted mb-3">
<li><?= Util::h(I18n::t('lookup_pending_passport')) ?>: <code><?= Util::h($lookupPending['passport']) ?></code></li>
<li><?= Util::h(I18n::t('lookup_pending_ticket')) ?>: <code><?= Util::h($lookupPending['ticket_id']) ?></code></li>
<li><?= Util::h(I18n::t('lookup_pending_status')) ?>: <code><?= Util::h($lookupPending['status']) ?></code><?php if ($lookupPending['posicion'] !== null): ?> · <?= Util::h(I18n::t('lookup_pending_position')) ?>: <strong><?= (int) $lookupPending['posicion'] ?></strong><?php endif; ?></li>
</ul>
<form method="post" class="d-inline">
<input type="hidden" name="_csrf" value="<?= Util::h(Security::csrfToken()) ?>">
<input type="hidden" name="person_type" value="employee">
<input type="hidden" name="code" value="<?= Util::h($lookupPending['passport']) ?>">
<button class="btn btn-primary" type="submit">
<span class="material-symbols-outlined align-middle">refresh</span>
<?= Util::h(I18n::t('lookup_pending_retry')) ?>
</button>
</form>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-danger">
<?= Util::h($error) ?>
<?php if (!empty($lookupErrorDetail)): ?>
<hr class="my-2">
<div class="small font-monospace text-break mb-0"><?= Util::h((string) $lookupErrorDetail) ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
<form method="post" class="card p-4 mb-3" style="max-width:520px">
<input type="hidden" name="_csrf" value="<?= Util::h(Security::csrfToken()) ?>">
<div class="mb-3">
<label class="form-label"><?= Util::h(I18n::t('lookup_type')) ?></label>
<select name="person_type" class="form-select">
<option value="employee"><?= Util::h(I18n::t('lookup_employee')) ?></option>
<option value="contractor"><?= Util::h(I18n::t('lookup_contractor')) ?></option>
</select>
</div>
<div class="mb-3">
<label class="form-label"><?= Util::h(I18n::t('lookup_code')) ?></label>
<input class="form-control" name="code" required placeholder="E000055821 / 10001 / C-5001" autocomplete="off">
<div class="form-text"><?= Util::h(I18n::t('lookup_passport_hint')) ?></div>
</div>
<button class="btn btn-success" type="submit"><?= Util::h(I18n::t('lookup_submit')) ?></button>
</form>
<p class="small text-muted"><?= Util::h(I18n::t('lookup_qr_hint')) ?></p>
<?php require __DIR__ . '/partials/footer.php'; ?>