query($query) ; while($db->next_record()) $nomecliente = stripslashes($db->f("Nome")) ; for ($i=0; $iquery($query) ; while($db->next_record()) { $datiforniid[] = $id ; $datiforninome[] = $db->f("Nome") ; } } @array_multisort($datiforninome, SORT_STRING, SORT_ASC, $datiforniid) ; $arrayDati = array() ; $arrayCons = array() ; ?> <? echo TITLE ?>
query($query) ; if ($db->num_rows() == 0) { /******************************************************************** * programmazione non ancora definita per cui la inizializzo a zero * NON PIU' ********** * repupero i prodotti di questo fornitore *********************************************************************/ /* $qprod = " select P.* from prodotti P where P.fornitore = $idforni and P.attivo = 'Y' " ; $dbprod->query($qprod) ; while($dbprod->next_record()) { $idpro = $dbprod->f("IdProdotti") ; $qprog = " insert into programmazione (Anno, idcliente, idprodotto, dato1, dato2) VALUES ($anno, $idcliente, $idpro, 0, 0) " ; $dbprog->query($qprog) ; } $query = "insert into progclienti (Anno, idcliente, idfornitore) VALUES ($anno, $idcliente, $idforni)" ; $db->query($query) ; */ } // fine if else { $proGiaDefinita = true ; /******************************************************** * Programmazione già inserita, per cui vado a recuperare * i valori definiti precedentemente *********************************************************/ $qpg = " select distinct P.IdProdotti, PROG.Dato1, PROG.Dato2 from progclienti PC inner join prodotti P on PC.IdFornitore = P.Fornitore left join programmazione PROG on P.IdProdotti = PROG.IdProdotto where PC.Anno = $anno and PC.idcliente = $idcliente and PC.IdFornitore = $idforni and P.Attivo = 'Y' and PROG.Anno = $anno and PROG.IdCliente = PC.IdCliente order by P.Nome " ; list($npg, $dng) = $db->RecuperaDati($qpg) ; for ($ig=0; $ig<=$npg; $ig++) { $arrayGia[$dng['IdProdotti'][$ig]]['Dato1'] = $dng['Dato1'][$ig] ; $arrayGia[$dng['IdProdotti'][$ig]]['Dato2'] = $dng['Dato2'][$ig] ; } } } // fine for($numfor .....) /************************************************************************* * Dopo aver eventualmente inserito le programmazioni non ancora definite * recupero tutti i dati di programmazione delle coppie cliente/fornitore e * le visualizzo ***************************************************************************/ $anno1 = $anno - 1 ; $anno2 = $anno - 2 ; $anno3 = $anno - 3 ; /******************************************************************** * Al posto della ennesima query, si potrebbero utilizzare i due array * datiforninome e datiforniid *********************************************************************/ unset($_SESSION["IDFORNI"]) ; for ($numfor=0; $numfor
= '$dataperiodo' then SUM(D.NumCartoni * D.ConfezioniDa) end as NumBottP2, 0 as NumBottSMP1, 0 as NumBottSMP2 from ordini O inner join dettagli D on O.Idordini = D.Idordine and O.Anno = D.Anno where O.Anno = $anno and O.idcliente = $idcliente and O.idfornitore = $idforni group by D.IdProdotto UNION ALL select SM.IdProdotto as IdProdotto, 0 as NumBottP1, 0 as NumBottP2, case when O.DataSpedFattura < '$dataperiodo' then SUM(SM.NumCartoni * SM.ConfezioniDa) end as NumBottSMP1, case when O.DataSpedFattura >= '$dataperiodo' then SUM(SM.NumCartoni * SM.ConfezioniDa) end as NumBottSMP2 from ordini O left join scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = O.Anno where O.Anno = $anno and O.idcliente = $idcliente and O.idfornitore = $idforni group by SM.IdProdotto) T group by IdProdotto" ; debug (0, $qcons) ; list($ncons, $dcons) = $db->RecuperaDati($qcons) ; for ($x=0; $x<$ncons; $x++) { $arrayCons[$dcons['IdProdotto'][$x]]['NumBottP1'] = $dcons['NumBottP1'][$x] ; $arrayCons[$dcons['IdProdotto'][$x]]['NumBottP2'] = $dcons['NumBottP2'][$x] ; $arrayCons[$dcons['IdProdotto'][$x]]['NumBottSMP1'] = $dcons['NumBottSMP1'][$x] ; $arrayCons[$dcons['IdProdotto'][$x]]['NumBottSMP2'] = $dcons['NumBottSMP2'][$x] ; } /****************************************************************************************** * Dalla versione 3.0 la tabella dei prodotti è unica e non si tiene più conto degli anni ******************************************************************************************/ $qord = " select P.IdProdotti as IdProdotto, P.Nome as NomeProdotto, O.Anno, SUM(D.NumCartoni * D.ConfezioniDa) as NumBottiglie, SUM(SM.NumCartoni * SM.ConfezioniDa) as NumBottiglieSM from ordini O inner join dettagli D on D.IdOrdine = O.IdOrdini and O.Anno = D.Anno inner join Prodotti P on D.IdProdotto = P.IdProdotti left join scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = O.Anno where ((O.Anno = $anno3 and D.Anno = $anno3) or (O.Anno = $anno2 and D.Anno = $anno2) or (O.Anno = $anno1 and D.Anno = $anno1)) and O.idcliente = $idcliente and O.idfornitore = $idforni group by P.Nome, O.Anno order by P.Nome asc, O.Anno asc" ; list($nord, $dord) = $db->RecuperaDati($qord) ; for ($x=0; $x<$ncons; $x++) { $arrayCons[$dcons['IdProdotto'][$x]]['NumBottP1'] = $dcons['NumBottP1'][$x] ; $arrayCons[$dcons['IdProdotto'][$x]]['NumBottP2'] = $dcons['NumBottP2'][$x] ; $arrayCons[$dcons['IdProdotto'][$x]]['NumBottSMP1'] = $dcons['NumBottSMP1'][$x] ; $arrayCons[$dcons['IdProdotto'][$x]]['NumBottSMP2'] = $dcons['NumBottSMP2'][$x] ; } /****************************************************************************************** * Dalla versione 3.0 la tabella dei prodotti è unica e non si tiene più conto degli anni ******************************************************************************************/ $qord = " select P.IdProdotti as IdProdotto, P.Nome as NomeProdotto, O.Anno, SUM(D.NumCartoni * D.ConfezioniDa) as NumBottiglie, SUM(SM.NumCartoni * SM.ConfezioniDa) as NumBottiglieSM from ordini O inner join dettagli D on D.IdOrdine = O.IdOrdini and O.Anno = D.Anno inner join Prodotti P on D.IdProdotto = P.IdProdotti left join scontomerce SM on SM.IdOrdine = O.IdOrdini and SM.Anno = O.Anno where ((O.Anno = $anno3 and D.Anno = $anno3) or (O.Anno = $anno2 and D.Anno = $anno2) or (O.Anno = $anno1 and D.Anno = $anno1)) and O.idcliente = $idcliente and O.idfornitore = $idforni group by P.Nome, O.Anno order by P.Nome asc, O.Anno asc" ; debug (0, $qord) ; list($nord, $dord) = $db->RecuperaDati($qord) ; for ($j=0; $j<$nord; $j++) { $numBott = $dord['NumBottiglie'][$j] ; $numBottSM = $dord['NumBottiglieSM'][$j] ; $idProd = $dord['IdProdotto'][$j] ; $nomeProd = $dord['NomeProdotto'][$j] ; $annoOrd = $dord['Anno'][$j] ; if ($numBott != 0 or $numBottSM != 0) { $arrayDati[$idProd]['Nome'] = $nomeProd ; $arrayDati[$idProd][$annoOrd]['Bott'] = $numBott ; $arrayDati[$idProd][$annoOrd]['BottSM'] = $numBottSM ; } } $qpro = " select P.IdProdotti, P.Nome from prodotti P where P.fornitore = $idforni order by P.nome ASC" ; @reset($arrayDati) ; list($nprod, $dbpro) = $db->RecuperaDati($qpro) ; for ($i=0; $i<$nprod; $i++) { $iPrd = $dbpro['IdProdotti'][$i] ; $nPrd = $dbpro['Nome'][$i] ; debug (0, "PRD = $iPrd") ; $codpro[$i] = $iPrd ; if ($arrCons[$iPrd]['NumBott'] > 0) $dper1 = $arrCons[$iPrd]['NumBott'] ; else $dper1 = "" ; if ($arrCons[$iPrd]['NumBottSM'] > 0) $dper2 = $arrCons[$iPrd]['NumBottSM'] ; else $dper2 = "" ; if ($proGiaDefinita) { if (array_key_exists($iPrd, $arrayGia)) { debug (0, "In Arra.....") ; $dati1 = $arrayGia[$iPrd]['Dato1'] ; $dati2 = $arrayGia[$iPrd]['Dato2'] ; } else { debug (0, "In NO Arra.....") ; $dati1 = 0 ; $dati2 = 0 ; } } else { $dati1 = 0 ; $dati2 = 0 ; } /************************************ * controllo l'eventuale consegnato ************************************/ if (@array_key_exists($iPrd, $arrayCons)) { $dper1 = $arrayCons[$iPrd]['NumBottP1'] ; $dper2 = $arrayCons[$iPrd]['NumBottP2'] ; $dper1sm = $arrayCons[$iPrd]['NumBottSMP1'] ; $dper2sm = $arrayCons[$iPrd]['NumBottSMP2'] ; if (($dper1sm > 0) or ($dper2sm > 0)) $sconto2 = "* Sconto Merce" ; } else { $dper1 = 0 ; $dper2 = 0 ; $dper1sm = 0 ; $dper2sm = 0 ; } if (@array_key_exists($iPrd, $arrayDati)) { $d3 = $arrayDati[$iPrd][$anno3]['Bott'] ; $d2 = $arrayDati[$iPrd][$anno2]['Bott'] ; $d1 = $arrayDati[$iPrd][$anno1]['Bott'] ; $d3SM = $arrayDati[$iPrd][$anno3]['BottSM'] ; $d2SM = $arrayDati[$iPrd][$anno2]['BottSM'] ; $d1SM = $arrayDati[$iPrd][$anno1]['BottSM'] ; if (($d1SM > 0) or ($d2SM > 0) or ($d3SM > 0)) $sconto1 = "* Sconto Merce" ; } else { $d3 = 0 ; $d2 = 0 ; $d1 = 0 ; $d3SM = 0 ; $d2SM = 0 ; $d1SM = 0 ; } ?>
 
Programmazione Consegnato
 
1º periodo 2º periodo