1 package FS::cust_location;
4 use base qw( FS::Record );
6 use FS::Record qw( qsearch ); #qsearchs );
9 use FS::cust_main_county;
13 FS::cust_location - Object methods for cust_location records
17 use FS::cust_location;
19 $record = new FS::cust_location \%hash;
20 $record = new FS::cust_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_location object represents a customer location. FS::cust_location
33 inherits from FS::Record. The following fields are currently supported:
47 Address line one (required)
51 Address line two (optional)
59 County (optional, see L<FS::cust_main_county>)
63 State (see L<FS::cust_main_county>)
71 Country (see L<FS::cust_main_county>)
85 Creates a new location. To add the location to the database, see L<"insert">.
87 Note that this stores the hash reference, not a distinct copy of the hash it
88 points to. You can ask the object for a copy with the I<hash> method.
92 sub table { 'cust_location'; }
96 Adds this record to the database. If there is an error, returns the error,
97 otherwise returns false.
101 Delete this record from the database.
103 =item replace OLD_RECORD
105 Replaces the OLD_RECORD with this one in the database. If there is an error,
106 returns the error, otherwise returns false.
110 Checks all fields to make sure this is a valid location. If there is
111 an error, returns the error, otherwise returns false. Called by the insert
116 #some false laziness w/cust_main, but since it should eventually lose these
122 $self->ut_numbern('locationnum')
123 || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
124 || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
125 || $self->ut_text('address1')
126 || $self->ut_textn('address2')
127 || $self->ut_text('city')
128 || $self->ut_textn('county')
129 || $self->ut_textn('state')
130 || $self->ut_country('country')
131 || $self->ut_zip('zip', $self->country)
132 || $self->ut_alphan('geocode')
134 return $error if $error;
136 return "No prospect or customer!" unless $self->prospectnum || $self->custnum;
137 return "Prospect and customer!" if $self->prospectnum && $self->custnum;
139 unless ( qsearch('cust_main_county', {
140 'country' => $self->country,
143 return "Unknown state/county/country: ".
144 $self->state. "/". $self->county. "/". $self->country
145 unless qsearch('cust_main_county',{
146 'state' => $self->state,
147 'county' => $self->county,
148 'country' => $self->country,
157 Returns this locations's full country name
163 code2country($self->country);
166 =item location_label [ OPTION => VALUE ... ]
168 Returns the label of the service location for this customer.
176 used to separate the address elements (defaults to ', ')
178 =item escape_function
181 a callback used for escaping the text of the address elements
187 # false laziness with FS::cust_main::location_label
193 my $separator = $opt{join_string} || ', ';
194 my $escape = $opt{escape_function} || sub{ shift };
195 my $ds = $opt{double_space} || ' ';
198 $opt{'countrydefault'} || FS::Conf->new->config('countrydefault') || 'US';
202 foreach (qw ( address1 address2 ) ) {
203 my $method = "$prefix$_";
204 $line .= ($notfirst ? $separator : ''). &$escape($self->$method)
209 foreach (qw ( city county state zip ) ) {
210 my $method = "$prefix$_";
211 if ( $self->$method ) {
212 $line .= ($notfirst ? ($method eq 'zip' ? $ds : ' ') : $separator);
213 $line .= '(' if $method eq 'county';
214 $line .= &$escape($self->$method);
215 $line .= ')' if $method eq 'county';
218 $line .= ',' if $method eq 'county';
220 $line .= $separator. &$escape(code2country($self->country))
221 if $self->country ne $cydefault;
228 Synonym for location_label
234 $self->location_label;
241 Not yet used for cust_main billing and shipping addresses.
245 L<FS::cust_main_county>, L<FS::cust_pkg>, L<FS::Record>,
246 schema.html from the base documentation.