package import w/bulk phone number ranges, RT#39127
authorIvan Kohler <ivan@freeside.biz>
Mon, 23 Nov 2015 03:44:51 +0000 (19:44 -0800)
committerIvan Kohler <ivan@freeside.biz>
Mon, 23 Nov 2015 03:44:51 +0000 (19:44 -0800)
FS/FS/cust_pkg/Import.pm
httemplate/misc/cust_pkg-import.html

index e8c4427..63a9909 100644 (file)
@@ -211,6 +211,52 @@ sub batch_import {
     push @fields, 'locationnum';
   }
 
+  if ( $format =~ /^bulk_(.*)$/ ) {
+
+    $format = $1;
+
+    $opt->{'postinsert_callback'} = sub {
+      my( $record, $param ) = @_;
+
+      my $formatfields = _formatfields;
+      foreach my $svc_x ( grep /^svc/, keys %$formatfields ) {
+
+        my $ff = $formatfields->{$svc_x};
+
+        if ( grep $param->{"$svc_x.$_"}, @$ff ) {
+
+          $param->{'svc_phone.phonenum'} =~ /^\s*(\d+)\s*\-\s*(\d+)\s*$/
+            or return 'Enter a phone number range, with dash as the separator';
+          my($start, $end) = ($1, $2);
+          if ( length($end) < length($start) ) {
+            $end = substr($start, 0, length($start) - length($end) ). $end;
+          }
+
+          foreach my $phonenum ( "$start" .. "$end" ) {
+
+            my $svc = "FS::$svc_x"->new( {
+              'pkgnum'  => $record->pkgnum,
+              'svcpart' => $record->part_pkg->svcpart($svc_x),
+              map { $_ => $param->{"$svc_x.$_"} } @$ff
+            } );
+
+            $svc->phonenum($phonenum);
+            #$svc->set_default_and_fixed;
+            my $error = $svc->insert;
+            return "error inserting service: $error" if $error;
+
+          }
+
+        }
+
+      }
+
+      return ''; #no error
+
+    };
+
+  }
+
   push @fields, ( 'pkgpart', 'discountnum' );
 
   my @date_fields = ();
index 8784dbb..9769941 100644 (file)
@@ -39,6 +39,9 @@ Import a file containing customer packages.
         <OPTION VALUE="svc_phone">Phone service
         <OPTION VALUE="svc_phone-agent_custid">Phone service with agent_custid
         <OPTION VALUE="svc_phone-locationnum">Phone service with existing location
+        <OPTION VALUE="bulk_svc_phone">Bulk phone service
+        <OPTION VALUE="bulk_svc_phone-agent_custid">Bulk phone service with agent_custid
+        <OPTION VALUE="bulk_svc_phone-locationnum">Bulk phone service with existing location
         <OPTION VALUE="svc_external">External service
         <OPTION VALUE="svc_external-agent_custid">External service with agent_custid
         <OPTION VALUE="svc_external-locationnum">External service with existing location
@@ -108,6 +111,15 @@ Uploaded files can be CSV (comma-separated value) files or Excel spreadsheets.
 <b>Phone sevice with existing location</b> format has the following field order: <i>custnum<%$req%>, locationnum, pkgpart<%$req%>, discountnum, start_date, setup, bill, last_bill, susp, adjourn, cancel, expire, countrycode, phonenum, sip_password, pin</i>
 <BR><BR>
 
+<b>Bulk phone sevice</b> format has the following field order: <i>custnum<%$req%>, pkgpart<%$req%>, discountnum, start_date, setup, bill, last_bill, susp, adjourn, cancel, expire, countrycode, start_phonenum-end_phonenum, sip_password, pin</i>
+<BR><BR>
+
+<b>Bulk phone service with agent_custid</b> format has the following field order: <i>agent_custid<%$req%>, pkgpart<%$req%>, discountnum, start_date, setup, bill, last_bill, susp, adjourn, cancel, expire, countrycode, start_phonenum-end_phonenum, sip_password, pin</i>
+<BR><BR>
+
+<b>Bulk phone sevice with existing location</b> format has the following field order: <i>custnum<%$req%>, locationnum, pkgpart<%$req%>, discountnum, start_date, setup, bill, last_bill, susp, adjourn, cancel, expire, countrycode, start_phonenum-end_phonenum, sip_password, pin</i>
+<BR><BR>
+
 <b>External sevice</b> format has the following field order: <i>custnum<%$req%>, pkgpart<%$req%>, discountnum, start_date, setup, bill, last_bill, susp, adjourn, cancel, expire, id, title</i>
 <BR><BR>