1 ###=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (C) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
15 # Contributors: Benjamin Lee <benjaminlee@consultant.com>
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #======================================================================
31 # backend code for reports
33 #======================================================================
41 $main::lxdebug->enter_sub();
43 my ($self, $myconfig, $form) = @_;
46 my $dbh = $form->dbconnect($myconfig);
49 my @categories = qw(A C L Q);
51 # if there are any dates construct a where
52 if ($form->{asofdate}) {
53 $form->{period} = $form->{this_period} = conv_dateq($form->{asofdate});
56 $form->{decimalplaces} *= 1;
58 &get_accounts($dbh, $last_period, "", $form->{asofdate}, $form,
61 # if there are any compare dates
62 if ($form->{compareasofdate}) {
65 &get_accounts($dbh, $last_period, "", $form->{compareasofdate},
68 $form->{last_period} = conv_dateq($form->{compareasofdate});
75 # now we got $form->{A}{accno}{ } assets
76 # and $form->{L}{accno}{ } liabilities
77 # and $form->{Q}{accno}{ } equity
78 # build asset accounts
84 'A' => { 'label' => 'asset',
88 'L' => { 'label' => 'liability',
89 'labels' => 'liabilities',
92 'Q' => { 'label' => 'equity',
97 foreach my $category (grep { !/C/ } @categories) {
99 foreach $key (sort keys %{ $form->{$category} }) {
101 $str = ($form->{l_heading}) ? $form->{padding} : "";
103 if ($form->{$category}{$key}{charttype} eq "A") {
106 ? "$form->{$category}{$key}{accno} - $form->{$category}{$key}{description}"
107 : "$form->{$category}{$key}{description}";
109 if ($form->{$category}{$key}{charttype} eq "H") {
110 if ($account{$category}{subtotal} && $form->{l_subtotal}) {
112 push(@{ $form->{"$account{$category}{label}_account"} },
113 "$str$form->{bold}$account{$category}{subdescription}$form->{endbold}"
115 push(@{ $form->{"$account{$category}{label}_this_period"} },
116 $form->format_amount(
118 $account{$category}{subthis} * $account{$category}{ml},
119 $form->{decimalplaces}, $dash
123 push(@{ $form->{"$account{$category}{label}_last_period"} },
124 $form->format_amount(
126 $account{$category}{sublast} * $account{$category}{ml},
127 $form->{decimalplaces}, $dash
133 "$form->{bold}$form->{$category}{$key}{description}$form->{endbold}";
135 $account{$category}{subthis} = $form->{$category}{$key}{this};
136 $account{$category}{sublast} = $form->{$category}{$key}{last};
137 $account{$category}{subdescription} =
138 $form->{$category}{$key}{description};
139 $account{$category}{subtotal} = 1;
141 $form->{$category}{$key}{this} = 0;
142 $form->{$category}{$key}{last} = 0;
144 next unless $form->{l_heading};
149 # push description onto array
150 push(@{ $form->{"$account{$category}{label}_account"} }, $str);
152 if ($form->{$category}{$key}{charttype} eq 'A') {
153 $form->{"total_$account{$category}{labels}_this_period"} +=
154 $form->{$category}{$key}{this} * $account{$category}{ml};
158 push(@{ $form->{"$account{$category}{label}_this_period"} },
159 $form->format_amount(
161 $form->{$category}{$key}{this} * $account{$category}{ml},
162 $form->{decimalplaces}, $dash
166 $form->{"total_$account{$category}{labels}_last_period"} +=
167 $form->{$category}{$key}{last} * $account{$category}{ml};
169 push(@{ $form->{"$account{$category}{label}_last_period"} },
170 $form->format_amount(
172 $form->{$category}{$key}{last} * $account{$category}{ml},
173 $form->{decimalplaces}, $dash
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}"
183 push(@{ $form->{"$account{$category}{label}_this_period"} },
184 $form->format_amount(
186 $account{$category}{subthis} * $account{$category}{ml},
187 $form->{decimalplaces}, $dash
191 push(@{ $form->{"$account{$category}{label}_last_period"} },
192 $form->format_amount(
194 $account{$category}{sublast} * $account{$category}{ml},
195 $form->{decimalplaces}, $dash
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});
214 $form->{earnings_this_period} =
215 $form->{total_assets_this_period} -
216 $form->{total_liabilities_this_period} - $form->{total_equity_this_period};
218 push(@{ $form->{equity_this_period} },
219 $form->format_amount($myconfig,
220 $form->{earnings_this_period},
221 $form->{decimalplaces}, "- "
224 $form->{total_equity_this_period} =
226 $form->{total_equity_this_period} + $form->{earnings_this_period},
227 $form->{decimalplaces});
229 # add liability + equity
230 $form->{total_this_period} =
231 $form->format_amount(
233 $form->{total_liabilities_this_period} + $form->{total_equity_this_period},
234 $form->{decimalplaces},
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});
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};
256 push(@{ $form->{equity_last_period} },
257 $form->format_amount($myconfig,
258 $form->{earnings_last_period},
259 $form->{decimalplaces}, "- "
262 $form->{total_equity_last_period} =
264 $form->{total_equity_last_period} + $form->{earnings_last_period},
265 $form->{decimalplaces});
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},
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);
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);
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);
295 $form->{total_assets_this_period} =
296 $form->format_amount($myconfig,
297 $form->{total_assets_this_period},
298 $form->{decimalplaces}, "- ");
300 $form->{total_liabilities_this_period} =
301 $form->format_amount($myconfig,
302 $form->{total_liabilities_this_period},
303 $form->{decimalplaces}, "- ");
305 $form->{total_equity_this_period} =
306 $form->format_amount($myconfig,
307 $form->{total_equity_this_period},
308 $form->{decimalplaces}, "- ");
310 $main::lxdebug->leave_sub();
314 $main::lxdebug->enter_sub();
316 my ($dbh, $last_period, $fromdate, $todate, $form, $categories) = @_;
318 my ($null, $department_id) = split /--/, $form->{department};
330 my $category = qq| AND (| . join(" OR ", map({ "(c.category = " . $dbh->quote($_) . ")" } @{$categories})) . qq|) |;
334 qq|SELECT c.accno, c.description, c.category
336 WHERE (c.charttype = 'H')
340 $sth = prepare_execute_query($form, $dbh, $query);
342 my @headingaccounts = ();
343 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
344 $form->{ $ref->{category} }{ $ref->{accno} }{description} =
345 "$ref->{description}";
346 $form->{ $ref->{category} }{ $ref->{accno} }{charttype} = "H";
347 $form->{ $ref->{category} }{ $ref->{accno} }{accno} = $ref->{accno};
349 push @headingaccounts, $ref->{accno};
355 $fromdate = conv_dateq($fromdate);
356 if ($form->{method} eq 'cash') {
357 $subwhere .= " AND (transdate >= $fromdate)";
358 $glwhere = " AND (ac.transdate >= $fromdate)";
360 $where .= " AND (ac.transdate >= $fromdate)";
365 $todate = conv_dateq($todate);
366 $where .= " AND (ac.transdate <= $todate)";
367 $subwhere .= " AND (transdate <= $todate)";
370 if ($department_id) {
371 $dpt_join = qq| JOIN department t ON (a.department_id = t.id) |;
372 $dpt_where = qq| AND (t.id = | . conv_i($department_id, 'NULL') . qq|)|;
375 if ($form->{project_id}) {
376 $project = qq| AND (ac.project_id = | . conv_i($form->{project_id}, 'NULL') . qq|) |;
379 if ($form->{method} eq 'cash') {
381 qq|SELECT c.accno, sum(ac.amount) AS amount, c.description, c.category
383 JOIN chart c ON (c.id = ac.chart_id)
384 JOIN ar a ON (a.id = ac.trans_id)
393 JOIN chart ON (chart_id = id)
394 WHERE (link LIKE '%AR_paid%')
398 GROUP BY c.accno, c.description, c.category
402 SELECT c.accno, sum(ac.amount) AS amount, c.description, c.category
404 JOIN chart c ON (c.id = ac.chart_id)
405 JOIN ap a ON (a.id = ac.trans_id)
414 JOIN chart ON (chart_id = id)
415 WHERE (link LIKE '%AP_paid%')
419 GROUP BY c.accno, c.description, c.category
423 SELECT c.accno, sum(ac.amount) AS amount, c.description, c.category
425 JOIN chart c ON (c.id = ac.chart_id)
426 JOIN gl a ON (a.id = ac.trans_id)
432 AND NOT ((c.link = 'AR') OR (c.link = 'AP'))
434 GROUP BY c.accno, c.description, c.category |;
436 if ($form->{project_id}) {
441 SELECT c.accno AS accno, SUM(ac.sellprice * ac.qty) AS amount, c.description AS description, c.category
443 JOIN ar a ON (a.id = ac.trans_id)
444 JOIN parts p ON (ac.parts_id = p.id)
445 JOIN chart c on (p.income_accno_id = c.id)
447 -- use transdate from subwhere
448 WHERE (c.category = 'I')
455 JOIN chart ON (chart_id = id)
456 WHERE (link LIKE '%AR_paid%')
460 GROUP BY c.accno, c.description, c.category
464 SELECT c.accno AS accno, SUM(ac.sellprice) AS amount, c.description AS description, c.category
466 JOIN ap a ON (a.id = ac.trans_id)
467 JOIN parts p ON (ac.parts_id = p.id)
468 JOIN chart c on (p.expense_accno_id = c.id)
470 WHERE (c.category = 'E')
477 JOIN chart ON (chart_id = id)
478 WHERE link LIKE '%AP_paid%'
482 GROUP BY c.accno, c.description, c.category |;
485 } else { # if ($form->{method} eq 'cash')
486 if ($department_id) {
487 $dpt_join = qq| JOIN dpt_trans t ON (t.trans_id = ac.trans_id) |;
488 $dpt_where = qq| AND t.department_id = $department_id |;
492 SELECT c.accno, sum(ac.amount) AS amount, c.description, c.category
494 JOIN chart c ON (c.id = ac.chart_id)
500 GROUP BY c.accno, c.description, c.category |;
502 if ($form->{project_id}) {
506 SELECT c.accno AS accno, SUM(ac.sellprice * ac.qty) AS amount, c.description AS description, c.category
508 JOIN ar a ON (a.id = ac.trans_id)
509 JOIN parts p ON (ac.parts_id = p.id)
510 JOIN chart c on (p.income_accno_id = c.id)
512 -- use transdate from subwhere
513 WHERE (c.category = 'I')
517 GROUP BY c.accno, c.description, c.category
521 SELECT c.accno AS accno, SUM(ac.sellprice * ac.qty) * -1 AS amount, c.description AS description, c.category
523 JOIN ap a ON (a.id = ac.trans_id)
524 JOIN parts p ON (ac.parts_id = p.id)
525 JOIN chart c on (p.expense_accno_id = c.id)
527 WHERE (c.category = 'E')
531 GROUP BY c.accno, c.description, c.category |;
539 my $sth = prepare_execute_query($form, $dbh, $query);
541 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
543 if ($ref->{category} eq 'C') {
544 $ref->{category} = 'A';
547 # get last heading account
548 @accno = grep { $_ le "$ref->{accno}" } @headingaccounts;
552 $form->{ $ref->{category} }{$accno}{last} += $ref->{amount};
554 $form->{ $ref->{category} }{$accno}{this} += $ref->{amount};
558 $form->{ $ref->{category} }{ $ref->{accno} }{accno} = $ref->{accno};
559 $form->{ $ref->{category} }{ $ref->{accno} }{description} =
561 $form->{ $ref->{category} }{ $ref->{accno} }{charttype} = "A";
564 $form->{ $ref->{category} }{ $ref->{accno} }{last} += $ref->{amount};
566 $form->{ $ref->{category} }{ $ref->{accno} }{this} += $ref->{amount};
571 # remove accounts with zero balance
572 foreach $category (@{$categories}) {
573 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});
581 delete $form->{$category}{$accno}
582 if ( $form->{$category}{$accno}{this} == 0
583 && $form->{$category}{$accno}{last} == 0);
587 $main::lxdebug->leave_sub();
591 $main::lxdebug->enter_sub();
593 my ($dbh, $last_period, $fromdate, $todate, $form, $category) = @_;
595 my ($null, $department_id) = split /--/, $form->{department};
608 $fromdate = conv_dateq($fromdate);
609 if ($form->{method} eq 'cash') {
610 $subwhere .= " AND (transdate >= $fromdate)";
611 $glwhere = " AND (ac.transdate >= $fromdate)";
612 $prwhere = " AND (ar.transdate >= $fromdate)";
614 $where .= " AND (ac.transdate >= $fromdate)";
619 $todate = conv_dateq($todate);
620 $subwhere .= " AND (transdate <= $todate)";
621 $where .= " AND (ac.transdate <= $todate)";
622 $prwhere .= " AND (ar.transdate <= $todate)";
625 if ($department_id) {
626 $dpt_join = qq| JOIN department t ON (a.department_id = t.id) |;
627 $dpt_where = qq| AND (t.id = | . conv_i($department_id, 'NULL') . qq|) |;
630 if ($form->{project_id}) {
631 $project = qq| AND (ac.project_id = | . conv_i($form->{project_id}) . qq|) |;
634 if ($form->{method} eq 'cash') {
637 SELECT SUM(ac.amount * chart_category_to_sgn(c.category)) AS amount, c.$category
639 JOIN chart c ON (c.id = ac.chart_id)
640 JOIN ar a ON (a.id = ac.trans_id)
642 WHERE $where $dpt_where
643 AND ac.trans_id IN ( SELECT trans_id FROM acc_trans JOIN chart ON (chart_id = id) WHERE (link LIKE '%AR_paid%') $subwhere)
649 SELECT SUM(ac.amount * chart_category_to_sgn(c.category)) AS amount, c.$category
651 JOIN chart c ON (c.id = ac.chart_id)
652 JOIN ap a ON (a.id = ac.trans_id)
654 WHERE $where $dpt_where
655 AND ac.trans_id IN ( SELECT trans_id FROM acc_trans JOIN chart ON (chart_id = id) WHERE (link LIKE '%AP_paid%') $subwhere)
661 SELECT SUM(ac.amount * chart_category_to_sgn(c.category)) AS amount, c.$category
663 JOIN chart c ON (c.id = ac.chart_id)
664 JOIN gl a ON (a.id = ac.trans_id)
666 WHERE $where $dpt_where $glwhere
667 AND NOT ((c.link = 'AR') OR (c.link = 'AP'))
674 if ($form->{project_id}) {
678 SELECT SUM(ac.sellprice * ac.qty * chart_category_to_sgn(c.category)) AS amount, c.$category
680 JOIN ar a ON (a.id = ac.trans_id)
681 JOIN parts p ON (ac.parts_id = p.id)
682 JOIN chart c on (p.income_accno_id = c.id)
684 WHERE (c.category = 'I') $prwhere $dpt_where
685 AND ac.trans_id IN ( SELECT trans_id FROM acc_trans JOIN chart ON (chart_id = id) WHERE (link LIKE '%AR_paid%') $subwhere)
691 SELECT SUM(ac.sellprice * chart_category_to_sgn(c.category)) AS amount, c.$category
693 JOIN ap a ON (a.id = ac.trans_id)
694 JOIN parts p ON (ac.parts_id = p.id)
695 JOIN chart c on (p.expense_accno_id = c.id)
697 WHERE (c.category = 'E') $prwhere $dpt_where
698 AND ac.trans_id IN ( SELECT trans_id FROM acc_trans JOIN chart ON (chart_id = id) WHERE (link LIKE '%AP_paid%') $subwhere)
704 } else { # if ($form->{method} eq 'cash')
705 if ($department_id) {
706 $dpt_join = qq| JOIN dpt_trans t ON (t.trans_id = ac.trans_id) |;
707 $dpt_where = qq| AND (t.department_id = | . conv_i($department_id, 'NULL') . qq|) |;
711 SELECT sum(ac.amount * chart_category_to_sgn(c.category)) AS amount, c.$category
713 JOIN chart c ON (c.id = ac.chart_id)
718 GROUP BY c.$category |;
720 if ($form->{project_id}) {
724 SELECT SUM(ac.sellprice * ac.qty * chart_category_to_sgn(c.category)) AS amount, c.$category
726 JOIN ar a ON (a.id = ac.trans_id)
727 JOIN parts p ON (ac.parts_id = p.id)
728 JOIN chart c on (p.income_accno_id = c.id)
730 WHERE (c.category = 'I')
738 SELECT SUM(ac.sellprice * ac.qty * chart_category_to_sgn(c.category)) AS amount, c.$category
740 JOIN ap a ON (a.id = ac.trans_id)
741 JOIN parts p ON (ac.parts_id = p.id)
742 JOIN chart c on (p.expense_accno_id = c.id)
744 WHERE (c.category = 'E')
748 GROUP BY c.$category |;
756 my $sth = prepare_execute_query($form, $dbh, $query);
758 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
759 if ($category eq "pos_bwa") {
761 $form->{ $ref->{$category} }{kumm} += $ref->{amount};
763 $form->{ $ref->{$category} }{jetzt} += $ref->{amount};
766 $form->{ $ref->{$category} } += $ref->{amount};
771 $main::lxdebug->leave_sub();
775 $main::lxdebug->enter_sub();
777 my ($self, $myconfig, $form) = @_;
779 my $dbh = $form->dbconnect($myconfig);
781 my ($query, $sth, $ref);
784 my ($null, $department_id) = split /--/, $form->{department};
785 my @headingaccounts = ();
791 my $invwhere = $where;
793 if ($department_id) {
794 $dpt_join = qq| JOIN dpt_trans t ON (ac.trans_id = t.trans_id) |;
795 $dpt_where = qq| AND (t.department_id = | . conv_i($department_id, 'NULL') . qq|) |;
798 # project_id only applies to getting transactions
799 # it has nothing to do with a trial balance
800 # but we use the same function to collect information
802 if ($form->{project_id}) {
803 $project = qq| AND ac.project_id = | . conv_i($form->{project_id}, 'NULL') . qq|) |;
806 # get beginning balances
807 if ($form->{fromdate}) {
809 qq|SELECT c.accno, c.category, SUM(ac.amount) AS amount, c.description
811 JOIN chart c ON (ac.chart_id = c.id)
813 WHERE (ac.transdate < ?)
816 GROUP BY c.accno, c.category, c.description |;
818 $sth = prepare_execute_query($form, $dbh, $query, $form->{fromdate});
820 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
821 $balance{ $ref->{accno} } = $ref->{amount};
823 if ($ref->{amount} != 0 && $form->{all_accounts}) {
824 $trb{ $ref->{accno} }{description} = $ref->{description};
825 $trb{ $ref->{accno} }{charttype} = 'A';
826 $trb{ $ref->{accno} }{category} = $ref->{category};
836 qq|SELECT c.accno, c.description, c.category
838 WHERE c.charttype = 'H'
841 $sth = prepare_execute_query($form, $dbh, $query);
843 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
844 $trb{ $ref->{accno} }{description} = $ref->{description};
845 $trb{ $ref->{accno} }{charttype} = 'H';
846 $trb{ $ref->{accno} }{category} = $ref->{category};
848 push @headingaccounts, $ref->{accno};
856 if ($form->{fromdate} || $form->{todate}) {
857 if ($form->{fromdate}) {
858 my $fromdate = conv_dateq($form->{fromdate});
859 $tofrom .= " AND (ac.transdate >= $fromdate)";
860 $subwhere .= " AND (transdate >= $fromdate)";
861 $invwhere .= " AND (a.transdate >= $fromdate)";
862 $glwhere = " AND (ac.transdate >= $fromdate)";
864 if ($form->{todate}) {
865 my $todate = conv_dateq($form->{todate});
866 $tofrom .= " AND (ac.transdate <= $todate)";
867 $invwhere .= " AND (a.transdate <= $todate)";
868 $subwhere .= " AND (transdate <= $todate)";
869 $glwhere .= " AND (ac.transdate <= $todate)";
875 qq| AND ((ac.trans_id IN (SELECT id from ar) AND
880 JOIN chart ON (chart_id = id)
881 WHERE (link LIKE '%AR_paid%')
886 (ac.trans_id in (SELECT id from ap) AND
891 JOIN chart ON (chart_id = id)
892 WHERE (link LIKE '%AP_paid%')
897 (ac.trans_id in (SELECT id from gl)
905 SELECT c.accno, c.description, c.category, SUM(ac.amount) AS amount
907 JOIN chart c ON (c.id = ac.chart_id)
912 GROUP BY c.accno, c.description, c.category |;
914 if ($form->{project_id}) {
916 -- add project transactions from invoice
920 SELECT c.accno, c.description, c.category, SUM(ac.sellprice * ac.qty) AS amount
922 JOIN ar a ON (ac.trans_id = a.id)
923 JOIN parts p ON (ac.parts_id = p.id)
924 JOIN chart c ON (p.income_accno_id = c.id)
929 GROUP BY c.accno, c.description, c.category
933 SELECT c.accno, c.description, c.category, SUM(ac.sellprice * ac.qty) * -1 AS amount
935 JOIN ap a ON (ac.trans_id = a.id)
936 JOIN parts p ON (ac.parts_id = p.id)
937 JOIN chart c ON (p.expense_accno_id = c.id)
942 GROUP BY c.accno, c.description, c.category
946 $query .= qq| ORDER BY accno|;
948 $sth = prepare_execute_query($form, $dbh, $query);
950 # calculate the debit and credit in the period
951 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
952 $trb{ $ref->{accno} }{description} = $ref->{description};
953 $trb{ $ref->{accno} }{charttype} = 'A';
954 $trb{ $ref->{accno} }{category} = $ref->{category};
955 $trb{ $ref->{accno} }{amount} += $ref->{amount};
959 # prepare query for each account
960 my ($q_drcr, $drcr, $q_project_drcr, $project_drcr);
964 (SELECT SUM(ac.amount) * -1
966 JOIN chart c ON (c.id = ac.chart_id)
972 AND (c.accno = ?)) AS debit,
974 (SELECT SUM(ac.amount)
976 JOIN chart c ON (c.id = ac.chart_id)
982 AND c.accno = ?) AS credit |;
984 $drcr = prepare_query($form, $dbh, $q_drcr);
986 if ($form->{project_id}) {
987 # prepare query for each account
990 (SELECT SUM(ac.sellprice * ac.qty) * -1
992 JOIN parts p ON (ac.parts_id = p.id)
993 JOIN ap a ON (ac.trans_id = a.id)
994 JOIN chart c ON (p.expense_accno_id = c.id)
999 AND c.accno = ?) AS debit,
1001 (SELECT SUM(ac.sellprice * ac.qty)
1003 JOIN parts p ON (ac.parts_id = p.id)
1004 JOIN ar a ON (ac.trans_id = a.id)
1005 JOIN chart c ON (p.income_accno_id = c.id)
1010 AND c.accno = ?) AS credit |;
1012 $project_drcr = prepare_query($form, $dbh, $q_project_drcr);
1015 my ($debit, $credit);
1017 foreach my $accno (sort keys %trb) {
1020 $ref->{accno} = $accno;
1021 map { $ref->{$_} = $trb{$accno}{$_} }
1022 qw(description category charttype amount);
1024 $ref->{balance} = $form->round_amount($balance{ $ref->{accno} }, 2);
1026 if ($trb{$accno}{charttype} eq 'A') {
1029 do_statement($form, $drcr, $q_drcr, $ref->{accno}, $ref->{accno});
1031 ($debit, $credit) = (0, 0);
1032 while (($debit, $credit) = $drcr->fetchrow_array) {
1033 $ref->{debit} += $debit;
1034 $ref->{credit} += $credit;
1038 if ($form->{project_id}) {
1041 do_statement($form, $project_drcr, $q_project_drcr, $ref->{accno}, $ref->{accno});
1043 ($debit, $credit) = (0, 0);
1044 while (($debit, $credit) = $project_drcr->fetchrow_array) {
1045 $ref->{debit} += $debit;
1046 $ref->{credit} += $credit;
1048 $project_drcr->finish;
1051 $ref->{debit} = $form->round_amount($ref->{debit}, 2);
1052 $ref->{credit} = $form->round_amount($ref->{credit}, 2);
1057 @accno = grep { $_ le "$ref->{accno}" } @headingaccounts;
1058 $accno = pop @accno;
1060 $trb{$accno}{debit} += $ref->{debit};
1061 $trb{$accno}{credit} += $ref->{credit};
1064 push @{ $form->{TB} }, $ref;
1070 # debits and credits for headings
1071 foreach $accno (@headingaccounts) {
1072 foreach $ref (@{ $form->{TB} }) {
1073 if ($accno eq $ref->{accno}) {
1074 $ref->{debit} = $trb{$accno}{debit};
1075 $ref->{credit} = $trb{$accno}{credit};
1080 $main::lxdebug->leave_sub();
1084 $main::lxdebug->enter_sub();
1085 my ($self, $dbh, $form) = @_;
1086 my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
1087 my $query = qq|SELECT invnumber FROM $arap WHERE invnumber LIKE "Storno zu "|;
1088 my $sth = $dbh->prepare($query);
1089 while(my $ref = $sth->fetchrow_hashref()) {
1090 $ref->{invnumer} =~ s/Storno zu //g;
1091 $form->{storno}{$ref->{invnumber}} = 1;
1093 $main::lxdebug->leave_sub();
1097 $main::lxdebug->enter_sub();
1099 my ($self, $myconfig, $form) = @_;
1101 # connect to database
1102 my $dbh = $form->dbconnect($myconfig);
1104 my ($invoice, $arap, $buysell, $ct, $ct_id);
1106 if ($form->{ct} eq "customer") {
1117 $ct_id = "${ct}_id";
1119 $form->{todate} = $form->current_date($myconfig) unless ($form->{todate});
1120 my $todate = conv_dateq($form->{todate});
1122 my $where = " 1 = 1 ";
1125 if ($form->{$ct_id}) {
1126 $where .= qq| AND (ct.id = | . conv_i($form->{$ct_id}) . qq|)|;
1127 } elsif ($form->{ $form->{ct} }) {
1128 $where .= qq| AND (ct.name ILIKE | . $dbh->quote('%' . $form->{$ct} . '%') . qq|)|;
1132 if ($form->{department}) {
1133 ($null, $department_id) = split /--/, $form->{department};
1134 $dpt_join = qq| JOIN department d ON (a.department_id = d.id) |;
1135 $where .= qq| AND (a.department_id = | . conv_i($department_id, 'NULL') . qq|)|;
1139 -- between 0-30 days
1141 SELECT ${ct}.id AS ctid, ${ct}.name,
1142 street, zipcode, city, country, contact, email,
1143 phone as customerphone, fax as customerfax, ${ct}number,
1144 "invnumber", "transdate",
1145 (amount - paid) as "c0", 0.00 as "c30", 0.00 as "c60", 0.00 as "c90",
1146 "duedate", invoice, ${arap}.id,
1149 WHERE (${arap}.curr = exchangerate.curr)
1150 AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
1152 WHERE (paid != amount)
1153 AND (${arap}.storno IS FALSE)
1154 AND (${arap}.${ct}_id = ${ct}.id)
1156 AND (transdate <= (date $todate - interval '0 days'))
1157 AND (transdate >= (date $todate - interval '30 days'))
1161 -- between 31-60 days
1163 SELECT ${ct}.id AS ctid, ${ct}.name,
1164 street, zipcode, city, country, contact, email,
1165 phone as customerphone, fax as customerfax, ${ct}number,
1166 "invnumber", "transdate",
1167 0.00 as "c0", (amount - paid) as "c30", 0.00 as "c60", 0.00 as "c90",
1168 "duedate", invoice, ${arap}.id,
1171 WHERE (${arap}.curr = exchangerate.curr)
1172 AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
1174 WHERE (paid != amount)
1175 AND (${arap}.storno IS FALSE)
1176 AND (${arap}.${ct}_id = ${ct}.id)
1178 AND (transdate < (date $todate - interval '30 days'))
1179 AND (transdate >= (date $todate - interval '60 days'))
1183 -- between 61-90 days
1185 SELECT ${ct}.id AS ctid, ${ct}.name,
1186 street, zipcode, city, country, contact, email,
1187 phone as customerphone, fax as customerfax, ${ct}number,
1188 "invnumber", "transdate",
1189 0.00 as "c0", 0.00 as "c30", (amount - paid) as "c60", 0.00 as "c90",
1190 "duedate", invoice, ${arap}.id,
1193 WHERE (${arap}.curr = exchangerate.curr)
1194 AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
1196 WHERE (paid != amount)
1197 AND (${arap}.storno IS FALSE)
1198 AND (${arap}.${ct}_id = ${ct}.id)
1200 AND (transdate < (date $todate - interval '60 days'))
1201 AND (transdate >= (date $todate - interval '90 days'))
1207 SELECT ${ct}.id AS ctid, ${ct}.name,
1208 street, zipcode, city, country, contact, email,
1209 phone as customerphone, fax as customerfax, ${ct}number,
1210 "invnumber", "transdate",
1211 0.00 as "c0", 0.00 as "c30", 0.00 as "c60", (amount - paid) as "c90",
1212 "duedate", invoice, ${arap}.id,
1215 WHERE (${arap}.curr = exchangerate.curr)
1216 AND (exchangerate.transdate = ${arap}.transdate)) AS exchangerate
1218 WHERE (paid != amount)
1219 AND (${arap}.storno IS FALSE)
1220 AND (${arap}.${ct}_id = ${ct}.id)
1222 AND (transdate < (date $todate - interval '90 days'))
1224 ORDER BY ctid, transdate, invnumber |;
1226 my $sth_details = prepare_query($form, $dbh, $q_details);
1228 # select outstanding vendors or customers, depends on $ct
1230 qq|SELECT DISTINCT ct.id, ct.name
1231 FROM $ct ct, $arap a
1234 AND (a.${ct_id} = ct.id)
1235 AND (a.paid != a.amount)
1236 AND (a.transdate <= $todate)
1239 my $sth = prepare_execute_query($form, $dbh, $query);
1242 # for each company that has some stuff outstanding
1243 while (my ($id) = $sth->fetchrow_array) {
1244 do_statement($form, $sth_details, $q_details, $id, $id, $id, $id);
1246 while (my $ref = $sth_details->fetchrow_hashref(NAME_lc)) {
1247 $ref->{module} = ($ref->{invoice}) ? $invoice : $arap;
1248 $ref->{exchangerate} = 1 unless $ref->{exchangerate};
1249 push @{ $form->{AG} }, $ref;
1252 $sth_details->finish;
1261 $main::lxdebug->leave_sub();
1265 $main::lxdebug->enter_sub();
1267 my ($self, $myconfig, $form) = @_;
1269 # connect to database
1270 my $dbh = $form->dbconnect($myconfig);
1272 my $ct = $form->{ct} eq "customer" ? "customer" : "vendor";
1275 qq|SELECT ct.name, ct.email, ct.cc, ct.bcc
1278 ($form->{ $form->{ct} }, $form->{email}, $form->{cc}, $form->{bcc}) =
1279 selectrow_query($form, $dbh, $query, $form->{"${ct}_id"});
1282 $main::lxdebug->leave_sub();
1285 sub get_taxaccounts {
1286 $main::lxdebug->enter_sub();
1288 my ($self, $myconfig, $form) = @_;
1290 # connect to database
1291 my $dbh = $form->dbconnect($myconfig);
1295 qq|SELECT c.accno, c.description, t.rate
1297 WHERE (c.link LIKE '%CT_tax%') AND (c.id = t.chart_id)
1299 $form->{taxaccounts} = selectall_hashref_quert($form, $dbh, $query);
1303 $main::lxdebug->leave_sub();
1307 $main::lxdebug->enter_sub();
1309 my ($self, $myconfig, $form) = @_;
1311 # connect to database
1312 my $dbh = $form->dbconnect($myconfig);
1314 my ($null, $department_id) = split /--/, $form->{department};
1317 my $where = "1 = 1";
1319 if ($department_id) {
1320 $where .= qq| AND (a.department_id = | . conv_i($department_id, 'NULL') . qq|) |;
1325 if ($form->{accno}) {
1326 $accno = $form->{accno};
1327 $rate = $form->{"$form->{accno}_rate"};
1328 $accno = qq| AND (ch.accno = | . $dbh->quote($accno) . qq|)|;
1334 if ($form->{db} eq 'ar') {
1335 $table = "customer";
1342 my $arap = lc($ARAP);
1344 my $transdate = "a.transdate";
1346 if ($form->{method} eq 'cash') {
1347 $transdate = "a.datepaid";
1349 my $todate = conv_dateq($form->{todate} ? $form->{todate} : $form->current_date($myconfig));
1356 JOIN chart ON (chart_id = id)
1357 WHERE (link LIKE '%${ARAP}_paid%')
1358 AND (transdate <= $todate)
1363 # if there are any dates construct a where
1364 $where .= " AND ($transdate >= " . conv_dateq($form->{fromdate}) . ") " if ($form->{fromdate});
1365 $where .= " AND ($transdate <= " . conv_dateq($form->{todate}) . ") " if ($form->{todate});
1367 my $ml = ($form->{db} eq 'ar') ? 1 : -1;
1369 my $sortorder = join ', ', $form->sort_columns(qw(transdate invnumber name));
1370 $sortorder = $form->{sort} if ($form->{sort} && grep({ $_ eq $form->{sort} } qw(id transdate invnumber name netamount tax)));
1372 if ($form->{report} !~ /nontaxable/) {
1374 qq|SELECT a.id, '0' AS invoice, $transdate AS transdate, a.invnumber, n.name, a.netamount,
1375 ac.amount * $ml AS tax
1377 JOIN ${arap} a ON (a.id = ac.trans_id)
1378 JOIN chart ch ON (ch.id = ac.chart_id)
1379 JOIN $table n ON (n.id = a.${table}_id)
1383 AND (a.invoice = '0')
1387 SELECT a.id, '1' AS invoice, $transdate AS transdate, a.invnumber, n.name, i.sellprice * i.qty AS netamount,
1388 i.sellprice * i.qty * $rate * $ml AS tax
1390 JOIN ${arap} a ON (a.id = ac.trans_id)
1391 JOIN chart ch ON (ch.id = ac.chart_id)
1392 JOIN $table n ON (n.id = a.${table}_id)
1393 JOIN ${table}tax t ON (t.${table}_id = n.id)
1394 JOIN invoice i ON (i.trans_id = a.id)
1395 JOIN partstax p ON (p.parts_id = i.parts_id)
1399 AND (a.invoice = '1')
1400 ORDER BY $sortorder|;
1402 # only gather up non-taxable transactions
1404 qq|SELECT a.id, '0' AS invoice, $transdate AS transdate, a.invnumber, n.name, a.netamount
1406 JOIN ${arap} a ON (a.id = ac.trans_id)
1407 JOIN $table n ON (n.id = a.${table}_id)
1410 AND (a.invoice = '0')
1411 AND (a.netamount = a.amount)
1415 SELECT a.id, '1' AS invoice, $transdate AS transdate, a.invnumber, n.name, i.sellprice * i.qty AS netamount
1417 JOIN ${arap} a ON (a.id = ac.trans_id)
1418 JOIN $table n ON (n.id = a.${table}_id)
1419 JOIN invoice i ON (i.trans_id = a.id)
1422 AND (a.invoice = '1')
1424 a.${table}_id NOT IN (SELECT ${table}_id FROM ${table}tax t (${table}_id))
1426 i.parts_id NOT IN (SELECT parts_id FROM partstax p (parts_id))
1428 GROUP BY a.id, a.invnumber, $transdate, n.name, i.sellprice, i.qty
1429 ORDER by $sortorder|;
1432 $form->{TR} = selectall_hashref_query($form, $dbh, $query);
1436 $main::lxdebug->leave_sub();
1439 sub paymentaccounts {
1440 $main::lxdebug->enter_sub();
1442 my ($self, $myconfig, $form) = @_;
1444 # connect to database, turn AutoCommit off
1445 my $dbh = $form->dbconnect_noauto($myconfig);
1447 my $ARAP = $form->{db} eq "ar" ? "AR" : "AP";
1449 # get A(R|P)_paid accounts
1451 qq|SELECT accno, description
1453 WHERE link LIKE '%${ARAP}_paid%'|;
1454 $form->{PR} = selectall_hashref_query($form, $dbh, $query);
1458 $main::lxdebug->leave_sub();
1462 $main::lxdebug->enter_sub();
1464 my ($self, $myconfig, $form) = @_;
1466 # connect to database, turn AutoCommit off
1467 my $dbh = $form->dbconnect_noauto($myconfig);
1471 if ($form->{db} eq 'ar') {
1472 $table = 'customer';
1484 if ($form->{department_id}) {
1485 $dpt_join = qq| JOIN dpt_trans t ON (t.trans_id = ac.trans_id) |;
1486 $where = qq| AND (t.department_id = | . conv_i($form->{department_id}, 'NULL') . qq|) |;
1489 if ($form->{fromdate}) {
1490 $where .= " AND (ac.transdate >= " . $dbh->quote($form->{fromdate}) . ") ";
1492 if ($form->{todate}) {
1493 $where .= " AND (ac.transdate <= " . $dbh->quote($form->{todate}) . ") ";
1495 if (!$form->{fx_transaction}) {
1496 $where .= " AND ac.fx_transaction = '0'";
1501 if ($form->{reference}) {
1502 $reference = $dbh->quote('%' . $form->{reference} . '%');
1503 $invnumber = " AND (a.invnumber LIKE $reference)";
1504 $reference = " AND (g.reference LIKE $reference)";
1506 if ($form->{source}) {
1507 $where .= " AND (ac.source ILIKE " . $dbh->quote('%' . $form->{source} . '%') . ") ";
1509 if ($form->{memo}) {
1510 $where .= " AND (ac.memo ILIKE " . $dbh->quote('%' . $form->{memo} . '%') . ") ";
1513 my $sortorder = join(', ', qw(name invnumber ordnumber transdate source));
1514 $sortorder = $form->{sort} if ($form->{sort} && grep({ $_ eq $form->{sort} } qw(transdate invnumber name source memo)));
1516 $query = qq|SELECT id, accno, description FROM chart WHERE accno = ?|;
1517 my $sth = prepare_query($form, $dbh, $query);
1520 qq|SELECT c.name, a.invnumber, a.ordnumber,
1521 ac.transdate, ac.amount * $ml AS paid, ac.source,
1522 a.invoice, a.id, ac.memo, '${arap}' AS module
1524 JOIN $arap a ON (ac.trans_id = a.id)
1525 JOIN $table c ON (c.id = a.${table}_id)
1527 WHERE (ac.chart_id = ?)
1533 SELECT g.description, g.reference, NULL AS ordnumber,
1534 ac.transdate, ac.amount * $ml AS paid, ac.source,
1535 '0' as invoice, g.id, ac.memo, 'gl' AS module
1537 JOIN gl g ON (g.id = ac.trans_id)
1539 WHERE (ac.chart_id = ?)
1542 AND (ac.amount * $ml) > 0
1544 ORDER BY $sortorder|;
1545 my $sth_details = prepare_query($form, $dbh, $q_details);
1549 # cycle through each id
1550 foreach my $accno (split(/ /, $form->{paymentaccounts})) {
1551 do_statement($form, $sth, $query, $accno);
1552 my $ref = $sth->fetchrow_hashref();
1553 push(@{ $form->{PR} }, $ref);
1556 $form->{ $ref->{id} } = [] unless ($form->{ $ref->{id} });
1558 do_statement($form, $sth_details, $q_details, $ref->{id}, $ref->{id});
1559 while (my $pr = $sth_details->fetchrow_hashref()) {
1560 push(@{ $form->{ $ref->{id} } }, $pr);
1562 $sth_details->finish();
1567 $main::lxdebug->leave_sub();
1571 $main::lxdebug->enter_sub();
1573 my ($self, $myconfig, $form) = @_;
1575 # connect to database
1576 my $dbh = $form->dbconnect($myconfig);
1578 my $last_period = 0;
1581 qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40);
1583 $form->{decimalplaces} *= 1;
1585 &get_accounts_g($dbh, $last_period, $form->{fromdate}, $form->{todate}, $form, "pos_bwa");
1587 # if there are any compare dates
1588 if ($form->{fromdate} || $form->{todate}) {
1590 if ($form->{fromdate}) {
1591 $form->{fromdate} =~ /[0-9]*\.[0-9]*\.([0-9]*)/;
1594 $form->{todate} =~ /[0-9]*\.[0-9]*\.([0-9]*)/;
1597 $kummfromdate = $form->{comparefromdate};
1598 $kummtodate = $form->{comparetodate};
1599 &get_accounts_g($dbh, $last_period, $kummfromdate, $kummtodate, $form, "pos_bwa");
1602 @periods = qw(jetzt kumm);
1603 @gesamtleistung = qw(1 2 3);
1604 @gesamtkosten = qw (10 11 12 13 14 15 16 17 18 19 20);
1606 qw (rohertrag betriebrohertrag betriebsergebnis neutraleraufwand neutralerertrag ergebnisvorsteuern ergebnis gesamtleistung gesamtkosten);
1608 foreach $key (@periods) {
1609 $form->{ "$key" . "gesamtleistung" } = 0;
1610 $form->{ "$key" . "gesamtkosten" } = 0;
1612 foreach $category (@categories) {
1614 if (defined($form->{$category}{$key})) {
1615 $form->{"$key$category"} =
1616 $form->format_amount($myconfig,
1617 $form->round_amount($form->{$category}{$key}, 2
1619 $form->{decimalplaces},
1623 foreach $item (@gesamtleistung) {
1624 $form->{ "$key" . "gesamtleistung" } += $form->{$item}{$key};
1626 foreach $item (@gesamtkosten) {
1627 $form->{ "$key" . "gesamtkosten" } += $form->{$item}{$key};
1629 $form->{ "$key" . "rohertrag" } =
1630 $form->{ "$key" . "gesamtleistung" } - $form->{4}{$key};
1631 $form->{ "$key" . "betriebrohertrag" } =
1632 $form->{ "$key" . "rohertrag" } + $form->{5}{$key};
1633 $form->{ "$key" . "betriebsergebnis" } =
1634 $form->{ "$key" . "betriebrohertrag" } -
1635 $form->{ "$key" . "gesamtkosten" };
1636 $form->{ "$key" . "neutraleraufwand" } =
1637 $form->{30}{$key} + $form->{31}{$key};
1638 $form->{ "$key" . "neutralertrag" } =
1639 $form->{32}{$key} + $form->{33}{$key} + $form->{34}{$key};
1640 $form->{ "$key" . "ergebnisvorsteuern" } =
1641 $form->{ "$key" . "betriebsergebnis" } -
1642 $form->{ "$key" . "neutraleraufwand" } +
1643 $form->{ "$key" . "neutralertrag" };
1644 $form->{ "$key" . "ergebnis" } =
1645 $form->{ "$key" . "ergebnisvorsteuern" } + $form->{35}{$key};
1647 if ($form->{ "$key" . "gesamtleistung" } > 0) {
1648 foreach $category (@categories) {
1649 if (defined($form->{$category}{$key})) {
1650 $form->{ "$key" . "gl" . "$category" } =
1651 $form->format_amount(
1653 $form->round_amount(
1654 ($form->{$category}{$key} /
1655 $form->{ "$key" . "gesamtleistung" } * 100
1657 $form->{decimalplaces}
1659 $form->{decimalplaces},
1663 foreach $item (@ergebnisse) {
1664 $form->{ "$key" . "gl" . "$item" } =
1665 $form->format_amount($myconfig,
1666 $form->round_amount(
1667 ( $form->{ "$key" . "$item" } /
1668 $form->{ "$key" . "gesamtleistung" } * 100
1670 $form->{decimalplaces}
1672 $form->{decimalplaces},
1677 if ($form->{ "$key" . "gesamtkosten" } > 0) {
1678 foreach $category (@categories) {
1679 if (defined($form->{$category}{$key})) {
1680 $form->{ "$key" . "gk" . "$category" } =
1681 $form->format_amount($myconfig,
1682 $form->round_amount(
1683 ($form->{$category}{$key} /
1684 $form->{ "$key" . "gesamtkosten" } * 100
1686 $form->{decimalplaces}
1688 $form->{decimalplaces},
1692 foreach $item (@ergebnisse) {
1693 $form->{ "$key" . "gk" . "$item" } =
1694 $form->format_amount($myconfig,
1695 $form->round_amount(
1696 ($form->{ "$key" . "$item" } /
1697 $form->{ "$key" . "gesamtkosten" } * 100
1699 $form->{decimalplaces}
1701 $form->{decimalplaces},
1706 if ($form->{10}{$key} > 0) {
1707 foreach $category (@categories) {
1708 if (defined($form->{$category}{$key})) {
1709 $form->{ "$key" . "pk" . "$category" } =
1710 $form->format_amount(
1712 $form->round_amount(
1713 ($form->{$category}{$key} / $form->{10}{$key} * 100),
1714 $form->{decimalplaces}
1716 $form->{decimalplaces},
1720 foreach $item (@ergebnisse) {
1721 $form->{ "$key" . "pk" . "$item" } =
1722 $form->format_amount($myconfig,
1723 $form->round_amount(
1724 ($form->{ "$key" . "$item" } /
1725 $form->{10}{$key} * 100
1727 $form->{decimalplaces}
1729 $form->{decimalplaces},
1734 if ($form->{4}{$key} > 0) {
1735 foreach $category (@categories) {
1736 if (defined($form->{$category}{$key})) {
1737 $form->{ "$key" . "auf" . "$category" } =
1738 $form->format_amount(
1740 $form->round_amount(
1741 ($form->{$category}{$key} / $form->{4}{$key} * 100),
1742 $form->{decimalplaces}
1744 $form->{decimalplaces},
1748 foreach $item (@ergebnisse) {
1749 $form->{ "$key" . "auf" . "$item" } =
1750 $form->format_amount($myconfig,
1751 $form->round_amount(
1752 ($form->{ "$key" . "$item" } /
1753 $form->{4}{$key} * 100
1755 $form->{decimalplaces}
1757 $form->{decimalplaces},
1762 foreach $item (@ergebnisse) {
1763 $form->{ "$key" . "$item" } =
1764 $form->format_amount($myconfig,
1765 $form->round_amount($form->{ "$key" . "$item" },
1766 $form->{decimalplaces}
1768 $form->{decimalplaces},
1775 $main::lxdebug->leave_sub();
1779 $main::lxdebug->enter_sub();
1781 my ($self, $myconfig, $form) = @_;
1783 # connect to database
1784 my $dbh = $form->dbconnect($myconfig);
1786 my $last_period = 0;
1787 my @categories_cent = qw(51r 511 86r 861 97r 971 93r 931
1788 96 66 43 45 53 62 65 67);
1789 my @categories_euro = qw(48 51 86 91 97 93 94);
1790 $form->{decimalplaces} *= 1;
1792 foreach $item (@categories_cent) {
1793 $form->{"$item"} = 0;
1795 foreach $item (@categories_euro) {
1796 $form->{"$item"} = 0;
1799 &get_accounts_g($dbh, $last_period, $form->{fromdate}, $form->{todate}, $form, "pos_ustva");
1801 # foreach $item (@categories_cent) {
1802 # if ($form->{$item}{"jetzt"} > 0) {
1803 # $form->{$item} = $form->{$item}{"jetzt"};
1804 # delete $form->{$item}{"jetzt"};
1807 # foreach $item (@categories_euro) {
1808 # if ($form->{$item}{"jetzt"} > 0) {
1809 # $form->{$item} = $form->{$item}{"jetzt"};
1810 # delete $form->{$item}{"jetzt"};
1811 # } foreach $item (@categories_cent) {
1812 # if ($form->{$item}{"jetzt"} > 0) {
1813 # $form->{$item} = $form->{$item}{"jetzt"};
1814 # delete $form->{$item}{"jetzt"};
1817 # foreach $item (@categories_euro) {
1818 # if ($form->{$item}{"jetzt"} > 0) {
1819 # $form->{$item} = $form->{$item}{"jetzt"};
1820 # delete $form->{$item}{"jetzt"};
1827 # Berechnung der USTVA Formularfelder
1829 $form->{"51r"} = $form->{"511"};
1830 $form->{"86r"} = $form->{"861"};
1831 $form->{"97r"} = $form->{"971"};
1832 $form->{"93r"} = $form->{"931"};
1834 #$form->{"96"} = $form->{"94"} * 0.16;
1836 $form->{"51r"} + $form->{"86r"} + $form->{"97r"} + $form->{"93r"} +
1838 $form->{"45"} = $form->{"43"};
1839 $form->{"53"} = $form->{"43"};
1840 $form->{"62"} = $form->{"43"} - $form->{"66"};
1841 $form->{"65"} = $form->{"43"} - $form->{"66"};
1842 $form->{"67"} = $form->{"43"} - $form->{"66"};
1844 foreach $item (@categories_cent) {
1846 $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2),
1850 foreach $item (@categories_euro) {
1852 $form->format_amount($myconfig, $form->round_amount($form->{$item}, 0),
1858 $main::lxdebug->leave_sub();
1861 sub income_statement {
1862 $main::lxdebug->enter_sub();
1864 my ($self, $myconfig, $form) = @_;
1866 # connect to database
1867 my $dbh = $form->dbconnect($myconfig);
1869 my $last_period = 0;
1870 my @categories_einnahmen = qw(1 2 3 4 5 6 7);
1871 my @categories_ausgaben =
1872 qw(8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31);
1874 my @ergebnisse = qw(sumeura sumeurb guvsumme);
1876 $form->{decimalplaces} *= 1;
1878 foreach $item (@categories_einnahmen) {
1881 foreach $item (@categories_ausgaben) {
1885 foreach $item (@ergebnisse) {
1889 &get_accounts_g($dbh, $last_period, $form->{fromdate}, $form->{todate},
1892 foreach $item (@categories_einnahmen) {
1893 $form->{"eur${item}"} =
1894 $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2));
1895 $form->{"sumeura"} += $form->{$item};
1897 foreach $item (@categories_ausgaben) {
1898 $form->{"eur${item}"} =
1899 $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2));
1900 $form->{"sumeurb"} += $form->{$item};
1903 $form->{"guvsumme"} = $form->{"sumeura"} - $form->{"sumeurb"};
1905 foreach $item (@ergebnisse) {
1907 $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2));
1909 $main::lxdebug->leave_sub();