Steuerkram/migrations/092_afa_storno_fiscal_year_korrektur.sql
fds2610-bot 88d9cc53ff Fix #155: AfA-Buchungen laufen jetzt über Booking::createAfa()/reverseAfa()
AssetController setzte INSERT INTO bookings bislang direkt ab und umging
damit die Sperre des Geschäftsjahres, den transaktionalen Schutz der
Nummernvergabe und ordnete Stornos dem falschen Geschäftsjahr zu.
2026-08-03 22:09:16 +02:00

11 lines
523 B
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 092: Bestandskorrektur – AfA-Stornobuchungen erhalten die
-- fiscal_year_id ihrer Originalbuchung statt des Kalenderjahres der Stornierung.
-- (Fix #155: reverseAfaBooking() verwendete bislang date('Y') statt afa_jahr/
-- fiscal_year_id der stornierten Buchung.)
UPDATE bookings storno
JOIN bookings orig ON orig.reversed_by = storno.id
SET storno.fiscal_year_id = orig.fiscal_year_id
WHERE storno.buchungstyp = 'AfA'
AND storno.is_reversal = 1
AND storno.fiscal_year_id <> orig.fiscal_year_id;