From: Moritz Bunkus Date: Wed, 2 Mar 2011 15:50:05 +0000 (+0100) Subject: Viele weitere Klartextfelder bei Kunden-/Lieferantenstammdaten X-Git-Tag: release-2.7.0beta1~396^2~25 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1c84c7f2353749b92ab39bb6f3fec67e5e645756;p=kivitendo-erp.git Viele weitere Klartextfelder bei Kunden-/Lieferantenstammdaten --- diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 91efaaaac..7d966c17b 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -5,13 +5,15 @@ use strict; use List::MoreUtils qw(pairwise); use SL::Helper::Csv; +use SL::DB::Language; +use SL::DB::PaymentTerm; use parent qw(Rose::Object); use Rose::Object::MakeMethods::Generic ( scalar => [ qw(controller file csv) ], - 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs) ], + 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by) ], ); sub run { @@ -84,6 +86,19 @@ sub init_cvar_columns { return [ map { "cvar_" . $_->name } (@{ $self->all_cvar_configs }) ]; } +sub init_all_languages { + my ($self) = @_; + + return SL::DB::Manager::Language->get_all; +} + +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 handle_cvars { my ($self, $entry) = @_; @@ -154,6 +169,32 @@ sub check_objects { sub check_duplicates { } +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 save_objects { my ($self, %params) = @_; diff --git a/SL/Controller/CsvImport/CustomerVendor.pm b/SL/Controller/CsvImport/CustomerVendor.pm index a82af654a..2fec13189 100644 --- a/SL/Controller/CsvImport/CustomerVendor.pm +++ b/SL/Controller/CsvImport/CustomerVendor.pm @@ -3,14 +3,16 @@ package SL::Controller::CsvImport::CustomerVendor; use strict; use SL::Helper::Csv; +use SL::DB::Business; use SL::DB::CustomVariable; use SL::DB::CustomVariableConfig; +use SL::DB::PaymentTerm; use parent qw(SL::Controller::CsvImport::Base); use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(table) ], + 'scalar --get_set_init' => [ qw(table languages_by businesses_by) ], ); sub init_table { @@ -29,6 +31,18 @@ sub init_all_cvar_configs { return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'CT' ]); } +sub init_businesses_by { + my ($self) = @_; + + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ SL::DB::Manager::Business->get_all } } ) } qw(id description) }; +} + +sub init_languages_by { + my ($self) = @_; + + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_languages } } ) } qw(id description article_code) }; +} + sub check_objects { my ($self) = @_; @@ -38,23 +52,20 @@ sub check_objects { foreach my $entry (@{ $self->controller->data }) { my $object = $entry->{object}; - my $name = $object->name; - $name =~ s/^\s+//; - $name =~ s/\s+$//; - if (!$name) { - push @{ $entry->{errors} }, $::locale->text('Error: Name missing'); - next; - } + next unless $self->check_name($entry); + next unless $self->check_language($entry); + next unless $self->check_business($entry); + next unless $self->check_payment($entry); + $self->handle_cvars($entry); if ($vcs_by_number{ $object->$numbercolumn }) { $entry->{object}->$numbercolumn('####'); } else { $vcs_by_number{ $object->$numbercolumn } = $object; } - - $self->handle_cvars($entry); } + $self->add_columns(map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(language business payment)); $self->add_cvar_raw_data_columns; } @@ -81,6 +92,72 @@ sub check_duplicates { } } +sub check_name { + my ($self, $entry) = @_; + + my $name = $entry->{object}->name; + $name =~ s/^\s+//; + $name =~ s/\s+$//; + + return 1 if $name; + + push @{ $entry->{errors} }, $::locale->text('Error: Name missing'); + return 0; +} + +sub check_language { + my ($self, $entry) = @_; + + my $object = $entry->{object}; + + # Check whether or not language ID is valid. + if ($object->language_id && !$self->languages_by->{id}->{ $object->language_id }) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid language'); + return 0; + } + + # Map name to ID if given. + if (!$object->language_id && $entry->{raw_data}->{language}) { + my $language = $self->languages_by->{description}->{ $entry->{raw_data}->{language} } + || $self->languages_by->{article_code}->{ $entry->{raw_data}->{language} }; + + if (!$language) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid language'); + return 0; + } + + $object->language_id($language->id); + } + + return 1; +} + +sub check_business { + my ($self, $entry) = @_; + + my $object = $entry->{object}; + + # Check whether or not business ID is valid. + if ($object->business_id && !$self->businesss_by->{id}->{ $object->business_id }) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid business'); + return 0; + } + + # Map name to ID if given. + if (!$object->business_id && $entry->{raw_data}->{business}) { + my $business = $self->businesses_by->{description}->{ $entry->{raw_data}->{business} }; + + if (!$business) { + push @{ $entry->{errors} }, $::locale->text('Error: Invalid business'); + return 0; + } + + $object->business_id($business->id); + } + + return 1; +} + sub save_objects { my ($self, %params) = @_; @@ -115,10 +192,16 @@ sub field_lengths { ); } +sub init_profile { + my ($self) = @_; + + my $profile = $self->SUPER::init_profile; + delete @{$profile}{qw(language business salesman payment)}; + + return $profile; +} + # TODO: -# Kundentyp -# salesman_id -# Sprache -# Zahlungsbedingungen +# salesman_id -- Kunden mit Typ 'Verkäufer', falls $::vertreter an ist, ansonsten Employees 1; diff --git a/SL/Controller/CsvImport/Part.pm b/SL/Controller/CsvImport/Part.pm index 9746b7e64..af3b10755 100644 --- a/SL/Controller/CsvImport/Part.pm +++ b/SL/Controller/CsvImport/Part.pm @@ -7,7 +7,6 @@ use SL::Helper::Csv; use SL::DB::Buchungsgruppe; use SL::DB::CustomVariable; use SL::DB::CustomVariableConfig; -use SL::DB::Language; use SL::DB::PartsGroup; use SL::DB::PaymentTerm; use SL::DB::PriceFactor; @@ -19,8 +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 - all_languages translation_columns) ], + '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 { @@ -42,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) = @_; @@ -93,12 +85,6 @@ sub init_settings { shoparticle_if_missing parts_type) }; } -sub init_all_languages { - my ($self) = @_; - - return SL::DB::Manager::Language->get_all; -} - sub init_all_cvar_configs { my ($self) = @_; @@ -291,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) = @_;