Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Periods in GL Reports
03-10-2018, 11:00 PM, (This post was last modified: 03-11-2018, 01:20 AM by VortecCPI.)
#1
Periods in GL Reports
Now that we have pre-defined periods in Report Builder it would be nice to have them in the GL report areas as well:

   

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$ThisMonth1$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 == OR $QtrEnd == OR $QtrEnd == OR $QtrEnd == 11 ) { $TotalDays=30; }
            
$ds date('Y-m-d'mktime(0,0,0$QtrStrt1$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,011$ThisYear));
            
$de date('Y-m-d'mktime(0,0,01231$ThisYear));
            break;
        Case 
_('Last Month'):
            
$ds date('Y-m-d'mktime(0,0,0$LastMonth1$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 == OR $QtrEnd == OR $QtrEnd == OR $QtrEnd == 11 ) { $TotalDays=30; }
            
$ds date('Y-m-d'mktime(0,0,0$QtrStrt1$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,011$LastYear));
            
$de date('Y-m-d'mktime(0,0,01231$LastYear));
            break;
        Case 
_('Next Month'):
            
$ds date('Y-m-d'mktime(0,0,0$NextMonth1$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 == OR $QtrEnd == OR $QtrEnd == OR $QtrEnd == 11 ) { $TotalDays=30; }
            
$ds date('Y-m-d'mktime(0,0,0$QtrStrt1$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,011$NextYear));
            
$de date('Y-m-d'mktime(0,0,01231$NextYear));
            break;
    }    
    
    if (
$FromOrTo == 'From') {
        
$Period GetPeriod(ConvertSQLDate($ds));
    } else {
        
$Period GetPeriod(ConvertSQLDate($de));
    }
    return 
$Period;


Work in progress...
https://www.linkedin.com/in/eclipsepaulbecker
Reply
03-11-2018, 02:12 AM, (This post was last modified: 03-11-2018, 02:17 AM by VortecCPI.)
#2
RE: Periods in GL Reports
If anybody cares to check my work it would be greatly appreciated.

Attached files are for webERP version 4.14.1.

Pretty simple implementation.

   


Attached Files
.php   MiscFunctions.php (Size: 18.3 KB / Downloads: 2)
.php   GLTrialBalance.php (Size: 31.73 KB / Downloads: 2)
https://www.linkedin.com/in/eclipsepaulbecker
Reply
03-11-2018, 04:33 AM, (This post was last modified: 03-11-2018, 04:33 AM by VortecCPI.)
#3
RE: Periods in GL Reports
I have incorporated this into all the scrips that use Period From/To.

I find it quite handy...

   
https://www.linkedin.com/in/eclipsepaulbecker
Reply
03-13-2018, 03:21 PM, (This post was last modified: 03-13-2018, 03:31 PM by TurboPT.)
#4
RE: Periods in GL Reports
Paul, I made a minor mod to both files.

The minor change allows the user's selected period to keep the setting if they choose to "Select a Different Period" (the non-PDF route)

Also, in your original GLTrialBalance.php file, I contemplated moving lines 409-412 to just after the include at line 402 so that I could keep all the hidden inputs together.

However, if that block of code is moved, and the period sets the from/to dates will also make the form have the from/to date ranges set, as well as the period upon return to the form, and I wasn't sure that would be desired behavior if only the period was selected?

Anyway, give the files a diff. In MiscFunctions.php, the ReportPeriodList() function has entirely new handling to work with the change.

You can also preview the current changes at this git branch. Note that the diff will show removal of a few unused $j variables in GLTrialBalance, but this was not applied to the MOD file.


Attached Files
.php   MiscFunctionsMOD.php (Size: 18.19 KB / Downloads: 1)
.php   GLTrialBalanceMOD.php (Size: 31.89 KB / Downloads: 1)
Reply
03-13-2018, 09:51 PM,
#5
RE: Periods in GL Reports
Thank you so much Paul! So nice to know my work is being checked and improved!
https://www.linkedin.com/in/eclipsepaulbecker
Reply
03-16-2018, 04:32 PM, (This post was last modified: 03-16-2018, 04:34 PM by TurboPT.)
#6
RE: Periods in GL Reports
Changes committed.

Only the two files referenced in post #3 have the changes applied.

Paul, if you don't mind listing some other files that can use your new combobox, so that there is a list to revisit and eventually apply this change.
Reply
03-17-2018, 06:47 PM, (This post was last modified: 03-17-2018, 06:50 PM by VortecCPI.)
#7
RE: Periods in GL Reports
Thank you Paul. Will do over the next few days but I can tell you I have been using them all over...
https://www.linkedin.com/in/eclipsepaulbecker
Reply
03-18-2018, 01:42 AM,
#8
RE: Periods in GL Reports
That's fine, maximize the use. (as you get a chance to append a list, no rush)
Reply
03-18-2018, 10:46 PM,
#9
RE: Periods in GL Reports
Paul... Are you (and others) okay with the abstraction of the code to MiscFunctions? In my opinion it makes it easy to extend and maintain the new feature but it also means it would be more difficult to customize for a specific script.

As a long time OO guy (even brute-force inheritance in VBA and VB6) I try to share as many objects and/or attributes and behaviors as possible for the sake of extensibility and maintainability.

I ask because it seems to me we could also move other Period-related or GLAccount-related dropdowns/selectors to the MiscFunctions script as well, thus unifying the code.

Is there any penalty to having code outside of the page as in this case?
https://www.linkedin.com/in/eclipsepaulbecker
Reply
03-19-2018, 12:58 AM,
#10
RE: Periods in GL Reports
The policy has always been to avoid "unnecessary abstractions" which is vague and in the past it has been looked at on a case by case basis. This is to make each script as much as possible a self contained readable document.

In this case I think it's a good thing. I like your functions and have included them in my code (though my liking it may be more of a hindrance).

I have some observations on them but I will write them later when I am at a computer rather than try to tap them out on my phone.

Tim
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)