summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/Conf.pm7
-rw-r--r--FS/FS/Record.pm2
-rw-r--r--FS/FS/cust_main.pm87
3 files changed, 74 insertions, 22 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 3c4c6eebe..728a2136b 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -2350,6 +2350,13 @@ worry that config_items is freeside-specific and icky.
'type' => 'checkbox',
},
+ {
+ 'key' => 'cust_main-default_areacode',
+ 'section' => 'UI',
+ 'description' => 'Default area code for customers.',
+ 'type' => 'text',
+ },
+
);
1;
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 8bd57ebff..2540dd399 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -1614,6 +1614,8 @@ sub ut_phonen {
$self->setfield($field,'');
} elsif ( $country eq 'US' || $country eq 'CA' ) {
$phonen =~ s/\D//g;
+ $phonen = $conf->config('cust_main-default_areacode').$phonen
+ if length($phonen)==7 && $conf->config('cust_main-default_areacode');
$phonen =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
or return gettext('illegal_phone'). " $field: ". $self->getfield($field);
$phonen = "$1-$2-$3";
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 51270d6dd..e698bfa68 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -16,6 +16,8 @@ use Digest::MD5 qw(md5_base64);
use Date::Format;
use Date::Parse;
#use Date::Manip;
+use File::Slurp qw( slurp );
+use File::Temp qw( tempfile );
use String::Approx qw(amatch);
use Business::CreditCard 0.28;
use Locale::Country;
@@ -6208,17 +6210,19 @@ sub append_fuzzyfiles {
=cut
+#some false laziness w/cdr.pm now
sub batch_import {
my $param = shift;
- #warn join('-',keys %$param);
- my $fh = $param->{filehandle};
+
+ my $fh = $param->{filehandle};
+ my $type = $param->{type} || 'csv';
+
my $agentnum = $param->{agentnum};
+ my $refnum = $param->{refnum};
+ my $pkgpart = $param->{pkgpart};
- my $refnum = $param->{refnum};
- my $pkgpart = $param->{pkgpart};
+ my $format = $param->{'format'};
- #my @fields = @{$param->{fields}};
- my $format = $param->{'format'};
my @fields;
my $payby;
if ( $format eq 'simple' ) {
@@ -6253,14 +6257,32 @@ sub batch_import {
die "unknown format $format";
}
- eval "use Text::CSV_XS;";
- die $@ if $@;
+ my $parser;
+ my $spoolfile = '';
+ if ( $type eq 'csv' ) {
+ eval "use Text::CSV_XS;";
+ die $@ if $@;
+ $parser = new Text::CSV_XS;
+ } elsif ( $type eq 'xls' ) {
- my $csv = new Text::CSV_XS;
- #warn $csv;
- #warn $fh;
+ eval "use Spreadsheet::ParseExcel;";
+ die $@ if $@;
+
+ ( my $spool_fh, $spoolfile ) =
+ tempfile('cust_main-batch_import-XXXXXXXXXXXX',
+ DIR => '%%%FREESIDE_CACHE%%%',
+ SUFFIX => '.xls',
+ );
+ print $spool_fh slurp($fh);
+ close $spool_fh or die $!;
+
+ my $excel = new Spreadsheet::ParseExcel::Workbook->Parse($spoolfile);
+ $parser = $excel->{Worksheet}[0]; #first sheet
+
+ } else {
+ die "Unknown file type $type\n";
+ }
- my $imported = 0;
#my $columns;
local $SIG{HUP} = 'IGNORE';
@@ -6274,16 +6296,35 @@ sub batch_import {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- #while ( $columns = $csv->getline($fh) ) {
my $line;
- while ( defined($line=<$fh>) ) {
+ my $row = 0;
+ while (1) {
- $csv->parse($line) or do {
- $dbh->rollback if $oldAutoCommit;
- return "can't parse: ". $csv->error_input();
- };
+ my @columns = ();
+ if ( $type eq 'csv' ) {
+
+ last unless defined($line=<$fh>);
+
+ $parser->parse($line) or do {
+ $dbh->rollback if $oldAutoCommit;
+ return "can't parse: ". $parser->error_input();
+ };
+ @columns = $parser->fields();
+
+ } elsif ( $type eq 'xls' ) {
+
+ last if $row > ($parser->{MaxRow} || $parser->{MinRow});
+
+ my @row = @{ $parser->{Cells}[$row] };
+ @columns = map $_->{Val}, @row;
+
+ #my $z = 'A';
+ #warn $z++. ": $_\n" for @columns;
+
+ } else {
+ die "Unknown file type $type\n";
+ }
- my @columns = $csv->fields();
#warn join('-',@columns);
my %cust_main = (
@@ -6375,7 +6416,7 @@ sub batch_import {
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
- return "can't insert customer for $line: $error";
+ return "can't insert customer ". ( $line ? "for $line" : '' ). ": $error";
}
if ( $format eq 'simple' ) {
@@ -6401,12 +6442,14 @@ sub batch_import {
}
- $imported++;
+ $row++;
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
- return "Empty file!" unless $imported;
+ unlink($spoolfile) if $spoolfile;
+
+ return "Empty file!" unless $row;
''; #no error