pilot-qof  0.2.3
Data Structures | Defines | Typedefs | Functions | Variables
Expenses
Query Object Framework

Data Structures

struct  QofExpense
 Wraps QOF around Expense_t. More...

Defines

#define PQOF_EXPENSES_DESC   "Pilot-link QOF expenses"
#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
#define EXPENSE_CREATOR   "exps"

Typedefs

typedef struct Expense Expense_t

Functions

void populate_currencies (void)
 Populate the currency table with the known currencies.
PQCurrencypq_currency_lookup (QofInstance *inst, gint currency_code)
static gboolean currency_cb (gpointer key, gpointer value, gpointer data)
gint32 pq_set_currency (QofInstance *inst, gchar *mnemonic)
Expense_t * pq_expense_get_pilot (QofEntity *inst)
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 const gchar * expensePrintable (gpointer instance)
gboolean PQExpensesRegister (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

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.

Define Documentation

#define EXPENSE_CREATOR   "exps"

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

Definition at line 71 of file pilot-expenses.h.

#define PQ_CURRENCY_FRACTION   "expense/currency/fraction"

type: KVP_TYPE_GINT64

Definition at line 64 of file pilot-expenses.h.

#define PQ_CURRENCY_MNEMONIC   "expense/currency/mnemonic"

type: KVP_TYPE_STRING

Definition at line 60 of file pilot-expenses.h.

#define PQ_CURRENCY_SYMBOL   "expense/currency/symbol"

type: KVP_TYPE_STRING

Definition at line 62 of file pilot-expenses.h.

#define PQ_EXPENSE_PREF   Expense_Pref

Expense Preferences identifier.

Definition at line 67 of file pilot-expenses.h.


Function Documentation

static void exp_setAmount ( QofExpense e,
QofNumeric  h 
) [static]
Todo:
FIXME: INSERT handler can set one without the other. Need to use the pref.default_currency?

Definition at line 843 of file pilot-expenses.c.

References QofExpense::reset_amount, and QofExpense::temp_amount.

Referenced by PQExpensesRegister().

{
    Expense_t *qe;

    g_return_if_fail (e != NULL);
    qe = &e->wrap;
    g_return_if_fail (qe != NULL);
    e->temp_amount = qof_numeric_to_double (h);
    e->reset_amount = TRUE;
    /* if an amount can ever be set without a currency_code,
       this needs to be reviewed. */
    if (e->currency)
        exp_combine_currency_with_amount (e);
}
static void exp_setDistance ( QofExpense e,
const gchar *  distance_name 
) [static]
Todo:
Convert when setting into ExpensePref

Definition at line 901 of file pilot-expenses.c.

Referenced by PQExpensesRegister().

{
    gint i;
    for (i = 0; ExpenseDistanceNames[i] != NULL; i++)
    {
        if (0 == safe_strcmp (ExpenseDistanceNames[i], distance_name))
        {
            e->distance_unit = i;
        }
    }
}
void populate_currencies ( void  )

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 72 of file pilot-expenses.c.

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

{
    if (PQCurrencyTable != NULL)
        return;
    PQCurrencyTable = g_hash_table_new (g_direct_hash, g_direct_equal);
    {   /* Australia    0   100     AU$     AUD */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 0;
        c->fraction = 100;
        c->symbol = "AU$";
        c->mnemonic = "AUD";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Austria  1   100     €     ATS */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 1;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "ATS";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Belgium      2   100     €     BEF */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 2;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "BEF";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Brazil   3   100     R$      BRL */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 3;
        c->fraction = 100;
        c->symbol = "R$";
        c->mnemonic = "BRL";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Canada   4   100     $CN     CAD */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 4;
        c->fraction = 100;
        c->symbol = "$CN";
        c->mnemonic = "CAD";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Denmark      5   100     DKK     DKK */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 5;
        c->fraction = 100;
        c->symbol = "DKK";
        c->mnemonic = "DKK";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Finland      6   100     €     FIM */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 6;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "FIM";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* France       7   100     €     FRF */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 7;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "FRF";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Germany      8   100     €     DEM */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 8;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "DEM";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Hong Kong    9   100     HK$     HKD */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 9;
        c->fraction = 100;
        c->symbol = "HK$";
        c->mnemonic = "HKD";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Iceland  10  100     ISK     ISK */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 10;
        c->fraction = 100;
        c->symbol = "ISK";
        c->mnemonic = "ISK";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Ireland      11  100     €     IEP */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 11;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "IEP";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Italy    12  1       EUR     ITL */
        /* The Italian Lira had a fraction == 1 */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 12;
        c->fraction = 100;
        c->symbol = "EUR";
        c->mnemonic = "ITL";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Japan        13  1   ¥  ¥      JPY */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 13;
        c->fraction = 1;
        c->symbol = "¥";
        c->mnemonic = "JPY";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Luxembourg   14  100 ˆ  €     LUF */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 14;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "LUF";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Mexico       15  100     MXP     MXP */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 15;
        c->fraction = 100;
        c->symbol = "MXP";
        c->mnemonic = "MXP";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Netherlands  16  100     €     ANG */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 16;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "ANG";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* New Zealand  17  100     $NZ     NZD */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 17;
        c->fraction = 100;
        c->symbol = "$NZ";
        c->mnemonic = "NZD";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Norway       18  100     NOK     NOK */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 18;
        c->fraction = 100;
        c->symbol = "NOK";
        c->mnemonic = "NOK";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Spain    19  100     €     ESP */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 19;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "ESP";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Sweden   20  100     SEK     SEK */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 20;
        c->fraction = 100;
        c->symbol = "SEK";
        c->mnemonic = "SEK";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Switzerland  21  100     CHF     CHF */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 21;
        c->fraction = 100;
        c->symbol = "CHF";
        c->mnemonic = "CHF";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* United Kingdom 22    100     £      GBP */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 22;
        c->fraction = 100;
        c->symbol = "£";
        c->mnemonic = "GBP";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* United States  23    100     $US     USD */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 23;
        c->fraction = 100;
        c->symbol = "$US";
        c->mnemonic = "USD";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* India        24  100     Rs      INR */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 24;
        c->fraction = 100;
        c->symbol = "Rs";
        c->mnemonic = "INR";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Indonesia    25  1       Rp      IDR */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 25;
        c->fraction = 1;
        c->symbol = "Rp";
        c->mnemonic = "IDR";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Korea    26  100     KRW     KRW  (South) */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 26;
        c->fraction = 100;
        c->symbol = "KRW";
        c->mnemonic = "KRW";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Malaysia     27  100     RM      MYR */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 27;
        c->fraction = 100;
        c->symbol = "RM";
        c->mnemonic = "MYR";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* P.R.C. // People's Rep. China 28 100 RMB     CNY */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 28;
        c->fraction = 100;
        c->symbol = "RMB";
        c->mnemonic = "CNY";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Phillipines  29  100     P       PHP */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 29;
        c->fraction = 100;
        c->symbol = "P";
        c->mnemonic = "PHP";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Singapore    30  100     $       SGD */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 30;
        c->fraction = 100;
        c->symbol = "$";
        c->mnemonic = "SGD";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Thailand     31  100     BHT     THB */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 31;
        c->fraction = 100;
        c->symbol = "BHT";
        c->mnemonic = "THB";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* Taiwan   32  100     NT$     TWD */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 32;
        c->fraction = 100;
        c->symbol = "NT$";
        c->mnemonic = "TWD";
        c->non_utf8 = FALSE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
    {   /* EU (Euro)    133 100     €     EUR */
        PQCurrency *c = g_new0 (PQCurrency, 1);
        c->pq_code = 133;
        c->fraction = 100;
        c->symbol = "€";
        c->mnemonic = "EUR";
        c->non_utf8 = TRUE;
        g_hash_table_insert (PQCurrencyTable,
            GINT_TO_POINTER (c->pq_code), (gpointer) c);
    }
}

Variable Documentation

QofObject expenses_object_def [static]
Initial value:
 {
  interface_version  :   4 ,
  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 935 of file pilot-expenses.c.

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 53 of file pilot-expenses.c.

Referenced by populate_currencies().