diff --git a/CRM/Grant/BAO/GrantBudget.php b/CRM/Grant/BAO/GrantBudget.php index 027acb8..78770a5 100644 --- a/CRM/Grant/BAO/GrantBudget.php +++ b/CRM/Grant/BAO/GrantBudget.php @@ -3,7 +3,9 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { public static function getFiscalyear() { - return [2018 => 2018]; + $from = date("Y", strtotime(date('Y') . ' - ' . GRANT_SCHOLARSHIP_YEAR_DIFF . ' years')); + $to = date("Y", strtotime(date('Y') . ' + ' . GRANT_SCHOLARSHIP_YEAR_DIFF . ' years')); + return array_combine(range($to, $from), range($to, $from)); } public static function getGrantBudget($params) { @@ -12,12 +14,21 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { $fiscalYear = date('Y'); } $grantBudget = []; - $paidStatusID = 4; - // TODO fix hardcoded values + $paidStatusID = CRM_Core_PseudoConstant::getKey( + 'CRM_Grant_DAO_Grant', + 'status_id', + 'Paid' + ); + + $config = CRM_Core_Config::singleton(); + $mkTime = mktime(0, 0, 0, $config->fiscalYearStart['M'], $config->fiscalYearStart['d'], $fiscalYear); + $fiscalStartDate = date('Y-m-d', $mkTime); + $fiscalEndDate = date('Y-m-d', strtotime($startDate . '+ 1 year')); + $qParams = [ 1 => [$fiscalYear, 'String'], - 2 => ['2018-01-01', 'String'], - 3 => ['2018-12-31', 'String'], + 2 => [$fiscalStartDate, 'String'], + 3 => [$fiscalEndDate, 'String'], 4 => [$paidStatusID, 'Integer'], ]; @@ -36,7 +47,7 @@ class CRM_Grant_BAO_GrantBudget extends CRM_Grant_DAO_GrantBudget { 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.decision_date >= %2 AND cg.decision_date < %3 {$where} GROUP BY cft.id ORDER BY cft.name"; diff --git a/CRM/Grant/Page/AnnualBudgets.php b/CRM/Grant/Page/AnnualBudgets.php index 810cf7e..b341480 100644 --- a/CRM/Grant/Page/AnnualBudgets.php +++ b/CRM/Grant/Page/AnnualBudgets.php @@ -26,7 +26,7 @@ class CRM_Grant_Page_AnnualBudgets extends CRM_Core_Page_Basic { * Browse all Grant Budget. */ public function browse() { - $fiscalYear = NULL; + $fiscalYear = CRM_Utils_Request::retrieve('fiscalYears', 'Positive'); if (empty($fiscalYear)) { $fiscalYear = date('Y'); } diff --git a/annualgrantbudgets.php b/annualgrantbudgets.php index aa59c59..3fa11d1 100644 --- a/annualgrantbudgets.php +++ b/annualgrantbudgets.php @@ -6,6 +6,7 @@ use CRM_Annualgrantbudgets_ExtensionUtil as E; 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); /** * Implements hook_civicrm_config(). * diff --git a/templates/CRM/Grant/Page/AnnualBudgets.tpl b/templates/CRM/Grant/Page/AnnualBudgets.tpl index 80ba8a1..efcf02e 100644 --- a/templates/CRM/Grant/Page/AnnualBudgets.tpl +++ b/templates/CRM/Grant/Page/AnnualBudgets.tpl @@ -6,7 +6,7 @@