include ("../common/public.php") ; $data = date("Y-m-d", mktime(0,0,0, date("m"), date("d") - $giorni, date("Y"))) ; /****************************************************************************** * recupero le fatture scadute ma non pagate dell'anno in corso e dei due anni * precedenti * 8.11.2021 Modifiche versione 3.0 ******************************************************************************/ $an1 = $anno - 1 ; $an2 = $anno - 2 ; /*********** * PRIMA ***********/ $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_$anno O inner join pagamenti_$anno P on P.IdPagamenti = O.idpagamento inner join fornitori_$anno F on F.IdFornitori = O.IdFornitore and F.IdFornitori = $IdFornitore inner join clienti_$anno 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_$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 ************************/ $query1 = " 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 (0, $query) ; list($n, $d) = $db->RecuperaDati($query) ; if ($n > 0) { echo "
| Numero Fattura | Data Fattura | Giorni trascorsi | Importo Fattura | |
| ". $d['NumFattura'][$i] . " | ". ItaDate($d['DataSpedFattura'][$i]) . " | " . $ggpass . " | " . nfe($d['ImportoFattura'][$i]) . " |