support totals on grant budget screen

This commit is contained in:
Jon Goldberg 2019-08-19 17:06:17 -04:00
parent 956c1e90c6
commit 3534930f22
No known key found for this signature in database
GPG Key ID: C2D2247364F9DB13
3 changed files with 32 additions and 0 deletions

View File

@ -20,6 +20,8 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
* @return array * @return array
*/ */
public static function getGrantBudget($params) { public static function getGrantBudget($params) {
$returnTotals = $params['return_totals'];
$totals = [];
$fiscalYear = $params['fiscal_year']; $fiscalYear = $params['fiscal_year'];
if (empty($fiscalYear)) { if (empty($fiscalYear)) {
$fiscalYear = date('Y'); $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)), 'balance_amount' => CRM_Utils_Money::format(($result->budget - $result->total_amount_granted)),
'financial_type_id' => $result->financial_type_id, '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; return $grantBudget;
} }

View File

@ -70,4 +70,9 @@ function _civicrm_api3_grant_budget_getbudget_spec(&$spec) {
'title' => ts('Fiscal Year'), 'title' => ts('Fiscal Year'),
'type' => CRM_Utils_Type::T_INT, 'type' => CRM_Utils_Type::T_INT,
]; ];
$spec['return_totals'] = [
'api.required' => 0,
'title' => ts('Return Totals?'),
'type' => CRM_Utils_Type::T_BOOLEAN,
];
} }

View File

@ -12,6 +12,13 @@
<th>{ts}Amount Remaining{/ts}</th> <th>{ts}Amount Remaining{/ts}</th>
</thead> </thead>
{crmAPI var='result' entity='GrantBudget' action='getbudget' fiscal_year=$fiscalYear} {crmAPI var='result' entity='GrantBudget' action='getbudget' fiscal_year=$fiscalYear}
{crmAPI var='totals' entity='GrantBudget' action='getbudget' fiscal_year=$fiscalYear return_totals=1}
<tr id="GrantBudget-totals" class="crm-entity">
<td><strong>Totals:</strong></td>
{foreach from=$totals.values item=total}
<td><strong>{$total}</strong></td>
{/foreach}
</tr>
{foreach from=$result.values item=row} {foreach from=$result.values item=row}
{if $row.id} {if $row.id}
{assign var='rowId' value=$row.id} {assign var='rowId' value=$row.id}
@ -25,6 +32,12 @@
<td>{$row.balance_amount}</td> <td>{$row.balance_amount}</td>
</tr> </tr>
{/foreach} {/foreach}
<tr id="GrantBudget-totals" class="crm-entity">
<td><strong>Totals:</strong></td>
{foreach from=$totals.values item=total}
<td><strong>{$total}</strong></td>
{/foreach}
</tr>
</table> </table>
{crmButton p="civicrm" q="reset=1" class="cancel" icon="times"}{ts}Done{/ts}{/crmButton} {crmButton p="civicrm" q="reset=1" class="cancel" icon="times"}{ts}Done{/ts}{/crmButton}
</div> </div>