account entry reference stuff
This commit is contained in:
@ -93,7 +93,21 @@ CREATE OR REPLACE FUNCTION maintain_ledger()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
tenant RECORD;
|
||||
adjusted_description text;
|
||||
BEGIN
|
||||
IF ((NEW.description = 'Miete') AND (NEW.account_entry_category = 2)) THEN
|
||||
SELECT firstname, lastname
|
||||
INTO tenant
|
||||
FROM tenant_t
|
||||
WHERE account = NEW.account;
|
||||
adjusted_description := 'Miete ' || extract(year from NEW.created_at)::text || ' ' || to_char(to_date(extract(month from NEW.created_at)::text, 'MM'), 'Month') || tenant.firstname || ' ' || tenant.lastname;
|
||||
UPDATE account_entry_t
|
||||
SET description = adjusted_description
|
||||
WHERE id = NEW.id;
|
||||
END IF;
|
||||
|
||||
INSERT INTO account_entry_reference_t (account, account_entry) VALUES (1000, NEW.id);
|
||||
RETURN NEW;
|
||||
END;
|
||||
|
Reference in New Issue
Block a user