/****************************************
* VERSIONE .0 READY
*****************************************/
include ("../common/public.php") ;
// print_r($_GET + $_POST) ; // exit ;
function TogliIva($lordo)
{
$imp = 0 ;
if ($lordo > 0)
$imp = $lordo/1.22 ;
return $imp ;
}
$arrVal = array() ;
$arrTotali = array() ;
$annop = $anno - 1 ;
$anno2p = $anno - 2 ;
$NewArrVal = ["1" => array(),
"2" => array(),
"3" => array(),
"4" => array(),
"5" => array(),
"6" => array(),
"7" => array(),
"8" => array(),
"9" => array(),
"10" => array(),
"11" => array(),
"12" => array()] ;
/****************************************************
* Ricavo il fatturato per l'anno in corso, un anno
* prima e due anni prima
*****************************************************/
$query = "
SELECT
Mese,
SUM(Fatturato) AS Fatturato,
SUM(FatturatoAP) as FatturatoAP,
SUM(Fatturato2AP) as Fatturato2AP,
Idforni,
NomeForni,
ID
from
(
select
MONTH (O.DataSpedFattura) AS Mese,
O.ImportoFattura as Fatturato,
0 as FatturatoAP,
0 as Fatturato2AP,
F.IdFornitori as IdForni,
F.Nome as NomeForni,
O.IdOrdini as Id
FROM
ordini O INNER JOIN fornitori F ON
F.idfornitori = O.idfornitore
WHERE
O.Anno = $anno AND O.idfornitore = $fornitore and O.DataSpedFattura > 0
UNION
select
MONTH (O.DataSpedFattura) AS Mese,
0 as Fatturato,
O.ImportoFattura as FatturatoAP,
0 as Fatturato2AP,
F.IdFornitori as IdForni,
F.Nome as NomeForni,
O.IdOrdini as Id
FROM
ordini O INNER JOIN fornitori F ON
F.idfornitori = O.idfornitore
WHERE
O.Anno = $annop AND O.idfornitore = $fornitore and O.DataSpedFattura > 0
UNION
select
MONTH (O.DataSpedFattura) AS Mese,
0 as Fatturato,
0 as FatturatoAP,
O.ImportoFattura as Fatturato2AP,
F.IdFornitori as IdForni,
F.Nome as NomeForni,
O.IdOrdini as Id
FROM
ordini O INNER JOIN fornitori F ON
F.idfornitori = O.idfornitore
WHERE
O.Anno = $anno2p AND O.idfornitore = $fornitore and O.DataSpedFattura > 0
) as TT
WHERE
TT.mese > 0
group By Mese" ;
list($n, $d) = $db->RecuperaDati($query) ;
$nomeFornitore = $d['NomeForni'][0] ;
for($i=0; $i<$n; $i++)
{
if ($d['Fatturato'][$i] > 0)
$NewArrVal[$d['Mese'][$i]]['Fatturato'] = TogliIva($d['Fatturato'][$i]) ;
else
$NewArrVal[$d['Mese'][$i]]['Fatturato'] = "0,00" ;
if ($d['FatturatoAP'][$i] > 0)
$NewArrVal[$d['Mese'][$i]]['FatturatoAP'] = TogliIva($d['FatturatoAP'][$i]) ;
else
$NewArrVal[$d['Mese'][$i]]['FatturatoAP'] = "0,00" ;
if ($d['Fatturato2AP'][$i] > 0)
$NewArrVal[$d['Mese'][$i]]['Fatturato2AP'] = TogliIva($d['Fatturato2AP'][$i]) ;
else
$NewArrVal[$d['Mese'][$i]]['Fatturato2AP'] = "0,00" ;
}
/****************************************************
* Ricavo i nuero di bottiglie per l'anno in corsa,
l'anno prima e due anni prima
*****************************************************/
$qbott = "
SELECT
Mese,
SUM(TotBott+TotBottSM) as TotBott,
SUM(TotBottAP+TotBottSMAP) as TotBottAP
FROM
(
SELECT
MONTH(O.DataSpedFattura) as Mese,
(D.ConfezioniDa*D.NumCartoni) as TotBott,
0 as TotBottSM,
0 as TotBottAP,
0 as TotBottSMAP,
O.idfornitore
FROM
`ordini` O
Inner join dettagli D on O.IdOrdini = D.IdOrdine
and D.Anno = $anno
WHERE
O.IdFornitore = $fornitore
and O.Anno = $anno
UNION ALL
SELECT
MONTH(O.DataSpedFattura) as Mese,
0 as TotBott,
(D.ConfezioniDa*D.NumCartoni) as TotBott,
0 as TotBottAP,
0 as TotBottSMAP,
O.idfornitore
FROM
`ordini` O
Inner join scontomerce D on O.IdOrdini = D.IdOrdine
and D.Anno = $anno
WHERE
O.IdFornitore = $fornitore
and O.Anno = $anno
UNION ALL
SELECT
MONTH(O.DataSpedFattura) as Mese,
0 as TotBott,
0 as TotBottSM,
(D.ConfezioniDa*D.NumCartoni) as TotBottAP,
0 as TotBottSMAP,
O.idfornitore
FROM
`ordini` O
Inner join dettagli D on O.IdOrdini = D.IdOrdine
and D.Anno = $annop
WHERE
O.IdFornitore = $fornitore
and O.Anno = $annop
UNION ALL
SELECT
MONTH(O.DataSpedFattura) as Mese,
0 as TotBott,
0 as TotBott,
0 as TotBottAP,
(D.ConfezioniDa*D.NumCartoni) as TotBottSMAP,
O.idfornitore
FROM
`ordini` O
Inner join scontomerce D on O.IdOrdini = D.IdOrdine
and D.Anno = $annop
WHERE
O.IdFornitore = $fornitore
and O.Anno = $annop
) as TT
WHERE
TT.Mese > 0
group By Mese
" ;
list($nbott, $dbott) = $db->RecuperaDati($qbott) ;
for ($i=0; $i<$nbott; $i++)
{
if ($dbott['TotBott'][$i] > 0)
$NewArrVal[$dbott['Mese'][$i]]['TotBott'] = $dbott['TotBott'][$i] ;
else
$NewArrVal[$dbott['Mese'][$i]]['TotBott'] = 0 ;
if ($dbott['TotBottAP'][$i] > 0)
$NewArrVal[$dbott['Mese'][$i]]['TotBottAP'] = $dbott['TotBottAP'][$i] ;
else
$NewArrVal[$dbott['Mese'][$i]]['TotBottAP'] = 0 ;
}
/***********************************
* Controllo il numero di clienti
***********************************/
$qcli = "
SELECT
O.Anno,
COUNT(DISTINCT(O.idcliente)) as NUMCLIENTI
FROM
ordini O
WHERE
O.Anno = $anno AND O.IdFornitore = $fornitore
UNION
SELECT
O.Anno,
COUNT(DISTINCT(O.idcliente)) as NUMCLIENTI
FROM
ordini O
WHERE
O.Anno = $annop AND O.IdFornitore = $fornitore;
" ;
list($ncli, $dcli) = $db->RecuperaDati($qcli) ;
$arrTotali[8] = $dcli['NUMCLIENTI'][0] ;
$arrTotali[9] = $dcli['NUMCLIENTI'][1] ;
$diffCli = $arrTotali[9] - $arrTotali[8] ;
if ($diffCli != 0 and $arrTotali[9] != 0)
$diffCliper = ((($diffCli / $arrTotali[9]) * 100) * -1) ;
else
$diffCliper = 0 ;
if ($diffCli < 0)
$classCli = "piu" ;
elseif ($diffCli > 0)
{
$classCli = "meno" ;
if ($diffCliper == "0,00000")
$diffCliper = "100,00000" ;
}
else
$classCli = "" ;
$titolo = "Totale Venduto / Fatturato per il Fornitore: Fbrizio" ;
?>
New Document
Statistiche X Mese per il fornitore echo $nomeFornitore ?>
Dati calcolati in base al valore inserito nel campo Importo Fattura dei dati dell'ordine