use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(controller file csv) ],
- 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class) ],
+ 'scalar --get_set_init' => [ qw(profile existing_objects class manager_class cvar_columns all_cvar_configs) ],
);
sub run {
}
}
+sub add_cvar_raw_data_columns {
+ my ($self) = @_;
+
+ map { $self->add_raw_data_columns($_) if exists $self->controller->data->[0]->{raw_data}->{$_} } @{ $self->cvar_columns };
+}
+
+sub init_cvar_columns {
+ my ($self) = @_;
+
+ return [ map { "cvar_" . $_->name } (@{ $self->all_cvar_configs }) ];
+}
+
+sub handle_cvars {
+ my ($self, $entry) = @_;
+
+ return unless $self->can('all_cvar_configs');
+
+ 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' );
+
+ my @cvars;
+ foreach my $config (@{ $self->all_cvar_configs }) {
+ 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);
+ }
+
+ $entry->{object}->custom_variables(\@cvars);
+}
+
sub init_profile {
my ($self) = @_;
use strict;
use SL::Helper::Csv;
+use SL::DB::CustomVariable;
+use SL::DB::CustomVariableConfig;
use parent qw(SL::Controller::CsvImport::Base);
$self->class('SL::DB::' . ucfirst($self->table));
}
+sub init_all_cvar_configs {
+ my ($self) = @_;
+
+ return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'CT' ]);
+}
+
sub check_objects {
my ($self) = @_;
} else {
$vcs_by_number{ $object->$numbercolumn } = $object;
}
+
+ $self->handle_cvars($entry);
}
+
+ $self->add_cvar_raw_data_columns;
}
sub check_duplicates {
);
}
+# TODO:
+# Kundentyp
+# salesman_id
+# Sprache
+# Zahlungsbedingungen
+
1;
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 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 payment_terms_by packing_types_by partsgroups_by
+ all_languages translation_columns) ],
);
sub init_class {
return SL::DB::Manager::Language->get_all;
}
+sub init_all_cvar_configs {
+ my ($self) = @_;
+
+ return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'IC' ]);
+}
+
sub init_translation_columns {
my ($self) = @_;
$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);
}
$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 };
}
$self->SUPER::save_objects(data => $without_number);
}
-# TODO:
-# CVARs ins Profil rein
-
1;