From 4b48d335511464f7a37b92e6d5c0cbed616fe48d Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 7 Jul 2008 14:03:08 +0000 Subject: [PATCH] Buchungsjournal auf- und absteigend sortierbar gemacht. --- SL/GL.pm | 34 ++++++++++++++++++++++++++++------ bin/mozilla/gl.pl | 21 +++++++++++++-------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/SL/GL.pm b/SL/GL.pm index 28c503043..51fbfacc8 100644 --- a/SL/GL.pm +++ b/SL/GL.pm @@ -323,11 +323,30 @@ sub all_transactions { my $false = ($myconfig->{dbdriver} eq 'Pg') ? FALSE: q|'0'|; - my $sortorder; - - if ($form->{sort}) { - $form->{sort} =~ s/[^a-zA-Z_]//g; - $sortorder = $form->{sort} . ","; + my %sort_columns = ( + 'id' => [ qw(id) ], + 'transdate' => [ qw(transdate id) ], + 'reference' => [ qw(lower_reference id) ], + 'source' => [ qw(lower_source id) ], + 'description' => [ qw(lower_description id) ], + 'accno' => [ qw(accno transdate id) ], + ); + my %lowered_columns = ( + 'reference' => { 'gl' => 'g.reference', 'arap' => 'a.invnumber', }, + 'source' => { 'gl' => 'ac.source', 'arap' => 'ac.source', }, + 'description' => { 'gl' => 'g.description', 'arap' => 'ct.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); } my $query = @@ -336,6 +355,7 @@ sub all_transactions { g.description, ac.transdate, ac.source, ac.trans_id, ac.amount, c.accno, g.notes, t.chart_id, ac.oid $project_columns + $columns_for_sorting{gl} FROM gl g, acc_trans ac $project_join, chart c LEFT JOIN tax t ON (t.chart_id = c.id) WHERE $glwhere @@ -348,6 +368,7 @@ sub all_transactions { ct.name, ac.transdate, ac.source, ac.trans_id, ac.amount, c.accno, a.notes, t.chart_id, ac.oid $project_columns + $columns_for_sorting{arap} FROM ar a, acc_trans ac $project_join, customer ct, chart c LEFT JOIN tax t ON (t.chart_id=c.id) WHERE $arwhere @@ -361,6 +382,7 @@ sub all_transactions { ct.name, ac.transdate, ac.source, ac.trans_id, ac.amount, c.accno, a.notes, t.chart_id, ac.oid $project_columns + $columns_for_sorting{arap} FROM ap a, acc_trans ac $project_join, vendor ct, chart c LEFT JOIN tax t ON (t.chart_id=c.id) WHERE $apwhere @@ -368,7 +390,7 @@ sub all_transactions { AND (a.vendor_id = ct.id) AND (a.id = ac.trans_id) - ORDER BY $sortorder transdate, trans_id, acoid, taxkey DESC|; + ORDER BY $sortorder, acoid $sortdir|; my @values = (@glvalues, @arvalues, @apvalues); diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index 7cc8c0162..128113eaf 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -421,7 +421,7 @@ sub generate_report { $auth->assert('general_ledger'); - $form->{sort} ||= "transdate"; + report_generator_set_default_sort('transdate', 1); GL->all_transactions(\%myconfig, \%$form); @@ -468,7 +468,7 @@ sub generate_report { } - my $callback = build_std_url('action=generate_report', @hidden_variables); + my $callback = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables); $form->{l_credit_accno} = 'Y'; $form->{l_debit_accno} = 'Y'; @@ -497,14 +497,19 @@ sub generate_report { 'projectnumbers' => { 'text' => $locale->text('Project Numbers'), }, ); - map { $column_defs{$_}->{link} = $callback . "&sort=${_}" } qw(id transdate reference source description); - map { $column_defs{$_}->{link} = $callback . "&sort=accno" } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno debit_tax credit_tax); + foreach my $name (qw(id transdate reference source description debit_accno credit_accno debit_tax_accno credit_tax_accno)) { + my $sortname = $name =~ m/accno/ ? 'accno' : $name; + my $sortdir = $sortname eq $name ? 1 - $form->{sortdir} : $form->{sortdir}; + $column_defs{$name}->{link} = $callback . "&sort=$sortname&sortdir=$sortdir"; + } + map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns; map { $column_defs{$_}->{visible} = 0 } qw(debit_accno credit_accno debit_tax_accno credit_tax_accno) if $form->{accno}; my %column_alignment; - map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax); - map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno); + map { $column_alignment{$_} = 'right' } qw(balance id debit credit debit_tax credit_tax); + map { $column_alignment{$_} = 'center' } qw(transdate reference description source notes debit_accno credit_accno debit_tax_accno credit_tax_accno); + map { $column_defs{$_}->{align} = $column_alignment{$_} } keys %column_alignment; my $report = SL::ReportGenerator->new(\%myconfig, $form); @@ -513,7 +518,7 @@ sub generate_report { $report->set_export_options('generate_report', @hidden_variables); - $report->set_sort_indicator($form->{sort}, 1); + $report->set_sort_indicator($form->{sort} eq 'accno' ? 'debit_accno' : $form->{sort}, $form->{sortdir}); $report->set_options('top_info_text' => join("\n", @options), 'output_format' => 'HTML', @@ -523,7 +528,7 @@ sub generate_report { $report->set_options_from_form(); # add sort to callback - $form->{callback} = "$callback&sort=" . E($form->{sort}); + $form->{callback} = "$callback&sort=" . E($form->{sort}) . "&sortdir=" . E($form->{sortdir}); $form->{balance} *= $ml; -- 2.20.1