]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Controller/Project.pm
paginating im druck gefixt. debugmeldungen aufgerÀumt
[mfinanz.git] / SL / Controller / Project.pm
index fa42007bd45f6a1b50d02ba07b1e1f8ed347c411..7d66f35937c90779b892bff27da9a470806a602a 100644 (file)
@@ -9,26 +9,35 @@ use Clone qw(clone);
 use SL::Controller::Helper::GetModels;
 use SL::Controller::Helper::Paginated;
 use SL::Controller::Helper::Sorted;
 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::Customer;
 use SL::Controller::Helper::ParseFilter;
 use SL::Controller::Helper::ReportGenerator;
 use SL::CVar;
 use SL::DB::Customer;
+use SL::DB::DeliveryOrder;
+use SL::DB::Invoice;
+use SL::DB::Order;
 use SL::DB::Project;
 use SL::DB::Project;
+use SL::DB::PurchaseInvoice;
 use SL::Helper::Flash;
 use SL::Locale::String;
 
 use Rose::Object::MakeMethods::Generic
 (
 use SL::Helper::Flash;
 use SL::Locale::String;
 
 use Rose::Object::MakeMethods::Generic
 (
- scalar => [ qw(project db_args flat_filter) ],
+ scalar => [ qw(project linked_records) ],
 );
 
 __PACKAGE__->run_before('check_auth');
 __PACKAGE__->run_before('load_project', only => [ qw(edit update destroy) ]);
 
 );
 
 __PACKAGE__->run_before('check_auth');
 __PACKAGE__->run_before('load_project', only => [ qw(edit update destroy) ]);
 
-__PACKAGE__->get_models_url_params('flat_filter');
+__PACKAGE__->make_filtered(
+  MODEL         => 'Project',
+  LAUNDER_TO    => 'filter',
+  ONLY          => [ qw(list) ],
+);
 __PACKAGE__->make_paginated(
   MODEL         => 'Project',
 __PACKAGE__->make_paginated(
   MODEL         => 'Project',
-  PAGINATE_ARGS => 'db_args',
+#  PAGINATE_ARGS => 'db_args',
   ONLY          => [ qw(list) ],
 );
 
   ONLY          => [ qw(list) ],
 );
 
@@ -67,15 +76,15 @@ sub action_search {
 sub action_list {
   my ($self) = @_;
 
 sub action_list {
   my ($self) = @_;
 
-  $self->setup_db_args_from_filter;
-  $self->flat_filter({ map { $_->{key} => $_->{value} } $::form->flatten_variables('filter') });
   # $self->make_filter_summary;
 
   # $self->make_filter_summary;
 
-  $self->prepare_report;
+  my $projects = $self->get_models(
+    with_objects => [ 'customer' ],
+  );
 
 
-  $self->{projects} = $self->get_models(%{ $self->db_args });
+  $self->prepare_report;
 
 
-  $self->list_objects;
+  $self->report_generator_list_objects(report => $self->{report}, objects => $projects);
 }
 
 sub action_new {
 }
 
 sub action_new {
@@ -88,6 +97,16 @@ sub action_new {
 
 sub action_edit {
   my ($self) = @_;
 
 sub action_edit {
   my ($self) = @_;
+
+  $self->linked_records([
+    map  { @{ $_ } }
+    grep { $_      } (
+      SL::DB::Manager::Order->          get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer', 'vendor' ], sort_by => 'transdate ASC'),
+      SL::DB::Manager::DeliveryOrder->  get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer', 'vendor' ], sort_by => 'transdate ASC'),
+      SL::DB::Manager::Invoice->        get_all(where => [ globalproject_id => $self->project->id ], with_objects => [ 'customer'           ], sort_by => 'transdate ASC'),
+      SL::DB::Manager::PurchaseInvoice->get_all(where => [ globalproject_id => $self->project->id ], with_objects => [             'vendor' ], sort_by => 'transdate ASC'),
+    )]);
+
   $self->display_form(title    => $::locale->text('Edit project #1', $self->project->projectnumber),
                       callback => $::form->{callback} || $self->url_for(action => 'edit', id => $self->project->id));
 }
   $self->display_form(title    => $::locale->text('Edit project #1', $self->project->projectnumber),
                       callback => $::form->{callback} || $self->url_for(action => 'edit', id => $self->project->id));
 }
@@ -135,8 +154,6 @@ sub display_form {
   $params{CUSTOM_VARIABLES} = CVar->get_custom_variables(module => 'Projects', trans_id => $self->project->id);
   CVar->render_inputs(variables => $params{CUSTOM_VARIABLES}) if @{ $params{CUSTOM_VARIABLES} };
 
   $params{CUSTOM_VARIABLES} = CVar->get_custom_variables(module => 'Projects', trans_id => $self->project->id);
   CVar->render_inputs(variables => $params{CUSTOM_VARIABLES}) if @{ $params{CUSTOM_VARIABLES} };
 
-  $::request->{layout}->focus('#projectnumber');
-
   $self->render('project/form', %params);
 }
 
   $self->render('project/form', %params);
 }
 
@@ -190,35 +207,6 @@ sub setup_db_args_from_filter {
   $self->db_args(\%args);
 }
 
   $self->db_args(\%args);
 }
 
-# unfortunately ParseFilter can't handle compount filters.
-# so we clone the original filter (still need that for serializing)
-# rip out the options we know an replace them with the compound options.
-# ParseFilter will take care of the prefixing then.
-sub _pre_parse_filter {
-  my ($self, $orig_filter, $launder_to) = @_;
-
-  return undef unless $orig_filter;
-
-  my $filter = clone($orig_filter);
-
-  $launder_to->{active} = delete $filter->{active};
-  if ($orig_filter->{active} ne 'both') {
-    push @{ $filter->{and} }, $orig_filter->{active} eq 'active' ? (active => 1) : (or => [ active => 0, active => undef ]);
-  }
-
-  $launder_to->{valid} = delete $filter->{valid};
-  if ($orig_filter->{valid} ne 'both') {
-    push @{ $filter->{and} }, $orig_filter->{valid} eq 'valid' ? (valid => 1) : (or => [ valid => 0, valid => undef ]);
-  }
-
-  $launder_to->{status} = delete $filter->{status};
-  if ($orig_filter->{status} ne 'all') {
-    push @{ $filter->{and} }, SL::DB::Manager::Project->is_not_used_filter;
-  }
-
-  return $filter;
-}
-
 sub prepare_report {
   my ($self)      = @_;
 
 sub prepare_report {
   my ($self)      = @_;
 
@@ -248,7 +236,7 @@ sub prepare_report {
     controller_class      => 'Project',
     output_format         => 'HTML',
     top_info_text         => $::locale->text('Projects'),
     controller_class      => 'Project',
     output_format         => 'HTML',
     top_info_text         => $::locale->text('Projects'),
-    raw_bottom_info_text  => $self->render('project/report_bottom', { no_output => 1, partial => 1 }),
+    raw_bottom_info_text  => $self->render('project/report_bottom', { output => 0 }),
     title                 => $::locale->text('Projects'),
     allow_pdf_export      => 1,
     allow_csv_export      => 1,
     title                 => $::locale->text('Projects'),
     allow_pdf_export      => 1,
     allow_csv_export      => 1,
@@ -260,31 +248,6 @@ sub prepare_report {
   $self->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
 
   $self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
   $self->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable);
 
   $self->disable_pagination if $report->{options}{output_format} =~ /^(pdf|csv)$/i;
-
-  $self->{report_data} = {
-    column_defs        => \%column_defs,
-    columns            => \@columns,
-  };
-}
-
-sub list_objects {
-  my ($self)      = @_;
-  my $column_defs = $self->{report_data}->{column_defs};
-
-  for my $obj (@{ $self->{projects} || [] }) {
-    my %data = map {
-      $_ => {
-        data => $column_defs->{$_}{sub} ? $column_defs->{$_}{sub}->($obj)
-              : $obj->can($_)           ? $obj->$_
-              :                           $obj->{$_},
-        link => $column_defs->{$_}{obj_link} ? $column_defs->{$_}{obj_link}->($obj) : '',
-      },
-    } @{ $self->{report_data}{columns} || {} };
-
-    $self->{report}->add_data(\%data);
-  }
-
-  return $self->{report}->generate_with_headers;
 }
 
 1;
 }
 
 1;