use SL::DB::Order;
use SL::DB::ProjectType;
use SL::Controller::Helper::GetModels;
-use SL::Controller::Helper::Paginated;
-use SL::Controller::Helper::Sorted;
-use SL::Controller::Helper::ParseFilter;
use SL::Controller::Helper::ReportGenerator;
use SL::Locale::String;
use Rose::Object::MakeMethods::Generic (
- scalar => [ qw(db_args flat_filter project_types) ],
+ scalar => [ qw(project_types) ],
+ 'scalar --get_set_init' => [ qw(models) ],
);
__PACKAGE__->run_before(sub { $::auth->assert('sales_order_edit'); });
-__PACKAGE__->get_models_url_params('flat_filter');
-__PACKAGE__->make_paginated(
- MODEL => 'Order',
- PAGINATE_ARGS => 'db_args',
- ONLY => [ qw(list) ],
-);
-
-__PACKAGE__->make_sorted(
- MODEL => 'Order',
- ONLY => [ qw(list) ],
-
- DEFAULT_BY => 'globalprojectnumber',
- DEFAULT_DIR => 1,
-
+my %sort_columns = (
ordnumber => t8('Order'),
customer => t8('Customer'),
transaction_description => t8('Transaction description'),
$self->project_types(SL::DB::Manager::ProjectType->get_all_sorted);
- $self->db_args($self->setup_db_args_for_list(filter => $::form->{filter}));
- $self->flat_filter({ map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') });
$self->make_filter_summary;
$self->prepare_report;
- $self->{orders} = $self->get_models(%{ $self->db_args });
+ $self->{orders} = $self->models->get;
$self->calculate_data;
# private functions
-sub setup_db_args_for_list {
- my ($self) = @_;
-
- $self->{filter} = {};
- my %args = ( parse_filter($::form->{filter}, with_objects => [ 'customer', 'globalproject', 'globalproject.project_type' ], launder_to => $self->{filter}));
- $args{query} = [
- @{ $args{query} || [] },
- SL::DB::Manager::Order->type_filter('sales_order'),
- '!closed' => 1,
- or => [
- globalproject_id => undef,
- and => [
- 'globalproject.active' => 1,
- 'globalproject.valid' => 1,
- ]],
- ];
-
- return \%args;
-}
-
sub prepare_report {
my ($self) = @_;
sub => sub { $_[0]->globalproject_id ? $_[0]->globalproject->project_type->description : '' } },
);
- map { $column_defs{$_}->{text} ||= $::locale->text( $self->get_sort_spec->{$_}->{title} ) } keys %column_defs;
+ map { $column_defs{$_}->{text} ||= $::locale->text( $self->models->get_sort_spec->{$_}->{title} ) } keys %column_defs;
map { $column_defs{$_}->{align} = 'right' } @{ $self->{number_columns} };
$report->set_options(
controller_class => 'FinancialControllingReport',
output_format => 'HTML',
top_info_text => $::locale->text('Financial controlling report for open sales orders'),
- raw_top_info_text => $self->render('financial_controlling_report/report_top', { output => 0 }),
- raw_bottom_info_text => $self->render('financial_controlling_report/report_bottom', { output => 0 }),
title => $::locale->text('Financial Controlling Report'),
allow_pdf_export => 1,
allow_csv_export => 1,
$report->set_column_order(@columns);
$report->set_export_options(qw(list filter));
$report->set_options_from_form;
- $self->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
-
- $self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
+ $self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
+ $self->models->finalize;
+ $self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
+ $report->set_options(
+ raw_top_info_text => $self->render('financial_controlling_report/report_top', { output => 0 }),
+ raw_bottom_info_text => $self->render('financial_controlling_report/report_bottom', { output => 0 }, models => $self->models),
+ );
}
sub calculate_data {
$self->{filter_summary} = join ', ', @filter_strings;
}
+sub init_models {
+ my ($self) = @_;
+
+ SL::Controller::Helper::GetModels->new(
+ controller => $self,
+ model => 'Order',
+ sorted => {
+ _default => {
+ by => 'globalprojectnumber',
+ dir => 1,
+ },
+ %sort_columns,
+ },
+ query => [
+ SL::DB::Manager::Order->type_filter('sales_order'),
+ '!closed' => 1,
+ or => [
+ globalproject_id => undef,
+ and => [
+ 'globalproject.active' => 1,
+ 'globalproject.valid' => 1,
+ ]],
+ ],
+ with_objects => [ 'customer', 'globalproject', 'globalproject.project_type' ],
+ );
+}
+
sub link_to {
my ($self, $object, %params) = @_;
use base qw(SL::DB::Object);
-__PACKAGE__->meta->setup(
- table => 'project_types',
+__PACKAGE__->meta->table('project_types');
- columns => [
- id => { type => 'serial', not_null => 1 },
- position => { type => 'integer', not_null => 1 },
- description => { type => 'text' },
- ],
-
- primary_key_columns => [ 'id' ],
+__PACKAGE__->meta->columns(
+ description => { type => 'text' },
+ id => { type => 'serial', not_null => 1 },
+ position => { type => 'integer', not_null => 1 },
);
+__PACKAGE__->meta->primary_key_columns([ 'id' ]);
+
1;
;