diff options
Diffstat (limited to 'httemplate/misc')
-rw-r--r-- | httemplate/misc/cust_main-import.cgi | 51 | ||||
-rw-r--r-- | httemplate/misc/process/cust_main-import.cgi | 30 |
2 files changed, 81 insertions, 0 deletions
diff --git a/httemplate/misc/cust_main-import.cgi b/httemplate/misc/cust_main-import.cgi new file mode 100644 index 000000000..6b36f478d --- /dev/null +++ b/httemplate/misc/cust_main-import.cgi @@ -0,0 +1,51 @@ +<!-- mason kludge --> +<%= header('Batch Customer Import') %> +<FORM ACTION="process/cust_main-import.cgi" METHOD="post" ENCTYPE="multipart/form-data"> +Import a CSV file containing customer records.<BR><BR> +Default 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> + +<% + #false laziness with edit/cust_main.cgi + my @agents = qsearch( 'agent', {} ); + die "No agents created!" unless @agents; + my $agentnum = $agents[0]->agentnum; #default to first + + if ( scalar(@agents) == 1 ) { +%> + <INPUT TYPE="hidden" NAME="agentnum" VALUE="<%= $agentnum %>"> +<% } else { %> + <BR><BR>Agent <SELECT NAME="agentnum" SIZE="1"> + <% foreach my $agent (sort { $a->agent cmp $b->agent } @agents) { %> + <OPTION VALUE="<%= $agent->agentnum %>" <%= " SELECTED"x($agent->agentnum==$agentnum) %>><%= $agent->agent %></OPTION> + <% } %> + </SELECT><BR><BR> +<% } %> + +<% + my @referrals = qsearch('part_referral',{}); + die "No advertising sources created!" unless @referrals; + my $refnum = $referrals[0]->refnum; #default to first + + if ( scalar(@referrals) == 1 ) { +%> + <INPUT TYPE="hidden" NAME="refnum" VALUE="<%= $refnum %>"> +<% } else { %> + <BR><BR>Advertising source <SELECT NAME="refnum" SIZE="1"> + <% foreach my $referral ( sort { $a->referral <=> $b->referral } @referrals) { %> + <OPTION VALUE="<%= $referral->refnum %>" <%= " SELECTED"x($referral->refnum==$refnum) %>><%= $referral->refnum %>: <%= $referral->referral %></OPTION> + <% } %> + </SELECT><BR><BR> +<% } %> + + First package: <SELECT NAME="pkgpart"><OPTION VALUE="">(none)</OPTION> +<% foreach my $part_pkg ( qsearch('part_pkg',{'disabled'=>'' }) ) { %> + <OPTION VALUE="<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkg. ' - '. $part_pkg->comment %></OPTION> +<% } %> +</SELECT><BR><BR> + + CSV Filename: <INPUT TYPE="file" NAME="csvfile"><BR><BR> + <INPUT TYPE="submit" VALUE="Import"> + </FORM> + </BODY> +<HTML> + diff --git a/httemplate/misc/process/cust_main-import.cgi b/httemplate/misc/process/cust_main-import.cgi new file mode 100644 index 000000000..9e1adce54 --- /dev/null +++ b/httemplate/misc/process/cust_main-import.cgi @@ -0,0 +1,30 @@ +<% + + my $fh = $cgi->upload('csvfile'); + #warn $cgi; + #warn $fh; + + my $error = defined($fh) + ? FS::cust_main::batch_import( { + filehandle => $fh, + 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 )], + } ) + : 'No file'; + + if ( $error ) { + %> + <!-- mason kludge --> + <% + eidiot($error); +# $cgi->param('error', $error); +# print $cgi->redirect( "${p}cust_main-import.cgi + } else { + %> + <!-- mason kludge --> + <%= header('Import sucessful') %> <% + } +%> |