-
-
-
-|;
+ foreach my $ar (@{ $form->{AR} }) {
+ $ar->{tax} = $ar->{amount} - $ar->{netamount};
+ $ar->{due} = $ar->{amount} - $ar->{paid};
- map { print "\n$column_header{$_}" } @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;
- # add sort and escape callback, this one we use for the add sub
- $form->{callback} = $callback .= "&sort=$form->{sort}";
+ map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
- # escape callback for href
- $callback = $form->escape($callback);
+ my $is_storno = $ar->{storno} && $ar->{storno_id};
+ my $has_storno = $ar->{storno} && !$ar->{storno_id};
- if (@{ $form->{AR} }) {
- $sameitem = $form->{AR}->[0]->{ $form->{sort} };
- }
+ $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)");
- # sums and tax on reports by Antonio Gallardo
- #
- foreach $ar (@{ $form->{AR} }) {
+ my $row = { };
- if ($form->{l_subtotal} eq 'Y') {
- if ($sameitem ne $ar->{ $form->{sort} }) {
- &ar_subtotal;
- }
+ foreach my $column (@columns) {
+ $row->{$column} = {
+ 'data' => $ar->{$column},
+ 'align' => $column_alignment{$column},
+ };
}
- $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 "
-
-";
+ $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
+ . "&id=" . E($ar->{id}) . "&callback=${callback}";
- map { print "\n$column_data{$_}" } @column_index;
+ my $row_set = [ $row ];
- print qq|
-
-|;
+ if (($form->{l_subtotal} eq 'Y')
+ && (($idx == (scalar @{ $form->{AR} } - 1))
+ || ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
+ push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
+ }
- }
+ $report->add_data($row_set);
- if ($form->{l_subtotal} eq 'Y') {
- &ar_subtotal;
+ $idx++;
}
- # print totals
- print qq|
-
-|;
-
- 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;
+ $report->add_separator();
+ $report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
- print qq|
-
-
- |
-
-