]> wagnertech.de Git - mfinanz.git/blobdiff - SL/BackgroundJob/ConvertTimeRecordings.pm
Zeiterfassung: Parameter f. Konvertierung in params übergeben
[mfinanz.git] / SL / BackgroundJob / ConvertTimeRecordings.pm
index 2df2d8026de9b8d1e01941032d1ecc12c5eff6b5..dbbf12c1a249e412bd06d318ea7e2fd1d6778576 100644 (file)
@@ -21,9 +21,9 @@ use Rose::Object::MakeMethods::Generic (
 );
 
 # valid parameters -> better as class members with rose generic set/get
-my %params = (
-              fromdate => '',
-              todate   => '',
+my %valid_params = (
+              from_date => '',
+              to_date   => '',
               customernumbers => '',
               part_id => '',
               rounding => 1,
@@ -48,7 +48,7 @@ sub run {
 
   # check user input param names
   foreach my $param (keys %{ $data }) {
-    croak "Not a valid key: $param" unless $params{$param};
+    die "Not a valid parameter: $param" unless exists $valid_params{$param};
   }
 
   # TODO check user input param values - (defaults are assigned later)
@@ -79,25 +79,20 @@ sub run {
                                                                                  or => [booked => 0, booked => undef],
                                                                                  %customer_where],
                                                                 with_objects => ['customer']);
+
   # no time recordings at all ? -> better exit here before iterating a empty hash
   # return undef or message unless ref $time_recordings->[0] eq SL::DB::Manager::TimeRecording;
+
   my %time_recordings_by_customer_id;
-  # push @{ $time_recordings_by_customer_id{$_->customer_id} }, $_ for @$time_recordings;
-  # loop over all entries and add default or user defined params:
-
-  for my $source_entry (@$time_recordings) {
-    # set user defaults for processing
-    $source_entry->{$_} = $self->$_ for qw(rounding link_project);
-    foreach (qw(project_id parts_id)) {
-      $source_entry->{$_} = $self->{$_} if length ($self->{$_});
-    }
-    push @{ $time_recordings_by_customer_id{$source_entry->customer_id} }, $source_entry;
-  }
+  push @{ $time_recordings_by_customer_id{$_->customer_id} }, $_ for @$time_recordings;
+
+  my %convert_params = map { $_ => $data->{$_} } qw(rounding link_project part_id project_id);
+
   my @donumbers;
   foreach my $customer_id (keys %time_recordings_by_customer_id) {
     my $do;
     if (!eval {
-      $do = SL::DB::DeliveryOrder->new_from_time_recordings($time_recordings_by_customer_id{$customer_id});
+      $do = SL::DB::DeliveryOrder->new_from_time_recordings($time_recordings_by_customer_id{$customer_id}, %convert_params);
       1;
     }) {
       $::lxdebug->message(LXDebug->WARN(),
@@ -130,8 +125,9 @@ sub run {
   # die if errors exists
   if (@{ $self->{job_errors} }) {
     $msg  .= ' ' . t8('The following errors occurred:');
+    $msg  .= ' ';
     $msg  .= join "\n", @{ $self->{job_errors} };
-    die $msg;
+    die $msg . "\n";
   }
   return $msg;
 }