SQL-Ledger Homepage

SQL-Ledger User Forum

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

Pre-fill drop down menus? (General)

posted by Dieter Simader(R), 26.01.2016, 15:54

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
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

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!


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.


Complete thread:

Back to the forum
Board view  Mix view
971 Postings in 319 Threads, 324 registered users, 59 users online (0 registered, 59 guests)
SQL-Ledger User Forum | Admin contact
powered by my little forum