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) ],
);
__PACKAGE__->run_before('check_auth');
$headers->{methods} = [ map { $profile->{$_} } @{ $headers->{headers} } ];
$headers->{used} = { map { ($_ => 1) } @{ $headers->{headers} } };
$self->controller->headers($headers);
+ $self->controller->raw_data_headers({ used => { }, headers => [ ] });
# my @data;
# foreach my $object ($self->csv->get_objects)
}
}
+sub add_raw_data_columns {
+ my ($self, @columns) = @_;
+
+ my $h = $self->controller->raw_data_headers;
+
+ foreach my $column (grep { !$h->{used}->{$_} } @columns) {
+ $h->{used}->{$column} = 1;
+ push @{ $h->{headers} }, $column;
+ }
+}
+
sub init_profile {
my ($self) = @_;
use SL::Helper::Csv;
use SL::DB::Buchungsgruppe;
+use SL::DB::Language;
use SL::DB::PartsGroup;
use SL::DB::PaymentTerm;
use SL::DB::PriceFactor;
+use SL::DB::Translation;
use SL::DB::Unit;
use parent qw(SL::Controller::CsvImport::Base);
use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(table) ],
- 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by) ],
+ 'scalar --get_set_init' => [ qw(bg_by settings parts_by price_factors_by units_by payment_terms_by packing_types_by partsgroups_by all_languages
+ translation_columns) ],
);
sub init_class {
shoparticle_if_missing parts_type) };
}
+sub init_all_languages {
+ my ($self) = @_;
+
+ return SL::DB::Manager::Language->get_all;
+}
+
+sub init_translation_columns {
+ my ($self) = @_;
+
+ return [ map { ("description_" . $_->article_code, "notes_" . $_->article_code) } (@{ $self->all_languages }) ];
+}
+
sub check_objects {
my ($self) = @_;
$self->check_existing($entry);
$self->handle_prices($entry) if $self->settings->{sellprice_adjustment};
$self->handle_shoparticle($entry);
+ $self->handle_translations($entry);
$self->set_various_fields($entry);
}
$self->add_columns(qw(buchungsgruppen_id unit));
$self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw (price_factor payment packing_type partsgroup));
$self->add_columns(qw(shop)) if $self->settings->{shoparticle_if_missing};
+
+ map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->translation_columns };
}
sub check_duplicates {
return 1;
}
+sub handle_translations {
+ my ($self, $entry) = @_;
+
+ my @translations;
+ foreach my $language (@{ $self->all_languages }) {
+ my ($desc, $notes) = @{ $entry->{raw_data} }{ "description_" . $language->article_code, "notes_" . $language->article_code };
+ next unless $desc || $notes;
+
+ push @translations, SL::DB::Translation->new(language_id => $language->id,
+ translation => $desc,
+ longdescription => $notes);
+ }
+
+ $entry->{object}->translations(\@translations);
+}
+
sub set_various_fields {
my ($self, $entry) = @_;
[%- FOREACH column = SELF.headers.headers %]
<th>[%- HTML.escape(column) %]</th>
[%- END %]
+ [%- FOREACH column = SELF.raw_data_headers.headers %]
+ <th>[%- HTML.escape(column) %]</th>
+ [%- END %]
<th>[%- LxERP.t8('Notes') %]</th>
</tr>
[%- FOREACH method = SELF.headers.methods %]
<td>[%- HTML.escape(row.object.$method) %]</td>
[%- END %]
+ [%- FOREACH method = SELF.raw_data_headers.headers %]
+ <td>[%- HTML.escape(row.raw_data.$method) %]</td>
+ [%- END %]
<td>
[%- FOREACH error = row.errors %][%- HTML.escape(error) %][% UNLESS loop.last %]<br>[%- END %][%- END %]
</td>