From 94e596e55cef6b9ef9b80b5a4dba8204e0c29c9f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 7 Jul 2008 14:49:04 +0000 Subject: [PATCH] =?utf8?q?Berichte=20=C3=BCber=20Zahlungsein-=20und=20-aus?= =?utf8?q?g=C3=A4nge=20auf-=20und=20absteigend=20sortierbar=20gemacht.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/RP.pm | 30 ++++++++++++++++++++++++++++-- bin/mozilla/rp.pl | 9 +++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/SL/RP.pm b/SL/RP.pm index 365d6e023..d536bf88a 100644 --- a/SL/RP.pm +++ b/SL/RP.pm @@ -1632,8 +1632,32 @@ sub payments { $where .= " AND (ac.memo ILIKE " . $dbh->quote('%' . $form->{memo} . '%') . ") "; } - my $sortorder = join(', ', qw(name invnumber ordnumber transdate source)); - $sortorder = $form->{sort} if ($form->{sort} && grep({ $_ eq $form->{sort} } qw(transdate invnumber name source memo))); + my %sort_columns = ( + 'transdate' => [ qw(transdate lower_invnumber lower_name) ], + 'invnumber' => [ qw(lower_invnumber lower_name transdate) ], + 'name' => [ qw(lower_name transdate) ], + 'source' => [ qw(lower_source) ], + 'memo' => [ qw(lower_memo) ], + ); + my %lowered_columns = ( + 'invnumber' => { 'gl' => 'g.reference', 'arap' => 'a.invnumber', }, + 'memo' => { 'gl' => 'ac.memo', 'arap' => 'ac.memo', }, + 'source' => { 'gl' => 'ac.source', 'arap' => 'ac.source', }, + 'name' => { 'gl' => 'g.description', 'arap' => 'c.name', }, + ); + + my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC'; + my $sortkey = $sort_columns{$form->{sort}} ? $form->{sort} : 'transdate'; + my $sortorder = join ', ', map { "$_ $sortdir" } @{ $sort_columns{$sortkey} }; + + + my %columns_for_sorting = ( 'gl' => '', 'arap' => '', ); + foreach my $spec (@{ $sort_columns{$sortkey} }) { + next if ($spec !~ m/^lower_(.*)$/); + + my $column = $1; + map { $columns_for_sorting{$_} .= sprintf(', lower(%s) AS lower_%s', $lowered_columns{$column}->{$_}, $column) } qw(gl arap); + } $query = qq|SELECT id, accno, description FROM chart WHERE accno = ?|; my $sth = prepare_query($form, $dbh, $query); @@ -1642,6 +1666,7 @@ sub payments { qq|SELECT c.name, a.invnumber, a.ordnumber, ac.transdate, ac.amount * $ml AS paid, ac.source, a.invoice, a.id, ac.memo, '${arap}' AS module + $columns_for_sorting{arap} FROM acc_trans ac JOIN $arap a ON (ac.trans_id = a.id) JOIN $table c ON (c.id = a.${table}_id) @@ -1655,6 +1680,7 @@ sub payments { SELECT g.description, g.reference, NULL AS ordnumber, ac.transdate, ac.amount * $ml AS paid, ac.source, '0' as invoice, g.id, ac.memo, 'gl' AS module + $columns_for_sorting{gl} FROM acc_trans ac JOIN gl g ON (g.id = ac.trans_id) $dpt_join diff --git a/bin/mozilla/rp.pl b/bin/mozilla/rp.pl index 4a548595b..4734d205e 100644 --- a/bin/mozilla/rp.pl +++ b/bin/mozilla/rp.pl @@ -2346,6 +2346,8 @@ sub list_payments { $option = $locale->text('Department') . " : $department"; } + report_generator_set_default_sort('transdate', 1); + RP->payments(\%myconfig, \%$form); my @hidden_variables = qw(account title department reference source memo fromdate todate @@ -2365,7 +2367,10 @@ sub list_payments { ); my %column_alignment = ('paid' => 'right'); - map { $column_defs{$_}->{link} = $href . "&sort=$_" } grep { $_ ne 'paid' } @columns; + foreach my $name (grep { $_ ne 'paid' } @columns) { + my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir}; + $column_defs{$name}->{link} = $href . "&sort=${name}&sortdir=$sortdir"; + } my @options; if ($form->{fromdate}) { @@ -2392,7 +2397,7 @@ sub list_payments { $report->set_export_options('list_payments', @hidden_variables); - $report->set_sort_indicator($form->{sort}, 1); + $report->set_sort_indicator($form->{sort}, $form->{sortdir}); my $total_paid = 0; -- 2.20.1