From 2e6998c4284851d5f0b905d43952765954ddc5af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Tue, 29 Dec 2020 15:51:46 +0100 Subject: [PATCH] =?utf8?q?Zeiterfassung:=20Artikel=20beim=20Erfassen=20w?= =?utf8?q?=C3=A4hlen=20k=C3=B6nnen=20und=20mit=20auflisten?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/TimeRecording.pm | 33 ++++++++++++++++----- templates/webpages/time_recording/form.html | 2 ++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/SL/Controller/TimeRecording.pm b/SL/Controller/TimeRecording.pm index e3e2aabbc..1e4ef4578 100644 --- a/SL/Controller/TimeRecording.pm +++ b/SL/Controller/TimeRecording.pm @@ -11,14 +11,16 @@ use SL::Controller::Helper::GetModels; use SL::Controller::Helper::ReportGenerator; use SL::DB::Customer; use SL::DB::Employee; +use SL::DB::Part; use SL::DB::TimeRecording; +use SL::DB::TimeRecordingArticle; use SL::Locale::String qw(t8); use SL::ReportGenerator; use Rose::Object::MakeMethods::Generic ( # scalar => [ qw() ], - 'scalar --get_set_init' => [ qw(time_recording models all_employees can_view_all can_edit_all) ], + 'scalar --get_set_init' => [ qw(time_recording models all_employees all_time_recording_articles can_view_all can_edit_all) ], ); @@ -26,20 +28,21 @@ use Rose::Object::MakeMethods::Generic __PACKAGE__->run_before('check_auth'); __PACKAGE__->run_before('check_auth_edit', only => [ qw(edit save delete) ]); -# -# actions -# - my %sort_columns = ( start_time => t8('Start'), end_time => t8('End'), customer => t8('Customer'), + part => t8('Article'), project => t8('Project'), description => t8('Description'), staff_member => t8('Mitarbeiter'), duration => t8('Duration'), ); +# +# actions +# + sub action_list { my ($self, %params) = @_; @@ -150,7 +153,7 @@ sub init_models { sorted => \%sort_columns, disable_plugin => 'paginated', query => \@where, - with_objects => [ 'customer', 'project', 'staff_member', 'employee' ], + with_objects => [ 'customer', 'part', 'project', 'staff_member', 'employee' ], ); } @@ -158,6 +161,21 @@ sub init_all_employees { SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]); } +sub init_all_time_recording_articles { + my $selectable_parts = SL::DB::Manager::TimeRecordingArticle->get_all_sorted( + query => [or => [ 'part.obsolete' => 0, 'part.obsolete' => undef ]], + with_objects => ['part']); + + my $res = [ map { {id => $_->part_id, description => $_->part->displayable_name} } @$selectable_parts]; + my $curr_id = $_[0]->time_recording->part_id; + + if ($curr_id && !grep { $curr_id == $_->{id} } @$res) { + unshift @$res, {id => $curr_id, description => $_[0]->time_recording->part->displayable_name}; + } + + return $res; +} + sub check_auth { $::auth->assert('time_recording'); } @@ -176,7 +194,7 @@ sub prepare_report { my $report = SL::ReportGenerator->new(\%::myconfig, $::form); $self->{report} = $report; - my @columns = qw(start_time end_time customer project description staff_member duration); + my @columns = qw(start_time end_time customer part project description staff_member duration); my %column_defs = ( start_time => { text => t8('Start'), sub => sub { $_[0]->start_time_as_timestamp }, @@ -184,6 +202,7 @@ sub prepare_report { end_time => { text => t8('End'), sub => sub { $_[0]->end_time_as_timestamp }, obj_link => sub { $self->url_for(action => 'edit', 'id' => $_[0]->id, callback => $self->models->get_callback) } }, customer => { text => t8('Customer'), sub => sub { $_[0]->customer->displayable_name } }, + part => { text => t8('Article'), sub => sub { $_[0]->part && $_[0]->part->displayable_name } }, project => { text => t8('Project'), sub => sub { $_[0]->project && $_[0]->project->displayable_name } }, description => { text => t8('Description'), sub => sub { $_[0]->description_as_stripped_html }, raw_data => sub { $_[0]->description_as_restricted_html }, # raw_data only used for html(?) diff --git a/templates/webpages/time_recording/form.html b/templates/webpages/time_recording/form.html index 08a871f97..32207b538 100644 --- a/templates/webpages/time_recording/form.html +++ b/templates/webpages/time_recording/form.html @@ -18,6 +18,7 @@ [% 'Start' | $T8 %] [% 'End' | $T8 %] [% 'Customer' | $T8 %] + [% 'Article' | $T8 %] [% 'Project' | $T8 %] [% 'Description' | $T8 %] [% 'Mitarbeiter' | $T8 %] @@ -36,6 +37,7 @@ [% P.button_tag('kivi.TimeRecording.set_current_date_time("end")', LxERP.t8('now')) %] [% 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') %] [% L.textarea_tag('time_recording.description', SELF.time_recording.description, wrap="soft", style="width: 350px; height: 150px", class="texteditor", "data-validate"="required", "data-title"=LxERP.t8('Description')) %] -- 2.20.1