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