Revision acca1e1b
Von Jan Büren vor mehr als 14 Jahren hinzugefügt
sql/Pg-upgrade2/rundungsfehler_korrigieren_BUG1328.pl | ||
---|---|---|
1 |
# @tag: rundungsfehler_korrigieren_BUG1328-2 |
|
2 |
# @description: Die entsprechende Cent-Abweichung die durch den Rundungsfehler in Bug 1328 behoben wurde, entsprechende für alte Buchungen korrigieren. |
|
3 |
# @depends: release_2_6_0 |
|
4 |
# @charset: utf-8 |
|
5 |
|
|
6 |
use strict; |
|
7 |
use Data::Dumper; |
|
8 |
die("This script cannot be run from the command line.") unless ($main::form); |
|
9 |
|
|
10 |
sub mydberror { |
|
11 |
my ($msg) = @_; |
|
12 |
die($dbup_locale->text("Database update error:") . |
|
13 |
"<br>$msg<br>" . $DBI::errstr); |
|
14 |
} |
|
15 |
|
|
16 |
sub do_query { |
|
17 |
my ($query, $may_fail) = @_; |
|
18 |
|
|
19 |
if (!$dbh->do($query)) { |
|
20 |
mydberror($query) unless ($may_fail); |
|
21 |
$dbh->rollback(); |
|
22 |
$dbh->begin_work(); |
|
23 |
} |
|
24 |
} |
|
25 |
|
|
26 |
sub do_update { |
|
27 |
my @queries; |
|
28 |
|
|
29 |
|
|
30 |
my $query = qq|select distinct id,acamount from (select ap.id,ap.amount as apamount, ac.amount*-1 as acamount from ap left join acc_trans ac on (ac.trans_id = |
|
31 |
ap.id) where ac.chart_id IN (select id from chart where link ='AP' OR link like '%:AP' OR link like 'AP:%')) as foo where apamount + 0.01 = abs(acamount)|; |
|
32 |
my $sth_all_groups = prepare_execute_query($form, $dbh, $query); |
|
33 |
while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife |
|
34 |
push @queries, "UPDATE ap set amount =" . $hash_ref->{acamount} . " WHERE id = " . $hash_ref->{id}; |
|
35 |
} |
|
36 |
$sth_all_groups->finish(); |
|
37 |
|
|
38 |
|
|
39 |
my $query = qq|select distinct id,acamount from (select ar.id, ar.amount as aramount, ac.amount*-1 as acamount from ar left join acc_trans ac on (ac.trans_id = |
|
40 |
ar.id) where ac.chart_id IN (select id from chart where link ='AR' OR link like '%:AR' OR link like 'AR:%')) as foo where aramount + 0.01 = abs(acamount)|; |
|
41 |
my $sth_all_groups = prepare_execute_query($form, $dbh, $query); |
|
42 |
while (my $hash_ref = $sth_all_groups->fetchrow_hashref()) { # Schleife |
|
43 |
# Falls wir keine alte buggy Installation haben, ist es super die |
|
44 |
# Gewissheit zu haben, dass kein acc_trans-Eintrag ohne trans_id vorhanden ist |
|
45 |
push @queries, "UPDATE ar set amount =" . $hash_ref->{acamount} . " WHERE id = " . $hash_ref->{id}; |
|
46 |
} |
|
47 |
$sth_all_groups->finish(); |
|
48 |
|
|
49 |
# if in doubt use brute force ;-) jb |
|
50 |
foreach my $query (@queries){ |
|
51 |
my $sth = prepare_query($form, $dbh, $query); |
|
52 |
do_statement($form,$sth,$query); |
|
53 |
$sth->finish(); |
|
54 |
} |
|
55 |
$dbh ->commit(); |
|
56 |
return 1; |
|
57 |
} |
|
58 |
|
|
59 |
return do_update(); |
|
60 |
|
Auch abrufbar als: Unified diff
Entsprechendes DB-Skript um den Rundungsfehler von 1 Cent in Bug 1328 zu korrigieren