create or replace view zahlung_forderung_v1 as
    select 
        'zahlung' as zf_type,
        datum_soll,
        datum_ist,
        id,
        betrag as betrag_zahlung,
        '-' as betrag_forderung,
        kommentar,
        mieter
    from zahlung
    union
    select 
        'forderung' as zf_type,
        datum as datum_soll,
        '-' as datum_ist,
        id,
        '-' as betrag_zahlung,
        betrag as betrag_forderung,
        kommentar,
        mieter
    from forderung;

create or replace view zahlung_forderung as
    select
        *
    from zahlung_forderung_v1
    order by datum_soll;


grant select on zahlung_forderung to 'hausverwaltung-ui'@'%';
