GnuCash  4.904-1-g0110442c28
gncOwner.h
Go to the documentation of this file.
1 /********************************************************************\
2  * gncOwner.h -- Business Interface: Object OWNERs *
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 \********************************************************************/
33 #ifndef GNC_OWNER_H_
34 #define GNC_OWNER_H_
35 
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 typedef struct _gncOwner GncOwner;
42 
43 #define GNC_ID_OWNER "gncOwner"
44 
45 typedef enum
46 {
47  GNC_OWNER_NONE ,
48  GNC_OWNER_UNDEFINED ,
49  GNC_OWNER_CUSTOMER ,
50  GNC_OWNER_JOB ,
51  GNC_OWNER_VENDOR ,
52  GNC_OWNER_EMPLOYEE ,
53 } GncOwnerType;
54 
55 #include "qof.h"
56 #include "gncCustomer.h"
57 #include "gncJob.h"
58 #include "gncVendor.h"
59 #include "gncEmployee.h"
60 #include "gncInvoice.h"
61 #include "Account.h"
62 #include "gnc-lot.h"
63 
74 const char * gncOwnerGetTypeString (const GncOwner *owner);
82 gboolean GNC_IS_OWNER (QofInstance *ent);
83 
87 
88 gboolean
89 gncOwnerRegister(void);
90 
93 #ifndef SWIG
94 
96 struct _gncOwner
97 {
98  GncOwnerType type;
99  union
100  {
101  gpointer undefined;
102  GncCustomer * customer;
103  GncJob * job;
104  GncVendor * vendor;
105  GncEmployee * employee;
106  } owner;
107  gpointer qof_temp;
108 };
109 
110 #endif /* SWIG */
111 
115 void gncOwnerInitUndefined (GncOwner *owner, gpointer obj);
116 void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer);
117 void gncOwnerInitJob (GncOwner *owner, GncJob *job);
118 void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor);
119 void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee);
125 GncOwnerType gncOwnerGetType (const GncOwner *owner);
128 gboolean gncOwnerIsValid (const GncOwner *owner);
129 
132 gpointer gncOwnerGetUndefined (const GncOwner *owner);
135 GncCustomer * gncOwnerGetCustomer (const GncOwner *owner);
138 GncJob * gncOwnerGetJob (const GncOwner *owner);
141 GncVendor * gncOwnerGetVendor (const GncOwner *owner);
144 GncEmployee * gncOwnerGetEmployee (const GncOwner *owner);
145 
146 const char * gncOwnerGetID (const GncOwner *owner);
147 const char * gncOwnerGetName (const GncOwner *owner);
148 GncAddress * gncOwnerGetAddr (const GncOwner *owner);
149 gboolean gncOwnerGetActive (const GncOwner *owner);
150 gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner);
156 void gncOwnerSetActive (const GncOwner *owner, gboolean active);
159 void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
160 
168 gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
171 int gncOwnerGCompareFunc (const GncOwner *a, const GncOwner *b);
173 int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
177 const GncGUID * gncOwnerGetGUID (const GncOwner *owner);
178 GncGUID gncOwnerRetGUID (GncOwner *owner);
179 
184 const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner);
185 const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner);
186 
188 void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);
189 
192 gboolean gncOwnerLotMatchOwnerFunc (GNCLot *lot, gpointer user_data);
193 
198 gint gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB);
199 
203 gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
204 
212 gboolean gncOwnerGetOwnerFromTxn (Transaction *txn, GncOwner *owner);
213 
214 gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid);
215 
223 GNCLot *
224 gncOwnerCreatePaymentLotSecs (const GncOwner *owner, Transaction **preset_txn,
225  Account *posted_acc, Account *xfer_acc,
226  gnc_numeric amount, gnc_numeric exch, time64 date,
227  const char *memo, const char *num);
228 
263 void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots);
264 
276 void
277 gncOwnerApplyPaymentSecs (const GncOwner *owner, Transaction **preset_txn,
278  GList *lots, Account *posted_acc, Account *xfer_acc,
279  gnc_numeric amount, gnc_numeric exch, time64 date,
280  const char *memo, const char *num, gboolean auto_pay);
281 
293 Split *gncOwnerFindOffsettingSplit (GNCLot *pay_lot, gnc_numeric target_value);
294 
301 gboolean gncOwnerReduceSplitTo (Split *split, gnc_numeric target_value);
302 
308 void gncOwnerSetLotLinkMemo (Transaction *ll_txn);
309 
311 GList * gncOwnerGetAccountTypesList (const GncOwner *owner);
312 
314 GList * gncOwnerGetCommoditiesList (const GncOwner *owner);
315 
316 
320 gnc_numeric
322  const gnc_commodity *report_currency);
323 
324 #define OWNER_TYPE "type"
325 #define OWNER_TYPE_STRING "type-string"
326 #define OWNER_CUSTOMER "customer"
327 #define OWNER_JOB "job"
328 #define OWNER_VENDOR "vendor"
329 #define OWNER_EMPLOYEE "employee"
330 #define OWNER_PARENT "parent"
331 #define OWNER_PARENTG "parent-guid"
332 #define OWNER_NAME "name"
333 
334 #define OWNER_FROM_LOT "owner-from-lot"
335 
341 GncOwner * gncOwnerNew (void);
342 void gncOwnerFree (GncOwner *owner);
343 
344 
350 void gncOwnerBeginEdit (GncOwner *owner);
351 void gncOwnerCommitEdit (GncOwner *owner);
352 void gncOwnerDestroy (GncOwner *owner);
353 
354 #ifdef __cplusplus
355 }
356 #endif
357 
358 #endif /* GNC_OWNER_H_ */
359 
Core Customer Interface.
GList * gncOwnerGetCommoditiesList(const GncOwner *owner)
Returns a GList of currencies associated with the owner.
Definition: gncOwner.c:1447
const GncGUID * gncOwnerGetGUID(const GncOwner *owner)
Get the GncGUID of the immediate owner.
Definition: gncOwner.c:519
union _gncOwner::@20 owner
holds the pointer to the owner object.
gboolean gncOwnerGetOwnerFromTxn(Transaction *txn, GncOwner *owner)
Convenience function to get the owner from a transaction.
Definition: gncOwner.c:675
GList * gncOwnerGetAccountTypesList(const GncOwner *owner)
Returns a GList of account-types based on the owner type.
Definition: gncOwner.c:1429
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
Definition: qofid.h:82
GncOwnerType type
Customer, Job, Vendor, Employee or Undefined.
Definition: gncOwner.h:98
gpointer qof_temp
Set type independently of the owner.
Definition: gncOwner.h:107
gboolean gncOwnerEqual(const GncOwner *a, const GncOwner *b)
Assess equality by checking.
Definition: gncOwner.c:405
const char * gncOwnerGetTypeString(const GncOwner *owner)
return the type for the owner as an untranslated string.
Definition: gncOwner.c:207
void gncOwnerBeginEdit(GncOwner *owner)
These are convenience wrappers around gnc{Vendor,Customer,Job,Employee}* functions.
Definition: gncOwner.c:73
gboolean gncOwnerIsValid(const GncOwner *owner)
Returns TRUE if the given owner is one of the valid objects.
Definition: gncOwner.c:700
QofInstance * qofOwnerGetOwner(const GncOwner *owner)
return the owner itself as an entity.
Definition: gncOwner.c:276
void gncOwnerAutoApplyPaymentsWithLots(const GncOwner *owner, GList *lots)
Given a list of lots, try to balance as many of them as possible by creating balancing transactions b...
Definition: gncOwner.c:1243
const gchar * QofIdType
QofIdType declaration.
Definition: qofid.h:80
int gncOwnerGCompareFunc(const GncOwner *a, const GncOwner *b)
Same as gncOwnerEqual, but returns 0 if equal to be used as a GList custom compare function...
Definition: gncOwner.c:412
void gncOwnerApplyPaymentSecs(const GncOwner *owner, Transaction **preset_txn, GList *lots, Account *posted_acc, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, time64 date, const char *memo, const char *num, gboolean auto_pay)
A convenience function to apply a payment to the owner.
Definition: gncOwner.c:1392
Account handling public routines.
gint gncOwnerLotsSortFunc(GNCLot *lotA, GNCLot *lotB)
Helper function used to sort lots by date.
Definition: gncOwner.c:729
gboolean gncOwnerReduceSplitTo(Split *split, gnc_numeric target_value)
Helper function to reduce the value of a split to target_value.
Definition: gncOwner.c:963
gnc_numeric gncOwnerGetBalanceInCurrency(const GncOwner *owner, const gnc_commodity *report_currency)
Given an owner, extract the open balance from the owner and then convert it to the desired currency...
Definition: gncOwner.c:1463
QofIdTypeConst qofOwnerGetType(const GncOwner *owner)
return the type for the collection.
Definition: gncOwner.c:231
int gncOwnerCompare(const GncOwner *a, const GncOwner *b)
Sort on name.
Definition: gncOwner.c:591
void qofOwnerSetEntity(GncOwner *owner, QofInstance *ent)
set the owner from the entity.
Definition: gncOwner.c:320
void gncOwnerAttachToLot(const GncOwner *owner, GNCLot *lot)
Attach an owner to a lot.
Definition: gncOwner.c:623
QofIdTypeConst gncOwnerTypeToQofIdType(GncOwnerType t)
Returns the QofIdType of the given GncOwnerType, or NULL if no suitable one exists.
Definition: gncOwner.c:236
gpointer gncOwnerGetUndefined(const GncOwner *owner)
If the given owner is of type GNC_OWNER_UNDEFINED, returns the undefined pointer, which is usually NU...
Definition: gncOwner.c:363
gboolean gncOwnerGetOwnerFromLot(GNCLot *lot, GncOwner *owner)
Get the owner from the lot.
Definition: gncOwner.c:637
GNCLot * gncOwnerCreatePaymentLotSecs(const GncOwner *owner, Transaction **preset_txn, Account *posted_acc, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, time64 date, const char *memo, const char *num)
Create a lot for a payment to the owner using the other parameters passed in.
Definition: gncOwner.c:751
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr, currency, taxtable, taxtable_override taxincluded, active and jobs are identical to ::GncVendor.
gboolean GNC_IS_OWNER(QofInstance *ent)
Check if entity is an owner kind.
Definition: gncOwner.c:353
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
Definition: gncOwner.c:201
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
Definition: gncOwner.c:573
Business Invoice Interface.
GncJob * gncOwnerGetJob(const GncOwner *owner)
If the given owner is of type GNC_OWNER_JOB, returns the pointer to the job object.
Definition: gncOwner.c:377
Job Interface.
gboolean gncOwnerLotMatchOwnerFunc(GNCLot *lot, gpointer user_data)
Helper function used to filter a list of lots by owner.
Definition: gncOwner.c:707
Employee Interface.
Split * gncOwnerFindOffsettingSplit(GNCLot *pay_lot, gnc_numeric target_value)
Helper function to find a split in lot that best offsets target_value Obviously it should be of oppos...
Definition: gncOwner.c:897
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object...
Definition: gncOwner.c:384
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object...
Definition: gncOwner.c:370
Vendor Interface.
void gncOwnerSetLotLinkMemo(Transaction *ll_txn)
To help a user understand what a lot link transaction does, we set the memo to name all documents inv...
Definition: gncOwner.c:997
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:87
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object...
Definition: gncOwner.c:391
The type used to store guids in C.
Definition: guid.h:75
GncOwner * gncOwnerNew(void)
These two functions are mainly for the convenience of scheme code.
Definition: gncOwner.c:58