X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fedit%2Felements%2Fsvc_Common.html;h=e1c30908041424cbee226b4d091afbd10fd563c0;hp=aa7699555cd6bbab46e28fbf6afdd91e0e192050;hb=25efd7207d9ea9be4bea1093917c0d8dc4b1e87a;hpb=e0a26680d75fc2000bde195eba7946805a3aaa28 diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html index aa7699555..e1c309080 100644 --- a/httemplate/edit/elements/svc_Common.html +++ b/httemplate/edit/elements/svc_Common.html @@ -21,6 +21,7 @@ : ''; #? &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); } + }, 'edit_callback' => sub { @@ -43,6 +44,27 @@ : ''; #? &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); } + + if ( $part_svc->has_router ) { + my $router = qsearchs('router', {svcnum => $svc_x->svcnum}); + if ( $router ) { + $svc_x->set("router_$_", $router->get($_)) + foreach ('routername', 'routernum'); + my ($block) = $router->addr_block; # one-to-one for now + if ( $block ) { + $svc_x->set('router_blocknum', $block->blocknum); + # silly, but necessary...make the currently + # assigned block appear on the list + my ($field) = grep {ref($_) and + $_->{field} eq 'router_blocknum'} + @$fields; + $field->{extra_sql} = + ' OR routernum = '.$router->routernum; + $field->{curr_value} = $block->blocknum; + } + } + } + }, 'new_hashref_callback' => sub { @@ -72,7 +94,6 @@ } $svc_x->set_default_and_fixed; - }, 'field_callback' => sub { @@ -80,35 +101,85 @@ my $columndef = $part_svc->part_svc_column($f->{'field'}); my $flag = $columndef->columnflag; - if ( $flag eq 'F' ) { - $f->{'type'} = length($columndef->columnvalue) - ? 'fixed' - : 'hidden'; + + $f->{'required'} = 1 + if $columndef->required; + + if ( $flag eq 'F' ) { #fixed $f->{'value'} = $columndef->columnvalue; - } elsif ( $flag eq 'A' ) { + if (length($columndef->columnvalue)) { + + if ( $f->{'type'} =~ /^select-?(.*)/ ) { + # try to display this in a user-friendly manner + if ( $f->{'table'} ) { # find matching records + $f->{'value_col'} ||= + dbdef->table($f->{'table'})->primary_key; + + my @values = split(',', $f->{'value'}); + my @recs; + foreach (@values) { + push @recs, qsearchs( $f->{'table'}, + { $f->{'value_col'} => $_ } + ); + } + if ( @recs ) { + my $method = $f->{'name_col'}; + if ( $f->{'multiple'} ) { + $f->{'formatted_value'} = [ + map { $_->method } @recs + ]; + } else { # there shouldn't be more than one... + $f->{'formatted_value'} = $recs[0]->$method; + } + } # if not, then just let tr-fixed display the + # values as-is + + } # other select types probably don't matter + } # if it's a select + + $f->{'type'} = 'fixed'; + + } else { # fixed, null + $f->{'type'} = 'hidden'; + } + + } elsif ( $flag eq 'A' ) { #auto assign from inventory $f->{'type'} = 'hidden'; - } elsif ( $flag eq 'M' ) { + + } elsif ( $flag eq 'M' ) { #manually assign from inventory + $f->{'type'} = 'select-inventory_item'; $f->{'empty_label'} = 'Select inventory item'; - $f->{'type'} = 'select-table'; - $f->{'table'} = 'inventory_item'; - $f->{'name_col'} = 'item'; - $f->{'value_col'} = 'item'; - $f->{'agent_virt'} = 1; - $f->{'agent_null'} = 1; + $f->{'extra_sql'} = 'WHERE ( svcnum IS NULL ' . + ($object->svcnum && ' OR svcnum = '.$object->svcnum) . + ')'; + $f->{'classnum'} = $columndef->columnvalue; + $f->{'disable_empty'} = $object->svcnum ? 1 : 0; + + } elsif ( $flag eq 'H' ) { #hardware + $f->{'type'} = 'select-hardware_type'; $f->{'hashref'} = { - 'classnum'=>$columndef->columnvalue, - #'svcnum' => '', + 'classnum'=>$columndef->columnvalue }; - $f->{'extra_sql'} = 'AND ( svcnum IS NULL '; - $f->{'extra_sql'} .= ' OR svcnum = '. $object->svcnum - if $object->svcnum; - $f->{'extra_sql'} .= ' ) '; - $f->{'disable_empty'} = $object->svcnum ? 1 : 0, - } - if ( $f->{'type'} eq 'select-svc_pbx' - || $f->{'type'} eq 'select-svc-domain' - ) + } elsif ( $flag eq 'S' #selectable choice + && $f->{type} !~ /^select-svc/ ) { + $f->{type} = 'select'; + $f->{options} = [ split( /\s*,\s*/, + $columndef->columnvalue) + ]; + } # shouldn't this be enforced for all 'S' fields? + + elsif ( $flag eq 'P' ) { #form fcc_477 values + $f->{type} = 'fixed'; + my $cust_pkg = FS::Record::qsearchs({ + 'table' => 'cust_pkg', + 'hashref' => { 'pkgnum' => $object->{Hash}->{pkgnum} } + }); + my $fcc_record = $cust_pkg->fcc_477_record('broadband_'.$columndef->columnvalue.'stream') if $cust_pkg; + $f->{'value'} = $fcc_record->{Hash}->{optionvalue} ? $fcc_record->{Hash}->{optionvalue} * 1000 : ''; + } # end 477 values + + if ( $f->{'type'} =~ /^select-svc/ ) { $f->{'include_opt_callback'} = sub { ( 'pkgnum' => $pkgnum, @@ -122,23 +193,28 @@ $object->set('custnum', $cust_pkg->custnum); } + if ( my $cb = $opt{'svc_field_callback'} ) { + &{ $cb }( $cgi, $object, $f); + } + }, 'html_init' => sub { + my $html; my $cust_main; if ( $pkgnum ) { my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum}); $cust_main = $cust_pkg->cust_main if $cust_pkg; - } - $cust_main - ? include( '/elements/small_custview.html', + if ( $cust_main ) { + $html = include( '/elements/small_custview.html', $cust_main, '', 1, popurl(2). "view/cust_main.cgi" - ). '
' - : ''; - + ). '
'; + } + } + $html; }, 'html_table_bottom' => sub { @@ -200,6 +276,28 @@ sub label_fixup { $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/; } + if ( $part_svc->has_router ) { + # these will be set up as pseudo-fields in the new_ and edit_ callbacks + push @{ $opt->{'fields'} }, ( + { field => 'router_routernum', type => 'hidden' }, + { field => 'router_routername', type => 'text', size => 32 }, + # router address block selection + # (one-to-one for now) + { field => 'router_blocknum', + type => 'select-table', + table => 'addr_block', + hashref => { 'routernum' => '0' }, + agent_virt => 1, + agent_null => 1, + name_col => 'cidr', + order_by => 'ORDER BY ip_gateway, ip_netmask', + empty_label => '(none)', + disable_empty => 0, + }, + ); + $labels->{router_routername} = 'Attached router name'; + $labels->{router_blocknum} = 'Attached address block'; + } }