Skip to content

Commit

Permalink
fix(Trial Balance): limit lookup to FY
Browse files Browse the repository at this point in the history
This commit limits the Trial Balance lookup to only oldest fiscal year.

Closes IMA-WorldHealth#2568.
  • Loading branch information
jniles committed Feb 24, 2018
1 parent 7b6be38 commit f5d72d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions server/models/procedures/trial_balance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ CREATE PROCEDURE TrialBalanceSummary()
BEGIN
-- this assumes lines have been staged using CALL StageTrialBalanceTransaction()

-- fiscal year to limit period_total search
DECLARE fiscalYearId MEDIUMINT;

-- get the fiscal year of the oldest record to limit period_total search
SET fiscalYearId = (
SELECT MIN(fiscal_year_id)
FROM posting_journal JOIN stage_trial_balance_transaction
ON posting_journal.record_uuid = stage_trial_balance_transaction.record_uuid
);

-- gather the staged accounts
CREATE TEMPORARY TABLE IF NOT EXISTS staged_accounts AS
SELECT DISTINCT account_id FROM posting_journal JOIN stage_trial_balance_transaction
Expand All @@ -200,6 +210,7 @@ BEGIN
SELECT u.account_id, IFNULL(SUM(debit - credit), 0) AS balance_before
FROM staged_accounts as u
LEFT JOIN period_total ON u.account_id = period_total.account_id
WHERE period_total.fiscal_year_id = fiscalYearId
GROUP BY u.account_id;

SELECT account_id, account.number AS number, account.label AS label,
Expand Down
4 changes: 2 additions & 2 deletions server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ CREATE TABLE `rubric_payroll` (
`is_discount` tinyint(1) DEFAULT 0,
`is_tax` tinyint(1) DEFAULT 0,
`is_social_care` tinyint(1) DEFAULT 0,
`is_membership_fee` tinyint(1) DEFAULT 0,
`is_membership_fee` tinyint(1) DEFAULT 0,
`debtor_account_id` int(10) unsigned DEFAULT NULL,
`expense_account_id` int(10) unsigned DEFAULT NULL,
`is_ipr` tinyint(1) DEFAULT 0,
Expand Down Expand Up @@ -1587,7 +1587,7 @@ CREATE TABLE `taxe_ipr` (
`currency_id` TINYINT(3) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
KEY `currency_id` (`currency_id`),
FOREIGN KEY (`currency_id`) REFERENCES `currency` (`id`) ON UPDATE CASCADE
FOREIGN KEY (`currency_id`) REFERENCES `currency` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `taxe_ipr_configuration`;
Expand Down

0 comments on commit f5d72d0

Please sign in to comment.