diff options
author | jeff <jeff> | 2009-12-23 21:21:15 +0000 |
---|---|---|
committer | jeff <jeff> | 2009-12-23 21:21:15 +0000 |
commit | b50700f72235bcbc23df43f4cf550b5676d70ed7 (patch) | |
tree | 5cc845c4bb1f1f19aa5f305d50d36203e1164a9a /FS/FS/cust_location.pm | |
parent | ef2b25a7063f9e5f644cca7014c59890f5a1e918 (diff) |
correct invoice package address display and reduce false laziness
Diffstat (limited to 'FS/FS/cust_location.pm')
-rw-r--r-- | FS/FS/cust_location.pm | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 3a9cc7f..997532c 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -158,58 +158,71 @@ sub country_full { code2country($self->country); } -=item line +=item location_label [ OPTION => VALUE ... ] -Returns this location on one line +Returns the label of the service location for this customer. -=cut +Options are -sub line { - my $self = shift; - my $cydefault = FS::conf->new->config('countrydefault') || 'US'; +=over 4 - my $line = $self->address1; - $line .= ', '. $self->address2 if $self->address2; - $line .= ', '. $self->city; - $line .= ' ('. $self->county. ' county)' if $self->county; - $line .= ', '. $self->state if $self->state; - $line .= ' '. $self->zip if $self->zip; - $line .= ' '. code2country($self->country) if $self->country ne $cydefault; +=item join_string - $line; -} +used to separate the address elements (defaults to ', ') + +=item escape_function -=item line_short -Returns this location on one line in a shortened form +a callback used for escaping the text of the address elements + +=back =cut -# configurable? +# false laziness with FS::cust_main::location_label -sub line_short { +sub location_label { my $self = shift; - my $cydefault = FS::conf->new->config('countrydefault') || 'US'; + my %opt = @_; - my $line = $self->address1; - #$line .= ', '. $self->address2 if $self->address2; - $line .= ', '. $self->city; - $line .= ', '. $self->state if $self->state; - $line .= ' '. $self->zip if $self->zip; - $line .= ' '. code2country($self->country) if $self->country ne $cydefault; + 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 location_label_short +=item line -Synonym for line_short +Synonym for location_label =cut -sub location_label_short { +sub line { my $self = shift; - $self->line_short; + $self->location_label; } =back |