include ("../common/public.php") ;
// print_r($_GET + $_POST) ;
// debug(1, "gime = $gime") ;
session_start() ;
$_SESSION["Carica"] = $_SERVER['REQUEST_URI'] ;
if (isset($gime))
$_SESSION["giornoMese"] = $gime ;
else
$gime = $_SESSION["giornoMese"] ;
$nomemese = Array("", "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre") ;
list($giorno, $mese) = explode("/", $gime) ;
$chk = "$mese/$giorno" ;
$mese = $nomemese[ltrim($mese,"0")] ;
$annop = $anno-1 ;
$titolo = "Confronto Anno $annop - Anno $anno al $giorno $mese" ;
$dataordine_1 = MySqlDate("$gime/$anno") ;
$dataordine_2 = MySqlDate("$gime/$annop") ;
$str = "" ;
/****************
* NUMERO ORDINI
****************/
$qtot = "
select
count(*) as TOT
from
ordini
where
Anno = $anno and
dataordine <= '$dataordine_1'
union
select
count(*) as TOT
from
ordini
where
Anno = $annop and
dataordine <= '$dataordine_2'
" ;
list($ntot, $dtot) = $db->RecuperaDati($qtot) ;
/********************************************
* si gestisce il caso particolare in cui il numero
* degli ordini per i due anni coincide
*******************************************/
if ($ntot == 1)
$dtot['TOT'][1] = $dtot['TOT'][0] ;
$difftot = $dtot['TOT'][0] - $dtot['TOT'][1] ;
$str .= "" ;
$str .= "| " . $dtot['TOT'][1] . " | " ;
$str .= "" . $dtot['TOT'][0] . " | " ;
if ($difftot < 0)
$classtot = 'meno' ;
else
$classtot = 'piu' ;
if ($dtot['TOT'][0] == 0 or $dtot['TOT'][1] == 0)
$diff_t_perc = @nfp(100) ;
else
$diff_t_perc = @nfp((($dtot['TOT'][0] - $dtot['TOT'][1]) / $dtot['TOT'][1] * 100)) ;
$str .= "" . $difftot . " ($diff_t_perc %) | " ;
/**********************
* VENDUTO e FATTURATO
**********************/
// TEST
$dbt = new FC_SQL ;
$query = "
select
*
from
ordini O
inner join fornitori F on O.IdFornitore = F.IdFornitori
where
(O.Anno = $anno and O.DataOrdine <= '$dataordine_1') or
(O.Anno = $anno -1 and O.DataOrdine <= '$dataordine_2')
order by
O.Anno
" ;
list($ndati, $dati) = $db->RecuperaDati($query) ;
// print_r($dati) ;
for ($i=0; $i<$ndati; $i++)
{
$idfor = $dati['IdFornitori'][$i] ;
$annoOrdine = $dati['Anno'][$i] ;
$provvigione = $dati['Provvigione'][$i] ;
$an = $dati['Anno'][$i] ;
$chk_dataordine = "$an-$chk" ;
$totordine = 0 ;
$importofattura = $dati['ImportoFattura'][$i] ;
$dataspedfattura = $dati['DataSpedFattura'][$i] ;
$sco1 = $dati['Sconto1'][$i] ;
$sco2 = $dati['Sconto2'][$i] ;
$sco3 = $dati['Sconto3'][$i] ;
$idordine = $dati['IdOrdini'][$i] ;
$importoNC = $dati['ImportoNC'][$i] ;
if ($importoNC > 0)
$valNC = ($importoNC / 1.2) ;
else
$valNC = 0 ;
debug (0, $provvigione . ' ' . $idordine . ' ' . $annoOrdine . ' ' . $idfor) ;
if ($idfor != $idsarzi)
$qdett = "
select
*
from
dettagli D,
prodotti P
where
D.Anno = $an and
D.idordine = $idordine and
P.idprodotti = D.idprodotto " ;
else
$qdett = "select * from dettagli_$an, sarzi_$an where dettagli_$an.idordine = $idordine and dettagli_$an.idprodotto = CONCAT('SA', idprodotti)" ;
list($ndett, $ddett) = $dbt->RecuperaDati($qdett) ;
for($j=0; $j<$ndett; $j++)
{
if ($ddett['PrezzoForzato'][$j] > 0)
$prezzoDaConsiderare = $ddett['PrezzoForzato'][$j] ;
else
$prezzoDaConsiderare = $ddett['PrezzoUnitario'][$j] ;
$impparz = $ddett["NumCartoni"][$j] * $ddett["ConfezioniDa"][$j] * $prezzoDaConsiderare ;
if ($ddett["ScontoPrd"][$j] != "")
$impparz = CalcolaScontoProdotto($impparz, $ddett["ScontoPrd"][$j]) ;
$totordine += $impparz ;
}
$sconto1 = ($totordine * $sco1 / 100) ;
$ammpro1 = $totordine - $sconto1 ;
$sconto2 = ($ammpro1 * $sco2 / 100) ;
$ammpro2 = $ammpro1 - $sconto2 - $valNC ;
/***********************************************************
* Calcolo a questo punto l'ammontare delle provvigioni per
* questo ordine dopo aver sottratto dall'imponibile gli
* eventuali 2 sconti forniti dal fornitore e l'eventuale
* ammontare della nota di credito. Idem per il
* fatturato
*************************************************************/
$sconto = $sconto1 + $sconto2 ;
$totordine = $totordine - $sconto - $valNC;
$totforn += $totordine ;
$TotVend[$an] += $totordine ;
if ($importofattura > 0 and ($dataspedfattura <= $chk_dataordine))
{
debug (0, "DENTRO => IDORDINE = $idordine; IMP FATT = $importofattura ; IMP ORDINE = $totordine ; $dataspedfattura <= $chk_dataordine") ;
$gtotal_fatt += $totordine ;
$TotFatt[$an] += $totordine ;
}
}
$diffvend = $TotVend[$anno] - $TotVend[$anno-1] ;
$difffatt = $TotFatt[$anno] - $TotFatt[$anno-1] ;
$str .= "" . nfp($TotVend[$anno-1]) . " | " ;
$str .= "" . nfp($TotVend[$anno]) . " | " ;
if ($diffvend < 0)
$classvend = 'meno' ;
else
$classvend = 'piu' ;
if ($TotVend[$anno-1] == 0 or $TotVend[$anno] == 0)
$diff_v_perc = @nfp(100) ;
else
$diff_v_perc = @nfp((($TotVend[$anno] - $TotVend[$anno-1]) / $TotVend[$anno-1] * 100)) ;
$str .= "" . nfp($diffvend) . " ($diff_v_perc %) | " ;
$str .= "" . nfp($TotFatt[$anno-1]) . " | " ;
$str .= "" . nfp($TotFatt[$anno]) . " | " ;
if ($difffatt < 0)
$classfatt = 'meno' ;
else
$classfatt = 'piu' ;
if ($TotFatt[$anno-1] == 0 or $TotFatt[$anno] == 0)
$diff_f_perc = @nfp(100) ;
else
$diff_f_perc = @nfp((($TotFatt[$anno] - $TotFatt[$anno-1]) / $TotFatt[$anno-1] * 100)) ;
$str .= "" . nfp($difffatt) . " ($diff_f_perc %) | " ;
$str .= "
" ;
$str .= "" ;
$header = "NUMERO ORDINI,#cspan,#cspan,VENDUTO,#cspan,#cspan,FATTURATO,#cspan,#cspan" ;
$attachHeader = "$annop,$anno,Differenza,$annop,$anno,Differenza,$annop,$anno,Differenza" ;
$strSort = "int,euro,euro,int,int,int,int,int,int" ;
$iniWP = "8,8,13,9,9,16,9,9,16" ;
$setColType = "ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro,ro" ;
$setColAlign = "right,right,right,right,right,right,right,right,right" ;
?>
echo TITLE ?>
echo $titolo ?>