1 package FS::tax_status;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
11 FS::tax_status - Object methods for tax_status records
17 $record = new FS::tax_status \%hash;
18 $record = new FS::tax_status { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::tax_status object represents a customer tax status for use with
31 an external tax table. FS::tax_status inherits from FS::Record. The
32 following fields are currently supported:
42 Data vendor name (corresponds to the value of the C<taxproduct> config
47 The data vendor's name or code for the tax status.
51 Description for use in the Freeside UI.
61 Creates a new tax status. To add the record to the database, see L<"insert">.
65 sub table { 'tax_status'; }
69 Adds this record to the database. If there is an error, returns the error,
70 otherwise returns false.
74 Delete this record from the database.
76 =item replace OLD_RECORD
78 Replaces the OLD_RECORD with this one in the database. If there is an error,
79 returns the error, otherwise returns false.
83 Checks all fields to make sure this is a valid example. If there is
84 an error, returns the error, otherwise returns false. Called by the insert
93 $self->ut_numbern('taxstatusnum')
94 || $self->ut_textn('data_vendor')
95 || $self->ut_text('taxstatus')
96 || $self->ut_text('description')
98 return $error if $error;
106 foreach my $data_vendor ( keys %initial_data ) {
107 my $status_hash = $initial_data{$data_vendor};
108 foreach my $taxstatus (sort keys %$status_hash) {
109 my $description = $status_hash->{$taxstatus};
111 if ($tax_status = qsearchs('tax_status', {
112 data_vendor => $data_vendor,
113 taxstatus => $taxstatus
116 if ($tax_status->description ne $description) {
117 $tax_status->set(description => $description);
118 $error = $tax_status->replace;
120 # else it's already correct
122 $tax_status = FS::tax_status->new({
123 data_vendor => $data_vendor,
124 taxstatus => $taxstatus,
125 description => $description
127 $error = $tax_status->insert;
129 die $error if $error;
136 'A' => 'Federal Government',
137 'B' => 'State/Local Government',
138 'C' => 'Tribal Government',
139 'D' => 'Foreign Diplomat',
140 'E' => 'Charitable Organization',
141 'F' => 'Religious/Education',
143 'H' => 'Agricultural Production',
144 'I' => 'Industrial Production',
145 'J' => 'Direct Pay Permit',
146 'K' => 'Direct Mail',
148 'M' => 'Local Government',
149 # P, Q, R: Canada, not yet supported
150 # MED1/MED2: totally irrelevant to our users
153 'R' => 'Residential',
164 L<FS::Record>, schema.html from the base documentation.