X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_location.pm;h=ab80941f9b6a1184c184429394787202e8ac17ea;hb=eec4949e2c8f09a0b89331437186b77c4db6ff38;hp=87c6c3eb6a78a722ef86c71644b79f49e83ee378;hpb=085a29e3efffe7db3277a2f7f13ff6bd364835fb;p=freeside.git diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 87c6c3eb6..ab80941f9 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -1,9 +1,10 @@ package FS::cust_location; use strict; -use base qw( FS::Record ); +use base qw( FS::geocode_Mixin FS::Record ); use Locale::Country; use FS::Record qw( qsearch ); #qsearchs ); +use FS::prospect_main; use FS::cust_main; use FS::cust_main_county; @@ -119,7 +120,8 @@ sub check { my $error = $self->ut_numbern('locationnum') - || $self->ut_foreign_key('custnum', 'cust_main', 'custnum') + || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum') + || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum') || $self->ut_text('address1') || $self->ut_textn('address2') || $self->ut_text('city') @@ -131,6 +133,9 @@ sub check { ; return $error if $error; + return "No prospect or customer!" unless $self->prospectnum || $self->custnum; + return "Prospect and customer!" if $self->prospectnum && $self->custnum; + unless ( qsearch('cust_main_county', { 'country' => $self->country, 'state' => '', @@ -158,73 +163,35 @@ sub country_full { code2country($self->country); } -=item location_label [ OPTION => VALUE ... ] - -Returns the label of the service location for this customer. - -Options are - -=over 4 - -=item join_string +=item line -used to separate the address elements (defaults to ', ') +Synonym for location_label -=item escape_function +=cut +sub line { + my $self = shift; + $self->location_label; +} -a callback used for escaping the text of the address elements +=item has_ship_address -=back +Returns false since cust_location objects do not have a separate shipping +address. =cut -# false laziness with FS::cust_main::location_label - -sub location_label { - my $self = shift; - my %opt = @_; - - my $separator = $opt{join_string} || ', '; - my $escape = $opt{escape_function} || sub{ shift }; - my $line = ''; - my $cydefault = FS::conf->new->config('countrydefault') || 'US'; - my $prefix = ''; - - my $notfirst = 0; - foreach (qw ( address1 address2 ) ) { - my $method = "$prefix$_"; - $line .= ($notfirst ? $separator : ''). &$escape($self->$method) - if $self->$method; - $notfirst++; - } - $notfirst = 0; - foreach (qw ( city county state zip ) ) { - my $method = "$prefix$_"; - if ( $self->$method ) { - $line .= ' (' if $method eq 'county'; - $line .= ($notfirst ? ' ' : $separator). &$escape($self->$method); - $line .= ' )' if $method eq 'county'; - $notfirst++; - } - } - $line .= $separator. &$escape(code2country($self->country)) - if $self->country ne $cydefault; - - $line; +sub has_ship_address { + ''; } -=item line +=item location_hash -Synonym for location_label +Returns a list of key/value pairs, with the following keys: address1, address2, +city, county, state, zip, country, geocode. =cut -sub line { - my $self = shift; - $self->location_label; -} - =back =head1 BUGS