CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Can Contribution Dashboard show Fiscal not Calendar Years
Pages: [1]

Author Topic: Can Contribution Dashboard show Fiscal not Calendar Years  (Read 829 times)

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Can Contribution Dashboard show Fiscal not Calendar Years
February 15, 2013, 06:06:12 am
Hi,

I'm interested in how to get the Contribution Dashboard to display Fiscal Years as opposed to Calendar Years.  Can this be done?

Thanks, Henry

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Can Contribution Dashboard show Fiscal not Calendar Years
February 15, 2013, 08:54:51 am

what happens when you set the fiscal year in CiviCRM? does it change the contribution dashboard

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: Can Contribution Dashboard show Fiscal not Calendar Years
February 15, 2013, 09:12:18 am
Sorry - should of said that was the first place I checked.  Assuming that you mean [localization] [Dates] [Fiscal Year Start] I've already got that set to 1st October. 

Charts still collates on calendar rather than fiscal year. 
« Last Edit: February 15, 2013, 02:18:41 pm by speleo »

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: Can Contribution Dashboard show Fiscal not Calendar Years
February 16, 2013, 03:12:50 am
A little investigation shows that the data is pulled using the following function from CRM_Contribute_BAO_Contribution_Utils

Code: [Select]
/**
   * Function to get the contribution details by year
   *
   * @return array associated array
   *
   * @static
   * @access public
   */
  static function contributionChartYearly() {
    $query = '
    SELECT   sum(contrib.total_amount) AS ctAmt,
             year(contrib.receive_date) as contribYear
      FROM   civicrm_contribution AS contrib
INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     WHERE   ( contrib.is_test = 0 OR contrib.is_test IS NULL )
       AND   contrib.contribution_status_id = 1
       AND   contact.is_deleted = 0
  GROUP BY   contribYear
  ORDER BY   contribYear';
    $dao = CRM_Core_DAO::executeQuery($query);

    $params = NULL;
    while ($dao->fetch()) {
      if (!empty($dao->contribYear)) {
        $params['By Year'][$dao->contribYear] = $dao->ctAmt;
      }
    }
    return $params;
  }

There must be a quick way to change the date params to fiscal period.

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: Can Contribution Dashboard show Fiscal not Calendar Years
February 17, 2013, 11:47:21 am
ok - if we update CRM_Contribute_BAO_Contribution_Utils with the below:

Code: [Select]
/**
   * Function to get the contribution details by year
   *
   * @return array associated array
   *
   * @static
   * @access public
   */
  static function contributionChartYearly() {
    $config = CRM_Core_Config::singleton();
    $query = "SELECT   sum(contrib.total_amount) AS ctAmt,
  CASE WHEN DAYOFYEAR(contrib.receive_date)>=".
  date('z',mktime(0, 0, 0, $config->fiscalYearStart['M'], $config->fiscalYearStart['d']+1, 2000)).
  " THEN
          concat(YEAR(contrib.receive_date), '-',YEAR(contrib.receive_date)+1)
   ELSE concat(YEAR(contrib.receive_date)-1,'-', YEAR(contrib.receive_date)) END AS contribYear
      FROM   civicrm_contribution AS contrib
INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     WHERE   ( contrib.is_test = 0 OR contrib.is_test IS NULL )
       AND   contrib.contribution_status_id = 1
       AND   contact.is_deleted = 0
  GROUP BY   contribYear
  ORDER BY   contribYear";

    $dao = CRM_Core_DAO::executeQuery($query);

    $params = NULL;
    while ($dao->fetch()) {
      if (!empty($dao->contribYear)) {
        $params['By Year'][$dao->contribYear] = $dao->ctAmt;
      }
    }
    return $params;
  }

then we get the chart showing fiscal years.  However the horizontal labels on the chart are now too long and I can't see where to rotate them. 


speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
FIXED: Can Contribution Dashboard show Fiscal not Calendar Years
February 25, 2013, 07:13:59 am
Fixed the display issues and chart logic.

Issue raised CRM-11970  http://issues.civicrm.org/jira/browse/CRM-11970

update CRM_Contribute_BAO_Contribution_Utils with the below:
Code: [Select]
/**
   * Function to get the contribution details by year
   *
   * @return array associated array
   *
   * @static
   * @access public
   */
  static function contributionChartYearly() {
    $config = CRM_Core_Config::singleton();

    $query = '
    SELECT   sum(contrib.total_amount) AS ctAmt,';

    if ($config->fiscalYearStart['M'] == 1 && $config->fiscalYearStart['d'] == 1) {
    $query = $query.'
             year(contrib.receive_date) as contribYear';
    } else {
    $query = $query."
      CASE WHEN DAYOFYEAR(contrib.receive_date)>=".
  date('z',mktime(0, 0, 0, $config->fiscalYearStart['M'], $config->fiscalYearStart['d']+1, 2000)).
  " THEN
           concat(YEAR(contrib.receive_date), '-',YEAR(contrib.receive_date)+1)
      ELSE concat(YEAR(contrib.receive_date)-1,'-', YEAR(contrib.receive_date)) END AS contribYear";
    }

    $query = $query."
      FROM   civicrm_contribution AS contrib
INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     WHERE   ( contrib.is_test = 0 OR contrib.is_test IS NULL )
       AND   contrib.contribution_status_id = 1
       AND   contact.is_deleted = 0
  GROUP BY   contribYear
  ORDER BY   contribYear";

    $dao = CRM_Core_DAO::executeQuery($query);

    $params = NULL;
    while ($dao->fetch()) {
      if (!empty($dao->contribYear)) {
        $params['By Year'][$dao->contribYear] = $dao->ctAmt;
      }
    }
    return $params;
  }

and modify CRM/Contribute/Form/ContributionCharts.php as below (have also uploaded the modified file)

89              $years[$k] = $k;
------------------------------------------------------------------------
    89          $years[substr($k,0,4)] = substr($k,0,4);
------------------------------------------------------------------------
------------------------------------------------------------------------
    109     $config = CRM_Core_Config::singleton();
------------------------------------------------------------------------
------------------------------------------------------------------------
174             $yearlyChart = TRUE;
------------------------------------------------------------------------
    175               $yearlyChart = TRUE;
    176               if ($config->fiscalYearStart['M'] == 1 && $config->fiscalYearStart['d'] == 1) {
    177                       $values['xLabelAngle'] = 0 ;
    178               } else {
    179                       $values['xLabelAngle'] = 45 ;
    180               }
------------------------------------------------------------------------

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Can Contribution Dashboard show Fiscal not Calendar Years

This forum was archived on 2017-11-26.