1 package SL::Controller::Mebil;
5 use parent qw(SL::Controller::Base);
7 #use SL::Controller::Helper::ReportGenerator;
8 use SL::ReportGenerator;
14 use Rose::Object::MakeMethods::Generic (
15 scalar => [ qw(report number_columns year current_year objects subtotals_per_quarter salesman_id) ],
16 'scalar --get_set_init' => [ qw(employees types data) ],
20 $::lxdebug->enter_sub;
21 $::lxdebug->message(5, 'controller=mebil/action=map');
24 $::form->header(no_layout => 1);
26 print "<h1>Mebil running</h1>";
28 my $sql = "SELECT chart_id,xbrl_tag from mebil_mapping";
29 my $result = SL::DBUtils::do_query($::form, $::form->get_standard_dbh, $sql);
30 $::lxdebug->message(5, "result= $result");
31 print "$result<br>\n";
33 my @r = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
34 print ref($r[1])||"SCALAR";
37 while (my($k,$v) = each(%$fst)) {
38 print $k, " : ", $v, "</br>\n";
44 print "<p>Mebil ready</p>";
45 $::lxdebug->leave_sub;
49 $::lxdebug->enter_sub;
52 my $sql = "SELECT fromacc,typ,toacc from mebil_mapping order by ordering";
53 $self->{data} = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
55 $self->prepare_report;
58 $::lxdebug->leave_sub;
62 $::lxdebug->enter_sub;
65 my $sql = "SELECT fromacc,typ,toacc from mebil_mapping order by ordering";
66 $self->{data} = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
70 foreach my $mapping (@{ $self->{data} }) {
71 if ($mapping->{typ} eq 'H') {
73 $sql = "SELECT SUM(ac.amount) AS saldo
75 JOIN chart c ON (c.id = ac.chart_id)
76 WHERE (ac.transdate <= '31.12.2020')
77 AND (c.accno = '$mapping->{fromacc}') ";
78 my $result = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
79 $fromacc{$mapping->{fromacc}} = $result->[0]->{saldo};
80 $toacc{$mapping->{toacc}} += $result->[0]->{saldo};
82 elsif ($mapping->{typ} eq 'S') {
84 $fromacc{$mapping->{fromacc}} = 200.;
85 $toacc{$mapping->{toacc}} = 200.;
87 elsif ($mapping->{typ} eq 'V') {
89 $fromacc{$mapping->{fromacc}} = 300.;
90 $toacc{$mapping->{toacc}} = 300.;
92 elsif ($mapping->{typ} eq 'A') {
94 $fromacc{$mapping->{fromacc}} = 400.;
95 $toacc{$mapping->{toacc}} = 400.;
97 elsif ($mapping->{typ} eq 'X') {
99 $fromacc{$mapping->{fromacc}} += $toacc{$mapping->{fromacc}};
100 $toacc{$mapping->{toacc}} += $toacc{$mapping->{fromacc}};
103 die "Error: Invalid mapping type\n";
107 $self->report(SL::ReportGenerator->new(\%::myconfig, $::form));
109 my @columns = (qw(name amount));
112 name => { text => 'Konto', align => 'left' },
113 amount => { text => 'Betrag' , align => 'right' },
116 #$column_defs{$_}->{align} = 'right' for @columns;
118 $self->report->set_options(
119 std_column_visibility => 1,
120 controller_class => 'Mebil',
121 output_format => 'HTML',
122 # raw_top_info_text => $self->render('financial_overview/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->current_year - 10)..($self->current_year + 5)) ]),
123 title => 'mebil - Mapping',
124 # allow_pdf_export => 1,
125 # allow_csv_export => 1,
127 $self->report->set_columns(%column_defs);
128 $self->report->set_column_order(@columns);
129 # $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id));
130 $self->report->set_options_from_form;
132 while (my($a,$v) = each(%fromacc)) {
134 # list only kivitendo accounts
136 name => { data => $a },
137 amount => { data => $v },
139 $self->report->add_data(\%data);
142 while (my($a,$v) = each(%toacc)) {
144 name => { data => $a },
145 amount => { data => $v },
147 $self->report->add_data(\%data);
150 return $self->report->generate_with_headers;
151 $::lxdebug->leave_sub;
157 $self->report(SL::ReportGenerator->new(\%::myconfig, $::form));
159 my @columns = (qw(fromacc typ toacc));
161 #$self->number_columns([ grep { !m/^(?:month|year|quarter)$/ } @columns ]);
164 fromacc => { text => 'Quelle', align => 'left' },
165 typ => { text => 'Typ' , align => 'right' },
166 toacc => { text => 'Ziel' , align => 'left' },
169 #$column_defs{$_}->{align} = 'right' for @columns;
171 $self->report->set_options(
172 std_column_visibility => 1,
173 controller_class => 'Mebil',
174 output_format => 'HTML',
175 # raw_top_info_text => $self->render('financial_overview/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->current_year - 10)..($self->current_year + 5)) ]),
176 title => 'mebil - Mapping',
177 # allow_pdf_export => 1,
178 # allow_csv_export => 1,
180 $self->report->set_columns(%column_defs);
181 $self->report->set_column_order(@columns);
182 # $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id));
183 $self->report->set_options_from_form;
188 # my @visible_columns = $self->report->get_visible_columns;
189 # my @type_columns = @{ $self->types };
190 # my @non_type_columns = grep { my $c = $_; none { $c eq $_ } @type_columns } @visible_columns;
192 foreach my $mapping (@{ $self->{data} }) {
194 fromacc => { data => $mapping->{fromacc} },
195 typ => { data => $mapping->{typ} },
196 toacc => { data => $mapping->{toacc} },
198 $self->report->add_data(\%data);
201 return $self->report->generate_with_headers;