Skip to content

Commit

Permalink
fix(db): build TEMP tables before posting
Browse files Browse the repository at this point in the history
This commit fixes a bug specifically in the administrative tools that
builds temporary tables required for posting cash payments before
the zRepostCash() method attempts to repost them.  This also helps
modularize the procedure code.
  • Loading branch information
Jonathan Niles authored and jniles committed Feb 13, 2017
1 parent f8c6c5a commit 2d5b7e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions server/models/admin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ CREATE PROCEDURE zRepostCash(
)
BEGIN
DELETE FROM posting_journal WHERE posting_journal.record_uuid = cUuid;
CALL VerifyCashTemporaryTables();
CALL PostCash(cUuid);
END $$

Expand Down
28 changes: 17 additions & 11 deletions server/models/procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,22 @@ BEGIN
END IF;
END $$

-- This makes sure the temporary tables exist before using them
CREATE PROCEDURE VerifyCashTemporaryTables()
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS stage_cash_records (
uuid BINARY(16), debit DECIMAL(19,4), credit DECIMAL(19,4), entity_uuid BINARY(16), date TIMESTAMP
);

CREATE TEMPORARY TABLE IF NOT EXISTS stage_cash_references (
uuid BINARY(16), debit DECIMAL(19,4), credit DECIMAL(19,4), entity_uuid BINARY(16), date TIMESTAMP
);

CREATE TEMPORARY TABLE IF NOT EXISTS stage_cash_invoice_balances (
uuid BINARY(16), balance DECIMAL(19, 4), date TIMESTAMP
);
END $$

-- This calculates the amount due on previous invoices based on what is being paid
CREATE PROCEDURE CalculateCashInvoiceBalances(
IN cashUuid BINARY(16)
Expand Down Expand Up @@ -811,17 +827,7 @@ BEGIN
SET currentExchangeRate = GetExchangeRate(cashEnterpriseId, cashCurrencyId, cashDate);
SET currentExchangeRate = (SELECT IF(cashCurrencyId = enterpriseCurrencyId, 1, currentExchangeRate));

CREATE TEMPORARY TABLE IF NOT EXISTS stage_cash_records (
uuid BINARY(16), debit DECIMAL(19,4), credit DECIMAL(19,4), entity_uuid BINARY(16), date TIMESTAMP
);

CREATE TEMPORARY TABLE IF NOT EXISTS stage_cash_references (
uuid BINARY(16), debit DECIMAL(19,4), credit DECIMAL(19,4), entity_uuid BINARY(16), date TIMESTAMP
);

CREATE TEMPORARY TABLE IF NOT EXISTS stage_cash_invoice_balances (
uuid BINARY(16), balance DECIMAL(19, 4), date TIMESTAMP
);
CALL VerifyCashTemporaryTables();

INSERT INTO stage_cash_records
SELECT cl.record_uuid AS uuid, cl.debit_equiv as debit, cl.credit_equiv as credit, cl.entity_uuid, cl.trans_date as date
Expand Down

0 comments on commit 2d5b7e2

Please sign in to comment.