1 package SL::Controller::PartsPriceHistory;
4 use parent qw(SL::Controller::Base);
7 use SL::DB::PartsPriceHistory;
8 use SL::Controller::Helper::ParseFilter;
9 use SL::Controller::Helper::ReportGenerator;
13 $self->{action} = 'list';
16 sort_by => $::form->{sort_by} || 'valid_from',
17 sort_dir => $::form->{sort_dir},
18 filter => $::form->{filter},
19 page => $::form->{page},
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);
25 my $bottom = $::form->parse_html_template('parts_price_history/report_bottom', { SELF => $self });
27 $self->prepare_report(
29 report_generator_options => {
30 raw_bottom_info_text => $bottom,
31 controller_class => 'PartsPriceHistory',
35 my $history = SL::DB::Manager::PartsPriceHistory->get_all(%{ $db_args });
37 $self->report_generator_list_objects(
38 report => $self->{report},
48 my ($self, %params) = @_;
50 $self->{filter} = clone($params{filter});
53 parse_filter($self->{filter}),
54 sort_by => $self->set_sort_params(%params),
55 page => $params{page},
62 my ($self, %params) = @_;
65 ($self->{sort_by}, $self->{sort_dir}, $sort_str) = SL::DB::Manager::PartsPriceHistory->make_sort_string(%params);
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 }},
81 my ($self, %params) = @_;
83 my $objects = $params{objects} || [];
84 my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
85 $self->{report} = $report;
87 my $title = $::locale->text('Price history for master data');
89 my @columns = qw(valid_from lastcost listprice sellprice);
91 my $column_defs = $self->column_defs;
93 for my $col (@columns) {
94 $column_defs->{$col}{link} = $self->self_url(
96 sort_dir => ($self->{sort_by} eq $col ? 1 - $self->{sort_dir} : $self->{sort_dir}),
97 page => $self->{pages}{cur},
101 $column_defs->{$_}{visible} = 1 for @columns;
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}),
114 $report->set_options_from_form;
117 sub displayable_filter {
118 my ($self, $filter) = @_;
120 my $column_defs = $self->column_defs;
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;
126 return join '; ', map { "$_->[0]: $_->[1]" } @texts;
130 my ($self, %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},
141 return $self->url_for(%params);