X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FProject.pm;h=59e1034b8311d6fda3496ad652bae7fb7ab9179f;hb=826d79929635c726f7459296fafa7e630c00e72d;hp=9a75836fe1f3405630bc6a575c487d30aacf9a83;hpb=e5d70ebcb6b7c240378ac5b1a04f12716e15ab33;p=kivitendo-erp.git diff --git a/SL/Controller/Project.pm b/SL/Controller/Project.pm index 9a75836fe..59e1034b8 100644 --- a/SL/Controller/Project.pm +++ b/SL/Controller/Project.pm @@ -28,8 +28,8 @@ use Rose::DB::Object::Helpers qw(as_tree); use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(project linked_records) ], - 'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects) ], + scalar => [ qw(project) ], + 'scalar --get_set_init' => [ qw(models customers project_types project_statuses projects linked_records) ], ); __PACKAGE__->run_before('check_auth', except => [ qw(ajax_autocomplete) ]); @@ -51,12 +51,16 @@ sub action_search { include_prefix => 'l_', include_value => 'Y'); + $self->setup_search_action_bar; + $self->render('project/search', %params); } sub action_list { my ($self) = @_; + $self->setup_search_action_bar; + $self->make_filter_summary; $self->prepare_report; @@ -69,15 +73,14 @@ sub action_new { $self->project(SL::DB::Project->new); $self->display_form(title => $::locale->text('Create a new project'), - callback => $::form->{callback} || $self->url_for(action => 'new')); + callback => $::form->{callback} || $self->url_for(action => 'list')); } sub action_edit { my ($self) = @_; - $self->get_linked_records; $self->display_form(title => $::locale->text('Edit project #1', $self->project->projectnumber), - callback => $::form->{callback} || $self->url_for(action => 'edit', id => $self->project->id)); + callback => $::form->{callback} || $self->url_for(action => 'list')); } sub action_create { @@ -117,8 +120,7 @@ sub action_ajax_autocomplete { my $exact_matches; if (1 == scalar @{ $exact_matches = SL::DB::Manager::Project->get_all( query => [ - obsolete => 0, - SL::DB::Manager::Project->type_filter($::form->{filter}{type}), + valid => 1, or => [ description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, projectnumber => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, @@ -165,6 +167,47 @@ sub check_auth { sub init_project_statuses { SL::DB::Manager::ProjectStatus->get_all_sorted } sub init_project_types { SL::DB::Manager::ProjectType->get_all_sorted } +sub init_linked_records { + my ($self) = @_; + return [ + map { @{ $_ } } + grep { $_ } ( + SL::DB::Manager::Invoice-> get_all(where => [ invoice => 1, or => [ globalproject_id => $self->project->id, 'invoiceitems.project_id' => $self->project->id ] ], + with_objects => [ 'invoiceitems', 'customer' ], + distinct => [ 'customer' ], + sort_by => 'transdate ASC'), + SL::DB::Manager::Invoice-> get_all(where => [ invoice => 0, or => [ globalproject_id => $self->project->id, 'transactions.project_id' => $self->project->id ] ], + with_objects => [ 'transactions', 'customer' ], + distinct => [ 'customer' ], + sort_by => 'transdate ASC'), + SL::DB::Manager::PurchaseInvoice->get_all(where => [ invoice => 1, + or => [ globalproject_id => $self->project->id, 'invoiceitems.project_id' => $self->project->id ] + ], + with_objects => [ 'invoiceitems', 'vendor' ], + distinct => [ 'customer' ], + sort_by => 'transdate ASC'), + SL::DB::Manager::PurchaseInvoice->get_all(where => [ invoice => 0, + or => [ globalproject_id => $self->project->id, 'transactions.project_id' => $self->project->id ] + ], + with_objects => [ 'transactions', 'vendor' ], + distinct => [ 'customer' ], + sort_by => 'transdate ASC'), + SL::DB::Manager::GLTransaction-> get_all(where => [ 'transactions.project_id' => $self->project->id ], + with_objects => [ 'transactions' ], + distinct => 1, + sort_by => 'transdate ASC'), + SL::DB::Manager::Order-> get_all(where => [ or => [ globalproject_id => $self->project->id, 'orderitems.project_id' => $self->project->id ] ], + with_objects => [ 'orderitems', 'customer', 'vendor' ], + distinct => [ 'customer', 'vendor' ], + sort_by => 'transdate ASC' ), + SL::DB::Manager::DeliveryOrder-> get_all(where => [ or => [ globalproject_id => $self->project->id, 'orderitems.project_id' => $self->project->id ] ], + with_objects => [ 'orderitems', 'customer', 'vendor' ], + distinct => [ 'customer', 'vendor' ], + sort_by => 'transdate ASC'), + )]; +} + + sub init_projects { if ($::form->{no_paginate}) { $_[0]->models->disable_plugin('paginated'); @@ -193,6 +236,8 @@ sub display_form { CVar->render_inputs(variables => $params{CUSTOM_VARIABLES}) if @{ $params{CUSTOM_VARIABLES} }; + $self->setup_edit_action_bar(callback => $params{callback}); + $self->render('project/form', %params); } @@ -234,18 +279,6 @@ sub load_project { $self->project(SL::DB::Project->new(id => $::form->{id})->load); } -sub get_linked_records { - my ($self) = @_; - - $self->linked_records([ - map { @{ $_ } } - grep { $_ } ( - SL::DB::Manager::Order-> get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer', 'vendor' ], sort_by => 'transdate ASC'), - SL::DB::Manager::DeliveryOrder-> get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer', 'vendor' ], sort_by => 'transdate ASC'), - SL::DB::Manager::Invoice-> get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer' ], sort_by => 'transdate ASC'), - SL::DB::Manager::PurchaseInvoice->get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'vendor' ], sort_by => 'transdate ASC'), - )]); -} sub prepare_report { my ($self) = @_; @@ -345,4 +378,60 @@ sub make_filter_summary { $self->{filter_summary} = join ', ', @filter_strings; } + +sub setup_edit_action_bar { + my ($self, %params) = @_; + + my $is_new = !$self->project->id; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + combobox => [ + action => [ + t8('Save'), + submit => [ '#form', { action => 'Project/' . ($is_new ? 'create' : 'update') } ], + accesskey => 'enter', + ], + action => [ + t8('Save as new'), + submit => [ '#form', { action => 'Project/create' }], + disabled => $is_new ? t8('The object has not been saved yet.') : undef, + ], + ], # end of combobox "Save" + + action => [ + t8('Delete'), + submit => [ '#form', { action => 'Project/destroy' } ], + confirm => $::locale->text('Do you really want to delete this object?'), + disabled => $is_new ? t8('This object has not been saved yet.') + : $self->project->is_used ? t8('This object has already been used.') + : undef, + ], + + link => [ + t8('Abort'), + link => $params{callback} || $self->url_for(action => 'list'), + ], + ); + } +} + +sub setup_search_action_bar { + my ($self, %params) = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Update'), + submit => [ '#search_form', { action => 'Project/list' } ], + accesskey => 'enter', + ], + link => [ + t8('Add'), + link => $self->url_for(action => 'new'), + ], + ); + } +} + 1;