From: Jan Büren Date: Mon, 28 Mar 2022 11:12:37 +0000 (+0200) Subject: Aufräumskript für Steuerschlüssel 18,19 - Prüfung auf Kontenrahmen X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~77 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=51aa7d3ccc53449c3582bae461d567ff2203e964;p=kivitendo-erp.git Aufräumskript für Steuerschlüssel 18,19 - Prüfung auf Kontenrahmen --- diff --git a/sql/Pg-upgrade2/clean_tax_18_19.pl b/sql/Pg-upgrade2/clean_tax_18_19.pl new file mode 100644 index 000000000..e62056707 --- /dev/null +++ b/sql/Pg-upgrade2/clean_tax_18_19.pl @@ -0,0 +1,75 @@ +# @tag: clean_tax_18_19 +# @description: Vorbereitung für neue Steuerschlüssel 18,19 +# @depends: release_3_6_0 +# @ignore: 0 +package SL::DBUpgrade2::clean_tax_18_19; + +use strict; +use utf8; + +use parent qw(SL::DBUpgrade2::Base); + +sub delete_alter_tax { + my $self = shift; + + my $query = <dbh->prepare($query); + my $acc_fetch = $self->dbh->prepare($q_fetch); + my $delete_tk = $self->dbh->prepare($delete_taxkey); + my $delete_t = $self->dbh->prepare($delete_tax); + my $edit_q = $self->dbh->prepare($edit_tax); + + + my $tax_id; + foreach ( qw(18 19) ) { + $h_fetch->execute($_) || $::form->dberror($query); + while (my $entry = $h_fetch->fetchrow_hashref) { + $tax_id = $entry->{id}; + next unless $tax_id; + $edit_q->execute($tax_id) || $::form->dberror($edit_tax); + $acc_fetch->execute($tax_id) || $::form->dberror($q_fetch); + if (!$acc_fetch->fetchrow_hashref) { + $delete_tk->execute($tax_id) || $::form->dberror($delete_tk); + $delete_t ->execute($tax_id) || $::form->dberror($delete_t); + } + } + } +} + +sub run { + my ($self) = @_; + + return 1 unless ($self->check_coa('Germany-DATEV-SKR03EU') ||$self->check_coa('Germany-DATEV-SKR04EU')); + + $self->delete_alter_tax; + + return 1; +} + +1; diff --git a/sql/Pg-upgrade2/tax_reverse_charge_key_18.sql b/sql/Pg-upgrade2/tax_reverse_charge_key_18.sql index 024e7c48d..f67eff3d9 100644 --- a/sql/Pg-upgrade2/tax_reverse_charge_key_18.sql +++ b/sql/Pg-upgrade2/tax_reverse_charge_key_18.sql @@ -1,6 +1,6 @@ -- @tag: tax_reverse_charge_key_18 -- @description: Reverse Charge für Kreditorenbelege Steuerschlüssel 18 --- @depends: release_3_6_0 +-- @depends: release_3_6_0 clean_tax_18_19 -- @ignore: 0 INSERT INTO tax ( @@ -41,8 +41,11 @@ WHERE EXISTS ( -- update only for SKR04 -- if not defined insert into taxkeys(chart_id,tax_id,taxkey_id,startdate) SELECT (SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null),0,0,'1970-01-01' WHERE NOT EXISTS - (SELECT chart_id from taxkeys where chart_id = ( SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null)); + (SELECT chart_id from taxkeys where chart_id = ( SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null)) + AND (EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR04EU') OR EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR03EU')); + -- if not defined insert into taxkeys(chart_id,tax_id,taxkey_id,startdate) SELECT (SELECT chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null),0,0,'1970-01-01' WHERE NOT EXISTS - (SELECT chart_id from taxkeys where chart_id = ( SELECT chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null)); + (SELECT chart_id from taxkeys where chart_id = ( SELECT chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null)) + AND (EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR04EU') OR EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR03EU')); diff --git a/sql/Pg-upgrade2/tax_reverse_charge_key_19.sql b/sql/Pg-upgrade2/tax_reverse_charge_key_19.sql index 33d65048c..c4b4a6872 100644 --- a/sql/Pg-upgrade2/tax_reverse_charge_key_19.sql +++ b/sql/Pg-upgrade2/tax_reverse_charge_key_19.sql @@ -1,6 +1,6 @@ -- @tag: tax_reverse_charge_key_19 -- @description: Reverse Charge für Kreditorenbelege Steuerschlüssel 19 --- @depends: release_3_6_0 +-- @depends: release_3_6_0 clean_tax_18_19 -- @ignore: 0 UPDATE tax set rate=0.19 where taxkey=94 AND reverse_charge_chart_id is not NULL; @@ -56,8 +56,10 @@ WHERE EXISTS ( -- update only for SKR04 -- if not defined insert into taxkeys(chart_id,tax_id,taxkey_id,startdate) SELECT (SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '19' and rate = 0.19 and reverse_charge_chart_id is not null),0,0,'1970-01-01' WHERE NOT EXISTS - (SELECT chart_id from taxkeys where chart_id = ( SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '19' and rate = 0.19 and reverse_charge_chart_id is not null)); + (SELECT chart_id from taxkeys where chart_id = ( SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '19' and rate = 0.19 and reverse_charge_chart_id is not null)) + AND (EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR04EU') OR EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR03EU')); -- if not defined insert into taxkeys(chart_id,tax_id,taxkey_id,startdate) SELECT (SELECT chart_id FROM tax WHERE taxkey = '19' and rate = 0.19 and reverse_charge_chart_id is not null),0,0,'1970-01-01' WHERE NOT EXISTS - (SELECT chart_id from taxkeys where chart_id = ( SELECT chart_id FROM tax WHERE taxkey = '19' and rate = 0.19 and reverse_charge_chart_id is not null)); + (SELECT chart_id from taxkeys where chart_id = ( SELECT chart_id FROM tax WHERE taxkey = '19' and rate = 0.19 and reverse_charge_chart_id is not null)) + AND (EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR04EU') OR EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR03EU'));