X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/33823a7743de188f6e37802716ee5bd877a3ec5f..c381d6c41b2c6a0da6811525fb5a0fc5ea716975:/SL/Controller/TimeRecording.pm diff --git a/SL/Controller/TimeRecording.pm b/SL/Controller/TimeRecording.pm index ed1d9b93e..e97c3c1d8 100644 --- a/SL/Controller/TimeRecording.pm +++ b/SL/Controller/TimeRecording.pm @@ -11,10 +11,13 @@ 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::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::UserPreferences::TimeRecording; use SL::Locale::String qw(t8); use SL::ReportGenerator; @@ -22,7 +25,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) ], ); @@ -34,6 +37,7 @@ my %sort_columns = ( date => t8('Date'), start_time => t8('Start'), end_time => t8('End'), + order => t8('Sales Order'), customer => t8('Customer'), part => t8('Article'), project => t8('Project'), @@ -93,8 +97,8 @@ sub action_save { my ($self) = @_; if ($self->use_duration) { - $self->time_recording->start_date(undef); - $self->time_recording->end_date(undef); + $self->time_recording->start_time(undef); + $self->time_recording->end_time(undef); } my @errors = $self->time_recording->validate; @@ -119,6 +123,37 @@ 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 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) = @_; @@ -129,7 +164,12 @@ sub init_time_recording { my %attributes = %{ $::form->{time_recording} || {} }; - if (!$self->use_duration) { + if ($self->use_duration) { + if ($::form->{duration_h} || $::form->{duration_m}) { + $attributes{duration} = _round_number(_parse_number($::form->{duration_h}) * 60 + _parse_number($::form->{duration_m}), 0); + } + + } else { foreach my $type (qw(start end)) { if ($::form->{$type . '_date'}) { my $date = DateTime->from_kivitendo($::form->{$type . '_date'}); @@ -173,7 +213,7 @@ sub init_models { sorted => \%sort_columns, disable_plugin => 'paginated', query => \@where, - with_objects => [ 'customer', 'part', 'project', 'staff_member', 'employee' ], + with_objects => [ 'customer', 'part', 'project', 'staff_member', 'employee', 'order' ], ); } @@ -196,6 +236,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(); } @@ -218,7 +263,7 @@ sub prepare_report { my $report = SL::ReportGenerator->new(\%::myconfig, $::form); $self->{report} = $report; - my @columns = qw(date start_time end_time customer part project description staff_member duration booked); + my @columns = qw(date start_time end_time order customer project part description staff_member duration booked); my %column_defs = ( date => { text => t8('Date'), sub => sub { $_[0]->date_as_date }, @@ -227,6 +272,7 @@ sub prepare_report { obj_link => sub { $self->url_for(action => 'edit', 'id' => $_[0]->id, callback => $self->models->get_callback) } }, 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) } }, + 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 } },