From: Bernd Bleßmann Date: Mon, 7 Oct 2013 14:26:40 +0000 (+0200) Subject: benutzerdef. Variable behandeln. X-Git-Tag: release-3.1.0beta1~22^2~124 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=01a4e61cd737bfd84e45169c78ee2071bd6b3acc;p=kivitendo-erp.git benutzerdef. Variable behandeln. --- diff --git a/SL/Controller/CsvImport/BaseMulti.pm b/SL/Controller/CsvImport/BaseMulti.pm index 32dc4c45e..d5010a26e 100644 --- a/SL/Controller/CsvImport/BaseMulti.pm +++ b/SL/Controller/CsvImport/BaseMulti.pm @@ -8,6 +8,11 @@ use SL::Helper::Csv; use parent qw(SL::Controller::CsvImport::Base); +use Rose::Object::MakeMethods::Generic +( +'scalar --get_set_init' => [ qw(cvar_configs_by cvar_columns_by) ], +); + sub run { my ($self, %params) = @_; @@ -124,6 +129,56 @@ sub add_raw_data_columns { } } +sub add_cvar_raw_data_columns { + my ($self) = @_; + + foreach my $data (@{ $self->controller->data }) { + my $ri = $data->{raw_data}->{datatype}; + map { $self->add_raw_data_columns($ri, $_) if exists $data->{raw_data}->{$_} } @{ $self->cvar_columns_by->{row_ident}->{$ri} }; + } +} + +sub init_cvar_configs_by { + # Must be overridden by derived specialized importer classes. + return {}; +} + +sub init_cvar_columns_by { + my ($self) = @_; + + my $ccb; + foreach my $p (@{ $self->profile }) { + my $ri = $p->{row_ident}; + $ccb->{row_ident}->{$ri} = [ map { "cvar_" . $_->name } (@{ $self->cvar_configs_by->{row_ident}->{$ri} }) ]; + } + + return $ccb; +} + +sub handle_cvars { + my ($self, $entry, %params) = @_; + + my %type_to_column = ( text => 'text_value', + textfield => 'text_value', + select => 'text_value', + date => 'timestamp_value_as_date', + timestamp => 'timestamp_value_as_date', + number => 'number_value_as_number', + bool => 'bool_value' ); + + $params{sub_module} ||= ''; + my @cvars; + foreach my $config (@{ $self->cvar_configs_by->{row_ident}->{$entry->{raw_data}->{datatype}} }) { + next unless exists $entry->{raw_data}->{ "cvar_" . $config->name }; + my $value = $entry->{raw_data}->{ "cvar_" . $config->name }; + my $column = $type_to_column{ $config->type } || die "Program logic error: unknown custom variable storage type"; + + push @cvars, SL::DB::CustomVariable->new(config_id => $config->id, $column => $value, sub_module => $params{sub_module}); + } + + $entry->{object}->custom_variables(\@cvars) if @cvars; +} + sub init_profile { my ($self) = @_; @@ -145,7 +200,7 @@ sub init_profile { $prof{$col} = $name; } - $prof{ 'cvar_' . $_->name } = '' for @{ $self->all_cvar_configs }; + $prof{ 'cvar_' . $_->name } = '' for @{ $self->cvar_configs_by->{class}->{$class} }; $class =~ m/^SL::DB::(.+)/; push @profile, {'profile' => \%prof, 'class' => $class, 'row_ident' => $::locale->text($1)}; @@ -186,6 +241,15 @@ sub setup_displayable_columns { } } +sub add_cvar_columns_to_displayable_columns { + my ($self, $row_ident) = @_; + + $self->add_displayable_columns($row_ident, + map { { name => 'cvar_' . $_->name, + description => $::locale->text('#1 (custom variable)', $_->description) } } + @{ $self->cvar_configs_by->{row_ident}->{$row_ident} }); +} + sub is_multiplexed { 1 } 1; diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index 34f093146..35743e079 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -41,6 +41,22 @@ sub init_settings { } +sub init_cvar_configs_by { + my ($self) = @_; + + my $item_cvar_configs = SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'IC' ]); + $item_cvar_configs = [grep { $_->has_flag('editable') } @{ $item_cvar_configs }]; + + my $ccb; + $ccb->{class}->{'SL::DB::Order'} = []; + $ccb->{class}->{'SL::DB::OrderItem'} = $item_cvar_configs; + $ccb->{row_ident}->{$self->_order_column} = []; + $ccb->{row_ident}->{$self->_item_column} = $item_cvar_configs; + + return $ccb; +} + + sub init_profile { my ($self) = @_; @@ -123,6 +139,8 @@ sub setup_displayable_columns { { name => 'shipto_id', description => $::locale->text('Ship to (database ID)') }, ); + $self->add_cvar_columns_to_displayable_columns($self->_item_column); + $self->add_displayable_columns($self->_item_column, { name => 'datatype', description => $self->_item_column }, { name => 'cusordnumber', description => $::locale->text('Customer Order Number') }, @@ -247,6 +265,7 @@ sub check_objects { } elsif ($entry->{raw_data}->{datatype} eq $self->_item_column && $entry->{object}->can('part')) { $self->handle_item($entry); } + $self->handle_cvars($entry, sub_module => 'orderitems'); } continue { $i++; @@ -267,6 +286,7 @@ sub check_objects { map { "${_}_id" } grep { exists $self->controller->data->[1]->{raw_data}->{$_} } qw(project price_factor pricegroup)); $self->add_columns($self->_item_column, 'project_id') if exists $self->controller->data->[1]->{raw_data}->{projectnumber}; + $self->add_cvar_raw_data_columns(); $self->add_items_to_order(); $self->handle_prices_and_taxes();