X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTaxEngine.pm;h=70f1f9223cbab035ff71980cc119425b94292e43;hb=c14803e37f1bfdcff882ee5cb35a9b10a93a88c9;hp=0972fb74dc10956704d7e1670f9e22a9f615c2bc;hpb=76d6fe17d02b77301619065ad43d7300432e977c;p=freeside.git diff --git a/FS/FS/TaxEngine.pm b/FS/FS/TaxEngine.pm index 0972fb74d..70f1f9223 100644 --- a/FS/FS/TaxEngine.pm +++ b/FS/FS/TaxEngine.pm @@ -40,8 +40,12 @@ FS::TaxEngine - Base class for tax calculation engines. Creates an L object. The subclass will be chosen by the 'enable_taxproducts' configuration setting. -CUST_MAIN and TIME are required. OPTIONS can include "cancel" => 1 to -indicate that the package is being billed on cancellation. +CUST_MAIN and TIME are required. OPTIONS can include: + +"cancel" => 1 to indicate that the package is being billed on cancellation. + +"estimate" => 1 to indicate that this calculation is for tax estimation, +and isn't an actual sale invoice, in case that matters. =cut @@ -160,19 +164,27 @@ sub consolidate_taxlines { my %tax_amount; my $link_table = $self->info->{link_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({ + 'pkgnum' => 0, + 'recur' => 0, + 'sdate' => '', + 'edate' => '', + 'itemdesc' => $_ + }) + } keys %taxname; + # 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({ - 'pkgnum' => 0, - 'recur' => 0, - 'sdate' => '', - 'edate' => '', - 'itemdesc' => $taxname, - $link_table => \@tax_links, - }); + my $tax_cust_bill_pkg = $real_taxline_named{$taxname}; + $tax_cust_bill_pkg->set( $link_table => \@tax_links ); my $tax_total = 0; warn "adding $taxname\n" if $DEBUG > 1; @@ -183,6 +195,16 @@ sub consolidate_taxlines { $tax_total += $taxitem->setup; foreach my $link ( @{ $taxitem->get($link_table) } ) { $link->set('tax_cust_bill_pkg', $tax_cust_bill_pkg); + + # if the link represents tax on tax, also fix its taxable pointer + # to point to the "final" taxline + my $taxable_cust_bill_pkg = $link->get('taxable_cust_bill_pkg'); + if (my $other_taxname = $taxable_cust_bill_pkg->itemdesc) { + $link->set('taxable_cust_bill_pkg', + $real_taxline_named{$other_taxname} + ); + } + push @tax_links, $link; } } # foreach $taxitem