Revision a05cda74
Von G. Richardson vor mehr als 4 Jahren hinzugefügt
sql/Pg-upgrade2/konjunkturpaket_2020_SKR04.sql | ||
---|---|---|
3 | 3 |
-- @depends: release_3_5_5 |
4 | 4 |
-- @ignore: 0 |
5 | 5 |
|
6 |
-- TODO: |
|
7 |
-- how to deal with old 16% charts in SKR03? |
|
8 |
-- A) move to their correct taxkeys, 5 and 8, like for SKR04 |
|
9 |
-- and then create new versions of 3 and 9 with same taxkey |
|
10 |
-- UST 5%, already exists in SKR03, so rename it, but also add new taxkeys |
|
11 |
|
|
12 |
|
|
13 | 6 |
DO $$ |
14 | 7 |
BEGIN |
15 | 8 |
|
16 | 9 |
IF ( select coa from defaults ) = 'Germany-DATEV-SKR04EU' THEN |
17 | 10 |
|
18 |
-- DEBUG |
|
19 |
|
|
11 |
-- charts 1403 und 3803 for 5% taxes already existed, reconfigure them |
|
20 | 12 |
UPDATE chart set description = 'Abziehbare Vorsteuer 5 %', taxkey_id = 8 where accno = '1403' and description = 'Abziehbare Vorsteuer aus innergemeinschftl. Erwerb 16%'; |
21 |
|
|
22 | 13 |
UPDATE chart set description = 'Umsatzsteuer 5 %', taxkey_id = 2 where accno = '3803' and description = 'Umsatzsteuer aus innergemeinschftl. Erwerb 16%'; |
23 | 14 |
|
24 |
-- create new chart for Abziehbare Vorsteuer 5 % with taxkey 8 |
|
25 |
-- INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_bwa, pos_bilanz, pos_eur, datevautomatik, pos_er) |
|
26 |
-- VALUES ('1403','Abziehbare Vorsteuer 5 %','A', 'E', 'AP_tax:IC_taxpart:IC_taxservice', 8, null, null, 27, 'f', 27); |
|
27 |
|
|
28 |
UPDATE tax SET taxdescription = 'OLD ' || taxdescription WHERE (taxkey = 5 or taxkey = 7); -- and rate = 0.16; |
|
15 |
-- DEBUG |
|
16 |
-- UPDATE tax SET taxdescription = 'OLD ' || taxdescription WHERE (taxkey = 5 or taxkey = 7); -- and rate = 0.16; |
|
29 | 17 |
|
30 | 18 |
UPDATE taxkeys SET tax_id = (SELECT id FROM tax WHERE taxkey = 5 and rate = 0.16) |
31 | 19 |
WHERE chart_id = (SELECT id FROM chart where accno = '4400') |
32 | 20 |
AND startdate = '1970-01-01'; |
33 | 21 |
|
34 |
-- rename charts if they weren't 't already changed |
|
35 |
-- UPDATE chart SET description = 'Erlöse 19 % / 16 % USt' where accno = '8400' and description = 'Erlöse 16%/19% USt.'; |
|
36 |
-- UPDATE chart SET description = 'Erlöse 7 % / 5 % USt' where accno = '8300' and description = 'Erlöse 7%USt'; |
|
37 |
|
|
38 |
-- move old 16% taxkeys to their proper taxkeys, should be 5 and 7 |
|
39 |
-- UPDATE tax SET taxkey = 5 WHERE taxkey = 3 and rate = 0.16; |
|
40 |
-- UPDATE tax SET taxkey = 7 WHERE taxkey = 9 and rate = 0.16; |
|
41 |
|
|
42 |
|
|
43 | 22 |
-- new charts for 5% |
23 |
-- 4732 and 5732 |
|
44 | 24 |
INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_bwa, pos_bilanz, pos_eur, datevautomatik) |
45 | 25 |
VALUES ('4732','Gewährte Skonti 5 % USt','A', 'I', 'AR_paid', 2, 1, null, 1, 't'); |
46 | 26 |
INSERT INTO chart (accno, description, charttype, category, link, taxkey_id, pos_bwa, pos_bilanz, pos_eur, datevautomatik) |
47 | 27 |
VALUES ('5732','Erhaltene Skonti 5 % Vorsteuer','A', 'E', 'AP_paid', 8, 4, null, null, 't'); |
48 | 28 |
|
49 |
|
|
50 |
-- SKR03 |
|
51 |
-- datev reactivated the previously reserved chart 1775 in 2020, but it still exists in kivitendo (at least for SKR03) with a taxkey starting from 2007 and pointing to the existing automatic tax chart 1775 |
|
52 |
-- so we don't need to to anything! |
|
53 |
-- 3 | 0.16000 | Umsatzsteuer | 1775 | Umsatzsteuer 16% |
|
54 |
|
|
55 |
-- rename old 8735 to 8736 |
|
56 |
-- UPDATE chart SET accno = '8736', description = 'Gewährte Skonti 19 % USt' where accno = '8735' and description = 'Gewährte Skonti 16%/19% USt.'; |
|
57 |
-- create new 8735 with 16% |
|
58 |
|
|
59 |
-- create new 16% chart for Gewährte Skonti |
|
60 |
INSERT INTO chart(accno, description, charttype, category, link, taxkey_id, pos_bwa, pos_bilanz, pos_eur, datevautomatik, pos_er) |
|
61 |
VALUES ('8735','Gewährte Skonti 16 % USt', 'A', 'I', 'AR_paid', 3, 1, null, 1, 't', 1); |
|
62 |
|
|
29 |
-- Gewährte and Erhaltene Skonti 16% already exist, but rename them |
|
30 |
UPDATE chart SET description = 'Gewährte Skonti 16%' where accno = '4735' and description = 'Gewährte Skonti 16%/19% USt'; |
|
31 |
UPDATE chart SET description = 'Erhaltene Skonti 16%' where accno = '4735' and description = 'Erhaltene Skonti 16%/19% USt'; |
|
63 | 32 |
|
64 | 33 |
-- taxkeys can't be inserted until the new taxes exist |
65 |
|
|
66 | 34 |
INSERT INTO tax (chart_id, rate, taxkey, taxdescription, chart_categories, skonto_sales_chart_id, skonto_purchase_chart_id) |
67 | 35 |
VALUES ( (select id from chart where accno = '3803'), 0.05, 2, 'Umsatzsteuer', 'I', (select id from chart where accno = '4732'), null), -- ok |
68 | 36 |
( (select id from chart where accno = '3805'), 0.16, 3, 'Umsatzsteuer', 'I', (select id from chart where accno = '4735'), null), |
69 | 37 |
( (select id from chart where accno = '1405'), 0.16, 9, 'Vorsteuer', 'E', null, (select id from chart where accno = '5735')), |
70 | 38 |
( (select id from chart where accno = '1403'), 0.05, 8, 'Vorsteuer', 'E', null, (select id from chart where accno = '5732')); |
71 | 39 |
|
72 |
-- UPDATE tax SET skonto_sales_chart_id = (select id from chart where accno = '8735') where taxkey = 3 and rate = 0.16 and skonto_sales_chart_id is null; |
|
73 |
|
|
74 | 40 |
-- new taxkeys for 5% and 16% only need one startdate, not valid before and won't change back to anything later |
75 | 41 |
-- these taxkeys won't be valid on 2020-06-30, so won't be affected later by big taxkeys update |
42 |
-- 4732 and 5732 |
|
76 | 43 |
INSERT INTO taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) |
77 | 44 |
VALUES ( (select id from chart where accno = '4732'), |
78 |
( select id from tax where rate = 0.05 and taxkey = 2 and chart_id = (select id from chart where accno = '3803')), 2, 861, '2020-07-01'); -- is ustva correct?
|
|
45 |
( select id from tax where rate = 0.05 and taxkey = 2 and chart_id = (select id from chart where accno = '3803')), 2, 861, '2020-07-01'); -- ustva_id like 3801, is this correct?
|
|
79 | 46 |
|
80 | 47 |
INSERT INTO taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) |
81 | 48 |
VALUES ( (select id from chart where accno = '5732'), |
82 |
(select id from tax where rate = 0.05 and taxkey = 8 and chart_id = (select id from chart where accno = '1403')), 8, 861, '2020-07-01'); -- is ustva correct? |
|
83 |
-- INSERT INTO taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) |
|
84 |
-- VALUES ( (select id from chart where accno = '8735'), (select id from tax where rate = 0.16 and taxkey = 3 and chart_id = (select id from chart where accno = '1775')), 3, 81, '2020-07-01'); |
|
85 |
|
|
86 |
-- INSERT INTO taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) |
|
87 |
-- VALUES ( (select id from chart where accno = '8400'), (select id from tax where rate = 0.16 and taxkey = 3 and chart_id = (select id from chart where accno = '1775')), 3, 81, '2020-07-01'); -- is 81 correct, or 51? |
|
88 |
|
|
89 |
-- INSERT INTO taxkeys (chart_id, tax_id, taxkey_id, pos_ustva, startdate) |
|
90 |
-- VALUES ( (select id from chart where accno = '8400'), (select id from tax where rate = 0.19 and taxkey = 3 and chart_id = (select id from chart where accno = '1776')), 3, 81, '2021-01-01'); |
|
49 |
(select id from tax where rate = 0.05 and taxkey = 8 and chart_id = (select id from chart where accno = '1403')), 8, 66, '2020-07-01'); -- ustva_id like 1401, is this correct? |
|
91 | 50 |
|
92 | 51 |
-- the taxkeys for the existing charts will be updated in a later update |
93 | 52 |
END IF; |
94 | 53 |
|
95 | 54 |
END $$; |
96 |
|
|
97 |
|
|
98 |
-- do the same for all other accounts linked to 9 |
|
99 |
|
|
100 |
|
|
101 |
-- select t.taxkey, |
|
102 |
-- t.rate, |
|
103 |
-- t.taxdescription, |
|
104 |
-- c.accno, |
|
105 |
-- c.description |
|
106 |
-- from tax t |
|
107 |
-- left join chart c on (c.id = t.chart_id) |
|
108 |
-- ; |
|
109 |
-- taxkey | rate | taxdescription | accno | description |
|
110 |
-- --------+---------+--------------------------------------------------------------+-------+-------------------------------------------------------- |
|
111 |
-- 8 | 0.07000 | Vorsteuer | 1401 | Abziehbare Vorsteuer 7% |
|
112 |
-- 18 | 0.07000 | Steuerpflichtiger innergem. Erwerb zum ermäßigten Steuersatz | 1402 | Abziehbare Vorsteuer aus innergemeinschftl. Erwerb |
|
113 |
-- 17 | 0.16000 | Steuerpflicht. EG-Erwerb | 1403 | Abziehbare Vorsteuer aus innergemeinschftl. Erwerb 16% |
|
114 |
-- 19 | 0.19000 | Steuerpflichtiger innergem. Erwerb zum vollen Steuersatz | 1404 | Abziehbare Vorsteuer aus innergemeinschftl. Erwerb 19% |
|
115 |
-- 7 | 0.16000 | Vorsteuer | 1405 | Abziehbare Vorsteuer 16% |
|
116 |
-- 9 | 0.19000 | Vorsteuer | 1406 | Abziehbare Vorsteuer 19 % |
|
117 |
-- 9 | 0.19000 | Vorsteuer | 1406 | Abziehbare Vorsteuer 19 % |
|
118 |
-- 2 | 0.07000 | Umsatzsteuer | 3801 | Umsatzsteuer 7% |
|
119 |
-- 12 | 0.07000 | Steuerpflichtige EG-Lieferung zum ermäßigten Steuersatz | 3802 | Umsatzsteuer aus innergemeinschftl. Erwerb |
|
120 |
-- 15 | 0.16000 | Steuerpflicht. EG-Lieferungen% | 3803 | Umsatzsteuer aus innergemeinschftl. Erwerb 16% |
|
121 |
-- 13 | 0.19000 | Steuerpflichtige EG-Lieferung zum vollen Steuersatz | 3804 | Umsatzsteuer aus innergemeinschftl. Erwerb 19% |
|
122 |
-- 5 | 0.16000 | Umsatzsteuer | 3805 | Umsatzsteuer 16% |
|
123 |
-- 3 | 0.19000 | Umsatzsteuer | 3806 | Umsatzsteuer 19% |
|
124 |
-- 3 | 0.19000 | Umsatzsteuer | 3806 | Umsatzsteuer 19% |
|
125 |
-- 1 | 0.00000 | USt-frei | ☠ | ☠ |
|
126 |
-- 11 | 0.00000 | Steuerfreie innergem. Lieferung an Abnehmer mit Id.-Nr. | ☠ | ☠ |
|
127 |
-- 0 | 0.00000 | Keine Steuer | ☠ | ☠ |
|
128 |
-- 10 | 0.00000 | Im anderen EU-Staat steuerpflichtige Lieferung | ☠ | ☠ |
Auch abrufbar als: Unified diff
Konjunkturpaket - SKR04 überarbeitet