-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7649 from ehuelsmann/feature/more-consistency-checks
One fixed and two additional consistency checks
- Loading branch information
Showing
3 changed files
with
51 additions
and
13 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
sql/consistency/00005-transaction-approved-consistency.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|