Introduce GncInvoiceType enum and start using it instead of the char based Invoice Type.

This also puts a first structure in place to add credit notes later on.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21393 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2011-10-08 16:59:01 +00:00
parent fda7e72c89
commit 1546e8204c
3 changed files with 95 additions and 37 deletions

View File

@ -2646,7 +2646,7 @@ gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book)
columns = gnc_search_param_prepend (columns, _("Billing ID"), NULL, type,
INVOICE_BILLINGID, NULL);
columns = gnc_search_param_prepend (columns, _("Type"), NULL, type,
INVOICE_TYPE, NULL);
INVOICE_TYPE_STRING, NULL);
columns = gnc_search_param_prepend_with_justify (columns, _("Paid"),
GTK_JUSTIFY_CENTER, NULL, type,
INVOICE_IS_PAID, NULL);
@ -2712,9 +2712,8 @@ gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book)
{
QofQueryPredData *inv_type_pred;
GSList *param_list = NULL;
inv_type_pred = qof_query_string_predicate(QOF_COMPARE_EQUAL,
gncInvoiceGetTypeFromOwnerType(owner_type),
QOF_STRING_MATCH_NORMAL, FALSE);
inv_type_pred = qof_query_int32_predicate(QOF_COMPARE_EQUAL,
gncInvoiceGetTypeListForOwnerType(owner_type));
param_list = g_slist_prepend (param_list, INVOICE_TYPE);
qof_query_add_term (q, param_list, inv_type_pred, QOF_QUERY_AND);
}
@ -2844,14 +2843,14 @@ gnc_invoice_show_bills_due (QofBook *book, double days_in_advance)
qof_query_add_boolean_match (q, g_slist_prepend(g_slist_prepend(NULL, LOT_IS_CLOSED),
INVOICE_POST_LOT), FALSE, QOF_QUERY_AND);
/* Bug#602091, #639365: The INVOICE_TYPE string unfortunately is
* stored in translated form due to the usage of gncInvoiceGetType
/* Bug#602091, #639365: The INVOICE_TYPE_STRING string unfortunately is
* stored in translated form due to the usage of gncInvoiceGetTypeString
* for user-visible strings as well. Hence, as an exception we
* must also search for the translated here even though it's an
* internal flag. */
pred_data = qof_query_string_predicate (QOF_COMPARE_NEQ, _("Invoice"),
QOF_STRING_MATCH_NORMAL, FALSE);
qof_query_add_term (q, g_slist_prepend(NULL, INVOICE_TYPE), pred_data, QOF_QUERY_AND);
qof_query_add_term (q, g_slist_prepend(NULL, INVOICE_TYPE_STRING), pred_data, QOF_QUERY_AND);
end_date = time(NULL);
if (days_in_advance < 0)

View File

@ -838,26 +838,68 @@ gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type)
return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, TRUE, type);
}
const char * gncInvoiceGetTypeFromOwnerType (GncOwnerType type)
// FIXME this should return a list of valid invoice types for a given owner type
GncInvoiceType gncInvoiceGetTypeListForOwnerType (GncOwnerType type)
{
switch (type)
{
case GNC_OWNER_CUSTOMER:
return _("Invoice");
return GNC_INVOICE_CUST_INVOICE;
case GNC_OWNER_VENDOR:
return _("Bill");
return GNC_INVOICE_VEND_INVOICE;
case GNC_OWNER_EMPLOYEE:
return _("Expense");
return GNC_INVOICE_EMPL_INVOICE;
default:
return NULL;
return GNC_INVOICE_UNDEFINED;
}
}
const char * gncInvoiceGetType (GncInvoice *invoice)
GncInvoiceType gncInvoiceGetType (GncInvoice *invoice)
{
if (!invoice) return NULL;
return gncInvoiceGetTypeFromOwnerType (gncInvoiceGetOwnerType (invoice));
if (!invoice) return GNC_INVOICE_UNDEFINED;
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;
case GNC_OWNER_VENDOR:
if (/* Amount is positive*/ 1 >= 0)
return GNC_INVOICE_VEND_INVOICE;
else
return GNC_INVOICE_VEND_CREDIT_NOTE;
case GNC_OWNER_EMPLOYEE:
if (/* Amount is positive*/ 1 >= 0)
return GNC_INVOICE_EMPL_INVOICE;
else
return GNC_INVOICE_EMPL_CREDIT_NOTE;
default:
return GNC_INVOICE_UNDEFINED;
}
}
const char * gncInvoiceGetTypeString (GncInvoice *invoice)
{
GncInvoiceType type = gncInvoiceGetType(invoice);
switch (type)
{
case GNC_INVOICE_CUST_INVOICE:
return _("Invoice");
case GNC_INVOICE_VEND_INVOICE:
return _("Bill");
case GNC_INVOICE_EMPL_INVOICE:
return _("Expense");
case GNC_INVOICE_CUST_CREDIT_NOTE:
return _("Customer Credit Note");
case GNC_INVOICE_VEND_CREDIT_NOTE:
return _("Vendor Credit Note");
case GNC_INVOICE_EMPL_CREDIT_NOTE:
return _("Employee Credit Note");
default:
return NULL;
}
}
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice)
@ -1178,7 +1220,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
lot = gnc_lot_new (book);
gnc_lot_begin_edit (lot);
type = gncInvoiceGetType (invoice);
type = gncInvoiceGetTypeString (invoice);
/* Set the lot title */
lot_title = g_strdup_printf ("%s %s", type, gncInvoiceGetID (invoice));
@ -1823,26 +1865,27 @@ gboolean gncInvoiceRegister (void)
{
static QofParam params[] =
{
{ INVOICE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID, (QofSetterFunc)gncInvoiceSetID },
{ INVOICE_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL },
{ INVOICE_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened, (QofSetterFunc)gncInvoiceSetDateOpened },
{ INVOICE_DUE, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateDue, NULL },
{ INVOICE_POSTED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted, (QofSetterFunc)gncInvoiceSetDatePosted },
{ INVOICE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID, (QofSetterFunc)gncInvoiceSetID },
{ INVOICE_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL },
{ INVOICE_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened, (QofSetterFunc)gncInvoiceSetDateOpened },
{ INVOICE_DUE, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateDue, NULL },
{ INVOICE_POSTED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted, (QofSetterFunc)gncInvoiceSetDatePosted },
{ INVOICE_IS_POSTED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted, NULL },
{ INVOICE_IS_PAID, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid, NULL },
{ INVOICE_BILLINGID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetBillingID, (QofSetterFunc)gncInvoiceSetBillingID },
{ INVOICE_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetNotes, (QofSetterFunc)gncInvoiceSetNotes },
{ INVOICE_ACC, GNC_ID_ACCOUNT, (QofAccessFunc)gncInvoiceGetPostedAcc, (QofSetterFunc)gncInvoiceSetPostedAcc },
{ INVOICE_POST_TXN, GNC_ID_TRANS, (QofAccessFunc)gncInvoiceGetPostedTxn, (QofSetterFunc)gncInvoiceSetPostedTxn },
{ INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot, NULL/*(QofSetterFunc)gncInvoiceSetPostedLot*/ },
{ INVOICE_TYPE, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetType, NULL },
{ INVOICE_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms, (QofSetterFunc)gncInvoiceSetTerms },
{ INVOICE_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL },
{ 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 },
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
{ INVOICE_IS_PAID, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid, NULL },
{ INVOICE_BILLINGID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetBillingID, (QofSetterFunc)gncInvoiceSetBillingID },
{ INVOICE_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetNotes, (QofSetterFunc)gncInvoiceSetNotes },
{ INVOICE_ACC, GNC_ID_ACCOUNT, (QofAccessFunc)gncInvoiceGetPostedAcc, (QofSetterFunc)gncInvoiceSetPostedAcc },
{ INVOICE_POST_TXN, GNC_ID_TRANS, (QofAccessFunc)gncInvoiceGetPostedTxn, (QofSetterFunc)gncInvoiceSetPostedTxn },
{ INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot, NULL/*(QofSetterFunc)gncInvoiceSetPostedLot*/ },
{ INVOICE_TYPE, QOF_TYPE_INT32, (QofAccessFunc)gncInvoiceGetType, NULL },
{ INVOICE_TYPE_STRING, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetTypeString, NULL },
{ INVOICE_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms, (QofSetterFunc)gncInvoiceSetTerms },
{ INVOICE_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL },
{ 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 },
{ 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 },
};

View File

@ -51,6 +51,20 @@ typedef GList GncInvoiceList;
#define GNC_ID_INVOICE "gncInvoice"
typedef enum
{
GNC_INVOICE_UNDEFINED ,
GNC_INVOICE_CUST_INVOICE , /* Invoice */
GNC_INVOICE_VEND_INVOICE , /* Bill */
GNC_INVOICE_EMPL_INVOICE , /* Voucher */
GNC_INVOICE_CUST_CREDIT_NOTE , /* Credit Note for a customer */
GNC_INVOICE_VEND_CREDIT_NOTE , /* Credit Note from a vendor */
GNC_INVOICE_EMPL_CREDIT_NOTE , /* Credit Note from an employee,
not sure this makes sense,
but all code is symmetrical
so I've added it to prevent unexpected errors */
} GncInvoiceType;
/* --- type macros --- */
#define GNC_TYPE_INVOICE (gnc_invoice_get_type ())
#define GNC_INVOICE(o) \
@ -122,8 +136,9 @@ GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
const char * gncInvoiceGetNotes (const GncInvoice *invoice);
GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice);
const char * gncInvoiceGetTypeFromOwnerType (GncOwnerType type);
const char * gncInvoiceGetType (GncInvoice *invoice);
GncInvoiceType gncInvoiceGetTypeListForOwnerType (GncOwnerType type);
GncInvoiceType gncInvoiceGetType (GncInvoice *invoice);
const char * gncInvoiceGetTypeString (GncInvoice *invoice);
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
@ -207,6 +222,7 @@ gboolean gncInvoiceIsPaid (const GncInvoice *invoice);
#define INVOICE_POST_TXN "posted_txn"
#define INVOICE_POST_LOT "posted_lot"
#define INVOICE_TYPE "type"
#define INVOICE_TYPE_STRING "type_string"
#define INVOICE_BILLTO "bill-to"
#define INVOICE_ENTRIES "list_of_entries"
#define INVOICE_JOB "invoice_job"