rewrite budget screen to be multifund-aware

This commit is contained in:
Jon Goldberg 2019-06-18 18:56:47 -04:00
parent 75cee740f7
commit e00085d701
No known key found for this signature in database
GPG Key ID: C2D2247364F9DB13
2 changed files with 32 additions and 26 deletions

View File

@ -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";

View File

@ -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.");
// }
// }
//}