"); $log = true ; if ($log) $handle = fopen('log_LoadListaProdottiBottiglieVenduteSarzi.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"] ; $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: // 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() ; $query = " select TT.IdProdotto, TT.NomeProdotto, TT.IdFornitori, TT.NomeFornitore, sum(TT.NumTotBottV) as NumBottV, sum(TT.NumTotBottSM) as NumBottSM from (select P.idprodotti as IdProdotto, P.nome as NomeProdotto, (D.NumCartoni * D.ConfezioniDa) as NumTotBottV, 0 as NumTotBottSM, F.IdFornitori, F.nome as NomeFornitore from $tsarzi P inner join $tdettagli D on D.idprodotto = CONCAT('SA', P.idprodotti), $tfornitori F where F.idfornitori = $idsarzi and $where union all select P.idprodotti as IdProdotto, P.nome as NomeProdotto, 0 as NumTotBottV, (D.NumCartoni * D.ConfezioniDa) as NumTotBottSM, F.IdFornitori, F.nome as NomeFornitore from $tsarzi P inner join $tscontomerce D on D.idprodotto = CONCAT('SA', P.idprodotti), $tfornitori F where F.idfornitori = $idsarzi and $where ) as TT group by IdProdotto, 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]) ; $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) ; } @reset($arrIdProdotti) ; for($i=0; $i") ; if ($log) fclose($handle) ; ?>