use Clone qw(clone);
use SL::Controller::Helper::GetModels;
-use SL::Controller::Helper::Paginated;
-use SL::Controller::Helper::Sorted;
-use SL::Controller::Helper::Filtered;
use SL::Controller::Helper::ParseFilter;
use SL::Controller::Helper::ReportGenerator;
use SL::CVar;
use SL::DB::Order;
use SL::DB::Project;
use SL::DB::PurchaseInvoice;
+use SL::DB::ProjectType;
use SL::Helper::Flash;
use SL::Locale::String;
use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(project linked_records) ],
+ 'scalar --get_set_init' => [ qw(models) ],
);
__PACKAGE__->run_before('check_auth');
-__PACKAGE__->run_before('load_project', only => [ qw(edit update destroy) ]);
-
-__PACKAGE__->make_filtered(
- MODEL => 'Project',
- LAUNDER_TO => 'filter',
- ONLY => [ qw(list) ],
-);
-__PACKAGE__->make_paginated(
- MODEL => 'Project',
-# PAGINATE_ARGS => 'db_args',
- ONLY => [ qw(list) ],
-);
-
-__PACKAGE__->make_sorted(
- MODEL => 'Project',
- ONLY => [ qw(list) ],
-
- DEFAULT_BY => 'projectnumber',
- DEFAULT_DIR => 1,
-
- customer => t8('Customer'),
- description => t8('Description'),
- projectnumber => t8('Project Number'),
- type => t8('Type'),
-);
-
+__PACKAGE__->run_before('load_project', only => [ qw(edit update destroy) ]);
#
# actions
my %params;
- $params{CUSTOM_VARIABLES} = CVar->get_configs(module => 'Projects');
+ $params{ALL_PROJECT_TYPES} = SL::DB::Manager::ProjectType->get_all_sorted;
+ $params{CUSTOM_VARIABLES} = CVar->get_configs(module => 'Projects');
($params{CUSTOM_VARIABLES_FILTER_CODE}, $params{CUSTOM_VARIABLES_INCLUSION_CODE})
= CVar->render_search_options(variables => $params{CUSTOM_VARIABLES},
include_prefix => 'l_',
# $self->make_filter_summary;
- my $projects = $self->get_models(
- with_objects => [ 'customer' ],
- );
+ my $projects = $self->models->get;
$self->prepare_report;
sub display_form {
my ($self, %params) = @_;
- $params{ALL_CUSTOMERS} = SL::DB::Manager::Customer->get_all_sorted(where => [ or => [ obsolete => 0, obsolete => undef, id => $self->project->customer_id ]]);
- $params{CUSTOM_VARIABLES} = CVar->get_custom_variables(module => 'Projects', trans_id => $self->project->id);
+ $params{ALL_CUSTOMERS} = SL::DB::Manager::Customer->get_all_sorted(where => [ or => [ obsolete => 0, obsolete => undef, id => $self->project->customer_id ]]);
+ $params{ALL_PROJECT_TYPES} = SL::DB::Manager::ProjectType->get_all_sorted;
+ $params{CUSTOM_VARIABLES} = CVar->get_custom_variables(module => 'Projects', trans_id => $self->project->id);
+
+ if ($params{keep_cvars}) {
+ for my $cvar (@{ $params{CUSTOM_VARIABLES} }) {
+ $cvar->{value} = $::form->{"cvar_$cvar->{name}"} if $::form->{"cvar_$cvar->{name}"};
+ }
+ }
+
CVar->render_inputs(variables => $params{CUSTOM_VARIABLES}) if @{ $params{CUSTOM_VARIABLES} };
$self->render('project/form', %params);
if (@errors) {
flash('error', @errors);
$self->display_form(title => $is_new ? $::locale->text('Create a new project') : $::locale->text('Edit project'),
- callback => $::form->{callback});
+ callback => $::form->{callback},
+ keep_cvars => 1);
return;
}
$self->{filter} = {};
my %args = parse_filter(
$self->_pre_parse_filter($::form->{filter}, $self->{filter}),
- with_objects => [ 'customer' ],
+ with_objects => [ 'customer', 'project_type' ],
launder_to => $self->{filter},
);
sub prepare_report {
my ($self) = @_;
- my $callback = $self->get_callback;
+ my $callback = $self->models->get_callback;
my $report = SL::ReportGenerator->new(\%::myconfig, $::form);
$self->{report} = $report;
- my @columns = qw(projectnumber description customer active valid type);
- my @sortable = qw(projectnumber description customer type);
+ my @columns = qw(projectnumber description customer active valid project_type);
+ my @sortable = qw(projectnumber description customer project_type);
my %column_defs = (
projectnumber => { obj_link => sub { $self->url_for(action => 'edit', id => $_[0]->id, callback => $callback) } },
description => { obj_link => sub { $self->url_for(action => 'edit', id => $_[0]->id, callback => $callback) } },
- type => { },
+ project_type => { sub => sub { $_[0]->project_type->description } },
customer => { sub => sub { $_[0]->customer ? $_[0]->customer->name : '' } },
active => { sub => sub { $_[0]->active ? $::locale->text('Active') : $::locale->text('Inactive') },
text => $::locale->text('Active') },
text => $::locale->text('Valid') },
);
- 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;
+ if ( $report->{options}{output_format} =~ /^(pdf|csv)$/i ) {
+ $self->models->disable_plugin('paginated');
+ }
$report->set_options(
std_column_visibility => 1,
controller_class => 'Project',
output_format => 'HTML',
top_info_text => $::locale->text('Projects'),
- raw_bottom_info_text => $self->render('project/report_bottom', { output => 0 }),
title => $::locale->text('Projects'),
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->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
+ $report->set_options(
+ raw_bottom_info_text => $self->render('project/report_bottom', { output => 0 }),
+ );
+}
+
+sub init_models {
+ my ($self) = @_;
- $self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
+ SL::Controller::Helper::GetModels->new(
+ controller => $self,
+ sorted => {
+ _default => {
+ by => 'projectnumber',
+ dir => 1,
+ },
+ customer => t8('Customer'),
+ description => t8('Description'),
+ projectnumber => t8('Project Number'),
+ project_type => t8('Project Type'),
+ },
+ with_objects => [ 'customer' ],
+ );
}
1;