forked from CiviWare/org.agbu.annualgrantbudgets
added validation
This commit is contained in:
@ -237,18 +237,9 @@ function annualgrantbudgets_civicrm_validateForm($formName, &$fields, &$files, &
|
||||
if ($paidStatusID != $fields['status_id']) {
|
||||
return;
|
||||
}
|
||||
$year = date('Y', strtotime($fields['decision_date']));
|
||||
$grantBudget = civicrm_api3('GrantBudget', 'getbudget', [
|
||||
'financial_type_id' => $fields['financial_type_id'],
|
||||
'fiscal_year' => $year,
|
||||
]);
|
||||
$grantBudget = reset($grantBudget['values']);
|
||||
if ($grantBudget && !empty($grantBudget['id'])) {
|
||||
$balanceAmount = CRM_Utils_Rule::cleanMoney($grantBudget['balance_amount']);
|
||||
$amountGranted = CRM_Utils_Rule::cleanMoney($fields['amount_granted']);
|
||||
if ($balanceAmount < $amountGranted) {
|
||||
$errors['amount_granted'] = ts("The annual budget for this grant is {$grantBudget['budget']}. Grants totaling {$grantBudget['total_amount_granted']} have been made. {$grantBudget['balance_amount']} remains.");
|
||||
}
|
||||
list($isError, $grantBudget) = CRM_Grant_BAO_GrantBudget::checkBudget($fields, $form->getVar('_id'));
|
||||
if ($isError) {
|
||||
$errors['amount_granted'] = ts("The annual budget for this grant is {$grantBudget['budget']}. Grants totaling {$grantBudget['total_amount_granted']} have been made. {$grantBudget['balance_amount']} remains.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user