diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-11-22 19:44:53 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-11-22 19:44:53 -0800 |
commit | 7b8adf960efd4b48d61f49b3331c11b4d3e8c2d9 (patch) | |
tree | 6da28fe7dfb1dcc6bbdcfac9a3884af1da51d179 /FS/FS/cust_pkg | |
parent | 812bc7c3fab50cefca3cae5b9430350c5a65a077 (diff) |
package import w/bulk phone number ranges, RT#39127
Diffstat (limited to 'FS/FS/cust_pkg')
-rw-r--r-- | FS/FS/cust_pkg/Import.pm | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/FS/FS/cust_pkg/Import.pm b/FS/FS/cust_pkg/Import.pm index e8c4427..63a9909 100644 --- a/FS/FS/cust_pkg/Import.pm +++ b/FS/FS/cust_pkg/Import.pm @@ -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 = (); |