X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=88aceb935e23acf099c6acd2d523977de6f09156;hb=dd2249efe0daa3fc3257029de84d212aa89a4ee9;hp=250c40f699739294c813fdacdcbcaaea741a94f1;hpb=dfaf4546c93da08221e275e5a7ae03f78ef54a43;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 250c40f69..88aceb935 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1910,6 +1910,25 @@ sub has_ship_address { scalar( grep { $self->getfield("ship_$_") ne '' } $self->addr_fields ); } +=item location_hash + +Returns a list of key/value pairs, with the following keys: address1, adddress2, +city, county, state, zip, country. The shipping address is used if present. + +=cut + +#geocode? dependent on tax-ship_address config, not available in cust_location +#mostly. not yet then. + +sub location_hash { + my $self = shift; + my $prefix = $self->has_ship_address ? 'ship_' : ''; + + map { $_ => $self->get($prefix.$_) } + qw( address1 address2 city county state zip country geocode ); + #fields that cust_location has +} + =item all_pkgs [ EXTRA_QSEARCH_PARAMS_HASHREF ] Returns all packages (see L) for this customer. @@ -1953,24 +1972,57 @@ sub cust_location { qsearch('cust_location', { 'custnum' => $self->custnum } ); } -=item location_label_short +=item location_label [ OPTION => VALUE ... ] + +Returns the label of the service location (see analog in L) for this customer. + +Options are + +=over 4 + +=item join_string + +used to separate the address elements (defaults to ', ') -Returns the short label of the service location (see analog in L) for this customer. +=item escape_function + +a callback used for escaping the text of the address elements + +=back =cut -# false laziness with FS::cust_location::line_short +# false laziness with FS::cust_location::line -sub location_label_short { +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 = length($self->ship_last) ? 'ship_' : ''; - 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 $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; } @@ -2036,7 +2088,7 @@ sub _cust_pkg { # This should be generalized to use config options to determine order. sub sort_packages { - my $locationsort = $a->locationnum <=> $b->locationnum; + my $locationsort = ( $a->locationnum || 0 ) <=> ( $b->locationnum || 0 ); return $locationsort if $locationsort; if ( $a->get('cancel') xor $b->get('cancel') ) { @@ -2333,9 +2385,11 @@ sub agent { =item bill_and_collect Cancels and suspends any packages due, generates bills, applies payments and -cred +credits, and applies collection events to run cards, send bills and notices, +etc. -Warns on errors (Does not currently: If there is an error, returns the error, otherwise returns false.) +By default, warns on errors and continues with the next operation (but see the +"fatal" flag below). Options are passed as name-value pairs. Currently available options are: @@ -2361,6 +2415,12 @@ Used in conjunction with the I