Skip to content

Commit

Permalink
Merge 5a48d1d into 32e4d25
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuelsmann committed Oct 8, 2023
2 parents 32e4d25 + 5a48d1d commit 3404eba
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 13 deletions.
20 changes: 20 additions & 0 deletions sql/consistency/00005-transaction-approved-consistency.sql
@@ -0,0 +1,20 @@
--- yaml frontmatter
title: Approval consistent across transactions and AR/AP/GL
description: |
ahhh
---

select trns.*
from transactions trns
join ar on trns.id = ar.id
where trns.approved is distinct from ar.approved
union all
select trns.*
from transactions trns
join ap on trns.id = ap.id
where trns.approved is distinct from ap.approved
union all
select trns.*
from transactions trns
join gl on trns.id = gl.id
where trns.approved is distinct from gl.approved
14 changes: 14 additions & 0 deletions sql/consistency/00006-transaction-workflows.sql
@@ -0,0 +1,14 @@
--- yaml frontmatter
title: State of workflows linked to approved transactions
description: |
Workflows linked to approved transactions must be in a state other
than INITIAL, SAVED or DELETED (implying the transaction has not
been posted).
---


select *
from transactions trns
join workflow wf on trns.workflow_id = wf.workflow_id
where trns.approved
and wf.state in ('INITIAL', 'SAVED', 'DELETED')
30 changes: 17 additions & 13 deletions sql/consistency/00030-account-checkpoint-balances.sql
@@ -1,22 +1,26 @@
--- yaml frontmatter
title: Account checkpoint balances
title: Account checkpoint balances match journal totals
description: |
Account checkpoints summarize the impact of preceeding transactions
on account level. The accumulated balance on an account should reconcile
with the total stored in account checkpoints.
---

select *, (select sum(amount_bc)
from acc_trans
where chart_id = account_id
and transdate <= end_date
and approved
and a.curr = curr) as journal_balance
from (
select account_id, end_date, curr, sum(amount_bc) as checkpoint_balance
from account_checkpoint
group by account_id, end_date, curr
) a

select *
from (
select *, (select sum(amount_bc)
from acc_trans
where chart_id = account_id
and transdate <= end_date
and approved
and a.curr = curr) as journal_balance
from (
select account_id, end_date, curr, sum(amount_bc) as checkpoint_balance
from account_checkpoint
group by account_id, end_date, curr
) a
) b
where checkpoint_balance <> journal_balance
order by end_date, account_id;
order by end_date, account_id

0 comments on commit 3404eba

Please sign in to comment.