Use constant
This commit is contained in:
parent
dc36f24333
commit
6559524f46
@ -50,16 +50,18 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
|
||||
}
|
||||
$grantBudgetTableName = CRM_Grant_DAO_GrantBudget::getTableName();
|
||||
$sql = "SELECT cgb.id, cft.name, IFNULL(cgb.budget, 0) AS budget,
|
||||
SUM(IFNULL(cg.amount_granted, 0)) as total_amount_granted,
|
||||
SUM(IFNULL(cg." . GRANT_AMOUNT_CHECK_FIELD . ", 0)) as total_amount_granted,
|
||||
cft.id AS financial_type_id
|
||||
FROM civicrm_financial_type cft
|
||||
INNER JOIN " . GRANT_SCHOLARSHIP_CUSTOM_TABLE_NAME . " gs
|
||||
ON gs.entity_id = cft.id AND gs." . GRANT_SCHOLARSHIP_CUSTOM_FIELD . " = 1
|
||||
ON gs.entity_id = cft.id
|
||||
AND gs." . GRANT_SCHOLARSHIP_CUSTOM_FIELD . " = 1
|
||||
LEFT JOIN " . $grantBudgetTableName . " cgb
|
||||
ON cgb.financial_type_id = cft.id AND cgb.fiscal_year = %1
|
||||
LEFT JOIN civicrm_grant cg
|
||||
ON cg.financial_type_id = cft.id AND cg.status_id IN (%4)
|
||||
AND cg.decision_date >= %2 AND cg.decision_date < %3
|
||||
AND cg." . GRANT_DATE_CHECK_FIELD . " >= %2
|
||||
AND cg." . GRANT_DATE_CHECK_FIELD . " < %3
|
||||
{$where}
|
||||
GROUP BY cft.id
|
||||
ORDER BY cft.name";
|
||||
@ -86,7 +88,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkBudget($params, $grantId) {
|
||||
$year = date('Y', strtotime($params['decision_date']));
|
||||
$year = date('Y', strtotime($params[GRANT_DATE_CHECK_FIELD]));
|
||||
$grantBudget = civicrm_api3('GrantBudget', 'getbudget', [
|
||||
'financial_type_id' => $params['financial_type_id'],
|
||||
'fiscal_year' => $year,
|
||||
@ -95,16 +97,16 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget {
|
||||
$isError = FALSE;
|
||||
if ($grantBudget) {
|
||||
$balanceAmount = CRM_Utils_Rule::cleanMoney($grantBudget['balance_amount']);
|
||||
$amountGranted = CRM_Utils_Rule::cleanMoney($params['amount_granted']);
|
||||
$amountGranted = CRM_Utils_Rule::cleanMoney($params[GRANT_AMOUNT_CHECK_FIELD]);
|
||||
if ($grantId) {
|
||||
$oldGrantValues = civicrm_api3('Grant', 'getsingle', [
|
||||
'return' => ["amount_granted", 'financial_type_id', 'decision_date'],
|
||||
'return' => [GRANT_AMOUNT_CHECK_FIELD, 'financial_type_id', GRANT_DATE_CHECK_FIELD],
|
||||
'id' => $grantId,
|
||||
]);
|
||||
if ($oldGrantValues['financial_type_id'] == $params['financial_type_id']
|
||||
&& $year == date('Y', strtotime($oldGrantValues['decision_date']))
|
||||
&& $year == date('Y', strtotime($oldGrantValues[GRANT_DATE_CHECK_FIELD]))
|
||||
) {
|
||||
$amountGranted -= $oldGrantValues['amount_granted'];
|
||||
$amountGranted -= $oldGrantValues[GRANT_AMOUNT_CHECK_FIELD];
|
||||
}
|
||||
}
|
||||
if ($balanceAmount < $amountGranted) {
|
||||
|
@ -7,6 +7,8 @@ define('GRANT_SCHOLARSHIP_CUSTOM_GROUP', 'grant_scholarship');
|
||||
define('GRANT_SCHOLARSHIP_CUSTOM_FIELD', 'is_grant_scholarship');
|
||||
define('GRANT_SCHOLARSHIP_CUSTOM_TABLE_NAME', 'civicrm_value_grant_scholarship');
|
||||
define('GRANT_SCHOLARSHIP_YEAR_DIFF', 10);
|
||||
define('GRANT_DATE_CHECK_FIELD', 'decision_date');
|
||||
define('GRANT_AMOUNT_CHECK_FIELD', 'amount_granted');
|
||||
/**
|
||||
* Implements hook_civicrm_config().
|
||||
*
|
||||
@ -224,8 +226,8 @@ function annualgrantbudgets_civicrm_validateForm($formName, &$fields, &$files, &
|
||||
if ($formName == 'CRM_Grant_Form_Grant' && !($form->_action & CRM_Core_Action::DELETE)) {
|
||||
if (empty($fields['financial_type_id'])
|
||||
|| empty($fields['status_id'])
|
||||
|| empty($fields['decision_date'])
|
||||
|| empty($fields['amount_granted'])
|
||||
|| empty($fields[GRANT_DATE_CHECK_FIELD])
|
||||
|| empty($fields[GRANT_AMOUNT_CHECK_FIELD])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@ -239,7 +241,7 @@ function annualgrantbudgets_civicrm_validateForm($formName, &$fields, &$files, &
|
||||
}
|
||||
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.");
|
||||
$errors[GRANT_AMOUNT_CHECK_FIELD] = 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