From e7de0e4bea3de131a839e0ed6defb71fd690a6b0 Mon Sep 17 00:00:00 2001 From: paoloar77 Date: Fri, 20 Dec 2024 11:31:03 +0100 Subject: [PATCH] view tables --- app/Http/Controllers/ArticleController.php | 58 +++++++++++++++++++++- resources/views/info.blade.php | 19 +++++++ routes/web.php | 1 + 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 resources/views/info.blade.php diff --git a/app/Http/Controllers/ArticleController.php b/app/Http/Controllers/ArticleController.php index b8f4b6ba..26bb155d 100755 --- a/app/Http/Controllers/ArticleController.php +++ b/app/Http/Controllers/ArticleController.php @@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; use App\Article; use DateTime; @@ -199,7 +200,7 @@ class ArticleController extends Controller ->leftJoin(DB::raw('(SELECT CodArticoloGM, SUM(Qta) as totVen FROM T_WEB_Ordini GROUP BY CodArticoloGM) o'), function ($join) { $join->on('T_WEB_Articoli.IdArticolo', '=', 'o.CodArticoloGM'); }) - ->leftJoin(DB::raw('(SELECT CodArticoloGM, SUM(Qta) as venduti3mesi, RANK() OVER (ORDER BY SUM(Qta) DESC) as rank3M + ->leftJoin(DB::raw('(SELECT CodArticoloGM, SUM(Qta) as venduti3mesi, RANK() OVER (ORDER BY SUM(Qta) DESC) as rank3M FROM T_WEB_Ordini WHERE DataOra >= DATEADD(MONTH, -3, GETDATE()) GROUP BY CodArticoloGM) p'), function ($join) { @@ -373,7 +374,7 @@ class ArticleController extends Controller } catch (\Exception $e) { // Potresti considerare di registrare l'errore per debugging return new Response('Error exporting showArticlesFatturati: ' . $e->getMessage() . - 'Articoli Fatturati ' . json_encode($articoliVenduti), 500); + 'Articoli Fatturati ' . json_encode($articoliVenduti), 500); } } @@ -588,4 +589,57 @@ class ArticleController extends Controller } + function showTableContent($tableName, $recordCount) + { + // Verifica se la tabella esiste + if (!Schema::hasTable($tableName)) { + return "La tabella '$tableName' non esiste."; + } + + // Ottieni tutti i campi della tabella + $columns = Schema::getColumnListing($tableName); + + // Recupera i record dalla tabella + $records = DB::table($tableName)->take($recordCount)->get(); + + // Se non ci sono record, restituisci un messaggio + if ($records->isEmpty()) { + return "Nessun record trovato nella tabella '$tableName'."; + } + + // Prepara l'output in formato tabellare + $output = ""; + + // Intestazioni della tabella + foreach ($columns as $column) { + $output .= ""; + } + $output .= ""; + + // Righe dei dati + foreach ($records as $record) { + $output .= ""; + foreach ($columns as $column) { + $output .= ""; + } + $output .= ""; + } + + $output .= "
$column
" . ($record->$column ?? 'NULL') . "
"; + + return $output; + } + + public function showTableByName($tableName, $numrec) + { + + // Usa la funzione showTableContent per ottenere i dati in formato tabellare + $tableContent = $this->showTableContent($tableName, $numrec); + + // Passa i dati alla vista + return view('article.info', [ + 'tableName' => $tableName, + 'tableContent' => $tableContent + ]); + } } \ No newline at end of file diff --git a/resources/views/info.blade.php b/resources/views/info.blade.php new file mode 100644 index 00000000..54f64fce --- /dev/null +++ b/resources/views/info.blade.php @@ -0,0 +1,19 @@ + + + + + + + Articoli Venduti + + + + +
+

Mostra Tabella: {{ $tableName }}

+ + {!! $tableContent !!} +
+ + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 1c9f4b04..fab29889 100644 --- a/routes/web.php +++ b/routes/web.php @@ -6476,3 +6476,4 @@ Route::get('/view-fatturati-by-idarticolo/{idarticolo}', [ArticleController::cla Route::get('/article-test', [ArticleController::class, 'test']); Route::get('/view-info-articolo/{idarticolo}', [ArticleController::class, 'showInfoArticolo']); +Route::get('/view-table/{tableName}/{numrec}', [ArticleController::class, 'showInfoArticolo']);