GnuCash  4.8a-80-g9825132ea+
gncInvoice.h
Go to the documentation of this file.
1 /********************************************************************\
2  * gncInvoice.h -- the Core Business Invoice 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 \********************************************************************/
36 #ifndef GNC_INVOICE_H_
37 #define GNC_INVOICE_H_
38 
39 struct _gncInvoice;
40 typedef struct _gncInvoice GncInvoice;
41 typedef struct _gncInvoiceClass GncInvoiceClass;
42 typedef GList GncInvoiceList;
43 
44 #include <glib.h>
45 #include "gncBillTerm.h"
46 #include "gncEntry.h"
47 #include "gncOwner.h"
48 #include "gnc-lot.h"
49 #include "qofbook.h"
50 #include "qofbook.h"
51 #include "gnc-pricedb.h"
52 
53 #define GNC_ID_INVOICE "gncInvoice"
54 
55 typedef enum
56 {
57  GNC_INVOICE_UNDEFINED ,
58  GNC_INVOICE_CUST_INVOICE , /* Invoice */
59  GNC_INVOICE_VEND_INVOICE , /* Bill */
60  GNC_INVOICE_EMPL_INVOICE , /* Voucher */
61  GNC_INVOICE_CUST_CREDIT_NOTE , /* Credit Note for a customer */
62  GNC_INVOICE_VEND_CREDIT_NOTE , /* Credit Note from a vendor */
63  GNC_INVOICE_EMPL_CREDIT_NOTE , /* Credit Note from an employee,
64  not sure this makes sense,
65  but all code is symmetrical
66  so I've added it to prevent unexpected errors */
67  GNC_INVOICE_NUM_TYPES
68 } GncInvoiceType;
69 
70 /* --- type macros --- */
71 #define GNC_TYPE_INVOICE (gnc_invoice_get_type ())
72 #define GNC_INVOICE(o) \
73  (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_INVOICE, GncInvoice))
74 #define GNC_INVOICE_CLASS(k) \
75  (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_INVOICE, GncInvoiceClass))
76 #define GNC_IS_INVOICE(o) \
77  (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_INVOICE))
78 #define GNC_IS_INVOICE_CLASS(k) \
79  (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_INVOICE))
80 #define GNC_INVOICE_GET_CLASS(o) \
81  (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_INVOICE, GncInvoiceClass))
82 GType gnc_invoice_get_type(void);
83 
86 GncInvoice *gncInvoiceCreate (QofBook *book);
87 
88 void gncInvoiceDestroy (GncInvoice *invoice);
89 
96 GncInvoice *gncInvoiceCopy (const GncInvoice *other_invoice);
101 void gncInvoiceSetID (GncInvoice *invoice, const char *id);
102 void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner);
105 void gncInvoiceSetDateOpenedGDate (GncInvoice *invoice, const GDate *date);
106 void gncInvoiceSetDateOpened (GncInvoice *invoice, time64 date);
107 void gncInvoiceSetDatePosted (GncInvoice *invoice, time64 date);
108 void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms);
109 void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id);
110 void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes);
111 void gncInvoiceSetDocLink (GncInvoice *invoice, const char *doclink);
112 void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency);
113 void gncInvoiceSetActive (GncInvoice *invoice, gboolean active);
114 void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note);
115 void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto);
116 void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount);
119 void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry);
120 void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry);
121 void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price);
122 
124 void gncBillAddEntry (GncInvoice *bill, GncEntry *entry);
125 void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry);
126 
130 void gncInvoiceSortEntries (GncInvoice *invoice);
131 
135 void gncInvoiceRemoveEntries (GncInvoice *invoice);
136 
139 const char * gncInvoiceGetID (const GncInvoice *invoice);
140 const GncOwner * gncInvoiceGetOwner (const GncInvoice *invoice);
141 time64 gncInvoiceGetDateOpened (const GncInvoice *invoice);
142 time64 gncInvoiceGetDatePosted (const GncInvoice *invoice);
143 time64 gncInvoiceGetDateDue (const GncInvoice *invoice);
144 GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
145 const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
146 const char * gncInvoiceGetNotes (const GncInvoice *invoice);
147 const char * gncInvoiceGetDocLink (const GncInvoice *invoice);
148 GncOwnerType gncInvoiceGetOwnerType (const GncInvoice *invoice);
149 GList * gncInvoiceGetTypeListForOwnerType (const GncOwnerType type);
150 GncInvoiceType gncInvoiceGetType (const GncInvoice *invoice);
151 const char * gncInvoiceGetTypeString (const GncInvoice *invoice);
152 gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
153 GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
154 gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
155 gboolean gncInvoiceGetActive (const GncInvoice *invoice);
156 gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice);
157 
158 GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice);
159 Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice);
160 Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice);
165 gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice);
166 gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type);
167 gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice);
168 gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice);
171 AccountValueList *gncInvoiceGetTotalTaxList (GncInvoice *invoice);
172 
173 typedef GList EntryList;
174 EntryList * gncInvoiceGetEntries (GncInvoice *invoice);
175 GNCPrice * gncInvoiceGetPrice (GncInvoice *invoice, gnc_commodity* commodity);
176 
185 gboolean gncInvoiceAmountPositive (const GncInvoice *invoice);
186 
196 GHashTable *gncInvoiceGetForeignCurrencies (const GncInvoice *invoice);
197 
215 Transaction *
216 gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
217  time64 posted_date, time64 due_date,
218  const char *memo, gboolean accumulatesplits,
219  gboolean autopay);
220 
231 gboolean
232 gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables);
233 
239 void
240 gncInvoiceAutoApplyPayments (GncInvoice *invoice);
241 
255 void
256 gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn,
257  Account *xfer_acc, gnc_numeric amount,
258  gnc_numeric exch, time64 date,
259  const char *memo, const char *num);
260 
261 
263 GncInvoice * gncInvoiceGetInvoiceFromTxn (const Transaction *txn);
264 
266 GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
267 
274 static inline GncInvoice * gncInvoiceLookup (const QofBook *book, const GncGUID *guid)
275 {
276  if (book == NULL || guid == NULL) return NULL;
277  QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_INVOICE, GncInvoice);
278 }
279 
280 void gncInvoiceBeginEdit (GncInvoice *invoice);
281 void gncInvoiceCommitEdit (GncInvoice *invoice);
282 int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b);
283 gboolean gncInvoiceIsPosted (const GncInvoice *invoice);
284 gboolean gncInvoiceIsPaid (const GncInvoice *invoice);
285 
286 #define INVOICE_ID "id"
287 #define INVOICE_OWNER "owner"
288 #define INVOICE_OPENED "date_opened"
289 #define INVOICE_POSTED "date_posted"
290 #define INVOICE_DUE "date_due"
291 #define INVOICE_IS_POSTED "is_posted?"
292 #define INVOICE_IS_PAID "is_paid?"
293 #define INVOICE_TERMS "terms"
294 #define INVOICE_BILLINGID "billing_id"
295 #define INVOICE_NOTES "notes"
296 #define INVOICE_DOCLINK "doclink"
297 #define INVOICE_ACC "account"
298 #define INVOICE_POST_TXN "posted_txn"
299 #define INVOICE_POST_LOT "posted_lot"
300 #define INVOICE_IS_CN "credit_note"
301 #define INVOICE_TYPE "type"
302 #define INVOICE_TYPE_STRING "type_string"
303 #define INVOICE_BILLTO "bill-to"
304 #define INVOICE_ENTRIES "list_of_entries"
305 #define INVOICE_JOB "invoice_job"
306 
307 #define INVOICE_FROM_LOT "invoice-from-lot"
308 #define INVOICE_FROM_TXN "invoice-from-txn"
309 
310 QofBook *gncInvoiceGetBook (GncInvoice *x);
311 
313 #define gncInvoiceGetGUID(x) qof_instance_get_guid (QOF_INSTANCE(x))
314 #define gncInvoiceRetGUID(x) (x ? *(qof_instance_get_guid (QOF_INSTANCE(x))) : *(guid_null()))
315 
317 gboolean gncInvoiceEqual (const GncInvoice *a, const GncInvoice *b);
318 
319 #endif /* GNC_INVOICE_H_ */
320 
Business Interface: Object OWNERs.
a simple price database for gnucash
void gncInvoiceRemoveEntries(GncInvoice *invoice)
Remove all entries from an invoice.
Definition: gncInvoice.c:775
Transaction * gncInvoicePostToAccount(GncInvoice *invoice, Account *acc, time64 posted_date, time64 due_date, const char *memo, gboolean accumulatesplits, gboolean autopay)
Post this invoice to an account.
Definition: gncInvoice.c:1502
#define QOF_BOOK_RETURN_ENTITY(book, guid, e_type, c_type)
Encapsulates all the information about a dataset manipulated by QOF.
Definition: qofbook.h:183
GHashTable * gncInvoiceGetForeignCurrencies(const GncInvoice *invoice)
Return an overview of amounts on this invoice that will be posted to accounts in currencies that are ...
Definition: gncInvoice.c:1375
void gncInvoiceSortEntries(GncInvoice *invoice)
Call this function when an Entry is changed and you want to re-sort the list of entries.
Definition: gncInvoice.c:765
gnc_numeric gncInvoiceGetTotal(GncInvoice *invoice)
Return the "total" amount of the invoice as seen on the document (and shown to the user in the report...
Definition: gncInvoice.c:1021
void gncInvoiceAutoApplyPayments(GncInvoice *invoice)
Attempt to pay the invoice using open payment lots and lots for documents of the opposite sign (credi...
Definition: gncInvoice.c:1951
GncInvoice * gncInvoiceGetInvoiceFromTxn(const Transaction *txn)
Given a transaction, find and return the Invoice.
Definition: gncInvoice.c:1339
void gncBillAddEntry(GncInvoice *bill, GncEntry *entry)
Call this function when adding an entry to a bill instead of an invoice.
Definition: gncInvoice.c:734
void gncInvoiceApplyPayment(const GncInvoice *invoice, Transaction *txn, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, time64 date, const char *memo, const char *num)
A convenience function to apply a payment to an invoice.
Definition: gncInvoice.c:1995
Encapsulate all the information about a dataset.
void gncInvoiceSetDateOpenedGDate(GncInvoice *invoice, const GDate *date)
Set the DateOpened using a GDate argument.
Definition: gncInvoice.c:493
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Definition: gncInvoice.c:1301
gboolean gncInvoiceUnpost(GncInvoice *invoice, gboolean reset_tax_tables)
Unpost this invoice.
Definition: gncInvoice.c:1785
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Definition: gnc-date.h:93
Business Entry Interface.
gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b)
Test support function used by test-dbi-business-stuff.c.
Definition: gncInvoice.c:2081
AccountValueList * gncInvoiceGetTotalTaxList(GncInvoice *invoice)
Return a list of tax totals accumulated per tax account.
Definition: gncInvoice.c:1045
The type used to store guids in C.
Definition: guid.h:75
GncInvoice * gncInvoiceCopy(const GncInvoice *other_invoice)
Create a new GncInvoice object as a deep copy of the given other invoice.
Definition: gncInvoice.c:342
Billing Term interface.
gboolean gncInvoiceAmountPositive(const GncInvoice *invoice)
Depending on the invoice type, invoices have a different effect on the balance.
Definition: gncInvoice.c:1354