Author Topic: Multiple renewal notices?  (Read 16295 times)

Offline annaleevk

  • I post occasionally
  • **
  • Posts: 87
  • Karma: 3
  • Carpe Noctem!
    • Women in Development, New York
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.1.48
  • PHP version: 5.2.14
Re: Multiple renewal notices?
« Reply #15 on: November 27, 2011, 02:42:33 pm »
Dave,

We are testing a program which sends up to 7 reminders to our members, however, we ran into a bad snag which we just caught 4 days into implementation.  Basically, the program is designed to check the expire date and set a reminder date based on the following rules.  Then the reminders are sent out based on the reminder date.

90 days before expire
60 days before expire
30 days before expire
on expire
30 days after expire
60 days after expire
90 days after expire

The snag we ran into is that it appears that the UpdateMembershipRecord.php program which runs right before this program is resetting the Reminder Date to NULL when it changes the Member Status even though we are not using the renewal reminders features within the member types.  These are all set to NULL.

Do you know why and where this is happening and how we can skip over this bit of code so our program can run as intended.  We discovered that it was happily setting reminder dates and then when it hits the status update, it sets the reminder date to null and so the first reminder date gets set all over again and folks are getting way more reminders than intended.

Thanks,
Annalee
Annalee Van Kleeck
Lyric Systems, LLC
201 951.8711
annalee@lyricsystems.com

Offline Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Multiple renewal notices?
« Reply #16 on: November 28, 2011, 10:00:28 am »
Check lines 258-9 in UpdateMembershipRecord.php

Code: [Select]
//set membership reminder date to NULL since we've sent the reminder.
                        CRM_Core_DAO::setFieldValue( 'CRM_Member_DAO_Membership', $dao->membership_id, 'reminder_date', 'null');

HOWEVER, that code SHOULD only be executed if the membership type has a non-NULL value for renewal_msg_id or autorenewal_msg_id - which you said was not the case.  ??? You may need to add some debug code in the script to see what's happening (after verifying the values in your civicrm_membership_type table).
Protect your investment in CiviCRM by  becoming a Member!

Offline annaleevk

  • I post occasionally
  • **
  • Posts: 87
  • Karma: 3
  • Carpe Noctem!
    • Women in Development, New York
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.1.48
  • PHP version: 5.2.14
Re: Multiple renewal notices?
« Reply #17 on: November 29, 2011, 05:35:43 am »
Thanks, Dave and yes, the membership_type table values are all set to NULL so this should not be happening.  Because we need to resolve this issue immediately, we have decided not to use the reminder date field at all to generate the notices.  The effort# will be calculated at the time the program runs (daily) based on the expire date alone.  There are a few other issues we have been wrestling with re: membership scripts so we will try to investigate further when we have time.
Annalee Van Kleeck
Lyric Systems, LLC
201 951.8711
annalee@lyricsystems.com

Offline fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: Multiple renewal notices?
« Reply #18 on: February 07, 2012, 12:44:19 pm »
I've started to work on this which is also a MIH campaign: http://civicrm.org/mih#multremind

Not sure if others have already started working on this (which is part of the reason I'm writing here) - I have attached a diff to UpdateMembershipRecord.php that - if run on a daily cron job - will send out three reminders ($this->reminder_dates = array(45,15,0);).

Updates would include:
 * support different reminder templates per reminder
 * create a UI for setting reminder dates (and templates)
 * support proper operations when cron is not run daily

Offline Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Multiple renewal notices?
« Reply #19 on: February 07, 2012, 02:34:38 pm »
Fen and others who might be looking for this functionality - Yashodha is working on an implementation for this which will be part of the 4.2 release.

http://issues.civicrm.org/jira/browse/CRM-8359

This approach is leveraging the existing Scheduled Reminders functionality (available for Events in 4.1).

Also a heads-up that UpdateMembershipRecord.php along with all the other command line scripts are deprecated in 4.1 - replaced with the Scheduled Jobs / Consolidated Cron feature:

http://wiki.civicrm.org/confluence/display/CRMDOC41/Managing+Scheduled+Jobs

The logic from UpdateMembershipRecord has been moved into a BAO function.
Protect your investment in CiviCRM by  becoming a Member!

Offline annaleevk

  • I post occasionally
  • **
  • Posts: 87
  • Karma: 3
  • Carpe Noctem!
    • Women in Development, New York
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.1.48
  • PHP version: 5.2.14
Re: Multiple renewal notices - sharing some custom code
« Reply #20 on: February 09, 2012, 01:08:40 pm »
Hi!  Wanted to share the membership reminders program that we are using in case it's helpful to the cause.  It's a hack that my brother wrote for me to send 7 renewal emails based on their expire date.  We bypass the reminder feature in membertype and do not use any of the reminder fields.  We use CiviMail and the message templates to send the emails but otherwise, this is a separate program which runs after the UpdateMembershipRecord.php script.  It also has some additional membership parameters like expire date and member type which we merge into the email to personalize it.

NOTE:  The membership reminders.txt file is a zip file.  Rename it to .zip and unzip it.  This is the code.

In a nutshell, this program provides the following:

Supports up to 7 renewal reminder emails to be sent based on their expire date.  NOTE:  The program provides parameters that can be changed to support a smaller or larger number of reminders but it must be an odd number, i.e., 3, 5, 7, etc.
Calculates which reminder letter to send based on their expire date.  Calculated nightly.  Nothing is stored.
Provides the ability to produce reminders that may have been missed should the cron job fail or the server go down.  A simulation mode that tells the computer which set of dates to run the program for.
Provides a way to test the program in simulation mode and not send emails but generate the log so you can see what would have been sent.
Logs an activity record of each email sent with the text content saved and the # of the renewal reminder stored in the description.

I've attached the code we are using.  Here's how to use it.  I've attached my documentation which is written more for the user than the programmer but it may help explain the concepts.

1.  Setup your member types in CiviCRM.  Find out the member type ids.  You will need to put these in the SendReminder.php file.  Do not use the reminder fields within member type setup.
2.  Setup your message templates in CiviMail.  Find out the template ids.  Keep these handy for the program.
3.  To Find the Ids, roll your mouse over the Edit button next to the template or member type.  Look at the bottom of your browser window in the status bar for the url link.  Look for something that says update&id=  The number after the equal sign is your ID.
4.  Rename the membership reminders.txt file to membership reminders.zip and copy it into sites/all/modules/civicrm/bin and unzip it.  You should have the following files:  SendReminder.php, VKutil.php and Arg.php.
5.  Open the SendReminder.php in a text editor and CHANGE the following lines to run this in test mode.

LINE 166:  define ("SIMULATE_DATES", false);  Set this to true to run in simulation mode.
LINE 170-175:  Set the date range to run the simulation.
LINE 183:  define ("SEND_MAIL", true);  Set this to false to NOT SEND EMAILS.  It will create output to your screen but it will not make any changes to your database.

LINES 202-203:  This is where you set how many reminders to send and how many days between reminders.  Read the notes above carefully.  The current settings are set up for 7 reminders.
LINE 204: define ("FROM_EMAIL", '"Membership at YourSite" <membership@yoursite.org>');  Change this to whatever email address you want to use for your org.

LINE 217: define ("INCLUDED_MEMBERSHIP_TYPE_IDS", "1, 2, 3");  This is where you specify your member type ids.
LINE 272:     $ids = array(45, 46, 47, 48, 49, 50, 51);  This is where you specify your message template ids.

To run this program in test in a browser use this string and replace with your sitename, username, password and site key.

http://www.yoursite.com/sites/all/modules/civicrm/bin/SendReminder.php?name=USERNAME&pass=PASSWORD&key=SITE_KEY

6.  Create a cronjob to run this program nightly AFTER the UpdateMembershipRecord.php program once you've tested it thoroughly and change the settings above to take it out of test mode and run it for real.

7.  I've attached a sample reminder so you can see how it looks and the parameter fields used.

Contact me if you have any questions or issues.  It's not perfect but it works....:-)

- Annalee

P.S. - We are currently running this on Drupal 6.22/CiviCRM 3.4.5.
Annalee Van Kleeck
Lyric Systems, LLC
201 951.8711
annalee@lyricsystems.com

Offline sjthespian

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 3
    • The League of Professional System Administrators
  • CiviCRM version: 4.2.7
  • CMS version: Drupal 6.28
  • MySQL version: 5.1.66
  • PHP version: 5.3.3
Re: Multiple renewal notices?
« Reply #21 on: March 26, 2012, 09:30:18 am »
Has anyone else done this patch for 4.1? I'm assuming that the same patch will work if installed into CRM/Member/BAO/Membership.php, does that sound right?
Dan Rich <drich@lopsa.org>
    Director, LOPSA - http://lopsa.org/

Offline Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Multiple renewal notices?
« Reply #22 on: March 26, 2012, 09:59:44 am »
Related note - this functionality is on track for being added to core for 4.2. You can help make it happen here:
http://civicrm.org/participate/mih#multremind
Protect your investment in CiviCRM by  becoming a Member!

Offline fen

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 13
    • CivicActions
  • CiviCRM version: 3.3-4.3
  • CMS version: Drupal 6/7
  • MySQL version: 5.1/5.5
  • PHP version: 5.3/5.4
Re: Multiple renewal notices?
« Reply #23 on: March 26, 2012, 05:42:11 pm »
Excellent!  In the short term, the script by @annaleevk several comments above works.  My client is on v3.3 and is not willing to upgrade to 4.x anytime soon, so I'll probbaly have to stick with this script for a while.  But as the release of the new functionality nears, I may be able to help with testing.