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 => 10);
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, options => { no_layout => 1 });
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 @columns = qw(transdate ordnumber customer ship qty sellprice discount amount);
100 my @visible = qw(transdate ordnumber customer ship qty sellprice discount amount);
101 my @sortable = qw(transdate ordnumber customer sellprice discount );
103 my $column_defs = $self->column_defs;
105 for my $col (@sortable) {
106 $column_defs->{$col}{link} = $self->self_url(
108 sort_dir => ($self->{sort_by} eq $col ? 1 - $self->{sort_dir} : $self->{sort_dir}),
109 page => $self->{pages}{cur},
113 map { $column_defs->{$_}{visible} = 1 } @visible;
115 $report->set_columns(%$column_defs);
116 $report->set_column_order(@columns);
117 $report->set_options(allow_pdf_export => 0, allow_csv_export => 0);
118 $report->set_sort_indicator($self->{sort_by}, $self->{sort_dir});
119 $report->set_export_options(@{ $params{report_generator_export_options} || [] });
120 $report->set_options(
121 %{ $params{report_generator_options} || {} },
122 output_format => 'HTML',
123 top_info_text => $self->displayable_filter($::form->{filter}),
124 title => $::locale->text('Sales Price information'),
126 $report->set_options_from_form;
130 my ($self, $object, %params) = @_;
132 return unless $object;
133 my $action = $params{action} || 'edit';
135 if ($object->isa('SL::DB::Order')) {
136 my $type = $object->type;
137 my $vc = $object->is_sales ? 'customer' : 'vendor';
138 my $id = $object->id;
140 return "oe.pl?action=$action&type=$type&vc=$vc&id=$id";
142 if ($object->isa('SL::DB::Customer')) {
143 my $id = $object->id;
144 return "ct.pl?action=$action&id=$id&db=customer";
148 sub _pre_parse_filter {
149 my $filter = clone(shift);
151 if ( exists $filter->{order}
152 && exists $filter->{order}{type}) {
153 push @{ $filter->{and} }, SL::DB::Manager::Order->type_filter(delete $filter->{order}{type}, "order."),
159 sub displayable_filter {
160 my ($self, $filter) = @_;
162 my $column_defs = $self->column_defs;
165 push @texts, [ $::locale->text('Type'), $::locale->text($filter->{order}{type}) ] if $filter->{order}{type};
166 push @texts, [ $::locale->text('Sort By'), $column_defs->{$self->{sort_by}}{text} ] if $column_defs->{$self->{sort_by}}{text};
167 push @texts, [ $::locale->text('Page'), $::locale->text($self->{pages}{cur}) ] if $self->{pages}{cur} != 1;
169 return join '; ', map { "$_->[0]: $_->[1]" } @texts;
173 my ($self, %params) = @_;
175 action => $self->{action},
176 sort_by => $self->{sort_by},
177 sort_dir => $self->{sort_dir},
178 page => $self->{pages}{cur},
179 filter => $::form->{filter},
183 return $self->url_for(%params);