0

I checked the awesome Summary Fields extension and the Advanced Fundraising Reports one but neither seem to quite offer this.

I could do this as a Drupal View but that won't give me the full suite of 'Actions' that might be required.

0

If Summary Fields does not have the fields you need, it's pretty easy to add your own using hook_civicrm_sumfields_definitions()

Try dropping something like this into an extension:

/**
 * Implements hook_civicrm_sumfields_definitions().
 *
 */
function myextension_civicrm_sumfields_definitions(&$custom) {
  $custom['fields']['contribution_count_twelve_months'] = array(
    'label' => 'Count of Contributions in last 12 months',
    'data_type' => 'Int',
    'html_type' => 'Text',
    'weight' => '15',
    'text_length' => '32',
    'trigger_sql' => '(
      SELECT COALESCE(COUNT(id), 0) 
      FROM civicrm_contribution t1
      WHERE t1.contact_id = NEW.contact_id AND t1.contribution_status_id = 1 AND
      t1.financial_type_id IN (%financial_type_ids) AND 
      CAST(receive_date AS DATE) BETWEEN DATE_SUB(NOW(), INTERVAL 12 MONTH) AND NOW()
      )',
    'trigger_table' => 'civicrm_contribution',
    'optgroup' => 'fundraising',
  );
}

Tweak the trigger_sql for your preferred time interval.

See the Readme for more info.

1
  • Many thanks Aidan - this is the route we will likely go assuming there is nothing already around. Appreciate the effort put in to providing a useable answer
    – petednz - fuzion
    Jan 26 '18 at 19:42
0

We did create additional Summary Fields to cover 1 Apr - Mar 31, and for July 1 - June 30. We then found out that by setting the Financial Year field in civicrm/admin/setting/date?reset=1 to the correct date had the desired outcome.

We therefore made a PR for the extension to improve the documentation to avoid this catching out others unaware.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.