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 JayArr(R), Mission BC Canada, 21.01.2016, 22:32

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

 

Complete thread:

Back to the forum
Board view  Mix view
986 Postings in 325 Threads, 327 registered users, 89 users online (0 registered, 89 guests)
SQL-Ledger User Forum | Admin contact
RSS-Feed
powered by my little forum