epic-ts
[kivitendo-erp.git] / SL / Controller / Mebil.pm
1 package SL::Controller::Mebil;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::Controller::Helper::ReportGenerator;
8 use SL::DBUtils;
9
10 #use Data::Dumper;
11 #use SL::ClientJS;
12
13 use Rose::Object::MakeMethods::Generic (
14   scalar                  => [ qw(report number_columns year current_year objects subtotals_per_quarter salesman_id) ],
15   'scalar --get_set_init' => [ qw(employees types data) ],
16 );
17
18 sub action_map {
19         $::lxdebug->enter_sub;
20         $::lxdebug->message(5, 'controller=mebil/action=map');
21         my ($self) = @_;
22         
23         $::form->header(no_layout => 1);
24         
25         print "<h1>Mebil running</h1>";
26
27         my $sql = "SELECT  chart_id,xbrl_tag from mebil_mapping";
28         my $result = SL::DBUtils::do_query($::form, $::form->get_standard_dbh, $sql);
29         $::lxdebug->message(5, "result= $result");
30         print "$result<br>\n";
31         
32         my @r = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
33         print ref($r[1])||"SCALAR";
34         print "<br>";
35         my $fst = $r[1];
36         while (my($k,$v) = each(%$fst)) {
37                 print $k, " : ", $v, "</br>\n";
38         }
39         print "<br>";
40         print scalar @r;
41         print "<br>";
42         print @r;
43         print "<p>Mebil ready</p>";
44         $::lxdebug->leave_sub;
45 }
46
47 sub action_showmap {
48         $::lxdebug->enter_sub;
49         my ($self) = @_;
50
51         my $sql = "SELECT  chart_id,xbrl_tag from mebil_mapping";
52         $self->{data} = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
53
54 #       $self->get_objects;
55 #       $self->calculate_one_time_data;
56 #       $self->calculate_periodic_invoices;
57         $self->prepare_report;
58         $self->list_data;
59 =cut
60         $::form->header(no_layout => 1);
61         
62         print "<h1>Mebil-Mapping</h1>";
63         print "<p>Folgende Zuordnungen sind in der DB hinterlegt:";
64
65         
66         print "<table><tr><th>Konto</th><th>Ziel</th></tr>\n";
67         foreach my $mapping (@{ $self->{data} }) {
68                 print "<tr><td>",$mapping->{chart_id},"</td><td>",$mapping->{xbrl_tag},"</td></tr>\n";
69         } 
70         print "</table>\n";
71 =cut
72         $::lxdebug->leave_sub;
73 }
74 sub prepare_report {
75   my ($self)      = @_;
76
77   $self->report(SL::ReportGenerator->new(\%::myconfig, $::form));
78
79   my @columns = (qw(chart_id xbrl_tag));
80
81   #$self->number_columns([ grep { !m/^(?:month|year|quarter)$/ } @columns ]);
82
83   my %column_defs          = (
84     chart_id                  => { text => 'Kontonummer'                  },
85     xbrl_tag                   => { text => 'XBRL'                   },
86   );
87
88   $column_defs{$_}->{align} = 'right' for @columns;
89
90   $self->report->set_options(
91     std_column_visibility => 1,
92     controller_class      => 'Mebil',
93     output_format         => 'HTML',
94  #   raw_top_info_text     => $self->render('financial_overview/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->current_year - 10)..($self->current_year + 5)) ]),
95  #   title                 => t8('Financial overview for #1', $self->year),
96  #   allow_pdf_export      => 1,
97  #   allow_csv_export      => 1,
98   );
99   $self->report->set_columns(%column_defs);
100   $self->report->set_column_order(@columns);
101 #  $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id));
102   $self->report->set_options_from_form;
103 }
104 sub list_data {
105         my ($self)           = @_;
106
107 #  my @visible_columns  = $self->report->get_visible_columns;
108 #  my @type_columns     = @{ $self->types };
109 #  my @non_type_columns = grep { my $c = $_; none { $c eq $_ } @type_columns } @visible_columns;
110
111         foreach my $mapping (@{ $self->{data} }) {
112                 my %data = (
113                         chart_id => { data => $mapping->{chart_id}},
114                         xbrl_tag => { data => $mapping->{xbrl_tag}},
115                 );
116                 $self->report->add_data(\%data);
117         }
118  
119         return $self->report->generate_with_headers;
120 }
121
122
123 =cut
124 sub get_objects {
125         my ($self) = @_;
126         $self->objects({
127             sales_quotations       => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_quotation')   ]]),
128             sales_orders           => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('sales_order')       ]], with_objects => [ qw(periodic_invoices_config) ]),
129             sales_orders_per_inv   => [],
130             requests_for_quotation => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('request_quotation') ]]),
131             purchase_orders        => SL::DB::Manager::Order->get_all(          where => [ and => [ @f_date, @f_salesman, SL::DB::Manager::Order->type_filter('purchase_order')    ]]),
132             sales_invoices         => SL::DB::Manager::Invoice->get_all(        where => [ and => [ @f_date, @f_salesman, ]]),
133             purchase_invoices      => SL::DB::Manager::PurchaseInvoice->get_all(where => [ and =>  \@f_date ]),
134             periodic_invoices_cfg  => SL::DB::Manager::PeriodicInvoicesConfig->get_all(where => [ active => 1, $self->salesman_id ? ('order.salesman_id' => $self->salesman_id) : () ], with_objects => [ qw(order) ]),
135   });
136
137   $self->objects->{sales_orders} = [ grep { !$_->periodic_invoices_config || !$_->periodic_invoices_config->active } @{ $self->objects->{sales_orders} } ];
138 }
139 =cut
140
141 1;