SQL-Ledger Homepage

SQL-Ledger User Forum

Forum index page

Log in | Register

Back to index page
Thread view  Board view
JayArr(R)

Mission BC Canada,
21.01.2016, 15:35
 

Pre-fill drop down menus? (General)

I think it would be a real nice feature if the drop down boxes for Month and Year in the reports pages were pre-filled with the 'current' month and year.

I don't know about everyone else but 99% of the time when I want to run a report it's for "this month" not last year. We all have to select the month and year every time which is a waste of time.

I'd like to open up my A/R or A/P aging reports or my Income Statement and have it all set up to just hit continue and get my report, having to set the month and year every time is just wasteful.

Here's the section of code I want to edit:

> if ($selectfrom) {
> print qq|
> <tr>
> <th align=right>|.$locale->text('Period').qq|</th>
> <td colspan=3>
> <select name=frommonth>|.$form->select_option($selectaccountingmonth, undef, 1, 1).qq|</select>
> <select name=fromyear>|.$form->select_option($selectaccountingyear) .qq|</select>
> <input name=interval class=radio type=radio value=0>&nbsp;|.$locale->text('Current').qq|
> <input name=interval class=radio type=radio value=1 checked>&nbsp;|.$locale->text('Month').qq|
> <input name=interval class=radio type=radio value=3>&nbsp;|.$locale->text('Quarter').qq|
> <input name=interval class=radio type=radio value=12>&nbsp;|.$locale->text('Year').qq|
> </td>
> </tr>
> |;
> }

Can anyone suggest a way to make "select name" lines have a default value that corresponds to the current date?

This should not be difficult. IMHO.

Jeff

JayArr(R)

Mission BC Canada,
21.01.2016, 22:32

@ JayArr
 

Pre-fill drop down menus?

Hi All

I was in the wrong section before but with a little help from a guy on another forum I figured it out!

I'll share it with you all in case you want to apply it.

Up near the top of this same file (rp.pl) is a section where the drop down boxes are set up, around line 118 for 3.0.8.

Here's how it looked originally:

> if (@{ $form->{all_years} }) {
> # accounting years
> $selectaccountingyear = "\n";
> for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
> $selectaccountingmonth = "\n";
> for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }

Notice how $selectaccountingyear and $selectaccountingmonth are both set to ="\n"?
That is what causes the boxes to be blank when you first load the page.

I found right away that if I changed $selectaccountingyear to ="" that the box will show the top item in the list as default, in our case that's the latest year, 2016. Great, I'll never have to select a year again unless running reports on past years. That should save me some clicks.

Unfortunately that won't work for month because it will just always show January.

I found a perl command call localtime() and played around with it and I had to create a simple array called monthplusone but now it works!!

When you hit the page it will show a number in the box corresponding to the month ie 01 for Jan and the reports run just fine.

Here's the code I ended up with:

> if (@{ $form->{all_years} }) {
> # accounting years
> $selectaccountingyear = "";
> @monthsplusone = qw( 01 02 03 04 05 06 07 08 09 10 11 12);
> $monthtoday=(localtime())[4];
> for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
> $selectaccountingmonth = $monthsplusone[$monthtoday]."\n" ;
> for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .= qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }

I knew it would be pretty simple.

As a bonus it seems like a lot of different forms all use this same code snippet so wherever I go my month and year are pre-filled for me so I can get on with the report I need.

I LOVE open source software! When you don't like how it works you can just tweak it to your particular taste or process!

Jeff

Dieter Simader(R)

26.01.2016, 15:54

@ JayArr
 

Pre-fill drop down menus?

Hi All

I was in the wrong section before but with a little help from a guy on
another forum I figured it out!

I'll share it with you all in case you want to apply it.

Up near the top of this same file (rp.pl) is a section where the drop down
boxes are set up, around line 118 for 3.0.8.

Here's how it looked originally:

> if (@{ $form->{all_years} }) {
> # accounting years
> $selectaccountingyear = "\n";
> for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
> $selectaccountingmonth = "\n";
> for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .=
qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }

Notice how $selectaccountingyear and $selectaccountingmonth are both set to
="\n"?
That is what causes the boxes to be blank when you first load the page.

I found right away that if I changed $selectaccountingyear to ="" that the
box will show the top item in the list as default, in our case that's the
latest year, 2016. Great, I'll never have to select a year again unless
running reports on past years. That should save me some clicks.

Unfortunately that won't work for month because it will just always show
January.

I found a perl command call localtime() and played around with it and I had
to create a simple array called monthplusone but now it works!!

When you hit the page it will show a number in the box corresponding to the
month ie 01 for Jan and the reports run just fine.

Here's the code I ended up with:

> if (@{ $form->{all_years} }) {
> # accounting years
> $selectaccountingyear = "";
> @monthsplusone = qw( 01 02 03 04 05 06 07 08 09 10 11 12);
> $monthtoday=(localtime())[4];
> for (@{ $form->{all_years} }) { $selectaccountingyear .= qq|$_\n| }
> $selectaccountingmonth = $monthsplusone[$monthtoday]."\n" ;
> for (sort keys %{ $form->{all_month} }) { $selectaccountingmonth .=
qq|$_--|.$locale->text($form->{all_month}{$_}).qq|\n| }

I knew it would be pretty simple.

As a bonus it seems like a lot of different forms all use this same code
snippet so wherever I go my month and year are pre-filled for me so I can
get on with the report I need.

I LOVE open source software! When you don't like how it works you can just
tweak it to your particular taste or process!

Jeff

The year/month selection takes precedence over other date entries so if you enter a date it will have no effect and you will always get a report for the period.

A better solution is to pass the variables for current year and month to the select_option function.

$cd = $form->current_date();
($cy, $cm) = $cd =~ /(....)(..)/;

and change the select_option calls to
$form->select_option($selectaccountingmonth, $cm, 1, 1)
$form->select_option($selectaccountingyear, $cy, 1)

This way you can still unselect the year and month and enter a date in the From and To fields if you want another report.

Back to index page
Thread view  Board view
964 Postings in 318 Threads, 322 registered users, 169 users online (0 registered, 169 guests)
SQL-Ledger User Forum | Admin contact
RSS-Feed
powered by my little forum