~ubuntu-branches/ubuntu/oneiric/gpe-expenses/oneiric

« back to all changes in this revision

Viewing changes to src/qof-expenses.c

  • Committer: Bazaar Package Importer
  • Author(s): Neil Williams
  • Date: 2009-05-24 08:46:26 UTC
  • mfrom: (1.1.6 upstream) (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090524084626-aj2m6clr8fwoigoz
Tags: 0.1.7-1
* New upstream release
* (Closes: #505073): FTBFS with GCC 4.4: expected
  'gint *' but argument is of type 'guint *'
* Add new package to remove translation files from library in
  accordance with Policy 8.2 (libqofexpensesobjects-data)
* Add devhelp support.
* Remove Section and Priority duplication in debian/control.
* use upstream symbol versioning support.
* Update Standards Version (no changes)
* SONAME bump for libqofexpensesobjects to enhance support in other
  applications.
* Add xsltproc to build depends for doc generation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *            qof-expenses.c
3
3
 *
4
4
 *  Thu Oct 21 07:59:13 2004-2005
5
 
 *  Copyright  2004-2005  Neil Williams  <linux@codehelp.co.uk>
 
5
 *  Copyright  2004-2009  Neil Williams  <linux@codehelp.co.uk>
6
6
 ****************************************************************************/
7
7
/*
8
 
    This package is free software; you can redistribute it and/or modify
 
8
    This program is free software; you can redistribute it and/or modify
9
9
    it under the terms of the GNU General Public License as published by
10
10
    the Free Software Foundation; either version 3 of the License, or
11
11
    (at your option) any later version.
41
41
AS_STRING_FUNC  (ExpenseType, EXPENSE_TYPE_LIST)
42
42
FROM_STRING_FUNC(ExpenseType, EXPENSE_TYPE_LIST)
43
43
 
44
 
/** \brief Copy of qof-main function
45
 
 
46
 
Copied into qof-expenses library to prevent a spurious
47
 
dependency.
48
 
*/
49
 
static gchar *
50
 
qof_main_make_utf8 (gchar * string)
51
 
{
52
 
        gchar *value;
53
 
 
54
 
        if (!string)
55
 
                return NULL;
56
 
        if (g_utf8_validate (string, -1, NULL))
57
 
                return string;
58
 
        value = g_locale_to_utf8 (string, -1, NULL, NULL, NULL);
59
 
        if (!value)
60
 
        {
61
 
                PWARN (" unable to convert from locale %s", string);
62
 
                PINFO ("trying to convert from ISO-8859-15.");
63
 
                value = g_convert (string, -1, "UTF-8", "ISO-8859-15",
64
 
                        NULL, NULL, NULL);
65
 
                if (!value)
66
 
                {
67
 
                        PERR (" conversion failed");
68
 
                        return string;
69
 
                }
70
 
                return value;
71
 
        }
72
 
        return value;
73
 
}
74
 
 
75
44
/** \brief Currency Table data
76
 
        
 
45
 
77
46
Table relating the currencies[5] to the actual currency names, mnemonics
78
47
 and symbols. In pilot-qof it is indexed by GINT_TO_POINTER(pq_code). */
79
 
static GHashTable *gpe_currency_table = NULL;
 
48
static GHashTable *qof_currency_table = NULL;
80
49
 
81
50
void
82
 
gpe_currency_foreach(GpeCurrencyCB cb, gpointer user_data)
 
51
qof_currency_foreach(QofCurrencyCB cb, gpointer user_data)
83
52
{
84
 
        g_hash_table_foreach(gpe_currency_table, cb, user_data);
 
53
        g_hash_table_foreach(qof_currency_table, cb, user_data);
85
54
}
86
55
 
87
56
/** \brief Populate the currency table with the known currencies.
103
72
static void
104
73
populate_currencies (void)
105
74
{
106
 
        gpe_currency_table = g_hash_table_new(g_direct_hash, g_direct_equal);
 
75
        qof_currency_table = g_hash_table_new(g_direct_hash, g_direct_equal);
107
76
        {       /* Australia    0       100             AU$             AUD */
108
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
77
                QofCurrency *c = g_new0(QofCurrency, 1);
109
78
                c->pq_code = 0;
110
79
                c->fraction = 100;
111
80
                c->symbol = "AU$";
112
81
                c->mnemonic = "AUD";
113
82
                c->non_utf8 = FALSE;
114
 
                g_hash_table_insert(gpe_currency_table, 
 
83
                g_hash_table_insert(qof_currency_table, 
115
84
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
116
85
        }
117
86
        {       /* Austria      1       100             €               ATS */
118
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
87
                QofCurrency *c = g_new0(QofCurrency, 1);
119
88
                c->pq_code = 1;
120
89
                c->fraction = 100;
121
90
                c->symbol = "€";
122
91
                c->mnemonic = "ATS";
123
92
                c->non_utf8 = TRUE;
124
 
                g_hash_table_insert(gpe_currency_table, 
 
93
                g_hash_table_insert(qof_currency_table, 
125
94
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
126
95
        }
127
96
        {       /* Belgium      2       100             €               BEF */
128
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
97
                QofCurrency *c = g_new0(QofCurrency, 1);
129
98
                c->pq_code = 2;
130
99
                c->fraction = 100;
131
100
                c->symbol = "€";
132
101
                c->mnemonic = "BEF";
133
102
                c->non_utf8 = TRUE;
134
 
                g_hash_table_insert(gpe_currency_table, 
 
103
                g_hash_table_insert(qof_currency_table, 
135
104
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
136
105
        }
137
106
        {       /* Brazil       3       100             R$              BRL */
138
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
107
                QofCurrency *c = g_new0(QofCurrency, 1);
139
108
                c->pq_code = 3;
140
109
                c->fraction = 100;
141
110
                c->symbol = "R$";
142
111
                c->mnemonic = "BRL";
143
112
                c->non_utf8 = FALSE;
144
 
                g_hash_table_insert(gpe_currency_table, 
 
113
                g_hash_table_insert(qof_currency_table, 
145
114
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
146
115
        }
147
116
        {       /* Canada       4       100             $CN             CAD */
148
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
117
                QofCurrency *c = g_new0(QofCurrency, 1);
149
118
                c->pq_code = 4;
150
119
                c->fraction = 100;
151
120
                c->symbol = "$CN";
152
121
                c->mnemonic = "CAD";
153
122
                c->non_utf8 = FALSE;
154
 
                g_hash_table_insert(gpe_currency_table, 
 
123
                g_hash_table_insert(qof_currency_table, 
155
124
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
156
125
        }
157
126
        {       /* Denmark      5       100             DKK             DKK */
158
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
127
                QofCurrency *c = g_new0(QofCurrency, 1);
159
128
                c->pq_code = 5;
160
129
                c->fraction = 100;
161
130
                c->symbol = "DKK";
162
131
                c->mnemonic = "DKK";
163
132
                c->non_utf8 = FALSE;
164
 
                g_hash_table_insert(gpe_currency_table, 
 
133
                g_hash_table_insert(qof_currency_table, 
165
134
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
166
135
        }
167
136
        {       /* Finland      6       100             €               FIM */
168
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
137
                QofCurrency *c = g_new0(QofCurrency, 1);
169
138
                c->pq_code = 6;
170
139
                c->fraction = 100;
171
140
                c->symbol = "€";
172
141
                c->mnemonic = "FIM";
173
142
                c->non_utf8 = TRUE;
174
 
                g_hash_table_insert(gpe_currency_table, 
 
143
                g_hash_table_insert(qof_currency_table, 
175
144
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
176
145
        }
177
146
        {       /* France       7       100             €               FRF */
178
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
147
                QofCurrency *c = g_new0(QofCurrency, 1);
179
148
                c->pq_code = 7;
180
149
                c->fraction = 100;
181
150
                c->symbol = "€";
182
151
                c->mnemonic = "FRF";
183
152
                c->non_utf8 = TRUE;
184
 
                g_hash_table_insert(gpe_currency_table, 
 
153
                g_hash_table_insert(qof_currency_table, 
185
154
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
186
155
        }
187
156
        {       /* Germany      8       100             €               DEM */
188
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
157
                QofCurrency *c = g_new0(QofCurrency, 1);
189
158
                c->pq_code = 8;
190
159
                c->fraction = 100;
191
160
                c->symbol = "€";
192
161
                c->mnemonic = "DEM";
193
162
                c->non_utf8 = TRUE;
194
 
                g_hash_table_insert(gpe_currency_table, 
 
163
                g_hash_table_insert(qof_currency_table, 
195
164
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
196
165
        }
197
166
        {       /* Hong Kong    9       100             HK$             HKD */
198
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
167
                QofCurrency *c = g_new0(QofCurrency, 1);
199
168
                c->pq_code = 9;
200
169
                c->fraction = 100;
201
170
                c->symbol = "HK$";
202
171
                c->mnemonic = "HKD";
203
172
                c->non_utf8 = FALSE;
204
 
                g_hash_table_insert(gpe_currency_table, 
 
173
                g_hash_table_insert(qof_currency_table, 
205
174
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
206
175
        }
207
176
        {       /* Iceland      10      100             ISK             ISK */
208
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
177
                QofCurrency *c = g_new0(QofCurrency, 1);
209
178
                c->pq_code = 10;
210
179
                c->fraction = 100;
211
180
                c->symbol = "ISK";
212
181
                c->mnemonic = "ISK";
213
182
                c->non_utf8 = FALSE;
214
 
                g_hash_table_insert(gpe_currency_table, 
 
183
                g_hash_table_insert(qof_currency_table, 
215
184
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
216
185
        }
217
186
        {       /* Ireland      11      100             €               IEP */
218
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
187
                QofCurrency *c = g_new0(QofCurrency, 1);
219
188
                c->pq_code = 11;
220
189
                c->fraction = 100;
221
190
                c->symbol = "€";
222
191
                c->mnemonic = "IEP";
223
192
                c->non_utf8 = TRUE;
224
 
                g_hash_table_insert(gpe_currency_table, 
 
193
                g_hash_table_insert(qof_currency_table, 
225
194
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
226
195
        }
227
196
        {       /* Italy        12      1               EUR             ITL */
228
197
                /* The Italian Lira had a fraction == 1*/
229
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
198
                QofCurrency *c = g_new0(QofCurrency, 1);
230
199
                c->pq_code = 12;
231
200
                c->fraction = 100;
232
201
                c->symbol = "EUR";
233
202
                c->mnemonic = "ITL";
234
203
                c->non_utf8 = FALSE;
235
 
                g_hash_table_insert(gpe_currency_table, 
 
204
                g_hash_table_insert(qof_currency_table, 
236
205
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
237
206
        }
238
207
        {       /* Japan        13      1       &#165;  ¥               JPY */
239
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
208
                QofCurrency *c = g_new0(QofCurrency, 1);
240
209
                c->pq_code = 13;
241
210
                c->fraction = 1;
242
211
                c->symbol = "¥";
243
212
                c->mnemonic = "JPY";
244
213
                c->non_utf8 = TRUE;
245
 
                g_hash_table_insert(gpe_currency_table, 
 
214
                g_hash_table_insert(qof_currency_table, 
246
215
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
247
216
        }
248
217
        {       /* Luxembourg   14      100     &#136;  €               LUF */
249
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
218
                QofCurrency *c = g_new0(QofCurrency, 1);
250
219
                c->pq_code = 14;
251
220
                c->fraction = 100;
252
221
                c->symbol = "€";
253
222
                c->mnemonic = "LUF";
254
223
                c->non_utf8 = TRUE;
255
 
                g_hash_table_insert(gpe_currency_table, 
 
224
                g_hash_table_insert(qof_currency_table, 
256
225
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
257
226
        }
258
227
        {       /* Mexico       15      100             MXP             MXP */
259
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
228
                QofCurrency *c = g_new0(QofCurrency, 1);
260
229
                c->pq_code = 15;
261
230
                c->fraction = 100;
262
231
                c->symbol = "MXP";
263
232
                c->mnemonic = "MXP";
264
233
                c->non_utf8 = FALSE;
265
 
                g_hash_table_insert(gpe_currency_table, 
 
234
                g_hash_table_insert(qof_currency_table, 
266
235
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
267
236
        }
268
237
        {       /* Netherlands  16      100             €               ANG */
269
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
238
                QofCurrency *c = g_new0(QofCurrency, 1);
270
239
                c->pq_code = 16;
271
240
                c->fraction = 100;
272
241
                c->symbol = "€";
273
242
                c->mnemonic = "ANG";
274
243
                c->non_utf8 = TRUE;
275
 
                g_hash_table_insert(gpe_currency_table, 
 
244
                g_hash_table_insert(qof_currency_table, 
276
245
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
277
246
        }
278
247
        {       /* New Zealand  17      100             $NZ             NZD */
279
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
248
                QofCurrency *c = g_new0(QofCurrency, 1);
280
249
                c->pq_code = 17;
281
250
                c->fraction = 100;
282
251
                c->symbol = "$NZ";
283
252
                c->mnemonic = "NZD";
284
253
                c->non_utf8 = FALSE;
285
 
                g_hash_table_insert(gpe_currency_table, 
 
254
                g_hash_table_insert(qof_currency_table, 
286
255
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
287
256
        }
288
257
        {       /* Norway       18      100             NOK             NOK */
289
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
258
                QofCurrency *c = g_new0(QofCurrency, 1);
290
259
                c->pq_code = 18;
291
260
                c->fraction = 100;
292
261
                c->symbol = "NOK";
293
262
                c->mnemonic = "NOK";
294
263
                c->non_utf8 = FALSE;
295
 
                g_hash_table_insert(gpe_currency_table, 
 
264
                g_hash_table_insert(qof_currency_table, 
296
265
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
297
266
        }
298
267
        {       /* Spain        19      100             €               ESP */
299
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
268
                QofCurrency *c = g_new0(QofCurrency, 1);
300
269
                c->pq_code = 19;
301
270
                c->fraction = 100;
302
271
                c->symbol = "€";
303
272
                c->mnemonic = "ESP";
304
273
                c->non_utf8 = TRUE;
305
 
                g_hash_table_insert(gpe_currency_table, 
 
274
                g_hash_table_insert(qof_currency_table, 
306
275
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
307
276
        }
308
277
        {       /* Sweden       20      100             SEK             SEK */
309
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
278
                QofCurrency *c = g_new0(QofCurrency, 1);
310
279
                c->pq_code = 20;
311
280
                c->fraction = 100;
312
281
                c->symbol = "SEK";
313
282
                c->mnemonic = "SEK";
314
283
                c->non_utf8 = FALSE;
315
 
                g_hash_table_insert(gpe_currency_table, 
 
284
                g_hash_table_insert(qof_currency_table, 
316
285
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
317
286
        }
318
287
        {       /* Switzerland  21      100             CHF             CHF */
319
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
288
                QofCurrency *c = g_new0(QofCurrency, 1);
320
289
                c->pq_code = 21;
321
290
                c->fraction = 100;
322
291
                c->symbol = "CHF";
323
292
                c->mnemonic = "CHF";
324
293
                c->non_utf8 = FALSE;
325
 
                g_hash_table_insert(gpe_currency_table, 
 
294
                g_hash_table_insert(qof_currency_table, 
326
295
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
327
296
        }
328
297
        {       /* United Kingdom 22    100             £               GBP */
329
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
298
                QofCurrency *c = g_new0(QofCurrency, 1);
330
299
                c->pq_code = 22;
331
300
                c->fraction = 100;
332
301
                c->symbol = "£";
333
302
                c->mnemonic = "GBP";
334
303
                c->non_utf8 = TRUE;
335
 
                g_hash_table_insert(gpe_currency_table, 
 
304
                g_hash_table_insert(qof_currency_table, 
336
305
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
337
306
        }
338
307
        {       /* United States  23    100             $US             USD */
339
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
308
                QofCurrency *c = g_new0(QofCurrency, 1);
340
309
                c->pq_code = 23;
341
310
                c->fraction = 100;
342
311
                c->symbol = "$US";
343
312
                c->mnemonic = "USD";
344
313
                c->non_utf8 = FALSE;
345
 
                g_hash_table_insert(gpe_currency_table, 
 
314
                g_hash_table_insert(qof_currency_table, 
346
315
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
347
316
        }
348
317
        {       /* India        24      100             Rs              INR */
349
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
318
                QofCurrency *c = g_new0(QofCurrency, 1);
350
319
                c->pq_code = 24;
351
320
                c->fraction = 100;
352
321
                c->symbol = "Rs";
353
322
                c->mnemonic = "INR";
354
323
                c->non_utf8 = FALSE;
355
 
                g_hash_table_insert(gpe_currency_table, 
 
324
                g_hash_table_insert(qof_currency_table, 
356
325
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
357
326
        }
358
327
        {       /* Indonesia    25      1               Rp              IDR */
359
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
328
                QofCurrency *c = g_new0(QofCurrency, 1);
360
329
                c->pq_code = 25;
361
330
                c->fraction = 1;
362
331
                c->symbol = "Rp";
363
332
                c->mnemonic = "IDR";
364
333
                c->non_utf8 = FALSE;
365
 
                g_hash_table_insert(gpe_currency_table, 
 
334
                g_hash_table_insert(qof_currency_table, 
366
335
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
367
336
        }
368
337
        {       /* Korea        26      100             KRW             KRW  (South) */
369
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
338
                QofCurrency *c = g_new0(QofCurrency, 1);
370
339
                c->pq_code = 26;
371
340
                c->fraction = 100;
372
341
                c->symbol = "KRW";
373
342
                c->mnemonic = "KRW";
374
343
                c->non_utf8 = FALSE;
375
 
                g_hash_table_insert(gpe_currency_table, 
 
344
                g_hash_table_insert(qof_currency_table, 
376
345
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
377
346
        }
378
347
        {       /* Malaysia     27      100             RM              MYR */
379
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
348
                QofCurrency *c = g_new0(QofCurrency, 1);
380
349
                c->pq_code = 27;
381
350
                c->fraction = 100;
382
351
                c->symbol = "RM";
383
352
                c->mnemonic = "MYR";
384
353
                c->non_utf8 = FALSE;
385
 
                g_hash_table_insert(gpe_currency_table, 
 
354
                g_hash_table_insert(qof_currency_table, 
386
355
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
387
356
        }
388
357
        {       /* P.R.C. // People's Rep. China 28     100     RMB             CNY */
389
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
358
                QofCurrency *c = g_new0(QofCurrency, 1);
390
359
                c->pq_code = 28;
391
360
                c->fraction = 100;
392
361
                c->symbol = "RMB";
393
362
                c->mnemonic = "CNY";
394
363
                c->non_utf8 = FALSE;
395
 
                g_hash_table_insert(gpe_currency_table, 
 
364
                g_hash_table_insert(qof_currency_table, 
396
365
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
397
366
        }
398
367
        {       /* Phillipines  29      100             P               PHP */
399
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
368
                QofCurrency *c = g_new0(QofCurrency, 1);
400
369
                c->pq_code = 29;
401
370
                c->fraction = 100;
402
371
                c->symbol = "P";
403
372
                c->mnemonic = "PHP";
404
373
                c->non_utf8 = FALSE;
405
 
                g_hash_table_insert(gpe_currency_table, 
 
374
                g_hash_table_insert(qof_currency_table, 
406
375
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
407
376
        }
408
377
        {       /* Singapore    30      100             $               SGD */
409
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
378
                QofCurrency *c = g_new0(QofCurrency, 1);
410
379
                c->pq_code = 30;
411
380
                c->fraction = 100;
412
381
                c->symbol = "$";
413
382
                c->mnemonic = "SGD";
414
383
                c->non_utf8 = FALSE;
415
 
                g_hash_table_insert(gpe_currency_table, 
 
384
                g_hash_table_insert(qof_currency_table, 
416
385
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
417
386
        }
418
387
        {       /* Thailand     31      100             BHT             THB */
419
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
388
                QofCurrency *c = g_new0(QofCurrency, 1);
420
389
                c->pq_code = 31;
421
390
                c->fraction = 100;
422
391
                c->symbol = "BHT";
423
392
                c->mnemonic = "THB";
424
393
                c->non_utf8 = FALSE;
425
 
                g_hash_table_insert(gpe_currency_table, 
 
394
                g_hash_table_insert(qof_currency_table, 
426
395
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
427
396
        }
428
397
        {       /* Taiwan       32      100             NT$             TWD */
429
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
398
                QofCurrency *c = g_new0(QofCurrency, 1);
430
399
                c->pq_code = 32;
431
400
                c->fraction = 100;
432
401
                c->symbol = "NT$";
433
402
                c->mnemonic = "TWD";
434
403
                c->non_utf8 = FALSE;
435
 
                g_hash_table_insert(gpe_currency_table, 
 
404
                g_hash_table_insert(qof_currency_table, 
436
405
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
437
406
        }
438
407
        {       /* EU (Euro)    133     100             €               EUR */
439
 
                GpeCurrency *c = g_new0(GpeCurrency, 1);
 
408
                QofCurrency *c = g_new0(QofCurrency, 1);
440
409
                c->pq_code = 133;
441
410
                c->fraction = 100;
442
411
                c->symbol = "€";
443
412
                c->mnemonic = "EUR";
444
413
                c->non_utf8 = TRUE;
445
 
                g_hash_table_insert(gpe_currency_table, 
 
414
                g_hash_table_insert(qof_currency_table, 
446
415
                        GINT_TO_POINTER(c->pq_code), (gpointer)c);
447
416
        }
448
417
}
451
420
check_name (gpointer G_GNUC_UNUSED key, gpointer value, gpointer data)
452
421
{
453
422
        gchar * mnemonic = (gchar*) data;
454
 
        GpeCurrency * currency = (GpeCurrency*) value;
 
423
        QofCurrency * currency = (QofCurrency*) value;
455
424
        if (0 == safe_strcmp (mnemonic, currency->mnemonic))
456
425
                return TRUE;
457
426
        return FALSE;
458
427
}
459
428
 
460
 
GpeCurrency*
461
 
gpe_currency_lookup_name (QofInstance * inst, gchar * mnemonic)
 
429
QofCurrency*
 
430
qof_currency_lookup_name (QofInstance * inst, gchar * mnemonic)
462
431
{
463
 
        GpeCurrency *currency;
 
432
        QofCurrency *currency;
464
433
 
465
434
        currency = NULL;
466
 
        if(!gpe_currency_table) populate_currencies();
467
 
        currency = (GpeCurrency*) g_hash_table_find 
468
 
                (gpe_currency_table, check_name, mnemonic);
 
435
        if(!qof_currency_table) populate_currencies();
 
436
        currency = (QofCurrency*) g_hash_table_find 
 
437
                (qof_currency_table, check_name, mnemonic);
469
438
        if (!currency) return NULL;
470
 
        gpe_currency_lookup(inst, currency->pq_code);
 
439
        qof_currency_lookup(inst, currency->pq_code);
471
440
        return currency;
472
441
}
473
442
 
474
 
GpeCurrency*
475
 
gpe_currency_lookup (QofInstance* inst, gint currency_code)
 
443
QofCurrency*
 
444
qof_currency_lookup (QofInstance* inst, gint currency_code)
476
445
{
477
 
        GpeCurrency *currency;
 
446
        QofCurrency *currency;
478
447
 
479
448
        currency = NULL;
480
 
        if(!gpe_currency_table) populate_currencies();
481
 
        currency = (GpeCurrency*)g_hash_table_lookup(
482
 
                gpe_currency_table, GINT_TO_POINTER(currency_code));
 
449
        if(!qof_currency_table) populate_currencies();
 
450
        currency = (QofCurrency*)g_hash_table_lookup(
 
451
                qof_currency_table, GINT_TO_POINTER(currency_code));
483
452
        if(!currency)
484
453
        {
485
454
                PERR (" unsupported currency! %d", currency_code);
493
462
        {
494
463
                gchar * k_symbol = g_strdup (currency->symbol);
495
464
                kvp_frame_set_string(qof_instance_get_slots(inst),
496
 
                        PQ_CURRENCY_SYMBOL, qof_main_make_utf8(k_symbol));
 
465
                        PQ_CURRENCY_SYMBOL, qof_util_make_utf8(k_symbol));
497
466
        }
498
467
        else
499
468
        {
501
470
                        PQ_CURRENCY_SYMBOL, currency->symbol);
502
471
        }
503
472
        return currency;
504
 
}       
505
 
 
506
 
typedef struct ExpenseCustomCurrency {
507
 
                gchar name[16];
508
 
                gchar symbol[4];
509
 
                gchar rate[8];
510
 
} ExpenseCustomCurrency_t;
511
 
 
512
 
struct Expense {
513
 
                struct tm date;
514
 
                ExpenseType type;
515
 
                ExpensePayment payment;
516
 
                gint currency;
517
 
                gchar *amount;
518
 
                gchar *vendor;
519
 
                gchar *city;
520
 
                gchar *attendees;
521
 
                gchar *note;
522
 
};
523
 
 
524
 
struct ExpenseAppInfo {
525
 
//      struct CategoryAppInfo category;
526
 
        struct ExpenseCustomCurrency currencies[4];
527
 
};
 
473
}
528
474
 
529
475
struct QofExp_s
530
476
{
531
477
        QofInstance inst;
532
 
        Expense_t wrap;
533
478
        ExpenseDistance distance_unit;
 
479
        struct tm date;
 
480
        ExpenseType type;
 
481
        ExpensePayment payment;
 
482
        gint currency_code;
 
483
        gchar *amount;
 
484
        gchar *vendor;
 
485
        gchar *city;
 
486
        gchar *attendees;
 
487
        gchar *note;
534
488
        gchar *category;
535
489
        const gchar* print_string;
536
 
        GpeCurrency *currency;
 
490
        QofCurrency *currency;
537
491
        gdouble temp_amount;     /**<  The amount is set before the
538
492
                currency code is available so this acts as a buffer until both
539
493
                pieces of data are available. */
543
497
static QofExp *
544
498
expense_create (QofBook *book)
545
499
{
546
 
        Expense_t *qe;
547
500
        QofExp *obj;
548
501
        QofCollection *coll;
549
502
        GList *all;
 
503
        glong nanosecs;
 
504
        QofTime *qt;
 
505
        QofDate *qd;
550
506
 
551
507
        obj = g_new0(QofExp, 1);
552
508
        qof_instance_init (&obj->inst, GPE_QOF_EXPENSES, book);
554
510
        all = qof_collection_get_data (coll);
555
511
        all = g_list_prepend (all, obj);
556
512
        qof_collection_set_data (coll, all);
557
 
        qe = &obj->wrap;
558
 
        {
559
 
                glong nanosecs;
560
 
                QofTime *qt;
561
 
                QofDate *qd;
562
 
 
563
 
                qt = qof_time_get_current ();
564
 
                nanosecs = qof_time_get_nanosecs (qt);
565
 
                qd = qof_date_from_qtime (qt);
566
 
                if (!qof_date_to_struct_tm (qd, &qe->date, 
567
 
                        &nanosecs))
568
 
                        DEBUG (" failed to set initial date");
569
 
                qof_date_free (qd);
570
 
                qof_time_free (qt);
571
 
        }
572
 
        qe->amount = "0";
 
513
        qt = qof_time_get_current ();
 
514
        nanosecs = qof_time_get_nanosecs (qt);
 
515
        qd = qof_date_from_qtime (qt);
 
516
        if (!qof_date_to_struct_tm (qd, &obj->date, &nanosecs))
 
517
                DEBUG (" failed to set initial date");
 
518
        qof_date_free (qd);
 
519
        qof_time_free (qt);
 
520
        obj->amount = "0";
573
521
        /* 0 == AU$ so use an init value */
574
 
        qe->currency = -1;
575
 
        if(!gpe_currency_table) populate_currencies();
 
522
        obj->currency_code = -1;
 
523
        if(!qof_currency_table) populate_currencies();
576
524
        qof_event_gen ((QofEntity*)obj, QOF_EVENT_CREATE, NULL);
577
525
        return obj;
578
526
}
612
560
static QofTime *
613
561
exp_getTime (QofExp * e)
614
562
{
615
 
        Expense_t *qe;
616
563
        QofDate *qd;
617
564
        QofTime *qt;
618
565
 
619
566
        g_return_val_if_fail (e != NULL, NULL);
620
 
        qe = &e->wrap;
621
 
        qd = qof_date_from_struct_tm (&qe->date);
 
567
        qd = qof_date_from_struct_tm (&e->date);
622
568
        qt = qof_date_to_qtime (qd);
623
569
        qof_date_free (qd);
624
570
        return qt;
627
573
static gchar*
628
574
exp_getType (QofExp * e)
629
575
{
630
 
        Expense_t *qe;
631
576
        gchar* string;
632
577
 
633
578
        g_return_val_if_fail (e != NULL, NULL);
634
 
        qe = &e->wrap;
635
 
        string = g_strdup(qof_exp_typeAsString(qe->type));
 
579
        string = g_strdup(qof_exp_typeAsString(e->type));
636
580
        return string;
637
581
}
638
582
 
639
583
static gchar*
640
584
exp_getPayment (QofExp * e)
641
585
{
642
 
        Expense_t *qe;
643
586
        gchar* string;
644
587
 
645
588
        g_return_val_if_fail (e != NULL, NULL);
646
 
        qe = &e->wrap;
647
 
        string = g_strdup(qof_exp_paymentAsString(qe->payment));
 
589
        string = g_strdup(qof_exp_paymentAsString(e->payment));
648
590
        return string;
649
591
}
650
592
 
651
593
static gint
652
594
exp_getCurrency (QofExp * e)
653
595
{
654
 
        Expense_t *qe;
655
 
 
656
596
        g_return_val_if_fail (e != NULL, -1);
657
 
        qe = &e->wrap;
658
 
        return qe->currency;
 
597
        return e->currency_code;
659
598
}
660
599
 
661
600
static QofNumeric
662
601
exp_getAmount (QofExp * e)
663
602
{
664
 
        Expense_t *qe;
665
603
        QofNumeric amount;
666
604
        gdouble pi_amount;
667
605
        gchar *numeric_char;
668
606
 
669
607
        amount = qof_numeric_zero ();
670
608
        g_return_val_if_fail (e != NULL, amount);
671
 
        qe = &e->wrap;
672
 
        if(qe->amount == 0) { return amount; }
 
609
        if(e->amount == 0) { return amount; }
673
610
        /* floating point as a string converts to gnc_numeric */
674
 
        pi_amount = strtod (qe->amount, NULL);
 
611
        pi_amount = strtod (e->amount, NULL);
675
612
        if(e->currency)
676
613
        {
677
614
                amount = qof_numeric_from_double (pi_amount, e->currency->fraction,
679
616
        }
680
617
        else /* default: use the most common fraction in the Palm currency list. */
681
618
        {
682
 
        amount = qof_numeric_from_double (pi_amount, 100, 
683
 
                QOF_HOW_DENOM_EXACT | QOF_HOW_RND_ROUND);
 
619
                amount = qof_numeric_from_double (pi_amount, 100, 
 
620
                        QOF_HOW_DENOM_EXACT | QOF_HOW_RND_ROUND);
684
621
        }
685
622
        numeric_char = qof_numeric_to_string(amount);
686
623
        g_free(numeric_char);
687
624
 
688
625
        if (qof_numeric_check (amount) == QOF_ERROR_OK)
689
 
        {
690
626
                return amount;
691
 
        }
692
627
        return qof_numeric_zero ();
693
628
}
694
629
 
695
630
static const gchar *
696
631
exp_getVendor (QofExp * e)
697
632
{
698
 
        Expense_t *qe;
699
 
 
700
633
        g_return_val_if_fail (e != NULL, NULL);
701
 
        qe = &e->wrap;
702
 
        return qe->vendor;
 
634
        return e->vendor;
703
635
}
704
636
 
705
637
static const gchar *
706
638
exp_getCity (QofExp * e)
707
639
{
708
 
        Expense_t *qe;
709
 
 
710
640
        g_return_val_if_fail (e != NULL, NULL);
711
 
        qe = &e->wrap;
712
 
        return qe->city;
 
641
        return e->city;
713
642
}
714
643
 
715
644
static const gchar *
716
645
exp_getAttendees (QofExp * e)
717
646
{
718
 
        Expense_t *qe;
719
 
 
720
647
        g_return_val_if_fail (e != NULL, NULL);
721
 
        qe = &e->wrap;
722
 
        return qe->attendees;
 
648
        return e->attendees;
723
649
}
724
650
 
725
651
static const gchar *
726
652
exp_getNote (QofExp * e)
727
653
{
728
 
        Expense_t *qe;
729
 
 
730
654
        g_return_val_if_fail (e != NULL, NULL);
731
 
        qe = &e->wrap;
732
 
        return qe->note;
 
655
        return e->note;
733
656
}
734
657
 
735
658
static const gchar*
749
672
static void
750
673
exp_setTime (QofExp * e, QofTime *h)
751
674
{
752
 
        Expense_t *qe;
753
675
        glong nanosecs;
754
676
        QofDate *qd;
755
677
 
756
678
        g_return_if_fail (e != NULL);
757
 
        qe = &e->wrap;
758
679
        if (!h)
759
680
                return;
760
681
        nanosecs = qof_time_get_nanosecs (h);
761
682
        qd = qof_date_from_qtime (h);
762
 
        qof_date_to_struct_tm (qd, &qe->date, 
763
 
                &nanosecs);
 
683
        qof_date_to_struct_tm (qd, &e->date, &nanosecs);
764
684
        qof_date_free (qd);
765
685
}
766
686
 
767
687
static void
768
688
exp_setType (QofExp * e, const gchar *type_string)
769
689
{
770
 
        Expense_t *qe;
771
 
 
772
690
        g_return_if_fail (e != NULL);
773
 
        qe = &e->wrap;
774
 
        qe->type = qof_exp_typeFromString(type_string);
 
691
        e->type = qof_exp_typeFromString(type_string);
775
692
}
776
693
 
777
694
static void
778
695
exp_setPayment (QofExp * e, const gchar *payment_string)
779
696
{
780
 
        Expense_t *qe;
781
 
 
782
697
        g_return_if_fail (e != NULL);
783
 
        qe = &e->wrap;
784
 
        qe->payment = qof_exp_paymentFromString(payment_string);
 
698
        e->payment = qof_exp_paymentFromString(payment_string);
785
699
}
786
700
 
787
701
static void
788
702
exp_combine_currency_with_amount(QofExp *e)
789
703
{
790
 
        Expense_t *qe;
791
 
 
792
704
        g_return_if_fail (e != NULL);
793
 
        qe = &e->wrap;
794
 
        if(!e->currency || qe->currency < 0)
 
705
        if(!e->currency || e->currency_code < 0)
795
706
        {
796
707
                /* the gint32 currency is actually to be set BEFORE the numeric amount. :-( */
797
 
                e->currency = gpe_currency_lookup((QofInstance*)e, qe->currency);
 
708
                e->currency = qof_currency_lookup((QofInstance*)e, e->currency_code);
798
709
        }
799
710
        if(!e->currency)
800
711
        {
802
713
                        " Using two decimal places.");
803
714
                /* Amount is stored in the Palm as a string version
804
715
                of a floating point number. */
805
 
                qe->amount = g_strdup_printf ("%.2f", e->temp_amount);
 
716
                e->amount = g_strdup_printf ("%.2f", e->temp_amount);
806
717
                return;
807
718
        }
808
719
        switch (e->currency->fraction)
809
720
        {
810
721
                case 1 : 
811
722
                {
812
 
                        qe->amount = g_strdup_printf ("%.0f", e->temp_amount);
 
723
                        e->amount = g_strdup_printf ("%.0f", e->temp_amount);
813
724
                        break;
814
725
                }
815
726
                case 10 : 
816
727
                {
817
 
                        qe->amount = g_strdup_printf ("%.1f", e->temp_amount);
 
728
                        e->amount = g_strdup_printf ("%.1f", e->temp_amount);
818
729
                        break;
819
730
                }
820
731
                case 100 : 
821
732
                {
822
 
                        qe->amount = g_strdup_printf ("%.2f", e->temp_amount);
 
733
                        e->amount = g_strdup_printf ("%.2f", e->temp_amount);
823
734
                        break;
824
735
                }
825
736
                case 1000 : 
826
737
                {
827
 
                        qe->amount = g_strdup_printf ("%.3f", e->temp_amount);
 
738
                        e->amount = g_strdup_printf ("%.3f", e->temp_amount);
828
739
                        break;
829
740
                }
830
741
                default :
831
742
                {
832
743
                        PERR (" Invalid currency fraction."
833
744
                                " Using two decimal places as default.");
834
 
                        qe->amount = g_strdup_printf ("%.2f", e->temp_amount);
 
745
                        e->amount = g_strdup_printf ("%.2f", e->temp_amount);
835
746
                }
836
747
        }
837
748
}
839
750
static void
840
751
exp_setCurrency (QofExp * e, gint data)
841
752
{
842
 
        Expense_t *qe;
843
 
 
844
753
        g_return_if_fail (e != NULL);
845
 
        qe = &e->wrap;
846
 
        qe->currency = data;
847
 
        e->currency = gpe_currency_lookup((QofInstance*)e, data);
 
754
        e->currency_code = data;
 
755
        e->currency = qof_currency_lookup((QofInstance*)e, data);
848
756
        if(e->reset_amount)
849
 
        {
850
757
                exp_combine_currency_with_amount(e);
851
 
        }
852
758
        e->reset_amount = FALSE;
853
759
}
854
760
 
855
761
static void
856
762
exp_setAmount (QofExp * e, QofNumeric h)
857
763
{
858
 
        Expense_t *qe;
859
 
 
860
764
        g_return_if_fail (e != NULL);
861
 
        qe = &e->wrap;
862
765
        e->temp_amount = qof_numeric_to_double (h);
863
766
        e->reset_amount = TRUE;
864
767
        /* if an amount can ever be set without a currency_code,
871
774
static void
872
775
exp_setVendor (QofExp * e, gchar *h)
873
776
{
874
 
        Expense_t *qe;
875
 
 
876
777
        g_return_if_fail (e != NULL);
877
 
        qe = &e->wrap;
878
 
        qe->vendor = g_strdup (qof_main_make_utf8(h));
 
778
        e->vendor = g_strdup (qof_util_make_utf8(h));
879
779
}
880
780
 
881
781
static void
882
782
exp_setCity (QofExp * e, gchar *h)
883
783
{
884
 
        Expense_t *qe;
885
 
 
886
784
        g_return_if_fail (e != NULL);
887
 
        qe = &e->wrap;
888
 
        qe->city = g_strdup (qof_main_make_utf8(h));
 
785
        e->city = g_strdup (qof_util_make_utf8(h));
889
786
}
890
787
 
891
788
static void
892
789
exp_setAttendees (QofExp * e, gchar *h)
893
790
{
894
 
        Expense_t *qe;
895
 
 
896
791
        g_return_if_fail (e != NULL);
897
 
        qe = &e->wrap;
898
 
        qe->attendees = g_strdup (qof_main_make_utf8(h));
 
792
        e->attendees = g_strdup (qof_util_make_utf8(h));
899
793
}
900
794
 
901
795
static void
902
796
exp_setNote (QofExp * e, gchar *h)
903
797
{
904
 
        Expense_t *qe;
905
 
 
906
798
        g_return_if_fail (e != NULL);
907
 
        qe = &e->wrap;
908
 
        qe->note = g_strdup (qof_main_make_utf8(h));
 
799
        e->note = g_strdup (qof_util_make_utf8(h));
909
800
}
910
801
 
911
802
static void
912
803
exp_setDistance(QofExp *e, const gchar *distance_name)
913
804
{
914
 
 
915
805
        g_return_if_fail(e);
916
806
        e->distance_unit = ExpenseDistancefromString(distance_name);
917
807
}
920
810
exp_setCategory(QofExp *e, gchar *n)
921
811
{
922
812
        g_return_if_fail(e != NULL);
923
 
        e->category = g_strdup(qof_main_make_utf8(n));
 
813
        e->category = g_strdup(qof_util_make_utf8(n));
924
814
}
925
815
 
926
816
static const gchar*
927
817
expensePrintable (gpointer instance)
928
818
{
929
819
        QofExp *obj;
930
 
        
 
820
 
931
821
        obj = (QofExp*)instance;
932
822
        if(!obj) return NULL;
933
823
        if(exp_getType(obj))
934
 
        {
935
 
        return g_strconcat(exp_getType(obj), " ",
936
 
                exp_getVendor(obj), " ", exp_getCity(obj), NULL);
937
 
        }
 
824
                return g_strconcat(exp_getType(obj), " ", 
 
825
                        exp_getVendor(obj), " ", exp_getCity(obj), NULL);
938
826
        return NULL;
939
827
}
940
828
 
941
829
static QofObject expenses_object_def = {
942
 
      .interface_version = QOF_OBJECT_VERSION,
943
 
      .e_type =            GPE_QOF_EXPENSES,
944
 
      .type_label =        QOF_EXPENSES_DESC,
945
 
      .create =            ((gpointer)expense_create),
946
 
      .book_begin =        NULL,
947
 
      .book_end =          NULL,
948
 
      .is_dirty =          qof_collection_is_dirty,
949
 
      .mark_clean =        qof_collection_mark_clean,
950
 
      .foreach =           qof_collection_foreach,
951
 
          .printable =         expensePrintable,
952
 
      .version_cmp =       (gint (*)(gpointer, gpointer)) qof_instance_version_cmp,
 
830
        .interface_version = QOF_OBJECT_VERSION,
 
831
        .e_type =            GPE_QOF_EXPENSES,
 
832
        .type_label =        QOF_EXPENSES_DESC,
 
833
        .create =            ((gpointer)expense_create),
 
834
        .book_begin =        NULL,
 
835
        .book_end =          NULL,
 
836
        .is_dirty =          qof_collection_is_dirty,
 
837
        .mark_clean =        qof_collection_mark_clean,
 
838
        .foreach =           qof_collection_foreach,
 
839
        .printable =         expensePrintable,
 
840
        .version_cmp =       (gint (*)(gpointer, gpointer)) qof_instance_version_cmp,
953
841
};
954
842
 
955
843
gboolean
976
864
        bindtextdomain (LIBRARY_GETTEXT_PACKAGE, LOCALE_DIR);
977
865
 
978
866
        qof_class_register (GPE_QOF_EXPENSES, NULL, params);
979
 
        if(!gpe_currency_table) populate_currencies();
 
867
        if(!qof_currency_table) populate_currencies();
980
868
 
981
869
        return qof_object_register (&expenses_object_def);
982
870
}