mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
more account balance checkpoint work
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4534 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
3cabf41fff
commit
92a75f9362
@ -769,6 +769,11 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* This routine isn't used anywhere, and probably shouldn't
|
||||
* be, in part because its balance checkpointing algorithm
|
||||
* is wrong. */
|
||||
|
||||
static void
|
||||
pgendStoreTransaction (PGBackend *be, Transaction *trans)
|
||||
{
|
||||
@ -788,8 +793,23 @@ pgendStoreTransaction (PGBackend *be, Transaction *trans)
|
||||
bufp = "COMMIT;";
|
||||
SEND_QUERY (be,bufp, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
/* If this is the multi-user mode, we need to update the
|
||||
* balances as well. */
|
||||
if ((MODE_POLL == be->session_mode) ||
|
||||
(MODE_EVENT == be->session_mode))
|
||||
{
|
||||
/* hack alert -- we should also recompute
|
||||
* the checkpoints for any accounts from which splits have
|
||||
* been deleted ... but we don't have these handy here ...
|
||||
* is this is actually kinda wrong ...
|
||||
*/
|
||||
pgendTransactionRecomputeCheckpoints (be, trans);
|
||||
}
|
||||
|
||||
LEAVE(" ");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ============================================================= */
|
||||
/* The pgendStoreAllTransactions() routine traverses through *all*
|
||||
@ -828,6 +848,14 @@ pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp)
|
||||
p = "COMMIT;";
|
||||
SEND_QUERY (be,p, );
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
/* If this is the multi-user mode, we need to update the
|
||||
* balances as well. */
|
||||
if ((MODE_POLL == be->session_mode) ||
|
||||
(MODE_EVENT == be->session_mode))
|
||||
{
|
||||
pgendGroupRecomputeAllCheckpoints(be, grp);
|
||||
}
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
@ -1168,8 +1196,16 @@ pgendCopyTransactionToEngine (PGBackend *be, GUID *trans_guid)
|
||||
* right metaphor. Its OK to poke date into the engine, but writing
|
||||
* data out to the database should make use of versioning, and this
|
||||
* routine doesn't.
|
||||
*
|
||||
* THIS IS NOT USED ANYWHERE should probably go away. Although
|
||||
* this kind of a routine could be handy for resyncing after a lost
|
||||
* contact to the backend. Note, however, that it would
|
||||
* mangle balance checkpoints, and these would need to be
|
||||
* recomputed.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
|
||||
static void
|
||||
pgendSyncTransaction (PGBackend *be, GUID *trans_guid)
|
||||
{
|
||||
@ -1213,6 +1249,8 @@ pgendSyncTransaction (PGBackend *be, GUID *trans_guid)
|
||||
LEAVE (" ");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ============================================================= */
|
||||
/* QUERY STUFF */
|
||||
/* ============================================================= */
|
||||
@ -1916,6 +1954,25 @@ pgend_trans_commit_edit (Backend * bend,
|
||||
SEND_QUERY (be,bufp,334);
|
||||
FINISH_QUERY(be->connection);
|
||||
|
||||
/* If this is the multi-user mode, we need to update the
|
||||
* balances as well. */
|
||||
if ((MODE_POLL == be->session_mode) ||
|
||||
(MODE_EVENT == be->session_mode))
|
||||
{
|
||||
GList *node;
|
||||
|
||||
/* loop over the old accounts, as they used to be. */
|
||||
for (node = xaccTransGetSplitList(trans->orig); node; node=node->next)
|
||||
{
|
||||
Split *s = (Split *) node->data;
|
||||
Account *acc = xaccSplitGetAccount (s);
|
||||
pgendAccountRecomputeOneCheckpoint (be, acc, trans->orig->date_posted);
|
||||
}
|
||||
|
||||
/* set checkpoints for the new accounts */
|
||||
pgendTransactionRecomputeCheckpoints (be, trans);
|
||||
}
|
||||
|
||||
/* hack alert -- the following code will get rid of that annoying
|
||||
* message from the GUI about saving one's data. However, it doesn't
|
||||
* do the right thing if the connection to the backend was ever lost.
|
||||
|
@ -232,17 +232,23 @@ This list only affects the multi-user and advanced/optional features.
|
||||
Most of the items on this list are 'critical' in the sense that
|
||||
multi-user mode is fundamentally broken unless they are fixed.
|
||||
|
||||
-- test checkpoint balances. There seem to be some bugs ...
|
||||
-- bug: if one user adds a transaction, the second user's starting
|
||||
balances will come out wrong. Why??
|
||||
|
||||
-- modify checkpoint computation to always occur on fixed dates.
|
||||
Failure to do so causes the fill-out algorithm to pull in all
|
||||
data.
|
||||
data. Document this inn design.txt
|
||||
|
||||
-- if another user deletes a transaction, or an account, we
|
||||
-- bug: if another user deletes a transaction, or an account, we
|
||||
need to look at the audit trail to see if the thing has been deleted.
|
||||
Otherwise, any sort of sync will incorrectly
|
||||
add the deleted transaction back in.
|
||||
|
||||
-- we should use LISTEN/NOTIFY to let others know tht things have
|
||||
changed. This is of limited utility, but still...
|
||||
It could be used to update the balances in the main window
|
||||
dynamically.
|
||||
|
||||
-- during sync, detect and report conflicting edits to accounts
|
||||
and transactions. See the notes for pgendSync() for details
|
||||
as to what this is about. For the first pass, this is not a
|
||||
@ -284,10 +290,10 @@ multi-user mode is fundamentally broken unless they are fixed.
|
||||
report a rollback.
|
||||
-- pgTransactionSync() is broken, but its not used anywhere.
|
||||
-- pgend_account_commit checks version but doesn't rollback.
|
||||
(nor does the GUI report a rollback.
|
||||
(nor does the GUI report a rollback.)
|
||||
-- pgendSync does the right thing, except that it doesn't
|
||||
detect any version conflicts, nor does it notify the user
|
||||
of such conflicts.
|
||||
of such conflicts. (actually, it also screws checkpoints).
|
||||
|
||||
I'm not sure how critical this all is; with a small number of users
|
||||
it shouldn't be a problem. With a huge number of users, each editing
|
||||
|
@ -237,7 +237,7 @@ pgendGroupRecomputeAllCheckpoints (PGBackend *be, AccountGroup *grp)
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* recompute *one* checkpoints for the account */
|
||||
/* recompute *one* checkpoint for the account */
|
||||
|
||||
void
|
||||
pgendAccountRecomputeOneCheckpoint (PGBackend *be, Account *acc, Timespec ts)
|
||||
@ -267,6 +267,32 @@ pgendAccountRecomputeOneCheckpoint (PGBackend *be, Account *acc, Timespec ts)
|
||||
FINISH_QUERY(be->connection);
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* recompute all checkpoints affected by this transaction */
|
||||
|
||||
void
|
||||
pgendTransactionRecomputeCheckpoints (PGBackend *be, Transaction *trans)
|
||||
{
|
||||
char *p, dbuf[80];
|
||||
|
||||
p = be->buff; *p = 0;
|
||||
p = stpcpy (p, "BEGIN WORK;\n"
|
||||
"LOCK TABLE gncCheckpoint IN ACCESS EXCLUSIVE MODE;\n"
|
||||
"LOCK TABLE gncEntry, gncTransaction IN SHARE MODE;\n"
|
||||
"UPDATE gncCheckpoint SET "
|
||||
" balance = (gncsubtotalbalance (gncEntry.accountGuid, date_start, date_end )),"
|
||||
" cleared_balance = (gncsubtotalclearedbalance (gncEntry.accountGuid, date_start, date_end )),"
|
||||
" reconciled_balance = (gncsubtotalreconedbalance (gncEntry.accountGuid, date_start, date_end )) "
|
||||
" WHERE gncEntry.transGuid = '");
|
||||
p = guid_to_string_buff (xaccTransGetGUID(trans), p);
|
||||
p = stpcpy (p, "' AND gncTransaction.transGuid = gncEntry.transGuid "
|
||||
" AND date_start <= gncTransaction.date_posted "
|
||||
" AND date_end > gncTransaction.date_posted;\n"
|
||||
"COMMIT WORK;\n");
|
||||
SEND_QUERY (be,be->buff, );
|
||||
FINISH_QUERY(be->connection);
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* get checkpoint value for the account
|
||||
* We find the checkpoint which matches the account and commodity,
|
||||
|
@ -77,6 +77,7 @@ typedef struct _checkpoint {
|
||||
#define CK_AFTER_LAST_DATE "2038-01-02 12:12:12.00"
|
||||
|
||||
|
||||
void pgendTransactionRecomputeCheckpoints (PGBackend *be, Transaction *trans);
|
||||
void pgendAccountRecomputeOneCheckpoint (PGBackend *be, Account *acc, Timespec ts);
|
||||
void pgendGroupRecomputeAllCheckpoints (PGBackend *, AccountGroup *);
|
||||
void pgendGroupGetAllBalances (PGBackend *, AccountGroup *, Timespec as_of_date);
|
||||
|
Loading…
Reference in New Issue
Block a user