summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2008-08-14 01:58:43 +0000
committerivan <ivan>2008-08-14 01:58:43 +0000
commit10fdf2307587c3e6a7061598db83528d9060e772 (patch)
treece1fb79e88b2006b67171e0557b880f3ff8378cf /httemplate
parentbb8b959377cb2a39506a074e58f8f222ce42d3dc (diff)
import customer from Excel file too
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/elements/menu.html2
-rw-r--r--httemplate/misc/cust_main-import.cgi15
-rw-r--r--httemplate/misc/process/cust_main-import.cgi30
3 files changed, 32 insertions, 15 deletions
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index 08a7962..2444fc0 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -208,7 +208,7 @@ $report_menu{'SQL Query'} = [ $fsurl.'search/report_sql.html', 'SQL Query' ]
if $curuser->access_right('Raw SQL');
tie my %tools_importing, 'Tie::IxHash',
- 'Import customers from CSV file' => [ $fsurl.'misc/cust_main-import.cgi', '' ],
+ 'Import customers' => [ $fsurl.'misc/cust_main-import.cgi', '' ],
'Import payments from CSV file' => [ $fsurl.'misc/cust_pay-import.cgi', '' ],
'Import customer notes from CSV file' => [ $fsurl.'misc/cust_main_note-import.html', '' ],
'Import one-time charges from CSV file' => [ $fsurl.'misc/cust_main-import_charges.cgi', '' ],
diff --git a/httemplate/misc/cust_main-import.cgi b/httemplate/misc/cust_main-import.cgi
index a491639..e1580e5 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.
<BR><BR>
<FORM ACTION="process/cust_main-import.cgi" METHOD="post" ENCTYPE="multipart/form-data">
@@ -25,8 +25,8 @@ Import a CSV file containing customer records.
</TR>
<TR>
- <TH ALIGN="right">CSV filename</TH>
- <TD><INPUT TYPE="file" NAME="csvfile"></TD>
+ <TH ALIGN="right">Filename</TH>
+ <TD><INPUT TYPE="file" NAME="file"></TD>
</TR>
% #include('/elements/tr-select-part_referral.html')
%
@@ -48,7 +48,7 @@ Import a CSV file containing customer records.
</TR>
-->
-<TR><TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px"><INPUT TYPE="submit" VALUE="Import CSV file"></TD></TR>
+<TR><TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px"><INPUT TYPE="submit" VALUE="Import file"></TD></TR>
</TABLE>
@@ -59,10 +59,13 @@ Import a CSV file containing customer records.
<!-- Simple file format is CSV, with the following field order: <i>cust_pkg.setup, dayphone, first, last, address1, address2, city, state, zip, comments</i>
<BR><BR> -->
-<b>Extended</b> file format is CSV, with the following field order: <i>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</i>
+Uploaded files can be CSV (comma-separated value) files or Excel spreadsheets. The file should have a .CSV or .XLS extension.
<BR><BR>
-<b>Extended plus company</b> file format is CSV, with the following field order: <i>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</i>
+<b>Extended</b> format has the following field order: <i>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</i>
+<BR><BR>
+
+<b>Extended plus company</b> format has the following field order: <i>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</i>
<BR><BR>
<%$req%> Required fields
diff --git a/httemplate/misc/process/cust_main-import.cgi b/httemplate/misc/process/cust_main-import.cgi
index aa8cd52..2568d1c 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';
+}
</%init>