0 and O.dataspedfattura <= '$data' UNION ALL select O.*, O.DataSpedFattura as DataSpedizioneFattura, F.Nome as NomeFornitore, C.nome as NomeCliente, C.Indirizzo as IndirizzoCliente, C.Citta as CittaCliente, C.Provincia as ProvinciaCliente, P.modalita as TipoPagamento from ordini_$an1 O inner join pagamenti_$an1 P on P.IdPagamenti = O.idpagamento inner join fornitori_$an1 F on F.IdFornitori = O.IdFornitore and F.IdFornitori = $IdFornitore inner join clienti_$an1 C on C.IdClienti = O.IdCliente and O.IdCliente = $IdCliente where O.idpagamento IN (1,3,4,5,6,8,9,10,11) and O.saldofattura = 0 and O.NumFattura <> 0 and O.dataspedfattura <= '$data' UNION ALL select O.*, O.DataSpedFattura as DataSpedizioneFattura, F.Nome as NomeFornitore, C.nome as NomeCliente, C.Indirizzo as IndirizzoCliente, C.Citta as CittaCliente, C.Provincia as ProvinciaCliente, P.modalita as TipoPagamento from ordini_$an2 O inner join pagamenti_$an2 P on P.IdPagamenti = O.idpagamento inner join fornitori_$an2 F on F.IdFornitori = O.IdFornitore and F.IdFornitori = $IdFornitore inner join clienti_$an2 C on C.IdClienti = O.IdCliente and O.IdCliente = $IdCliente where O.idpagamento IN (1,3,4,5,6,8,9,10,11) and O.saldofattura = 0 and O.NumFattura <> 0 and O.dataspedfattura <= '$data' order by NomeCliente, DataSpedizioneFattura" ; /************************ * DOPO versione 3.0 ************************/ $query = " select O.*, case when (O.DataSpedFattura = '0000-00-00') then '2002-01-01' else O.DataSpedFattura end as DataSpedizioneFattura, F.Nome as NomeFornitore, C.nome as NomeCliente, C.Indirizzo as IndirizzoCliente, C.Citta as CittaCliente, C.Provincia as ProvinciaCliente, P.modalita as TipoPagamento from ordini O inner join pagamenti P on P.IdPagamenti = O.idpagamento inner join fornitori F on F.IdFornitori = O.IdFornitore and F.IdFornitori = $IdFornitore inner join clienti C on C.IdClienti = O.IdCliente and O.IdCliente = $IdCliente where (O.Anno = $anno or O.Anno = $an1 or O.Anno = $an2) and O.idpagamento IN (1,3,4,5,6,8,9,10,11) and O.saldofattura = 0 and O.NumFattura <> 0 and O.dataspedfattura <= '$data' " ; debug (1, $query) ; list($n, $d) = $db->RecuperaDati($query) ; if ($n > 0) { echo " " ; for ($i=0; $i<$n; $i++) { preg_match ("/([0-9]{4})[-\/]([0-9]{1,2})[-\/]([0-9]{1,2})/", $d['DataSpedizioneFattura'][$i], $reg_str) ; // ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $d['DataSpedizioneFattura'][$i], $reg_str) ; $ggpass = dateDiff(date("d"), date("m"), date("Y"), $reg_str[3], $reg_str[2], $reg_str[1]) ; echo " " ; } echo "
Numero Fattura Data Fattura Giorni trascorsi Importo Fattura
". $d['NumFattura'][$i] . " ". ItaDate($d['DataSpedFattura'][$i]) . " " . $ggpass . " " . nfe($d['ImportoFattura'][$i]) . "
" ; } else echo "0" ; ?>