Revision ee2a0ae9
Von Jan Büren vor fast 3 Jahren hinzugefügt
sql/Pg-upgrade2/delete_wrong_charts_for_taxkeys.pl | ||
---|---|---|
1 |
# @tag: delete_wrong_charts_for_taxkeys |
|
2 |
# @description: Uralte falsch angelegte Automatikkonten raus -> Chance auf tax.chart_id unique setzen |
|
3 |
# @depends: release_3_6_0 |
|
4 |
# @ignore: 0 |
|
5 |
package SL::DBUpgrade2::delete_wrong_charts_for_taxkeys; |
|
6 |
|
|
7 |
use strict; |
|
8 |
use utf8; |
|
9 |
|
|
10 |
use parent qw(SL::DBUpgrade2::Base); |
|
11 |
|
|
12 |
sub delete_chart_id_tax { |
|
13 |
my $self = shift; |
|
14 |
|
|
15 |
my $q_fetch = <<SQL; |
|
16 |
SELECT chart_id |
|
17 |
FROM tax where chart_id is not null |
|
18 |
GROUP BY chart_id HAVING COUNT(*) > 1 |
|
19 |
SQL |
|
20 |
|
|
21 |
# skr03 |
|
22 |
my $q_update = <<SQL; |
|
23 |
UPDATE tax |
|
24 |
SET chart_id = NULL |
|
25 |
WHERE chart_id = ? |
|
26 |
AND rate = 0.16 |
|
27 |
AND (taxkey = 19 OR taxkey = 13) |
|
28 |
AND EXISTS (SELECT * FROM defaults WHERE coa = 'Germany-DATEV-SKR03EU') |
|
29 |
SQL |
|
30 |
|
|
31 |
my $h_fetch = $self->dbh->prepare($q_fetch); |
|
32 |
$h_fetch->execute || $::form->dberror($q_fetch); |
|
33 |
|
|
34 |
my $h_update_03 = $self->dbh->prepare($q_update); |
|
35 |
|
|
36 |
while (my $entry = $h_fetch->fetchrow_hashref) { |
|
37 |
$h_update_03->execute($entry->{chart_id}) || $::form->dberror($q_update); |
|
38 |
} |
|
39 |
# might be unique now |
|
40 |
$h_fetch->execute || $::form->dberror($q_fetch); |
|
41 |
|
|
42 |
if (!$h_fetch->fetchrow_hashref) { |
|
43 |
my $q_unique = <<SQL; |
|
44 |
alter table tax |
|
45 |
ADD CONSTRAINT chart_id_unique_tax UNIQUE (chart_id) |
|
46 |
SQL |
|
47 |
my $q_unique_p = $self->dbh->prepare($q_unique); |
|
48 |
$q_unique_p->execute || $::form->dberror($q_unique_p); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
sub run { |
|
53 |
my ($self) = @_; |
|
54 |
|
|
55 |
return 1 unless $self->check_coa('Germany-DATEV-SKR03EU'); |
|
56 |
|
|
57 |
$self->delete_chart_id_tax; |
|
58 |
|
|
59 |
return 1; |
|
60 |
} |
|
61 |
|
|
62 |
1; |
sql/Pg-upgrade2/delete_wrong_charts_for_taxkeys_04.pl | ||
---|---|---|
1 |
# @tag: delete_wrong_charts_for_taxkeys_04 |
|
2 |
# @description: SKR04: Uralte falsch angelegte Automatikkonten raus -> Chance auf tax.chart_id unique setzen |
|
3 |
# @depends: release_3_6_0 |
|
4 |
# @ignore: 0 |
|
5 |
package SL::DBUpgrade2::delete_wrong_charts_for_taxkeys_04; |
|
6 |
|
|
7 |
use strict; |
|
8 |
use utf8; |
|
9 |
|
|
10 |
use parent qw(SL::DBUpgrade2::Base); |
|
11 |
|
|
12 |
sub delete_chart_id_tax { |
|
13 |
my $self = shift; |
|
14 |
|
|
15 |
my $q_fetch = <<SQL; |
|
16 |
SELECT chart_id |
|
17 |
FROM tax where chart_id is not null |
|
18 |
GROUP BY chart_id HAVING COUNT(*) > 1 |
|
19 |
SQL |
|
20 |
|
|
21 |
# SKR04 |
|
22 |
my $q_update_04 = <<SQL; |
|
23 |
UPDATE tax |
|
24 |
SET chart_id = NULL |
|
25 |
WHERE chart_id = ? |
|
26 |
AND rate = 0.16 |
|
27 |
AND (taxkey = 3 OR taxkey = 9) |
|
28 |
AND EXISTS (SELECT * FROM defaults WHERE coa = 'Germany-DATEV-SKR04EU') |
|
29 |
SQL |
|
30 |
|
|
31 |
|
|
32 |
my $h_fetch = $self->dbh->prepare($q_fetch); |
|
33 |
$h_fetch->execute || $::form->dberror($q_fetch); |
|
34 |
|
|
35 |
my $h_update_04 = $self->dbh->prepare($q_update_04); |
|
36 |
|
|
37 |
while (my $entry = $h_fetch->fetchrow_hashref) { |
|
38 |
$h_update_04->execute($entry->{chart_id}) || $::form->dberror($q_update_04); |
|
39 |
} |
|
40 |
# might be unique now |
|
41 |
$h_fetch->execute || $::form->dberror($q_fetch); |
|
42 |
|
|
43 |
if (!$h_fetch->fetchrow_hashref) { |
|
44 |
my $q_unique = <<SQL; |
|
45 |
alter table tax |
|
46 |
ADD CONSTRAINT chart_id_unique_tax UNIQUE (chart_id) |
|
47 |
SQL |
|
48 |
my $q_unique_p = $self->dbh->prepare($q_unique); |
|
49 |
$q_unique_p->execute || $::form->dberror($q_unique_p); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
sub run { |
|
54 |
my ($self) = @_; |
|
55 |
|
|
56 |
return 1 unless $self->check_coa('Germany-DATEV-SKR04EU'); |
|
57 |
|
|
58 |
$self->delete_chart_id_tax; |
|
59 |
|
|
60 |
return 1; |
|
61 |
} |
|
62 |
|
|
63 |
1; |
Auch abrufbar als: Unified diff
SKR03/SKR04 Entfernt ggf. uralte falsch verknüpfte Automatikkonten
Laut der DATEV Steuerschlüssel Spezifikation darf es ferner
auch kein Automatik-Konto mehrfach bei Steuerschlüssel verwendet werden.
kivi erlaubt das schon immer, falls möglich setzt das skript den
Wert auf unique