GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Enumerations | Functions

Define an object to track tax properties for invoices. More...

Files

file  gncTaxTable.h
 Tax Table programming interface.
 

Data Structures

struct  GncAccountValue
 
struct  GncTaxTable
 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 More...
 
struct  GncTaxTableEntry
 

Macros

#define GNC_ID_TAXTABLE   "gncTaxTable"
 
#define GNC_TYPE_TAXTABLE   (gnc_taxtable_get_type ())
 
#define GNC_TAXTABLE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TAXTABLE, GncTaxTable))
 
#define GNC_TAXTABLE_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TAXTABLE, GncTaxTableClass))
 
#define GNC_IS_TAXTABLE(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TAXTABLE))
 
#define GNC_IS_TAXTABLE_CLASS(k)    (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TAXTABLE))
 
#define GNC_TAXTABLE_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TAXTABLE, GncTaxTableClass))
 
#define GNC_TT_NAME   "tax table name"
 QOF parameter definitions.
 
#define GNC_TT_REFCOUNT   "reference count"
 
#define gncTaxTableGetGUID(x)   qof_instance_get_guid(QOF_INSTANCE(x))
 
#define gncTaxTableRetGUID(x)   (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
 
#define gncTaxTableLookupDirect(G, B)   gncTaxTableLookup((B), &(G))
 

Enumerations

enum  GncAmountType { GNC_AMT_TYPE_VALUE = 1 , GNC_AMT_TYPE_PERCENT }
 How to interpret the amount. More...
 
enum  GncTaxIncluded { GNC_TAXINCLUDED_YES = 1 , GNC_TAXINCLUDED_NO , GNC_TAXINCLUDED_USEGLOBAL }
 How to interpret the TaxIncluded. More...
 

Functions

GType gnc_taxtable_get_type (void)
 
const char * gncAmountTypeToString (GncAmountType type)
 
gboolean gncAmountStringToType (const char *str, GncAmountType *type)
 
const char * gncTaxIncludedTypeToString (GncTaxIncluded type)
 
gboolean gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type)
 
void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry)
 
void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry)
 
void gncTaxTableChanged (GncTaxTable *table)
 
void gncTaxTableBeginEdit (GncTaxTable *table)
 
void gncTaxTableCommitEdit (GncTaxTable *table)
 
gboolean gncTaxTableEqual (const GncTaxTable *a, const GncTaxTable *b)
 
int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b)
 
int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b)
 
gboolean gncTaxTableEntryEqual (const GncTaxTableEntry *a, const GncTaxTableEntry *b)
 
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.
 
GList * gncAccountValueAddList (GList *l1, GList *l2)
 Merge l2 into l1.
 
gnc_numeric gncAccountValueTotal (GList *list)
 return the total for this list
 
void gncAccountValueDestroy (GList *list)
 Destroy a list of accountvalues.
 

Get Functions

typedef GList GncTaxTableList
 
typedef GList GncTaxTableEntryList
 
GncTaxTablegncTaxTableLookupByName (QofBook *book, const char *name)
 
GncTaxTablegncTaxTableGetDefault (QofBook *book, GncOwnerType type)
 
GncTaxTableList * gncTaxTableGetTables (QofBook *book)
 
const char * gncTaxTableGetName (const GncTaxTable *table)
 
GncTaxTablegncTaxTableGetParent (const GncTaxTable *table)
 
GncTaxTablegncTaxTableReturnChild (GncTaxTable *table, gboolean make_new)
 
GncTaxTableEntryList * gncTaxTableGetEntries (const GncTaxTable *table)
 
gint64 gncTaxTableGetRefcount (const GncTaxTable *table)
 
time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table)
 
AccountgncTaxTableEntryGetAccount (const GncTaxTableEntry *entry)
 
GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry)
 
gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry)
 
#define gncTaxTableGetChild(t)   gncTaxTableReturnChild((t),FALSE)
 

Create/Destroy Functions

GncTaxTablegncTaxTableCreate (QofBook *book)
 
void gncTaxTableDestroy (GncTaxTable *table)
 
GncTaxTableEntrygncTaxTableEntryCreate (void)
 
void gncTaxTableEntryDestroy (GncTaxTableEntry *entry)
 

Set Functions

void gncTaxTableSetName (GncTaxTable *table, const char *name)
 
void gncTaxTableIncRef (GncTaxTable *table)
 
void gncTaxTableDecRef (GncTaxTable *table)
 
void gncTaxTableEntrySetAccount (GncTaxTableEntry *entry, Account *account)
 
void gncTaxTableEntrySetType (GncTaxTableEntry *entry, GncAmountType type)
 
void gncTaxTableEntrySetAmount (GncTaxTableEntry *entry, gnc_numeric amount)
 

Detailed Description

Define an object to track tax properties for invoices.

Note
A tax table added to an invoice is immutable, that is it can't change any more. To achieve that a tax table is copied when added to an invoice. This uses some internal fields to track this which are explained in Some notes on tracking fields in gncBillTerm and gncTaxTable objects.

Macro Definition Documentation

◆ GNC_ID_TAXTABLE

#define GNC_ID_TAXTABLE   "gncTaxTable"

Definition at line 101 of file gncTaxTable.h.

◆ GNC_IS_TAXTABLE

#define GNC_IS_TAXTABLE (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TAXTABLE))

Definition at line 109 of file gncTaxTable.h.

158{
159 QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_TAXTABLE, GncTaxTable);
160}
161
162GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
163GncTaxTable *gncTaxTableGetDefault (QofBook *book, GncOwnerType type);
164
165typedef GList GncTaxTableList;
166GncTaxTableList * gncTaxTableGetTables (QofBook *book);
167
168const char *gncTaxTableGetName (const GncTaxTable *table);
169GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table);
170GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
171#define gncTaxTableGetChild(t) gncTaxTableReturnChild((t),FALSE)
172typedef GList GncTaxTableEntryList;
173GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table);
174gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
175time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table);
176
177Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
178GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);
179gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry);
182int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b);
183int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b);
184gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b);
185
186/************************************************/
187
188struct _gncAccountValue
189{
190 Account * account;
191 gnc_numeric value;
192};
193
198GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value);
199
201GList *gncAccountValueAddList (GList *l1, GList *l2);
202
204gnc_numeric gncAccountValueTotal (GList *list);
205
207void gncAccountValueDestroy (GList *list);
208
210#define GNC_TT_NAME "tax table name"
211#define GNC_TT_REFCOUNT "reference count"
212
214#define gncTaxTableGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
215#define gncTaxTableRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
216#define gncTaxTableLookupDirect(G,B) gncTaxTableLookup((B), &(G))
217
218#ifdef __cplusplus
219}
220#endif
221
222#endif /* GNC_TAXTABLE_H_ */
#define QOF_BOOK_RETURN_ENTITY(book, guid, e_type, c_type)
Encapsulates all the information about a dataset manipulated by QOF.
Definition qofbook.h:101
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
void gncAccountValueDestroy(GList *list)
Destroy a list of accountvalues.
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.
GncAmountType
How to interpret the amount.
Definition gncTaxTable.h:79
GList * gncAccountValueAddList(GList *l1, GList *l2)
Merge l2 into l1.
gnc_numeric gncAccountValueTotal(GList *list)
return the total for this list
STRUCTS.
modtime is the internal date of the last modtime See libgnucash/engine/TaxTableBillTermImmutability....
QofBook reference.
Definition qofbook-p.hpp:47

◆ GNC_IS_TAXTABLE_CLASS

#define GNC_IS_TAXTABLE_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TAXTABLE))

Definition at line 111 of file gncTaxTable.h.

◆ GNC_TAXTABLE

#define GNC_TAXTABLE (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TAXTABLE, GncTaxTable))

Definition at line 105 of file gncTaxTable.h.

◆ GNC_TAXTABLE_CLASS

#define GNC_TAXTABLE_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TAXTABLE, GncTaxTableClass))

Definition at line 107 of file gncTaxTable.h.

◆ GNC_TAXTABLE_GET_CLASS

#define GNC_TAXTABLE_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TAXTABLE, GncTaxTableClass))

Definition at line 113 of file gncTaxTable.h.

◆ GNC_TT_NAME

#define GNC_TT_NAME   "tax table name"

QOF parameter definitions.

Definition at line 210 of file gncTaxTable.h.

◆ GNC_TT_REFCOUNT

#define GNC_TT_REFCOUNT   "reference count"

Definition at line 211 of file gncTaxTable.h.

◆ GNC_TYPE_TAXTABLE

#define GNC_TYPE_TAXTABLE   (gnc_taxtable_get_type ())

Definition at line 104 of file gncTaxTable.h.

◆ gncTaxTableGetChild

#define gncTaxTableGetChild (   t)    gncTaxTableReturnChild((t),FALSE)

Definition at line 171 of file gncTaxTable.h.

◆ gncTaxTableGetGUID

#define gncTaxTableGetGUID (   x)    qof_instance_get_guid(QOF_INSTANCE(x))
Deprecated:
routine

Definition at line 214 of file gncTaxTable.h.

◆ gncTaxTableLookupDirect

#define gncTaxTableLookupDirect (   G,
 
)    gncTaxTableLookup((B), &(G))

Definition at line 216 of file gncTaxTable.h.

◆ gncTaxTableRetGUID

#define gncTaxTableRetGUID (   x)    (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))

Definition at line 215 of file gncTaxTable.h.

Typedef Documentation

◆ GncTaxTableEntryList

typedef GList GncTaxTableEntryList

Definition at line 172 of file gncTaxTable.h.

◆ GncTaxTableList

typedef GList GncTaxTableList

Definition at line 165 of file gncTaxTable.h.

Enumeration Type Documentation

◆ GncAmountType

How to interpret the amount.

You can interpret it as a VALUE or a PERCENT.

Enumerator
GNC_AMT_TYPE_VALUE 

tax is a number

GNC_AMT_TYPE_PERCENT 

tax is a percentage

Definition at line 78 of file gncTaxTable.h.

79{
@ GNC_AMT_TYPE_VALUE
tax is a number
Definition gncTaxTable.h:80
@ GNC_AMT_TYPE_PERCENT
tax is a percentage
Definition gncTaxTable.h:81

◆ GncTaxIncluded

How to interpret the TaxIncluded.

Enumerator
GNC_TAXINCLUDED_YES 

tax is included

GNC_TAXINCLUDED_NO 

tax is not included

GNC_TAXINCLUDED_USEGLOBAL 

use the global setting

Definition at line 85 of file gncTaxTable.h.

86{
GncTaxIncluded
How to interpret the TaxIncluded.
Definition gncTaxTable.h:86
@ GNC_TAXINCLUDED_NO
tax is not included
Definition gncTaxTable.h:88
@ GNC_TAXINCLUDED_YES
tax is included
Definition gncTaxTable.h:87
@ GNC_TAXINCLUDED_USEGLOBAL
use the global setting
Definition gncTaxTable.h:89

Function Documentation

◆ gncAccountValueAdd()

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.

Definition at line 942 of file gncTaxTable.c.

943{
944 GList *li;
945 GncAccountValue *res = NULL;
946
947 g_return_val_if_fail (acc, list);
948 g_return_val_if_fail (gnc_numeric_check (value) == GNC_ERROR_OK, list);
949
950 /* Try to find the account in the list */
951 for (li = list; li; li = li->next)
952 {
953 res = li->data;
954 if (res->account == acc)
955 {
956 res->value = gnc_numeric_add (res->value, value, GNC_DENOM_AUTO,
957 GNC_HOW_DENOM_REDUCE | GNC_HOW_RND_ROUND_HALF_UP);
958 return list;
959 }
960 }
961 /* Nope, didn't find it. */
962
963 res = g_new0 (GncAccountValue, 1);
964 res->account = acc;
965 res->value = value;
966 return g_list_prepend (list, res);
967}
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
@ GNC_ERROR_OK
No error.

◆ gncAccountValueAddList()

GList * gncAccountValueAddList ( GList *  l1,
GList *  l2 
)

Merge l2 into l1.

l2 is not touched.

Definition at line 970 of file gncTaxTable.c.

971{
972 GList *li;
973
974 for (li = l2; li; li = li->next )
975 {
976 GncAccountValue *val = li->data;
977 l1 = gncAccountValueAdd (l1, val->account, val->value);
978 }
979
980 return l1;
981}

◆ gncAccountValueDestroy()

void gncAccountValueDestroy ( GList *  list)

Destroy a list of accountvalues.

Definition at line 997 of file gncTaxTable.c.

998{
999 GList *node;
1000 for ( node = list; node ; node = node->next)
1001 g_free (node->data);
1002
1003 g_list_free (list);
1004}

◆ gncAccountValueTotal()

gnc_numeric gncAccountValueTotal ( GList *  list)

return the total for this list

Definition at line 984 of file gncTaxTable.c.

985{
986 gnc_numeric total = gnc_numeric_zero ();
987
988 for ( ; list ; list = list->next)
989 {
990 GncAccountValue *val = list->data;
991 total = gnc_numeric_add (total, val->value, GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE | GNC_HOW_RND_ROUND_HALF_UP);
992 }
993 return total;
994}

◆ gncAmountStringToType()

gboolean gncAmountStringToType ( const char *  str,
GncAmountType type 
)

Definition at line 110 of file gncTaxTable.c.

111{
112 GNC_RETURN_ON_MATCH ("VALUE", GNC_AMT_TYPE_VALUE);
113 GNC_RETURN_ON_MATCH ("PERCENT", GNC_AMT_TYPE_PERCENT);
114 g_warning ("asked to translate unknown amount type string %s.\n",
115 str ? str : "(null)");
116
117 return(FALSE);
118}

◆ gncAmountTypeToString()

const char * gncAmountTypeToString ( GncAmountType  type)

Definition at line 79 of file gncTaxTable.c.

80{
81 switch (type)
82 {
83 GNC_RETURN_ENUM_AS_STRING(GNC_AMT_TYPE_VALUE, "VALUE");
84 GNC_RETURN_ENUM_AS_STRING(GNC_AMT_TYPE_PERCENT, "PERCENT");
85 default:
86 g_warning ("asked to translate unknown amount type %d.\n", type);
87 break;
88 }
89 return(NULL);
90}

◆ gncTaxIncludedStringToType()

gboolean gncTaxIncludedStringToType ( const char *  str,
GncTaxIncluded type 
)

Definition at line 121 of file gncTaxTable.c.

122{
123 GNC_RETURN_ON_MATCH ("YES", GNC_TAXINCLUDED_YES);
124 GNC_RETURN_ON_MATCH ("NO", GNC_TAXINCLUDED_NO);
125 GNC_RETURN_ON_MATCH ("USEGLOBAL", GNC_TAXINCLUDED_USEGLOBAL);
126 g_warning ("asked to translate unknown taxincluded type string %s.\n",
127 str ? str : "(null)");
128
129 return(FALSE);
130}

◆ gncTaxIncludedTypeToString()

const char * gncTaxIncludedTypeToString ( GncTaxIncluded  type)

Definition at line 93 of file gncTaxTable.c.

94{
95 switch (type)
96 {
97 GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_YES, "YES");
98 GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_NO, "NO");
99 GNC_RETURN_ENUM_AS_STRING(GNC_TAXINCLUDED_USEGLOBAL, "USEGLOBAL");
100 default:
101 g_warning ("asked to translate unknown taxincluded type %d.\n", type);
102 break;
103 }
104 return(NULL);
105}

◆ gncTaxTableAddEntry()

void gncTaxTableAddEntry ( GncTaxTable table,
GncTaxTableEntry entry 
)

Definition at line 594 of file gncTaxTable.c.

595{
596 if (!table || !entry) return;
597 if (entry->table == table) return; /* already mine */
598
599 gncTaxTableBeginEdit (table);
600 if (entry->table)
601 gncTaxTableRemoveEntry (entry->table, entry);
602
603 entry->table = table;
604 table->entries = g_list_insert_sorted (table->entries, entry,
605 (GCompareFunc)gncTaxTableEntryCompare);
606 mark_table (table);
607 mod_table (table);
608 gncTaxTableCommitEdit (table);
609}

◆ gncTaxTableBeginEdit()

void gncTaxTableBeginEdit ( GncTaxTable table)

Definition at line 632 of file gncTaxTable.c.

633{
634 qof_begin_edit(&table->inst);
635}
gboolean qof_begin_edit(QofInstance *inst)
begin_edit

◆ gncTaxTableChanged()

void gncTaxTableChanged ( GncTaxTable table)

Definition at line 622 of file gncTaxTable.c.

623{
624 if (!table) return;
625 gncTaxTableBeginEdit (table);
626 table->child = NULL;
627 gncTaxTableCommitEdit (table);
628}

◆ gncTaxTableCommitEdit()

void gncTaxTableCommitEdit ( GncTaxTable table)

Definition at line 651 of file gncTaxTable.c.

652{
653 /* GnuCash 2.6.3 and earlier didn't handle taxtable kvp's... */
654 if (qof_instance_has_kvp (QOF_INSTANCE (table)))
656 GNC_FEATURE_KVP_EXTRA_DATA);
657
658 if (!qof_commit_edit (QOF_INSTANCE(table))) return;
659 qof_commit_edit_part2 (&table->inst, gncTaxTableOnError,
660 gncTaxTableOnDone, table_free);
661}
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_instance_has_kvp(QofInstance *inst)
Report whether a QofInstance has anything stored in KVP.
void gnc_features_set_used(QofBook *book, const gchar *feature)
Indicate that the current book uses the given feature.
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
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers

◆ gncTaxTableCompare()

int gncTaxTableCompare ( const GncTaxTable a,
const GncTaxTable b 
)

Definition at line 842 of file gncTaxTable.c.

843{
844 if (!a && !b) return 0;
845 if (!a) return -1;
846 if (!b) return 1;
847 return g_strcmp0 (a->name, b->name);
848}

◆ gncTaxTableCreate()

GncTaxTable * gncTaxTableCreate ( QofBook book)

Definition at line 406 of file gncTaxTable.c.

407{
409 if (!book) return NULL;
410
411 table = g_object_new (GNC_TYPE_TAXTABLE, NULL);
412 qof_instance_init_data (&table->inst, _GNC_MOD_NAME, book);
413 table->name = CACHE_INSERT ("");
414 addObj (table);
415 qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL);
416 return table;
417}
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition qofevent.cpp:231
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.

◆ gncTaxTableDecRef()

void gncTaxTableDecRef ( GncTaxTable table)

Definition at line 526 of file gncTaxTable.c.

527{
528 if (!table) return;
529 if (table->parent || table->invisible) return; /* children dont need refcounts */
530 g_return_if_fail (table->refcount > 0);
531 gncTaxTableBeginEdit (table);
532 table->refcount--;
533 mark_table (table);
534 gncTaxTableCommitEdit (table);
535}

◆ gncTaxTableDestroy()

void gncTaxTableDestroy ( GncTaxTable table)

Definition at line 420 of file gncTaxTable.c.

421{
422 if (!table) return;
423 qof_instance_set_destroying(table, TRUE);
424 qof_instance_set_dirty (&table->inst);
425 gncTaxTableCommitEdit (table);
426}

◆ gncTaxTableEntryCompare()

int gncTaxTableEntryCompare ( const GncTaxTableEntry a,
const GncTaxTableEntry b 
)

Definition at line 821 of file gncTaxTable.c.

822{
823 char *name_a, *name_b;
824 int retval;
825
826 if (!a && !b) return 0;
827 if (!a) return -1;
828 if (!b) return 1;
829
830 name_a = gnc_account_get_full_name (a->account);
831 name_b = gnc_account_get_full_name (b->account);
832 retval = g_strcmp0(name_a, name_b);
833 g_free(name_a);
834 g_free(name_b);
835
836 if (retval)
837 return retval;
838
839 return gnc_numeric_compare (a->amount, b->amount);
840}
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...
Definition Account.cpp:3305
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b

◆ gncTaxTableEntryCreate()

GncTaxTableEntry * gncTaxTableEntryCreate ( void  )

Definition at line 466 of file gncTaxTable.c.

467{
468 GncTaxTableEntry *entry;
469 entry = g_new0 (GncTaxTableEntry, 1);
470 entry->amount = gnc_numeric_zero ();
471 return entry;
472}

◆ gncTaxTableEntryDestroy()

void gncTaxTableEntryDestroy ( GncTaxTableEntry entry)

Definition at line 474 of file gncTaxTable.c.

475{
476 if (!entry) return;
477 g_free (entry);
478}

◆ gncTaxTableEntryEqual()

gboolean gncTaxTableEntryEqual ( const GncTaxTableEntry a,
const GncTaxTableEntry b 
)

Definition at line 850 of file gncTaxTable.c.

851{
852 if (a == NULL && b == NULL) return TRUE;
853 if (a == NULL || b == NULL) return FALSE;
854
855 if (!xaccAccountEqual(a->account, b->account, TRUE))
856 {
857 PWARN("accounts differ");
858 return FALSE;
859 }
860
861 if (a->type != b->type)
862 {
863 PWARN("types differ");
864 return FALSE;
865 }
866
867 if (!gnc_numeric_equal(a->amount, b->amount))
868 {
869 PWARN("amounts differ");
870 return FALSE;
871 }
872
873 return TRUE;
874}
gboolean xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
Compare two accounts for equality - this is a deep compare.
Definition Account.cpp:1666
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.

◆ gncTaxTableEntryGetAccount()

Account * gncTaxTableEntryGetAccount ( const GncTaxTableEntry entry)

Definition at line 795 of file gncTaxTable.c.

796{
797 if (!entry) return NULL;
798 return entry->account;
799}

◆ gncTaxTableEntryGetAmount()

gnc_numeric gncTaxTableEntryGetAmount ( const GncTaxTableEntry entry)

Definition at line 807 of file gncTaxTable.c.

808{
809 if (!entry) return gnc_numeric_zero();
810 return entry->amount;
811}

◆ gncTaxTableEntryGetType()

GncAmountType gncTaxTableEntryGetType ( const GncTaxTableEntry entry)

Definition at line 801 of file gncTaxTable.c.

802{
803 if (!entry) return 0;
804 return entry->type;
805}

◆ gncTaxTableEntrySetAccount()

void gncTaxTableEntrySetAccount ( GncTaxTableEntry entry,
Account account 
)

Definition at line 558 of file gncTaxTable.c.

559{
560 if (!entry || !account) return;
561 if (entry->account == account) return;
562 entry->account = account;
563 if (entry->table)
564 {
565 mark_table (entry->table);
566 mod_table (entry->table);
567 }
568}

◆ gncTaxTableEntrySetAmount()

void gncTaxTableEntrySetAmount ( GncTaxTableEntry entry,
gnc_numeric  amount 
)

Definition at line 582 of file gncTaxTable.c.

583{
584 if (!entry) return;
585 if (gnc_numeric_eq (entry->amount, amount)) return;
586 entry->amount = amount;
587 if (entry->table)
588 {
589 mark_table (entry->table);
590 mod_table (entry->table);
591 }
592}
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 ...

◆ gncTaxTableEntrySetType()

void gncTaxTableEntrySetType ( GncTaxTableEntry entry,
GncAmountType  type 
)

Definition at line 570 of file gncTaxTable.c.

571{
572 if (!entry) return;
573 if (entry->type == type) return;
574 entry->type = type;
575 if (entry->table)
576 {
577 mark_table (entry->table);
578 mod_table (entry->table);
579 }
580}

◆ gncTaxTableEqual()

gboolean gncTaxTableEqual ( const GncTaxTable a,
const GncTaxTable b 
)

Definition at line 876 of file gncTaxTable.c.

877{
878 if (a == NULL && b == NULL) return TRUE;
879 if (a == NULL || b == NULL) return FALSE;
880
881 g_return_val_if_fail(GNC_IS_TAXTABLE(a), FALSE);
882 g_return_val_if_fail(GNC_IS_TAXTABLE(b), FALSE);
883
884 if (g_strcmp0(a->name, b->name) != 0)
885 {
886 PWARN("Names differ: %s vs %s", a->name, b->name);
887 return FALSE;
888 }
889
890 if (a->invisible != b->invisible)
891 {
892 PWARN("invisible flags differ");
893 return FALSE;
894 }
895
896 if ((a->entries != NULL) != (b->entries != NULL))
897 {
898 PWARN("only one has entries");
899 return FALSE;
900 }
901
902 if (a->entries != NULL && b->entries != NULL)
903 {
904 GncTaxTableEntryList* a_node;
905 GncTaxTableEntryList* b_node;
906
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)
910 {
911 if (!gncTaxTableEntryEqual((GncTaxTableEntry*)a_node->data,
912 (GncTaxTableEntry*)b_node->data))
913 {
914 PWARN("entries differ");
915 return FALSE;
916 }
917 }
918
919 if (a_node != NULL || b_node != NULL)
920 {
921 PWARN("Unequal number of entries");
922 return FALSE;
923 }
924 }
925
926#if 0
927 /* See libgnucash/engine/TaxTableBillTermImmutability.txt for an explanation of the following */
928 /* Code that handles this is *identical* to that in gncBillTerm */
929 gint64 refcount;
930 GncTaxTable * parent; /* if non-null, we are an immutable child */
931 GncTaxTable * child; /* if non-null, we have not changed */
932 GList * children; /* list of children for disconnection */
933#endif
934
935 return TRUE;
936}

◆ gncTaxTableGetDefault()

GncTaxTable * gncTaxTableGetDefault ( QofBook book,
GncOwnerType  type 
)

Definition at line 681 of file gncTaxTable.c.

682{
683 GSList *path = NULL;
684 const GncGUID *guid = NULL;
685 const char *vendor = "Default Vendor TaxTable";
686 const char *customer = "Default Customer TaxTable";
687 const char *section = "Business";
688
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);
694
695 guid = qof_book_get_guid_option (book, path);
696 g_slist_free (path);
697
698 return gncTaxTableLookup (book, guid);
699}
The type used to store guids in C.
Definition guid.h:75

◆ gncTaxTableGetEntries()

GncTaxTableEntryList * gncTaxTableGetEntries ( const GncTaxTable table)

Definition at line 771 of file gncTaxTable.c.

772{
773 if (!table) return NULL;
774 return table->entries;
775}

◆ gncTaxTableGetName()

const char * gncTaxTableGetName ( const GncTaxTable table)

Definition at line 710 of file gncTaxTable.c.

711{
712 if (!table) return NULL;
713 return table->name;
714}

◆ gncTaxTableGetParent()

GncTaxTable * gncTaxTableGetParent ( const GncTaxTable table)

Definition at line 765 of file gncTaxTable.c.

766{
767 if (!table) return NULL;
768 return table->parent;
769}

◆ gncTaxTableGetRefcount()

gint64 gncTaxTableGetRefcount ( const GncTaxTable table)

Definition at line 777 of file gncTaxTable.c.

778{
779 if (!table) return 0;
780 return table->refcount;
781}

◆ gncTaxTableGetTables()

GncTaxTableList * gncTaxTableGetTables ( QofBook book)

Definition at line 701 of file gncTaxTable.c.

702{
703 struct _book_info *bi;
704 if (!book) return NULL;
705
706 bi = qof_book_get_data (book, _GNC_MOD_NAME);
707 return bi ? bi->tables : NULL;
708}

◆ gncTaxTableIncRef()

void gncTaxTableIncRef ( GncTaxTable table)

Definition at line 516 of file gncTaxTable.c.

517{
518 if (!table) return;
519 if (table->parent || table->invisible) return; /* children dont need refcounts */
520 gncTaxTableBeginEdit (table);
521 table->refcount++;
522 mark_table (table);
523 gncTaxTableCommitEdit (table);
524}

◆ gncTaxTableLastModifiedSecs()

time64 gncTaxTableLastModifiedSecs ( const GncTaxTable table)

Definition at line 783 of file gncTaxTable.c.

784{
785 if (!table) return 0;
786 return table->modtime;
787}

◆ gncTaxTableLookupByName()

GncTaxTable * gncTaxTableLookupByName ( QofBook book,
const char *  name 
)

Definition at line 667 of file gncTaxTable.c.

668{
669 GList *list = gncTaxTableGetTables (book);
670
671 for ( ; list; list = list->next)
672 {
673 GncTaxTable *table = list->data;
674 if (!g_strcmp0 (table->name, name))
675 return list->data;
676 }
677 return NULL;
678}

◆ gncTaxTableRemoveEntry()

void gncTaxTableRemoveEntry ( GncTaxTable table,
GncTaxTableEntry entry 
)

Definition at line 611 of file gncTaxTable.c.

612{
613 if (!table || !entry) return;
614 gncTaxTableBeginEdit (table);
615 entry->table = NULL;
616 table->entries = g_list_remove (table->entries, entry);
617 mark_table (table);
618 mod_table (table);
619 gncTaxTableCommitEdit (table);
620}

◆ gncTaxTableReturnChild()

GncTaxTable * gncTaxTableReturnChild ( GncTaxTable table,
gboolean  make_new 
)

Definition at line 749 of file gncTaxTable.c.

750{
751 GncTaxTable *child = NULL;
752
753 if (!table) return NULL;
754 if (table->child) return table->child;
755 if (table->parent || table->invisible) return table;
756 if (make_new)
757 {
758 child = gncTaxTableCopy (table);
759 gncTaxTableSetChild (table, child);
760 gncTaxTableSetParent (child, table);
761 }
762 return child;
763}

◆ gncTaxTableSetName()

void gncTaxTableSetName ( GncTaxTable table,
const char *  name 
)

Definition at line 483 of file gncTaxTable.c.

484{
485 if (!table || !name) return;
486 SET_STR (table, table->name, name);
487 mark_table (table);
488 maybe_resort_list (table);
489 gncTaxTableCommitEdit (table);
490}