Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 40f891ac

Von Bernd Bleßmann vor fast 11 Jahren hinzugefügt

  • ID 40f891acb75026351e3309294745caadd67247b3
  • Vorgänger 1d78de40
  • Nachfolger 7dd4a299

Alle Kontakte und Lieferadressen für entspr. Kunden/Lieferanten behandeln.

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
129 129
sub init_contacts_by {
130 130
  my ($self) = @_;
131 131

  
132
  my $cby = { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_contacts } } ) } qw(cp_id cp_name) };
132
  my $cby;
133 133

  
134 134
  # by customer/vendor id  _and_  contact person id
135
  $cby->{'cp_cv_id+cp_id'} = { map { ( $_->cp_cv_id . '+' . $_->cp_id => $_ ) } @{ $self->all_contacts } };
135
  $cby->{'cp_cv_id+cp_id'}   = { map { ( $_->cp_cv_id . '+' . $_->cp_id   => $_ ) } @{ $self->all_contacts } };
136
  # by customer/vendor id  _and_  contact person name
137
  $cby->{'cp_cv_id+cp_name'} = { map { ( $_->cp_cv_id . '+' . $_->cp_name => $_ ) } @{ $self->all_contacts } };
138

  
136 139

  
137 140
  return $cby;
138 141
}
......
170 173
sub init_ct_shiptos_by {
171 174
  my ($self) = @_;
172 175

  
173
  my $sby = { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_ct_shiptos } } ) } qw(shipto_id) };
176
  my $sby;
174 177

  
175 178
  # by trans_id  _and_  shipto_id
176 179
  $sby->{'trans_id+shipto_id'} = { map { ( $_->trans_id . '+' . $_->shipto_id => $_ ) } @{ $self->all_ct_shiptos } };
......
250 253
                          { header => $::locale->text('Customer/Vendor'), method => 'vc_name' });
251 254
  # Todo: access via ->[0] ok? Better: search first order column and use this
252 255
  $self->add_columns($self->settings->{'order_column'},
253
                     map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone));
256
                     map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject taxzone cp));
254 257
  $self->add_columns($self->settings->{'order_column'}, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber};
258
  $self->add_columns($self->settings->{'order_column'}, 'cp_id')            if exists $self->controller->data->[0]->{raw_data}->{contact};
255 259

  
256 260
  foreach my $entry (@{ $self->controller->data }) {
257 261
    if ($entry->{raw_data}->{datatype} eq $self->settings->{'item_column'} && $entry->{object}->can('part')) {
......
444 448

  
445 449
  my $object = $entry->{object};
446 450

  
451
  my $cp_cv_id = $object->customer_id || $object->vendor_id;
452
  return 0 unless $cp_cv_id;
453

  
447 454
  # Check wether or not contact ID is valid.
448
  if ($object->cp_id && !$self->contacts_by->{cp_id}->{ $object->cp_id }) {
455
  if ($object->cp_id && !$self->contacts_by->{'cp_cv_id+cp_id'}->{ $cp_cv_id . '+' . $object->cp_id }) {
449 456
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact');
450 457
    return 0;
451 458
  }
452 459

  
453 460
  # Map name to ID if given.
454
  # Todo: names have not to be unique ... search all and check for matching customer/vendor?
455 461
  if (!$object->cp_id && $entry->{raw_data}->{contact}) {
456
    my $cp = $self->contacts_by->{cp_name}->{ $entry->{raw_data}->{contact} };
462
    my $cp = $self->contacts_by->{'cp_cv_id+cp_name'}->{ $cp_cv_id . '+' . $entry->{raw_data}->{contact} };
457 463
    if (!$cp) {
458 464
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact');
459 465
      return 0;
......
462 468
    $object->cp_id($cp->cp_id);
463 469
  }
464 470

  
465
  # Check if the contact belongs to this customer/vendor.
466
  my $trans_id = $object->customer_id || $object->vendor_id;
467
  if ($object->cp_id && $trans_id
468
      && !$self->contacts_by->{'cp_cv_id+cp_id'}->{ $trans_id . '+' . $object->cp_id }) {
469
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact this customer/vendor');
470
    return 0;
471
  }
472

  
473 471
  if ($object->cp_id) {
474
    $entry->{info_data}->{contact} = $self->contacts_by->{cp_id}->{ $object->cp_id }->cp_name;
472
    $entry->{info_data}->{contact} = $self->contacts_by->{'cp_cv_id+cp_id'}->{ $cp_cv_id . '+' . $object->cp_id }->cp_name;
475 473
  }
476 474

  
477 475
  return 1;
......
547 545

  
548 546
  my $object = $entry->{object};
549 547

  
548
  my $trans_id = $object->customer_id || $object->vendor_id;
549
  return 0 unless $trans_id;
550

  
550 551
  # Check wether or not shipto ID is valid.
551
  if ($object->shipto_id && !$self->ct_shiptos_by->{shipto_id}->{ $object->shipto_id }) {
552
  if ($object->shipto_id && !$self->ct_shiptos_by->{'trans_id+shipto_id'}->{ $trans_id . '+' . $object->shipto_id }) {
552 553
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto');
553 554
    return 0;
554 555
  }
555 556

  
556
  # Check if the shipto belongs to this customer/vendor.
557
  my $trans_id = $object->customer_id || $object->vendor_id;
558
  if ($object->shipto_id && $trans_id
559
      && !$self->ct_shiptos_by->{'trans_id+shipto_id'}->{ $trans_id . '+' . $object->shipto_id } ) {
560
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto for this customer/vendor');
561
    return 0;
562
  }
563

  
564 557
  return 1;
565 558
}
566 559

  

Auch abrufbar als: Unified diff