query totalevenduti
This commit is contained in:
@@ -2216,3 +2216,30 @@ function getvalstr($mystr, $value, $separato = false)
|
||||
|
||||
return $my;
|
||||
}
|
||||
|
||||
function exportArticlesSalesAction(Request $request)
|
||||
{
|
||||
$articoliVenduti = Articolo::join('Ordine', 'Articolo.idArticolo', '=', 'Ordine.codArticoloGM')
|
||||
->leftJoin('StatoProdotto as sp', function ($join) {
|
||||
$join->on('Articolo.idStatoProdotto', '=', 'sp.idStatoProdotto')
|
||||
->where('sp.dataOra', '=', DB::raw('(SELECT MAX(dataOra) FROM StatoProdotto WHERE idStatoProdotto = sp.idStatoProdotto)'));
|
||||
})
|
||||
->whereIn('sp.descrizione', ['In commercio', 'In prevendita', 'Prossima uscita'])
|
||||
->selectRaw('Articolo.idArticolo, SUM(Ordine.qta) as totaleVenduto')
|
||||
->groupBy('Articolo.idArticolo')
|
||||
->get();
|
||||
|
||||
$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,TotaleVenduto\n";
|
||||
foreach ($articoliVenduti as $articoloVenduto) {
|
||||
$csvContent .= $articoloVenduto->idArticolo . ',' . $articoloVenduto->totaleVenduto . "\n";
|
||||
}
|
||||
|
||||
$response->setContent($csvContent);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user