-
+
|;
$main::lxdebug->leave_sub();
+ return $fa_auswahl;
}
sub info {
@@ -398,7 +452,8 @@ sub stichtag {
sub query_finanzamt {
$main::lxdebug->enter_sub();
- my ($myconfig, $form) = @_;
+ my ($self, $myconfig, $form) = @_;
+
my $dbh = $form->dbconnect($myconfig) or $self->error(DBI->errstr);
#Test, if table finanzamt exist
@@ -410,7 +465,7 @@ sub query_finanzamt {
if ($DBI::err) {
#There is no table, read the table from sql/finanzamt.sql
- print qq|
Bitte warten, Tabelle $table wird einmalig in Datenbank:
+ print qq|
Bitte warten, Tabelle $table wird einmalig in Datenbank:
$myconfig->{dbname} als Benutzer: $myconfig->{dbuser} hinzugefügt...
|;
process_query($form, $dbh, $filename) || $self->error(DBI->errstr);
@@ -507,12 +562,12 @@ sub process_query {
# return unless (-f $filename);
- open(FH, "$filename") or $form->error("$filename : $!\n");
+ open my $FH, "<", "$filename" or $form->error("$filename : $!\n");
my $query = "";
my $sth;
my @quote_chars;
- while () {
+ while (<$FH>) {
# Remove DOS and Unix style line endings.
s/[\r\n]//g;
@@ -551,10 +606,405 @@ sub process_query {
}
}
- close FH;
+ close $FH;
$main::lxdebug->leave_sub();
}
-1;
+sub ustva {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+
+ # connect to database
+ my $dbh = $form->dbconnect($myconfig);
+
+ my $last_period = 0;
+ my $category = "pos_ustva";
+
+ my @category_cent = USTVA->report_variables({
+ myconfig => $myconfig,
+ form => $form,
+ type => '',
+ attribute => 'position',
+ dec_places => '2',
+ });
+
+ push @category_cent, qw(83 Z43 Z45 Z53 Z62 Z65 Z67);
+
+ my @category_euro = USTVA->report_variables({
+ myconfig => $myconfig,
+ form => $form,
+ type => '',
+ attribute => 'position',
+ dec_places => '0',
+ });
+
+ push @category_euro, USTVA->report_variables({
+ myconfig => $myconfig,
+ form => $form,
+ type => '',
+ attribute => 'position',
+ dec_places => '0',
+ });
+
+ $form->{decimalplaces} *= 1;
+
+ foreach $item (@category_cent) {
+ $form->{"$item"} = 0;
+ }
+ foreach $item (@category_euro) {
+ $form->{"$item"} = 0;
+ }
+ my $coa_name = coa_get($dbh);
+ $form->{coa} = $coa_name;
+
+ # Controlvariable for templates
+ $form->{"$coa_name"} = '1';
+
+ $main::lxdebug->message(LXDebug::DEBUG2, "COA: '$form->{coa}', \$form->{$coa_name} = 1");
+
+ &get_accounts_ustva($dbh, $last_period, $form->{fromdate}, $form->{todate},
+ $form, $category);
+
+ ###########################################
+ #
+ # Nationspecific Modfications
+ #
+ ###########################################
+
+ # Germany
+
+ if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU'){
+
+ # 16%/19% Umstellung
+ # Umordnen der Kennziffern
+ if ( $form->{year} < 2007) {
+ $form->{35} += $form->{81};
+ $form->{36} += $form->{811};
+ $form->{95} += $form->{89};
+ $form->{98} += $form->{891};
+ map { delete $form->{$_} } qw(81 811 89 891);
+ } else {
+ $form->{35} += $form->{51};
+ $form->{36} += $form->{511};
+ $form->{95} += $form->{97};
+ $form->{98} += $form->{971};
+ map { delete $form->{$_} } qw(51 511 97 971);
+ }
+ }
+
+
+ # Fixme: Wird auch noch für Oesterreich gebraucht,
+ # weil kein eigenes Ausgabeformular
+ # sotte aber aus der allgeméinen Steuerberechnung verschwinden
+ #
+ # Berechnung der USTVA Formularfelder laut Bogen 207
+ #
+
+ $form->{"51r"} = $form->{"511"};
+ $form->{"86r"} = $form->{"861"};
+ $form->{"97r"} = $form->{"971"};
+ $form->{"93r"} = $form->{"931"};
+
+ $form->{"Z43"} = $form->{"511"} + $form->{"811"} + $form->{"861"}
+ + $form->{"36"} + $form->{"80"} + $form->{"971"}
+ + $form->{"891"} + $form->{"931"} + $form->{"96"}
+ + $form->{"98"};
+
+ $form->{"Z45"} = $form->{"Z43"};
+
+ $form->{"Z53"} = $form->{"Z45"} + $form->{"53"} + $form->{"74"}
+ + $form->{"85"} + $form->{"65"};
+
+ $form->{"Z62"} = $form->{"Z43"} - $form->{"66"} - $form->{"61"}
+ - $form->{"62"} - $form->{"67"} - $form->{"63"}
+ - $form->{"64"} - $form->{"59"};
+
+ $form->{"Z65"} = $form->{"Z62"} - $form->{"69"};
+ $form->{"83"} = $form->{"Z65"} - $form->{"39"};
+
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub coa_get {
+
+ my ($dbh) = @_;
+
+ my $query= qq|SELECT coa FROM defaults|;
+
+ my $sth = $dbh->prepare($query);
+
+ $sth->execute || $form->dberror($query);
+
+ ($ref) = $sth->fetchrow_array;
+
+ return $ref;
+
+};
+
+sub get_accounts_ustva {
+ $main::lxdebug->enter_sub();
+
+ my ($dbh, $last_period, $fromdate, $todate, $form, $category) = @_;
+
+ my $query;
+ my $where = "";
+ my $glwhere = "";
+ my $subwhere = "";
+ my $ARwhere = "";
+ my $APwhere = '';
+ my $arwhere = "";
+ my $item;
+
+ my $gltaxkey_where = "(tk.pos_ustva>=59 AND tk.pos_ustva<=66)";
+
+ if ($fromdate) {
+ if ($form->{method} eq 'cash') {
+ $subwhere .= " AND transdate >= '$fromdate'";
+ $glwhere = " AND ac.transdate >= '$fromdate'";
+ $ARwhere .= " AND acc.transdate >= '$fromdate'";
+ }
+ $APwhere .= " AND AP.transdate >= '$fromdate'";
+ $where .= " AND ac.transdate >= '$fromdate'";
+ }
+
+ if ($todate) {
+ $where .= " AND ac.transdate <= '$todate'";
+ $ARwhere .= " AND acc.transdate <= '$todate'";
+ }
+
+ ############################################
+ # Method eq 'cash' = IST Versteuerung
+ ############################################
+ # Betrifft nur die eingenommene Umsatzsteuer
+ #
+ ############################################
+
+ if ($form->{method} eq 'cash') {
+
+ $query = qq|
+ SELECT
+ -- USTVA IST-Versteuerung
+ --
+ -- Alle tatsaechlichen _Zahlungseingaenge_
+ -- im Voranmeldezeitraum erfassen
+ -- (Teilzahlungen werden prozentual auf verschiedene Steuern aufgeteilt)
+ SUM( ac.amount *
+ -- Bezahlt / Rechnungssumme
+ (
+ SELECT SUM(acc.amount)
+ FROM acc_trans acc
+ INNER JOIN chart c ON (acc.chart_id = c.id
+ AND c.link like '%AR_paid%')
+ WHERE
+ 1=1
+ $ARwhere
+ AND acc.trans_id = ac.trans_id
+ )
+ /
+ (
+ SELECT amount FROM ar WHERE id = ac.trans_id
+ )
+ ) AS amount,
+ tk.pos_ustva
+ FROM acc_trans ac
+ LEFT JOIN chart c ON (c.id = ac.chart_id)
+ LEFT JOIN ar ON (ar.id = ac.trans_id)
+ LEFT JOIN taxkeys tk ON (
+ tk.id = (
+ SELECT id FROM taxkeys
+ WHERE chart_id = ac.chart_id
+ -- AND taxkey_id = ac.taxkey
+ AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
+ ORDER BY startdate DESC LIMIT 1
+ )
+ )
+ WHERE
+ 1=1
+ -- Here no where, please. All Transactions ever should be
+ -- testet if they are paied in the USTVA report period.
+ GROUP BY tk.pos_ustva
+ |;
+
+ } elsif ($form->{method} eq 'accrual') {
+ #########################################
+ # Method eq 'accrual' = Soll Versteuerung
+ #########################################
+
+ $query = qq|
+ -- Alle Einnahmen AR und pos_ustva erfassen
+ SELECT
+ - sum(ac.amount) AS amount,
+ tk.pos_ustva
+ FROM acc_trans ac
+ JOIN chart c ON (c.id = ac.chart_id)
+ JOIN ar ON (ar.id = ac.trans_id)
+ JOIN taxkeys tk ON (
+ tk.id = (
+ SELECT id FROM taxkeys
+ WHERE chart_id = ac.chart_id
+ AND startdate <= COALESCE(ar.deliverydate,ar.transdate)
+ ORDER BY startdate DESC LIMIT 1
+ )
+ )
+ $dpt_join
+ WHERE 1 = 1
+ $where
+ GROUP BY tk.pos_ustva
+ |;
+
+ } else {
+
+ $self->error("Unknown tax method: $form->{method}")
+
+ }
+
+ #########################################
+ # Ausgaben und Gl Buchungen sind gleich
+ # für Ist- und Soll-Versteuerung
+ #########################################
+ $query .= qq|
+ UNION -- alle Ausgaben AP erfassen
+
+ SELECT
+ sum(ac.amount) AS amount,
+ tk.pos_ustva
+ FROM acc_trans ac
+ JOIN ap ON (ap.id = ac.trans_id )
+ JOIN chart c ON (c.id = ac.chart_id)
+ LEFT JOIN taxkeys tk ON (
+ tk.id = (
+ SELECT id FROM taxkeys
+ WHERE 1=1
+ AND chart_id=ac.chart_id
+ --AND taxkey_id = ac.taxkey
+ AND startdate <= COALESCE(AP.transdate)
+ ORDER BY startdate DESC LIMIT 1
+ )
+ )
+ WHERE
+ 1=1
+ $where
+ GROUP BY tk.pos_ustva
+
+ UNION -- Einnahmen direkter gl Buchungen erfassen
+
+ SELECT sum
+ ( - ac.amount) AS amount,
+ tk.pos_ustva
+ FROM acc_trans ac
+ JOIN chart c ON (c.id = ac.chart_id)
+ JOIN gl a ON (a.id = ac.trans_id)
+ LEFT JOIN taxkeys tk ON (
+ tk.id = (
+ SELECT id FROM taxkeys
+ WHERE chart_id=ac.chart_id
+ AND NOT $gltaxkey_where
+ AND startdate <= COALESCE(ac.transdate)
+ ORDER BY startdate DESC LIMIT 1
+ )
+ )
+
+ $dpt_join
+ WHERE 1 = 1
+ $where
+ GROUP BY tk.pos_ustva
+
+
+ UNION -- Ausgaben direkter gl Buchungen erfassen
+
+ SELECT sum
+ (ac.amount) AS amount,
+ tk.pos_ustva
+ FROM acc_trans ac
+ JOIN chart c ON (c.id = ac.chart_id)
+ JOIN gl a ON (a.id = ac.trans_id)
+ LEFT JOIN taxkeys tk ON (
+ tk.id = (
+ SELECT id FROM taxkeys
+ WHERE chart_id=ac.chart_id
+ AND $gltaxkey_where
+ AND startdate <= COALESCE(ac.transdate)
+ ORDER BY startdate DESC LIMIT 1
+ )
+ )
+
+ $dpt_join
+ WHERE 1 = 1
+ $where
+ GROUP BY tk.pos_ustva
+
+ |;
+
+ my @accno;
+ my $accno;
+ my $ref;
+
+ # Show all $query in Debuglevel LXDebug::QUERY
+ $callingdetails = (caller (0))[3];
+ $main::lxdebug->message(LXDebug::QUERY, "$callingdetails \$query=\n $query");
+
+ my $sth = $dbh->prepare($query);
+
+ $sth->execute || $form->dberror($query);
+
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ # Bug 365 solved?!
+ $ref->{amount} *= -1;
+ $form->{ $ref->{$category} } += $ref->{amount};
+ }
+
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+
+}
+
+sub get_config {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $userspath, $filename) = @_;
+
+ $form->error("Missing Parameter: @_") if !$userspath || !$filename;
+
+ my $form = $main::form;
+
+ $filename = "$form->{login}_$filename";
+ $filename =~ s|.*/||;
+ $filename = "$userspath/$filename";
+ open my $FACONF, "<", $filename or sub {# Annon Sub
+ # catch open error
+ # create file if file does not exist
+ open my $FANEW, ">", $filename or $form->error("CREATE: $filename : $!");
+ close $FANEW or $form->error("CLOSE: $filename : $!");
+
+ #try again open file
+ open my $FACONF, "<", $filename or $form->error("OPEN: $filename : $!");
+ };
+
+ while (<$FACONF>) {
+ last if (/^\[/);
+ next if (/^(\#|\s)/);
+
+ # remove comments
+ s/\s#.*//g;
+
+ # remove any trailing whitespace
+ s/^\s*(.*?)\s*$/$1/;
+ my ($key, $value) = split(/=/, $_, 2);
+
+ $form->{$key} = "$value";
+
+ }
+
+ close $FACONF;
+
+ $main::lxdebug->leave_sub();
+}
+
+
+1;