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

Christian Stimming cstim at code.gnucash.org
Tue Aug 24 16:23:27 EDT 2010


Author: cstim
Date: 2010-08-24 16:23:27 -0400 (Tue, 24 Aug 2010)
New Revision: 19470
Trac: http://svn.gnucash.org/trac/changeset/19470

Modified:
   gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
   gnucash/trunk/src/app-utils/gnc-sx-instance-model.h
   gnucash/trunk/src/libqof/qof/guid.c
   gnucash/trunk/src/libqof/qof/guid.h
Log:
Add functions to calculate the cash-flow numbers that will be generated by a Scheduled Transaction. Unfinished, though.

Modified: gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-sx-instance-model.c	2010-08-24 20:23:12 UTC (rev 19469)
+++ gnucash/trunk/src/app-utils/gnc-sx-instance-model.c	2010-08-24 20:23:27 UTC (rev 19470)
@@ -256,7 +256,7 @@
 }
 
 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 @@
     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:

Modified: gnucash/trunk/src/app-utils/gnc-sx-instance-model.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-sx-instance-model.h	2010-08-24 20:23:12 UTC (rev 19469)
+++ gnucash/trunk/src/app-utils/gnc-sx-instance-model.h	2010-08-24 20:23:27 UTC (rev 19470)
@@ -139,7 +139,7 @@
 /** @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 @@
 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

Modified: gnucash/trunk/src/libqof/qof/guid.c
===================================================================
--- gnucash/trunk/src/libqof/qof/guid.c	2010-08-24 20:23:12 UTC (rev 19469)
+++ gnucash/trunk/src/libqof/qof/guid.c	2010-08-24 20:23:27 UTC (rev 19470)
@@ -712,7 +712,7 @@
     }
 }
 
-static gint
+gint
 guid_g_hash_table_equal (gconstpointer guid_a, gconstpointer guid_b)
 {
     return guid_equal (guid_a, guid_b);

Modified: gnucash/trunk/src/libqof/qof/guid.h
===================================================================
--- gnucash/trunk/src/libqof/qof/guid.h	2010-08-24 20:23:12 UTC (rev 19469)
+++ gnucash/trunk/src/libqof/qof/guid.h	2010-08-24 20:23:27 UTC (rev 19470)
@@ -199,9 +199,14 @@
 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);
 
 /* @} */



More information about the gnucash-changes mailing list