Use constant

This commit is contained in:
2018-08-12 05:47:25 +05:30
parent dc36f24333
commit 6559524f46
2 changed files with 15 additions and 11 deletions

View File

@ -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) {