aa
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
@@ -10,19 +11,21 @@ use App\Article;
|
|||||||
|
|
||||||
class ArticleController extends Controller
|
class ArticleController extends Controller
|
||||||
{
|
{
|
||||||
public function exportArticlesSales(Request $request): Response // Cambiato il tipo di ritorno a Response
|
static public function queryArticlesSales()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$articoliVenduti = Article::join('T_WEB_Ordini', 'T_WEB_Articoli.idArticolo', '=', 'T_WEB_Ordini.codArticoloGM')
|
$articoliVenduti = Article::join('T_WEB_Ordini', 'T_WEB_Articoli.idArticolo', '=', 'T_WEB_Ordini.codArticoloGM')
|
||||||
->leftJoin(DB::raw('(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto
|
->leftJoin(
|
||||||
|
DB::raw('(SELECT e.IdStatoProdotto, e.Descrizione as DescrizioneStatoProdotto
|
||||||
FROM T_WEB_StatiProdotto e
|
FROM T_WEB_StatiProdotto e
|
||||||
JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1
|
JOIN (SELECT IdStatoProdotto, MAX(DataOra) as data1
|
||||||
FROM T_WEB_StatiProdotto
|
FROM T_WEB_StatiProdotto
|
||||||
GROUP BY IdStatoProdotto) c
|
GROUP BY IdStatoProdotto) c
|
||||||
ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1) f'),
|
ON e.IdStatoProdotto = c.IdStatoProdotto AND e.DataOra = c.data1) f'),
|
||||||
function ($join) {
|
function ($join) {
|
||||||
$join->on('T_WEB_Articoli.IdStatoProdotto', '=', 'f.IdStatoProdotto');
|
$join->on('T_WEB_Articoli.IdStatoProdotto', '=', 'f.IdStatoProdotto');
|
||||||
})
|
}
|
||||||
|
)
|
||||||
->whereIn('f.DescrizioneStatoProdotto', ['In commercio', 'In prevendita', 'Prossima uscita'])
|
->whereIn('f.DescrizioneStatoProdotto', ['In commercio', 'In prevendita', 'Prossima uscita'])
|
||||||
->selectRaw('T_WEB_Articoli.idArticolo, T_WEB_Articoli.Titolo, SUM(T_WEB_Ordini.qta) as totaleVenduto')
|
->selectRaw('T_WEB_Articoli.idArticolo, T_WEB_Articoli.Titolo, SUM(T_WEB_Ordini.qta) as totaleVenduto')
|
||||||
->groupBy('T_WEB_Articoli.idArticolo', 'T_WEB_Articoli.Titolo')
|
->groupBy('T_WEB_Articoli.idArticolo', 'T_WEB_Articoli.Titolo')
|
||||||
@@ -30,26 +33,47 @@ class ArticleController extends Controller
|
|||||||
->take(10)
|
->take(10)
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
// Controlla se si desidera esportare i dati in CSV
|
} catch (\Exception $e) {
|
||||||
$esporta = $request->input('esporta', false); // Utilizza un parametro dalla richiesta
|
// Potresti considerare di registrare l'errore per debugging
|
||||||
|
return new Response('Error exporting articles: ' . $e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
|
||||||
if ($esporta) {
|
return $articoliVenduti;
|
||||||
$filename = 'articoli_venduti_' . date('Y-m-d') . '.csv';
|
|
||||||
$response = new Response();
|
|
||||||
$response->headers->set('Content-Type', 'text/csv');
|
|
||||||
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
|
||||||
|
|
||||||
$csvContent = "IdArticolo,Titolo,TotaleVenduto\n";
|
}
|
||||||
foreach ($articoliVenduti as $articoloVenduto) {
|
|
||||||
$csvContent .= "{$articoloVenduto->idArticolo},{$articoloVenduto->Titolo},{$articoloVenduto->totaleVenduto}\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$response->setContent($csvContent);
|
public function showArticlesSales(Request $request): View
|
||||||
return $response;
|
{
|
||||||
} else {
|
try {
|
||||||
return view('export_articles_sales', ['articoliVenduti' => $articoliVenduti]);
|
|
||||||
|
$articoliVenduti = ArticleController::queryArticlesSales();
|
||||||
|
|
||||||
|
return view('export_articles_sales', ['articoliVenduti' => $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 {
|
||||||
|
|
||||||
|
$articoliVenduti = ArticleController::queryArticlesSales();
|
||||||
|
|
||||||
|
$filename = 'articoli_venduti_' . date('Y-m-d') . '.csv';
|
||||||
|
$response = new Response();
|
||||||
|
$response->headers->set('Content-Type', 'text/csv');
|
||||||
|
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
|
||||||
|
|
||||||
|
$csvContent = "IdArticolo,Titolo,TotaleVenduto\n";
|
||||||
|
foreach ($articoliVenduti as $articoloVenduto) {
|
||||||
|
$csvContent .= "{$articoloVenduto->idArticolo},{$articoloVenduto->Titolo},{$articoloVenduto->totaleVenduto}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$response->setContent($csvContent);
|
||||||
|
return $response;
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// Potresti considerare di registrare l'errore per debugging
|
// Potresti considerare di registrare l'errore per debugging
|
||||||
return new Response('Error exporting articles: ' . $e->getMessage(), 500);
|
return new Response('Error exporting articles: ' . $e->getMessage(), 500);
|
||||||
|
|||||||
@@ -6404,3 +6404,5 @@ Route::get('/handle-article-action-pao/{id}/{action}', function ($id, $action) {
|
|||||||
Route::get('/product/{sku}', [TestPaoController::class, 'getProductBySku']);
|
Route::get('/product/{sku}', [TestPaoController::class, 'getProductBySku']);
|
||||||
|
|
||||||
Route::get('/export-articles-sales', [ArticleController::class, 'exportArticlesSales']);
|
Route::get('/export-articles-sales', [ArticleController::class, 'exportArticlesSales']);
|
||||||
|
|
||||||
|
Route::get('/view-articles-sales', [ArticleController::class, 'showArticlesSales']);
|
||||||
|
|||||||
Reference in New Issue
Block a user