Expenses
[Query Object Framework]


Detailed Description

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

Note:
pack_Expense still uses the old prototype using 0xffff instead of pi_buf->used. exp_pack has been modified to set pi_buf->used from the length returned by pack_Expense. Other databases already support pi_buffer and if expense is updated, this will need to be changed.


Files

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

Data Structures

struct  PQCurrency_s
 Pilot-expenses currency data wrapper. More...
struct  QofExpense
 Wraps QOF around Expense_t. More...

Defines

#define QOF_EXPENSES_DESC   "Pilot-link QOF expenses"
#define EXPENSE_CREATOR   "exps"
#define PILOT_LINK_QOF_EXPENSES   "pilot_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_ATTENDEES   "expense_attendees"
#define EXP_NOTE   "expense_note"
#define EXP_CATEGORY   "category"
#define EXP_DISTANCE   "distance_unit"
#define EXP_VENDOR   "expense_vendor"
#define EXP_CITY   "expense_city"
#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 PQ_EXPENSE_PREF   Expense_Pref

Typedefs

typedef PQCurrency_s PQCurrency
 Pilot-expenses currency data wrapper.

Functions

static void populate_currencies (void)
 Populate the currency table with the known currencies.
static PQCurrencypq_currency_lookup (QofInstance *inst, gint currency_code)
static QofExpenseexpense_create (QofBook *book)
static const gchar * qof_exp_distanceAsString (enum ExpenseDistance distance)
static const gchar * qof_exp_paymentAsString (enum ExpensePayment payment)
static const gchar * qof_exp_typeAsString (enum ExpenseType type)
static enum ExpensePayment qof_exp_paymentFromString (const gchar *payment_string)
static enum ExpenseType qof_exp_typeFromString (const gchar *type_string)
static QofTime * exp_getTime (QofExpense *e)
static const gchar * exp_getType (QofExpense *e)
static const gchar * exp_getPayment (QofExpense *e)
static gint exp_getCurrency (QofExpense *e)
static QofNumeric exp_getAmount (QofExpense *e)
static const gchar * exp_getVendor (QofExpense *e)
static const gchar * exp_getCity (QofExpense *e)
static const gchar * exp_getAttendees (QofExpense *e)
static const gchar * exp_getNote (QofExpense *e)
static const gchar * exp_getDistance (QofExpense *e)
static const gchar * exp_getCategory (QofExpense *e)
static void exp_setTime (QofExpense *e, QofTime *h)
static void exp_setType (QofExpense *e, const gchar *type_string)
static void exp_setPayment (QofExpense *e, const gchar *payment_string)
static void exp_combine_currency_with_amount (QofExpense *e)
static void exp_setCurrency (QofExpense *e, gint code)
static void exp_setAmount (QofExpense *e, QofNumeric h)
static void exp_setVendor (QofExpense *e, gchar *h)
static void exp_setCity (QofExpense *e, gchar *h)
static void exp_setAttendees (QofExpense *e, gchar *h)
static void exp_setNote (QofExpense *e, gchar *h)
static void exp_setDistance (QofExpense *e, const gchar *distance_name)
static void exp_setCategory (QofExpense *e, gchar *n)
static gint exp_unpack (QofEntity *ent, gpointer user_data)
static gint exp_pack (QofEntity *ent, gpointer user_data)
static gint exp_pref_unpack (QofEntity *ent, gpointer user_data)
static gint exp_appinfo_unpack (QofEntity *ent, gpointer user_data)
static gint qof_exp_free (QofEntity *ent, gpointer user_data)
static const gchar * expensePrintable (gpointer instance)
gboolean ExpensesRegister (void)
 Register this object with QOF.

Variables

static QofLogModule log_module = "pilotqof-objects"
static GHashTable * PQCurrencyTable = NULL
 Currency Table data.
static QofObject expenses_object_def
static PQPack expenses_pack_def


Define Documentation

#define EXPENSE_CREATOR   "exps"

Inherited from pilot-link because the exported form using makelong is not constant.

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

#define PQ_CURRENCY_FRACTION   "expense/currency/fraction"

type: KVP_TYPE_GINT64

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

Referenced by pq_currency_lookup().

#define PQ_CURRENCY_MNEMONIC   "expense/currency/mnemonic"

type: KVP_TYPE_STRING

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

Referenced by pq_currency_lookup().

#define PQ_CURRENCY_SYMBOL   "expense/currency/symbol"

type: KVP_TYPE_STRING

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

Referenced by pq_currency_lookup().

#define PQ_EXPENSE_PREF   Expense_Pref

Expense Preferences identifier.

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


Function Documentation

static void exp_setAmount ( QofExpense e,
QofNumeric  h 
) [static]

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

References QofExpense::currency, exp_combine_currency_with_amount(), QofExpense::reset_amount, QofExpense::temp_amount, and QofExpense::wrap.

Referenced by ExpensesRegister().

00818 {
00819     Expense_t *qe;
00820 
00821     g_return_if_fail (e != NULL);
00822     qe = &e->wrap;
00823     e->temp_amount = qof_numeric_to_double (h);
00824     e->reset_amount = TRUE;
00825     /* if an amount can ever be set without a currency_code,
00826        this needs to be reviewed. */
00829     if (e->currency)
00830         exp_combine_currency_with_amount (e);
00831 }

static void exp_setDistance ( QofExpense e,
const gchar *  distance_name 
) [static]

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

References QofExpense::distance_unit.

Referenced by ExpensesRegister().

00875 {
00876     gint i;
00878     for (i = 0; ExpenseDistanceNames[i] != NULL; i++)
00879     {
00880         if (0 == safe_strcmp (ExpenseDistanceNames[i], distance_name))
00881         {
00882             e->distance_unit = i;
00883         }
00884     }
00885 }

static void populate_currencies ( void   )  [static]

Populate the currency table with the known currencies.

Custom currencies are not included.

All mnemonics are from gnucash and use the ISO4217 namespace

custom currencies are the same and may end up with the same struct: gchar name[16], gchar symbol[4], gchar rate[8].

Ignore currencies[5] (the five available currencies from the main table above) but:

Todo:
store currencies[4] from AppInfo which are the four custom currencies.

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

References PQCurrency_s::fraction, PQCurrency_s::mnemonic, PQCurrency_s::non_utf8, PQCurrency_s::pq_code, PQCurrencyTable, and PQCurrency_s::symbol.

Referenced by exp_pref_unpack(), and pq_currency_lookup().

00084 {
00085     PQCurrencyTable = g_hash_table_new (g_direct_hash, g_direct_equal);
00086     {   /* Australia    0   100     AU$     AUD */
00087         PQCurrency *c = g_new0 (PQCurrency, 1);
00088         c->pq_code = 0;
00089         c->fraction = 100;
00090         c->symbol = "AU$";
00091         c->mnemonic = "AUD";
00092         c->non_utf8 = FALSE;
00093         g_hash_table_insert (PQCurrencyTable,
00094             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00095     }
00096     {   /* Austria  1   100     €     ATS */
00097         PQCurrency *c = g_new0 (PQCurrency, 1);
00098         c->pq_code = 1;
00099         c->fraction = 100;
00100         c->symbol = "€";
00101         c->mnemonic = "ATS";
00102         c->non_utf8 = TRUE;
00103         g_hash_table_insert (PQCurrencyTable,
00104             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00105     }
00106     {   /* Belgium      2   100     €     BEF */
00107         PQCurrency *c = g_new0 (PQCurrency, 1);
00108         c->pq_code = 2;
00109         c->fraction = 100;
00110         c->symbol = "€";
00111         c->mnemonic = "BEF";
00112         c->non_utf8 = TRUE;
00113         g_hash_table_insert (PQCurrencyTable,
00114             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00115     }
00116     {   /* Brazil   3   100     R$      BRL */
00117         PQCurrency *c = g_new0 (PQCurrency, 1);
00118         c->pq_code = 3;
00119         c->fraction = 100;
00120         c->symbol = "R$";
00121         c->mnemonic = "BRL";
00122         c->non_utf8 = FALSE;
00123         g_hash_table_insert (PQCurrencyTable,
00124             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00125     }
00126     {   /* Canada   4   100     $CN     CAD */
00127         PQCurrency *c = g_new0 (PQCurrency, 1);
00128         c->pq_code = 4;
00129         c->fraction = 100;
00130         c->symbol = "$CN";
00131         c->mnemonic = "CAD";
00132         c->non_utf8 = FALSE;
00133         g_hash_table_insert (PQCurrencyTable,
00134             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00135     }
00136     {   /* Denmark      5   100     DKK     DKK */
00137         PQCurrency *c = g_new0 (PQCurrency, 1);
00138         c->pq_code = 5;
00139         c->fraction = 100;
00140         c->symbol = "DKK";
00141         c->mnemonic = "DKK";
00142         c->non_utf8 = FALSE;
00143         g_hash_table_insert (PQCurrencyTable,
00144             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00145     }
00146     {   /* Finland      6   100     €     FIM */
00147         PQCurrency *c = g_new0 (PQCurrency, 1);
00148         c->pq_code = 6;
00149         c->fraction = 100;
00150         c->symbol = "€";
00151         c->mnemonic = "FIM";
00152         c->non_utf8 = TRUE;
00153         g_hash_table_insert (PQCurrencyTable,
00154             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00155     }
00156     {   /* France       7   100     €     FRF */
00157         PQCurrency *c = g_new0 (PQCurrency, 1);
00158         c->pq_code = 7;
00159         c->fraction = 100;
00160         c->symbol = "€";
00161         c->mnemonic = "FRF";
00162         c->non_utf8 = TRUE;
00163         g_hash_table_insert (PQCurrencyTable,
00164             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00165     }
00166     {   /* Germany      8   100     €     DEM */
00167         PQCurrency *c = g_new0 (PQCurrency, 1);
00168         c->pq_code = 8;
00169         c->fraction = 100;
00170         c->symbol = "€";
00171         c->mnemonic = "DEM";
00172         c->non_utf8 = TRUE;
00173         g_hash_table_insert (PQCurrencyTable,
00174             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00175     }
00176     {   /* Hong Kong    9   100     HK$     HKD */
00177         PQCurrency *c = g_new0 (PQCurrency, 1);
00178         c->pq_code = 9;
00179         c->fraction = 100;
00180         c->symbol = "HK$";
00181         c->mnemonic = "HKD";
00182         c->non_utf8 = FALSE;
00183         g_hash_table_insert (PQCurrencyTable,
00184             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00185     }
00186     {   /* Iceland  10  100     ISK     ISK */
00187         PQCurrency *c = g_new0 (PQCurrency, 1);
00188         c->pq_code = 10;
00189         c->fraction = 100;
00190         c->symbol = "ISK";
00191         c->mnemonic = "ISK";
00192         c->non_utf8 = FALSE;
00193         g_hash_table_insert (PQCurrencyTable,
00194             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00195     }
00196     {   /* Ireland      11  100     €     IEP */
00197         PQCurrency *c = g_new0 (PQCurrency, 1);
00198         c->pq_code = 11;
00199         c->fraction = 100;
00200         c->symbol = "€";
00201         c->mnemonic = "IEP";
00202         c->non_utf8 = TRUE;
00203         g_hash_table_insert (PQCurrencyTable,
00204             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00205     }
00206     {   /* Italy    12  1       EUR     ITL */
00207         /* The Italian Lira had a fraction == 1 */
00208         PQCurrency *c = g_new0 (PQCurrency, 1);
00209         c->pq_code = 12;
00210         c->fraction = 100;
00211         c->symbol = "EUR";
00212         c->mnemonic = "ITL";
00213         c->non_utf8 = FALSE;
00214         g_hash_table_insert (PQCurrencyTable,
00215             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00216     }
00217     {   /* Japan        13  1   ¥  ¥      JPY */
00218         PQCurrency *c = g_new0 (PQCurrency, 1);
00219         c->pq_code = 13;
00220         c->fraction = 1;
00221         c->symbol = "¥";
00222         c->mnemonic = "JPY";
00223         c->non_utf8 = TRUE;
00224         g_hash_table_insert (PQCurrencyTable,
00225             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00226     }
00227     {   /* Luxembourg   14  100 ˆ  €     LUF */
00228         PQCurrency *c = g_new0 (PQCurrency, 1);
00229         c->pq_code = 14;
00230         c->fraction = 100;
00231         c->symbol = "€";
00232         c->mnemonic = "LUF";
00233         c->non_utf8 = TRUE;
00234         g_hash_table_insert (PQCurrencyTable,
00235             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00236     }
00237     {   /* Mexico       15  100     MXP     MXP */
00238         PQCurrency *c = g_new0 (PQCurrency, 1);
00239         c->pq_code = 15;
00240         c->fraction = 100;
00241         c->symbol = "MXP";
00242         c->mnemonic = "MXP";
00243         c->non_utf8 = FALSE;
00244         g_hash_table_insert (PQCurrencyTable,
00245             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00246     }
00247     {   /* Netherlands  16  100     €     ANG */
00248         PQCurrency *c = g_new0 (PQCurrency, 1);
00249         c->pq_code = 16;
00250         c->fraction = 100;
00251         c->symbol = "€";
00252         c->mnemonic = "ANG";
00253         c->non_utf8 = TRUE;
00254         g_hash_table_insert (PQCurrencyTable,
00255             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00256     }
00257     {   /* New Zealand  17  100     $NZ     NZD */
00258         PQCurrency *c = g_new0 (PQCurrency, 1);
00259         c->pq_code = 17;
00260         c->fraction = 100;
00261         c->symbol = "$NZ";
00262         c->mnemonic = "NZD";
00263         c->non_utf8 = FALSE;
00264         g_hash_table_insert (PQCurrencyTable,
00265             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00266     }
00267     {   /* Norway       18  100     NOK     NOK */
00268         PQCurrency *c = g_new0 (PQCurrency, 1);
00269         c->pq_code = 18;
00270         c->fraction = 100;
00271         c->symbol = "NOK";
00272         c->mnemonic = "NOK";
00273         c->non_utf8 = FALSE;
00274         g_hash_table_insert (PQCurrencyTable,
00275             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00276     }
00277     {   /* Spain    19  100     €     ESP */
00278         PQCurrency *c = g_new0 (PQCurrency, 1);
00279         c->pq_code = 19;
00280         c->fraction = 100;
00281         c->symbol = "€";
00282         c->mnemonic = "ESP";
00283         c->non_utf8 = TRUE;
00284         g_hash_table_insert (PQCurrencyTable,
00285             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00286     }
00287     {   /* Sweden   20  100     SEK     SEK */
00288         PQCurrency *c = g_new0 (PQCurrency, 1);
00289         c->pq_code = 20;
00290         c->fraction = 100;
00291         c->symbol = "SEK";
00292         c->mnemonic = "SEK";
00293         c->non_utf8 = FALSE;
00294         g_hash_table_insert (PQCurrencyTable,
00295             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00296     }
00297     {   /* Switzerland  21  100     CHF     CHF */
00298         PQCurrency *c = g_new0 (PQCurrency, 1);
00299         c->pq_code = 21;
00300         c->fraction = 100;
00301         c->symbol = "CHF";
00302         c->mnemonic = "CHF";
00303         c->non_utf8 = FALSE;
00304         g_hash_table_insert (PQCurrencyTable,
00305             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00306     }
00307     {   /* United Kingdom 22    100     £      GBP */
00308         PQCurrency *c = g_new0 (PQCurrency, 1);
00309         c->pq_code = 22;
00310         c->fraction = 100;
00311         c->symbol = "£";
00312         c->mnemonic = "GBP";
00313         c->non_utf8 = TRUE;
00314         g_hash_table_insert (PQCurrencyTable,
00315             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00316     }
00317     {   /* United States  23    100     $US     USD */
00318         PQCurrency *c = g_new0 (PQCurrency, 1);
00319         c->pq_code = 23;
00320         c->fraction = 100;
00321         c->symbol = "$US";
00322         c->mnemonic = "USD";
00323         c->non_utf8 = FALSE;
00324         g_hash_table_insert (PQCurrencyTable,
00325             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00326     }
00327     {   /* India        24  100     Rs      INR */
00328         PQCurrency *c = g_new0 (PQCurrency, 1);
00329         c->pq_code = 24;
00330         c->fraction = 100;
00331         c->symbol = "Rs";
00332         c->mnemonic = "INR";
00333         c->non_utf8 = FALSE;
00334         g_hash_table_insert (PQCurrencyTable,
00335             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00336     }
00337     {   /* Indonesia    25  1       Rp      IDR */
00338         PQCurrency *c = g_new0 (PQCurrency, 1);
00339         c->pq_code = 25;
00340         c->fraction = 1;
00341         c->symbol = "Rp";
00342         c->mnemonic = "IDR";
00343         c->non_utf8 = FALSE;
00344         g_hash_table_insert (PQCurrencyTable,
00345             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00346     }
00347     {   /* Korea    26  100     KRW     KRW  (South) */
00348         PQCurrency *c = g_new0 (PQCurrency, 1);
00349         c->pq_code = 26;
00350         c->fraction = 100;
00351         c->symbol = "KRW";
00352         c->mnemonic = "KRW";
00353         c->non_utf8 = FALSE;
00354         g_hash_table_insert (PQCurrencyTable,
00355             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00356     }
00357     {   /* Malaysia     27  100     RM      MYR */
00358         PQCurrency *c = g_new0 (PQCurrency, 1);
00359         c->pq_code = 27;
00360         c->fraction = 100;
00361         c->symbol = "RM";
00362         c->mnemonic = "MYR";
00363         c->non_utf8 = FALSE;
00364         g_hash_table_insert (PQCurrencyTable,
00365             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00366     }
00367     {   /* P.R.C. // People's Rep. China 28 100 RMB     CNY */
00368         PQCurrency *c = g_new0 (PQCurrency, 1);
00369         c->pq_code = 28;
00370         c->fraction = 100;
00371         c->symbol = "RMB";
00372         c->mnemonic = "CNY";
00373         c->non_utf8 = FALSE;
00374         g_hash_table_insert (PQCurrencyTable,
00375             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00376     }
00377     {   /* Phillipines  29  100     P       PHP */
00378         PQCurrency *c = g_new0 (PQCurrency, 1);
00379         c->pq_code = 29;
00380         c->fraction = 100;
00381         c->symbol = "P";
00382         c->mnemonic = "PHP";
00383         c->non_utf8 = FALSE;
00384         g_hash_table_insert (PQCurrencyTable,
00385             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00386     }
00387     {   /* Singapore    30  100     $       SGD */
00388         PQCurrency *c = g_new0 (PQCurrency, 1);
00389         c->pq_code = 30;
00390         c->fraction = 100;
00391         c->symbol = "$";
00392         c->mnemonic = "SGD";
00393         c->non_utf8 = FALSE;
00394         g_hash_table_insert (PQCurrencyTable,
00395             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00396     }
00397     {   /* Thailand     31  100     BHT     THB */
00398         PQCurrency *c = g_new0 (PQCurrency, 1);
00399         c->pq_code = 31;
00400         c->fraction = 100;
00401         c->symbol = "BHT";
00402         c->mnemonic = "THB";
00403         c->non_utf8 = FALSE;
00404         g_hash_table_insert (PQCurrencyTable,
00405             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00406     }
00407     {   /* Taiwan   32  100     NT$     TWD */
00408         PQCurrency *c = g_new0 (PQCurrency, 1);
00409         c->pq_code = 32;
00410         c->fraction = 100;
00411         c->symbol = "NT$";
00412         c->mnemonic = "TWD";
00413         c->non_utf8 = FALSE;
00414         g_hash_table_insert (PQCurrencyTable,
00415             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00416     }
00417     {   /* EU (Euro)    133 100     €     EUR */
00418         PQCurrency *c = g_new0 (PQCurrency, 1);
00419         c->pq_code = 133;
00420         c->fraction = 100;
00421         c->symbol = "€";
00422         c->mnemonic = "EUR";
00423         c->non_utf8 = TRUE;
00424         g_hash_table_insert (PQCurrencyTable,
00425             GINT_TO_POINTER (c->pq_code), (gpointer) c);
00426     }
00427 }


Variable Documentation

QofObject expenses_object_def [static]

Initial value:

 {
  interface_version: 3 ,
  e_type: "pilot_expenses" ,
  type_label: "Pilot-link QOF expenses" ,
  create:(gpointer) expense_create,
  book_begin:NULL,
  book_end:NULL,
  is_dirty:qof_collection_is_dirty,
  mark_clean:qof_collection_mark_clean,
  foreach:qof_collection_foreach,
  printable:expensePrintable,
  version_cmp:(gint (*)(gpointer, gpointer)) qof_instance_version_cmp,
}

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

Referenced by ExpensesRegister().

PQPack expenses_pack_def [static]

Initial value:

 {
  e_type: "pilot_expenses" ,
  pack_func:exp_pack,
  unpack_func:exp_unpack,
  free_pack_func:qof_exp_free,
  palm_db_name:Expense_DB,
  app_info_unpack:exp_appinfo_unpack,
  db_pref_unpack:exp_pref_unpack,
  pref_creator: "exps" ,
  pref_flag:Expense_Pref,
}

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

Referenced by ExpensesRegister().

GHashTable* PQCurrencyTable = NULL [static]

Currency Table data.

Table relating the currencies[5] to the actual currency names, mnemonics and symbols. In pilot-qof it is indexed by GINT_TO_POINTER(pq_code).

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

Referenced by exp_unpack(), populate_currencies(), and pq_currency_lookup().


Generated on Tue Mar 6 00:08:10 2007 for pilot-qof by  doxygen 1.5.1