2003-10-16 23:32:04 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gncInvoice.h -- the Core Business Invoice Interface *
|
|
|
|
* *
|
|
|
|
* 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 Invoice
|
2005-11-01 21:32:36 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
An invoice holds a list of entries, a pointer to the customer,
|
|
|
|
and the job, the dates entered and posted, as well as the account,
|
2005-11-01 21:32:36 -06:00
|
|
|
transaction and lot for the posted invoice.
|
2004-05-07 00:11:49 -05:00
|
|
|
@{ */
|
|
|
|
/** @file gncInvoice.h
|
2010-03-02 15:41:05 -06:00
|
|
|
@brief Business Invoice Interface
|
2006-02-26 23:42:45 -06:00
|
|
|
@author Copyright (C) 2001,2006 Derek Atkins <warlord@MIT.EDU>
|
2005-11-01 21:32:36 -06:00
|
|
|
@author Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
2004-05-07 00:11:49 -05:00
|
|
|
*/
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
#ifndef GNC_INVOICE_H_
|
|
|
|
#define GNC_INVOICE_H_
|
|
|
|
|
|
|
|
struct _gncInvoice;
|
|
|
|
typedef struct _gncInvoice GncInvoice;
|
2007-04-04 21:44:01 -05:00
|
|
|
typedef struct _gncInvoiceClass GncInvoiceClass;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-06-21 21:38:13 -05:00
|
|
|
#include "gncBillTerm.h"
|
2001-11-29 17:04:34 -06:00
|
|
|
#include "gncEntry.h"
|
2001-12-05 23:46:42 -06:00
|
|
|
#include "gncOwner.h"
|
2002-06-24 17:30:36 -05:00
|
|
|
#include "gnc-lot.h"
|
2006-10-15 14:02:05 -05:00
|
|
|
#include "qofbook.h"
|
2008-11-26 07:06:44 -06:00
|
|
|
#include "qofbook.h"
|
|
|
|
#include "gnc-pricedb.h"
|
2001-11-29 17:04:34 -06:00
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
#define GNC_ID_INVOICE "gncInvoice"
|
2007-04-04 21:44:01 -05:00
|
|
|
|
|
|
|
/* --- type macros --- */
|
|
|
|
#define GNC_TYPE_INVOICE (gnc_invoice_get_type ())
|
|
|
|
#define GNC_INVOICE(o) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_INVOICE, GncInvoice))
|
|
|
|
#define GNC_INVOICE_CLASS(k) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_INVOICE, GncInvoiceClass))
|
|
|
|
#define GNC_IS_INVOICE(o) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_INVOICE))
|
|
|
|
#define GNC_IS_INVOICE_CLASS(k) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_INVOICE))
|
|
|
|
#define GNC_INVOICE_GET_CLASS(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_INVOICE, GncInvoiceClass))
|
|
|
|
GType gnc_invoice_get_type(void);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/** @name Create/Destroy Functions
|
2005-11-01 21:32:36 -06:00
|
|
|
@{ */
|
2003-06-26 22:05:25 -05:00
|
|
|
GncInvoice *gncInvoiceCreate (QofBook *book);
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceDestroy (GncInvoice *invoice);
|
2004-05-07 00:11:49 -05:00
|
|
|
/** @} */
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/** @name Set Functions
|
2005-11-01 21:32:36 -06:00
|
|
|
@{ */
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceSetID (GncInvoice *invoice, const char *id);
|
2001-12-07 21:17:51 -06:00
|
|
|
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
|
2002-02-26 17:42:11 -06:00
|
|
|
void gncInvoiceSetDateOpened (GncInvoice *invoice, Timespec date);
|
|
|
|
void gncInvoiceSetDatePosted (GncInvoice *invoice, Timespec date);
|
2002-06-21 21:38:13 -05:00
|
|
|
void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms);
|
2002-05-08 15:42:38 -05:00
|
|
|
void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id);
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes);
|
2003-01-12 16:07:33 -06:00
|
|
|
void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency);
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceSetActive (GncInvoice *invoice, gboolean active);
|
2002-07-10 16:07:46 -05:00
|
|
|
void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto);
|
2003-04-01 15:15:22 -06:00
|
|
|
void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount);
|
2004-05-07 00:11:49 -05:00
|
|
|
/** @} */
|
2001-11-21 19:23:07 -06:00
|
|
|
|
|
|
|
void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry);
|
|
|
|
void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry);
|
2008-11-26 07:06:44 -06:00
|
|
|
void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price);
|
|
|
|
void gncInvoiceRemovePrice (GncInvoice *invoice, GNCPrice *price);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/** Call this function when adding an entry to a bill instead of an invoice */
|
2002-07-09 23:12:19 -05:00
|
|
|
void gncBillAddEntry (GncInvoice *bill, GncEntry *entry);
|
|
|
|
void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry);
|
2008-11-26 07:06:44 -06:00
|
|
|
void gncBillAddPrice (GncInvoice *bill, GNCPrice *price);
|
|
|
|
void gncBillRemovePrice (GncInvoice *bill, GNCPrice *price);
|
2002-07-09 23:12:19 -05:00
|
|
|
|
2006-02-01 15:49:06 -06:00
|
|
|
/** Call this function when an Entry is changed and you want to
|
|
|
|
re-sort the list of entries
|
|
|
|
*/
|
|
|
|
void gncInvoiceSortEntries (GncInvoice *invoice);
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/** @name Get Functions
|
2005-11-01 21:32:36 -06:00
|
|
|
@{ */
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncInvoiceGetID (const GncInvoice *invoice);
|
2001-12-05 23:46:42 -06:00
|
|
|
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
|
2008-08-01 11:02:07 -05:00
|
|
|
Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice);
|
|
|
|
Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice);
|
|
|
|
Timespec gncInvoiceGetDateDue (const GncInvoice *invoice);
|
|
|
|
GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
|
|
|
|
const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
|
|
|
|
const char * gncInvoiceGetNotes (const GncInvoice *invoice);
|
2008-11-26 07:06:44 -06:00
|
|
|
GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice);
|
2010-03-02 15:41:05 -06:00
|
|
|
const char * gncInvoiceGetType (GncInvoice *invoice);
|
2008-08-01 11:02:07 -05:00
|
|
|
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
|
2002-07-10 16:07:46 -05:00
|
|
|
GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
|
2008-08-01 11:02:07 -05:00
|
|
|
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
|
|
|
|
gboolean gncInvoiceGetActive (const GncInvoice *invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice);
|
|
|
|
Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice);
|
|
|
|
Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice);
|
2004-05-07 00:11:49 -05:00
|
|
|
/** @} */
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/** return the "total" amount of the invoice */
|
2002-10-27 19:44:18 -06:00
|
|
|
gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice);
|
2003-04-01 15:15:22 -06:00
|
|
|
gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type);
|
2003-05-29 11:21:38 -05:00
|
|
|
gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice);
|
|
|
|
gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice);
|
2002-10-27 19:44:18 -06:00
|
|
|
|
2006-10-15 14:02:05 -05:00
|
|
|
typedef GList EntryList;
|
|
|
|
EntryList * gncInvoiceGetEntries (GncInvoice *invoice);
|
2008-11-26 07:06:44 -06:00
|
|
|
GList * gncInvoiceGetPrices(GncInvoice *invoice);
|
|
|
|
GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity* commodity);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/** Post this invoice to an account. Returns the new Transaction
|
2001-11-23 23:35:08 -06:00
|
|
|
* that is tied to this invoice. The transaction is set with
|
2002-05-16 17:45:50 -05:00
|
|
|
* the supplied posted date, due date, and memo. The Transaction
|
|
|
|
* description is set to the name of the company.
|
2001-11-23 23:35:08 -06:00
|
|
|
*/
|
2002-01-22 21:58:07 -06:00
|
|
|
Transaction *
|
|
|
|
gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
2010-03-02 15:41:05 -06:00
|
|
|
Timespec *posted_date, Timespec *due_date,
|
|
|
|
const char *memo, gboolean accumulatesplits);
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/**
|
2003-05-28 22:02:11 -05:00
|
|
|
* UNpost this invoice. This will destroy the posted transaction and
|
|
|
|
* return the invoice to its unposted state. It may leave empty lots
|
|
|
|
* out there. If reset_tax_tables is TRUE, then it will also revert
|
|
|
|
* all the Tax Tables to the parent, which will potentially change the
|
|
|
|
* total value of the invoice. It may also leave some orphaned Tax
|
|
|
|
* Table children.
|
2003-01-01 22:07:58 -06:00
|
|
|
*
|
|
|
|
* Returns TRUE if successful, FALSE if there is a problem.
|
|
|
|
*/
|
|
|
|
gboolean
|
2003-05-28 22:02:11 -05:00
|
|
|
gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/**
|
2003-01-01 20:30:44 -06:00
|
|
|
* Apply a payment of "amount" for the owner, between the xfer_account
|
2006-02-26 23:42:45 -06:00
|
|
|
* (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.
|
2003-01-01 20:30:44 -06:00
|
|
|
*
|
|
|
|
* XXX: yes, this should be in gncOwner, but all the other logic is
|
|
|
|
* in gncInvoice...
|
|
|
|
*/
|
|
|
|
Transaction *
|
2006-02-26 23:42:45 -06:00
|
|
|
gncOwnerApplyPayment (GncOwner *owner, GncInvoice *invoice,
|
2010-03-02 15:41:05 -06:00
|
|
|
Account *posted_acc, Account *xfer_acc,
|
|
|
|
gnc_numeric amount, gnc_numeric exch, Timespec date,
|
|
|
|
const char *memo, const char *num);
|
2003-01-01 20:30:44 -06:00
|
|
|
|
2002-02-10 19:59:54 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/** Given a transaction, find and return the Invoice */
|
2008-08-01 11:02:07 -05:00
|
|
|
GncInvoice * gncInvoiceGetInvoiceFromTxn (const Transaction *txn);
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2004-05-07 00:11:49 -05:00
|
|
|
/** Given a LOT, find and return the Invoice attached to the lot */
|
2002-06-24 17:30:36 -05:00
|
|
|
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
|
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
/** Return a pointer to the instance gncInvoice that is identified
|
2010-03-02 15:41:05 -06:00
|
|
|
* by the guid, and is residing in the book. Returns NULL if the
|
2003-10-19 00:13:59 -05:00
|
|
|
* instance can't be found.
|
|
|
|
* Equivalent function prototype is
|
|
|
|
* GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid);
|
|
|
|
*/
|
|
|
|
#define gncInvoiceLookup(book,guid) \
|
|
|
|
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_INVOICE, GncInvoice)
|
|
|
|
|
2001-11-30 01:37:50 -06:00
|
|
|
void gncInvoiceBeginEdit (GncInvoice *invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceCommitEdit (GncInvoice *invoice);
|
2008-08-01 11:02:07 -05:00
|
|
|
int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b);
|
|
|
|
gboolean gncInvoiceIsPosted (const GncInvoice *invoice);
|
|
|
|
gboolean gncInvoiceIsPaid (const GncInvoice *invoice);
|
2002-02-03 14:01:08 -06:00
|
|
|
|
2002-02-08 22:18:50 -06:00
|
|
|
#define INVOICE_ID "id"
|
|
|
|
#define INVOICE_OWNER "owner"
|
|
|
|
#define INVOICE_OPENED "date_opened"
|
2002-02-10 19:59:54 -06:00
|
|
|
#define INVOICE_POSTED "date_posted"
|
2002-02-08 22:18:50 -06:00
|
|
|
#define INVOICE_DUE "date_due"
|
2002-02-19 12:23:53 -06:00
|
|
|
#define INVOICE_IS_POSTED "is_posted?"
|
2003-05-12 21:07:15 -05:00
|
|
|
#define INVOICE_IS_PAID "is_paid?"
|
2002-05-08 15:42:38 -05:00
|
|
|
#define INVOICE_TERMS "terms"
|
|
|
|
#define INVOICE_BILLINGID "billing_id"
|
2002-02-08 22:18:50 -06:00
|
|
|
#define INVOICE_NOTES "notes"
|
2002-02-03 19:55:33 -06:00
|
|
|
#define INVOICE_ACC "account"
|
2002-02-10 19:59:54 -06:00
|
|
|
#define INVOICE_POST_TXN "posted_txn"
|
2003-05-19 09:56:25 -05:00
|
|
|
#define INVOICE_POST_LOT "posted_lot"
|
2002-05-16 17:45:50 -05:00
|
|
|
#define INVOICE_TYPE "type"
|
2002-07-10 16:07:46 -05:00
|
|
|
#define INVOICE_BILLTO "bill-to"
|
2005-11-01 21:32:36 -06:00
|
|
|
#define INVOICE_ENTRIES "list_of_entries"
|
|
|
|
#define INVOICE_JOB "invoice_job"
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2002-06-27 23:39:18 -05:00
|
|
|
#define INVOICE_FROM_LOT "invoice-from-lot"
|
|
|
|
#define INVOICE_FROM_TXN "invoice-from-txn"
|
|
|
|
|
2006-10-15 14:02:05 -05:00
|
|
|
QofBook *gncInvoiceGetBook(GncInvoice *x);
|
|
|
|
|
2003-10-14 16:20:55 -05:00
|
|
|
/** deprecated functions */
|
|
|
|
#define gncInvoiceGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
2004-01-06 19:54:37 -06:00
|
|
|
#define gncInvoiceRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
|
2003-10-16 23:32:04 -05:00
|
|
|
#define gncInvoiceLookupDirect(G,B) gncInvoiceLookup((B),&(G))
|
2003-10-14 16:20:55 -05:00
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
#endif /* GNC_INVOICE_H_ */
|
2004-05-07 00:11:49 -05:00
|
|
|
/** @} */
|
|
|
|
/** @} */
|