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., 51 Franklin Street, Fifth Floor, Boston,
23 #======================================================================
25 #=====================================================================
29 use List::Util qw(first);
34 use SL::DB::Finanzamt;
39 my @tax_office_information = (
40 { 'id' => 8, 'name' => 'Baden-Württemberg', 'taxbird_nr' => '1', 'elster_format' => 'FFBBB/UUUUP', },
41 { 'id' => 9, 'name' => 'Bayern', 'taxbird_nr' => '2', 'elster_format' => 'FFF/BBB/UUUUP', },
42 { 'id' => 11, 'name' => 'Berlin', 'taxbird_nr' => '3', 'elster_format' => 'FF/BBB/UUUUP', },
43 { 'id' => 12, 'name' => 'Brandenburg', 'taxbird_nr' => '4', 'elster_format' => 'FFF/BBB/UUUUP', },
44 { 'id' => 4, 'name' => 'Bremen', 'taxbird_nr' => '5', 'elster_format' => 'FF BBB UUUUP', },
45 { 'id' => 2, 'name' => 'Hamburg', 'taxbird_nr' => '6', 'elster_format' => 'FF/BBB/UUUUP', },
46 { 'id' => 6, 'name' => 'Hessen', 'taxbird_nr' => '7', 'elster_format' => '0FF BBB UUUUP', },
47 { 'id' => 13, 'name' => 'Mecklenburg-Vorpommern', 'taxbird_nr' => '8', 'elster_format' => 'FFF/BBB/UUUUP', },
48 { 'id' => 3, 'name' => 'Niedersachsen', 'taxbird_nr' => '9', 'elster_format' => 'FF/BBB/UUUUP', },
49 { 'id' => 5, 'name' => 'Nordrhein-Westfalen', 'taxbird_nr' => '10', 'elster_format' => 'FFF/BBBB/UUUP', },
50 { 'id' => 7, 'name' => 'Rheinland-Pfalz', 'taxbird_nr' => '11', 'elster_format' => 'FF/BBB/UUUUP', },
51 { 'id' => 10, 'name' => 'Saarland', 'taxbird_nr' => '12', 'elster_format' => 'FFF/BBB/UUUUP', },
52 { 'id' => 14, 'name' => 'Sachsen', 'taxbird_nr' => '13', 'elster_format' => 'FFF/BBB/UUUUP', },
53 { 'id' => 15, 'name' => 'Sachsen-Anhalt', 'taxbird_nr' => '14', 'elster_format' => 'FFF/BBB/UUUUP', },
54 { 'id' => 1, 'name' => 'Schleswig-Holstein', 'taxbird_nr' => '15', 'elster_format' => 'FF BBB UUUUP', },
55 { 'id' => 16, 'name' => 'Thüringen', 'taxbird_nr' => '16', 'elster_format' => 'FFF/BBB/UUUUP', },
58 my @fiamt_config = qw(taxnumber fa_bufa_nr fa_dauerfrist fa_steuerberater_city fa_steuerberater_name
59 fa_steuerberater_street fa_steuerberater_tel fa_voranmeld);
61 my @fiamt_finanzamt = qw(
62 fa_land_nr fa_bufa_nr fa_name fa_strasse
63 fa_plz fa_ort fa_telefon fa_fax
64 fa_plz_grosskunden fa_plz_postfach fa_postfach
65 fa_blz_1 fa_kontonummer_1 fa_bankbezeichnung_1
66 fa_blz_2 fa_kontonummer_2 fa_bankbezeichnung_2 fa_oeffnungszeiten
67 fa_email fa_internet);
85 $self->{tax_office_information} = [];
87 foreach (@tax_office_information) {
89 $entry->{name} = $::locale->{iconv_utf8}->convert($entry->{name});
90 push @{ $self->{tax_office_information} }, $entry;
96 my ( $self, $form ) = @_;
98 my $coa = $::instance_conf->get_coa;
100 $form->{"COA_$coa"} = '1';
101 $form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
107 sub report_variables {
108 # Get all positions for taxreport out of the database
109 # Needs Databaseupdate Pg-upgrade2/USTVA_abstraction.pl
114 my $myconfig = $arg_ref->{myconfig};
115 my $form = $arg_ref->{form};
116 my $type = $arg_ref->{type}; # 'paied' || 'received' || ''
117 my $attribute = $arg_ref->{attribute}; #
118 my $dec_places = (defined $arg_ref->{dec_places}) ? $arg_ref->{dec_places}:undef;
120 my $where_type = $type ? "AND tax.report_headings.type = '$type'" : '';
121 my $where_dcp = defined $dec_places ? "AND tax.report_variables.dec_places = '$dec_places'" : '';
125 FROM tax.report_variables
126 LEFT JOIN tax.report_headings
127 ON (tax.report_variables.heading_id = tax.report_headings.id)
135 SL::DB->client->with_transaction(sub {
136 my $dbh = SL::DB->client->dbh;
137 my $sth = $dbh->prepare($query);
139 $sth->execute() || $form->dberror($query);
141 while ( my $row_ref = $sth->fetchrow_arrayref() ) {
142 push @positions, @$row_ref; # Copy the array contents
147 }) or do { die SL::DB->client->error };
153 sub steuernummer_input {
154 $main::lxdebug->enter_sub();
156 my ($self, $elsterland, $elsterFFFF, $steuernummer) = @_;
157 our ($elster_FFFF, $elster_land);
159 my $steuernummer_input = '';
161 $elster_land = $elsterland;
162 $elster_FFFF = $elsterFFFF;
163 $steuernummer = '0000000000' if ($steuernummer eq '');
165 # $steuernummer formatieren (nur Zahlen) -> $stnr
166 my $stnr = $steuernummer;
169 #Pattern description Elstersteuernummer
172 my $tax_office = first { $_->{id} eq $elster_land } @{ $self->{tax_office_information} };
173 my $elster_pattern = $tax_office->{elster_format};
174 # $::lxdebug->message(LXDebug->DEBUG2, "stnr=".$stnr." elster_FFFF=".$elster_FFFF.
175 # " pattern=".$elster_pattern." land=".$elster_land);
176 my @elster_pattern = split(' ', $elster_pattern);
177 my $delimiter1 = ' ';
178 my $delimiter2 = ' ';
179 my $patterncount = @elster_pattern;
180 if ($patterncount < 2) {
181 @elster_pattern = ();
182 @elster_pattern = split('/', $elster_pattern);
185 $patterncount = @elster_pattern;
186 if ($patterncount < 2) {
187 @elster_pattern = ();
188 @elster_pattern = split(' ', $elster_pattern);
191 $patterncount = @elster_pattern;
195 # no we have an array of patternparts and a delimiter
196 # create the first automated and fixed part and delimiter
198 $steuernummer_input .= qq|<b><font size="+1">|;
200 # $::lxdebug->message(LXDebug->DEBUG2, "pattern0=".$elster_pattern[0]);
202 $elster_pattern[0] eq 'FFF' && do {
203 $part = substr($elster_FFFF, 1, 4);
204 $steuernummer_input .= qq|$part|;
207 $elster_pattern[0] eq '0FF' && do {
208 $part = '0' . substr($elster_FFFF, 2, 4);
209 $steuernummer_input .= qq|$part|;
212 $elster_pattern[0] eq 'FFBBB' && do {
213 $part = substr($elster_FFFF, 2, 4);
214 $steuernummer_input .= qq|$part|;
218 @elster_pattern = ('FF','BBB','UUUUP');
221 $elster_pattern[0] eq 'FF' && do {
222 $part = substr($elster_FFFF, 2, 4);
223 $steuernummer_input .= qq|$part|;
227 $steuernummer_input .= qq|Fehler!|;
232 #now the rest of the Steuernummer ...
233 $steuernummer_input .= qq|</font></b>|;
234 $steuernummer_input .= qq|\n
235 <input type=hidden name="elster_pattern" value="$elster_pattern">
236 <input type=hidden name="patterncount" value="$patterncount">
237 <input type=hidden name="patternlength" value="$patterncount">
238 <input type=hidden name="delimiter1" value="$delimiter1">
239 <input type=hidden name="delimiter2" value="$delimiter2">
240 <input type=hidden name="part" value="$part">
245 for (my $h = 1; $h < $patterncount; $h++) {
246 my $delimiter = ( $h==1?$delimiter1:$delimiter2);
247 $steuernummer_input .= qq| $delimiter \n|;
248 # $::lxdebug->message(LXDebug->DEBUG2, "pattern[$h]=".$elster_pattern[$h]);
249 for (my $i = 1; $i <= length($elster_pattern[$h]); $i++) {
250 $steuernummer_input .= qq|<select name="part_$h\_$i">\n|;
252 for (my $j = 0; $j <= 9; $j++) {
253 $steuernummer_input .= qq| <option value="$j"|;
254 if ($steuernummer ne '') {
255 if ($j eq substr($stnr, length($part) + $k, 1)) {
256 $steuernummer_input .= qq| selected|;
259 $steuernummer_input .= qq|>$j</option>\n|;
262 $steuernummer_input .= qq|</select>\n|;
266 $main::lxdebug->leave_sub();
268 return $steuernummer_input;
272 $main::lxdebug->enter_sub();
274 # Referenz wird übergeben, hash of hash wird nicht
275 # in neues Hash kopiert, sondern direkt über die Referenz verändert
276 # Prototyp für diese Konstruktion
278 my ($self, $land, $elsterFFFF, $elster_init) = @_;
280 # $::lxdebug->message(LXDebug->DEBUG2,"land=".$land." amt=".$elsterFFFF);
282 my $FFFF = $elsterFFFF;
285 $checked = 'checked' if ($elsterFFFF eq '' and $land eq '');
287 my %elster_land_name = ();
290 <script language="Javascript">
291 function update_auswahl()
293 var elsterBLAuswahl = document.verzeichnis.fa_land_nr_new;
294 var elsterFAAuswahl = document.verzeichnis.fa_bufa_nr_new;
296 elsterFAAuswahl.options.length = 0; // dropdown aufräumen
299 foreach my $elster_land (sort keys %$elster_init) {
301 if (elsterBLAuswahl.options[elsterBLAuswahl.selectedIndex].value == "$elster_land")
305 %elster_land_fa = ();
307 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
308 if ( $FFFF eq 'name' ) {
309 $elster_land_name{$elster_land} = $elster_init->{$elster_land}{$FFFF};
310 delete $elster_init->{$elster_land}{$FFFF};
312 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}{$FFFF}->fa_name;
315 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
316 keys(%elster_land_fa)
319 elsterFAAuswahl.options[$j] = new Option("$elster_land_fa{$ffff} ($ffff)","$ffff");|;
335 <select size="1" name="fa_land_nr_new" onchange="update_auswahl()">|;
337 $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select federal state...') . qq|</option>\n|;
339 foreach my $elster_land (sort keys %$elster_init) {
341 <option value="$elster_land"|;
342 # $::lxdebug->message(LXDebug->DEBUG2,"land=".$land." elster_land=".$elster_land." lname=".$elster_land_name{$elster_land});
343 if ($elster_land eq $land and $checked eq '') {
344 $fa_auswahl .= qq| selected|;
346 $fa_auswahl .= qq|>$elster_land_name{$elster_land}</option>
355 my $elster_land = '';
356 $elster_land = ($land ne '') ? $land : '';
357 %elster_land_fa = ();
358 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
359 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}{$FFFF}->fa_name;
367 <select size="1" name="fa_bufa_nr_new">|;
368 if ($elsterFFFF eq '') {
369 $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select tax office...') . qq|</option>|;
371 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
372 keys(%elster_land_fa)
376 <option value="$ffff"|;
377 if ($ffff eq $elsterFFFF and $checked eq '') {
378 $fa_auswahl .= qq| selected|;
380 $fa_auswahl .= qq|>$elster_land_fa{$ffff} ($ffff)</option>|;
389 $main::lxdebug->leave_sub();
395 $main::lxdebug->enter_sub();
399 if ($ENV{HTTP_USER_AGENT}) {
402 print qq|<body><h2 class=info>Hinweis</h2>
408 <input type=button value="| . $main::locale->text('Back') . qq|" onClick="history.go(-1)">
412 $::dispatcher->end_request;
416 die "Hinweis: $msg\n";
419 $main::lxdebug->leave_sub();
422 # 20.10.2009 sschoeling: this sub seems to be orphaned.
424 $main::lxdebug->enter_sub();
427 # soll mal eine Erinnerungsfunktion für USTVA Abgaben werden, die automatisch
428 # den Termin der nächsten USTVA anzeigt.
431 my ($today, $FA_dauerfrist, $FA_voranmeld) = @_;
436 $today =~ /(\d\d\d\d)(\d\d)(\d\d)/;
442 my $yymmdd = "$year$month$day" * 1;
443 my $mmdd = "$month$day" * 1;
447 #$ical = '...vcal format';
449 #if ($FA_voranmeld eq 'month'){
452 "0110" => 'December',
454 "0310" => 'February',
461 "1010" => 'September',
463 "1210" => 'November',
468 $month += 1 if ($day > 10);
469 $month = sprintf("%02d", $month);
470 $stichtag = $year . $month . "10";
471 my $ust_va = $month . "10";
473 foreach my $date (%liste) {
474 $ust_va = $liste{$date} if ($date eq $stichtag);
477 #} elsif ($FA_voranmeld eq 'quarter'){
482 #@stichtag = ('10.04.2004', '10.05.2004');
484 #@liste = ['0110', '0210', '0310', '0410', '0510', '0610', '0710', '0810', '0910',
485 # '1010', '1110', '1210', ];
487 #foreach $key (@liste){
488 # #if ($ddmm < ('0110' * 1));
490 # $stichtag = $liste[$key - 1] if ($ddmm > $key);
494 #$stichtag =~ /([\d]\d)(\d\d)$/
495 #$stichtag = "$1.$2.$yy"
497 our $description; # most probably not existent.
498 our $tage_bis; # most probably not existent.
499 our $ical; # most probably not existent.
501 $main::lxdebug->leave_sub();
502 return ($stichtag, $description, $tage_bis, $ical);
505 sub query_finanzamt {
506 $main::lxdebug->enter_sub();
508 my ($self, $myconfig, $form) = @_;
510 my $dbh = SL::DB->client->dbh;
512 #Test, if table finanzamt exist
513 my $table = 'finanzamt';
514 my $filename = "sql/$table.sql";
516 my $tst = $dbh->prepare("SELECT * FROM $table");
517 $tst->execute || do {
518 #There is no table, read the table from sql/finanzamt.sql
519 print qq|<p>Bitte warten, Tabelle $table wird einmalig in Datenbank:
520 $myconfig->{dbname} als Benutzer: $myconfig->{dbuser} hinzugefügt...</p>|;
521 SL::DB->client->with_transaction(sub {
522 process_query($form, $dbh, $filename) || $self->error(DBI->errstr);
524 }) or do { die SL::DB->client->error };
529 my $fiamt = SL::DB::Finanzamt->_get_manager_class->get_all(sort => 'fa_land_nr');
532 foreach my $row (@$fiamt) {
533 my $tax_office = first { $_->{id} == $row->fa_land_nr } @{ $self->{tax_office_information} };
534 $land = $tax_office->{id};
535 $finanzamt{$land}{$row->fa_bufa_nr} = $row;
536 $finanzamt{$land}{'name'} ||= $tax_office->{name};
538 $main::lxdebug->leave_sub();
544 $main::lxdebug->enter_sub();
546 # Copyright D. Simander -> SL::Form under Gnu GPL.
547 my ($form, $dbh, $filename) = @_;
549 # return unless (-f $filename);
551 open my $FH, "<", "$filename" or $form->error("$filename : $!\n");
558 # Remove DOS and Unix style line endings.
561 # don't add comments or empty lines
562 next if /^(--.*|\s+)$/;
564 for (my $i = 0; $i < length($_); $i++) {
565 my $char = substr($_, $i, 1);
567 # Are we inside a string?
569 if ($char eq $quote_chars[-1]) {
575 if (($char eq "'") || ($char eq "\"")) {
576 push(@quote_chars, $char);
578 } elsif ($char eq ";") {
580 # Query is complete. Send it.
582 $sth = $dbh->prepare($query);
583 $sth->execute || $form->dberror($query);
597 $main::lxdebug->leave_sub();
601 $main::lxdebug->enter_sub();
603 my ($self, $myconfig, $form) = @_;
605 my $dbh = SL::DB->client->dbh;
608 my $category = "pos_ustva";
610 $form->{coa} = $::instance_conf->get_coa;
612 my @category_cent = USTVA->report_variables({
613 myconfig => $myconfig,
616 attribute => 'position',
620 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
621 push @category_cent, qw(Z43 Z45 Z53 Z54 Z62 Z65 Z67);
623 my @category_euro = USTVA->report_variables({
624 myconfig => $myconfig,
627 attribute => 'position',
631 @{$form->{category_cent}} = @category_cent;
632 @{$form->{category_euro}} = @category_euro;
633 $form->{decimalplaces} *= 1;
635 foreach my $item (@category_cent) {
636 $form->{"$item"} = 0;
638 foreach my $item (@category_euro) {
639 $form->{"$item"} = 0;
642 # Controlvariable for templates
643 my $coa_name = $form->{coa};
644 $form->{"$coa_name"} = '1';
646 &get_accounts_ustva($dbh, $last_period, $form->{fromdate}, $form->{todate},
649 ###########################################
651 # Nationspecific Modfications
653 ###########################################
657 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU'){
660 # Umordnen der Kennziffern
661 if ( $form->{year} < 2007) {
662 $form->{35} += $form->{81};
663 $form->{36} += $form->{811};
664 $form->{95} += $form->{89};
665 $form->{98} += $form->{891};
666 map { delete $form->{$_} } qw(81 811 89 891);
668 $form->{35} += $form->{51};
669 $form->{36} += $form->{511};
670 $form->{95} += $form->{97};
671 $form->{98} += $form->{971};
672 map { delete $form->{$_} } qw(51 511 97 971);
678 # Fixme: Wird auch noch für Oesterreich gebraucht,
679 # weil kein eigenes Ausgabeformular
680 # sotte aber aus der allgeméinen Steuerberechnung verschwinden
682 # Berechnung der USTVA Formularfelder laut Bogen 207
685 $form->{"51r"} = $form->{"511"};
686 $form->{"86r"} = $form->{"861"};
687 $form->{"97r"} = $form->{"971"};
688 $form->{"93r"} = $form->{"931"};
690 $form->{"Z43"} = $form->{"511"} + $form->{"811"} + $form->{"861"}
691 + $form->{"36"} + $form->{"80"} + $form->{"971"}
692 + $form->{"891"} + $form->{"931"} + $form->{"96"}
695 $form->{"Z45"} = $form->{"Z43"};
697 $form->{"Z53"} = $form->{"Z45"} + $form->{"47"} + $form->{"53"} + $form->{"74"}
698 + $form->{"85"} + $form->{"65"};
700 $form->{"Z62"} = $form->{"Z53"} - $form->{"66"} - $form->{"61"}
701 - $form->{"62"} - $form->{"67"} - $form->{"63"}
702 - $form->{"64"} - $form->{"59"};
704 $form->{"Z65"} = $form->{"Z62"} - $form->{"69"};
705 $form->{"83"} = $form->{"Z65"} - $form->{"39"};
707 $main::lxdebug->leave_sub();
710 sub get_accounts_ustva {
711 $main::lxdebug->enter_sub();
713 my ($dbh, $last_period, $fromdate, $todate, $form, $category) = @_;
725 my $gltaxkey_where = "((tk.pos_ustva = 46) OR (tk.pos_ustva>=59 AND tk.pos_ustva<=67) or (tk.pos_ustva>=89 AND tk.pos_ustva<=93))";
728 if ($form->{accounting_method} eq 'cash') {
729 $subwhere .= " AND transdate >= '$fromdate'";
730 $glwhere = " AND ac.transdate >= '$fromdate'";
731 $ARwhere .= " AND acc.transdate >= '$fromdate'";
733 $APwhere .= " AND AP.transdate >= '$fromdate'";
734 $where .= " AND ac.transdate >= '$fromdate'";
738 $where .= " AND ac.transdate <= '$todate'";
739 $ARwhere .= " AND acc.transdate <= '$todate'";
742 my $acc_trans_where = '1=1';
743 if ($fromdate || $todate) {
744 $acc_trans_where = "ac.trans_id IN (SELECT DISTINCT trans_id FROM acc_trans WHERE ";
747 $acc_trans_where .= "transdate >= '$fromdate'";
750 $acc_trans_where .= " AND " if ($fromdate);
751 $acc_trans_where .= "transdate <= '$todate'";
754 $acc_trans_where .= ")";
757 ############################################
758 # Method eq 'cash' = IST Versteuerung
759 ############################################
760 # Betrifft nur die eingenommene Umsatzsteuer
762 ############################################
764 if ($form->{accounting_method} eq 'cash') {
768 -- USTVA IST-Versteuerung
770 -- Alle tatsaechlichen _Zahlungseingaenge_
771 -- im Voranmeldezeitraum erfassen
772 -- (Teilzahlungen werden prozentual auf verschiedene Steuern aufgeteilt)
774 -- Bezahlt / Rechnungssumme
776 SELECT SUM(acc.amount)
778 INNER JOIN chart c ON (acc.chart_id = c.id
779 AND c.link like '%AR_paid%')
783 AND acc.trans_id = ac.trans_id
787 SELECT amount FROM ar WHERE id = ac.trans_id
792 LEFT JOIN chart c ON (c.id = ac.chart_id)
793 LEFT JOIN ar ON (ar.id = ac.trans_id)
794 LEFT JOIN taxkeys tk ON (
796 SELECT id FROM taxkeys
797 WHERE chart_id = ac.chart_id
798 -- AND taxkey_id = ac.taxkey
799 AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
800 ORDER BY startdate DESC LIMIT 1
805 GROUP BY tk.pos_ustva
808 } elsif ($form->{accounting_method} eq 'accrual') {
809 #########################################
810 # Method eq 'accrual' = Soll Versteuerung
811 #########################################
814 -- Alle Einnahmen AR und pos_ustva erfassen
816 - sum(ac.amount) AS amount,
819 JOIN chart c ON (c.id = ac.chart_id)
820 JOIN ar ON (ar.id = ac.trans_id)
823 SELECT id FROM taxkeys
824 WHERE chart_id = ac.chart_id
825 AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
826 ORDER BY startdate DESC LIMIT 1
832 GROUP BY tk.pos_ustva
837 $form->error("Unknown tax method: $form->{accounting_method}")
841 #########################################
842 # Ausgaben und Gl Buchungen sind gleich
843 # für Ist- und Soll-Versteuerung
844 #########################################
846 UNION -- alle Ausgaben AP erfassen
849 sum(ac.amount) AS amount,
852 JOIN ap ON (ap.id = ac.trans_id )
853 JOIN chart c ON (c.id = ac.chart_id)
854 LEFT JOIN taxkeys tk ON (
856 SELECT id FROM taxkeys
858 AND chart_id=ac.chart_id
859 --AND taxkey_id = ac.taxkey
860 AND startdate <= COALESCE(AP.transdate)
861 ORDER BY startdate DESC LIMIT 1
867 GROUP BY tk.pos_ustva
869 UNION -- Einnahmen direkter gl Buchungen erfassen
872 ( - ac.amount) AS amount,
875 JOIN chart c ON (c.id = ac.chart_id)
876 JOIN gl a ON (a.id = ac.trans_id)
877 LEFT JOIN taxkeys tk ON (
879 SELECT id FROM taxkeys
880 WHERE chart_id=ac.chart_id
881 AND NOT $gltaxkey_where
882 AND startdate <= COALESCE(ac.transdate)
883 ORDER BY startdate DESC LIMIT 1
890 GROUP BY tk.pos_ustva
893 UNION -- Ausgaben direkter gl Buchungen erfassen
896 (ac.amount) AS amount,
899 JOIN chart c ON (c.id = ac.chart_id)
900 JOIN gl a ON (a.id = ac.trans_id)
901 LEFT JOIN taxkeys tk ON (
903 SELECT id FROM taxkeys
904 WHERE chart_id=ac.chart_id
906 AND startdate <= COALESCE(ac.transdate)
907 ORDER BY startdate DESC LIMIT 1
914 GROUP BY tk.pos_ustva
922 # Show all $query in Debuglevel LXDebug::QUERY
923 my $callingdetails = (caller (0))[3];
924 $main::lxdebug->message(LXDebug->QUERY(), "$callingdetails \$query=\n $query");
926 my $sth = $dbh->prepare($query);
928 $sth->execute || $form->dberror($query);
930 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
932 $ref->{amount} *= -1;
933 $form->{ $ref->{$category} } += $ref->{amount};
938 $main::lxdebug->leave_sub();
943 $main::lxdebug->enter_sub();
945 my ($self, $form) = @_;
947 # init some form vars
948 my @anmeldungszeitraum =
949 qw('0401' '0402' '0403'
953 '0441' '0442' '0443' '0444');
955 foreach my $item (@anmeldungszeitraum) {
959 #forgotten the year --> thisyear
960 if ($form->{year} !~ m/^\d\d\d\d$/) {
961 $form->{year} = substr(
963 $form->current_date(\%::myconfig), \%::myconfig
966 $::lxdebug->message(LXDebug->DEBUG1,
967 qq|Actual year from Database: $form->{year}\n|);
971 # using dates in ISO-8601 format: yyyymmmdd for Postgres...
975 if ($form->{period} eq "13") {
976 $form->{fromdate} = "$form->{year}0101";
977 $form->{todate} = "$form->{year}1231";
981 if ($form->{period} eq "41") {
982 $form->{fromdate} = "$form->{year}0101";
983 $form->{todate} = "$form->{year}0331";
984 $form->{'0441'} = "X";
986 if ($form->{period} eq "42") {
987 $form->{fromdate} = "$form->{year}0401";
988 $form->{todate} = "$form->{year}0630";
989 $form->{'0442'} = "X";
991 if ($form->{period} eq "43") {
992 $form->{fromdate} = "$form->{year}0701";
993 $form->{todate} = "$form->{year}0930";
994 $form->{'0443'} = "X";
996 if ($form->{period} eq "44") {
997 $form->{fromdate} = "$form->{year}1001";
998 $form->{todate} = "$form->{year}1231";
999 $form->{'0444'} = "X";
1004 $form->{period} eq "01" && do {
1005 $form->{fromdate} = "$form->{year}0101";
1006 $form->{todate} = "$form->{year}0131";
1007 $form->{'0401'} = "X";
1010 $form->{period} eq "02" && do {
1011 $form->{fromdate} = "$form->{year}0201";
1013 #this works from 1901 to 2099, 1900 and 2100 fail.
1014 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
1015 $form->{todate} = "$form->{year}02$leap";
1016 $form->{"0402"} = "X";
1019 $form->{period} eq "03" && do {
1020 $form->{fromdate} = "$form->{year}0301";
1021 $form->{todate} = "$form->{year}0331";
1022 $form->{"0403"} = "X";
1025 $form->{period} eq "04" && do {
1026 $form->{fromdate} = "$form->{year}0401";
1027 $form->{todate} = "$form->{year}0430";
1028 $form->{"0404"} = "X";
1031 $form->{period} eq "05" && do {
1032 $form->{fromdate} = "$form->{year}0501";
1033 $form->{todate} = "$form->{year}0531";
1034 $form->{"0405"} = "X";
1037 $form->{period} eq "06" && do {
1038 $form->{fromdate} = "$form->{year}0601";
1039 $form->{todate} = "$form->{year}0630";
1040 $form->{"0406"} = "X";
1043 $form->{period} eq "07" && do {
1044 $form->{fromdate} = "$form->{year}0701";
1045 $form->{todate} = "$form->{year}0731";
1046 $form->{"0407"} = "X";
1049 $form->{period} eq "08" && do {
1050 $form->{fromdate} = "$form->{year}0801";
1051 $form->{todate} = "$form->{year}0831";
1052 $form->{"0408"} = "X";
1055 $form->{period} eq "09" && do {
1056 $form->{fromdate} = "$form->{year}0901";
1057 $form->{todate} = "$form->{year}0930";
1058 $form->{"0409"} = "X";
1061 $form->{period} eq "10" && do {
1062 $form->{fromdate} = "$form->{year}1001";
1063 $form->{todate} = "$form->{year}1031";
1064 $form->{"0410"} = "X";
1067 $form->{period} eq "11" && do {
1068 $form->{fromdate} = "$form->{year}1101";
1069 $form->{todate} = "$form->{year}1130";
1070 $form->{"0411"} = "X";
1073 $form->{period} eq "12" && do {
1074 $form->{fromdate} = "$form->{year}1201";
1075 $form->{todate} = "$form->{year}1231";
1076 $form->{"0412"} = "X";
1081 # Kontrollvariablen für die Templates
1082 $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
1084 $main::lxdebug->leave_sub();
1087 sub get_fiamt_vars {
1088 return @fiamt_finanzamt;
1092 $main::lxdebug->enter_sub();
1096 'steuernummer' => 'taxnumber',
1097 'elsterFFFF' => 'fa_bufa_nr',
1098 'FA_dauerfrist' => 'fa_dauerfrist',
1099 'FA_steuerberater_city' => 'fa_steuerberater_city',
1100 'FA_steuerberater_name' => 'fa_steuerberater_name',
1101 'FA_steuerberater_street' => 'fa_steuerberater_street',
1102 'FA_steuerberater_tel' => 'fa_steuerberater_tel',
1103 'FA_voranmeld' => 'fa_voranmeld',
1106 my $filename = $::lx_office_conf{paths}{userspath}."/finanzamt.ini";
1108 return unless (open( $FACONF, "<", $filename));
1112 next if (/^(\#|\s)/);
1117 # remove any trailing whitespace
1118 s/^\s*(.*?)\s*$/$1/;
1119 my ($key, $value) = split(/=/, $_, 2);
1121 $main::lxdebug->message(LXDebug->DEBUG2(), "oldkey: ".$key." val=".$value." newkey=".
1122 $oldkeys{$key}." oval=".$::form->{$oldkeys{$key}});
1123 if ( $oldkeys{$key} && $::form->{$oldkeys{$key}} eq '' ) {
1124 $::form->{$oldkeys{$key}} = $::locale->{iconv_utf8}->convert($value);
1125 $main::lxdebug->message(LXDebug->DEBUG2(), "set ".$oldkeys{$key}."=".$::form->{$oldkeys{$key}});
1129 $main::lxdebug->leave_sub();
1134 $main::lxdebug->enter_sub();
1135 my $defaults = SL::DB::Default->get;
1136 my @rd_config = @fiamt_config;
1137 push @rd_config ,qw(accounting_method coa company address co_ustid duns);
1138 $::form->{$_} = $defaults->$_ for @rd_config;
1140 if ( $::form->{taxnumber} eq '' || $::form->{fa_bufa_nr} eq '') {
1141 #alte finanzamt.ini lesen, ggf abspeichern
1142 if ( get_oldconfig() ) {
1148 my $coa = $::form->{coa};
1149 $::form->{"COA_$coa"} = '1';
1150 $::form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
1151 $main::lxdebug->leave_sub();
1155 $main::lxdebug->enter_sub();
1156 if ( $::form->{fa_bufa_nr} && $::form->{fa_bufa_nr} ne '' ) {
1157 my $fiamt = SL::DB::Finanzamt->_get_manager_class->get_first(
1158 query => [ fa_bufa_nr => $::form->{fa_bufa_nr} ]);
1159 $::form->{$_} = $fiamt->$_ for @fiamt_finanzamt;
1161 $main::lxdebug->leave_sub();
1165 $main::lxdebug->enter_sub();
1166 my $defaults = SL::DB::Default->get;
1167 $defaults->$_($::form->{$_}) for @fiamt_config;
1169 if ( $defaults->fa_bufa_nr ) {
1170 my $fiamt = SL::DB::Finanzamt->_get_manager_class->get_first(
1171 query => [ fa_bufa_nr => $defaults->fa_bufa_nr ]);
1172 $fiamt->$_($::form->{$_}) for @fiamt_finanzamt;
1175 $main::lxdebug->leave_sub();