Revision 404d9b0a
Von Moritz Bunkus vor fast 9 Jahren hinzugefügt
SL/Controller/PartsPriceHistory.pm | ||
---|---|---|
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;
|
SL/DB/Manager/PartsPriceHistory.pm | ||
---|---|---|
|
||
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;
|
SL/DB/PartsPriceHistory.pm | ||
---|---|---|
# 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;
|
locale/de/all | ||
---|---|---|
'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.',
|
templates/webpages/ic/sales_price_information.html | ||
---|---|---|
<div id='sales_price_information_sales_order'></div>
|
||
<div id='sales_price_information_sales_quotation'></div>
|
||
<div id='parts_price_history'></div>
|
||
|
||
<script type='text/javascript'>
|
||
function get_report(target, source, data){
|
||
... | ... | |
if (ui.newPanel.attr('id') == 'sales_price_information') {
|
||
get_report('#sales_price_information_sales_order', 'controller.pl', { action: 'SellPriceInformation/list', 'filter.part.id': [% id %], 'filter.order.type': 'sales_order' });
|
||
get_report('#sales_price_information_sales_quotation', 'controller.pl', { action: 'SellPriceInformation/list', 'filter.part.id': [% id %], 'filter.order.type': 'sales_quotation' });
|
||
get_report('#parts_price_history', 'controller.pl', { action: 'PartsPriceHistory/list', 'filter.part_id': [% id %] });
|
||
}
|
||
return 1;
|
||
});
|
templates/webpages/parts_price_history/report_bottom.html | ||
---|---|---|
<p align=right>[% PROCESS 'common/paginate.html' pages=SELF.pages, base_url=SELF.self_url %]</p>
|
Auch abrufbar als: Unified diff
Verkaufspreisinformationen: Preisentwicklung der Stammdaten anzeigen