From: Ivan Kohler Date: Sat, 25 Oct 2014 19:08:06 +0000 (-0700) Subject: user-defined site ID / location codes per location, RT#30856, RT#27545 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=f1e9e0cd3fb22e3e615142889f5f3df799841cc2 user-defined site ID / location codes per location, RT#30856, RT#27545 --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index b4cd7d84d..6b59574a5 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -3477,7 +3477,8 @@ and customer address. Include units.', 'description' => 'Optional "site ID" to show in the location label', 'type' => 'select', 'select_hash' => [ '' => '', - 'CoStAg' => 'CoStAgXXXXX (country, state, agent name, locationnum)', + 'CoStAg' => 'CoStAgXXXXX (country, state, agent name, locationnum)', + '_location' => 'Manually defined per location', ], }, diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 9b1fa9456..cb5fb85b7 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1358,6 +1358,7 @@ sub tables_hashref { 'locationnum', 'serial', '', '', '', '', 'prospectnum', 'int', 'NULL', '', '', '', 'custnum', 'int', 'NULL', '', '', '', + 'locationname', 'varchar', 'NULL', $char_d, '', '', 'address1', 'varchar', '', $char_d, '', '', 'address2', 'varchar', 'NULL', $char_d, '', '', 'city', 'varchar', '', $char_d, '', '', diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm index d652d5349..ce7efcab1 100644 --- a/FS/FS/Template_Mixin.pm +++ b/FS/FS/Template_Mixin.pm @@ -2090,8 +2090,9 @@ sub _items_sections { $section->{'sort_weight'} = sprintf('%012s',$location->zip) . $locationnum; $section->{'location'} = { + label_prefix => &{ $escape }($location->label_prefix), map { $_ => &{ $escape }($location->get($_)) } - $location->fields + $location->fields }; } else { $section->{'category'} = $sectionname; diff --git a/FS/FS/cust_location.pm b/FS/FS/cust_location.pm index 2e0871ddb..23dbce909 100644 --- a/FS/FS/cust_location.pm +++ b/FS/FS/cust_location.pm @@ -322,6 +322,7 @@ sub check { $self->ut_numbern('locationnum') || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum') || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum') + || $self->ut_alphan('locationname') || $self->ut_text('address1') || $self->ut_textn('address2') || $self->ut_text('city') @@ -604,14 +605,61 @@ sub dealternize { =item location_label -Returns the label of the location object, with an optional site ID -string (based on the cust_location-label_prefix config option). +Returns the label of the location object. + +Options: + +=over 4 + +=item cust_main + +Customer object (see L) + +=item prospect_main + +Prospect object (see L) + +=item join_string + +String used to join location elements + +=back =cut sub location_label { my( $self, %opt ) = @_; + my $prefix = $self->label_prefix; + $prefix .= ($opt{join_string} || ': ') if $prefix; + + $prefix . $self->SUPER::location_label(%opt); +} + +=item label_prefix + +Returns the optional site ID string (based on the cust_location-label_prefix +config option), "Default service location", or the empty string. + +Options: + +=over 4 + +=item cust_main + +Customer object (see L) + +=item prospect_main + +Prospect object (see L) + +=back + +=cut + +sub label_prefix { + my( $self, %opt ) = @_; + my $cust_or_prospect = $opt{cust_main} || $opt{prospect_main}; unless ( $cust_or_prospect ) { if ( $self->custnum ) { @@ -633,14 +681,16 @@ sub location_label { ($agent =~ /^(..)/), sprintf('%05d', $self->locationnum) ) ); - } - elsif ( ( $opt{'cust_main'} || $self->custnum ) + + } elsif ( $label_prefix eq '_location' && $self->locationname ) { + $prefix = $self->locationname; + + } elsif ( ( $opt{'cust_main'} || $self->custnum ) && $self->locationnum == $cust_or_prospect->ship_locationnum ) { $prefix = 'Default service location'; } - $prefix .= ($opt{join_string} || ': ') if $prefix; - $prefix . $self->SUPER::location_label(%opt); + $prefix; } =item county_state_county diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index c0d8dbe20..57abc18ab 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2092,6 +2092,7 @@ Returns a list of fields which have ship_ duplicates. sub addr_fields { qw( last first company + locationname address1 address2 city county state zip country latitude longitude daytime night fax mobile diff --git a/FS/FS/cust_main/Location.pm b/FS/FS/cust_main/Location.pm index 095bbe7b8..9f3829700 100644 --- a/FS/FS/cust_main/Location.pm +++ b/FS/FS/cust_main/Location.pm @@ -17,10 +17,12 @@ BEGIN { # set up accessors for location fields if (!$init) { no strict 'refs'; - @location_fields = - qw( address1 address2 city county state zip country district - latitude longitude coord_auto censustract censusyear geocode - addr_clean ); + @location_fields = qw( + locationname + address1 address2 city county state zip country + district latitude longitude coord_auto censustract censusyear geocode + addr_clean + ); foreach my $f (@location_fields) { *{"FS::cust_main::Location::$f"} = sub { diff --git a/conf/invoice_html b/conf/invoice_html index 35de6cf09..795242d5d 100644 --- a/conf/invoice_html +++ b/conf/invoice_html @@ -115,6 +115,8 @@ $OUT .= '

'; my $sectionhead; if ( $section->{'location'} ) { + $sectionhead .= $section->{'location'}{'label_prefix'}. ': '. + if length($section->{'location'}{'label_prefix'}); $sectionhead = $section->{'location'}{'address1'}; $sectionhead .= ', '.$section->{'location'}{'address2'} if length($section->{'location'}{'address2'}); diff --git a/conf/invoice_latex b/conf/invoice_latex index 70b36b13d..6a5b53dd5 100644 --- a/conf/invoice_latex +++ b/conf/invoice_latex @@ -259,6 +259,8 @@ $OUT .= '\begin{longtable}{cllllllr}'; $OUT .= '\caption*{ '; if ($section->{'location'}) { + $OUT .= $section->{'location'}{'label_prefix'}. ': ' + if length($section->{'location'}{'label_prefix'}); $OUT .= $section->{'location'}{'address1'}; $OUT .= ', ' . $section->{'location'}{'address2'} if length($section->{'location'}{'address2'}); diff --git a/httemplate/edit/cust_main/top_misc.html b/httemplate/edit/cust_main/top_misc.html index f3fde53fa..41dd5636b 100644 --- a/httemplate/edit/cust_main/top_misc.html +++ b/httemplate/edit/cust_main/top_misc.html @@ -39,8 +39,10 @@ var ship_locked_agents = <% encode_json(\%ship_locked_agents) %>; - var ship_fields = ['address1', 'city', 'state', 'zip', 'country', - 'latitude', 'longitude', 'district']; + var ship_fields = [ + 'locationname', 'address1', 'city', 'state', 'zip', 'country', + 'latitude', 'longitude', 'district' + ]; function agent_changed(what) { var agentnum = what.value; @@ -270,7 +272,7 @@ foreach (qsearch('agent',{})) { my $agent_ship_location = $cust_main->ship_location; $ship_locked_agents{$agentnum} = +{ map { $_ => $agent_ship_location->$_ } - qw(address1 city state zip country latitude longitude district) + qw(locationname address1 city state zip country latitude longitude district) }; } diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html index 799531e01..5cdc424a7 100644 --- a/httemplate/elements/location.html +++ b/httemplate/elements/location.html @@ -41,6 +41,33 @@ Example: % } +% if ( $label_prefix eq '_location' ) { + + + <% $opt{'locationname_label'} || emt('Location ID') %> + + + <% $style %> + > + + + +% } else { + + + +% } + <<%$th%> STYLE="width:16ex" ALIGN="right"><%$r%><% $opt{'address1_label'} || emt('Address') %>> @@ -291,13 +318,14 @@ my $object = $opt{'object'}; my $onchange = $opt{'onchange'}; my $disabled = $opt{'disabled'}; -my $conf = new FS::Conf; - my $r = $opt{'no_asterisks'} ? '' : qq!* !; +my $conf = new FS::Conf; my $countrydefault = $conf->config('countrydefault') || 'US'; -my $statedefault = $conf->config('statedefault') - || ($countrydefault eq 'US' ? 'CA' : ''); +my $statedefault = $conf->config('statedefault') + || ($countrydefault eq 'US' ? 'CA' : ''); +my $label_prefix = $conf->config('cust_location-label_prefix'); + $object ||= FS::cust_location->new({ 'country' => $countrydefault, 'state' => $statedefault, diff --git a/httemplate/view/cust_main/contacts.html b/httemplate/view/cust_main/contacts.html index dbc491af0..5b61e7400 100644 --- a/httemplate/view/cust_main/contacts.html +++ b/httemplate/view/cust_main/contacts.html @@ -60,6 +60,14 @@ % } % } % # now the actual address + +% if ( $location->locationname ) { + + <% mt('Location ID') |h %> + <% $location->locationname |h %> + +% } + <% mt('Address') |h %> <% $location->address1 |h %>