]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/TimeRecording.pm
Zeiterfassung: Bei Zeitanzeige auch Varianten mit Datum und Dauer berücksichtigen
[mfinanz.git] / SL / DB / TimeRecording.pm
index 970fa87382916b5a40c1720fee34aeb2c044a683..13329b782aded9bf9d950e42812391478c61b335 100644 (file)
@@ -33,7 +33,6 @@ sub validate {
 
   my @errors;
 
-  push @errors, t8('Start time must not be empty.')                            if !$self->start_time;
   push @errors, t8('Customer must not be empty.')                              if !$self->customer_id;
   push @errors, t8('Staff member must not be empty.')                          if !$self->staff_member_id;
   push @errors, t8('Employee must not be empty.')                              if !$self->employee_id;
@@ -109,24 +108,26 @@ sub is_time_in_wrong_order {
   return;
 }
 
+sub is_duration_used {
+  return !$_[0]->start_time;
+}
+
 sub displayable_times {
   my ($self) = @_;
 
-  # placeholder
-  my $ph = $::locale->format_date_object(DateTime->new(year => 1111, month => 11, day => 11, hour => 11, minute => 11), precision => 'minute');
-  $ph =~ s{1}{-}g;
-
-  return ($self->start_time_as_timestamp||$ph) . ' - ' . ($self->end_time_as_timestamp||$ph);
-}
+  my $text;
 
-sub duration {
-  my ($self) = @_;
+  if ($self->is_duration_used) {
+    $text = $self->date_as_date . ': ' . ($self->duration_as_duration_string || '--:--');
 
-  if ($self->start_time && $self->end_time) {
-    return ($self->end_time->subtract_datetime_absolute($self->start_time))->seconds/60.0;
   } else {
-    return;
+    # placeholder
+    my $ph =  $::locale->format_date_object(DateTime->new(year => 1111, month => 11, day => 11, hour => 11, minute => 11), precision => 'minute');
+    $ph    =~ s{1}{-}g;
+    $text  =  ($self->start_time_as_timestamp||$ph) . ' - ' . ($self->end_time_as_timestamp||$ph);
   }
+
+  return $text;
 }
 
 1;