X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/4b482612c2d0ebf99050c95fdea6a1b0d22084fe..01f650056:/SL/Controller/TimeRecording.pm diff --git a/SL/Controller/TimeRecording.pm b/SL/Controller/TimeRecording.pm index 84f1814bd..b90af921f 100644 --- a/SL/Controller/TimeRecording.pm +++ b/SL/Controller/TimeRecording.pm @@ -5,10 +5,12 @@ use parent qw(SL::Controller::Base); use DateTime; use English qw(-no_match_vars); +use List::Util qw(sum0); use POSIX qw(strftime); use SL::Controller::Helper::GetModels; use SL::Controller::Helper::ReportGenerator; +use SL::Controller::Helper::ReportGenerator::ControlRow qw(make_control_row); use SL::DB::Customer; use SL::DB::Employee; use SL::DB::Order; @@ -17,7 +19,7 @@ use SL::DB::Project; use SL::DB::TimeRecording; use SL::DB::TimeRecordingArticle; use SL::Helper::Flash qw(flash); -use SL::Helper::Number qw(_round_number _parse_number); +use SL::Helper::Number qw(_round_number _parse_number _round_total); use SL::Helper::UserPreferences::TimeRecording; use SL::Locale::String qw(t8); use SL::ReportGenerator; @@ -63,7 +65,22 @@ sub action_list { $self->make_filter_summary; $self->prepare_report; - $self->report_generator_list_objects(report => $self->{report}, objects => $self->models->get); + my $objects = $self->models->get; + + my $total = sum0 map { _round_total($_->duration_in_hours) } @$objects; + my $total_h = int($total); + my $total_m = int($total * 60.0 + 0.5) % 60; + my $total_s = sprintf('%d:%02d', $total_h, $total_m); + + push @$objects, make_control_row("separator"); + push @$objects, make_control_row("data", + row => { + map( { $_ => {class => 'listtotal'} } keys %{$self->{report}->{columns}} ), + description => {data => t8('Total'), class => 'listtotal'}, + duration => {data => $total_s, class => 'listtotal'} + }); + + $self->report_generator_list_objects(report => $self->{report}, objects => $objects); } sub action_edit { @@ -165,7 +182,7 @@ sub init_time_recording { my %attributes = %{ $::form->{time_recording} || {} }; if ($self->use_duration) { - if ($::form->{duration_h} || $::form->{duration_m}) { + if (exists $::form->{duration_h} || exists $::form->{duration_m}) { $attributes{duration} = _round_number(_parse_number($::form->{duration_h}) * 60 + _parse_number($::form->{duration_m}), 0); } @@ -184,10 +201,10 @@ sub init_time_recording { } # do not overwrite staff member if you do not have the right - delete $attributes{staff_member_id} if !$_[0]->can_edit_all; - $attributes{staff_member_id} = SL::DB::Manager::Employee->current->id if $is_new; + delete $attributes{staff_member_id} if !$_[0]->can_edit_all; + $attributes{staff_member_id} ||= SL::DB::Manager::Employee->current->id if $is_new; - $attributes{employee_id} = SL::DB::Manager::Employee->current->id; + $attributes{employee_id} = SL::DB::Manager::Employee->current->id; $time_recording->assign_attributes(%attributes); @@ -276,7 +293,7 @@ sub prepare_report { order => { text => t8('Sales Order'), sub => sub { $_[0]->order && $_[0]->order->number } }, 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 } }, + project => { text => t8('Project'), sub => sub { $_[0]->project && $_[0]->project->full_description(sytle => 'both') } }, 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(?) obj_link => sub { $self->url_for(action => 'edit', 'id' => $_[0]->id, callback => $self->models->get_callback) } }, @@ -321,13 +338,17 @@ sub make_filter_summary { my $filter = $::form->{filter} || {}; my @filter_strings; - my $staff_member = $filter->{staff_member_id} ? SL::DB::Employee->new(id => $filter->{staff_member_id})->load->safe_name : ''; + my $staff_member = $filter->{staff_member_id} ? SL::DB::Employee->new(id => $filter->{staff_member_id})->load->safe_name : ''; + my $project = $filter->{project_id} ? SL::DB::Project->new (id => $filter->{project_id}) ->load->full_description(sytle => 'both') : ''; my @filters = ( - [ $filter->{"date:date::ge"}, t8('From Date') ], - [ $filter->{"date:date::le"}, t8('To Date') ], + [ $filter->{"date:date::ge"}, t8('From Date') ], + [ $filter->{"date:date::le"}, t8('To Date') ], [ $filter->{"customer"}->{"name:substr::ilike"}, t8('Customer') ], [ $filter->{"customer"}->{"customernumber:substr::ilike"}, t8('Customer Number') ], + [ $filter->{"order"}->{"ordnumber:substr::ilike"}, t8('Order Number') ], + [ $project, t8('Project') ], + [ $filter->{"description:substr::ilike"}, t8('Description') ], [ $staff_member, t8('Mitarbeiter') ], );