don't double-count grant when editing a grant
This commit is contained in:
parent
cf1a4923bc
commit
956c1e90c6
@ -113,6 +113,20 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
|
|||||||
if ($grantBudget) {
|
if ($grantBudget) {
|
||||||
$balanceAmount = CRM_Utils_Rule::cleanMoney($grantBudget['balance_amount']);
|
$balanceAmount = CRM_Utils_Rule::cleanMoney($grantBudget['balance_amount']);
|
||||||
$amountGranted = CRM_Utils_Rule::cleanMoney($params['multifund_amount'][$k]);
|
$amountGranted = CRM_Utils_Rule::cleanMoney($params['multifund_amount'][$k]);
|
||||||
|
// If there's a $grantId, we're updating an existing grant. Make sure we don't
|
||||||
|
// double-count this money on validation.
|
||||||
|
if ($grantId) {
|
||||||
|
$oldGrantLineItem = civicrm_api3('EntityFinancialTrxn', 'get', [
|
||||||
|
'sequential' => 1,
|
||||||
|
'return' => ["financial_trxn_id.total_amount", "financial_trxn_id.trxn_date"],
|
||||||
|
'entity_table' => "civicrm_grant",
|
||||||
|
'entity_id' => $grantId,
|
||||||
|
'financial_trxn_id.from_financial_account_id' => $financialAccount,
|
||||||
|
])['values'][0];
|
||||||
|
if ($oldGrantLineItem && $year == date('Y', strtotime($oldGrantLineItem['financial_trxn_id.trxn_date']))) {
|
||||||
|
$amountGranted -= $oldGrantLineItem['financial_trxn_id.total_amount'];
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($balanceAmount < $amountGranted) {
|
if ($balanceAmount < $amountGranted) {
|
||||||
$errors["multifund_amount[$k]"] = ts("The annual budget for this grant is {$grantBudget['budget']}. Grants totaling {$grantBudget['total_amount_granted']} have been made. {$grantBudget['balance_amount']} remains.");
|
$errors["multifund_amount[$k]"] = ts("The annual budget for this grant is {$grantBudget['budget']}. Grants totaling {$grantBudget['total_amount_granted']} have been made. {$grantBudget['balance_amount']} remains.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user