query($query) ; while($db->next_record()) $nomecliente = $db->f("Nome") ; $query = " select * from progclienti PC inner join programmazione P on P.idcliente = PC.idcliente and P.Anno = $anno where PC.Anno = $anno and PC.IdCliente = $idcliente and (P.Dato1 > 0 or P.Dato2) " ; list($nfor, $dfor) = $db->RecuperaDati($query) ; if ($nfor == 0) { ?>
0 OR P.Dato2 > 0) " ; list($n, $d) = $db->RecuperaDati($query) ; for ($i=0; $i<$n; $i++) { $nF = $d['Nome'][$i] ; $nP = $d['NomeProdotto'][$i] ; $idP = $d['IdProdotto'][$i] ; $arrVal[$nF]['NomeProdotto'][] = $nP ; $arrVal[$nF]['Dato1'][] = $d['Dato1'][$i] ; $arrVal[$nF]['Dato2'][] = $d['Dato2'][$i] ; /********************************************************** * Di questo prodotto (di cui conosco l'id) ci sono state * delle vendite negli anni precedenti ? **********************************************************/ $qAP = " select Anno, sum(TotBott) as TotBott, Sum(TotBottSM) as TotBottSM from ( SELECT $anno3 as Anno, SUM(D.NumCartoni * D.ConfezioniDa) as TotBott, 0 as totBottSM FROM ordini O RIGHT JOIN dettagli D on D.IdOrdine = O.IdOrdini and D.Anno = $anno3 and D.IdProdotto = $idP WHERE O.Anno = $anno3 and O.IdCliente = $idcliente UNION SELECT $anno3 as Anno, 0 as TotBott, SUM(SM.NumCartoni * SM.ConfezioniDa) as TotBottSM FROM ordini O RIGHT JOIN scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = $anno3 and SM.IdProdotto = $idP WHERE O.Anno = $anno3 and O.IdCliente = $idcliente UNION SELECT $anno2 as Anno, SUM(D.NumCartoni * D.ConfezioniDa) as TotBott, 0 as totBottSM FROM ordini O RIGHT JOIN dettagli D on D.IdOrdine = O.IdOrdini and D.Anno = $anno2 and D.IdProdotto = $idP WHERE O.Anno = $anno2 and O.IdCliente = $idcliente UNION SELECT $anno2 as Anno, 0 as TotBott, SUM(SM.NumCartoni * SM.ConfezioniDa) as TotBottSM FROM ordini O RIGHT JOIN scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = $anno2 and SM.IdProdotto = $idP WHERE O.Anno = $anno2 and O.IdCliente = $idcliente UNION SELECT $anno1 as Anno, SUM(D.NumCartoni * D.ConfezioniDa) as TotBott, 0 as totBottSM FROM ordini O RIGHT JOIN dettagli D on D.IdOrdine = O.IdOrdini and D.Anno = $anno1 and D.IdProdotto = $idP WHERE O.Anno = $anno1 and O.IdCliente = $idcliente UNION SELECT $anno1 as Anno, 0 as TotBott, SUM(SM.NumCartoni * SM.ConfezioniDa) as TotBottSM FROM ordini O RIGHT JOIN scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = $anno1 and SM.IdProdotto = $idP WHERE O.Anno = $anno1 and O.IdCliente = $idcliente ) as TT group by TT.Anno " ; list($nAP, $dAP) = $db->RecuperaDati($qAP) ; // print_r($dAP) ; exit ; for ($iAP=0; $iAP<$nAP; $iAP++) { $arrAP[$idP][$dAP['Anno'][$iAP]] = $dAP['TotBott'][$iAP] ; $arrVal[$nF]['TotBott'][$dAP['Anno'][$iAP]][] = $dAP['TotBott'][$iAP] ; $arrVal[$nF]['TotBottSM'][$dAP['Anno'][$iAP]][] = $dAP['TotBottSM'][$iAP] ; } /************************************************************** * Ma per questo cliente ci sono già state delle consegne con * questi prodotti ? ***************************************************************/ debug (0, "IDPRODOTTO = $idP") ; $qC = " Select Anno, sum(TotBottP1) as TotBottP1, sum(TotBottP2) as TotBottP2, Sum(TotBottSMP1) as TotBottSMP1, Sum(TotBottSMP2) as TotBottSMP2 from ( SELECT $anno as Anno, SUM(D.NumCartoni * D.ConfezioniDa) as TotBottP1, 0 as TotBottP2, 0 as TotBottSMP1, 0 as TotBottSMP2 FROM ordini O RIGHT JOIN dettagli D on D.IdOrdine = O.IdOrdini and D.Anno = $anno and D.IdProdotto = $idP WHERE O.Anno = $anno and O.IdCliente = $idcliente and O.DataSpedizione <= '$dataperiodo' UNION SELECT $anno as Anno, 0 as TotBottP1, SUM(D.NumCartoni * D.ConfezioniDa) as TotBottP2, 0 as TotBottSMP1, 0 as TotBottSMP2 FROM ordini O RIGHT JOIN dettagli D on D.IdOrdine = O.IdOrdini and D.Anno = $anno and D.IdProdotto = $idP WHERE O.Anno = $anno and O.IdCliente = $idcliente and O.DataSpedizione > '$dataperiodo' UNION select $anno as Anno, 0 as TotBottP1, 0 as TotBottP2, SUM(SM.NumCartoni * SM.ConfezioniDa) as TotBottSMP1, 0 as TotBottSMP2 FROM ordini O RIGHT JOIN scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = $anno and SM.IdProdotto = $idP WHERE O.Anno = $anno and O.IdCliente = $idcliente and O.DataSpedizione <= '$dataperiodo' UNION select $anno as Anno, 0 as TotBottP1, 0 as TotBottP2, 0 as TotBottSMP1, SUM(SM.NumCartoni * SM.ConfezioniDa) as TotBottSMP2 FROM ordini O RIGHT JOIN scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = $anno and SM.IdProdotto = $idP WHERE O.Anno = $anno and O.IdCliente = $idcliente and O.DataSpedizione > '$dataperiodo' ) as TT group by TT.Anno; " ; list($nC, $dC) = $db->RecuperaDati($qC) ; // print_r($dC) ; // exit ; for ($iC=0; $iC<$nC; $iC ++) { $arrVal[$nF]['TotBottP1'][] = $dC['TotBottP1'][$iC] ; $arrVal[$nF]['TotBottP2'][] = $dC['TotBottP2'][$iC] ; $arrVal[$nF]['TotBottSMP1'][] = $dC['TotBottSMP1'][$iC] ; $arrVal[$nF]['TotBottSMP2'][] = $dC['TotBottSMP2'][$iC] ; } } reset($arrVal) ; foreach($arrVal as $nomeFor => $arrValori) { ?>
 
Programmazione Consegnato
 
1° periodo 2° periodo