This commit is contained in:
paoloar77
2024-12-07 20:57:15 +01:00
parent 2e6d4b7251
commit 7162958252
3 changed files with 52 additions and 1 deletions

View File

@@ -11,6 +11,16 @@ use App\Article;
class ArticleController extends Controller
{
private function queryTest(){
$articoli = DB::table('T_WEB_Articoli as A')
->leftJoin(DB::raw('(SELECT CodArticoloGM, SUM(Qta) as totaleVenduti FROM T_WEB_Ordini GROUP BY CodArticoloGM) O'), 'A.IdArticolo', '=', 'O.CodArticoloGM')
->select('A.IdArticolo', 'A.Descrizione', DB::raw('COALESCE(O.totaleVenduti, 0) as totaleVenduti'))
->orderBy('totaleVenduti', 'desc')
->get();
return $articoli;
}
private function queryArticlesSales()
{
try {
@@ -69,7 +79,8 @@ class ArticleController extends Controller
)
->where('DescrizioneStatoProdotto', 'In commercio')
->where('DescrizioneTipologia', 'Libri')
->orderBy('rank1Y', 'asc')
//->orderBy('rank1Y', 'asc')
->orderBy('totaleVenduti', 'desc')
->get();
if ($articoliVenduti->isEmpty()) {
@@ -99,6 +110,20 @@ class ArticleController extends Controller
}
}
public function showtest(Request $request)
{
try {
$articoliVenduti = $this->queryTest();
return view('export_articles_test', ['articoli' => $articoliVenduti]);
} catch (\Exception $e) {
// Potresti considerare di registrare l'errore per debugging
return new Response('Error exporting articles: ' . $e->getMessage(), 500);
}
}
public function exportArticlesSales(Request $request): Response
{
try {

View File

@@ -0,0 +1,25 @@
@extends('layouts.app')
@section('content')
<div class="container">
<h1>Totale Vendite per Articolo</h1>
<table class="table table-striped">
<thead>
<tr>
<th>ID Articolo</th>
<th>Descrizione</th>
<th>Totale Venduti</th>
</tr>
</thead>
<tbody>
@foreach($articoliVenduti as $articolo)
<tr>
<td>{{ $articolo->IdArticolo }}</td>
<td>{{ $articolo->Descrizione }}</td>
<td>{{ number_format($articolo->totaleVenduti, 0, ',', '.') }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection

View File

@@ -6466,4 +6466,5 @@ Route::get('/export-articles-sales', [ArticleController::class, 'exportArticlesS
Route::get('/export-articles-sales-json', [ArticleController::class, 'exportArticlesSalesByJSON']);
Route::get('/view-articles-sales', [ArticleController::class, 'showArticlesSales']);
Route::get('/view-articles-test', [ArticleController::class, 'showtest']);
Route::get('/article-test', [ArticleController::class, 'test']);