1 package FS::cust_location;
4 use base qw( FS::geocode_Mixin 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);
168 Synonym for location_label
174 $self->location_label;
177 =item has_ship_address
179 Returns false since cust_location objects do not have a separate shipping
184 sub has_ship_address {
190 Returns a list of key/value pairs, with the following keys: address1, address2,
191 city, county, state, zip, country, geocode.
199 Not yet used for cust_main billing and shipping addresses.
203 L<FS::cust_main_county>, L<FS::cust_pkg>, L<FS::Record>,
204 schema.html from the base documentation.