- my $link_table = $self->info->{link_table};
- # For each distinct tax name (the values set as $taxline->itemdesc),
- # create a consolidated tax item with the total amount and all the links
- # of all tax items that share that name.
- foreach my $taxname ( keys %taxname ) {
- my @tax_links;
- my $tax_cust_bill_pkg = FS::cust_bill_pkg->new({
- 'invnum' => $cust_bill->invnum,
+ return @raw_taxlines;
+}
+
+sub consolidate_taxlines {
+
+ my $self = shift;
+ my $conf = $self->{conf};
+
+ my @raw_taxlines = @_;
+ return if !@raw_taxlines; # shouldn't even be here
+
+ my @tax_line_items;
+
+ # keys are tax names (as printed on invoices / itemdesc )
+ # values are arrayrefs of tax links ("raw taxlines")
+ my %taxname;
+ # collate these by itemdesc
+ foreach my $taxline (@raw_taxlines) {
+ my $taxname = $taxline->taxname;
+ $taxname{$taxname} ||= [];
+ push @{ $taxname{$taxname} }, $taxline;
+ }
+
+ # keys are taxnums
+ # values are (cumulative) amounts
+ my %tax_amount;
+
+ my $link_table = $raw_taxlines[0]->table;
+
+ # Preconstruct cust_bill_pkg objects that will become the "final"
+ # taxlines for each name, so that we can reference them.
+ # (keys are taxnames)
+ my %real_taxline_named = map {
+ $_ => FS::cust_bill_pkg->new({