|
1 |
package SL::Controller::PartsPriceHistory;
|
|
2 |
|
|
3 |
use strict;
|
|
4 |
use parent qw(SL::Controller::Base);
|
|
5 |
|
|
6 |
use Clone qw(clone);
|
|
7 |
use SL::DB::PartsPriceHistory;
|
|
8 |
use SL::Controller::Helper::ParseFilter;
|
|
9 |
use SL::Controller::Helper::ReportGenerator;
|
|
10 |
|
|
11 |
sub action_list {
|
|
12 |
my ($self) = @_;
|
|
13 |
$self->{action} = 'list';
|
|
14 |
|
|
15 |
my %list_params = (
|
|
16 |
sort_by => $::form->{sort_by} || 'valid_from',
|
|
17 |
sort_dir => $::form->{sort_dir},
|
|
18 |
filter => $::form->{filter},
|
|
19 |
page => $::form->{page},
|
|
20 |
);
|
|
21 |
|
|
22 |
my $db_args = $self->setup_for_list(%list_params);
|
|
23 |
$self->{pages} = SL::DB::Manager::PartsPriceHistory->paginate(%list_params, args => $db_args, per_page => 5);
|
|
24 |
|
|
25 |
my $bottom = $::form->parse_html_template('parts_price_history/report_bottom', { SELF => $self });
|
|
26 |
|
|
27 |
$self->prepare_report(
|
|
28 |
db_args => $db_args,
|
|
29 |
report_generator_options => {
|
|
30 |
raw_bottom_info_text => $bottom,
|
|
31 |
controller_class => 'PartsPriceHistory',
|
|
32 |
},
|
|
33 |
);
|
|
34 |
|
|
35 |
my $history = SL::DB::Manager::PartsPriceHistory->get_all(%{ $db_args });
|
|
36 |
|
|
37 |
$self->report_generator_list_objects(
|
|
38 |
report => $self->{report},
|
|
39 |
objects => $history,
|
|
40 |
layout => 0,
|
|
41 |
header => 0,
|
|
42 |
);
|
|
43 |
}
|
|
44 |
|
|
45 |
# private functions
|
|
46 |
|
|
47 |
sub setup_for_list {
|
|
48 |
my ($self, %params) = @_;
|
|
49 |
|
|
50 |
$self->{filter} = clone($params{filter});
|
|
51 |
|
|
52 |
my %args = (
|
|
53 |
parse_filter($self->{filter}),
|
|
54 |
sort_by => $self->set_sort_params(%params),
|
|
55 |
page => $params{page},
|
|
56 |
);
|
|
57 |
|
|
58 |
return \%args;
|
|
59 |
}
|
|
60 |
|
|
61 |
sub set_sort_params {
|
|
62 |
my ($self, %params) = @_;
|
|
63 |
|
|
64 |
my $sort_str;
|
|
65 |
($self->{sort_by}, $self->{sort_dir}, $sort_str) = SL::DB::Manager::PartsPriceHistory->make_sort_string(%params);
|
|
66 |
return $sort_str;
|
|
67 |
}
|
|
68 |
|
|
69 |
sub column_defs {
|
|
70 |
my ($self) = @_;
|
|
71 |
|
|
72 |
return {
|
|
73 |
valid_from => { text => $::locale->text('Date'), sub => sub { $_[0]->valid_from_as_timestamp }},
|
|
74 |
lastcost => { text => $::locale->text('Lastcost'), sub => sub { $_[0]->lastcost_as_number }},
|
|
75 |
listprice => { text => $::locale->text('List Price'), sub => sub { $_[0]->listprice_as_number }},
|
|
76 |
sellprice => { text => $::locale->text('Sell Price'), sub => sub { $_[0]->sellprice_as_number }},
|
|
77 |
};
|
|
78 |
}
|
|
79 |
|
|
80 |
sub prepare_report {
|
|
81 |
my ($self, %params) = @_;
|
|
82 |
|
|
83 |
my $objects = $params{objects} || [];
|
|
84 |
my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
|
|
85 |
$self->{report} = $report;
|
|
86 |
|
|
87 |
my $title = $::locale->text('Price history for master data');
|
|
88 |
|
|
89 |
my @columns = qw(valid_from lastcost listprice sellprice);
|
|
90 |
|
|
91 |
my $column_defs = $self->column_defs;
|
|
92 |
|
|
93 |
for my $col (@columns) {
|
|
94 |
$column_defs->{$col}{link} = $self->self_url(
|
|
95 |
sort_by => $col,
|
|
96 |
sort_dir => ($self->{sort_by} eq $col ? 1 - $self->{sort_dir} : $self->{sort_dir}),
|
|
97 |
page => $self->{pages}{cur},
|
|
98 |
);
|
|
99 |
}
|
|
100 |
|
|
101 |
$column_defs->{$_}{visible} = 1 for @columns;
|
|
102 |
|
|
103 |
$report->set_columns(%$column_defs);
|
|
104 |
$report->set_column_order(@columns);
|
|
105 |
$report->set_options(allow_pdf_export => 0, allow_csv_export => 0);
|
|
106 |
$report->set_sort_indicator($self->{sort_by}, $self->{sort_dir});
|
|
107 |
$report->set_export_options(@{ $params{report_generator_export_options} || [] });
|
|
108 |
$report->set_options(
|
|
109 |
%{ $params{report_generator_options} || {} },
|
|
110 |
output_format => 'HTML',
|
|
111 |
top_info_text => $self->displayable_filter($::form->{filter}),
|
|
112 |
title => $title,
|
|
113 |
);
|
|
114 |
$report->set_options_from_form;
|
|
115 |
}
|
|
116 |
|
|
117 |
sub displayable_filter {
|
|
118 |
my ($self, $filter) = @_;
|
|
119 |
|
|
120 |
my $column_defs = $self->column_defs;
|
|
121 |
my @texts;
|
|
122 |
|
|
123 |
push @texts, [ $::locale->text('Sort By'), $column_defs->{$self->{sort_by}}{text} ] if $column_defs->{$self->{sort_by}}{text};
|
|
124 |
push @texts, [ $::locale->text('Page'), $::locale->text($self->{pages}{cur}) ] if $self->{pages}{cur} > 1;
|
|
125 |
|
|
126 |
return join '; ', map { "$_->[0]: $_->[1]" } @texts;
|
|
127 |
}
|
|
128 |
|
|
129 |
sub self_url {
|
|
130 |
my ($self, %params) = @_;
|
|
131 |
|
|
132 |
%params = (
|
|
133 |
action => $self->{action},
|
|
134 |
sort_by => $self->{sort_by},
|
|
135 |
sort_dir => $self->{sort_dir},
|
|
136 |
page => $self->{pages}{cur},
|
|
137 |
filter => $::form->{filter},
|
|
138 |
%params,
|
|
139 |
);
|
|
140 |
|
|
141 |
return $self->url_for(%params);
|
|
142 |
}
|
|
143 |
|
|
144 |
1;
|
Verkaufspreisinformationen: Preisentwicklung der Stammdaten anzeigen