X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FUSTVA.pm;h=4ac3c1a2c49e75aacebdab1eefadc7b7fe2e80ca;hb=226b80e3c56c07d022b1238774302de8d83d01c5;hp=09f56836aa30b36eb518f57b9cdb8a9acbd63338;hpb=785ef602f0f48db5ebc7f29c621b24277a71d0fe;p=kivitendo-erp.git diff --git a/SL/USTVA.pm b/SL/USTVA.pm index 09f56836a..4ac3c1a2c 100644 --- a/SL/USTVA.pm +++ b/SL/USTVA.pm @@ -597,6 +597,24 @@ sub ustva { &get_accounts_ustva($dbh, $last_period, $form->{fromdate}, $form->{todate}, $form, $category); + + # 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); + } + + # # Berechnung der USTVA Formularfelder laut Bogen 207 # @@ -639,7 +657,7 @@ sub get_accounts_ustva { my $dpt_where; my $dpt_join; my $project; - my $where = "1 = 1"; + my $where = ""; my $glwhere = ""; my $subwhere = ""; my $ARwhere = ""; @@ -678,80 +696,63 @@ sub get_accounts_ustva { AND ac.project_id = $form->{project_id} |; } -######################################### -# Method eq 'cash' = IST Versteuerung -######################################### + ############################################ + # Method eq 'cash' = IST Versteuerung + ############################################ + # Betrifft nur die eingenommene Umsatzsteuer + # + ############################################ if ($form->{method} eq 'cash') { $query = qq| - SELECT - -- 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, - c.pos_ustva - FROM acc_trans ac - JOIN chart c ON (c.id = ac.chart_id) - --JOIN ar ON (ar.id = ac.trans_id) - where - 1=1 - -- Here no where, please. All Transactions ever should be - -- testet if they are paied in the USTVA report period. - GROUP BY c.pos_ustva - - UNION -- alle Ausgaben AP erfassen - - SELECT - sum(ac.amount) AS amount, pos_ustva - FROM acc_trans ac - JOIN AP ON (AP.id = ac.trans_id ) - JOIN chart c ON (c.id = ac.chart_id AND pos_ustva NOT LIKE '') - WHERE - 1=1 - $APwhere - $dpt_where - $project - GROUP BY pos_ustva - - UNION -- alle Ausgaben und Einnahmen direkter gl Buchungen erfassen - - SELECT sum - ( - CASE WHEN c.link LIKE '%AR%' THEN ac.amount * -1 - WHEN c.link LIKE '%AP%' THEN ac.amount * 1 - END - ) AS amount, c.$category - FROM acc_trans ac - JOIN chart c ON (c.id = ac.chart_id) - JOIN gl a ON (a.id = ac.trans_id) - $dpt_join - WHERE $where - $dpt_from - AND NOT (c.link = 'AR' OR c.link = 'AP') - $project - GROUP BY c.$category - |; - - } else { -######################################### -# Method eq 'accrual' = Soll Versteuerung -######################################### + 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 + ######################################### if ($department_id) { $dpt_join = qq| @@ -762,22 +763,91 @@ sub get_accounts_ustva { |; } + $query = qq| - SELECT sum - ( - CASE WHEN c.link LIKE '%AR%' THEN ac.amount * -1 - WHEN c.link LIKE '%AP%' THEN ac.amount * 1 - END - ) AS amount, c.$category - FROM acc_trans ac - JOIN chart c ON (c.id = ac.chart_id) - $dpt_join - WHERE $where - $dpt_where - $project - GROUP BY c.$category - |; + -- 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 + $dpt_where + $project + 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 chart_id=ac.chart_id + --AND taxkey_id=ac.taxkey + AND startdate <= COALESCE(AP.transdate) + ORDER BY startdate DESC LIMIT 1 + ) + ) + WHERE + 1=1 + $APwhere + $dpt_where + $project + GROUP BY tk.pos_ustva + + UNION -- alle Ausgaben und 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 taxkey_id=ac.taxkey + AND startdate <= COALESCE(ac.transdate) + ORDER BY startdate DESC LIMIT 1 + ) + ) + + $dpt_join + WHERE 1 = 1 + $where + $dpt_from + $project + GROUP BY tk.pos_ustva + |; my @accno; my $accno; @@ -788,11 +858,12 @@ sub get_accounts_ustva { $main::lxdebug->message(LXDebug::QUERY, "$callingdetails \$query=\n $query"); my $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); while ($ref = $sth->fetchrow_hashref(NAME_lc)) { -# Bug 365 solved?! - $ref->{amount} *= -1; + # Bug 365 solved?! + $ref->{amount} *= -1; if ($category eq "pos_bwa") { if ($last_period) { $form->{ $ref->{$category} }{kumm} += $ref->{amount}; @@ -803,9 +874,11 @@ sub get_accounts_ustva { $form->{ $ref->{$category} } += $ref->{amount}; } } + $sth->finish; $main::lxdebug->leave_sub(); + }