Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5be29159

Von Sven Schöling vor mehr als 15 Jahren hinzugefügt

  • ID 5be291594a4ead20f6900b249357deb262137cac
  • Vorgänger dc6e7f0d
  • Nachfolger bd6a8782

Bilanz Fix - erste Version.

Unterschiede anzeigen:

SL/RP.pm
1
###=====================================================================
1
#=====================================================================
2 2
# LX-Office ERP
3 3
# Copyright (C) 2004
4 4
# Based on SQL-Ledger Version 2.1.9
......
36 36

  
37 37
use SL::DBUtils;
38 38
use Data::Dumper;
39
use List::Util qw(sum);
40
use strict;
41
use warnings;
42

  
39 43

  
44
# new implementation of balance sheet
45
# readme!
46
#
47
# stuff missing from the original implementation:
48
# - bold stuff
49
# - format (2 places, varying signs of negative amounts)
50
# - rounding (might not be necessary)
51
# - accno and subdescription
52
# - proper testing for heading charts
53
# - transmission from $form to TMPL realm is not as clear as i'd like
40 54
sub balance_sheet {
41 55
  $main::lxdebug->enter_sub();
42 56

  
43
  my ($self, $myconfig, $form) = @_;
44

  
45
  # connect to database
46
  my $dbh = $form->dbconnect($myconfig);
57
  my $myconfig = \%main::myconfig;
58
  my $form     = $main::form;
59
  my $dbh      = $form->get_standard_dbh($myconfig);
47 60

  
48 61
  my $last_period = 0;
49 62
  my @categories  = qw(A C L Q);
......
54 67
  }
55 68

  
56 69
  $form->{decimalplaces} *= 1;
70
  my $dec = $form->{decimalplaces};
57 71

  
58
  &get_accounts($dbh, $last_period, "", $form->{asofdate}, $form,
59
                \@categories);
72
  get_accounts($dbh, $last_period, "", $form->{asofdate}, $form, \@categories);
60 73

  
61 74
  # if there are any compare dates
62 75
  if ($form->{compareasofdate}) {
63

  
64 76
    $last_period = 1;
65
    &get_accounts($dbh, $last_period, "", $form->{compareasofdate},
66
                  $form, \@categories);
67

  
77
    get_accounts($dbh, $last_period, "", $form->{compareasofdate}, $form, \@categories);
68 78
    $form->{last_period} = conv_dateq($form->{compareasofdate});
69

  
70 79
  }
71 80

  
72
  # disconnect
73
  $dbh->disconnect;
74

  
75 81
  # now we got $form->{A}{accno}{ }    assets
76 82
  # and $form->{L}{accno}{ }           liabilities
77 83
  # and $form->{Q}{accno}{ }           equity
78 84
  # build asset accounts
79 85

  
80
  my $str;
81
  my $key;
82

  
83
  my %account = (
84
                 'A' => { 'label'  => 'asset',
85
                          'labels' => 'assets',
86
                          'ml'     => -1
87
                 },
88
                 'L' => { 'label'  => 'liability',
89
                          'labels' => 'liabilities',
90
                          'ml'     => 1
91
                 },
92
                 'Q' => { 'label'  => 'equity',
93
                          'labels' => 'equity',
94
                          'ml'     => 1
95
                 });
86
  my %account = ('A' => { 'ml'     => -1 },
87
                 'L' => { 'ml'     =>  1 },
88
                 'Q' => { 'ml'     =>  1 });
89

  
90
  my $TMPL_DATA = {};
96 91

  
97 92
  foreach my $category (grep { !/C/ } @categories) {
98 93

  
99
    foreach $key (sort keys %{ $form->{$category} }) {
94
    $TMPL_DATA->{$category} = [];
100 95

  
101
      $str = ($form->{l_heading}) ? $form->{padding} : "";
96
    foreach my $key (sort keys %{ $form->{$category} }) {
102 97

  
103
      if ($form->{$category}{$key}{charttype} eq "A") {
104
        $str .=
105
          ($form->{l_accno})
106
          ? "$form->{$category}{$key}{accno} - $form->{$category}{$key}{description}"
107
          : "$form->{$category}{$key}{description}";
108
      }
109
      if ($form->{$category}{$key}{charttype} eq "H") {
110
        if ($account{$category}{subtotal} && $form->{l_subtotal}) {
111
          $dash = "- ";
112
          push(@{ $form->{"$account{$category}{label}_account"} },
113
               "$str$form->{bold}$account{$category}{subdescription}$form->{endbold}"
114
          );
115
          push(@{ $form->{"$account{$category}{label}_this_period"} },
116
               $form->format_amount(
117
                        $myconfig,
118
                        $account{$category}{subthis} * $account{$category}{ml},
119
                        $form->{decimalplaces}, $dash
120
               ));
98
       my $row = { %{ $form->{$category}{$key} } };
121 99

  
122
          if ($last_period) {
123
            push(@{ $form->{"$account{$category}{label}_last_period"} },
124
                 $form->format_amount(
125
                        $myconfig,
126
                        $account{$category}{sublast} * $account{$category}{ml},
127
                        $form->{decimalplaces}, $dash
128
                 ));
129
          }
100
      # if charttype "heading" - calculate this entry, start a new batch of charts belonging to this heading and skip the rest bo the loop
101
      if ($row->{charttype} eq "H") {
102
        if ($account{$category}{subtotal} && $form->{l_subtotal}) {
103
          $row->{subdescription} = $account{$category}{subdescription};
104
          $row->{this}           = $account{$category}{subthis} * $account{$category}{ml};                   # format: $dec, $dash
105
          $row->{last}           = $account{$category}{sublast} * $account{$category}{ml} if $last_period;   # format: $dec, $dash
130 106
        }
131 107

  
132
        $str =
133
          "$form->{bold}$form->{$category}{$key}{description}$form->{endbold}";
134

  
108
        $row->{subheader} = 1;
135 109
        $account{$category}{subthis}        = $form->{$category}{$key}{this};
136 110
        $account{$category}{sublast}        = $form->{$category}{$key}{last};
137
        $account{$category}{subdescription} =
138
          $form->{$category}{$key}{description};
111
        $account{$category}{subdescription} = $form->{$category}{$key}{description};
139 112
        $account{$category}{subtotal} = 1;
140 113

  
141 114
        $form->{$category}{$key}{this} = 0;
142 115
        $form->{$category}{$key}{last} = 0;
143 116

  
144 117
        next unless $form->{l_heading};
145

  
146
        $dash = " ";
147 118
      }
148 119

  
149
      # push description onto array
150
      push(@{ $form->{"$account{$category}{label}_account"} }, $str);
120
      $row->{this} = $form->{$category}{$key}{this} * $account{$category}{ml};
151 121

  
152
      if ($form->{$category}{$key}{charttype} eq 'A') {
153
        $form->{"total_$account{$category}{labels}_this_period"} +=
154
          $form->{$category}{$key}{this} * $account{$category}{ml};
155
        $dash = "- ";
122
      # only add assets
123
      if ($row->{charttype} eq 'A') {
124
        $form->{total}{$category}{this} += $row->{this};
156 125
      }
157 126

  
158
      push(@{ $form->{"$account{$category}{label}_this_period"} },
159
           $form->format_amount(
160
                      $myconfig,
161
                      $form->{$category}{$key}{this} * $account{$category}{ml},
162
                      $form->{decimalplaces}, $dash
163
           ));
164

  
165 127
      if ($last_period) {
166
        $form->{"total_$account{$category}{labels}_last_period"} +=
167
          $form->{$category}{$key}{last} * $account{$category}{ml};
168

  
169
        push(@{ $form->{"$account{$category}{label}_last_period"} },
170
             $form->format_amount(
171
                      $myconfig,
172
                      $form->{$category}{$key}{last} * $account{$category}{ml},
173
                      $form->{decimalplaces}, $dash
174
             ));
128
        $row->{last}                     = $form->{$category}{$key}{last} * $account{$category}{ml};
129
        $form->{total}{$category}{last} += $row->{last};
175 130
      }
176
    }
177 131

  
178
    $str = ($form->{l_heading}) ? $form->{padding} : "";
179
    if ($account{$category}{subtotal} && $form->{l_subtotal}) {
180
      push(@{ $form->{"$account{$category}{label}_account"} },
181
           "$str$form->{bold}$account{$category}{subdescription}$form->{endbold}"
182
      );
183
      push(@{ $form->{"$account{$category}{label}_this_period"} },
184
           $form->format_amount(
185
                        $myconfig,
186
                        $account{$category}{subthis} * $account{$category}{ml},
187
                        $form->{decimalplaces}, $dash
188
           ));
132
      push @{ $TMPL_DATA->{$category} }, $row;
133
    } # foreach
189 134

  
190
      if ($last_period) {
191
        push(@{ $form->{"$account{$category}{label}_last_period"} },
192
             $form->format_amount(
193
                        $myconfig,
194
                        $account{$category}{sublast} * $account{$category}{ml},
195
                        $form->{decimalplaces}, $dash
196
             ));
197
      }
135
    if ($account{$category}{subtotal} && $form->{l_subtotal}) {
136
      $TMPL_DATA->{$category}[-1]{subdescription} = $account{$category}{subdescription};
137
      $TMPL_DATA->{$category}[-1]{this}           = $account{$category}{subthis} * $account{$category}{ml};                   # format: $dec, $dash
138
      $TMPL_DATA->{$category}[-1]{last}           = $account{$category}{sublast} * $account{$category}{ml} if $last_period;   # format: $dec, $dash
198 139
    }
199 140

  
141
    $TMPL_DATA->{total}{$category}{this} = sum map { $_->{this} } @{ $TMPL_DATA->{$category} };
142
    $TMPL_DATA->{total}{$category}{last} = sum map { $_->{last} } @{ $TMPL_DATA->{$category} };
200 143
  }
201 144

  
202
  # totals for assets, liabilities
203
  $form->{total_assets_this_period} =
204
    $form->round_amount($form->{total_assets_this_period},
205
                        $form->{decimalplaces});
206
  $form->{total_liabilities_this_period} =
207
    $form->round_amount($form->{total_liabilities_this_period},
208
                        $form->{decimalplaces});
209
  $form->{total_equity_this_period} =
210
    $form->round_amount($form->{total_equity_this_period},
211
                        $form->{decimalplaces});
212

  
213
  # calculate earnings
214
  $form->{earnings_this_period} =
215
    $form->{total_assets_this_period} -
216
    $form->{total_liabilities_this_period} - $form->{total_equity_this_period};
217

  
218
  push(@{ $form->{equity_this_period} },
219
       $form->format_amount($myconfig,
220
                            $form->{earnings_this_period},
221
                            $form->{decimalplaces}, "- "
222
       ));
223

  
224
  $form->{total_equity_this_period} =
225
    $form->round_amount(
226
             $form->{total_equity_this_period} + $form->{earnings_this_period},
227
             $form->{decimalplaces});
228

  
229
  # add liability + equity
230
  $form->{total_this_period} =
231
    $form->format_amount(
232
    $myconfig,
233
    $form->{total_liabilities_this_period} + $form->{total_equity_this_period},
234
    $form->{decimalplaces},
235
    "- ");
236

  
237
  if ($last_period) {
238

  
239
    # totals for assets, liabilities
240
    $form->{total_assets_last_period} =
241
      $form->round_amount($form->{total_assets_last_period},
242
                          $form->{decimalplaces});
243
    $form->{total_liabilities_last_period} =
244
      $form->round_amount($form->{total_liabilities_last_period},
245
                          $form->{decimalplaces});
246
    $form->{total_equity_last_period} =
247
      $form->round_amount($form->{total_equity_last_period},
248
                          $form->{decimalplaces});
249

  
250
    # calculate retained earnings
251
    $form->{earnings_last_period} =
252
      $form->{total_assets_last_period} -
253
      $form->{total_liabilities_last_period} -
254
      $form->{total_equity_last_period};
255

  
256
    push(@{ $form->{equity_last_period} },
257
         $form->format_amount($myconfig,
258
                              $form->{earnings_last_period},
259
                              $form->{decimalplaces}, "- "
260
         ));
261

  
262
    $form->{total_equity_last_period} =
263
      $form->round_amount(
264
             $form->{total_equity_last_period} + $form->{earnings_last_period},
265
             $form->{decimalplaces});
266

  
267
    # add liability + equity
268
    $form->{total_last_period} =
269
      $form->format_amount($myconfig,
270
                           $form->{total_liabilities_last_period} +
271
                             $form->{total_equity_last_period},
272
                           $form->{decimalplaces},
273
                           "- ");
145
  for my $period (qw(this last)) {
146
    next if ($period eq 'last' && !$last_period);
274 147

  
148
    $form->{E}{$period}             = $form->{total}{A}{$period} - $form->{total}{L}{$period} - $form->{total}{Q}{$period};
149
    $form->{total}{Q}{$period}     += $form->{E}{$period};
150
    $TMPL_DATA->{total}{Q}{$period} = $form->{total}{Q}{$period};
151
    $TMPL_DATA->{total}{$period}    = $form->{total}{L}{$period} + $form->{total}{Q}{$period};
275 152
  }
276 153

  
277
  $form->{total_liabilities_last_period} =
278
    $form->format_amount($myconfig,
279
                         $form->{total_liabilities_last_period},
280
                         $form->{decimalplaces}, "- ")
281
    if ($form->{total_liabilities_last_period} != 0);
282

  
283
  $form->{total_equity_last_period} =
284
    $form->format_amount($myconfig,
285
                         $form->{total_equity_last_period},
286
                         $form->{decimalplaces}, "- ")
287
    if ($form->{total_equity_last_period} != 0);
288

  
289
  $form->{total_assets_last_period} =
290
    $form->format_amount($myconfig,
291
                         $form->{total_assets_last_period},
292
                         $form->{decimalplaces}, "- ")
293
    if ($form->{total_assets_last_period} != 0);
294

  
295
  $form->{total_assets_this_period} =
296
    $form->format_amount($myconfig,
297
                         $form->{total_assets_this_period},
298
                         $form->{decimalplaces}, "- ");
299

  
300
  $form->{total_liabilities_this_period} =
301
    $form->format_amount($myconfig,
302
                         $form->{total_liabilities_this_period},
303
                         $form->{decimalplaces}, "- ");
304

  
305
  $form->{total_equity_this_period} =
306
    $form->format_amount($myconfig,
307
                         $form->{total_equity_this_period},
308
                         $form->{decimalplaces}, "- ");
154
  push @{ $TMPL_DATA->{Q} }, $form->{E};
309 155

  
310 156
  $main::lxdebug->leave_sub();
157

  
158
  return $TMPL_DATA;
311 159
}
312 160

  
313 161
sub get_accounts {
......
318 166
  my ($null, $department_id) = split /--/, $form->{department};
319 167

  
320 168
  my $query;
321
  my $dpt_where;
322
  my $dpt_join;
323
  my $project;
324
  my $where    = "1 = 1";
325
  my $glwhere  = "";
326
  my $subwhere = "";
169
  my $dpt_where = '';
170
  my $dpt_join  = '';
171
  my $project   = '';
172
  my $where     = "1 = 1";
173
  my $glwhere   = "";
174
  my $subwhere  = "";
327 175
  my $item;
328 176
  my $sth;
177
  my $dec = $form->{decimalplaces};
329 178

  
330 179
  my $category = qq| AND (| . join(" OR ", map({ "(c.category = " . $dbh->quote($_) . ")" } @{$categories})) . qq|) |;
331 180

  
......
340 189
  $sth = prepare_execute_query($form, $dbh, $query);
341 190

  
342 191
  my @headingaccounts = ();
343
  while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
192
  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
344 193
    $form->{ $ref->{category} }{ $ref->{accno} }{description} =
345 194
      "$ref->{description}";
346 195
    $form->{ $ref->{category} }{ $ref->{accno} }{charttype} = "H";
......
536 385
  my $accno;
537 386
  my $ref;
538 387

  
539
  my $sth = prepare_execute_query($form, $dbh, $query);
388
  $sth = prepare_execute_query($form, $dbh, $query);
540 389

  
541
  while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
390
  while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
542 391

  
543 392
    if ($ref->{category} eq 'C') {
544 393
      $ref->{category} = 'A';
......
556 405
    }
557 406

  
558 407
    $form->{ $ref->{category} }{ $ref->{accno} }{accno}       = $ref->{accno};
559
    $form->{ $ref->{category} }{ $ref->{accno} }{description} =
560
      $ref->{description};
408
    $form->{ $ref->{category} }{ $ref->{accno} }{description} = $ref->{description};
561 409
    $form->{ $ref->{category} }{ $ref->{accno} }{charttype} = "A";
562 410

  
563 411
    if ($last_period) {
......
571 419
  # remove accounts with zero balance
572 420
  foreach $category (@{$categories}) {
573 421
    foreach $accno (keys %{ $form->{$category} }) {
574
      $form->{$category}{$accno}{last} =
575
        $form->round_amount($form->{$category}{$accno}{last},
576
                            $form->{decimalplaces});
577
      $form->{$category}{$accno}{this} =
578
        $form->round_amount($form->{$category}{$accno}{this},
579
                            $form->{decimalplaces});
422
      $form->{$category}{$accno}{last} = $form->round_amount($form->{$category}{$accno}{last}, $dec);
423
      $form->{$category}{$accno}{this} = $form->round_amount($form->{$category}{$accno}{this}, $dec);
580 424

  
581 425
      delete $form->{$category}{$accno}
582 426
        if (   $form->{$category}{$accno}{this} == 0
......
753 597

  
754 598
  my $sth = prepare_execute_query($form, $dbh, $query);
755 599

  
756
  while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
600
  while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
757 601
    if ($category eq "pos_bwa") {
758 602
      if ($last_period) {
759 603
        $form->{ $ref->{$category} }{kumm} += $ref->{amount};
......
802 646
  }
803 647

  
804 648
  my $acc_cash_where = "";
805
  my $ar_cash_where = "";
806
  my $ap_cash_where = "";
649
#  my $ar_cash_where = "";
650
#  my $ap_cash_where = "";
807 651

  
808 652

  
809 653
  if ($form->{method} eq "cash") {
810 654
    $acc_cash_where = qq| AND (ac.trans_id IN (SELECT id FROM ar WHERE datepaid>='$form->{fromdate}' AND datepaid<='$form->{todate}' UNION SELECT id FROM ap WHERE datepaid>='$form->{fromdate}' AND datepaid<='$form->{todate}' UNION SELECT id FROM gl WHERE transdate>='$form->{fromdate}' AND transdate<='$form->{todate}')) |;
811
    $ar_ap_cash_where = qq| AND (a.datepaid>='$form->{fromdate}' AND a.datepaid<='$form->{todate}') |;
655
#    $ar_ap_cash_where = qq| AND (a.datepaid>='$form->{fromdate}' AND a.datepaid<='$form->{todate}') |;
812 656
  }
813 657

  
814 658
  # get beginning balances
......
824 668

  
825 669
  $sth = prepare_execute_query($form, $dbh, $query, $form->{fromdate});
826 670

  
827
  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
671
  while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
828 672

  
829 673
    if ($ref->{amount} != 0 || $form->{all_accounts}) {
830 674
      $trb{ $ref->{accno} }{description} = $ref->{description};
......
851 695

  
852 696
  $sth = prepare_execute_query($form, $dbh, $query);
853 697

  
854
  while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
698
  while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
855 699
    $trb{ $ref->{accno} }{description} = $ref->{description};
856 700
    $trb{ $ref->{accno} }{charttype}   = 'H';
857 701
    $trb{ $ref->{accno} }{category}    = $ref->{category};
......
862 706
  $sth->finish;
863 707

  
864 708
  $where = " 1 = 1 ";
865
  $saldowhere = " 1 = 1 ";
866
  $sumwhere = " 1 = 1 ";
709
  my $saldowhere    = " 1 = 1 ";
710
  my $sumwhere      = " 1 = 1 ";
711
  my $subwhere      = '';
712
  my $sumsubwhere   = '';
713
  my $saldosubwhere = '';
714
  my $glsaldowhere  = '';
715
  my $glsubwhere    = '';
716
  my $glwhere       = '';
717
  my $glsumwhere    = '';
867 718
  my $tofrom;
868 719

  
869 720
  if ($form->{fromdate} || $form->{todate}) {
870 721
    if ($form->{fromdate}) {
871 722
      my $fromdate = conv_dateq($form->{fromdate});
872
      $tofrom   .= " AND (ac.transdate >= $fromdate)";
873
      $subwhere .= " AND (transdate >= $fromdate)";
874
      $sumsubwhere .= " AND (transdate >= (select date_trunc('year', date $fromdate))) ";
723
      $tofrom        .= " AND (ac.transdate >= $fromdate)";
724
      $subwhere      .= " AND (transdate >= $fromdate)";
725
      $sumsubwhere   .= " AND (transdate >= (select date_trunc('year', date $fromdate))) ";
875 726
      $saldosubwhere .= " AND transdate>=(select date_trunc('year', date $fromdate))  ";
876
      $invwhere .= " AND (a.transdate >= $fromdate)";
877
      $glsaldowhere .= " AND ac.transdate>=(select date_trunc('year', date $fromdate)) ";
878
      $glwhere = " AND (ac.transdate >= $fromdate)";
879
      $glsumwhere = " AND (ac.transdate >= (select date_trunc('year', date $fromdate))) ";
727
      $invwhere      .= " AND (a.transdate >= $fromdate)";
728
      $glsaldowhere  .= " AND ac.transdate>=(select date_trunc('year', date $fromdate)) ";
729
      $glwhere        = " AND (ac.transdate >= $fromdate)";
730
      $glsumwhere     = " AND (ac.transdate >= (select date_trunc('year', date $fromdate))) ";
880 731
    }
881 732
    if ($form->{todate}) {
882 733
      my $todate = conv_dateq($form->{todate});
883
      $tofrom   .= " AND (ac.transdate <= $todate)";
884
      $invwhere .= " AND (a.transdate <= $todate)";
734
      $tofrom        .= " AND (ac.transdate <= $todate)";
735
      $invwhere      .= " AND (a.transdate <= $todate)";
885 736
      $saldosubwhere .= " AND (transdate <= $todate)";
886
      $sumsubwhere .= " AND (transdate <= $todate)";
887
      $subwhere .= " AND (transdate <= $todate)";
888
      $glwhere  .= " AND (ac.transdate <= $todate)";
889
      $glsumwhere .= " AND (ac.transdate <= $todate) ";
890
      $glsaldowhere .= " AND (ac.transdate <= $todate) ";
737
      $sumsubwhere   .= " AND (transdate <= $todate)";
738
      $subwhere      .= " AND (transdate <= $todate)";
739
      $glwhere       .= " AND (ac.transdate <= $todate)";
740
      $glsumwhere    .= " AND (ac.transdate <= $todate) ";
741
      $glsaldowhere  .= " AND (ac.transdate <= $todate) ";
891 742
   }
892 743
  }
893 744

  
......
1024 875
  $sth = prepare_execute_query($form, $dbh, $query);
1025 876

  
1026 877
  # calculate the debit and credit in the period
1027
  while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
878
  while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
1028 879
    $trb{ $ref->{accno} }{description} = $ref->{description};
1029 880
    $trb{ $ref->{accno} }{charttype}   = 'A';
1030 881
    $trb{ $ref->{accno} }{category}    = $ref->{category};
......
1183 1034
      # get DR/CR
1184 1035
      do_statement($form, $drcr, $q_drcr, $ref->{accno}, $ref->{accno}, $ref->{accno}, $ref->{accno}, $ref->{accno}, $ref->{accno});
1185 1036

  
1186
      ($debit, $credit, $saldo, $haben_saldo, $soll_saldo, $soll_kumuliert, $haben_kumuliert) = (0, 0, 0, 0, 0, 0, 0);
1037
      ($debit, $credit, $saldo, $haben_saldo, $soll_saldo) = (0, 0, 0, 0, 0);
1038
      my ($soll_kumuliert, $haben_kumuliert) = (0, 0);
1187 1039
      $last_transaction = "";
1188 1040
      while (($debit, $credit, $saldo, $haben_kumuliert, $soll_kumuliert, $last_transaction) = $drcr->fetchrow_array) {
1189 1041
        $ref->{debit}  += $debit;
......
1228 1080
    }
1229 1081

  
1230 1082
    # add subtotal
1083
    my @accno;
1231 1084
    @accno = grep { $_ le "$ref->{accno}" } @headingaccounts;
1232 1085
    $accno = pop @accno;
1233 1086
    if ($accno) {
......
1246 1099
  $dbh->disconnect;
1247 1100

  
1248 1101
  # debits and credits for headings
1249
  foreach $accno (@headingaccounts) {
1102
  foreach my $accno (@headingaccounts) {
1250 1103
    foreach $ref (@{ $form->{TB} }) {
1251 1104
      if ($accno eq $ref->{accno}) {
1252 1105
        $ref->{debit}  = $trb{$accno}{debit};
......
1316 1169

  
1317 1170
  my $dpt_join;
1318 1171
  if ($form->{department}) {
1319
    ($null, $department_id) = split /--/, $form->{department};
1172
    my ($null, $department_id) = split /--/, $form->{department};
1320 1173
    $dpt_join = qq| JOIN department d ON (a.department_id = d.id) |;
1321 1174
    $where .= qq| AND (a.department_id = | . conv_i($department_id, 'NULL') . qq|)|;
1322 1175
  }
......
1363 1216
  while (my ($id) = $sth->fetchrow_array) {
1364 1217
    do_statement($form, $sth_details, $q_details, $id);
1365 1218

  
1366
    while (my $ref = $sth_details->fetchrow_hashref(NAME_lc)) {
1219
    while (my $ref = $sth_details->fetchrow_hashref("NAME_lc")) {
1367 1220
      $ref->{module} = ($ref->{invoice}) ? $invoice : $arap;
1368 1221
      $ref->{exchangerate} = 1 unless $ref->{exchangerate};
1369 1222
      push @{ $form->{AG} }, $ref;
......
1489 1342
  my $sortorder = join ', ', $form->sort_columns(qw(transdate invnumber name));
1490 1343
  $sortorder = $form->{sort} if ($form->{sort} && grep({ $_ eq $form->{sort} } qw(id transdate invnumber name netamount tax)));
1491 1344

  
1345
  my $query = '';
1492 1346
  if ($form->{report} !~ /nontaxable/) {
1493 1347
    $query =
1494 1348
      qq|SELECT a.id, '0' AS invoice, $transdate AS transdate, a.invnumber, n.name, a.netamount,
......
1588 1442

  
1589 1443
  my $ml = 1;
1590 1444
  my $arap;
1445
  my $table;
1591 1446
  if ($form->{db} eq 'ar') {
1592 1447
    $table = 'customer';
1593 1448
    $ml = -1;
......
1658 1513
  }
1659 1514

  
1660 1515
  $query = qq|SELECT id, accno, description FROM chart WHERE accno = ?|;
1661
  my $sth = prepare_query($form, $dbh, $query);
1516
  $sth = prepare_query($form, $dbh, $query);
1662 1517

  
1663 1518
  my $q_details =
1664 1519
      qq|SELECT c.name, a.invnumber, a.ordnumber,
......
1731 1586
  &get_accounts_g($dbh, $last_period, $form->{fromdate}, $form->{todate}, $form, "pos_bwa");
1732 1587

  
1733 1588
  # if there are any compare dates
1589
  my $year;
1734 1590
  if ($form->{fromdate} || $form->{todate}) {
1735 1591
    $last_period = 1;
1736 1592
    if ($form->{fromdate}) {
......
1740 1596
      $form->{todate} =~ /[0-9]*\.[0-9]*\.([0-9]*)/;
1741 1597
      $year = $1;
1742 1598
    }
1743
    $kummfromdate = $form->{comparefromdate};
1744
    $kummtodate   = $form->{comparetodate};
1599
    my $kummfromdate = $form->{comparefromdate};
1600
    my $kummtodate   = $form->{comparetodate};
1745 1601
    &get_accounts_g($dbh, $last_period, $kummfromdate, $kummtodate, $form, "pos_bwa");
1746 1602
  }
1747 1603

  
1748
  @periods        = qw(jetzt kumm);
1749
  @gesamtleistung = qw(1 2 3);
1750
  @gesamtkosten   = qw (10 11 12 13 14 15 16 17 18 19 20);
1751
  @ergebnisse     =
1604
  my @periods        = qw(jetzt kumm);
1605
  my @gesamtleistung = qw(1 2 3);
1606
  my @gesamtkosten   = qw (10 11 12 13 14 15 16 17 18 19 20);
1607
  my @ergebnisse     =
1752 1608
    qw (rohertrag betriebrohertrag betriebsergebnis neutraleraufwand neutralerertrag ergebnisvorsteuern ergebnis gesamtleistung gesamtkosten);
1753 1609

  
1754
  foreach $key (@periods) {
1610
  foreach my $key (@periods) {
1755 1611
    $form->{ "$key" . "gesamtleistung" } = 0;
1756 1612
    $form->{ "$key" . "gesamtkosten" }   = 0;
1757 1613

  
......
1766 1622
                               '0');
1767 1623
      }
1768 1624
    }
1769
    foreach $item (@gesamtleistung) {
1625
    foreach my $item (@gesamtleistung) {
1770 1626
      $form->{ "$key" . "gesamtleistung" } += $form->{$item}{$key};
1771 1627
    }
1772
    foreach $item (@gesamtkosten) {
1628
    foreach my $item (@gesamtkosten) {
1773 1629
      $form->{ "$key" . "gesamtkosten" } += $form->{$item}{$key};
1774 1630
    }
1775 1631
    $form->{ "$key" . "rohertrag" } =
......
1806 1662
                               '0');
1807 1663
        }
1808 1664
      }
1809
      foreach $item (@ergebnisse) {
1665
      foreach my $item (@ergebnisse) {
1810 1666
        $form->{ "$key" . "gl" . "$item" } =
1811 1667
          $form->format_amount($myconfig,
1812 1668
                               $form->round_amount(
......
1835 1691
                                 '0');
1836 1692
        }
1837 1693
      }
1838
      foreach $item (@ergebnisse) {
1694
      foreach my $item (@ergebnisse) {
1839 1695
        $form->{ "$key" . "gk" . "$item" } =
1840 1696
          $form->format_amount($myconfig,
1841 1697
                               $form->round_amount(
......
1863 1719
                        '0');
1864 1720
        }
1865 1721
      }
1866
      foreach $item (@ergebnisse) {
1722
      foreach my $item (@ergebnisse) {
1867 1723
        $form->{ "$key" . "pk" . "$item" } =
1868 1724
          $form->format_amount($myconfig,
1869 1725
                               $form->round_amount(
......
1891 1747
                         '0');
1892 1748
        }
1893 1749
      }
1894
      foreach $item (@ergebnisse) {
1750
      foreach my $item (@ergebnisse) {
1895 1751
        $form->{ "$key" . "auf" . "$item" } =
1896 1752
          $form->format_amount($myconfig,
1897 1753
                               $form->round_amount(
......
1905 1761
      }
1906 1762
    }
1907 1763

  
1908
    foreach $item (@ergebnisse) {
1764
    foreach my $item (@ergebnisse) {
1909 1765
      $form->{ "$key" . "$item" } =
1910 1766
        $form->format_amount($myconfig,
1911 1767
                             $form->round_amount($form->{ "$key" . "$item" },
......
1935 1791
  my @categories_euro = qw(48 51 86 91 97 93 94);
1936 1792
  $form->{decimalplaces} *= 1;
1937 1793

  
1938
  foreach $item (@categories_cent) {
1794
  foreach my $item (@categories_cent) {
1939 1795
    $form->{"$item"} = 0;
1940 1796
  }
1941
  foreach $item (@categories_euro) {
1797
  foreach my $item (@categories_euro) {
1942 1798
    $form->{"$item"} = 0;
1943 1799
  }
1944 1800

  
......
1987 1843
  $form->{"65"} = $form->{"43"} - $form->{"66"};
1988 1844
  $form->{"67"} = $form->{"43"} - $form->{"66"};
1989 1845

  
1990
  foreach $item (@categories_cent) {
1846
  foreach my $item (@categories_cent) {
1991 1847
    $form->{$item} =
1992 1848
      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2),
1993 1849
                           2, '0');
1994 1850
  }
1995 1851

  
1996
  foreach $item (@categories_euro) {
1852
  foreach my $item (@categories_euro) {
1997 1853
    $form->{$item} =
1998 1854
      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 0),
1999 1855
                           0, '0');
......
2021 1877

  
2022 1878
  $form->{decimalplaces} *= 1;
2023 1879

  
2024
  foreach $item (@categories_einnahmen) {
1880
  foreach my $item (@categories_einnahmen) {
2025 1881
    $form->{$item} = 0;
2026 1882
  }
2027
  foreach $item (@categories_ausgaben) {
1883
  foreach my $item (@categories_ausgaben) {
2028 1884
    $form->{$item} = 0;
2029 1885
  }
2030 1886

  
2031
  foreach $item (@ergebnisse) {
1887
  foreach my $item (@ergebnisse) {
2032 1888
    $form->{$item} = 0;
2033 1889
  }
2034 1890

  
2035 1891
  &get_accounts_g($dbh, $last_period, $form->{fromdate}, $form->{todate},
2036 1892
                  $form, "pos_eur");
2037 1893

  
2038
  foreach $item (@categories_einnahmen) {
1894
  foreach my $item (@categories_einnahmen) {
2039 1895
    $form->{"eur${item}"} =
2040 1896
      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2));
2041 1897
    $form->{"sumeura"} += $form->{$item};
2042 1898
  }
2043
  foreach $item (@categories_ausgaben) {
1899
  foreach my $item (@categories_ausgaben) {
2044 1900
    $form->{"eur${item}"} =
2045 1901
      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2));
2046 1902
    $form->{"sumeurb"} += $form->{$item};
......
2048 1904

  
2049 1905
  $form->{"guvsumme"} = $form->{"sumeura"} - $form->{"sumeurb"};
2050 1906

  
2051
  foreach $item (@ergebnisse) {
1907
  foreach my $item (@ergebnisse) {
2052 1908
    $form->{$item} =
2053 1909
      $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2));
2054 1910
  }

Auch abrufbar als: Unified diff