remove hardcoded account relationship ID

This commit is contained in:
Jon Goldberg 2019-06-18 19:12:48 -04:00
parent e00085d701
commit f05a93ddc5
No known key found for this signature in database
GPG Key ID: C2D2247364F9DB13

View File

@ -30,7 +30,11 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
'status_id', 'status_id',
'Paid' 'Paid'
); );
$accountRelationshipId = civicrm_api3('OptionValue', 'getvalue', [
'return' => "value",
'option_group_id' => "account_relationship",
'name' => "Grant Expense Account is",
]);
$config = CRM_Core_Config::singleton(); $config = CRM_Core_Config::singleton();
$mkTime = mktime(0, 0, 0, $config->fiscalYearStart['M'], $config->fiscalYearStart['d'], $fiscalYear); $mkTime = mktime(0, 0, 0, $config->fiscalYearStart['M'], $config->fiscalYearStart['d'], $fiscalYear);
$fiscalStartDate = date('Y-m-d', $mkTime); $fiscalStartDate = date('Y-m-d', $mkTime);
@ -41,6 +45,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
2 => [$fiscalStartDate, 'String'], 2 => [$fiscalStartDate, 'String'],
3 => [$fiscalEndDate, 'String'], 3 => [$fiscalEndDate, 'String'],
4 => [$paidStatusID, 'Integer'], 4 => [$paidStatusID, 'Integer'],
5 => [$accountRelationshipId, 'Integer'],
]; ];
$where = ''; $where = '';
@ -48,6 +53,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
$where = 'WHERE cft.id = %5'; $where = 'WHERE cft.id = %5';
$qParams[5] = [$params['financial_type_id'], 'Integer']; $qParams[5] = [$params['financial_type_id'], 'Integer'];
} }
$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(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 . " >= %2
AND cg." . GRANT_DATE_CHECK_FIELD . " < %3 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 = 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 LEFT JOIN civicrm_financial_trxn trxn ON trxn.from_financial_account_id = cefa.financial_account_id
{$where} {$where}
GROUP BY cft.id GROUP BY cft.id