1 package FS::cust_tax_location;
5 use FS::Record qw( qsearch qsearchs dbh );
11 FS::cust_tax_location - Object methods for cust_tax_location records
15 use FS::cust_tax_location;
17 $record = new FS::cust_tax_location \%hash;
18 $record = new FS::cust_tax_location { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::cust_tax_location object represents a mapping between a customer and
31 a tax location. FS::cust_tax_location inherits from FS::Record. The
32 following fields are currently supported:
50 the upper bound of the last 4 zip code digits
54 the lower bound of the last 4 zip code digits
56 =item default_location
58 'Y' when this record represents the default for zip
60 =item geocode - the foreign key into FS::part_pkg_tax_rate and FS::tax_rate
71 Creates a new cust_tax_location. To add the cust_tax_location to the database,
74 Note that this stores the hash reference, not a distinct copy of the hash it
75 points to. You can ask the object for a copy with the I<hash> method.
79 sub table { 'cust_tax_location'; }
83 Adds this record to the database. If there is an error, returns the error,
84 otherwise returns false.
90 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.
103 Checks all fields to make sure this is a valid cust_tax_location. If there is
104 an error, returns the error, otherwise returns false. Called by the insert
113 $self->ut_numbern('custlocationnum')
114 || $self->ut_text('data_vendor')
115 || $self->ut_number('zip')
116 || $self->ut_text('state')
117 || $self->ut_number('plus4hi')
118 || $self->ut_number('plus4lo')
119 || $self->ut_enum('default', [ '', ' ', 'Y' ] )
120 || $self->ut_number('geocode')
122 return $error if $error;
131 my $fh = $param->{filehandle};
132 my $format = $param->{'format'};
135 if ( $format eq 'cch' ) {
136 @fields = qw( zip state plus4lo plus4hi geocode default );
137 } elsif ( $format eq 'extended' ) {
138 die "unimplemented\n";
141 die "unknown format $format";
144 eval "use Text::CSV_XS;";
147 my $csv = new Text::CSV_XS;
151 local $SIG{HUP} = 'IGNORE';
152 local $SIG{INT} = 'IGNORE';
153 local $SIG{QUIT} = 'IGNORE';
154 local $SIG{TERM} = 'IGNORE';
155 local $SIG{TSTP} = 'IGNORE';
156 local $SIG{PIPE} = 'IGNORE';
158 my $oldAutoCommit = $FS::UID::AutoCommit;
159 local $FS::UID::AutoCommit = 0;
163 while ( defined($line=<$fh>) ) {
164 $csv->parse($line) or do {
165 $dbh->rollback if $oldAutoCommit;
166 return "can't parse: ". $csv->error_input();
169 my @columns = $csv->fields();
171 my %cust_tax_location = ( 'data_vendor' => $format );;
172 foreach my $field ( @fields ) {
173 $cust_tax_location{$field} = shift @columns;
176 my $cust_tax_location = new FS::cust_tax_location( \%cust_tax_location );
177 my $error = $cust_tax_location->insert;
180 $dbh->rollback if $oldAutoCommit;
181 return "can't insert cust_tax_location for $line: $error";
187 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
189 return "Empty file!" unless $imported;
199 The author should be informed of any you find.
203 L<FS::Record>, schema.html from the base documentation.