From 4bd9d3d9dc5325f0d7bd498e457140b15d01866c Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 12 Mar 2010 03:36:47 +0000 Subject: [PATCH] add location to svc_phone, RT#7047 --- FS/FS/Schema.pm | 5 ++- FS/FS/cust_pkg.pm | 30 ++++------------- FS/FS/location_Mixin.pm | 43 ++++++++++++++++++++++++ FS/FS/svc_phone.pm | 9 ++++- FS/t/location_Mixin.t | 5 +++ httemplate/edit/elements/edit.html | 8 +++-- httemplate/edit/elements/svc_Common.html | 19 ++++++++--- httemplate/edit/svc_phone.cgi | 28 ++++++++++++++- httemplate/elements/location.html | 16 +++++---- httemplate/elements/tr-select-cust_location.html | 5 ++- httemplate/view/svc_phone.cgi | 23 +++++++++++++ 11 files changed, 150 insertions(+), 41 deletions(-) create mode 100644 FS/FS/location_Mixin.pm create mode 100644 FS/t/location_Mixin.t diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 9016676c3..46ad18a2f 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -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' => { diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index e11e82f81..dbce6cbf5 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -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). -=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), otherwise returns the customer (see L). -=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). =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 index 000000000..675e00255 --- /dev/null +++ b/FS/FS/location_Mixin.pm @@ -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). + +=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), otherwise returns the customer (see L). + +=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). + +=cut + +sub location_label { + my $self = shift; + my $object = $self->cust_location_or_main; + $object->location_label(@_); +} + +1; diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index 0ed01ad36..7405a71fd 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -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 index 000000000..b6a9bf23f --- /dev/null +++ b/FS/t/location_Mixin.t @@ -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"; diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 8c88852ae..1a1023cbd 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -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 = ''; diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html index 2e98a1b25..1cb1659f4 100644 --- a/httemplate/edit/elements/svc_Common.html +++ b/httemplate/edit/elements/svc_Common.html @@ -34,12 +34,14 @@ '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; @@ -48,6 +50,13 @@ #$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; }, @@ -141,11 +150,13 @@ 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*$/; } } diff --git a/httemplate/edit/svc_phone.cgi b/httemplate/edit/svc_phone.cgi index 3c7b75249..779708b4e 100644 --- a/httemplate/edit/svc_phone.cgi +++ b/httemplate/edit/svc_phone.cgi @@ -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', @@ -10,7 +10,12 @@ '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, + ); + }, + }, ; diff --git a/httemplate/elements/location.html b/httemplate/elements/location.html index 07aaa69f0..4750b687d 100644 --- a/httemplate/elements/location.html +++ b/httemplate/elements/location.html @@ -18,7 +18,7 @@ Example: - <%$r%><% $opt{'address1_label'} || 'Address' %> + <<%$th%> ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %>> - <%$r%>City + <<%$th%> ALIGN="right"><%$r%>City> > - ><%$r%>County + <<%$th%> ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County> <% include('/elements/select-county.html', %select_hash ) %> - <%$r%>State + <<%$th%> ALIGN="right" WIDTH="1"><%$r%>State> <% include('/elements/select-state.html', %select_hash ) %> - <%$r%>Zip + <<%$th%>><%$r%>Zip> - <%$r%>Country + <<%$th%> ALIGN="right"><%$r%>Country> <% include('/elements/select-country.html', %select_hash ) %> @@ -88,7 +88,7 @@ Example: % } else { % if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) { - Census tract
(automatic) + <<%$th%> ALIGN="right">Census tract
(automatic)> @@ -161,4 +161,6 @@ my %select_hash = ( 'style' => \@style, ); +my $th = $opt{'no_bold'} ? 'TD' : 'TH'; + diff --git a/httemplate/elements/tr-select-cust_location.html b/httemplate/elements/tr-select-cust_location.html index da16dfe1c..695070699 100644 --- a/httemplate/elements/tr-select-cust_location.html +++ b/httemplate/elements/tr-select-cust_location.html @@ -118,7 +118,7 @@ Example: - Service location + <<%$th%> ALIGN="right"><% $opt{'label'} || 'Service location' %>>