From: Ivan Kohler Date: Sat, 5 May 2012 00:07:09 +0000 (-0700) Subject: add searchable and displayable legacy service id (cust_svc.agent_svcid), RT#17619 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=7f2da0c0259bfde6ee3b0d26a62c9663e00a6e77 add searchable and displayable legacy service id (cust_svc.agent_svcid), RT#17619 --- diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 00c519e5b..625e34fad 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1663,14 +1663,15 @@ sub tables_hashref { 'cust_svc' => { 'columns' => [ - 'svcnum', 'serial', '', '', '', '', - 'pkgnum', 'int', 'NULL', '', '', '', - 'svcpart', 'int', '', '', '', '', - 'overlimit', @date_type, '', '', + 'svcnum', 'serial', '', '', '', '', + 'pkgnum', 'int', 'NULL', '', '', '', + 'svcpart', 'int', '', '', '', '', + 'agent_svcid', 'int', 'NULL', '', '', '', + 'overlimit', @date_type, '', '', ], 'primary_key' => 'svcnum', 'unique' => [], - 'index' => [ ['svcnum'], ['pkgnum'], ['svcpart'] ], + 'index' => [ ['svcnum'], ['pkgnum'], ['svcpart'], [ 'agent_svcid' ] ], }, 'cust_svc_option' => { diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index 6bd8cb837..1fd84063d 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -69,6 +69,8 @@ The following fields are currently supported: =item svcpart - Service definition (see L) +=item agent_svcid - Optional legacy service ID + =item overlimit - date the service exceeded its usage limit =back @@ -319,6 +321,7 @@ sub check { $self->ut_numbern('svcnum') || $self->ut_numbern('pkgnum') || $self->ut_number('svcpart') + || $self->ut_numbern('agent_svcid') || $self->ut_numbern('overlimit') ; return $error if $error; @@ -446,9 +449,12 @@ sub svc_label_long { shift->_svc_label('label_long', @_); } sub _svc_label { my( $self, $method, $svc_x ) = ( shift, shift, shift ); + my $identifier = $svc_x->$method(@_); + $identifier = '['.$self->agent_svcid.']'. $identifier if $self->agent_svcid; + ( $self->part_svc->svc, - $svc_x->$method(@_), + $identifier, $self->part_svc->svcdb, $self->svcnum ); @@ -831,24 +837,37 @@ customers, this always requires an exact match. =cut # though perhaps it should be fuzzy in some cases? + sub smart_search { + my %param = __PACKAGE__->smart_search_param(@_); + qsearch(\%param); +} + +sub smart_search_param { + my $class = shift; my %opt = @_; - # some false laziness w/ search/cust_svc.html + my $string = $opt{'search'}; $string =~ s/(^\s+|\s+$)//; #trim leading & trailing whitespace - my @extra_sql = ' ( '. join(' OR ', - map { my $table = $_; - my $search_sql = "FS::$table"->search_sql($string); - " ( svcdb = '$table' - AND 0 < ( SELECT COUNT(*) FROM $table - WHERE $table.svcnum = cust_svc.svcnum - AND $search_sql - ) - ) "; - } - FS::part_svc->svc_tables - ). ' ) '; + my @or = + map { my $table = $_; + my $search_sql = "FS::$table"->search_sql($string); + " ( svcdb = '$table' + AND 0 < ( SELECT COUNT(*) FROM $table + WHERE $table.svcnum = cust_svc.svcnum + AND $search_sql + ) + ) "; + } + FS::part_svc->svc_tables; + + if ( $string =~ /^(\d+)$/ ) { + unshift @or, " ( agent_svcid IS NOT NULL AND agent_svcid = $1 ) "; + } + + my @extra_sql = ' ( '. join(' OR ', @or). ' ) '; + push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( 'null_right' => 'View/link unlinked services' ); @@ -858,14 +877,16 @@ sub smart_search { ' LEFT JOIN cust_main USING ( custnum )'. ' LEFT JOIN part_svc USING ( svcpart )'; - qsearch({ - 'table' => 'cust_svc', - 'addl_from' => $addl_from, - 'hashref' => {}, - 'extra_sql' => $extra_sql, - }); + ( + 'table' => 'cust_svc', + 'addl_from' => $addl_from, + 'hashref' => {}, + 'extra_sql' => $extra_sql, + ); } +=back + =head1 BUGS Behaviour of changing the svcpart of cust_svc records is undefined and should diff --git a/httemplate/search/cust_svc.html b/httemplate/search/cust_svc.html index 9cf4bbda6..585431eb4 100644 --- a/httemplate/search/cust_svc.html +++ b/httemplate/search/cust_svc.html @@ -42,79 +42,75 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('List services'); -my $addl_from = ' LEFT JOIN part_svc USING ( svcpart ) '. - ' LEFT JOIN cust_pkg USING ( pkgnum ) '. - ' LEFT JOIN cust_main USING ( custnum ) '; +my $sql_query; -my @extra_sql = (); my $orderby = 'ORDER BY svcnum'; #has to be ordered by something #for pagination to work + if ( length( $cgi->param('search_svc') ) ) { - my $string = $cgi->param('search_svc'); - $string =~ s/(^\s+|\s+$)//; #trim leading & trailing whitespace - - # implement fuzzy searching in subclasses too at some point? - # service searching maybe shouldn't be fuzzy... - - push @extra_sql, - ' ( '. join(' OR ', - map { my $table = $_; - my $search_sql = "FS::$table"->search_sql($string); - " ( svcdb = '$table' - AND 0 < ( SELECT COUNT(*) FROM $table - WHERE $table.svcnum = cust_svc.svcnum - AND $search_sql - ) - ) "; - } - FS::part_svc->svc_tables - ). ' ) '; - -} elsif ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) { - - $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb"; - push @extra_sql, "svcdb = '$1'"; - $addl_from .= " LEFT JOIN $1 USING ( svcnum ) "; - - push @extra_sql, 'pkgnum IS NULL' - if $cgi->param('magic') eq 'unlinked'; - - if ( $cgi->param('sortby') =~ /^(\w+)$/ ) { - my $sortby = $1; - $orderby = "ORDER BY $sortby"; + $sql_query = { + FS::cust_svc->smart_search_param( + 'search' => scalar($cgi->param('search_svc')) + ) + }; + +} else { + + my $addl_from = ' LEFT JOIN part_svc USING ( svcpart ) '. + ' LEFT JOIN cust_pkg USING ( pkgnum ) '. + ' LEFT JOIN cust_main USING ( custnum ) '; + + my @extra_sql = (); + + if ( $cgi->param('magic') =~ /^(all|unlinked)$/ ) { + + $cgi->param('svcdb') =~ /^(svc_\w+)$/ or die "unknown svcdb"; + push @extra_sql, "svcdb = '$1'"; + $addl_from .= " LEFT JOIN $1 USING ( svcnum ) "; + + push @extra_sql, 'pkgnum IS NULL' + if $cgi->param('magic') eq 'unlinked'; + + if ( $cgi->param('sortby') =~ /^(\w+)$/ ) { + my $sortby = $1; + $orderby = "ORDER BY $sortby"; + } + + } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) { + + push @extra_sql, "svcpart = $1"; + + } else { + errorpage("No search term specified"); } -} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) { + #here is the agent virtualization + push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( + 'null_right' => 'View/link unlinked services' + ); - push @extra_sql, "svcpart = $1"; + my $extra_sql = ' WHERE '. join(' AND ', @extra_sql ); + + $sql_query = { + 'table' => 'cust_svc', + 'addl_from' => $addl_from, + 'hashref' => {}, + 'extra_sql' => $extra_sql, + }; -} else { - errorpage("No search term specified"); } -#here is the agent virtualization -push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql( - 'null_right' => 'View/link unlinked services' - ); - -my $extra_sql = ' WHERE '. join(' AND ', @extra_sql ); - -my $sql_query = { - 'select' => join(', ', - 'cust_svc.*', - 'part_svc.*', - 'cust_main.custnum', - FS::UI::Web::cust_sql_fields(), - ), - 'table' => 'cust_svc', - 'addl_from' => $addl_from, - 'hashref' => {}, - 'extra_sql' => $extra_sql, - 'order_by' => $orderby, -}; +$sql_query->{'select'} = join(', ', + 'cust_svc.*', + 'part_svc.*', + 'cust_main.custnum', + FS::UI::Web::cust_sql_fields(), + ); +$sql_query->{'order_by'} = $orderby; -my $count_query = "SELECT COUNT(*) FROM cust_svc $addl_from $extra_sql"; +my $count_query = "SELECT COUNT(*) FROM cust_svc ". $sql_query->{addl_from}. + ' '. $sql_query->{extra_sql}; my $link = sub { my $cust_svc = shift; diff --git a/httemplate/view/svc_acct.cgi b/httemplate/view/svc_acct.cgi index 3bfcee473..3ad21bb4d 100755 --- a/httemplate/view/svc_acct.cgi +++ b/httemplate/view/svc_acct.cgi @@ -47,6 +47,7 @@ <& svc_acct/basics.html, 'svc_acct' => $svc_acct, 'part_svc' => $part_svc, + 'cust_svc' => $cust_svc, %gopt, &> diff --git a/httemplate/view/svc_acct/basics.html b/httemplate/view/svc_acct/basics.html index 8f180b648..bcd84696e 100644 --- a/httemplate/view/svc_acct/basics.html +++ b/httemplate/view/svc_acct/basics.html @@ -1,6 +1,9 @@ <% &ntable("#cccccc") %><% &ntable("#cccccc",2) %> <& /view/elements/tr.html, label=>mt('Service'), value=>$part_svc->svc &> +% if ( $opt{cust_svc}->agent_svcid ) { + <& /view/elements/tr.html, label=>mt('Legacy ID'), value=>$opt{cust_svc}->agent_svcid &> +% } <& /view/elements/tr.html, label=>mt('Username'), value=>$svc_acct->username &> <& /view/elements/tr.html, label=>mt('Domain'), value=>$domain &>