From f05a93ddc51cb7f51d902b14d3b8f4158865bc45 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Tue, 18 Jun 2019 19:12:48 -0400 Subject: [PATCH] remove hardcoded account relationship ID --- CRM/Grant/BAO/GrantBudget.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CRM/Grant/BAO/GrantBudget.php b/CRM/Grant/BAO/GrantBudget.php index 11eb86e..1c412b5 100644 --- a/CRM/Grant/BAO/GrantBudget.php +++ b/CRM/Grant/BAO/GrantBudget.php @@ -30,7 +30,11 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { 'status_id', 'Paid' ); - + $accountRelationshipId = civicrm_api3('OptionValue', 'getvalue', [ + 'return' => "value", + 'option_group_id' => "account_relationship", + 'name' => "Grant Expense Account is", + ]); $config = CRM_Core_Config::singleton(); $mkTime = mktime(0, 0, 0, $config->fiscalYearStart['M'], $config->fiscalYearStart['d'], $fiscalYear); $fiscalStartDate = date('Y-m-d', $mkTime); @@ -41,6 +45,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { 2 => [$fiscalStartDate, 'String'], 3 => [$fiscalEndDate, 'String'], 4 => [$paidStatusID, 'Integer'], + 5 => [$accountRelationshipId, 'Integer'], ]; $where = ''; @@ -48,6 +53,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { $where = 'WHERE cft.id = %5'; $qParams[5] = [$params['financial_type_id'], 'Integer']; } + $grantBudgetTableName = CRM_Grant_DAO_GrantBudget::getTableName(); $sql = "SELECT cgb.id, cft.name, IFNULL(cgb.budget, 0) AS budget, SUM(IFNULL(trxn." . GRANT_AMOUNT_CHECK_FIELD . ", 0)) as total_amount_granted, @@ -63,7 +69,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { AND cg." . GRANT_DATE_CHECK_FIELD . " >= %2 AND cg." . GRANT_DATE_CHECK_FIELD . " < %3 LEFT JOIN civicrm_entity_financial_account cefa - ON cefa.entity_table = 'civicrm_financial_type' AND cft.id = cefa.entity_id AND account_relationship = 14 + 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 {$where} GROUP BY cft.id