1 package SL::Controller::Mebil;
5 use parent qw(SL::Controller::Base);
7 #use SL::Controller::Helper::ReportGenerator;
8 use SL::ReportGenerator;
11 use SL::Locale::String; # t8
16 use Rose::Object::MakeMethods::Generic (
17 scalar => [ qw(report number_columns year current_year objects subtotals_per_quarter salesman_id) ],
18 'scalar --get_set_init' => [ qw(employees types data) ],
22 $::lxdebug->enter_sub;
23 $::lxdebug->message(5, 'controller=mebil/action=map');
26 $::form->header(no_layout => 1);
28 print "<h1>Mebil running</h1>";
30 my $sql = "SELECT chart_id,xbrl_tag from mebil_mapping";
31 my $result = SL::DBUtils::do_query($::form, $::form->get_standard_dbh, $sql);
32 $::lxdebug->message(5, "result= $result");
33 print "$result<br>\n";
35 my @r = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
36 print ref($r[1])||"SCALAR";
39 while (my($k,$v) = each(%$fst)) {
40 print $k, " : ", $v, "</br>\n";
46 print "<p>Mebil ready</p>";
47 $::lxdebug->leave_sub;
51 $::lxdebug->enter_sub;
54 $::form->{title} = $::locale->text('Mebil Map');
56 my $sql = "SELECT fromacc,typ,toacc from mebil_mapping order by ordering";
57 $self->{data} = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
59 $self->prepare_report;
62 $::lxdebug->leave_sub;
66 $::lxdebug->enter_sub;
69 $self->year($::form->{year} || DateTime->today->year - 1);
71 $::form->{title} = $::locale->text('Mebil Map');
73 my $sql = "SELECT fromacc,typ,toacc from mebil_mapping order by ordering";
74 $self->{data} = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
78 my $year = $self->year;
79 foreach my $mapping (@{ $self->{data} }) {
80 if ($mapping->{typ} eq 'H') {
82 $sql = "SELECT SUM(ac.amount) AS saldo
84 JOIN chart c ON (c.id = ac.chart_id)
85 WHERE (ac.transdate <= '31.12.$year')
86 AND (c.accno = '$mapping->{fromacc}') ";
87 my $result = SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, $sql);
88 $fromacc{$mapping->{fromacc}} = $result->[0]->{saldo};
89 $toacc{$mapping->{toacc}} += $result->[0]->{saldo};
91 elsif ($mapping->{typ} eq 'S') {
93 $sql = "SELECT SUM(ac.amount)* -1 AS saldo
95 JOIN chart c ON (c.id = ac.chart_id)
96 WHERE (ac.transdate <= '31.12.$year')
97 AND (c.accno = '$mapping->{fromacc}') ";
98 my @result = SL::DBUtils::selectfirst_array_query($::form, $::form->get_standard_dbh, $sql);
99 $fromacc{$mapping->{fromacc}} = $result[0];
100 $toacc{$mapping->{toacc}} += $result[0];
102 # elsif ($mapping->{typ} eq 'V') {
104 # $fromacc{$mapping->{fromacc}} = 300.;
105 # $toacc{$mapping->{toacc}} = 300.;
107 # elsif ($mapping->{typ} eq 'A') {
109 # $fromacc{$mapping->{fromacc}} = 400.;
110 # $toacc{$mapping->{toacc}} = 400.;
112 elsif ($mapping->{typ} eq 'X') {
113 # add to other account
114 $toacc{$mapping->{toacc}} += $toacc{$mapping->{fromacc}};
116 elsif ($mapping->{typ} eq 'Y') {
117 # substract from other account
118 $toacc{$mapping->{toacc}} -= $toacc{$mapping->{fromacc}};
120 elsif ($mapping->{typ} eq 'C') {
125 die "Error: Invalid mapping type: $mapping->{typ}\n";
129 $self->report(SL::ReportGenerator->new(\%::myconfig, $::form));
131 my @columns = (qw(name amount));
134 name => { text => 'Konto', align => 'left' },
135 amount => { text => 'Betrag' , align => 'right' },
138 $self->report->set_options(
139 std_column_visibility => 1,
140 controller_class => 'Mebil',
141 output_format => 'HTML',
142 raw_top_info_text => $self->render('mebil/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->year - 10)..($self->year + 5)) ]),
143 title => t8('mebil - Mapping: values for #1', $self->year),
144 # allow_pdf_export => 1,
145 # allow_csv_export => 1,
147 $self->report->set_columns(%column_defs);
148 $self->report->set_column_order(@columns);
149 # $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id));
150 $self->report->set_options_from_form;
151 $self->add_data_sorted(\%fromacc);
152 $self->add_data_sorted(\%toacc);
154 return $self->report->generate_with_headers;
155 $::lxdebug->leave_sub;
157 sub add_data_sorted {
159 my $data = shift; # hash reference
161 foreach my $key (sort keys %$data) {
163 name => { data => $key },
164 amount => { data => $::form->format_amount(\%::myconfig, $data->{$key}, 2) },
166 $self->report->add_data(\%data);
173 $self->report(SL::ReportGenerator->new(\%::myconfig, $::form));
175 my @columns = (qw(fromacc typ toacc));
177 #$self->number_columns([ grep { !m/^(?:month|year|quarter)$/ } @columns ]);
180 fromacc => { text => 'Quelle', align => 'left' },
181 typ => { text => 'Typ' , align => 'right' },
182 toacc => { text => 'Ziel' , align => 'left' },
185 #$column_defs{$_}->{align} = 'right' for @columns;
187 $self->report->set_options(
188 std_column_visibility => 1,
189 controller_class => 'Mebil',
190 output_format => 'HTML',
191 # raw_top_info_text => $self->render('financial_overview/report_top', { output => 0 }, YEARS_TO_LIST => [ reverse(($self->current_year - 10)..($self->current_year + 5)) ]),
192 title => 'mebil - Mapping',
193 # allow_pdf_export => 1,
194 # allow_csv_export => 1,
196 $self->report->set_columns(%column_defs);
197 $self->report->set_column_order(@columns);
198 # $self->report->set_export_options(qw(list year subtotals_per_quarter salesman_id));
199 $self->report->set_options_from_form;
204 # my @visible_columns = $self->report->get_visible_columns;
205 # my @type_columns = @{ $self->types };
206 # my @non_type_columns = grep { my $c = $_; none { $c eq $_ } @type_columns } @visible_columns;
208 foreach my $mapping (@{ $self->{data} }) {
210 fromacc => { data => $mapping->{fromacc} },
211 typ => { data => $mapping->{typ} },
212 toacc => { data => $mapping->{toacc} },
214 $self->report->add_data(\%data);
217 return $self->report->generate_with_headers;