diff --git a/CRM/Grant/BAO/GrantBudget.php b/CRM/Grant/BAO/GrantBudget.php index f87d42e..11eb86e 100644 --- a/CRM/Grant/BAO/GrantBudget.php +++ b/CRM/Grant/BAO/GrantBudget.php @@ -50,7 +50,7 @@ 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." . GRANT_AMOUNT_CHECK_FIELD . ", 0)) as total_amount_granted, + SUM(IFNULL(trxn." . 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 @@ -62,6 +62,9 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { ON cg.financial_type_id = cft.id AND cg.status_id IN (%4) AND cg." . GRANT_DATE_CHECK_FIELD . " >= %2 AND cg." . GRANT_DATE_CHECK_FIELD . " < %3 + LEFT JOIN civicrm_entity_financial_account cefa + ON cefa.entity_table = 'civicrm_financial_type' AND cft.id = cefa.entity_id AND account_relationship = 14 + LEFT JOIN civicrm_financial_trxn trxn ON trxn.from_financial_account_id = cefa.financial_account_id {$where} GROUP BY cft.id ORDER BY cft.name"; diff --git a/annualgrantbudgets.php b/annualgrantbudgets.php index 1040e72..ef62106 100644 --- a/annualgrantbudgets.php +++ b/annualgrantbudgets.php @@ -7,8 +7,9 @@ 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', 'money_transfer_date'); -define('GRANT_AMOUNT_CHECK_FIELD', 'amount_granted'); +define('GRANT_DATE_CHECK_FIELD', 'decision_date'); +define('GRANT_AMOUNT_CHECK_FIELD', 'total_amount'); + /** * Implements hook_civicrm_config(). * @@ -221,26 +222,28 @@ function annualgrantbudgets_civicrm_apiWrappers(&$wrappers, $apiRequest) { * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_validateForm * */ -function annualgrantbudgets_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) { - if ($formName == 'CRM_Grant_Form_Grant' && !($form->_action & CRM_Core_Action::DELETE)) { - if (empty($fields['financial_type_id']) - || empty($fields['status_id']) - || empty($fields[GRANT_DATE_CHECK_FIELD]) - || empty($fields[GRANT_AMOUNT_CHECK_FIELD]) - ) { - return; - } - $paidStatusID = CRM_Core_PseudoConstant::getKey( - 'CRM_Grant_DAO_Grant', - 'status_id', - 'Paid' - ); - if ($paidStatusID != $fields['status_id']) { - return; - } - list($isError, $grantBudget) = CRM_Grant_BAO_GrantBudget::checkBudget($fields, $form->getVar('_id')); - if ($isError) { - $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."); - } - } -} +// //This whole validation needs rewriting. +//function annualgrantbudgets_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) { +// if ($formName == 'CRM_Grant_Form_Grant' && !($form->_action & CRM_Core_Action::DELETE)) { +// if (empty($fields['financial_type_id']) +// || empty($fields['status_id']) +// || empty($fields[GRANT_DATE_CHECK_FIELD]) +// || empty($fields[GRANT_AMOUNT_CHECK_FIELD]) +// ) { +// return; +// } +// $paidStatusID = CRM_Core_PseudoConstant::getKey( +// 'CRM_Grant_DAO_Grant', +// 'status_id', +// 'Paid' +// ); +// if ($paidStatusID != $fields['status_id']) { +// return; +// } +// +// list($isError, $grantBudget) = CRM_Grant_BAO_GrantBudget::checkBudget($fields, $form->getVar('_id')); +// if ($isError) { +// $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."); +// } +// } +//}