mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
continue hacking on books ...
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6165 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2fcbda7e6f
commit
a902e92d8d
@ -44,6 +44,7 @@ gncinclude_HEADERS = \
|
|||||||
FreqSpec.h \
|
FreqSpec.h \
|
||||||
GNCId.h \
|
GNCId.h \
|
||||||
Group.h \
|
Group.h \
|
||||||
|
Period.h \
|
||||||
SchedXaction.h \
|
SchedXaction.h \
|
||||||
SX-ttinfo.h \
|
SX-ttinfo.h \
|
||||||
Query.h \
|
Query.h \
|
||||||
|
@ -15,59 +15,13 @@ Open questions: how do we deal with the backends ???
|
|||||||
* Copyright (c) 2001 Linas Vepstas <linas@linas.org>
|
* Copyright (c) 2001 Linas Vepstas <linas@linas.org>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef XACC_PERIOD_H
|
|
||||||
#define XACC_PERIOD_H
|
|
||||||
|
|
||||||
#include "gnc-book.h"
|
|
||||||
#include "gnc-engine.h"
|
|
||||||
#include "Query.h"
|
|
||||||
|
|
||||||
/* The gnc_book_partition() uses the result of the indicated query
|
|
||||||
* to partition an existing book into two parts. It returns
|
|
||||||
* a newly created book, containing a copy of all of the accounts,
|
|
||||||
* and it moves all of the transactions returned by the query to
|
|
||||||
* the copied accounts.
|
|
||||||
|
|
||||||
The intent is that the 'typical' query will be a date that splits
|
|
||||||
the book into a 'before and after'; but in fact, any general query
|
|
||||||
will do.
|
|
||||||
|
|
||||||
Note that this routine is 'special' in that it works hard to make sure
|
|
||||||
that the partitioned accounts, transactions and splits are really
|
|
||||||
moved to a new book -- things like entity tables must be cleared
|
|
||||||
and repopulated correctly.
|
|
||||||
|
|
||||||
This routine intentionally does not copy scheduled/recurring
|
|
||||||
transactions.
|
|
||||||
|
|
||||||
TBD:
|
|
||||||
-- Make an equity transfer so that we can carry forward the balances.
|
|
||||||
-- set kvp values indicating that the books were split.
|
|
||||||
|
|
||||||
*/
|
|
||||||
GNCBook * gnc_book_partition (GNCBook *, Query *);
|
|
||||||
|
|
||||||
/* The gnc_book_insert_trans() routine takes an existing transaction
|
|
||||||
* that is located in one book, and moves it to another book.
|
|
||||||
* It moves all of the splits as well. In the course of the
|
|
||||||
* move, the transaction is literally deleted from the first
|
|
||||||
* book as its placed into the second. The transaction and
|
|
||||||
* split GUID's are not changed in the move. This routine
|
|
||||||
* assumes that twin accounts already exist in both books
|
|
||||||
* (and can be located with the standard twining proceedure).
|
|
||||||
*/
|
|
||||||
|
|
||||||
void gnc_book_insert_trans (GNCBook *book, Transaction *trans);
|
|
||||||
|
|
||||||
#endif /* XACC_PERIOD_H */
|
|
||||||
|
|
||||||
#include "AccountP.h"
|
#include "AccountP.h"
|
||||||
#include "gnc-book-p.h"
|
#include "gnc-book-p.h"
|
||||||
#include "gnc-engine-util.h"
|
#include "gnc-engine-util.h"
|
||||||
#include "gnc-event-p.h"
|
#include "gnc-event-p.h"
|
||||||
#include "GroupP.h"
|
#include "GroupP.h"
|
||||||
#include "kvp-util-p.h"
|
#include "kvp-util-p.h"
|
||||||
|
#include "Period.h"
|
||||||
#include "TransactionP.h"
|
#include "TransactionP.h"
|
||||||
|
|
||||||
/* This static indicates the debugging module that this .o belongs to. */
|
/* This static indicates the debugging module that this .o belongs to. */
|
||||||
@ -143,13 +97,18 @@ gnc_book_partition (GNCBook *existing_book, Query *query)
|
|||||||
|
|
||||||
partition_book = gnc_book_new();
|
partition_book = gnc_book_new();
|
||||||
|
|
||||||
/* first, copy all of the accounts */
|
/* First, copy the book's KVP tree */
|
||||||
|
kvp_frame_delete (partition_book->kvp_data);
|
||||||
|
partition_book->kvp_data = kvp_frame_copy (existing_book->kvp_data);
|
||||||
|
|
||||||
|
/* Next, copy all of the accounts */
|
||||||
xaccGroupCopyGroup (partition_book->topgroup, existing_book->topgroup);
|
xaccGroupCopyGroup (partition_book->topgroup, existing_book->topgroup);
|
||||||
|
|
||||||
/* next, run the query */
|
/* Next, run the query */
|
||||||
|
xaccQuerySetGroup (query, existing_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 (partition_book->topgroup);
|
||||||
xaccAccountGroupBeginEdit (existing_book->topgroup);
|
xaccAccountGroupBeginEdit (existing_book->topgroup);
|
||||||
for (snode = split_list; snode; snode=snode->next)
|
for (snode = split_list; snode; snode=snode->next)
|
||||||
@ -174,4 +133,47 @@ gnc_book_partition (GNCBook *existing_book, Query *query)
|
|||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
|
|
||||||
|
GNCBook *
|
||||||
|
gnc_book_calve_period (GNCBook *existing_book, Timespec calve_date)
|
||||||
|
{
|
||||||
|
Query *query;
|
||||||
|
GNCBook *partition_book;
|
||||||
|
kvp_frame *exist_cwd, partn_cwd;
|
||||||
|
kvp_value *vvv;
|
||||||
|
Timespec ts;
|
||||||
|
|
||||||
|
/* Get all transactions that are *earlier* than the calve date,
|
||||||
|
* and put them in the new book. */
|
||||||
|
query = xaccMallocQuery();
|
||||||
|
xaccQueryAddDateMatchTS (query, FALSE, calve_date,
|
||||||
|
TRUE, calve_date,
|
||||||
|
QUERY_OR);
|
||||||
|
partition_book = gnc_book_partition (existing_book, query);
|
||||||
|
|
||||||
|
xaccFreeQuery (query);
|
||||||
|
|
||||||
|
/* Now add the various identifying kvp's */
|
||||||
|
/* cwd == 'current working directory' */
|
||||||
|
exist_cwd = kvp_frame_get_frame_slash (existing_book->kvp_data, "/book/");
|
||||||
|
partn_cwd = kvp_frame_get_frame_slash (partition_book->kvp_data, "/book/");
|
||||||
|
|
||||||
|
vvv = kvp_value_new_timespec (calve_date);
|
||||||
|
kvp_frame_set_slot_nc (exist_cwd, "start-date", vvv);
|
||||||
|
kvp_frame_set_slot_nc (partn_cwd, "end-date", vvv);
|
||||||
|
|
||||||
|
/* mark partition as being closed */
|
||||||
|
ts.tv_sec = time(0);
|
||||||
|
ts.tv_nsec = 0;
|
||||||
|
vvv = kvp_value_new_timespec (ts);
|
||||||
|
kvp_frame_set_slot_nc (partn_cwd, "close-date", vvv);
|
||||||
|
|
||||||
|
vvv = kvp_value_new_guid (existing_book->guid);
|
||||||
|
kvp_frame_set_slot_nc (partn_cwd, "next-book", vvv);
|
||||||
|
|
||||||
|
vvv = kvp_value_new_guid (partition_book->guid);
|
||||||
|
kvp_frame_set_slot_nc (exist_cwd, "prev-book", vvv);
|
||||||
|
|
||||||
|
return partition_book;
|
||||||
|
}
|
||||||
|
|
||||||
/* ============================= END OF FILE ====================== */
|
/* ============================= END OF FILE ====================== */
|
||||||
|
@ -28,14 +28,20 @@
|
|||||||
*
|
*
|
||||||
-- It will use the /book/blah-blah kvp value to denote xxx.
|
-- It will use the /book/blah-blah kvp value to denote xxx.
|
||||||
-- Make an equity transfer so that we can carry forward the balances.
|
-- Make an equity transfer so that we can carry forward the balances.
|
||||||
/book/close-date
|
-- hack alert -- should not allow closed books to have unreconciled
|
||||||
|
transactions ???
|
||||||
|
|
||||||
|
Implemented:
|
||||||
|
/book/start-date earliest date in this book.
|
||||||
|
/book/end-date latest date in this book. must not change ...
|
||||||
|
/book/close-date date on which book was closed.
|
||||||
|
/book/next-book guid of next book
|
||||||
|
/book/prev-book guid of previous book
|
||||||
|
|
||||||
|
Mot imlemented (yet):
|
||||||
/book/closing-balance-of-account-guid
|
/book/closing-balance-of-account-guid
|
||||||
/book/previous-guid
|
|
||||||
/book/name=some-user-supplied-name
|
/book/name=some-user-supplied-name
|
||||||
/book/notes=user-supplied-descriptive-comments
|
/book/notes=user-supplied-descriptive-comments
|
||||||
/book/start-date=xxx
|
|
||||||
/book/end-date=xxx
|
|
||||||
/book/previous-book-guids=(list 0xa 0xb 0xc)
|
|
||||||
/book/accounting-period=enum {none, week, month, quarter, trimester, year}
|
/book/accounting-period=enum {none, week, month, quarter, trimester, year}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,11 +46,13 @@ 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/
|
Name: /gemini/
|
||||||
Type: kvp_frame
|
Type: kvp_frame
|
||||||
Entities: Account, Book
|
Entities: Account, Book
|
||||||
Use: subdirectory holding identification of accounts that are copies
|
Use: kvp subdirectory holding identification of accounts or books
|
||||||
of this account.
|
that are copies of this account.
|
||||||
|
|
||||||
Name: /gemini/ncopies
|
Name: /gemini/ncopies
|
||||||
Type: int64
|
Type: int64
|
||||||
@ -72,13 +74,17 @@ Use: guid of another account that is a copy of this one.
|
|||||||
Name: /gemini/0/book_guid
|
Name: /gemini/0/book_guid
|
||||||
Type: guid
|
Type: guid
|
||||||
Entities: Account, Book
|
Entities: Account, Book
|
||||||
Use: guid of the book that the other account belongs to.
|
Use: When this appears in an account, then it contains the guid of
|
||||||
|
the book that the other account belongs to. When this appears
|
||||||
|
in a book, then this is the guid of the other book.
|
||||||
|
|
||||||
Name: /gemini/0/date
|
Name: /gemini/0/date
|
||||||
Type: timespec
|
Type: timespec
|
||||||
Entities: Account, Book
|
Entities: Account, Book
|
||||||
Use: date that the copy was created.
|
Use: date that the copy was created.
|
||||||
|
|
||||||
|
-----------------------
|
||||||
|
|
||||||
Name: last-num
|
Name: last-num
|
||||||
Type: string
|
Type: string
|
||||||
Entities: Account
|
Entities: Account
|
||||||
|
Loading…
Reference in New Issue
Block a user