my @a = (transdate, invnumber, name);
push @a, "employee" if $self->{l_employee};
- my $sortorder = join(', ', @a);
+ my $sortdir = $form->{sortdir} ? 'ASC' : 'DESC';
+ my $sortorder = join(', ', map { "$_ $sortdir" } @a);
if (grep({ $_ eq $form->{sort} }
qw(transdate id invnumber ordnumber name netamount tax amount
paid datepaid due duedate notes employee))) {
- $sortorder = $form->{sort};
+ $sortorder = $form->{sort} . " $sortdir";
}
- $query .= " ORDER by $sortorder";
+ $query .= " ORDER BY $sortorder";
my $sth = $dbh->prepare($query);
$sth->execute(@values) ||
($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
- $form->{sort} ||= 'transdate';
+ report_generator_set_default_sort('transdate', 1);
AP->ap_transactions(\%myconfig, \%$form);
'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
);
- foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid
- employee shippingpoint shipvia)) {
- $column_defs{$name}->{link} = $href . "&sort=$name";
+ foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia)) {
+ my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
}
my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
$report->set_export_options('ap_transactions', @hidden_variables);
- $report->set_sort_indicator($form->{sort}, 1);
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
my @options;
if ($form->{vendor}) {