push(@values, $form->{dunningto});
}
- $query =
+ my %sort_columns = (
+ 'dunning_description' => [ qw(dn.dunning_description customername invnumber) ],
+ 'customername' => [ qw(customername invnumber) ],
+ 'invnumber' => [ qw(a.invnumber) ],
+ 'transdate' => [ qw(a.transdate a.invnumber) ],
+ 'duedate' => [ qw(a.duedate a.invnumber) ],
+ 'dunning_date' => [ qw(dunning_date a.invnumber) ],
+ 'dunning_duedate' => [ qw(dunning_duedate a.invnumber) ],
+ );
+
+ my $sortdir = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
+ my $sortkey = $sort_columns{$form->{sort}} ? $form->{sort} : 'customername';
+ my $sortorder = join ', ', map { "$_ $sortdir" } @{ $sort_columns{$sortkey} };
+
+ my $query =
qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount,
ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee,
da.interest, dn.dunning_description, da.transdate AS dunning_date,
JOIN customer ct ON (a.customer_id = ct.id), dunning da
LEFT JOIN dunning_config dn ON (da.dunning_config_id = dn.id)
$where
- ORDER BY name, a.id|;
+ ORDER BY $sortorder|;
$form->{DUNNINGS} = selectall_hashref_query($form, $dbh, $query, @values);
my @filter_field_list = qw(customer_id customer dunning_level department_id invnumber ordnumber
transdatefrom transdateto dunningfrom dunningto notes showold);
+ report_generator_set_default_sort('customername', 1);
+
DN->get_dunning(\%myconfig, \%$form);
if (!$form->{callback}) {
'title' => $form->{title});
$report->set_export_options('show_dunning', @filter_field_list);
- $report->set_columns(
+ my %column_defs = (
'checkbox' => { 'text' => '', 'visible' => 'HTML' },
'dunning_description' => { 'text' => $locale->text('Dunning Level') },
'customername' => { 'text' => $locale->text('Customername') },
'interest' => { 'text' => $locale->text('Interest') },
);
+ $report->set_columns(%column_defs);
$report->set_column_order(qw(checkbox dunning_description customername invnumber transdate
duedate amount dunning_date dunning_duedate fee interest));
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
my $edit_url = build_std_url('script=is.pl', 'action=edit', 'callback') . '&id=';
my $print_url = build_std_url('action=print_dunning', 'format=pdf', 'media=screen') . '&dunning_id=';
+ my $sort_url = build_std_url('action=show_dunning', grep { $form->{$_} } @filter_field_list);
+
+ foreach my $name (qw(dunning_description customername invnumber transdate duedate dunning_date dunning_duedate)) {
+ my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$name}->{link} = $sort_url . "&sort=$name&sortdir=$sortdir";
+ }
my %alignment = map { $_ => 'right' } qw(transdate duedate amount dunning_date dunning_duedate fee interest);