Expenses
[Query Object Framework]


Detailed Description

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

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.


Files

file  qof-expenses.h
 QOF expense definitions for pilot-link.

Data Structures

struct  GpeCurrency
 gpe-expenses currency data wrapper. More...

Defines

#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 Expense Expense_t
typedef struct QofExp_s QofExp
 Wraps QOF around Expense_t.
typedef void(* GpeCurrencyCB )(gpointer key, gpointer value, gpointer user_data)

Enumerations

enum  ExpenseDistance { Miles = 0, Kilometers }
enum  ExpensePayment {
  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
}
 typedef for expense types More...

Functions

void gpe_currency_foreach (GpeCurrencyCB cb, gpointer user_data)
GpeCurrencygpe_currency_lookup (QofInstance *inst, gint currency_code)
 Set details of a GpeCurrency from a currency_code.
GpeCurrencygpe_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)


Define 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 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

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

Referenced by gpe_currency_lookup().

#define PQ_CURRENCY_MNEMONIC   "expense/currency/mnemonic"

type: KVP_TYPE_STRING

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

Referenced by gpe_currency_lookup().

#define PQ_CURRENCY_SYMBOL   "expense/currency/symbol"

type: KVP_TYPE_STRING

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

Referenced by gpe_currency_lookup().


Typedef Documentation

typedef struct QofExp_s QofExp

Wraps QOF around Expense_t.

This allows QOF to build as an option rather than adding QofInstance to Expense_t and requiring QOF for all builds.

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


Enumeration Type Documentation

enum ExpensePayment

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 239 of file qof-expenses.h.

enum ExpenseType

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 273 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 955 of file qof-expenses.c.

00956 {
00957         static QofParam params[] = {
00958          { EXP_DATE,       QOF_TYPE_TIME,    (QofAccessFunc) exp_getTime,      (QofSetterFunc) exp_setTime, NULL },
00959          { EXP_TYPE,       QOF_TYPE_STRING,  (QofAccessFunc) exp_getType,      (QofSetterFunc) exp_setType, NULL },
00960          { EXP_PAYMENT,    QOF_TYPE_STRING,  (QofAccessFunc) exp_getPayment,   (QofSetterFunc) exp_setPayment, NULL },
00961          { EXP_CURRENCY,   QOF_TYPE_INT32,   (QofAccessFunc) exp_getCurrency,  (QofSetterFunc) exp_setCurrency, NULL },
00962          { EXP_AMOUNT,     QOF_TYPE_NUMERIC, (QofAccessFunc) exp_getAmount,    (QofSetterFunc) exp_setAmount, NULL },
00963          { EXP_VENDOR,     QOF_TYPE_STRING,  (QofAccessFunc) exp_getVendor,    (QofSetterFunc) exp_setVendor, NULL },
00964          { EXP_CITY,       QOF_TYPE_STRING,  (QofAccessFunc) exp_getCity,      (QofSetterFunc) exp_setCity, NULL },
00965          { EXP_ATTENDEES,  QOF_TYPE_STRING,  (QofAccessFunc) exp_getAttendees, (QofSetterFunc) exp_setAttendees, NULL },
00966          { EXP_NOTE,       QOF_TYPE_STRING,  (QofAccessFunc) exp_getNote,      (QofSetterFunc) exp_setNote, NULL },
00967          { EXP_DISTANCE,   QOF_TYPE_STRING,  (QofAccessFunc) exp_getDistance,  (QofSetterFunc) exp_setDistance, NULL },
00968          { EXP_CATEGORY,   QOF_TYPE_STRING,  (QofAccessFunc) exp_getCategory,  (QofSetterFunc) exp_setCategory, NULL },
00969          { EXP_KVP,        QOF_TYPE_KVP,     (QofAccessFunc) qof_instance_get_slots, NULL, NULL },
00970          { QOF_PARAM_BOOK, QOF_ID_BOOK,      (QofAccessFunc) qof_instance_get_book, NULL, NULL },
00971          { QOF_PARAM_GUID, QOF_TYPE_GUID,    (QofAccessFunc) qof_instance_get_guid, NULL, NULL },
00972          { NULL, NULL, NULL, NULL, NULL },
00973         };
00974 
00975         bindtextdomain (LIBRARY_GETTEXT_PACKAGE, LOCALE_DIR);
00976 
00977         qof_class_register (GPE_QOF_EXPENSES, NULL, params);
00978         if(!gpe_currency_table) populate_currencies();
00979 
00980         return qof_object_register (&expenses_object_def);
00981 }

GpeCurrency* gpe_currency_lookup ( QofInstance *  inst,
gint  currency_code 
)

Set details of a GpeCurrency from a currency_code.

Lookup details of a GpeCurrency 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:
inst The QofInstance to hold the KvpFrame containing the details of the currency.
currency_code The identifier of this currency.
Returns:
a pointer to the GpeCurrency identified by the currency_code or NULL on error.

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

00475 {
00476         GpeCurrency *currency;
00477 
00478         currency = NULL;
00479         if(!gpe_currency_table) populate_currencies();
00480         currency = (GpeCurrency*)g_hash_table_lookup(
00481                 gpe_currency_table, GINT_TO_POINTER(currency_code));
00482         if(!currency)
00483         {
00484                 PERR (" unsupported currency! %d", currency_code);
00485                 return NULL;
00486         }
00487         kvp_frame_set_string(qof_instance_get_slots(inst),
00488                 PQ_CURRENCY_MNEMONIC, currency->mnemonic);
00489         kvp_frame_set_gint64(qof_instance_get_slots(inst),
00490                 PQ_CURRENCY_FRACTION, currency->fraction);
00491         if(currency->non_utf8)
00492         {
00493                 gchar * k_symbol = g_strdup (currency->symbol);
00494                 kvp_frame_set_string(qof_instance_get_slots(inst),
00495                         PQ_CURRENCY_SYMBOL, qof_main_make_utf8(k_symbol));
00496         }
00497         else
00498         {
00499                 kvp_frame_set_string(qof_instance_get_slots(inst),
00500                         PQ_CURRENCY_SYMBOL, currency->symbol);
00501         }
00502         return currency;
00503 }       

GpeCurrency* gpe_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 461 of file qof-expenses.c.

00462 {
00463         GpeCurrency *currency;
00464 
00465         currency = NULL;
00466         if(!gpe_currency_table) populate_currencies();
00467         currency = (GpeCurrency*) g_hash_table_find 
00468                 (gpe_currency_table, check_name, mnemonic);
00469         gpe_currency_lookup(inst, currency->pq_code);
00470         return currency;
00471 }


Generated on Tue Dec 11 05:37:30 2007 for gpe-expenses by  doxygen 1.5.4