Die Funktion Form::parse_html_template2() in Form::parse_html_template() umbenannt...
[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_template("dbupgrade/units_error", { "message" => $msg }));
15   return 2;
16 }
17
18
19 sub update_steuersaetze_skr03 {
20   my $query;
21
22   $query = "SELECT COUNT(*) FROM chart " .
23     "WHERE accno = '1776'";
24   my ($count) = $dbh->selectrow_array($query);
25
26   if (!$count) {
27     $query =
28       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
29       VALUES ('1776','Umsatzsteuer 19 %', 'A', 'I', 'AR_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 511,6)|;
30     $dbh->do($query) || mydberror($query);
31   }
32   $query = "SELECT COUNT(*) FROM chart " .
33     "WHERE accno = '1576'";
34   my ($count) = $dbh->selectrow_array($query);
35
36   if (!$count) {
37     $query =
38       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
39       VALUES ('1576','Abziehbare Vorsteuer 19 %', 'A', 'E', 'AP_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 66,27)|;
40     $dbh->do($query) || mydberror($query);
41   }
42
43   $query =
44     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='1776'), 0.19, '1776', 3, 'Umsatzsteuer 19%')|;
45   $dbh->do($query) || mydberror($query);
46   $query =
47     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='1576'), 0.19, '1576', 9, 'Vorsteuer 19%')|;
48   $dbh->do($query) || mydberror($query);
49
50   $query =
51     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|;
52   $dbh->do($query) || mydberror($query);
53
54   $query =
55     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|;
56   $dbh->do($query) || mydberror($query);
57
58
59   return 1;
60 }
61
62 sub update_steuersaetze_skr04 {
63   my $query;
64
65   $query = "SELECT COUNT(*) FROM chart " .
66     "WHERE accno = '3806'";
67   my ($count) = $dbh->selectrow_array($query);
68
69   if (!$count) {
70     $query =
71       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
72       VALUES ('3806','Umsatzsteuer 19 %', 'A', 'I', 'AR_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 511,6)|;
73     $dbh->do($query) || mydberror($query);
74   }
75   $query = "SELECT COUNT(*) FROM chart " .
76     "WHERE accno = '1406'";
77   my ($count) = $dbh->selectrow_array($query);
78
79   if (!$count) {
80     $query =
81       qq|INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_ustva, pos_eur)
82       VALUES ('1406','Abziehbare Vorsteuer 19 %', 'A', 'E', 'AP_tax:IC_taxpart:IC_taxservice:CT_tax', 0, 66,27)|;
83     $dbh->do($query) || mydberror($query);
84   }
85
86   $query =
87     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='3806'), 0.19, '3806', 3, 'Umsatzsteuer 19%')|;
88   $dbh->do($query) || mydberror($query);
89   $query =
90     qq|INSERT INTO tax (chart_id, rate, taxnumber, taxkey, taxdescription) VALUES ((SELECT id from CHART WHERE accno='1406'), 0.19, '1406', 9, 'Vorsteuer 19%')|;
91   $dbh->do($query) || mydberror($query);
92
93   $query =
94     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|;
95   $dbh->do($query) || mydberror($query);
96
97   $query =
98     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|;
99   $dbh->do($query) || mydberror($query);
100
101
102   return 1;
103 }
104
105
106 sub update_steuersaetze {
107   my $form = $main::form;
108
109   my $query = "SELECT coa FROM defaults";
110   my ($coa) = $dbh->selectrow_array($query);
111
112   if ($coa eq "Germany-DATEV-SKR03EU") {
113     return update_steuersaetze_skr03();
114
115   } elsif ($coa eq "Germany-DATEV-SKR04EU") {
116     return update_steuersaetze_skr04();
117   }
118
119   print($form->parse_html_template("dbupgrade/std_buchungsgruppen_unknown_coa", { "coa" => $coa }));
120
121   return 1;
122 }
123
124
125
126 return update_steuersaetze();