Sprache auf ungültig setzen im Admin-Bereich
[kivitendo-erp.git] / SL / Controller / Chart.pm
index 68c75bf..eb2b473 100644 (file)
@@ -4,14 +4,16 @@ use strict;
 use parent qw(SL::Controller::Base);
 
 use Clone qw(clone);
+use List::UtilsBy qw(partition_by sort_by);
+
+use SL::AM;
 use SL::DB::Chart;
 use SL::Controller::Helper::GetModels;
-use SL::DB::Helper::Paginated;
 use SL::Locale::String qw(t8);
 use SL::JSON;
 
 use Rose::Object::MakeMethods::Generic (
-  'scalar --get_set_init' => [ qw(charts models chart) ],
+  'scalar --get_set_init' => [ qw(charts models chart filter) ],
 );
 
 sub action_ajax_autocomplete {
@@ -30,6 +32,7 @@ sub action_ajax_autocomplete {
     if (1 == scalar @{ $exact_matches = SL::DB::Manager::Chart->get_all(
       query => [
         SL::DB::Manager::Chart->type_filter($::form->{filter}{type}),
+        charttype => 'A',
         or => [
           description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
           accno       => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
@@ -55,7 +58,7 @@ sub action_ajax_autocomplete {
 }
 
 sub action_test_page {
-  $_[0]->render('chart/test_page');
+  $_[0]->render('chart/test_page', pre_filled_chart => SL::DB::Manager::Chart->get_first);
 }
 
 sub action_chart_picker_search {
@@ -74,15 +77,50 @@ sub action_show {
     if (!$self->chart) {
       # TODO error
     } else {
-      require Rose::DB::Object::Helpers;
-        $chart_hash                     = $self->chart->as_tree;
-        $chart_hash->{displayable_name} = $self->chart->displayable_name;
+      $chart_hash                     = $self->chart->as_tree;
+      $chart_hash->{displayable_name} = $self->chart->displayable_name;
     }
 
     $self->render(\ SL::JSON::to_json($chart_hash), { layout => 0, type => 'json', process => 0 });
   }
 }
 
+sub action_show_report_configuration_overview {
+  my ($self) = @_;
+
+  my @all_charts = sort { $a->accno cmp $b->accno } @{ SL::DB::Manager::Chart->get_all(inject_results => 1) };
+  my @types      = qw(bilanz bwa er eur);
+  my %headings   = (
+    bilanz       => t8('Balance'),
+    bwa          => t8('BWA'),
+    er           => t8('Erfolgsrechnung'),
+    eur          => t8('EUER'),
+  );
+
+  my @data;
+
+  foreach my $type (@types) {
+    my $method = "pos_${type}";
+    my $names  = $type eq 'bwa' ? AM->get_bwa_categories(\%::myconfig, $::form)
+               : $type eq 'eur' ? AM->get_eur_categories(\%::myconfig, $::form)
+               :                  {};
+    my %charts = partition_by { $_->$method // '' } @all_charts;
+    delete $charts{''};
+
+    next if !%charts;
+
+    push @data, {
+      type      => $type,
+      heading   => $headings{$type},
+      charts    => \%charts,
+      positions => [ sort { ($a * 1) <=> ($b * 1) } keys %charts ],
+      names     => $names,
+    };
+  }
+
+  $self->render('chart/report_configuration_overview', DATA => \@data);
+}
+
 sub init_charts {
 
   # disable pagination when hiding chart details = paginate when showing chart details
@@ -110,7 +148,12 @@ sub init_models {
       accno       => t8('Account number'),
       description => t8('Description'),
     },
+    query => [
+      charttype => 'A',
+    ],
   );
 }
 
+sub init_filter { $_[0]->models->filtered->laundered }
+
 1;