GnuCash  4.8a-80-g9825132ea+
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 typedef struct _gncOwner GncOwner;
37 
38 #define GNC_ID_OWNER "gncOwner"
39 
40 typedef enum
41 {
42  GNC_OWNER_NONE ,
43  GNC_OWNER_UNDEFINED ,
44  GNC_OWNER_CUSTOMER ,
45  GNC_OWNER_JOB ,
46  GNC_OWNER_VENDOR ,
47  GNC_OWNER_EMPLOYEE ,
48 } GncOwnerType;
49 
50 #include "qof.h"
51 #include "gncCustomer.h"
52 #include "gncJob.h"
53 #include "gncVendor.h"
54 #include "gncEmployee.h"
55 #include "gncInvoice.h"
56 #include "Account.h"
57 #include "gnc-lot.h"
58 
69 const char * gncOwnerGetTypeString (const GncOwner *owner);
71 QofInstance* qofOwnerGetOwner (const GncOwner *owner);
73 void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent);
77 gboolean GNC_IS_OWNER (QofInstance *ent);
78 
82 
83 gboolean
84 gncOwnerRegister(void);
85 
88 #ifndef SWIG
89 
91 struct _gncOwner
92 {
93  GncOwnerType type;
94  union
95  {
96  gpointer undefined;
97  GncCustomer * customer;
98  GncJob * job;
99  GncVendor * vendor;
100  GncEmployee * employee;
101  } owner;
102  gpointer qof_temp;
103 };
104 
105 #endif /* SWIG */
106 
110 void gncOwnerInitUndefined (GncOwner *owner, gpointer obj);
111 void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer);
112 void gncOwnerInitJob (GncOwner *owner, GncJob *job);
113 void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor);
114 void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee);
120 GncOwnerType gncOwnerGetType (const GncOwner *owner);
123 gboolean gncOwnerIsValid (const GncOwner *owner);
124 
127 gpointer gncOwnerGetUndefined (const GncOwner *owner);
130 GncCustomer * gncOwnerGetCustomer (const GncOwner *owner);
133 GncJob * gncOwnerGetJob (const GncOwner *owner);
136 GncVendor * gncOwnerGetVendor (const GncOwner *owner);
139 GncEmployee * gncOwnerGetEmployee (const GncOwner *owner);
140 
141 const char * gncOwnerGetID (const GncOwner *owner);
142 const char * gncOwnerGetName (const GncOwner *owner);
143 GncAddress * gncOwnerGetAddr (const GncOwner *owner);
144 gboolean gncOwnerGetActive (const GncOwner *owner);
145 gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner);
151 void gncOwnerSetActive (const GncOwner *owner, gboolean active);
154 void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
155 
163 gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
166 int gncOwnerGCompareFunc (const GncOwner *a, const GncOwner *b);
168 int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
172 const GncGUID * gncOwnerGetGUID (const GncOwner *owner);
173 GncGUID gncOwnerRetGUID (GncOwner *owner);
174 
179 const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner);
180 const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner);
181 
183 void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);
184 
187 gboolean gncOwnerLotMatchOwnerFunc (GNCLot *lot, gpointer user_data);
188 
193 gint gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB);
194 
198 gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
199 
207 gboolean gncOwnerGetOwnerFromTxn (Transaction *txn, GncOwner *owner);
208 
209 gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid);
210 
218 GNCLot *
219 gncOwnerCreatePaymentLotSecs (const GncOwner *owner, Transaction **preset_txn,
220  Account *posted_acc, Account *xfer_acc,
221  gnc_numeric amount, gnc_numeric exch, time64 date,
222  const char *memo, const char *num);
223 
258 void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots);
259 
271 void
272 gncOwnerApplyPaymentSecs (const GncOwner *owner, Transaction **preset_txn,
273  GList *lots, Account *posted_acc, Account *xfer_acc,
274  gnc_numeric amount, gnc_numeric exch, time64 date,
275  const char *memo, const char *num, gboolean auto_pay);
276 
288 Split *gncOwnerFindOffsettingSplit (GNCLot *pay_lot, gnc_numeric target_value);
289 
296 gboolean gncOwnerReduceSplitTo (Split *split, gnc_numeric target_value);
297 
303 void gncOwnerSetLotLinkMemo (Transaction *ll_txn);
304 
306 GList * gncOwnerGetAccountTypesList (const GncOwner *owner);
307 
309 GList * gncOwnerGetCommoditiesList (const GncOwner *owner);
310 
311 
315 gnc_numeric
317  const gnc_commodity *report_currency);
318 
319 #define OWNER_TYPE "type"
320 #define OWNER_TYPE_STRING "type-string"
321 #define OWNER_CUSTOMER "customer"
322 #define OWNER_JOB "job"
323 #define OWNER_VENDOR "vendor"
324 #define OWNER_EMPLOYEE "employee"
325 #define OWNER_PARENT "parent"
326 #define OWNER_PARENTG "parent-guid"
327 #define OWNER_NAME "name"
328 
329 #define OWNER_FROM_LOT "owner-from-lot"
330 
336 GncOwner * gncOwnerNew (void);
337 void gncOwnerFree (GncOwner *owner);
338 
339 
345 void gncOwnerBeginEdit (GncOwner *owner);
346 void gncOwnerCommitEdit (GncOwner *owner);
347 void gncOwnerDestroy (GncOwner *owner);
348 
349 #endif /* GNC_OWNER_H_ */
350 
Core Customer Interface.
GList * gncOwnerGetCommoditiesList(const GncOwner *owner)
Returns a GList of currencies associated with the owner.
Definition: gncOwner.c:1463
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:1445
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
Definition: qofid.h:87
GncOwnerType type
Customer, Job, Vendor, Employee or Undefined.
Definition: gncOwner.h:93
gpointer qof_temp
Set type independently of the owner.
Definition: gncOwner.h:102
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:1259
const gchar * QofIdType
QofIdType declaration.
Definition: qofid.h:85
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:1408
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:979
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:1479
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:913
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:1013
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93
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