hitobito-kjv/app/domain/kjv/membership_fee_payment.rb
Stefan Hofmann 8f305a2c14 Kontoimport mit hitobito_banking_de, Version 0.5.0 🤖
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 12:09:44 +02:00

57 lines
2.1 KiB
Ruby

# frozen_string_literal: true
# Copyright (c) 2026, Kreisjagdverband Bautzen e.V. This file is part of
# hitobito_kjv and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory.
# Verbindung zum Kontoimport (hitobito_banking_de): Eine bestätigte Beitragszahlung setzt
# "Beitrag bezahlt bis", eine Rücklastschrift setzt es zurück. Jede Änderung wird in der
# Zuordnung festgehalten (effect), damit sie beim Zurücknehmen rückgängig gemacht werden
# kann.
#
# - Zahlung für das Folgejahr des bisherigen Stands (oder erster Eintrag): Stand = Jahr
# - Zahlung für ein schon bezahltes Jahr: keine Änderung
# - Zahlung mit Lücke (z. B. bezahlt bis 2024, Zahlung für 2026): keine Änderung, damit
# das offene Jahr nicht verdeckt wird; der Stand muss von Hand geprüft werden
# - Rücklastschrift für ein Jahr <= Stand: Stand = Jahr - 1
module Kjv::MembershipFeePayment
module_function
def apply(allocation)
person = allocation.person
before = person.beitrag_bezahlt_bis
after = allocation.amount.negative? ? returned(before, allocation.year) : paid(before, allocation.year)
update(person, after) if after != before
{"before" => before, "after" => after, "gap" => gap?(before, allocation)}.compact
end
def revert(allocation)
effect = allocation.effect || {}
person = allocation.person
return if effect["before"] == effect["after"]
# Nur zurücksetzen, wenn seither niemand den Stand geändert hat
return unless person.beitrag_bezahlt_bis == effect["after"]
update(person, effect["before"])
end
def paid(before, year)
return year if before.nil? || year == before + 1
before
end
def returned(before, year)
(before && before >= year) ? year - 1 : before
end
def gap?(before, allocation)
true if !allocation.amount.negative? && before && allocation.year > before + 1
end
def update(person, year)
person.beitrag_bezahlt_bis = year
# Wie bei der Massenbearbeitung: Altdaten sollen nicht blockieren, PaperTrail protokolliert
person.save(validate: false)
end
end