X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_bill_pkg_tax_rate_location.pm;h=7ae5250e9d81dbdd7f2d60118cd1f29535c7bfde;hp=fc5734fc1b55fbba6514bb4dfa16719e842ad1de;hb=HEAD;hpb=794a4505360fec404e2b9d5c6daf79f750186bfe diff --git a/FS/FS/cust_bill_pkg_tax_rate_location.pm b/FS/FS/cust_bill_pkg_tax_rate_location.pm index fc5734fc1..7ae5250e9 100644 --- a/FS/FS/cust_bill_pkg_tax_rate_location.pm +++ b/FS/FS/cust_bill_pkg_tax_rate_location.pm @@ -1,11 +1,12 @@ package FS::cust_bill_pkg_tax_rate_location; +use base qw( FS::Record ); use strict; -use base qw( FS::Record ); use FS::Record qw( qsearch qsearchs ); -use FS::cust_bill_pkg; use FS::cust_pkg; -use FS::cust_location; +use FS::cust_bill_pay_pkg; +use FS::cust_credit_bill_pkg; +use FS::tax_rate; =head1 NAME @@ -122,6 +123,86 @@ sub check { $self->SUPER::check; } +=item cust_bill_pkg + +Returns the associated cust_bill_pkg object + +=item tax_rate_location + +Returns the associated tax_rate_location object + +=item taxname + +Returns the tax name (the itemdesc). + +=cut + +sub taxname { + my $self = shift; + my $tax_rate = FS::tax_rate->by_key($self->taxnum) + or return ''; + $tax_rate->taxname; +} + +=item desc + +Returns a description for this tax line item constituent. Currently this +is the desc of the associated line item followed by the +state,county,city,locationtaxid for the location in parentheses. + +=cut + +sub desc { + my $self = shift; + my $tax_rate_location = $self->tax_rate_location; + my $location = join(', ', grep { $_ } + map { $tax_rate_location->$_ } + qw( state county city ) + ); + $location .= ( $location && $self->locationtaxid ) ? ', ' : ''; + $location .= $self->locationtaxid; + my $cust_bill_pkg_desc = $self->billpkgnum + ? $self->cust_bill_pkg->desc + : $self->cust_bill_pkg_desc; + "$cust_bill_pkg_desc ($location)"; + +} + + +=item owed + +Returns the amount owed (still outstanding) on this tax line item which is +the amount of this record minus all payment applications and credit +applications. + +=cut + +sub owed { + my $self = shift; + my $balance = $self->amount; + $balance -= $_->amount foreach ( $self->cust_bill_pay_pkg('setup') ); + $balance -= $_->amount foreach ( $self->cust_credit_bill_pkg('setup') ); + $balance = sprintf( '%.2f', $balance ); + $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp + $balance; +} + +sub cust_bill_pay_pkg { + my $self = shift; + qsearch( 'cust_bill_pay_pkg', { map { $_ => $self->$_ } + qw( billpkgtaxratelocationnum billpkgnum ) + } + ); +} + +sub cust_credit_bill_pkg { + my $self = shift; + qsearch( 'cust_credit_bill_pkg', { map { $_ => $self->$_ } + qw( billpkgtaxratelocationnum billpkgnum ) + } + ); +} + =back =head1 BUGS