+ # defined, in this case the customer/vendor taxzone will be used later
+ if ( defined $object->taxzone_id ) {
+ $entry->{info_data}->{taxzone} = _taxzones_by($self)->{id}->{ $object->taxzone_id }->description;
+ };
+
+ return 1;
+}
+
+sub check_project {
+ my ($self, $entry, %params) = @_;
+
+ my $id_column = ($params{global} ? 'global' : '') . 'project_id';
+ my $number_column = ($params{global} ? 'global' : '') . 'projectnumber';
+ my $description_column = ($params{global} ? 'global' : '') . 'project';
+
+ my $object = $entry->{object};
+
+ # Check whether or not project ID is valid.
+ if ($object->$id_column) {
+ if (! _projects_by($self)->{id}->{ $object->$id_column }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
+ return 0;
+ } else {
+ $entry->{info_data}->{$number_column} = _projects_by($self)->{id}->{ $object->$id_column }->description;
+ };
+ }
+
+ my $proj;
+ # Map number to ID if given.
+ if (!$object->$id_column && $entry->{raw_data}->{$number_column}) {
+ $proj = _projects_by($self)->{projectnumber}->{ $entry->{raw_data}->{$number_column} };
+ if (!$proj) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
+ return 0;
+ }
+
+ $object->$id_column($proj->id);
+ }
+
+ # Map description to ID if given.
+ if (!$object->$id_column && $entry->{raw_data}->{$description_column}) {
+ $proj = _projects_by($self)->{description}->{ $entry->{raw_data}->{$description_column} };
+ if (!$proj) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid project');
+ return 0;
+ }
+
+ $object->$id_column($proj->id);
+ }
+
+ if ( $proj ) {
+ $entry->{info_data}->{"$description_column"} = $proj->description;
+ $entry->{info_data}->{"$number_column"} = $proj->projectnumber;
+ };
+
+ return 1;
+}
+
+sub check_department {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Check whether or not department ID was assigned and is valid.
+ if ($object->department_id) {
+ if (!_departments_by($self)->{id}->{ $object->department_id }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid department');
+ return 0;
+ } else {
+ # add department description as well, more feedback for user
+ $entry->{info_data}->{department} = _departments_by($self)->{id}->{ $object->department_id }->description;
+ };
+ }
+
+ # Map department description to ID if given.
+ if (!$object->department_id && $entry->{raw_data}->{department}) {
+ $entry->{info_data}->{department} = $entry->{raw_data}->{department};
+ my $dep = _departments_by($self)->{description}->{ $entry->{raw_data}->{department} };
+ if (!$dep) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid department');
+ return 0;
+ }
+ $entry->{info_data}->{department} = $dep->description;
+ $object->department_id($dep->id);
+ }