-
-
-
-|;
-
- map { print "\n$column_header{$_}" } @column_index;
-
- print qq|
-
-|;
+ $report->set_options('top_info_text' => join("\n", @options),
+ 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
+ 'output_format' => 'HTML',
+ 'title' => $form->{title},
+ 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
+ );
+ $report->set_options_from_form();
# add sort and escape callback, this one we use for the add sub
- $form->{callback} = $callback .= "&sort=$form->{sort}";
+ $form->{callback} = $href .= "&sort=$form->{sort}";
# escape callback for href
- $callback = $form->escape($callback);
+ $callback = $form->escape($href);
- if (@{ $form->{AR} }) {
- $sameitem = $form->{AR}->[0]->{ $form->{sort} };
- }
+ my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
- # sums and tax on reports by Antonio Gallardo
- #
- foreach $ar (@{ $form->{AR} }) {
+ my %totals = map { $_ => 0 } @subtotal_columns;
+ my %subtotals = map { $_ => 0 } @subtotal_columns;
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ar->{ $form->{sort} }) {
- &ar_subtotal;
- }
- }
+ my $idx = 0;
- $column_data{netamount} =
- ""
- . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ")
- . " | ";
- $column_data{tax} = ""
- . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount},
- 2, " ")
- . " | ";
- $column_data{amount} =
- ""
- . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . " | ";
- $column_data{paid} =
- ""
- . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . " | ";
- $column_data{due} = ""
- . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid},
- 2, " ")
- . " | ";
-
- $subtotalnetamount += $ar->{netamount};
- $subtotalamount += $ar->{amount};
- $subtotalpaid += $ar->{paid};
- $subtotaldue += $ar->{amount} - $ar->{paid};
-
- $totalnetamount += $ar->{netamount};
- $totalamount += $ar->{amount};
- $totalpaid += $ar->{paid};
- $totaldue += ($ar->{amount} - $ar->{paid});
-
- $column_data{transdate} = "$ar->{transdate} | ";
- $column_data{id} = "$ar->{id} | ";
- $column_data{datepaid} = "$ar->{datepaid} | ";
- $column_data{duedate} = "$ar->{duedate} | ";
-
- $module = ($ar->{invoice}) ? "is.pl" : $form->{script};
-
- $column_data{invnumber} =
- "{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber} | ";
- $column_data{type} = "" .
- ($ar->{storno} ? $locale->text("Storno (one letter abbreviation)") :
- $ar->{amount} < 0 ?
- $locale->text("Credit note (one letter abbreviation)") :
- $locale->text("Invoice (one letter abbreviation)")) . " | ";
- $column_data{ordnumber} = "$ar->{ordnumber} | ";
- $column_data{name} = "$ar->{name} | ";
- $ar->{notes} =~ s/\r\n/ /g;
- $column_data{notes} = "$ar->{notes} | ";
- $column_data{shippingpoint} = "$ar->{shippingpoint} | ";
- $column_data{shipvia} = "$ar->{shipvia} | ";
- $column_data{employee} = "$ar->{employee} | ";
-
- $i++;
- $i %= 2;
- print "
-
-";
+ foreach my $ar (@{ $form->{AR} }) {
+ $ar->{tax} = $ar->{amount} - $ar->{netamount};
+ $ar->{due} = $ar->{amount} - $ar->{paid};
- map { print "\n$column_data{$_}" } @column_index;
+ map { $subtotals{$_} += $ar->{$_};
+ $totals{$_} += $ar->{$_} } @subtotal_columns;
- print qq|
-
-|;
+ $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
+ $totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
- }
+ map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
- if ($form->{l_subtotal} eq 'Y') {
- &ar_subtotal;
- }
+ my $is_storno = $ar->{storno} && $ar->{storno_id};
+ my $has_storno = $ar->{storno} && !$ar->{storno_id};
- # print totals
- print qq|
-
-|;
+ $ar->{type} =
+ $has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
+ $is_storno ? $locale->text("Storno (one letter abbreviation)") :
+ $ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
+ $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
+ $locale->text("AR Transaction (abbreviation)");
- map { $column_data{$_} = " | " } @column_index;
-
- $column_data{netamount} =
- ""
- . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . " | ";
- $column_data{tax} = ""
- . $form->format_amount(\%myconfig, $totalamount - $totalnetamount,
- 2, " ")
- . " | ";
- $column_data{amount} =
- ""
- . $form->format_amount(\%myconfig, $totalamount, 2, " ") . " | ";
- $column_data{paid} =
- ""
- . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . " | ";
- $column_data{due} =
- ""
- . $form->format_amount(\%myconfig, $totaldue, 2, " ") . " | ";
-
- map { print "\n$column_data{$_}" } @column_index;
+ my $row = { };
- print qq|
-
-
- |
-
-