9a8542a3699c3cc2cee1bb2b3a705029ccbe61ee
[kivitendo-erp.git] / sql / Pg-upgrade / Pg-upgrade-2.2.0.31-2.2.0.32.pl
1 #!/usr/bin/perl
2
3 die("This script cannot be run from the command line.") unless ($main::form);
4
5 sub mydberror {
6   my ($msg) = @_;
7   die($dbup_locale->text("Database update error:") .
8       "<br>$msg<br>" . $DBI::errstr);
9 }
10
11 sub myshowerror {
12   my ($msg) = @_;
13
14   print($main::form->parse_html_template2("dbupgrade/units_error",
15                                           { "message" => $msg }));
16   return 2;
17 }
18
19
20 sub update_steuersaetze_skr03 {
21   my $query;
22
23   $query = "SELECT COUNT(*) FROM chart " .
24     "WHERE accno = '1776'";
25   my ($count) = $dbh->selectrow_array($query);
26
27   if (!$count) {
28     $query =
29       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
30       VALUES ('1776','Umsatzsteuer 19 %', 'A', 'I', 'AR_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 511,6)|;
31     $dbh->do($query) || mydberror($query);
32   }
33   $query = "SELECT COUNT(*) FROM chart " .
34     "WHERE accno = '1576'";
35   my ($count) = $dbh->selectrow_array($query);
36
37   if (!$count) {
38     $query =
39       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
40       VALUES ('1576','Abziehbare Vorsteuer 19 %', 'A', 'E', 'AP_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 66,27)|;
41     $dbh->do($query) || mydberror($query);
42   }
43
44   $query =
45     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='1776'), 0.19, '1776', 3, 'Umsatzsteuer 19%')|;
46   $dbh->do($query) || mydberror($query);
47   $query =
48     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='1576'), 0.19, '1576', 9, 'Vorsteuer 19%')|;
49   $dbh->do($query) || mydberror($query);
50
51   $query =
52     qq|insert into taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) select chart.id, (SELECT id from tax where taxdescription='Umsatzsteuer 19%'), 3, pos_ustva, '2007-01-01' from chart WHERE taxkey_id=3|;
53   $dbh->do($query) || mydberror($query);
54
55   $query =
56     qq|insert into taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) select chart.id, (SELECT id from tax where taxdescription='Vorsteuer 19%'), 9, pos_ustva, '2007-01-01' from chart WHERE taxkey_id=9|;
57   $dbh->do($query) || mydberror($query);
58
59
60   return 1;
61 }
62
63 sub update_steuersaetze_skr04 {
64   my $query;
65
66   $query = "SELECT COUNT(*) FROM chart " .
67     "WHERE accno = '3806'";
68   my ($count) = $dbh->selectrow_array($query);
69
70   if (!$count) {
71     $query =
72       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
73       VALUES ('3806','Umsatzsteuer 19 %', 'A', 'I', 'AR_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 511,6)|;
74     $dbh->do($query) || mydberror($query);
75   }
76   $query = "SELECT COUNT(*) FROM chart " .
77     "WHERE accno = '1406'";
78   my ($count) = $dbh->selectrow_array($query);
79
80   if (!$count) {
81     $query =
82       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
83       VALUES ('1406','Abziehbare Vorsteuer 19 %', 'A', 'E', 'AP_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 66,27)|;
84     $dbh->do($query) || mydberror($query);
85   }
86
87   $query =
88     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='3806'), 0.19, '3806', 3, 'Umsatzsteuer 19%')|;
89   $dbh->do($query) || mydberror($query);
90   $query =
91     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='1406'), 0.19, '1406', 9, 'Vorsteuer 19%')|;
92   $dbh->do($query) || mydberror($query);
93
94   $query =
95     qq|insert into taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) select chart.id, (SELECT id from tax where taxdescription='Umsatzsteuer 19%'), 3, pos_ustva, '2007-01-01' from chart WHERE taxkey_id=3|;
96   $dbh->do($query) || mydberror($query);
97
98   $query =
99     qq|insert into taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) select chart.id, (SELECT id from tax where taxdescription='Vorsteuer 19%'), 9, pos_ustva, '2007-01-01' from chart WHERE taxkey_id=9|;
100   $dbh->do($query) || mydberror($query);
101
102
103   return 1;
104 }
105
106
107 sub update_steuersaetze {
108   my $form = $main::form;
109
110   my $query = "SELECT coa FROM defaults";
111   my ($coa) = $dbh->selectrow_array($query);
112
113   if ($coa eq "Germany-DATEV-SKR03EU") {
114     return update_steuersaetze_skr03();
115
116   } elsif ($coa eq "Germany-DATEV-SKR04EU") {
117     return update_steuersaetze_skr04();
118   }
119
120   print($form->parse_html_template2("dbupgrade/std_buchungsgruppen_unknown_coa", { "coa" => $coa }));
121
122   return 1;
123 }
124
125
126
127 return update_steuersaetze();