Add functions to calculate the cash-flow numbers that will be generated by a Scheduled Transaction. Unfinished, though.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19470 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2010-08-24 20:23:27 +00:00
parent dfee800c87
commit e0e1fba675
4 changed files with 94 additions and 4 deletions

View File

@ -256,7 +256,7 @@ _get_vars_helper(Transaction *txn, void *var_hash_data)
}
Account*
gnc_sx_get_template_transaction_account(SchedXaction *sx)
gnc_sx_get_template_transaction_account(const SchedXaction *sx)
{
Account *template_root, *sx_template_acct;
char sx_guid_str[GUID_ENCODING_LENGTH+1];
@ -1449,3 +1449,55 @@ gnc_sx_summary_print(const GncSxSummary *summary)
g_message("num_auto_create_no_notify_instances: %d", summary->num_auto_create_no_notify_instances);
g_message("need dialog? %s", summary->need_dialog ? "true" : "false");
}
static void gnc_numeric_free(gpointer data)
{
gnc_numeric *p = (gnc_numeric*) data;
g_free(p);
}
GHashTable* gnc_g_hash_new_guid_numeric()
{
return g_hash_table_new_full (guid_hash_to_guint, guid_g_hash_table_equal,
NULL, gnc_numeric_free);
}
typedef struct {
GHashTable *hash;
GList **creation_errors;
} SxCashflowData;
static gboolean
create_cashflow_helper(Transaction *template_txn, void *user_data)
{
/* FIXME: Still unfinished here! */
return FALSE;
}
void gnc_sx_instantiate_cashflow(const SchedXaction* sx,
GHashTable* map, GList **creation_errors)
{
SxCashflowData create_cashflow_data;
Account* sx_template_account = gnc_sx_get_template_transaction_account(sx);
create_cashflow_data.hash = map;
create_cashflow_data.creation_errors = creation_errors;
xaccAccountForEachTransaction(sx_template_account,
create_cashflow_helper,
&create_cashflow_data);
}
void gnc_sx_all_instantiate_cashflow(GList *all_sxes,
const GDate *range_start, const GDate *range_end,
GHashTable* map, GList **creation_errors)
{
/* FIXME: Still unfinished here! */
}
// Local Variables:
// mode: c
// indent-tabs-mode: nil
// c-block-comment-prefix: "* "
// eval: (c-add-style "gnc" '("k&r" (c-basic-offset . 4) (c-offsets-alist (case-label . +))) t)
// End:

View File

@ -139,7 +139,7 @@ void gnc_sx_instance_model_remove_sx_instances(GncSxInstanceModel *model, SchedX
/** @return GList<GncSxVariable*>. Caller owns the list, but not the items. **/
GList *gnc_sx_instance_get_variables(GncSxInstance *inst);
Account* gnc_sx_get_template_transaction_account(SchedXaction *sx);
Account* gnc_sx_get_template_transaction_account(const SchedXaction *sx);
/**
* @return caller-owned data struct.
@ -221,6 +221,39 @@ void gnc_sx_get_variables(SchedXaction *sx, GHashTable *var_hash);
int gnc_sx_parse_vars_from_formula(const char *formula, GHashTable *var_hash, gnc_numeric *result);
void gnc_sx_randomize_variables(GHashTable *vars);
/** Returns a GHashTable<GUID*, gnc_numeric*> with no destructor for
* the key, but a destructor for the value set.
*
* The returned value must be free'd with g_hash_table_destroy or
* g_hash_table_unref. */
GHashTable* gnc_g_hash_new_guid_numeric(void);
/** Calculates the cash flow of one single instance of the given SX
* into the GHashTable<GUID*, gnc_numeric*> such that the cash flow on
* each account is added to the given hash under the GUID of that
* account.
*
* Exactly one instance of the SX is calculated, regardless of its
* start date, recurrence, or end date.
*
* The creation_errors list, if non-NULL, receive any errors that
* occurred during creation, similar as in
* gnc_sx_instance_model_effect_change(). */
void gnc_sx_instantiate_cashflow(const SchedXaction* sx,
GHashTable* map, GList **creation_errors);
/** Instantiates the cash flow of all given SXs (in the given
* GList<SchedXAction*>) into the GHashTable<GUID*, gnc_numeric*> for the
* given date range. Each SX is counted with multiplicity as it has
* occurrences in the given date range.
*
* The creation_errors list, if non-NULL, receive any errors that
* occurred during creation, similar as in
* gnc_sx_instance_model_effect_change(). */
void gnc_sx_all_instantiate_cashflow(GList *all_sxes,
const GDate *range_start, const GDate *range_end,
GHashTable* map, GList **creation_errors);
G_END_DECLS
#endif // _GNC_SX_INSTANCE_MODEL_H

View File

@ -712,7 +712,7 @@ guid_hash_to_guint (gconstpointer ptr)
}
}
static gint
gint
guid_g_hash_table_equal (gconstpointer guid_a, gconstpointer guid_b)
{
return guid_equal (guid_a, guid_b);

View File

@ -199,9 +199,14 @@ gboolean string_to_guid(const gchar * string, /*@ out @*/ GncGUID * guid);
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2);
gint guid_compare(const GncGUID *g1, const GncGUID *g2);
/** Given a GncGUID *, hash it to a guint */
/** Hash function for a GUID. Given a GncGUID *, hash it to a guint */
guint guid_hash_to_guint(gconstpointer ptr);
/** Equality function for two GUIDs in a GHashTable. */
gint guid_g_hash_table_equal (gconstpointer guid_a, gconstpointer guid_b);
/** Returns a GHashTable with <GUID*> as key and a <gpointer> as
* value and no destructor functions for key or value set. */
GHashTable *guid_hash_table_new(void);
/* @} */