SELECT
npsp__General_Accounting_Unit__r.Project_Number_Ext__c AS Projekt,
npe01__OppPayment__c.npe01__Payment_Date__c AS Buchungsdatum,
npe01__OppPayment__c.npe01__Payment_Amount__c AS Betrag,
Master_Campaign__r.Campaign_ID__c AS Kampagne,
npe01__OppPayment__c.Bank_Statement_No__c AS KontoauszugsNr,
npe01__OppPayment__c.Cash_Account_ID__c AS GeldkontoID,
Opportunity.Donation_ID__c AS LfdNr,
npe01__OppPayment__c.DTA_Textkey__c AS Textschlüssel,
npe01__OppPayment__c.Purpose__c AS Buchungstext,
npe01__OppPayment__c.Bank_Fee__c AS BankgebührBeiRückbelastung,
Linked_Donation__r.Donation_ID__c AS LfdNrAlt,
Opportunity.Id
FROM Opportunity
LEFT JOIN npe01__OppPayment__c ON npe01__OppPayment__c.npe01__Opportunity__c = Opportunity.Id
LEFT JOIN npsp__Allocation__c ON npsp__Allocation__c.npsp__Opportunity__c = Opportunity.Id
LEFT OUTER JOIN npsp__General_Accounting_Unit__c AS npsp__General_Accounting_Unit__r ON npsp__Allocation__c.npsp__General_Accounting_Unit__c = npsp__General_Accounting_Unit__r.Id
LEFT OUTER JOIN Campaign ON Opportunity.CampaignId = Campaign.Id
LEFT OUTER JOIN Campaign AS Master_Campaign__r ON Campaign.Master_Campaign__c = Master_Campaign__r.Id
LEFT OUTER JOIN Opportunity AS Linked_Donation__r ON Opportunity.Linked_Donation__c = Linked_Donation__r.Id
WHERE Opportunity.SAP_Synchronization__c = FALSE AND (Opportunity.StageName = 'Received' OR Opportunity.StageName = 'Declined') AND Opportunity.Export_Status__c != 'Error' AND Opportunity.Error_Reason__c != 'Error'