1 package SL::Controller::Chart;
 
   4 use parent qw(SL::Controller::Base);
 
   7 use List::UtilsBy qw(partition_by sort_by);
 
  11 use SL::Controller::Helper::GetModels;
 
  12 use SL::Locale::String qw(t8);
 
  15 use Rose::Object::MakeMethods::Generic (
 
  16   'scalar --get_set_init' => [ qw(charts models chart filter) ],
 
  19 sub action_ajax_autocomplete {
 
  20   my ($self, %params) = @_;
 
  22   my $value = $::form->{column} || 'description';
 
  24   # if someone types something, and hits enter, assume he entered the full name.
 
  25   # if something matches, treat that as sole match
 
  26   # unfortunately get_models can't do more than one per package atm, so we do it
 
  27   # the oldfashioned way.
 
  28   if ($::form->{prefer_exact}) {
 
  30     # we still need the type filter so that we can't choose an illegal chart
 
  31     # via exact_match if we have preset a link type, e.g. AR_paid
 
  32     if (1 == scalar @{ $exact_matches = SL::DB::Manager::Chart->get_all(
 
  34         SL::DB::Manager::Chart->type_filter($::form->{filter}{type}),
 
  37           description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
 
  38           accno       => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
 
  43       $self->charts($exact_matches);
 
  49      value       => $_->displayable_name,
 
  50      label       => $_->displayable_name,
 
  53      description => $_->description,
 
  55   } @{ $self->charts }; # neato: if exact match triggers we don't even need the init_parts
 
  57   $self->render(\ SL::JSON::to_json(\@hashes), { layout => 0, type => 'json', process => 0 });
 
  60 sub action_test_page {
 
  61   $_[0]->render('chart/test_page', pre_filled_chart => SL::DB::Manager::Chart->get_first);
 
  64 sub action_chart_picker_search {
 
  65   $_[0]->render('chart/chart_picker_search', { layout => 0 }, charts => $_[0]->charts);
 
  68 sub action_chart_picker_result {
 
  69   $_[0]->render('chart/_chart_picker_result', { layout => 0 });
 
  75   if ($::request->type eq 'json') {
 
  80       $chart_hash                     = $self->chart->as_tree;
 
  81       $chart_hash->{displayable_name} = $self->chart->displayable_name;
 
  84     $self->render(\ SL::JSON::to_json($chart_hash), { layout => 0, type => 'json', process => 0 });
 
  88 sub action_show_report_configuration_overview {
 
  91   my @all_charts = sort { $a->accno cmp $b->accno } @{ SL::DB::Manager::Chart->get_all(inject_results => 1) };
 
  92   my @types      = qw(bilanz bwa er eur);
 
  94     bilanz       => t8('Balance'),
 
  96     er           => t8('Erfolgsrechnung'),
 
 102   foreach my $type (@types) {
 
 103     my $method = "pos_${type}";
 
 104     my $names  = $type eq 'bwa' ? AM->get_bwa_categories(\%::myconfig, $::form)
 
 105                : $type eq 'eur' ? AM->get_eur_categories(\%::myconfig, $::form)
 
 107     my %charts = partition_by { $_->$method // '' } @all_charts;
 
 114       heading   => $headings{$type},
 
 116       positions => [ sort { ($a * 1) <=> ($b * 1) } keys %charts ],
 
 121   $self->render('chart/report_configuration_overview', DATA => \@data);
 
 126   # disable pagination when hiding chart details = paginate when showing chart details
 
 127   if ($::form->{hide_chart_details}) {
 
 128     $_[0]->models->disable_plugin('paginated');
 
 135   SL::DB::Chart->new(id => $::form->{id} || $::form->{chart}{id})->load;
 
 141   SL::Controller::Helper::GetModels->new(
 
 148       accno       => t8('Account number'),
 
 149       description => t8('Description'),
 
 157 sub init_filter { $_[0]->models->filtered->laundered }