r21395 - gnucash/trunk/src/engine - Introduce credit_note flag in invoice object
Geert Janssens
gjanssens at code.gnucash.org
Sat Oct 8 12:59:19 EDT 2011
Author: gjanssens
Date: 2011-10-08 12:59:19 -0400 (Sat, 08 Oct 2011)
New Revision: 21395
Trac: http://svn.gnucash.org/trac/changeset/21395
Modified:
gnucash/trunk/src/engine/gncInvoice.c
gnucash/trunk/src/engine/gncInvoice.h
Log:
Introduce credit_note flag in invoice object
Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c 2011-10-08 16:59:10 UTC (rev 21394)
+++ gnucash/trunk/src/engine/gncInvoice.c 2011-10-08 16:59:19 UTC (rev 21395)
@@ -44,30 +44,31 @@
struct _gncInvoice
{
- QofInstance inst;
+ QofInstance inst;
- char *id;
- char *notes;
- gboolean active;
+ char *id;
+ char *notes;
+ gboolean active;
+ gboolean credit_note;
- char *billing_id;
- char *printname;
- GncBillTerm *terms;
- GList *entries;
- GList *prices;
- GncOwner owner;
- GncOwner billto;
- GncJob *job;
- Timespec date_opened;
- Timespec date_posted;
+ char *billing_id;
+ char *printname;
+ GncBillTerm *terms;
+ GList *entries;
+ GList *prices;
+ GncOwner owner;
+ GncOwner billto;
+ GncJob *job;
+ Timespec date_opened;
+ Timespec date_posted;
- gnc_numeric to_charge_amount;
+ gnc_numeric to_charge_amount;
- gnc_commodity * currency;
+ gnc_commodity *currency;
- Account *posted_acc;
- Transaction *posted_txn;
- GNCLot *posted_lot;
+ Account *posted_acc;
+ Transaction *posted_txn;
+ GNCLot *posted_lot;
};
struct _gncInvoiceClass
@@ -306,6 +307,7 @@
invoice->billto.type = GNC_OWNER_CUSTOMER;
invoice->active = TRUE;
+ invoice->credit_note = FALSE;
invoice->to_charge_amount = gnc_numeric_zero();
@@ -333,6 +335,7 @@
invoice->notes = CACHE_INSERT (from->notes);
invoice->billing_id = CACHE_INSERT (from->billing_id);
invoice->active = from->active;
+ invoice->credit_note = from->credit_note;
invoice->terms = from->terms;
gncBillTermIncRef (invoice->terms);
@@ -513,6 +516,16 @@
gncInvoiceCommitEdit (invoice);
}
+void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note)
+{
+ if (!invoice) return;
+ if (invoice->credit_note == credit_note) return;
+ gncInvoiceBeginEdit (invoice);
+ invoice->credit_note = credit_note;
+ mark_invoice (invoice);
+ gncInvoiceCommitEdit (invoice);
+}
+
void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency)
{
if (!invoice || !currency) return;
@@ -861,20 +874,11 @@
switch (gncInvoiceGetOwnerType (invoice))
{
case GNC_OWNER_CUSTOMER:
- if (/* Amount is positive*/ 1 >= 0)
- return GNC_INVOICE_CUST_INVOICE;
- else
- return GNC_INVOICE_CUST_CREDIT_NOTE;
+ return (invoice->credit_note ? GNC_INVOICE_CUST_CREDIT_NOTE : GNC_INVOICE_CUST_INVOICE);
case GNC_OWNER_VENDOR:
- if (/* Amount is positive*/ 1 >= 0)
- return GNC_INVOICE_VEND_INVOICE;
- else
- return GNC_INVOICE_VEND_CREDIT_NOTE;
+ return (invoice->credit_note ? GNC_INVOICE_VEND_CREDIT_NOTE : GNC_INVOICE_VEND_INVOICE);
case GNC_OWNER_EMPLOYEE:
- if (/* Amount is positive*/ 1 >= 0)
- return GNC_INVOICE_EMPL_INVOICE;
- else
- return GNC_INVOICE_EMPL_CREDIT_NOTE;
+ return (invoice->credit_note ? GNC_INVOICE_EMPL_CREDIT_NOTE : GNC_INVOICE_EMPL_INVOICE);
default:
return GNC_INVOICE_UNDEFINED;
}
@@ -938,7 +942,13 @@
return invoice->active;
}
+gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice)
+{
+ if (!invoice) return FALSE;
+ return invoice->credit_note;
+}
+
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice)
{
if (!invoice) return gnc_numeric_zero();
@@ -1884,6 +1894,7 @@
{ INVOICE_ENTRIES, QOF_TYPE_COLLECT, (QofAccessFunc)qofInvoiceGetEntries, (QofSetterFunc)qofInvoiceSetEntries },
{ INVOICE_JOB, GNC_ID_JOB, (QofAccessFunc)qofInvoiceGetJob, (QofSetterFunc)qofInvoiceSetJob },
{ QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive, (QofSetterFunc)gncInvoiceSetActive },
+ { INVOICE_IS_CN, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetIsCreditNote, (QofSetterFunc)gncInvoiceSetIsCreditNote },
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
{ NULL },
Modified: gnucash/trunk/src/engine/gncInvoice.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h 2011-10-08 16:59:10 UTC (rev 21394)
+++ gnucash/trunk/src/engine/gncInvoice.h 2011-10-08 16:59:19 UTC (rev 21395)
@@ -105,6 +105,7 @@
void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes);
void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency);
void gncInvoiceSetActive (GncInvoice *invoice, gboolean active);
+void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note);
void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto);
void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount);
/** @} */
@@ -143,6 +144,7 @@
GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
gboolean gncInvoiceGetActive (const GncInvoice *invoice);
+gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice);
GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice);
Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice);
@@ -221,6 +223,7 @@
#define INVOICE_ACC "account"
#define INVOICE_POST_TXN "posted_txn"
#define INVOICE_POST_LOT "posted_lot"
+#define INVOICE_IS_CN "credit_note"
#define INVOICE_TYPE "type"
#define INVOICE_TYPE_STRING "type_string"
#define INVOICE_BILLTO "bill-to"
More information about the gnucash-changes
mailing list