-
-
-
-|;
+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
- map { print "$column_header{$_}\n" } @column_index;
+ $report->set_options('top_info_text' => join("\n", @options),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $locale->text('list_of_transactions') . strftime('_%Y%m%d', localtime time),
+ 'std_column_visibility' => 1,
+ );
+ $report->set_options_from_form();
- print qq|
-
-|;
+ $report->set_columns(%column_defs);
+ $report->set_column_order(@columns);
- $ctid = 0;
- $subtotal = 0;
- $i = 0;
+ $report->set_export_options($action, @hidden_variables);
- foreach $ref (@{ $form->{AG} }) {
+ $report->set_sort_indicator('accno', 1);
- if ($ctid != $ref->{ctid}) {
+ my @totals_columns = qw(credit debit begbalance endbalance);
+ my %subtotals = map { $_ => 0 } @totals_columns;
+ my %totals = map { $_ => 0 } @totals_columns;
+ my $found_heading = 0;
+ my @tb = sort { $a->{accno} cmp $b->{accno} } @{ $form->{TB} };
- $i++;
+ # sort the whole thing by account numbers and display
+ foreach my $idx (0 .. scalar(@tb) - 1) {
+ my $ref = $tb[$idx];
+ my $href = build_std_url('script=ca.pl', 'action=list_transactions', 'accno=' . E($ref->{accno}), 'description=' . E($ref->{description}), @hidden_variables);
- if ($subtotal) {
- $c0subtotal = ($c0subtotal != 0) ?
- $form->format_amount(\%myconfig, $c0subtotal, 2, " ") : "";
- $c30subtotal = ($c30subtotal != 0) ?
- $form->format_amount(\%myconfig, $c30subtotal, 2, " ") : "";
- $c60subtotal = ($c60subtotal != 0) ?
- $form->format_amount(\%myconfig, $c60subtotal, 2, " ") : "";
- $c90subtotal = ($c90subtotal != 0) ?
- $form->format_amount(\%myconfig, $c90subtotal, 2, " ") : "";
- }
+ my $ml = ($ref->{category} =~ /(A|C|E)/) ? -1 : 1;
- $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|
-
-|;
+ my $row = { map { $_ => { 'align' => $column_alignment{$_} } } @columns };
- map { print "$column_data{$_}\n" } @column_index;
+ if ($ref->{charttype} eq 'H') {
+ next unless ($form->{l_heading});
- $column_data{statement} = qq| | |;
+ %subtotals = map { $_ => 0 } @totals_columns;
+ $found_heading = 1;
+ $row->{description}->{class} = 'listheading';
+ $row->{description}->{data} = $ref->{description};
- print qq|
-
-|;
- }
+ $report->add_data($row);
- $subtotal = 1;
+ next;
+ }
- $c0subtotal = 0;
- $c30subtotal = 0;
- $c60subtotal = 0;
- $c90subtotal = 0;
+ foreach (qw(debit credit)) {
+ $subtotals{$_} += $ref->{$_};
+ $totals{$_} += $ref->{$_};
+ }
- $column_data{ct} = qq|$ref->{name} | |;
- $column_data{statement} =
- qq|{checked}>
- {ctid}>
- | |;
+ $subtotals{begbalance} += $ref->{balance} * $ml;
+ $subtotals{endbalance} += ($ref->{balance} + $ref->{amount}) * $ml;
+
+ map { $row->{$_}->{data} = $ref->{$_} } qw(accno description);
+ map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $ref->{$_}, 2) if ($ref->{$_} != 0) } qw(credit debit);
+
+ $row->{begbalance}->{data} = $form->format_amount(\%myconfig, $ref->{balance} * $ml, 2);
+ $row->{endbalance}->{data} = $form->format_amount(\%myconfig, ($ref->{balance} + $ref->{amount}) * $ml, 2);
+
+ $report->add_data($row);
+
+ if ($form->{l_heading} && $found_heading &&
+ (($idx == scalar(@tb) - 1) || ('H' eq $tb[$idx + 1]->{charttype}))) {
+ $report->add_data(create_list_accounts_subtotal_row(\%subtotals, \@columns, \@totals_columns, 'listsubtotal'));
}
+ }
- $c0subtotal += $ref->{c0};
- $c30subtotal += $ref->{c30};
- $c60subtotal += $ref->{c60};
- $c90subtotal += $ref->{c90};
+ $report->add_separator();
- $c0total += $ref->{c0};
- $c30total += $ref->{c30};
- $c60total += $ref->{c60};
- $c90total += $ref->{c90};
+ $report->add_data(create_list_accounts_subtotal_row(\%totals, \@columns, [ qw(debit credit) ], 'listtotal'));
- $ref->{c0} = ($ref->{c0} != 0) ? $form->format_amount(\%myconfig, $ref->{c0}, 2, " ") : "";
- $ref->{c30} = ($ref->{c30} != 0) ? $form->format_amount(\%myconfig, $ref->{c30}, 2, " ") : "";
- $ref->{c60} = ($ref->{c60} != 0) ? $form->format_amount(\%myconfig, $ref->{c60}, 2, " ") : "";
- $ref->{c90} = ($ref->{c90} != 0) ? $form->format_amount(\%myconfig, $ref->{c90}, 2, " ") : "";
+ $report->generate_with_headers();
- $href =
- qq|$ref->{module}.pl?path=$form->{path}&action=edit&id=$ref->{id}&login=$form->{login}&password=$form->{password}&callback=|
- . $form->escape($form->{callback});
+ $lxdebug->leave_sub();
+}
- $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|
-
-|;
+sub generate_ar_aging {
+ $lxdebug->enter_sub();
- map { print "$column_data{$_}\n" } @column_index;
+ $auth->assert('general_ledger');
- print qq|
-
-|;
+ # split customer
+ ($form->{customer}) = split(/--/, $form->{customer});
- $column_data{ct} = qq| | |;
- $column_data{statement} = qq| | |;
+ $form->{ct} = "customer";
+ $form->{arap} = "ar";
+
+ $form->{callback} = build_std_url('action=generate_ar_aging', qw(todate customer title));
+
+ RP->aging(\%myconfig, \%$form);
+ aging();
+
+ $lxdebug->leave_sub();
+}
+
+sub generate_ap_aging {
+ $lxdebug->enter_sub();
+
+ $auth->assert('general_ledger');
- $ctid = $ref->{ctid};
+ # split vendor
+ ($form->{vendor}) = split(/--/, $form->{vendor});
+
+ $form->{ct} = "vendor";
+ $form->{arap} = "ap";
+
+ $form->{callback} = build_std_url('action=generate_ap_aging', qw(todate vendor title));
+ RP->aging(\%myconfig, \%$form);
+ aging();
+
+ $lxdebug->leave_sub();
+}
+
+sub create_aging_subtotal_row {
+ $lxdebug->enter_sub();
+
+ my ($subtotals, $columns, $periods, $class) = @_;
+
+ my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => 'right' } } @{ $columns } };
+
+ foreach (@{ $periods }) {
+ $row->{"$_"}->{data} = $subtotals->{$_} != 0 ? $form->format_amount(\%myconfig, $subtotals->{$_}, 2) : '';
+ $subtotals->{$_} = 0;
}
- # 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, " ");
+ $lxdebug->leave_sub();
- print qq|
-
-|;
+ return $row;
+}
- map { $column_data{$_} = qq| | | } @column_index;
+sub aging {
+ $lxdebug->enter_sub();
- $column_data{c0} = qq|$c0subtotal | |;
- $column_data{c30} = qq|$c30subtotal | |;
- $column_data{c60} = qq|$c60subtotal | |;
- $column_data{c90} = qq|$c90subtotal | |;
+ $auth->assert('general_ledger');
- map { print "$column_data{$_}\n" } @column_index;
+ my $report = SL::ReportGenerator->new(\%myconfig, $form);
- print qq|
-
-
-|;
+ my @columns = qw(statement ct invnumber transdate duedate amount open);
- $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, " ");
+ 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'), },
+ 'amount' => { 'text' => $locale->text('Amount'), },
+ 'open' => { 'text' => $locale->text('Open'), },
+ );
- $column_data{c0} = qq|$c0total | |;
- $column_data{c30} = qq|$c30total | |;
- $column_data{c60} = qq|$c60total | |;
- $column_data{c90} = qq|$c90total | |;
+ my %column_alignment = ('statement' => 'center',
+ map { $_ => 'right' } qw(open amount));
- map { print "$column_data{$_}\n" } @column_index;
+ $report->set_options('std_column_visibility' => 1);
+ $report->set_columns(%column_defs);
+ $report->set_column_order(@columns);
- print qq|
-
-
-
- |
-
-