Projekt

Allgemein

Profil

Fehler #431 » remove_double_tax_entries_skr04.pl

Bernd Bleßmann, 30.06.2020 13:46

 
1
# @tag: remove_double_tax_entries_skr04
2
# @description: doppelte Steuer-Einträge für SKR04 entfernen, wenn unbebucht
3
# @depends: release_3_5_5
4
package SL::DBUpgrade2::remove_double_tax_entries_skr04;
5

    
6
use strict;
7
use utf8;
8

    
9
use parent qw(SL::DBUpgrade2::Base);
10

    
11
use SL::DBUtils;
12

    
13
sub run {
14
  my ($self) = @_;
15

    
16
  if (!$self->check_coa('Germany-DATEV-SKR04EU')) {
17
    return 1;
18
  }
19

    
20
  my $query = <<SQL;
21
    SELECT id FROM tax WHERE chart_id = (SELECT id FROM chart WHERE accno LIKE ?) AND taxkey = ? AND rate = ? ORDER BY id;
22
SQL
23

    
24
  my $query2 = <<SQL;
25
    DELETE FROM taxkeys WHERE tax_id = ?;
26
SQL
27

    
28
  my $query3 = <<SQL;
29
    DELETE FROM tax WHERE id = ?;
30
SQL
31

    
32
  my @taxes_to_test = (
33
    {accno => '3806', taxkey => 3, rate => 0.19},
34
    {accno => '1406', taxkey => 9, rate => 0.19},
35
  );
36

    
37
  foreach my $tax_to_test (@taxes_to_test) {
38
    my @entries = selectall_hashref_query($::form, $self->dbh, $query, ($tax_to_test->{accno}, $tax_to_test->{taxkey}, $tax_to_test->{rate}));
39

    
40
    if (scalar @entries > 1) {
41
      foreach my $tax (@entries) {
42
        my ($num_acc_trans_entries) = $self->dbh->selectrow_array("SELECT COUNT(*) FROM acc_trans WHERE tax_id = ?", undef, $tax->{id});
43
        next if $num_acc_trans_entries > 0;
44

    
45
        $self->db_query($query2, bind => [ $tax->{id} ]);
46
        $self->db_query($query3, bind => [ $tax->{id} ]);
47

    
48
        last; # delete only one tax
49
      }
50
    }
51
  }
52

    
53
  return 1;
54
}
55

    
56
1;
(2-2/2)