]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/CsvImport/Part.pm
Viele weitere Klartextfelder bei Kunden-/Lieferantenstammdaten
[mfinanz.git] / SL / Controller / CsvImport / Part.pm
index 9d0e66ba33699b8ef1233198370906367413725f..af3b1075567b22861e22893e2833ef73f6e2215e 100644 (file)
@@ -5,9 +5,12 @@ use strict;
 use SL::Helper::Csv;
 
 use SL::DB::Buchungsgruppe;
+use SL::DB::CustomVariable;
+use SL::DB::CustomVariableConfig;
 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);
@@ -15,7 +18,8 @@ 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 packing_types_by partsgroups_by
+                                 translation_columns) ],
 );
 
 sub init_class {
@@ -37,13 +41,6 @@ sub init_price_factors_by {
   return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_price_factors } } ) } qw(id description) };
 }
 
-sub init_payment_terms_by {
-  my ($self) = @_;
-
-  my $all_payment_terms = SL::DB::Manager::PaymentTerm->get_all;
-  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_payment_terms } } ) } qw(id description) };
-}
-
 sub init_packing_types_by {
   my ($self) = @_;
 
@@ -88,6 +85,18 @@ sub init_settings {
                                                                     shoparticle_if_missing parts_type) };
 }
 
+sub init_all_cvar_configs {
+  my ($self) = @_;
+
+  return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'IC' ]);
+}
+
+sub init_translation_columns {
+  my ($self) = @_;
+
+  return [ map { ("description_" . $_->article_code, "notes_" . $_->article_code) } (@{ $self->all_languages }) ];
+}
+
 sub check_objects {
   my ($self) = @_;
 
@@ -107,6 +116,8 @@ sub check_objects {
     $self->check_existing($entry);
     $self->handle_prices($entry) if $self->settings->{sellprice_adjustment};
     $self->handle_shoparticle($entry);
+    $self->handle_translations($entry);
+    $self->handle_cvars($entry);
     $self->set_various_fields($entry);
   }
 
@@ -114,6 +125,8 @@ sub check_objects {
   $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};
+  $self->add_cvar_raw_data_columns;
+  map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->translation_columns };
 }
 
 sub check_duplicates {
@@ -264,32 +277,6 @@ sub check_price_factor {
   return 1;
 }
 
-sub check_payment {
-  my ($self, $entry) = @_;
-
-  my $object = $entry->{object};
-
-  # Check whether or not payment ID is valid.
-  if ($object->payment_id && !$self->payment_terms_by->{id}->{ $object->payment_id }) {
-    push @{ $entry->{errors} }, $::locale->text('Error: Invalid payment terms');
-    return 0;
-  }
-
-  # Map name to ID if given.
-  if (!$object->payment_id && $entry->{raw_data}->{payment}) {
-    my $terms = $self->payment_terms_by->{description}->{ $entry->{raw_data}->{payment} };
-
-    if (!$terms) {
-      push @{ $entry->{errors} }, $::locale->text('Error: Invalid payment terms');
-      return 0;
-    }
-
-    $object->payment_id($terms->id);
-  }
-
-  return 1;
-}
-
 sub check_packing_type {
   my ($self, $entry) = @_;
 
@@ -356,6 +343,22 @@ sub check_unit {
   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) = @_;
 
@@ -383,7 +386,4 @@ sub save_objects {
   $self->SUPER::save_objects(data => $without_number);
 }
 
-# TODO:
-#  CVARs ins Profil rein
-
 1;