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,
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);
$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;
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 };
);
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;
$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 }),