X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/2498c3fe17bc3846b308645dd37aa32c64b5574d..47db6ae13df64092d401896ec476b9335e9ec807:/SL/Controller/Mebil.pm diff --git a/SL/Controller/Mebil.pm b/SL/Controller/Mebil.pm index ced266f10..b8d02a46c 100644 --- a/SL/Controller/Mebil.pm +++ b/SL/Controller/Mebil.pm @@ -4,11 +4,22 @@ use strict; use parent qw(SL::Controller::Base); +#use SL::Controller::Helper::ReportGenerator; +use SL::ReportGenerator; use SL::DBUtils; +use SL::Locale::String; # t8 + #use Data::Dumper; #use SL::ClientJS; +use SL::mebil::Mapping; + +use Rose::Object::MakeMethods::Generic ( + scalar => [ qw(report number_columns year current_year objects subtotals_per_quarter salesman_id) ], + 'scalar --get_set_init' => [ qw(employees types data) ], +); + sub action_map { $::lxdebug->enter_sub; $::lxdebug->message(5, 'controller=mebil/action=map'); @@ -18,12 +29,145 @@ sub action_map { print "

Mebil running

"; - my $sql = "SELECT * from mebil_mapping"; + my $sql = "SELECT chart_id,xbrl_tag from mebil_mapping"; my $result = SL::DBUtils::do_query($::form, $::form->get_standard_dbh, $sql); $::lxdebug->message(5, "result= $result"); - print "$result\n"; + print "$result
\n"; + + my @r = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql); + print ref($r[1])||"SCALAR"; + print "
"; + my $fst = $r[1]; + while (my($k,$v) = each(%$fst)) { + print $k, " : ", $v, "
\n"; + } + print "
"; + print scalar @r; + print "
"; + print @r; print "

Mebil ready

"; $::lxdebug->leave_sub; } +sub action_showmap { + $::lxdebug->enter_sub; + my ($self) = @_; + + # call model -> diese Zeile ist fraglich, war ein Konflikt + #$self->{data} = DB::MebilMapping::getMappings($::form->get_standard_dbh); + + $::form->{title} = $::locale->text('Mebil Map'); + + my $mapping = new SL::mebil::Mapping($::form, $::form->get_standard_dbh); + $self->{data} = $mapping->get_mapping(); + + $self->prepare_report; + $self->list_data; + + $::lxdebug->leave_sub; +} + +sub action_calcmap { + $::lxdebug->enter_sub; + my ($self) = @_; + + $self->year($::form->{year} || DateTime->today->year - 1); + + $::form->{title} = $::locale->text('Mebil Map'); + + my $mapping = new SL::mebil::Mapping($::form, $::form->get_standard_dbh); + + (my $fromacc, my $toacc) = $mapping->calc_mapping($self->{year}); + + $self->report(SL::ReportGenerator->new(\%::myconfig, $::form)); + + my @columns = (qw(name amount)); + + my %column_defs = ( + name => { text => 'Konto', align => 'left' }, + amount => { text => 'Betrag' , align => 'right' }, + ); + + $self->report->set_options( + std_column_visibility => 1, + controller_class => 'Mebil', + output_format => 'HTML', + raw_top_info_text => $self->render('mebil/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->year - 10)..($self->year + 5)) ]), + title => t8('mebil - Mapping: values for #1', $self->year), +# allow_pdf_export => 1, +# allow_csv_export => 1, + ); + $self->report->set_columns(%column_defs); + $self->report->set_column_order(@columns); +# $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id)); + $self->report->set_options_from_form; + $self->add_data_sorted($fromacc); + $self->add_data_sorted($toacc); + + $::lxdebug->leave_sub; + return $self->report->generate_with_headers; +} +sub add_data_sorted { + my $self = shift; + my $data = shift; # hash reference + + foreach my $key (sort keys %$data) { + my %data = ( + name => { data => $key }, + amount => { data => $::form->format_amount(\%::myconfig, $data->{$key}, 2) }, + ); + $self->report->add_data(\%data); + + } +} +sub prepare_report { + my ($self) = @_; + + $self->report(SL::ReportGenerator->new(\%::myconfig, $::form)); + + my @columns = (qw(fromacc typ toacc)); + + #$self->number_columns([ grep { !m/^(?:month|year|quarter)$/ } @columns ]); + + my %column_defs = ( + fromacc => { text => 'Quelle', align => 'left' }, + typ => { text => 'Typ' , align => 'right' }, + toacc => { text => 'Ziel' , align => 'left' }, + ); + + #$column_defs{$_}->{align} = 'right' for @columns; + + $self->report->set_options( + std_column_visibility => 1, + controller_class => 'Mebil', + output_format => 'HTML', + # raw_top_info_text => $self->render('financial_overview/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->current_year - 10)..($self->current_year + 5)) ]), + title => 'mebil - Mapping', +# allow_pdf_export => 1, +# allow_csv_export => 1, + ); + $self->report->set_columns(%column_defs); + $self->report->set_column_order(@columns); +# $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id)); + $self->report->set_options_from_form; +} +sub list_data { + my ($self) = @_; + +# my @visible_columns = $self->report->get_visible_columns; +# my @type_columns = @{ $self->types }; +# my @non_type_columns = grep { my $c = $_; none { $c eq $_ } @type_columns } @visible_columns; + + foreach my $mapping (@{ $self->{data} }) { + my %data = ( + fromacc => { data => $mapping->{fromacc} }, + typ => { data => $mapping->{typ} }, + toacc => { data => $mapping->{toacc} }, + ); + $self->report->add_data(\%data); + } + + return $self->report->generate_with_headers; +} + 1;