Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d9cf6b76

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

  • ID d9cf6b762b186a447ea5abac79c50893341f42ca
  • Vorgänger 69f73331
  • Nachfolger c4d248c6

Abteilungen und Projekte behandeln.

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
11 11
use SL::DB::Part;
12 12
use SL::DB::PaymentTerm;
13 13
use SL::DB::Contact;
14
use SL::DB::Department;
14 15
use SL::TransNumber;
15 16

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

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

  
24 25

  
......
77 78
                                 { name => 'payment_id',       description => $::locale->text('Payment terms (database ID)')    },
78 79
                                 { name => 'payment',          description => $::locale->text('Payment terms (name)')           },
79 80
                                 { name => 'taxzone_id',       description => $::locale->text('Steuersatz')                     },
80
                                 { name => 'contact_id',       description => $::locale->text('Contact Person (database ID)')   },
81
                                 { name => 'cp_id',            description => $::locale->text('Contact Person (database ID)')   },
81 82
                                 { name => 'contact',          description => $::locale->text('Contact Person (name)')          },
83
                                 { name => 'department_id',    description => $::locale->text('Department (database ID)')       },
84
                                 { name => 'department',       description => $::locale->text('Department (description)')       },
85
                                 { name => 'globalproject_id', description => $::locale->text('Document Project (database ID)') },
86
                                 { name => 'globalprojectnumber', description => $::locale->text('Document Project (number)')   },
87
                                 { name => 'globalproject',    description => $::locale->text('Document Project (description)') },
88

  
82 89
                                );
83 90

  
84 91
  $self->add_displayable_columns('OrderItem',
......
123 130
  return $cby;
124 131
}
125 132

  
133
sub init_all_departments {
134
  my ($self) = @_;
135

  
136
  return SL::DB::Manager::Department->get_all;
137
}
138

  
139
sub init_departments_by {
140
  my ($self) = @_;
141

  
142
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_departments } } ) } qw(id description) };
143
}
144

  
145
sub init_all_projects {
146
  my ($self) = @_;
147

  
148
  return SL::DB::Manager::Project->get_all;
149
}
150

  
151
sub init_projects_by {
152
  my ($self) = @_;
153

  
154
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $self->all_projects } } ) } qw(id projectnumber description) };
155
}
156

  
126 157
sub check_objects {
127 158
  my ($self) = @_;
128 159

  
......
149 180
      $self->check_contact($entry);
150 181
      $self->check_language($entry);
151 182
      $self->check_payment($entry);
183
      $self->check_department($entry);
184
      $self->check_project($entry, global => 1);
152 185

  
153 186
      if ($vc_obj) {
154 187
        # copy from customer if not given
......
178 211
  $self->add_info_columns($self->settings->{'order_column'},
179 212
                          { header => $::locale->text('Customer/Vendor'), method => 'vc_name' });
180 213
  $self->add_columns($self->settings->{'order_column'},
181
                     map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(business payment));
182

  
214
                     map { "${_}_id" } grep { exists $self->controller->data->[0]->{raw_data}->{$_} } qw(payment language department globalproject));
215
  $self->add_columns($self->settings->{'order_column'}, 'globalproject_id') if exists $self->controller->data->[0]->{raw_data}->{globalprojectnumber};
183 216

  
184 217
  foreach my $entry (@{ $self->controller->data }) {
185 218
    if ($entry->{raw_data}->{datatype} eq $self->settings->{'item_column'} && $entry->{object}->can('part')) {
......
365 398

  
366 399
  my $object = $entry->{object};
367 400

  
368
  # Check wether or non contact ID is valid.
401
  # Check wether or not contact ID is valid.
369 402
  if ($object->cp_id && !$self->contacts_by->{cp_id}->{ $object->cp_id }) {
370 403
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid contact');
371 404
    return 0;
372 405
  }
373 406

  
374
  # Map number to ID if given.
407
  # Map name to ID if given.
375 408
  if (!$object->cp_id && $entry->{raw_data}->{contact}) {
376 409
    my $cp = $self->contacts_by->{cp_name}->{ $entry->{raw_data}->{contact} };
377 410
    if (!$cp) {
......
395 428
  return 1;
396 429
}
397 430

  
431
sub check_department {
432
  my ($self, $entry) = @_;
433

  
434
  my $object = $entry->{object};
435

  
436
  # Check wether or not department ID is valid.
437
  if ($object->department_id && !$self->departments_by->{id}->{ $object->department_id }) {
438
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid department');
439
    return 0;
440
  }
441

  
442
  # Map description to ID if given.
443
  if (!$object->department_id && $entry->{raw_data}->{department}) {
444
    my $dep = $self->departments_by->{description}->{ $entry->{raw_data}->{department} };
445
    if (!$dep) {
446
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid department');
447
      return 0;
448
    }
449

  
450
    $object->department_id($dep->id);
451
  }
452

  
453
  return 1;
454
}
455

  
456
sub check_project {
457
  my ($self, $entry, %params) = @_;
458

  
459
  my $id_column          = ($params{global} ? 'global' : '') . 'project_id';
460
  my $number_column      = ($params{global} ? 'global' : '') . 'projectnumber';
461
  my $description_column = ($params{global} ? 'global' : '') . 'project';
462

  
463
  my $object = $entry->{object};
464

  
465
  # Check wether or not projetc ID is valid.
466
  if ($object->$id_column && !$self->projects_by->{id}->{ $object->$id_column }) {
467
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
468
    return 0;
469
  }
470

  
471
  # Map number to ID if given.
472
  if (!$object->$id_column && $entry->{raw_data}->{$number_column}) {
473
    my $proj = $self->projects_by->{projectnumber}->{ $entry->{raw_data}->{$number_column} };
474
    if (!$proj) {
475
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
476
      return 0;
477
    }
478

  
479
    $object->$id_column($proj->id);
480
  }
481

  
482
  # Map description to ID if given.
483
  if (!$object->$id_column && $entry->{raw_data}->{$description_column}) {
484
    my $proj = $self->projects_by->{description}->{ $entry->{raw_data}->{$description_column} };
485
    if (!$proj) {
486
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
487
      return 0;
488
    }
489

  
490
    $object->$id_column($proj->id);
491
  }
492

  
493
  return 1;
494
}
495

  
496

  
497

  
398 498
sub save_objects {
399 499
  my ($self, %params) = @_;
400 500

  

Auch abrufbar als: Unified diff