multiple DID provisioning, RT#13721
authorivan <ivan>
Wed, 10 Aug 2011 05:22:34 +0000 (05:22 +0000)
committerivan <ivan>
Wed, 10 Aug 2011 05:22:34 +0000 (05:22 +0000)
12 files changed:
httemplate/edit/process/elements/process.html
httemplate/edit/process/svc_phone.html
httemplate/edit/svc_phone.cgi
httemplate/elements/select-areacode.html
httemplate/elements/select-did.html
httemplate/elements/select-exchange.html
httemplate/elements/select-phonenum.html
httemplate/elements/select-state.html
httemplate/misc/areacodes.cgi
httemplate/misc/exchanges.cgi
httemplate/misc/phonenums.cgi
httemplate/view/cust_main/packages/services.html

index f7558e8..24064f9 100644 (file)
@@ -78,6 +78,9 @@ Example:
    'agent_virt'       => 1,
    'agent_null_right' => 'Access Right Name',
 
+   #special bulk insert mode
+   'bulk' => 'field',
+
  &>
 
 </%doc>
@@ -85,6 +88,9 @@ Example:
 %
 %  my $edit_ext = $opt{'edit_ext'} || 'html';
 %  my $url = $opt{'error_redirect'} || popurl(2)."$table.$edit_ext";
+
+%  #my $query = $m->scomp('/elements/create_uri_query');
+%  #$cgi->redirect("$url?$query");
 %  if ( length($cgi->query_string) > 1920 ) { #stupid IE 2083 URL limit
 % 
 %    my $session = int(rand(4294967296)); #XXX
@@ -128,7 +134,7 @@ Example:
 %
 %  if ( $opt{'redirect'} ) {
 %
-<% $cgi->redirect( $opt{'redirect'}. $pkeyvalue ) %>
+<% $cgi->redirect( $opt{'redirect'}. $new_pkey) %>
 %
 %  } else { 
 %
@@ -163,13 +169,13 @@ my $fields = $opt{'fields'}
              #|| [ grep { $_ ne $pkey } dbdef->table($table)->columns ];
              || [ fields($table) ];
 
-my $pkeyvalue = $cgi->param($pkey);
+my $old_pkey = $cgi->param($pkey);
 
 my $old = '';
-if ( $pkeyvalue ) {
+if ( $old_pkey ) {
   $old = qsearchs({
     'table'   => $table,
-    'hashref' => { $pkey => $pkeyvalue },
+    'hashref' => { $pkey => $old_pkey },
     'extra_sql' => ( $opt{'agent_virt'}
                        ? ' AND '. $curuser->agentnums_sql(
                                     'null_right' => $opt{'agent_null_right'}
@@ -179,145 +185,163 @@ if ( $pkeyvalue ) {
   });
 }
 
+my $bfield = $opt{'bulk'};
+
 my %hash =
   map { my @entry = ( $_ => scalar($cgi->param($_)) );
         $opt{'value_callback'} ? ( $_ => &{ $opt{'value_callback'} }( @entry ))
                                : ( @entry )
-      } @$fields;
+      } grep { $_ ne $bfield } @$fields;
+
+my @values = ( 1 );
+if ( $bfield ) {
+  @values = $cgi->param($bfield);
+  warn join(',', @values);
+}
+
+my $new;
+my $new_pkey = '';
+foreach my $value ( @values ) {
 
-my $new = $class->new( \%hash );
+  $new = $class->new( \%hash );
 
-if ($old && exists($opt{'copy_on_empty'})) {
-  foreach my $field (@{$opt{'copy_on_empty'}}) {
-    $new->set($field, $old->get($field))
-      unless scalar($cgi->param($field));
+  $new->$bfield($value) if $bfield;
+
+  if ($old && exists($opt{'copy_on_empty'})) {
+    foreach my $field (@{$opt{'copy_on_empty'}}) {
+      $new->set($field, $old->get($field))
+        unless scalar($cgi->param($field));
+    }
   }
-}
 
-if ( $opt{'agent_virt'} ) {
+  if ( $opt{'agent_virt'} ) {
 
-  if ( ! $new->agentnum
-       && (    ! $opt{'agent_null_right'}
-            || ! $curuser->access_right($opt{'agent_null_right'})
-          )
-     )
-  {
+    if ( ! $new->agentnum
+         && (    ! $opt{'agent_null_right'}
+              || ! $curuser->access_right($opt{'agent_null_right'})
+            )
+       )
+    {
 
-    $error ||= 'Select an agent';
+      $error ||= 'Select an agent';
 
-  } else {
+    } else {
 
-    die "illegal agentnum"
-      unless $curuser->agentnums_href->{$new->agentnum}
-          or $curuser->access_right('View customers of all agents')
-          or $opt{'agent_null_right'}
-             && ! $new->agentnum
-             && $curuser->access_right($opt{'agent_null_right'});
+      die "illegal agentnum"
+        unless $curuser->agentnums_href->{$new->agentnum}
+            or $curuser->access_right('View customers of all agents')
+            or $opt{'agent_null_right'}
+               && ! $new->agentnum
+               && $curuser->access_right($opt{'agent_null_right'});
 
-  }
+    }
 
-}
+  }
 
-$error ||= $new->check;
+  $error ||= $new->check;
 
-my @args = ();
-if ( !$error && $opt{'args_callback'} ) {
-  @args = &{ $opt{'args_callback'} }( $cgi, $new );
-}
+  my @args = ();
+  if ( !$error && $opt{'args_callback'} ) {
+    @args = &{ $opt{'args_callback'} }( $cgi, $new );
+  }
 
-if ( !$error && $opt{'debug'} ) {
-  warn "$me updating record in $table table using $class class\n";
-  warn Dumper(\%hash);
-  warn "with args: \n". Dumper(\@args) if @args;
-}
+  if ( !$error && $opt{'debug'} ) {
+    warn "$me updating record in $table table using $class class\n";
+    warn Dumper(\%hash);
+    warn "with args: \n". Dumper(\@args) if @args;
+  }
 
-if ( !$error ) {
-  if ( $pkeyvalue ) {
-    $error = $new->replace($old, @args);
-  } else {
-    $error = $new->insert(@args);
-    $pkeyvalue = $new->getfield($pkey);
+  if ( !$error ) {
+    if ( $old_pkey ) {
+      $error = $new->replace($old, @args);
+    } else {
+      $error = $new->insert(@args);
+      $new_pkey = $new->getfield($pkey);
+    }
   }
-}
 
-if ( !$error && $opt{'process_m2m'} ) {
+  if ( !$error && $opt{'process_m2m'} ) {
+
+    my @process_m2m = ref($opt{'process_m2m'}) eq 'ARRAY'
+                        ? @{ $opt{'process_m2m'} }
+                        :  ( $opt{'process_m2m'} );
 
-  my @process_m2m = ref($opt{'process_m2m'}) eq 'ARRAY'
-                      ? @{ $opt{'process_m2m'} }
-                      :  ( $opt{'process_m2m'} );
+    foreach my $process_m2m (@process_m2m) {
 
-  foreach my $process_m2m (@process_m2m) {
+      $process_m2m->{'params'} ||= scalar($cgi->Vars);
 
-    $process_m2m->{'params'} ||= scalar($cgi->Vars);
+      warn "$me processing m2m:\n". Dumper( %$process_m2m )
+        if $opt{'debug'};
 
-    warn "$me processing m2m:\n". Dumper( %$process_m2m )
-      if $opt{'debug'};
+      $error = $new->process_m2m( %$process_m2m );
+    }
 
-    $error = $new->process_m2m( %$process_m2m );
   }
 
-}
+  if ( !$error && $opt{'process_m2name'} ) {
 
-if ( !$error && $opt{'process_m2name'} ) {
+    my @process_m2name = ref($opt{'process_m2name'}) eq 'ARRAY'
+                           ? @{ $opt{'process_m2name'} }
+                           :  ( $opt{'process_m2name'} );
 
-  my @process_m2name = ref($opt{'process_m2name'}) eq 'ARRAY'
-                         ? @{ $opt{'process_m2name'} }
-                         :  ( $opt{'process_m2name'} );
 
+    foreach my $process_m2name (@process_m2name) {
 
-  foreach my $process_m2name (@process_m2name) {
+      if ( $opt{'debug'} ) {
+        warn "$me processing m2name:\n". Dumper( %{ $process_m2name },
+                                                 'params' => scalar($cgi->Vars),
+                                               );
+      }
 
-    if ( $opt{'debug'} ) {
-      warn "$me processing m2name:\n". Dumper( %{ $process_m2name },
-                                               'params' => scalar($cgi->Vars),
-                                             );
+      $error = $new->process_m2name( %{ $process_m2name },
+                                     'params' => scalar($cgi->Vars),
+                                   );
     }
 
-    $error = $new->process_m2name( %{ $process_m2name },
-                                   'params' => scalar($cgi->Vars),
-                                 );
   }
 
-}
+  if ( !$error && $opt{'process_o2m'} ) {
 
-if ( !$error && $opt{'process_o2m'} ) {
+    my @process_o2m = ref($opt{'process_o2m'}) eq 'ARRAY'
+                           ? @{ $opt{'process_o2m'} }
+                           :  ( $opt{'process_o2m'} );
 
-  my @process_o2m = ref($opt{'process_o2m'}) eq 'ARRAY'
-                         ? @{ $opt{'process_o2m'} }
-                         :  ( $opt{'process_o2m'} );
 
+    foreach my $process_o2m (@process_o2m) {
 
-  foreach my $process_o2m (@process_o2m) {
+      if ( $opt{'debug'} ) {
+        warn "$me processing o2m:\n". Dumper( %{ $process_o2m },
+                                                 'params' => scalar($cgi->Vars),
+                                               );
+      }
 
-    if ( $opt{'debug'} ) {
-      warn "$me processing o2m:\n". Dumper( %{ $process_o2m },
-                                               'params' => scalar($cgi->Vars),
-                                             );
+      $error = $new->process_o2m( %{ $process_o2m },
+                                     'params' => scalar($cgi->Vars),
+                                   );
     }
 
-    $error = $new->process_o2m( %{ $process_o2m },
-                                   'params' => scalar($cgi->Vars),
-                                 );
   }
 
-}
-
 
-if ( $error ) {
+  if ( $error ) {
 
-  $cgi->param('error', $error);
-  if ( $opt{'clear_on_error'} && scalar(@{$opt{'clear_on_error'}}) ) {
-    foreach my $field (@{$opt{'clear_on_error'}}) {
-      $cgi->param($field, '')
+    $cgi->param('error', $error);
+    if ( $opt{'clear_on_error'} && scalar(@{$opt{'clear_on_error'}}) ) {
+      foreach my $field (@{$opt{'clear_on_error'}}) {
+        $cgi->param($field, '')
+      }
     }
-  }
 
-} else {
+  } else {
+
+    if ( $opt{'noerror_callback'} ) {
+      &{ $opt{'noerror_callback'} }( $cgi, $new );
+    }
 
-  if ( $opt{'noerror_callback'} ) {
-    &{ $opt{'noerror_callback'} }( $cgi, $new );
   }
 
+  last if $error;
+
 }
 
 </%init>
index 9dd1226..7a3b43d 100644 (file)
@@ -1,13 +1,32 @@
-<% include( 'elements/svc_Common.html',
-               'table'    => 'svc_phone',
-               'args_callback' => $args_callback,
+<& elements/svc_Common.html,
+               'table'          => 'svc_phone',
+               'args_callback'  => $args_callback,
               'value_callback' => $value_callback,
-           )
-%>
+               %opt,
+&>
 <%init>
 
+my %opt = ();
+if ( $cgi->param('bulk') ) {
+  $opt{'bulk'}     = 'phonenum';
+
+  my $cust_pkg = qsearchs('cust_pkg', { pkgnum=>scalar($cgi->param('pkgnum')) })
+    or die "unknown pkgnum";
+  my $custnum = $cust_pkg->custnum;
+
+  my $show =
+    $FS::CurrentUser::CurrentUser->default_customer_view =~ /^(jumbo|packages)$/
+      ? ''
+      : ';show=packages';
+  #my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
+  $opt{'redirect'}= popurl(3)."view/cust_main.cgi?custnum=$custnum$show;dummy=";
+}
+
+my $right = $opt{'bulk'} ? 'Bulk provision customer service'
+                         :      'Provision customer service';
+
 die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
+  unless $FS::CurrentUser::CurrentUser->access_right($right);
 
 my $tollfreephonenum = $cgi->param('tollfreephonenum');
 $cgi->param('phonenum',$tollfreephonenum) if $tollfreephonenum =~ /^\d+$/;
index 2c19d2c..9647b68 100644 (file)
@@ -1,36 +1,56 @@
-<% include( 'elements/svc_Common.html',
-               'table'    => 'svc_phone',
-               'fields'   => \@fields,
-               'svc_new_callback' => sub {
-                 my( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, $opt ) = @_;
-                 $svc_x->locationnum($cust_pkg->locationnum) if $cust_pkg;
-               },
-           )
-%>
+<& elements/svc_Common.html,
+     'table'            => 'svc_phone',
+     'fields'           => [],
+     'begin_callback'   => $begin_callback,
+     'svc_new_callback' => sub {
+       my( $cgi, $svc_x, $part_svc, $cust_pkg, $fields, $opt ) = @_;
+       $svc_x->locationnum($cust_pkg->locationnum) if $cust_pkg;
+     },
+&>
 <%init>
 
-die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
+my $begin_callback = sub {
+  my( $cgi, $fields, $opt ) = @_;
 
-my $conf = new FS::Conf;
+  my $bulk = $cgi->param('bulk') ? 1 : 0;
 
-my @fields = ( 'countrycode',
-               { field => 'phonenum',
-                 type  => 'select-did',
-                 label => 'Phone number',
-               },
-             );
+  my $right = $bulk ? 'Bulk provision customer service'
+                    :      'Provision customer service';
 
-push @fields, { field => 'domsvc',
-                type  => 'select-svc-domain',
-                label => 'Domain',
-              }
-  if $conf->exists('svc_phone-domain');
+  die "access denied"
+    unless $FS::CurrentUser::CurrentUser->access_right($right);
 
-push @fields, { field => 'pbxsvc',
-                type  => 'select-svc_pbx',
-                label => 'PBX',
-              },
+  my $conf = new FS::Conf;
+
+  push @$fields,
+              'countrycode',
+              { field    => 'phonenum',
+                type     => 'select-did',
+                label    => 'Phone number',
+                multiple => $bulk,
+              };
+
+  push @$fields, { field => 'domsvc',
+                   type  => 'select-svc-domain',
+                   label => 'Domain',
+                 }
+    if $conf->exists('svc_phone-domain');
+
+  push @$fields, { field => 'pbxsvc',
+                   type  => 'select-svc_pbx',
+                   label => 'PBX',
+                 };
+
+  if ( $bulk ) {
+
+    push @$fields, { field => 'bulk',
+                     type  => 'hidden',
+                     value => '1',
+                   };
+
+  } else {
+
+    push @$fields,
               'sip_password',
               'pin',
               { field => 'phone_name',
@@ -62,10 +82,11 @@ push @fields, { field => 'pbxsvc',
                 },
               },
               { field => 'custnum', type=> 'hidden' }, #for new cust_locations
-;
+    ;
+  }
 
-if ( $conf->exists('svc_phone-lnp') ) {
-    push @fields,
+  if ( $conf->exists('svc_phone-lnp') && !$bulk ) {
+    push @$fields,
             { value   => 'Number Portability',
              type    => 'tablebreak-tr-title',
                                colspan => 8,
@@ -87,7 +108,9 @@ if ( $conf->exists('svc_phone-lnp') ) {
            },
             'lnp_other_provider',
             'lnp_other_provider_account',
-;
-}
+    ;
+  }
+
+};
 
 </%init>
index 453205c..a302bef 100644 (file)
@@ -38,7 +38,9 @@
       // blank the current phonenum too
       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
-      opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
+      if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
+        opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
+      }
 
 %     if ($opt{empty}) {
         opt(what.form.<% $opt{'prefix'} %>areacode, '', '<% $opt{empty} %>');
index 8e981fd..a69450c 100644 (file)
@@ -18,47 +18,46 @@ Example:
     <TABLE>
 
       <TR>
-        <TD>
+        <TD VALIGN="top">
           <% include('/elements/select-state.html',
                        'prefix'        => 'phonenum_', #$field.'_',
                        'country'       => $country,
+                       'svcpart'       => $svcpart,
                        'disable_empty' => 0,
                        'empty_label'   => 'Select state',
                     )
           %>
+          <BR><FONT SIZE="-1">State</FONT>
         </TD>
-        <TD>
+        <TD VALIGN="top">
           <% include('/elements/select-areacode.html',
                        'state_prefix' => 'phonenum_', #$field.'_',
                        'svcpart'      => $svcpart,
                        'empty'        => 'Select area code',
                     )
           %>
+          <BR><FONT SIZE="-1">Area code</FONT>
         </TD>
-        <TD>
+        <TD VALIGN="top">
           <% include('/elements/select-exchange.html',
                        'svcpart' => $svcpart,
                        'empty'   => 'Select exchange',
                     )
           %>
+          <BR><FONT SIZE="-1">City / Exchange</FONT>
         </TD>
-        <TD>
+        <TD VALIGN="top">
           <% include('/elements/select-phonenum.html',
-                       'svcpart' => $svcpart,
-                       'empty'   => 'Select phone number',
-                      'bulknum' => $bulknum,
+                       'svcpart'  => $svcpart,
+                       'empty'    => 'Select phone number',
+                      'bulknum'  => $bulknum,
+                       'multiple' => $multiple,
                     )
           %>
+          <BR><FONT SIZE="-1">Phone number</FONT>
         </TD>
       </TR>
 
-      <TR>
-        <TD><FONT SIZE="-1">State</FONT></TD>
-        <TD><FONT SIZE="-1">Area code</FONT></TD>
-        <TD><FONT SIZE="-1">City / Exchange</FONT></TD>
-        <TD><FONT SIZE="-1">Phone number</FONT></TD>
-      </TR>
-
     </TABLE>
 
 % } 
@@ -118,7 +117,8 @@ $export = $exports[0] if scalar(@exports);
 
 my $use_selector = scalar(@exports) ? 1 : 0;
 
-my $bulknum = $opt{'bulknum'} || 0;
+my $bulknum = $opt{'bulknum'} || 0; #Bulk DID orders via ordering system, vs.
+my $multiple = $opt{'multiple'} || 0; #just selecting a bunch at a time
 
 my $country  = ( $export && $export->option('country') )
             || $conf->config('countrydefault')
index 012e7c6..9e4b5ce 100644 (file)
@@ -33,7 +33,9 @@
       // blank the current phonenum too
       for ( var i = what.form.<% $opt{'prefix'} %>phonenum.length; i >= 0; i-- )
           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
-      opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
+      if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ) {
+        opt(what.form.<% $opt{'prefix'} %>phonenum, '', 'Select phone number');
+      }
 
 %     if ($opt{empty}) {
         opt(what.form.<% $opt{'prefix'} %>exchange, '', '<% $opt{empty} %>');
index 25a885a..d555bf4 100644 (file)
@@ -30,7 +30,9 @@
           what.form.<% $opt{'prefix'} %>phonenum.options[i] = null;
 
 %     if ($opt{empty}) {
-        opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
+        if ( what.form.<% $opt{'prefix'} %>phonenum.type != 'select-multiple' ){
+          opt(what.form.<% $opt{'prefix'} %>phonenum, '', '<% $opt{empty} %>');
+        }
 %     }
 
       // add the new phonenums
 <DIV ID="phonenumerror" STYLE="display:none"><IMG SRC="<%$fsurl%>images/cross.png"> <B>Select a different city/exchange</B></DIV>
 % }
 
-<SELECT ID="<% $opt{'prefix'} %>phonenum" NAME="<% $opt{'prefix'} %>phonenum" 
-    notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>"
-    <% $opt{'disabled'} %>>
-  <OPTION VALUE="">Select phone number</OPTION>
+<SELECT <% $opt{multiple} ? 'MULTIPLE SIZE=25' : '' %>
+        ID   = "<% $opt{'prefix'} %>phonenum"
+        NAME = "<% $opt{'prefix'} %>phonenum" 
+        <% $opt{'disabled'} %>
+%#        notonChange="<% $opt{'prefix'} %>phonenum_changed(this); <% $opt{'onchange'} %>"
+>
+% unless ( $opt{multiple} ) {
+    <OPTION VALUE="">Select phone number</OPTION>
+% }
 </SELECT>
 
 <%init>
index 2d60fde..785b2ec 100644 (file)
@@ -42,7 +42,9 @@ Example:
 <%init>
 
 my %opt = @_;
-foreach my $opt (qw( state country prefix onchange disabled empty_label )) {
+foreach my $opt (qw(
+  state country prefix onchange disabled empty_label svcpart
+)) {
   $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
 }
 
@@ -62,5 +64,16 @@ my $style =
 
 tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} ); 
 
+if ( $opt{'svcpart'} ) {
+
+  my $sth = dbh->prepare(
+    'SELECT DISTINCT state FROM phone_avail WHERE svcnum IS NULL'
+  ) or die dbh->errstr;
+  $sth->execute or die $sth->errstr;
+  my %avail_states = map { $_->[0] => 1 } @{ $sth->fetchall_arrayref };
+
+  delete $states{$_} foreach grep ! $avail_states{$_}, keys %states;
+}
+
 </%init>
 
index 69c9573..9d32a3b 100644 (file)
@@ -1,4 +1,3 @@
-%# [ <% join(', ', map { qq("$_") } @areacodes) %> ]
 <% objToJson(\@areacodes) %>
 <%init>
 
@@ -7,18 +6,21 @@ my( $state, $svcpart ) = $cgi->param('arg');
 my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } );
 die "unknown svcpart $svcpart" unless $part_svc;
 
-my @exports = $part_svc->part_export_did;
-if ( scalar(@exports) > 1 ) {
-  die "more than one DID-providing export attached to svcpart $svcpart";
-} elsif ( ! @exports ) {
-  die "no DID providing export attached to svcpart $svcpart";
-}
-my $export = $exports[0];
+my @areacodes = ();
+if ( $state ) {
+
+  my @exports = $part_svc->part_export_did;
+  if ( scalar(@exports) > 1 ) {
+    die "more than one DID-providing export attached to svcpart $svcpart";
+  } elsif ( ! @exports ) {
+    die "no DID providing export attached to svcpart $svcpart";
+  }
+  my $export = $exports[0];
 
-my $something = $export->get_dids('state'=>$state);
+  my $something = $export->get_dids('state'=>$state);
 
-#warn Dumper($something);
+  @areacodes = @{ $something };
 
-my @areacodes = @{ $something };
+}
 
 </%init>
index f5860cf..8a67f7b 100644 (file)
@@ -1,4 +1,3 @@
-%# [ <% join(', ', map { qq("$_") } @exchanges) %> ]
 <% objToJson(\@exchanges) %>
 <%init>
 
@@ -7,18 +6,21 @@ my( $areacode, $svcpart ) = $cgi->param('arg');
 my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } );
 die "unknown svcpart $svcpart" unless $part_svc;
 
-my @exports = $part_svc->part_export_did;
-if ( scalar(@exports) > 1 ) {
-  die "more than one DID-providing export attached to svcpart $svcpart";
-} elsif ( ! @exports ) {
-  die "no DID providing export attached to svcpart $svcpart";
-}
-my $export = $exports[0];
+my @exchanges = ();
+if ( $areacode ) {
+
+  my @exports = $part_svc->part_export_did;
+  if ( scalar(@exports) > 1 ) {
+    die "more than one DID-providing export attached to svcpart $svcpart";
+  } elsif ( ! @exports ) {
+    die "no DID providing export attached to svcpart $svcpart";
+  }
+  my $export = $exports[0];
 
-my $something = $export->get_dids('areacode'=>$areacode);
+  my $something = $export->get_dids('areacode'=>$areacode);
 
-#warn Dumper($something);
+  @exchanges = @{ $something };
 
-my @exchanges = @{ $something };
+}
 
 </%init>
index 108a5f7..784a190 100644 (file)
@@ -1,4 +1,4 @@
-<% objToJson(\@exchanges) %>
+<% objToJson(\@phonenums) %>
 <%init>
 
 my( $exchangestring, $svcpart ) = $cgi->param('arg');
@@ -6,31 +6,37 @@ my( $exchangestring, $svcpart ) = $cgi->param('arg');
 my $part_svc = qsearchs('part_svc', { 'svcpart'=>$svcpart } );
 die "unknown svcpart $svcpart" unless $part_svc;
 
-my @exports = $part_svc->part_export_did;
-if ( scalar(@exports) > 1 ) {
-  die "more than one DID-providing export attached to svcpart $svcpart";
-} elsif ( ! @exports ) {
-  die "no DID providing export attached to svcpart $svcpart";
-}
-my $export = $exports[0];
+my @phonenums = ();
+
+if ( $exchangestring ) {
+
+  my @exports = $part_svc->part_export_did;
+  if ( scalar(@exports) > 1 ) {
+    die "more than one DID-providing export attached to svcpart $svcpart";
+  } elsif ( ! @exports ) {
+    die "no DID providing export attached to svcpart $svcpart";
+  }
+  my $export = $exports[0];
     
-my %opts = ();
-if ( $exchangestring eq 'tollfree' ) {
-    $opts{'tollfree'} = 1;
-}
-elsif ( $exchangestring =~ /^([\w\s]+), ([A-Z][A-Z])$/ ) {
-    $opts{'ratecenter'} = $1;
-    $opts{'state'} = $2;
-}
-else {
-    $exchangestring =~ /\((\d{3})-(\d{3})-XXXX\)\s*$/i
-      or die "unparsable exchange: $exchangestring";
-    my( $areacode, $exchange ) = ( $1, $2 );
-    $opts{'areacode'} = $areacode;
-    $opts{'exchange'} = $exchange;
-}
+  my %opts = ();
+  if ( $exchangestring eq 'tollfree' ) {
+      $opts{'tollfree'} = 1;
+  }
+  elsif ( $exchangestring =~ /^([\w\s]+), ([A-Z][A-Z])$/ ) {
+      $opts{'ratecenter'} = $1;
+      $opts{'state'} = $2;
+  }
+  else {
+      $exchangestring =~ /\((\d{3})-(\d{3})-XXXX\)\s*$/i
+        or die "unparsable exchange: $exchangestring";
+      my( $areacode, $exchange ) = ( $1, $2 );
+      $opts{'areacode'} = $areacode;
+      $opts{'exchange'} = $exchange;
+  }
 
-my $something = $export->get_dids(%opts);
-my @exchanges = @{ $something };
+  my $something = $export->get_dids(%opts);
+  @phonenums = @{ $something };
+
+}
 
 </%init>
index 0c18f58..8f3a028 100644 (file)
@@ -73,7 +73,13 @@ function clearhint_search_cust_svc(obj, str) {
           <B><% svc_provision_link($cust_pkg, $part_svc, \%opt, $curuser) %></B>
 %        if ( $curuser->access_right('Bulk provision customer service') 
 %               && $part_svc->svcdb eq 'svc_phone' ) {
-            <BR><A HREF="<%$p%>browse/did_order.html?custnum=<%$cust_pkg->custnum%>"><% mt('Browse Received DID Inventory') |h %></A> 
+%          if ( $part_svc->num_avail > 5 ) {
+%             $opt{'bulk'} = 1;
+              <BR><% svc_provision_link($cust_pkg, $part_svc, \%opt, $curuser) %>
+%           }
+%           #XXX if there's orders for this customer {
+              <BR><A HREF="<%$p%>browse/did_order.html?custnum=<%$cust_pkg->custnum%>"><% mt('Browse Received DID Inventory') |h %></A> 
+%           #}
 %       }
         </TD>
       </TR>
@@ -98,33 +104,38 @@ my $conf = new FS::Conf;
 
 sub svc_provision_link {
   my ($cust_pkg, $part_svc, $opt, $curuser) = @_;
+
   ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
   my $num_avail = $part_svc->num_avail;
-  my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
-                       "svcpart=". $part_svc->svcpart;
+
+  my $query = "pkgnum=". $cust_pkg->pkgnum. ';'.
+              "svcpart=". $part_svc->svcpart;
+  $query .= ';bulk=1' if $opt->{bulk};
+
   my $url;
   if ( $part_svc->svcdb eq 'svc_external' #could be generalized
        && $opt->{'svc_external-skip_manual'}
   ) {
-    $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
+    $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$query";
   } else {
     $url = svc_url(
                     'm'        => $m,
                     'action'   => 'edit',
                     'part_svc' => $part_svc, 
-                    'query'    => $pkgnum_svcpart,
+                    'query'    => $query,
                   );
   }
 
+  my $action = $opt->{bulk} ? 'Bulk provision' : 'Provision';
+
   my $link = qq!<A CLASS="provision" HREF="$url">!.
-             emt("Provision [_1] ([_2])",$svc_nbsp,$num_avail).'</A>';
+             emt("$action [_1] ([_2])",$svc_nbsp,$num_avail).'</A>';
   if ( $opt->{'legacy_link'}
        && $curuser->access_right('View/link unlinked services')
      )
   {
     $link .= '<BR>'.
-             qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
-             qq!$pkgnum_svcpart">!.
+             qq!<A CLASS="provision" HREF="${p}misc/link.cgi?$query">!.
             emt("Link to legacy [_1] ([_2])",$svc_nbsp,$num_avail).'</A>';
   }
   $link;