simple bulk provisioning of phone number ranges, RT#29800
authorIvan Kohler <ivan@freeside.biz>
Sat, 13 Dec 2014 04:56:22 +0000 (20:56 -0800)
committerIvan Kohler <ivan@freeside.biz>
Sat, 13 Dec 2014 04:56:22 +0000 (20:56 -0800)
FS/FS/Conf.pm
httemplate/edit/bulk-svc_phone.html [new file with mode: 0644]
httemplate/edit/process/bulk-svc_phone.html [new file with mode: 0644]
httemplate/view/cust_main/packages/section.html
httemplate/view/cust_main/packages/services.html

index 97659bc..c88d3e7 100644 (file)
@@ -4950,8 +4950,15 @@ and customer address. Include units.',
   },
 
   {
+    'key'         => 'svc_phone-bulk_provision_simple',
+    'section'     => 'telephony',
+    'description' => 'Bulk provision phone numbers with a simple number range instead of from DID vendor orders',
+    'type'        => 'checkbox',
+  },
+
+  {
     'key'         => 'default_phone_countrycode',
-    'section'     => '',
+    'section'     => 'telephony',
     'description' => 'Default countrycode',
     'type'        => 'text',
   },
diff --git a/httemplate/edit/bulk-svc_phone.html b/httemplate/edit/bulk-svc_phone.html
new file mode 100644 (file)
index 0000000..fb71836
--- /dev/null
@@ -0,0 +1,52 @@
+<& /elements/header.html, mt('Bulk add [_1]',$svc) &>
+
+<& /elements/error.html &>
+
+% if ( $cust_main ) { 
+
+  <& /elements/small_custview.html, $cust_main, '', 1,
+              popurl(2) . "view/cust_main.cgi" &>
+  <BR>
+% } 
+
+<FORM NAME="OneTrueForm" ACTION="<% popurl(1) %>process/bulk-svc_phone.html" METHOD=POST>
+<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
+<INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
+<INPUT TYPE="hidden" NAME="num_avail" VALUE="<% scalar($cgi->param('num_avail')) |h %>">
+
+<% ntable("#cccccc",2) %>
+
+<TR>
+  <TD ALIGN="right"><% mt('Phone number range') |h %></TD>
+  <TD><INPUT TYPE="text" NAME="phonenum" VALUE=""></TD>
+</TR>
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="Submit">
+
+</FORM>
+
+<& /elements/footer.html &>
+
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Bulk provision customer service');
+
+$cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum';
+my $pkgnum = $1;
+my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $pkgnum })
+  or die 'unknown pkgnum';
+my $cust_main = $cust_pkg->cust_main;
+
+$cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart';
+my $svcpart = $1;
+
+my $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
+die "No part_svc entry!" unless $part_svc;
+
+my $svc = $part_svc->getfield('svc');
+
+</%init>
diff --git a/httemplate/edit/process/bulk-svc_phone.html b/httemplate/edit/process/bulk-svc_phone.html
new file mode 100644 (file)
index 0000000..5a1fbc6
--- /dev/null
@@ -0,0 +1,41 @@
+<% $cgi->redirect(popurl(3). "view/cust_main.cgi?custnum=$custnum;show=packages#cust_pkg$pkgnum") %>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Bulk provision customer service');
+
+$cgi->param('phonenum') =~ /^\s*(\d+)\s*\-\s*(\d+)\s*$/
+  or errorpage('Enter a phone number range, with dash as the separator');
+my($start, $end) = ($1, $2);
+
+$cgi->param('pkgnum') =~ /^(\d+)$/ or die 'illegal pkgnum';
+my $pkgnum = $1;
+my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $pkgnum })
+  or die 'unknown pkgnum';
+my $custnum = $cust_pkg->custnum;
+
+if ( length($end) < length($start) ) {
+  $end = substr($start, 0, length($start) - length($end) ). $end;
+}
+
+errorpage("$end is smaller than $start") if $end < $start;
+
+$cgi->param('num_avail') =~ /^(\d+)$/ or die 'illegal num_avail';
+my $num_avail = $1;
+errorpage("There are only $num_avail available")
+  if $end - $start + 1 > $num_avail;
+
+foreach my $phonenum ( $start .. $end ) {
+
+  my $svc_phone = new FS::svc_phone {
+    'phonenum' => $phonenum,
+    'pkgnum'   => $pkgnum,
+    'svcpart'  => scalar($cgi->param('svcpart')),
+  };
+  $svc_phone->set_default_and_fixed;
+
+  my $error = $svc_phone->insert;
+  errorpage($error) if $error;
+}
+
+</%init>
index 217e8c5..e888c94 100755 (executable)
@@ -128,6 +128,7 @@ my %conf_opt = (
   
   #for services.html
   'svc_external-skip_manual'  => $conf->exists('svc_external-skip_manual'),
+  'svc_phone-bulk_provision_simple' => $conf->exists('svc_phone-bulk_provision_simple'),
   'legacy_link'               => $conf->exists('legacy_link'),
   'manage_link'               => scalar($conf->config('svc_broadband-manage_link')),
   'manage_link_text'          => scalar($conf->config('svc_broadband-manage_link_text')),
index bb676e8..5fe41a3 100644 (file)
@@ -93,6 +93,8 @@ function clearhint_search_cust_svc(obj, str) {
 %        {
 %          if ( $part_svc->num_avail > 5 ) {
 %             local $opt{'bulk'} = 1;
+%             local $opt{'svc_phone_bulk_provision_simple'} =  $svc_phone_bulk_provision_simple;
+%             local $opt{'num_avail'} = $part_svc->num_avail;
               <BR><% svc_provision_link($cust_pkg, $part_svc, \%opt, $curuser) %>
 %           }
 %           #XXX if there's orders for this customer {
@@ -116,6 +118,8 @@ my %opt = @_;
 my $bgcolor  = $opt{'bgcolor'};
 my $cust_pkg = $opt{'cust_pkg'};
 my $part_pkg = $opt{'part_pkg'};
+my $svc_phone_bulk_provision_simple = $opt{'svc_phone-bulk_provision_simple'};
+
 my $curuser  = $FS::CurrentUser::CurrentUser;
 
 sub svc_provision_link {
@@ -133,6 +137,12 @@ sub svc_provision_link {
        && $opt->{'svc_external-skip_manual'}
   ) {
     $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$query";
+  } elsif ( $part_svc->svcdb eq 'svc_phone' && $opt->{bulk}
+              && $opt->{svc_phone_bulk_provision_simple}
+          )
+  {
+    $query .= ';num_avail='. $opt->{num_avail};
+    $url = "${p}edit/bulk-svc_phone.html?$query";
   } else {
     $url = svc_url(
                     'm'        => $m,
@@ -146,14 +156,17 @@ sub svc_provision_link {
 
   my $link = qq!<A CLASS="provision" HREF="$url">!.
              emt("$action [_1] ([_2])",$svc_nbsp,$num_avail).'</A>';
+
   if ( $opt->{'legacy_link'}
        && $curuser->access_right('View/link unlinked services')
+       && ! $opt{bulk}
      )
   {
     $link .= '<BR>'.
              qq!<A CLASS="provision" HREF="${p}misc/link.cgi?$query">!.
             emt("Link to legacy [_1] ([_2])",$svc_nbsp,$num_avail).'</A>';
   }
+
   $link;
 }