Created
March 31, 2020 12:35
-
-
Save JoeMurray/7c20481c2d8f43c429a778e3cb0a37b2 to your computer and use it in GitHub Desktop.
subquery for GL report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
fa.name as civicrm_contact_financial_account, | |
contribution_civireport.id as contribution_id, | |
contribution_civireport.currency as civicrm_contribution_currency, | |
IF(ISNULL(ft.from_financial_account_id),fi.amount,-fi.amount) as civicrm_contribution_amount_sum | |
FROM civicrm_contact contact_civireport | |
INNER JOIN civicrm_contribution contribution_civireport ON contact_civireport.id = contribution_civireport.contact_id AND contribution_civireport.is_test = 0 | |
INNER JOIN civicrm_entity_financial_trxn eft_c ON contribution_civireport.id = eft_c.entity_id AND eft_c.entity_table = 'civicrm_contribution' | |
INNER JOIN civicrm_financial_trxn ft ON eft_c.financial_trxn_id = ft.id | |
INNER JOIN civicrm_entity_financial_trxn eft_fi ON ft.id = eft_fi.financial_trxn_id AND eft_fi.entity_table = 'civicrm_financial_item' | |
INNER JOIN civicrm_financial_item fi ON eft_fi.entity_id = fi.id AND fi.entity_table = 'civicrm_line_item' | |
INNER JOIN civicrm_financial_account fa ON fi.financial_account_id = fa.id | |
WHERE ( contact_civireport.is_deleted = 0 ) AND ( contribution_civireport.contribution_status_id IN (1) ) AND (contribution_civireport.is_test = 0 ) | |
GROUP BY fa.name, contribution_civireport.id | |
HAVING SUM(IF(ISNULL(ft.from_financial_account_id),fi.amount,-fi.amount)) <> 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment