Line data Source code
1 : /********************************************************************\
2 : * gncTaxTable.h -- the Gnucash Tax Table interface *
3 : * *
4 : * This program is free software; you can redistribute it and/or *
5 : * modify it under the terms of the GNU General Public License as *
6 : * published by the Free Software Foundation; either version 2 of *
7 : * the License, or (at your option) any later version. *
8 : * *
9 : * This program is distributed in the hope that it will be useful, *
10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 : * GNU General Public License for more details. *
13 : * *
14 : * You should have received a copy of the GNU General Public License*
15 : * along with this program; if not, contact: *
16 : * *
17 : * Free Software Foundation Voice: +1-617-542-5942 *
18 : * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19 : * Boston, MA 02110-1301, USA gnu@gnu.org *
20 : * *
21 : \********************************************************************/
22 : /** @addtogroup Business
23 : @{ */
24 : /** @addtogroup TaxTable
25 : Define an object to track tax properties for invoices.
26 :
27 : @note A tax table added to an invoice is immutable, that is it
28 : can't change any more. To achieve that a tax table is copied when
29 : added to an invoice. This uses some internal fields to track this which
30 : are explained in @ref ImmutableTaxTableBillTerm.
31 :
32 : @{ */
33 : /** @file gncTaxTable.h
34 : @brief Tax Table programming interface
35 : @author Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU>
36 : */
37 :
38 : #ifndef GNC_TAXTABLE_H_
39 : #define GNC_TAXTABLE_H_
40 :
41 : #ifdef __cplusplus
42 : extern "C" {
43 : #endif
44 :
45 : /** @struct GncTaxTable
46 :
47 : modtime is the internal date of the last modtime\n
48 : See libgnucash/engine/TaxTableBillTermImmutability.txt for an explanation of the following\n
49 : Code that handles refcount, parent, child, invisible and children
50 : is *identical* to that in ::GncBillTerm
51 :
52 : @param QofInstance inst;
53 : @param char * name;
54 : @param GncTaxTableEntryList* entries;
55 : @param time64 modtime;
56 : @param gint64 refcount;
57 : @param GncTaxTable * parent; if non-null, we are an immutable child
58 : @param GncTaxTable * child; if non-null, we have not changed
59 : @param gboolean invisible;
60 : @param GList * children; list of children for disconnection
61 : */
62 : typedef struct _gncTaxTable GncTaxTable;
63 : typedef struct _gncTaxTableClass GncTaxTableClass;
64 :
65 : /** @struct GncTaxTableEntry
66 :
67 : @param GncTaxTable * table;
68 : @param Account * account;
69 : @param GncAmountType type;
70 : @param gnc_numeric amount;
71 : };
72 :
73 : */
74 : /**
75 : * How to interpret the amount.
76 : * You can interpret it as a VALUE or a PERCENT.
77 : */
78 : typedef enum
79 : {
80 : GNC_AMT_TYPE_VALUE = 1, /**< tax is a number */
81 : GNC_AMT_TYPE_PERCENT /**< tax is a percentage */
82 : } GncAmountType;
83 :
84 : /** How to interpret the TaxIncluded */
85 : typedef enum
86 : {
87 : GNC_TAXINCLUDED_YES = 1, /**< tax is included */
88 : GNC_TAXINCLUDED_NO, /**< tax is not included */
89 : GNC_TAXINCLUDED_USEGLOBAL, /**< use the global setting */
90 : } GncTaxIncluded;
91 :
92 : typedef struct _gncTaxTableEntry GncTaxTableEntry;
93 :
94 : typedef struct _gncAccountValue GncAccountValue;
95 :
96 : #include "Account.h"
97 : #include "qof.h"
98 : #include "gncBusiness.h"
99 : #include "gncOwner.h"
100 :
101 : #define GNC_ID_TAXTABLE "gncTaxTable"
102 :
103 : /* --- type macros --- */
104 : #define GNC_TYPE_TAXTABLE (gnc_taxtable_get_type ())
105 : #define GNC_TAXTABLE(o) \
106 : (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TAXTABLE, GncTaxTable))
107 : #define GNC_TAXTABLE_CLASS(k) \
108 : (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TAXTABLE, GncTaxTableClass))
109 : #define GNC_IS_TAXTABLE(o) \
110 : (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TAXTABLE))
111 : #define GNC_IS_TAXTABLE_CLASS(k) \
112 : (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TAXTABLE))
113 : #define GNC_TAXTABLE_GET_CLASS(o) \
114 : (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TAXTABLE, GncTaxTableClass))
115 : GType gnc_taxtable_get_type(void);
116 :
117 :
118 : const char * gncAmountTypeToString (GncAmountType type);
119 : gboolean gncAmountStringToType (const char *str, GncAmountType *type);
120 :
121 : const char * gncTaxIncludedTypeToString (GncTaxIncluded type);
122 : gboolean gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type);
123 :
124 : /** @name Create/Destroy Functions
125 : @{ */
126 : GncTaxTable * gncTaxTableCreate (QofBook *book);
127 : void gncTaxTableDestroy (GncTaxTable *table);
128 : GncTaxTableEntry * gncTaxTableEntryCreate (void);
129 : void gncTaxTableEntryDestroy (GncTaxTableEntry *entry);
130 : /** @} */
131 : /** \name Set Functions
132 : @{
133 : */
134 : void gncTaxTableSetName (GncTaxTable *table, const char *name);
135 : void gncTaxTableIncRef (GncTaxTable *table);
136 : void gncTaxTableDecRef (GncTaxTable *table);
137 :
138 : void gncTaxTableEntrySetAccount (GncTaxTableEntry *entry, Account *account);
139 : void gncTaxTableEntrySetType (GncTaxTableEntry *entry, GncAmountType type);
140 : void gncTaxTableEntrySetAmount (GncTaxTableEntry *entry, gnc_numeric amount);
141 : /** @} */
142 : void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry);
143 : void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry);
144 :
145 : void gncTaxTableChanged (GncTaxTable *table);
146 : void gncTaxTableBeginEdit (GncTaxTable *table);
147 : void gncTaxTableCommitEdit (GncTaxTable *table);
148 : gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b);
149 :
150 : /** @name Get Functions
151 : @{ */
152 :
153 : /** Return a pointer to the instance gncTaxTable that is identified
154 : * by the guid, and is residing in the book. Returns NULL if the
155 : * instance can't be found.
156 : */
157 6 : static inline GncTaxTable *gncTaxTableLookup (const QofBook* book, const GncGUID *guid)
158 : {
159 6 : QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_TAXTABLE, GncTaxTable);
160 : }
161 :
162 : GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
163 : GncTaxTable *gncTaxTableGetDefault (QofBook *book, GncOwnerType type);
164 :
165 : typedef GList GncTaxTableList;
166 : GncTaxTableList * gncTaxTableGetTables (QofBook *book);
167 :
168 : const char *gncTaxTableGetName (const GncTaxTable *table);
169 : GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table);
170 : GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
171 : #define gncTaxTableGetChild(t) gncTaxTableReturnChild((t),FALSE)
172 : typedef GList GncTaxTableEntryList;
173 : GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table);
174 : gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
175 : time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table);
176 :
177 : Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
178 : GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);
179 : gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry);
180 : /** @} */
181 :
182 : int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b);
183 : int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b);
184 : gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b);
185 :
186 : /************************************************/
187 :
188 : struct _gncAccountValue
189 : {
190 : Account * account;
191 : gnc_numeric value;
192 : };
193 :
194 : /**
195 : * This will add value to the account-value for acc, creating a new
196 : * list object if necessary
197 : */
198 : GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value);
199 :
200 : /** Merge l2 into l1. l2 is not touched. */
201 : GList *gncAccountValueAddList (GList *l1, GList *l2);
202 :
203 : /** return the total for this list */
204 : gnc_numeric gncAccountValueTotal (GList *list);
205 :
206 : /** Destroy a list of accountvalues */
207 : void gncAccountValueDestroy (GList *list);
208 :
209 : /** QOF parameter definitions */
210 : #define GNC_TT_NAME "tax table name"
211 : #define GNC_TT_REFCOUNT "reference count"
212 :
213 : /** @deprecated routine */
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_ */
223 : /** @} */
224 : /** @} */
|