03-10-2018, 11:00 PM
Now that we have pre-defined periods in Report Builder it would be nice to have them in the GL report areas as well:
[attachment=783]
Perhaps in other areas as well?
I am going to have a crack at this using MiscFunctions.php:
Work in progress...
[attachment=783]
Perhaps in other areas as well?
I am going to have a crack at this using MiscFunctions.php:
PHP Code:
//Select the period
echo '<tr>
<td>' . _('Select Period') . '</td>
<td>' . ReportPeriodList() . '</td>
</tr>';
PHP Code:
function ReportPeriodList(){
/* Used in report scripts for standard periods.
*/
$html = '<select name="Period">
<option value=""></option>
<option value="' . _('This Month') . '">' . _('This Month') . '</option>
<option value="' . _('This Quarter') . '">' . _('This Quarter') . '</option>
<option value="' . _('This Year') . '">' . _('This Year') . '</option>
<option value="' . _('Last Month') . '">' . _('Last Month') . '</option>
<option value="' . _('Last Quarter') . '">' . _('Last Quarter') . '</option>
<option value="' . _('Last Year') . '">' . _('Last Year') . '</option>
<option value="' . _('Next Month') . '">' . _('Next Month') . '</option>
<option value="' . _('Next Quarter') . '">' . _('Next Quarter') . '</option>
<option value="' . _('Next Year') . '">' . _('Next Year') . '</option>
</select>';
return $html;
}
PHP Code:
function ReportPeriod($PeriodName, $FromOrTo){
/* Used in report scripts to determine period.
*/
$ThisMonth = date('m');
$ThisYear = date('Y');
$LastMonth = $ThisMonth-1;
$LastYear = $ThisYear-1;
$NextMonth = $ThisMonth+1;
$NextYear = $ThisYear+1;
// Find total number of days in this month:
$TotalDays = cal_days_in_month(CAL_GREGORIAN, $ThisMonth, $ThisYear);
// Find total number of days in last month:
$TotalDaysLast = cal_days_in_month(CAL_GREGORIAN, $LastMonth, $ThisYear);
// Find total number of days in next month:
$TotalDaysNext = cal_days_in_month(CAL_GREGORIAN, $NextMonth, $ThisYear);
switch ($PeriodName) {
Case _('This Month'):
$ds = date('Y-m-d', mktime(0,0,0, $ThisMonth, 1, $ThisYear));
$de = date('Y-m-d', mktime(0,0,0, $ThisMonth, $TotalDays, $ThisYear));
break;
Case _('This Quarter'):
$QtrStrt = intval(($ThisMonth-1)/3)*3+1;
$QtrEnd = intval(($ThisMonth-1)/3)*3+3;
if ( $QtrEnd == 4 OR $QtrEnd == 6 OR $QtrEnd == 9 OR $QtrEnd == 11 ) { $TotalDays=30; }
$ds = date('Y-m-d', mktime(0,0,0, $QtrStrt, 1, $ThisYear));
$de = date('Y-m-d', mktime(0,0,0, $QtrEnd, $TotalDays, $ThisYear));
break;
Case _('This Year'):
$ds = date('Y-m-d', mktime(0,0,0, 1, 1, $ThisYear));
$de = date('Y-m-d', mktime(0,0,0, 12, 31, $ThisYear));
break;
Case _('Last Month'):
$ds = date('Y-m-d', mktime(0,0,0, $LastMonth, 1, $ThisYear));
$de = date('Y-m-d', mktime(0,0,0, $LastMonth, $TotalDaysLast, $ThisYear));
break;
Case _('Last Quarter'):
$QtrStrt = intval(($ThisMonth-1)/3)*3-2;
$QtrEnd = intval(($ThisMonth-1)/3)*3+0;
if ( $QtrEnd == 4 OR $QtrEnd == 6 OR $QtrEnd == 9 OR $QtrEnd == 11 ) { $TotalDays=30; }
$ds = date('Y-m-d', mktime(0,0,0, $QtrStrt, 1, $ThisYear));
$de = date('Y-m-d', mktime(0,0,0, $QtrEnd, $TotalDays, $ThisYear));
break;
Case _('Last Year'):
$ds = date('Y-m-d', mktime(0,0,0, 1, 1, $LastYear));
$de = date('Y-m-d', mktime(0,0,0, 12, 31, $LastYear));
break;
Case _('Next Month'):
$ds = date('Y-m-d', mktime(0,0,0, $NextMonth, 1, $ThisYear));
$de = date('Y-m-d', mktime(0,0,0, $NextMonth, $TotalDaysNext, $ThisYear));
break;
Case _('Next Quarter'):
$QtrStrt = intval(($ThisMonth-1)/3)*3+4;
$QtrEnd = intval(($ThisMonth-1)/3)*3+6;
if ( $QtrEnd == 4 OR $QtrEnd == 6 OR $QtrEnd == 9 OR $QtrEnd == 11 ) { $TotalDays=30; }
$ds = date('Y-m-d', mktime(0,0,0, $QtrStrt, 1, $ThisYear));
$de = date('Y-m-d', mktime(0,0,0, $QtrEnd, $TotalDays, $ThisYear));
break;
Case _('Next Year'):
$ds = date('Y-m-d', mktime(0,0,0, 1, 1, $NextYear));
$de = date('Y-m-d', mktime(0,0,0, 12, 31, $NextYear));
break;
}
if ($FromOrTo == 'From') {
$Period = GetPeriod(ConvertSQLDate($ds));
} else {
$Period = GetPeriod(ConvertSQLDate($de));
}
return $Period;
}
Work in progress...