<div dir="ltr">Hi Alan,<div><br></div><div>Thanks! for notification and detailed explanation on the issue will review this. It's reported here on <a href="http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/8547">trac</a>. Please do update your further observations here.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 28, 2015 at 2:04 PM, Alan Lord <span dir="ltr"><<a href="mailto:alanslists@gmail.com" target="_blank">alanslists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 27/04/15 16:02, Alan Lord wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Our customer has created a report in which one of the conditions is<br>
using the Previous Week meta value on a date field.<br>
<br>
Her user preferences say a week starts on Monday.<br>
<br>
The report always shows results starting on the Sunday...<br>
<br>
Is this hardcoded somewhere? Should it use the user's preferences? Can I<br>
change it start from a Monday?<br>
</blockquote>
<br></span>
Oh Dear...<br>
<br>
Looking through the code for the Report module in modules/Reports/Reports.php in the function getCriteriaJS() it says:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
$lastweek0 = date("Y-m-d",strtotime("-2 week Monday"));<br>
$lastWeekStartDateTime = new DateTimeField($lastweek0.' '. date('H:i:s'));<br>
$lastweek1 = date("Y-m-d",strtotime("-1 week Sunday"));<br>
$lastWeekEndDateTime = new DateTimeField($lastweek1.' '. date('H:i:s'));<br>
</blockquote>
<br>
Note that the startdate is supposed to start on a Monday and also note that it is hardcoded. Yet my customer is seeing the Previous Week select option generating a date that starts on a Sunday.<br>
<br>
So I grepped the code:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
alanlord@dev1:/var/www/test$ grep -rn "lastWeekStartDateTime" *<br>
modules/Reports/Reports.php:968: $lastWeekStartDateTime = new DateTimeField($lastweek0.' '. date('H:i:s'));<br>
modules/Reports/Reports.php:1124: document.NewReport.startdate.value = "'.$lastWeekStartDateTime->getDisplayDate().'";<br>
modules/CustomView/CustomView.php:584: $lastWeekStartDateTime = new DateTimeField($lastweek0 . ' ' . date('H:i:s'));<br>
modules/CustomView/CustomView.php:737: document.CustomView.startdate.value = "' . $lastWeekStartDateTime->getDisplayDate() . '";<br>
</blockquote>
<br>
So I looked in modules/CustomView/CustomView.php in a function called getCriteriaJS() - Note the same name as above!!!<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
$lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));<br>
$lastWeekStartDateTime = new DateTimeField($lastweek0 . ' ' . date('H:i:s'));<br>
$lastweek1 = date("Y-m-d", strtotime("-1 week Saturday"));<br>
$lastWeekEndDateTime = new DateTimeField($lastweek1 . ' ' . date('H:i:s'));<br>
</blockquote>
<br>
Note that this one says "Sunday" for the start date... Note that it is also hardcoded.<br>
<br>
Changing this made no difference :-(<br>
<br>
So then I decided to grep the tree for "lastweek" to see if was set somewhere else too...<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
modules/Vtiger/models/Field.php:555: $lastweek0 = date("Y-m-d",strtotime("-1 week Sunday"));<br>
modules/Vtiger/models/Field.php:557: $lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));<br>
modules/Vtiger/models/Field.php:558: $lastweek1 = date("Y-m-d", strtotime("-1 week Saturday"));<br>
modules/Vtiger/models/Field.php:636: } elseif ($type == "lastweek") {<br>
modules/Vtiger/models/Field.php:637: $dateValues[0] = $lastweek0;<br>
modules/Vtiger/models/Field.php:638: $dateValues[1] = $lastweek1;<br>
modules/Vtiger/models/Field.php:722: 'lastweek' => array('label' => 'LBL_LAST_WEEK'),<br>
modules/Reports/ReportRun.php:1584: $lastweek0 = date("Y-m-d",strtotime("-1 week Sunday"));<br>
modules/Reports/ReportRun.php:1586: $lastweek0 = date("Y-m-d",strtotime("-2 week Sunday"));<br>
modules/Reports/ReportRun.php:1587: $lastweek1 = date("Y-m-d",strtotime("-1 week Saturday"));<br>
modules/Reports/ReportRun.php:1683: elseif($type == "lastweek" )<br>
modules/Reports/ReportRun.php:1686: $datevalue[0] = $lastweek0;<br>
modules/Reports/ReportRun.php:1687: $datevalue[1] = $lastweek1;<br>
modules/Reports/Reports.php:852: "yesterday","today","tomorrow","lastweek","thisweek","nextweek","lastmonth","thismonth",<br>
modules/Reports/Reports.php:967: $lastweek0 = date("Y-m-d",strtotime("-2 week Monday"));<br>
modules/Reports/Reports.php:968: $lastWeekStartDateTime = new DateTimeField($lastweek0.' '. date('H:i:s'));<br>
modules/Reports/Reports.php:969: $lastweek1 = date("Y-m-d",strtotime("-1 week Sunday"));<br>
modules/Reports/Reports.php:970: $lastWeekEndDateTime = new DateTimeField($lastweek1.' '. date('H:i:s'));<br>
modules/Reports/Reports.php:1123: } else if( type == "lastweek" ) {<br>
modules/CustomView/CustomView.php:493: "lastweek","thisweek","nextweek","lastmonth","thismonth",<br>
modules/CustomView/CustomView.php:521: "lastweek" => "" . $mod_strings['Last Week'] . "",<br>
modules/CustomView/CustomView.php:583: $lastweek0 = date("Y-m-d", strtotime("-2 week Monday"));<br>
modules/CustomView/CustomView.php:584: $lastWeekStartDateTime = new DateTimeField($lastweek0 . ' ' . date('H:i:s'));<br>
modules/CustomView/CustomView.php:585: $lastweek1 = date("Y-m-d", strtotime("-1 week Sunday"));<br>
modules/CustomView/CustomView.php:586: $lastWeekEndDateTime = new DateTimeField($lastweek1 . ' ' . date('H:i:s'));<br>
modules/CustomView/CustomView.php:736: } else if( type == "lastweek" ) {<br>
modules/CustomView/CustomView.php:1537: $lastweek0 = date("Y-m-d",strtotime("-1 week Sunday"));<br>
modules/CustomView/CustomView.php:1539: $lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));<br>
modules/CustomView/CustomView.php:1540: $lastweek1 = date("Y-m-d", strtotime("-1 week Saturday"));<br>
modules/CustomView/CustomView.php:1614: } elseif ($type == "lastweek") {<br>
modules/CustomView/CustomView.php:1616: $datevalue[0] = $lastweek0;<br>
modules/CustomView/CustomView.php:1617: $datevalue[1] = $lastweek1;<br>
modules/CustomView/models/Record.php:655: $lastweek0 = date("Y-m-d", strtotime("-2 week Sunday"));<br>
modules/CustomView/models/Record.php:656: $lastweek1 = date("Y-m-d", strtotime("-1 week Saturday"));<br>
modules/CustomView/models/Record.php:719: } elseif ($type == "lastweek") {<br>
modules/CustomView/models/Record.php:720: $dateValues[0] = $lastweek0;<br>
modules/CustomView/models/Record.php:721: $dateValues[1] = $lastweek1;<br>
modules/CustomView/models/Record.php:805: 'lastweek' => array('label' => 'LBL_LAST_WEEK'),<br>
</blockquote>
<br>
So the hardcoding that affects the population of the dates in the Conditions fields when you change the Select is in modules/Vtiger/models/Field.php Changing this to a Monday works in that is changes the date you *see*.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// (Last Week) If Today is "Sunday" then "-2 week Sunday" will give before last week Sunday date<br>
if($todayName == "Monday")<br>
$lastweek0 = date("Y-m-d",strtotime("-1 week Monday"));<br>
else<br>
$lastweek0 = date("Y-m-d", strtotime("-2 week Monday"));<br>
$lastweek1 = date("Y-m-d", strtotime("-1 week Sunday"));<br>
</blockquote>
<br>
But this didn't affect the output of the report at all... So I took a look in modules/Reports/ReportRun.php and found the *exact* same code... Changing this to Monday now produces the output I desire.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
// (Last Week) If Today is "Sunday" then "-2 week Sunday" will give before last week Sunday date<br>
if($todayName == "Monday")<br>
$lastweek0 = date("Y-m-d",strtotime("-1 week Monday"));<br>
else<br>
$lastweek0 = date("Y-m-d",strtotime("-2 week Monday"));<br>
$lastweek1 = date("Y-m-d",strtotime("-1 week Sunday"));<br>
</blockquote>
<br>
There are several issues with all this...<br>
<br>
1. There is tons of duplication of code<br>
2. The code is inconsistent. Some bits use Monday, some use Sunday<br>
3. It's hardcoded. Islamic countries consider that Saturday is the start of the week and certain businesses may well want to use any random day as the start of _their_ week<br>
4. It's a mess.<br>
<br>
Al<br>
<br>
<br>
_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">With<br>Best Regards<br>Uma.S<br><div>Vtiger Team</div></div></div>
</div>