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     @{ */
26 /** @file gncTaxTable.h
27     @brief Tax Table programming interface
28     @author Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU>
29 */
30 
31 #ifndef GNC_TAXTABLE_H_
32 #define GNC_TAXTABLE_H_
33 
34 /** @struct GncTaxTable
35 
36 modtime is the internal date of the last modtime\n
37 See src/doc/business.txt for an explanation of the following\n
38 Code that handles refcount, parent, child, invisible and children
39 is *identical* to that in ::GncBillTerm
40 
41 @param	QofInstance     inst;
42 @param 	char *          name;
43 @param 	GncTaxTableEntryList*  entries;
44 @param 	time64        modtime;
45 @param 	gint64          refcount;
46 @param 	GncTaxTable *   parent; if non-null, we are an immutable child
47 @param 	GncTaxTable *   child;  if non-null, we have not changed
48 @param 	gboolean        invisible;
49 @param 	GList *         children; list of children for disconnection
50 */
51 typedef struct _gncTaxTable GncTaxTable;
52 typedef struct _gncTaxTableClass GncTaxTableClass;
53 
54 /** @struct GncTaxTableEntry
55 
56 @param	GncTaxTable *   table;
57 @param  Account *       account;
58 @param	GncAmountType   type;
59 @param	gnc_numeric     amount;
60 };
61 
62 */
63 /**
64  * How to interpret the amount.
65  * You can interpret it as a VALUE or a PERCENT.
66  */
67 typedef enum
68 {
69     GNC_AMT_TYPE_VALUE = 1, 	/**< tax is a number */
70     GNC_AMT_TYPE_PERCENT		/**< tax is a percentage */
71 } GncAmountType;
72 
73 /** How to interpret the TaxIncluded */
74 typedef enum
75 {
76     GNC_TAXINCLUDED_YES = 1,  /**< tax is included */
77     GNC_TAXINCLUDED_NO,		/**< tax is not included */
78     GNC_TAXINCLUDED_USEGLOBAL, /**< use the global setting */
79 } GncTaxIncluded;
80 
81 typedef struct _gncTaxTableEntry GncTaxTableEntry;
82 
83 typedef struct _gncAccountValue GncAccountValue;
84 
85 #include "Account.h"
86 #include "qof.h"
87 #include "gncBusiness.h"
88 #include "gncOwner.h"
89 
90 #define GNC_ID_TAXTABLE       "gncTaxTable"
91 
92 /* --- type macros --- */
93 #define GNC_TYPE_TAXTABLE            (gnc_taxtable_get_type ())
94 #define GNC_TAXTABLE(o)              \
95      (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TAXTABLE, GncTaxTable))
96 #define GNC_TAXTABLE_CLASS(k)        \
97      (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_TAXTABLE, GncTaxTableClass))
98 #define GNC_IS_TAXTABLE(o)           \
99      (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TAXTABLE))
100 #define GNC_IS_TAXTABLE_CLASS(k)     \
101      (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TAXTABLE))
102 #define GNC_TAXTABLE_GET_CLASS(o)    \
103      (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TAXTABLE, GncTaxTableClass))
104 GType gnc_taxtable_get_type(void);
105 
106 
107 const char * gncAmountTypeToString (GncAmountType type);
108 gboolean gncAmountStringToType (const char *str, GncAmountType *type);
109 
110 const char * gncTaxIncludedTypeToString (GncTaxIncluded type);
111 gboolean gncTaxIncludedStringToType (const char *str, GncTaxIncluded *type);
112 
113 /** @name Create/Destroy Functions
114  @{ */
115 GncTaxTable * gncTaxTableCreate (QofBook *book);
116 void gncTaxTableDestroy (GncTaxTable *table);
117 GncTaxTableEntry * gncTaxTableEntryCreate (void);
118 void gncTaxTableEntryDestroy (GncTaxTableEntry *entry);
119 /** @} */
120 /** \name Set Functions
121 @{
122 */
123 void gncTaxTableSetName (GncTaxTable *table, const char *name);
124 void gncTaxTableIncRef (GncTaxTable *table);
125 void gncTaxTableDecRef (GncTaxTable *table);
126 
127 void gncTaxTableEntrySetAccount (GncTaxTableEntry *entry, Account *account);
128 void gncTaxTableEntrySetType (GncTaxTableEntry *entry, GncAmountType type);
129 void gncTaxTableEntrySetAmount (GncTaxTableEntry *entry, gnc_numeric amount);
130 /** @} */
131 void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry);
132 void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry);
133 
134 void gncTaxTableChanged (GncTaxTable *table);
135 void gncTaxTableBeginEdit (GncTaxTable *table);
136 void gncTaxTableCommitEdit (GncTaxTable *table);
137 gboolean gncTaxTableEqual(const GncTaxTable *a, const GncTaxTable *b);
138 
139 /** @name Get Functions
140  @{ */
141 
142 /** Return a pointer to the instance gncTaxTable that is identified
143  *  by the guid, and is residing in the book. Returns NULL if the
144  *  instance can't be found.
145  *  Equivalent function prototype is
146  *  GncTaxTable * gncTaxTableLookup (QofBook *book, const GncGUID *guid);
147  */
gncTaxTableLookup(const QofBook * book,const GncGUID * guid)148 static inline GncTaxTable *gncTaxTableLookup (const QofBook* book, const GncGUID *guid)
149 {
150     QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_TAXTABLE, GncTaxTable);
151 }
152 
153 GncTaxTable *gncTaxTableLookupByName (QofBook *book, const char *name);
154 GncTaxTable *gncTaxTableGetDefault (QofBook *book, GncOwnerType type);
155 
156 typedef GList GncTaxTableList;
157 GncTaxTableList  * gncTaxTableGetTables (QofBook *book);
158 
159 const char *gncTaxTableGetName (const GncTaxTable *table);
160 GncTaxTable *gncTaxTableGetParent (const GncTaxTable *table);
161 GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new);
162 #define gncTaxTableGetChild(t) gncTaxTableReturnChild((t),FALSE)
163 typedef GList GncTaxTableEntryList;
164 GncTaxTableEntryList* gncTaxTableGetEntries (const GncTaxTable *table);
165 gint64 gncTaxTableGetRefcount (const GncTaxTable *table);
166 time64 gncTaxTableLastModifiedSecs (const GncTaxTable *table);
167 
168 Account * gncTaxTableEntryGetAccount (const GncTaxTableEntry *entry);
169 GncAmountType gncTaxTableEntryGetType (const GncTaxTableEntry *entry);
170 gnc_numeric gncTaxTableEntryGetAmount (const GncTaxTableEntry *entry);
171 /** @} */
172 
173 int gncTaxTableCompare (const GncTaxTable *a, const GncTaxTable *b);
174 int gncTaxTableEntryCompare (const GncTaxTableEntry *a, const GncTaxTableEntry *b);
175 gboolean gncTaxTableEntryEqual(const GncTaxTableEntry *a, const GncTaxTableEntry *b);
176 
177 /************************************************/
178 
179 struct _gncAccountValue
180 {
181     Account *	account;
182     gnc_numeric	value;
183 };
184 
185 /**
186  * This will add value to the account-value for acc, creating a new
187  * list object if necessary
188  */
189 GList *gncAccountValueAdd (GList *list, Account *acc, gnc_numeric value);
190 
191 /** Merge l2 into l1.  l2 is not touched. */
192 GList *gncAccountValueAddList (GList *l1, GList *l2);
193 
194 /** return the total for this list */
195 gnc_numeric gncAccountValueTotal (GList *list);
196 
197 /** Destroy a list of accountvalues */
198 void gncAccountValueDestroy (GList *list);
199 
200 /** QOF parameter definitions */
201 #define GNC_TT_NAME "tax table name"
202 #define GNC_TT_REFCOUNT "reference count"
203 
204 /** @deprecated routine */
205 #define gncTaxTableGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
206 #define gncTaxTableRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
207 #define gncTaxTableLookupDirect(G,B) gncTaxTableLookup((B), &(G))
208 
209 #endif /* GNC_TAXTABLE_H_ */
210 /** @} */
211 /** @} */
212