Steuerkram/migrations/048_ustva_kz_neustrukturierung.sql

23 lines
1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Migration 048: UStVA-Kennzahlen auf neues 5-Kz-Schema umstellen.
--
-- Neues Schema:
-- Kz 81 – Steuerpflichtige Umsätze 19 % (Konten mit ustva_kz='81', unverändert)
-- Kz 89 – ig. Erwerbe 19 % Bemessungsgrundlage (steuerart-basiert, kein Konto)
-- Kz 66 – Gesamte Vorsteuerbeträge (Konten 1571, 1576)
-- Kz 61 – Vorsteuerbeträge ig. Erwerb (Konto 1574)
-- Kz 83 – Vorauszahlung / Überschuss = (Konten 1771+1774+1776) - Kz66 - Kz61
--
-- Alle anderen ustva_kz-Werte werden auf NULL gesetzt.
-- Schritt 1: Alles auf NULL setzen, was nicht '81' oder '83' ist
-- (81 bleibt, 83 bleibt für die USt-Konten)
UPDATE accounts SET ustva_kz = NULL
WHERE ustva_kz IS NOT NULL
AND ustva_kz NOT IN ('81', '83');
-- Schritt 2: Vorsteuerkonten zuordnen
UPDATE accounts SET ustva_kz = '66' WHERE kontonummer IN ('1571', '1576');
UPDATE accounts SET ustva_kz = '61' WHERE kontonummer = '1574';
-- Schritt 3: Fehlende USt-Konten auf Kz 83 setzen (1776 hat bereits '83')
UPDATE accounts SET ustva_kz = '83' WHERE kontonummer IN ('1771', '1774');