From: Bernd Bleßmann Date: Tue, 4 May 2021 13:46:09 +0000 (+0200) Subject: Zeiterfassung: Bei Projektauswahl ggf. Kunde daraus setzen X-Git-Tag: kivitendo-mebil_0.1-0~9^2~272 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=c381d6c41b2c6a0da6811525fb5a0fc5ea716975;p=kivitendo-erp.git Zeiterfassung: Bei Projektauswahl ggf. Kunde daraus setzen 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. --- diff --git a/SL/Controller/TimeRecording.pm b/SL/Controller/TimeRecording.pm index db8d22646..e97c3c1d8 100644 --- a/SL/Controller/TimeRecording.pm +++ b/SL/Controller/TimeRecording.pm @@ -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) = @_; diff --git a/js/kivi.TimeRecording.js b/js/kivi.TimeRecording.js index f5cf3c841..47b0f16cc 100644 --- a/js/kivi.TimeRecording.js +++ b/js/kivi.TimeRecording.js @@ -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); + } + }); + }; + }); diff --git a/templates/webpages/time_recording/form.html b/templates/webpages/time_recording/form.html index 233eb706a..9b3050b84 100644 --- a/templates/webpages/time_recording/form.html +++ b/templates/webpages/time_recording/form.html @@ -56,7 +56,7 @@ [% 'Project' | $T8 %] - [% P.project.picker('time_recording.project_id', SELF.time_recording.project_id, style='width: 300px') %] + [% P.project.picker('time_recording.project_id', SELF.time_recording.project_id, fat_set_item=1, style='width: 300px', onchange='kivi.TimeRecording.project_changed()') %]