summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Record.pm2
-rw-r--r--FS/FS/inventory_item.pm58
-rw-r--r--httemplate/misc/inventory_item-import.html56
-rw-r--r--httemplate/misc/process/inventory_item-import.html17
4 files changed, 65 insertions, 68 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 4b6684d8e..80ab564f1 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -1339,6 +1339,8 @@ sub process_batch_import {
warn "can't parse file type from filename $file; defaulting to CSV";
$type = 'csv';
}
+ $type = 'csv' unless $type eq 'xls';
+ $opt->{'default_csv'} && $type ne 'xls';
my $error =
FS::Record::batch_import( {
diff --git a/FS/FS/inventory_item.pm b/FS/FS/inventory_item.pm
index 7fa350f2a..3bba1cdda 100644
--- a/FS/FS/inventory_item.pm
+++ b/FS/FS/inventory_item.pm
@@ -129,61 +129,25 @@ sub cust_svc {
=back
-=head1 CLASS METHODS
+=head1 SUBROUTINES
=over 4
-=item batch_import
+=item process_batch_import
=cut
-sub batch_import {
- my $param = shift;
+sub process_batch_import {
+ my $job = shift;
- my $fh = $param->{filehandle};
+ my $opt = { 'table' => 'inventory_item',
+ #'params' => [ 'itembatch', 'classnum', ],
+ 'params' => [ 'classnum', ],
+ 'formats' => { 'default' => [ 'item' ] },
+ 'default_csv' => 1,
+ };
- my $imported = 0;
-
- local $SIG{HUP} = 'IGNORE';
- local $SIG{INT} = 'IGNORE';
- local $SIG{QUIT} = 'IGNORE';
- local $SIG{TERM} = 'IGNORE';
- local $SIG{TSTP} = 'IGNORE';
- local $SIG{PIPE} = 'IGNORE';
-
- my $oldAutoCommit = $FS::UID::AutoCommit;
- local $FS::UID::AutoCommit = 0;
- my $dbh = dbh;
-
- my $line;
- while ( defined($line=<$fh>) ) {
-
- chomp $line;
-
- my $inventory_item = new FS::inventory_item {
- 'classnum' => $param->{'classnum'},
- 'item' => $line,
- };
-
- my $error = $inventory_item->insert;
-
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
-
- #or just skip?
- #next;
- }
-
- $imported++;
- }
-
- $dbh->commit or die $dbh->errstr if $oldAutoCommit;
-
- #might want to disable this if we skip records for any reason...
- return "Empty file!" unless $imported;
-
- '';
+ FS::Record::process_batch_import( $job, $opt, @_ );
}
diff --git a/httemplate/misc/inventory_item-import.html b/httemplate/misc/inventory_item-import.html
index f3636c0e7..65a123e2a 100644
--- a/httemplate/misc/inventory_item-import.html
+++ b/httemplate/misc/inventory_item-import.html
@@ -1,14 +1,54 @@
-<% include("/elements/header.html", $inventory_class->classname. 's') %>
+<% include("/elements/header.html", PL($inventory_class->classname)) %>
-<FORM ACTION="process/inventory_item-import.html" METHOD="POST" ENCTYPE="multipart/form-data">
-<INPUT TYPE="hidden" NAME="classnum" VALUE="<% $classnum %>">
-Import a file containing <% $inventory_class->classname %>s, one per line.<BR><BR>
+Import a file containing <% PL($inventory_class->classname) %>, one per line.
+<BR><BR>
-Filename: <INPUT TYPE="file" NAME="filename"><BR><BR>
+<% include( '/elements/form-file_upload.html',
+ 'name' => 'InventoryItemImportForm',
+ 'action' => 'process/inventory_item-import.html',
+ 'num_files' => 1,
+ #'fields' => [ 'format', 'itembatch', 'classnum', ],
+ 'fields' => [ 'format', 'classnum', ],
+ 'message' => 'Inventory import successful',
+ #XXX redirect via $itembatch? or just back to class browse?
+ 'url' => $p."search/inventory_item.html?classnum=$classnum;avail=1",
+ )
+%>
+
+<% &ntable("#cccccc", 2) %>
+
+ <INPUT TYPE="hidden" NAME="format" VALUE="default">
+
+ <INPUT TYPE="hidden" NAME="classnum" VALUE="<% $classnum %>">
+
+%# <INPUT TYPE="hidden" NAME="itembatch" VALUE="<% $itembatch %>">
+
+ <% include( '/elements/file-upload.html',
+ 'field' => 'file',
+ 'label' => 'Filename',
+ )
+ %>
+
+ <TR>
+ <TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px">
+ <INPUT TYPE = "submit"
+ ID = "submit"
+ VALUE = "Import file"
+ onClick = "document.InventoryItemImportForm.submit.disabled=true;"
+ >
+ </TD>
+ </TR>
+
+</TABLE>
-<INPUT TYPE="submit" VALUE="Upload">
</FORM>
+<BR>
+
+Upload file can be a text file or Excel spreadsheet. If an Excel spreadsheet,
+ should have an .XLS extension.
+<BR><BR>
+
<% include('/elements/footer.html') %>
<%init>
@@ -20,4 +60,8 @@ $cgi->param =~ /^(\d+)$/ or errorpage("illegal classnum");
my $classnum = $1;
my $inventory_class = qsearchs('inventory_class', { 'classnum' => $classnum } );
+#my $conf = new FS::Conf;
+#my $itembatch =
+# time2str('webimport-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
+
</%init>
diff --git a/httemplate/misc/process/inventory_item-import.html b/httemplate/misc/process/inventory_item-import.html
index 3aae202c7..377943fb1 100644
--- a/httemplate/misc/process/inventory_item-import.html
+++ b/httemplate/misc/process/inventory_item-import.html
@@ -1,22 +1,9 @@
-% if ( $error ) {
-% errorpage($error);
-% } else {
- <% include("/elements/header.html",'Import successful') %>
- <!-- XXX redirect to batch search like the payment entry... -->
- <% include("/elements/footer.html",'Import successful') %>
-% }
+<% $server->process %>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Import');
-my $fh = $cgi->upload('filename');
-
-my $error = defined($fh)
- ? FS::inventory_item::batch_import( {
- 'filehandle' => $fh,
- 'classnum' => $cgi->param('classnum'),
- } )
- : 'No file';
+my $server = new FS::UI::Web::JSRPC 'FS::inventory_item::process_batch_import', $cgi;
</%init>