GnuCash c935c2f+
Loading...
Searching...
No Matches
Macros | Typedefs | Enumerations | Functions

a simple price database for gnucash More...

#include <stdio.h>
#include "qof.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"

Go to the source code of this file.

Macros

#define GNC_TYPE_PRICE   (gnc_price_get_type ())
 
#define GNC_PRICE(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_PRICE, GNCPrice))
 
#define GNC_PRICE_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_PRICE, GNCPriceClass))
 
#define GNC_IS_PRICE(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_PRICE))
 
#define GNC_IS_PRICE_CLASS(k)    (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_PRICE))
 
#define GNC_PRICE_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_PRICE, GNCPriceClass))
 
#define GNC_TYPE_PRICEDB   (gnc_pricedb_get_type ())
 
#define GNC_PRICEDB(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_PRICEDB, GNCPriceDB))
 
#define GNC_PRICEDB_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_PRICEDB, GNCPriceDBClass))
 
#define GNC_IS_PRICEDB(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_PRICEDB))
 
#define GNC_IS_PRICEDB_CLASS(k)    (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_PRICEDB))
 
#define GNC_PRICEDB_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_PRICEDB, GNCPriceDBClass))
 
#define PRICE_TYPE_LAST   "last"
 
#define PRICE_TYPE_UNK   "unknown"
 
#define PRICE_TYPE_TRN   "transaction"
 
Denominator Constants Price policy: In order to avoid rounding

problems, currency prices (often called exchange rates) are saved in terms of the smaller currency, so that price > 1, with a fixed denominator of 1/1000.

Commodity prices in currency are always expressed as value per unit of the commodity with a fixed denominator of the pricing currency's SCU * 10000.

#define CURRENCY_DENOM   10000
 
#define COMMODITY_DENOM_MULT   10000
 
Price Parameter Names

For use with QofQuery

#define PRICE_COMMODITY   "price-commodity"
 
#define PRICE_CURRENCY   "price-currency"
 
#define PRICE_DATE   "price-date"
 
#define PRICE_SOURCE   "price-source"
 
#define PRICE_TYPE   "price-type"
 
#define PRICE_VALUE   "price-value"
 

Typedefs

typedef GList PriceList
 
typedef gboolean(* GncPriceForeachFunc) (GNCPrice *p, gpointer user_data)
 

Enumerations

enum  PriceSource {
  PRICE_SOURCE_EDIT_DLG , PRICE_SOURCE_FQ , PRICE_SOURCE_USER_PRICE , PRICE_SOURCE_XFER_DLG_VAL ,
  PRICE_SOURCE_SPLIT_REG , PRICE_SOURCE_SPLIT_IMPORT , PRICE_SOURCE_STOCK_SPLIT , PRICE_SOURCE_STOCK_TRANSACTION ,
  PRICE_SOURCE_INVOICE , PRICE_SOURCE_TEMP , PRICE_SOURCE_INVALID
}
 Price source enum. More...
 
enum  PriceRemoveSourceFlags { PRICE_REMOVE_SOURCE_FQ = 1 , PRICE_REMOVE_SOURCE_USER = 2 , PRICE_REMOVE_SOURCE_APP = 4 , PRICE_REMOVE_SOURCE_COMM = 8 }
 
enum  PriceRemoveKeepOptions {
  PRICE_REMOVE_KEEP_NONE , PRICE_REMOVE_KEEP_LAST_WEEKLY , PRICE_REMOVE_KEEP_LAST_MONTHLY , PRICE_REMOVE_KEEP_LAST_QUARTERLY ,
  PRICE_REMOVE_KEEP_LAST_PERIOD , PRICE_REMOVE_KEEP_SCALED
}
 

Functions

GType gnc_price_get_type (void)
 
GType gnc_pricedb_get_type (void)
 
GNCPriceDB * gnc_pricedb_get_db (QofBook *book)
 Return the pricedb associated with the book.
 
GNCPriceDB * gnc_collection_get_pricedb (QofCollection *col)
 Return the pricedb via the Book's collection.
 
void gnc_pricedb_destroy (GNCPriceDB *db)
 Destroy the given pricedb and unref all of the prices it contains.
 
void gnc_pricedb_begin_edit (GNCPriceDB *)
 Begin an edit.
 
void gnc_pricedb_commit_edit (GNCPriceDB *)
 Commit an edit.
 
void gnc_pricedb_set_bulk_update (GNCPriceDB *db, gboolean bulk_update)
 Set flag to indicate whether duplication checks should be performed.
 
gboolean gnc_pricedb_add_price (GNCPriceDB *db, GNCPrice *p)
 Add a price to the pricedb.
 
gboolean gnc_pricedb_remove_price (GNCPriceDB *db, GNCPrice *p)
 Remove a price from the pricedb and unref the price.
 
gboolean gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list, GDate *fiscal_end_date, time64 cutoff, PriceRemoveSourceFlags source, PriceRemoveKeepOptions keep)
 Remove and unref prices older than a certain time.
 
GNCPrice * gnc_pricedb_lookup_latest (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
 Find the most recent price between the two commodities.
 
PriceList * gnc_pricedb_lookup_latest_any_currency (GNCPriceDB *db, const gnc_commodity *commodity)
 Find the most recent price between a commodity and all other commodities.
 
gboolean gnc_pricedb_has_prices (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
 Report whether the pricedb contains prices for one commodity in another.
 
PriceList * gnc_pricedb_get_prices (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
 Return all the prices for a given commodity in another.
 
GNCPrice * gnc_pricedb_lookup_day_t64 (GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency, time64 t)
 Return the price between the two commodities on the indicated day.
 
GNCPrice * gnc_pricedb_lookup_nearest_in_time64 (GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t)
 Return the price between the two commoditiesz nearest to the given time.
 
PriceList * gnc_pricedb_lookup_nearest_in_time_any_currency_t64 (GNCPriceDB *db, const gnc_commodity *c, time64 t)
 Return the price nearest in time to that given between the given commodity and every other.
 
GNCPrice * gnc_pricedb_lookup_nearest_before_t64 (GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t)
 Return the nearest price between the given commodities before the given time.
 
PriceList * gnc_pricedb_lookup_nearest_before_any_currency_t64 (GNCPriceDB *db, const gnc_commodity *c, time64 t)
 Return the nearest price between the given commodity and any other before the given time.
 
gnc_numeric gnc_pricedb_get_nearest_before_price (GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency, const time64 t)
 Retrieve the price one currency to another using the price nearest to before the given time.
 
gnc_numeric gnc_pricedb_get_nearest_price (GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency, const time64 t)
 Retrieve the price one currency to another using the price nearest to the given time.
 
gnc_numeric gnc_pricedb_get_latest_price (GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency)
 Retrieve the price one currency to another using the latest price.
 
gnc_numeric gnc_pricedb_convert_balance_latest_price (GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency)
 Convert a balance from one currency to another using the most recent price between the two.
 
gnc_numeric gnc_pricedb_convert_balance_nearest_price_t64 (GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t)
 Convert a balance from one currency to another using the price nearest to the given time.
 
gnc_numeric gnc_pricedb_convert_balance_nearest_before_price_t64 (GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t)
 Convert a balance from one currency to another using the price nearest to before the given time.
 
gboolean gnc_pricedb_foreach_price (GNCPriceDB *db, GncPriceForeachFunc f, gpointer user_data, gboolean stable_order)
 Call a GncPriceForeachFunction once for each price in db, until the function returns FALSE.
 
int gnc_pricedb_num_prices (GNCPriceDB *db, const gnc_commodity *c)
 Get the number of prices, in any currency, for a given commodity.
 
GNCPrice * gnc_pricedb_nth_price (GNCPriceDB *db, const gnc_commodity *c, const int n)
 Get the nth price for the given commodity in reverse date order.
 
void gnc_pricedb_nth_price_reset_cache (GNCPriceDB *db)
 
guint gnc_pricedb_get_num_prices (GNCPriceDB *db)
 Return the number of prices in the database.
 
gboolean gnc_pricedb_equal (GNCPriceDB *db1, GNCPriceDB *db2)
 Test equality of two pricedbs.
 
Constructors
GNCPrice * gnc_price_create (QofBook *book)
 gnc_price_create - returns a newly allocated and initialized price with a reference count of 1.
 
GNCPrice * gnc_price_clone (GNCPrice *p, QofBook *book)
 gnc_price_clone - returns a newly allocated price that's a content-wise duplicate of the given price, p.
 
GNCPrice * gnc_price_invert (GNCPrice *p)
 Return a newly-allocated price that's the inverse of the given price, p.
 
Memory Management
void gnc_price_ref (GNCPrice *p)
 gnc_price_ref - indicate your need for a given price to stick around (i.e.
 
void gnc_price_unref (GNCPrice *p)
 gnc_price_unref - indicate you're finished with a price (i.e.
 
Setters

All of the setters store copies of the data given, with the exception of the commodity field which just stores the pointer given.

It is assumed that commodities are a global resource and are pointer unique.

Invocations of the setters should be wrapped with calls to gnc_price_begin_edit() and commit_edit(). The begin/commit calls help ensure that the local price db is synchronized with the backend.

void gnc_price_begin_edit (GNCPrice *p)
 
void gnc_price_commit_edit (GNCPrice *p)
 
void gnc_price_set_commodity (GNCPrice *p, gnc_commodity *c)
 
void gnc_price_set_currency (GNCPrice *p, gnc_commodity *c)
 
void gnc_price_set_time64 (GNCPrice *p, time64 t)
 
void gnc_price_set_source (GNCPrice *p, PriceSource source)
 
void gnc_price_set_source_string (GNCPrice *p, const char *s)
 
void gnc_price_set_typestr (GNCPrice *p, const char *type)
 
void gnc_price_set_value (GNCPrice *p, gnc_numeric value)
 
Internal/Debugging
void gnc_price_print (GNCPrice *db, FILE *f, int indent)
 This simple function can be useful for debugging the price code.
 
void gnc_pricedb_print_contents (GNCPriceDB *db, FILE *f)
 This simple function can be useful for debugging the pricedb code.
 
GNCPrice lists

The database communicates multiple prices in and out via gnc price lists.

These are just time sorted GLists of GNCPrice pointers. Functions for manipulating these lists are provided. These functions are helpful in that they handle maintaining proper reference counts on behalf of the price list for every price being held in a given list. I.e. insert "refs" the prices being inserted, remove and destroy "unref" the prices that will no longer be referred to by the list.

gboolean gnc_price_list_insert (PriceList **prices, GNCPrice *p, gboolean check_dupl)
 gnc_price_list_insert - insert a price into the given list, calling gnc_price_ref on it during the process.
 
gboolean gnc_price_list_remove (PriceList **prices, GNCPrice *p)
 gnc_price_list_remove - remove the price, p, from the given list, calling gnc_price_unref on it during the process.
 
void gnc_price_list_destroy (PriceList *prices)
 gnc_price_list_destroy - destroy the given price list, calling gnc_price_unref on all the prices included in the list.
 
gboolean gnc_price_list_equal (PriceList *prices1, PriceList *prices2)
 

Getters

All of the getters return data that's internal to the GNCPrice, not copies, so don't free these values.

#define gnc_price_get_guid(X)   qof_entity_get_guid(QOF_INSTANCE(X))
 
#define gnc_price_return_guid(X)   (*(qof_entity_get_guid(QOF_INSTANCE(X))))
 
#define gnc_price_get_book(X)   qof_instance_get_book(QOF_INSTANCE(X))
 
GNCPrice * gnc_price_lookup (const GncGUID *guid, QofBook *book)
 
gnc_commodity * gnc_price_get_commodity (const GNCPrice *p)
 
gnc_commodity * gnc_price_get_currency (const GNCPrice *p)
 
time64 gnc_price_get_time64 (const GNCPrice *p)
 
PriceSource gnc_price_get_source (const GNCPrice *p)
 
const char * gnc_price_get_source_string (const GNCPrice *p)
 
const char * gnc_price_get_typestr (const GNCPrice *p)
 
gnc_numeric gnc_price_get_value (const GNCPrice *p)
 
gboolean gnc_price_equal (const GNCPrice *p1, const GNCPrice *p2)
 

Detailed Description

a simple price database for gnucash

Author
Copyright (C) 2001 Rob Browning
Copyright (C) 2001,2003 Linas Vepstas linas.nosp@m.@lin.nosp@m.as.or.nosp@m.g

Definition in file gnc-pricedb.h.

Macro Definition Documentation

◆ GNC_IS_PRICE

#define GNC_IS_PRICE (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_PRICE))

Definition at line 44 of file gnc-pricedb.h.

170{
171 PRICE_SOURCE_EDIT_DLG, // "user:price-editor"
172 PRICE_SOURCE_FQ, // "Finance::Quote"
173 PRICE_SOURCE_USER_PRICE, // "user:price"
174 PRICE_SOURCE_XFER_DLG_VAL, // "user:xfer-dialog"
175 PRICE_SOURCE_SPLIT_REG, // "user:split-register"
176 PRICE_SOURCE_SPLIT_IMPORT, // "user:split-import"
177 PRICE_SOURCE_STOCK_SPLIT, // "user:stock-split"
178 PRICE_SOURCE_STOCK_TRANSACTION,// "user:stock-transaction"
179 PRICE_SOURCE_INVOICE, // "user:invoice-post"
180 PRICE_SOURCE_TEMP, // "temporary"
181 PRICE_SOURCE_INVALID, // "invalid"
183
184#define PRICE_TYPE_LAST "last"
185#define PRICE_TYPE_UNK "unknown"
186#define PRICE_TYPE_TRN "transaction"
187/* ------------------ */
193/*@ dependent @*/
194GNCPrice *gnc_price_create(QofBook *book);
195
199GNCPrice *gnc_price_clone(GNCPrice* p, QofBook *book);
200
209GNCPrice *gnc_price_invert(GNCPrice *p);
210
213/* ------------------ */
219void gnc_price_ref(GNCPrice *p);
220
223void gnc_price_unref(GNCPrice *p);
226/* ------------------ */
238void gnc_price_begin_edit (GNCPrice *p);
239void gnc_price_commit_edit (GNCPrice *p);
240
241void gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c);
242void gnc_price_set_currency(GNCPrice *p, gnc_commodity *c);
243void gnc_price_set_time64(GNCPrice *p, time64 t);
244void gnc_price_set_source(GNCPrice *p, PriceSource source);
245void gnc_price_set_source_string(GNCPrice *p, const char* s);
246void gnc_price_set_typestr(GNCPrice *p, const char* type);
247void gnc_price_set_value(GNCPrice *p, gnc_numeric value);
250/* ------------------ */
256 GNCPrice * gnc_price_lookup (const GncGUID *guid, QofBook *book);
257/*@ dependent @*/
258gnc_commodity * gnc_price_get_commodity(const GNCPrice *p);
259/*@ dependent @*/
260gnc_commodity * gnc_price_get_currency(const GNCPrice *p);
261time64 gnc_price_get_time64(const GNCPrice *p);
262PriceSource gnc_price_get_source(const GNCPrice *p);
263const char * gnc_price_get_source_string(const GNCPrice *p);
264const char * gnc_price_get_typestr(const GNCPrice *p);
265gnc_numeric gnc_price_get_value(const GNCPrice *p);
266gboolean gnc_price_equal(const GNCPrice *p1, const GNCPrice *p2);
267
268#define gnc_price_get_guid(X) qof_entity_get_guid(QOF_INSTANCE(X))
269#define gnc_price_return_guid(X) (*(qof_entity_get_guid(QOF_INSTANCE(X))))
270#define gnc_price_get_book(X) qof_instance_get_book(QOF_INSTANCE(X))
276void gnc_price_print(GNCPrice *db, FILE *f, int indent);
285#define CURRENCY_DENOM 10000
286#define COMMODITY_DENOM_MULT 10000
287
288/* ================================================================ */
303gboolean gnc_price_list_insert(PriceList **prices, GNCPrice *p,
304 gboolean check_dupl);
305
308gboolean gnc_price_list_remove(PriceList **prices, GNCPrice *p);
309
312void gnc_price_list_destroy(PriceList *prices);
313
314gboolean gnc_price_list_equal(PriceList *prices1, PriceList *prices2);
318/* ================================================================ */
331typedef struct gnc_price_db_s GNCPriceDB;
332
337GNCPriceDB * gnc_pricedb_get_db(QofBook *book);
342GNCPriceDB * gnc_collection_get_pricedb(QofCollection *col);
343
350void gnc_pricedb_destroy(GNCPriceDB *db);
351
353void gnc_pricedb_begin_edit (GNCPriceDB *);
355void gnc_pricedb_commit_edit (GNCPriceDB *);
356
363void gnc_pricedb_set_bulk_update(GNCPriceDB *db, gboolean bulk_update);
364
373gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p);
374
379gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p);
380
381typedef enum
382{
383 PRICE_REMOVE_SOURCE_FQ = 1, // this flag is set when added by F:Q checked
384 PRICE_REMOVE_SOURCE_USER = 2, // this flag is set when added by the user checked
385 PRICE_REMOVE_SOURCE_APP = 4, // this flag is set when added by the app checked
386 PRICE_REMOVE_SOURCE_COMM = 8, // this flag is set when we have commodities selected
387} PriceRemoveSourceFlags;
388
389typedef enum
390{
391 PRICE_REMOVE_KEEP_NONE, // keep none
392 PRICE_REMOVE_KEEP_LAST_WEEKLY, // leave last one of every week
393 PRICE_REMOVE_KEEP_LAST_MONTHLY, // leave last one of every month
394 PRICE_REMOVE_KEEP_LAST_QUARTERLY, // leave last one of every quarter
395 PRICE_REMOVE_KEEP_LAST_PERIOD, // leave last one of every annual period
396 PRICE_REMOVE_KEEP_SCALED, // leave one every week then one a month
397} PriceRemoveKeepOptions;
398
408gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, GList *comm_list,
409 GDate *fiscal_end_date, time64 cutoff,
410 PriceRemoveSourceFlags source,
411 PriceRemoveKeepOptions keep);
412
422GNCPrice * gnc_pricedb_lookup_latest(GNCPriceDB *db,
423 const gnc_commodity *commodity,
424 const gnc_commodity *currency);
425
435PriceList * gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db,
436 const gnc_commodity *commodity);
437
448gboolean gnc_pricedb_has_prices(GNCPriceDB *db,
449 const gnc_commodity *commodity,
450 const gnc_commodity *currency);
451
462PriceList * gnc_pricedb_get_prices(GNCPriceDB *db,
463 const gnc_commodity *commodity,
464 const gnc_commodity *currency);
465
478GNCPrice * gnc_pricedb_lookup_day_t64(GNCPriceDB *db,
479 const gnc_commodity *commodity,
480 const gnc_commodity *currency,
481 time64 t);
482
494GNCPrice * gnc_pricedb_lookup_nearest_in_time64(GNCPriceDB *db,
495 const gnc_commodity *c,
496 const gnc_commodity *currency,
497 time64 t);
498
512 const gnc_commodity *c,
513 time64 t);
514
526GNCPrice * gnc_pricedb_lookup_nearest_before_t64 (GNCPriceDB *db,
527 const gnc_commodity *c,
528 const gnc_commodity *currency,
529 time64 t);
530
542 const gnc_commodity *c,
543 time64 t);
544
554gnc_numeric gnc_pricedb_get_nearest_before_price (GNCPriceDB *pdb,
555 const gnc_commodity *orig_currency,
556 const gnc_commodity *new_currency,
557 const time64 t);
558
568gnc_numeric gnc_pricedb_get_nearest_price (GNCPriceDB *pdb,
569 const gnc_commodity *orig_currency,
570 const gnc_commodity *new_currency,
571 const time64 t);
572
580gnc_numeric gnc_pricedb_get_latest_price (GNCPriceDB *pdb,
581 const gnc_commodity *orig_currency,
582 const gnc_commodity *new_currency);
583
584
594gnc_numeric
596 gnc_numeric balance,
597 const gnc_commodity *balance_currency,
598 const gnc_commodity *new_currency);
599
610gnc_numeric
612 gnc_numeric balance,
613 const gnc_commodity *balance_currency,
614 const gnc_commodity *new_currency,
615 time64 t);
616
627gnc_numeric
629 gnc_numeric balance,
630 const gnc_commodity *balance_currency,
631 const gnc_commodity *new_currency,
632 time64 t);
633
634typedef gboolean (*GncPriceForeachFunc)(GNCPrice *p, gpointer user_data);
635
650gboolean gnc_pricedb_foreach_price(GNCPriceDB *db,
651 GncPriceForeachFunc f,
652 gpointer user_data,
653 gboolean stable_order);
654
660int
661gnc_pricedb_num_prices(GNCPriceDB *db,
662 const gnc_commodity *c);
663
671GNCPrice *
672gnc_pricedb_nth_price (GNCPriceDB *db,
673 const gnc_commodity *c,
674 const int n);
675
676void gnc_pricedb_nth_price_reset_cache (GNCPriceDB *db);
677
678/* The following two convenience functions are used to test the xml backend */
683guint gnc_pricedb_get_num_prices(GNCPriceDB *db);
684
688gboolean gnc_pricedb_equal (GNCPriceDB *db1, GNCPriceDB *db2);
689
693void gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f);
700#define PRICE_COMMODITY "price-commodity"
701#define PRICE_CURRENCY "price-currency"
702#define PRICE_DATE "price-date"
703#define PRICE_SOURCE "price-source"
704#define PRICE_TYPE "price-type"
705#define PRICE_VALUE "price-value"
710#ifdef __cplusplus
711} /* extern "C" */
712#endif
713
714#endif /* GNC_PRICEDB_H */
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
GNCPrice * gnc_pricedb_lookup_nearest_before_t64(GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t)
Return the nearest price between the given commodities before the given time.
void gnc_pricedb_set_bulk_update(GNCPriceDB *db, gboolean bulk_update)
Set flag to indicate whether duplication checks should be performed.
PriceList * gnc_pricedb_lookup_latest_any_currency(GNCPriceDB *db, const gnc_commodity *commodity)
Find the most recent price between a commodity and all other commodities.
gboolean gnc_pricedb_has_prices(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
Report whether the pricedb contains prices for one commodity in another.
gnc_numeric gnc_pricedb_convert_balance_nearest_before_price_t64(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t)
Convert a balance from one currency to another using the price nearest to before the given time.
GNCPrice * gnc_pricedb_nth_price(GNCPriceDB *db, const gnc_commodity *c, const int n)
Get the nth price for the given commodity in reverse date order.
gboolean gnc_pricedb_foreach_price(GNCPriceDB *db, GncPriceForeachFunc f, gpointer user_data, gboolean stable_order)
Call a GncPriceForeachFunction once for each price in db, until the function returns FALSE.
gnc_numeric gnc_pricedb_get_nearest_before_price(GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency, const time64 t)
Retrieve the price one currency to another using the price nearest to before the given time.
void gnc_pricedb_commit_edit(GNCPriceDB *)
Commit an edit.
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
Remove a price from the pricedb and unref the price.
gnc_numeric gnc_pricedb_get_nearest_price(GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency, const time64 t)
Retrieve the price one currency to another using the price nearest to the given time.
gnc_numeric gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency)
Convert a balance from one currency to another using the most recent price between the two.
PriceList * gnc_pricedb_lookup_nearest_before_any_currency_t64(GNCPriceDB *db, const gnc_commodity *c, time64 t)
Return the nearest price between the given commodity and any other before the given time.
gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, GList *comm_list, GDate *fiscal_end_date, time64 cutoff, PriceRemoveSourceFlags source, PriceRemoveKeepOptions keep)
Remove and unref prices older than a certain time.
GNCPriceDB * gnc_collection_get_pricedb(QofCollection *col)
Return the pricedb via the Book's collection.
gnc_numeric gnc_pricedb_convert_balance_nearest_price_t64(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t)
Convert a balance from one currency to another using the price nearest to the given time.
guint gnc_pricedb_get_num_prices(GNCPriceDB *db)
Return the number of prices in the database.
PriceList * gnc_pricedb_lookup_nearest_in_time_any_currency_t64(GNCPriceDB *db, const gnc_commodity *c, time64 t)
Return the price nearest in time to that given between the given commodity and every other.
GNCPrice * gnc_pricedb_lookup_nearest_in_time64(GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t)
Return the price between the two commoditiesz nearest to the given time.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.
void gnc_pricedb_begin_edit(GNCPriceDB *)
Begin an edit.
int gnc_pricedb_num_prices(GNCPriceDB *db, const gnc_commodity *c)
Get the number of prices, in any currency, for a given commodity.
PriceList * gnc_pricedb_get_prices(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
Return all the prices for a given commodity in another.
GNCPrice * gnc_pricedb_lookup_latest(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
Find the most recent price between the two commodities.
void gnc_pricedb_destroy(GNCPriceDB *db)
Destroy the given pricedb and unref all of the prices it contains.
gboolean gnc_pricedb_equal(GNCPriceDB *db1, GNCPriceDB *db2)
Test equality of two pricedbs.
GNCPrice * gnc_pricedb_lookup_day_t64(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency, time64 t)
Return the price between the two commodities on the indicated day.
gnc_numeric gnc_pricedb_get_latest_price(GNCPriceDB *pdb, const gnc_commodity *orig_currency, const gnc_commodity *new_currency)
Retrieve the price one currency to another using the latest price.
gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p)
Add a price to the pricedb.
void gnc_price_print(GNCPrice *db, FILE *f, int indent)
This simple function can be useful for debugging the price code.
void gnc_price_list_destroy(PriceList *prices)
gnc_price_list_destroy - destroy the given price list, calling gnc_price_unref on all the prices incl...
void gnc_price_ref(GNCPrice *p)
gnc_price_ref - indicate your need for a given price to stick around (i.e.
GNCPrice * gnc_price_invert(GNCPrice *p)
Return a newly-allocated price that's the inverse of the given price, p.
gboolean gnc_price_list_insert(PriceList **prices, GNCPrice *p, gboolean check_dupl)
gnc_price_list_insert - insert a price into the given list, calling gnc_price_ref on it during the pr...
GNCPrice * gnc_price_clone(GNCPrice *p, QofBook *book)
gnc_price_clone - returns a newly allocated price that's a content-wise duplicate of the given price,...
PriceSource
Price source enum.
void gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f)
This simple function can be useful for debugging the pricedb code.
gboolean gnc_price_list_remove(PriceList **prices, GNCPrice *p)
gnc_price_list_remove - remove the price, p, from the given list, calling gnc_price_unref on it durin...
GNCPrice * gnc_price_create(QofBook *book)
gnc_price_create - returns a newly allocated and initialized price with a reference count of 1.
void gnc_price_unref(GNCPrice *p)
gnc_price_unref - indicate you're finished with a price (i.e.
The type used to store guids in C.
Definition guid.h:75
QofBook reference.
Definition qofbook-p.hpp:47

◆ GNC_IS_PRICE_CLASS

#define GNC_IS_PRICE_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_PRICE))

Definition at line 46 of file gnc-pricedb.h.

◆ GNC_IS_PRICEDB

#define GNC_IS_PRICEDB (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_PRICEDB))

Definition at line 58 of file gnc-pricedb.h.

◆ GNC_IS_PRICEDB_CLASS

#define GNC_IS_PRICEDB_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_PRICEDB))

Definition at line 60 of file gnc-pricedb.h.

◆ GNC_PRICE

#define GNC_PRICE (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_PRICE, GNCPrice))

Definition at line 40 of file gnc-pricedb.h.

◆ GNC_PRICE_CLASS

#define GNC_PRICE_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_PRICE, GNCPriceClass))

Definition at line 42 of file gnc-pricedb.h.

◆ GNC_PRICE_GET_CLASS

#define GNC_PRICE_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_PRICE, GNCPriceClass))

Definition at line 48 of file gnc-pricedb.h.

◆ GNC_PRICEDB

#define GNC_PRICEDB (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_PRICEDB, GNCPriceDB))

Definition at line 54 of file gnc-pricedb.h.

◆ GNC_PRICEDB_CLASS

#define GNC_PRICEDB_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_PRICEDB, GNCPriceDBClass))

Definition at line 56 of file gnc-pricedb.h.

◆ GNC_PRICEDB_GET_CLASS

#define GNC_PRICEDB_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_PRICEDB, GNCPriceDBClass))

Definition at line 62 of file gnc-pricedb.h.

◆ GNC_TYPE_PRICE

#define GNC_TYPE_PRICE   (gnc_price_get_type ())

Definition at line 39 of file gnc-pricedb.h.

◆ GNC_TYPE_PRICEDB

#define GNC_TYPE_PRICEDB   (gnc_pricedb_get_type ())

Definition at line 53 of file gnc-pricedb.h.