Zeiterfassung: Dauer und Min mit Attribut Placeholder vorbelegen
[kivitendo-erp.git] / SL / Controller / TimeRecording.pm
index db8d226..d1120ce 100644 (file)
@@ -13,10 +13,11 @@ use SL::DB::Customer;
 use SL::DB::Employee;
 use SL::DB::Order;
 use SL::DB::Part;
+use SL::DB::Project;
 use SL::DB::TimeRecording;
 use SL::DB::TimeRecordingArticle;
 use SL::Helper::Flash qw(flash);
-use SL::Helper::Number qw(_round_number _parse_number);
+use SL::Helper::Number qw(_round_number _parse_number _format_total);
 use SL::Helper::UserPreferences::TimeRecording;
 use SL::Locale::String qw(t8);
 use SL::ReportGenerator;
@@ -89,6 +90,7 @@ sub action_edit {
 
   $self->render('time_recording/form',
                 title  => t8('Time Recording'),
+                ZERO   => _format_total(0.00),
   );
 }
 
@@ -137,6 +139,22 @@ sub action_ajaj_get_order_info {
   $_[0]->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
 }
 
+sub action_ajaj_get_project_info {
+
+  my $project = SL::DB::Project->new(id => $::form->{id})->load;
+
+  my $data;
+  if ($project->customer_id) {
+    $data = { customer => { id    => $project->customer_id,
+                            value => $project->customer->displayable_name,
+                            type  => 'customer'
+                          },
+    };
+  }
+
+  $_[0]->render(\SL::JSON::to_json($data), { type => 'json', process => 0 });
+}
+
 sub init_time_recording {
   my ($self) = @_;
 
@@ -148,7 +166,7 @@ sub init_time_recording {
   my %attributes = %{ $::form->{time_recording} || {} };
 
   if ($self->use_duration) {
-    if ($::form->{duration_h} || $::form->{duration_m}) {
+    if (exists $::form->{duration_h} || exists $::form->{duration_m}) {
       $attributes{duration} = _round_number(_parse_number($::form->{duration_h}) * 60 + _parse_number($::form->{duration_m}), 0);
     }
 
@@ -220,8 +238,9 @@ sub init_all_time_recording_articles {
 }
 
 sub init_all_orders {
-  SL::DB::Manager::Order->get_all_sorted(query => [or             => [ closed => 0, closed => undef ],
-                                                   '!customer_id' => undef]);
+  my $orders = SL::DB::Manager::Order->get_all(query => [or             => [ closed => 0, closed => undef ],
+                                                         '!customer_id' => undef]);
+  return [ map { [$_->id, sprintf("%s %s", $_->number, $_->customervendor->name) ] } sort { $a->number <=> $b->number } @{$orders||[]} ];
 }
 
 sub init_use_duration {