From: Moritz Bunkus Date: Tue, 7 Jun 2016 09:41:03 +0000 (+0200) Subject: Verkaufspreisinformationen: Preisentwicklung der Stammdaten anzeigen X-Git-Tag: release-3.4.1~98 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=404d9b0abcb5019e99812e1c4121140aff64e292;p=kivitendo-erp.git Verkaufspreisinformationen: Preisentwicklung der Stammdaten anzeigen --- diff --git a/SL/Controller/PartsPriceHistory.pm b/SL/Controller/PartsPriceHistory.pm new file mode 100644 index 000000000..82263b876 --- /dev/null +++ b/SL/Controller/PartsPriceHistory.pm @@ -0,0 +1,144 @@ +package SL::Controller::PartsPriceHistory; + +use strict; +use parent qw(SL::Controller::Base); + +use Clone qw(clone); +use SL::DB::PartsPriceHistory; +use SL::Controller::Helper::ParseFilter; +use SL::Controller::Helper::ReportGenerator; + +sub action_list { + my ($self) = @_; + $self->{action} = 'list'; + + my %list_params = ( + sort_by => $::form->{sort_by} || 'valid_from', + sort_dir => $::form->{sort_dir}, + filter => $::form->{filter}, + page => $::form->{page}, + ); + + my $db_args = $self->setup_for_list(%list_params); + $self->{pages} = SL::DB::Manager::PartsPriceHistory->paginate(%list_params, args => $db_args, per_page => 5); + + my $bottom = $::form->parse_html_template('parts_price_history/report_bottom', { SELF => $self }); + + $self->prepare_report( + db_args => $db_args, + report_generator_options => { + raw_bottom_info_text => $bottom, + controller_class => 'PartsPriceHistory', + }, + ); + + my $history = SL::DB::Manager::PartsPriceHistory->get_all(%{ $db_args }); + + $self->report_generator_list_objects( + report => $self->{report}, + objects => $history, + layout => 0, + header => 0, + ); +} + +# private functions + +sub setup_for_list { + my ($self, %params) = @_; + + $self->{filter} = clone($params{filter}); + + my %args = ( + parse_filter($self->{filter}), + sort_by => $self->set_sort_params(%params), + page => $params{page}, + ); + + return \%args; +} + +sub set_sort_params { + my ($self, %params) = @_; + + my $sort_str; + ($self->{sort_by}, $self->{sort_dir}, $sort_str) = SL::DB::Manager::PartsPriceHistory->make_sort_string(%params); + return $sort_str; +} + +sub column_defs { + my ($self) = @_; + + return { + valid_from => { text => $::locale->text('Date'), sub => sub { $_[0]->valid_from_as_timestamp }}, + lastcost => { text => $::locale->text('Lastcost'), sub => sub { $_[0]->lastcost_as_number }}, + listprice => { text => $::locale->text('List Price'), sub => sub { $_[0]->listprice_as_number }}, + sellprice => { text => $::locale->text('Sell Price'), sub => sub { $_[0]->sellprice_as_number }}, + }; +} + +sub prepare_report { + my ($self, %params) = @_; + + my $objects = $params{objects} || []; + my $report = SL::ReportGenerator->new(\%::myconfig, $::form); + $self->{report} = $report; + + my $title = $::locale->text('Price history for master data'); + + my @columns = qw(valid_from lastcost listprice sellprice); + + my $column_defs = $self->column_defs; + + for my $col (@columns) { + $column_defs->{$col}{link} = $self->self_url( + sort_by => $col, + sort_dir => ($self->{sort_by} eq $col ? 1 - $self->{sort_dir} : $self->{sort_dir}), + page => $self->{pages}{cur}, + ); + } + + $column_defs->{$_}{visible} = 1 for @columns; + + $report->set_columns(%$column_defs); + $report->set_column_order(@columns); + $report->set_options(allow_pdf_export => 0, allow_csv_export => 0); + $report->set_sort_indicator($self->{sort_by}, $self->{sort_dir}); + $report->set_export_options(@{ $params{report_generator_export_options} || [] }); + $report->set_options( + %{ $params{report_generator_options} || {} }, + output_format => 'HTML', + top_info_text => $self->displayable_filter($::form->{filter}), + title => $title, + ); + $report->set_options_from_form; +} + +sub displayable_filter { + my ($self, $filter) = @_; + + my $column_defs = $self->column_defs; + my @texts; + + push @texts, [ $::locale->text('Sort By'), $column_defs->{$self->{sort_by}}{text} ] if $column_defs->{$self->{sort_by}}{text}; + push @texts, [ $::locale->text('Page'), $::locale->text($self->{pages}{cur}) ] if $self->{pages}{cur} > 1; + + return join '; ', map { "$_->[0]: $_->[1]" } @texts; +} + +sub self_url { + my ($self, %params) = @_; + + %params = ( + action => $self->{action}, + sort_by => $self->{sort_by}, + sort_dir => $self->{sort_dir}, + page => $self->{pages}{cur}, + filter => $::form->{filter}, + %params, + ); + + return $self->url_for(%params); +} + +1; diff --git a/SL/DB/Manager/PartsPriceHistory.pm b/SL/DB/Manager/PartsPriceHistory.pm index 34cd4dc1f..6cc14ca2a 100644 --- a/SL/DB/Manager/PartsPriceHistory.pm +++ b/SL/DB/Manager/PartsPriceHistory.pm @@ -4,8 +4,20 @@ use strict; use parent qw(SL::DB::Helper::Manager); +use SL::DB::Helper::Sorted; +use SL::DB::Helper::Paginated; + sub object_class { 'SL::DB::PartsPriceHistory' } __PACKAGE__->make_manager_methods; +sub _sort_spec { + ( + default => [ 'valid_from', 0 ], + columns => { + SIMPLE => 'ALL', + }, + ); +} + 1; diff --git a/SL/DB/PartsPriceHistory.pm b/SL/DB/PartsPriceHistory.pm index 424b48765..f53e8f290 100644 --- a/SL/DB/PartsPriceHistory.pm +++ b/SL/DB/PartsPriceHistory.pm @@ -1,6 +1,3 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::PartsPriceHistory; use strict; diff --git a/locale/de/all b/locale/de/all index 939df90ef..f7c9b362f 100755 --- a/locale/de/all +++ b/locale/de/all @@ -2096,6 +2096,7 @@ $self->{texts} = { 'Price group' => 'Preisgruppe', 'Price group (database ID)' => 'Preisgruppe (Datenbank-ID)', 'Price group (name)' => 'Preisgruppe (Name) ', + 'Price history for master data' => 'Preisentwicklung für Stammdaten', 'Price information' => 'Preisinformation', 'Price or discount must not be zero.' => 'Preis/Rabatt darf nicht 0,00 sein', 'Price rules must have at least one rule.' => 'Preisregeln brauchen mindestens eine Bedingung.', diff --git a/templates/webpages/ic/sales_price_information.html b/templates/webpages/ic/sales_price_information.html index 4f5794cb4..012a68b4c 100644 --- a/templates/webpages/ic/sales_price_information.html +++ b/templates/webpages/ic/sales_price_information.html @@ -1,5 +1,6 @@
+