$giorno $mesevis per i prodotti del
Fornitore $nome_fn" ; if ($idAgente > 0) { $innerJoinAnno = " inner join agenti A on A.idagenti = O.idagente and A.idagenti = $idAgente" ; /*** * Se è settato un agente, dal nome recupero l'id dell'anno prima ***/ $q = " select A.IdAgenti as ID_AG_ANNO_PRIMA from agenti A where A.Nome = '$nomeAgente' " ; list($n, $d) = $db->RecuperaDati($q) ; if ($n > 0) { $idAgenteAnnoPrima = $d['ID_AG_ANNO_PRIMA'][0] ; $titolo .= "
(Agente $nomeAgente)" ; $innerJoinAnnoP = " inner join agenti A on A.idagenti = O.idagente and A.idagenti = $idAgenteAnnoPrima" ; } else { $idAgenteAnnoPrima = -1 ; $innerJoinAnnoP = " inner join agenti A on A.idagenti = O.idagente and A.idagenti = $idAgenteAnnoPrima" ; } } else { $innerJoinAnno = "" ; $innerJoinAnnoP = "" ; } if ($idCliente > 0) { $titolo .= "
(Cliente $nomeCliente)" ; $innerJoinAnnoCl = " inner join clienti C on C.idclienti = O.idcliente and C.idclienti = $idCliente" ; $innerJoinAnnoPCl = " inner join clienti C on C.idclienti = O.idcliente and C.idclienti = $idCliente" ; } else { $innerJoinAnnoCl = "" ; $innerJoinAnnoPCl = "" ; } /*** * mi ricavo il nome dell'azienda per andare a recuperare nell'anno prima * la stessa azienda ***/ $q = " select F.IdFornitori as ID, F.nome as NOME from fornitori F where F.IdFornitori = $azienda " ; $db->query($q) ; if ( $db->num_rows() > 0 ) { /* * i nomi dell'azienda nelle due annate coincidono */ while ($db->next_record()) { $id_a_p = $db->f("ID") ; $nome_a_p = $db->f("NOME") ; $nome_a = $db->f("NOME") ; /* * recupero i prodotti dell'anno precedente */ $query = " select P.*, D.IdOrdine, (D.NumCartoni * D.ConfezioniDa) as NumBottPerOrdine, O.DataOrdine, O.DataSpedFattura, (TO_DAYS('$dataordine') - TO_DAYS(O.DataSpedFattura)) as DIFFGG from prodotti P, dettagli D, ordini O $innerJoinAnnoP $innerJoinAnnoPCl where O.Anno = $anno_prec and D.Anno = $anno_prec and P.Fornitore = $id_a_p and D.IdProdotto = P.IdProdotti and D.IdOrdine = O.IdOrdini and O.dataordine <= '$dataordine' order by P.Nome " ; $dbp->query($query) ; while ($dbp->next_record()) { $nome_pro = strtoupper(trim($dbp->f("Nome"))) ; $num_bott = $dbp->f("NumBottPerOrdine") ; $data_ordine = $dbp->f("DataOrdine") ; $data_sped_fatt = $dbp->f("DataSpedFattura") ; $diffgg = ($dbp->f("DIFFGG") != '' ? $dbp->f("DIFFGG") : -1) ; $prezzo_uni = $dbp->f("PrezzoUnitario") ; $tot_per_ordine = $num_bott * $prezzo_uni ; if (! array_key_exists($nome_pro, $valori)) { $valori[$nome_pro] = array("$anno_prec" => array ('num_bott_vend' => 0, 'num_bott_fatt' => 0, 'in_cifre_vend' => 0, 'in_cifre_fatt' => 0), "$anno" => array ('num_bott_vend' => 0, 'num_bott_fatt' => 0, 'in_cifre_vend' => 0, 'in_cifre_fatt' => 0)) ; } $valori[$nome_pro]["$anno_prec"]['num_bott_vend'] += $num_bott ; $valori[$nome_pro]["$anno_prec"]['in_cifre_vend'] += $tot_per_ordine ; /*** * se diffgg è negativo allora vuol dire che la data di fatturazione * è superiore alla data dell'anno prima in cui sto facendo il confronto ***/ if ($diffgg >= 0) { $valori[$nome_pro]["$anno_prec"]['num_bott_fatt'] += $num_bott ; $valori[$nome_pro]["$anno_prec"]['in_cifre_fatt'] += $tot_per_ordine ; } } /* * recupero i prodotti per l'anno in corso */ $dataordine = MySqlDate("$gime/$anno") ; $query = " select P.*, D.IdOrdine, (D.NumCartoni * D.ConfezioniDa) as NumBottPerOrdine, O.DataOrdine, O.DataSpedFattura, (TO_DAYS('$dataordine') - TO_DAYS(O.DataSpedFattura)) as DIFFGG from prodotti P, dettagli D, ordini O $innerJoinAnno $innerJoinAnnoCl where O.Anno = $anno and D.Anno = $anno and P.Fornitore = $azienda and D.IdProdotto = P.IdProdotti and D.IdOrdine = O.IdOrdini and O.dataordine <= '$dataordine' order by P.Nome " ; $dbp->query($query) ; while ($dbp->next_record()) { $nome_pro = strtoupper(trim($dbp->f("Nome"))) ; $num_bott = $dbp->f("NumBottPerOrdine") ; $data_ordine = $dbp->f("DataOrdine") ; $data_sped_fatt = $dbp->f("DataSpedFattura") ; $diffgg = ($dbp->f("DIFFGG") != '' ? $dbp->f("DIFFGG") : -1) ; $prezzo_uni = $dbp->f("PrezzoUnitario") ; $tot_per_ordine = $num_bott * $prezzo_uni ; if (! array_key_exists($nome_pro, $valori)) { $valori[$nome_pro] = array("$anno_prec" => array ('num_bott_vend' => 0, 'num_bott_fatt' => 0, 'in_cifre_vend' => 0, 'in_cifre_fatt' => 0), "$anno" => array ('num_bott_vend' => 0, 'num_bott_fatt' => 0, 'in_cifre_vend' => 0, 'in_cifre_fatt' => 0)) ; } $valori[$nome_pro]["$anno"]['num_bott_vend'] += $num_bott ; $valori[$nome_pro]["$anno"]['in_cifre_vend'] += $tot_per_ordine ; /* * se diffgg è negativo allora vuol dire che la data di fatturazione * è superiore alla data dell'anno prima in cui sto facendo il confronto */ if ($diffgg >= 0) { $valori[$nome_pro]["$anno"]['num_bott_fatt'] += $num_bott ; $valori[$nome_pro]["$anno"]['in_cifre_fatt'] += $tot_per_ordine ; } } } ksort($valori) ; @reset($valori) ; ?> <? echo TITLE ?> $arr_anni) // while(list($prodotto, $arr_anni) = each($valori)) { ?>
  VENDUTO FATTURATO
Differenza Differenza
Num Bott
In Cifre
 
  VENDUTO FATTURATO
Differenza Differenza
TOTALI Num Bott
In Cifre