From c968d1f703a9a51e24c9b5dfd5acfe2012170792 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 18 Jan 2021 15:29:38 +0100 Subject: [PATCH] =?utf8?q?Zeiterfassung:=20Parameter=20f.=20Konvertierung?= =?utf8?q?=20in=20params=20=C3=BCbergeben?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/BackgroundJob/ConvertTimeRecordings.pm | 19 +++++++------------ SL/DB/DeliveryOrder.pm | 8 ++++---- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/SL/BackgroundJob/ConvertTimeRecordings.pm b/SL/BackgroundJob/ConvertTimeRecordings.pm index e65fb497e..dbbf12c1a 100644 --- a/SL/BackgroundJob/ConvertTimeRecordings.pm +++ b/SL/BackgroundJob/ConvertTimeRecordings.pm @@ -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(), diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index 3f2cd3e7e..8c5efab9c 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -207,9 +207,9 @@ sub new_from_time_recordings { # - merge same descriptions (todo) # - ### config - my $default_partnummer = 6; - my $default_part_id = SL::DB::Manager::Part->find_by(partnumber => $default_partnummer)->id; + my $default_part_id = $params{default_part_id} ? $params{default_part_id} + : $params{default_partnumber} ? SL::DB::Manager::Part->find_by(partnumber => $params{default_partnumber})->id + : undef; # check parts and collect entries my %part_by_part_id; @@ -227,7 +227,7 @@ sub new_from_time_recordings { } my $date = $source->start_time->to_kivitendo; - $entries->{$part_id}->{$date}->{duration} += $source->{rounding} + $entries->{$part_id}->{$date}->{duration} += $params{rounding} ? nhimult(0.25, ($source->duration_in_hours)) : _round_total($source->duration_in_hours); # add content if not already in description -- 2.20.1