GL Rules & Bank rules
So eventhough Yuki has these as seperate entities, i cannot right now see why this is a better design, so we will just beef up our GL_RULES to be able to deal with both
Heres a snapshot from the appix domain from Yuki
Processing = Automatic
-
Criteria:
-
Bank statement type = Bankafschrift
-
Transaction type = All types
-
Counterparty account =
NL20INGB0103490124 -
All amounts
-
-
Action when matched:
-
Book automatically on Grootboekrekening 05106 (Privéopnamen Niloufar Heydari)
-
Linked to relation: Niloufar Heydari
-
Example of a gl_rule that mutates into this rule
INSERT INTO public.gl_rules (
company_id,
company_coa_profile_id,
priority,
condition_json,
debit_gl_account,
credit_gl_account,
contact_id
)
SELECT
'00000000-0000-0000-0000-000000000001', -- your company_id
'11111111-1111-1111-1111-111111111111', -- profile_id (RGS 3.7 NL)
10,
jsonb_build_object(
'iban_counterparty',
'NL20INGB0103490124',
'transaction_type',
'ALL'
),
(
SELECT gl_account_id
FROM gl_accounts
WHERE code = '05106'
AND company_coa_profile_id = '11111111-1111-1111-1111-111111111111'
),
(
SELECT gl_account_id
FROM gl_accounts
WHERE code = '11000'
AND company_coa_profile_id = '11111111-1111-1111-1111-111111111111'
),
(
SELECT contact_id
FROM contacts
WHERE name = 'Niloufar Heydari'
LIMIT 1
);
-
Any transaction with counterparty IBAN =
NL20INGB0103490124will match. -
Debit will go to
05106(Privéopnamen Niloufar Heydari). -
Credit will go to
11000(Bankrekening). -
It will book automatically when the posting function runs.
Why the fuck does this work (honestly no clue)
-
criteria section →
condition_jsonin our rule. -
action (book on Grootboekrekening) →
debit_gl_accountorcredit_gl_account -
relation → optional extra field in rules if you want to enforce matching on
contactorrelation_id
Inside post_transaction_to_gl, when inserting into journal_entries or journal_lines, we now also attach the contact_id if the rule has one
-- Create journal entry
INSERT INTO public.journal_entries (
company_id,
company_coa_profile_id,
transaction_id, entry_date,
description,
contact_id
) VALUES (
tx.company_id,
prof.company_coa_profile_id,
tx.transaction_id,
current_date,
tx.description,
r.contact_id
)
RETURNING journal_entry_id
INTO entry_id;