From ec5603ae351d4ed8e4873dcd20bf71f8a4d549bb Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 14 Aug 2008 01:58:31 +0000 Subject: import customer from Excel file too --- httemplate/misc/cust_main-import.cgi | 15 ++++++++------ httemplate/misc/process/cust_main-import.cgi | 30 ++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 14 deletions(-) (limited to 'httemplate/misc') diff --git a/httemplate/misc/cust_main-import.cgi b/httemplate/misc/cust_main-import.cgi index 84da38611..8e170c3c6 100644 --- a/httemplate/misc/cust_main-import.cgi +++ b/httemplate/misc/cust_main-import.cgi @@ -1,6 +1,6 @@ <% include("/elements/header.html",'Batch Customer Import') %> -Import a CSV file containing customer records. +Import a file containing customer records.

@@ -26,8 +26,8 @@ Import a CSV file containing customer records. - CSV filename - + Filename + % #include('/elements/tr-select-part_referral.html') % @@ -49,7 +49,7 @@ Import a CSV file containing customer records. --> - + @@ -60,10 +60,13 @@ Import a CSV file containing customer records. -Extended file format is CSV, with the following field order: agent_custid, refnum<%$req%>, last<%$req%>, first<%$req%>, address1<%$req%>, address2, city<%$req%>, state<%$req%>, zip<%$req%>, country, daytime, night, ship_last, ship_first, ship_address1, ship_address2, ship_city, ship_state, ship_zip, ship_country, payinfo<%$req%>, paycvv, paydate<%$req%>, invoicing_list, pkgpart, username, _password +Uploaded files can be CSV (comma-separated value) files or Excel spreadsheets. The file should have a .CSV or .XLS extension.

-Extended plus company file format is CSV, with the following field order: agent_custid, refnum<%$req%>, last<%$req%>, first<%$req%>, company, address1<%$req%>, address2, city<%$req%>, state<%$req%>, zip<%$req%>, country, daytime, night, ship_last, ship_first, ship_company, ship_address1, ship_address2, ship_city, ship_state, ship_zip, ship_country, payinfo<%$req%>, paycvv, paydate<%$req%>, invoicing_list, pkgpart, username, _password +Extended format has the following field order: agent_custid, refnum<%$req%>, last<%$req%>, first<%$req%>, address1<%$req%>, address2, city<%$req%>, state<%$req%>, zip<%$req%>, country, daytime, night, ship_last, ship_first, ship_address1, ship_address2, ship_city, ship_state, ship_zip, ship_country, payinfo, paycvv, paydate, invoicing_list, pkgpart, username, _password +

+ +Extended plus company format has the following field order: agent_custid, refnum<%$req%>, last<%$req%>, first<%$req%>, company, address1<%$req%>, address2, city<%$req%>, state<%$req%>, zip<%$req%>, country, daytime, night, ship_last, ship_first, ship_company, ship_address1, ship_address2, ship_city, ship_state, ship_zip, ship_country, payinfo, paycvv, paydate, invoicing_list, pkgpart, username, _password

<%$req%> Required fields diff --git a/httemplate/misc/process/cust_main-import.cgi b/httemplate/misc/process/cust_main-import.cgi index aa8cd5298..2568d1c7b 100644 --- a/httemplate/misc/process/cust_main-import.cgi +++ b/httemplate/misc/process/cust_main-import.cgi @@ -9,20 +9,34 @@ die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); -my $fh = $cgi->upload('csvfile'); -#warn $cgi; -#warn $fh; +my $fh = $cgi->upload('file'); +my $error = ''; +if ( defined($fh) ) { -my $error = defined($fh) - ? FS::cust_main::batch_import( { + my $type; + if ( $cgi->param('file') =~ /\.(\w+)$/i ) { + $type = lc($1); + } else { + #or error out??? + warn "can't parse file type from filename ". $cgi->param('file'). + '; defaulting to CSV'; + $type = 'csv'; + } + + $error = + FS::cust_main::batch_import( { filehandle => $fh, + type => $type, agentnum => scalar($cgi->param('agentnum')), refnum => scalar($cgi->param('refnum')), pkgpart => scalar($cgi->param('pkgpart')), #'fields' => [qw( cust_pkg.setup dayphone first last address1 address2 - # city state zip comments )], + # city state zip comments )], 'format' => scalar($cgi->param('format')), - } ) - : 'No file'; + } ); + +} else { + $error = 'No file'; +} -- cgit v1.2.1