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 #=====================================================================
30 use List::Util qw(first);
35 use SL::DB::Finanzamt;
40 my @tax_office_information = (
41 { 'id' => 8, 'name' => 'Baden-Württemberg', 'taxbird_nr' => '1', 'elster_format' => 'FFBBB/UUUUP', },
42 { 'id' => 9, 'name' => 'Bayern', 'taxbird_nr' => '2', 'elster_format' => 'FFF/BBB/UUUUP', },
43 { 'id' => 11, 'name' => 'Berlin', 'taxbird_nr' => '3', 'elster_format' => 'FF/BBB/UUUUP', },
44 { 'id' => 12, 'name' => 'Brandenburg', 'taxbird_nr' => '4', 'elster_format' => 'FFF/BBB/UUUUP', },
45 { 'id' => 4, 'name' => 'Bremen', 'taxbird_nr' => '5', 'elster_format' => 'FF BBB UUUUP', },
46 { 'id' => 2, 'name' => 'Hamburg', 'taxbird_nr' => '6', 'elster_format' => 'FF/BBB/UUUUP', },
47 { 'id' => 6, 'name' => 'Hessen', 'taxbird_nr' => '7', 'elster_format' => '0FF BBB UUUUP', },
48 { 'id' => 13, 'name' => 'Mecklenburg-Vorpommern', 'taxbird_nr' => '8', 'elster_format' => 'FFF/BBB/UUUUP', },
49 { 'id' => 3, 'name' => 'Niedersachsen', 'taxbird_nr' => '9', 'elster_format' => 'FF/BBB/UUUUP', },
50 { 'id' => 5, 'name' => 'Nordrhein-Westfalen', 'taxbird_nr' => '10', 'elster_format' => 'FFF/BBBB/UUUP', },
51 { 'id' => 7, 'name' => 'Rheinland-Pfalz', 'taxbird_nr' => '11', 'elster_format' => 'FF/BBB/UUUUP', },
52 { 'id' => 10, 'name' => 'Saarland', 'taxbird_nr' => '12', 'elster_format' => 'FFF/BBB/UUUUP', },
53 { 'id' => 14, 'name' => 'Sachsen', 'taxbird_nr' => '13', 'elster_format' => 'FFF/BBB/UUUUP', },
54 { 'id' => 15, 'name' => 'Sachsen-Anhalt', 'taxbird_nr' => '14', 'elster_format' => 'FFF/BBB/UUUUP', },
55 { 'id' => 1, 'name' => 'Schleswig-Holstein', 'taxbird_nr' => '15', 'elster_format' => 'FF BBB UUUUP', },
56 { 'id' => 16, 'name' => 'Thüringen', 'taxbird_nr' => '16', 'elster_format' => 'FFF/BBB/UUUUP', },
59 my @fiamt_config = qw(taxnumber fa_bufa_nr fa_dauerfrist fa_steuerberater_city fa_steuerberater_name
60 fa_steuerberater_street fa_steuerberater_tel fa_voranmeld);
62 my @fiamt_finanzamt = qw(
63 fa_land_nr fa_bufa_nr fa_name fa_strasse
64 fa_plz fa_ort fa_telefon fa_fax
65 fa_plz_grosskunden fa_plz_postfach fa_postfach
66 fa_blz_1 fa_kontonummer_1 fa_bankbezeichnung_1
67 fa_blz_2 fa_kontonummer_2 fa_bankbezeichnung_2 fa_oeffnungszeiten
68 fa_email fa_internet);
86 $self->{tax_office_information} = [];
88 foreach (@tax_office_information) {
90 $entry->{name} = $::locale->{iconv_utf8}->convert($entry->{name});
91 push @{ $self->{tax_office_information} }, $entry;
97 my ( $self, $form ) = @_;
99 my $coa = $::instance_conf->get_coa;
101 $form->{"COA_$coa"} = '1';
102 $form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
108 sub report_variables {
109 # Get all positions for taxreport out of the database
110 # Needs Databaseupdate Pg-upgrade2/USTVA_abstraction.pl
115 my $myconfig = $arg_ref->{myconfig};
116 my $form = $arg_ref->{form};
117 my $type = $arg_ref->{type}; # 'paied' || 'received' || ''
118 my $attribute = $arg_ref->{attribute}; #
119 my $dec_places = (defined $arg_ref->{dec_places}) ? $arg_ref->{dec_places}:undef;
121 my $where_type = $type ? "AND tax.report_headings.type = '$type'" : '';
122 my $where_dcp = defined $dec_places ? "AND tax.report_variables.dec_places = '$dec_places'" : '';
126 FROM tax.report_variables
127 LEFT JOIN tax.report_headings
128 ON (tax.report_variables.heading_id = tax.report_headings.id)
136 SL::DB->client->with_transaction(sub {
137 my $dbh = SL::DB->client->dbh;
138 my $sth = $dbh->prepare($query);
140 $sth->execute() || $form->dberror($query);
142 while ( my $row_ref = $sth->fetchrow_arrayref() ) {
143 push @positions, @$row_ref; # Copy the array contents
148 }) or do { die SL::DB->client->error };
154 sub steuernummer_input {
155 $main::lxdebug->enter_sub();
157 my ($self, $elsterland, $elsterFFFF, $steuernummer) = @_;
158 our ($elster_FFFF, $elster_land);
160 my $steuernummer_input = '';
162 $elster_land = $elsterland;
163 $elster_FFFF = $elsterFFFF;
164 $steuernummer = '0000000000' if ($steuernummer eq '');
166 # $steuernummer formatieren (nur Zahlen) -> $stnr
167 my $stnr = $steuernummer;
170 #Pattern description Elstersteuernummer
173 my $tax_office = first { $_->{id} eq $elster_land } @{ $self->{tax_office_information} };
174 my $elster_pattern = $tax_office->{elster_format};
175 # $::lxdebug->message(LXDebug->DEBUG2, "stnr=".$stnr." elster_FFFF=".$elster_FFFF.
176 # " pattern=".$elster_pattern." land=".$elster_land);
177 my @elster_pattern = split(' ', $elster_pattern);
178 my $delimiter1 = ' ';
179 my $delimiter2 = ' ';
180 my $patterncount = @elster_pattern;
181 if ($patterncount < 2) {
182 @elster_pattern = ();
183 @elster_pattern = split('/', $elster_pattern);
186 $patterncount = @elster_pattern;
187 if ($patterncount < 2) {
188 @elster_pattern = ();
189 @elster_pattern = split(' ', $elster_pattern);
192 $patterncount = @elster_pattern;
196 # no we have an array of patternparts and a delimiter
197 # create the first automated and fixed part and delimiter
199 $steuernummer_input .= qq|<b><font size="+1">|;
201 # $::lxdebug->message(LXDebug->DEBUG2, "pattern0=".$elster_pattern[0]);
203 $elster_pattern[0] eq 'FFF' && do {
204 $part = substr($elster_FFFF, 1, 4);
205 $steuernummer_input .= qq|$part|;
208 $elster_pattern[0] eq '0FF' && do {
209 $part = '0' . substr($elster_FFFF, 2, 4);
210 $steuernummer_input .= qq|$part|;
213 $elster_pattern[0] eq 'FFBBB' && do {
214 $part = substr($elster_FFFF, 2, 4);
215 $steuernummer_input .= qq|$part|;
219 @elster_pattern = ('FF','BBB','UUUUP');
222 $elster_pattern[0] eq 'FF' && do {
223 $part = substr($elster_FFFF, 2, 4);
224 $steuernummer_input .= qq|$part|;
228 $steuernummer_input .= qq|Fehler!|;
233 #now the rest of the Steuernummer ...
234 $steuernummer_input .= qq|</font></b>|;
235 $steuernummer_input .= qq|\n
236 <input type=hidden name="elster_pattern" value="$elster_pattern">
237 <input type=hidden name="patterncount" value="$patterncount">
238 <input type=hidden name="patternlength" value="$patterncount">
239 <input type=hidden name="delimiter1" value="$delimiter1">
240 <input type=hidden name="delimiter2" value="$delimiter2">
241 <input type=hidden name="part" value="$part">
246 for (my $h = 1; $h < $patterncount; $h++) {
247 my $delimiter = ( $h==1?$delimiter1:$delimiter2);
248 $steuernummer_input .= qq| $delimiter \n|;
249 # $::lxdebug->message(LXDebug->DEBUG2, "pattern[$h]=".$elster_pattern[$h]);
250 for (my $i = 1; $i <= length($elster_pattern[$h]); $i++) {
251 $steuernummer_input .= qq|<select name="part_$h\_$i">\n|;
253 for (my $j = 0; $j <= 9; $j++) {
254 $steuernummer_input .= qq| <option value="$j"|;
255 if ($steuernummer ne '') {
256 if ($j eq substr($stnr, length($part) + $k, 1)) {
257 $steuernummer_input .= qq| selected|;
260 $steuernummer_input .= qq|>$j</option>\n|;
263 $steuernummer_input .= qq|</select>\n|;
267 $main::lxdebug->leave_sub();
269 return $steuernummer_input;
273 $main::lxdebug->enter_sub();
275 # Referenz wird übergeben, hash of hash wird nicht
276 # in neues Hash kopiert, sondern direkt über die Referenz verändert
277 # Prototyp für diese Konstruktion
279 my ($self, $land, $elsterFFFF, $elster_init) = @_;
281 # $::lxdebug->message(LXDebug->DEBUG2,"land=".$land." amt=".$elsterFFFF);
283 my $FFFF = $elsterFFFF;
286 $checked = 'checked' if ($elsterFFFF eq '' and $land eq '');
288 my %elster_land_name = ();
291 <script language="Javascript">
292 function update_auswahl()
294 var elsterBLAuswahl = document.verzeichnis.fa_land_nr_new;
295 var elsterFAAuswahl = document.verzeichnis.fa_bufa_nr_new;
297 elsterFAAuswahl.options.length = 0; // dropdown aufräumen
300 foreach my $elster_land (sort keys %$elster_init) {
302 if (elsterBLAuswahl.options[elsterBLAuswahl.selectedIndex].value == "$elster_land")
306 %elster_land_fa = ();
308 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
309 if ( $FFFF eq 'name' ) {
310 $elster_land_name{$elster_land} = $elster_init->{$elster_land}{$FFFF};
311 delete $elster_init->{$elster_land}{$FFFF};
313 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}{$FFFF}->fa_name;
316 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
317 keys(%elster_land_fa)
320 elsterFAAuswahl.options[$j] = new Option("$elster_land_fa{$ffff} ($ffff)","$ffff");|;
336 <select size="1" name="fa_land_nr_new" onchange="update_auswahl()">|;
338 $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select federal state...') . qq|</option>\n|;
340 foreach my $elster_land (sort keys %$elster_init) {
342 <option value="$elster_land"|;
343 # $::lxdebug->message(LXDebug->DEBUG2,"land=".$land." elster_land=".$elster_land." lname=".$elster_land_name{$elster_land});
344 if ($elster_land eq $land and $checked eq '') {
345 $fa_auswahl .= qq| selected|;
347 $fa_auswahl .= qq|>$elster_land_name{$elster_land}</option>
356 my $elster_land = '';
357 $elster_land = ($land ne '') ? $land : '';
358 %elster_land_fa = ();
359 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
360 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}{$FFFF}->fa_name;
368 <select size="1" name="fa_bufa_nr_new">|;
369 if ($elsterFFFF eq '') {
370 $fa_auswahl .= qq|<option value="Auswahl" $checked>| . $main::locale->text('Select tax office...') . qq|</option>|;
372 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
373 keys(%elster_land_fa)
377 <option value="$ffff"|;
378 if ($ffff eq $elsterFFFF and $checked eq '') {
379 $fa_auswahl .= qq| selected|;
381 $fa_auswahl .= qq|>$elster_land_fa{$ffff} ($ffff)</option>|;
390 $main::lxdebug->leave_sub();
396 $main::lxdebug->enter_sub();
400 if ($ENV{HTTP_USER_AGENT}) {
403 print qq|<body><h2 class=info>Hinweis</h2>
409 <input type=button value="| . $main::locale->text('Back') . qq|" onClick="history.go(-1)">
413 $::dispatcher->end_request;
417 die "Hinweis: $msg\n";
420 $main::lxdebug->leave_sub();
423 sub query_finanzamt {
424 $main::lxdebug->enter_sub();
426 my ($self, $myconfig, $form) = @_;
428 my $dbh = SL::DB->client->dbh;
430 #Test, if table finanzamt exist
431 my $table = 'finanzamt';
432 my $filename = "sql/$table.sql";
434 my $tst = $dbh->prepare("SELECT * FROM $table");
435 $tst->execute || do {
436 #There is no table, read the table from sql/finanzamt.sql
437 print qq|<p>Bitte warten, Tabelle $table wird einmalig in Datenbank:
438 $myconfig->{dbname} als Benutzer: $myconfig->{dbuser} hinzugefügt...</p>|;
439 SL::DB->client->with_transaction(sub {
440 process_query($form, $dbh, $filename) || $self->error(DBI->errstr);
442 }) or do { die SL::DB->client->error };
447 my $fiamt = SL::DB::Finanzamt->_get_manager_class->get_all(sort => 'fa_land_nr');
450 foreach my $row (@$fiamt) {
451 my $tax_office = first { $_->{id} == $row->fa_land_nr } @{ $self->{tax_office_information} };
452 $land = $tax_office->{id};
453 $finanzamt{$land}{$row->fa_bufa_nr} = $row;
454 $finanzamt{$land}{'name'} ||= $tax_office->{name};
456 $main::lxdebug->leave_sub();
462 $main::lxdebug->enter_sub();
464 my ($form, $dbh, $filename) = @_;
466 open my $FH, "<", "$filename" or $form->error("$filename : $!\n");
473 # Remove DOS and Unix style line endings.
476 # don't add comments or empty lines
477 next if /^(--.*|\s+)$/;
479 for (my $i = 0; $i < length($_); $i++) {
480 my $char = substr($_, $i, 1);
482 # Are we inside a string?
484 if ($char eq $quote_chars[-1]) {
490 if (($char eq "'") || ($char eq "\"")) {
491 push(@quote_chars, $char);
493 } elsif ($char eq ";") {
495 # Query is complete. Send it.
497 $sth = $dbh->prepare($query);
498 $sth->execute || $form->dberror($query);
512 $main::lxdebug->leave_sub();
516 $main::lxdebug->enter_sub();
518 my ($self, $myconfig, $form) = @_;
520 my $dbh = SL::DB->client->dbh;
523 my $category = "pos_ustva";
525 $form->{coa} = $::instance_conf->get_coa;
527 unless ($form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
528 croak t8("Advance turnover tax return only valid for SKR03 or SKR04");
530 my @category_cent = USTVA->report_variables({
531 myconfig => $myconfig,
534 attribute => 'position',
537 push @category_cent, ("pos_ustva_811b_kivi", "pos_ustva_861b_kivi");
538 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
539 push @category_cent, qw(Z43 Z45 Z53 Z54 Z62 Z65 Z67);
541 my @category_euro = USTVA->report_variables({
542 myconfig => $myconfig,
545 attribute => 'position',
548 push @category_euro, ("pos_ustva_81b_kivi", "pos_ustva_86b_kivi");
549 @{$form->{category_cent}} = @category_cent;
550 @{$form->{category_euro}} = @category_euro;
551 $form->{decimalplaces} *= 1;
553 foreach my $item (@category_cent) {
554 $form->{"$item"} = 0;
556 foreach my $item (@category_euro) {
557 $form->{"$item"} = 0;
560 # Controlvariable for templates
561 my $coa_name = $form->{coa};
562 $form->{"$coa_name"} = '1';
564 &get_accounts_ustva($dbh, $last_period, $form->{fromdate}, $form->{todate},
567 ###########################################
569 # Nationspecific Modfications
571 ###########################################
575 if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') {
578 # Umordnen der Kennziffern
579 if ( $form->{year} < 2007) {
580 $form->{35} += $form->{81};
581 $form->{36} += $form->{811};
582 $form->{95} += $form->{89};
583 $form->{98} += $form->{891};
584 map { delete $form->{$_} } qw(81 811 89 891);
586 $form->{35} += $form->{51};
587 $form->{36} += $form->{511};
588 $form->{95} += $form->{97};
589 $form->{98} += $form->{971};
590 map { delete $form->{$_} } qw(51 511 97 971);
596 # Fixme: Wird auch noch für Oesterreich gebraucht,
597 # weil kein eigenes Ausgabeformular
598 # sollte aber aus der allgemeinen Steuerberechnung verschwinden
600 # Berechnung der USTVA Formularfelder laut Bogen 207
603 $form->{"51r"} = $form->{"511"};
604 $form->{"86r"} = $form->{"861"};
605 $form->{"97r"} = $form->{"971"};
606 $form->{"93r"} = $form->{"931"};
608 $form->{"Z43"} = $form->{"511"} + $form->{"811"} + $form->{"861"}
609 + $form->{"36"} + $form->{"80"} + $form->{"971"}
610 + $form->{"891"} + $form->{"931"} + $form->{"96"}
613 $form->{"Z45"} = $form->{"Z43"};
615 $form->{"Z53"} = $form->{"Z45"} + $form->{"47"} + $form->{"53"} + $form->{"74"}
616 + $form->{"85"} + $form->{"65"};
618 $form->{"Z62"} = $form->{"Z53"} - $form->{"66"} - $form->{"61"}
619 - $form->{"62"} - $form->{"67"} - $form->{"63"}
620 - $form->{"64"} - $form->{"59"};
622 $form->{"Z65"} = $form->{"Z62"} - $form->{"69"};
623 $form->{"83"} = $form->{"Z65"} - $form->{"39"};
625 $main::lxdebug->leave_sub();
628 sub get_accounts_ustva {
629 $main::lxdebug->enter_sub();
631 my ($dbh, $last_period, $fromdate, $todate, $form, $category) = @_;
643 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))";
646 if ($form->{accounting_method} eq 'cash') {
647 $subwhere .= " AND transdate >= '$fromdate'";
648 $glwhere = " AND ac.transdate >= '$fromdate'";
649 $ARwhere .= " AND acc.transdate >= '$fromdate'";
651 $APwhere .= " AND AP.transdate >= '$fromdate'";
652 $where .= " AND ac.transdate >= '$fromdate'";
656 $where .= " AND ac.transdate <= '$todate'";
657 $ARwhere .= " AND acc.transdate <= '$todate'";
660 my $acc_trans_where = '1=1';
661 if ($fromdate || $todate) {
662 $acc_trans_where = "ac.trans_id IN (SELECT DISTINCT trans_id FROM acc_trans WHERE ";
665 $acc_trans_where .= "transdate >= '$fromdate'";
668 $acc_trans_where .= " AND " if ($fromdate);
669 $acc_trans_where .= "transdate <= '$todate'";
672 $acc_trans_where .= ")";
675 ############################################
676 # Method eq 'cash' = IST Versteuerung
677 ############################################
678 # Betrifft nur die eingenommene Umsatzsteuer
680 ############################################
682 if ($form->{accounting_method} eq 'cash') {
686 -- USTVA IST-Versteuerung
688 -- Alle tatsaechlichen _Zahlungseingaenge_
689 -- im Voranmeldezeitraum erfassen
690 -- (Teilzahlungen werden prozentual auf verschiedene Steuern aufgeteilt)
692 -- Bezahlt / Rechnungssumme
694 SELECT SUM(acc.amount), t.rate, c.accno
696 INNER JOIN chart c ON (acc.chart_id = c.id
697 AND c.link like '%AR_paid%')
701 AND acc.trans_id = ac.trans_id
705 SELECT amount FROM ar WHERE id = ac.trans_id
710 LEFT JOIN chart c ON (c.id = ac.chart_id)
711 LEFT JOIN ar ON (ar.id = ac.trans_id)
712 LEFT JOIN tax t ON (t.id = ac.tax_id)
713 LEFT JOIN taxkeys tk ON (
715 SELECT id FROM taxkeys
716 WHERE chart_id = ac.chart_id
717 -- AND taxkey_id = ac.taxkey
718 AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
719 ORDER BY startdate DESC LIMIT 1
724 GROUP BY tk.pos_ustva, t.rate, c.accno
727 } elsif ($form->{accounting_method} eq 'accrual') {
728 #########################################
729 # Method eq 'accrual' = Soll Versteuerung
730 #########################################
733 -- Alle Einnahmen AR und pos_ustva erfassen
735 - sum(ac.amount) AS amount,
736 tk.pos_ustva, t.rate, c.accno
738 JOIN chart c ON (c.id = ac.chart_id)
739 JOIN ar ON (ar.id = ac.trans_id)
740 JOIN tax t ON (t.id = ac.tax_id)
743 SELECT id FROM taxkeys
744 WHERE chart_id = ac.chart_id
745 AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
746 ORDER BY startdate DESC LIMIT 1
752 GROUP BY tk.pos_ustva, t.rate, c.accno
757 $form->error("Unknown tax method: $form->{accounting_method}")
761 #########################################
762 # Ausgaben und Gl Buchungen sind gleich
763 # für Ist- und Soll-Versteuerung
764 #########################################
766 UNION -- alle Ausgaben AP erfassen
769 sum(ac.amount) AS amount,
770 tk.pos_ustva, t.rate, c.accno
772 JOIN ap ON (ap.id = ac.trans_id )
773 JOIN chart c ON (c.id = ac.chart_id)
774 JOIN tax t ON (t.id = ac.tax_id)
775 LEFT JOIN taxkeys tk ON (
777 SELECT id FROM taxkeys
779 AND chart_id=ac.chart_id
780 --AND taxkey_id = ac.taxkey
781 AND startdate <= COALESCE(AP.transdate)
782 ORDER BY startdate DESC LIMIT 1
788 GROUP BY tk.pos_ustva, t.rate, c.accno
790 UNION -- Einnahmen direkter gl Buchungen erfassen
793 ( - ac.amount) AS amount,
794 tk.pos_ustva, t.rate, c.accno
796 JOIN chart c ON (c.id = ac.chart_id)
797 JOIN gl a ON (a.id = ac.trans_id)
798 JOIN tax t ON (t.id = ac.tax_id)
799 LEFT JOIN taxkeys tk ON (
801 SELECT id FROM taxkeys
802 WHERE chart_id=ac.chart_id
803 AND NOT $gltaxkey_where
804 AND startdate <= COALESCE(ac.transdate)
805 ORDER BY startdate DESC LIMIT 1
812 GROUP BY tk.pos_ustva, t.rate, c.accno
815 UNION -- Ausgaben direkter gl Buchungen erfassen
818 (ac.amount) AS amount,
819 tk.pos_ustva, t.rate, c.accno
821 JOIN chart c ON (c.id = ac.chart_id)
822 JOIN gl a ON (a.id = ac.trans_id)
823 JOIN tax t ON (t.id = ac.tax_id)
824 LEFT JOIN taxkeys tk ON (
826 SELECT id FROM taxkeys
827 WHERE chart_id=ac.chart_id
829 AND startdate <= COALESCE(ac.transdate)
830 ORDER BY startdate DESC LIMIT 1
837 GROUP BY tk.pos_ustva, t.rate, c.accno
841 # Show all $query in Debuglevel LXDebug::QUERY
842 my $callingdetails = (caller (0))[3];
843 $main::lxdebug->message(LXDebug->QUERY(), "$callingdetails \$query=\n $query");
845 my $sth = $dbh->prepare($query);
847 $sth->execute || $form->dberror($query);
848 # ugly, but we need to use static accnos
849 my ($accno_five, $accno_sixteen, $corr);
851 if ($form->{coa} eq 'Germany-DATEV-SKR03EU') {
853 $accno_sixteen = 1775;
854 } elsif (($form->{coa} eq 'Germany-DATEV-SKR04EU')) {
855 $accno_five = 3803; # SKR04
856 $accno_sixteen = 3805; # SKR04
857 } else {die "wrong call"; }
859 while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
860 next unless $ref->{$category};
862 $ref->{amount} *= -1;
864 if ($ref->{pos_ustva} eq '35') {
865 if ($ref->{rate} == 0.16) {
866 $form->{"pos_ustva_81b_kivi"} += $ref->{amount};
867 } elsif ($ref->{rate} == 0.05) {
868 $form->{"pos_ustva_86b_kivi"} += $ref->{amount};
869 } elsif ($ref->{rate} == 0.19) {
870 # pos_ustva says 16, but rate says 19
871 # (pos_ustva should be tax dependant and not taxkeys dependant)
872 # correction hotfix for this case:
873 # bookings exists with 19% ->
874 # move 19% bookings to the 19% position
875 # Dont rely on dates of taxkeys
877 $form->{"81"} += $ref->{amount};
878 } else {die ("No valid tax rate for pos 35" . Dumper($ref)); }
880 # USTVA Pos 36 (Steuerkonten)
881 if ($ref->{pos_ustva} eq '36') {
882 if ($ref->{accno} =~ /^$accno_sixteen/) {
883 $form->{"pos_ustva_811b_kivi"} += $ref->{amount};
884 } elsif ($ref->{accno} =~ /^$accno_five/) {
885 $form->{"pos_ustva_861b_kivi"} += $ref->{amount};
886 } else { die ("No valid accno for pos 36" . Dumper($ref)); }
888 $form->{ $ref->{$category} } += $ref->{amount} unless $corr;
893 $main::lxdebug->leave_sub();
898 $main::lxdebug->enter_sub();
900 my ($self, $form) = @_;
902 # init some form vars
903 my @anmeldungszeitraum =
904 qw('0401' '0402' '0403'
908 '0441' '0442' '0443' '0444');
910 foreach my $item (@anmeldungszeitraum) {
914 #forgotten the year --> thisyear
915 if ($form->{year} !~ m/^\d\d\d\d$/) {
916 $form->{year} = substr(
918 $form->current_date(\%::myconfig), \%::myconfig
921 $::lxdebug->message(LXDebug->DEBUG1,
922 qq|Actual year from Database: $form->{year}\n|);
926 # using dates in ISO-8601 format: yyyymmmdd for Postgres...
930 if ($form->{period} eq "13") {
931 $form->{fromdate} = "$form->{year}0101";
932 $form->{todate} = "$form->{year}1231";
936 if ($form->{period} eq "41") {
937 $form->{fromdate} = "$form->{year}0101";
938 $form->{todate} = "$form->{year}0331";
939 $form->{'0441'} = "X";
941 if ($form->{period} eq "42") {
942 $form->{fromdate} = "$form->{year}0401";
943 $form->{todate} = "$form->{year}0630";
944 $form->{'0442'} = "X";
946 if ($form->{period} eq "43") {
947 $form->{fromdate} = "$form->{year}0701";
948 $form->{todate} = "$form->{year}0930";
949 $form->{'0443'} = "X";
951 if ($form->{period} eq "44") {
952 $form->{fromdate} = "$form->{year}1001";
953 $form->{todate} = "$form->{year}1231";
954 $form->{'0444'} = "X";
959 $form->{period} eq "01" && do {
960 $form->{fromdate} = "$form->{year}0101";
961 $form->{todate} = "$form->{year}0131";
962 $form->{'0401'} = "X";
965 $form->{period} eq "02" && do {
966 $form->{fromdate} = "$form->{year}0201";
968 #this works from 1901 to 2099, 1900 and 2100 fail.
969 my $leap = ($form->{year} % 4 == 0) ? "29" : "28";
970 $form->{todate} = "$form->{year}02$leap";
971 $form->{"0402"} = "X";
974 $form->{period} eq "03" && do {
975 $form->{fromdate} = "$form->{year}0301";
976 $form->{todate} = "$form->{year}0331";
977 $form->{"0403"} = "X";
980 $form->{period} eq "04" && do {
981 $form->{fromdate} = "$form->{year}0401";
982 $form->{todate} = "$form->{year}0430";
983 $form->{"0404"} = "X";
986 $form->{period} eq "05" && do {
987 $form->{fromdate} = "$form->{year}0501";
988 $form->{todate} = "$form->{year}0531";
989 $form->{"0405"} = "X";
992 $form->{period} eq "06" && do {
993 $form->{fromdate} = "$form->{year}0601";
994 $form->{todate} = "$form->{year}0630";
995 $form->{"0406"} = "X";
998 $form->{period} eq "07" && do {
999 $form->{fromdate} = "$form->{year}0701";
1000 $form->{todate} = "$form->{year}0731";
1001 $form->{"0407"} = "X";
1004 $form->{period} eq "08" && do {
1005 $form->{fromdate} = "$form->{year}0801";
1006 $form->{todate} = "$form->{year}0831";
1007 $form->{"0408"} = "X";
1010 $form->{period} eq "09" && do {
1011 $form->{fromdate} = "$form->{year}0901";
1012 $form->{todate} = "$form->{year}0930";
1013 $form->{"0409"} = "X";
1016 $form->{period} eq "10" && do {
1017 $form->{fromdate} = "$form->{year}1001";
1018 $form->{todate} = "$form->{year}1031";
1019 $form->{"0410"} = "X";
1022 $form->{period} eq "11" && do {
1023 $form->{fromdate} = "$form->{year}1101";
1024 $form->{todate} = "$form->{year}1130";
1025 $form->{"0411"} = "X";
1028 $form->{period} eq "12" && do {
1029 $form->{fromdate} = "$form->{year}1201";
1030 $form->{todate} = "$form->{year}1231";
1031 $form->{"0412"} = "X";
1036 # Kontrollvariablen für die Templates
1037 $form->{"year$_"} = ($form->{year} >= $_ ) ? "1":"0" for 2007..2107;
1039 $main::lxdebug->leave_sub();
1042 sub get_fiamt_vars {
1043 return @fiamt_finanzamt;
1047 $main::lxdebug->enter_sub();
1051 'steuernummer' => 'taxnumber',
1052 'elsterFFFF' => 'fa_bufa_nr',
1053 'FA_dauerfrist' => 'fa_dauerfrist',
1054 'FA_steuerberater_city' => 'fa_steuerberater_city',
1055 'FA_steuerberater_name' => 'fa_steuerberater_name',
1056 'FA_steuerberater_street' => 'fa_steuerberater_street',
1057 'FA_steuerberater_tel' => 'fa_steuerberater_tel',
1058 'FA_voranmeld' => 'fa_voranmeld',
1061 my $filename = $::lx_office_conf{paths}{userspath}."/finanzamt.ini";
1063 return unless (open( $FACONF, "<", $filename));
1067 next if (/^(\#|\s)/);
1072 # remove any trailing whitespace
1073 s/^\s*(.*?)\s*$/$1/;
1074 my ($key, $value) = split(/=/, $_, 2);
1076 $main::lxdebug->message(LXDebug->DEBUG2(), "oldkey: ".$key." val=".$value." newkey=".
1077 $oldkeys{$key}." oval=".$::form->{$oldkeys{$key}});
1078 if ( $oldkeys{$key} && $::form->{$oldkeys{$key}} eq '' ) {
1079 $::form->{$oldkeys{$key}} = $::locale->{iconv_utf8}->convert($value);
1080 $main::lxdebug->message(LXDebug->DEBUG2(), "set ".$oldkeys{$key}."=".$::form->{$oldkeys{$key}});
1084 $main::lxdebug->leave_sub();
1089 $main::lxdebug->enter_sub();
1090 my $defaults = SL::DB::Default->get;
1091 my @rd_config = @fiamt_config;
1092 push @rd_config ,qw(accounting_method coa company address co_ustid duns);
1093 $::form->{$_} = $defaults->$_ for @rd_config;
1095 if ( $::form->{taxnumber} eq '' || $::form->{fa_bufa_nr} eq '') {
1096 #alte finanzamt.ini lesen, ggf abspeichern
1097 if ( get_oldconfig() ) {
1103 my $coa = $::form->{coa};
1104 $::form->{"COA_$coa"} = '1';
1105 $::form->{COA_Germany} = '1' if ($coa =~ m/^germany/i);
1106 $main::lxdebug->leave_sub();
1110 $main::lxdebug->enter_sub();
1111 if ( $::form->{fa_bufa_nr} && $::form->{fa_bufa_nr} ne '' ) {
1112 my $fiamt = SL::DB::Finanzamt->_get_manager_class->get_first(
1113 query => [ fa_bufa_nr => $::form->{fa_bufa_nr} ]);
1114 $::form->{$_} = $fiamt->$_ for @fiamt_finanzamt;
1116 $main::lxdebug->leave_sub();
1120 $main::lxdebug->enter_sub();
1121 my $defaults = SL::DB::Default->get;
1122 $defaults->$_($::form->{$_}) for @fiamt_config;
1124 if ( $defaults->fa_bufa_nr ) {
1125 my $fiamt = SL::DB::Finanzamt->_get_manager_class->get_first(
1126 query => [ fa_bufa_nr => $defaults->fa_bufa_nr ]);
1127 $fiamt->$_($::form->{$_}) for @fiamt_finanzamt;
1130 $main::lxdebug->leave_sub();