From: Moritz Bunkus Date: Mon, 7 Jul 2008 12:55:09 +0000 (+0000) Subject: Wiedervorlagenbericht sortierbar gemacht. X-Git-Tag: release-2.6.0beta1~79 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=e02b6c616968db9aef1ba9425254d4b29ff1c7e8;p=kivitendo-erp.git Wiedervorlagenbericht sortierbar gemacht. --- diff --git a/SL/FU.pm b/SL/FU.pm index bd761913c..c34a03129 100644 --- a/SL/FU.pm +++ b/SL/FU.pm @@ -241,6 +241,20 @@ sub follow_ups { push @values, $employee_id; } + my $order_by = ''; + + if ($form->{sort} ne 'title') { + my %sort_columns = ( + 'follow_up_date' => [ qw(fu.follow_up_date fu.id) ], + 'created_on' => [ qw(created_on fu.id) ], + 'subject' => [ qw(lower(n.subject)) ], + ); + + my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC'; + my $sortkey = $sort_columns{$form->{sort}} ? $form->{sort} : 'follow_up_date'; + $order_by = 'ORDER BY ' . join(', ', map { "$_ $sortdir" } @{ $sort_columns{$sortkey} }); + } + $query = qq|SELECT fu.*, n.subject, n.body, n.created_by, fu.follow_up_date <= current_date AS due, fu.itime::DATE AS created_on, @@ -253,7 +267,7 @@ sub follow_ups { WHERE ((fu.created_by = ?) OR (fu.created_for_user = ?) $where_user) $where - ORDER BY fu.follow_up_date DESC, fu.id ASC|; + $order_by|; my $follow_ups = selectall_hashref_query($form, $dbh, $query, @values); @@ -266,6 +280,14 @@ sub follow_ups { $fu->{LINKS} = $self->retrieve_links(%{ $fu }); } + if ($form->{sort} eq 'title') { + my $dir_factor = !defined $form->{sortdir} ? 1 : $form->{sortdir} ? 1 : -1; + $follow_ups = [ map { $_->[1] } + sort { ($a->[0] cmp $b->[0]) * $dir_factor } + map { my $fu = $follow_ups->[$_]; [ @{ $fu->{LINKS} } ? lc($fu->{LINKS}->[0]->{title}) : '', $fu ] } + (0 .. scalar(@{ $follow_ups }) - 1) ]; + } + $main::lxdebug->leave_sub(); return $follow_ups; diff --git a/bin/mozilla/fu.pl b/bin/mozilla/fu.pl index 7c78dd7ed..ae67e304e 100644 --- a/bin/mozilla/fu.pl +++ b/bin/mozilla/fu.pl @@ -205,6 +205,8 @@ sub report { my @report_params = qw(created_for subject body reference follow_up_date_from follow_up_date_to itime_from itime_to due_only all_users done not_done); + report_generator_set_default_sort('follow_up_date', 1); + my $follow_ups = FU->follow_ups(map { $_ => $form->{$_} } @report_params); $form->{rowcount} = scalar @{ $follow_ups }; @@ -222,6 +224,12 @@ sub report { ); my @columns = qw(selected follow_up_date created_on subject title created_by_name created_for_user_name done); + my $href = build_std_url('action=report', grep { $form->{$_} } @report_params); + + foreach my $name (qw(follow_up_date created_on title subject)) { + my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir}; + $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir"; + } my @options; @@ -253,7 +261,7 @@ sub report { $report->set_export_options('report', @report_params); - $report->set_sort_indicator('follow_up_date', 1); + $report->set_sort_indicator($form->{sort}, $form->{sortdir}); $report->set_options('raw_top_info_text' => $form->parse_html_template('fu/report_top', { 'OPTIONS' => \@options }), 'raw_bottom_info_text' => $form->parse_html_template('fu/report_bottom', { 'HIDDEN' => \@hidden_report_params }),