select a.Societa, a.IDSocieta, fp.* from anagrafica a inner join spese_generali fp on a.IDSocieta = fp.IDSocieta where fp.data_documento <= str_to_date('#data_rif#','%d/%m/%Y') and ( (fp.cambio > 0 and abs((fp.importo + fp.iva)/fp.cambio - fp.pagato) > 0.1) or (fp.cambio = 0 and abs(fp.importo + fp.iva - fp.pagato) > 0.1) or (fp.ndc = 'ndc' and IDdocumento IN (select distinct IDspesa from movimenti where tipologia = 'in_' and datacont > str_to_date('#data_rif#','%d-%m-%Y'))) or (fp.ndc <> 'ndc' and IDdocumento IN (select distinct IDspesa from movimenti where tipologia = 'out' and datacont > str_to_date('#data_rif#','%d-%m-%Y'))) ) order by a.societa, data_documento, Numero_documento select datacont, importo, tipologia, IDspesa from movimenti where IDspesa IN (select IDdocumento from spese_generali )
select sum(importo) as successivi from tutti_movimenti where IDspesa = #IDdocumento# and tipologia = 'in_out' and datacont > #data_rif# select sum(importo) as successivi from tutti_movimenti where IDspesa = #IDdocumento# and tipologia = 'in_out' and datacont > #data_rif# bgcolor="##ffff00">
#societa# 
ID   N° data Descrizione Destinazione Imponibile Importo Scad. Saldo
#IDDocumento# €   #trim(note_)#  #Numero_documento# #dateformat(data_documento, "dd/mm/yy")# #Descrizione# #Classificazione# #LSNumberFormat(Importo)# L.#LSEuroCurrencyFormat(Importo, "none")# € #LSNumberFormat(Importo+iva)# L.#LSEuroCurrencyFormat(Importo+iva, "none")# € #dateformat(scadenza, "dd/mm/yy")# #LSNumberFormat(saldo)# L.#LSEuroCurrencyFormat(saldo, "none")# €
SubTotale #LSEuroCurrencyFormat(saldo_for, "local")#
Totale #LSEuroCurrencyFormat(saldo_totale, "local")#