+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);
+ }
+
+ return 1;
+}
+
+# ToDo: salesman by name
+sub handle_salesman {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+ my $vc_obj;
+ $vc_obj = SL::DB::Customer->new(id => $object->customer_id)->load if $object->can('customer') && $object->customer_id;
+ $vc_obj = SL::DB::Vendor->new(id => $object->vendor_id)->load if (!$vc_obj && $object->can('vendor') && $object->vendor_id);
+
+ # salesman from customer/vendor or login if not given
+ if (!$object->salesman) {
+ if ($vc_obj && $vc_obj->salesman_id) {
+ $object->salesman(SL::DB::Manager::Employee->find_by(id => $vc_obj->salesman_id));
+ } else {
+ $object->salesman(SL::DB::Manager::Employee->find_by(login => $::myconfig{login}));
+ }
+ }
+}
+
+# ToDo: employee by name
+sub handle_employee {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # employee from login if not given
+ if (!$object->employee_id) {
+ $object->employee_id(SL::DB::Manager::Employee->find_by(login => $::myconfig{login})->id);
+ }
+}
+
+
+