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 sub create_steuernummer {
29 $main::lxdebug->enter_sub();
31 $part = $form->{part};
32 $patterncount = $form->{patterncount};
33 $delimiter = $form->{delimiter};
34 $elster_pattern = $form->{elster_pattern};
36 # rebuild steuernummer and elstersteuernummer
37 # es gibt eine gespeicherte steuernummer $form->{steuernummer}
38 # und die parts und delimiter
43 $steuernummer_new = $part;
44 $elstersteuernummer_new = $elster_FFFF;
45 $elstersteuernummer_new .= '0';
47 for ($h = 1; $h < $patterncount; $h++) {
48 $steuernummer_new .= qq|$delimiter|;
49 for ($i = 1; $i <= length($elster_pattern); $i++) {
50 $steuernummer_new .= $form->{"part_$h\_$i"};
51 $elstersteuernummer_new .= $form->{"part_$h\_$i"};
54 if ($form->{steuernummer} ne $steuernummer_new) {
55 $form->{steuernummer} = $steuernummer_new;
56 $form->{elstersteuernummer} = $elstersteuernummer_new;
57 $form->{steuernummer_new} = $steuernummer_new;
59 $main::lxdebug->leave_sub();
60 return ($steuernummer_new, $elstersteuernummer_new);
63 sub steuernummer_input {
64 $main::lxdebug->enter_sub();
66 ($elsterland, $elsterFFFF, $steuernummer) = @_;
68 $elster_land = $elsterland;
69 $elster_FFFF = $elsterFFFF;
70 $steuernummer = '0000000000' if ($steuernummer eq '');
72 # $steuernummer formatieren (nur Zahlen) -> $stnr
73 $stnr = $steuernummer;
76 #Pattern description Elstersteuernummer
77 my %elster_STNRformat = (
78 'Mecklenburg Vorpommern' => 'FFF/BBB/UUUUP', # '/' 3
79 'Hessen' => '0FF BBB UUUUP', # ' ' 3
80 'Nordrhein Westfalen' => 'FFF/BBBB/UUUP', # '/' 3
81 'Schleswig Holstein' => 'FF BBB UUUUP', # ' ' 2
82 'Berlin' => 'FF/BBB/UUUUP', # '/' 3
83 'Thüringen' => 'FFF/BBB/UUUUP', # '/' 3
84 'Sachsen' => 'FFF/BBB/UUUUP', # '/' 3
85 'Hamburg' => 'FF/BBB/UUUUP', # '/' 3
86 'Baden Würtemberg' => 'FF/BBB/UUUUP', # '/' 2
87 'Sachsen Anhalt' => 'FFF/BBB/UUUUP', # '/' 3
88 'Saarland' => 'FFF/BBB/UUUUP', # '/' 3
89 'Bremen' => 'FF BBB UUUUP', # ' ' 3
90 'Bayern' => 'FFF/BBB/UUUUP', # '/' 3
91 'Rheinland Pfalz' => 'FF/BBB/UUUU/P', # '/' 4
92 'Niedersachsen' => 'FF/BBB/UUUUP', # '/' 3
93 'Brandenburg' => 'FFF/BBB/UUUUP', # '/' 3
97 $elster_pattern = $elster_STNRformat{$elster_land};
98 my @elster_pattern = split(' ', $elster_pattern);
99 my $delimiter = ' ';
100 my $patterncount = @elster_pattern;
101 if ($patterncount < 2) {
102 @elster_pattern = ();
103 @elster_pattern = split('/', $elster_pattern);
105 $patterncount = @elster_pattern;
108 # no we have an array of patternparts and a delimiter
109 # create the first automated and fixed part and delimiter
111 print qq|<b><font size="+1">|;
114 $elster_pattern[0] eq 'FFF' && do {
115 $part = substr($elster_FFFF, 1, 4);
119 $elster_pattern[0] eq '0FF' && do {
120 $part = '0' . substr($elster_FFFF, 2, 4);
124 $elster_pattern[0] eq 'FF' && do {
125 $part = substr($elster_FFFF, 2, 4);
135 #now the rest of the Steuernummer ...
136 print qq|</b></font>|;
138 <input type=hidden name="elster_pattern" value="$elster_pattern">
139 <input type=hidden name="patterncount" value="$patterncount">
140 <input type=hidden name="patternlength" value="$patterncount">
141 <input type=hidden name="delimiter" value="$delimiter">
142 <input type=hidden name="part" value="$part">
149 for ($h = 1; $h < $patterncount; $h++) {
150 print qq| $delimiter \n|;
151 for ($i = 1; $i <= length($elster_pattern[$h]); $i++) {
152 print qq|<select name="part_$h\_$i">\n|;
154 for ($j = 0; $j <= 9; $j++) {
155 print qq| <option value="$j"|;
156 if ($steuernummer ne '') {
157 if ($j eq substr($stnr, length($part) + $k, 1)) {
161 print qq|>$j</option>\n|;
164 print qq|</select>\n|;
167 $main::lxdebug->leave_sub();
171 $main::lxdebug->enter_sub();
175 # Referenz wird übergeben, hash of hash wird nicht
176 # in neues Hash kopiert, sondern direkt über die Referenz verändert
177 # Prototyp für diese Konstruktion
179 my ($land, $elsterFFFF, $elster_init) =
180 @_; #Referenz auf Hash von Hash übergeben
182 my $FFFF = $elsterFFFF;
185 $checked = 'checked' if ($elsterFFFF eq '' and $land eq '');
187 #if ($ENV{HTTP_USER_AGENT} =~ /(mozilla|opera|w3m)/i){
188 #$terminal='mozilla';
189 #} elsif ($ENV{HTTP_USER_AGENT} =~ /(links|lynx)/i){
193 #if ( $terminal eq 'mozilla' or $terminal eq 'js' ) {
196 <script language="Javascript">
197 function update_auswahl()
199 var elsterBLAuswahl = document.verzeichnis.elsterland_new;
200 var elsterFAAuswahl = document.verzeichnis.elsterFFFF_new;
202 elsterFAAuswahl.options.length = 0; // dropdown aufräumen
205 foreach $elster_land (sort keys %$elster_init) {
207 if (elsterBLAuswahl.options[elsterBLAuswahl.selectedIndex].
208 value == "$elster_land")
212 my %elster_land_fa = ();
214 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
215 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}->{$FFFF}->[0];
217 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
218 keys(%elster_land_fa)
221 elsterFAAuswahl.options[$j] = new Option("$elster_land_fa{$ffff} ($ffff)","$ffff");|;
237 <select size="1" name="elsterland_new" onchange="update_auswahl()">|;
239 print qq|<option value="Auswahl" $checked>hier auswählen...</option>\n|;
241 foreach $elster_land (sort keys %$elster_init) {
243 <option value="$elster_land"|;
244 if ($elster_land eq $land and $checked eq '') {
247 print qq|>$elster_land</option>
255 my $elster_land = '';
256 $elster_land = ($land ne '') ? $land : '';
257 %elster_land_fa = ();
258 for $FFFF (keys %{ $elster_init->{$elster_land} }) {
259 $elster_land_fa{$FFFF} = $elster_init->{$elster_land}->{$FFFF}->[0];
267 <select size="1" name="elsterFFFF_new">|;
268 if ($elsterFFFF eq '') {
269 print qq|<option value="Auswahl" $checked>hier auswählen...</option>|;
271 foreach $ffff (sort { $elster_land_fa{$a} cmp $elster_land_fa{$b} }
272 keys(%elster_land_fa)
276 <option value="$ffff"|;
277 if ($ffff eq $elsterFFFF and $checked eq '') {
280 print qq|>$elster_land_fa{$ffff} ($ffff)</option>|;
289 $main::lxdebug->leave_sub();
293 $main::lxdebug->enter_sub();
297 if ($ENV{HTTP_USER_AGENT}) {
300 print qq|<body><h2 class=info>Hinweis</h2>
306 <input type=button value="zurück" onClick="history.go(-1)">
314 if ($form->{error_function}) {
315 &{ $form->{error_function} }($msg);
317 die "Hinweis: $msg\n";
321 $main::lxdebug->leave_sub();
325 $main::lxdebug->enter_sub();
328 # soll mal eine Erinnerungsfunktion für USTVA Abgaben werden, die automatisch
329 # den Termin der nächsten USTVA anzeigt.
332 my ($today, $FA_dauerfrist, $FA_voranmeld) = @_;
337 $today =~ /(\d\d\d\d)(\d\d)(\d\d)/;
343 $yymmdd = "$year$month$day" * 1;
344 $mmdd = "$month$day" * 1;
348 #$ical = '...vcal format';
350 #if ($FA_voranmeld eq 'month'){
352 %liste = ("0110" => 'December',
354 "0310" => 'February',
361 "1010" => 'September',
363 "1210" => 'November');
367 $month += 1 if ($day > 10);
368 $month = sprintf("%02d", $month);
369 $stichtag = $year . $month . "10";
370 $ust_va = $month . "10";
372 foreach $date (%liste) {
373 $ust_va = $liste{$date} if ($date eq $stichtag);
376 #} elsif ($FA_voranmeld eq 'quarter'){
381 #@stichtag = ('10.04.2004', '10.05.2004');
383 #@liste = ['0110', '0210', '0310', '0410', '0510', '0610', '0710', '0810', '0910',
384 # '1010', '1110', '1210', ];
386 #foreach $key (@liste){
387 # #if ($ddmm < ('0110' * 1));
389 # $stichtag = $liste[$key - 1] if ($ddmm > $key);
393 #$stichtag =~ /([\d]\d)(\d\d)$/
394 #$stichtag = "$1.$2.$yy"
396 $main::lxdebug->leave_sub();
397 return ($stichtag, $description, $tage_bis, $ical);
400 sub query_finanzamt {
401 $main::lxdebug->enter_sub();
403 my ($myconfig, $form) = @_;
404 my $dbh = $form->dbconnect($myconfig) or $self->error(DBI->errstr);
406 #Test, if table finanzamt exist
407 my $table = 'finanzamt';
408 my $filename = "sql/$table.sql";
410 my $tst = $dbh->prepare("SELECT * FROM $table");
414 #There is no table, read the table from sql/finanzamt.sql
415 print qq|<p>Bitte warten, Tabelle $table wird einmalig in Datenbank:
416 $myconfig->{dbname} als Benutzer: $myconfig->{dbuser} hinzugefügt...</p>|;
417 process_query($form, $dbh, $filename) || $self->error(DBI->errstr);
419 #execute second last call
420 my $dbh = $form->dbconnect($myconfig) or $self->error(DBI->errstr);
437 'FA_PLZ_Grosskunden', # 9
438 'FA_PLZ_Postfach', # 10
441 'FA_Kontonummer_1', # 13
442 'FA_Bankbezeichnung_1', # 14
443 #'FA_BankIBAN_1', # 15
444 #'FA_BankBIC_1', # 16
445 #'FA_BankInhaber_BUFA_Nr_1', # 17
447 'FA_Kontonummer_2', # 19
448 'FA_Bankbezeichnung_2', # 20
449 #'FA_BankIBAN_2', # 21
450 #'FA_BankBIC_2', # 22
451 #'FA_BankInhaber_BUFA_Nr_2', # 23
452 'FA_Oeffnungszeiten', # 24
455 #'FA_zustaendige_Hauptstelle_BUFA_Nr', # 27
456 #'FA_zustaendige_vorgesetzte_Finanzbehoerde' # 28
459 my $field = join(', ', @vars);
461 my $query = "SELECT $field FROM finanzamt ORDER BY FA_Land_nr";
462 my $sth = $dbh->prepare($query) or $self->error($dbh->errstr);
463 $sth->execute || $form->dberror($query);
464 my $array_ref = $sth->fetchall_arrayref();
466 foreach my $row (@$array_ref) {
467 my $FA_finanzamt = $row;
468 $land = 'Schleswig Holstein' if (@$FA_finanzamt[0] eq '1');
469 $land = 'Hamburg' if (@$FA_finanzamt[0] eq '2');
470 $land = 'Niedersachsen' if (@$FA_finanzamt[0] eq '3');
471 $land = 'Bremen' if (@$FA_finanzamt[0] eq '4');
472 $land = 'Nordrhein Westfalen' if (@$FA_finanzamt[0] eq '5');
473 $land = 'Hessen' if (@$FA_finanzamt[0] eq '6');
474 $land = 'Rheinland Pfalz' if (@$FA_finanzamt[0] eq '7');
475 $land = 'Baden Würtemberg' if (@$FA_finanzamt[0] eq '8');
476 $land = 'Bayern' if (@$FA_finanzamt[0] eq '9');
477 $land = 'Saarland' if (@$FA_finanzamt[0] eq '10');
478 $land = 'Berlin' if (@$FA_finanzamt[0] eq '11');
479 $land = 'Brandenburg' if (@$FA_finanzamt[0] eq '12');
480 $land = 'Mecklenburg Vorpommern' if (@$FA_finanzamt[0] eq '13');
481 $land = 'Sachsen' if (@$FA_finanzamt[0] eq '14');
482 $land = 'Sachsen Anhalt' if (@$FA_finanzamt[0] eq '15');
483 $land = 'Thüringen' if (@$FA_finanzamt[0] eq '16');
485 my $ffff = @$FA_finanzamt[1];
488 $rec->{$land} = $ffff;
493 $finanzamt{$land}{$ffff} = [@$FA_finanzamt];
499 $main::lxdebug->leave_sub();
505 $main::lxdebug->enter_sub();
507 # Copyright D. Simander -> SL::Form under Gnu GPL.
508 my ($form, $dbh, $filename) = @_;
510 # return unless (-f $filename);
512 open(FH, "$filename") or $form->error("$filename : $!\n");
519 # Remove DOS and Unix style line endings.
522 # don't add comments or empty lines
523 next if /^(--.*|\s+)$/;
525 for (my $i = 0; $i < length($_); $i++) {
526 my $char = substr($_, $i, 1);
528 # Are we inside a string?
530 if ($char eq $quote_chars[-1]) {
536 if (($char eq "'") || ($char eq "\"")) {
537 push(@quote_chars, $char);
539 } elsif ($char eq ";") {
541 # Query is complete. Send it.
543 $sth = $dbh->prepare($query);
544 $sth->execute || $form->dberror($query);
558 $main::lxdebug->leave_sub();
562 $main::lxdebug->enter_sub();
564 my ($self, $myconfig, $form) = @_;
566 # connect to database
567 my $dbh = $form->dbconnect($myconfig);
570 my $category = "pos_ustva";
571 my @categories_cent = qw(511 861 36 80 971 931 98 96 53 74
572 85 65 66 61 62 67 63 64 59 69 39 83
573 Z43 Z45 Z53 Z62 Z65 Z67);
575 my @categories_euro = qw(41 44 49 43 48 51 86 35 77 76 91 97 93
576 95 94 42 60 45 52 73 84);
578 $form->{decimalplaces} *= 1;
580 foreach $item (@categories_cent) {
581 $form->{"$item"} = 0;
583 foreach $item (@categories_euro) {
584 $form->{"$item"} = 0;
587 &get_accounts_ustva($dbh, $last_period, $form->{fromdate}, $form->{todate},
591 # Berechnung der USTVA Formularfelder
593 $form->{"51r"} = $form->{"511"};
594 $form->{"86r"} = $form->{"861"};
595 $form->{"97r"} = $form->{"971"};
596 $form->{"93r"} = $form->{"931"};
598 $form->{"511"} + $form->{"861"} + $form->{"36"} + $form->{"80"} +
599 $form->{"971"} + $form->{"931"} + $form->{"96"} + $form->{"98"};
600 $form->{"Z45"} = $form->{"Z43"};
601 $form->{"Z53"} = $form->{"Z43"};
603 $form->{"Z43"} - $form->{"66"} - $form->{"61"} - $form->{"62"} -
604 $form->{"63"} - $form->{"64"} - $form->{"59"};
605 $form->{"Z65"} = $form->{"Z62"} - $form->{"69"};
606 $form->{"83"} = $form->{"Z65"} - $form->{"39"};
608 foreach $item (@categories_cent) {
610 $form->format_amount($myconfig, $form->round_amount($form->{$item}, 2),
614 foreach $item (@categories_euro) {
616 $form->format_amount($myconfig, $form->round_amount($form->{$item}, 0),
622 $main::lxdebug->leave_sub();
625 sub get_accounts_ustva {
626 $main::lxdebug->enter_sub();
628 my ($dbh, $last_period, $fromdate, $todate, $form, $category) = @_;
630 my ($null, $department_id) = split /--/, $form->{department};
645 if ($form->{method} eq 'cash') {
646 $subwhere .= " AND transdate >= '$fromdate'";
647 $glwhere = " AND ac.transdate >= '$fromdate'";
648 $ARwhere .= " AND acc.transdate >= '$fromdate'";
649 $APwhere .= " AND AP.transdate >= '$fromdate'";
651 $where .= " AND ac.transdate >= '$fromdate'";
655 $where .= " AND ac.transdate <= '$todate'";
656 $ARwhere .= " AND acc.transdate <= '$todate'";
657 $subwhere .= " AND transdate <= '$todate'";
658 $APwhere .= " AND AP.transdate <= '$todate'";
661 if ($department_id) {
663 JOIN department t ON (a.department_id = t.id)
666 AND t.id = $department_id
670 if ($form->{project_id}) {
672 AND ac.project_id = $form->{project_id}
675 #########################################
676 # Method eq 'cash' = IST Versteuerung
677 #########################################
679 if ($form->{method} eq 'cash') {
683 -- Alle tatsaechlichen Zahlungseingaenge
684 -- im Voranmeldezeitraum erfassen
685 -- (Teilzahlungen werden prozentual auf verschiedene Steuern aufgeteilt)
687 -- Bezahlt / Rechnungssumme
689 SELECT SUM(acc.amount)
691 INNER JOIN chart c ON (acc.chart_id = c.id AND c.link like '%AR_paid%')
695 AND acc.trans_id = ac.trans_id
699 select amount from ar where id = ac.trans_id
704 JOIN chart c ON (c.id = ac.chart_id)
705 --JOIN ar ON (ar.id = ac.trans_id)
708 -- Here no where, please. All Transactions ever should be
709 -- testet if they are paied in the USTVA report period.
712 UNION -- alle Ausgaben AP erfassen
715 sum(ac.amount) AS amount, pos_ustva
717 JOIN AP ON (AP.id = ac.trans_id )
718 JOIN chart c ON (c.id = ac.chart_id AND pos_ustva NOT LIKE '')
726 UNION -- alle Ausgaben und Einnahmen direkter gl Buchungen erfassen
730 CASE WHEN c.link LIKE '%AR%' THEN ac.amount * -1
731 WHEN c.link LIKE '%AP%' THEN ac.amount * 1
733 ) AS amount, c.$category
735 JOIN chart c ON (c.id = ac.chart_id)
736 JOIN gl a ON (a.id = ac.trans_id)
740 AND NOT (c.link = 'AR' OR c.link = 'AP')
746 #########################################
747 # Method eq 'accrual' = Soll Versteuerung
748 #########################################
750 if ($department_id) {
752 JOIN dpt_trans t ON (t.trans_id = ac.trans_id)
755 AND t.department_id = $department_id
762 CASE WHEN c.link LIKE '%AR%' THEN ac.amount * -1
763 WHEN c.link LIKE '%AP%' THEN ac.amount * 1
765 ) AS amount, c.$category
767 JOIN chart c ON (c.id = ac.chart_id)
780 # Show all $query in Debuglevel LXDebug::QUERY
781 $callingdetails = (caller (0))[3];
782 $main::lxdebug->message(LXDebug::QUERY, "$callingdetails \$query=\n $query");
784 my $sth = $dbh->prepare($query);
785 $sth->execute || $form->dberror($query);
787 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
789 # if ($ref->{amount} < 0) {
790 $ref->{amount} *= -1;
792 if ($category eq "pos_bwa") {
794 $form->{ $ref->{$category} }{kumm} += $ref->{amount};
796 $form->{ $ref->{$category} }{jetzt} += $ref->{amount};
799 $form->{ $ref->{$category} } += $ref->{amount};
804 $main::lxdebug->leave_sub();