gpe-expenses  0.1.9
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
Expenses
Query Object Framework

Files

file  qof-expenses.h
 QOF expense definitions.

Data Structures

struct  QofCurrency
 qof-expenses currency data wrapper. More...

Macros

#define GPE_MOD_EXP   "gpe-expenses-module"
#define GPE_QOF_EXPENSES   "gpe_expenses"
#define QOF_EXPENSES_DESC   "GPE QOF expenses"
#define EXP_DATE   "expense_date"
#define EXP_TYPE   "type_of_expense"
#define EXP_PAYMENT   "form_of_payment"
#define EXP_CURRENCY   "currency_code"
#define EXP_AMOUNT   "expense_amount"
#define EXP_VENDOR   "expense_vendor"
#define EXP_CITY   "expense_city"
#define EXP_ATTENDEES   "expense_attendees"
#define EXP_NOTE   "expense_note"
#define EXP_CATEGORY   "category"
#define EXP_DISTANCE   "distance_unit"
#define EXP_KVP   "currency_lookup"
#define PQ_CURRENCY_MNEMONIC   "expense/currency/mnemonic"
#define PQ_CURRENCY_SYMBOL   "expense/currency/symbol"
#define PQ_CURRENCY_FRACTION   "expense/currency/fraction"
#define DISTANCE_LIST(_)
#define PAYMENT_TYPE_LIST(_)
#define EXPENSE_TYPE_LIST(_)
#define _GNU_SOURCE
#define _(String)   dgettext (LIBRARY_GETTEXT_PACKAGE, String)
#define STRING(name, value)   gchar * G_GNUC_UNUSED name##noop = _(#name);
#define MARKUP(name, list)

Typedefs

typedef struct QofExp_s QofExp
 Wraps QOF around pilot-link expenses.
typedef void(* QofCurrencyCB )(gpointer key, gpointer value, gpointer user_data)

Enumerations

enum  ExpenseDistance { Miles = 0, Kilometers, Miles = 0, Kilometers }
enum  ExpensePayment {
  AmericanExpress = 0, Cash = 1, Cheque, CreditCard,
  MasterCard, Prepaid, VISA, Unfiled,
  AmericanExpress = 0, Cash = 1, Cheque, CreditCard,
  MasterCard, Prepaid, VISA, Unfiled
}
 typedef for expense payment types. More...
enum  ExpenseType {
  Airfare = 0, Breakfast = 1, Bus = 2, BusinessMeals,
  CarRental, Dinner, Entertainment, Fax,
  Gas, Gifts, Hotel, Incidentals,
  Laundry, Limo, Lodging, Lunch,
  Mileage, Other, Parking, Postage,
  Snack, Subway, Supplies, Taxi,
  Telephone, Tips, Tolls, Train,
  Airfare = 0, Breakfast = 1, Bus = 2, BusinessMeals,
  CarRental, Dinner, Entertainment, Fax,
  Gas, Gifts, Hotel, Incidentals,
  Laundry, Limo, Lodging, Lunch,
  Mileage, Other, Parking, Postage,
  Snack, Subway, Supplies, Taxi,
  Telephone, Tips, Tolls, Train
}
 typedef for expense types More...

Functions

void qof_currency_foreach (QofCurrencyCB cb, gpointer user_data)
QofCurrencyqof_currency_lookup (QofInstance *inst, gint currency_code)
 Set details of a QofCurrency from a currency_code.
QofCurrencyqof_currency_lookup_name (QofInstance *inst, gchar *mnemonic)
 Lookup a currency by name.
const gchar * ExpenseDistanceasString (ExpenseDistance n)
ExpenseDistance ExpenseDistancefromString (const gchar *str)
const gchar * ExpensePaymentasString (ExpensePayment n)
ExpensePayment ExpensePaymentfromString (const gchar *str)
const gchar * ExpenseTypeasString (ExpenseType n)
ExpenseType ExpenseTypefromString (const gchar *str)
gboolean ExpensesRegister (void)
 Register this object with QOF.
static void G_GNUC_UNUSED ExpenseTypetranslate (void)
static void G_GNUC_UNUSED ExpensePaymenttranslate (void)

Detailed Description

    Like ::DB, Expenses uses UTC time within QOF and sets localtime when
    calling pilot-link code.

Gradually becoming a standard QOF method, whilst retaining compatibility with the simple pilot-link currency handling instead of going the whole hog to GnuCash currencies. The old Expense_t has been removed for easier sharing between applications.

The typed enumerators ::ExpenseDistance, ExpenseType and ExpensePayment may look strange initially because macros are used to ensure that the enum value and a string version of the enum are always in sync. This allows the QOF backends to write human-readable data stores by specifying an ExpenseType of "Parking" as:

<string type="type_of_expense">Parking</string>

instead of:

<string type="type_of_expense">5</string>

In particular, do not let the macro syntax _(name, value) fool you into thinking it is related to _(String) from gettext! Note how the enumerator is handled by doxygen:

enum ExpenseType {
  Airfare = 0, Breakfast = 1, Bus = 2, BusinessMeals, ...

Translation must only be used to represent the string version of the enum value in the user interface and all internal handling of the enum value must remain untranslated in the QofEntity itself as this would lock the data into a specific locale.

Note
Translation support in the user interface requires a little adjustment of the display routines. Do NOT use translated strings in the ::QofEntity - only in the user interface. The problem is that although only the UI cares, the translated strings themselves are only accessible via the library. See ExpenseType and ExpensePayment.

Macro Definition Documentation

#define DISTANCE_LIST (   _)
Value:
_(Miles, = 0) \
_(Kilometers,)

Definition at line 162 of file qof-expenses.h.

#define EXPENSE_TYPE_LIST (   _)
Value:
_(Airfare, = 0) \
_(Breakfast, = 1) \
_(Bus, = 2) \
_(BusinessMeals, ) \
_(CarRental, ) \
_(Dinner, ) \
_(Entertainment, ) \
_(Fax, ) \
_(Gas, ) \
_(Gifts, ) \
_(Hotel, ) \
_(Incidentals, ) \
_(Laundry, ) \
_(Limo, ) \
_(Lodging, ) \
_(Lunch, ) \
_(Mileage, ) \
_(Other, ) \
_(Parking, ) \
_(Postage, ) \
_(Snack, ) \
_(Subway, ) \
_(Supplies, ) \
_(Taxi, ) \
_(Telephone, ) \
_(Tips, ) \
_(Tolls, ) \
_(Train, )

Definition at line 176 of file qof-expenses.h.

#define GPE_MOD_EXP   "gpe-expenses-module"
Bug:
need to support qof-expenses and gpe-expenses

Definition at line 80 of file qof-expenses.h.

#define MARKUP (   name,
  list 
)
Value:
static void G_GNUC_UNUSED name##translate (void) \
{ \
list(STRING) \
}

Definition at line 66 of file translate.c.

#define PAYMENT_TYPE_LIST (   _)
Value:
_(AmericanExpress, = 0) \
_(Cash, = 1 ) \
_(Cheque, ) \
_(CreditCard, ) \
_(MasterCard, ) \
_(Prepaid, ) \
_(VISA, ) \
_(Unfiled, )

Definition at line 166 of file qof-expenses.h.

#define PQ_CURRENCY_FRACTION   "expense/currency/fraction"

type: KVP_TYPE_GINT64 - inherited from pilot-link via pilot-qof.

Definition at line 101 of file qof-expenses.h.

#define PQ_CURRENCY_MNEMONIC   "expense/currency/mnemonic"

type: KVP_TYPE_STRING - inherited from pilot-link via pilot-qof.

Definition at line 97 of file qof-expenses.h.

#define PQ_CURRENCY_SYMBOL   "expense/currency/symbol"

type: KVP_TYPE_STRING - inherited from pilot-link via pilot-qof.

Definition at line 99 of file qof-expenses.h.

Enumeration Type Documentation

typedef for expense payment types.

Note
These can be translated but it requires a little adjustment of the display routines. Do NOT use translated strings in the ::QofEntity - only in the user interface. The problem is that although only the UI cares, the translated strings themselves are only accessible via the library. This requires the use of dgettext not the ordinary gettext or the _(String) macro.

In your UI, to retrieve the translated string for an ExpensePayment, wrap ExpenseTypeasString in a call to the library translation support:

ExpensePayment i = Cash;
GtkComboBox * my_combo_box;
// set i to the enum value to display as a translated string
gtk_combo_box_append_text (my_combo_box,
dgettext(LIBRARY_GETTEXT_PACKAGE, ExpensePaymentasString(i)));
// the combo_box has a translation of "Cash" added to the list.

You may choose to define your own macro for this.

Other translatable strings in your application code must continue to use gettext or the _(String) macro as normal.

In accordance with the gettext manual, the library code does not call setlocale (LC_ALL, ""). It is the responsibility of the main program to set the locale.

Definition at line 238 of file qof-expenses.h.

typedef for expense types

Note
These can be translated but it requires a little adjustment of the display routines. Do NOT use translated strings in the ::QofEntity - only in the user interface. The problem is that although only the UI cares, the translated strings themselves are only accessible via the library. This requires the use of dgettext not the ordinary gettext or the _(String) macro.

In your UI, to retrieve the translated string for an ExpenseType, wrap ExpenseTypeasString in a call to the library translation support:

GtkComboBox * my_combo_box;
ExpenseType i = Telephone;
// set i to the enum value to display as a translated string
gtk_combo_box_append_text (my_combo_box,
dgettext(LIBRARY_GETTEXT_PACKAGE, ExpenseTypeasString(i)));
// the combo_box has a translation of "Telephone" added to the list.

You may choose to define your own macro for this.

Other translatable strings in your application code must continue to use gettext or the _(String) macro as normal.

In accordance with the gettext manual, the library code does not call setlocale (LC_ALL, ""). It is the responsibility of the main program to set the locale.

Definition at line 270 of file qof-expenses.h.

Function Documentation

gboolean ExpensesRegister ( void  )

Register this object with QOF.

In accordance with the gettext manual, the library code does not call setlocale (LC_ALL, ""). It is the responsibility of the main program to set the locale. The library just calls bindtextdomain with the domain for the library, LIBRARY_GETTEXT_PACKAGE which is exported via the libqofexpensesobjects API.

bindtextdomain (LIBRARY_GETTEXT_PACKAGE, LOCALE_DIR);

Definition at line 837 of file qof-expenses.c.

{
static QofParam params[] = {
{ EXP_DATE, QOF_TYPE_TIME, (QofAccessFunc) exp_getTime, (QofSetterFunc) exp_setTime, NULL },
{ EXP_TYPE, QOF_TYPE_STRING, (QofAccessFunc) exp_getType, (QofSetterFunc) exp_setType, NULL },
{ EXP_PAYMENT, QOF_TYPE_STRING, (QofAccessFunc) exp_getPayment, (QofSetterFunc) exp_setPayment, NULL },
{ EXP_CURRENCY, QOF_TYPE_INT32, (QofAccessFunc) exp_getCurrency, (QofSetterFunc) exp_setCurrency, NULL },
{ EXP_AMOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc) exp_getAmount, (QofSetterFunc) exp_setAmount, NULL },
{ EXP_VENDOR, QOF_TYPE_STRING, (QofAccessFunc) exp_getVendor, (QofSetterFunc) exp_setVendor, NULL },
{ EXP_CITY, QOF_TYPE_STRING, (QofAccessFunc) exp_getCity, (QofSetterFunc) exp_setCity, NULL },
{ EXP_ATTENDEES, QOF_TYPE_STRING, (QofAccessFunc) exp_getAttendees, (QofSetterFunc) exp_setAttendees, NULL },
{ EXP_NOTE, QOF_TYPE_STRING, (QofAccessFunc) exp_getNote, (QofSetterFunc) exp_setNote, NULL },
{ EXP_DISTANCE, QOF_TYPE_STRING, (QofAccessFunc) exp_getDistance, (QofSetterFunc) exp_setDistance, NULL },
{ EXP_CATEGORY, QOF_TYPE_STRING, (QofAccessFunc) exp_getCategory, (QofSetterFunc) exp_setCategory, NULL },
{ EXP_KVP, QOF_TYPE_KVP, (QofAccessFunc) qof_instance_get_slots, NULL, NULL },
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc) qof_instance_get_book, NULL, NULL },
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc) qof_instance_get_guid, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL },
};
QofCurrency* qof_currency_lookup ( QofInstance inst,
gint  currency_code 
)

Set details of a QofCurrency from a currency_code.

Lookup details of a QofCurrency from a short identifier. The QofInstance will have a KvpFrame set (replacing any existing values for the same keys) containing: -PQ_CURRENCY_MNEMONIC -PQ_CURRENCY_FRACTION -PQ_CURRENCY_SYMBOL

Parameters
instThe QofInstance to hold the KvpFrame containing the details of the currency.
currency_codeThe identifier of this currency.
Returns
a pointer to the QofCurrency identified by the currency_code or NULL on error.

Definition at line 437 of file qof-expenses.c.

{
QofCurrency *currency;
currency = NULL;
if(!qof_currency_table) populate_currencies();
currency = (QofCurrency*)g_hash_table_lookup(
qof_currency_table, GINT_TO_POINTER(currency_code));
if(!currency)
{
PERR (" unsupported currency! %d", currency_code);
return NULL;
}
kvp_frame_set_string(qof_instance_get_slots(inst),
kvp_frame_set_gint64(qof_instance_get_slots(inst),
if(currency->non_utf8)
{
gchar * k_symbol = g_strdup (currency->symbol);
kvp_frame_set_string(qof_instance_get_slots(inst),
PQ_CURRENCY_SYMBOL, qof_util_make_utf8(k_symbol));
}
QofCurrency* qof_currency_lookup_name ( QofInstance inst,
gchar *  mnemonic 
)

Lookup a currency by name.

Slower than ::gpe_currency_lookup because the entire currency hash must be searched. Otherwise, equivalent.

Definition at line 423 of file qof-expenses.c.

{
QofCurrency *currency;
currency = NULL;