2003-10-16 23:32:04 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gncOwner.h -- Business Interface: Object OWNERs *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2003-10-16 23:32:04 -05:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
2004-05-07 00:11:49 -05:00
|
|
|
/** @addtogroup Business
|
|
|
|
@{ */
|
|
|
|
/** @addtogroup Owner
|
|
|
|
@{ */
|
|
|
|
/** @file gncOwner.h
|
|
|
|
@brief Business Interface: Object OWNERs
|
|
|
|
@author Copyright (C) 2001,2002 Derek Atkins <warlord@MIT.EDU>
|
2005-11-01 21:32:36 -06:00
|
|
|
@author Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
2006-01-23 00:38:20 -06:00
|
|
|
@author Copyright (c) 2006 David Hampton <hampton@employees.org>
|
2004-05-07 00:11:49 -05:00
|
|
|
*/
|
2001-12-05 23:46:42 -06:00
|
|
|
|
|
|
|
#ifndef GNC_OWNER_H_
|
|
|
|
#define GNC_OWNER_H_
|
|
|
|
|
2006-10-15 14:02:05 -05:00
|
|
|
typedef struct _gncOwner GncOwner;
|
2002-01-22 09:51:14 -06:00
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
#define GNC_ID_OWNER "gncOwner"
|
2002-02-03 20:53:13 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GNC_OWNER_NONE ,
|
|
|
|
GNC_OWNER_UNDEFINED ,
|
|
|
|
GNC_OWNER_CUSTOMER ,
|
|
|
|
GNC_OWNER_JOB ,
|
|
|
|
GNC_OWNER_VENDOR ,
|
|
|
|
GNC_OWNER_EMPLOYEE ,
|
|
|
|
} GncOwnerType;
|
2005-11-01 21:32:36 -06:00
|
|
|
|
2011-08-13 10:33:27 -05:00
|
|
|
#include "qof.h"
|
|
|
|
#include "gncCustomer.h"
|
|
|
|
#include "gncJob.h"
|
|
|
|
#include "gncVendor.h"
|
|
|
|
#include "gncEmployee.h"
|
|
|
|
#include "gncInvoice.h"
|
|
|
|
#include "Account.h"
|
|
|
|
#include "gnc-lot.h"
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
/** \name QOF handling
|
|
|
|
|
|
|
|
Whilst GncOwner is not a formal QOF object, these functions
|
|
|
|
are still expected to be useful in making GncOwner transparent
|
|
|
|
to QOF as they can be used by objects like GncInvoice.
|
|
|
|
@{
|
|
|
|
*/
|
|
|
|
/** return the type for the collection. */
|
2010-10-02 09:59:33 -05:00
|
|
|
QofIdTypeConst qofOwnerGetType(const GncOwner *owner);
|
2005-11-01 21:32:36 -06:00
|
|
|
/** return the owner itself as an entity. */
|
2008-08-01 11:02:07 -05:00
|
|
|
QofInstance* qofOwnerGetOwner (const GncOwner *owner);
|
2005-11-01 21:32:36 -06:00
|
|
|
/** set the owner from the entity. */
|
2007-04-01 17:18:50 -05:00
|
|
|
void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent);
|
2011-08-17 05:54:27 -05:00
|
|
|
/** Check if entity is an owner kind. This function conveniently
|
|
|
|
* imitates the various GNC_IS_ checks on the other gnucash
|
|
|
|
* objects even though an owner is not really a true object. */
|
|
|
|
gboolean GNC_IS_OWNER (QofInstance *ent);
|
2005-11-01 21:32:36 -06:00
|
|
|
|
2010-10-02 09:59:33 -05:00
|
|
|
/** Returns the QofIdType of the given GncOwnerType, or NULL if no
|
|
|
|
* suitable one exists. */
|
|
|
|
QofIdTypeConst gncOwnerTypeToQofIdType(GncOwnerType t);
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
gboolean
|
|
|
|
gncOwnerRegister(void);
|
2001-12-05 23:46:42 -06:00
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
/** @} */
|
|
|
|
|
2006-10-17 16:46:25 -05:00
|
|
|
#ifndef SWIG
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
/** \struct GncOwner */
|
2010-03-02 15:41:05 -06:00
|
|
|
struct _gncOwner
|
|
|
|
{
|
|
|
|
GncOwnerType type; /**< Customer, Job, Vendor, Employee or Undefined. */
|
|
|
|
union
|
|
|
|
{
|
|
|
|
gpointer undefined;
|
|
|
|
GncCustomer * customer;
|
|
|
|
GncJob * job;
|
|
|
|
GncVendor * vendor;
|
|
|
|
GncEmployee * employee;
|
|
|
|
} owner; /**< holds the pointer to the owner object. */
|
|
|
|
gpointer qof_temp; /**< Set type independently of the owner. */
|
2002-01-22 09:51:14 -06:00
|
|
|
};
|
2001-12-05 23:46:42 -06:00
|
|
|
|
2006-10-17 16:46:25 -05:00
|
|
|
#endif /* SWIG */
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
/** \name Setup routines
|
|
|
|
@{
|
|
|
|
*/
|
2001-12-05 23:46:42 -06:00
|
|
|
void gncOwnerInitUndefined (GncOwner *owner, gpointer obj);
|
|
|
|
void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer);
|
|
|
|
void gncOwnerInitJob (GncOwner *owner, GncJob *job);
|
|
|
|
void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor);
|
2003-03-03 00:47:54 -06:00
|
|
|
void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee);
|
2005-11-01 21:32:36 -06:00
|
|
|
/** @} */
|
|
|
|
/** \name Get routines.
|
|
|
|
@{
|
|
|
|
*/
|
2011-10-08 04:19:54 -05:00
|
|
|
/** Returns the GncOwnerType of this owner. (Not to be confused with qofOwnerGetType().) */
|
2002-01-22 09:51:14 -06:00
|
|
|
GncOwnerType gncOwnerGetType (const GncOwner *owner);
|
2011-10-08 04:19:54 -05:00
|
|
|
/** Returns TRUE if the given owner is one of the valid objects.
|
|
|
|
* Returns FALSE if the owner is (still) undefined, or if it is NULL. */
|
|
|
|
gboolean gncOwnerIsValid (const GncOwner *owner);
|
|
|
|
|
|
|
|
/** If the given owner is of type GNC_OWNER_UNDEFINED, returns the undefined
|
|
|
|
* pointer, which is usually NULL. Otherwise returns NULL. */
|
2002-01-22 09:51:14 -06:00
|
|
|
gpointer gncOwnerGetUndefined (const GncOwner *owner);
|
2011-10-08 04:19:54 -05:00
|
|
|
/** If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer
|
|
|
|
* to the customer object. Otherwise returns NULL. */
|
2002-01-22 09:51:14 -06:00
|
|
|
GncCustomer * gncOwnerGetCustomer (const GncOwner *owner);
|
2011-10-08 04:19:54 -05:00
|
|
|
/** If the given owner is of type GNC_OWNER_JOB, returns the pointer
|
|
|
|
* to the job object. Otherwise returns NULL. */
|
2002-01-22 09:51:14 -06:00
|
|
|
GncJob * gncOwnerGetJob (const GncOwner *owner);
|
2011-10-08 04:19:54 -05:00
|
|
|
/** If the given owner is of type GNC_OWNER_VENDOR, returns the pointer
|
|
|
|
* to the vendor object. Otherwise returns NULL. */
|
2002-01-22 09:51:14 -06:00
|
|
|
GncVendor * gncOwnerGetVendor (const GncOwner *owner);
|
2011-10-08 04:19:54 -05:00
|
|
|
/** If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer
|
|
|
|
* to the employee object. Otherwise returns NULL. */
|
2003-03-03 00:47:54 -06:00
|
|
|
GncEmployee * gncOwnerGetEmployee (const GncOwner *owner);
|
2001-12-05 23:46:42 -06:00
|
|
|
|
2011-03-20 14:33:55 -05:00
|
|
|
const char * gncOwnerGetID (const GncOwner *owner);
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncOwnerGetName (const GncOwner *owner);
|
2011-03-20 14:33:55 -05:00
|
|
|
GncAddress * gncOwnerGetAddr (const GncOwner *owner);
|
|
|
|
gboolean gncOwnerGetActive (const GncOwner *owner);
|
2008-08-01 11:02:07 -05:00
|
|
|
gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner);
|
2011-05-11 16:50:45 -05:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/** \name Set routines.
|
|
|
|
@{
|
|
|
|
*/
|
|
|
|
void gncOwnerSetActive (const GncOwner *owner, gboolean active);
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
|
2011-05-11 16:51:45 -05:00
|
|
|
|
|
|
|
/** \name Comparison routines.
|
|
|
|
@{
|
|
|
|
*/
|
2011-05-11 16:51:54 -05:00
|
|
|
/** Assess equality by checking
|
|
|
|
* - if both owner objects refer to the same owner type
|
|
|
|
* - and if the owner reference points to the same
|
|
|
|
* {vendor/customer/employee} in memory */
|
|
|
|
gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
|
|
|
|
/** Same as gncOwnerEqual, but returns 0 if
|
|
|
|
equal to be used as a GList custom compare function */
|
|
|
|
int gncOwnerGCompareFunc (const GncOwner *a, const GncOwner *b);
|
|
|
|
/** Sort on name */
|
|
|
|
int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
|
2011-05-11 16:51:45 -05:00
|
|
|
/** @} */
|
2001-12-05 23:46:42 -06:00
|
|
|
|
2010-03-27 16:01:21 -05:00
|
|
|
/** Get the GncGUID of the immediate owner */
|
|
|
|
const GncGUID * gncOwnerGetGUID (const GncOwner *owner);
|
|
|
|
GncGUID gncOwnerRetGUID (GncOwner *owner);
|
2002-02-03 20:53:13 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/**
|
2010-03-27 16:01:21 -05:00
|
|
|
* Get the "parent" Owner or GncGUID thereof. The "parent" owner
|
2002-02-03 20:53:13 -06:00
|
|
|
* is the Customer or Vendor, or the Owner of a Job
|
|
|
|
*/
|
2011-10-10 07:34:58 -05:00
|
|
|
const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner);
|
|
|
|
const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner);
|
2002-02-03 20:53:13 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/** attach an owner to a lot */
|
2008-08-01 11:02:07 -05:00
|
|
|
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);
|
2002-06-25 10:08:50 -05:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/** Get the owner from the lot. If an owner is found in the lot,
|
2002-06-25 10:08:50 -05:00
|
|
|
* fill in "owner" and return TRUE. Otherwise return FALSE.
|
|
|
|
*/
|
|
|
|
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
|
|
|
|
|
2010-03-27 16:01:21 -05:00
|
|
|
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid);
|
2006-01-18 22:09:00 -06:00
|
|
|
|
2006-02-19 12:20:18 -06:00
|
|
|
/** Get the kvp-frame from the underlying owner object */
|
|
|
|
KvpFrame* gncOwnerGetSlots(GncOwner* owner);
|
|
|
|
|
2011-08-13 10:33:27 -05:00
|
|
|
/**
|
|
|
|
* Apply a payment of "amount" for the owner, between the xfer_account
|
|
|
|
* (bank or other asset) and the posted_account (A/R or A/P). If the
|
|
|
|
* caller supplies an (optional) invoice argument, then apply the
|
|
|
|
* payment to that invoice first before any other invoice.
|
|
|
|
*/
|
|
|
|
Transaction *
|
2011-09-30 13:47:43 -05:00
|
|
|
gncOwnerApplyPayment (const GncOwner *owner, GncInvoice *invoice,
|
2011-08-13 10:33:27 -05:00
|
|
|
Account *posted_acc, Account *xfer_acc,
|
|
|
|
gnc_numeric amount, gnc_numeric exch, Timespec date,
|
|
|
|
const char *memo, const char *num);
|
|
|
|
|
2011-09-30 13:47:56 -05:00
|
|
|
/**
|
|
|
|
* Fill in a half-finished payment transaction for the owner. The
|
|
|
|
* transaction txn must already contain one split that belongs to a
|
|
|
|
* bank or other asset account. This function will add the other split
|
|
|
|
* (or splits) that go to the posted_account (A/R or A/P), including
|
|
|
|
* the linking to the lots so that the payment is recorded in the
|
|
|
|
* correct lot(s).
|
|
|
|
*
|
|
|
|
* If the caller supplies an (optional) invoice argument, then apply
|
|
|
|
* the payment to that invoice first before any other invoice.
|
|
|
|
*
|
|
|
|
* Preconditions: The arguments owner, txn, and posted_account must
|
|
|
|
* not be NULL. The txn must be open (by xaccTransBeginEdit()); it
|
|
|
|
* must contain exactly one split; its commodity (by
|
|
|
|
* xaccTransGetCurrency()) must be equal to the owner's commodity (by
|
|
|
|
* gncOwnerGetCurrency()).
|
|
|
|
*
|
|
|
|
* \return The number of splits that have been assigned as owner
|
|
|
|
* payments. On success, this is always positive (1 or larger). In
|
|
|
|
* case of failure (due to unfulfilled conditions on the input
|
|
|
|
* values), null is returned.
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gncOwnerAssignPaymentTxn(const GncOwner *owner, Transaction *txn,
|
|
|
|
Account *posted_account, GncInvoice* invoice);
|
|
|
|
|
2011-08-13 10:33:27 -05:00
|
|
|
/** Returns a GList of account-types based on the owner type */
|
|
|
|
GList * gncOwnerGetAccountTypesList (const GncOwner *owner);
|
|
|
|
|
|
|
|
/** Returns a GList of currencies associated with the owner */
|
|
|
|
GList * gncOwnerGetCommoditiesList (const GncOwner *owner);
|
|
|
|
|
2011-08-13 10:33:42 -05:00
|
|
|
|
|
|
|
/** Given an owner, extract the open balance from the owner and then
|
|
|
|
* convert it to the desired currency.
|
|
|
|
*/
|
|
|
|
gnc_numeric
|
2011-09-30 13:47:43 -05:00
|
|
|
gncOwnerGetBalanceInCurrency (const GncOwner *owner,
|
2011-08-13 10:33:42 -05:00
|
|
|
const gnc_commodity *report_currency);
|
|
|
|
|
2003-10-21 00:12:38 -05:00
|
|
|
#define OWNER_TYPE "type"
|
2005-11-01 21:32:36 -06:00
|
|
|
#define OWNER_TYPE_STRING "type-string" /**< Allows the type to be handled externally. */
|
2003-10-21 00:12:38 -05:00
|
|
|
#define OWNER_CUSTOMER "customer"
|
|
|
|
#define OWNER_JOB "job"
|
|
|
|
#define OWNER_VENDOR "vendor"
|
|
|
|
#define OWNER_EMPLOYEE "employee"
|
|
|
|
#define OWNER_PARENT "parent"
|
|
|
|
#define OWNER_PARENTG "parent-guid"
|
|
|
|
#define OWNER_NAME "name"
|
2002-02-03 20:53:13 -06:00
|
|
|
|
2003-10-21 00:12:38 -05:00
|
|
|
#define OWNER_FROM_LOT "owner-from-lot"
|
2002-06-27 23:39:18 -05:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/**
|
2002-02-04 22:11:31 -06:00
|
|
|
* These two functions are mainly for the convenience of scheme code.
|
|
|
|
* Normal C code has no need to ever use these two functions, and rather
|
|
|
|
* can just use a GncOwner directly and just pass around a pointer to it.
|
|
|
|
*/
|
2011-05-11 16:51:17 -05:00
|
|
|
GncOwner * gncOwnerNew (void);
|
|
|
|
void gncOwnerFree (GncOwner *owner);
|
2002-02-04 22:11:31 -06:00
|
|
|
|
2011-05-11 16:51:27 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These are convenience wrappers around gnc{Vender,Customer,Job,Employee}*
|
|
|
|
* functions. This allows you to begin edit, destroy commit edit an owner
|
|
|
|
* without knowing its type.
|
|
|
|
*/
|
|
|
|
void gncOwnerBeginEdit (GncOwner *owner);
|
|
|
|
void gncOwnerDestroy (GncOwner *owner);
|
|
|
|
|
2001-12-05 23:46:42 -06:00
|
|
|
#endif /* GNC_OWNER_H_ */
|
2004-05-07 00:11:49 -05:00
|
|
|
/** @} */
|
|
|
|
/** @} */
|