1 /********************************************************************\
2  * gncCustomer.h -- the Core Customer 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 Customer
25     @{ */
26 /** @file gncCustomer.h
27     @brief Core Customer Interface
28     @author Copyright (C) 2001,2002 Derek Atkins <warlord@MIT.EDU>
29 */
30 
31 #ifndef GNC_CUSTOMER_H_
32 #define GNC_CUSTOMER_H_
33 
34 /** @struct GncCustomer
35 
36 credit, discount and shipaddr are unique to GncCustomer\n
37 id, name, notes, terms, addr, currency, taxtable, taxtable_override
38 taxincluded, active and jobs are identical to ::GncVendor.
39 
40 @param	QofInstance     inst;
41 @param	char *          id;
42 @param	char *          name;
43 @param	char *          notes;
44 @param	GncBillTerm *   terms;
45 @param	GncAddress *    addr;
46 @param	gnc_commodity * currency;
47 @param	GncTaxTable*    taxtable;
48 @param	gboolean        taxtable_override;
49 @param	GncTaxIncluded  taxincluded;
50 @param	gboolean        active;
51 @param	GList *         jobs;
52 @param	gnc_numeric     credit;
53 @param	gnc_numeric     discount;
54 @param	GncAddress *    shipaddr;
55 
56 */
57 typedef struct _gncCustomer GncCustomer;
58 typedef struct _gncCustomerClass GncCustomerClass;
59 
60 #include "gncAddress.h"
61 #include "gncBillTerm.h"
62 #include "gncTaxTable.h"
63 #include "gncJob.h"
64 
65 #define GNC_ID_CUSTOMER       "gncCustomer"
66 
67 /* --- type macros --- */
68 #define GNC_TYPE_CUSTOMER            (gnc_customer_get_type ())
69 #define GNC_CUSTOMER(o)              \
70      (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_CUSTOMER, GncCustomer))
71 #define GNC_CUSTOMER_CLASS(k)        \
72      (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_CUSTOMER, GncCustomerClass))
73 #define GNC_IS_CUSTOMER(o)           \
74      (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_CUSTOMER))
75 #define GNC_IS_CUSTOMER_CLASS(k)     \
76      (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_CUSTOMER))
77 #define GNC_CUSTOMER_GET_CLASS(o)    \
78      (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_CUSTOMER, GncCustomerClass))
79 GType gnc_customer_get_type(void);
80 
81 /** @name Create/Destroy Functions
82  @{ */
83 GncCustomer *gncCustomerCreate (QofBook *book);
84 void gncCustomerDestroy (GncCustomer *customer);
85 void gncCustomerBeginEdit (GncCustomer *customer);
86 void gncCustomerCommitEdit (GncCustomer *customer);
87 /** @} */
88 
89 /** @name Set Functions
90  @{ */
91 
92 void gncCustomerSetID (GncCustomer *customer, const char *id);
93 void gncCustomerSetName (GncCustomer *customer, const char *name);
94 void gncCustomerSetNotes (GncCustomer *customer, const char *notes);
95 void gncCustomerSetTerms (GncCustomer *customer, GncBillTerm *term);
96 void gncCustomerSetTaxIncluded (GncCustomer *customer, GncTaxIncluded taxincl);
97 void gncCustomerSetActive (GncCustomer *customer, gboolean active);
98 void gncCustomerSetDiscount (GncCustomer *customer, gnc_numeric discount);
99 void gncCustomerSetCredit (GncCustomer *customer, gnc_numeric credit);
100 void gncCustomerSetCurrency (GncCustomer *customer, gnc_commodity *currency);
101 
102 void gncCustomerSetTaxTableOverride (GncCustomer *customer, gboolean override);
103 void gncCustomerSetTaxTable (GncCustomer *customer, GncTaxTable *table);
104 
105 void gncCustomerAddJob (GncCustomer *customer, GncJob *job);
106 void gncCustomerRemoveJob (GncCustomer *customer, GncJob *job);
107 
108 /** @} */
109 
110 /** @name Get Functions
111  @{ */
112 /** Return a pointer to the instance gncCustomer that is identified
113  *  by the guid, and is residing in the book. Returns NULL if the
114  *  instance can't be found.
115  *  Equivalent function prototype is
116  *  GncCustomer * gncCustomerLookup (QofBook *book, const GncGUID *guid);
117  */
gncCustomerLookup(const QofBook * book,const GncGUID * guid)118 static inline GncCustomer * gncCustomerLookup (const QofBook *book, const GncGUID *guid)
119 {
120     QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_CUSTOMER, GncCustomer);
121 }
122 
123 const char * gncCustomerGetID (const GncCustomer *customer);
124 const char * gncCustomerGetName (const GncCustomer *customer);
125 GncAddress * gncCustomerGetAddr (const GncCustomer *customer);
126 GncAddress * gncCustomerGetShipAddr (const GncCustomer *customer);
127 const char * gncCustomerGetNotes (const GncCustomer *customer);
128 GncBillTerm * gncCustomerGetTerms (const GncCustomer *customer);
129 GncTaxIncluded gncCustomerGetTaxIncluded (const GncCustomer *customer);
130 gboolean gncCustomerGetActive (const GncCustomer *customer);
131 gnc_numeric gncCustomerGetDiscount (const GncCustomer *customer);
132 gnc_numeric gncCustomerGetCredit (const GncCustomer *customer);
133 gnc_commodity * gncCustomerGetCurrency (const GncCustomer *customer);
134 
135 gboolean gncCustomerGetTaxTableOverride (const GncCustomer *customer);
136 GncTaxTable* gncCustomerGetTaxTable (const GncCustomer *customer);
137 
138 /** @} */
139 
140 int gncCustomerCompare (const GncCustomer *a, const GncCustomer *b);
141 
142 #define CUSTOMER_ID         "id"
143 #define CUSTOMER_NAME       "name"
144 #define CUSTOMER_ADDR       "addr"
145 #define CUSTOMER_SHIPADDR   "shipaddr"
146 #define CUSTOMER_NOTES      "notes"
147 #define CUSTOMER_DISCOUNT   "amount of discount"
148 #define CUSTOMER_CREDIT     "amount of credit"
149 #define CUSTOMER_TT_OVER    "tax table override"
150 #define CUSTOMER_TAX_INC    "customer_tax_included"
151 #define CUSTOMER_TERMS      "customer_terms"
152 #define CUSTOMER_ACTIVE     "customer_is_active"
153 #define CUSTOMER_SLOTS      "customer_values"
154 
155 /** @deprecated functions, should be removed */
156 #define gncCustomerGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
157 #define gncCustomerRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
158 #define gncCustomerGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
159 #define gncCustomerLookupDirect(g,b) gncCustomerLookup((b), &(g))
160 
161 /** Test support function, used in gets-dbi-business-stuff.c */
162 gboolean gncCustomerEqual(const GncCustomer *a, const GncCustomer *b);
163 
164 GList * gncCustomerGetJoblist (const GncCustomer *customer, gboolean show_all);
165 gboolean gncCustomerIsDirty (GncCustomer *customer);
166 
167 #endif /* GNC_CUSTOMER_H_ */
168 /** @} */
169 /** @} */
170