X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/1d78de409b3536e1dba613700eb8ec5ffa531567..7dd4a29917927325e1f063173acbc6afd6e71a4d:/SL/Controller/CsvImport/Order.pm diff --git a/SL/Controller/CsvImport/Order.pm b/SL/Controller/CsvImport/Order.pm index 2cd1b42af..f0b3312df 100644 --- a/SL/Controller/CsvImport/Order.pm +++ b/SL/Controller/CsvImport/Order.pm @@ -22,7 +22,7 @@ use parent qw(SL::Controller::CsvImport::BaseMulti); use Rose::Object::MakeMethods::Generic ( - 'scalar --get_set_init' => [ qw(settings languages_by all_parts parts_by all_contacts contacts_by all_departments departments_by all_projects projects_by all_ct_shiptos ct_shiptos_by all_taxzones taxzones_by) ], + 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by taxzones_by) ], ); @@ -108,86 +108,58 @@ sub init_languages_by { return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_languages } } ) } qw(id description article_code) }; } -sub init_all_parts { - my ($self) = @_; - - return SL::DB::Manager::Part->get_all; -} - sub init_parts_by { my ($self) = @_; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_parts } } ) } qw(id partnumber ean description) }; -} - -sub init_all_contacts { - my ($self) = @_; - - return SL::DB::Manager::Contact->get_all; + my $all_parts = SL::DB::Manager::Part->get_all; + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_parts } } ) } qw(id partnumber ean description) }; } sub init_contacts_by { my ($self) = @_; - my $cby = { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_contacts } } ) } qw(cp_id cp_name) }; + my $all_contacts = SL::DB::Manager::Contact->get_all; + my $cby; # by customer/vendor id _and_ contact person id - $cby->{'cp_cv_id+cp_id'} = { map { ( $_->cp_cv_id . '+' . $_->cp_id => $_ ) } @{ $self->all_contacts } }; + $cby->{'cp_cv_id+cp_id'} = { map { ( $_->cp_cv_id . '+' . $_->cp_id => $_ ) } @{ $all_contacts } }; + # by customer/vendor id _and_ contact person name + $cby->{'cp_cv_id+cp_name'} = { map { ( $_->cp_cv_id . '+' . $_->cp_name => $_ ) } @{ $all_contacts } }; return $cby; } -sub init_all_departments { - my ($self) = @_; - - return SL::DB::Manager::Department->get_all; -} - sub init_departments_by { my ($self) = @_; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_departments } } ) } qw(id description) }; -} - -sub init_all_projects { - my ($self) = @_; - - return SL::DB::Manager::Project->get_all; + my $all_departments = SL::DB::Manager::Department->get_all; + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_departments } } ) } qw(id description) }; } sub init_projects_by { my ($self) = @_; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_projects } } ) } qw(id projectnumber description) }; -} - -sub init_all_ct_shiptos { - my ($self) = @_; - - return SL::DB::Manager::Shipto->get_all(query => [module => 'CT']); + my $all_projects = SL::DB::Manager::Project->get_all; + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_projects } } ) } qw(id projectnumber description) }; } sub init_ct_shiptos_by { my ($self) = @_; - my $sby = { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_ct_shiptos } } ) } qw(shipto_id) }; + my $all_ct_shiptos = SL::DB::Manager::Shipto->get_all(query => [module => 'CT']); + my $sby; # by trans_id _and_ shipto_id - $sby->{'trans_id+shipto_id'} = { map { ( $_->trans_id . '+' . $_->shipto_id => $_ ) } @{ $self->all_ct_shiptos } }; + $sby->{'trans_id+shipto_id'} = { map { ( $_->trans_id . '+' . $_->shipto_id => $_ ) } @{ $all_ct_shiptos } }; return $sby; } -sub init_all_taxzones { - my ($self) = @_; - - return SL::DB::Manager::TaxZone->get_all; -} - sub init_taxzones_by { my ($self) = @_; - return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_taxzones } } ) } qw(id description) }; + my $all_taxzones = SL::DB::Manager::TaxZone->get_all; + return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_taxzones } } ) } qw(id description) }; } sub check_objects { @@ -250,8 +222,9 @@ sub check_objects { { header => $::locale->text('Customer/Vendor'), method => 'vc_name' }); # Todo: access via ->[0] ok? Better: search first order column and use this $self->add_columns($self->settings->{'order_column'}, - map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone)); + map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone cp)); $self->add_columns($self->settings->{'order_column'}, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber}; + $self->add_columns($self->settings->{'order_column'}, 'cp_id') if exists $self->controller->data->[0]->{raw_data}->{contact}; foreach my $entry (@{ $self->controller->data }) { if ($entry->{raw_data}->{datatype} eq $self->settings->{'item_column'} && $entry->{object}->can('part')) { @@ -444,16 +417,18 @@ sub check_contact { my $object = $entry->{object}; + my $cp_cv_id = $object->customer_id || $object->vendor_id; + return 0 unless $cp_cv_id; + # Check wether or not contact ID is valid. - if ($object->cp_id && !$self->contacts_by->{cp_id}->{ $object->cp_id }) { + if ($object->cp_id && !$self->contacts_by->{'cp_cv_id+cp_id'}->{ $cp_cv_id . '+' . $object->cp_id }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact'); return 0; } # Map name to ID if given. - # Todo: names have not to be unique ... search all and check for matching customer/vendor? if (!$object->cp_id && $entry->{raw_data}->{contact}) { - my $cp = $self->contacts_by->{cp_name}->{ $entry->{raw_data}->{contact} }; + my $cp = $self->contacts_by->{'cp_cv_id+cp_name'}->{ $cp_cv_id . '+' . $entry->{raw_data}->{contact} }; if (!$cp) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact'); return 0; @@ -462,16 +437,8 @@ sub check_contact { $object->cp_id($cp->cp_id); } - # Check if the contact belongs to this customer/vendor. - my $trans_id = $object->customer_id || $object->vendor_id; - if ($object->cp_id && $trans_id - && !$self->contacts_by->{'cp_cv_id+cp_id'}->{ $trans_id . '+' . $object->cp_id }) { - push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact this customer/vendor'); - return 0; - } - if ($object->cp_id) { - $entry->{info_data}->{contact} = $self->contacts_by->{cp_id}->{ $object->cp_id }->cp_name; + $entry->{info_data}->{contact} = $self->contacts_by->{'cp_cv_id+cp_id'}->{ $cp_cv_id . '+' . $object->cp_id }->cp_name; } return 1; @@ -547,20 +514,15 @@ sub check_ct_shipto { my $object = $entry->{object}; + my $trans_id = $object->customer_id || $object->vendor_id; + return 0 unless $trans_id; + # Check wether or not shipto ID is valid. - if ($object->shipto_id && !$self->ct_shiptos_by->{shipto_id}->{ $object->shipto_id }) { + if ($object->shipto_id && !$self->ct_shiptos_by->{'trans_id+shipto_id'}->{ $trans_id . '+' . $object->shipto_id }) { push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto'); return 0; } - # Check if the shipto belongs to this customer/vendor. - my $trans_id = $object->customer_id || $object->vendor_id; - if ($object->shipto_id && $trans_id - && !$self->ct_shiptos_by->{'trans_id+shipto_id'}->{ $trans_id . '+' . $object->shipto_id } ) { - push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto for this customer/vendor'); - return 0; - } - return 1; }