aaa
This commit is contained in:
@@ -250,6 +250,82 @@ class ArticleController extends Controller
|
||||
|
||||
return $articoliVenduti;
|
||||
|
||||
}
|
||||
private function queryArticlesFatturati()
|
||||
{
|
||||
try {
|
||||
ini_set("memory_limit", "512M");
|
||||
|
||||
$articoliVenduti = Article::join(DB::raw('(SELECT IdArticolo, MAX(DataOra) AS data FROM T_WEB_Articoli GROUP BY IdArticolo) b'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdArticolo', '=', 'b.IdArticolo')
|
||||
->on('T_WEB_Articoli.DataOra', '=', 'b.data');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto FROM T_WEB_StatiProdotto e JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1 from T_WEB_StatiProdotto GROUP BY IdStatoProdotto) c ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1 ) f'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdStatoProdotto', '=', 'f.IdStatoProdotto');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT g.IdTipologia, g.Descrizione as DescrizioneTipologia FROM T_WEB_Tipologie g JOIN (SELECT IdTipologia, MAX(DataOra) as data1 from T_WEB_Tipologie GROUP BY IdTipologia) h ON g.IdTipologia = h.IdTipologia AND g.DataOra = h.data1 ) i'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdTipologia', '=', 'i.IdTipologia');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT l.IdTipoFormato, l.Descrizione as DescrizioneFormato FROM T_WEB_TipiFormato l JOIN (SELECT IdTipoFormato, MAX(DataOra) as data1 from T_WEB_TipiFormato GROUP BY IdTipoFormato) m ON l.IdTipoFormato = m.IdTipoFormato AND l.DataOra = m.data1 ) n'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdTipoFormato', '=', 'n.IdTipoFormato');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT CodArticolo, SUM(Qta) as totVen FROM T_WEB_ArticoliFatturati GROUP BY CodArticolo) o'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdArticolo', '=', 'o.CodArticolo');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT CodArticoloGM, SUM(Qta) as venduti3mesi, RANK() OVER (ORDER BY SUM(Qta) DESC) as rank3M
|
||||
FROM T_WEB_ArticoliFatturati
|
||||
WHERE DataOra >= DATEADD(MONTH, -3, GETDATE())
|
||||
GROUP BY CodArticolo) p'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdArticolo', '=', 'p.CodArticolo');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT CodArticolo, SUM(Qta) as venduti6mesi, RANK() OVER (ORDER BY SUM(Qta) DESC) as rank6M
|
||||
FROM T_WEB_ArticoliFatturati
|
||||
WHERE DataOra >= DATEADD(MONTH, -6, GETDATE())
|
||||
GROUP BY CodArticolo) q'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdArticolo', '=', 'q.CodArticolo');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT CodArticolo, SUM(Qta) as venduti1anno, RANK() OVER (ORDER BY SUM(Qta) DESC) as rank1Y
|
||||
FROM T_WEB_ArticoliFatturati
|
||||
WHERE DataOra >= DATEADD(MONTH, -12, GETDATE())
|
||||
GROUP BY CodArticolo) r'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdArticolo', '=', 'r.CodArticolo');
|
||||
})
|
||||
->leftJoin(DB::raw('(SELECT CodArticolo, MAX(DataOra) as ultimoOrdine
|
||||
FROM T_WEB_ArticoliFatturati
|
||||
GROUP BY CodArticolo) s'), function ($join) {
|
||||
$join->on('T_WEB_Articoli.IdArticolo', '=', 's.CodArticolo');
|
||||
})
|
||||
->select(
|
||||
'T_WEB_Articoli.*',
|
||||
'f.DescrizioneStatoProdotto',
|
||||
'i.DescrizioneTipologia',
|
||||
'n.DescrizioneFormato',
|
||||
DB::raw('COALESCE(o.totVen, 0) as totVen'),
|
||||
DB::raw('COALESCE(p.venduti3mesi, 0) as venduti3mesi'),
|
||||
DB::raw('COALESCE(p.rank3M, 0) as rank3M'),
|
||||
DB::raw('COALESCE(q.venduti6mesi, 0) as venduti6mesi'),
|
||||
DB::raw('COALESCE(q.rank6M, 0) as rank6M'),
|
||||
DB::raw('COALESCE(r.venduti1anno, 0) as venduti1anno'),
|
||||
DB::raw('COALESCE(r.rank1Y, 0) as rank1Y'),
|
||||
DB::raw('s.ultimoOrdine')
|
||||
)
|
||||
->where('DescrizioneStatoProdotto', 'In commercio')
|
||||
->where('DescrizioneTipologia', 'Libri')
|
||||
//->orderBy('rank1Y', 'asc')
|
||||
->orderBy('totVen', 'desc')
|
||||
->get();
|
||||
|
||||
if ($articoliVenduti->isEmpty()) {
|
||||
return response()->json(['message' => 'Nessun articolo fatturato trovato.'], 404);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Registrazione dell'errore
|
||||
return response()->json(['error' => 'Si è verificato un errore durante il recupero dei dati: ' . $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $articoliVenduti;
|
||||
|
||||
}
|
||||
|
||||
public function showArticlesSales(Request $request)
|
||||
@@ -266,6 +342,20 @@ class ArticleController extends Controller
|
||||
|
||||
}
|
||||
}
|
||||
public function showArticlesFatturati(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$articoliVenduti = $this->queryArticlesFatturati();
|
||||
|
||||
return view('export_articles_fatturati', ['articoliVenduti' => $articoliVenduti]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Potresti considerare di registrare l'errore per debugging
|
||||
return new Response('Error exporting articles: ' . $e->getMessage(), 500);
|
||||
|
||||
}
|
||||
}
|
||||
public function showArticoliByDataStart($data_start)
|
||||
{
|
||||
try {
|
||||
@@ -384,11 +474,14 @@ class ArticleController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function exportArticlesSalesByJSON(Request $request): Response
|
||||
public function exportArticlesSalesByJSON_Base($cosa, Request $request): Response
|
||||
{
|
||||
try {
|
||||
// Recupera gli articoli venduti
|
||||
$articoliVenduti = $this->queryArticlesSales();
|
||||
if ($cosa === 'fatturati') {
|
||||
$articoliVenduti = $this->queryArticlesFatturati();
|
||||
} else {
|
||||
$articoliVenduti = $this->queryArticlesSales();
|
||||
}
|
||||
|
||||
// Mappa i risultati nella struttura JSON desiderata
|
||||
$result = $articoliVenduti->map(function ($articoloVenduto) {
|
||||
@@ -423,6 +516,16 @@ class ArticleController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function exportArticlesSalesByJSON(Request $request): Response
|
||||
{
|
||||
return $this->exportArticlesSalesByJSON_Base('', $request);
|
||||
}
|
||||
|
||||
public function exportArticlesFatturatiByJSON(Request $request): Response
|
||||
{
|
||||
return $this->exportArticlesSalesByJSON_Base('fatturati', $request);
|
||||
}
|
||||
|
||||
public function test(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
111
resources/views/export_articles_fatturati.blade.php
Normal file
111
resources/views/export_articles_fatturati.blade.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Articoli Fatturati</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 class="mb-4">Articoli Fatturati</h1>
|
||||
<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/export-articles-fatturati-json" target="_blank">EXPORT FATTURATI</a>
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id Articolo</th>
|
||||
<th>Titolo</th>
|
||||
<th>Data Pubbl</th>
|
||||
<th>ISBN</th>
|
||||
<th>Pagine</th>
|
||||
<th>Misure</th>
|
||||
<th>Rank 3 M</th>
|
||||
<th>Rank 6 M</th>
|
||||
<th>Rank 1 Y</th>
|
||||
<th>Ult Ordi</th>
|
||||
<th>Tot Venduti</th>
|
||||
<th>Ult 3 Mese</th>
|
||||
<th>Ult 6 Mesi</th>
|
||||
<th>Ult Anno</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<!--<pre>{{ print_r($articoliVenduti, true) }}</pre>-->
|
||||
|
||||
@if ($articoliVenduti->isEmpty())
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">Nessun articolo fatturato trovato.</td>
|
||||
</tr>
|
||||
@else
|
||||
@foreach ($articoliVenduti as $articolo)
|
||||
@if (isset($articolo->Ean13))
|
||||
<tr>
|
||||
|
||||
<td>@if (isset($articolo->IdArticolo))
|
||||
<a href="/apimacro/public/view-info-articolo/{{$articolo->IdArticolo}}"
|
||||
target="_blank">{{ $articolo->IdArticolo }}</a>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
|
||||
<td>@if (isset($articolo->Titolo)){{ $articolo->Titolo }}@endif</td>
|
||||
|
||||
<td>@if (isset($articolo->DataPubblicazione)){{ \Carbon\Carbon::parse($articolo->DataPubblicazione)->format('d/m/Y') }}@endif
|
||||
</td>
|
||||
|
||||
|
||||
<td>@if (isset($articolo->Ean13)){{ $articolo->Ean13 }}@endif</td>
|
||||
|
||||
<td>@if (isset($articolo->Pagine)){{ $articolo->Pagine }}@endif</td>
|
||||
<td>@if (isset($articolo->misure)){{ $articolo->misure }}@endif</td>
|
||||
|
||||
<td>@if (isset($articolo->rank3M))
|
||||
{{ $articolo->rank3M }}
|
||||
@endif
|
||||
</td>
|
||||
<td>@if (isset($articolo->rank6M))
|
||||
{{ $articolo->rank6M }}
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<td>@if (isset($articolo->rank1Y))
|
||||
{{ $articolo->rank1Y }}
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<td>@if (isset($articolo->ultimoOrdine)){{ \Carbon\Carbon::parse($articolo->ultimoOrdine)->format('d/m/Y') }}@endif
|
||||
</td>
|
||||
|
||||
|
||||
<td>@if (isset($articolo->totVen))
|
||||
<!--<a href="/apimacro/public/view-ordini-by-idarticolo/{{$articolo->IdArticolo}}"
|
||||
target="_blank">{{ $articolo->totVen }}</a>-->
|
||||
<a href="/apimacro/public/view-fatturati-by-idarticolo/{{$articolo->IdArticolo}}"
|
||||
target="_blank">{{ $articolo->totVen }}</a>
|
||||
@endif
|
||||
</td>
|
||||
|
||||
<td>@if (isset($articolo->venduti3mesi))
|
||||
{{ $articolo->venduti3mesi }}
|
||||
@endif
|
||||
</td>
|
||||
<td>@if (isset($articolo->venduti6mesi))
|
||||
{{ $articolo->venduti6mesi }}
|
||||
@endif
|
||||
<td>@if (isset($articolo->venduti1anno))
|
||||
{{ $articolo->venduti1anno }}
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -70,6 +70,8 @@
|
||||
<div>
|
||||
<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-articles-sales" target="_blank">Articoli
|
||||
Venduti</a><br>
|
||||
<a href="http://vps-88271abb.vps.ovh.net/apimacro/public/view-articles-sales" target="_blank">Articoli
|
||||
Venduti</a><br>
|
||||
|
||||
</div>
|
||||
<div id="result"></div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Articoli Venduti</title>
|
||||
<title>Ordini Articoli</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
</head>
|
||||
|
||||
|
||||
@@ -6464,6 +6464,8 @@ Route::get('/product/{sku}', [TestPaoController::class, 'getProductBySku']);
|
||||
|
||||
Route::get('/export-articles-sales', [ArticleController::class, 'exportArticlesSales']);
|
||||
Route::get('/export-articles-sales-json', [ArticleController::class, 'exportArticlesSalesByJSON']);
|
||||
Route::get('/export-articles-fatturati', [ArticleController::class, 'exportArticlesFatturati']);
|
||||
Route::get('/export-articles-fatturati-json', [ArticleController::class, 'exportArticlesFatturatiByJSON']);
|
||||
|
||||
Route::get('/view-articles-sales', [ArticleController::class, 'showArticlesSales']);
|
||||
Route::get('/view-lista-ordini-totale/{data_start}', [ArticleController::class, 'showArticoliByDataStart']);
|
||||
|
||||
Reference in New Issue
Block a user