[freeside-commits] freeside/FS/FS Conf.pm, 1.180.2.30, 1.180.2.31 Record.pm, 1.135.2.11, 1.135.2.12 cust_main.pm, 1.271.2.51, 1.271.2.52
Ivan,,,
ivan at wavetail.420.am
Wed Aug 13 18:58:45 PDT 2008
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv960/FS/FS
Modified Files:
Tag: FREESIDE_1_7_BRANCH
Conf.pm Record.pm cust_main.pm
Log Message:
import customer from Excel file too
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.180.2.30
retrieving revision 1.180.2.31
diff -u -d -r1.180.2.30 -r1.180.2.31
--- Conf.pm 24 Jun 2008 16:39:10 -0000 1.180.2.30
+++ Conf.pm 14 Aug 2008 01:58:42 -0000 1.180.2.31
@@ -2322,6 +2322,13 @@
'type' => 'checkbox',
},
+ {
+ 'key' => 'cust_main-default_areacode',
+ 'section' => 'UI',
+ 'description' => 'Default area code for customers.',
+ 'type' => 'text',
+ },
+
);
1;
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.271.2.51
retrieving revision 1.271.2.52
diff -u -d -r1.271.2.51 -r1.271.2.52
--- cust_main.pm 15 Jul 2008 20:56:11 -0000 1.271.2.51
+++ cust_main.pm 14 Aug 2008 01:58:42 -0000 1.271.2.52
@@ -18,6 +18,8 @@
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;
@@ -5472,17 +5474,19 @@
=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' ) {
@@ -5517,14 +5521,32 @@
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';
@@ -5538,16 +5560,35 @@
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('-', at columns);
my %cust_main = (
@@ -5639,7 +5680,7 @@
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' ) {
@@ -5665,12 +5706,14 @@
}
- $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
Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.135.2.11
retrieving revision 1.135.2.12
diff -u -d -r1.135.2.11 -r1.135.2.12
--- Record.pm 3 Jul 2008 04:19:35 -0000 1.135.2.11
+++ Record.pm 14 Aug 2008 01:58:42 -0000 1.135.2.12
@@ -1538,6 +1538,8 @@
$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";
More information about the freeside-commits
mailing list