add location to svc_phone, RT#7047
authorivan <ivan>
Fri, 12 Mar 2010 03:36:47 +0000 (03:36 +0000)
committerivan <ivan>
Fri, 12 Mar 2010 03:36:47 +0000 (03:36 +0000)
FS/FS/Schema.pm
FS/FS/cust_pkg.pm
FS/FS/location_Mixin.pm [new file with mode: 0644]
FS/FS/svc_phone.pm
FS/t/location_Mixin.t [new file with mode: 0644]
httemplate/edit/elements/edit.html
httemplate/edit/elements/svc_Common.html
httemplate/edit/svc_phone.cgi
httemplate/elements/location.html
httemplate/elements/tr-select-cust_location.html
httemplate/view/svc_phone.cgi

index 9016676..46ad18a 100644 (file)
@@ -2439,10 +2439,13 @@ sub tables_hashref {
         'phone_name',   'varchar', 'NULL', $char_d, '', '',
         'pbxsvc',           'int', 'NULL',      '', '', '',
         'domsvc',           'int', 'NULL',      '', '', '', 
+        'locationnum',      'int', 'NULL', '', '', '',
       ],
       'primary_key' => 'svcnum',
       'unique' => [],
-      'index'  => [ [ 'countrycode', 'phonenum' ], ['pbxsvc'], ['domsvc'] ],
+      'index'  => [ ['countrycode', 'phonenum'], ['pbxsvc'], ['domsvc'],
+                    ['locationnum'],
+                  ],
     },
 
     'phone_device' => {
index e11e82f..dbce6cb 100644 (file)
@@ -1,6 +1,9 @@
 package FS::cust_pkg;
 
 use strict;
+use base qw( FS::cust_main_Mixin FS::location_Mixin
+             FS::m2m_Common FS::option_Common FS::Record
+           );
 use vars qw(@ISA $disable_agentcheck $DEBUG $me);
 use Carp qw(cluck);
 use Scalar::Util qw( blessed );
@@ -11,8 +14,6 @@ use MIME::Entity;
 use FS::UID qw( getotaker dbh );
 use FS::Misc qw( send_email );
 use FS::Record qw( qsearch qsearchs );
-use FS::m2m_Common;
-use FS::cust_main_Mixin;
 use FS::cust_svc;
 use FS::part_pkg;
 use FS::cust_main;
@@ -39,8 +40,6 @@ use FS::svc_forward;
 # for sending cancel emails in sub cancel
 use FS::Conf;
 
-@ISA = qw( FS::m2m_Common FS::cust_main_Mixin FS::option_Common FS::Record );
-
 $DEBUG = 0;
 $me = '[FS::cust_pkg]';
 
@@ -1946,41 +1945,24 @@ sub cust_main {
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
+#these subs are in location_Mixin.pm now... unfortunately the POD doesn't mixin
+
 =item cust_location
 
 Returns the location object, if any (see L<FS::cust_location>).
 
-=cut
-
-sub cust_location {
-  my $self = shift;
-  return '' unless $self->locationnum;
-  qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );
-}
-
 =item cust_location_or_main
 
 If this package is associated with a location, returns the locaiton (see
 L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).
 
-=cut
-
-sub cust_location_or_main {
-  my $self = shift;
-  $self->cust_location || $self->cust_main;
-}
-
 =item location_label [ OPTION => VALUE ... ]
 
 Returns the label of the location object (see L<FS::cust_location>).
 
 =cut
 
-sub location_label {
-  my $self = shift;
-  my $object = $self->cust_location_or_main;
-  $object->location_label(@_);
-}
+#end of subs in location_Mixin.pm now... unfortunately the POD doesn't mixin
 
 =item seconds_since TIMESTAMP
 
diff --git a/FS/FS/location_Mixin.pm b/FS/FS/location_Mixin.pm
new file mode 100644 (file)
index 0000000..675e002
--- /dev/null
@@ -0,0 +1,43 @@
+package FS::location_Mixin;
+
+use strict;
+use FS::Record qw( qsearchs );
+use FS::cust_location;
+
+=item cust_location
+
+Returns the location object, if any (see L<FS::cust_location>).
+
+=cut
+
+sub cust_location {
+  my $self = shift;
+  return '' unless $self->locationnum;
+  qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } );
+}
+
+=item cust_location_or_main
+
+If this package is associated with a location, returns the locaiton (see
+L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>).
+
+=cut
+
+sub cust_location_or_main {
+  my $self = shift;
+  $self->cust_location || $self->cust_main;
+}
+
+=item location_label [ OPTION => VALUE ... ]
+
+Returns the label of the location object (see L<FS::cust_location>).
+
+=cut
+
+sub location_label {
+  my $self = shift;
+  my $object = $self->cust_location_or_main;
+  $object->location_label(@_);
+}
+
+1;
index 0ed01ad..7405a71 100644 (file)
@@ -1,7 +1,7 @@
 package FS::svc_phone;
 
 use strict;
-use base qw( FS::svc_Domain_Mixin FS::svc_Common );
+use base qw( FS::svc_Domain_Mixin FS::location_Mixin FS::svc_Common );
 use vars qw( @pw_set $conf );
 use FS::Conf;
 use FS::Record qw( qsearch qsearchs dbh );
@@ -10,6 +10,7 @@ use FS::part_svc;
 use FS::phone_device;
 use FS::svc_pbx;
 use FS::svc_domain;
+use FS::cust_location;
 
 #avoid l 1 and o O 0
 @pw_set = ( 'a'..'k', 'm','n', 'p-z', 'A'..'N', 'P'..'Z' , '2'..'9' );
@@ -121,6 +122,11 @@ sub table_info {
                          select_label => 'domain',
                          disable_inventory => 1,
                        },
+        'locationnum' => {
+                           label => 'E911 location',
+                           disable_inventory => 1,
+                           disable_select    => 1,
+                         },
     },
   };
 }
@@ -278,6 +284,7 @@ sub check {
     || $self->ut_textn('phone_name')
     || $self->ut_foreign_keyn('pbxsvc', 'svc_pbx',    'svcnum' )
     || $self->ut_foreign_keyn('domsvc', 'svc_domain', 'svcnum' )
+    || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
   ;
   return $error if $error;
 
diff --git a/FS/t/location_Mixin.t b/FS/t/location_Mixin.t
new file mode 100644 (file)
index 0000000..b6a9bf2
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::location_Mixin;
+$loaded=1;
+print "ok 1\n";
index 8c88852..1a1023c 100644 (file)
@@ -40,7 +40,7 @@ Example:
                     'disabled' => 0,
                     'onchange' => 'javascript_function',
 
-                    'include_opt_callback' => sub { #my $ = @_;
+                    'include_opt_callback' => sub { my $object = @_;
                                                     ( 'option' => 'value', );
                                                   },
 
@@ -296,11 +296,15 @@ Example:
 %
 %   if ( $type eq 'tablebreak-tr-title' ) {
 %     $include_common{'table_id'} = 'TableNumber'. $tablenum++;
+%   }
+%   if ( $type eq 'tablebreak-tr-title' || $type eq 'title' ) {
 %     $include_common{'colspan'} = $f->{colspan} if $f->{colspan};
 %   }
 %
 %   if ( $f->{include_opt_callback} ) {
-%     %include_common = ( %include_common, &{ $f->{include_opt_callback} } );
+%     %include_common = ( %include_common,
+%                         &{ $f->{include_opt_callback} }( $object )
+%                       );
 %   }
 %
 %   my $layer_prefix_on = '';
index 2e98a1b..1cb1659 100644 (file)
                  'new_hashref_callback' => sub {
                    #my( $cgi, $svc_x ) = @_;
 
-                   { svcpart => $svcpart };
+                   { pkgnum  => $pkgnum,
+                     svcpart => $svcpart,
+                   };
 
                  },
 
                  'new_callback' => sub {
-                    my( $cgi, $svc_x, $fields, $opt ) = @_;;
+                    my( $cgi, $svc_x, $fields, $opt ) = @_;
 
                     $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
                     die "No part_svc entry!" unless $part_svc;
 
                     #$svcnum='';
 
+                    if ( my $cb = $opt{'svc_new_callback'} ) {
+                     my $cust_pkg = $pkgnum
+                                      ? qsearchs('cust_pkg', {pkgnum=>$pkgnum})
+                                      : ''; #?
+                      &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt);
+                    }
+
                     $svc_x->set_default_and_fixed;
 
                  },
 sub label_fixup {
   my( $part_svc, $opt ) = @_;
 
+  $opt->{'name'} ||= $part_svc->svc;
+
   my $svcdb = $part_svc->svcdb;
   require "FS/$svcdb.pm";
 
   if ( UNIVERSAL::can("FS::$svcdb", 'table_info') ) {
-    $opt->{'name'} ||= "FS::$svcdb"->table_info->{'name'};
+    #$opt->{'name'} ||= "FS::$svcdb"->table_info->{'name'};
 
     my $fields = "FS::$svcdb"->table_info->{'fields'};
     $opt->{'fields'} ||= [ grep { $_ ne 'svcnum' } keys %$fields ];
@@ -165,7 +176,7 @@ sub label_fixup {
   my $labels = $opt->{labels}; # with -> here
   foreach my $field ( keys %{ $opt->{labels} } ) {
     my $col = $part_svc->part_svc_column($field);
-    $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\S*$/;
+    $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/;
   }
 
 }
index 3c7b752..779708b 100644 (file)
@@ -1,8 +1,8 @@
 <% include( 'elements/svc_Common.html',
-               'name'     => 'Phone number',
                'table'    => 'svc_phone',
                'fields'   => \@fields,
                'labels'   => {
+                               'svcnum'       => 'Service',
                                'countrycode'  => 'Country code',
                                'phonenum'     => 'Phone number',
                                'domsvc'       => 'Domain',
                                'pin'          => 'Voicemail PIN',
                                'phone_name'   => 'Name',
                                'pbxsvc'       => 'PBX',
+                               'locationnum'  => 'E911 location',
                              },
+               'svc_new_callback' => sub {
+                 my( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, $opt ) = @_;
+                 $svc_x->locationnum($cust_pkg->locationnum) if $cust_pkg;
+               },
            )
 %>
 <%init>
@@ -40,6 +45,27 @@ push @fields, { field => 'pbxsvc',
               'sip_password',
               'pin',
               'phone_name',
+
+              { value   => 'E911 Information',
+                type    => 'tablebreak-tr-title',
+                colspan => 7,
+              },
+              { field => 'locationnum',
+                type  => 'select-cust_location',
+                label => 'E911 location',
+                include_opt_callback => sub {
+                  my $svc_phone = shift;
+                  my $pkgnum =  $svc_phone->get('pkgnum')
+                             || $cgi->param('pkgnum')
+                             || $svc_phone->cust_svc->pkgnum; #hua?
+                               #cross agent location exposure?  sheesh
+                  my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum});
+                  my $cust_main = $cust_pkg ? $cust_pkg->cust_main : '';
+                  ( 'no_bold'   => 1,
+                    'cust_main' => $cust_main,
+                  );
+                },
+              },
 ;
 
 </%init>
index 07aaa69..4750b68 100644 (file)
@@ -18,7 +18,7 @@ Example:
 </%doc>
 
 <TR>
-  <TH ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></TH>
+  <<%$th%> ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></<%$th%>>
   <TD COLSPAN=7>
     <INPUT TYPE     = "text"
            NAME     = "<%$pre%>address1"
@@ -48,7 +48,7 @@ Example:
 </TR>
 
 <TR>
-  <TH ALIGN="right"><%$r%>City</TH>
+  <<%$th%> ALIGN="right"><%$r%>City</<%$th%>>
   <TD WIDTH="1">
     <INPUT TYPE     = "text"
            NAME     = "<%$pre%>city"
@@ -59,13 +59,13 @@ Example:
            <% $style %>
     >
   </TD>
-  <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
+  <<%$th%> ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
   <TD><% include('/elements/select-county.html', %select_hash ) %></TD>
-  <TH ALIGN="right" WIDTH="1"><%$r%>State</TH>
+  <<%$th%> ALIGN="right" WIDTH="1"><%$r%>State</<%$th%>>
   <TD WIDTH="1">
     <% include('/elements/select-state.html', %select_hash ) %>
   </TD>
-  <TH><%$r%>Zip</TH>
+  <<%$th%>><%$r%>Zip</<%$th%>>
   <TD>
     <INPUT TYPE     = "text"
            NAME     = "<%$pre%>zip"
@@ -80,7 +80,7 @@ Example:
 </TR>
 
 <TR>
-  <TH ALIGN="right"><%$r%>Country</TH>
+  <<%$th%> ALIGN="right"><%$r%>Country</<%$th%>>
   <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
 </TR>
 
@@ -88,7 +88,7 @@ Example:
   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
 % } else {
 %   if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) {
-      <TR><TH ALIGN="right">Census tract<BR>(automatic)</TH>
+      <TR><<%$th%> ALIGN="right">Census tract<BR>(automatic)</<%$th%>>
         <TD>
           <INPUT TYPE="text" NAME="censustract" VALUE="<% $opt{censustract} %>">
         </TD>
@@ -161,4 +161,6 @@ my %select_hash = (
   'style'    => \@style,
 );
 
+my $th = $opt{'no_bold'} ? 'TD' : 'TH';
+
 </%init>
index da16dfe..6950706 100644 (file)
@@ -118,7 +118,7 @@ Example:
 </SCRIPT>
 
 <TR>
-  <TH ALIGN="right">Service&nbsp;location</TH>
+  <<%$th%> ALIGN="right"><% $opt{'label'} || 'Service&nbsp;location' %></<%$th%>>
   <TD COLSPAN=7>
     <SELECT NAME="locationnum" onChange="locationnum_changed(this);">
       <OPTION VALUE="">(default service address)
@@ -139,6 +139,7 @@ Example:
              #'onchange' ?  probably not
              'disabled'     => ( $locationnum == -1 ? '' : 'DISABLED' ),
              'no_asterisks' => 1,
+             'no_bold'      => $opt{'no_bold'},
           )
 %>
 
@@ -175,4 +176,6 @@ if ( $locationnum && $locationnum != -1 ) {
   }
 }
 
+my $th = $opt{'no_bold'} ? 'TD' : 'TH';
+
 </%init>
index 76ee739..ebde422 100644 (file)
@@ -16,6 +16,7 @@
 <%init>
 
 my $conf = new FS::Conf;
+my $countrydefault = $conf->config('countrydefault') || 'US';
 
 my @fields = qw( countrycode phonenum );
 push @fields, 'domain' if $conf->exists('svc_phone-domain');
@@ -25,6 +26,27 @@ my $html_foot = sub {
   my $svc_phone = shift;
 
   ###
+  # E911 Info
+  ###
+
+  my $loc = $svc_phone->cust_location_or_main;
+
+  my $e911 = 
+    'E911 Information'.
+    &ntable("#cccccc"). '<TR><TD>'. ntable("#cccccc",2).
+      '<TR><TD>Location</TD>'.
+      '<TD BGCOLOR="#FFFFFF">'.
+        $loc->location_label( 'join_string'     => '<BR>',
+                              'double_space'    => ' &nbsp; ',
+                              'escape_function' => \&encode_entities,
+                              'countrydefault'  => $countrydefault,
+                            ).
+      '</TD></TR>'.
+    '</TABLE></TD></TR></TABLE>'.
+    '<BR>'
+  ;
+
+  ###
   # Devices
   ###
 
@@ -123,6 +145,7 @@ my $html_foot = sub {
   # concatenate & return
   ###
 
+  $e911.
   $devices.
   join(' | ', @links ). '<BR>'.
   join(' | ', @ilinks). '<BR>';