use kvp's to identify sibling copies of accounts

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6043 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2001-11-25 05:38:23 +00:00
parent c104a92c47
commit 21e5d5f329
3 changed files with 94 additions and 4 deletions

View File

@ -1,7 +1,7 @@
/********************************************************************\ /********************************************************************\
* Group.c -- chart of accounts (hierarchical tree of accounts) * * Group.c -- chart of accounts (hierarchical tree of accounts) *
* Copyright (C) 1997 Robin D. Clark * * Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1997-2000 Linas Vepstas <linas@linas.org> * * Copyright (C) 1997-2001 Linas Vepstas <linas@linas.org> *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as * * modify it under the terms of the GNU General Public License as *
@ -789,21 +789,81 @@ xaccGroupConcatGroup (AccountGroup *togrp, AccountGroup *fromgrp)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
/* mark the guid and date of the copy, using kvp. The info will be
* places in /gemini/ncopies, /gemini/<n>/guid, /gemini/<n>/date,
* where <n> = ncopies-1.
*/
static void
gemini (kvp_frame *kvp_root, const GUID *guid, time_t secs)
{
char buff[80];
kvp_frame *cwd, *pwd;
kvp_value *v_ncopies, *vvv;
gint64 ncopies = 0;
Timespec ts;
/* cwd == 'current working directory' */
pwd = kvp_frame_get_frame (kvp_root, "gemini");
if (!pwd)
{
pwd = kvp_frame_new();
kvp_frame_set_slot_nc (kvp_root,
"gemini", kvp_value_new_frame(pwd));
}
/* find, increment, store number of copies */
v_ncopies = kvp_frame_get_slot (pwd, "ncopies");
if (v_ncopies)
{
ncopies = kvp_value_get_gint64 (v_ncopies);
}
ncopies ++;
v_ncopies = kvp_value_new_gint64 (ncopies);
kvp_frame_set_slot_nc (pwd, "ncopies", v_ncopies);
/* OK, now create subdirectory and put the actual data */
--ncopies;
sprintf (buff, "%lld", ncopies);
cwd = kvp_frame_new();
kvp_frame_set_slot_nc(pwd, buff, kvp_value_new_frame(cwd));
vvv = kvp_value_new_guid (guid);
kvp_frame_set_slot_nc (cwd, "guid", vvv);
ts.tv_sec = secs;
ts.tv_nsec = 0;
vvv = kvp_value_new_timespec (ts);
kvp_frame_set_slot_nc (cwd, "date", vvv);
}
void void
xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from) xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from)
{ {
time_t now;
GList *node; GList *node;
if (!to || !from) return; if (!to || !from) return;
if (!from->accounts || !to->book) return; if (!from->accounts || !to->book) return;
now = time(0);
for (node = from->accounts; node; node=node->next) for (node = from->accounts; node; node=node->next)
{ {
Account *to_acc, *from_acc = node->data; Account *to_acc, *from_acc = node->data;
/* This will copy the basic data and the KVP. It will
* not copy any splits/transactions. */
to_acc = xaccCloneAccountSimple (from_acc, to->book); to_acc = xaccCloneAccountSimple (from_acc, to->book);
xaccAccountBeginEdit (to_acc); xaccAccountBeginEdit (to_acc);
to->accounts = g_list_append (to->accounts, to_acc); to->accounts = g_list_append (to->accounts, to_acc);
/* put in markers giving relationships */
gemini (to_acc->kvp_data, &from_acc->guid, now);
gemini (from_acc->kvp_data, &to_acc->guid, now);
/* copy child accounts too. */
if (from_acc->children) if (from_acc->children)
{ {
to_acc->children = xaccMallocAccountGroup (to->book); to_acc->children = xaccMallocAccountGroup (to->book);

View File

@ -53,6 +53,8 @@ void xaccAccountGroupCommitEdit (AccountGroup *grp);
* from the "from" group to the "to" group, preserving the * from the "from" group to the "to" group, preserving the
* account heirarchy. It will also take care that the moved * account heirarchy. It will also take care that the moved
* accounts will have the "to" groups book parent as well. * accounts will have the "to" groups book parent as well.
* This routine will *NOT* copy any splits/transactions.
* It will copy the KVP tree.
* *
* The xaccGroupMergeAccounts() subroutine will go through a group, * The xaccGroupMergeAccounts() subroutine will go through a group,
* merging all accounts that have the same name and description. * merging all accounts that have the same name and description.

View File

@ -42,6 +42,34 @@ Entities: Transaction
Use: Identifies that the Transaction was created from a ScheduledTransaction, Use: Identifies that the Transaction was created from a ScheduledTransaction,
and stores the GUID of that SX. and stores the GUID of that SX.
Name: /gemini/
Type: kvp_frame
Entities: Accounts
Use: subdirectory holding identification of accounts that are copies
of this account.
Name: /gemini/ncopies
Type: int64
Entities: Accounts
Use: number of subdirectories containing copy info.
Name: /gemini/0/
Type: kvp_frame
Entities: Accounts
Use: subdirectory holding identification of the first copied account.
Other copies would appear in directories /gemini/1/, /gemini/2/,
etc.
Name: /gemini/0/guid
Type: guid
Entities: Accounts
Use: guid of another account that is a copy of this one.
Name: /gemini/0/date
Type: timespec
Entities: Accounts
Use: date that copy was created.
Name: last-num Name: last-num
Type: string Type: string
Entities: Account Entities: Account
@ -157,13 +185,13 @@ Type: gint64
Entities: Account Entities: Account
Use: A boolean flag indicated whether the Account is tax-related. Use: A boolean flag indicated whether the Account is tax-related.
Name: sched-xaction Name: /sched-xaction/
Type: frame Type: frame
Entities: Split in a SchedXaction Entities: Split in a SchedXaction
Use: Storage for the various fields of a scheduled transaction's Use: Storage for the various fields of a scheduled transaction's
template Splits. template Splits.
Name: sched-xaction/account Name: /sched-xaction/account
Type: GUID Type: GUID
Entities: Split associated with a SchedXaction Entities: Split associated with a SchedXaction
Use: The GUID of this Split's xfrm account. Use: The GUID of this Split's xfrm account.
@ -173,7 +201,7 @@ Type: string
Entities: Split associated with a SchedXaction Entities: Split associated with a SchedXaction
Use: Store the formula for the credit side of the split Use: Store the formula for the credit side of the split
Name: sched-xaction/debit-formula Name: /sched-xaction/debit-formula
Type: string Type: string
Entities: Split associated with a SchedXaction Entities: Split associated with a SchedXaction
Use: Formula for the debit. Either the credit or the Use: Formula for the debit. Either the credit or the