1 package FS::cust_bill_pkg_tax_location;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
9 use FS::cust_bill_pay_pkg;
10 use FS::cust_credit_bill_pkg;
14 FS::cust_bill_pkg_tax_location - Object methods for cust_bill_pkg_tax_location records
18 use FS::cust_bill_pkg_tax_location;
20 $record = new FS::cust_bill_pkg_tax_location \%hash;
21 $record = new FS::cust_bill_pkg_tax_location { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::cust_bill_pkg_tax_location object represents an record of taxation
34 based on package location. FS::cust_bill_pkg_tax_location inherits from
35 FS::Record. The following fields are currently supported:
39 =item billpkgtaxlocationnum
76 Creates a new record. To add the record to the database, see L<"insert">.
78 Note that this stores the hash reference, not a distinct copy of the hash it
79 points to. You can ask the object for a copy with the I<hash> method.
83 sub table { 'cust_bill_pkg_tax_location'; }
87 Adds this record to the database. If there is an error, returns the error,
88 otherwise returns false.
92 Delete this record from the database.
94 =item replace OLD_RECORD
96 Replaces the OLD_RECORD with this one in the database. If there is an error,
97 returns the error, otherwise returns false.
101 Checks all fields to make sure this is a valid record. If there is
102 an error, returns the error, otherwise returns false. Called by the insert
107 # the check method should currently be supplied - FS::Record contains some
108 # data checking routines
114 $self->ut_numbern('billpkgtaxlocationnum')
115 || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum' )
116 || $self->ut_number('taxnum') #cust_bill_pkg/tax_rate key, based on taxtype
117 || $self->ut_enum('taxtype', [ qw( FS::cust_main_county FS::tax_rate ) ] )
118 || $self->ut_foreign_key('pkgnum', 'cust_pkg', 'pkgnum' )
119 || $self->ut_foreign_key('locationnum', 'cust_location', 'locationnum' )
120 || $self->ut_money('amount')
122 return $error if $error;
129 Returns the associated cust_bill_pkg object
135 qsearchs( 'cust_bill_pkg', { 'billpkgnum' => $self->billpkgnum } );
140 Returns the associated cust_location object
146 qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );
151 Returns a description for this tax line item constituent. Currently this
152 is the desc of the associated line item followed by the state/county/city
153 for the location in parentheses.
159 my $cust_location = $self->cust_location;
160 my $location = join('/', grep { $_ } # leave in?
161 map { $cust_location->$_ }
162 qw( state county city ) # country?
164 $self->cust_bill_pkg->desc. " ($location)";
169 Returns the amount owed (still outstanding) on this tax line item which is
170 the amount of this record minus all payment applications and credit
177 my $balance = $self->amount;
178 $balance -= $_->amount foreach ( $self->cust_bill_pay_pkg('setup') );
179 $balance -= $_->amount foreach ( $self->cust_credit_bill_pkg('setup') );
180 $balance = sprintf( '%.2f', $balance );
181 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
185 sub cust_bill_pay_pkg {
187 qsearch( 'cust_bill_pay_pkg',
188 { map { $_ => $self->$_ } qw( billpkgtaxlocationnum billpkgnum ) }
192 sub cust_credit_bill_pkg {
194 qsearch( 'cust_credit_bill_pkg',
195 { map { $_ => $self->$_ } qw( billpkgtaxlocationnum billpkgnum ) }
205 L<FS::Record>, schema.html from the base documentation.