"); $dbtot = new FC_SQL ; $log = false ; if ($log) $handle = fopen('log_LoadListaClientiProdotti.txt', 'a+') ; $posStart = $_GET['posStart'] ; $count = $_GET['count'] ; if ($log) { fwrite($handle, "posStart = " . $posStart . "\n") ; fwrite($handle, "count = " . $count . "\n") ; } /*************************************************************************** * where-list ***************************************************************************/ $selAge = $_GET["selage"] ; $selCli = $_GET["selcli"] ; $selFor = $_GET["selfor"] ; $selPro = $_GET["selpro"] ; $ordinaper = $_GET["ordinaper"] ; $direction = $_GET["direction"] ; $where_cli = "1=1" ; $where_age = "1=1" ; $where_for_no_sarzi = "F.IdFornitori != $idsarzi" ; $where_for_sarzi = "F.IdFornitori = $idsarzi" ; $where_pro = "1=1" ; /************************* * filtro Agente **************************/ if (isset($selAge) and ($selAge != 'tutti')) $where_age = " A.IdAgenti = $selAge" ; if ($profilo == 3) $where_age .= " and A.idagenti != 4 and A.idagenti != 5 and A.idagenti != 9 and A.idagenti != 10" ; else $where_age .= " and 1=1" ; /************************* * filtro Cliente **************************/ if (isset($selCli) and ($selCli != 'tutti')) $where_cli = " C.idclienti = '$selCli'" ; /************************* * filtro Fornitori **************************/ if (isset($selFor) and ($selFor != 'tutti')) { if ($selFor != $idsarzi) { $where_for_no_sarzi = "F.IdFornitori = $selFor" ; $where_for_sarzi = "F.IdFornitori = -21" ; } else { $where_for_no_sarzi = "F.IdFornitori = -21" ; $where_for_sarzi = "F.IdFornitori = $selFor" ; } } /************************* * filtro Prodotto **************************/ if (isset($selPro) and ($selPro != '')) $where_pro = " D.DescDettaglio like '%$selPro%'" ; /*************************************** * controllo la colonna da ordinare ***************************************/ switch($ordinaper) { case 0: // agente $order_by = "NomeAgente $direction, NomeProdotto" ; break ; case 1: // cliente $order_by = "NomeCliente $direction, NomeProdotto" ; break ; case 2: // fornitore $order_by = "NomeFornitore $direction, NomeProdotto" ; break ; case 3: // prodotto $order_by = "NomeProdotto $direction, NomeCliente" ; break ; case 4: // numero prodotti totali $order_by = "NumBottTot $direction, NomeProdotto" ; break ; case 5: // numero prodotti venduti $order_by = "NumBottVend $direction, NomeProdotto" ; break ; case 6: // numero prodotti in sconto merce $order_by = "NumBottSM $direction, NomeProdotto" ; break ; case 7: // Percentuale Sconto Merce $order_by = "PercSM $direction, NomeProdotto" ; break ; } $qclipro = " select TT.IdAgente, TT.NomeAgente, TT.IdCliente, TT.NomeCliente, TT.IdFornitore, TT.NomeFornitore, TT.NomeProdotto, -- TT.IdProdotto, sum(TT.NumBottVend) + sum(TT.NumBottSM) as NumBottTot, sum(TT.NumBottVend) as NumBottVend, sum(TT.NumBottSM) as NumBottSM, (sum(TT.NumBottSM) / (sum(TT.NumBottVend) + sum(TT.NumBottSM))) * 100 as PercSM from ( select A.idagenti as IdAgente, A.nome as NomeAgente, C.idclienti as IdCliente, C.nome as NomeCliente, F.idfornitori as IdFornitore, F.nome as NomeFornitore, D.DescDettaglio as NomeProdotto, -- D.idprodotto as IdProdotto, (D.NumCartoni * D.ConfezioniDa) as NumBottVend, 0 as NumBottSM from agenti A inner join ordini O on O.idagente = A.idagenti and O.Anno = $anno inner join clienti C on C.idclienti = O.idcliente and $where_cli inner join fornitori F on F.idfornitori = O.idfornitore and $where_for_no_sarzi inner join dettagli D on D.idordine = O.idordini and D.Anno = $anno and $where_pro where $where_age union all select A.idagenti as IdAgente, A.nome as NomeAgente, C.idclienti as IdCliente, C.nome as NomeCliente, F.idfornitori as IdFornitore, F.nome as NomeFornitore, P.nome as NomeProdotto, -- P.idprodotti as IdProdotto, (D.NumCartoni * D.ConfezioniDa) as NumBottVend, 0 as NumBottSM from agenti A inner join ordini O on O.idagente = A.idagenti and O.Anno = $anno inner join clienti C on C.idclienti = O.idcliente and $where_cli inner join fornitori F on F.idfornitori = O.idfornitore and $where_for_sarzi inner join dettagli D on D.idordine = O.idordini and D.Anno = $anno inner join sarzi P on P.idprodotti = SUBSTRING(D.idprodotto,3) and $where_pro where $where_age union all select A.idagenti as IdAgente, A.nome as NomeAgente, C.idclienti as IdCliente, C.nome as NomeCliente, F.idfornitori as IdFornitore, F.nome as NomeFornitore, D.DescDettaglio as NomeProdotto, -- D.idprodotto as IdProdotto, 0 as NumBottVend, (D.NumCartoni * D.ConfezioniDa) as NumBottSM from agenti A inner join ordini O on O.idagente = A.idagenti and O.Anno = $anno inner join clienti C on C.idclienti = O.idcliente and $where_cli inner join fornitori F on F.idfornitori = O.idfornitore and $where_for_no_sarzi inner join scontomerce D on D.idordine = O.idordini and D.Anno = $anno and $where_pro where $where_age union all select A.idagenti as IdAgente, A.nome as NomeAgente, C.idclienti as IdCliente, C.nome as NomeCliente, F.idfornitori as IdFornitore, F.nome as NomeFornitore, P.nome as NomeProdotto, -- P.idprodotti as IdProdotto, 0 as NumBottVend, (D.NumCartoni * D.ConfezioniDa) as NumBottSM from agenti A inner join ordini O on O.idagente = A.idagenti and O.Anno = $anno inner join clienti C on C.idclienti = O.idcliente and $where_cli inner join fornitori F on F.idfornitori = O.idfornitore and $where_for_sarzi inner join scontomerce D on D.idordine = O.idordini and D.Anno = $anno inner join sarzi P on P.idprodotti = SUBSTRING(D.idprodotto,3) and $where_pro where $where_age ) as TT group by TT.IdAgente, TT.NomeAgente, TT.IdCliente, TT.NomeCliente, TT.IdFornitore, TT.NomeFornitore, TT.NomeProdotto -- TT.IdProdotto order by $order_by " ; if ($log) fwrite($handle, "$qclipro \n") ; list($nrowsdati, $dati) = $db->RecuperaDati($qclipro) ; if ($log) fwrite($handle, "\n") ; print("") ; $arrClienti = array() ; for ($i = 0; $i < $nrowsdati ; $i++ ) { $idagente = $dati['IdAgente'][$i] ; $idcliente = $dati['IdCliente'][$i] ; $idfornitore = $dati['IdFornitore'][$i] ; $idprodotto = $dati['IdProdotto'][$i] ; $nomeagente = htmlspecialchars($dati['NomeAgente'][$i]) ; $nomecliente = htmlspecialchars($dati['NomeCliente'][$i]) ; $nomefornitore = htmlspecialchars($dati['NomeFornitore'][$i]) ; if ($dati['DescDettaglio'][$i] == "") $nomeprodotto = htmlspecialchars($dati['NomeProdotto'][$i]) ; else $nomeprodotto = htmlspecialchars($dati['DescDettaglio'][$i]) ; $numbottvend = nfl($dati['NumBottVend'][$i]) ; $numbottSM = nfl($dati['NumBottSM'][$i]) ; $numBottTot = nfl($dati['NumBottTot'][$i]) ; $percSM = nfp($dati['PercSM'][$i]) ; if ($log) fwrite($handle, "$nomeagente$nomecliente$nomefornitore$nomeprodotto$numbottvend$numbottSM\n") ; print ("$nomeagente$nomecliente$nomefornitore$nomeprodotto$numBottTot$numbottvend$numbottSM$percSM") ; } print ("") ; if ($log) fclose($handle) ; ?>