Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Periods in GL Reports
03-19-2018, 05:22 AM
Post: #11
RE: Periods in GL Reports
All comments and criticism welcome.

https://www.linkedin.com/in/eclipsepaulbecker
Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2018, 07:49 AM
Post: #12
RE: Periods in GL Reports
I'd echo Tim's comments too ... there has been extensive discussion on this subject i.e. to OO or not - over the years.
Although there is some (ok a lot of) duplication it does mean that reading a single script - with knowledge of just a few others will show all the logic you need to understand it. The pros for OO are well understood, but the down-side is readability - certainly for newbie programmers - we've opted to have readability as paramount.
I notice too in some code the use of short variable names .... $ds $de etc... the webERP code base - in general - has been very careful to use verbose variables to improve readability capitalising each word ... to aid in reading the code. In this example we would have used $DateStart (or $StartDate) and $DateEnd (or $EndDate).
That said - I too like your functions here :-)

If you are interested, check out:

http://www.weberp.org/CodingConventions.html

Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2018, 08:07 AM (This post was last modified: 03-19-2018 08:40 AM by falkoner.)
Post: #13
RE: Periods in GL Reports
I did fix the variable names in my code which you can just drop into your MiscFunctions.php script
You can see them at the bottom of this commit:

https://github.com/timschofield/KwaMoja/...aee2144c95
As well as the variable naming I was thinking that some of the options make little sense in some of the cases. For instance a P&L report for next year won't be very relevant. Could we pass in a variable that will decide which of "Last" "This" and "Next" appear in the drop down box?

Also we are making the start and end dates Y-m-d format, and then converting them into company default date format to pass to the GetPeriod() function. This is probably an unnecessary step as we could use the default date format originally so the statements become something like:

$DateEnd = date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, 12, 31, $NextYear));

and then at the end of the function we would have:

$Period = GetPeriod($DateStart);

saving a few steps along the way. Oh yes and finally should we include a default case just to prevent the function falling through with no start and end date?

Thanks
Tim
Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2018, 11:00 AM
Post: #14
RE: Periods in GL Reports
100% agreed on all thoughts.

From 1983 to 1999 I was a non-OO developer who used short, often-undeclared variables, cared little about extensibility/maintainability, never worried about my code being audited, and never read MS Practical Guidelines and Best Practices.

In 2000 I was trained in OOAD by a Senor Application Architect from Vanguard and the rest is history. His training completely and significantly changed everything about the way I construct applications and code. The same way the study of W. Edwards Deming changed my life and career.

And for the record that code was borrowed from Report Builder as a proof-of-concept so little of it was mine. I just stuck it into MiscFunctions and Paul tidied it up. I really had no idea if it would be found useful or acceptable by this forum.

Now that I have a better idea of your thoughts I will keep all this in mind when I attempt other features.

Thank you all so much for commenting and consideration!

https://www.linkedin.com/in/eclipsepaulbecker
Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2018, 06:33 PM
Post: #15
RE: Periods in GL Reports
(03-19-2018 11:00 AM)VortecCPI Wrote:  And for the record that code was borrowed from Report Builder as a proof-of-concept so little of it was mine. I just stuck it into MiscFunctions and Paul tidied it up. I really had no idea if it would be found useful or acceptable by this forum.

I thought it was familiar Smile

One of the issues with the report builder is that it doesn't really conform to the rest of the code.

Tim
Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2018, 09:17 PM (This post was last modified: 03-19-2018 09:18 PM by falkoner.)
Post: #16
RE: Periods in GL Reports
I have done the changes mentioned above, and also added in options to show financial years as well as calendar years. The second parameter to the ReportPeriodList() function is an array that can contain some or all of the letters 'l', 't', and 'n' for Last, This, or Next. So using:

ReportPeriodList($_POST['Period'], array('l', 't'))

just shows Last and This options. If the second parameter is not given it defaults to showing everything so existing code *should* just work. Any comments let me know or I will commit this.

Tim

PHP Code:
/* Used in report scripts for standard periods.
 * Parameter $Choice is from the 'Period' combobox value.
*/
function ReportPeriodList($Choice$Options=array('t''l''n')) {
    
$Periods = array();

    if (
in_array('t'$Options)) {
        
$Periods[] = _('This Month');
        
$Periods[] = _('This Year');
        
$Periods[] = _('This Financial Year');
    }

    if (
in_array('l'$Options)) {
        
$Periods[] = _('Last Month');
        
$Periods[] = _('Last Year');
        
$Periods[] = _('Last Financial Year');
    }

    if (
in_array('n'$Options)) {
        
$Periods[] = _('Next Month');
        
$Periods[] = _('Next Year');
        
$Periods[] = _('Next Financial Year');
    }

    
$Count count($Periods);

    
$HTML '<select name="Period">
                <option value=""></option>'
;

    for (
$x 0;$x $Count;++$x) {
        if (!empty(
$Choice) && $Choice == $Periods[$x]) {
            
$HTML .= '<option value="' $Periods[$x] . '" selected>' $Periods[$x] . '</option>';
        } else {
            
$HTML .= '<option value="' $Periods[$x] . '">' $Periods[$x] . '</option>';
        }
    }

    
$HTML .= '</select>';

    return 
$HTML;
}

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'):
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(000$ThisMonth1$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(000$ThisMonth$TotalDays$ThisYear));
        break;
        case 
_('This Quarter'):
            
$QtrStrt intval(($ThisMonth 1) / 3) * 1;
            
$QtrEnd intval(($ThisMonth 1) / 3) * 3;
            if (
$QtrEnd == or $QtrEnd == or $QtrEnd == or $QtrEnd == 11) {
                
$TotalDays 30;
            }
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(000$QtrStrt1$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(000$QtrEnd$TotalDays$ThisYear));
        break;
        case 
_('This Year'):
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(00011$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(0001231$ThisYear));
        break;
        case 
_('This Financial Year'):
            if (
Date('m') > $_SESSION['YearEnd']) {
                
$DateStart Date($_SESSION['DefaultDateFormat'], Mktime(000$_SESSION['YearEnd'] + 11Date('Y')));
            } else {
                
$DateStart Date($_SESSION['DefaultDateFormat'], Mktime(000$_SESSION['YearEnd'] + 11Date('Y') - 1));
            }
            
$DateEnd date($_SESSION['DefaultDateFormat'], YearEndDate($_SESSION['YearEnd'], 0));
        break;
        case 
_('Last Month'):
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(000$LastMonth1$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(000$LastMonth$TotalDaysLast$ThisYear));
        break;
        case 
_('Last Quarter'):
            
$QtrStrt intval(($ThisMonth 1) / 3) * 2;
            
$QtrEnd intval(($ThisMonth 1) / 3) * 0;
            if (
$QtrEnd == or $QtrEnd == or $QtrEnd == or $QtrEnd == 11) {
                
$TotalDays 30;
            }
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(000$QtrStrt1$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(000$QtrEnd$TotalDays$ThisYear));
        break;
        case 
_('Last Year'):
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(00011$LastYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(0001231$LastYear));
        break;
        case 
_('Last Financial Year'):
            if (
Date('m') > $_SESSION['YearEnd']) {
                
$DateStart Date($_SESSION['DefaultDateFormat'], Mktime(000$_SESSION['YearEnd'] + 11Date('Y') - 1));
            } else {
                
$DateStart Date($_SESSION['DefaultDateFormat'], Mktime(000$_SESSION['YearEnd'] + 11Date('Y') - 2));
            }
            
$DateEnd date($_SESSION['DefaultDateFormat'], YearEndDate($_SESSION['YearEnd'], -1));
        break;
        case 
_('Next Month'):
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(000$NextMonth1$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(000$NextMonth$TotalDaysNext$ThisYear));
        break;
        case 
_('Next Quarter'):
            
$QtrStrt intval(($ThisMonth 1) / 3) * 4;
            
$QtrEnd intval(($ThisMonth 1) / 3) * 6;
            if (
$QtrEnd == or $QtrEnd == or $QtrEnd == or $QtrEnd == 11) {
                
$TotalDays 30;
            }
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(000$QtrStrt1$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(000$QtrEnd$TotalDays$ThisYear));
        break;
        case 
_('Next Year'):
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(00011$NextYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(0001231$NextYear));
        break;
        case 
_('Next Financial Year'):
            if (
Date('m') > $_SESSION['YearEnd']) {
                
$DateStart Date($_SESSION['DefaultDateFormat'], Mktime(000$_SESSION['YearEnd'] + 11Date('Y') + 1));
            } else {
                
$DateStart Date($_SESSION['DefaultDateFormat'], Mktime(000$_SESSION['YearEnd'] + 11Date('Y')));
            }
            
$DateEnd date($_SESSION['DefaultDateFormat'], YearEndDate($_SESSION['YearEnd'], 1));
        break;
        default:
            
$DateStart date($_SESSION['DefaultDateFormat'], mktime(000$LastMonth1$ThisYear));
            
$DateEnd date($_SESSION['DefaultDateFormat'], mktime(000$LastMonth$TotalDaysLast$ThisYear));
        break;
    }

    if (
$FromOrTo == 'From') {
        
$Period GetPeriod($DateStart);
    } else {
        
$Period GetPeriod($DateEnd);
    }

    return 
$Period;

Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2018, 10:38 PM (This post was last modified: 03-19-2018 10:57 PM by VortecCPI.)
Post: #17
RE: Periods in GL Reports
I realized the Report Builder code was not our favorite due to some work I had already done with it but I just needed something to get started.

Amazing how something so simple can be extended into something so flexible and so useful (useful for my needs anyhow)...

https://www.linkedin.com/in/eclipsepaulbecker
Visit this user's website Find all posts by this user
Quote this message in a reply
03-19-2018, 11:11 PM
Post: #18
RE: Periods in GL Reports
That is why I love FLOSS. Somebody needs some functionality and goes ahead and codes it. Others see further possibilities in that functionality and go ahead and work on that, releasing the code back so all can enjoy Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
03-20-2018, 07:19 PM
Post: #19
RE: Periods in GL Reports
As there appears to be no objections I have committed these changes.

https://github.com/timschofield/webERP-s...e23c7e97c4

Tim
Visit this user's website Find all posts by this user
Quote this message in a reply
03-22-2018, 10:22 AM (This post was last modified: 03-22-2018 10:22 AM by TurboPT.)
Post: #20
RE: Periods in GL Reports
Tim, your change committed to the two forks.
(though I have not applied the new use to other files, just yet)
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)