Revision 3ce13f69
Von Moritz Bunkus vor etwa 12 Jahren hinzugefügt
SL/Controller/DeliveryPlan.pm | ||
---|---|---|
7 | 7 |
use SL::DB::OrderItem; |
8 | 8 |
use SL::Controller::Helper::GetModels; |
9 | 9 |
use SL::Controller::Helper::Paginated; |
10 |
use SL::Controller::Helper::Sorted; |
|
10 | 11 |
use SL::Controller::Helper::ParseFilter; |
11 | 12 |
use SL::Controller::Helper::ReportGenerator; |
12 | 13 |
|
13 |
use Rose::Object::MakeMethods::Generic |
|
14 |
( |
|
15 |
scalar => [ qw(db_args) ], |
|
14 |
use Rose::Object::MakeMethods::Generic ( |
|
15 |
scalar => [ qw(db_args flat_filter) ], |
|
16 | 16 |
); |
17 | 17 |
|
18 | 18 |
__PACKAGE__->run_before(sub { $::auth->assert('sales_order_edit'); }); |
19 | 19 |
|
20 |
__PACKAGE__->get_models_url_params(sub { |
|
21 |
my ($self) = @_; |
|
22 |
return ( |
|
23 |
%{ $self->{flat_filter} || {} }, |
|
24 |
sort_dir => $self->{sort_dir}, |
|
25 |
sort_by => $self->{sort_by}, |
|
26 |
); |
|
27 |
}); |
|
20 |
__PACKAGE__->get_models_url_params('flat_filter'); |
|
28 | 21 |
__PACKAGE__->make_paginated( |
29 | 22 |
MODEL => 'OrderItem', |
30 | 23 |
PAGINATE_ARGS => 'db_args', |
31 | 24 |
ONLY => [ qw(list) ], |
32 | 25 |
); |
33 | 26 |
|
27 |
__PACKAGE__->make_sorted( |
|
28 |
MODEL => 'OrderItem', |
|
29 |
ONLY => [ qw(list) ], |
|
30 |
|
|
31 |
DEFAULT_BY => 'reqdate', |
|
32 |
DEFAULT_DIR => 1, |
|
33 |
|
|
34 |
reqdate => 'Reqdate', |
|
35 |
description => 'Description', |
|
36 |
partnumber => 'Part Number', |
|
37 |
qty => 'Qty', |
|
38 |
missing => 'Missing qty', |
|
39 |
shipped_qty => 'shipped', |
|
40 |
ordnumber => 'Order', |
|
41 |
customer => 'Customer', |
|
42 |
); |
|
43 |
|
|
34 | 44 |
sub action_list { |
35 | 45 |
my ($self) = @_; |
36 | 46 |
my %list_params = ( |
37 |
sort_by => $::form->{sort_by} || 'reqdate', |
|
38 |
sort_dir => $::form->{sort_dir}, |
|
39 | 47 |
filter => $::form->{filter}, |
40 | 48 |
); |
41 | 49 |
|
42 | 50 |
$self->db_args($self->setup_for_list(%list_params)); |
43 |
$self->{flat_filter} = { map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') };
|
|
51 |
$self->flat_filter({ map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') });
|
|
44 | 52 |
$self->make_filter_summary; |
45 | 53 |
|
46 | 54 |
my $top = $::form->parse_html_template('delivery_plan/report_top', { FORM => $::form, SELF => $self }); |
... | ... | |
52 | 60 |
raw_bottom_info_text => $bottom, |
53 | 61 |
controller_class => 'DeliveryPlan', |
54 | 62 |
}, |
55 |
report_generator_export_options => [ |
|
56 |
'list', qw(filter sort_by sort_dir), |
|
57 |
], |
|
63 |
report_generator_export_options => [ qw(list filter sort_by sort_dir) ], |
|
58 | 64 |
); |
59 | 65 |
|
60 | 66 |
$self->{orderitems} = $self->get_models(%{ $self->db_args }); |
... | ... | |
73 | 79 |
with_objects => [ 'order', 'order.customer', 'part' ], |
74 | 80 |
launder_to => $self->{filter}, |
75 | 81 |
), |
76 |
sort_by => $self->set_sort_params(%params), |
|
77 | 82 |
); |
78 | 83 |
|
79 | 84 |
$args{query} = [ @{ $args{query} || [] }, |
... | ... | |
133 | 138 |
return \%args; |
134 | 139 |
} |
135 | 140 |
|
136 |
sub set_sort_params { |
|
137 |
my ($self, %params) = @_; |
|
138 |
my $sort_str; |
|
139 |
($self->{sort_by}, $self->{sort_dir}, $sort_str) = |
|
140 |
SL::DB::Manager::OrderItem->make_sort_string(%params); |
|
141 |
return $sort_str; |
|
142 |
} |
|
143 |
|
|
144 | 141 |
sub prepare_report { |
145 | 142 |
my ($self, %params) = @_; |
146 | 143 |
|
... | ... | |
153 | 150 |
my @sortable = qw(reqdate partnumber description ordnumber customer); |
154 | 151 |
|
155 | 152 |
my %column_defs = ( |
156 |
reqdate => { text => $::locale->text('Reqdate'), |
|
157 |
sub => sub { $_[0]->reqdate_as_date || $_[0]->order->reqdate_as_date }}, |
|
158 |
description => { text => $::locale->text('Description'), |
|
159 |
sub => sub { $_[0]->description }, |
|
160 |
obj_link => sub { $self->link_to($_[0]->part) }}, |
|
161 |
partnumber => { text => $::locale->text('Part Number'), |
|
162 |
sub => sub { $_[0]->part->partnumber }, |
|
163 |
obj_link => sub { $self->link_to($_[0]->part) }}, |
|
164 |
qty => { text => $::locale->text('Qty'), |
|
165 |
sub => sub { $_[0]->qty_as_number . ' ' . $_[0]->unit }}, |
|
166 |
missing => { text => $::locale->text('Missing qty'), |
|
167 |
sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit }}, |
|
168 |
shipped_qty => { text => $::locale->text('shipped'), |
|
169 |
sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit }}, |
|
170 |
ordnumber => { text => $::locale->text('Order'), |
|
171 |
sub => sub { $_[0]->order->ordnumber }, |
|
172 |
obj_link => sub { $self->link_to($_[0]->order) }}, |
|
173 |
customer => { text => $::locale->text('Customer'), |
|
174 |
sub => sub { $_[0]->order->customer->name }, |
|
175 |
obj_link => sub { $self->link_to($_[0]->order->customer) }}, |
|
153 |
reqdate => { sub => sub { $_[0]->reqdate_as_date || $_[0]->order->reqdate_as_date }}, |
|
154 |
description => { sub => sub { $_[0]->description }, |
|
155 |
obj_link => sub { $self->link_to($_[0]->part) }}, |
|
156 |
partnumber => { sub => sub { $_[0]->part->partnumber }, |
|
157 |
obj_link => sub { $self->link_to($_[0]->part) }}, |
|
158 |
qty => { sub => sub { $_[0]->qty_as_number . ' ' . $_[0]->unit }}, |
|
159 |
missing => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty - $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit }}, |
|
160 |
shipped_qty => { sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty, 2) . ' ' . $_[0]->unit }}, |
|
161 |
ordnumber => { sub => sub { $_[0]->order->ordnumber }, |
|
162 |
obj_link => sub { $self->link_to($_[0]->order) }}, |
|
163 |
customer => { sub => sub { $_[0]->order->customer->name }, |
|
164 |
obj_link => sub { $self->link_to($_[0]->order->customer) }}, |
|
176 | 165 |
); |
177 | 166 |
|
167 |
map { $column_defs{$_}->{text} = $::locale->text( $self->get_sort_spec->{$_}->{title} ) } keys %column_defs; |
|
168 |
|
|
169 |
my %current_sort_params = $self->get_current_sort_params; |
|
178 | 170 |
|
179 | 171 |
for my $col (@sortable) { |
180 | 172 |
$column_defs{$col}{link} = $self->get_callback( |
173 |
# TODO: column header links from helper |
|
181 | 174 |
sort_by => $col, |
182 |
sort_dir => ($self->{sort_by} eq $col ? 1 - $self->{sort_dir} : $self->{sort_dir}),
|
|
175 |
sort_dir => ($current_sort_params{by} eq $col ? 1 - $current_sort_params{dir} : $current_sort_params{dir}),
|
|
183 | 176 |
); |
184 | 177 |
} |
185 | 178 |
|
... | ... | |
188 | 181 |
$report->set_columns(%column_defs); |
189 | 182 |
$report->set_column_order(@columns); |
190 | 183 |
$report->set_options(allow_pdf_export => 1, allow_csv_export => 1); |
191 |
$report->set_sort_indicator(%params);
|
|
184 |
$report->set_sort_indicator($current_sort_params{by}, $current_sort_params{dir});
|
|
192 | 185 |
$report->set_export_options(@{ $params{report_generator_export_options} || [] }); |
193 | 186 |
$report->set_options( |
194 | 187 |
%{ $params{report_generator_options} || {} }, |
Auch abrufbar als: Unified diff
DeliveryPlan-Controller auf Sorted-Controller-Helper umstellen