Scheduled reports - Every month instead of every 4 weeks

Hello,

My problem is simple : we want to schedule a report to be send every month and not every 4 weeks.

I am sure we are not the only one to face this issue but, today, I don't find an easy well to solve it.

Best wishes,

Fred

Parents Reply Children
  • I gave this some more thought... 

    The interval used in calculating the getNextRunDate is an integer, a number of seconds, so it's useless for what you are trying to do.

    As you said, the logical thing would be to extend or override the getNextRunDate.

    I do NOT think this will work well at all but I'll share anyway just as a fun discussion:

    The only way I can think of to try and modify the getNextRunDate:

    Add a custom dropdown field to the ReportSchedules module to override the interval. Tricky because ReportSchedules are not in Studio, so you would have to do so in code, potentially not part of the Extension Framework?

    Let's call the field something like RepeatTypeOverride to make it obvious.

    Define a new dropdown with the values you need, something like: 

    "FDM" => "Each First Day of the Month",

    "LDM" => "Each Last Day of the Month"

    extend the getNextRunDate method in the ReportSchedule class within the framework - and I don't know if you can - to check if RepeatTypeOverride has a value, if it does then see what it is and do the calculation to update the time_interval to whatever number of of seconds until the next desired run

    It's clunky but it might work...

    So if FDM, something like:

    $d = new DateTime();
    $date = $d->modify( 'first day of next month' );
    echo $date->format('Y-m-d H:i:s');

    Will give you the date timestamp of this time on the first of next month.

    It's then a question of calculating the number of seconds between that date-timestamp and the current date-timestamp and using that to update the interval... 

    You should probably also extend the save method to set the appropriate time interval when the scheduler is first saved or updated, else the first run will not be what might be expected.

    As I said, it's clunky... very clunky...

    Good Luck, I look forward to seeing if you find a solution.

    FrancescaS