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)
RETURNS NUMERIC
AS 'SELECT sum(gncentry.value)
FROM gncentry, gnctransaction
AS 'SELECT sum(gncEntry.value)
FROM gncEntry, gncTransaction
WHERE
gncentry.accountguid = $1 AND
gncentry.transguid = gnctransaction.transguid AND
gnctransaction.date_posted BETWEEN $2 AND $3'
gncEntry.accountGuid = $1 AND
gncEntry.transGuid = gncTransaction.transGuid AND
gncTransaction.date_posted BETWEEN $2 AND $3'
LANGUAGE 'sql';
CREATE FUNCTION gncSubtotalClearedBalance (char(32), DATETIME, DATETIME)
RETURNS NUMERIC
AS 'SELECT sum(gncentry.value)
FROM gncentry, gnctransaction
AS 'SELECT sum(gncEntry.value)
FROM gncEntry, gncTransaction
WHERE
gncentry.accountguid = $1 AND
gncentry.transguid = gnctransaction.transguid AND
gnctransaction.date_posted BETWEEN $2 AND $3 AND
gncentry.reconciled <> \\'n\\''
gncEntry.accountGuid = $1 AND
gncEntry.transGuid = gncTransaction.transGuid AND
gncTransaction.date_posted BETWEEN $2 AND $3 AND
gncEntry.reconciled <> \\'n\\''
LANGUAGE 'sql';
CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME)
RETURNS NUMERIC
AS 'SELECT sum(gncentry.value)
FROM gncentry, gnctransaction
AS 'SELECT sum(gncEntry.value)
FROM gncEntry, gncTransaction
WHERE
gncentry.accountguid = $1 AND
gncentry.transguid = gnctransaction.transguid AND
gnctransaction.date_posted BETWEEN $2 AND $3 AND
gncentry.reconciled = \\'y\\''
gncEntry.accountGuid = $1 AND
gncEntry.transGuid = gncTransaction.transGuid AND
gncTransaction.date_posted BETWEEN $2 AND $3 AND
gncEntry.reconciled = \\'y\\''
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';