AOR - "Last Month" period variable returns current month's start date

Hi there, I was just looking into the AOR reports module and noticed that the period variable “last_month” returns the current month’s start date. Looking at the SQL query executed when I’m filtering with a condition of GREATER THAN OR EQUAL TO - PERIOD - LAST MONTH, this is the following query that is generated

Query:SELECT `tasks`.id AS 'tasks_id', `tasks`.assigned_user_id AS 'Assigned_to0', `tasks`.status AS 'Status1', `tasks`.date_start AS 'Start_Date2', `tasks`.date_due AS 'Due_Date3' FROM `tasks`  WHERE ( `tasks`.status = 'Completed' AND ( `tasks`.date_start >= "2016-03-01 00:00:00" ) ) AND  tasks.deleted = 0

Also, it would be really nice if someone could chime in as to whether or not it’s possible to add a custom period here (such as THIS MONTH) so that i can filter my reports where start_date >= last month AND due_date <= this month so that I can pull all tasks from the last month.

I found the culprit in modules/AOR_Reports/aor_utils.php on line 166, the ‘last_month’ clause is exactly the same as the ‘this_month’ clause which essentially gets the current month and current year, and sets the day variable to 1.

I hate to change this file but I see no other option. I see the strtotime function being used above in the ‘this_week’ and ‘last_week’ clauses so I assume they are ok with using this function elsewhere.

$datetime_period = $datetime_period->setTimestamp(strtotime('first day of last month'));


I also see below in the ‘last_year’ clause that they are using another method to change the year, which could be applied to change the month as well. A little bit less of a change as it’s using the same function as the original code. Altering this a bit, we can get what we want to achieve.

$datetime_period = $datetime_period->setDate($datetime_period->format('Y'), $datetime_period->format('m') - 1, 1);

added issue to github #1066, please close topic and pm if need more details