32 #include <qofinstance-p.h>    35 #include "gncTaxTableP.h"    41     GncTaxTableEntryList*  entries;
    55     QofInstanceClass parent_class;
    71 static QofLogModule log_module = GNC_MOD_BUSINESS;
    77 #define GNC_RETURN_ENUM_AS_STRING(x,s) case (x): return (s);    86         g_warning (
"asked to translate unknown amount type %d.\n", type);
   101         g_warning (
"asked to translate unknown taxincluded type %d.\n", type);
   106 #undef GNC_RETURN_ENUM_AS_STRING   107 #define GNC_RETURN_ON_MATCH(s,x) \   108   if(g_strcmp0((s), (str)) == 0) { *type = x; return(TRUE); }   114     g_warning (
"asked to translate unknown amount type string %s.\n",
   115                str ? str : 
"(null)");
   121 gncTaxIncludedStringToType (
const char *str, 
GncTaxIncluded *type)
   126     g_warning (
"asked to translate unknown taxincluded type string %s.\n",
   127                str ? str : 
"(null)");
   131 #undef GNC_RETURN_ON_MATCH   136 #define _GNC_MOD_NAME        GNC_ID_TAXTABLE   138 #define SET_STR(obj, member, str) { \   139         if (!g_strcmp0 (member, str)) return; \   140         gncTaxTableBeginEdit (obj); \   141         CACHE_REPLACE (member, str); \   147     qof_instance_set_dirty(&
table->inst);
   156     if (
table->parent || 
table->invisible) 
return;
   158     bi->tables = g_list_sort (bi->tables, (GCompareFunc)gncTaxTableCompare);
   171     bi->tables = g_list_insert_sorted (bi->tables, 
table,
   172                                        (GCompareFunc)gncTaxTableCompare);
   179     bi->tables = g_list_remove (bi->tables, 
table);
   185     g_return_if_fail(
table);
   186     g_return_if_fail(child);
   189     table->children = g_list_prepend(
table->children, child);
   195     g_return_if_fail(
table);
   196     g_return_if_fail(child);
   200     table->children = g_list_remove(
table->children, child);
   215 G_DEFINE_TYPE(
GncTaxTable, gnc_taxtable, QOF_TYPE_INSTANCE)
   223 gnc_taxtable_dispose(GObject *ttp)
   225     G_OBJECT_CLASS(gnc_taxtable_parent_class)->dispose(ttp);
   229 gnc_taxtable_finalize(GObject* ttp)
   231     G_OBJECT_CLASS(gnc_taxtable_parent_class)->dispose(ttp);
   235 gnc_taxtable_get_property (GObject         *
object,
   242     g_return_if_fail(GNC_IS_TAXTABLE(
object));
   244     tt = GNC_TAXTABLE(
object);
   248         g_value_set_string(value, tt->name);
   251         g_value_set_boolean(value, tt->invisible);
   254         g_value_set_uint64(value, tt->refcount);
   257         G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
   263 gnc_taxtable_set_property (GObject         *
object,
   270     g_return_if_fail(GNC_IS_TAXTABLE(
object));
   272     tt = GNC_TAXTABLE(
object);
   273     g_assert (qof_instance_get_editlevel(tt));
   278         gncTaxTableSetName(tt, g_value_get_string(value));
   281         if (g_value_get_boolean(value))
   283             gncTaxTableMakeInvisible(tt);
   287         gncTaxTableSetRefcount(tt, g_value_get_uint64(value));
   290         G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
   301     g_return_val_if_fail(inst != NULL, FALSE);
   302     g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
   304     tt = GNC_TAXTABLE(inst);
   305     return g_strdup_printf(
"Tax table %s", tt->name);
   314     g_return_val_if_fail(inst != NULL, FALSE);
   315     g_return_val_if_fail(GNC_IS_TAXTABLE(inst), FALSE);
   317     tt = GNC_TAXTABLE(inst);
   319     if (GNC_IS_ACCOUNT(ref))
   323         for (node = tt->entries; node != NULL; node = node->next)
   327             if (tte->account == GNC_ACCOUNT(ref))
   346     if (!GNC_IS_ACCOUNT(ref))
   355 gnc_taxtable_class_init (GncTaxTableClass *klass)
   357     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   358     QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
   360     gobject_class->dispose = gnc_taxtable_dispose;
   361     gobject_class->finalize = gnc_taxtable_finalize;
   362     gobject_class->set_property = gnc_taxtable_set_property;
   363     gobject_class->get_property = gnc_taxtable_get_property;
   365     qof_class->get_display_name = impl_get_display_name;
   366     qof_class->refers_to_object = impl_refers_to_object;
   367     qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
   369     g_object_class_install_property
   372      g_param_spec_string (
"name",
   374                           "The accountName is an arbitrary string "   375                           "assigned by the user.  It is intended to "   376                           "a short, 10 to 30 character long string "   377                           "that is displayed by the GUI as the "   378                           "tax table mnemonic.",
   382     g_object_class_install_property
   385      g_param_spec_boolean (
"invisible",
   387                            "TRUE if the tax table is invisible.  FALSE if visible.",
   391     g_object_class_install_property
   394      g_param_spec_uint64(
"ref-count",
   396                          "The ref-count property contains number of times this tax table "   406 gncTaxTableCreate (QofBook *book)
   409     if (!book) 
return NULL;
   411     table = g_object_new (GNC_TYPE_TAXTABLE, NULL);
   413     table->name = CACHE_INSERT (
"");
   423     qof_instance_set_destroying(
table, TRUE);
   424     qof_instance_set_dirty (&
table->inst);
   425     gncTaxTableCommitEdit (
table);
   437     CACHE_REMOVE (
table->name);
   441     for (list = 
table->entries; list; list = list->next)
   442         gncTaxTableEntryDestroy (list->data);
   443     g_list_free (
table->entries);
   446         PERR(
"free a taxtable without do_free set!");
   453     for (list = 
table->children; list; list = list->next)
   456         gncTaxTableSetParent(child, NULL);
   458     g_list_free(
table->children);
   461     g_object_unref (
table);
   470     entry->amount = gnc_numeric_zero ();
   485     if (!
table || !name) 
return;
   488     maybe_resort_list (
table);
   489     gncTaxTableCommitEdit (
table);
   495     gncTaxTableBeginEdit (
table);
   498     table->parent = parent;
   500         gncTaxTableAddChild(parent, 
table);
   502     gncTaxTableMakeInvisible (
table);
   504     gncTaxTableCommitEdit (
table);
   510     gncTaxTableBeginEdit (
table);
   511     table->child = child;
   513     gncTaxTableCommitEdit (
table);
   519     if (
table->parent || 
table->invisible) 
return;        
   520     gncTaxTableBeginEdit (
table);
   523     gncTaxTableCommitEdit (
table);
   529     if (
table->parent || 
table->invisible) 
return;        
   530     g_return_if_fail (
table->refcount > 0);
   531     gncTaxTableBeginEdit (
table);
   534     gncTaxTableCommitEdit (
table);
   540     g_return_if_fail (refcount >= 0);
   541     gncTaxTableBeginEdit (
table);
   542     table->refcount = refcount;
   544     gncTaxTableCommitEdit (
table);
   551     gncTaxTableBeginEdit (
table);
   552     table->invisible = TRUE;
   554     bi->tables = g_list_remove (bi->tables, 
table);
   555     gncTaxTableCommitEdit (
table);
   560     if (!entry || !account) 
return;
   561     if (entry->account == account) 
return;
   562     entry->account = account;
   565         mark_table (entry->table);
   566         mod_table (entry->table);
   573     if (entry->type == type) 
return;
   577         mark_table (entry->table);
   578         mod_table (entry->table);
   582 void gncTaxTableEntrySetAmount (
GncTaxTableEntry *entry, gnc_numeric amount)
   586     entry->amount = amount;
   589         mark_table (entry->table);
   590         mod_table (entry->table);
   596     if (!
table || !entry) 
return;
   597     if (entry->table == 
table) 
return; 
   599     gncTaxTableBeginEdit (
table);
   601         gncTaxTableRemoveEntry (entry->table, entry);
   603     entry->table = 
table;
   604     table->entries = g_list_insert_sorted (
table->entries, entry,
   605                                            (GCompareFunc)gncTaxTableEntryCompare);
   608     gncTaxTableCommitEdit (
table);
   613     if (!
table || !entry) 
return;
   614     gncTaxTableBeginEdit (
table);
   616     table->entries = g_list_remove (
table->entries, entry);
   619     gncTaxTableCommitEdit (
table);
   625     gncTaxTableBeginEdit (
table);
   627     gncTaxTableCommitEdit (
table);
   639     PERR(
"TaxTable QofBackend Failure: %d", errcode);
   640     gnc_engine_signal_commit_error( errcode );
   643 static void gncTaxTableOnDone (
QofInstance *inst) {}
   648     gncTaxTableFree (
table);
   656                                  GNC_FEATURE_KVP_EXTRA_DATA);
   660                            gncTaxTableOnDone, table_free);
   667 GncTaxTable *gncTaxTableLookupByName (QofBook *book, 
const char *name)
   669     GList *list = gncTaxTableGetTables (book);
   671     for ( ; list; list = list->next)
   674         if (!g_strcmp0 (
table->name, name))
   681 gncTaxTableGetDefault (QofBook *book, GncOwnerType type)
   685     const char *vendor = 
"Default Vendor TaxTable";
   686     const char *customer = 
"Default Customer TaxTable";
   687     const char *section = 
"Business";
   689     g_return_val_if_fail (book != NULL, NULL);
   690     g_return_val_if_fail (type == GNC_OWNER_CUSTOMER || \
   691                           type == GNC_OWNER_VENDOR, NULL);
   692     path = g_slist_prepend (path, type == GNC_OWNER_CUSTOMER ? (
void*)customer : (
void*)vendor);
   693     path = g_slist_prepend (path, (
void*)section);
   695     guid = qof_book_get_guid_option (book, path);
   698     return gncTaxTableLookup (book, guid);
   701 GncTaxTableList * gncTaxTableGetTables (QofBook *book)
   704     if (!book) 
return NULL;
   707     return bi ? bi->tables : NULL;
   712     if (!
table) 
return NULL;
   719     if (!entry) 
return NULL;
   721     e = gncTaxTableEntryCreate ();
   722     gncTaxTableEntrySetAccount (e, entry->account);
   723     gncTaxTableEntrySetType (e, entry->type);
   724     gncTaxTableEntrySetAmount (e, entry->amount);
   734     if (!
table) 
return NULL;
   736     gncTaxTableSetName (t, 
table->name);
   737     for (list = 
table->entries; list; list = list->next)
   741         e = gncTaxTableEntryCopy (entry);
   744         gncTaxTableAddEntry (t, e);
   753     if (!
table) 
return NULL;
   758         child = gncTaxTableCopy (
table);
   759         gncTaxTableSetChild (
table, child);
   760         gncTaxTableSetParent (child, 
table);
   767     if (!
table) 
return NULL;
   768     return table->parent;
   773     if (!
table) 
return NULL;
   774     return table->entries;
   779     if (!
table) 
return 0;
   780     return table->refcount;
   785     if (!
table) 
return 0;
   786     return table->modtime;
   791     if (!
table) 
return FALSE;
   792     return table->invisible;
   797     if (!entry) 
return NULL;
   798     return entry->account;
   803     if (!entry) 
return 0;
   809     if (!entry) 
return gnc_numeric_zero();
   810     return entry->amount;
   817     if (!entry) 
return NULL;
   823     char *name_a, *name_b;
   826     if (!a && !b) 
return 0;
   832     retval = g_strcmp0(name_a, name_b);
   844     if (!a && !b) 
return 0;
   847     return g_strcmp0 (a->name, b->name);
   852     if (a == NULL && b == NULL) 
return TRUE;
   853     if (a == NULL || b == NULL) 
return FALSE;
   857         PWARN(
"accounts differ");
   861     if (a->type != b->type)
   863         PWARN(
"types differ");
   869         PWARN(
"amounts differ");
   878     if (a == NULL && b == NULL) 
return TRUE;
   879     if (a == NULL || b == NULL) 
return FALSE;
   881     g_return_val_if_fail(GNC_IS_TAXTABLE(a), FALSE);
   882     g_return_val_if_fail(GNC_IS_TAXTABLE(b), FALSE);
   884     if (g_strcmp0(a->name, b->name) != 0)
   886         PWARN(
"Names differ: %s vs %s", a->name, b->name);
   890     if (a->invisible != b->invisible)
   892         PWARN(
"invisible flags differ");
   896     if ((a->entries != NULL) != (b->entries != NULL))
   898         PWARN(
"only one has entries");
   902     if (a->entries != NULL && b->entries != NULL)
   904         GncTaxTableEntryList* a_node;
   905         GncTaxTableEntryList* b_node;
   907         for (a_node = a->entries, b_node = b->entries;
   908                 a_node != NULL && b_node != NULL;
   909                 a_node = a_node->next, b_node = b_node->next)
   914                 PWARN(
"entries differ");
   919         if (a_node != NULL || b_node != NULL)
   921             PWARN(
"Unequal number of entries");
   945     GncAccountValue *res = NULL;
   947     g_return_val_if_fail (acc, list);
   951     for (li = list; li; li = li->next)
   954         if (res->account == acc)
   963     res = g_new0 (GncAccountValue, 1);
   966     return g_list_prepend (list, res);
   974     for (li = l2; li; li = li->next )
   976         GncAccountValue *val = li->data;
   986     gnc_numeric total = gnc_numeric_zero ();
   988     for ( ; list ; list = list->next)
   990         GncAccountValue *val = list->data;
  1000     for ( node = list; node ; node = node->next)
  1001         g_free (node->data);
  1008 static void _gncTaxTableCreate (QofBook *book)
  1019 destroy_taxtable_on_book_close (
QofInstance *ent, gpointer data)
  1023     gncTaxTableBeginEdit (
table);
  1024     gncTaxTableDestroy (
table);
  1027 static void _gncTaxTableDestroy (QofBook *book)
  1037     qof_collection_foreach (col, destroy_taxtable_on_book_close, NULL);
  1039     g_list_free (bi->tables);
  1043 static QofObject gncTaxTableDesc =
  1046     DI(.e_type            = ) _GNC_MOD_NAME,
  1047     DI(.type_label        = ) "Tax Table",
  1048     DI(.create            = ) (gpointer)gncTaxTableCreate,
  1049     DI(.book_begin        = ) _gncTaxTableCreate,
  1050     DI(.book_end          = ) _gncTaxTableDestroy,
  1053     DI(.foreach           = ) qof_collection_foreach,
  1054     DI(.printable         = ) NULL,
  1058 gboolean gncTaxTableRegister (
void)
  1060     static QofParam params[] =
 int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times. 
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number. 
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance. 
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer. 
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection. 
GncTaxIncluded
How to interpret the TaxIncluded. 
#define GNC_TT_NAME
QOF parameter definitions. 
QofBackendError
The errors that can be reported to the GUI & other front-end users. 
GList * qof_instance_get_referring_object_list_from_collection(const QofCollection *coll, const QofInstance *ref)
Returns a list of objects from the collection which refer to the specific object. ...
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed. 
void gnc_features_set_used(QofBook *book, const gchar *feature)
Indicate that the current book uses the given feature. 
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem. 
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b. 
QofCollection * qof_instance_get_collection(gconstpointer ptr)
Return the collection this instance belongs to. 
gnc_numeric gncAccountValueTotal(GList *list)
return the total for this list 
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type. 
gint gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b. 
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface. 
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers 
#define PERR(format, args...)
Log a serious error. 
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these 
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters. 
#define PWARN(format, args...)
Log a warning. 
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance. 
gboolean qof_begin_edit(QofInstance *inst)
begin_edit 
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
Reduce the result value by common factor elimination, using the smallest possible value for the denom...
void qof_book_set_data(QofBook *book, const gchar *key, gpointer data)
The qof_book_set_data() allows arbitrary pointers to structs to be stored in QofBook. 
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend 
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions. 
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag 
void gncAccountValueDestroy(GList *list)
Destroy a list of accountvalues. 
gboolean xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
Compare two accounts for equality - this is a deep compare. 
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b are exactly the same (have the same numerator and ...
GList * gncAccountValueAddList(GList *l1, GList *l2)
Merge l2 into l1. 
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
time64 gnc_time(time64 *tbuf)
get the current time 
GNCNumericErrorCode gnc_numeric_check(gnc_numeric a)
Check for error signal in value. 
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type. 
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
gboolean qof_object_register(const QofObject *object)
Register new types of object objects. 
GList * gncAccountValueAdd(GList *list, Account *acc, gnc_numeric value)
This will add value to the account-value for acc, creating a new list object if necessary. 
gboolean qof_instance_has_kvp(QofInstance *inst)
Report whether a QofInstance has anything stored in KVP. 
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments. 
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument. 
The type used to store guids in C. 
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
Retrieves arbitrary pointers to structs stored by qof_book_set_data. 
GncAmountType
How to interpret the amount. 
modtime is the internal date of the last modtime See libgnucash/engine/TaxTableBillTermImmutability.txt for an explanation of the following Code that handles refcount, parent, child, invisible and children is identical to that in ::GncBillTerm 
Utility functions for file access.