my @a = (transdate, invnumber, name);
push @a, "employee" if $form->{l_employee};
- my $sortorder = join(', ', @a);
+ my $sortdir = $form->{sortdir} ? 'ASC' : 'DESC';
+ my $sortorder = join(', ', map { "$_ $sortdir" } @a);
if (grep({ $_ eq $form->{sort} }
qw(id transdate duedate invnumber ordnumber name
datepaid employee shippingpoint shipvia))) {
- $sortorder = $form->{sort};
+ $sortorder = $form->{sort} . " $sortdir";
}
- $query .= " WHERE $where ORDER by $sortorder";
+ $query .= " WHERE $where ORDER BY $sortorder";
my $sth = $dbh->prepare($query);
$sth->execute(@values) ||
$form->{customer} = $form->unescape($form->{customer});
($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
- $form->{sort} ||= 'transdate';
+ report_generator_set_default_sort('transdate', 1);
AR->ar_transactions(\%myconfig, \%$form);
'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
);
- 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('ar_transactions', @hidden_variables);
- $report->set_sort_indicator($form->{sort}, 1);
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
my @options;
if ($form->{customer}) {