Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c4d248c6

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

  • ID c4d248c6fc53195f1c566d8084a80fb5d936d8df
  • Vorgänger d9cf6b76
  • Nachfolger 9fa0473d

Lieferadressen behandeln u. kleiner Bugfix bei Ansprechpersonen

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
12 12
use SL::DB::PaymentTerm;
13 13
use SL::DB::Contact;
14 14
use SL::DB::Department;
15
use SL::DB::Project;
16
use SL::DB::Shipto;
15 17
use SL::TransNumber;
16 18

  
17 19
use parent qw(SL::Controller::CsvImport::BaseMulti);
......
19 21

  
20 22
use Rose::Object::MakeMethods::Generic
21 23
(
22
 'scalar --get_set_init' => [ qw(settings languages_by all_parts parts_by all_contacts contacts_by all_departments departments_by all_projects projects_by) ],
24
 '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) ],
23 25
);
24 26

  
25 27

  
......
85 87
                                 { name => 'globalproject_id', description => $::locale->text('Document Project (database ID)') },
86 88
                                 { name => 'globalprojectnumber', description => $::locale->text('Document Project (number)')   },
87 89
                                 { name => 'globalproject',    description => $::locale->text('Document Project (description)') },
88

  
90
                                 { name => 'shipto_id',        description => $::locale->text('Ship to (database ID)')          },
89 91
                                );
90 92

  
91 93
  $self->add_displayable_columns('OrderItem',
......
154 156
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_projects } } ) } qw(id projectnumber description) };
155 157
}
156 158

  
159
sub init_all_ct_shiptos {
160
  my ($self) = @_;
161

  
162
  return SL::DB::Manager::Shipto->get_all(query => [module => 'CT']);
163
}
164

  
165
sub init_ct_shiptos_by {
166
  my ($self) = @_;
167

  
168
  my $sby = { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_ct_shiptos } } ) } qw(shipto_id) };
169

  
170
  # by trans_id  _and_  shipto_id
171
  $sby->{'trans_id+shipto_id'} = { map { ( $_->trans_id . '+' . $_->shipto_id => $_ ) } @{ $self->all_ct_shiptos } };
172

  
173
  return $sby;
174
}
175

  
157 176
sub check_objects {
158 177
  my ($self) = @_;
159 178

  
......
182 201
      $self->check_payment($entry);
183 202
      $self->check_department($entry);
184 203
      $self->check_project($entry, global => 1);
204
      $self->check_ct_shipto($entry);
185 205

  
186 206
      if ($vc_obj) {
187 207
        # copy from customer if not given
......
405 425
  }
406 426

  
407 427
  # Map name to ID if given.
428
  # Todo: names have not to be unique ... search all and check for matching customer/vendor?
408 429
  if (!$object->cp_id && $entry->{raw_data}->{contact}) {
409 430
    my $cp = $self->contacts_by->{cp_name}->{ $entry->{raw_data}->{contact} };
410 431
    if (!$cp) {
......
416 437
  }
417 438

  
418 439
  # Check if the contact belongs to this customer/vendor.
419
  if ($object->cp_id && $object->customer_id && !$self->contacts_by->{'cp_cv_id+cp_id'}) {
420
    push @{ $entry->{errors} }, $::locale->text('Error: Contact not found for this customer/vendor');
440
  my $trans_id = $object->customer_id || $object->vendor_id;
441
  if ($object->cp_id && $trans_id
442
      && !$self->contacts_by->{'cp_cv_id+cp_id'}->{ $trans_id . '+' . $object->cp_id }) {
443
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact this customer/vendor');
421 444
    return 0;
422 445
  }
423 446

  
......
493 516
  return 1;
494 517
}
495 518

  
519
sub check_ct_shipto {
520
  my ($self, $entry) = @_;
521

  
522
  my $object = $entry->{object};
523

  
524
  # Check wether or not shipto ID is valid.
525
  if ($object->shipto_id && !$self->ct_shiptos_by->{shipto_id}->{ $object->shipto_id }) {
526
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto');
527
    return 0;
528
  }
529

  
530
  # Check if the shipto belongs to this customer/vendor.
531
  my $trans_id = $object->customer_id || $object->vendor_id;
532
  if ($object->shipto_id && $trans_id
533
      && !$self->ct_shiptos_by->{'trans_id+shipto_id'}->{ $trans_id . '+' . $object->shipto_id } ) {
534
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid shipto for this customer/vendor');
535
    return 0;
536
  }
537

  
538
  return 1;
539
}
540

  
496 541

  
497 542

  
498 543
sub save_objects {

Auch abrufbar als: Unified diff