-
-
-
-|;
+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
- map { print "$column_header{$_}\n" } @column_index;
+ my @columns = qw(statement ct invnumber transdate duedate c0 c30 c60 c90);
- print qq|
-
-|;
+ my %column_defs = (
+ 'statement' => { 'text' => '', 'visible' => $form->{ct} eq 'customer' ? 'HTML' : 0, },
+ 'ct' => { 'text' => $form->{ct} eq 'customer' ? $locale->text('Customer') : $locale->text('Vendor'), },
+ 'invnumber' => { 'text' => $locale->text('Invoice'), },
+ 'transdate' => { 'text' => $locale->text('Date'), },
+ 'duedate' => { 'text' => $locale->text('Due'), },
+ 'c0' => { 'text' => $locale->text('Current'), },
+ 'c30' => { 'text' => '30', },
+ 'c60' => { 'text' => '60', },
+ 'c90' => { 'text' => '90', },
+ );
- $ctid = 0;
- $subtotal = 0;
- $i = 0;
+ my %column_alignment = ('statement' => 'center',
+ map { $_ => 'right' } qw(c0 c30 c60 c90));
- foreach $ref (@{ $form->{AG} }) {
+ $report->set_options('std_column_visibility' => 1);
+ $report->set_columns(%column_defs);
+ $report->set_column_order(@columns);
- if ($ctid != $ref->{ctid}) {
+ my @hidden_variables = qw(todate customer vendor arap title ct);
+ $report->set_export_options('generate_' . ($form->{arap} eq 'ar' ? 'ar' : 'ap') . '_aging', @hidden_variables);
- $i++;
+ my @options;
- if ($subtotal) {
- $c0subtotal =
- $form->format_amount(\%myconfig, $c0subtotal, 2, " ");
- $c30subtotal =
- $form->format_amount(\%myconfig, $c30subtotal, 2, " ");
- $c60subtotal =
- $form->format_amount(\%myconfig, $c60subtotal, 2, " ");
- $c90subtotal =
- $form->format_amount(\%myconfig, $c90subtotal, 2, " ");
- }
+ if ($form->{department}) {
+ my ($department) = split /--/, $form->{department};
+ push @options, $locale->text('Department') . " : $department";
+ $form->{callback} .= "&department=" . E($department);
+ }
- $column_data{ct} = qq| | |;
- $column_data{invnumber} = qq| | |;
- $column_data{transdate} = qq| | |;
- $column_data{duedate} = qq| | |;
- $column_data{c0} =
- qq|$c0subtotal | |;
- $column_data{c30} =
- qq|$c30subtotal | |;
- $column_data{c60} =
- qq|$c60subtotal | |;
- $column_data{c90} =
- qq|$c90subtotal | |;
-
- if ($subtotal) {
-
- # print subtotals
- print qq|
-
-|;
+ if (($form->{arap} eq 'ar') && $form->{customer}) {
+ push @options, $form->{customer};
+ }
- map { print "$column_data{$_}\n" } @column_index;
+ if (($form->{arap} eq 'ap') && $form->{vendor}) {
+ push @options, $form->{vendor};
+ }
- $column_data{statement} = qq| | |;
+ push @options, $locale->text('for Period') . " " . $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{todate}, 1);
- print qq|
-
-|;
- }
+ my $attachment_basename = $form->{ct} eq 'customer' ? $locale->text('ar_aging_list') : $locale->text('ap_aging_list');
- $subtotal = 1;
+ $report->set_options('top_info_text' => join("\n", @options),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $attachment_basename . strftime('_%Y%m%d', localtime time),
+ );
- $c0subtotal = 0;
- $c30subtotal = 0;
- $c60subtotal = 0;
- $c90subtotal = 0;
+ my $previous_ctid = 0;
+ my $row_idx = 0;
+ my @periods = qw(0 30 60 90);
+ my %subtotals = map { $_ => 0 } @periods;
+ my %totals = map { $_ => 0 } @periods;
- $column_data{ct} = qq|$ref->{name} | |;
- $column_data{statement} =
- qq|{checked}>
- {ctid}>
- | |;
+ foreach $ref (@{ $form->{AG} }) {
+ if ($row_idx && ($previous_ctid != $ref->{ctid})) {
+ $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal'));
}
- $c0subtotal += $ref->{c0};
- $c30subtotal += $ref->{c30};
- $c60subtotal += $ref->{c60};
- $c90subtotal += $ref->{c90};
-
- $c0total += $ref->{c0};
- $c30total += $ref->{c30};
- $c60total += $ref->{c60};
- $c90total += $ref->{c90};
-
- $ref->{c0} = $form->format_amount(\%myconfig, $ref->{c0}, 2, " ");
- $ref->{c30} = $form->format_amount(\%myconfig, $ref->{c30}, 2, " ");
- $ref->{c60} = $form->format_amount(\%myconfig, $ref->{c60}, 2, " ");
- $ref->{c90} = $form->format_amount(\%myconfig, $ref->{c90}, 2, " ");
+ foreach my $key (@periods) {
+ $subtotals{$key} += $ref->{"c${key}"};
+ $totals{$key} += $ref->{"c${key}"};
+ $ref->{"c${key}"} = $ref->{"c${key}"} != 0 ? $form->format_amount(\%myconfig, $ref->{"c${key}"}, 2) : '';
+ }
- $href =
- qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=|
- . $form->escape($form->{callback});
+ my $row = { };
- $column_data{invnumber} = qq|$ref->{invnumber} | |;
- $column_data{transdate} = qq|$ref->{transdate} | |;
- $column_data{duedate} = qq|$ref->{duedate} | |;
- $column_data{c0} = qq|$ref->{c0} | |;
- $column_data{c30} = qq|$ref->{c30} | |;
- $column_data{c60} = qq|$ref->{c60} | |;
- $column_data{c90} = qq|$ref->{c90} | |;
-
- $j++;
- $j %= 2;
- print qq|
-
-|;
+ foreach my $column (@columns) {
+ $row->{$column} = {
+ 'data' => (($column eq 'ct') || ($column eq 'statement')) ? '' : $ref->{$column},
+ 'align' => $column_alignment{$column},
+ 'valign' => $column eq 'statement' ? 'center' : '',
+ };
+ }
- map { print "$column_data{$_}\n" } @column_index;
+ $row->{invnumber}->{link} = build_std_url("script=$ref->{module}.pl", 'action=edit', 'callback', 'id=' . E($ref->{id}));
- print qq|
-
-|;
+ if ($previous_ctid != $ref->{ctid}) {
+ $row->{statement}->{raw_data} =
+ $cgi->hidden('-name' => "customer_id_${row_idx}", '-value' => $ref->{ctid})
+ . $cgi->checkbox('-name' => "statement_${row_idx}", '-value' => 1, '-label' => '', 'checked' => $ref->{checked});
+ $row->{ct}->{data} = $ref->{name};
- $column_data{ct} = qq| | |;
- $column_data{statement} = qq| | |;
+ $row_idx++;
+ }
- $ctid = $ref->{ctid};
+ $previous_ctid = $ref->{ctid};
+ $report->add_data($row);
}
- # print subtotals
- $c0subtotal = $form->format_amount(\%myconfig, $c0subtotal, 2, " ");
- $c30subtotal = $form->format_amount(\%myconfig, $c30subtotal, 2, " ");
- $c60subtotal = $form->format_amount(\%myconfig, $c60subtotal, 2, " ");
- $c90subtotal = $form->format_amount(\%myconfig, $c90subtotal, 2, " ");
-
- print qq|
-
-|;
-
- map { $column_data{$_} = qq| | | } @column_index;
-
- $column_data{c0} = qq|$c0subtotal | |;
- $column_data{c30} = qq|$c30subtotal | |;
- $column_data{c60} = qq|$c60subtotal | |;
- $column_data{c90} = qq|$c90subtotal | |;
-
- map { print "$column_data{$_}\n" } @column_index;
-
- print qq|
-
-
-|;
-
- $c0total = $form->format_amount(\%myconfig, $c0total, 2, " ");
- $c30total = $form->format_amount(\%myconfig, $c30total, 2, " ");
- $c60total = $form->format_amount(\%myconfig, $c60total, 2, " ");
- $c90total = $form->format_amount(\%myconfig, $c90total, 2, " ");
+ $report->add_data(create_aging_subtotal_row(\%subtotals, \@columns, \@periods, 'listsubtotal')) if ($row_idx);
- $column_data{c0} = qq|$c0total | |;
- $column_data{c30} = qq|$c30total | |;
- $column_data{c60} = qq|$c60total | |;
- $column_data{c90} = qq|$c90total | |;
-
- map { print "$column_data{$_}\n" } @column_index;
-
- print qq|
-
-
-
- |
-
-