From 078bb016bca38979f722bf94b8a4d006f5b57077 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Thu, 29 Apr 2021 14:19:46 +0200 Subject: [PATCH] =?utf8?q?Zeiterfassung:=20Auftrag=20ausw=C3=A4hlen=20k?= =?utf8?q?=C3=B6nnen,=20Kunden=20und=20ggf.=20Projekt=20daraus=20setzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Auftrag hat Vorrang und setzt Kunde und Projekt. Diese Felder sind dann gesperrt. Wenn kein Auftrag gewählt ist (oder einer wieder abgtewählt wird, dann ist Kunde und Projekt wieder frei. --- SL/Controller/TimeRecording.pm | 23 ++++++++++++++++++++- js/kivi.TimeRecording.js | 18 ++++++++++++++++ templates/webpages/time_recording/form.html | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/SL/Controller/TimeRecording.pm b/SL/Controller/TimeRecording.pm index ed1d9b93e..709b6b672 100644 --- a/SL/Controller/TimeRecording.pm +++ b/SL/Controller/TimeRecording.pm @@ -11,6 +11,7 @@ use SL::Controller::Helper::GetModels; use SL::Controller::Helper::ReportGenerator; use SL::DB::Customer; use SL::DB::Employee; +use SL::DB::Order; use SL::DB::Part; use SL::DB::TimeRecording; use SL::DB::TimeRecordingArticle; @@ -22,7 +23,7 @@ use SL::ReportGenerator; use Rose::Object::MakeMethods::Generic ( # scalar => [ qw() ], - 'scalar --get_set_init' => [ qw(time_recording models all_employees all_time_recording_articles can_view_all can_edit_all use_duration) ], + 'scalar --get_set_init' => [ qw(time_recording models all_employees all_time_recording_articles all_orders can_view_all can_edit_all use_duration) ], ); @@ -119,6 +120,21 @@ sub action_delete { $self->redirect_to(safe_callback()); } +sub action_ajaj_get_order_info { + + my $order = SL::DB::Order->new(id => $::form->{id})->load; + my $data = { customer => { id => $order->customer_id, + value => $order->customer->displayable_name, + type => 'customer' + }, + project => { id => $order->globalproject_id, + value => ($order->globalproject_id ? $order->globalproject->displayable_name : undef), + }, + }; + + $_[0]->render(\SL::JSON::to_json($data), { type => 'json', process => 0 }); +} + sub init_time_recording { my ($self) = @_; @@ -196,6 +212,11 @@ sub init_all_time_recording_articles { return $res; } +sub init_all_orders { + SL::DB::Manager::Order->get_all_sorted(query => [or => [ closed => 0, closed => undef ], + '!customer_id' => undef]); +} + sub init_use_duration { return SL::Helper::UserPreferences::TimeRecording->new()->get_use_duration(); } diff --git a/js/kivi.TimeRecording.js b/js/kivi.TimeRecording.js index cf5014905..f5cf3c841 100644 --- a/js/kivi.TimeRecording.js +++ b/js/kivi.TimeRecording.js @@ -19,4 +19,22 @@ namespace('kivi.TimeRecording', function(ns) { $time.val(kivi.format_time(date)); }; + ns.order_changed = function(value) { + if (!value) { + $('#time_recording_customer_id').data('customer_vendor_picker').set_item({}); + $('#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; + } + + var url = 'controller.pl?action=TimeRecording/ajaj_get_order_info&id='+ value; + $.getJSON(url, function(data) { + $('#time_recording_customer_id').data('customer_vendor_picker').set_item(data.customer); + $('#time_recording_customer_id_name').prop('disabled', true); + $('#time_recording_project_id').data('project_picker').set_item(data.project); + $('#time_recording_project_id_name').prop('disabled', true); + }); + }; + }); diff --git a/templates/webpages/time_recording/form.html b/templates/webpages/time_recording/form.html index 99e9c0f00..7c2e3d57a 100644 --- a/templates/webpages/time_recording/form.html +++ b/templates/webpages/time_recording/form.html @@ -22,6 +22,7 @@ [% 'Start' | $T8 %] [% 'End' | $T8 %] [%- END %] + [% 'Sales Order' | $T8 %] [% 'Customer' | $T8 %] [% 'Article' | $T8 %] [% 'Project' | $T8 %] @@ -50,6 +51,7 @@ [% P.button_tag('kivi.TimeRecording.set_current_date_time("end")', LxERP.t8('now')) %] [%- END %] + [% P.select_tag('time_recording.order_id', SELF.all_orders, default=SELF.time_recording.order_id, title_key='digest', with_empty=1, onchange='kivi.TimeRecording.order_changed(this.value)') %] [% P.customer_vendor.picker('time_recording.customer_id', SELF.time_recording.customer_id, type='customer', style='width: 300px', "data-validate"="required", "data-title"=LxERP.t8('Customer')) %] [% P.select_tag('time_recording.part_id', SELF.all_time_recording_articles, default=SELF.time_recording.part_id, with_empty=1, value_key='id', title_key='description') %] [% P.project.picker('time_recording.project_id', SELF.time_recording.project_id, style='width: 300px') %] -- 2.20.1