Autosave: 20260524-013507

This commit is contained in:
Flatlogic Bot 2026-05-24 01:35:11 +00:00
parent e71ff2d7a4
commit 4671e9246d
2 changed files with 139 additions and 1 deletions

View File

@ -270,6 +270,19 @@ $navItems = [
],
]
],
'modulo_pruebas_group' => [
'icon' => 'fa-flask',
'text' => 'Módulo de Pruebas',
'roles' => ['Administrador', 'admin'],
'submenu' => [
'test_importar_drive' => [
'url' => 'test_importar_drive.php',
'icon' => 'fa-google-drive',
'text' => 'Importar Drive (Test)',
'roles' => ['Administrador', 'admin']
]
]
],
'configuracion_group' => [
'icon' => 'fa-cog',
'text' => 'Configuración',
@ -304,7 +317,7 @@ $navItems = [
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo isset($pageTitle) ? htmlspecialchars($pageTitle) : 'FLOOWER ERP'; ?></title>
<meta name="description" content="CRM de seguimiento de pedidos para Floower Store.">
<meta name="description" content="<?php echo htmlspecialchars(isset($pageDescription) ? $pageDescription : 'CRM de seguimiento de pedidos para Floower Store.'); ?>">
<meta name="keywords" content="dashboard, call center, payment validation, order tracking, crm">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">

125
test_importar_drive.php Normal file
View File

@ -0,0 +1,125 @@
<?php
$pageTitle = 'Importar Drive (Test)';
$pageDescription = 'Vista previa de los últimos 10 pedidos detectados en Google Sheets antes de importarlos al CRM.';
require_once __DIR__ . '/layout_header.php';
if (($_SESSION['user_role'] ?? '') !== 'Administrador' && ($_SESSION['user_role'] ?? '') !== 'admin') {
echo "<div class='alert alert-danger'>Acceso denegado.</div>";
require_once __DIR__ . '/layout_footer.php';
exit();
}
require_once __DIR__ . '/vendor/autoload.php';
$credentialsPath = __DIR__ . '/google_credentials.json';
$spreadsheetId = '1SSmQuR9quxeQbMKNMDkRe8-n1gU7WuEfsFaJ3WKFO-c';
$range = 'A:Z';
$headers = [];
$previewRows = [];
$errorMessage = null;
$totalDataRows = 0;
try {
if (!file_exists($credentialsPath)) {
throw new RuntimeException('No se encontró el archivo de credenciales de Google.');
}
$client = new Google\Client();
$client->setAuthConfig($credentialsPath);
$client->addScope(Google\Service\Sheets::SPREADSHEETS_READONLY);
$service = new Google\Service\Sheets($client);
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
if (empty($values)) {
throw new RuntimeException('La hoja está vacía o no devolvió datos.');
}
$headers = $values[0] ?? [];
$dataRows = array_slice($values, 1);
$totalDataRows = count($dataRows);
$previewRows = array_reverse(array_slice($dataRows, -10));
} catch (Throwable $exception) {
$errorMessage = $exception->getMessage();
}
?>
<div class="container py-4">
<div class="row g-4 align-items-stretch">
<div class="col-12 col-xl-8">
<div class="card shadow-sm border-0 h-100">
<div class="card-body p-4">
<div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3 mb-3">
<div>
<h2 class="h4 mb-1">Vista previa de pedidos desde Drive</h2>
<p class="text-muted mb-0">Aquí verás solo los últimos 10 registros encontrados en la hoja, sin guardar nada todavía en la base de datos.</p>
</div>
<span class="badge bg-primary-subtle text-primary-emphasis px-3 py-2">
<?php echo (int) count($previewRows); ?> visibles
</span>
</div>
<?php if ($errorMessage !== null): ?>
<div class="alert alert-danger mb-0" role="alert">
<strong>No se pudo cargar la vista previa.</strong><br>
<?php echo htmlspecialchars($errorMessage); ?>
</div>
<?php elseif (empty($previewRows)): ?>
<div class="alert alert-warning mb-0" role="alert">
La hoja respondió correctamente, pero todavía no hay pedidos suficientes para mostrar una vista previa.
</div>
<?php else: ?>
<div class="table-responsive">
<table class="table table-hover align-middle">
<thead class="table-dark">
<tr>
<?php foreach ($headers as $header): ?>
<th scope="col"><?php echo htmlspecialchars((string) $header); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($previewRows as $row): ?>
<tr>
<?php for ($i = 0; $i < count($headers); $i++): ?>
<td><?php echo htmlspecialchars((string) ($row[$i] ?? '')); ?></td>
<?php endfor; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
<div class="col-12 col-xl-4">
<div class="card shadow-sm border-0 mb-4">
<div class="card-body p-4">
<h2 class="h5">Cómo funciona esta prueba</h2>
<ol class="mb-0 ps-3">
<li class="mb-2">Lee la hoja de Google Sheets en tiempo real.</li>
<li class="mb-2">Toma solo los últimos 10 pedidos detectados.</li>
<li class="mb-0">Muestra la información en pantalla sin importar nada al CRM.</li>
</ol>
</div>
</div>
<div class="card shadow-sm border-0">
<div class="card-body p-4">
<h2 class="h5">Resumen rápido</h2>
<ul class="list-unstyled mb-0">
<li class="mb-2"><strong>Modo:</strong> Vista previa segura</li>
<li class="mb-2"><strong>Pedidos totales detectados:</strong> <?php echo (int) $totalDataRows; ?></li>
<li class="mb-2"><strong>Pedidos visibles:</strong> <?php echo (int) count($previewRows); ?></li>
<li class="mb-0"><strong>Base de datos:</strong> Sin cambios</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php require_once __DIR__ . '/layout_footer.php'; ?>