diff --git a/layout_header.php b/layout_header.php index ea573c02..cbf77013 100644 --- a/layout_header.php +++ b/layout_header.php @@ -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 = [ <?php echo isset($pageTitle) ? htmlspecialchars($pageTitle) : 'FLOOWER ERP'; ?> - + diff --git a/test_importar_drive.php b/test_importar_drive.php new file mode 100644 index 00000000..648c05a7 --- /dev/null +++ b/test_importar_drive.php @@ -0,0 +1,125 @@ +Acceso denegado."; + 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(); +} +?> + +
+
+
+
+
+
+
+

Vista previa de pedidos desde Drive

+

Aquí verás solo los últimos 10 registros encontrados en la hoja, sin guardar nada todavía en la base de datos.

+
+ + visibles + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +
+
+
+

Cómo funciona esta prueba

+
    +
  1. Lee la hoja de Google Sheets en tiempo real.
  2. +
  3. Toma solo los últimos 10 pedidos detectados.
  4. +
  5. Muestra la información en pantalla sin importar nada al CRM.
  6. +
+
+
+ +
+
+

Resumen rápido

+
    +
  • Modo: Vista previa segura
  • +
  • Pedidos totales detectados:
  • +
  • Pedidos visibles:
  • +
  • Base de datos: Sin cambios
  • +
+
+
+
+
+
+ +