"); $log = false ; if ($log) $handle = fopen('log_LoadListaProdottiBottiglieVendute.txt', 'a+') ; $posStart = $_GET['posStart'] ; $count = $_GET['count'] ; if ($log) { fwrite($handle, "posStart = " . $posStart . "\n") ; fwrite($handle, "count = " . $count . "\n") ; } /*************************************************************************** * where-list ***************************************************************************/ $nomeProdotto = $_GET["nomeProdotto"] ; $idFornitore = $_GET["idFornitore"] ; $ordinaper = $_GET["ordinaper"] ; $direction = $_GET["direction"] ; $where = "1=1" ; /************************* * filtro Fornitori **************************/ if (isset($idFornitore) and ($idFornitore != 'tutti') and ($idFornitore != '')) $where .= " and F.IdFornitori = $idFornitore" ; /************************* * filtro Nome Prodotto **************************/ if (isset($nomeProdotto) and ($nomeProdotto != '')) $where .= " and P.Nome like '" . "%$nomeProdotto%" . "'" ; /*************************************** * controllo la colonna da ordinare ***************************************/ switch($ordinaper) { case 0: // codice - nome Prodotto $orderBy = "NomeProdotto $direction" ; break ; case 1: // numero fornitore $orderBy = "NomeFornitore $direction, NomeProdotto" ; break ; case 3: // numero bottiglie vendute $orderBy = "NumBottV $direction, NomeProdotto" ; break ; case 4: // numero bottiglie sconto merce $orderBy = "NumBottSM $direction, NomeProdotto" ; break ; default: $orderBy = "NomeProdotto $direction" ; break ; } $arrIdProdotti = array() ; $arrProdotti = array() ; $arrFornitori = array() ; $arrTotali = array() ; $arrVenduto = array() ; $arrSM = array() ; /********************************************************************** * Questa query terrebbe conto anche della descrizione del dettaglio * degli ordini ********************************************************************** $query = " select TT.IdProdotto, TT.CodiceProdotto, TT.NomeProdotto, TT.DescDettaglio, TT.IdFornitori, TT.NomeFornitore, sum(TT.NumTotBottV) as NumBottV, sum(TT.NumTotBottSM) as NumBottSM from (select P.idprodotti as IdProdotto, P.CodiceProdotto, case when (P.Annata <> '') then CONCAT(P.nome, ' - ',P.Annata) else P.nome end as NomeProdotto, D.DescDettaglio, (D.NumCartoni * D.ConfezioniDa) as NumTotBottV, 0 as NumTotBottSM, F.IdFornitori, F.nome as NomeFornitore from prodotti P inner join dettagli D on D.idprodotto = P.idprodotti and D.Anno = $anno inner join ordini O on O.IdOrdini = D.IdOrdine and O.Anno = $anno inner join fornitori F on F.IdFornitori = P.Fornitore where $where union all select P.idprodotti as IdProdotto, P.CodiceProdotto, case when (P.Annata <> '') then CONCAT(P.nome, ' - ',P.Annata) else P.nome end as NomeProdotto, D.DescDettaglio, 0 as NumTotBottV, (D.NumCartoni * D.ConfezioniDa) as NumTotBottSM, F.IdFornitori, F.nome as NomeFornitore from prodotti P inner join scontomerce D on D.idprodotto = P.idprodotti and D.Anno = $anno inner join ordini O on O.IdOrdini = D.IdOrdine and O.Anno = $anno inner join fornitori F on F.IdFornitori = P.Fornitore where $where ) as TT group by IdProdotto, CodiceProdotto, NomeProdotto, DescDettaglio, IdFornitori, NomeFornitore order by $orderBy " ; */ /************************************************************************ * 14.10.2022: adesso la lista viene raggrupata per la descrizione del * prodotto presente nella tabella dettagli **************************************************************************/ $query = " select TT.IdProdotto, TT.NomeProdotto, TT.IdFornitori, TT.NomeFornitore, sum(TT.NumTotBottV) as NumBottV, sum(TT.NumTotBottSM) as NumBottSM from (select D.IdProdotto, D.DescDettaglio as NomeProdotto, (D.NumCartoni * D.ConfezioniDa) as NumTotBottV, 0 as NumTotBottSM, F.IdFornitori, F.nome as NomeFornitore from prodotti P inner join dettagli D on D.idprodotto = P.idprodotti and D.Anno = $anno inner join ordini O on O.IdOrdini = D.IdOrdine and O.Anno = $anno inner join fornitori F on F.IdFornitori = P.Fornitore where $where union all select D.IdProdotto, D.DescDettaglio as NomeProdotto, 0 as NumTotBottV, (D.NumCartoni * D.ConfezioniDa) as NumTotBottSM, F.IdFornitori, F.nome as NomeFornitore from prodotti P inner join scontomerce D on D.idprodotto = P.idprodotti and D.Anno = $anno inner join ordini O on O.IdOrdini = D.IdOrdine and O.Anno = $anno inner join fornitori F on F.IdFornitori = P.Fornitore where $where ) as TT group by NomeProdotto, IdFornitori, NomeFornitore order by $orderBy " ; if ($log) fwrite($handle, "$query \n") ; list($n, $d) = $db->RecuperaDati($query) ; if ($log) fwrite($handle, "\n") ; print("") ; // $str = "" ; // $n = 10 ; for ($i = 0; $i<$n ; $i++ ) { $arrIdProdotti[] = $d['IdProdotto'][$i] ; $arrProdotti[] = htmlspecialchars($d['NomeProdotto'][$i]) ; $arrIdFornitori[] = $d['IdFornitori'][$i] ; $arrFornitori[] = htmlspecialchars($d['NomeFornitore'][$i]) ; $arrTotali[] = $d['NumBottV'][$i] + $d['NumBottSM'][$i] ; $arrVenduto[] = $d['NumBottV'][$i] ; $arrSM[] = $d['NumBottSM'][$i] ; } if ($ordinaper == 2) { if ($log) fwrite($handle, "ORDINA PER $ordinaper\n") ; if ($direction == "ASC") $orderByDir = SORT_ASC ; else $orderByDir = SORT_DESC ; // array_multisort($arrTotali, $orderByDir, $arrIdProdotti, $arrProdotti, $arrFornitori, $arrVenduto, $arrSM) ; // array_multisort($arrProdotti, $orderByDir, $arrIdProdotti, $arrTotali, $arrFornitori, $arrVenduto, $arrSM) ; array_multisort($arrProdotti, $orderByDir, $arrIdProdotti, $arrTotali, $arrIdFornitori,$arrFornitori, $arrVenduto, $arrSM) ; } @reset($arrProdotti) ; for($i=0; $i" ; $str .= "" . $arrVenduto[$i] . "" ; $str .= "" . $arrSM[$i] . "" ; $str .= "" ; if ($log) fwrite($handle, "$str\r\n") ; print ("$str") ; } print ("") ; if ($log) fclose($handle) ; ?>