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 CiviMember (Moderator: Deepak Srivastava) »
  • Prorating memberships
Pages: 1 [2]

Author Topic: Prorating memberships  (Read 7191 times)

jackrabbithanna

  • I post occasionally
  • **
  • Posts: 61
  • Karma: 3
  • Quick like bunny
    • http://www.skvare.com
  • CiviCRM version: 4.3.5
  • CMS version: Drupal 7.23
  • MySQL version: 5.1
  • PHP version: 5.3.3
Re: Prorating memberships
February 09, 2013, 01:13:54 pm
Just thought I'd post my solution for changing membership end dates.  In my previous code I had a function to prorate the membership dues on a daily basis. My customer wanted 2 billing periods...Dec1-May31 and June1-Nov30. This function sets the end date to either May31 or Nov30 depending on the period of the current date.  Implementing hook_civicrm_pre

@Lobo....this should work right? with having 6-month rolling period membership types, changing the end date should allow the current civicrm membership logic to then start billing automatically on a recurring basis for all members on Dec1 and June1???

You will have to look at your $params array to find the source you want to use...I had a membership contrib page titled 'Membership Signup'
you could take that if statement out which checks $params['source'] for a particular source and this function would act on all memberships created globally.

Code: [Select]
function mycustommodule_civicrm_pre( $op, $objectName, $id, &$params ){

  if($op=='create' && $objectName=='Membership'){
  if($params['source']=='Online Contribution: Membership Signup'){
  $today = getdate();
$current_day_in_year = $today['yday'];
$june1 = getdate(strtotime($today['year']. '-06-01'));
  $dec1 = getdate(strtotime($today['year']. '-12-01'));
$june1_day_in_year = $june1['yday'];
  $dec1_day_in_year = $dec1['yday'];
$today_year = $today['year'];
    $next_year = (int)$today_year + 1;



if($current_day_in_year < $june1_day_in_year) {
$params['end_date'] = $today_year. '0531';

}

if($current_day_in_year > $june1_day_in_year && $current_day_in_year < $dec1_day_in_year) {
$params['end_date'] = $today_year . '1130';
}

if($current_day_in_year > $dec1_day_in_year) {

$params['end_date'] = $next_year . '0531';
}

if($current_day_in_year == $june1_day_in_year) { 

}
 
if($current_day_in_year ==  $dec1_day_in_year) {

}
}
}

}

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Prorating memberships

This forum was archived on 2017-11-26.