1 package FS::cust_location;
4 use base qw( FS::Record );
6 use FS::Record qw( qsearch ); #qsearchs );
8 use FS::cust_main_county;
12 FS::cust_location - Object methods for cust_location records
16 use FS::cust_location;
18 $record = new FS::cust_location \%hash;
19 $record = new FS::cust_location { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::cust_location object represents a customer location. FS::cust_location
32 inherits from FS::Record. The following fields are currently supported:
46 Address line one (required)
50 Address line two (optional)
58 County (optional, see L<FS::cust_main_county>)
62 State (see L<FS::cust_main_county>)
70 Country (see L<FS::cust_main_county>)
84 Creates a new location. To add the location to the database, see L<"insert">.
86 Note that this stores the hash reference, not a distinct copy of the hash it
87 points to. You can ask the object for a copy with the I<hash> method.
91 sub table { 'cust_location'; }
95 Adds this record to the database. If there is an error, returns the error,
96 otherwise returns false.
100 Delete this record from the database.
102 =item replace OLD_RECORD
104 Replaces the OLD_RECORD with this one in the database. If there is an error,
105 returns the error, otherwise returns false.
109 Checks all fields to make sure this is a valid location. If there is
110 an error, returns the error, otherwise returns false. Called by the insert
115 #some false laziness w/cust_main, but since it should eventually lose these
121 $self->ut_numbern('locationnum')
122 || $self->ut_foreign_key('custnum', 'cust_main', 'custnum')
123 || $self->ut_text('address1')
124 || $self->ut_textn('address2')
125 || $self->ut_text('city')
126 || $self->ut_textn('county')
127 || $self->ut_textn('state')
128 || $self->ut_country('country')
129 || $self->ut_zip('zip', $self->country)
130 || $self->ut_alphan('geocode')
132 return $error if $error;
134 unless ( qsearch('cust_main_county', {
135 'country' => $self->country,
138 return "Unknown state/county/country: ".
139 $self->state. "/". $self->county. "/". $self->country
140 unless qsearch('cust_main_county',{
141 'state' => $self->state,
142 'county' => $self->county,
143 'country' => $self->country,
152 Returns this locations's full country name
158 code2country($self->country);
163 Returns this location on one line
169 my $cydefault = FS::conf->new->config('countrydefault') || 'US';
171 my $line = $self->address1;
172 $line .= ', '. $self->address2 if $self->address2;
173 $line .= ', '. $self->city;
174 $line .= ' ('. $self->county. ' county)' if $self->county;
175 $line .= ', '. $self->state if $self->state;
176 $line .= ' '. $self->zip if $self->zip;
177 $line .= ' '. code2country($self->country) if $self->country ne $cydefault;
186 Not yet used for cust_main billing and shipping addresses.
190 L<FS::cust_main_county>, L<FS::cust_pkg>, L<FS::Record>,
191 schema.html from the base documentation.