1 package SL::Controller::CsvImport;
6 use SL::DB::Buchungsgruppe;
7 use SL::DB::CsvImportProfile;
8 use SL::DB::CsvImportReport;
10 use SL::DB::Helper::Paginated ();
11 use SL::Helper::Flash;
12 use SL::Locale::String;
14 use SL::Controller::CsvImport::Contact;
15 use SL::Controller::CsvImport::CustomerVendor;
16 use SL::Controller::CsvImport::Part;
17 use SL::Controller::CsvImport::Inventory;
18 use SL::Controller::CsvImport::Shipto;
19 use SL::Controller::CsvImport::Project;
20 use SL::Controller::CsvImport::Order;
21 use SL::Controller::CsvImport::ARTransaction;
23 use SL::Controller::CsvImport::BankTransaction;
24 use SL::BackgroundJob::CsvImport;
25 use SL::System::TaskServer;
27 use List::MoreUtils qw(none);
28 use List::Util qw(min);
30 use parent qw(SL::Controller::Base);
32 use Rose::Object::MakeMethods::Generic
34 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 all_units
35 import_status errors headers raw_data_headers info_headers data num_importable displayable_columns file all_taxzones) ],
36 'scalar --get_set_init' => [ qw(worker task_server num_imported mappings) ],
38 progress_tracker => { },
39 add_progress_tracker => { interface => 'add', hash_key => 'progress_tracker' },
43 __PACKAGE__->run_before('check_auth', except => [ qw(report) ]);
44 __PACKAGE__->run_before('ensure_form_structure');
45 __PACKAGE__->run_before('check_type', except => [ qw(report) ]);
46 __PACKAGE__->run_before('load_all_profiles');
47 __PACKAGE__->run_before('check_task_server');
49 __PACKAGE__->run_after('cleanup_reports');
58 $self->load_default_profile unless $self->profile;
64 $self->test_and_import_deferred(test => 1);
69 $self->test_and_import_deferred(test => 0);
75 $self->profile_from_form(SL::DB::Manager::CsvImportProfile->find_by(name => $::form->{profile}->{name}, login => $::myconfig{login}));
78 flash_later('info', $::locale->text("The profile has been saved under the name '#1'.", $self->profile->name));
79 $self->redirect_to(action => 'new', 'profile.type' => $self->type, 'profile.id' => $self->profile->id);
85 my $profile = SL::DB::CsvImportProfile->new(id => $::form->{profile}->{id}, login => $::myconfig{login});
86 $profile->delete(cascade => 1);
88 flash_later('info', $::locale->text('The profile \'#1\' has been deleted.', $profile->name));
89 $self->redirect_to(action => 'new', 'profile.type' => $self->type);
96 $self->{background_job} = SL::DB::Manager::BackgroundJob->find_by(id => $::form->{job});
98 my $data = $self->{background_job}->data_as_hash;
100 my $profile = SL::DB::Manager::CsvImportProfile->find_by(id => $data->{profile_id});
101 $self->profile($profile);
103 if ($data->{errors} and my $first_error = $data->{errors}->[0]) {
104 flash('error', $::locale->text('There was an error parsing the csv file: #1 in line #2: #3', $first_error->[2], $first_error->[0], $first_error->[1]));
107 if ($data->{progress}{finished} || $data->{errors}) {
108 $self->render('csv_import/_deferred_report', { layout => 0 });
110 if (!$self->task_server->is_running) {
111 $self->task_server->start;
112 $self->{status_text} = t8('Task Server is not running, starting it now. If this does not change, please check your task server config');
113 } elsif (my $phase = $data->{progress}{phase}) {
114 $self->{status_text} = "$data->{progress}{plan}{$phase} / $data->{progress}{num_phases} " . t8($phase);
116 $self->{status_text} = t8('Import not started yet, please wait...');
119 $self->render('csv_import/_deferred_results', { layout => 0 });
123 sub action_download_sample {
126 $self->profile_from_form;
129 my $file_name = 'csv_import_sample_' . $self->type . '.csv';
130 my $file = SL::SessionFile->new($file_name, mode => '>', encoding => $self->profile->get('charset'));
131 my $csv = Text::CSV_XS->new({ binary => 1, map { ( $_ => $self->profile->get($_) ) } qw(sep_char escape_char quote_char),});
133 if ($self->worker->is_multiplexed) {
134 foreach my $p (@{ $self->worker->profile }) {
135 $csv->print($file->fh, [ map { $_->{name} } @{ $self->displayable_columns->{$p->{row_ident}} } ]);
136 $file->fh->print("\r\n");
138 foreach my $p (@{ $self->worker->profile }) {
139 $csv->print($file->fh, [ map { $_->{description} } @{ $self->displayable_columns->{$p->{row_ident}} } ]);
140 $file->fh->print("\r\n");
143 $csv->print($file->fh, [ map { $_->{name} } @{ $self->displayable_columns } ]);
144 $file->fh->print("\r\n");
145 $csv->print($file->fh, [ map { $_->{description} } @{ $self->displayable_columns } ]);
146 $file->fh->print("\r\n");
151 $self->send_file($file->file_name, name => $file_name);
155 my ($self, %params) = @_;
157 my $report_id = $params{report_id} || $::form->{id};
158 $self->{report} = SL::DB::Manager::CsvImportReport->find_by(id => $report_id);
160 if (!$self->{report}) {
161 $::form->error(t8('No report with id #1', $report_id));
164 my $num_rows = $self->{report}->numrows;
165 my $num_cols = SL::DB::Manager::CsvImportReportRow->get_all_count(query => [ csv_import_report_id => $report_id, row => 0 ]);
167 # manual paginating, yuck
168 my $page = $::form->{page} || 1;
170 $pages->{per_page} = $::form->{per_page} || 20;
171 $pages->{max} = SL::DB::Helper::Paginated::ceil($num_rows, $pages->{per_page}) || 1;
172 $pages->{page} = $page < 1 ? 1
173 : $page > $pages->{max} ? $pages->{max}
175 $pages->{common} = [ grep { $_->{visible} } @{ SL::DB::Helper::Paginated::make_common_pages($pages->{page}, $pages->{max}) } ];
177 $self->{report_numheaders} = $self->{report}->numheaders;
178 my $first_row_header = 0;
179 my $last_row_header = $self->{report_numheaders} - 1;
180 my $first_row_data = $pages->{per_page} * ($pages->{page}-1) + $self->{report_numheaders};
181 my $last_row_data = min($pages->{per_page} * $pages->{page}, $num_rows) + $self->{report_numheaders} - 1;
182 $self->{display_rows} = [
192 csv_import_report_id => $report_id,
195 row => { ge => $first_row_header },
196 row => { le => $last_row_header },
199 row => { ge => $first_row_data },
200 row => { le => $last_row_data },
205 my $rows = SL::DB::Manager::CsvImportReportRow ->get_all(query => \@query);
206 my $status = SL::DB::Manager::CsvImportReportStatus->get_all(query => \@query);
208 $self->{report_rows} = $self->{report}->folded_rows(rows => $rows);
209 $self->{report_status} = $self->{report}->folded_status(status => $status);
210 $self->{pages} = $pages;
211 $self->{base_url} = $self->url_for(action => 'report', id => $report_id, no_layout => $params{no_layout} || $::form->{no_layout} );
213 $self->render('csv_import/report', { layout => !($params{no_layout} || $::form->{no_layout}) });
216 sub action_add_empty_mapping_line {
219 $self->profile_from_form;
223 ->append('#csv_import_mappings', $self->render('csv_import/_mapping_item', { layout => 0, output => 0 }))
224 ->hide('#mapping_empty')
228 sub action_add_mapping_from_upload {
231 $self->profile_from_form;
234 my $file = SL::SessionFile->new($self->csv_file_name, mode => '<', encoding => $self->profile->get('charset'));
237 ->flash('error', t8('No file has been uploaded yet.'))
242 my $csv = SL::Helper::Csv->new(
243 file => $file->file_name,
244 map { $_ => $self->profile->get($_) } qw(sep_char escape_char quote_char),
248 my $header = $csv->check_header;
250 for my $field (@$header) {
251 next if $self->mappings_for_profile->{$field};
253 '#csv_import_mappings',
254 $self->render('csv_import/_mapping_item', { layout => 0, output => 0 }, item => { from => $field }),
259 ->hide('#mapping_empty')
270 $_[0]->worker->check_auth;
276 die "Invalid CSV import type" if none { $_ eq $::form->{profile}->{type} } qw(parts inventories customers_vendors addresses contacts projects orders bank_transactions ar_transactions);
277 $self->type($::form->{profile}->{type});
280 sub ensure_form_structure {
281 my ($self, %params) = @_;
283 $::form->{profile} = {} unless ref $::form->{profile} eq 'HASH';
284 $::form->{settings} = {} unless ref $::form->{settings} eq 'HASH';
292 my ($self, %params) = @_;
294 $self->all_charsets([ [ 'UTF-8', 'UTF-8' ],
295 [ 'ISO-8859-1', 'ISO-8859-1 (Latin 1)' ],
296 [ 'ISO-8859-15', 'ISO-8859-15 (Latin 9)' ],
297 [ 'CP850', 'CP850 (DOS/ANSI)' ],
298 [ 'CP1252', 'CP1252 (Windows)' ],
301 my %char_map = $self->char_map;
303 foreach my $type (qw(sep quote escape)) {
304 my $sub = "all_${type}_chars";
305 $self->$sub([ sort { $a->[0] cmp $b->[0] } values %{ $char_map{$type} } ]);
307 my $char = $self->profile->get($type . '_char');
308 $sub = "${type}_char";
309 $self->$sub(($char_map{$type}->{$char} || [])->[0] || $char);
312 $self->file(SL::SessionFile->new($self->csv_file_name));
314 my $title = $self->type eq 'customers_vendors' ? $::locale->text('CSV import: customers and vendors')
315 : $self->type eq 'addresses' ? $::locale->text('CSV import: shipping addresses')
316 : $self->type eq 'contacts' ? $::locale->text('CSV import: contacts')
317 : $self->type eq 'parts' ? $::locale->text('CSV import: parts and services')
318 : $self->type eq 'inventories' ? $::locale->text('CSV import: inventories')
319 : $self->type eq 'projects' ? $::locale->text('CSV import: projects')
320 : $self->type eq 'orders' ? $::locale->text('CSV import: orders')
321 : $self->type eq 'bank_transactions' ? $::locale->text('CSV import: bank transactions')
322 : $self->type eq 'ar_transactions' ? $::locale->text('CSV import: ar transactions')
325 if ($self->{type} eq 'customers_vendors' or $self->{type} eq 'orders' or $self->{type} eq 'ar_transactions' ) {
326 $self->all_taxzones(SL::DB::Manager::TaxZone->get_all_sorted(query => [ obsolete => 0 ]));
329 if ($self->{type} eq 'parts') {
330 $self->all_buchungsgruppen(SL::DB::Manager::Buchungsgruppe->get_all_sorted);
331 $self->all_units(SL::DB::Manager::Unit->get_all_sorted);
336 $self->render('csv_import/form', title => $title);
339 sub test_and_import_deferred {
340 my ($self, %params) = @_;
342 if ( $::form->{force_profile} && $::form->{profile}->{id} ) {
343 $self->load_default_profile;
345 $self->profile_from_form;
348 if ($::form->{file}) {
349 my $file = SL::SessionFile->new($self->csv_file_name, mode => '>');
350 $file->fh->print($::form->{file});
354 my $file = SL::SessionFile->new($self->csv_file_name, mode => '<', encoding => $self->profile->get('charset'));
356 flash('error', $::locale->text('No file has been uploaded yet.'));
357 return $self->action_new;
360 $self->{background_job} = SL::BackgroundJob::CsvImport->create_job(
361 file => $self->csv_file_name,
362 profile => $self->profile,
363 type => $self->profile->type,
364 test => $params{test},
365 employee_id => SL::DB::Manager::Employee->current->id,
368 if ($self->task_server->is_running) {
369 $self->task_server->wake_up;
371 $self->task_server->start;
374 flash('info', $::locale->text('Your import is being processed.'));
376 $self->{deferred} = 1;
378 if ($::request->type eq 'json') {
379 $self->render(\ SL::JSON::to_json($self->{background_job}->as_tree), { type => 'json' })
381 $self->render_inputs;
385 sub test_and_import {
386 my ($self, %params) = @_;
388 my $file = SL::SessionFile->new(
389 $self->csv_file_name,
391 encoding => $self->profile->get('charset'),
392 session_id => $params{session_id}
397 my $worker = $self->worker();
399 $worker->run(%params);
401 return if $self->errors;
403 $self->num_imported(0);
404 $worker->save_objects if !$params{test};
406 $self->num_importable(scalar grep { !$_ } map { scalar @{ $_->{errors} } } @{ $self->data || [] });
407 $self->import_status($params{test} ? 'tested' : 'imported');
409 # flash('info', $::locale->text('Objects have been imported.')) if !$params{test};
412 sub load_default_profile {
416 if ($::form->{profile}->{id}) {
417 $profile = SL::DB::Manager::CsvImportProfile->find_by(id => $::form->{profile}->{id});
419 $profile ||= SL::DB::Manager::CsvImportProfile->find_by(type => $self->{type}, is_default => 1, login => $::myconfig{login});
420 $profile ||= SL::DB::CsvImportProfile->new(type => $self->{type}, login => $::myconfig{login});
422 $self->profile($profile);
423 $self->mappings(SL::JSON::from_json($self->profile->get('json_mappings'))) if $self->profile->get('json_mappings');
424 $self->worker->set_profile_defaults;
425 $self->profile->set_defaults;
428 sub load_all_profiles {
429 my ($self, %params) = @_;
431 $self->all_profiles(SL::DB::Manager::CsvImportProfile->get_all(
434 login => $::myconfig{login},
440 sub profile_from_form {
441 my ($self, $existing_profile) = @_;
443 delete $::form->{profile}->{id};
445 my %char_map = $self->char_map;
448 foreach my $type (qw(sep quote escape)) {
449 my %rev_chars = map { $char_map{$type}->{$_}->[0] => $_ } keys %{ $char_map{$type} };
450 my $char = $::form->{"${type}_char"} eq 'custom' ? $::form->{"custom_${type}_char"} : $rev_chars{ $::form->{"${type}_char"} };
452 push @settings, { key => "${type}_char", value => $char };
455 if ($self->type eq 'parts') {
456 $::form->{settings}->{sellprice_adjustment} = $::form->parse_amount(\%::myconfig, $::form->{settings}->{sellprice_adjustment});
459 if ($self->type eq 'orders') {
460 $::form->{settings}->{max_amount_diff} = $::form->parse_amount(\%::myconfig, $::form->{settings}->{max_amount_diff});
463 delete $::form->{profile}->{id};
464 $self->profile($existing_profile || SL::DB::CsvImportProfile->new(login => $::myconfig{login}));
465 $self->profile->assign_attributes(%{ $::form->{profile} });
466 $self->profile->settings(map({ { key => $_, value => $::form->{settings}->{$_} } } keys %{ $::form->{settings} }),
469 $self->profile->set('json_mappings', JSON::to_json($self->mappings));
471 $self->profile->set_defaults;
475 return ( sep => { ',' => [ 'comma', $::locale->text('Comma') ],
476 ';' => [ 'semicolon', $::locale->text('Semicolon') ],
477 "\t" => [ 'tab', $::locale->text('Tab') ],
478 ' ' => [ 'space', $::locale->text('Space') ],
480 quote => { '"' => [ 'quote', $::locale->text('Quotes') ],
481 "'" => [ 'singlequote', $::locale->text('Single quotes') ],
483 escape => { '"' => [ 'quote', $::locale->text('Quotes') ],
484 "'" => [ 'singlequote', $::locale->text('Single quotes') ],
490 my ($self, %params) = @_;
492 if ($self->worker->is_multiplexed) {
493 return $self->save_report_multi(%params);
495 return $self->save_report_single(%params);
499 sub save_report_single {
500 my ($self, %params) = @_;
502 $self->track_progress(phase => 'building report', progress => 0);
504 my $clone_profile = $self->profile->clone_and_reset_deep;
505 $clone_profile->save; # weird bug. if this isn't saved before adding it to the report, it will default back to the last profile.
507 my $report = SL::DB::CsvImportReport->new(
508 session_id => $params{session_id},
509 profile => $clone_profile,
512 numrows => scalar @{ $self->data },
514 test_mode => $params{test} ? 1 : 0,
517 $report->save(cascade => 1) or die $report->db->error;
519 SL::DB->client->with_transaction(sub {
520 my $dbh = SL::DB->client->dbh;
522 my $query = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)';
523 my $query2 = 'INSERT INTO csv_import_report_status (csv_import_report_id, row, type, value) VALUES (?, ?, ?, ?)';
525 my $sth = $dbh->prepare($query);
526 my $sth2 = $dbh->prepare($query2);
529 my (@headers, @info_methods, @raw_methods, @methods);
531 for my $i (0 .. $#{ $self->info_headers->{headers} }) {
532 next unless $self->info_headers->{used}->{ $self->info_headers->{methods}->[$i] };
533 push @headers, $self->info_headers->{headers}->[$i];
534 push @info_methods, $self->info_headers->{methods}->[$i];
536 for my $i (0 .. $#{ $self->headers->{headers} }) {
537 next unless $self->headers->{used}->{ $self->headers->{headers}->[$i] };
538 push @headers, $self->headers->{headers}->[$i];
539 push @methods, $self->headers->{methods}->[$i];
541 for my $i (0 .. $#{ $self->raw_data_headers->{headers} }) {
542 next unless $self->raw_data_headers->{used}->{ $self->raw_data_headers->{headers}->[$i] };
543 push @headers, $self->raw_data_headers->{headers}->[$i];
544 push @raw_methods, $self->raw_data_headers->{headers}->[$i];
547 $sth->execute($report->id, $_, 0, $headers[$_]) for 0 .. $#headers;
550 my $o1 = @info_methods;
551 my $o2 = $o1 + @methods;
553 for my $row (0 .. $#{ $self->data }) {
554 $self->track_progress(progress => $row / @{ $self->data } * 100) if $row % 1000 == 0;
555 my $data_row = $self->{data}[$row];
557 $sth->execute($report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods;
558 $sth->execute($report->id, $o1 + $_, $row + 1, $data_row->{object}->${ \ $methods[$_] }) for 0 .. $#methods;
559 $sth->execute($report->id, $o2 + $_, $row + 1, $data_row->{raw_data}{ $raw_methods[$_] }) for 0 .. $#raw_methods;
561 $sth2->execute($report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] };
562 $sth2->execute($report->id, $row + 1, 'errors', $_) for @{ $data_row->{errors} || [] };
565 }) or do { die SL::DB->client->error };
570 sub save_report_multi {
571 my ($self, %params) = @_;
573 $self->track_progress(phase => 'building report', progress => 0);
575 my $clone_profile = $self->profile->clone_and_reset_deep;
576 $clone_profile->save; # weird bug. if this isn't saved before adding it to the report, it will default back to the last profile.
578 my $report = SL::DB::CsvImportReport->new(
579 session_id => $params{session_id},
580 profile => $clone_profile,
583 numrows => scalar @{ $self->data },
584 numheaders => scalar @{ $self->worker->profile },
585 test_mode => $params{test} ? 1 : 0,
588 $report->save(cascade => 1) or die $report->db->error;
590 SL::DB->client->with_transaction(sub {
591 my $dbh = SL::DB->client->dbh;
593 my $query = 'INSERT INTO csv_import_report_rows (csv_import_report_id, col, row, value) VALUES (?, ?, ?, ?)';
594 my $query2 = 'INSERT INTO csv_import_report_status (csv_import_report_id, row, type, value) VALUES (?, ?, ?, ?)';
596 my $sth = $dbh->prepare($query);
597 my $sth2 = $dbh->prepare($query2);
600 my ($headers, $info_methods, $raw_methods, $methods);
602 for my $i (0 .. $#{ $self->worker->profile }) {
603 my $row_ident = $self->worker->profile->[$i]->{row_ident};
605 for my $i (0 .. $#{ $self->info_headers->{$row_ident}->{headers} }) {
606 next unless $self->info_headers->{$row_ident}->{used}->{ $self->info_headers->{$row_ident}->{methods}->[$i] };
607 push @{ $headers->{$row_ident} }, $self->info_headers->{$row_ident}->{headers}->[$i];
608 push @{ $info_methods->{$row_ident} }, $self->info_headers->{$row_ident}->{methods}->[$i];
610 for my $i (0 .. $#{ $self->headers->{$row_ident}->{headers} }) {
611 next unless $self->headers->{$row_ident}->{used}->{ $self->headers->{$row_ident}->{headers}->[$i] };
612 push @{ $headers->{$row_ident} }, $self->headers->{$row_ident}->{headers}->[$i];
613 push @{ $methods->{$row_ident} }, $self->headers->{$row_ident}->{methods}->[$i];
616 for my $i (0 .. $#{ $self->raw_data_headers->{$row_ident}->{headers} }) {
617 next unless $self->raw_data_headers->{$row_ident}->{used}->{ $self->raw_data_headers->{$row_ident}->{headers}->[$i] };
618 push @{ $headers->{$row_ident} }, $self->raw_data_headers->{$row_ident}->{headers}->[$i];
619 push @{ $raw_methods->{$row_ident} }, $self->raw_data_headers->{$row_ident}->{headers}->[$i];
624 for my $i (0 .. $#{ $self->worker->profile }) {
625 my $row_ident = $self->worker->profile->[$i]->{row_ident};
626 $sth->execute($report->id, $_, $i, $headers->{$row_ident}->[$_]) for 0 .. $#{ $headers->{$row_ident} };
631 for my $i (0 .. $#{ $self->worker->profile }) {
632 my $row_ident = $self->worker->profile->[$i]->{row_ident};
633 my $n_info_methods = $info_methods->{$row_ident} ? scalar @{ $info_methods->{$row_ident} } : 0;
634 my $n_methods = $methods->{$row_ident} ? scalar @{ $methods->{$row_ident} } : 0;
636 $off1->{$row_ident} = $n_info_methods;
637 $off2->{$row_ident} = $off1->{$row_ident} + $n_methods;
640 my $n_header_rows = scalar @{ $self->worker->profile };
642 for my $row (0 .. $#{ $self->data }) {
643 $self->track_progress(progress => $row / @{ $self->data } * 100) if $row % 1000 == 0;
644 my $data_row = $self->{data}[$row];
645 my $row_ident = $data_row->{raw_data}{datatype};
647 my $o1 = $off1->{$row_ident};
648 my $o2 = $off2->{$row_ident};
650 $sth->execute($report->id, $_, $row + $n_header_rows, $data_row->{info_data}{ $info_methods->{$row_ident}->[$_] }) for 0 .. $#{ $info_methods->{$row_ident} };
651 $sth->execute($report->id, $o1 + $_, $row + $n_header_rows, $data_row->{object}->${ \ $methods->{$row_ident}->[$_] }) for 0 .. $#{ $methods->{$row_ident} };
652 $sth->execute($report->id, $o2 + $_, $row + $n_header_rows, $data_row->{raw_data}{ $raw_methods->{$row_ident}->[$_] }) for 0 .. $#{ $raw_methods->{$row_ident} };
654 $sth2->execute($report->id, $row + $n_header_rows, 'information', $_) for @{ $data_row->{information} || [] };
655 $sth2->execute($report->id, $row + $n_header_rows, 'errors', $_) for @{ $data_row->{errors} || [] };
658 }) or do { die SL::DB->client->error };
665 return "csv-import-" . $self->type . ".csv";
671 my @args = (controller => $self);
673 if ( $self->file() ) {
674 push(@args, file => $self->file());
677 return $self->{type} eq 'customers_vendors' ? SL::Controller::CsvImport::CustomerVendor->new(@args)
678 : $self->{type} eq 'contacts' ? SL::Controller::CsvImport::Contact->new(@args)
679 : $self->{type} eq 'addresses' ? SL::Controller::CsvImport::Shipto->new(@args)
680 : $self->{type} eq 'parts' ? SL::Controller::CsvImport::Part->new(@args)
681 : $self->{type} eq 'inventories' ? SL::Controller::CsvImport::Inventory->new(@args)
682 : $self->{type} eq 'projects' ? SL::Controller::CsvImport::Project->new(@args)
683 : $self->{type} eq 'orders' ? SL::Controller::CsvImport::Order->new(@args)
684 : $self->{type} eq 'bank_transactions' ? SL::Controller::CsvImport::BankTransaction->new(@args)
685 : $self->{type} eq 'ar_transactions' ? SL::Controller::CsvImport::ARTransaction->new(@args)
686 : die "Program logic error";
689 sub init_num_imported { 0 }
694 $self->worker->setup_displayable_columns;
698 my ($self, %params) = @_;
700 for my $tracker ($self->progress_tracker) {
701 $tracker->track_progress(%params);
705 sub init_task_server {
706 SL::System::TaskServer->new;
709 sub cleanup_reports {
710 SL::DB::Manager::CsvImportReport->cleanup;
713 sub check_task_server {
714 return 1 if $_[0]->task_server->is_running;
716 flash('info', t8('The task server is not running at the moment but needed for this module'));
721 sub mappings_for_profile {
722 +{ map { $_->{from} => $_->{to} } @{ $_[0]->mappings } }
726 [ grep { $_->{from} } @{ $::form->{mappings} || [] } ]