DROP VIEW IF EXISTS "view_fibu_bookings_full";

CREATE VIEW "view_fibu_bookings_full" AS
SELECT fibu_bookings.*,
fibu_accountgroupaccounts.accountsystemid,
fibu_accountgroupaccounts.accountclasseid,
fibu_accountclasses.accountclasstype,
fibu_accountgroupaccounts.accountmaingroupid,
fibu_accountgroupaccounts.accountgroupid
FROM fibu_bookings
LEFT JOIN fibu_books ON fibu_books.id = fibu_bookings.bookid
LEFT JOIN fibu_accountgroupaccounts ON fibu_books.accountsystemid = fibu_accountgroupaccounts.accountsystemid AND fibu_accountgroupaccounts.fibuaccountid = fibu_bookings.accountid
LEFT JOIN fibu_accountclasses ON fibu_accountclasses.id = fibu_accountgroupaccounts.accountclasseid