my $usage_total;
foreach my $classnum ($self->usage_classes) {
+ next if $classnum eq ''; # null-class usage is included in 'recur'
my $amount = $self->usage($classnum);
next if $amount == 0; # though if so we shouldn't be here
my $usage_item = FS::cust_bill_pkg->new({
my $sql = 'SELECT SUM(COALESCE(amount,0)) FROM cust_bill_pkg_detail '.
' WHERE billpkgnum = '. $self->billpkgnum;
- $sql .= " AND classnum = $classnum" if defined($classnum);
+ if ($classnum =~ /^(\d+)$/) {
+ $sql .= " AND classnum = $1";
+ } elsif (defined($classnum) and $classnum eq '') {
+ $sql .= " AND classnum IS NULL";
+ }
my $sth = dbh->prepare($sql) or die dbh->errstr;
$sth->execute or die $sth->errstr;
my $self = shift;
if ( $self->pkgnum ) { # normal sales
return $self->cust_pkg->tax_locationnum;
- } elsif ( $self->feepart ) { # fees
+ } elsif ( $self->feepart and $self->invnum ) { # fees
return $self->cust_bill->cust_main->ship_locationnum;
} else { # taxes
return '';
my $self = shift;
if ( $self->pkgnum ) { # normal sales
return $self->cust_pkg->tax_location;
- } elsif ( $self->feepart ) { # fees
+ } elsif ( $self->feepart and $self->invnum ) { # fees
return $self->cust_bill->cust_main->ship_location;
} else { # taxes
return;
# pertain to this tax def
$taxable_charged -= $_->amount;
}
-
- my $locationnum = $cust_bill_pkg->tax_locationnum;
+
+ # can't determine the tax_locationnum directly for fees; they're not
+ # yet linked to an invoice
+ my $locationnum = $cust_bill_pkg->tax_locationnum
+ || $cust_main->ship_locationnum;
### Monthly capped exemptions ###
if ( $self->exempt_amount && $self->exempt_amount > 0
} elsif ( $self->unittype == 2 ) {
+ my $locationnum = $cust_bill_pkg->tax_locationnum
+ || $cust_main->ship_locationnum;
# per account
- $units = 1 unless $seen{$cust_bill_pkg->tax_locationnum};
- $seen{$cust_bill_pkg->tax_locationnum} = 1;
+ $units = 1 unless $seen{$locationnum};
+ $seen{$locationnum} = 1;
} else {
# Unittype 19 is used for prepaid wireless E911 charges in many states.