Aufräumskript für Steuerschlüssel 18,19 - Prüfung auf Kontenrahmen
[kivitendo-erp.git] / sql / Pg-upgrade2 / tax_reverse_charge_key_18.sql
1 -- @tag: tax_reverse_charge_key_18
2 -- @description: Reverse Charge für Kreditorenbelege Steuerschlüssel 18
3 -- @depends: release_3_6_0 clean_tax_18_19
4 -- @ignore: 0
5
6 INSERT INTO tax (
7   chart_id,
8   reverse_charge_chart_id,
9   rate,
10   taxkey,
11   taxdescription,
12   chart_categories
13   )
14   SELECT
15   (SELECT id FROM chart WHERE accno = '1572'),
16   (SELECT id FROM chart WHERE accno = '1772'), 0.07,
17   '18', 'Stpf. innergemeinschaftlicher Erwerb zum verminderten Vor- und Ust.-satz', 'EI'
18 WHERE EXISTS ( -- update only for SKR03
19     SELECT coa FROM defaults
20     WHERE defaults.coa='Germany-DATEV-SKR03EU'
21 );
22
23
24 INSERT INTO tax (
25   chart_id,
26   reverse_charge_chart_id,
27   rate,
28   taxkey,
29   taxdescription,
30   chart_categories
31   )
32   SELECT
33   (SELECT id FROM chart WHERE accno = '1402'),
34   (SELECT id FROM chart WHERE accno = '3802'), 0.07,
35   '18', 'Stpf. innergemeinschaftlicher Erwerb zum verminderten Vor- und Ust.-satz', 'EI'
36 WHERE EXISTS ( -- update only for SKR04
37     SELECT coa FROM defaults
38     WHERE defaults.coa='Germany-DATEV-SKR04EU'
39 );
40
41
42 -- if not defined
43 insert into taxkeys(chart_id,tax_id,taxkey_id,startdate) SELECT (SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null),0,0,'1970-01-01' WHERE NOT EXISTS
44   (SELECT chart_id from taxkeys where chart_id = ( SELECT reverse_charge_chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null))
45   AND (EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR04EU') OR EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR03EU'));
46
47 -- if not defined
48 insert into taxkeys(chart_id,tax_id,taxkey_id,startdate) SELECT (SELECT chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null),0,0,'1970-01-01' WHERE NOT EXISTS
49   (SELECT chart_id from taxkeys where chart_id = ( SELECT chart_id FROM tax WHERE taxkey = '18' and rate = 0.07 and reverse_charge_chart_id is not null))
50   AND (EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR04EU') OR EXISTS (SELECT coa FROM defaults WHERE defaults.coa='Germany-DATEV-SKR03EU'));
51