From c381d6c41b2c6a0da6811525fb5a0fc5ea716975 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Tue, 4 May 2021 15:46:09 +0200 Subject: [PATCH] Zeiterfassung: Bei Projektauswahl ggf. Kunde daraus setzen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 17 +++++++++++++++++ js/kivi.TimeRecording.js | 21 ++++++++++++++++++++- templates/webpages/time_recording/form.html | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) 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()') %] -- 2.20.1