diff --git a/CRM/Grant/BAO/GrantBudget.php b/CRM/Grant/BAO/GrantBudget.php index d4ba0a5..ff601f6 100644 --- a/CRM/Grant/BAO/GrantBudget.php +++ b/CRM/Grant/BAO/GrantBudget.php @@ -20,6 +20,8 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { * @return array */ public static function getGrantBudget($params) { + $returnTotals = $params['return_totals']; + $totals = []; $fiscalYear = $params['fiscal_year']; if (empty($fiscalYear)) { $fiscalYear = date('Y'); @@ -86,6 +88,18 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { 'balance_amount' => CRM_Utils_Money::format(($result->budget - $result->total_amount_granted)), 'financial_type_id' => $result->financial_type_id, ]; + if ($returnTotals) { + $totals['budget'] += $result->budget; + $totals['total_amount_granted'] += $result->total_amount_granted; + $totals['balance_amount'] += $result->budget - $result->total_amount_granted; + } + } + if ($returnTotals) { + // Format as money. + foreach ($totals as $k => $v) { + $totals[$k] = CRM_Utils_Money::format($v); + } + return $totals; } return $grantBudget; } diff --git a/api/v3/GrantBudget.php b/api/v3/GrantBudget.php index e745658..7ea41f0 100644 --- a/api/v3/GrantBudget.php +++ b/api/v3/GrantBudget.php @@ -70,4 +70,9 @@ function _civicrm_api3_grant_budget_getbudget_spec(&$spec) { 'title' => ts('Fiscal Year'), 'type' => CRM_Utils_Type::T_INT, ]; + $spec['return_totals'] = [ + 'api.required' => 0, + 'title' => ts('Return Totals?'), + 'type' => CRM_Utils_Type::T_BOOLEAN, + ]; } diff --git a/templates/CRM/Grant/Page/AnnualBudgets.tpl b/templates/CRM/Grant/Page/AnnualBudgets.tpl index 24a8131..95efe42 100644 --- a/templates/CRM/Grant/Page/AnnualBudgets.tpl +++ b/templates/CRM/Grant/Page/AnnualBudgets.tpl @@ -12,6 +12,13 @@