X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/f59c9111f911e0c4d418d9b126483970cef4df5a..aa2d928e4f13b7f730b68c947d5b8211abd9f0e4:/SL/USTVA.pm diff --git a/SL/USTVA.pm b/SL/USTVA.pm index 1453562ee..22d12cecf 100644 --- a/SL/USTVA.pm +++ b/SL/USTVA.pm @@ -26,6 +26,7 @@ package USTVA; +use Data::Dumper; use List::Util qw(first); use SL::DB; @@ -523,6 +524,9 @@ sub ustva { $form->{coa} = $::instance_conf->get_coa; + unless ($form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') { + croak t8("Advance turnover tax return only valid for SKR03 or SKR04"); + } my @category_cent = USTVA->report_variables({ myconfig => $myconfig, form => $form, @@ -530,7 +534,7 @@ sub ustva { attribute => 'position', dec_places => '2', }); - + push @category_cent, ("pos_ustva_811b_kivi", "pos_ustva_861b_kivi"); if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') { push @category_cent, qw(Z43 Z45 Z53 Z54 Z62 Z65 Z67); } @@ -541,7 +545,7 @@ sub ustva { attribute => 'position', dec_places => '0', }); - + push @category_euro, ("pos_ustva_81b_kivi", "pos_ustva_86b_kivi"); @{$form->{category_cent}} = @category_cent; @{$form->{category_euro}} = @category_euro; $form->{decimalplaces} *= 1; @@ -568,7 +572,7 @@ sub ustva { # Germany - if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU'){ + if ( $form->{coa} eq 'Germany-DATEV-SKR03EU' or $form->{coa} eq 'Germany-DATEV-SKR04EU') { # 16%/19% Umstellung # Umordnen der Kennziffern @@ -687,7 +691,7 @@ sub get_accounts_ustva { SUM( ac.amount * -- Bezahlt / Rechnungssumme ( - SELECT SUM(acc.amount) + SELECT SUM(acc.amount), t.rate, c.accno FROM acc_trans acc INNER JOIN chart c ON (acc.chart_id = c.id AND c.link like '%AR_paid%') @@ -705,6 +709,7 @@ sub get_accounts_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 tax t ON (t.id = ac.tax_id) LEFT JOIN taxkeys tk ON ( tk.id = ( SELECT id FROM taxkeys @@ -716,7 +721,7 @@ sub get_accounts_ustva { ) WHERE $acc_trans_where - GROUP BY tk.pos_ustva + GROUP BY tk.pos_ustva, t.rate, c.accno |; } elsif ($form->{accounting_method} eq 'accrual') { @@ -728,10 +733,11 @@ sub get_accounts_ustva { -- Alle Einnahmen AR und pos_ustva erfassen SELECT - sum(ac.amount) AS amount, - tk.pos_ustva + tk.pos_ustva, t.rate, c.accno FROM acc_trans ac JOIN chart c ON (c.id = ac.chart_id) JOIN ar ON (ar.id = ac.trans_id) + JOIN tax t ON (t.id = ac.tax_id) JOIN taxkeys tk ON ( tk.id = ( SELECT id FROM taxkeys @@ -743,7 +749,7 @@ sub get_accounts_ustva { $dpt_join WHERE 1 = 1 $where - GROUP BY tk.pos_ustva + GROUP BY tk.pos_ustva, t.rate, c.accno |; } else { @@ -761,10 +767,11 @@ sub get_accounts_ustva { SELECT sum(ac.amount) AS amount, - tk.pos_ustva + tk.pos_ustva, t.rate, c.accno FROM acc_trans ac JOIN ap ON (ap.id = ac.trans_id ) JOIN chart c ON (c.id = ac.chart_id) + JOIN tax t ON (t.id = ac.tax_id) LEFT JOIN taxkeys tk ON ( tk.id = ( SELECT id FROM taxkeys @@ -778,16 +785,17 @@ sub get_accounts_ustva { WHERE 1=1 $where - GROUP BY tk.pos_ustva + GROUP BY tk.pos_ustva, t.rate, c.accno UNION -- Einnahmen direkter gl Buchungen erfassen SELECT sum ( - ac.amount) AS amount, - tk.pos_ustva + tk.pos_ustva, t.rate, c.accno FROM acc_trans ac JOIN chart c ON (c.id = ac.chart_id) JOIN gl a ON (a.id = ac.trans_id) + JOIN tax t ON (t.id = ac.tax_id) LEFT JOIN taxkeys tk ON ( tk.id = ( SELECT id FROM taxkeys @@ -801,17 +809,18 @@ sub get_accounts_ustva { $dpt_join WHERE 1 = 1 $where - GROUP BY tk.pos_ustva + GROUP BY tk.pos_ustva, t.rate, c.accno UNION -- Ausgaben direkter gl Buchungen erfassen SELECT sum (ac.amount) AS amount, - tk.pos_ustva + tk.pos_ustva, t.rate, c.accno FROM acc_trans ac JOIN chart c ON (c.id = ac.chart_id) JOIN gl a ON (a.id = ac.trans_id) + JOIN tax t ON (t.id = ac.tax_id) LEFT JOIN taxkeys tk ON ( tk.id = ( SELECT id FROM taxkeys @@ -825,14 +834,10 @@ sub get_accounts_ustva { $dpt_join WHERE 1 = 1 $where - GROUP BY tk.pos_ustva + GROUP BY tk.pos_ustva, t.rate, c.accno |; - my @accno; - my $accno; - my $ref; - # Show all $query in Debuglevel LXDebug::QUERY my $callingdetails = (caller (0))[3]; $main::lxdebug->message(LXDebug->QUERY(), "$callingdetails \$query=\n $query"); @@ -840,11 +845,53 @@ sub get_accounts_ustva { my $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); + # ugly, but we need to use static accnos + my ($accno_five, $accno_sixteen, $corr); + + if ($form->{coa} eq 'Germany-DATEV-SKR03EU') { + $accno_five = 1773; + $accno_sixteen = 1775; + } elsif (($form->{coa} eq 'Germany-DATEV-SKR04EU')) { + $accno_five = 3803; # SKR04 + $accno_sixteen = 3805; # SKR04 + } else {die "wrong call"; } while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { next unless $ref->{$category}; + $corr = 0; $ref->{amount} *= -1; - $form->{ $ref->{$category} } += $ref->{amount}; + # USTVA Pos 35 + if ($ref->{pos_ustva} eq '35') { + if ($ref->{rate} == 0.16) { + $form->{"pos_ustva_81b_kivi"} += $ref->{amount}; + } elsif ($ref->{rate} == 0.05) { + $form->{"pos_ustva_86b_kivi"} += $ref->{amount}; + } elsif ($ref->{rate} == 0.19) { + # pos_ustva says 16, but rate says 19 + # (pos_ustva should be tax dependent and not taxkeys dependent) + # correction hotfix for this case: + # bookings exists with 19% -> + # move 19% bookings to the 19% position + # Dont rely on dates of taxkeys + $corr = 1; + $form->{"81"} += $ref->{amount}; + } elsif ($ref->{rate} == 0.07) { + # pos_ustva says 5, but rate says 7 + # see comment above: + # Dont rely on dates of taxkeys + $corr = 1; + $form->{"86"} += $ref->{amount}; + } else {die ("No valid tax rate for pos 35" . Dumper($ref)); } + } + # USTVA Pos 36 (Steuerkonten) + if ($ref->{pos_ustva} eq '36') { + if ($ref->{accno} =~ /^$accno_sixteen/) { + $form->{"pos_ustva_811b_kivi"} += $ref->{amount}; + } elsif ($ref->{accno} =~ /^$accno_five/) { + $form->{"pos_ustva_861b_kivi"} += $ref->{amount}; + } else { die ("No valid accno for pos 36" . Dumper($ref)); } + } + $form->{ $ref->{$category} } += $ref->{amount} unless $corr; } $sth->finish;