Fix incorrect calculation of grant budgets over multiple years
This commit is contained in:
parent
0edd576388
commit
836c86c042
@ -56,7 +56,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
|
|||||||
|
|
||||||
$grantBudgetTableName = CRM_Grant_DAO_GrantBudget::getTableName();
|
$grantBudgetTableName = CRM_Grant_DAO_GrantBudget::getTableName();
|
||||||
$sql = "SELECT cgb.id, cft.name, IFNULL(cgb.budget, 0) AS budget,
|
$sql = "SELECT cgb.id, cft.name, IFNULL(cgb.budget, 0) AS budget,
|
||||||
SUM(IFNULL(trxn." . GRANT_AMOUNT_CHECK_FIELD . ", 0)) as total_amount_granted,
|
SUM(CASE WHEN cg.id IS NULL THEN 0 ELSE IFNULL(trxn.total_amount, 0) END) as total_amount_granted,
|
||||||
cft.id AS financial_type_id
|
cft.id AS financial_type_id
|
||||||
FROM civicrm_financial_type cft
|
FROM civicrm_financial_type cft
|
||||||
INNER JOIN " . GRANT_SCHOLARSHIP_CUSTOM_TABLE_NAME . " gs
|
INNER JOIN " . GRANT_SCHOLARSHIP_CUSTOM_TABLE_NAME . " gs
|
||||||
@ -64,13 +64,14 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
|
|||||||
AND gs." . GRANT_SCHOLARSHIP_CUSTOM_FIELD . " = 1
|
AND gs." . GRANT_SCHOLARSHIP_CUSTOM_FIELD . " = 1
|
||||||
LEFT JOIN " . $grantBudgetTableName . " cgb
|
LEFT JOIN " . $grantBudgetTableName . " cgb
|
||||||
ON cgb.financial_type_id = cft.id AND cgb.fiscal_year = %1
|
ON cgb.financial_type_id = cft.id AND cgb.fiscal_year = %1
|
||||||
LEFT JOIN civicrm_grant cg
|
|
||||||
ON cg.financial_type_id = cft.id AND cg.status_id IN (%4)
|
|
||||||
AND cg." . GRANT_DATE_CHECK_FIELD . " >= %2
|
|
||||||
AND cg." . GRANT_DATE_CHECK_FIELD . " < %3
|
|
||||||
LEFT JOIN civicrm_entity_financial_account cefa
|
LEFT JOIN civicrm_entity_financial_account cefa
|
||||||
ON cefa.entity_table = 'civicrm_financial_type' AND cft.id = cefa.entity_id AND account_relationship = %5
|
ON cefa.entity_table = 'civicrm_financial_type' AND cft.id = cefa.entity_id AND account_relationship = %5
|
||||||
LEFT JOIN civicrm_financial_trxn trxn ON trxn.from_financial_account_id = cefa.financial_account_id
|
LEFT JOIN civicrm_financial_trxn trxn ON trxn.from_financial_account_id = cefa.financial_account_id
|
||||||
|
LEFT JOIN civicrm_entity_financial_trxn ceft on trxn.id = ceft.financial_trxn_id AND ceft.entity_table = 'civicrm_grant'
|
||||||
|
LEFT JOIN civicrm_grant cg
|
||||||
|
ON cg.id = ceft.entity_id AND cg.status_id IN (%4)
|
||||||
|
AND cg." . GRANT_DATE_CHECK_FIELD . " >= %2
|
||||||
|
AND cg." . GRANT_DATE_CHECK_FIELD . " < %3
|
||||||
{$where}
|
{$where}
|
||||||
GROUP BY cft.id
|
GROUP BY cft.id
|
||||||
ORDER BY cft.name";
|
ORDER BY cft.name";
|
||||||
|
Loading…
Reference in New Issue
Block a user