mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
API change
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6185 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
f7b024189b
commit
f156eef1de
@ -85,50 +85,53 @@ gnc_book_insert_trans (GNCBook *book, Transaction *trans)
|
|||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
|
|
||||||
GNCBook *
|
void
|
||||||
gnc_book_partition (GNCBook *existing_book, Query *query)
|
gnc_book_partition (GNCBook *dest_book, GNCBook *src_book, Query *query)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
GList *split_list, *snode;
|
GList *split_list, *snode;
|
||||||
GNCBook *partition_book;
|
GNCBook *partition_book;
|
||||||
AccountGroup *part_topgrp;
|
AccountGroup *part_topgrp;
|
||||||
|
|
||||||
if (!existing_book || !query) return NULL;
|
if (!src_book || !dest_book || !query) return;
|
||||||
|
|
||||||
partition_book = gnc_book_new();
|
|
||||||
|
|
||||||
/* First, copy the book's KVP tree */
|
/* First, copy the book's KVP tree */
|
||||||
kvp_frame_delete (partition_book->kvp_data);
|
/* hack alert -- FIXME -- this should really be a merge, not a
|
||||||
partition_book->kvp_data = kvp_frame_copy (existing_book->kvp_data);
|
* clobber copy, but I am too lazy to write a kvp merge routine,
|
||||||
|
* and it is not needed for the current usage. */
|
||||||
|
kvp_frame_delete (dest_book->kvp_data);
|
||||||
|
dest_book->kvp_data = kvp_frame_copy (src_book->kvp_data);
|
||||||
|
|
||||||
/* Next, copy all of the accounts */
|
/* Next, copy all of the accounts */
|
||||||
xaccGroupCopyGroup (partition_book->topgroup, existing_book->topgroup);
|
/* hack alert -- FIXME -- this should really be a merge, not a
|
||||||
|
* clobber copy, but I am too lazy to write an account-group merge
|
||||||
|
* routine, and it is not needed for the current usage. */
|
||||||
|
xaccAccountGroupBeginEdit (dest_book->topgroup);
|
||||||
|
xaccAccountGroupBeginEdit (src_book->topgroup);
|
||||||
|
xaccGroupCopyGroup (dest_book->topgroup, src_book->topgroup);
|
||||||
|
|
||||||
/* Next, run the query */
|
/* Next, run the query */
|
||||||
xaccQuerySetGroup (query, existing_book->topgroup);
|
xaccQuerySetGroup (query, src_book->topgroup);
|
||||||
split_list = xaccQueryGetSplitsUniqueTrans (query);
|
split_list = xaccQueryGetSplitsUniqueTrans (query);
|
||||||
|
|
||||||
/* And start moving transactions over */
|
/* And start moving transactions over */
|
||||||
xaccAccountGroupBeginEdit (partition_book->topgroup);
|
|
||||||
xaccAccountGroupBeginEdit (existing_book->topgroup);
|
|
||||||
for (snode = split_list; snode; snode=snode->next)
|
for (snode = split_list; snode; snode=snode->next)
|
||||||
{
|
{
|
||||||
GList *tnode;
|
GList *tnode;
|
||||||
Split *s = snode->data;
|
Split *s = snode->data;
|
||||||
Transaction *trans = s->parent;
|
Transaction *trans = s->parent;
|
||||||
|
|
||||||
gnc_book_insert_trans (partition_book, trans);
|
gnc_book_insert_trans (dest_book, trans);
|
||||||
|
|
||||||
}
|
}
|
||||||
xaccAccountGroupCommitEdit (existing_book->topgroup);
|
xaccAccountGroupCommitEdit (src_book->topgroup);
|
||||||
xaccAccountGroupCommitEdit (partition_book->topgroup);
|
xaccAccountGroupCommitEdit (dest_book->topgroup);
|
||||||
|
|
||||||
/* make note of the sibling books */
|
/* make note of the sibling books */
|
||||||
now = time(0);
|
now = time(0);
|
||||||
gnc_kvp_gemini (existing_book->kvp_data, NULL, &partition_book->guid, now);
|
gnc_kvp_gemini (src_book->kvp_data, NULL, &dest_book->guid, now);
|
||||||
gnc_kvp_gemini (partition_book->kvp_data, NULL, &existing_book->guid, now);
|
gnc_kvp_gemini (dest_book->kvp_data, NULL, &src_book->guid, now);
|
||||||
|
|
||||||
return partition_book;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
@ -320,7 +323,7 @@ gnc_book_close_period (GNCBook *existing_book, Timespec calve_date,
|
|||||||
const char * memo)
|
const char * memo)
|
||||||
{
|
{
|
||||||
Query *query;
|
Query *query;
|
||||||
GNCBook *partition_book;
|
GNCBook *closing_book;
|
||||||
kvp_frame *exist_cwd, *partn_cwd;
|
kvp_frame *exist_cwd, *partn_cwd;
|
||||||
kvp_value *vvv;
|
kvp_value *vvv;
|
||||||
Timespec ts;
|
Timespec ts;
|
||||||
@ -333,14 +336,15 @@ gnc_book_close_period (GNCBook *existing_book, Timespec calve_date,
|
|||||||
xaccQueryAddDateMatchTS (query, FALSE, calve_date,
|
xaccQueryAddDateMatchTS (query, FALSE, calve_date,
|
||||||
TRUE, calve_date,
|
TRUE, calve_date,
|
||||||
QUERY_OR);
|
QUERY_OR);
|
||||||
partition_book = gnc_book_partition (existing_book, query);
|
closing_book = gnc_book_new();
|
||||||
|
gnc_book_partition (closing_book, existing_book, query);
|
||||||
|
|
||||||
xaccFreeQuery (query);
|
xaccFreeQuery (query);
|
||||||
|
|
||||||
/* Now add the various identifying kvp's */
|
/* Now add the various identifying kvp's */
|
||||||
/* cwd == 'current working directory' */
|
/* cwd == 'current working directory' */
|
||||||
exist_cwd = kvp_frame_get_frame_slash (existing_book->kvp_data, "/book/");
|
exist_cwd = kvp_frame_get_frame_slash (existing_book->kvp_data, "/book/");
|
||||||
partn_cwd = kvp_frame_get_frame_slash (partition_book->kvp_data, "/book/");
|
partn_cwd = kvp_frame_get_frame_slash (closing_book->kvp_data, "/book/");
|
||||||
|
|
||||||
/* Mark the boundary date between the books */
|
/* Mark the boundary date between the books */
|
||||||
vvv = kvp_value_new_timespec (calve_date);
|
vvv = kvp_value_new_timespec (calve_date);
|
||||||
@ -357,16 +361,16 @@ gnc_book_close_period (GNCBook *existing_book, Timespec calve_date,
|
|||||||
vvv = kvp_value_new_guid (&existing_book->guid);
|
vvv = kvp_value_new_guid (&existing_book->guid);
|
||||||
kvp_frame_set_slot_nc (partn_cwd, "next-book", vvv);
|
kvp_frame_set_slot_nc (partn_cwd, "next-book", vvv);
|
||||||
|
|
||||||
vvv = kvp_value_new_guid (&partition_book->guid);
|
vvv = kvp_value_new_guid (&closing_book->guid);
|
||||||
kvp_frame_set_slot_nc (exist_cwd, "prev-book", vvv);
|
kvp_frame_set_slot_nc (exist_cwd, "prev-book", vvv);
|
||||||
|
|
||||||
/* add in transactions to equity accounts that will
|
/* add in transactions to equity accounts that will
|
||||||
* hold the colsing balances */
|
* hold the colsing balances */
|
||||||
add_closing_balances (gnc_book_get_group(partition_book),
|
add_closing_balances (gnc_book_get_group(closing_book),
|
||||||
existing_book, partition_book,
|
existing_book, closing_book,
|
||||||
equity_account,
|
equity_account,
|
||||||
&calve_date, &ts, memo);
|
&calve_date, &ts, memo);
|
||||||
return partition_book;
|
return closing_book;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ============================= END OF FILE ====================== */
|
/* ============================= END OF FILE ====================== */
|
||||||
|
@ -99,13 +99,15 @@ GNCBook * gnc_book_close_period (GNCBook *, Timespec,
|
|||||||
const char *memo);
|
const char *memo);
|
||||||
|
|
||||||
/* The gnc_book_partition() uses the result of the indicated query
|
/* The gnc_book_partition() uses the result of the indicated query
|
||||||
* to partition an existing book into two parts. It returns
|
* to move a set of transactions from the "src" book to the "dest"
|
||||||
* a newly created book, containing a copy of all of the accounts,
|
* book. Before moving the transactions, it will first place a
|
||||||
* and it moves all of the transactions returned by the query to
|
* copy of all of the accounts in "src" into "dest". This is done
|
||||||
* the copied accounts in the copied book. Any query will work
|
* in order to ensure that all of the moved transactions will have
|
||||||
* to partition a book; however, its expected that this routine
|
* the corrrect set of accounts to reference. The transactions
|
||||||
* will mostly serve as a utility to break up a book into
|
* that will be moved are precisely those specified by the query.
|
||||||
* accounting periods.
|
* Any query will work to partition a book; however, its expected
|
||||||
|
* that this routine will mostly serve as a utility to break up a
|
||||||
|
* book into accounting periods.
|
||||||
*
|
*
|
||||||
* This routine intentionally does not copy scheduled/recurring
|
* This routine intentionally does not copy scheduled/recurring
|
||||||
* transactions.
|
* transactions.
|
||||||
@ -117,8 +119,14 @@ GNCBook * gnc_book_close_period (GNCBook *, Timespec,
|
|||||||
* are removed from one book's entity table and placed into the
|
* are removed from one book's entity table and placed into the
|
||||||
* other book: Once moved, they won't be findable in the entity
|
* other book: Once moved, they won't be findable in the entity
|
||||||
* table of the old book.
|
* table of the old book.
|
||||||
|
*
|
||||||
|
* Known Bugs:
|
||||||
|
* When this routine copies accounts, it does not check to see
|
||||||
|
* if they already exist in the 'dest' book; it should.
|
||||||
|
* For the current usage, this bug aint important, and I'm too
|
||||||
|
* lazy to fix it.
|
||||||
*/
|
*/
|
||||||
GNCBook * gnc_book_partition (GNCBook *, Query *);
|
void gnc_book_partition (GNCBook *dest, GNCBook *src, Query *);
|
||||||
|
|
||||||
/* The gnc_book_insert_trans() routine takes an existing transaction
|
/* The gnc_book_insert_trans() routine takes an existing transaction
|
||||||
* that is located in one book, and moves it to another book.
|
* that is located in one book, and moves it to another book.
|
||||||
|
Loading…
Reference in New Issue
Block a user