From: Ivan Kohler Date: Mon, 23 Nov 2015 03:44:51 +0000 (-0800) Subject: package import w/bulk phone number ranges, RT#39127 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=155cb2a71481bdcaad6fd66bbe9d804c64d7c29d package import w/bulk phone number ranges, RT#39127 --- diff --git a/FS/FS/cust_pkg/Import.pm b/FS/FS/cust_pkg/Import.pm index e8c4427d6..63a9909e5 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 = (); diff --git a/httemplate/misc/cust_pkg-import.html b/httemplate/misc/cust_pkg-import.html index 8784dbbe1..9769941a1 100644 --- a/httemplate/misc/cust_pkg-import.html +++ b/httemplate/misc/cust_pkg-import.html @@ -39,6 +39,9 @@ Import a file containing customer packages.