Revision ea507623
Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt
SL/Controller/CsvImport/Order.pm | ||
---|---|---|
25 | 25 |
|
26 | 26 |
use Rose::Object::MakeMethods::Generic |
27 | 27 |
( |
28 |
'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by price_factors_by pricegroups_by) ],
|
|
28 |
'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by ct_shiptos_by price_factors_by pricegroups_by) ], |
|
29 | 29 |
); |
30 | 30 |
|
31 | 31 |
|
... | ... | |
211 | 211 |
return $cby; |
212 | 212 |
} |
213 | 213 |
|
214 |
sub init_departments_by { |
|
215 |
my ($self) = @_; |
|
216 |
|
|
217 |
my $all_departments = SL::DB::Manager::Department->get_all; |
|
218 |
return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_departments } } ) } qw(id description) }; |
|
219 |
} |
|
220 |
|
|
221 |
sub init_projects_by { |
|
222 |
my ($self) = @_; |
|
223 |
|
|
224 |
my $all_projects = SL::DB::Manager::Project->get_all; |
|
225 |
return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_projects } } ) } qw(id projectnumber description) }; |
|
226 |
} |
|
227 |
|
|
228 | 214 |
sub init_ct_shiptos_by { |
229 | 215 |
my ($self) = @_; |
230 | 216 |
|
... | ... | |
345 | 331 |
$self->handle_employee($entry); |
346 | 332 |
} |
347 | 333 |
|
348 |
# ToDo: salesman by name |
|
349 |
sub handle_salesman { |
|
350 |
my ($self, $entry) = @_; |
|
351 |
|
|
352 |
my $object = $entry->{object}; |
|
353 |
my $vc_obj; |
|
354 |
$vc_obj = SL::DB::Customer->new(id => $object->customer_id)->load if $object->customer_id; |
|
355 |
$vc_obj = SL::DB::Vendor->new(id => $object->vendor_id)->load if (!$vc_obj && $object->vendor_id); |
|
356 |
|
|
357 |
# salesman from customer/vendor or login if not given |
|
358 |
if (!$object->salesman) { |
|
359 |
if ($vc_obj && $vc_obj->salesman_id) { |
|
360 |
$object->salesman(SL::DB::Manager::Employee->find_by(id => $vc_obj->salesman_id)); |
|
361 |
} else { |
|
362 |
$object->salesman(SL::DB::Manager::Employee->find_by(login => $::myconfig{login})); |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
|
|
367 |
# ToDo: employee by name |
|
368 |
sub handle_employee { |
|
369 |
my ($self, $entry) = @_; |
|
370 |
|
|
371 |
my $object = $entry->{object}; |
|
372 |
|
|
373 |
# employee from login if not given |
|
374 |
if (!$object->employee_id) { |
|
375 |
$object->employee_id(SL::DB::Manager::Employee->find_by(login => $::myconfig{login})->id); |
|
376 |
} |
|
377 |
} |
|
378 |
|
|
379 | 334 |
sub check_language { |
380 | 335 |
my ($self, $entry) = @_; |
381 | 336 |
|
... | ... | |
506 | 461 |
return 1; |
507 | 462 |
} |
508 | 463 |
|
509 |
sub check_department { |
|
510 |
my ($self, $entry) = @_; |
|
511 |
|
|
512 |
my $object = $entry->{object}; |
|
513 |
|
|
514 |
# Check whether or not department ID is valid. |
|
515 |
if ($object->department_id && !$self->departments_by->{id}->{ $object->department_id }) { |
|
516 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid department'); |
|
517 |
return 0; |
|
518 |
} |
|
519 |
|
|
520 |
# Map description to ID if given. |
|
521 |
if (!$object->department_id && $entry->{raw_data}->{department}) { |
|
522 |
my $dep = $self->departments_by->{description}->{ $entry->{raw_data}->{department} }; |
|
523 |
if (!$dep) { |
|
524 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid department'); |
|
525 |
return 0; |
|
526 |
} |
|
527 |
|
|
528 |
$object->department_id($dep->id); |
|
529 |
} |
|
530 |
|
|
531 |
return 1; |
|
532 |
} |
|
533 |
|
|
534 |
sub check_project { |
|
535 |
my ($self, $entry, %params) = @_; |
|
536 |
|
|
537 |
my $id_column = ($params{global} ? 'global' : '') . 'project_id'; |
|
538 |
my $number_column = ($params{global} ? 'global' : '') . 'projectnumber'; |
|
539 |
my $description_column = ($params{global} ? 'global' : '') . 'project'; |
|
540 |
|
|
541 |
my $object = $entry->{object}; |
|
542 |
|
|
543 |
# Check whether or not projetc ID is valid. |
|
544 |
if ($object->$id_column && !$self->projects_by->{id}->{ $object->$id_column }) { |
|
545 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid project'); |
|
546 |
return 0; |
|
547 |
} |
|
548 |
|
|
549 |
# Map number to ID if given. |
|
550 |
if (!$object->$id_column && $entry->{raw_data}->{$number_column}) { |
|
551 |
my $proj = $self->projects_by->{projectnumber}->{ $entry->{raw_data}->{$number_column} }; |
|
552 |
if (!$proj) { |
|
553 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid project'); |
|
554 |
return 0; |
|
555 |
} |
|
556 |
|
|
557 |
$object->$id_column($proj->id); |
|
558 |
} |
|
559 |
|
|
560 |
# Map description to ID if given. |
|
561 |
if (!$object->$id_column && $entry->{raw_data}->{$description_column}) { |
|
562 |
my $proj = $self->projects_by->{description}->{ $entry->{raw_data}->{$description_column} }; |
|
563 |
if (!$proj) { |
|
564 |
push @{ $entry->{errors} }, $::locale->text('Error: Invalid project'); |
|
565 |
return 0; |
|
566 |
} |
|
567 |
|
|
568 |
$object->$id_column($proj->id); |
|
569 |
} |
|
570 |
|
|
571 |
return 1; |
|
572 |
} |
|
573 |
|
|
574 | 464 |
sub check_ct_shipto { |
575 | 465 |
my ($self, $entry) = @_; |
576 | 466 |
|
Auch abrufbar als: Unified diff
Auftragsimport - Methoden ausgelagert
für Prüfung von Abteilung, Projekt, Bearbeiter und Verkäufer
Vorbereitung für Debitorenbuchungsimport