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);
161 =item location_label [ OPTION => VALUE ... ]
163 Returns the label of the service location for this customer.
171 used to separate the address elements (defaults to ', ')
173 =item escape_function
176 a callback used for escaping the text of the address elements
182 # false laziness with FS::cust_main::location_label
188 my $separator = $opt{join_string} || ', ';
189 my $escape = $opt{escape_function} || sub{ shift };
191 my $cydefault = FS::conf->new->config('countrydefault') || 'US';
195 foreach (qw ( address1 address2 ) ) {
196 my $method = "$prefix$_";
197 $line .= ($notfirst ? $separator : ''). &$escape($self->$method)
202 foreach (qw ( city county state zip ) ) {
203 my $method = "$prefix$_";
204 if ( $self->$method ) {
205 $line .= ' (' if $method eq 'county';
206 $line .= ($notfirst ? ' ' : $separator). &$escape($self->$method);
207 $line .= ' )' if $method eq 'county';
211 $line .= $separator. &$escape(code2country($self->country))
212 if $self->country ne $cydefault;
219 Synonym for location_label
225 $self->location_label;
232 Not yet used for cust_main billing and shipping addresses.
236 L<FS::cust_main_county>, L<FS::cust_pkg>, L<FS::Record>,
237 schema.html from the base documentation.