view tables

This commit is contained in:
paoloar77
2024-12-20 11:31:03 +01:00
parent d707cd28e8
commit e7de0e4bea
3 changed files with 76 additions and 2 deletions

View File

@@ -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 = "<table border='1'><thead><tr>";
// Intestazioni della tabella
foreach ($columns as $column) {
$output .= "<th>$column</th>";
}
$output .= "</tr></thead><tbody>";
// Righe dei dati
foreach ($records as $record) {
$output .= "<tr>";
foreach ($columns as $column) {
$output .= "<td>" . ($record->$column ?? 'NULL') . "</td>";
}
$output .= "</tr>";
}
$output .= "</tbody></table>";
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
]);
}
}

View File

@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Articoli Venduti</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
<h1>Mostra Tabella: {{ $tableName }}</h1>
{!! $tableContent !!}
</div>
</body>
</html>

View File

@@ -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']);