$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 *---------------------------------------------------------------- * 3.0: Non ha senso controllare se l'agente cambia nome da un anno all'altro !!! ***/ $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 = "" ; } $msgNoDati = "Non è possibile effettuare il confronto dei prodotti di questa azienda per le due annate" ; /******************************************************************************************* * mi ricavo il nome dell'azienda per andare a recuperare nell'anno prima la stessa azienda *---------------------------- * 3.0: non ha senso controllare se l'azienda ha cambiato nome, in ogni caso è sempre la stessa * e quindi il suo id rimane uguale ********************************************************************************************/ $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 ) { $stampa = "si" ; /* * 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 *--------------------------------------------- * 3.0: per sapere l'anno adesso si guarda * nella tabella degli ordini e dei dettagli */ $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) ; $totRecAnnoP = $dbp->num_rows() ; 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) ; $totRecAnno = $dbp->num_rows() ; 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 ; } } } } else { $stampa = "no" ; } $totBottAnnoP_V = $totBottAnno_V = $diffNumBott_V = 0 ; $totCifreAnnoP_V = $totCifreAnno_V = $diffCifre_V = 0 ; $totBottAnnoP_F = $totBottAnno_F = $diffNumBott_F = 0 ; $totCifreAnnoP_F = $totCifreAnno_F = $diffCifre_F = 0 ; ksort($valori) ; @reset($valori) ; $classno = "meno" ; $id_prd = 0 ; $str = "" ; foreach($valori as $prodotto => $arr_anni) // while(list($prodotto, $arr_anni) = each($valori)) { if ($arr_anni[$anno_prec]['num_bott_vend'] > $arr_anni[$anno]['num_bott_vend']) $class = "meno" ; else $class = "piu" ; $str .= "" ; $str .= "" . htmlspecialchars($prodotto) . "" ; $str .= "" . $arr_anni[$anno_prec]['num_bott_vend'] . "" ; $str .= "" . $arr_anni[$anno]['num_bott_vend'] . "" ; $str .= "" . ($arr_anni[$anno]['num_bott_vend'] - $arr_anni[$anno_prec]['num_bott_vend']) . "" ; if ($arr_anni[$anno_prec]['in_cifre_vend'] > $arr_anni[$anno]['in_cifre_vend']) $class = "meno" ; else $class = "piu" ; $str .= "" . nfp($arr_anni[$anno_prec]['in_cifre_vend']) . "" ; $str .= "" . nfp($arr_anni[$anno]['in_cifre_vend']) . "" ; $str .= "" . nfp($arr_anni[$anno]['in_cifre_vend'] - $arr_anni[$anno_prec]['in_cifre_vend']) . "" ; if ($arr_anni[$anno_prec]['num_bott_fatt'] > $arr_anni[$anno]['num_bott_fatt']) $class = "meno" ; else $class = "piu" ; $str .= "" . $arr_anni[$anno_prec]['num_bott_fatt'] . "" ; $str .= "" . $arr_anni[$anno]['num_bott_fatt'] . "" ; $str .= "" . ($arr_anni[$anno]['num_bott_fatt'] - $arr_anni[$anno_prec]['num_bott_fatt']) . "" ; if ($arr_anni[$anno_prec]['in_cifre_fatt'] > $arr_anni[$anno]['in_cifre_fatt']) $class = "meno" ; else $class = "piu" ; $str .= "" . nfp($arr_anni[$anno_prec]['in_cifre_fatt']) . "" ; $str .= "" . nfp($arr_anni[$anno]['in_cifre_fatt']) . "" ; $str .= "" . nfp($arr_anni[$anno]['in_cifre_fatt'] - $arr_anni[$anno_prec]['in_cifre_fatt']) . "" ; $str .= "" ; $id_prd ++ ; $totBottAnnoP_V += $arr_anni[$anno_prec]['num_bott_vend'] ; $totBottAnno_V += $arr_anni[$anno]['num_bott_vend'] ; $totCifreAnnoP_V += $arr_anni[$anno_prec]['in_cifre_vend'] ; $totCifreAnno_V += $arr_anni[$anno]['in_cifre_vend'] ; $totBottAnnoP_F += $arr_anni[$anno_prec]['num_bott_fatt'] ; $totBottAnno_F += $arr_anni[$anno]['num_bott_fatt'] ; $totCifreAnnoP_F += $arr_anni[$anno_prec]['in_cifre_fatt'] ; $totCifreAnno_F += $arr_anni[$anno]['in_cifre_fatt'] ; } $diffNumBott_V = $totBottAnno_V - $totBottAnnoP_V ; $diffCifre_V = $totCifreAnno_V - $totCifreAnnoP_V ; $diffNumBott_F = $totBottAnno_F - $totBottAnnoP_F ; $diffCifre_F = $totCifreAnno_F - $totCifreAnnoP_F ; $str .= "" ; $annop = ($anno - 1) ; $header = "PRODOTTO,VENDUTO,#cspan,#cspan,#cspan,#cspan,#cspan,FATTURATO,#cspan,#cspan,#cspan,#cspan,#cspan" ; $attachHeader = "#rspan,Numero Bottiglie,#cspan,#cspan,In Cifre,#cspan,#cspan,Numero Bottiglie,#cspan,#cspan,In Cifre,#cspan,#cspan" ; $attachHeader2 = "#rspan,$annop,$anno,Differenza,$annop,$anno,Differenza,$annop,$anno,Differenza,$annop,$anno,Differenza" ; $strSort = "str,int,int,int,euro,euro,euro,int,int,int,euro,euro,euro" ; $iniWP = "28,5,5,7,6,6,7,5,5,7,6,6,7" ; $setColType = "ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro" ; $setColAlign = "left,center,center,center,center,center,center,center,center,center,center,center,center" ; $footer = "TOTALI:^" . nfl($totBottAnnoP_V) . "^" . nfl($totBottAnno_V) . "^" . nfl($diffNumBott_V) . "^" . nfp($totCifreAnnoP_V) . "^" . nfp($totCifreAnno_V) . "^" . nfp($diffCifre_V) . "^" . nfl($totBottAnnoP_F) . "^" . nfl($totBottAnno_F) . "^" . nfl($diffNumBott_F) . "^" . nfp($totCifreAnnoP_F) . "^" . nfp($totCifreAnno_F) . "^" . nfp($diffCifre_F) ; if ($totRecAnnoP == 0 and $totRecAnno == 0) $msgNoDati = "Non ci sono dati da visualizzare per il confronto dei prodotti di questa azienda per l'agente selezionato per le due annate" ; ?> <? echo TITLE ?>