use SL::DB::Buchungsgruppe;
use SL::DB::CsvImportProfile;
use SL::Helper::Flash;
+use SL::SessionFile;
use List::MoreUtils qw(none);
use Rose::Object::MakeMethods::Generic
(
- scalar => [ qw(type profile all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen) ],
+ scalar => [ qw(type profile file all_profiles all_charsets sep_char all_sep_chars quote_char all_quote_chars escape_char all_escape_chars all_buchungsgruppen) ],
);
__PACKAGE__->run_before('check_auth');
$self->$sub(($char_map{$type}->{$char} || [])->[0] || $char);
}
+ $self->file(SL::SessionFile->new($self->csv_file_name));
+
my $title = $self->type eq 'customers_vendors' ? $::locale->text('CSV import: customers and vendors')
: $self->type eq 'addresses' ? $::locale->text('CSV import: shipping addresses')
: $self->type eq 'contacts' ? $::locale->text('CSV import: contacts')
$self->profile_from_form;
+ if ($::form->{file}) {
+ my $file = SL::SessionFile->new($self->csv_file_name, "w");
+ $file->fh->print($::form->{file});
+ $file->fh->close;
+ }
+
+ my $file = SL::SessionFile->new($self->csv_file_name, "w");
+ if (!$file->fh) {
+ flash('error', $::locale->text('No file has been uploaded yet.'));
+ return $self->action_new;
+ }
+
# do the import thingy...
$self->action_new;
}
);
}
+sub csv_file_name {
+ my ($self) = @_;
+ return "csv-import-" . $self->type . ".csv";
+}
+
1;
[%- INCLUDE 'common/flash.html' %]
- <form method="post" action="controller.pl">
+ <form method="post" action="controller.pl" enctype="multipart/form-data">
[% L.hidden_tag('action', 'CsvImport/dispatch') %]
[% L.hidden_tag('profile.type', SELF.profile.type) %]
[%- INCLUDE 'csv_import/_form_customers_vendors.html' %]
[%- END %]
+ <tr>
+ <th align="right">[%- LxERP.t8('Import file') %]:</th>
+ <td colspan="10">[% L.input_tag('file', '', type => 'file', accept => '*') %]</td>
+ </tr>
+
+ [%- IF SELF.file.exists %]
+ <tr>
+ <th align="right">[%- LxERP.t8('Existing file on server') %]:</th>
+ <td colspan="10">[%- LxERP.t8('Uploaded on #1, size #2 kB', SELF.file.displayable_mtime, LxERP.format_amount(SELF.file.size / 1024, 2)) %]</td>
+ </tr>
+ [%- END %]
+
</table>
[% L.submit_tag('action_test', LxERP.t8('Gogogo')) %]