X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_location.pm;h=87c6c3eb6a78a722ef86c71644b79f49e83ee378;hb=085a29e3efffe7db3277a2f7f13ff6bd364835fb;hp=0544dcfba1ed41325fefdab8a5c28b1a840b0835;hpb=2b8ffc98529637ffddfe7cbf6b4f9b8deb90f0fa;p=freeside.git diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 0544dcfba..87c6c3eb6 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -158,6 +158,73 @@ 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 + +used to separate the address elements (defaults to ', ') + +=item escape_function + + +a callback used for escaping the text of the address elements + +=back + +=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; +} + +=item line + +Synonym for location_label + +=cut + +sub line { + my $self = shift; + $self->location_label; +} + =back =head1 BUGS