Revision 5d195a27
Von Sven Schöling vor fast 11 Jahren hinzugefügt
SL/Controller/FinancialControllingReport.pm | ||
---|---|---|
8 | 8 |
use SL::DB::Order; |
9 | 9 |
use SL::DB::ProjectType; |
10 | 10 |
use SL::Controller::Helper::GetModels; |
11 |
use SL::Controller::Helper::Paginated; |
|
12 |
use SL::Controller::Helper::Sorted; |
|
13 |
use SL::Controller::Helper::ParseFilter; |
|
14 | 11 |
use SL::Controller::Helper::ReportGenerator; |
15 | 12 |
use SL::Locale::String; |
16 | 13 |
|
17 | 14 |
use Rose::Object::MakeMethods::Generic ( |
18 |
scalar => [ qw(db_args flat_filter project_types) ], |
|
15 |
scalar => [ qw(project_types) ], |
|
16 |
'scalar --get_set_init' => [ qw(models) ], |
|
19 | 17 |
); |
20 | 18 |
|
21 | 19 |
__PACKAGE__->run_before(sub { $::auth->assert('sales_order_edit'); }); |
22 | 20 |
|
23 |
__PACKAGE__->get_models_url_params('flat_filter'); |
|
24 |
__PACKAGE__->make_paginated( |
|
25 |
MODEL => 'Order', |
|
26 |
PAGINATE_ARGS => 'db_args', |
|
27 |
ONLY => [ qw(list) ], |
|
28 |
); |
|
29 |
|
|
30 |
__PACKAGE__->make_sorted( |
|
31 |
MODEL => 'Order', |
|
32 |
ONLY => [ qw(list) ], |
|
33 |
|
|
34 |
DEFAULT_BY => 'globalprojectnumber', |
|
35 |
DEFAULT_DIR => 1, |
|
36 |
|
|
21 |
my %sort_columns = ( |
|
37 | 22 |
ordnumber => t8('Order'), |
38 | 23 |
customer => t8('Customer'), |
39 | 24 |
transaction_description => t8('Transaction description'), |
... | ... | |
47 | 32 |
|
48 | 33 |
$self->project_types(SL::DB::Manager::ProjectType->get_all_sorted); |
49 | 34 |
|
50 |
$self->db_args($self->setup_db_args_for_list(filter => $::form->{filter})); |
|
51 |
$self->flat_filter({ map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') }); |
|
52 | 35 |
$self->make_filter_summary; |
53 | 36 |
|
54 | 37 |
$self->prepare_report; |
55 | 38 |
|
56 |
$self->{orders} = $self->get_models(%{ $self->db_args });
|
|
39 |
$self->{orders} = $self->models->get;
|
|
57 | 40 |
|
58 | 41 |
$self->calculate_data; |
59 | 42 |
|
... | ... | |
62 | 45 |
|
63 | 46 |
# private functions |
64 | 47 |
|
65 |
sub setup_db_args_for_list { |
|
66 |
my ($self) = @_; |
|
67 |
|
|
68 |
$self->{filter} = {}; |
|
69 |
my %args = ( parse_filter($::form->{filter}, with_objects => [ 'customer', 'globalproject', 'globalproject.project_type' ], launder_to => $self->{filter})); |
|
70 |
$args{query} = [ |
|
71 |
@{ $args{query} || [] }, |
|
72 |
SL::DB::Manager::Order->type_filter('sales_order'), |
|
73 |
'!closed' => 1, |
|
74 |
or => [ |
|
75 |
globalproject_id => undef, |
|
76 |
and => [ |
|
77 |
'globalproject.active' => 1, |
|
78 |
'globalproject.valid' => 1, |
|
79 |
]], |
|
80 |
]; |
|
81 |
|
|
82 |
return \%args; |
|
83 |
} |
|
84 |
|
|
85 | 48 |
sub prepare_report { |
86 | 49 |
my ($self) = @_; |
87 | 50 |
|
... | ... | |
113 | 76 |
sub => sub { $_[0]->globalproject_id ? $_[0]->globalproject->project_type->description : '' } }, |
114 | 77 |
); |
115 | 78 |
|
116 |
map { $column_defs{$_}->{text} ||= $::locale->text( $self->get_sort_spec->{$_}->{title} ) } keys %column_defs; |
|
79 |
map { $column_defs{$_}->{text} ||= $::locale->text( $self->models->get_sort_spec->{$_}->{title} ) } keys %column_defs;
|
|
117 | 80 |
map { $column_defs{$_}->{align} = 'right' } @{ $self->{number_columns} }; |
118 | 81 |
|
119 | 82 |
$report->set_options( |
... | ... | |
121 | 84 |
controller_class => 'FinancialControllingReport', |
122 | 85 |
output_format => 'HTML', |
123 | 86 |
top_info_text => $::locale->text('Financial controlling report for open sales orders'), |
124 |
raw_top_info_text => $self->render('financial_controlling_report/report_top', { output => 0 }), |
|
125 |
raw_bottom_info_text => $self->render('financial_controlling_report/report_bottom', { output => 0 }), |
|
126 | 87 |
title => $::locale->text('Financial Controlling Report'), |
127 | 88 |
allow_pdf_export => 1, |
128 | 89 |
allow_csv_export => 1, |
... | ... | |
131 | 92 |
$report->set_column_order(@columns); |
132 | 93 |
$report->set_export_options(qw(list filter)); |
133 | 94 |
$report->set_options_from_form; |
134 |
$self->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); |
|
135 |
|
|
136 |
$self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i; |
|
95 |
$self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i; |
|
96 |
$self->models->finalize; |
|
97 |
$self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); |
|
98 |
$report->set_options( |
|
99 |
raw_top_info_text => $self->render('financial_controlling_report/report_top', { output => 0 }), |
|
100 |
raw_bottom_info_text => $self->render('financial_controlling_report/report_bottom', { output => 0 }, models => $self->models), |
|
101 |
); |
|
137 | 102 |
} |
138 | 103 |
|
139 | 104 |
sub calculate_data { |
... | ... | |
232 | 197 |
$self->{filter_summary} = join ', ', @filter_strings; |
233 | 198 |
} |
234 | 199 |
|
200 |
sub init_models { |
|
201 |
my ($self) = @_; |
|
202 |
|
|
203 |
SL::Controller::Helper::GetModels->new( |
|
204 |
controller => $self, |
|
205 |
model => 'Order', |
|
206 |
sorted => { |
|
207 |
_default => { |
|
208 |
by => 'globalprojectnumber', |
|
209 |
dir => 1, |
|
210 |
}, |
|
211 |
%sort_columns, |
|
212 |
}, |
|
213 |
query => [ |
|
214 |
SL::DB::Manager::Order->type_filter('sales_order'), |
|
215 |
'!closed' => 1, |
|
216 |
or => [ |
|
217 |
globalproject_id => undef, |
|
218 |
and => [ |
|
219 |
'globalproject.active' => 1, |
|
220 |
'globalproject.valid' => 1, |
|
221 |
]], |
|
222 |
], |
|
223 |
with_objects => [ 'customer', 'globalproject', 'globalproject.project_type' ], |
|
224 |
); |
|
225 |
} |
|
226 |
|
|
235 | 227 |
sub link_to { |
236 | 228 |
my ($self, $object, %params) = @_; |
237 | 229 |
|
Auch abrufbar als: Unified diff
Finanzcontrolling auf getmodels umgestellt