add support for tax tables in the period closing

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9484 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-10-12 15:28:29 +00:00
parent a0747a6bf9
commit b2ab3ab805
6 changed files with 236 additions and 96 deletions

View File

@ -177,7 +177,6 @@ static void gncBillTermFree (GncBillTerm *term)
gnc_engine_generate_event (&term->inst.guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
CACHE_REMOVE (term->name);
CACHE_REMOVE (term->desc);
qof_instance_release(&term->inst);
remObj (term);
if (!term->inst.do_free)
@ -194,6 +193,7 @@ static void gncBillTermFree (GncBillTerm *term)
}
g_list_free(term->children);
qof_instance_release(&term->inst);
g_free (term);
}

View File

@ -1,7 +1,16 @@
XXX TODO:
-- billterms is incompletely cloned, not sure what to do
with certain fields, ask warlord
-- taxtable is incompletely cloned, not sure what to do
with certain fields, ask warlord
-- customer incomplete cloned, neeed to handle jobs
-- Ask warlord is *all bill terms should eb copied, or just
thiose on customers ...
XXX how to deal with customer tax table,
also jobs
#include "gncBusiness.h"
@ -37,6 +46,7 @@ partition (QofBook *dest_book, QofBook *src_book)
/* Copy all bill terms first, since the CustomerCopy expects
* these to be in place already. */
/* XXX not strictly needed, the customer can pull thier own .. ? */
gncBillTermCopyAll (dest_book, src_book);
}

View File

@ -52,6 +52,7 @@
#include "gncBusiness.h"
#include "gncCustomer.h"
#include "gncCustomerP.h"
#include "gncTaxTableP.h"
struct _gncCustomer
{
@ -150,14 +151,26 @@ gncCloneCustomer (GncCustomer *from, QofBook *book)
cust->credit = from->credit;
cust->taxincluded = from->taxincluded;
cust->active = from->active;
cust->taxtable_override = from->taxtable_override;
/* cust->jobs = ??? XXXXXXXXXXXXXXXXXXXXXXX fixme not sure what to do here */
/* cust->jobs = ??? XXX fixme not sure what to do here */
/* cust->taxtable = ??? XXX fixme not sure what to do here */
cust->addr = gncCloneAddress (from->addr, book);
cust->shipaddr = gncCloneAddress (from->shipaddr, book);
/* Assume that bill terms have been previously inserted
* into the new book. Just find the matching bill term. */
/* Find the matching currency in the new book, assumes
* currency has already been copied into new book. */
if (from->currency)
{
const char * ucom;
const gnc_commodity_table * comtbl;
ucom = gnc_commodity_get_unique_name (from->currency);
comtbl = gnc_commodity_table_get_table (book);
cust->currency = gnc_commodity_table_lookup_unique (comtbl, ucom);
}
/* Find the matching bill term in the new book,
* else clone that too. */
if (from->terms)
{
GncBillTerm *bitty;
@ -169,6 +182,19 @@ gncCloneCustomer (GncCustomer *from, QofBook *book)
cust->terms = bitty;
}
/* Find the matching taxtable in the new book,
* else clone that too. */
if (from->taxtable)
{
GncTaxTable *txtab;
txtab = (GncTaxTable *) qof_instance_lookup_twin (QOF_INSTANCE(from->taxtable), book);
if (!txtab)
{
txtab = gncCloneTaxTable (from->taxtable, book);
}
cust->taxtable = txtab;
}
addObj (cust);
gnc_engine_generate_event (&cust->inst.guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);

View File

@ -1,6 +1,28 @@
/********************************************************************\
* gncTaxTable.c -- the Gnucash Tax Table interface *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
* *
\********************************************************************/
/*
* gncTaxTable.c -- the Gnucash Tax Table interface
* Copyright (C) 2002 Derek Atkins
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
* Author: Derek Atkins <warlord@MIT.EDU>
*/
@ -28,30 +50,31 @@
struct _gncTaxTable
{
QofInstance inst;
char * name;
GList * entries;
QofInstance inst;
char * name;
GList * entries;
Timespec modtime; /* internal date of last modtime */
gint64 refcount;
GncTaxTable * parent; /* if non-null, we are an immutable child */
GncTaxTable * child; /* if non-null, we have not changed */
gint64 refcount;
GncTaxTable * parent; /* if non-null, we are an immutable child */
GncTaxTable * child; /* if non-null, we have not changed */
gboolean invisible;
GList * children; /* A list of children */
GList * children; /* A list of children */
};
struct _gncTaxTableEntry
{
GncTaxTable * table;
Account * account;
GncAmountType type;
gnc_numeric amount;
GncTaxTable * table;
Account * account;
GncAmountType type;
gnc_numeric amount;
};
struct _book_info {
GncBookInfo bi;
GList * tables; /* visible tables */
struct _book_info
{
GncBookInfo bi;
GList * tables; /* visible tables */
};
static short module = MOD_BUSINESS;
@ -115,6 +138,9 @@ gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type)
}
#undef GNC_RETURN_ON_MATCH
/* =============================================================== */
/* Misc inline functions */
#define _GNC_MOD_NAME GNC_TAXTABLE_MODULE_NAME
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
@ -130,32 +156,73 @@ gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type)
member = tmp; \
}
static void add_or_rem_object (GncTaxTable *table, gboolean add);
static void addObj (GncTaxTable *table);
static void remObj (GncTaxTable *table);
static void maybe_resort_list (GncTaxTable *table);
static void gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child);
G_INLINE_FUNC void mark_table (GncTaxTable *table);
G_INLINE_FUNC void
static inline void
mark_table (GncTaxTable *table)
{
table->inst.dirty = TRUE;
gncBusinessSetDirtyFlag (table->inst.book, _GNC_MOD_NAME, TRUE);
gnc_engine_generate_event (&table->inst.guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
}
G_INLINE_FUNC void mod_table (GncTaxTable *table);
G_INLINE_FUNC void
static inline void
maybe_resort_list (GncTaxTable *table)
{
struct _book_info *bi;
if (table->parent || table->invisible) return;
bi = gnc_book_get_data (table->inst.book, _GNC_MOD_NAME);
bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare);
}
static inline void
mod_table (GncTaxTable *table)
{
timespecFromTime_t (&table->modtime, time(NULL));
}
static inline void addObj (GncTaxTable *table)
{
struct _book_info *bi;
gncBusinessAddObject (table->inst.book, _GNC_MOD_NAME, table, &table->inst.guid);
bi = gnc_book_get_data (table->inst.book, _GNC_MOD_NAME);
bi->tables = g_list_insert_sorted (bi->tables, table,
(GCompareFunc)gncTaxTableCompare);
}
static inline void remObj (GncTaxTable *table)
{
struct _book_info *bi;
gncBusinessRemoveObject (table->inst.book, _GNC_MOD_NAME, &table->inst.guid);
bi = gnc_book_get_data (table->inst.book, _GNC_MOD_NAME);
bi->tables = g_list_remove (bi->tables, table);
}
static inline void
gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child)
{
g_return_if_fail(table);
g_return_if_fail(child);
g_return_if_fail(table->inst.do_free == FALSE);
table->children = g_list_prepend(table->children, child);
}
static inline void
gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child)
{
g_return_if_fail(table);
g_return_if_fail(child);
if (table->inst.do_free) return;
table->children = g_list_remove(table->children, child);
}
/* =============================================================== */
/* Create/Destroy Functions */
GncTaxTable * gncTaxTableCreate (QofBook *book)
GncTaxTable *
gncTaxTableCreate (QofBook *book)
{
GncTaxTable *table;
if (!book) return NULL;
@ -168,7 +235,38 @@ GncTaxTable * gncTaxTableCreate (QofBook *book)
return table;
}
void gncTaxTableDestroy (GncTaxTable *table)
GncTaxTable *
gncCloneTaxTable (GncTaxTable *from, QofBook *book)
{
GncTaxTable *table;
if (!book) return NULL;
table = g_new0 (GncTaxTable, 1);
qof_instance_init (&table->inst, book);
qof_instance_gemini (&table->inst, &from->inst);
table->name = CACHE_INSERT (from->name);
table->modtime = from->modtime;
table->invisible = from->invisible;
/* XXX not sure how to handle these, but the must be explicitly
* handled or ignored ... */
#if LATER_FIXME
GList * entries;
gint64 refcount;
GncTaxTable * parent;
GncTaxTable * child;
GList * children;
#endif
addObj (table);
gnc_engine_generate_event (&table->inst.guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
return table;
}
void
gncTaxTableDestroy (GncTaxTable *table)
{
if (!table) return;
table->inst.do_free = TRUE;
@ -176,7 +274,8 @@ void gncTaxTableDestroy (GncTaxTable *table)
gncTaxTableCommitEdit (table);
}
static void gncTaxTableFree (GncTaxTable *table)
static void
gncTaxTableFree (GncTaxTable *table)
{
GList *list;
GncTaxTable *child;
@ -210,27 +309,6 @@ static void gncTaxTableFree (GncTaxTable *table)
g_free (table);
}
static void
gncTaxTableAddChild (GncTaxTable *table, GncTaxTable *child)
{
g_return_if_fail(table);
g_return_if_fail(child);
g_return_if_fail(table->inst.do_free == FALSE);
table->children = g_list_prepend(table->children, child);
}
static void
gncTaxTableRemoveChild (GncTaxTable *table, GncTaxTable *child)
{
g_return_if_fail(table);
g_return_if_fail(child);
if (table->inst.do_free) return;
table->children = g_list_remove(table->children, child);
}
GncTaxTableEntry * gncTaxTableEntryCreate (void)
{
GncTaxTableEntry *entry;
@ -246,7 +324,9 @@ void gncTaxTableEntryDestroy (GncTaxTableEntry *entry)
}
/* =============================================================== */
/* Set Functions */
void gncTaxTableSetGUID (GncTaxTable *table, const GUID *guid)
{
if (!table || !guid) return;
@ -318,10 +398,12 @@ void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount)
void gncTaxTableMakeInvisible (GncTaxTable *table)
{
struct _book_info *bi;
if (!table) return;
gncTaxTableBeginEdit (table);
table->invisible = TRUE;
add_or_rem_object (table, FALSE);
bi = gnc_book_get_data (table->inst.book, _GNC_MOD_NAME);
bi->tables = g_list_remove (bi->tables, table);
gncTaxTableCommitEdit (table);
}
@ -394,6 +476,8 @@ void gncTaxTableChanged (GncTaxTable *table)
gncTaxTableCommitEdit (table);
}
/* =============================================================== */
void gncTaxTableBeginEdit (GncTaxTable *table)
{
GNC_BEGIN_EDIT (&table->inst, _GNC_MOD_NAME);
@ -423,6 +507,7 @@ void gncTaxTableCommitEdit (GncTaxTable *table)
}
/* =============================================================== */
/* Get Functions */
GncTaxTable * gncTaxTableLookup (QofBook *book, const GUID *guid)
{
@ -663,41 +748,6 @@ GncTaxTable *gncTaxTableLookupDirect (GUID guid, QofBook *book)
/* Package-Private functions */
static void maybe_resort_list (GncTaxTable *table)
{
struct _book_info *bi;
if (table->parent || table->invisible) return;
bi = gnc_book_get_data (table->inst.book, _GNC_MOD_NAME);
bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare);
}
static void add_or_rem_object (GncTaxTable *table, gboolean add)
{
struct _book_info *bi;
if (!table) return;
bi = gnc_book_get_data (table->inst.book, _GNC_MOD_NAME);
if (add)
bi->tables = g_list_insert_sorted (bi->tables, table,
(GCompareFunc)gncTaxTableCompare);
else
bi->tables = g_list_remove (bi->tables, table);
}
static void addObj (GncTaxTable *table)
{
gncBusinessAddObject (table->inst.book, _GNC_MOD_NAME, table, &table->inst.guid);
add_or_rem_object (table, TRUE);
}
static void remObj (GncTaxTable *table)
{
gncBusinessRemoveObject (table->inst.book, _GNC_MOD_NAME, &table->inst.guid);
add_or_rem_object (table, FALSE);
}
static void _gncTaxTableCreate (QofBook *book)
{
struct _book_info *bi;

View File

@ -1,5 +1,26 @@
/********************************************************************\
* gncTaxTable.h -- the Gnucash Tax Table interface *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
* *
\********************************************************************/
/*
* gncTaxTable.h -- the Gnucash Tax Table interface
* Copyright (C) 2002 Derek Atkins
* Author: Derek Atkins <warlord@MIT.EDU>
*/

View File

@ -1,6 +1,28 @@
/********************************************************************\
* gncTaxTableP.h -- the Gnucash Tax Table private interface *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
* *
\********************************************************************/
/*
* gncTaxTableP.h -- the Gnucash Tax Table interface: private interface
* Copyright (C) 2002 Derek Atkins
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
* Author: Derek Atkins <warlord@MIT.EDU>
*/
@ -19,4 +41,15 @@ void gncTaxTableMakeInvisible (GncTaxTable *table);
gboolean gncTaxTableGetInvisible (GncTaxTable *table);
/** The gncCloneTaxTable() routine makes a copy of the indicated
* tax table, placing it in the indicated book. It copies
* the etc.
* It does not copy parent/child relationships ???
* XXX the above need fixin....
* It then adds a pair of 'gemini' kvp pointers so that each copy
* can be found from the other.
*/
GncTaxTable * gncCloneTaxTable (GncTaxTable *from, QofBook *book);
#endif /* GNC_TAXTABLEP_H_ */