1 #=====================================================================
3 # Copyright (c) 2004 by Udo Spallek, Aachen
7 # Web: http://www.lx-office.org
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #======================================================================
24 #=====================================================================
28 use List::Util qw(first);
32 my @tax_office_information = (
33 { 'id' => 8, 'name' => 'Baden Württemberg', 'taxbird_nr' => '0', 'elster_format' => 'FF/BBB/UUUUP', },
34 { 'id' => 9, 'name' => 'Bayern', 'taxbird_nr' => '1', 'elster_format' => 'FFF/BBB/UUUUP', },
35 { 'id' => 11, 'name' => 'Berlin', 'taxbird_nr' => '2', 'elster_format' => 'FF/BBB/UUUUP', },
36 { 'id' => 12, 'name' => 'Brandenburg', 'taxbird_nr' => '3', 'elster_format' => 'FFF/BBB/UUUUP', },
37 { 'id' => 4, 'name' => 'Bremen', 'taxbird_nr' => '4', 'elster_format' => 'FF BBB UUUUP', },
38 { 'id' => 2, 'name' => 'Hamburg', 'taxbird_nr' => '5', 'elster_format' => 'FF/BBB/UUUUP', },
39 { 'id' => 6, 'name' => 'Hessen', 'taxbird_nr' => '6', 'elster_format' => '0FF BBB UUUUP', },
40 { 'id' => 13, 'name' => 'Mecklenburg Vorpommern', 'taxbird_nr' => '7', 'elster_format' => 'FFF/BBB/UUUUP', },
41 { 'id' => 3, 'name' => 'Niedersachsen', 'taxbird_nr' => '8', 'elster_format' => 'FF/BBB/UUUUP', },
42 { 'id' => 5, 'name' => 'Nordrhein Westfalen', 'taxbird_nr' => '9', 'elster_format' => 'FFF/BBBB/UUUP', },
43 { 'id' => 7, 'name' => 'Rheinland Pfalz', 'taxbird_nr' => '10', 'elster_format' => 'FF/BBB/UUUU/P', },
44 { 'id' => 10, 'name' => 'Saarland', 'taxbird_nr' => '11', 'elster_format' => 'FFF/BBB/UUUUP', },
45 { 'id' => 14, 'name' => 'Sachsen', 'taxbird_nr' => '12', 'elster_format' => 'FFF/BBB/UUUUP', },
46 { 'id' => 15, 'name' => 'Sachsen Anhalt', 'taxbird_nr' => '13', 'elster_format' => 'FFF/BBB/UUUUP', },
47 { 'id' => 1, 'name' => 'Schleswig Holstein', 'taxbird_nr' => '14', 'elster_format' => 'FF BBB UUUUP', },
48 { 'id' => 16, 'name' => 'Thüringen', 'taxbird_nr' => '15', 'elster_format' => 'FFF/BBB/UUUUP', },
66 $self->{tax_office_information} = [];
68 foreach (@tax_office_information) {
70 $entry->{name} = $main::locale->{iconv_iso8859}->convert($entry->{name});
71 push @{ $self->{tax_office_information} }, $entry;
77 my ( $self, $form, $myconfig) = @_;
79 my $query = q{ SELECT coa FROM defaults };
81 my $dbh = $form->dbconnect($myconfig);
82 my $sth = $dbh->prepare($query);
83 $sth->execute() || $form->dberror($query);
85 my ($coa) = selectrow_query($form, $dbh, $query);
91 $form->{"COA_$coa"} = '1';
92 $form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
98 sub report_variables {
99 # Get all positions for taxreport out of the database
100 # Needs Databaseupdate Pg-upgrade2/USTVA_abstraction.pl
102 return unless defined wantarray;
107 my $myconfig = $arg_ref->{myconfig};
108 my $form = $arg_ref->{form};
109 my $type = $arg_ref->{type}; # 'paied' || 'received' || ''
110 my $attribute = $arg_ref->{attribute}; #
111 my $dec_places = (defined $arg_ref->{dec_places}) ? $arg_ref->{dec_places}:undef;
113 my $where_type = "AND tax.report_headings.type = '$type'" if ( $type );
114 my $where_dcp = "AND tax.report_variables.dec_places = '$dec_places'" if ( defined $dec_places );
118 FROM tax.report_variables
119 LEFT JOIN tax.report_headings
120 ON (tax.report_variables.heading_id = tax.report_headings.id)
126 my $dbh = $form->dbconnect($myconfig);
127 my $sth = $dbh->prepare($query);
129 $sth->execute() || $form->dberror($query);
133 while ( my $row_ref = $sth->fetchrow_arrayref() ) {
134 push @positions, @$row_ref; # Copy the array contents
145 sub create_steuernummer {
146 $main::lxdebug->enter_sub();
148 $part = $form->{part};
149 $patterncount = $form->{patterncount};
150 $delimiter = $form->{delimiter};
151 $elster_pattern = $form->{elster_pattern};
153 # rebuild steuernummer and elstersteuernummer
154 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
155 # und die parts und delimiter
160 $steuernummer_new = $part;
161 $elstersteuernummer_new = $elster_FFFF;
162 $elstersteuernummer_new .= '0';
164 for ($h = 1; $h < $patterncount; $h++) {
165 $steuernummer_new .= qq|$delimiter|;
166 for ($i = 1; $i <= length($elster_pattern); $i++) {
167 $steuernummer_new .= $form->{"part_$h\_$i"};
168 $elstersteuernummer_new .= $form->{"part_$h\_$i"};
171 if ($form->{steuernummer} ne $steuernummer_new) {
172 $form->{steuernummer} = $steuernummer_new;
173 $form->{elstersteuernummer} = $elstersteuernummer_new;
174 $form->{steuernummer_new} = $steuernummer_new;
176 $main::lxdebug->leave_sub();
177 return ($steuernummer_new, $elstersteuernummer_new);
180 sub steuernummer_input {
181 $main::lxdebug->enter_sub();
183 my ($self, $elsterland, $elsterFFFF, $steuernummer) = @_;
185 my $steuernummer_input = '';
187 $elster_land = $elsterland;
188 $elster_FFFF = $elsterFFFF;
189 $steuernummer = '0000000000' if ($steuernummer eq '');
191 # $steuernummer formatieren (nur Zahlen) -> $stnr
192 my $stnr = $steuernummer;
195 #Pattern description Elstersteuernummer
198 my $tax_office = first { $_->{name} eq $elster_land } @{ $self->{tax_office_information} };
199 my $elster_pattern = $tax_office->{elster_format};
200 my @elster_pattern = split(' ', $elster_pattern);
201 my $delimiter = ' ';
202 my $patterncount = @elster_pattern;
203 if ($patterncount < 2) {
204 @elster_pattern = ();
205 @elster_pattern = split('/', $elster_pattern);
207 $patterncount = @elster_pattern;
210 # no we have an array of patternparts and a delimiter
211 # create the first automated and fixed part and delimiter
213 $steuernummer_input .= qq|<b><font size="+1">|;
216 $elster_pattern[0] eq 'FFF' && do {
217 $part = substr($elster_FFFF, 1, 4);
218 $steuernummer_input .= qq|$part|;
221 $elster_pattern[0] eq '0FF' && do {
222 $part = '0' . substr($elster_FFFF, 2, 4);
223 $steuernummer_input .= qq|$part|;
226 $elster_pattern[0] eq 'FF' && do {
227 $part = substr($elster_FFFF, 2, 4);
228 $steuernummer_input .= qq|$part|;
232 $steuernummer_input .= qq|Fehler!|;
237 #now the rest of the Steuernummer ...
238 $steuernummer_input .= qq|</b></font>|;
239 $steuernummer_input .= qq|\n
240 <input type=hidden name="elster_pattern" value="$elster_pattern">
241 <input type=hidden name="patterncount" value="$patterncount">
242 <input type=hidden name="patternlength" value="$patterncount">
243 <input type=hidden name="delimiter" value="$delimiter">
244 <input type=hidden name="part" value="$part">
249 for (my $h = 1; $h < $patterncount; $h++) {
250 $steuernummer_input .= qq| $delimiter \n|;
251 for (my $i = 1; $i <= length($elster_pattern[$h]); $i++) {
252 $steuernummer_input .= qq|<select name="part_$h\_$i">\n|;
254 for (my $j = 0; $j <= 9; $j++) {
255 $steuernummer_input .= qq| <option value="$j"|;
256 if ($steuernummer ne '') {
257 if ($j eq substr($stnr, length($part) + $k, 1)) {
258 $steuernummer_input .= qq| selected|;
261 $steuernummer_input .= qq|>$j</option>\n|;
264 $steuernummer_input .= qq|</select>\n|;
268 $main::lxdebug->leave_sub();
270 return $steuernummer_input;
274 $main::lxdebug->enter_sub();
278 # Referenz wird übergeben, hash of hash wird nicht
279 # in neues Hash kopiert, sondern direkt über die Referenz verändert
280 # Prototyp für diese Konstruktion
282 my ($self, $land, $elsterFFFF, $elster_init) = @_;
285 my $FFFF = $elsterFFFF;
288 $checked = 'checked' if ($elsterFFFF eq '' and $land eq '');
291 <script language="Javascript">
292 function update_auswahl()
294 var elsterBLAuswahl = document.verzeichnis.elsterland_new;
295 var elsterFAAuswahl = document.verzeichnis.elsterFFFF_new;
297 elsterFAAuswahl.options.length = 0; // dropdown aufräumen
300 foreach $elster_land (sort keys %$elster_init) {
302 if (elsterBLAuswahl.options[elsterBLAuswahl.selectedIndex].
303 value == "$elster_land")
307 my %elster_land_fa = ();
309 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
310 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}->{$FFFF}->[0];
312 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
313 keys(%elster_land_fa)
316 elsterFAAuswahl.options[$j] = new Option("$elster_land_fa{$ffff} ($ffff)","$ffff");|;
332 <select size="1" name="elsterland_new" onchange="update_auswahl()">|;
334 $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select federal state...') . qq|</option>\n|;
336 foreach $elster_land (sort keys %$elster_init) {
338 <option value="$elster_land"|;
339 if ($elster_land eq $land and $checked eq '') {
340 $fa_auswahl .= qq| selected|;
342 $fa_auswahl .= qq|>$elster_land</option>
350 my $elster_land = '';
351 $elster_land = ($land ne '') ? $land : '';
352 %elster_land_fa = ();
353 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
354 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}->{$FFFF}->[0];
362 <select size="1" name="elsterFFFF_new">|;
363 if ($elsterFFFF eq '') {
364 $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select tax office...') . qq|</option>|;
366 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
367 keys(%elster_land_fa)
371 <option value="$ffff"|;
372 if ($ffff eq $elsterFFFF and $checked eq '') {
373 $fa_auswahl .= qq| selected|;
375 $fa_auswahl .= qq|>$elster_land_fa{$ffff} ($ffff)</option>|;
384 $main::lxdebug->leave_sub();
390 $main::lxdebug->enter_sub();
394 if ($ENV{HTTP_USER_AGENT}) {
397 print qq|<body><h2 class=info>Hinweis</h2>
403 <input type=button value="| . $main::locale->text('Back') . qq|" onClick="history.go(-1)">
411 die "Hinweis: $msg\n";
414 $main::lxdebug->leave_sub();
418 $main::lxdebug->enter_sub();
421 # soll mal eine Erinnerungsfunktion für USTVA Abgaben werden, die automatisch
422 # den Termin der nächsten USTVA anzeigt.
425 my ($today, $FA_dauerfrist, $FA_voranmeld) = @_;
430 $today =~ /(\d\d\d\d)(\d\d)(\d\d)/;
436 $yymmdd = "$year$month$day" * 1;
437 $mmdd = "$month$day" * 1;
441 #$ical = '...vcal format';
443 #if ($FA_voranmeld eq 'month'){
445 %liste = ("0110" => 'December',
447 "0310" => 'February',
454 "1010" => 'September',
456 "1210" => 'November');
460 $month += 1 if ($day > 10);
461 $month = sprintf("%02d", $month);
462 $stichtag = $year . $month . "10";
463 $ust_va = $month . "10";
465 foreach $date (%liste) {
466 $ust_va = $liste{$date} if ($date eq $stichtag);
469 #} elsif ($FA_voranmeld eq 'quarter'){
474 #@stichtag = ('10.04.2004', '10.05.2004');
476 #@liste = ['0110', '0210', '0310', '0410', '0510', '0610', '0710', '0810', '0910',
477 # '1010', '1110', '1210', ];
479 #foreach $key (@liste){
480 # #if ($ddmm < ('0110' * 1));
482 # $stichtag = $liste[$key - 1] if ($ddmm > $key);
486 #$stichtag =~ /([\d]\d)(\d\d)$/
487 #$stichtag = "$1.$2.$yy"
489 $main::lxdebug->leave_sub();
490 return ($stichtag, $description, $tage_bis, $ical);
493 sub query_finanzamt {
494 $main::lxdebug->enter_sub();
496 my ($self, $myconfig, $form) = @_;
498 my $dbh = $form->dbconnect($myconfig) or $self->error(DBI->errstr);
500 #Test, if table finanzamt exist
501 my $table = 'finanzamt';
502 my $filename = "sql/$table.sql";
504 my $tst = $dbh->prepare("SELECT * FROM $table");
508 #There is no table, read the table from sql/finanzamt.sql
509 print qq|<p>Bitte warten, Tabelle $table wird einmalig in Datenbank:
510 $myconfig->{dbname} als Benutzer: $myconfig->{dbuser} hinzugefügt...</p>|;
511 process_query($form, $dbh, $filename) || $self->error(DBI->errstr);
513 #execute second last call
514 my $dbh = $form->dbconnect($myconfig) or $self->error(DBI->errstr);
531 'FA_PLZ_Grosskunden', # 9
532 'FA_PLZ_Postfach', # 10
535 'FA_Kontonummer_1', # 13
536 'FA_Bankbezeichnung_1', # 14
537 #'FA_BankIBAN_1', # 15
538 #'FA_BankBIC_1', # 16
539 #'FA_BankInhaber_BUFA_Nr_1', # 17
541 'FA_Kontonummer_2', # 19
542 'FA_Bankbezeichnung_2', # 20
543 #'FA_BankIBAN_2', # 21
544 #'FA_BankBIC_2', # 22
545 #'FA_BankInhaber_BUFA_Nr_2', # 23
546 'FA_Oeffnungszeiten', # 24
549 #'FA_zustaendige_Hauptstelle_BUFA_Nr', # 27
550 #'FA_zustaendige_vorgesetzte_Finanzbehoerde' # 28
553 my $field = join(', ', @vars);
555 my $query = "SELECT $field FROM finanzamt ORDER BY FA_Land_nr";
556 my $sth = $dbh->prepare($query) or $self->error($dbh->errstr);
557 $sth->execute || $form->dberror($query);
558 my $array_ref = $sth->fetchall_arrayref();
560 foreach my $row (@$array_ref) {
561 my $FA_finanzamt = $row;
562 my $tax_office = first { $_->{id} == $FA_finanzamt->[0] } @{ $self->{tax_office_information} };
563 $land = $tax_office->{name};
565 # $land = $main::locale->{iconv}->convert($land);
567 my $ffff = @$FA_finanzamt[1];
570 $rec->{$land} = $ffff;
575 $finanzamt{$land}{$ffff} = [@$FA_finanzamt];
581 $main::lxdebug->leave_sub();
587 $main::lxdebug->enter_sub();
589 # Copyright D. Simander -> SL::Form under Gnu GPL.
590 my ($form, $dbh, $filename) = @_;
592 # return unless (-f $filename);
594 open my $FH, "<", "$filename" or $form->error("$filename : $!\n");
601 # Remove DOS and Unix style line endings.
604 # don't add comments or empty lines
605 next if /^(--.*|\s+)$/;
607 for (my $i = 0; $i < length($_); $i++) {
608 my $char = substr($_, $i, 1);
610 # Are we inside a string?
612 if ($char eq $quote_chars[-1]) {
618 if (($char eq "'") || ($char eq "\"")) {
619 push(@quote_chars, $char);
621 } elsif ($char eq ";") {
623 # Query is complete. Send it.
625 $sth = $dbh->prepare($query);
626 $sth->execute || $form->dberror($query);
640 $main::lxdebug->leave_sub();
644 $main::lxdebug->enter_sub();
646 my ($self, $myconfig, $form) = @_;
648 # connect to database
649 my $dbh = $form->dbconnect($myconfig);
652 my $category = "pos_ustva";
654 my @category_cent = USTVA->report_variables({
655 myconfig => $myconfig,
658 attribute => 'position',
662 push @category_cent, qw(83 Z43 Z45 Z53 Z62 Z65 Z67);
664 my @category_euro = USTVA->report_variables({
665 myconfig => $myconfig,
668 attribute => 'position',
672 push @category_euro, USTVA->report_variables({
673 myconfig => $myconfig,
676 attribute => 'position',
680 $form->{decimalplaces} *= 1;
682 foreach $item (@category_cent) {
683 $form->{"$item"} = 0;
685 foreach $item (@category_euro) {
686 $form->{"$item"} = 0;
688 my $coa_name = coa_get($dbh);
689 $form->{coa} = $coa_name;
691 # Controlvariable for templates
692 $form->{"$coa_name"} = '1';
694 $main::lxdebug->message(LXDebug::DEBUG2, "COA: '$form->{coa}', \$form->{$coa_name} = 1");
696 &get_accounts_ustva($dbh, $last_period, $form->{fromdate}, $form->{todate},
699 ###########################################
701 # Nationspecific Modfications
703 ###########################################
707 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU'){
710 # Umordnen der Kennziffern
711 if ( $form->{year} < 2007) {
712 $form->{35} += $form->{81};
713 $form->{36} += $form->{811};
714 $form->{95} += $form->{89};
715 $form->{98} += $form->{891};
716 map { delete $form->{$_} } qw(81 811 89 891);
718 $form->{35} += $form->{51};
719 $form->{36} += $form->{511};
720 $form->{95} += $form->{97};
721 $form->{98} += $form->{971};
722 map { delete $form->{$_} } qw(51 511 97 971);
728 # Fixme: Wird auch noch für Oesterreich gebraucht,
729 # weil kein eigenes Ausgabeformular
730 # sotte aber aus der allgeméinen Steuerberechnung verschwinden
732 # Berechnung der USTVA Formularfelder laut Bogen 207
735 $form->{"51r"} = $form->{"511"};
736 $form->{"86r"} = $form->{"861"};
737 $form->{"97r"} = $form->{"971"};
738 $form->{"93r"} = $form->{"931"};
740 $form->{"Z43"} = $form->{"511"} + $form->{"811"} + $form->{"861"}
741 + $form->{"36"} + $form->{"80"} + $form->{"971"}
742 + $form->{"891"} + $form->{"931"} + $form->{"96"}
745 $form->{"Z45"} = $form->{"Z43"};
747 $form->{"Z53"} = $form->{"Z45"} + $form->{"53"} + $form->{"74"}
748 + $form->{"85"} + $form->{"65"};
750 $form->{"Z62"} = $form->{"Z43"} - $form->{"66"} - $form->{"61"}
751 - $form->{"62"} - $form->{"67"} - $form->{"63"}
752 - $form->{"64"} - $form->{"59"};
754 $form->{"Z65"} = $form->{"Z62"} - $form->{"69"};
755 $form->{"83"} = $form->{"Z65"} - $form->{"39"};
759 $main::lxdebug->leave_sub();
766 my $query= qq|SELECT coa FROM defaults|;
768 my $sth = $dbh->prepare($query);
770 $sth->execute || $form->dberror($query);
772 ($ref) = $sth->fetchrow_array;
778 sub get_accounts_ustva {
779 $main::lxdebug->enter_sub();
781 my ($dbh, $last_period, $fromdate, $todate, $form, $category) = @_;
792 my $gltaxkey_where = "(tk.pos_ustva>=59 AND tk.pos_ustva<=66)";
795 if ($form->{method} eq 'cash') {
796 $subwhere .= " AND transdate >= '$fromdate'";
797 $glwhere = " AND ac.transdate >= '$fromdate'";
798 $ARwhere .= " AND acc.transdate >= '$fromdate'";
800 $APwhere .= " AND AP.transdate >= '$fromdate'";
801 $where .= " AND ac.transdate >= '$fromdate'";
805 $where .= " AND ac.transdate <= '$todate'";
806 $ARwhere .= " AND acc.transdate <= '$todate'";
809 my $acc_trans_where = '1=1';
810 if ($fromdate || $todate) {
811 $acc_trans_where = "ac.trans_id IN (SELECT DISTINCT trans_id FROM acc_trans WHERE ";
814 $acc_trans_where .= "transdate >= '$fromdate'";
817 $acc_trans_where .= " AND " if ($fromdate);
818 $acc_trans_where .= "transdate <= '$todate'";
821 $acc_trans_where .= ")";
824 ############################################
825 # Method eq 'cash' = IST Versteuerung
826 ############################################
827 # Betrifft nur die eingenommene Umsatzsteuer
829 ############################################
831 if ($form->{method} eq 'cash') {
835 -- USTVA IST-Versteuerung
837 -- Alle tatsaechlichen _Zahlungseingaenge_
838 -- im Voranmeldezeitraum erfassen
839 -- (Teilzahlungen werden prozentual auf verschiedene Steuern aufgeteilt)
841 -- Bezahlt / Rechnungssumme
843 SELECT SUM(acc.amount)
845 INNER JOIN chart c ON (acc.chart_id = c.id
846 AND c.link like '%AR_paid%')
850 AND acc.trans_id = ac.trans_id
854 SELECT amount FROM ar WHERE id = ac.trans_id
859 LEFT JOIN chart c ON (c.id = ac.chart_id)
860 LEFT JOIN ar ON (ar.id = ac.trans_id)
861 LEFT JOIN taxkeys tk ON (
863 SELECT id FROM taxkeys
864 WHERE chart_id = ac.chart_id
865 -- AND taxkey_id = ac.taxkey
866 AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
867 ORDER BY startdate DESC LIMIT 1
872 GROUP BY tk.pos_ustva
875 } elsif ($form->{method} eq 'accrual') {
876 #########################################
877 # Method eq 'accrual' = Soll Versteuerung
878 #########################################
881 -- Alle Einnahmen AR und pos_ustva erfassen
883 - sum(ac.amount) AS amount,
886 JOIN chart c ON (c.id = ac.chart_id)
887 JOIN ar ON (ar.id = ac.trans_id)
890 SELECT id FROM taxkeys
891 WHERE chart_id = ac.chart_id
892 AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
893 ORDER BY startdate DESC LIMIT 1
899 GROUP BY tk.pos_ustva
904 $form->error("Unknown tax method: $form->{method}")
908 #########################################
909 # Ausgaben und Gl Buchungen sind gleich
910 # für Ist- und Soll-Versteuerung
911 #########################################
913 UNION -- alle Ausgaben AP erfassen
916 sum(ac.amount) AS amount,
919 JOIN ap ON (ap.id = ac.trans_id )
920 JOIN chart c ON (c.id = ac.chart_id)
921 LEFT JOIN taxkeys tk ON (
923 SELECT id FROM taxkeys
925 AND chart_id=ac.chart_id
926 --AND taxkey_id = ac.taxkey
927 AND startdate <= COALESCE(AP.transdate)
928 ORDER BY startdate DESC LIMIT 1
934 GROUP BY tk.pos_ustva
936 UNION -- Einnahmen direkter gl Buchungen erfassen
939 ( - ac.amount) AS amount,
942 JOIN chart c ON (c.id = ac.chart_id)
943 JOIN gl a ON (a.id = ac.trans_id)
944 LEFT JOIN taxkeys tk ON (
946 SELECT id FROM taxkeys
947 WHERE chart_id=ac.chart_id
948 AND NOT $gltaxkey_where
949 AND startdate <= COALESCE(ac.transdate)
950 ORDER BY startdate DESC LIMIT 1
957 GROUP BY tk.pos_ustva
960 UNION -- Ausgaben direkter gl Buchungen erfassen
963 (ac.amount) AS amount,
966 JOIN chart c ON (c.id = ac.chart_id)
967 JOIN gl a ON (a.id = ac.trans_id)
968 LEFT JOIN taxkeys tk ON (
970 SELECT id FROM taxkeys
971 WHERE chart_id=ac.chart_id
973 AND startdate <= COALESCE(ac.transdate)
974 ORDER BY startdate DESC LIMIT 1
981 GROUP BY tk.pos_ustva
989 # Show all $query in Debuglevel LXDebug::QUERY
990 $callingdetails = (caller (0))[3];
991 $main::lxdebug->message(LXDebug::QUERY, "$callingdetails \$query=\n $query");
993 my $sth = $dbh->prepare($query);
995 $sth->execute || $form->dberror($query);
997 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
999 $ref->{amount} *= -1;
1000 $form->{ $ref->{$category} } += $ref->{amount};
1005 $main::lxdebug->leave_sub();
1010 $main::lxdebug->enter_sub();
1012 my ($self, $userspath, $filename) = @_;
1014 $form->error("Missing Parameter: @_") if !$userspath || !$filename;
1016 my $form = $main::form;
1018 $filename = "$form->{login}_$filename";
1019 $filename =~ s|.*/||;
1020 $filename = "$userspath/$filename";
1021 open my $FACONF, "<", $filename or sub {# Annon Sub
1023 # create file if file does not exist
1024 open my $FANEW, ">", $filename or $form->error("CREATE: $filename : $!");
1025 close $FANEW or $form->error("CLOSE: $filename : $!");
1027 #try again open file
1028 open my $FACONF, "<", $filename or $form->error("OPEN: $filename : $!");
1033 next if (/^(\#|\s)/);
1038 # remove any trailing whitespace
1039 s/^\s*(.*?)\s*$/$1/;
1040 my ($key, $value) = split(/=/, $_, 2);
1042 $form->{$key} = "$value";
1048 $main::lxdebug->leave_sub();