+
+ if ( $maximum and $self->taxable ) {
+ warn "Estimating taxes on fee.\n" if $DEBUG;
+ # then we need to estimate tax to respect the maximum
+ # XXX currently doesn't work with external (tax_rate) taxes
+ # or batch taxes, obviously
+ my $taxlisthash = {};
+ my $error = $cust_main->_handle_taxes(
+ $taxlisthash,
+ $cust_bill_pkg,
+ location => $cust_main->ship_location
+ );
+ my $total_rate = 0;
+ # $taxlisthash: tax identifier => [ cust_main_county, cust_bill_pkg... ]
+ my @taxes = map { $_->[0] } values %$taxlisthash;
+ foreach (@taxes) {
+ $total_rate += $_->tax;
+ }
+ if ($total_rate > 0) {
+ my $max_cents = $maximum * 100;
+ my $charge_cents = sprintf('%0.f', $max_cents * 100/(100 + $total_rate));
+ # the actual maximum that we can charge...
+ $maximum = sprintf('%.2f', $charge_cents / 100.00);
+ $amount = $maximum if $amount > $maximum;
+ }
+ } # if $maximum and $self->taxable
+
+ # set the amount that we'll charge