$giorno $mesevis per i prodotti del Fornitore $nomeFornitore" ; $where_ag = "and 1" ; $where_age = "and 1" ; $where_cl = "and 1" ; $where_fo = "and 1" ; $where_pro = "and 1" ; debug (0, "IDAGENTE = $idAgente ; $nomeAgente -- $idCliente; $nomeCliente") ; if ($idAgente != 0 and $idAgente != 'tutti') { $where_ag = " and O.idagente = $idAgente" ; $where_age = " and A.idagenti = $idAgente" ; } debug (0, "$where_ag, $where_cl, $where_fo") ; if ($profilo == 3) { $where_ag .= " and O.idagente != 4 and O.idagente != 5 and O.idagente != 9 and O.idagente != 10" ; $where_age .= " and A.idagenti != 4 and A.idagenti != 5 and A.idagenti != 9 and A.idagenti != 10" ; } else { $where_age .= " and 1" ; } if ($idCliente != 0 and $idCliente != 'tutti') $where_cl = " and O.idcliente = $idCliente" ; if ($nomeFornitore != '' and $nomeFornitore != 'tutti') $where_fo = " and O.idfornitore = $idFornitore" ; if ($prodotto != '') $where_pro = " and P.nome like '%$prodotto%'" ; debug (0, "$where_age, $where_cl, $where_fo") ; /******************************************************************************** * Fab 6.10.2011: mi calcolo il totale dei clienti che hanno movimentato un certo * fornitore (o un certo articolo di un fornitore) *********************************************************************************/ $qnumClienti = " select distinct count(*) as NumeroOrdiniSingoloCliente, C.Nome from ordini O inner join clienti C on O.idcliente = C.idclienti inner join dettagli D on D.idordine = O.idordini and D.Anno = $anno inner join prodotti P on P.idprodotti = D.idprodotto where P.Anno = $anno and O.Anno = $anno $where_pro $where_ag $where_cl $where_fo group by C.Nome " ; list ($nNumCli, $arrNumCli) = $db->RecuperaDati($qnumClienti) ; $totClienti = count($arrNumCli['Nome']) ; debug (0, "$totClienti") ; /********************************************************************************* * per il calcolo del totale dei prodotti venduti e dei prodotti in sconto merce *********************************************************************************/ $qtot = " select sum(TT.TotBottAnnoPrecedente) as TotoAnnoPrec, sum(TT.TotBottAnnoPrecedenteSM) as TotoAnnoPrecSM, sum(TT.TotBottAnnoInCorso) as TotoAnnoInCorso, sum(TT.TotBottAnnoInCorsoSM) as TotoAnnoInCorsoSM from (select 0 as TotBottAnnoPrecedente, 0 as TotBottAnnoPrecedenteSM, sum(D.NumCartoni * D.ConfezioniDa) as TotBottAnnoInCorso, 0 as TotBottAnnoInCorsoSM from dettagli D inner join ordini O on O.idordini = D.idordine and O.Anno = $anno and O.idfornitore = $idFornitore and O.DataOrdine <= '$dataOrdineAnnoInCorso' inner join clienti C on C.IdClienti = O.IdCliente $where_cl inner join agenti A on A.IdAgenti = C.IdAgente $where_age inner join prodotti P on P.idprodotti = D.idprodotto $where_pro where P.Anno = $anno and D.Anno = $anno union select 0 as TotBottAnnoPrecedente, 0 as TotBottAnnoPrecedenteSM, 0 as TotBottAnnoInCorso, sum(D.NumCartoni * D.ConfezioniDa) as TotBottAnnoInCorsoSM from scontomerce D inner join ordini O on O.idordini = D.idordine and O.Anno = $anno and O.idfornitore = $idFornitore and O.DataOrdine <= '$dataOrdineAnnoInCorso' inner join clienti C on C.IdClienti = O.IdCliente $where_cl inner join agenti A on A.IdAgenti = C.IdAgente $where_age inner join prodotti P on P.idprodotti = D.idprodotto $where_pro where P.Anno = $anno and D.Anno = $anno union select sum(D.NumCartoni * D.ConfezioniDa) as TotBottAnnoPrecedente, 0 as TotBottAnnoPrecedenteSM, 0 as TotBottAnnoInCorso, 0 as TotBottAnnoInCorsoSM from dettagli D inner join ordini O on O.idordini = D.idordine and O.Anno = $anno_prec and O.idfornitore = $idFornitore and O.DataOrdine <= '$dataOrdineAnnoPrec' inner join clienti C on C.IdClienti = O.IdCliente $where_cl inner join agenti A on A.IdAgenti = C.IdAgente $where_age inner join prodotti P on P.idprodotti = D.idprodotto $where_pro where P.Anno = $anno_prec and D.Anno = $anno_prec union select 0 as TotBottAnnoPrecedente, sum(D.NumCartoni * D.ConfezioniDa) as TotBottAnnoPrecedenteSM, 0 as TotBottAnnoInCorso, 0 as TotBottAnnoInCorsoSM from scontomerce D inner join ordini O on O.idordini = D.idordine and O.Anno = $anno_prec and O.idfornitore = $idFornitore and O.DataOrdine <= '$dataOrdineAnnoPrec' inner join clienti C on C.IdClienti = O.IdCliente $where_cl inner join agenti A on A.IdAgenti = C.IdAgente $where_age inner join prodotti P on P.idprodotti = D.idprodotto $where_pro where P.Anno = $anno_prec and D.Anno = $anno_prec ) as TT " ; debug (0, $qtot) ; list ($nt, $d) = $db->RecuperaDati($qtot) ; $TotoAnnoPrec = nfl($d['TotoAnnoPrec'][0]) ; $TotoAnnoPrecSM = nfl($d['TotoAnnoPrecSM'][0]) ; $TotoAnnoInCorso = nfl($d['TotoAnnoInCorso'][0]) ; $TotoAnnoInCorsoSM = nfl($d['TotoAnnoInCorsoSM'][0]) ; debug (0, $TotoAnnoInCorsoSM) ; if ($TotoAnnoPrecSM > 0) $TotoAnnoPrec = nfl($d['TotoAnnoPrec'][0]) . " ($TotoAnnoPrecSM)" ; if ($TotoAnnoInCorsoSM > 0) $TotoAnnoInCorso = nfl($d['TotoAnnoInCorso'][0]) . " ($TotoAnnoInCorsoSM)" ; $TotDifferenza = nfl($d['TotoAnnoInCorso'][0] - $d['TotoAnnoPrec'][0]) ; // $TotPercSM = nfp($d['TotBottSM'][0] / ($d['TotBottV'][0] + $d['TotBottSM'][0]) * 100) ; $arrAgenti = array() ; $arrClienti = array() ; $qf = " select distinct O.IdAgente, A.Nome as NomeAgente, O.IdCliente, C.Nome as NomeCliente, O.IdOrdini from ordini O inner join agenti A on A.IdAgenti = O.IdAgente $where_age inner join clienti C on C.IdClienti = O.IdCliente where O.Anno = $anno_prec and O.DataOrdine <= '$dataOrdineAnnoPrec' and O.IdFornitore = $idFornitore union select distinct O.IdAgente, A.Nome as NomeAgente, O.IdCliente, C.Nome as NomeCliente, O.IdOrdini from ordini O inner join agenti A on A.IdAgenti = O.IdAgente $where_age inner join clienti C on C.IdClienti = O.IdCliente where O.Anno = $anno and O.DataOrdine <= '$dataOrdineAnnoInCorso' and O.IdFornitore = $idFornitore " ; list($n, $d) = $db->RecuperaDati($qf) ; for ($i=0; $i<$n; $i++) { if (!@array_key_exists($d['IdAgente'][$i], $arrAgenti)) $arrAgenti[$d['IdAgente'][$i]] = $d["NomeAgente"][$i] ; if (!@array_key_exists($d['IdCliente'][$i], $arrClienti)) $arrClienti[$d['IdCliente'][$i]] = $d["NomeCliente"][$i] ; } @asort($arrAgenti) ; @asort($arrClienti) ; $header = "AGENTE,CLIENTE,PRODOTTO,Anno $anno_prec,Anno $anno,Diff" ; $label = explode(",", $header) ; $attHeaderStyle = "background-color:#ffffaa;border-bottom:1px solid silver;padding:2px 2px 0px 2px" ; $attH = "
,
,
, , , " ; $attHS = "$attHeaderStyle,$attHeaderStyle,$attHeaderStyle,$attHeaderStyle,$attHeaderStyle,$attHeaderStyle" ; $footer = "TOTALI PARZIALI:-#cspan-#cspan-
-
-
" ; $strSort = "str,,str,str,int,int,int" ; $iniWP = "18,31,31,7,7,5" ; $setColType = "ro,ro,ro,ro,ro,ro" ; $setColAlign = "left,left,left,center,center,center" ; /******************************************************************************* * controllo se devo eseguire degli ordinamenti e qual č la colonna da ordinare *******************************************************************************/ if (! isset($colToSort) or $colToSort == '') $colToSort = 1 ; if (! isset($direction) or $direction == '') $direction = "ASC" ; $strLoadXml = "LoadConfrontoClientiBottiglieAcquistate.php?gime=$gime&ordinaper=$colToSort&direction=$direction" ; /****************************************************************** * controllo se provengo da una operazione di filtraggio. Questo si * verifica quando rag_sociale vale qualcosa ******************************************************************/ if ($idAgente != 0) $strLoadXml .= "&selage=$idAgente" ; if ($idCliente != 0) $strLoadXml .= "&selcli=$idCliente" ; $strLoadXml .= "&selfor=$idFornitore" ; if ($prodotto != '') $strLoadXml .= "&selpro=$prodotto" ; debug (0, "idCliente = $idCliente -- $strLoadXml") ; ?> New Document

(Fra parentesi il numero delle bottiglie in sconto merce)