add helper functions

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4381 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2001-06-03 02:41:25 +00:00
parent 96f072b35f
commit 3e5a402942

View File

@ -191,33 +191,55 @@ CREATE TABLE gncKVPvalue_list (
CREATE FUNCTION gncSubtotalBalance (CHAR(32), DATETIME, DATETIME) CREATE FUNCTION gncSubtotalBalance (CHAR(32), DATETIME, DATETIME)
RETURNS NUMERIC RETURNS NUMERIC
AS 'SELECT sum(gncentry.value) AS 'SELECT sum(gncEntry.value)
FROM gncentry, gnctransaction FROM gncEntry, gncTransaction
WHERE WHERE
gncentry.accountguid = $1 AND gncEntry.accountGuid = $1 AND
gncentry.transguid = gnctransaction.transguid AND gncEntry.transGuid = gncTransaction.transGuid AND
gnctransaction.date_posted BETWEEN $2 AND $3' gncTransaction.date_posted BETWEEN $2 AND $3'
LANGUAGE 'sql'; LANGUAGE 'sql';
CREATE FUNCTION gncSubtotalClearedBalance (char(32), DATETIME, DATETIME) CREATE FUNCTION gncSubtotalClearedBalance (char(32), DATETIME, DATETIME)
RETURNS NUMERIC RETURNS NUMERIC
AS 'SELECT sum(gncentry.value) AS 'SELECT sum(gncEntry.value)
FROM gncentry, gnctransaction FROM gncEntry, gncTransaction
WHERE WHERE
gncentry.accountguid = $1 AND gncEntry.accountGuid = $1 AND
gncentry.transguid = gnctransaction.transguid AND gncEntry.transGuid = gncTransaction.transGuid AND
gnctransaction.date_posted BETWEEN $2 AND $3 AND gncTransaction.date_posted BETWEEN $2 AND $3 AND
gncentry.reconciled <> \\'n\\'' gncEntry.reconciled <> \\'n\\''
LANGUAGE 'sql'; LANGUAGE 'sql';
CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME) CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME)
RETURNS NUMERIC RETURNS NUMERIC
AS 'SELECT sum(gncentry.value) AS 'SELECT sum(gncEntry.value)
FROM gncentry, gnctransaction FROM gncEntry, gncTransaction
WHERE WHERE
gncentry.accountguid = $1 AND gncEntry.accountGuid = $1 AND
gncentry.transguid = gnctransaction.transguid AND gncEntry.transGuid = gncTransaction.transGuid AND
gnctransaction.date_posted BETWEEN $2 AND $3 AND gncTransaction.date_posted BETWEEN $2 AND $3 AND
gncentry.reconciled = \\'y\\'' gncEntry.reconciled = \\'y\\''
LANGUAGE 'sql'; LANGUAGE 'sql';
-- helper functions. These intentionally use the 'wrong' fraction.
-- This is because value_frac * amount * price = value * amount_frac
CREATE FUNCTION gncHelperPrVal (gncEntry)
RETURNS INT8
AS 'SELECT abs($1 . value * gncCommodity.fraction)
FROM gncEntry, gncAccount, gncCommodity
WHERE
$1 . accountGuid = gncAccount.accountGuid AND
gncAccount.commodity = gncCommodity.commodity'
LANGUAGE 'sql';
CREATE FUNCTION gncHelperPrAmt (gncEntry)
RETURNS INT8
AS 'SELECT abs($1 . amount * gncCommodity.fraction)
FROM gncEntry, gncTransaction, gncCommodity
WHERE
$1 . transGuid = gncTransaction.transGuid AND
gncTransaction.currency = gncCommodity.commodity'
LANGUAGE 'sql';