[freeside-commits] branch master updated. 5556814b7ff65b0a4837390be9331e1841189427

Ivan ivan at 420.am
Sat Oct 25 12:08:14 PDT 2014


The branch, master has been updated
       via  5556814b7ff65b0a4837390be9331e1841189427 (commit)
      from  ff27ffb0342e4d630a9426a998ffe76de9d6ed8c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5556814b7ff65b0a4837390be9331e1841189427
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sat Oct 25 12:08:01 2014 -0700

    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 e410586..9cac9e1 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -3484,7 +3484,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 0b82f91..ae34bba 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1910,6 +1910,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 d652d53..ce7efca 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 309ab06..66fd7a0 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<FS::cust_main>)
+
+=item prospect_main
+
+Prospect object (see L<FS::prospect_main>)
+
+=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<FS::cust_main>)
+
+=item prospect_main
+
+Prospect object (see L<FS::prospect_main>)
+
+=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 84426b4..f3447cc 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2099,6 +2099,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 17a8f3d..be375dd 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 35de6cf..795242d 100644
--- a/conf/invoice_html
+++ b/conf/invoice_html
@@ -115,6 +115,8 @@
           $OUT .= '<p class="allcaps"><b>';
           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 70b36b1..6a5b53d 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 f3fde53..41dd563 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 799531e..5cdc424 100644
--- a/httemplate/elements/location.html
+++ b/httemplate/elements/location.html
@@ -41,6 +41,33 @@ Example:
 
 % } 
 
+% if ( $label_prefix eq '_location' ) {
+
+    <TR>
+      <TD ALIGN="right" ><% $opt{'locationname_label'} || emt('Location ID') %></TD>
+      <TD COLSPAN=7>
+        <INPUT TYPE     = "text"
+               NAME     = "<%$pre%>locationname"
+               ID       = "<%$pre%>locationname"
+               VALUE    = "<% $object->get('locationname') |h %>"
+               SIZE     = 24
+               onChange = "<% $onchange %>"
+               <% $disabled %>
+               <% $style %>
+        >
+      </TD>
+    </TR>
+
+% } else {
+
+    <INPUT TYPE     = "hidden"
+           NAME     = "<%$pre%>locationname"
+           ID       = "<%$pre%>locationname"
+           VALUE    = "<% $object->get('locationname') |h %>"
+    >
+
+% }
+
 <TR>
   <<%$th%> STYLE="width:16ex" ALIGN="right"><%$r%><% $opt{'address1_label'} || emt('Address') %></<%$th%>>
   <TD COLSPAN=7>
@@ -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!<font color="#ff0000">*</font> !;
 
+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 739cd58..c9f8005 100644
--- a/httemplate/view/cust_main/contacts.html
+++ b/httemplate/view/cust_main/contacts.html
@@ -62,6 +62,14 @@
 
 
 % if ( $location ) { # now the actual address
+
+%   if ( $location->locationname ) {
+      <TR>
+        <TD ALIGN="right"><% mt('Location ID') |h %></TD>
+        <TD COLSPAN=7 BGCOLOR="#ffffff"><% $location->locationname |h %></TD>
+      </TR>
+%   }
+
 <TR>
   <TD ALIGN="right"><% mt('Address') |h %></TD>
   <TD COLSPAN=7 BGCOLOR="#ffffff"><% $location->address1 |h %></TD>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm                           |    3 +-
 FS/FS/Schema.pm                         |    1 +
 FS/FS/Template_Mixin.pm                 |    3 +-
 FS/FS/cust_location.pm                  |   62 ++++++++++++++++++++++++++++---
 FS/FS/cust_main.pm                      |    1 +
 FS/FS/cust_main/Location.pm             |   10 +++--
 conf/invoice_html                       |    2 +
 conf/invoice_latex                      |    2 +
 httemplate/edit/cust_main/top_misc.html |    8 ++--
 httemplate/elements/location.html       |   36 ++++++++++++++++--
 httemplate/view/cust_main/contacts.html |    8 ++++
 11 files changed, 117 insertions(+), 19 deletions(-)




More information about the freeside-commits mailing list