use SL::DB::CsvImportProfile;
use SL::Helper::Flash;
use SL::SessionFile;
+use SL::Controller::CsvImport::Contact;
use SL::Controller::CsvImport::CustomerVendor;
+use SL::Controller::CsvImport::Part;
+use SL::Controller::CsvImport::Shipto;
use List::MoreUtils qw(none);
use Rose::Object::MakeMethods::Generic
(
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
- import_status errors headers data num_imported num_importable) ],
+ import_status errors headers raw_data_headers data num_imported num_importable worker displayable_columns) ],
);
__PACKAGE__->run_before('check_auth');
$self->all_buchungsgruppen(SL::DB::Manager::Buchungsgruppe->get_all_sorted);
+ $self->setup_help;
+
$self->render('csv_import/form', title => $title);
}
return $self->action_new;
}
- my $worker = $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(controller => $self, file => $file)
- : die "Program logic error";
-
+ my $worker = $self->create_worker($file);
$worker->run;
$worker->save_objects if !$params{test};
- $self->num_importable(scalar grep { !$_ } map { scalar @{ $_->{errors} } } @{ $self->data });
+ $self->num_importable(scalar grep { !$_ } map { scalar @{ $_->{errors} } } @{ $self->data || [] });
$self->import_status($params{test} ? 'tested' : 'imported');
+ flash('info', $::locale->text('Objects have been imported.')) if !$params{test};
+
$self->action_new;
}
push @settings, { key => "${type}_char", value => $char };
}
+ if ($self->type eq 'parts') {
+ $::form->{settings}->{sellprice_adjustment} = $::form->parse_amount(\%::myconfig, $::form->{settings}->{sellprice_adjustment});
+ }
+
delete $::form->{profile}->{id};
$self->profile($existing_profile || SL::DB::CsvImportProfile->new);
$self->profile->assign_attributes(%{ $::form->{profile} });
return "csv-import-" . $self->type . ".csv";
}
+sub create_worker {
+ my ($self, $file) = @_;
+
+ return $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(controller => $self, file => $file)
+ : $self->{type} eq 'contacts' ? SL::Controller::CsvImport::Contact->new( controller => $self, file => $file)
+ : $self->{type} eq 'addresses' ? SL::Controller::CsvImport::Shipto->new( controller => $self, file => $file)
+ : $self->{type} eq 'parts' ? SL::Controller::CsvImport::Part->new( controller => $self, file => $file)
+ : die "Program logic error";
+}
+
+sub setup_help {
+ my ($self) = @_;
+
+ $self->create_worker->setup_displayable_columns;
+}
+
+
1;