support totals on grant budget screen
This commit is contained in:
parent
956c1e90c6
commit
3534930f22
@ -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;
|
||||
}
|
||||
|
@ -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,
|
||||
];
|
||||
}
|
||||
|
@ -12,6 +12,13 @@
|
||||
<th>{ts}Amount Remaining{/ts}</th>
|
||||
</thead>
|
||||
{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}
|
||||
{if $row.id}
|
||||
{assign var='rowId' value=$row.id}
|
||||
@ -25,6 +32,12 @@
|
||||
<td>{$row.balance_amount}</td>
|
||||
</tr>
|
||||
{/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>
|
||||
{crmButton p="civicrm" q="reset=1" class="cancel" icon="times"}{ts}Done{/ts}{/crmButton}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user