From 2544135f3eef2df596d0f2a3c61cead6a637160d Mon Sep 17 00:00:00 2001 From: einhverfr Date: Sat, 8 Dec 2007 01:09:10 +0000 Subject: converting all_years to use extract and group by git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1963 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Form.pm | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index e2db2d0c..d14dbfdd 100755 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -2165,33 +2165,12 @@ sub all_years { $dbh = $self->{dbh}; + $self->{all_years} = []; + # get years my $query = qq| - SELECT (SELECT transdate FROM acc_trans ORDER BY transdate asc - LIMIT 1), - (SELECT transdate FROM acc_trans ORDER BY transdate desc - LIMIT 1)|; - - my ( $startdate, $enddate ) = $dbh->selectrow_array($query); - - if ( $myconfig->{dateformat} =~ /^yy/ ) { - ($startdate) = split /\W/, $startdate; - ($enddate) = split /\W/, $enddate; - } - else { - (@_) = split /\W/, $startdate; - $startdate = $_[2]; - (@_) = split /\W/, $enddate; - $enddate = $_[2]; - } - - $self->{all_years} = (); - $startdate = substr( $startdate, 0, 4 ); - $enddate = substr( $enddate, 0, 4 ); - - while ( $enddate >= $startdate ) { - push @{ $self->{all_years} }, $enddate--; - } + SELECT extract('YEARS' FROM transdate) FROM acc_trans + GROUP BY extract('YEARS' FROM transdate) ORDER BY 1 DESC|; #this should probably be changed to use locale %{ $self->{all_month} } = ( -- cgit v1.2.3