summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2006-08-15 14:20:51 +0000
committerivan <ivan>2006-08-15 14:20:51 +0000
commit04cbf1d986eabf7fdcc22ff95b95da17e5f4bf63 (patch)
treedaa121c0a546743af77aea831943e2f7d9377d75 /FS
parent16a001f9e22bdb68e85d6c23697bfb5f7b8fa8f4 (diff)
add a new, extended CSV import format
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_main.pm112
1 files changed, 92 insertions, 20 deletions
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 95097da71..c40d54aac 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -4230,9 +4230,33 @@ sub batch_import {
#warn join('-',keys %$param);
my $fh = $param->{filehandle};
my $agentnum = $param->{agentnum};
+
my $refnum = $param->{refnum};
my $pkgpart = $param->{pkgpart};
- my @fields = @{$param->{fields}};
+
+ #my @fields = @{$param->{fields}};
+ my $format = $param->{'format'};
+ my @fields;
+ my $payby;
+ if ( $format eq 'simple' ) {
+ @fields = qw( cust_pkg.setup dayphone first last
+ address1 address2 city state zip comments );
+ $payby = 'BILL';
+ } elsif ( $format eq 'extended' ) {
+ @fields = qw( agent_custid refnum
+ last first address1 address2 city state zip country
+ daytime night
+ ship_last ship_first ship_address1 ship_address2
+ ship_city ship_state ship_zip ship_country
+ payinfo paycvv paydate
+ invoicing_list
+ cust_pkg.pkgpart
+ svc_acct.username svc_acct._password
+ );
+ $payby = 'CARD';
+ } else {
+ die "unknown format $format";
+ }
eval "use Text::CSV_XS;";
die $@ if $@;
@@ -4271,51 +4295,99 @@ sub batch_import {
agentnum => $agentnum,
refnum => $refnum,
country => $conf->config('countrydefault') || 'US',
- payby => 'BILL', #default
+ payby => $payby, #default
paydate => '12/2037', #default
);
my $billtime = time;
my %cust_pkg = ( pkgpart => $pkgpart );
+ my %svc_acct = ();
foreach my $field ( @fields ) {
- if ( $field =~ /^cust_pkg\.(setup|bill|susp|expire|cancel)$/ ) {
+
+ if ( $field =~ /^cust_pkg\.(pkgpart|setup|bill|susp|expire|cancel)$/ ) {
+
#$cust_pkg{$1} = str2time( shift @$columns );
- if ( $1 eq 'setup' ) {
+ if ( $1 eq 'pkgpart' ) {
+ $cust_pkg{$1} = shift @columns;
+ } elsif ( $1 eq 'setup' ) {
$billtime = str2time(shift @columns);
} else {
$cust_pkg{$1} = str2time( shift @columns );
- }
+ }
+
+ } elsif ( $field =~ /^svc_acct\.(username|_password)$/ ) {
+
+ $svc_acct{$1} = shift @columns;
+
} else {
+
+ #refnum interception
+ if ( $field eq 'refnum' && $columns[0] !~ /^\s*(\d+)\s*$/ ) {
+
+ my $referral = $columns[0];
+ my $part_referral = new FS::part_referral {
+ 'referral' => $referral,
+ 'agentnum' => $agentnum,
+ };
+
+ my $error = $part_referral->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't auto-insert advertising source: $referral: $error";
+ }
+ $columns[0] = $part_referral->refnum;
+ }
+
#$cust_main{$field} = shift @$columns;
$cust_main{$field} = shift @columns;
}
}
- my $cust_pkg = new FS::cust_pkg ( \%cust_pkg ) if $pkgpart;
+ my $invoicing_list = $cust_main{'invoicing_list'}
+ ? [ delete $cust_main{'invoicing_list'} ]
+ : [];
+
my $cust_main = new FS::cust_main ( \%cust_main );
+
use Tie::RefHash;
tie my %hash, 'Tie::RefHash'; #this part is important
- $hash{$cust_pkg} = [] if $pkgpart;
- my $error = $cust_main->insert( \%hash );
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "can't insert customer for $line: $error";
+ if ( $cust_pkg{'pkgpart'} ) {
+ my $cust_pkg = new FS::cust_pkg ( \%cust_pkg );
+
+ my @svc_acct = ();
+ if ( $svc_acct{'username'} ) {
+ $svc_acct{svcpart} = $cust_pkg->part_pkg->svcpart( 'svc_acct' );
+ push @svc_acct, new FS::svc_acct ( \%svc_acct )
+ }
+
+ $hash{$cust_pkg} = \@svc_acct;
}
- #false laziness w/bill.cgi
- $error = $cust_main->bill( 'time' => $billtime );
+ my $error = $cust_main->insert( \%hash, $invoicing_list );
+
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
- return "can't bill customer for $line: $error";
+ return "can't insert customer for $line: $error";
}
- $cust_main->apply_payments;
- $cust_main->apply_credits;
+ if ( $format eq 'simple' ) {
+
+ #false laziness w/bill.cgi
+ $error = $cust_main->bill( 'time' => $billtime );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't bill customer for $line: $error";
+ }
+
+ $cust_main->apply_payments;
+ $cust_main->apply_credits;
+
+ $error = $cust_main->collect();
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't collect customer for $line: $error";
+ }
- $error = $cust_main->collect();
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return "can't collect customer for $line: $error";
}
$imported++;