From 5d195a27c681ad7837ee45f1ee951f5aafc70e97 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 17 Dec 2013 16:20:19 +0100 Subject: [PATCH] Finanzcontrolling auf getmodels umgestellt --- SL/Controller/FinancialControllingReport.pm | 86 +++++++++---------- SL/DB/MetaSetup/Project.pm | 1 - SL/DB/MetaSetup/ProjectType.pm | 16 ++-- .../report_bottom.html | 2 +- 4 files changed, 47 insertions(+), 58 deletions(-) diff --git a/SL/Controller/FinancialControllingReport.pm b/SL/Controller/FinancialControllingReport.pm index b306dcd0c..bedc7623f 100644 --- a/SL/Controller/FinancialControllingReport.pm +++ b/SL/Controller/FinancialControllingReport.pm @@ -8,32 +8,17 @@ use List::Util qw(sum); use SL::DB::Order; use SL::DB::ProjectType; use SL::Controller::Helper::GetModels; -use SL::Controller::Helper::Paginated; -use SL::Controller::Helper::Sorted; -use SL::Controller::Helper::ParseFilter; use SL::Controller::Helper::ReportGenerator; use SL::Locale::String; use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(db_args flat_filter project_types) ], + scalar => [ qw(project_types) ], + 'scalar --get_set_init' => [ qw(models) ], ); __PACKAGE__->run_before(sub { $::auth->assert('sales_order_edit'); }); -__PACKAGE__->get_models_url_params('flat_filter'); -__PACKAGE__->make_paginated( - MODEL => 'Order', - PAGINATE_ARGS => 'db_args', - ONLY => [ qw(list) ], -); - -__PACKAGE__->make_sorted( - MODEL => 'Order', - ONLY => [ qw(list) ], - - DEFAULT_BY => 'globalprojectnumber', - DEFAULT_DIR => 1, - +my %sort_columns = ( ordnumber => t8('Order'), customer => t8('Customer'), transaction_description => t8('Transaction description'), @@ -47,13 +32,11 @@ sub action_list { $self->project_types(SL::DB::Manager::ProjectType->get_all_sorted); - $self->db_args($self->setup_db_args_for_list(filter => $::form->{filter})); - $self->flat_filter({ map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') }); $self->make_filter_summary; $self->prepare_report; - $self->{orders} = $self->get_models(%{ $self->db_args }); + $self->{orders} = $self->models->get; $self->calculate_data; @@ -62,26 +45,6 @@ sub action_list { # private functions -sub setup_db_args_for_list { - my ($self) = @_; - - $self->{filter} = {}; - my %args = ( parse_filter($::form->{filter}, with_objects => [ 'customer', 'globalproject', 'globalproject.project_type' ], launder_to => $self->{filter})); - $args{query} = [ - @{ $args{query} || [] }, - SL::DB::Manager::Order->type_filter('sales_order'), - '!closed' => 1, - or => [ - globalproject_id => undef, - and => [ - 'globalproject.active' => 1, - 'globalproject.valid' => 1, - ]], - ]; - - return \%args; -} - sub prepare_report { my ($self) = @_; @@ -113,7 +76,7 @@ sub prepare_report { sub => sub { $_[0]->globalproject_id ? $_[0]->globalproject->project_type->description : '' } }, ); - map { $column_defs{$_}->{text} ||= $::locale->text( $self->get_sort_spec->{$_}->{title} ) } keys %column_defs; + map { $column_defs{$_}->{text} ||= $::locale->text( $self->models->get_sort_spec->{$_}->{title} ) } keys %column_defs; map { $column_defs{$_}->{align} = 'right' } @{ $self->{number_columns} }; $report->set_options( @@ -121,8 +84,6 @@ sub prepare_report { controller_class => 'FinancialControllingReport', output_format => 'HTML', top_info_text => $::locale->text('Financial controlling report for open sales orders'), - raw_top_info_text => $self->render('financial_controlling_report/report_top', { output => 0 }), - raw_bottom_info_text => $self->render('financial_controlling_report/report_bottom', { output => 0 }), title => $::locale->text('Financial Controlling Report'), allow_pdf_export => 1, allow_csv_export => 1, @@ -131,9 +92,13 @@ sub prepare_report { $report->set_column_order(@columns); $report->set_export_options(qw(list filter)); $report->set_options_from_form; - $self->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); - - $self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i; + $self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i; + $self->models->finalize; + $self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); + $report->set_options( + raw_top_info_text => $self->render('financial_controlling_report/report_top', { output => 0 }), + raw_bottom_info_text => $self->render('financial_controlling_report/report_bottom', { output => 0 }, models => $self->models), + ); } sub calculate_data { @@ -232,6 +197,33 @@ sub make_filter_summary { $self->{filter_summary} = join ', ', @filter_strings; } +sub init_models { + my ($self) = @_; + + SL::Controller::Helper::GetModels->new( + controller => $self, + model => 'Order', + sorted => { + _default => { + by => 'globalprojectnumber', + dir => 1, + }, + %sort_columns, + }, + query => [ + SL::DB::Manager::Order->type_filter('sales_order'), + '!closed' => 1, + or => [ + globalproject_id => undef, + and => [ + 'globalproject.active' => 1, + 'globalproject.valid' => 1, + ]], + ], + with_objects => [ 'customer', 'globalproject', 'globalproject.project_type' ], + ); +} + sub link_to { my ($self, $object, %params) = @_; diff --git a/SL/DB/MetaSetup/Project.pm b/SL/DB/MetaSetup/Project.pm index 0524fb679..51315358c 100644 --- a/SL/DB/MetaSetup/Project.pm +++ b/SL/DB/MetaSetup/Project.pm @@ -17,7 +17,6 @@ __PACKAGE__->meta->columns( mtime => { type => 'timestamp' }, project_type_id => { type => 'integer', not_null => 1 }, projectnumber => { type => 'text' }, - type => { type => 'text' }, valid => { type => 'boolean', default => 'true' }, ); diff --git a/SL/DB/MetaSetup/ProjectType.pm b/SL/DB/MetaSetup/ProjectType.pm index 5608f291f..3d452ccc8 100644 --- a/SL/DB/MetaSetup/ProjectType.pm +++ b/SL/DB/MetaSetup/ProjectType.pm @@ -6,17 +6,15 @@ use strict; use base qw(SL::DB::Object); -__PACKAGE__->meta->setup( - table => 'project_types', +__PACKAGE__->meta->table('project_types'); - columns => [ - id => { type => 'serial', not_null => 1 }, - position => { type => 'integer', not_null => 1 }, - description => { type => 'text' }, - ], - - primary_key_columns => [ 'id' ], +__PACKAGE__->meta->columns( + description => { type => 'text' }, + id => { type => 'serial', not_null => 1 }, + position => { type => 'integer', not_null => 1 }, ); +__PACKAGE__->meta->primary_key_columns([ 'id' ]); + 1; ; diff --git a/templates/webpages/financial_controlling_report/report_bottom.html b/templates/webpages/financial_controlling_report/report_bottom.html index 79e152304..da08e0758 100644 --- a/templates/webpages/financial_controlling_report/report_bottom.html +++ b/templates/webpages/financial_controlling_report/report_bottom.html @@ -1,2 +1,2 @@ [% USE L %] -[%- L.paginate_controls %] +[%- L.paginate_controls(models=models) %] -- 2.20.1