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) = @_;
}
}
+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) = @_;
$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)};
}
}
+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;
}
+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) = @_;
{ 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') },
} 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++;
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();