<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p>Hi</p>
<p>check this: <a href="https://github.com/YetiForceCompany/YetiForceCRM/commit/eb8827ef15e9860a3d5b5ddb74fdad4db7d15822">https://github.com/YetiForceCompany/YetiForceCRM/commit/eb8827ef15e9860a3d5b5ddb74fdad4db7d15822</a> </p>
<div>---<br />
<div>Z poważaniem / Regards</div>
<div> </div>
<div><strong>Błażej Pabiszczak</strong></div>
<div><em>Chief Executive Officer</em></div>
<div>M: +48.884999123<br />E: <a title="Mail do Błażej Pabiszczak" href="mailto:b.pabiszczak@yetiforce.com">b.pabiszczak@yetiforce.com</a></div>
<hr />
<p> </p>
</div>
<p> </p>
<div class="gmail_quote">---------- Forwarded message ----------<br />From: <strong class="gmail_sendername">Alan Lord</strong> <span><<a href="mailto:alanslists@gmail.com">alanslists@gmail.com</a>></span><br />Date: 2015-04-28 10:34 GMT+02:00<br />Subject: Re: [Vtigercrm-developers] Bug in Current/Previous Week options in Reports?<br />To: <a href="mailto:vtigercrm-developers@lists.vtigercrm.com">vtigercrm-developers@lists.vtigercrm.com</a><br /><br /><br />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?</blockquote>
<br /> 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'));</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() . '";</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'));</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'),</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"));</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"));</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/">http://www.vtiger.com/</a></div>
</body></html>