1 package FS::cust_bill_pkg_tax_rate_location;
2 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
7 use FS::cust_bill_pay_pkg;
8 use FS::cust_credit_bill_pkg;
13 FS::cust_bill_pkg_tax_rate_location - Object methods for cust_bill_pkg_tax_rate_location records
17 use FS::cust_bill_pkg_tax_rate_location;
19 $record = new FS::cust_bill_pkg_tax_rate_location \%hash;
20 $record = new FS::cust_bill_pkg_tax_rate_location { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::cust_bill_pkg_tax_rate_location object represents an record of taxation
33 based on package location. FS::cust_bill_pkg_tax_rate_location inherits from
34 FS::Record. The following fields are currently supported:
38 =item billpkgtaxratelocationnum
40 billpkgtaxratelocationnum
58 =item taxratelocationnum
75 Creates a new record. To add the record to the database, see L<"insert">.
77 Note that this stores the hash reference, not a distinct copy of the hash it
78 points to. You can ask the object for a copy with the I<hash> method.
82 sub table { 'cust_bill_pkg_tax_rate_location'; }
86 Adds this record to the database. If there is an error, returns the error,
87 otherwise returns false.
91 Delete this record from the database.
93 =item replace OLD_RECORD
95 Replaces the OLD_RECORD with this one in the database. If there is an error,
96 returns the error, otherwise returns false.
100 Checks all fields to make sure this is a valid record. If there is
101 an error, returns the error, otherwise returns false. Called by the insert
106 # the check method should currently be supplied - FS::Record contains some
107 # data checking routines
113 $self->ut_numbern('billpkgtaxratelocationnum')
114 || $self->ut_foreign_key('billpkgnum', 'cust_bill_pkg', 'billpkgnum' )
115 || $self->ut_number('taxnum') #cust_bill_pkg/tax_rate key, based on taxtype
116 || $self->ut_enum('taxtype', [ qw( FS::cust_main_county FS::tax_rate ) ] )
117 || $self->ut_textn('locationtaxid')
118 || $self->ut_foreign_key('taxratelocationnum', 'tax_rate_location', 'taxratelocationnum' )
119 || $self->ut_money('amount')
121 return $error if $error;
128 Returns the associated cust_bill_pkg object
130 =item tax_rate_location
132 Returns the associated tax_rate_location object
136 Returns the tax name (the itemdesc).
142 my $tax_rate = FS::tax_rate->by_key($self->taxnum)
149 Returns a description for this tax line item constituent. Currently this
150 is the desc of the associated line item followed by the
151 state,county,city,locationtaxid for the location in parentheses.
157 my $tax_rate_location = $self->tax_rate_location;
158 my $location = join(', ', grep { $_ }
159 map { $tax_rate_location->$_ }
160 qw( state county city )
162 $location .= ( $location && $self->locationtaxid ) ? ', ' : '';
163 $location .= $self->locationtaxid;
164 my $cust_bill_pkg_desc = $self->billpkgnum
165 ? $self->cust_bill_pkg->desc
166 : $self->cust_bill_pkg_desc;
167 "$cust_bill_pkg_desc ($location)";
174 Returns the amount owed (still outstanding) on this tax line item which is
175 the amount of this record minus all payment applications and credit
182 my $balance = $self->amount;
183 $balance -= $_->amount foreach ( $self->cust_bill_pay_pkg('setup') );
184 $balance -= $_->amount foreach ( $self->cust_credit_bill_pkg('setup') );
185 $balance = sprintf( '%.2f', $balance );
186 $balance =~ s/^\-0\.00$/0.00/; #yay ieee fp
190 sub cust_bill_pay_pkg {
192 qsearch( 'cust_bill_pay_pkg', { map { $_ => $self->$_ }
193 qw( billpkgtaxratelocationnum billpkgnum )
198 sub cust_credit_bill_pkg {
200 qsearch( 'cust_credit_bill_pkg', { map { $_ => $self->$_ }
201 qw( billpkgtaxratelocationnum billpkgnum )
212 L<FS::Record>, schema.html from the base documentation.