Zeiterfassung: Bei Projektauswahl ggf. Kunde daraus setzen
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Tue, 4 May 2021 13:46:09 +0000 (15:46 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 5 May 2021 15:25:04 +0000 (17:25 +0200)
Wenn ein Projekt ausgewählt wird und dieses einen Kunden zugeordnet hat,
so wird der Kunde daraus gesetzt und das Kunden-Feld gesperrt.

Wenn kein Projekt gewählt ist (oder eines wieder abgewählt wird,
dann ist Kunde wieder frei.

SL/Controller/TimeRecording.pm
js/kivi.TimeRecording.js
templates/webpages/time_recording/form.html

index db8d226..e97c3c1 100644 (file)
@@ -13,6 +13,7 @@ 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);
@@ -137,6 +138,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) = @_;
 
index f5cf3c8..47b0f16 100644 (file)
@@ -25,7 +25,7 @@ namespace('kivi.TimeRecording', function(ns) {
       $('#time_recording_customer_id_name').prop('disabled', false);
       $('#time_recording_project_id').data('project_picker').set_item({});
       $('#time_recording_project_id_name').prop('disabled', false);
-        return;
+      return;
     }
 
     var url = 'controller.pl?action=TimeRecording/ajaj_get_order_info&id='+ value;
@@ -37,4 +37,23 @@ namespace('kivi.TimeRecording', function(ns) {
     });
   };
 
+  ns.project_changed = function() {
+    var project_id = $('#time_recording_project_id').val();
+
+    if (!project_id) {
+      $('#time_recording_customer_id_name').prop('disabled', false);
+      return;
+    }
+
+    var url = 'controller.pl?action=TimeRecording/ajaj_get_project_info&id='+ project_id;
+    $.getJSON(url, function(data) {
+      if (data) {
+        $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer);
+        $('#time_recording_customer_id_name').prop('disabled', true);
+      } else {
+        $('#time_recording_customer_id_name').prop('disabled', false);
+      }
+    });
+  };
+
 });
index 233eb70..9b3050b 100644 (file)
@@ -56,7 +56,7 @@
     </tr>
     <tr>
       <th align="right">[% 'Project' | $T8 %]</th>
-      <td>[% P.project.picker('time_recording.project_id', SELF.time_recording.project_id, style='width: 300px') %]</td>
+      <td>[% P.project.picker('time_recording.project_id', SELF.time_recording.project_id, fat_set_item=1, style='width: 300px', onchange='kivi.TimeRecording.project_changed()') %]</td>
     </tr>
     <tr></tr><tr></tr>
     <tr>