1 package SL::Controller::SellPriceInformation;
4 use parent qw(SL::Controller::Base);
8 use SL::Controller::Helper::ParseFilter;
9 use SL::Controller::Helper::ReportGenerator;
13 $self->{action} = 'list';
16 sort_by => $::form->{sort_by} || 'reqdate',
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::OrderItem->paginate(%list_params, args => $db_args, per_page => 5);
25 my $bottom = $::form->parse_html_template('price_information/report_bottom', { SELF => $self });
27 $self->prepare_report(
28 report_generator_options => {
29 raw_bottom_info_text => $bottom,
30 controller_class => 'SellPriceInformation',
35 my $orderitems = SL::DB::Manager::OrderItem->get_all(%$db_args);
37 $self->report_generator_list_objects(report => $self->{report}, objects => $orderitems, layout => 0, header => 0);
43 my ($self, %params) = @_;
44 $self->{filter} = _pre_parse_filter($params{filter});
47 parse_filter($self->{filter},
48 with_objects => [ 'order', 'order.customer', 'part' ],
50 sort_by => $self->set_sort_params(%params),
51 page => $params{page},
58 my ($self, %params) = @_;
60 ($self->{sort_by}, $self->{sort_dir}, $sort_str) =
61 SL::DB::Manager::OrderItem->make_sort_string(%params);
68 transdate => { text => $::locale->text('Date'),
69 sub => sub { $_[0]->order->transdate_as_date }},
70 ordnumber => { text => $::locale->text('Number'),
71 sub => sub { $_[0]->order->number },
72 obj_link => sub { $self->link_to($_[0]->order) }},
73 customer => { text => $::locale->text('Customer'),
74 sub => sub { $_[0]->order->customer->name },
75 obj_link => sub { $self->link_to($_[0]->order->customer) }},
76 customer => { text => $::locale->text('Customer'),
77 sub => sub { $_[0]->order->customer->name },
78 obj_link => sub { $self->link_to($_[0]->order->customer) }},
79 ship => { text => $::locale->text('Delivered'),
80 sub => sub { $::form->format_amount(\%::myconfig, $_[0]->shipped_qty) . ' ' . $_[0]->unit }},
81 qty => { text => $::locale->text('Qty'),
82 sub => sub { $_[0]->qty_as_number . ' ' . $_[0]->unit }},
83 sellprice => { text => $::locale->text('Sell Price'),
84 sub => sub { $_[0]->sellprice_as_number }},
85 discount => { text => $::locale->text('Discount'),
86 sub => sub { $_[0]->discount_as_percent . "%" }},
87 amount => { text => $::locale->text('Amount'),
88 sub => sub { $::form->format_amount(\%::myconfig, $_[0]->qty * $_[0]->sellprice * (1 - $_[0]->discount), 2) }},
93 my ($self, %params) = @_;
95 my $objects = $params{objects} || [];
96 my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
97 $self->{report} = $report;
99 my $title = $::locale->text('Sales Price information');
100 $title .= ': ' . $::locale->text($::form->{filter}->{order}{type}) if $::form->{filter}->{order}{type};
102 my @columns = qw(transdate ordnumber customer ship qty sellprice discount amount);
103 my @visible = qw(transdate ordnumber customer ship qty sellprice discount amount);
104 my @sortable = qw(transdate ordnumber customer sellprice discount );
106 my $column_defs = $self->column_defs;
108 for my $col (@sortable) {
109 $column_defs->{$col}{link} = $self->self_url(
111 sort_dir => ($self->{sort_by} eq $col ? 1 - $self->{sort_dir} : $self->{sort_dir}),
112 page => $self->{pages}{cur},
116 map { $column_defs->{$_}{visible} = 1 } @visible;
118 $report->set_columns(%$column_defs);
119 $report->set_column_order(@columns);
120 $report->set_options(allow_pdf_export => 0, allow_csv_export => 0);
121 $report->set_sort_indicator($self->{sort_by}, $self->{sort_dir});
122 $report->set_export_options(@{ $params{report_generator_export_options} || [] });
123 $report->set_options(
124 %{ $params{report_generator_options} || {} },
125 output_format => 'HTML',
126 top_info_text => $self->displayable_filter($::form->{filter}),
129 $report->set_options_from_form;
133 my ($self, $object, %params) = @_;
135 return unless $object;
136 my $action = $params{action} || 'edit';
138 if ($object->isa('SL::DB::Order')) {
139 my $type = $object->type;
140 my $vc = $object->is_sales ? 'customer' : 'vendor';
141 my $id = $object->id;
143 if ($::instance_conf->get_feature_experimental_order) {
144 return "controller.pl?action=Order/$action&type=$type&id=$id";
146 return "oe.pl?action=$action&type=$type&vc=$vc&id=$id";
149 if ($object->isa('SL::DB::Customer')) {
150 my $id = $object->id;
151 return "controller.pl?action=CustomerVendor/$action&id=$id&db=customer";
155 sub _pre_parse_filter {
156 my $filter = clone(shift);
158 if ( exists $filter->{order}
159 && exists $filter->{order}{type}) {
160 push @{ $filter->{and} }, SL::DB::Manager::Order->type_filter(delete $filter->{order}{type}, "order."),
166 sub displayable_filter {
167 my ($self, $filter) = @_;
169 my $column_defs = $self->column_defs;
172 push @texts, [ $::locale->text('Sort By'), $column_defs->{$self->{sort_by}}{text} ] if $column_defs->{$self->{sort_by}}{text};
173 push @texts, [ $::locale->text('Page'), $::locale->text($self->{pages}{cur}) ] if $self->{pages}{cur} > 1;
175 return join '; ', map { "$_->[0]: $_->[1]" } @texts;
179 my ($self, %params) = @_;
181 action => $self->{action},
182 sort_by => $self->{sort_by},
183 sort_dir => $self->{sort_dir},
184 page => $self->{pages}{cur},
185 filter => $::form->{filter},
189 return $self->url_for(%params);