r18788 - gnucash/trunk/src/engine - Re-indentation of source code, next batch: src/engine/*
Christian Stimming
cstim at code.gnucash.org
Tue Mar 2 16:40:30 EST 2010
Author: cstim
Date: 2010-03-02 16:40:28 -0500 (Tue, 02 Mar 2010)
New Revision: 18788
Trac: http://svn.gnucash.org/trac/changeset/18788
Modified:
gnucash/trunk/src/engine/Account.c
gnucash/trunk/src/engine/Account.h
gnucash/trunk/src/engine/Period.c
gnucash/trunk/src/engine/Query.c
gnucash/trunk/src/engine/Recurrence.c
gnucash/trunk/src/engine/SX-book.c
gnucash/trunk/src/engine/SX-ttinfo.c
gnucash/trunk/src/engine/SchedXaction.c
gnucash/trunk/src/engine/Scrub.c
gnucash/trunk/src/engine/Scrub2.c
gnucash/trunk/src/engine/Scrub3.c
gnucash/trunk/src/engine/Split.c
gnucash/trunk/src/engine/Transaction.c
gnucash/trunk/src/engine/cap-gains.c
gnucash/trunk/src/engine/engine-helpers.c
gnucash/trunk/src/engine/glib-helpers.c
gnucash/trunk/src/engine/gnc-associate-account.c
gnucash/trunk/src/engine/gnc-budget.c
gnucash/trunk/src/engine/gnc-commodity.c
gnucash/trunk/src/engine/gnc-engine.c
gnucash/trunk/src/engine/gnc-filepath-utils.c
gnucash/trunk/src/engine/gnc-hooks.c
gnucash/trunk/src/engine/gnc-lot.c
gnucash/trunk/src/engine/gnc-lot.h
gnucash/trunk/src/engine/gnc-path.c
gnucash/trunk/src/engine/gnc-pricedb.c
gnucash/trunk/src/engine/gnc-session-scm.c
gnucash/trunk/src/engine/gnc-session.c
gnucash/trunk/src/engine/kvp-scm.c
gnucash/trunk/src/engine/policy.c
Log:
Re-indentation of source code, next batch: src/engine/*
This also strips trailing whitespaces from lines where they existed.
This re-indentation was done using astyle-1.24 using the following options:
astyle --indent=spaces=4 --brackets=break --pad-oper --pad-header --suffix=none
Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Account.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -47,61 +47,63 @@
static gchar account_separator[8] = ".";
gunichar account_uc_separator = ':';
-enum {
+enum
+{
LAST_SIGNAL
};
-enum {
- PROP_0,
- PROP_NAME,
- PROP_FULL_NAME,
- PROP_CODE,
- PROP_DESCRIPTION,
- PROP_COLOR,
- PROP_NOTES,
- PROP_TYPE,
+enum
+{
+ PROP_0,
+ PROP_NAME,
+ PROP_FULL_NAME,
+ PROP_CODE,
+ PROP_DESCRIPTION,
+ PROP_COLOR,
+ PROP_NOTES,
+ PROP_TYPE,
- PROP_COMMODITY,
- PROP_COMMODITY_SCU,
- PROP_NON_STD_SCU,
- PROP_SORT_DIRTY,
- PROP_BALANCE_DIRTY,
- PROP_START_BALANCE,
- PROP_START_CLEARED_BALANCE,
- PROP_START_RECONCILED_BALANCE,
- PROP_END_BALANCE,
- PROP_END_CLEARED_BALANCE,
- PROP_END_RECONCILED_BALANCE,
+ PROP_COMMODITY,
+ PROP_COMMODITY_SCU,
+ PROP_NON_STD_SCU,
+ PROP_SORT_DIRTY,
+ PROP_BALANCE_DIRTY,
+ PROP_START_BALANCE,
+ PROP_START_CLEARED_BALANCE,
+ PROP_START_RECONCILED_BALANCE,
+ PROP_END_BALANCE,
+ PROP_END_CLEARED_BALANCE,
+ PROP_END_RECONCILED_BALANCE,
- PROP_POLICY,
- PROP_MARK,
- PROP_TAX_RELATED,
- PROP_TAX_CODE,
- PROP_TAX_SOURCE,
- PROP_TAX_COPY_NUMBER,
+ PROP_POLICY,
+ PROP_MARK,
+ PROP_TAX_RELATED,
+ PROP_TAX_CODE,
+ PROP_TAX_SOURCE,
+ PROP_TAX_COPY_NUMBER,
- PROP_HIDDEN,
- PROP_PLACEHOLDER,
+ PROP_HIDDEN,
+ PROP_PLACEHOLDER,
};
typedef struct AccountPrivate
{
- /* The accountName is an arbitrary string assigned by the user.
+ /* The accountName is an arbitrary string assigned by the user.
* It is intended to a short, 5 to 30 character long string that
- * is displayed by the GUI as the account mnemonic.
+ * is displayed by the GUI as the account mnemonic.
*/
char *accountName;
/* The accountCode is an arbitrary string assigned by the user.
- * It is intended to be reporting code that is a synonym for the
- * accountName. Typically, it will be a numeric value that follows
- * the numbering assignments commonly used by accountants, such
+ * It is intended to be reporting code that is a synonym for the
+ * accountName. Typically, it will be a numeric value that follows
+ * the numbering assignments commonly used by accountants, such
* as 100, 200 or 600 for top-level accounts, and 101, 102.. etc.
* for detail accounts.
*/
char *accountCode;
- /* The description is an arbitrary string assigned by the user.
+ /* The description is an arbitrary string assigned by the user.
* It is intended to be a longer, 1-5 sentence description of what
* this account is all about.
*/
@@ -115,8 +117,8 @@
*/
GNCAccountType type;
- /*
- * The commodity field denotes the kind of 'stuff' stored
+ /*
+ * The commodity field denotes the kind of 'stuff' stored
* in this account. The 'amount' field of a split indicates
* how much of the 'stuff' there is.
*/
@@ -149,7 +151,7 @@
GNCPolicy *policy; /* Cached pointer to policy method */
/* The "mark" flag can be used by the user to mark this account
- * in any way desired. Handy for specialty traversals of the
+ * in any way desired. Handy for specialty traversals of the
* account tree. */
short mark;
} AccountPrivate;
@@ -177,31 +179,32 @@
const gchar *
gnc_get_account_separator_string (void)
{
- return account_separator;
+ return account_separator;
}
gunichar
gnc_get_account_separator (void)
{
- return account_uc_separator;
+ return account_uc_separator;
}
void
gnc_set_account_separator (const gchar *separator)
{
- gunichar uc;
- gint count;
+ gunichar uc;
+ gint count;
- uc = g_utf8_get_char_validated(separator, -1);
- if ((uc == (gunichar)-2) || (uc == (gunichar)-1) || g_unichar_isalnum(uc)) {
- account_uc_separator = ':';
- strcpy(account_separator, ":");
- return;
- }
+ uc = g_utf8_get_char_validated(separator, -1);
+ if ((uc == (gunichar) - 2) || (uc == (gunichar) - 1) || g_unichar_isalnum(uc))
+ {
+ account_uc_separator = ':';
+ strcpy(account_separator, ":");
+ return;
+ }
- account_uc_separator = uc;
- count = g_unichar_to_utf8(uc, account_separator);
- account_separator[count] = '\0';
+ account_uc_separator = uc;
+ count = g_unichar_to_utf8(uc, account_separator);
+ account_separator[count] = '\0';
}
/********************************************************************\
@@ -211,7 +214,7 @@
void
mark_account (Account *acc)
{
- qof_instance_set_dirty(&acc->inst);
+ qof_instance_set_dirty(&acc->inst);
}
/********************************************************************\
@@ -254,7 +257,7 @@
priv->splits = NULL;
priv->sort_dirty = FALSE;
- }
+}
static void
gnc_account_dispose (GObject *acctp)
@@ -270,9 +273,9 @@
static void
gnc_account_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
Account *account;
AccountPrivate *priv;
@@ -281,100 +284,101 @@
account = GNC_ACCOUNT(object);
priv = GET_PRIVATE(account);
- switch (prop_id) {
- case PROP_NAME:
- g_value_set_string(value, priv->accountName);
- break;
- case PROP_FULL_NAME:
- g_value_take_string(value, gnc_account_get_full_name(account));
- break;
- case PROP_CODE:
- g_value_set_string(value, priv->accountCode);
- break;
- case PROP_DESCRIPTION:
- g_value_set_string(value, priv->description);
- break;
- case PROP_COLOR:
- g_value_set_string(value, xaccAccountGetColor(account));
- break;
- case PROP_NOTES:
- g_value_set_string(value, xaccAccountGetNotes(account));
- break;
- case PROP_TYPE:
- // NEED TO BE CONVERTED TO A G_TYPE_ENUM
- g_value_set_int(value, priv->type);
- break;
- case PROP_COMMODITY:
- g_value_set_object(value, priv->commodity);
- break;
- case PROP_COMMODITY_SCU:
- g_value_set_int(value, priv->commodity_scu);
- break;
- case PROP_NON_STD_SCU:
- g_value_set_boolean(value, priv->non_standard_scu);
- break;
- case PROP_SORT_DIRTY:
- g_value_set_boolean(value, priv->sort_dirty);
- break;
- case PROP_BALANCE_DIRTY:
- g_value_set_boolean(value, priv->balance_dirty);
- break;
- case PROP_START_BALANCE:
- g_value_set_boxed(value, &priv->starting_balance);
- break;
- case PROP_START_CLEARED_BALANCE:
- g_value_set_boxed(value, &priv->starting_cleared_balance);
- break;
- case PROP_START_RECONCILED_BALANCE:
- g_value_set_boxed(value, &priv->starting_reconciled_balance);
- break;
- case PROP_END_BALANCE:
- g_value_set_boxed(value, &priv->balance);
- break;
- case PROP_END_CLEARED_BALANCE:
- g_value_set_boxed(value, &priv->cleared_balance);
- break;
- case PROP_END_RECONCILED_BALANCE:
- g_value_set_boxed(value, &priv->reconciled_balance);
- break;
- case PROP_POLICY:
- /* MAKE THIS A BOXED VALUE */
- g_value_set_pointer(value, priv->policy);
- break;
- case PROP_MARK:
- g_value_set_int(value, priv->mark);
- break;
- case PROP_TAX_RELATED:
- g_value_set_boolean(value, xaccAccountGetTaxRelated(account));
- break;
- case PROP_TAX_CODE:
- g_value_set_string(value, xaccAccountGetTaxUSCode(account));
- break;
- case PROP_TAX_SOURCE:
- g_value_set_string(value,
- xaccAccountGetTaxUSPayerNameSource(account));
- break;
- case PROP_TAX_COPY_NUMBER:
- g_value_set_int64(value,
- xaccAccountGetTaxUSCopyNumber(account));
- break;
- case PROP_HIDDEN:
- g_value_set_boolean(value, xaccAccountGetHidden(account));
- break;
- case PROP_PLACEHOLDER:
- g_value_set_boolean(value, xaccAccountGetPlaceholder(account));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ g_value_set_string(value, priv->accountName);
+ break;
+ case PROP_FULL_NAME:
+ g_value_take_string(value, gnc_account_get_full_name(account));
+ break;
+ case PROP_CODE:
+ g_value_set_string(value, priv->accountCode);
+ break;
+ case PROP_DESCRIPTION:
+ g_value_set_string(value, priv->description);
+ break;
+ case PROP_COLOR:
+ g_value_set_string(value, xaccAccountGetColor(account));
+ break;
+ case PROP_NOTES:
+ g_value_set_string(value, xaccAccountGetNotes(account));
+ break;
+ case PROP_TYPE:
+ // NEED TO BE CONVERTED TO A G_TYPE_ENUM
+ g_value_set_int(value, priv->type);
+ break;
+ case PROP_COMMODITY:
+ g_value_set_object(value, priv->commodity);
+ break;
+ case PROP_COMMODITY_SCU:
+ g_value_set_int(value, priv->commodity_scu);
+ break;
+ case PROP_NON_STD_SCU:
+ g_value_set_boolean(value, priv->non_standard_scu);
+ break;
+ case PROP_SORT_DIRTY:
+ g_value_set_boolean(value, priv->sort_dirty);
+ break;
+ case PROP_BALANCE_DIRTY:
+ g_value_set_boolean(value, priv->balance_dirty);
+ break;
+ case PROP_START_BALANCE:
+ g_value_set_boxed(value, &priv->starting_balance);
+ break;
+ case PROP_START_CLEARED_BALANCE:
+ g_value_set_boxed(value, &priv->starting_cleared_balance);
+ break;
+ case PROP_START_RECONCILED_BALANCE:
+ g_value_set_boxed(value, &priv->starting_reconciled_balance);
+ break;
+ case PROP_END_BALANCE:
+ g_value_set_boxed(value, &priv->balance);
+ break;
+ case PROP_END_CLEARED_BALANCE:
+ g_value_set_boxed(value, &priv->cleared_balance);
+ break;
+ case PROP_END_RECONCILED_BALANCE:
+ g_value_set_boxed(value, &priv->reconciled_balance);
+ break;
+ case PROP_POLICY:
+ /* MAKE THIS A BOXED VALUE */
+ g_value_set_pointer(value, priv->policy);
+ break;
+ case PROP_MARK:
+ g_value_set_int(value, priv->mark);
+ break;
+ case PROP_TAX_RELATED:
+ g_value_set_boolean(value, xaccAccountGetTaxRelated(account));
+ break;
+ case PROP_TAX_CODE:
+ g_value_set_string(value, xaccAccountGetTaxUSCode(account));
+ break;
+ case PROP_TAX_SOURCE:
+ g_value_set_string(value,
+ xaccAccountGetTaxUSPayerNameSource(account));
+ break;
+ case PROP_TAX_COPY_NUMBER:
+ g_value_set_int64(value,
+ xaccAccountGetTaxUSCopyNumber(account));
+ break;
+ case PROP_HIDDEN:
+ g_value_set_boolean(value, xaccAccountGetHidden(account));
+ break;
+ case PROP_PLACEHOLDER:
+ g_value_set_boolean(value, xaccAccountGetPlaceholder(account));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
static void
gnc_account_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
Account *account;
gnc_numeric *number;
@@ -383,89 +387,90 @@
account = GNC_ACCOUNT(object);
- switch (prop_id) {
- case PROP_NAME:
- xaccAccountSetName(account, g_value_get_string(value));
- break;
- case PROP_CODE:
- xaccAccountSetCode(account, g_value_get_string(value));
- break;
- case PROP_DESCRIPTION:
- xaccAccountSetDescription(account, g_value_get_string(value));
- break;
- case PROP_COLOR:
- xaccAccountSetColor(account, g_value_get_string(value));
- break;
- case PROP_NOTES:
- xaccAccountSetNotes(account, g_value_get_string(value));
- break;
- case PROP_TYPE:
- // NEED TO BE CONVERTED TO A G_TYPE_ENUM
- xaccAccountSetType(account, g_value_get_int(value));
- break;
- case PROP_COMMODITY:
- xaccAccountSetCommodity(account, g_value_get_object(value));
- break;
- case PROP_COMMODITY_SCU:
- xaccAccountSetCommoditySCU(account, g_value_get_int(value));
- break;
- case PROP_NON_STD_SCU:
- xaccAccountSetNonStdSCU(account, g_value_get_boolean(value));
- break;
- case PROP_SORT_DIRTY:
- gnc_account_set_sort_dirty(account);
- break;
- case PROP_BALANCE_DIRTY:
- gnc_account_set_balance_dirty(account);
- break;
- case PROP_START_BALANCE:
- number = g_value_get_boxed(value);
- gnc_account_set_start_balance(account, *number);
- break;
- case PROP_START_CLEARED_BALANCE:
- number = g_value_get_boxed(value);
- gnc_account_set_start_cleared_balance(account, *number);
- break;
- case PROP_START_RECONCILED_BALANCE:
- number = g_value_get_boxed(value);
- gnc_account_set_start_reconciled_balance(account, *number);
- break;
- case PROP_POLICY:
- gnc_account_set_policy(account, g_value_get_pointer(value));
- break;
- case PROP_MARK:
- xaccAccountSetMark(account, g_value_get_int(value));
- break;
- case PROP_TAX_RELATED:
- xaccAccountSetTaxRelated(account, g_value_get_boolean(value));
- break;
- case PROP_TAX_CODE:
- xaccAccountSetTaxUSCode(account, g_value_get_string(value));
- break;
- case PROP_TAX_SOURCE:
- xaccAccountSetTaxUSPayerNameSource(account,
- g_value_get_string(value));
- case PROP_TAX_COPY_NUMBER:
- xaccAccountSetTaxUSCopyNumber(account,
- g_value_get_int64(value));
- break;
- case PROP_HIDDEN:
- xaccAccountSetHidden(account, g_value_get_boolean(value));
- break;
- case PROP_PLACEHOLDER:
- xaccAccountSetPlaceholder(account, g_value_get_boolean(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ xaccAccountSetName(account, g_value_get_string(value));
+ break;
+ case PROP_CODE:
+ xaccAccountSetCode(account, g_value_get_string(value));
+ break;
+ case PROP_DESCRIPTION:
+ xaccAccountSetDescription(account, g_value_get_string(value));
+ break;
+ case PROP_COLOR:
+ xaccAccountSetColor(account, g_value_get_string(value));
+ break;
+ case PROP_NOTES:
+ xaccAccountSetNotes(account, g_value_get_string(value));
+ break;
+ case PROP_TYPE:
+ // NEED TO BE CONVERTED TO A G_TYPE_ENUM
+ xaccAccountSetType(account, g_value_get_int(value));
+ break;
+ case PROP_COMMODITY:
+ xaccAccountSetCommodity(account, g_value_get_object(value));
+ break;
+ case PROP_COMMODITY_SCU:
+ xaccAccountSetCommoditySCU(account, g_value_get_int(value));
+ break;
+ case PROP_NON_STD_SCU:
+ xaccAccountSetNonStdSCU(account, g_value_get_boolean(value));
+ break;
+ case PROP_SORT_DIRTY:
+ gnc_account_set_sort_dirty(account);
+ break;
+ case PROP_BALANCE_DIRTY:
+ gnc_account_set_balance_dirty(account);
+ break;
+ case PROP_START_BALANCE:
+ number = g_value_get_boxed(value);
+ gnc_account_set_start_balance(account, *number);
+ break;
+ case PROP_START_CLEARED_BALANCE:
+ number = g_value_get_boxed(value);
+ gnc_account_set_start_cleared_balance(account, *number);
+ break;
+ case PROP_START_RECONCILED_BALANCE:
+ number = g_value_get_boxed(value);
+ gnc_account_set_start_reconciled_balance(account, *number);
+ break;
+ case PROP_POLICY:
+ gnc_account_set_policy(account, g_value_get_pointer(value));
+ break;
+ case PROP_MARK:
+ xaccAccountSetMark(account, g_value_get_int(value));
+ break;
+ case PROP_TAX_RELATED:
+ xaccAccountSetTaxRelated(account, g_value_get_boolean(value));
+ break;
+ case PROP_TAX_CODE:
+ xaccAccountSetTaxUSCode(account, g_value_get_string(value));
+ break;
+ case PROP_TAX_SOURCE:
+ xaccAccountSetTaxUSPayerNameSource(account,
+ g_value_get_string(value));
+ case PROP_TAX_COPY_NUMBER:
+ xaccAccountSetTaxUSCopyNumber(account,
+ g_value_get_int64(value));
+ break;
+ case PROP_HIDDEN:
+ xaccAccountSetHidden(account, g_value_get_boolean(value));
+ break;
+ case PROP_PLACEHOLDER:
+ xaccAccountSetPlaceholder(account, g_value_get_boolean(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
}
static void
gnc_account_class_init (AccountClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
+
gobject_class->dispose = gnc_account_dispose;
gobject_class->finalize = gnc_account_finalize;
gobject_class->set_property = gnc_account_set_property;
@@ -474,333 +479,333 @@
g_type_class_add_private(klass, sizeof(AccountPrivate));
g_object_class_install_property
- (gobject_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Account Name",
- "The accountName is an arbitrary string "
- "assigned by the user. It is intended to "
- "a short, 5 to 30 character long string "
- "that is displayed by the GUI as the "
- "account mnemonic. Account names may be "
- "repeasted. but no two accounts that share "
- "a parent may have the same name.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Account Name",
+ "The accountName is an arbitrary string "
+ "assigned by the user. It is intended to "
+ "a short, 5 to 30 character long string "
+ "that is displayed by the GUI as the "
+ "account mnemonic. Account names may be "
+ "repeasted. but no two accounts that share "
+ "a parent may have the same name.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_FULL_NAME,
- g_param_spec_string ("fullname",
- "Full Account Name",
- "The name of the account concatenated with "
- "all its parent account names to indicate "
- "a unique account.",
- NULL,
- G_PARAM_READABLE));
+ (gobject_class,
+ PROP_FULL_NAME,
+ g_param_spec_string ("fullname",
+ "Full Account Name",
+ "The name of the account concatenated with "
+ "all its parent account names to indicate "
+ "a unique account.",
+ NULL,
+ G_PARAM_READABLE));
g_object_class_install_property
- (gobject_class,
- PROP_CODE,
- g_param_spec_string ("code",
- "Account Code",
- "The account code is an arbitrary string "
- "assigned by the user. It is intended to "
- "be reporting code that is a synonym for "
- "the accountName.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_CODE,
+ g_param_spec_string ("code",
+ "Account Code",
+ "The account code is an arbitrary string "
+ "assigned by the user. It is intended to "
+ "be reporting code that is a synonym for "
+ "the accountName.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_DESCRIPTION,
- g_param_spec_string ("description",
- "Account Description",
- "The account description is an arbitrary "
- "string assigned by the user. It is intended "
- "to be a longer, 1-5 sentence description of "
- "what this account is all about.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_DESCRIPTION,
+ g_param_spec_string ("description",
+ "Account Description",
+ "The account description is an arbitrary "
+ "string assigned by the user. It is intended "
+ "to be a longer, 1-5 sentence description of "
+ "what this account is all about.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_COLOR,
- g_param_spec_string ("color",
- "Account Color",
- "The account color is a color string assigned "
- "by the user. It is intended to highlight the "
- "account based on the users wishes.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_COLOR,
+ g_param_spec_string ("color",
+ "Account Color",
+ "The account color is a color string assigned "
+ "by the user. It is intended to highlight the "
+ "account based on the users wishes.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_NOTES,
- g_param_spec_string ("notes",
- "Account Notes",
- "The account notes is an arbitrary provided "
- "for the user to attach any orther text that "
- "they would like to associate with the account.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_NOTES,
+ g_param_spec_string ("notes",
+ "Account Notes",
+ "The account notes is an arbitrary provided "
+ "for the user to attach any orther text that "
+ "they would like to associate with the account.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_TYPE,
- g_param_spec_int ("type",
- "Account Type",
- "The account type, picked from the enumerated list "
- "that includes ACCT_TYPE_BANK, ACCT_TYPE_STOCK, "
- "ACCT_TYPE_CREDIT, ACCT_TYPE_INCOME, etc.",
- ACCT_TYPE_NONE,
- NUM_ACCOUNT_TYPES - 1,
- ACCT_TYPE_BANK,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_TYPE,
+ g_param_spec_int ("type",
+ "Account Type",
+ "The account type, picked from the enumerated list "
+ "that includes ACCT_TYPE_BANK, ACCT_TYPE_STOCK, "
+ "ACCT_TYPE_CREDIT, ACCT_TYPE_INCOME, etc.",
+ ACCT_TYPE_NONE,
+ NUM_ACCOUNT_TYPES - 1,
+ ACCT_TYPE_BANK,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_COMMODITY,
- g_param_spec_object ("commodity",
- "Commodity",
- "The commodity field denotes the kind of "
- "'stuff' stored in this account, whether "
- "it is USD, gold, stock, etc.",
- GNC_TYPE_COMMODITY,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_COMMODITY,
+ g_param_spec_object ("commodity",
+ "Commodity",
+ "The commodity field denotes the kind of "
+ "'stuff' stored in this account, whether "
+ "it is USD, gold, stock, etc.",
+ GNC_TYPE_COMMODITY,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_COMMODITY_SCU,
- g_param_spec_int ("commodity-scu",
- "Commodity SCU",
- "The smallest fraction of the commodity that is "
- "tracked. This number is used as the denominator "
- "value in 1/x, so a value of 100 says that the "
- "commodity can be divided into hundreths. E.G."
- "1 USD can be divided into 100 cents.",
- 0,
- G_MAXINT32,
- 1000000,
+ (gobject_class,
+ PROP_COMMODITY_SCU,
+ g_param_spec_int ("commodity-scu",
+ "Commodity SCU",
+ "The smallest fraction of the commodity that is "
+ "tracked. This number is used as the denominator "
+ "value in 1/x, so a value of 100 says that the "
+ "commodity can be divided into hundreths. E.G."
+ "1 USD can be divided into 100 cents.",
+ 0,
+ G_MAXINT32,
+ 1000000,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property
+ (gobject_class,
+ PROP_NON_STD_SCU,
+ g_param_spec_boolean ("non-std-scu",
+ "Non-std SCU",
+ "TRUE if the account SCU doesn't match "
+ "the commodity SCU. This indicates a case "
+ "where the two were accidentally set to "
+ "mismatched values in older versions of "
+ "GnuCash.",
+ FALSE,
G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_NON_STD_SCU,
- g_param_spec_boolean ("non-std-scu",
- "Non-std SCU",
- "TRUE if the account SCU doesn't match "
- "the commodity SCU. This indicates a case "
- "where the two were accidentally set to "
- "mismatched values in older versions of "
- "GnuCash.",
- FALSE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_SORT_DIRTY,
+ g_param_spec_boolean("sort-dirty",
+ "Sort Dirty",
+ "TRUE if the splits in the account needs to be "
+ "resorted. This flag is set by the accounts "
+ "code for certain internal modifications, or "
+ "when external code calls the engine to say a "
+ "split has been modified in a way that may "
+ "affect the sort order of the account. Note: "
+ "This value can only be set to TRUE.",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_SORT_DIRTY,
- g_param_spec_boolean("sort-dirty",
- "Sort Dirty",
- "TRUE if the splits in the account needs to be "
- "resorted. This flag is set by the accounts "
- "code for certain internal modifications, or "
- "when external code calls the engine to say a "
- "split has been modified in a way that may "
- "affect the sort order of the account. Note: "
- "This value can only be set to TRUE.",
- FALSE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_BALANCE_DIRTY,
+ g_param_spec_boolean("balance-dirty",
+ "Balance Dirty",
+ "TRUE if the running balances in the account "
+ "needs to be recalculated. This flag is set "
+ "by the accounts code for certain internal "
+ "modifications, or when external code calls "
+ "the engine to say a split has been modified. "
+ "Note: This value can only be set to TRUE.",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_BALANCE_DIRTY,
- g_param_spec_boolean("balance-dirty",
- "Balance Dirty",
- "TRUE if the running balances in the account "
- "needs to be recalculated. This flag is set "
- "by the accounts code for certain internal "
- "modifications, or when external code calls "
- "the engine to say a split has been modified. "
- "Note: This value can only be set to TRUE.",
- FALSE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_START_BALANCE,
+ g_param_spec_boxed("start-balance",
+ "Starting Balance",
+ "The starting balance for the account. This "
+ "parameter is intended for use with backends that "
+ "do not return the complete list of splits for an "
+ "account, but rather return a partial list. In "
+ "such a case, the backend will typically return "
+ "all of the splits after some certain date, and "
+ "the 'starting balance' will represent the "
+ "summation of the splits up to that date.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_START_BALANCE,
- g_param_spec_boxed("start-balance",
- "Starting Balance",
- "The starting balance for the account. This "
- "parameter is intended for use with backends that "
- "do not return the complete list of splits for an "
- "account, but rather return a partial list. In "
- "such a case, the backend will typically return "
- "all of the splits after some certain date, and "
- "the 'starting balance' will represent the "
- "summation of the splits up to that date.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_START_CLEARED_BALANCE,
+ g_param_spec_boxed("start-cleared-balance",
+ "Starting Cleared Balance",
+ "The starting cleared balance for the account. "
+ "This parameter is intended for use with backends "
+ "that do not return the complete list of splits "
+ "for an account, but rather return a partial "
+ "list. In such a case, the backend will "
+ "typically return all of the splits after "
+ "some certain date, and the 'starting cleared "
+ "balance' will represent the summation of the "
+ "splits up to that date.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_START_CLEARED_BALANCE,
- g_param_spec_boxed("start-cleared-balance",
- "Starting Cleared Balance",
- "The starting cleared balance for the account. "
- "This parameter is intended for use with backends "
- "that do not return the complete list of splits "
- "for an account, but rather return a partial "
- "list. In such a case, the backend will "
- "typically return all of the splits after "
- "some certain date, and the 'starting cleared "
- "balance' will represent the summation of the "
- "splits up to that date.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_START_RECONCILED_BALANCE,
+ g_param_spec_boxed("start-reconciled-balance",
+ "Starting Reconciled Balance",
+ "The starting reconciled balance for the "
+ "account. This parameter is intended for use "
+ "with backends that do not return the complete "
+ "list of splits for an account, but rather return "
+ "a partial list. In such a case, the backend "
+ "will typically return all of the splits after "
+ "some certain date, and the 'starting recontiled "
+ "balance' will represent the summation of the "
+ "splits up to that date.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_START_RECONCILED_BALANCE,
- g_param_spec_boxed("start-reconciled-balance",
- "Starting Reconciled Balance",
- "The starting reconciled balance for the "
- "account. This parameter is intended for use "
- "with backends that do not return the complete "
- "list of splits for an account, but rather return "
- "a partial list. In such a case, the backend "
- "will typically return all of the splits after "
- "some certain date, and the 'starting recontiled "
- "balance' will represent the summation of the "
- "splits up to that date.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_END_BALANCE,
+ g_param_spec_boxed("end-balance",
+ "Ending Account Balance",
+ "This is the current ending balance for the "
+ "account. It is computed from the sum of the "
+ "starting balance and all splits in the account.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READABLE));
g_object_class_install_property
- (gobject_class,
- PROP_END_BALANCE,
- g_param_spec_boxed("end-balance",
- "Ending Account Balance",
- "This is the current ending balance for the "
- "account. It is computed from the sum of the "
- "starting balance and all splits in the account.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READABLE));
+ (gobject_class,
+ PROP_END_CLEARED_BALANCE,
+ g_param_spec_boxed("end-cleared-balance",
+ "Ending Account Cleared Balance",
+ "This is the current ending cleared balance for "
+ "the account. It is computed from the sum of the "
+ "starting balance and all cleared splits in the "
+ "account.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READABLE));
g_object_class_install_property
- (gobject_class,
- PROP_END_CLEARED_BALANCE,
- g_param_spec_boxed("end-cleared-balance",
- "Ending Account Cleared Balance",
- "This is the current ending cleared balance for "
- "the account. It is computed from the sum of the "
- "starting balance and all cleared splits in the "
- "account.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READABLE));
+ (gobject_class,
+ PROP_END_RECONCILED_BALANCE,
+ g_param_spec_boxed("end-reconciled-balance",
+ "Ending Account Reconciled Balance",
+ "This is the current ending reconciled balance "
+ "for the account. It is computed from the sum of "
+ "the starting balance and all reconciled splits "
+ "in the account.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READABLE));
g_object_class_install_property
- (gobject_class,
- PROP_END_RECONCILED_BALANCE,
- g_param_spec_boxed("end-reconciled-balance",
- "Ending Account Reconciled Balance",
- "This is the current ending reconciled balance "
- "for the account. It is computed from the sum of "
- "the starting balance and all reconciled splits "
- "in the account.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READABLE));
+ (gobject_class,
+ PROP_POLICY,
+ g_param_spec_pointer ("policy",
+ "Policy",
+ "The account lots policy.",
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_POLICY,
- g_param_spec_pointer ("policy",
- "Policy",
- "The account lots policy.",
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_MARK,
+ g_param_spec_int ("acct-mark",
+ "Account Mark",
+ "Ipsum Lorem",
+ 0,
+ G_MAXINT16,
+ 0,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_MARK,
- g_param_spec_int ("acct-mark",
- "Account Mark",
- "Ipsum Lorem",
- 0,
- G_MAXINT16,
- 0,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_TAX_RELATED,
+ g_param_spec_boolean ("tax-related",
+ "Tax Related",
+ "Whether the account maps to an entry on an "
+ "income tax document.",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_TAX_RELATED,
- g_param_spec_boolean ("tax-related",
- "Tax Related",
- "Whether the account maps to an entry on an "
- "income tax document.",
- FALSE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_TAX_CODE,
+ g_param_spec_string ("tax-code",
+ "Tax Code",
+ "This is the code for mapping an account to a "
+ "specific entry on a taxable document. In the "
+ "United States it is used to transfer totals "
+ "into tax preparation software.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_TAX_CODE,
- g_param_spec_string ("tax-code",
- "Tax Code",
- "This is the code for mapping an account to a "
- "specific entry on a taxable document. In the "
- "United States it is used to transfer totals "
- "into tax preparation software.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_TAX_SOURCE,
+ g_param_spec_string ("tax-source",
+ "Tax Source",
+ "This specifies where exported name comes from.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_TAX_SOURCE,
- g_param_spec_string ("tax-source",
- "Tax Source",
- "This specifies where exported name comes from.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_TAX_COPY_NUMBER,
+ g_param_spec_int ("tax-copy-number",
+ "Tax Copy Number",
+ "This specifies the copy number of the tax "
+ "form/schedule.",
+ 1,
+ G_MAXINT16,
+ 1,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_TAX_COPY_NUMBER,
- g_param_spec_int ("tax-copy-number",
- "Tax Copy Number",
- "This specifies the copy number of the tax "
- "form/schedule.",
- 1,
- G_MAXINT16,
- 1,
+ (gobject_class,
+ PROP_HIDDEN,
+ g_param_spec_boolean ("hidden",
+ "Hidden",
+ "Whether the account should be hidden in the "
+ "account tree.",
+ FALSE,
G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_HIDDEN,
- g_param_spec_boolean ("hidden",
- "Hidden",
- "Whether the account should be hidden in the "
- "account tree.",
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property
- (gobject_class,
- PROP_PLACEHOLDER,
- g_param_spec_boolean ("placeholder",
- "Placeholder",
- "Whether the account is a placeholder account which does not "
- "allow transactions to be created, edited or deleted.",
- FALSE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_PLACEHOLDER,
+ g_param_spec_boolean ("placeholder",
+ "Placeholder",
+ "Whether the account is a placeholder account which does not "
+ "allow transactions to be created, edited or deleted.",
+ FALSE,
+ G_PARAM_READWRITE));
}
static void
xaccInitAccount (Account * acc, QofBook *book)
{
- ENTER ("book=%p\n", book);
- qof_instance_init_data (&acc->inst, GNC_ID_ACCOUNT, book);
+ ENTER ("book=%p\n", book);
+ qof_instance_init_data (&acc->inst, GNC_ID_ACCOUNT, book);
- LEAVE ("account=%p\n", acc);
+ LEAVE ("account=%p\n", acc);
}
/********************************************************************\
@@ -809,75 +814,77 @@
QofBook *
gnc_account_get_book(const Account *account)
{
- return qof_instance_get_book(QOF_INSTANCE(account));
+ return qof_instance_get_book(QOF_INSTANCE(account));
}
/********************************************************************\
\********************************************************************/
-static Account *
+static Account *
gnc_coll_get_root_account (QofCollection *col)
{
- if (!col) return NULL;
- return qof_collection_get_data (col);
+ if (!col) return NULL;
+ return qof_collection_get_data (col);
}
static void
gnc_coll_set_root_account (QofCollection *col, Account *root)
{
- AccountPrivate *rpriv;
- Account *old_root;
- if (!col) return;
+ AccountPrivate *rpriv;
+ Account *old_root;
+ if (!col) return;
- old_root = gnc_coll_get_root_account (col);
- if (old_root == root) return;
+ old_root = gnc_coll_get_root_account (col);
+ if (old_root == root) return;
- /* If the new root is already linked into the tree somewhere, then
- * remove it from its current position before adding it at the
- * top. */
- rpriv = GET_PRIVATE(root);
- if (rpriv->parent) {
- xaccAccountBeginEdit(root);
- gnc_account_remove_child(rpriv->parent, root);
- xaccAccountCommitEdit(root);
- }
-
- qof_collection_set_data (col, root);
+ /* If the new root is already linked into the tree somewhere, then
+ * remove it from its current position before adding it at the
+ * top. */
+ rpriv = GET_PRIVATE(root);
+ if (rpriv->parent)
+ {
+ xaccAccountBeginEdit(root);
+ gnc_account_remove_child(rpriv->parent, root);
+ xaccAccountCommitEdit(root);
+ }
- if (old_root) {
- xaccAccountBeginEdit (old_root);
- xaccAccountDestroy (old_root);
- }
+ qof_collection_set_data (col, root);
+
+ if (old_root)
+ {
+ xaccAccountBeginEdit (old_root);
+ xaccAccountDestroy (old_root);
+ }
}
Account *
gnc_book_get_root_account (QofBook *book)
{
- QofCollection *col;
- Account *root;
+ QofCollection *col;
+ Account *root;
- if (!book) return NULL;
- col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
- root = gnc_coll_get_root_account (col);
- if (root == NULL)
- root = gnc_account_create_root(book);
- return root;
+ if (!book) return NULL;
+ col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
+ root = gnc_coll_get_root_account (col);
+ if (root == NULL)
+ root = gnc_account_create_root(book);
+ return root;
}
void
gnc_book_set_root_account (QofBook *book, Account *root)
{
- QofCollection *col;
- if (!book) return;
+ QofCollection *col;
+ if (!book) return;
- if (root && gnc_account_get_book(root) != book)
- {
- PERR ("cannot mix and match books freely!");
- return;
- }
+ if (root && gnc_account_get_book(root) != book)
+ {
+ PERR ("cannot mix and match books freely!");
+ return;
+ }
- col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
- gnc_coll_set_root_account (col, root);
+ col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
+ gnc_coll_set_root_account (col, root);
}
/********************************************************************\
@@ -886,31 +893,31 @@
Account *
xaccMallocAccount (QofBook *book)
{
- Account *acc;
+ Account *acc;
- g_return_val_if_fail (book, NULL);
+ g_return_val_if_fail (book, NULL);
- acc = g_object_new (GNC_TYPE_ACCOUNT, NULL);
- xaccInitAccount (acc, book);
- qof_event_gen (&acc->inst, QOF_EVENT_CREATE, NULL);
+ acc = g_object_new (GNC_TYPE_ACCOUNT, NULL);
+ xaccInitAccount (acc, book);
+ qof_event_gen (&acc->inst, QOF_EVENT_CREATE, NULL);
- return acc;
+ return acc;
}
Account *
gnc_account_create_root (QofBook *book)
{
- Account *root;
- AccountPrivate *rpriv;
+ Account *root;
+ AccountPrivate *rpriv;
- root = xaccMallocAccount(book);
- rpriv = GET_PRIVATE(root);
- xaccAccountBeginEdit(root);
- rpriv->type = ACCT_TYPE_ROOT;
- CACHE_REPLACE(rpriv->accountName, "Root Account");
- xaccAccountCommitEdit(root);
- gnc_book_set_root_account(book, root);
- return root;
+ root = xaccMallocAccount(book);
+ rpriv = GET_PRIVATE(root);
+ xaccAccountBeginEdit(root);
+ rpriv->type = ACCT_TYPE_ROOT;
+ CACHE_REPLACE(rpriv->accountName, "Root Account");
+ xaccAccountCommitEdit(root);
+ gnc_book_set_root_account(book, root);
+ return root;
}
static Account *
@@ -930,7 +937,7 @@
priv = GET_PRIVATE(ret);
xaccInitAccount (ret, book);
- /* Do not Begin/CommitEdit() here; give the caller
+ /* Do not Begin/CommitEdit() here; give the caller
* a chance to fix things up, and let them do it.
* Also let caller issue the generate_event (EVENT_CREATE) */
priv->type = from_priv->type;
@@ -967,7 +974,7 @@
Account *
xaccCloneAccountSimple (const Account *from, QofBook *book)
{
- Account *ret = xaccCloneAccountCommon(from, book);
+ Account *ret = xaccCloneAccountCommon(from, book);
qof_instance_set_dirty(&ret->inst);
return ret;
}
@@ -981,26 +988,26 @@
/* FIXME: this code is kind of hacky. actually, all this code
* seems to assume that the account edit levels are all 1. */
if (qof_instance_get_editlevel(acc) == 0)
- xaccAccountBeginEdit(acc);
+ xaccAccountBeginEdit(acc);
xaccAccountDestroy(acc);
}
static void
xaccFreeAccountChildren (Account *acc)
{
- AccountPrivate *priv;
- GList *children;
+ AccountPrivate *priv;
+ GList *children;
- /* Copy the list since it will be modified */
- priv = GET_PRIVATE(acc);
- children = g_list_copy(priv->children);
- g_list_foreach(children, (GFunc)xaccFreeOneChildAccount, NULL);
- g_list_free(children);
+ /* Copy the list since it will be modified */
+ priv = GET_PRIVATE(acc);
+ children = g_list_copy(priv->children);
+ g_list_foreach(children, (GFunc)xaccFreeOneChildAccount, NULL);
+ g_list_free(children);
- /* The foreach should have removed all the children already. */
- if (priv->children)
- g_list_free(priv->children);
- priv->children = NULL;
+ /* The foreach should have removed all the children already. */
+ if (priv->children)
+ g_list_free(priv->children);
+ priv->children = NULL;
}
/* The xaccFreeAccount() routine releases memory associated with the
@@ -1010,97 +1017,98 @@
static void
xaccFreeAccount (Account *acc)
{
- AccountPrivate *priv;
- GList *lp;
+ AccountPrivate *priv;
+ GList *lp;
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- priv = GET_PRIVATE(acc);
- qof_event_gen (&acc->inst, QOF_EVENT_DESTROY, NULL);
+ priv = GET_PRIVATE(acc);
+ qof_event_gen (&acc->inst, QOF_EVENT_DESTROY, NULL);
- if (priv->children)
- {
- PERR (" instead of calling xaccFreeAccount(), please call \n"
- " xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
+ if (priv->children)
+ {
+ PERR (" instead of calling xaccFreeAccount(), please call \n"
+ " xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
- /* First, recursively free children */
- xaccFreeAccountChildren(acc);
- }
+ /* First, recursively free children */
+ xaccFreeAccountChildren(acc);
+ }
- /* remove lots -- although these should be gone by now. */
- if (priv->lots)
- {
- PERR (" instead of calling xaccFreeAccount(), please call \n"
- " xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
-
- for (lp=priv->lots; lp; lp=lp->next)
+ /* remove lots -- although these should be gone by now. */
+ if (priv->lots)
{
- GNCLot *lot = lp->data;
- gnc_lot_destroy (lot);
+ PERR (" instead of calling xaccFreeAccount(), please call \n"
+ " xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
+
+ for (lp = priv->lots; lp; lp = lp->next)
+ {
+ GNCLot *lot = lp->data;
+ gnc_lot_destroy (lot);
+ }
+ g_list_free (priv->lots);
+ priv->lots = NULL;
}
- g_list_free (priv->lots);
- priv->lots = NULL;
- }
- /* Next, clean up the splits */
- /* NB there shouldn't be any splits by now ... they should
- * have been all been freed by CommitEdit(). We can remove this
- * check once we know the warning isn't occurring any more. */
- if (priv->splits)
- {
- GList *slist;
- PERR (" instead of calling xaccFreeAccount(), please call \n"
- " xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
-
- qof_instance_reset_editlevel(acc);
+ /* Next, clean up the splits */
+ /* NB there shouldn't be any splits by now ... they should
+ * have been all been freed by CommitEdit(). We can remove this
+ * check once we know the warning isn't occurring any more. */
+ if (priv->splits)
+ {
+ GList *slist;
+ PERR (" instead of calling xaccFreeAccount(), please call \n"
+ " xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
- slist = g_list_copy(priv->splits);
- for (lp = slist; lp; lp = lp->next) {
- Split *s = (Split *) lp->data;
- g_assert(xaccSplitGetAccount(s) == acc);
- xaccSplitDestroy (s);
+ qof_instance_reset_editlevel(acc);
+
+ slist = g_list_copy(priv->splits);
+ for (lp = slist; lp; lp = lp->next)
+ {
+ Split *s = (Split *) lp->data;
+ g_assert(xaccSplitGetAccount(s) == acc);
+ xaccSplitDestroy (s);
+ }
+ g_list_free(slist);
+ g_assert(priv->splits == NULL);
}
- g_list_free(slist);
- g_assert(priv->splits == NULL);
- }
- CACHE_REPLACE(priv->accountName, NULL);
- CACHE_REPLACE(priv->accountCode, NULL);
- CACHE_REPLACE(priv->description, NULL);
+ CACHE_REPLACE(priv->accountName, NULL);
+ CACHE_REPLACE(priv->accountCode, NULL);
+ CACHE_REPLACE(priv->description, NULL);
- /* zero out values, just in case stray
- * pointers are pointing here. */
+ /* zero out values, just in case stray
+ * pointers are pointing here. */
- priv->parent = NULL;
- priv->children = NULL;
+ priv->parent = NULL;
+ priv->children = NULL;
- priv->balance = gnc_numeric_zero();
- priv->cleared_balance = gnc_numeric_zero();
- priv->reconciled_balance = gnc_numeric_zero();
+ priv->balance = gnc_numeric_zero();
+ priv->cleared_balance = gnc_numeric_zero();
+ priv->reconciled_balance = gnc_numeric_zero();
- priv->type = ACCT_TYPE_NONE;
- gnc_commodity_decrement_usage_count(priv->commodity);
- priv->commodity = NULL;
+ priv->type = ACCT_TYPE_NONE;
+ gnc_commodity_decrement_usage_count(priv->commodity);
+ priv->commodity = NULL;
- priv->balance_dirty = FALSE;
- priv->sort_dirty = FALSE;
+ priv->balance_dirty = FALSE;
+ priv->sort_dirty = FALSE;
- /* qof_instance_release (&acc->inst); */
- g_object_unref(acc);
+ /* qof_instance_release (&acc->inst); */
+ g_object_unref(acc);
}
/********************************************************************\
* transactional routines
\********************************************************************/
-void
-xaccAccountBeginEdit (Account *acc)
+void
+xaccAccountBeginEdit (Account *acc)
{
- g_return_if_fail(acc);
- qof_begin_edit(&acc->inst);
+ g_return_if_fail(acc);
+ qof_begin_edit(&acc->inst);
}
-static void on_done(QofInstance *inst)
+static void on_done(QofInstance *inst)
{
/* old event style */
qof_event_gen (inst, QOF_EVENT_MODIFY, NULL);
@@ -1108,19 +1116,19 @@
static void on_err (QofInstance *inst, QofBackendError errcode)
{
- PERR("commit error: %d", errcode);
- gnc_engine_signal_commit_error( errcode );
+ PERR("commit error: %d", errcode);
+ gnc_engine_signal_commit_error( errcode );
}
static void acc_free (QofInstance *inst)
{
- AccountPrivate *priv;
- Account *acc = (Account *) inst;
+ AccountPrivate *priv;
+ Account *acc = (Account *) inst;
- priv = GET_PRIVATE(acc);
- if (priv->parent)
- gnc_account_remove_child(priv->parent, acc);
- xaccFreeAccount(acc);
+ priv = GET_PRIVATE(acc);
+ if (priv->parent)
+ gnc_account_remove_child(priv->parent, acc);
+ xaccFreeAccount(acc);
}
static void
@@ -1134,80 +1142,81 @@
xaccSplitDestroy(split);
}
-void
-xaccAccountCommitEdit (Account *acc)
+void
+xaccAccountCommitEdit (Account *acc)
{
- AccountPrivate *priv;
- QofBook *book;
+ AccountPrivate *priv;
+ QofBook *book;
- g_return_if_fail(acc);
- if (!qof_commit_edit(&acc->inst)) return;
+ g_return_if_fail(acc);
+ if (!qof_commit_edit(&acc->inst)) return;
- /* If marked for deletion, get rid of subaccounts first,
- * and then the splits ... */
- priv = GET_PRIVATE(acc);
- if (qof_instance_get_destroying(acc))
- {
- GList *lp, *slist;
- QofCollection *col;
-
- qof_instance_increase_editlevel(acc);
+ /* If marked for deletion, get rid of subaccounts first,
+ * and then the splits ... */
+ priv = GET_PRIVATE(acc);
+ if (qof_instance_get_destroying(acc))
+ {
+ GList *lp, *slist;
+ QofCollection *col;
- /* First, recursively free children */
- xaccFreeAccountChildren(acc);
+ qof_instance_increase_editlevel(acc);
- PINFO ("freeing splits for account %p (%s)",
- acc, priv->accountName ? priv->accountName : "(null)");
+ /* First, recursively free children */
+ xaccFreeAccountChildren(acc);
- slist = g_list_copy(priv->splits);
- for (lp = slist; lp; lp = lp->next)
- {
- Split *s = lp->data;
- xaccSplitDestroy (s);
- }
- g_list_free(slist);
- /* It turns out there's a case where this assertion does not hold:
- When the user tries to delete an Imbalance account, while also
- deleting all the splits in it. The splits will just get
- recreated and put right back into the same account!
+ PINFO ("freeing splits for account %p (%s)",
+ acc, priv->accountName ? priv->accountName : "(null)");
- g_assert(priv->splits == NULL || qof_book_shutting_down(acc->inst.book));
- */
+ slist = g_list_copy(priv->splits);
+ for (lp = slist; lp; lp = lp->next)
+ {
+ Split *s = lp->data;
+ xaccSplitDestroy (s);
+ }
+ g_list_free(slist);
+ /* It turns out there's a case where this assertion does not hold:
+ When the user tries to delete an Imbalance account, while also
+ deleting all the splits in it. The splits will just get
+ recreated and put right back into the same account!
- book = qof_instance_get_book(acc);
- if (!qof_book_shutting_down(book)) {
- col = qof_book_get_collection(book, GNC_ID_TRANS);
- qof_collection_foreach(col, destroy_pending_splits_for_account, acc);
+ g_assert(priv->splits == NULL || qof_book_shutting_down(acc->inst.book));
+ */
+
+ book = qof_instance_get_book(acc);
+ if (!qof_book_shutting_down(book))
+ {
+ col = qof_book_get_collection(book, GNC_ID_TRANS);
+ qof_collection_foreach(col, destroy_pending_splits_for_account, acc);
+ }
+
+ /* the lots should be empty by now */
+ for (lp = priv->lots; lp; lp = lp->next)
+ {
+ GNCLot *lot = lp->data;
+ gnc_lot_destroy (lot);
+ }
+ g_list_free(priv->lots);
+ priv->lots = NULL;
+
+ qof_instance_set_dirty(&acc->inst);
+ qof_instance_decrease_editlevel(acc);
}
-
- /* the lots should be empty by now */
- for (lp = priv->lots; lp; lp = lp->next)
+ else
{
- GNCLot *lot = lp->data;
- gnc_lot_destroy (lot);
+ xaccAccountBringUpToDate(acc);
}
- g_list_free(priv->lots);
- priv->lots = NULL;
- qof_instance_set_dirty(&acc->inst);
- qof_instance_decrease_editlevel(acc);
- }
- else
- {
- xaccAccountBringUpToDate(acc);
- }
-
- qof_commit_edit_part2(&acc->inst, on_err, on_done, acc_free);
+ qof_commit_edit_part2(&acc->inst, on_err, on_done, acc_free);
}
-void
-xaccAccountDestroy (Account *acc)
+void
+xaccAccountDestroy (Account *acc)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- qof_instance_set_destroying(acc, TRUE);
+ qof_instance_set_destroying(acc, TRUE);
- xaccAccountCommitEdit (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -1215,255 +1224,256 @@
static gboolean
xaccAcctChildrenEqual(const GList *na,
- const GList *nb,
- gboolean check_guids)
+ const GList *nb,
+ gboolean check_guids)
{
- if ((!na && nb) || (na && !nb))
- {
- PWARN ("only one has accounts");
- return(FALSE);
- }
+ if ((!na && nb) || (na && !nb))
+ {
+ PWARN ("only one has accounts");
+ return(FALSE);
+ }
- while (na && nb)
- {
- Account *aa = na->data;
- Account *ab = nb->data;
-
- if (!xaccAccountEqual(aa, ab, check_guids))
+ while (na && nb)
{
- char sa[GUID_ENCODING_LENGTH + 1];
- char sb[GUID_ENCODING_LENGTH + 1];
+ Account *aa = na->data;
+ Account *ab = nb->data;
- guid_to_string_buff (xaccAccountGetGUID (aa), sa);
- guid_to_string_buff (xaccAccountGetGUID (ab), sb);
+ if (!xaccAccountEqual(aa, ab, check_guids))
+ {
+ char sa[GUID_ENCODING_LENGTH + 1];
+ char sb[GUID_ENCODING_LENGTH + 1];
- PWARN ("accounts %s and %s differ", sa, sb);
+ guid_to_string_buff (xaccAccountGetGUID (aa), sa);
+ guid_to_string_buff (xaccAccountGetGUID (ab), sb);
- return(FALSE);
+ PWARN ("accounts %s and %s differ", sa, sb);
+
+ return(FALSE);
+ }
+
+ na = na->next;
+ nb = nb->next;
}
- na = na->next;
- nb = nb->next;
- }
+ if (na || nb)
+ {
+ PWARN ("different numbers of accounts");
+ return(FALSE);
+ }
- if (na || nb)
- {
- PWARN ("different numbers of accounts");
- return(FALSE);
- }
-
- return(TRUE);
+ return(TRUE);
}
gboolean
xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
{
- AccountPrivate *priv_aa, *priv_ab;
+ AccountPrivate *priv_aa, *priv_ab;
- if(!aa && !ab) return TRUE;
+ if (!aa && !ab) return TRUE;
- g_return_val_if_fail(GNC_IS_ACCOUNT(aa), FALSE);
- g_return_val_if_fail(GNC_IS_ACCOUNT(ab), FALSE);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(aa), FALSE);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(ab), FALSE);
- priv_aa = GET_PRIVATE(aa);
- priv_ab = GET_PRIVATE(ab);
- if (priv_aa->type != priv_ab->type)
- {
- PWARN ("types differ: %d vs %d", priv_aa->type, priv_ab->type);
- return FALSE;
- }
+ priv_aa = GET_PRIVATE(aa);
+ priv_ab = GET_PRIVATE(ab);
+ if (priv_aa->type != priv_ab->type)
+ {
+ PWARN ("types differ: %d vs %d", priv_aa->type, priv_ab->type);
+ return FALSE;
+ }
- if (safe_strcmp(priv_aa->accountName, priv_ab->accountName) != 0)
- {
- PWARN ("names differ: %s vs %s", priv_aa->accountName, priv_ab->accountName);
- return FALSE;
- }
+ if (safe_strcmp(priv_aa->accountName, priv_ab->accountName) != 0)
+ {
+ PWARN ("names differ: %s vs %s", priv_aa->accountName, priv_ab->accountName);
+ return FALSE;
+ }
- if (safe_strcmp(priv_aa->accountCode, priv_ab->accountCode) != 0)
- {
- PWARN ("codes differ: %s vs %s", priv_aa->accountCode, priv_ab->accountCode);
- return FALSE;
- }
+ if (safe_strcmp(priv_aa->accountCode, priv_ab->accountCode) != 0)
+ {
+ PWARN ("codes differ: %s vs %s", priv_aa->accountCode, priv_ab->accountCode);
+ return FALSE;
+ }
- if (safe_strcmp(priv_aa->description, priv_ab->description) != 0)
- {
- PWARN ("descriptions differ: %s vs %s", priv_aa->description, priv_ab->description);
- return FALSE;
- }
+ if (safe_strcmp(priv_aa->description, priv_ab->description) != 0)
+ {
+ PWARN ("descriptions differ: %s vs %s", priv_aa->description, priv_ab->description);
+ return FALSE;
+ }
- if (!gnc_commodity_equal(priv_aa->commodity, priv_ab->commodity))
- {
- PWARN ("commodities differ");
- return FALSE;
- }
+ if (!gnc_commodity_equal(priv_aa->commodity, priv_ab->commodity))
+ {
+ PWARN ("commodities differ");
+ return FALSE;
+ }
- if(check_guids) {
- if(qof_instance_guid_compare(aa, ab) != 0)
+ if (check_guids)
{
- PWARN ("GUIDs differ");
- return FALSE;
+ if (qof_instance_guid_compare(aa, ab) != 0)
+ {
+ PWARN ("GUIDs differ");
+ return FALSE;
+ }
}
- }
- if (kvp_frame_compare(aa->inst.kvp_data, ab->inst.kvp_data) != 0)
- {
- char *frame_a;
- char *frame_b;
+ if (kvp_frame_compare(aa->inst.kvp_data, ab->inst.kvp_data) != 0)
+ {
+ char *frame_a;
+ char *frame_b;
- frame_a = kvp_frame_to_string (aa->inst.kvp_data);
- frame_b = kvp_frame_to_string (ab->inst.kvp_data);
+ frame_a = kvp_frame_to_string (aa->inst.kvp_data);
+ frame_b = kvp_frame_to_string (ab->inst.kvp_data);
- PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
+ PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
- g_free (frame_a);
- g_free (frame_b);
+ g_free (frame_a);
+ g_free (frame_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (!gnc_numeric_equal(priv_aa->starting_balance, priv_ab->starting_balance))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_equal(priv_aa->starting_balance, priv_ab->starting_balance))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string(priv_aa->starting_balance);
- str_b = gnc_numeric_to_string(priv_ab->starting_balance);
+ str_a = gnc_numeric_to_string(priv_aa->starting_balance);
+ str_b = gnc_numeric_to_string(priv_ab->starting_balance);
- PWARN ("starting balances differ: %s vs %s", str_a, str_b);
+ PWARN ("starting balances differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (!gnc_numeric_equal(priv_aa->starting_cleared_balance,
- priv_ab->starting_cleared_balance))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_equal(priv_aa->starting_cleared_balance,
+ priv_ab->starting_cleared_balance))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string(priv_aa->starting_cleared_balance);
- str_b = gnc_numeric_to_string(priv_ab->starting_cleared_balance);
+ str_a = gnc_numeric_to_string(priv_aa->starting_cleared_balance);
+ str_b = gnc_numeric_to_string(priv_ab->starting_cleared_balance);
- PWARN ("starting cleared balances differ: %s vs %s", str_a, str_b);
+ PWARN ("starting cleared balances differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (!gnc_numeric_equal(priv_aa->starting_reconciled_balance,
- priv_ab->starting_reconciled_balance))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_equal(priv_aa->starting_reconciled_balance,
+ priv_ab->starting_reconciled_balance))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string(priv_aa->starting_reconciled_balance);
- str_b = gnc_numeric_to_string(priv_ab->starting_reconciled_balance);
+ str_a = gnc_numeric_to_string(priv_aa->starting_reconciled_balance);
+ str_b = gnc_numeric_to_string(priv_ab->starting_reconciled_balance);
- PWARN ("starting reconciled balances differ: %s vs %s", str_a, str_b);
+ PWARN ("starting reconciled balances differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (!gnc_numeric_equal(priv_aa->balance, priv_ab->balance))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_equal(priv_aa->balance, priv_ab->balance))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string(priv_aa->balance);
- str_b = gnc_numeric_to_string(priv_ab->balance);
+ str_a = gnc_numeric_to_string(priv_aa->balance);
+ str_b = gnc_numeric_to_string(priv_ab->balance);
- PWARN ("balances differ: %s vs %s", str_a, str_b);
+ PWARN ("balances differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (!gnc_numeric_equal(priv_aa->cleared_balance, priv_ab->cleared_balance))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_equal(priv_aa->cleared_balance, priv_ab->cleared_balance))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string(priv_aa->cleared_balance);
- str_b = gnc_numeric_to_string(priv_ab->cleared_balance);
+ str_a = gnc_numeric_to_string(priv_aa->cleared_balance);
+ str_b = gnc_numeric_to_string(priv_ab->cleared_balance);
- PWARN ("cleared balances differ: %s vs %s", str_a, str_b);
+ PWARN ("cleared balances differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (!gnc_numeric_equal(priv_aa->reconciled_balance, priv_ab->reconciled_balance))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_equal(priv_aa->reconciled_balance, priv_ab->reconciled_balance))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string(priv_aa->reconciled_balance);
- str_b = gnc_numeric_to_string(priv_ab->reconciled_balance);
+ str_a = gnc_numeric_to_string(priv_aa->reconciled_balance);
+ str_b = gnc_numeric_to_string(priv_ab->reconciled_balance);
- PWARN ("reconciled balances differ: %s vs %s", str_a, str_b);
+ PWARN ("reconciled balances differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- /* no parent; always compare downwards. */
+ /* no parent; always compare downwards. */
- {
- GList *la = priv_aa->splits;
- GList *lb = priv_ab->splits;
-
- if ((la && !lb) || (!la && lb))
{
- PWARN ("only one has splits");
- return FALSE;
- }
+ GList *la = priv_aa->splits;
+ GList *lb = priv_ab->splits;
- if(la && lb)
- {
- /* presume that the splits are in the same order */
- while (la && lb)
- {
- Split *sa = (Split *) la->data;
- Split *sb = (Split *) lb->data;
-
- if (!xaccSplitEqual(sa, sb, check_guids, TRUE, FALSE))
+ if ((la && !lb) || (!la && lb))
{
- PWARN ("splits differ");
- return(FALSE);
+ PWARN ("only one has splits");
+ return FALSE;
}
- la = la->next;
- lb = lb->next;
- }
+ if (la && lb)
+ {
+ /* presume that the splits are in the same order */
+ while (la && lb)
+ {
+ Split *sa = (Split *) la->data;
+ Split *sb = (Split *) lb->data;
- if ((la != NULL) || (lb != NULL))
- {
- PWARN ("number of splits differs");
- return(FALSE);
- }
+ if (!xaccSplitEqual(sa, sb, check_guids, TRUE, FALSE))
+ {
+ PWARN ("splits differ");
+ return(FALSE);
+ }
+
+ la = la->next;
+ lb = lb->next;
+ }
+
+ if ((la != NULL) || (lb != NULL))
+ {
+ PWARN ("number of splits differs");
+ return(FALSE);
+ }
+ }
}
- }
- if (!xaccAcctChildrenEqual(priv_aa->children, priv_ab->children, check_guids))
- {
- PWARN ("children differ");
- return FALSE;
- }
+ if (!xaccAcctChildrenEqual(priv_aa->children, priv_ab->children, check_guids))
+ {
+ PWARN ("children differ");
+ return FALSE;
+ }
- return(TRUE);
+ return(TRUE);
}
/********************************************************************\
@@ -1475,7 +1485,7 @@
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
return GET_PRIVATE(acc)->sort_dirty;
}
-
+
void
gnc_account_set_sort_dirty (Account *acc)
{
@@ -1484,7 +1494,7 @@
g_return_if_fail(GNC_IS_ACCOUNT(acc));
if (qof_instance_get_destroying(acc))
- return;
+ return;
priv = GET_PRIVATE(acc);
priv->sort_dirty = TRUE;
@@ -1505,7 +1515,7 @@
g_return_if_fail(GNC_IS_ACCOUNT(acc));
if (qof_instance_get_destroying(acc))
- return;
+ return;
priv = GET_PRIVATE(acc);
priv->balance_dirty = TRUE;
@@ -1540,15 +1550,18 @@
priv = GET_PRIVATE(acc);
node = g_list_find(priv->splits, s);
if (node)
- return FALSE;
+ return FALSE;
- if (qof_instance_get_editlevel(acc) == 0) {
- priv->splits = g_list_insert_sorted(priv->splits, s,
- (GCompareFunc)xaccSplitOrder);
- } else {
- priv->splits = g_list_prepend(priv->splits, s);
- priv->sort_dirty = TRUE;
+ if (qof_instance_get_editlevel(acc) == 0)
+ {
+ priv->splits = g_list_insert_sorted(priv->splits, s,
+ (GCompareFunc)xaccSplitOrder);
}
+ else
+ {
+ priv->splits = g_list_prepend(priv->splits, s);
+ priv->sort_dirty = TRUE;
+ }
//FIXME: find better event
qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, NULL);
@@ -1573,7 +1586,7 @@
priv = GET_PRIVATE(acc);
node = g_list_find(priv->splits, s);
if (NULL == node)
- return FALSE;
+ return FALSE;
priv->splits = g_list_delete_link(priv->splits, node);
//FIXME: find better event type
@@ -1602,31 +1615,31 @@
}
static void
-xaccAccountBringUpToDate(Account *acc)
+xaccAccountBringUpToDate(Account *acc)
{
- if (!acc) return;
+ if (!acc) return;
- /* if a re-sort happens here, then everything will update, so the
- cost basis and balance calls are no-ops */
- xaccAccountSortSplits(acc, FALSE);
- xaccAccountRecomputeBalance(acc);
+ /* if a re-sort happens here, then everything will update, so the
+ cost basis and balance calls are no-ops */
+ xaccAccountSortSplits(acc, FALSE);
+ xaccAccountRecomputeBalance(acc);
}
/********************************************************************\
\********************************************************************/
-void
+void
xaccAccountSetGUID (Account *acc, const GUID *guid)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
- g_return_if_fail(guid);
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(guid);
- /* XXX this looks fishy and weird to me ... */
- PINFO("acct=%p", acc);
- xaccAccountBeginEdit (acc);
- qof_instance_set_guid (&acc->inst, guid);
- qof_instance_set_dirty(&acc->inst);
- xaccAccountCommitEdit (acc);
+ /* XXX this looks fishy and weird to me ... */
+ PINFO("acct=%p", acc);
+ xaccAccountBeginEdit (acc);
+ qof_instance_set_guid (&acc->inst, guid);
+ qof_instance_set_dirty(&acc->inst);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -1635,10 +1648,10 @@
Account *
xaccAccountLookup (const GUID *guid, QofBook *book)
{
- QofCollection *col;
- if (!guid || !book) return NULL;
- col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
- return (Account *) qof_collection_lookup_entity (col, guid);
+ QofCollection *col;
+ if (!guid || !book) return NULL;
+ col = qof_book_get_collection (book, GNC_ID_ACCOUNT);
+ return (Account *) qof_collection_lookup_entity (col, guid);
}
/********************************************************************\
@@ -1684,7 +1697,8 @@
priv = GET_PRIVATE(acc);
priv->mark = val;
- for (node = priv->children; node; node = node->next) {
+ for (node = priv->children; node; node = node->next)
+ {
xaccClearMarkDown(node->data, val);
}
}
@@ -1737,39 +1751,40 @@
{
AccountPrivate *priv, *opriv;
Account * old_acc = NULL;
- Account* lot_account;
+ Account* lot_account;
- /* errors */
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
- g_return_if_fail(GNC_IS_LOT(lot));
+ /* errors */
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_LOT(lot));
- /* optimizations */
- lot_account = gnc_lot_get_account(lot);
- if (lot_account == acc)
- return;
+ /* optimizations */
+ lot_account = gnc_lot_get_account(lot);
+ if (lot_account == acc)
+ return;
- ENTER ("(acc=%p, lot=%p)", acc, lot);
+ ENTER ("(acc=%p, lot=%p)", acc, lot);
- /* pull it out of the old account */
- if (lot_account) {
- old_acc = lot_account;
- opriv = GET_PRIVATE(old_acc);
- opriv->lots = g_list_remove(opriv->lots, lot);
- }
+ /* pull it out of the old account */
+ if (lot_account)
+ {
+ old_acc = lot_account;
+ opriv = GET_PRIVATE(old_acc);
+ opriv->lots = g_list_remove(opriv->lots, lot);
+ }
- priv = GET_PRIVATE(acc);
- priv->lots = g_list_prepend(priv->lots, lot);
- gnc_lot_set_account(lot, acc);
+ priv = GET_PRIVATE(acc);
+ priv->lots = g_list_prepend(priv->lots, lot);
+ gnc_lot_set_account(lot, acc);
- /* Don't move the splits to the new account. The caller will do this
- * if appropriate, and doing it here will not work if we are being
- * called from gnc_book_close_period since xaccAccountInsertSplit
- * will try to balance capital gains and things aren't ready for that. */
+ /* Don't move the splits to the new account. The caller will do this
+ * if appropriate, and doing it here will not work if we are being
+ * called from gnc_book_close_period since xaccAccountInsertSplit
+ * will try to balance capital gains and things aren't ready for that. */
- qof_event_gen (QOF_INSTANCE(lot), QOF_EVENT_ADD, NULL);
- qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, NULL);
+ qof_event_gen (QOF_INSTANCE(lot), QOF_EVENT_ADD, NULL);
+ qof_event_gen (&acc->inst, QOF_EVENT_MODIFY, NULL);
- LEAVE ("(acc=%p, lot=%p)", acc, lot);
+ LEAVE ("(acc=%p, lot=%p)", acc, lot);
}
/********************************************************************\
@@ -1777,68 +1792,68 @@
static void
xaccPreSplitMove (Split *split, gpointer dummy)
{
- xaccTransBeginEdit (xaccSplitGetParent (split));
+ xaccTransBeginEdit (xaccSplitGetParent (split));
}
static void
xaccPostSplitMove (Split *split, Account *accto)
{
- Transaction *trans;
+ Transaction *trans;
- xaccSplitSetAccount(split, accto);
- xaccSplitSetAmount(split, split->amount);
- trans = xaccSplitGetParent (split);
- xaccTransCommitEdit (trans);
+ xaccSplitSetAccount(split, accto);
+ xaccSplitSetAmount(split, split->amount);
+ trans = xaccSplitGetParent (split);
+ xaccTransCommitEdit (trans);
}
void
xaccAccountMoveAllSplits (Account *accfrom, Account *accto)
{
- AccountPrivate *from_priv, *to_priv;
+ AccountPrivate *from_priv, *to_priv;
- /* errors */
- g_return_if_fail(GNC_IS_ACCOUNT(accfrom));
- g_return_if_fail(GNC_IS_ACCOUNT(accto));
+ /* errors */
+ g_return_if_fail(GNC_IS_ACCOUNT(accfrom));
+ g_return_if_fail(GNC_IS_ACCOUNT(accto));
- /* optimizations */
- from_priv = GET_PRIVATE(accfrom);
- to_priv = GET_PRIVATE(accto);
- if (!from_priv->splits || accfrom == accto)
- return;
+ /* optimizations */
+ from_priv = GET_PRIVATE(accfrom);
+ to_priv = GET_PRIVATE(accto);
+ if (!from_priv->splits || accfrom == accto)
+ return;
- /* check for book mix-up */
- g_return_if_fail (qof_instance_books_equal(accfrom, accto));
- ENTER ("(accfrom=%p, accto=%p)", accfrom, accto);
+ /* check for book mix-up */
+ g_return_if_fail (qof_instance_books_equal(accfrom, accto));
+ ENTER ("(accfrom=%p, accto=%p)", accfrom, accto);
- xaccAccountBeginEdit(accfrom);
- xaccAccountBeginEdit(accto);
- /* Begin editing both accounts and all transactions in accfrom. */
- g_list_foreach(from_priv->splits, (GFunc)xaccPreSplitMove, NULL);
+ xaccAccountBeginEdit(accfrom);
+ xaccAccountBeginEdit(accto);
+ /* Begin editing both accounts and all transactions in accfrom. */
+ g_list_foreach(from_priv->splits, (GFunc)xaccPreSplitMove, NULL);
- /* Concatenate accfrom's lists of splits and lots to accto's lists. */
- //to_priv->splits = g_list_concat(to_priv->splits, from_priv->splits);
- //to_priv->lots = g_list_concat(to_priv->lots, from_priv->lots);
+ /* Concatenate accfrom's lists of splits and lots to accto's lists. */
+ //to_priv->splits = g_list_concat(to_priv->splits, from_priv->splits);
+ //to_priv->lots = g_list_concat(to_priv->lots, from_priv->lots);
- /* Set appropriate flags. */
- //from_priv->balance_dirty = TRUE;
- //from_priv->sort_dirty = FALSE;
- //to_priv->balance_dirty = TRUE;
- //to_priv->sort_dirty = TRUE;
+ /* Set appropriate flags. */
+ //from_priv->balance_dirty = TRUE;
+ //from_priv->sort_dirty = FALSE;
+ //to_priv->balance_dirty = TRUE;
+ //to_priv->sort_dirty = TRUE;
- /*
- * Change each split's account back pointer to accto.
- * Convert each split's amount to accto's commodity.
- * Commit to editing each transaction.
- */
- g_list_foreach(from_priv->splits, (GFunc)xaccPostSplitMove, (gpointer)accto);
+ /*
+ * Change each split's account back pointer to accto.
+ * Convert each split's amount to accto's commodity.
+ * Commit to editing each transaction.
+ */
+ g_list_foreach(from_priv->splits, (GFunc)xaccPostSplitMove, (gpointer)accto);
- /* Finally empty accfrom. */
- g_assert(from_priv->splits == NULL);
- g_assert(from_priv->lots == NULL);
- xaccAccountCommitEdit(accfrom);
- xaccAccountCommitEdit(accto);
+ /* Finally empty accfrom. */
+ g_assert(from_priv->splits == NULL);
+ g_assert(from_priv->lots == NULL);
+ xaccAccountCommitEdit(accfrom);
+ xaccAccountCommitEdit(accto);
- LEAVE ("(accfrom=%p, accto=%p)", accfrom, accto);
+ LEAVE ("(accfrom=%p, accto=%p)", accfrom, accto);
}
@@ -1873,170 +1888,178 @@
void
xaccAccountRecomputeBalance (Account * acc)
{
- AccountPrivate *priv;
- gnc_numeric balance;
- gnc_numeric cleared_balance;
- gnc_numeric reconciled_balance;
- Split *last_split = NULL;
- GList *lp;
+ AccountPrivate *priv;
+ gnc_numeric balance;
+ gnc_numeric cleared_balance;
+ gnc_numeric reconciled_balance;
+ Split *last_split = NULL;
+ GList *lp;
- if (NULL == acc) return;
+ if (NULL == acc) return;
- priv = GET_PRIVATE(acc);
- if (qof_instance_get_editlevel(acc) > 0) return;
- if (!priv->balance_dirty) return;
- if (qof_instance_get_destroying(acc)) return;
- if (qof_book_shutting_down(qof_instance_get_book(acc))) return;
+ priv = GET_PRIVATE(acc);
+ if (qof_instance_get_editlevel(acc) > 0) return;
+ if (!priv->balance_dirty) return;
+ if (qof_instance_get_destroying(acc)) return;
+ if (qof_book_shutting_down(qof_instance_get_book(acc))) return;
- balance = priv->starting_balance;
- cleared_balance = priv->starting_cleared_balance;
- reconciled_balance = priv->starting_reconciled_balance;
+ balance = priv->starting_balance;
+ cleared_balance = priv->starting_cleared_balance;
+ reconciled_balance = priv->starting_reconciled_balance;
- PINFO ("acct=%s starting baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
- priv->accountName, balance.num, balance.denom);
- for(lp = priv->splits; lp; lp = lp->next)
- {
- Split *split = (Split *) lp->data;
- gnc_numeric amt = xaccSplitGetAmount (split);
+ PINFO ("acct=%s starting baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+ priv->accountName, balance.num, balance.denom);
+ for (lp = priv->splits; lp; lp = lp->next)
+ {
+ Split *split = (Split *) lp->data;
+ gnc_numeric amt = xaccSplitGetAmount (split);
- balance = gnc_numeric_add_fixed(balance, amt);
+ balance = gnc_numeric_add_fixed(balance, amt);
- if (NREC != split->reconciled)
- {
- cleared_balance = gnc_numeric_add_fixed(cleared_balance, amt);
- }
+ if (NREC != split->reconciled)
+ {
+ cleared_balance = gnc_numeric_add_fixed(cleared_balance, amt);
+ }
- if (YREC == split->reconciled ||
- FREC == split->reconciled)
- {
- reconciled_balance =
- gnc_numeric_add_fixed(reconciled_balance, amt);
- }
+ if (YREC == split->reconciled ||
+ FREC == split->reconciled)
+ {
+ reconciled_balance =
+ gnc_numeric_add_fixed(reconciled_balance, amt);
+ }
- split->balance = balance;
- split->cleared_balance = cleared_balance;
- split->reconciled_balance = reconciled_balance;
+ split->balance = balance;
+ split->cleared_balance = cleared_balance;
+ split->reconciled_balance = reconciled_balance;
- last_split = split;
- }
+ last_split = split;
+ }
- priv->balance = balance;
- priv->cleared_balance = cleared_balance;
- priv->reconciled_balance = reconciled_balance;
- priv->balance_dirty = FALSE;
+ priv->balance = balance;
+ priv->cleared_balance = cleared_balance;
+ priv->reconciled_balance = reconciled_balance;
+ priv->balance_dirty = FALSE;
}
/********************************************************************\
\********************************************************************/
-/* The sort order is used to implicitly define an
+/* The sort order is used to implicitly define an
* order for report generation */
-static int typeorder[NUM_ACCOUNT_TYPES] = {
- ACCT_TYPE_BANK, ACCT_TYPE_STOCK, ACCT_TYPE_MUTUAL, ACCT_TYPE_CURRENCY,
- ACCT_TYPE_CASH, ACCT_TYPE_ASSET, ACCT_TYPE_RECEIVABLE,
- ACCT_TYPE_CREDIT, ACCT_TYPE_LIABILITY, ACCT_TYPE_PAYABLE,
- ACCT_TYPE_INCOME, ACCT_TYPE_EXPENSE, ACCT_TYPE_EQUITY, ACCT_TYPE_TRADING };
+static int typeorder[NUM_ACCOUNT_TYPES] =
+{
+ ACCT_TYPE_BANK, ACCT_TYPE_STOCK, ACCT_TYPE_MUTUAL, ACCT_TYPE_CURRENCY,
+ ACCT_TYPE_CASH, ACCT_TYPE_ASSET, ACCT_TYPE_RECEIVABLE,
+ ACCT_TYPE_CREDIT, ACCT_TYPE_LIABILITY, ACCT_TYPE_PAYABLE,
+ ACCT_TYPE_INCOME, ACCT_TYPE_EXPENSE, ACCT_TYPE_EQUITY, ACCT_TYPE_TRADING
+};
-static int revorder[NUM_ACCOUNT_TYPES] = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
+static int revorder[NUM_ACCOUNT_TYPES] =
+{
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+};
int
-xaccAccountOrder (const Account *aa, const Account *ab)
+xaccAccountOrder (const Account *aa, const Account *ab)
{
- AccountPrivate *priv_aa, *priv_ab;
- char *da, *db;
- char *endptr = NULL;
- int ta, tb, result;
- long la, lb;
+ AccountPrivate *priv_aa, *priv_ab;
+ char *da, *db;
+ char *endptr = NULL;
+ int ta, tb, result;
+ long la, lb;
- if ( aa && !ab ) return -1;
- if ( !aa && ab ) return +1;
- if ( !aa && !ab ) return 0;
+ if ( aa && !ab ) return -1;
+ if ( !aa && ab ) return +1;
+ if ( !aa && !ab ) return 0;
- priv_aa = GET_PRIVATE(aa);
- priv_ab = GET_PRIVATE(ab);
+ priv_aa = GET_PRIVATE(aa);
+ priv_ab = GET_PRIVATE(ab);
- /* sort on accountCode strings */
- da = priv_aa->accountCode;
- db = priv_ab->accountCode;
+ /* sort on accountCode strings */
+ da = priv_aa->accountCode;
+ db = priv_ab->accountCode;
- /* If accountCodes are both base 36 integers do an integer sort */
- la = strtoul (da, &endptr, 36);
- if((*da != '\0') && (*endptr == '\0')) {
- lb = strtoul (db, &endptr, 36);
- if((*db != '\0') && (*endptr == '\0')) {
- if (la < lb) return -1;
- if (la > lb) return +1;
+ /* If accountCodes are both base 36 integers do an integer sort */
+ la = strtoul (da, &endptr, 36);
+ if ((*da != '\0') && (*endptr == '\0'))
+ {
+ lb = strtoul (db, &endptr, 36);
+ if ((*db != '\0') && (*endptr == '\0'))
+ {
+ if (la < lb) return -1;
+ if (la > lb) return +1;
+ }
}
- }
- /* Otherwise do a string sort */
- result = safe_strcmp (da, db);
- if (result)
- return result;
+ /* Otherwise do a string sort */
+ result = safe_strcmp (da, db);
+ if (result)
+ return result;
- /* if acccount-type-order array not initialized, initialize it */
- /* this will happen at most once during program invocation */
- if (-1 == revorder[0]) {
- int i;
- for (i=0; i<NUM_ACCOUNT_TYPES; i++) {
- revorder [typeorder[i]] = i;
+ /* if acccount-type-order array not initialized, initialize it */
+ /* this will happen at most once during program invocation */
+ if (-1 == revorder[0])
+ {
+ int i;
+ for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
+ {
+ revorder [typeorder[i]] = i;
+ }
}
- }
- /* otherwise, sort on account type */
- ta = priv_aa->type;
- tb = priv_ab->type;
- ta = revorder[ta];
- tb = revorder[tb];
- if (ta < tb) return -1;
- if (ta > tb) return +1;
+ /* otherwise, sort on account type */
+ ta = priv_aa->type;
+ tb = priv_ab->type;
+ ta = revorder[ta];
+ tb = revorder[tb];
+ if (ta < tb) return -1;
+ if (ta > tb) return +1;
- /* otherwise, sort on accountName strings */
- da = priv_aa->accountName;
- db = priv_ab->accountName;
- result = safe_utf8_collate(da, db);
- if (result)
- return result;
+ /* otherwise, sort on accountName strings */
+ da = priv_aa->accountName;
+ db = priv_ab->accountName;
+ result = safe_utf8_collate(da, db);
+ if (result)
+ return result;
- /* guarantee a stable sort */
- return qof_instance_guid_compare(aa, ab);
+ /* guarantee a stable sort */
+ return qof_instance_guid_compare(aa, ab);
}
static int
qof_xaccAccountOrder (const Account **aa, const Account **ab)
{
- return xaccAccountOrder(*aa, *ab);
+ return xaccAccountOrder(*aa, *ab);
}
/********************************************************************\
\********************************************************************/
-void
-xaccAccountSetType (Account *acc, GNCAccountType tip)
+void
+xaccAccountSetType (Account *acc, GNCAccountType tip)
{
- AccountPrivate *priv;
+ AccountPrivate *priv;
- /* errors */
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
- g_return_if_fail(tip < NUM_ACCOUNT_TYPES);
+ /* errors */
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(tip < NUM_ACCOUNT_TYPES);
- /* optimizations */
- priv = GET_PRIVATE(acc);
- if (priv->type == tip)
- return;
+ /* optimizations */
+ priv = GET_PRIVATE(acc);
+ if (priv->type == tip)
+ return;
- xaccAccountBeginEdit(acc);
- priv->type = tip;
- priv->balance_dirty = TRUE; /* new type may affect balance computation */
- mark_account(acc);
- xaccAccountCommitEdit(acc);
+ xaccAccountBeginEdit(acc);
+ priv->type = tip;
+ priv->balance_dirty = TRUE; /* new type may affect balance computation */
+ mark_account(acc);
+ xaccAccountCommitEdit(acc);
}
-void
-xaccAccountSetName (Account *acc, const char *str)
+void
+xaccAccountSetName (Account *acc, const char *str)
{
AccountPrivate *priv;
@@ -2047,7 +2070,7 @@
/* optimizations */
priv = GET_PRIVATE(acc);
if (str == priv->accountName)
- return;
+ return;
xaccAccountBeginEdit(acc);
CACHE_REPLACE(priv->accountName, str);
@@ -2055,8 +2078,8 @@
xaccAccountCommitEdit(acc);
}
-void
-xaccAccountSetCode (Account *acc, const char *str)
+void
+xaccAccountSetCode (Account *acc, const char *str)
{
AccountPrivate *priv;
@@ -2066,7 +2089,7 @@
/* optimizations */
priv = GET_PRIVATE(acc);
if (str == priv->accountCode)
- return;
+ return;
xaccAccountBeginEdit(acc);
CACHE_REPLACE(priv->accountCode, str ? str : "");
@@ -2075,7 +2098,7 @@
}
void
-xaccAccountSetDescription (Account *acc, const char *str)
+xaccAccountSetDescription (Account *acc, const char *str)
{
AccountPrivate *priv;
@@ -2085,7 +2108,7 @@
/* optimizations */
priv = GET_PRIVATE(acc);
if (str == priv->description)
- return;
+ return;
xaccAccountBeginEdit(acc);
CACHE_REPLACE(priv->description, str ? str : "");
@@ -2094,97 +2117,103 @@
}
void
-xaccAccountSetColor (Account *acc, const char *str)
+xaccAccountSetColor (Account *acc, const char *str)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- xaccAccountBeginEdit(acc);
- if (str) {
- gchar *tmp = g_strstrip(g_strdup(str));
- kvp_frame_set_slot_nc(acc->inst.kvp_data, "color",
- strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
- g_free(tmp);
- } else {
- kvp_frame_set_slot_nc(acc->inst.kvp_data, "color", NULL);
- }
+ xaccAccountBeginEdit(acc);
+ if (str)
+ {
+ gchar *tmp = g_strstrip(g_strdup(str));
+ kvp_frame_set_slot_nc(acc->inst.kvp_data, "color",
+ strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
+ g_free(tmp);
+ }
+ else
+ {
+ kvp_frame_set_slot_nc(acc->inst.kvp_data, "color", NULL);
+ }
mark_account (acc);
xaccAccountCommitEdit(acc);
}
static void
-qofAccountSetParent (Account *acc, QofInstance *parent)
+qofAccountSetParent (Account *acc, QofInstance *parent)
{
- Account *parent_acc;
-
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
- g_return_if_fail(GNC_IS_ACCOUNT(parent));
+ Account *parent_acc;
- parent_acc = GNC_ACCOUNT(parent);
- xaccAccountBeginEdit(acc);
- xaccAccountBeginEdit(parent_acc);
- gnc_account_append_child(parent_acc, acc);
- mark_account (parent_acc);
- mark_account (acc);
- xaccAccountCommitEdit(acc);
- xaccAccountCommitEdit(parent_acc);
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(parent));
+
+ parent_acc = GNC_ACCOUNT(parent);
+ xaccAccountBeginEdit(acc);
+ xaccAccountBeginEdit(parent_acc);
+ gnc_account_append_child(parent_acc, acc);
+ mark_account (parent_acc);
+ mark_account (acc);
+ xaccAccountCommitEdit(acc);
+ xaccAccountCommitEdit(parent_acc);
}
void
-xaccAccountSetNotes (Account *acc, const char *str)
+xaccAccountSetNotes (Account *acc, const char *str)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- xaccAccountBeginEdit(acc);
- if (str) {
- gchar *tmp = g_strstrip(g_strdup(str));
- kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes",
- strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
- g_free(tmp);
- } else {
- kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes", NULL);
- }
- mark_account(acc);
- xaccAccountCommitEdit(acc);
+ xaccAccountBeginEdit(acc);
+ if (str)
+ {
+ gchar *tmp = g_strstrip(g_strdup(str));
+ kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes",
+ strlen(tmp) ? kvp_value_new_string(tmp) : NULL);
+ g_free(tmp);
+ }
+ else
+ {
+ kvp_frame_set_slot_nc(acc->inst.kvp_data, "notes", NULL);
+ }
+ mark_account(acc);
+ xaccAccountCommitEdit(acc);
}
-void
-xaccAccountSetCommodity (Account * acc, gnc_commodity * com)
+void
+xaccAccountSetCommodity (Account * acc, gnc_commodity * com)
{
- AccountPrivate *priv;
- GList *lp;
+ AccountPrivate *priv;
+ GList *lp;
- /* errors */
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
- g_return_if_fail(GNC_IS_COMMODITY(com));
+ /* errors */
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_COMMODITY(com));
- /* optimizations */
- priv = GET_PRIVATE(acc);
- if (com == priv->commodity)
- return;
+ /* optimizations */
+ priv = GET_PRIVATE(acc);
+ if (com == priv->commodity)
+ return;
- xaccAccountBeginEdit(acc);
- gnc_commodity_decrement_usage_count(priv->commodity);
- priv->commodity = com;
- gnc_commodity_increment_usage_count(com);
- priv->commodity_scu = gnc_commodity_get_fraction(com);
- priv->non_standard_scu = FALSE;
+ xaccAccountBeginEdit(acc);
+ gnc_commodity_decrement_usage_count(priv->commodity);
+ priv->commodity = com;
+ gnc_commodity_increment_usage_count(com);
+ priv->commodity_scu = gnc_commodity_get_fraction(com);
+ priv->non_standard_scu = FALSE;
- /* iterate over splits */
- for (lp = priv->splits; lp; lp = lp->next)
- {
- Split *s = (Split *) lp->data;
- Transaction *trans = xaccSplitGetParent (s);
+ /* iterate over splits */
+ for (lp = priv->splits; lp; lp = lp->next)
+ {
+ Split *s = (Split *) lp->data;
+ Transaction *trans = xaccSplitGetParent (s);
- xaccTransBeginEdit (trans);
- xaccSplitSetAmount (s, xaccSplitGetAmount(s));
- xaccTransCommitEdit (trans);
- }
+ xaccTransBeginEdit (trans);
+ xaccSplitSetAmount (s, xaccSplitGetAmount(s));
+ xaccTransCommitEdit (trans);
+ }
- priv->sort_dirty = TRUE; /* Not needed. */
- priv->balance_dirty = TRUE;
- mark_account (acc);
+ priv->sort_dirty = TRUE; /* Not needed. */
+ priv->balance_dirty = TRUE;
+ mark_account (acc);
- xaccAccountCommitEdit(acc);
+ xaccAccountCommitEdit(acc);
}
/*
@@ -2196,17 +2225,17 @@
void
xaccAccountSetCommoditySCU (Account *acc, int scu)
{
- AccountPrivate *priv;
+ AccountPrivate *priv;
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- priv = GET_PRIVATE(acc);
- xaccAccountBeginEdit(acc);
- priv->commodity_scu = scu;
- if (scu != gnc_commodity_get_fraction(priv->commodity))
- priv->non_standard_scu = TRUE;
- mark_account(acc);
- xaccAccountCommitEdit(acc);
+ priv = GET_PRIVATE(acc);
+ xaccAccountBeginEdit(acc);
+ priv->commodity_scu = scu;
+ if (scu != gnc_commodity_get_fraction(priv->commodity))
+ priv->non_standard_scu = TRUE;
+ mark_account(acc);
+ xaccAccountCommitEdit(acc);
}
int
@@ -2225,24 +2254,24 @@
priv = GET_PRIVATE(acc);
if (priv->non_standard_scu || !priv->commodity)
- return priv->commodity_scu;
+ return priv->commodity_scu;
return gnc_commodity_get_fraction(priv->commodity);
}
void
xaccAccountSetNonStdSCU (Account *acc, gboolean flag)
{
- AccountPrivate *priv;
+ AccountPrivate *priv;
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- priv = GET_PRIVATE(acc);
- if (priv->non_standard_scu == flag)
- return;
- xaccAccountBeginEdit(acc);
- priv->non_standard_scu = flag;
- mark_account (acc);
- xaccAccountCommitEdit(acc);
+ priv = GET_PRIVATE(acc);
+ if (priv->non_standard_scu == flag)
+ return;
+ xaccAccountBeginEdit(acc);
+ priv->non_standard_scu = flag;
+ mark_account (acc);
+ xaccAccountCommitEdit(acc);
}
gboolean
@@ -2256,28 +2285,28 @@
\********************************************************************/
/* below follow the old, deprecated currency/security routines. */
-void
+void
DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency)
{
- QofBook *book;
- const char *string;
- gnc_commodity *commodity;
+ QofBook *book;
+ const char *string;
+ gnc_commodity *commodity;
- if ((!acc) || (!currency)) return;
+ if ((!acc) || (!currency)) return;
- xaccAccountBeginEdit(acc);
- string = gnc_commodity_get_unique_name (currency);
- kvp_frame_set_slot_nc(acc->inst.kvp_data, "old-currency",
- kvp_value_new_string(string));
- mark_account (acc);
- xaccAccountCommitEdit(acc);
+ xaccAccountBeginEdit(acc);
+ string = gnc_commodity_get_unique_name (currency);
+ kvp_frame_set_slot_nc(acc->inst.kvp_data, "old-currency",
+ kvp_value_new_string(string));
+ mark_account (acc);
+ xaccAccountCommitEdit(acc);
- commodity = DxaccAccountGetCurrency (acc);
- if (!commodity)
- {
- book = qof_instance_get_book(acc);
- gnc_commodity_table_insert (gnc_commodity_table_get_table (book), currency);
- }
+ commodity = DxaccAccountGetCurrency (acc);
+ if (!commodity)
+ {
+ book = qof_instance_get_book(acc);
+ gnc_commodity_table_insert (gnc_commodity_table_get_table (book), currency);
+ }
}
/********************************************************************\
@@ -2286,97 +2315,99 @@
void
gnc_account_append_child (Account *new_parent, Account *child)
{
- AccountPrivate *ppriv, *cpriv;
- Account *old_parent;
- QofCollection *col;
+ AccountPrivate *ppriv, *cpriv;
+ Account *old_parent;
+ QofCollection *col;
- /* errors */
- g_assert(GNC_IS_ACCOUNT(new_parent));
- g_assert(GNC_IS_ACCOUNT(child));
+ /* errors */
+ g_assert(GNC_IS_ACCOUNT(new_parent));
+ g_assert(GNC_IS_ACCOUNT(child));
- /* optimizations */
- ppriv = GET_PRIVATE(new_parent);
- cpriv = GET_PRIVATE(child);
- old_parent = cpriv->parent;
- if (old_parent == new_parent)
- return;
+ /* optimizations */
+ ppriv = GET_PRIVATE(new_parent);
+ cpriv = GET_PRIVATE(child);
+ old_parent = cpriv->parent;
+ if (old_parent == new_parent)
+ return;
- // xaccAccountBeginEdit(new_parent);
- xaccAccountBeginEdit(child);
- if (old_parent) {
- gnc_account_remove_child(old_parent, child);
+ // xaccAccountBeginEdit(new_parent);
+ xaccAccountBeginEdit(child);
+ if (old_parent)
+ {
+ gnc_account_remove_child(old_parent, child);
- if (!qof_instance_books_equal(old_parent, new_parent)) {
- /* hack alert -- this implementation is not exactly correct.
- * If the entity tables are not identical, then the 'from' book
- * may have a different backend than the 'to' book. This means
- * that we should get the 'from' backend to destroy this account,
- * and the 'to' backend to save it. Right now, this is broken.
- *
- * A 'correct' implementation similar to this is in Period.c
- * except its for transactions ...
- *
- * Note also, we need to reparent the children to the new book as well.
- */
- PWARN ("reparenting accounts across books is not correctly supported\n");
+ if (!qof_instance_books_equal(old_parent, new_parent))
+ {
+ /* hack alert -- this implementation is not exactly correct.
+ * If the entity tables are not identical, then the 'from' book
+ * may have a different backend than the 'to' book. This means
+ * that we should get the 'from' backend to destroy this account,
+ * and the 'to' backend to save it. Right now, this is broken.
+ *
+ * A 'correct' implementation similar to this is in Period.c
+ * except its for transactions ...
+ *
+ * Note also, we need to reparent the children to the new book as well.
+ */
+ PWARN ("reparenting accounts across books is not correctly supported\n");
- qof_event_gen (&child->inst, QOF_EVENT_DESTROY, NULL);
- col = qof_book_get_collection (qof_instance_get_book(new_parent),
- GNC_ID_ACCOUNT);
- qof_collection_insert_entity (col, &child->inst);
- qof_event_gen (&child->inst, QOF_EVENT_CREATE, NULL);
+ qof_event_gen (&child->inst, QOF_EVENT_DESTROY, NULL);
+ col = qof_book_get_collection (qof_instance_get_book(new_parent),
+ GNC_ID_ACCOUNT);
+ qof_collection_insert_entity (col, &child->inst);
+ qof_event_gen (&child->inst, QOF_EVENT_CREATE, NULL);
+ }
}
- }
- cpriv->parent = new_parent;
- ppriv->children = g_list_append(ppriv->children, child);
- qof_instance_set_dirty(&new_parent->inst);
- qof_instance_set_dirty(&child->inst);
+ cpriv->parent = new_parent;
+ ppriv->children = g_list_append(ppriv->children, child);
+ qof_instance_set_dirty(&new_parent->inst);
+ qof_instance_set_dirty(&child->inst);
- /* Send events data. Warning: The call to commit_edit is also gpoing
- * to send a MODIFY event. If the gtktreemodelfilter code gets the
- * MODIFY before it gets the ADD, it gets very confused and thinks
- * that two nodes have been added. */
- qof_event_gen (&child->inst, QOF_EVENT_ADD, NULL);
- // qof_event_gen (&new_parent->inst, QOF_EVENT_MODIFY, NULL);
+ /* Send events data. Warning: The call to commit_edit is also gpoing
+ * to send a MODIFY event. If the gtktreemodelfilter code gets the
+ * MODIFY before it gets the ADD, it gets very confused and thinks
+ * that two nodes have been added. */
+ qof_event_gen (&child->inst, QOF_EVENT_ADD, NULL);
+ // qof_event_gen (&new_parent->inst, QOF_EVENT_MODIFY, NULL);
- xaccAccountCommitEdit (child);
- // xaccAccountCommitEdit(new_parent);
+ xaccAccountCommitEdit (child);
+ // xaccAccountCommitEdit(new_parent);
}
void
gnc_account_remove_child (Account *parent, Account *child)
{
- AccountPrivate *ppriv, *cpriv;
- GncEventData ed;
+ AccountPrivate *ppriv, *cpriv;
+ GncEventData ed;
- if (!child) return;
+ if (!child) return;
- /* Note this routine might be called on accounts which
- * are not yet parented. */
- if (!parent) return;
+ /* Note this routine might be called on accounts which
+ * are not yet parented. */
+ if (!parent) return;
- ppriv = GET_PRIVATE(parent);
- cpriv = GET_PRIVATE(child);
+ ppriv = GET_PRIVATE(parent);
+ cpriv = GET_PRIVATE(child);
- if (cpriv->parent != parent)
- {
- PERR ("account not a child of parent");
- return;
- }
+ if (cpriv->parent != parent)
+ {
+ PERR ("account not a child of parent");
+ return;
+ }
- /* Gather event data */
- ed.node = parent;
- ed.idx = g_list_index(ppriv->children, child);
+ /* Gather event data */
+ ed.node = parent;
+ ed.idx = g_list_index(ppriv->children, child);
- ppriv->children = g_list_remove(ppriv->children, child);
+ ppriv->children = g_list_remove(ppriv->children, child);
- /* Now send the event. */
- qof_event_gen(&child->inst, QOF_EVENT_REMOVE, &ed);
+ /* Now send the event. */
+ qof_event_gen(&child->inst, QOF_EVENT_REMOVE, &ed);
- /* clear the account's parent pointer after REMOVE event generation. */
- cpriv->parent = NULL;
+ /* clear the account's parent pointer after REMOVE event generation. */
+ cpriv->parent = NULL;
- qof_event_gen (&parent->inst, QOF_EVENT_MODIFY, NULL);
+ qof_event_gen (&parent->inst, QOF_EVENT_MODIFY, NULL);
}
Account *
@@ -2394,12 +2425,13 @@
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
priv = GET_PRIVATE(acc);
- while (priv->parent) {
- acc = priv->parent;
- priv = GET_PRIVATE(acc);
+ while (priv->parent)
+ {
+ acc = priv->parent;
+ priv = GET_PRIVATE(acc);
}
- return acc;
+ return acc;
}
gboolean
@@ -2427,7 +2459,7 @@
/* optimizations */
priv = GET_PRIVATE(account);
if (!priv->children)
- return NULL;
+ return NULL;
return g_list_sort(g_list_copy(priv->children), (GCompareFunc)xaccAccountOrder);
}
@@ -2463,8 +2495,9 @@
g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
priv = GET_PRIVATE(account);
- for (node = priv->children; node; node = g_list_next(node)) {
- count += gnc_account_n_descendants(node->data) + 1;
+ for (node = priv->children; node; node = g_list_next(node))
+ {
+ count += gnc_account_n_descendants(node->data) + 1;
}
return count;
}
@@ -2478,10 +2511,11 @@
g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
priv = GET_PRIVATE(account);
- while (priv->parent && (priv->type != ACCT_TYPE_ROOT)) {
- account = priv->parent;
- priv = GET_PRIVATE(account);
- depth++;
+ while (priv->parent && (priv->type != ACCT_TYPE_ROOT))
+ {
+ account = priv->parent;
+ priv = GET_PRIVATE(account);
+ depth++;
}
return depth;
@@ -2490,133 +2524,136 @@
gint
gnc_account_get_tree_depth (const Account *account)
{
- AccountPrivate *priv;
- GList *node;
- gint depth = 0, child_depth;
+ AccountPrivate *priv;
+ GList *node;
+ gint depth = 0, child_depth;
- g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(account), 0);
- priv = GET_PRIVATE(account);
- if (!priv->children)
- return 1;
+ priv = GET_PRIVATE(account);
+ if (!priv->children)
+ return 1;
- for (node = priv->children; node; node = g_list_next(node)) {
- child_depth = gnc_account_get_tree_depth(node->data);
- depth = MAX(depth, child_depth);
- }
- return depth + 1;
+ for (node = priv->children; node; node = g_list_next(node))
+ {
+ child_depth = gnc_account_get_tree_depth(node->data);
+ depth = MAX(depth, child_depth);
+ }
+ return depth + 1;
}
GList *
gnc_account_get_descendants (const Account *account)
{
- AccountPrivate *priv;
- GList *child, *descendants;
+ AccountPrivate *priv;
+ GList *child, *descendants;
- g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
- priv = GET_PRIVATE(account);
- if (!priv->children)
- return NULL;
+ priv = GET_PRIVATE(account);
+ if (!priv->children)
+ return NULL;
- descendants = NULL;
- for (child = priv->children; child; child = g_list_next(child)) {
- descendants = g_list_append(descendants, child->data);
- descendants = g_list_concat(descendants,
- gnc_account_get_descendants(child->data));
- }
- return descendants;
+ descendants = NULL;
+ for (child = priv->children; child; child = g_list_next(child))
+ {
+ descendants = g_list_append(descendants, child->data);
+ descendants = g_list_concat(descendants,
+ gnc_account_get_descendants(child->data));
+ }
+ return descendants;
}
GList *
gnc_account_get_descendants_sorted (const Account *account)
{
- AccountPrivate *priv;
- GList *child, *children, *descendants;
+ AccountPrivate *priv;
+ GList *child, *children, *descendants;
- /* errors */
- g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
+ /* errors */
+ g_return_val_if_fail(GNC_IS_ACCOUNT(account), NULL);
- /* optimizations */
- priv = GET_PRIVATE(account);
- if (!priv->children)
- return NULL;
+ /* optimizations */
+ priv = GET_PRIVATE(account);
+ if (!priv->children)
+ return NULL;
- descendants = NULL;
- children = g_list_sort(g_list_copy(priv->children), (GCompareFunc)xaccAccountOrder);
- for (child = children; child; child = g_list_next(child)) {
- descendants = g_list_append(descendants, child->data);
- descendants = g_list_concat(descendants,
- gnc_account_get_descendants(child->data));
- }
- g_list_free(children);
- return descendants;
+ descendants = NULL;
+ children = g_list_sort(g_list_copy(priv->children), (GCompareFunc)xaccAccountOrder);
+ for (child = children; child; child = g_list_next(child))
+ {
+ descendants = g_list_append(descendants, child->data);
+ descendants = g_list_concat(descendants,
+ gnc_account_get_descendants(child->data));
+ }
+ g_list_free(children);
+ return descendants;
}
Account *
gnc_account_lookup_by_name (const Account *parent, const char * name)
{
- AccountPrivate *cpriv, *ppriv;
- Account *child, *result;
- GList *node;
+ AccountPrivate *cpriv, *ppriv;
+ Account *child, *result;
+ GList *node;
- g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
- g_return_val_if_fail(name, NULL);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
+ g_return_val_if_fail(name, NULL);
- /* first, look for accounts hanging off the current node */
- ppriv = GET_PRIVATE(parent);
- for (node = ppriv->children; node; node = node->next)
- {
- child = node->data;
- cpriv = GET_PRIVATE(child);
- if (safe_strcmp(cpriv->accountName, name) == 0)
- return child;
- }
+ /* first, look for accounts hanging off the current node */
+ ppriv = GET_PRIVATE(parent);
+ for (node = ppriv->children; node; node = node->next)
+ {
+ child = node->data;
+ cpriv = GET_PRIVATE(child);
+ if (safe_strcmp(cpriv->accountName, name) == 0)
+ return child;
+ }
- /* if we are still here, then we haven't found the account yet.
- * Recursively search each of the child accounts next */
- for (node = ppriv->children; node; node = node->next)
- {
- child = node->data;
- result = gnc_account_lookup_by_name (child, name);
- if (result)
- return result;
- }
+ /* if we are still here, then we haven't found the account yet.
+ * Recursively search each of the child accounts next */
+ for (node = ppriv->children; node; node = node->next)
+ {
+ child = node->data;
+ result = gnc_account_lookup_by_name (child, name);
+ if (result)
+ return result;
+ }
- return NULL;
+ return NULL;
}
Account *
gnc_account_lookup_by_code (const Account *parent, const char * code)
{
- AccountPrivate *cpriv, *ppriv;
- Account *child, *result;
- GList *node;
+ AccountPrivate *cpriv, *ppriv;
+ Account *child, *result;
+ GList *node;
- g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
- g_return_val_if_fail(code, NULL);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
+ g_return_val_if_fail(code, NULL);
- /* first, look for accounts hanging off the current node */
- ppriv = GET_PRIVATE(parent);
- for (node = ppriv->children; node; node = node->next)
- {
- child = node->data;
- cpriv = GET_PRIVATE(child);
- if (safe_strcmp(cpriv->accountCode, code) == 0)
- return child;
- }
+ /* first, look for accounts hanging off the current node */
+ ppriv = GET_PRIVATE(parent);
+ for (node = ppriv->children; node; node = node->next)
+ {
+ child = node->data;
+ cpriv = GET_PRIVATE(child);
+ if (safe_strcmp(cpriv->accountCode, code) == 0)
+ return child;
+ }
- /* if we are still here, then we haven't found the account yet.
- * Recursively search each of the child accounts next */
- for (node = ppriv->children; node; node = node->next)
- {
- child = node->data;
- result = gnc_account_lookup_by_code (child, code);
- if (result)
- return result;
- }
+ /* if we are still here, then we haven't found the account yet.
+ * Recursively search each of the child accounts next */
+ for (node = ppriv->children; node; node = node->next)
+ {
+ child = node->data;
+ result = gnc_account_lookup_by_code (child, code);
+ if (result)
+ return result;
+ }
- return NULL;
+ return NULL;
}
/********************************************************************\
@@ -2625,71 +2662,75 @@
static Account *
gnc_account_lookup_by_full_name_helper (const Account *parent,
- gchar **names)
+ gchar **names)
{
- const AccountPrivate *priv, *ppriv;
- Account *found;
- GList *node;
+ const AccountPrivate *priv, *ppriv;
+ Account *found;
+ GList *node;
- g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
- g_return_val_if_fail(names, NULL);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
+ g_return_val_if_fail(names, NULL);
- /* Look for the first name in the children. */
- ppriv = GET_PRIVATE(parent);
- for (node = ppriv->children; node; node = node->next) {
- Account *account = node->data;
+ /* Look for the first name in the children. */
+ ppriv = GET_PRIVATE(parent);
+ for (node = ppriv->children; node; node = node->next)
+ {
+ Account *account = node->data;
- priv = GET_PRIVATE(account);
- if (safe_strcmp(priv->accountName, names[0]) == 0) {
- /* We found an account. If the next entry is NULL, there is
- * nothing left in the name, so just return the account. */
- if (names[1] == NULL)
- return account;
+ priv = GET_PRIVATE(account);
+ if (safe_strcmp(priv->accountName, names[0]) == 0)
+ {
+ /* We found an account. If the next entry is NULL, there is
+ * nothing left in the name, so just return the account. */
+ if (names[1] == NULL)
+ return account;
- /* No children? We're done. */
- if (!priv->children)
- return NULL;
+ /* No children? We're done. */
+ if (!priv->children)
+ return NULL;
- /* There's stuff left to search for. Search recursively. */
- found = gnc_account_lookup_by_full_name_helper(account, &names[1]);
- if (found != NULL) {
- return found;
- }
+ /* There's stuff left to search for. Search recursively. */
+ found = gnc_account_lookup_by_full_name_helper(account, &names[1]);
+ if (found != NULL)
+ {
+ return found;
+ }
+ }
}
- }
- return NULL;
+ return NULL;
}
Account *
gnc_account_lookup_by_full_name (const Account *any_acc,
- const gchar *name)
+ const gchar *name)
{
- const AccountPrivate *rpriv;
- const Account *root;
- Account *found;
- gchar **names;
+ const AccountPrivate *rpriv;
+ const Account *root;
+ Account *found;
+ gchar **names;
- g_return_val_if_fail(GNC_IS_ACCOUNT(any_acc), NULL);
- g_return_val_if_fail(name, NULL);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(any_acc), NULL);
+ g_return_val_if_fail(name, NULL);
- root = any_acc;
- rpriv = GET_PRIVATE(root);
- while (rpriv->parent) {
- root = rpriv->parent;
+ root = any_acc;
rpriv = GET_PRIVATE(root);
- }
- names = g_strsplit(name, gnc_get_account_separator_string(), -1);
- found = gnc_account_lookup_by_full_name_helper(root, names);
- g_strfreev(names);
- return found;
+ while (rpriv->parent)
+ {
+ root = rpriv->parent;
+ rpriv = GET_PRIVATE(root);
+ }
+ names = g_strsplit(name, gnc_get_account_separator_string(), -1);
+ found = gnc_account_lookup_by_full_name_helper(root, names);
+ g_strfreev(names);
+ return found;
}
void
gnc_account_foreach_child (const Account *acc,
- AccountCb thunk,
- gpointer user_data)
+ AccountCb thunk,
+ gpointer user_data)
{
const AccountPrivate *priv;
GList *node;
@@ -2698,15 +2739,16 @@
g_return_if_fail(thunk);
priv = GET_PRIVATE(acc);
- for (node = priv->children; node; node = node->next) {
- thunk (node->data, user_data);
+ for (node = priv->children; node; node = node->next)
+ {
+ thunk (node->data, user_data);
}
}
gpointer
gnc_account_foreach_child_until (const Account *acc,
- AccountCb2 thunk,
- gpointer user_data)
+ AccountCb2 thunk,
+ gpointer user_data)
{
const AccountPrivate *priv;
GList *node;
@@ -2716,10 +2758,11 @@
g_return_val_if_fail(thunk, NULL);
priv = GET_PRIVATE(acc);
- for (node = priv->children; node; node = node->next) {
- result = thunk (node->data, user_data);
- if (result)
- return(result);
+ for (node = priv->children; node; node = node->next)
+ {
+ result = thunk (node->data, user_data);
+ if (result)
+ return(result);
}
return NULL;
@@ -2727,8 +2770,8 @@
void
gnc_account_foreach_descendant (const Account *acc,
- AccountCb thunk,
- gpointer user_data)
+ AccountCb thunk,
+ gpointer user_data)
{
const AccountPrivate *priv;
GList *node;
@@ -2738,17 +2781,18 @@
g_return_if_fail(thunk);
priv = GET_PRIVATE(acc);
- for (node = priv->children; node; node = node->next) {
- child = node->data;
- thunk(child, user_data);
- gnc_account_foreach_descendant(child, thunk, user_data);
+ for (node = priv->children; node; node = node->next)
+ {
+ child = node->data;
+ thunk(child, user_data);
+ gnc_account_foreach_descendant(child, thunk, user_data);
}
}
gpointer
gnc_account_foreach_descendant_until (const Account *acc,
- AccountCb2 thunk,
- gpointer user_data)
+ AccountCb2 thunk,
+ gpointer user_data)
{
const AccountPrivate *priv;
GList *node;
@@ -2759,15 +2803,16 @@
g_return_val_if_fail(thunk, NULL);
priv = GET_PRIVATE(acc);
- for (node = priv->children; node; node = node->next) {
- child = node->data;
- result = thunk(child, user_data);
- if (result)
- return(result);
+ for (node = priv->children; node; node = node->next)
+ {
+ child = node->data;
+ result = thunk(child, user_data);
+ if (result)
+ return(result);
- result = gnc_account_foreach_descendant_until(child, thunk, user_data);
- if (result)
- return(result);
+ result = gnc_account_foreach_descendant_until(child, thunk, user_data);
+ if (result)
+ return(result);
}
return NULL;
@@ -2791,9 +2836,9 @@
static void
qofAccountSetType (Account *acc, const char *type_string)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
- g_return_if_fail(type_string);
- xaccAccountSetType(acc, xaccAccountStringToEnum(type_string));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(type_string);
+ xaccAccountSetType(acc, xaccAccountStringToEnum(type_string));
}
const char *
@@ -2806,47 +2851,49 @@
gchar *
gnc_account_get_full_name(const Account *account)
{
- AccountPrivate *priv;
- const Account *a;
- char *fullname;
- gchar **names;
- int level;
+ AccountPrivate *priv;
+ const Account *a;
+ char *fullname;
+ gchar **names;
+ int level;
- /* So much for hardening the API. Too many callers to this function don't
- * bother to check if they have a non-NULL pointer before calling. */
- if (NULL == account)
- return g_strdup("");
+ /* So much for hardening the API. Too many callers to this function don't
+ * bother to check if they have a non-NULL pointer before calling. */
+ if (NULL == account)
+ return g_strdup("");
- /* errors */
- g_return_val_if_fail(GNC_IS_ACCOUNT(account), g_strdup(""));
+ /* errors */
+ g_return_val_if_fail(GNC_IS_ACCOUNT(account), g_strdup(""));
- /* optimizations */
- priv = GET_PRIVATE(account);
- if (!priv->parent)
- return g_strdup("");
+ /* optimizations */
+ priv = GET_PRIVATE(account);
+ if (!priv->parent)
+ return g_strdup("");
- /* Figure out how much space is needed by counting the nodes up to
- * the root. */
- level = 0;
- for (a = account; a; a = priv->parent) {
- priv = GET_PRIVATE(a);
- level++;
- }
+ /* Figure out how much space is needed by counting the nodes up to
+ * the root. */
+ level = 0;
+ for (a = account; a; a = priv->parent)
+ {
+ priv = GET_PRIVATE(a);
+ level++;
+ }
- /* Get all the pointers in the right order. The root node "entry"
- * becomes the terminating NULL pointer for the array of strings. */
- names = g_malloc(level * sizeof(gchar *));
- names[--level] = NULL;
- for (a = account; level > 0; a = priv->parent) {
- priv = GET_PRIVATE(a);
- names[--level] = priv->accountName;
- }
+ /* Get all the pointers in the right order. The root node "entry"
+ * becomes the terminating NULL pointer for the array of strings. */
+ names = g_malloc(level * sizeof(gchar *));
+ names[--level] = NULL;
+ for (a = account; level > 0; a = priv->parent)
+ {
+ priv = GET_PRIVATE(a);
+ names[--level] = priv->accountName;
+ }
- /* Build the full name */
- fullname = g_strjoinv(account_separator, names);
- g_free(names);
+ /* Build the full name */
+ fullname = g_strjoinv(account_separator, names);
+ g_free(names);
- return fullname;
+ return fullname;
}
const char *
@@ -2856,48 +2903,48 @@
return GET_PRIVATE(acc)->accountCode;
}
-const char *
+const char *
xaccAccountGetDescription (const Account *acc)
{
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
return GET_PRIVATE(acc)->description;
}
-const char *
+const char *
xaccAccountGetColor (const Account *acc)
{
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
return acc ? kvp_frame_get_string(acc->inst.kvp_data, "color") : NULL;
}
-const char *
-xaccAccountGetNotes (const Account *acc)
+const char *
+xaccAccountGetNotes (const Account *acc)
{
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
return acc ? kvp_frame_get_string(acc->inst.kvp_data, "notes") : NULL;
}
-gnc_commodity *
+gnc_commodity *
DxaccAccountGetCurrency (const Account *acc)
{
- KvpValue *v;
- const char *s;
- gnc_commodity_table *table;
+ KvpValue *v;
+ const char *s;
+ gnc_commodity_table *table;
- if (!acc) return NULL;
+ if (!acc) return NULL;
- v = kvp_frame_get_slot(acc->inst.kvp_data, "old-currency");
- if (!v) return NULL;
+ v = kvp_frame_get_slot(acc->inst.kvp_data, "old-currency");
+ if (!v) return NULL;
- s = kvp_value_get_string (v);
- if (!s) return NULL;
+ s = kvp_value_get_string (v);
+ if (!s) return NULL;
- table = gnc_commodity_table_get_table (qof_instance_get_book(acc));
+ table = gnc_commodity_table_get_table (qof_instance_get_book(acc));
- return gnc_commodity_table_lookup_unique (table, s);
+ return gnc_commodity_table_lookup_unique (table, s);
}
-gnc_commodity *
+gnc_commodity *
xaccAccountGetCommodity (const Account *acc)
{
if (!GNC_IS_ACCOUNT(acc))
@@ -2908,70 +2955,70 @@
/********************************************************************\
\********************************************************************/
-gnc_numeric
+gnc_numeric
gnc_account_get_start_balance (Account *acc)
{
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
- return GET_PRIVATE(acc)->starting_balance;
+ return GET_PRIVATE(acc)->starting_balance;
}
-void
+void
gnc_account_set_start_balance (Account *acc, const gnc_numeric start_baln)
{
- AccountPrivate *priv;
+ AccountPrivate *priv;
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- priv = GET_PRIVATE(acc);
- priv->starting_balance = start_baln;
- priv->balance_dirty = TRUE;
+ priv = GET_PRIVATE(acc);
+ priv->starting_balance = start_baln;
+ priv->balance_dirty = TRUE;
}
-gnc_numeric
+gnc_numeric
gnc_account_get_start_cleared_balance (Account *acc)
{
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
- return GET_PRIVATE(acc)->starting_cleared_balance;
+ return GET_PRIVATE(acc)->starting_cleared_balance;
}
-void
+void
gnc_account_set_start_cleared_balance (Account *acc,
- const gnc_numeric start_baln)
+ const gnc_numeric start_baln)
{
- AccountPrivate *priv;
+ AccountPrivate *priv;
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- priv = GET_PRIVATE(acc);
- priv->starting_cleared_balance = start_baln;
- priv->balance_dirty = TRUE;
+ priv = GET_PRIVATE(acc);
+ priv->starting_cleared_balance = start_baln;
+ priv->balance_dirty = TRUE;
}
-gnc_numeric
+gnc_numeric
gnc_account_get_start_reconciled_balance (Account *acc)
{
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
- return GET_PRIVATE(acc)->starting_reconciled_balance;
+ return GET_PRIVATE(acc)->starting_reconciled_balance;
}
-void
+void
gnc_account_set_start_reconciled_balance (Account *acc,
- const gnc_numeric start_baln)
+ const gnc_numeric start_baln)
{
- AccountPrivate *priv;
+ AccountPrivate *priv;
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- priv = GET_PRIVATE(acc);
- priv->starting_reconciled_balance = start_baln;
- priv->balance_dirty = TRUE;
+ priv = GET_PRIVATE(acc);
+ priv->starting_reconciled_balance = start_baln;
+ priv->balance_dirty = TRUE;
}
gnc_numeric
-xaccAccountGetBalance (const Account *acc)
+xaccAccountGetBalance (const Account *acc)
{
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
return GET_PRIVATE(acc)->balance;
@@ -2994,33 +3041,35 @@
gnc_numeric
xaccAccountGetProjectedMinimumBalance (const Account *acc)
{
- AccountPrivate *priv;
- GList *node;
- time_t today;
- gnc_numeric lowest = gnc_numeric_zero ();
- int seen_a_transaction = 0;
+ AccountPrivate *priv;
+ GList *node;
+ time_t today;
+ gnc_numeric lowest = gnc_numeric_zero ();
+ int seen_a_transaction = 0;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
- priv = GET_PRIVATE(acc);
- today = gnc_timet_get_today_end();
- for (node = g_list_last(priv->splits); node; node = node->prev)
- {
- Split *split = node->data;
+ priv = GET_PRIVATE(acc);
+ today = gnc_timet_get_today_end();
+ for (node = g_list_last(priv->splits); node; node = node->prev)
+ {
+ Split *split = node->data;
- if (!seen_a_transaction)
- {
- lowest = xaccSplitGetBalance (split);
- seen_a_transaction = 1;
- } else if (gnc_numeric_compare(xaccSplitGetBalance (split), lowest) < 0) {
- lowest = xaccSplitGetBalance (split);
+ if (!seen_a_transaction)
+ {
+ lowest = xaccSplitGetBalance (split);
+ seen_a_transaction = 1;
+ }
+ else if (gnc_numeric_compare(xaccSplitGetBalance (split), lowest) < 0)
+ {
+ lowest = xaccSplitGetBalance (split);
+ }
+
+ if (xaccTransGetDate (xaccSplitGetParent (split)) <= today)
+ return lowest;
}
- if (xaccTransGetDate (xaccSplitGetParent (split)) <= today)
- return lowest;
- }
-
- return lowest;
+ return lowest;
}
@@ -3030,70 +3079,73 @@
gnc_numeric
xaccAccountGetBalanceAsOfDate (Account *acc, time_t date)
{
- /* Ideally this could use xaccAccountForEachSplit, but
- * it doesn't exist yet and I'm uncertain of exactly how
- * it would work at this time, since it differs from
- * xaccAccountForEachTransaction by using gpointer return
- * values rather than gints.
- */
- AccountPrivate *priv;
- GList *lp;
- Timespec ts, trans_ts;
- gboolean found = FALSE;
- gnc_numeric balance;
+ /* Ideally this could use xaccAccountForEachSplit, but
+ * it doesn't exist yet and I'm uncertain of exactly how
+ * it would work at this time, since it differs from
+ * xaccAccountForEachTransaction by using gpointer return
+ * values rather than gints.
+ */
+ AccountPrivate *priv;
+ GList *lp;
+ Timespec ts, trans_ts;
+ gboolean found = FALSE;
+ gnc_numeric balance;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
- xaccAccountSortSplits (acc, TRUE); /* just in case, normally a noop */
- xaccAccountRecomputeBalance (acc); /* just in case, normally a noop */
+ xaccAccountSortSplits (acc, TRUE); /* just in case, normally a noop */
+ xaccAccountRecomputeBalance (acc); /* just in case, normally a noop */
- priv = GET_PRIVATE(acc);
- balance = priv->balance;
+ priv = GET_PRIVATE(acc);
+ balance = priv->balance;
- /* Since transaction post times are stored as a Timespec,
- * convert date into a Timespec as well rather than converting
- * each transaction's Timespec into a time_t.
- *
- * FIXME: CAS: I think this comment is a bogus justification for
- * using xaccTransGetDatePostedTS. There's no benefit to using
- * Timespec when the input argument is time_t, and it's hard to
- * imagine that casting long long to long and comparing two longs is
- * worse than comparing two long longs every time. IMO,
- * xaccAccountGetPresentBalance gets this right, and its algorithm
- * should be used here.
- */
- ts.tv_sec = date;
- ts.tv_nsec = 0;
+ /* Since transaction post times are stored as a Timespec,
+ * convert date into a Timespec as well rather than converting
+ * each transaction's Timespec into a time_t.
+ *
+ * FIXME: CAS: I think this comment is a bogus justification for
+ * using xaccTransGetDatePostedTS. There's no benefit to using
+ * Timespec when the input argument is time_t, and it's hard to
+ * imagine that casting long long to long and comparing two longs is
+ * worse than comparing two long longs every time. IMO,
+ * xaccAccountGetPresentBalance gets this right, and its algorithm
+ * should be used here.
+ */
+ ts.tv_sec = date;
+ ts.tv_nsec = 0;
- lp = priv->splits;
- while( lp && !found )
- {
- xaccTransGetDatePostedTS( xaccSplitGetParent( (Split *)lp->data ),
- &trans_ts );
- if( timespec_cmp( &trans_ts, &ts ) >= 0 )
- found = TRUE;
- else
- lp = lp->next;
- }
+ lp = priv->splits;
+ while ( lp && !found )
+ {
+ xaccTransGetDatePostedTS( xaccSplitGetParent( (Split *)lp->data ),
+ &trans_ts );
+ if ( timespec_cmp( &trans_ts, &ts ) >= 0 )
+ found = TRUE;
+ else
+ lp = lp->next;
+ }
- if( lp ) {
- if ( lp->prev ) {
- /* Since lp is now pointing to a split which was past the reconcile
- * date, get the running balance of the previous split.
- */
- balance = xaccSplitGetBalance( (Split *)lp->prev->data );
- }
- else {
- /* AsOf date must be before any entries, return zero. */
- balance = gnc_numeric_zero();
+ if ( lp )
+ {
+ if ( lp->prev )
+ {
+ /* Since lp is now pointing to a split which was past the reconcile
+ * date, get the running balance of the previous split.
+ */
+ balance = xaccSplitGetBalance( (Split *)lp->prev->data );
+ }
+ else
+ {
+ /* AsOf date must be before any entries, return zero. */
+ balance = gnc_numeric_zero();
+ }
}
- }
- /* Otherwise there were no splits posted after the given date,
- * so the latest account balance should be good enough.
- */
+ /* Otherwise there were no splits posted after the given date,
+ * so the latest account balance should be good enough.
+ */
- return( balance );
+ return( balance );
}
/*
@@ -3107,30 +3159,30 @@
gnc_numeric
xaccAccountGetPresentBalance (const Account *acc)
{
- AccountPrivate *priv;
- GList *node;
- time_t today;
+ AccountPrivate *priv;
+ GList *node;
+ time_t today;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), gnc_numeric_zero());
- priv = GET_PRIVATE(acc);
- today = gnc_timet_get_today_end();
- for (node = g_list_last(priv->splits); node; node = node->prev)
- {
- Split *split = node->data;
+ priv = GET_PRIVATE(acc);
+ today = gnc_timet_get_today_end();
+ for (node = g_list_last(priv->splits); node; node = node->prev)
+ {
+ Split *split = node->data;
- if (xaccTransGetDate (xaccSplitGetParent (split)) <= today)
- return xaccSplitGetBalance (split);
- }
+ if (xaccTransGetDate (xaccSplitGetParent (split)) <= today)
+ return xaccSplitGetBalance (split);
+ }
- return gnc_numeric_zero ();
+ return gnc_numeric_zero ();
}
/********************************************************************\
\********************************************************************/
/* XXX TODO: These 'GetBal' routines should be moved to some
- * utility area outside of the core account engine area.
+ * utility area outside of the core account engine area.
*/
/*
@@ -3138,24 +3190,24 @@
*/
gnc_numeric
xaccAccountConvertBalanceToCurrency(const Account *acc, /* for book */
- gnc_numeric balance,
- const gnc_commodity *balance_currency,
- const gnc_commodity *new_currency)
+ gnc_numeric balance,
+ const gnc_commodity *balance_currency,
+ const gnc_commodity *new_currency)
{
- QofBook *book;
- GNCPriceDB *pdb;
+ QofBook *book;
+ GNCPriceDB *pdb;
- if (gnc_numeric_zero_p (balance) ||
- gnc_commodity_equiv (balance_currency, new_currency))
- return balance;
+ if (gnc_numeric_zero_p (balance) ||
+ gnc_commodity_equiv (balance_currency, new_currency))
+ return balance;
- book = gnc_account_get_book (acc);
- pdb = gnc_pricedb_get_db (book);
+ book = gnc_account_get_book (acc);
+ pdb = gnc_pricedb_get_db (book);
- balance = gnc_pricedb_convert_balance_latest_price(
- pdb, balance, balance_currency, new_currency);
+ balance = gnc_pricedb_convert_balance_latest_price(
+ pdb, balance, balance_currency, new_currency);
- return balance;
+ return balance;
}
/*
@@ -3164,29 +3216,29 @@
*/
gnc_numeric
xaccAccountConvertBalanceToCurrencyAsOfDate(const Account *acc, /* for book */
- gnc_numeric balance,
- gnc_commodity *balance_currency,
- gnc_commodity *new_currency,
- time_t date)
+ gnc_numeric balance,
+ gnc_commodity *balance_currency,
+ gnc_commodity *new_currency,
+ time_t date)
{
- QofBook *book;
- GNCPriceDB *pdb;
- Timespec ts;
+ QofBook *book;
+ GNCPriceDB *pdb;
+ Timespec ts;
- if (gnc_numeric_zero_p (balance) ||
- gnc_commodity_equiv (balance_currency, new_currency))
- return balance;
+ if (gnc_numeric_zero_p (balance) ||
+ gnc_commodity_equiv (balance_currency, new_currency))
+ return balance;
- book = gnc_account_get_book (acc);
- pdb = gnc_book_get_pricedb (book);
+ book = gnc_account_get_book (acc);
+ pdb = gnc_book_get_pricedb (book);
- ts.tv_sec = date;
- ts.tv_nsec = 0;
+ ts.tv_sec = date;
+ ts.tv_nsec = 0;
- balance = gnc_pricedb_convert_balance_nearest_price(
- pdb, balance, balance_currency, new_currency, ts);
+ balance = gnc_pricedb_convert_balance_nearest_price(
+ pdb, balance, balance_currency, new_currency, ts);
- return balance;
+ return balance;
}
/*
@@ -3196,8 +3248,8 @@
*/
static gnc_numeric
xaccAccountGetXxxBalanceInCurrency (const Account *acc,
- xaccGetBalanceFn fn,
- const gnc_commodity *report_currency)
+ xaccGetBalanceFn fn,
+ const gnc_commodity *report_currency)
{
AccountPrivate *priv;
gnc_numeric balance;
@@ -3209,15 +3261,15 @@
priv = GET_PRIVATE(acc);
balance = fn(acc);
balance = xaccAccountConvertBalanceToCurrency(acc, balance,
- priv->commodity,
- report_currency);
+ priv->commodity,
+ report_currency);
return balance;
}
static gnc_numeric
xaccAccountGetXxxBalanceAsOfDateInCurrency(Account *acc, time_t date,
- xaccGetBalanceAsOfDateFn fn,
- const gnc_commodity *report_commodity)
+ xaccGetBalanceAsOfDateFn fn,
+ const gnc_commodity *report_commodity)
{
AccountPrivate *priv;
@@ -3227,7 +3279,7 @@
priv = GET_PRIVATE(acc);
return xaccAccountConvertBalanceToCurrency(
- acc, fn(acc, date), priv->commodity, report_commodity);
+ acc, fn(acc, date), priv->commodity, report_commodity);
}
/*
@@ -3235,11 +3287,11 @@
*/
typedef struct
{
- const gnc_commodity *currency;
- gnc_numeric balance;
- xaccGetBalanceFn fn;
- xaccGetBalanceAsOfDateFn asOfDateFn;
- time_t date;
+ const gnc_commodity *currency;
+ gnc_numeric balance;
+ xaccGetBalanceFn fn;
+ xaccGetBalanceAsOfDateFn asOfDateFn;
+ time_t date;
} CurrencyBalance;
@@ -3251,15 +3303,15 @@
static void
xaccAccountBalanceHelper (Account *acc, gpointer data)
{
- CurrencyBalance *cb = data;
- gnc_numeric balance;
+ CurrencyBalance *cb = data;
+ gnc_numeric balance;
- if (!cb->fn || !cb->currency)
- return;
- balance = xaccAccountGetXxxBalanceInCurrency (acc, cb->fn, cb->currency);
- cb->balance = gnc_numeric_add (cb->balance, balance,
- gnc_commodity_get_fraction (cb->currency),
- GNC_HOW_RND_ROUND);
+ if (!cb->fn || !cb->currency)
+ return;
+ balance = xaccAccountGetXxxBalanceInCurrency (acc, cb->fn, cb->currency);
+ cb->balance = gnc_numeric_add (cb->balance, balance,
+ gnc_commodity_get_fraction (cb->currency),
+ GNC_HOW_RND_ROUND);
}
static void
@@ -3271,7 +3323,7 @@
g_return_if_fail (cb->asOfDateFn && cb->currency);
balance = xaccAccountGetXxxBalanceAsOfDateInCurrency (
- acc, cb->date, cb->asOfDateFn, cb->currency);
+ acc, cb->date, cb->asOfDateFn, cb->currency);
cb->balance = gnc_numeric_add (cb->balance, balance,
gnc_commodity_get_fraction (cb->currency),
GNC_HOW_RND_ROUND);
@@ -3291,38 +3343,39 @@
*/
static gnc_numeric
xaccAccountGetXxxBalanceInCurrencyRecursive (const Account *acc,
- xaccGetBalanceFn fn,
- const gnc_commodity *report_commodity,
- gboolean include_children)
+ xaccGetBalanceFn fn,
+ const gnc_commodity *report_commodity,
+ gboolean include_children)
{
- gnc_numeric balance;
+ gnc_numeric balance;
- if (!acc) return gnc_numeric_zero ();
- if (!report_commodity)
- report_commodity = xaccAccountGetCommodity (acc);
- if (!report_commodity)
- return gnc_numeric_zero();
+ if (!acc) return gnc_numeric_zero ();
+ if (!report_commodity)
+ report_commodity = xaccAccountGetCommodity (acc);
+ if (!report_commodity)
+ return gnc_numeric_zero();
- balance = xaccAccountGetXxxBalanceInCurrency (acc, fn, report_commodity);
+ balance = xaccAccountGetXxxBalanceInCurrency (acc, fn, report_commodity);
- /* If needed, sum up the children converting to the *requested*
- commodity. */
- if (include_children) {
+ /* If needed, sum up the children converting to the *requested*
+ commodity. */
+ if (include_children)
+ {
#ifdef _MSC_VER
- /* MSVC compiler: Somehow, the struct initialization containing a
- gnc_numeric doesn't work. As an exception, we hand-initialize
- that member afterwards. */
- CurrencyBalance cb = { report_commodity, { 0 }, fn, NULL, 0 };
- cb.balance = balance;
+ /* MSVC compiler: Somehow, the struct initialization containing a
+ gnc_numeric doesn't work. As an exception, we hand-initialize
+ that member afterwards. */
+ CurrencyBalance cb = { report_commodity, { 0 }, fn, NULL, 0 };
+ cb.balance = balance;
#else
- CurrencyBalance cb = { report_commodity, balance, fn, NULL, 0 };
+ CurrencyBalance cb = { report_commodity, balance, fn, NULL, 0 };
#endif
- gnc_account_foreach_descendant (acc, xaccAccountBalanceHelper, &cb);
- balance = cb.balance;
- }
+ gnc_account_foreach_descendant (acc, xaccAccountBalanceHelper, &cb);
+ balance = cb.balance;
+ }
- return balance;
+ return balance;
}
static gnc_numeric
@@ -3330,47 +3383,48 @@
Account *acc, time_t date, xaccGetBalanceAsOfDateFn fn,
gnc_commodity *report_commodity, gboolean include_children)
{
- gnc_numeric balance;
+ gnc_numeric balance;
- g_return_val_if_fail(acc, gnc_numeric_zero());
- if (!report_commodity)
- report_commodity = xaccAccountGetCommodity (acc);
- if (!report_commodity)
- return gnc_numeric_zero();
+ g_return_val_if_fail(acc, gnc_numeric_zero());
+ if (!report_commodity)
+ report_commodity = xaccAccountGetCommodity (acc);
+ if (!report_commodity)
+ return gnc_numeric_zero();
- balance = xaccAccountGetXxxBalanceAsOfDateInCurrency(
- acc, date, fn, report_commodity);
+ balance = xaccAccountGetXxxBalanceAsOfDateInCurrency(
+ acc, date, fn, report_commodity);
- /* If needed, sum up the children converting to the *requested*
- commodity. */
- if (include_children) {
+ /* If needed, sum up the children converting to the *requested*
+ commodity. */
+ if (include_children)
+ {
#ifdef _MSC_VER
- /* MSVC compiler: Somehow, the struct initialization containing a
- gnc_numeric doesn't work. As an exception, we hand-initialize
- that member afterwards. */
- CurrencyBalance cb = { report_commodity, 0, NULL, fn, date };
- cb.balance = balance;
+ /* MSVC compiler: Somehow, the struct initialization containing a
+ gnc_numeric doesn't work. As an exception, we hand-initialize
+ that member afterwards. */
+ CurrencyBalance cb = { report_commodity, 0, NULL, fn, date };
+ cb.balance = balance;
#else
- CurrencyBalance cb = { report_commodity, balance, NULL, fn, date };
+ CurrencyBalance cb = { report_commodity, balance, NULL, fn, date };
#endif
- gnc_account_foreach_descendant (acc, xaccAccountBalanceAsOfDateHelper, &cb);
- balance = cb.balance;
- }
+ gnc_account_foreach_descendant (acc, xaccAccountBalanceAsOfDateHelper, &cb);
+ balance = cb.balance;
+ }
- return balance;
+ return balance;
}
gnc_numeric
-xaccAccountGetBalanceInCurrency (const Account *acc,
+xaccAccountGetBalanceInCurrency (const Account *acc,
const gnc_commodity *report_commodity,
- gboolean include_children)
+ gboolean include_children)
{
- gnc_numeric rc;
- rc = xaccAccountGetXxxBalanceInCurrencyRecursive (
- acc, xaccAccountGetBalance, report_commodity, include_children);
- PINFO(" baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, rc.num, rc.denom);
- return rc;
+ gnc_numeric rc;
+ rc = xaccAccountGetXxxBalanceInCurrencyRecursive (
+ acc, xaccAccountGetBalance, report_commodity, include_children);
+ PINFO(" baln=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, rc.num, rc.denom);
+ return rc;
}
@@ -3379,41 +3433,41 @@
const gnc_commodity *report_commodity,
gboolean include_children)
{
- return xaccAccountGetXxxBalanceInCurrencyRecursive (
- acc, xaccAccountGetClearedBalance, report_commodity,
- include_children);
+ return xaccAccountGetXxxBalanceInCurrencyRecursive (
+ acc, xaccAccountGetClearedBalance, report_commodity,
+ include_children);
}
gnc_numeric
xaccAccountGetReconciledBalanceInCurrency (const Account *acc,
- const gnc_commodity *report_commodity,
- gboolean include_children)
+ const gnc_commodity *report_commodity,
+ gboolean include_children)
{
- return xaccAccountGetXxxBalanceInCurrencyRecursive (
- acc, xaccAccountGetReconciledBalance, report_commodity,
- include_children);
+ return xaccAccountGetXxxBalanceInCurrencyRecursive (
+ acc, xaccAccountGetReconciledBalance, report_commodity,
+ include_children);
}
gnc_numeric
xaccAccountGetPresentBalanceInCurrency (const Account *acc,
- const gnc_commodity *report_commodity,
- gboolean include_children)
+ const gnc_commodity *report_commodity,
+ gboolean include_children)
{
- return xaccAccountGetXxxBalanceInCurrencyRecursive (
- acc, xaccAccountGetPresentBalance, report_commodity,
- include_children);
+ return xaccAccountGetXxxBalanceInCurrencyRecursive (
+ acc, xaccAccountGetPresentBalance, report_commodity,
+ include_children);
}
gnc_numeric
xaccAccountGetProjectedMinimumBalanceInCurrency (
- const Account *acc,
+ const Account *acc,
const gnc_commodity *report_commodity,
gboolean include_children)
{
- return xaccAccountGetXxxBalanceInCurrencyRecursive (
- acc, xaccAccountGetProjectedMinimumBalance, report_commodity,
- include_children);
+ return xaccAccountGetXxxBalanceInCurrencyRecursive (
+ acc, xaccAccountGetProjectedMinimumBalance, report_commodity,
+ include_children);
}
gnc_numeric
@@ -3422,18 +3476,18 @@
gboolean include_children)
{
return xaccAccountGetXxxBalanceAsOfDateInCurrencyRecursive (
- acc, date, xaccAccountGetBalanceAsOfDate, report_commodity,
- include_children);
+ acc, date, xaccAccountGetBalanceAsOfDate, report_commodity,
+ include_children);
}
gnc_numeric
xaccAccountGetBalanceChangeForPeriod (Account *acc, time_t t1, time_t t2, gboolean recurse)
{
- gnc_numeric b1, b2;
+ gnc_numeric b1, b2;
- b1 = xaccAccountGetBalanceAsOfDateInCurrency(acc, t1, NULL, recurse);
- b2 = xaccAccountGetBalanceAsOfDateInCurrency(acc, t2, NULL, recurse);
- return gnc_numeric_sub(b2, b1, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
+ b1 = xaccAccountGetBalanceAsOfDateInCurrency(acc, t1, NULL, recurse);
+ b2 = xaccAccountGetBalanceAsOfDateInCurrency(acc, t2, NULL, recurse);
+ return gnc_numeric_sub(b2, b1, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
}
@@ -3452,7 +3506,7 @@
/* XXX: violates the const'ness by forcing a sort before returning
* the splitlist */
SplitList *
-xaccAccountGetSplitList (const Account *acc)
+xaccAccountGetSplitList (const Account *acc)
{
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
xaccAccountSortSplits((Account*)acc, FALSE); // normally a noop
@@ -3460,7 +3514,7 @@
}
LotList *
-xaccAccountGetLotList (const Account *acc)
+xaccAccountGetLotList (const Account *acc)
{
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
return g_list_copy(GET_PRIVATE(acc)->lots);
@@ -3469,53 +3523,54 @@
LotList *
xaccAccountFindOpenLots (const Account *acc,
gboolean (*match_func)(GNCLot *lot,
- gpointer user_data),
+ gpointer user_data),
gpointer user_data, GCompareFunc sort_func)
{
- AccountPrivate *priv;
- GList *lot_list;
- GList *retval = NULL;
+ AccountPrivate *priv;
+ GList *lot_list;
+ GList *retval = NULL;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
- priv = GET_PRIVATE(acc);
- for (lot_list = priv->lots; lot_list; lot_list = lot_list->next) {
- GNCLot *lot = lot_list->data;
+ priv = GET_PRIVATE(acc);
+ for (lot_list = priv->lots; lot_list; lot_list = lot_list->next)
+ {
+ GNCLot *lot = lot_list->data;
- /* If this lot is closed, then ignore it */
- if (gnc_lot_is_closed (lot))
- continue;
+ /* If this lot is closed, then ignore it */
+ if (gnc_lot_is_closed (lot))
+ continue;
- if (match_func && !(match_func)(lot, user_data))
- continue;
+ if (match_func && !(match_func)(lot, user_data))
+ continue;
- /* Ok, this is a valid lot. Add it to our list of lots */
- if (sort_func)
- retval = g_list_insert_sorted (retval, lot, sort_func);
- else
- retval = g_list_prepend (retval, lot);
- }
+ /* Ok, this is a valid lot. Add it to our list of lots */
+ if (sort_func)
+ retval = g_list_insert_sorted (retval, lot, sort_func);
+ else
+ retval = g_list_prepend (retval, lot);
+ }
- return retval;
+ return retval;
}
gpointer
-xaccAccountForEachLot(const Account *acc,
- gpointer (*proc)(GNCLot *lot, void *data), void *data)
+xaccAccountForEachLot(const Account *acc,
+ gpointer (*proc)(GNCLot *lot, void *data), void *data)
{
- AccountPrivate *priv;
- LotList *node;
- gpointer result = NULL;
+ AccountPrivate *priv;
+ LotList *node;
+ gpointer result = NULL;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
- g_return_val_if_fail(proc, NULL);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
+ g_return_val_if_fail(proc, NULL);
- priv = GET_PRIVATE(acc);
- for (node = priv->lots; node; node = node->next)
- if ((result = proc((GNCLot *)node->data, data)))
- break;
-
- return result;
+ priv = GET_PRIVATE(acc);
+ for (node = priv->lots; node; node = node->next)
+ if ((result = proc((GNCLot *)node->data, data)))
+ break;
+
+ return result;
}
/********************************************************************\
@@ -3525,102 +3580,102 @@
gboolean
xaccAccountGetTaxRelated (const Account *acc)
{
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
- return kvp_frame_get_gint64(acc->inst.kvp_data, "tax-related");
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
+ return kvp_frame_get_gint64(acc->inst.kvp_data, "tax-related");
}
void
xaccAccountSetTaxRelated (Account *acc, gboolean tax_related)
{
- KvpValue *new_value;
+ KvpValue *new_value;
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- if (tax_related)
- new_value = kvp_value_new_gint64 (tax_related);
- else
- new_value = NULL;
+ if (tax_related)
+ new_value = kvp_value_new_gint64 (tax_related);
+ else
+ new_value = NULL;
- xaccAccountBeginEdit (acc);
- kvp_frame_set_slot_nc(acc->inst.kvp_data, "tax-related", new_value);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_slot_nc(acc->inst.kvp_data, "tax-related", new_value);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
const char *
xaccAccountGetTaxUSCode (const Account *acc)
{
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
- return kvp_frame_get_string(acc->inst.kvp_data, "tax-US/code");
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
+ return kvp_frame_get_string(acc->inst.kvp_data, "tax-US/code");
}
void
xaccAccountSetTaxUSCode (Account *acc, const char *code)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- xaccAccountBeginEdit (acc);
- kvp_frame_set_string (acc->inst.kvp_data, "/tax-US/code", code);
- if (!code)
- {
- KvpFrame *frame = NULL;
- kvp_frame_set_frame (acc->inst.kvp_data, "/tax-US", frame);
- }
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_string (acc->inst.kvp_data, "/tax-US/code", code);
+ if (!code)
+ {
+ KvpFrame *frame = NULL;
+ kvp_frame_set_frame (acc->inst.kvp_data, "/tax-US", frame);
+ }
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
const char *
xaccAccountGetTaxUSPayerNameSource (const Account *acc)
{
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
- return kvp_frame_get_string(acc->inst.kvp_data,
- "tax-US/payer-name-source");
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
+ return kvp_frame_get_string(acc->inst.kvp_data,
+ "tax-US/payer-name-source");
}
void
xaccAccountSetTaxUSPayerNameSource (Account *acc, const char *source)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- xaccAccountBeginEdit (acc);
- kvp_frame_set_string (acc->inst.kvp_data,
- "/tax-US/payer-name-source", source);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_string (acc->inst.kvp_data,
+ "/tax-US/payer-name-source", source);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
gint64
xaccAccountGetTaxUSCopyNumber (const Account *acc)
{
- gint64 copy_number;
+ gint64 copy_number;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 1);
- copy_number = kvp_frame_get_gint64(acc->inst.kvp_data,
- "tax-US/copy-number");
- return (copy_number == 0) ? 1: copy_number;
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 1);
+ copy_number = kvp_frame_get_gint64(acc->inst.kvp_data,
+ "tax-US/copy-number");
+ return (copy_number == 0) ? 1 : copy_number;
}
void
xaccAccountSetTaxUSCopyNumber (Account *acc, gint64 copy_number)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
- xaccAccountBeginEdit (acc);
- if (copy_number != 0)
- kvp_frame_set_gint64 (acc->inst.kvp_data, "/tax-US/copy-number", copy_number);
- else
- {
- KvpFrame * frame;
- KvpValue *value;
+ xaccAccountBeginEdit (acc);
+ if (copy_number != 0)
+ kvp_frame_set_gint64 (acc->inst.kvp_data, "/tax-US/copy-number", copy_number);
+ else
+ {
+ KvpFrame * frame;
+ KvpValue *value;
- value = NULL;
- frame = kvp_frame_set_value_nc (acc->inst.kvp_data,
- "/tax-US/copy-number", value);
- if (!frame) kvp_value_delete (value);
- }
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ value = NULL;
+ frame = kvp_frame_set_value_nc (acc->inst.kvp_data,
+ "/tax-US/copy-number", value);
+ if (!frame) kvp_value_delete (value);
+ }
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -3629,44 +3684,45 @@
gboolean
xaccAccountGetPlaceholder (const Account *acc)
{
- const char *str;
+ const char *str;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
-
- str = kvp_frame_get_string(acc->inst.kvp_data, "placeholder");
- return (str && !strcmp(str, "true"));
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
+
+ str = kvp_frame_get_string(acc->inst.kvp_data, "placeholder");
+ return (str && !strcmp(str, "true"));
}
void
xaccAccountSetPlaceholder (Account *acc, gboolean val)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
-
- xaccAccountBeginEdit (acc);
- kvp_frame_set_string (acc->inst.kvp_data,
- "placeholder", val ? "true" : NULL);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_string (acc->inst.kvp_data,
+ "placeholder", val ? "true" : NULL);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
GNCPlaceholderType
xaccAccountGetDescendantPlaceholder (const Account *acc)
{
- GList *descendants, *node;
- GNCPlaceholderType ret = PLACEHOLDER_NONE;
+ GList *descendants, *node;
+ GNCPlaceholderType ret = PLACEHOLDER_NONE;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), PLACEHOLDER_NONE);
- if (xaccAccountGetPlaceholder(acc)) return PLACEHOLDER_THIS;
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), PLACEHOLDER_NONE);
+ if (xaccAccountGetPlaceholder(acc)) return PLACEHOLDER_THIS;
- descendants = gnc_account_get_descendants(acc);
- for (node = descendants; node; node = node->next)
- if (xaccAccountGetPlaceholder((Account *) node->data)) {
- ret = PLACEHOLDER_CHILD;
- break;
- }
+ descendants = gnc_account_get_descendants(acc);
+ for (node = descendants; node; node = node->next)
+ if (xaccAccountGetPlaceholder((Account *) node->data))
+ {
+ ret = PLACEHOLDER_CHILD;
+ break;
+ }
- g_list_free(descendants);
- return ret;
+ g_list_free(descendants);
+ return ret;
}
/********************************************************************\
@@ -3675,42 +3731,43 @@
gboolean
xaccAccountGetHidden (const Account *acc)
{
- const char *str;
+ const char *str;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
-
- str = kvp_frame_get_string(acc->inst.kvp_data, "hidden");
- return (str && !strcmp(str, "true"));
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
+
+ str = kvp_frame_get_string(acc->inst.kvp_data, "hidden");
+ return (str && !strcmp(str, "true"));
}
void
xaccAccountSetHidden (Account *acc, gboolean val)
{
- g_return_if_fail(GNC_IS_ACCOUNT(acc));
-
- xaccAccountBeginEdit (acc);
- kvp_frame_set_string (acc->inst.kvp_data, "hidden",
- val ? "true" : NULL);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ g_return_if_fail(GNC_IS_ACCOUNT(acc));
+
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_string (acc->inst.kvp_data, "hidden",
+ val ? "true" : NULL);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
gboolean
xaccAccountIsHidden (const Account *acc)
{
- AccountPrivate *priv;
+ AccountPrivate *priv;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
- if (xaccAccountGetHidden(acc))
- return TRUE;
- priv = GET_PRIVATE(acc);
- while ((acc = priv->parent) != NULL) {
+ if (xaccAccountGetHidden(acc))
+ return TRUE;
priv = GET_PRIVATE(acc);
- if (xaccAccountGetHidden(acc))
- return TRUE;
- }
- return FALSE;
+ while ((acc = priv->parent) != NULL)
+ {
+ priv = GET_PRIVATE(acc);
+ if (xaccAccountGetHidden(acc))
+ return TRUE;
+ }
+ return FALSE;
}
/********************************************************************\
@@ -3719,16 +3776,16 @@
gboolean
xaccAccountHasAncestor (const Account *acc, const Account * ancestor)
{
- const Account *parent;
+ const Account *parent;
- g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
- g_return_val_if_fail(GNC_IS_ACCOUNT(ancestor), FALSE);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
+ g_return_val_if_fail(GNC_IS_ACCOUNT(ancestor), FALSE);
- parent = acc;
- while (parent && parent != ancestor)
- parent = GET_PRIVATE(parent)->parent;
+ parent = acc;
+ while (parent && parent != ancestor)
+ parent = GET_PRIVATE(parent)->parent;
- return (parent == ancestor);
+ return (parent == ancestor);
}
/********************************************************************\
@@ -3740,35 +3797,35 @@
#define GNC_RETURN_ENUM_AS_STRING(x) case (ACCT_TYPE_ ## x): return #x;
const char *
-xaccAccountTypeEnumAsString(GNCAccountType type)
+xaccAccountTypeEnumAsString(GNCAccountType type)
{
- switch(type)
- {
- GNC_RETURN_ENUM_AS_STRING(NONE);
- GNC_RETURN_ENUM_AS_STRING(BANK);
- GNC_RETURN_ENUM_AS_STRING(CASH);
- GNC_RETURN_ENUM_AS_STRING(CREDIT);
- GNC_RETURN_ENUM_AS_STRING(ASSET);
- GNC_RETURN_ENUM_AS_STRING(LIABILITY);
- GNC_RETURN_ENUM_AS_STRING(STOCK);
- GNC_RETURN_ENUM_AS_STRING(MUTUAL);
- GNC_RETURN_ENUM_AS_STRING(CURRENCY);
- GNC_RETURN_ENUM_AS_STRING(INCOME);
- GNC_RETURN_ENUM_AS_STRING(EXPENSE);
- GNC_RETURN_ENUM_AS_STRING(EQUITY);
- GNC_RETURN_ENUM_AS_STRING(RECEIVABLE);
- GNC_RETURN_ENUM_AS_STRING(PAYABLE);
- GNC_RETURN_ENUM_AS_STRING(ROOT);
- GNC_RETURN_ENUM_AS_STRING(TRADING);
- GNC_RETURN_ENUM_AS_STRING(CHECKING);
- GNC_RETURN_ENUM_AS_STRING(SAVINGS);
- GNC_RETURN_ENUM_AS_STRING(MONEYMRKT);
- GNC_RETURN_ENUM_AS_STRING(CREDITLINE);
+ switch (type)
+ {
+ GNC_RETURN_ENUM_AS_STRING(NONE);
+ GNC_RETURN_ENUM_AS_STRING(BANK);
+ GNC_RETURN_ENUM_AS_STRING(CASH);
+ GNC_RETURN_ENUM_AS_STRING(CREDIT);
+ GNC_RETURN_ENUM_AS_STRING(ASSET);
+ GNC_RETURN_ENUM_AS_STRING(LIABILITY);
+ GNC_RETURN_ENUM_AS_STRING(STOCK);
+ GNC_RETURN_ENUM_AS_STRING(MUTUAL);
+ GNC_RETURN_ENUM_AS_STRING(CURRENCY);
+ GNC_RETURN_ENUM_AS_STRING(INCOME);
+ GNC_RETURN_ENUM_AS_STRING(EXPENSE);
+ GNC_RETURN_ENUM_AS_STRING(EQUITY);
+ GNC_RETURN_ENUM_AS_STRING(RECEIVABLE);
+ GNC_RETURN_ENUM_AS_STRING(PAYABLE);
+ GNC_RETURN_ENUM_AS_STRING(ROOT);
+ GNC_RETURN_ENUM_AS_STRING(TRADING);
+ GNC_RETURN_ENUM_AS_STRING(CHECKING);
+ GNC_RETURN_ENUM_AS_STRING(SAVINGS);
+ GNC_RETURN_ENUM_AS_STRING(MONEYMRKT);
+ GNC_RETURN_ENUM_AS_STRING(CREDITLINE);
default:
- PERR ("asked to translate unknown account type %d.\n", type);
- break;
- }
- return(NULL);
+ PERR ("asked to translate unknown account type %d.\n", type);
+ break;
+ }
+ return(NULL);
}
#undef GNC_RETURN_ENUM_AS_STRING
@@ -3780,95 +3837,97 @@
xaccAccountStringToType(const char* str, GNCAccountType *type)
{
- GNC_RETURN_ON_MATCH(NONE);
- GNC_RETURN_ON_MATCH(BANK);
- GNC_RETURN_ON_MATCH(CASH);
- GNC_RETURN_ON_MATCH(CREDIT);
- GNC_RETURN_ON_MATCH(ASSET);
- GNC_RETURN_ON_MATCH(LIABILITY);
- GNC_RETURN_ON_MATCH(STOCK);
- GNC_RETURN_ON_MATCH(MUTUAL);
- GNC_RETURN_ON_MATCH(CURRENCY);
- GNC_RETURN_ON_MATCH(INCOME);
- GNC_RETURN_ON_MATCH(EXPENSE);
- GNC_RETURN_ON_MATCH(EQUITY);
- GNC_RETURN_ON_MATCH(RECEIVABLE);
- GNC_RETURN_ON_MATCH(PAYABLE);
- GNC_RETURN_ON_MATCH(ROOT);
- GNC_RETURN_ON_MATCH(TRADING);
- GNC_RETURN_ON_MATCH(CHECKING);
- GNC_RETURN_ON_MATCH(SAVINGS);
- GNC_RETURN_ON_MATCH(MONEYMRKT);
- GNC_RETURN_ON_MATCH(CREDITLINE);
+ GNC_RETURN_ON_MATCH(NONE);
+ GNC_RETURN_ON_MATCH(BANK);
+ GNC_RETURN_ON_MATCH(CASH);
+ GNC_RETURN_ON_MATCH(CREDIT);
+ GNC_RETURN_ON_MATCH(ASSET);
+ GNC_RETURN_ON_MATCH(LIABILITY);
+ GNC_RETURN_ON_MATCH(STOCK);
+ GNC_RETURN_ON_MATCH(MUTUAL);
+ GNC_RETURN_ON_MATCH(CURRENCY);
+ GNC_RETURN_ON_MATCH(INCOME);
+ GNC_RETURN_ON_MATCH(EXPENSE);
+ GNC_RETURN_ON_MATCH(EQUITY);
+ GNC_RETURN_ON_MATCH(RECEIVABLE);
+ GNC_RETURN_ON_MATCH(PAYABLE);
+ GNC_RETURN_ON_MATCH(ROOT);
+ GNC_RETURN_ON_MATCH(TRADING);
+ GNC_RETURN_ON_MATCH(CHECKING);
+ GNC_RETURN_ON_MATCH(SAVINGS);
+ GNC_RETURN_ON_MATCH(MONEYMRKT);
+ GNC_RETURN_ON_MATCH(CREDITLINE);
- PERR("asked to translate unknown account type string %s.\n",
- str ? str : "(null)");
+ PERR("asked to translate unknown account type string %s.\n",
+ str ? str : "(null)");
- return(FALSE);
+ return(FALSE);
}
#undef GNC_RETURN_ON_MATCH
/* impedance mismatch is a source of loss */
GNCAccountType
-xaccAccountStringToEnum(const char* str)
+xaccAccountStringToEnum(const char* str)
{
- GNCAccountType type;
- gboolean rc;
- rc = xaccAccountStringToType(str, &type);
- if (FALSE == rc) return ACCT_TYPE_INVALID;
- return type;
+ GNCAccountType type;
+ gboolean rc;
+ rc = xaccAccountStringToType(str, &type);
+ if (FALSE == rc) return ACCT_TYPE_INVALID;
+ return type;
}
/********************************************************************\
\********************************************************************/
static char *
-account_type_name[NUM_ACCOUNT_TYPES] = {
- N_("Bank"),
- N_("Cash"),
- N_("Asset"),
- N_("Credit Card"),
- N_("Liability"),
- N_("Stock"),
- N_("Mutual Fund"),
- N_("Currency"),
- N_("Income"),
- N_("Expense"),
- N_("Equity"),
- N_("A/Receivable"),
- N_("A/Payable"),
- N_("Root"),
- N_("Trading")
- /*
- N_("Checking"),
- N_("Savings"),
- N_("Money Market"),
- N_("Credit Line")
- */
+account_type_name[NUM_ACCOUNT_TYPES] =
+{
+ N_("Bank"),
+ N_("Cash"),
+ N_("Asset"),
+ N_("Credit Card"),
+ N_("Liability"),
+ N_("Stock"),
+ N_("Mutual Fund"),
+ N_("Currency"),
+ N_("Income"),
+ N_("Expense"),
+ N_("Equity"),
+ N_("A/Receivable"),
+ N_("A/Payable"),
+ N_("Root"),
+ N_("Trading")
+ /*
+ N_("Checking"),
+ N_("Savings"),
+ N_("Money Market"),
+ N_("Credit Line")
+ */
};
const char *
-xaccAccountGetTypeStr(GNCAccountType type) {
- if (type < 0 || NUM_ACCOUNT_TYPES <= type ) return "";
- return _(account_type_name [type]);
+xaccAccountGetTypeStr(GNCAccountType type)
+{
+ if (type < 0 || NUM_ACCOUNT_TYPES <= type ) return "";
+ return _(account_type_name [type]);
}
GNCAccountType
xaccAccountGetTypeFromStr (const gchar *str)
{
- gint type;
+ gint type;
- for (type = 0; type < NUM_ACCOUNT_TYPES; type++)
- {
- if (!safe_strcmp (str, _(account_type_name [type])))
- return type;
- }
+ for (type = 0; type < NUM_ACCOUNT_TYPES; type++)
+ {
+ if (!safe_strcmp (str, _(account_type_name [type])))
+ return type;
+ }
- PERR("asked to translate unknown account type string %s.\n",
- str ? str : "(null)");
+ PERR("asked to translate unknown account type string %s.\n",
+ str ? str : "(null)");
- return ACCT_TYPE_INVALID;
+ return ACCT_TYPE_INVALID;
}
@@ -3878,56 +3937,57 @@
guint32
xaccParentAccountTypesCompatibleWith (GNCAccountType type)
{
- switch (type) {
- case ACCT_TYPE_BANK:
- case ACCT_TYPE_CASH:
- case ACCT_TYPE_ASSET:
- case ACCT_TYPE_STOCK:
- case ACCT_TYPE_MUTUAL:
- case ACCT_TYPE_CURRENCY:
- case ACCT_TYPE_CREDIT:
- case ACCT_TYPE_LIABILITY:
- case ACCT_TYPE_RECEIVABLE:
- case ACCT_TYPE_PAYABLE:
- return
- (1 << ACCT_TYPE_BANK) |
- (1 << ACCT_TYPE_CASH) |
- (1 << ACCT_TYPE_ASSET) |
- (1 << ACCT_TYPE_STOCK) |
- (1 << ACCT_TYPE_MUTUAL) |
- (1 << ACCT_TYPE_CURRENCY) |
- (1 << ACCT_TYPE_CREDIT) |
- (1 << ACCT_TYPE_LIABILITY) |
- (1 << ACCT_TYPE_RECEIVABLE) |
- (1 << ACCT_TYPE_PAYABLE) |
- (1 << ACCT_TYPE_ROOT);
- case ACCT_TYPE_INCOME:
- case ACCT_TYPE_EXPENSE:
- return
- (1 << ACCT_TYPE_INCOME) |
- (1 << ACCT_TYPE_EXPENSE) |
- (1 << ACCT_TYPE_ROOT);
- case ACCT_TYPE_EQUITY:
- return
- (1 << ACCT_TYPE_EQUITY) |
- (1 << ACCT_TYPE_ROOT);
- case ACCT_TYPE_TRADING:
- return
- (1 << ACCT_TYPE_TRADING) |
- (1 << ACCT_TYPE_ROOT);
- default:
- PERR("bad account type: %d", type);
- return 0;
- }
+ switch (type)
+ {
+ case ACCT_TYPE_BANK:
+ case ACCT_TYPE_CASH:
+ case ACCT_TYPE_ASSET:
+ case ACCT_TYPE_STOCK:
+ case ACCT_TYPE_MUTUAL:
+ case ACCT_TYPE_CURRENCY:
+ case ACCT_TYPE_CREDIT:
+ case ACCT_TYPE_LIABILITY:
+ case ACCT_TYPE_RECEIVABLE:
+ case ACCT_TYPE_PAYABLE:
+ return
+ (1 << ACCT_TYPE_BANK) |
+ (1 << ACCT_TYPE_CASH) |
+ (1 << ACCT_TYPE_ASSET) |
+ (1 << ACCT_TYPE_STOCK) |
+ (1 << ACCT_TYPE_MUTUAL) |
+ (1 << ACCT_TYPE_CURRENCY) |
+ (1 << ACCT_TYPE_CREDIT) |
+ (1 << ACCT_TYPE_LIABILITY) |
+ (1 << ACCT_TYPE_RECEIVABLE) |
+ (1 << ACCT_TYPE_PAYABLE) |
+ (1 << ACCT_TYPE_ROOT);
+ case ACCT_TYPE_INCOME:
+ case ACCT_TYPE_EXPENSE:
+ return
+ (1 << ACCT_TYPE_INCOME) |
+ (1 << ACCT_TYPE_EXPENSE) |
+ (1 << ACCT_TYPE_ROOT);
+ case ACCT_TYPE_EQUITY:
+ return
+ (1 << ACCT_TYPE_EQUITY) |
+ (1 << ACCT_TYPE_ROOT);
+ case ACCT_TYPE_TRADING:
+ return
+ (1 << ACCT_TYPE_TRADING) |
+ (1 << ACCT_TYPE_ROOT);
+ default:
+ PERR("bad account type: %d", type);
+ return 0;
+ }
}
gboolean
xaccAccountTypesCompatible (GNCAccountType parent_type,
GNCAccountType child_type)
{
- return ((xaccParentAccountTypesCompatibleWith (parent_type) &
- (1 << child_type))
- != 0);
+ return ((xaccParentAccountTypesCompatibleWith (parent_type) &
+ (1 << child_type))
+ != 0);
}
guint32
@@ -3948,7 +4008,7 @@
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
priv = GET_PRIVATE(acc);
- return (priv->type == ACCT_TYPE_STOCK || priv->type == ACCT_TYPE_MUTUAL ||
+ return (priv->type == ACCT_TYPE_STOCK || priv->type == ACCT_TYPE_MUTUAL ||
priv->type == ACCT_TYPE_CURRENCY);
}
@@ -3958,19 +4018,19 @@
gboolean
xaccAccountGetReconcileLastDate (const Account *acc, time_t *last_date)
{
- KvpValue *v;
+ KvpValue *v;
- if (!acc) return FALSE;
+ if (!acc) return FALSE;
- v = kvp_frame_get_value(acc->inst.kvp_data, "reconcile-info/last-date");
-
- if (!v || kvp_value_get_type(v) != KVP_TYPE_GINT64)
- return FALSE;
+ v = kvp_frame_get_value(acc->inst.kvp_data, "reconcile-info/last-date");
- if (last_date)
- *last_date = kvp_value_get_gint64(v);
+ if (!v || kvp_value_get_type(v) != KVP_TYPE_GINT64)
+ return FALSE;
- return TRUE;
+ if (last_date)
+ *last_date = kvp_value_get_gint64(v);
+
+ return TRUE;
}
/********************************************************************\
@@ -3979,39 +4039,39 @@
void
xaccAccountSetReconcileLastDate (Account *acc, time_t last_date)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit (acc);
- kvp_frame_set_gint64 (acc->inst.kvp_data,
- "/reconcile-info/last-date", last_date);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_gint64 (acc->inst.kvp_data,
+ "/reconcile-info/last-date", last_date);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
\********************************************************************/
gboolean
-xaccAccountGetReconcileLastInterval (const Account *acc,
+xaccAccountGetReconcileLastInterval (const Account *acc,
int *months, int *days)
{
- KvpValue *v1, *v2;
+ KvpValue *v1, *v2;
- if (!acc) return FALSE;
+ if (!acc) return FALSE;
- v1 = kvp_frame_get_value(acc->inst.kvp_data,
- "reconcile-info/last-interval/months");
- v2 = kvp_frame_get_value(acc->inst.kvp_data,
- "reconcile-info/last-interval/days");
- if (!v1 || (kvp_value_get_type (v1) != KVP_TYPE_GINT64) ||
- !v2 || (kvp_value_get_type (v2) != KVP_TYPE_GINT64))
- return FALSE;
+ v1 = kvp_frame_get_value(acc->inst.kvp_data,
+ "reconcile-info/last-interval/months");
+ v2 = kvp_frame_get_value(acc->inst.kvp_data,
+ "reconcile-info/last-interval/days");
+ if (!v1 || (kvp_value_get_type (v1) != KVP_TYPE_GINT64) ||
+ !v2 || (kvp_value_get_type (v2) != KVP_TYPE_GINT64))
+ return FALSE;
- if (months)
- *months = kvp_value_get_gint64 (v1);
- if (days)
- *days = kvp_value_get_gint64 (v2);
- return TRUE;
+ if (months)
+ *months = kvp_value_get_gint64 (v1);
+ if (days)
+ *days = kvp_value_get_gint64 (v2);
+ return TRUE;
}
/********************************************************************\
@@ -4020,20 +4080,20 @@
void
xaccAccountSetReconcileLastInterval (Account *acc, int months, int days)
{
- KvpFrame *frame;
- if (!acc) return;
+ KvpFrame *frame;
+ if (!acc) return;
- xaccAccountBeginEdit (acc);
+ xaccAccountBeginEdit (acc);
- frame = kvp_frame_get_frame_slash (acc->inst.kvp_data,
- "/reconcile-info/last-interval");
- g_assert(frame);
+ frame = kvp_frame_get_frame_slash (acc->inst.kvp_data,
+ "/reconcile-info/last-interval");
+ g_assert(frame);
- kvp_frame_set_gint64 (frame, "months", months);
- kvp_frame_set_gint64 (frame, "days", days);
+ kvp_frame_set_gint64 (frame, "months", months);
+ kvp_frame_set_gint64 (frame, "days", days);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -4042,18 +4102,18 @@
gboolean
xaccAccountGetReconcilePostponeDate (const Account *acc, time_t *postpone_date)
{
- KvpValue *v;
+ KvpValue *v;
- if (!acc) return FALSE;
+ if (!acc) return FALSE;
- v = kvp_frame_get_value(acc->inst.kvp_data, "reconcile-info/postpone/date");
- if (!v || kvp_value_get_type (v) != KVP_TYPE_GINT64)
- return FALSE;
+ v = kvp_frame_get_value(acc->inst.kvp_data, "reconcile-info/postpone/date");
+ if (!v || kvp_value_get_type (v) != KVP_TYPE_GINT64)
+ return FALSE;
- if (postpone_date)
- *postpone_date = kvp_value_get_gint64 (v);
+ if (postpone_date)
+ *postpone_date = kvp_value_get_gint64 (v);
- return TRUE;
+ return TRUE;
}
/********************************************************************\
@@ -4062,37 +4122,37 @@
void
xaccAccountSetReconcilePostponeDate (Account *acc, time_t postpone_date)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit (acc);
+ xaccAccountBeginEdit (acc);
- /* XXX this should be using timespecs, not gints !! */
- kvp_frame_set_gint64 (acc->inst.kvp_data,
- "reconcile-info/postpone/date", postpone_date);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ /* XXX this should be using timespecs, not gints !! */
+ kvp_frame_set_gint64 (acc->inst.kvp_data,
+ "reconcile-info/postpone/date", postpone_date);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
\********************************************************************/
gboolean
-xaccAccountGetReconcilePostponeBalance (const Account *acc,
+xaccAccountGetReconcilePostponeBalance (const Account *acc,
gnc_numeric *balance)
{
- KvpValue *v;
+ KvpValue *v;
- if (!acc) return FALSE;
+ if (!acc) return FALSE;
- v = kvp_frame_get_value(acc->inst.kvp_data,
- "reconcile-info/postpone/balance");
- if (!v || kvp_value_get_type (v) != KVP_TYPE_NUMERIC)
- return FALSE;
+ v = kvp_frame_get_value(acc->inst.kvp_data,
+ "reconcile-info/postpone/balance");
+ if (!v || kvp_value_get_type (v) != KVP_TYPE_NUMERIC)
+ return FALSE;
- if (balance)
- *balance = kvp_value_get_numeric (v);
+ if (balance)
+ *balance = kvp_value_get_numeric (v);
- return TRUE;
+ return TRUE;
}
/********************************************************************\
@@ -4101,13 +4161,13 @@
void
xaccAccountSetReconcilePostponeBalance (Account *acc, gnc_numeric balance)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit (acc);
- kvp_frame_set_gnc_numeric (acc->inst.kvp_data,
- "/reconcile-info/postpone/balance", balance);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_gnc_numeric (acc->inst.kvp_data,
+ "/reconcile-info/postpone/balance", balance);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -4117,12 +4177,12 @@
void
xaccAccountClearReconcilePostpone (Account *acc)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit (acc);
- kvp_frame_set_value (acc->inst.kvp_data, "reconcile-info/postpone", NULL);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_value (acc->inst.kvp_data, "reconcile-info/postpone", NULL);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -4135,12 +4195,12 @@
gboolean
xaccAccountGetAutoInterestXfer (const Account *acc, gboolean default_value)
{
- const char *str = NULL;
- if (!acc) return default_value;
+ const char *str = NULL;
+ if (!acc) return default_value;
- str = kvp_frame_get_string(acc->inst.kvp_data,
- "reconcile-info/auto-interest-transfer");
- return str ? !strcmp(str, "true") : default_value;
+ str = kvp_frame_get_string(acc->inst.kvp_data,
+ "reconcile-info/auto-interest-transfer");
+ return str ? !strcmp(str, "true") : default_value;
}
/********************************************************************\
@@ -4149,15 +4209,15 @@
void
xaccAccountSetAutoInterestXfer (Account *acc, gboolean option)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit (acc);
- /* FIXME: need KVP_TYPE_BOOLEAN for this someday */
- kvp_frame_set_string (acc->inst.kvp_data,
- "/reconcile-info/auto-interest-transfer",
- (option ? "true" : "false"));
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ /* FIXME: need KVP_TYPE_BOOLEAN for this someday */
+ kvp_frame_set_string (acc->inst.kvp_data,
+ "/reconcile-info/auto-interest-transfer",
+ (option ? "true" : "false"));
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -4166,7 +4226,7 @@
const char *
xaccAccountGetLastNum (const Account *acc)
{
- return acc ? kvp_frame_get_string(acc->inst.kvp_data, "last-num") : NULL;
+ return acc ? kvp_frame_get_string(acc->inst.kvp_data, "last-num") : NULL;
}
/********************************************************************\
@@ -4175,12 +4235,12 @@
void
xaccAccountSetLastNum (Account *acc, const char *num)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit (acc);
- kvp_frame_set_string(acc->inst.kvp_data, "last-num", num);
- mark_account (acc);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ kvp_frame_set_string(acc->inst.kvp_data, "last-num", num);
+ mark_account (acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -4189,68 +4249,72 @@
void
dxaccAccountSetPriceSrc(Account *acc, const char *src)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit(acc);
- if (xaccAccountIsPriced(acc)) {
- kvp_frame_set_slot_nc(acc->inst.kvp_data,
- "old-price-source",
- src ? kvp_value_new_string(src) : NULL);
- mark_account (acc);
- }
-
- qof_instance_set_dirty(&acc->inst);
- xaccAccountCommitEdit(acc);
+ xaccAccountBeginEdit(acc);
+ if (xaccAccountIsPriced(acc))
+ {
+ kvp_frame_set_slot_nc(acc->inst.kvp_data,
+ "old-price-source",
+ src ? kvp_value_new_string(src) : NULL);
+ mark_account (acc);
+ }
+
+ qof_instance_set_dirty(&acc->inst);
+ xaccAccountCommitEdit(acc);
}
/********************************************************************\
\********************************************************************/
const char*
-dxaccAccountGetPriceSrc(const Account *acc)
+dxaccAccountGetPriceSrc(const Account *acc)
{
- if(!acc) return NULL;
+ if (!acc) return NULL;
- if (xaccAccountIsPriced(acc)) {
- KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data,
- "old-price-source");
- if (value) return (kvp_value_get_string(value));
- }
- return NULL;
+ if (xaccAccountIsPriced(acc))
+ {
+ KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data,
+ "old-price-source");
+ if (value) return (kvp_value_get_string(value));
+ }
+ return NULL;
}
/********************************************************************\
\********************************************************************/
void
-dxaccAccountSetQuoteTZ(Account *acc, const char *tz)
+dxaccAccountSetQuoteTZ(Account *acc, const char *tz)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountBeginEdit(acc);
- if (xaccAccountIsPriced(acc)) {
- kvp_frame_set_slot_nc(acc->inst.kvp_data,
- "old-quote-tz",
- tz ? kvp_value_new_string(tz) : NULL);
- mark_account (acc);
- }
- qof_instance_set_dirty(&acc->inst);
- xaccAccountCommitEdit(acc);
+ xaccAccountBeginEdit(acc);
+ if (xaccAccountIsPriced(acc))
+ {
+ kvp_frame_set_slot_nc(acc->inst.kvp_data,
+ "old-quote-tz",
+ tz ? kvp_value_new_string(tz) : NULL);
+ mark_account (acc);
+ }
+ qof_instance_set_dirty(&acc->inst);
+ xaccAccountCommitEdit(acc);
}
/********************************************************************\
\********************************************************************/
const char*
-dxaccAccountGetQuoteTZ(const Account *acc)
+dxaccAccountGetQuoteTZ(const Account *acc)
{
- if (!acc) return NULL;
+ if (!acc) return NULL;
- if (xaccAccountIsPriced(acc)) {
- KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data, "old-quote-tz");
- if(value) return (kvp_value_get_string(value));
- }
- return NULL;
+ if (xaccAccountIsPriced(acc))
+ {
+ KvpValue *value = kvp_frame_get_slot(acc->inst.kvp_data, "old-quote-tz");
+ if (value) return (kvp_value_get_string(value));
+ }
+ return NULL;
}
/********************************************************************\
@@ -4258,16 +4322,16 @@
void
xaccAccountSetReconcileChildrenStatus(Account *acc, gboolean status)
-{
- if (!acc) return;
-
- xaccAccountBeginEdit (acc);
-
- /* XXX FIXME: someday this should use KVP_TYPE_BOOLEAN */
- kvp_frame_set_gint64 (acc->inst.kvp_data,
- "/reconcile-info/include-children", status);
- mark_account(acc);
- xaccAccountCommitEdit (acc);
+{
+ if (!acc) return;
+
+ xaccAccountBeginEdit (acc);
+
+ /* XXX FIXME: someday this should use KVP_TYPE_BOOLEAN */
+ kvp_frame_set_gint64 (acc->inst.kvp_data,
+ "/reconcile-info/include-children", status);
+ mark_account(acc);
+ xaccAccountCommitEdit (acc);
}
/********************************************************************\
@@ -4276,12 +4340,12 @@
gboolean
xaccAccountGetReconcileChildrenStatus(const Account *acc)
{
- /* access the account's kvp-data for status and return that, if no value
- * is found then we can assume not to include the children, that being
- * the default behaviour
- */
- return acc ? kvp_frame_get_gint64(acc->inst.kvp_data,
- "reconcile-info/include-children") : FALSE;
+ /* access the account's kvp-data for status and return that, if no value
+ * is found then we can assume not to include the children, that being
+ * the default behaviour
+ */
+ return acc ? kvp_frame_get_gint64(acc->inst.kvp_data,
+ "reconcile-info/include-children") : FALSE;
}
/********************************************************************\
@@ -4296,41 +4360,42 @@
finder_help_function(const Account *acc, const char *description,
Split **split, Transaction **trans )
{
- AccountPrivate *priv;
- GList *slp;
+ AccountPrivate *priv;
+ GList *slp;
- /* First, make sure we set the data to NULL BEFORE we start */
- if (split) *split = NULL;
- if (trans) *trans = NULL;
+ /* First, make sure we set the data to NULL BEFORE we start */
+ if (split) *split = NULL;
+ if (trans) *trans = NULL;
- /* Then see if we have any work to do */
- if (acc == NULL) return;
+ /* Then see if we have any work to do */
+ if (acc == NULL) return;
- /* Why is this loop iterated backwards ?? Presumably because the split
- * list is in date order, and the most recent matches should be
- * returned!? */
- priv = GET_PRIVATE(acc);
- for (slp = g_list_last(priv->splits); slp; slp = slp->prev) {
- Split *lsplit = slp->data;
- Transaction *ltrans = xaccSplitGetParent(lsplit);
+ /* Why is this loop iterated backwards ?? Presumably because the split
+ * list is in date order, and the most recent matches should be
+ * returned!? */
+ priv = GET_PRIVATE(acc);
+ for (slp = g_list_last(priv->splits); slp; slp = slp->prev)
+ {
+ Split *lsplit = slp->data;
+ Transaction *ltrans = xaccSplitGetParent(lsplit);
- if (safe_strcmp (description, xaccTransGetDescription (ltrans)) == 0)
- {
- if (split) *split = lsplit;
- if (trans) *trans = ltrans;
- return;
+ if (safe_strcmp (description, xaccTransGetDescription (ltrans)) == 0)
+ {
+ if (split) *split = lsplit;
+ if (trans) *trans = ltrans;
+ return;
+ }
}
- }
}
Split *
xaccAccountFindSplitByDesc(const Account *acc, const char *description)
{
- Split *split;
+ Split *split;
- /* Get the split which has a transaction matching the description. */
- finder_help_function(acc, description, &split, NULL);
- return split;
+ /* Get the split which has a transaction matching the description. */
+ finder_help_function(acc, description, &split, NULL);
+ return split;
}
/* This routine is for finding a matching transaction in an account by
@@ -4341,11 +4406,11 @@
Transaction *
xaccAccountFindTransByDesc(const Account *acc, const char *description)
{
- Transaction *trans;
+ Transaction *trans;
- /* Get the transation matching the description. */
- finder_help_function(acc, description, NULL, &trans);
- return trans;
+ /* Get the transation matching the description. */
+ finder_help_function(acc, description, NULL, &trans);
+ return trans;
}
/* ================================================================ */
@@ -4354,144 +4419,145 @@
void
gnc_account_join_children (Account *to_parent, Account *from_parent)
{
- AccountPrivate *from_priv;
- GList *children, *node;
+ AccountPrivate *from_priv;
+ GList *children, *node;
- /* errors */
- g_return_if_fail(GNC_IS_ACCOUNT(to_parent));
- g_return_if_fail(GNC_IS_ACCOUNT(from_parent));
+ /* errors */
+ g_return_if_fail(GNC_IS_ACCOUNT(to_parent));
+ g_return_if_fail(GNC_IS_ACCOUNT(from_parent));
- /* optimizations */
- from_priv = GET_PRIVATE(from_parent);
- if (!from_priv->children)
- return;
+ /* optimizations */
+ from_priv = GET_PRIVATE(from_parent);
+ if (!from_priv->children)
+ return;
- ENTER (" ");
- children = g_list_copy(from_priv->children);
- for (node = children; node; node = g_list_next(node))
- gnc_account_append_child(to_parent, node->data);
- g_list_free(children);
- LEAVE (" ");
+ ENTER (" ");
+ children = g_list_copy(from_priv->children);
+ for (node = children; node; node = g_list_next(node))
+ gnc_account_append_child(to_parent, node->data);
+ g_list_free(children);
+ LEAVE (" ");
}
void
gnc_account_copy_children (Account *to, Account *from)
{
- AccountPrivate *to_priv, *from_priv;
- GList *node;
- QofBook *to_book;
+ AccountPrivate *to_priv, *from_priv;
+ GList *node;
+ QofBook *to_book;
- /* errors */
- g_return_if_fail(GNC_IS_ACCOUNT(to));
- g_return_if_fail(GNC_IS_ACCOUNT(from));
+ /* errors */
+ g_return_if_fail(GNC_IS_ACCOUNT(to));
+ g_return_if_fail(GNC_IS_ACCOUNT(from));
- /* optimizations */
- to_priv = GET_PRIVATE(to);
- from_priv = GET_PRIVATE(from);
- if (!from_priv->children)
- return;
+ /* optimizations */
+ to_priv = GET_PRIVATE(to);
+ from_priv = GET_PRIVATE(from);
+ if (!from_priv->children)
+ return;
- to_book = gnc_account_get_book(to);
- if (!to_book) return;
+ to_book = gnc_account_get_book(to);
+ if (!to_book) return;
- ENTER (" ");
- xaccAccountBeginEdit(to);
- xaccAccountBeginEdit(from);
- for (node = from_priv->children; node; node=node->next)
- {
- Account *to_acc, *from_acc = node->data;
+ ENTER (" ");
+ xaccAccountBeginEdit(to);
+ xaccAccountBeginEdit(from);
+ for (node = from_priv->children; node; node = node->next)
+ {
+ Account *to_acc, *from_acc = node->data;
- /* This will copy the basic data and the KVP. It will
- * not copy any splits/transactions. It will gemini. */
- to_acc = xaccCloneAccount (from_acc, to_book);
+ /* This will copy the basic data and the KVP. It will
+ * not copy any splits/transactions. It will gemini. */
+ to_acc = xaccCloneAccount (from_acc, to_book);
- xaccAccountBeginEdit (to_acc);
- to_priv->children = g_list_append(to_priv->children, to_acc);
+ xaccAccountBeginEdit (to_acc);
+ to_priv->children = g_list_append(to_priv->children, to_acc);
- GET_PRIVATE(to_acc)->parent = to;
- qof_instance_set_dirty(&to_acc->inst);
+ GET_PRIVATE(to_acc)->parent = to;
+ qof_instance_set_dirty(&to_acc->inst);
- /* Copy child accounts too. */
- if (GET_PRIVATE(from_acc)->children)
- {
- gnc_account_copy_children(to_acc, from_acc);
- }
- xaccAccountCommitEdit (to_acc);
- qof_event_gen (&to_acc->inst, QOF_EVENT_CREATE, NULL);
- /* DRH - Should this send ADD/REMOVE events */
- }
- xaccAccountCommitEdit(from);
- xaccAccountCommitEdit(to);
- LEAVE (" ");
+ /* Copy child accounts too. */
+ if (GET_PRIVATE(from_acc)->children)
+ {
+ gnc_account_copy_children(to_acc, from_acc);
+ }
+ xaccAccountCommitEdit (to_acc);
+ qof_event_gen (&to_acc->inst, QOF_EVENT_CREATE, NULL);
+ /* DRH - Should this send ADD/REMOVE events */
+ }
+ xaccAccountCommitEdit(from);
+ xaccAccountCommitEdit(to);
+ LEAVE (" ");
}
/********************************************************************\
\********************************************************************/
-void
+void
gnc_account_merge_children (Account *parent)
{
- AccountPrivate *ppriv, *priv_a, *priv_b;
- GList *node_a, *node_b, *work, *worker;
+ AccountPrivate *ppriv, *priv_a, *priv_b;
+ GList *node_a, *node_b, *work, *worker;
- g_return_if_fail(GNC_IS_ACCOUNT(parent));
+ g_return_if_fail(GNC_IS_ACCOUNT(parent));
- ppriv = GET_PRIVATE(parent);
- for (node_a = ppriv->children; node_a; node_a = node_a->next)
- {
- Account *acc_a = node_a->data;
-
- priv_a = GET_PRIVATE(acc_a);
- for (node_b = node_a->next; node_b; node_b = g_list_next(node_b))
+ ppriv = GET_PRIVATE(parent);
+ for (node_a = ppriv->children; node_a; node_a = node_a->next)
{
- Account *acc_b = node_b->data;
+ Account *acc_a = node_a->data;
- priv_b = GET_PRIVATE(acc_b);
- if (0 != null_strcmp(priv_a->accountName, priv_b->accountName))
- continue;
- if (0 != null_strcmp(priv_a->accountCode, priv_b->accountCode))
- continue;
- if (0 != null_strcmp(priv_a->description, priv_b->description))
- continue;
- if (0 != null_strcmp(xaccAccountGetColor(acc_a),
- xaccAccountGetColor(acc_b)))
- continue;
- if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
- continue;
- if (0 != null_strcmp(xaccAccountGetNotes(acc_a),
- xaccAccountGetNotes(acc_b)))
- continue;
- if (priv_a->type != priv_b->type)
- continue;
+ priv_a = GET_PRIVATE(acc_a);
+ for (node_b = node_a->next; node_b; node_b = g_list_next(node_b))
+ {
+ Account *acc_b = node_b->data;
- /* consolidate children */
- if (priv_b->children) {
- work = g_list_copy(priv_b->children);
- for (worker = work; worker; worker = g_list_next(worker))
- gnc_account_append_child (acc_a, (Account *)worker->data);
- g_list_free(work);
+ priv_b = GET_PRIVATE(acc_b);
+ if (0 != null_strcmp(priv_a->accountName, priv_b->accountName))
+ continue;
+ if (0 != null_strcmp(priv_a->accountCode, priv_b->accountCode))
+ continue;
+ if (0 != null_strcmp(priv_a->description, priv_b->description))
+ continue;
+ if (0 != null_strcmp(xaccAccountGetColor(acc_a),
+ xaccAccountGetColor(acc_b)))
+ continue;
+ if (!gnc_commodity_equiv(priv_a->commodity, priv_b->commodity))
+ continue;
+ if (0 != null_strcmp(xaccAccountGetNotes(acc_a),
+ xaccAccountGetNotes(acc_b)))
+ continue;
+ if (priv_a->type != priv_b->type)
+ continue;
- qof_event_gen (&acc_a->inst, QOF_EVENT_MODIFY, NULL);
- qof_event_gen (&acc_b->inst, QOF_EVENT_MODIFY, NULL);
- }
+ /* consolidate children */
+ if (priv_b->children)
+ {
+ work = g_list_copy(priv_b->children);
+ for (worker = work; worker; worker = g_list_next(worker))
+ gnc_account_append_child (acc_a, (Account *)worker->data);
+ g_list_free(work);
- /* recurse to do the children's children */
- gnc_account_merge_children (acc_a);
+ qof_event_gen (&acc_a->inst, QOF_EVENT_MODIFY, NULL);
+ qof_event_gen (&acc_b->inst, QOF_EVENT_MODIFY, NULL);
+ }
- /* consolidate transactions */
- while (priv_b->splits)
- xaccSplitSetAccount (priv_b->splits->data, acc_a);
+ /* recurse to do the children's children */
+ gnc_account_merge_children (acc_a);
- /* move back one before removal. next iteration around the loop
- * will get the node after node_b */
- node_b = g_list_previous(node_b);
+ /* consolidate transactions */
+ while (priv_b->splits)
+ xaccSplitSetAccount (priv_b->splits->data, acc_a);
- /* The destroy function will remove from list -- node_a is ok,
- * it's before node_b */
- xaccAccountBeginEdit (acc_b);
- xaccAccountDestroy (acc_b);
+ /* move back one before removal. next iteration around the loop
+ * will get the node after node_b */
+ node_b = g_list_previous(node_b);
+
+ /* The destroy function will remove from list -- node_a is ok,
+ * it's before node_b */
+ xaccAccountBeginEdit (acc_b);
+ xaccAccountDestroy (acc_b);
+ }
}
- }
}
/* ================================================================ */
@@ -4501,16 +4567,16 @@
void
xaccSplitsBeginStagedTransactionTraversals (GList *splits)
{
- GList *lp;
+ GList *lp;
- for (lp = splits; lp; lp = lp->next)
- {
- Split *s = lp->data;
- Transaction *trans = s->parent;
+ for (lp = splits; lp; lp = lp->next)
+ {
+ Split *s = lp->data;
+ Transaction *trans = s->parent;
- if (trans)
- trans->marker = 0;
- }
+ if (trans)
+ trans->marker = 0;
+ }
}
/* original function */
@@ -4528,29 +4594,29 @@
gboolean
xaccTransactionTraverse (Transaction *trans, int stage)
{
- if (trans == NULL) return FALSE;
+ if (trans == NULL) return FALSE;
- if (trans->marker < stage)
- {
- trans->marker = stage;
- return TRUE;
- }
+ if (trans->marker < stage)
+ {
+ trans->marker = stage;
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
gboolean
xaccSplitTransactionTraverse (Split *split, int stage)
{
- if (split == NULL) return FALSE;
+ if (split == NULL) return FALSE;
- return xaccTransactionTraverse (split->parent, stage);
+ return xaccTransactionTraverse (split->parent, stage);
}
static void do_one_split (Split *s, gpointer data)
{
- Transaction *trans = s->parent;
- trans->marker = 0;
+ Transaction *trans = s->parent;
+ trans->marker = 0;
}
static void do_one_account (Account *account, gpointer data)
@@ -4563,11 +4629,11 @@
void
gnc_account_tree_begin_staged_transaction_traversals (Account *account)
{
- GList *descendants;
+ GList *descendants;
- descendants = gnc_account_get_descendants(account);
- g_list_foreach(descendants, (GFunc)do_one_account, NULL);
- g_list_free(descendants);
+ descendants = gnc_account_get_descendants(account);
+ g_list_foreach(descendants, (GFunc)do_one_account, NULL);
+ g_list_free(descendants);
}
int
@@ -4576,73 +4642,80 @@
TransactionCallback thunk,
void *cb_data)
{
- AccountPrivate *priv;
- GList *split_p;
- GList *next;
- Transaction *trans;
- Split *s;
- int retval;
+ AccountPrivate *priv;
+ GList *split_p;
+ GList *next;
+ Transaction *trans;
+ Split *s;
+ int retval;
- if (!acc) return 0;
+ if (!acc) return 0;
- priv = GET_PRIVATE(acc);
- for(split_p = priv->splits; split_p; split_p = next) {
- /* Get the next element in the split list now, just in case some
- * naughty thunk destroys the one we're using. This reduces, but
- * does not eliminate, the possibility of undefined results if
- * a thunk removes splits from this account. */
- next = g_list_next(split_p);
+ priv = GET_PRIVATE(acc);
+ for (split_p = priv->splits; split_p; split_p = next)
+ {
+ /* Get the next element in the split list now, just in case some
+ * naughty thunk destroys the one we're using. This reduces, but
+ * does not eliminate, the possibility of undefined results if
+ * a thunk removes splits from this account. */
+ next = g_list_next(split_p);
- s = split_p->data;
- trans = s->parent;
- if (trans && (trans->marker < stage)) {
- trans->marker = stage;
- if (thunk) {
- retval = thunk(trans, cb_data);
- if (retval) return retval;
- }
+ s = split_p->data;
+ trans = s->parent;
+ if (trans && (trans->marker < stage))
+ {
+ trans->marker = stage;
+ if (thunk)
+ {
+ retval = thunk(trans, cb_data);
+ if (retval) return retval;
+ }
+ }
}
- }
- return 0;
+ return 0;
}
int
gnc_account_tree_staged_transaction_traversal (const Account *acc,
- unsigned int stage,
- TransactionCallback thunk,
- void *cb_data)
+ unsigned int stage,
+ TransactionCallback thunk,
+ void *cb_data)
{
- const AccountPrivate *priv;
- GList *acc_p, *split_p;
- Transaction *trans;
- Split *s;
- int retval;
+ const AccountPrivate *priv;
+ GList *acc_p, *split_p;
+ Transaction *trans;
+ Split *s;
+ int retval;
- if (!acc) return 0;
+ if (!acc) return 0;
- /* depth first traversal */
- priv = GET_PRIVATE(acc);
- for (acc_p = priv->children; acc_p; acc_p = g_list_next(acc_p)) {
- retval = gnc_account_tree_staged_transaction_traversal(acc_p->data, stage,
- thunk, cb_data);
- if (retval) return retval;
- }
-
- /* Now this account */
- for(split_p = priv->splits; split_p; split_p = g_list_next(split_p)) {
- s = split_p->data;
- trans = s->parent;
- if (trans && (trans->marker < stage)) {
- trans->marker = stage;
- if (thunk) {
- retval = thunk(trans, cb_data);
+ /* depth first traversal */
+ priv = GET_PRIVATE(acc);
+ for (acc_p = priv->children; acc_p; acc_p = g_list_next(acc_p))
+ {
+ retval = gnc_account_tree_staged_transaction_traversal(acc_p->data, stage,
+ thunk, cb_data);
if (retval) return retval;
- }
}
- }
- return 0;
+ /* Now this account */
+ for (split_p = priv->splits; split_p; split_p = g_list_next(split_p))
+ {
+ s = split_p->data;
+ trans = s->parent;
+ if (trans && (trans->marker < stage))
+ {
+ trans->marker = stage;
+ if (thunk)
+ {
+ retval = thunk(trans, cb_data);
+ if (retval) return retval;
+ }
+ }
+ }
+
+ return 0;
}
/********************************************************************\
@@ -4650,23 +4723,23 @@
int
xaccAccountTreeForEachTransaction (Account *acc,
- int (*proc)(Transaction *t, void *data),
- void *data)
+ int (*proc)(Transaction *t, void *data),
+ void *data)
{
- if (!acc || !proc) return 0;
+ if (!acc || !proc) return 0;
- gnc_account_tree_begin_staged_transaction_traversals (acc);
- return gnc_account_tree_staged_transaction_traversal (acc, 42, proc, data);
+ gnc_account_tree_begin_staged_transaction_traversals (acc);
+ return gnc_account_tree_staged_transaction_traversal (acc, 42, proc, data);
}
gint
xaccAccountForEachTransaction(const Account *acc, TransactionCallback proc,
- void *data)
+ void *data)
{
- if (!acc || !proc) return 0;
- xaccAccountBeginStagedTransactionTraversals (acc);
- return xaccAccountStagedTransactionTraversal(acc, 42, proc, data);
+ if (!acc || !proc) return 0;
+ xaccAccountBeginStagedTransactionTraversals (acc);
+ return xaccAccountStagedTransactionTraversal(acc, 42, proc, data);
}
/* ================================================================ */
@@ -4678,75 +4751,113 @@
#else
# define DI(x) x
#endif
-static QofObject account_object_def = {
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_ID_ACCOUNT,
- DI(.type_label =) "Account",
- DI(.create =) (gpointer)xaccMallocAccount,
- DI(.book_begin =) NULL,
- DI(.book_end =) NULL,
- DI(.is_dirty =) qof_collection_is_dirty,
- DI(.mark_clean =) qof_collection_mark_clean,
- DI(.foreach =) qof_collection_foreach,
- DI(.printable =) (const char* (*)(gpointer)) xaccAccountGetName,
- DI(.version_cmp =) (int (*)(gpointer,gpointer)) qof_instance_version_cmp,
+static QofObject account_object_def =
+{
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_ID_ACCOUNT,
+ DI(.type_label = ) "Account",
+ DI(.create = ) (gpointer)xaccMallocAccount,
+ DI(.book_begin = ) NULL,
+ DI(.book_end = ) NULL,
+ DI(.is_dirty = ) qof_collection_is_dirty,
+ DI(.mark_clean = ) qof_collection_mark_clean,
+ DI(.foreach = ) qof_collection_foreach,
+ DI(.printable = ) (const char * (*)(gpointer)) xaccAccountGetName,
+ DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
};
gboolean xaccAccountRegister (void)
{
- static QofParam params[] = {
- { ACCOUNT_NAME_, QOF_TYPE_STRING,
- (QofAccessFunc) xaccAccountGetName,
- (QofSetterFunc) xaccAccountSetName },
- { ACCOUNT_CODE_, QOF_TYPE_STRING,
- (QofAccessFunc) xaccAccountGetCode,
- (QofSetterFunc) xaccAccountSetCode },
- { ACCOUNT_DESCRIPTION_, QOF_TYPE_STRING,
- (QofAccessFunc) xaccAccountGetDescription,
- (QofSetterFunc) xaccAccountSetDescription },
- { ACCOUNT_COLOR_, QOF_TYPE_STRING,
- (QofAccessFunc) xaccAccountGetColor,
- (QofSetterFunc) xaccAccountSetColor },
- { ACCOUNT_NOTES_, QOF_TYPE_STRING,
- (QofAccessFunc) xaccAccountGetNotes,
- (QofSetterFunc) xaccAccountSetNotes },
- { ACCOUNT_PRESENT_, QOF_TYPE_NUMERIC,
- (QofAccessFunc) xaccAccountGetPresentBalance, NULL },
- { ACCOUNT_BALANCE_, QOF_TYPE_NUMERIC,
- (QofAccessFunc) xaccAccountGetBalance, NULL },
- { ACCOUNT_CLEARED_, QOF_TYPE_NUMERIC,
- (QofAccessFunc) xaccAccountGetClearedBalance, NULL },
- { ACCOUNT_RECONCILED_, QOF_TYPE_NUMERIC,
- (QofAccessFunc) xaccAccountGetReconciledBalance, NULL },
- { ACCOUNT_TYPE_, QOF_TYPE_STRING,
- (QofAccessFunc) qofAccountGetTypeString,
- (QofSetterFunc) qofAccountSetType },
- { ACCOUNT_FUTURE_MINIMUM_, QOF_TYPE_NUMERIC,
- (QofAccessFunc) xaccAccountGetProjectedMinimumBalance, NULL },
- { ACCOUNT_TAX_RELATED, QOF_TYPE_BOOLEAN,
- (QofAccessFunc) xaccAccountGetTaxRelated,
- (QofSetterFunc) xaccAccountSetTaxRelated },
- { ACCOUNT_SCU, QOF_TYPE_INT32,
- (QofAccessFunc) xaccAccountGetCommoditySCU,
- (QofSetterFunc) xaccAccountSetCommoditySCU },
- { ACCOUNT_NSCU, QOF_TYPE_BOOLEAN,
- (QofAccessFunc) xaccAccountGetNonStdSCU,
- (QofSetterFunc) xaccAccountSetNonStdSCU },
- { ACCOUNT_PARENT, GNC_ID_ACCOUNT,
- (QofAccessFunc) gnc_account_get_parent,
- (QofSetterFunc) qofAccountSetParent },
- { QOF_PARAM_BOOK, QOF_ID_BOOK,
- (QofAccessFunc) qof_instance_get_book, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID,
- (QofAccessFunc) qof_instance_get_guid, NULL },
- { ACCOUNT_KVP, QOF_TYPE_KVP,
- (QofAccessFunc) qof_instance_get_slots, NULL },
- { NULL },
- };
+ static QofParam params[] =
+ {
+ {
+ ACCOUNT_NAME_, QOF_TYPE_STRING,
+ (QofAccessFunc) xaccAccountGetName,
+ (QofSetterFunc) xaccAccountSetName
+ },
+ {
+ ACCOUNT_CODE_, QOF_TYPE_STRING,
+ (QofAccessFunc) xaccAccountGetCode,
+ (QofSetterFunc) xaccAccountSetCode
+ },
+ {
+ ACCOUNT_DESCRIPTION_, QOF_TYPE_STRING,
+ (QofAccessFunc) xaccAccountGetDescription,
+ (QofSetterFunc) xaccAccountSetDescription
+ },
+ {
+ ACCOUNT_COLOR_, QOF_TYPE_STRING,
+ (QofAccessFunc) xaccAccountGetColor,
+ (QofSetterFunc) xaccAccountSetColor
+ },
+ {
+ ACCOUNT_NOTES_, QOF_TYPE_STRING,
+ (QofAccessFunc) xaccAccountGetNotes,
+ (QofSetterFunc) xaccAccountSetNotes
+ },
+ {
+ ACCOUNT_PRESENT_, QOF_TYPE_NUMERIC,
+ (QofAccessFunc) xaccAccountGetPresentBalance, NULL
+ },
+ {
+ ACCOUNT_BALANCE_, QOF_TYPE_NUMERIC,
+ (QofAccessFunc) xaccAccountGetBalance, NULL
+ },
+ {
+ ACCOUNT_CLEARED_, QOF_TYPE_NUMERIC,
+ (QofAccessFunc) xaccAccountGetClearedBalance, NULL
+ },
+ {
+ ACCOUNT_RECONCILED_, QOF_TYPE_NUMERIC,
+ (QofAccessFunc) xaccAccountGetReconciledBalance, NULL
+ },
+ {
+ ACCOUNT_TYPE_, QOF_TYPE_STRING,
+ (QofAccessFunc) qofAccountGetTypeString,
+ (QofSetterFunc) qofAccountSetType
+ },
+ {
+ ACCOUNT_FUTURE_MINIMUM_, QOF_TYPE_NUMERIC,
+ (QofAccessFunc) xaccAccountGetProjectedMinimumBalance, NULL
+ },
+ {
+ ACCOUNT_TAX_RELATED, QOF_TYPE_BOOLEAN,
+ (QofAccessFunc) xaccAccountGetTaxRelated,
+ (QofSetterFunc) xaccAccountSetTaxRelated
+ },
+ {
+ ACCOUNT_SCU, QOF_TYPE_INT32,
+ (QofAccessFunc) xaccAccountGetCommoditySCU,
+ (QofSetterFunc) xaccAccountSetCommoditySCU
+ },
+ {
+ ACCOUNT_NSCU, QOF_TYPE_BOOLEAN,
+ (QofAccessFunc) xaccAccountGetNonStdSCU,
+ (QofSetterFunc) xaccAccountSetNonStdSCU
+ },
+ {
+ ACCOUNT_PARENT, GNC_ID_ACCOUNT,
+ (QofAccessFunc) gnc_account_get_parent,
+ (QofSetterFunc) qofAccountSetParent
+ },
+ {
+ QOF_PARAM_BOOK, QOF_ID_BOOK,
+ (QofAccessFunc) qof_instance_get_book, NULL
+ },
+ {
+ QOF_PARAM_GUID, QOF_TYPE_GUID,
+ (QofAccessFunc) qof_instance_get_guid, NULL
+ },
+ {
+ ACCOUNT_KVP, QOF_TYPE_KVP,
+ (QofAccessFunc) qof_instance_get_slots, NULL
+ },
+ { NULL },
+ };
- qof_class_register (GNC_ID_ACCOUNT, (QofSortFunc) qof_xaccAccountOrder, params);
+ qof_class_register (GNC_ID_ACCOUNT, (QofSortFunc) qof_xaccAccountOrder, params);
- return qof_object_register (&account_object_def);
+ return qof_object_register (&account_object_def);
}
/* ======================= END OF FILE =========================== */
Modified: gnucash/trunk/src/engine/Account.h
===================================================================
--- gnucash/trunk/src/engine/Account.h 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Account.h 2010-03-02 21:40:28 UTC (rev 18788)
@@ -36,8 +36,8 @@
convention, the value of an Account is equal to the value of all of its
Splits plus the value of all of its sub-Accounts.
@{ */
-/** @file Account.h
- @brief Account handling public routines
+/** @file Account.h
+ @brief Account handling public routines
@author Copyright (C) 1997 Robin D. Clark
@author Copyright (C) 1997-2003 Linas Vepstas <linas at linas.org>
*/
@@ -60,7 +60,8 @@
typedef void (*AccountCb)(Account *a, gpointer data);
typedef gpointer (*AccountCb2)(Account *a, gpointer data);
-typedef struct {
+typedef struct
+{
QofInstanceClass parent_class;
} AccountClass;
@@ -81,41 +82,41 @@
/** The account types are used to determine how the transaction data
* in the account is displayed. These values can be safely changed
* from one release to the next. Note that if values are added,
- * the file IO translation routines need to be updated. Note
+ * the file IO translation routines need to be updated. Note
* also that GUI code depends on these numbers.
*
* @note ***IMPORTANT***: If you do change the enumeration names (not the
* numbers), you need to update xaccAccountTypeEnumAsString --- used
* for text file exports */
-typedef enum
+typedef enum
{
- ACCT_TYPE_INVALID = -1, /**< Not a type */
- ACCT_TYPE_NONE = -1,/**< Not a type */
-
- ACCT_TYPE_BANK = 0, /**< The bank account type denotes a savings
+ ACCT_TYPE_INVALID = -1, /**< Not a type */
+ ACCT_TYPE_NONE = -1,/**< Not a type */
+
+ ACCT_TYPE_BANK = 0, /**< The bank account type denotes a savings
* or checking account held at a bank.
* Often * interest * bearing. */
- ACCT_TYPE_CASH = 1, /**< The cash account type is used to denote a
+ ACCT_TYPE_CASH = 1, /**< The cash account type is used to denote a
* shoe-box or pillowcase stuffed with *
* cash. */
- ACCT_TYPE_CREDIT = 3, /**< The Credit card account is used to denote
+ ACCT_TYPE_CREDIT = 3, /**< The Credit card account is used to denote
* credit (e.g. amex) and debit (e.g. visa,
* mastercard) * card accounts */
- ACCT_TYPE_ASSET = 2, /**< asset (and liability) accounts indicate
+ ACCT_TYPE_ASSET = 2, /**< asset (and liability) accounts indicate
* generic, generalized accounts that are
* none of the * above. */
- ACCT_TYPE_LIABILITY = 4,/**< liability (and asset) accounts indicate
+ ACCT_TYPE_LIABILITY = 4,/**< liability (and asset) accounts indicate
* generic, generalized accounts that are
* none of the * above. */
- ACCT_TYPE_STOCK = 5, /**< Stock accounts will typically be shown in
+ ACCT_TYPE_STOCK = 5, /**< Stock accounts will typically be shown in
* registers which show three columns:
* price, number of * shares, and value. */
- ACCT_TYPE_MUTUAL= 6, /**< Mutual Fund accounts will typically be
+ ACCT_TYPE_MUTUAL = 6, /**< Mutual Fund accounts will typically be
* shown in registers which show three
* columns: price, * number of shares, and
* value. */
- ACCT_TYPE_CURRENCY = 7,/**< The currency account type indicates that
+ ACCT_TYPE_CURRENCY = 7,/**< The currency account type indicates that
* the account is a currency trading
* account. In many * ways, a currency
* trading account is like a stock *
@@ -126,44 +127,44 @@
* no longer needed to exchange currencies
* between * accounts, so this type is
* DEPRECATED. */
- ACCT_TYPE_INCOME = 8, /**< Income accounts are used to denote
+ ACCT_TYPE_INCOME = 8, /**< Income accounts are used to denote
* income */
-
- ACCT_TYPE_EXPENSE = 9,/**< Expense accounts are used to denote
+
+ ACCT_TYPE_EXPENSE = 9,/**< Expense accounts are used to denote
* expenses. */
-
- ACCT_TYPE_EQUITY = 10,/**< Equity account is used to balance the
+
+ ACCT_TYPE_EQUITY = 10,/**< Equity account is used to balance the
* balance sheet. */
-
- ACCT_TYPE_RECEIVABLE = 11,/**< A/R account type */
- ACCT_TYPE_PAYABLE = 12, /**< A/P account type */
+ ACCT_TYPE_RECEIVABLE = 11,/**< A/R account type */
- ACCT_TYPE_ROOT = 13, /**< The hidden root account of an account tree. */
-
- ACCT_TYPE_TRADING = 14, /**< Account used to record multiple commodity transactions.
+ ACCT_TYPE_PAYABLE = 12, /**< A/P account type */
+
+ ACCT_TYPE_ROOT = 13, /**< The hidden root account of an account tree. */
+
+ ACCT_TYPE_TRADING = 14, /**< Account used to record multiple commodity transactions.
* This is not the same as ACCT_TYPE_CURRENCY above.
* Multiple commodity transactions have splits in these
- * accounts to make the transaction balance in each
+ * accounts to make the transaction balance in each
* commodity as well as in total value. */
- NUM_ACCOUNT_TYPES = 15, /**< stop here; the following types
+ NUM_ACCOUNT_TYPES = 15, /**< stop here; the following types
* just aren't ready for prime time */
-
- /* bank account types */
- ACCT_TYPE_CHECKING = 15, /**< bank account type -- don't use this
+
+ /* bank account types */
+ ACCT_TYPE_CHECKING = 15, /**< bank account type -- don't use this
* for now, see NUM_ACCOUNT_TYPES */
- ACCT_TYPE_SAVINGS = 16, /**< bank account type -- don't use this for
+ ACCT_TYPE_SAVINGS = 16, /**< bank account type -- don't use this for
* now, see NUM_ACCOUNT_TYPES */
- ACCT_TYPE_MONEYMRKT = 17, /**< bank account type -- don't use this
+ ACCT_TYPE_MONEYMRKT = 17, /**< bank account type -- don't use this
* for now, see NUM_ACCOUNT_TYPES */
- ACCT_TYPE_CREDITLINE = 18, /**< line of credit -- don't use this for
+ ACCT_TYPE_CREDITLINE = 18, /**< line of credit -- don't use this for
* now, see NUM_ACCOUNT_TYPES */
} GNCAccountType;
-/** @name Account Constructors, Edit/Commit, Comparison
+/** @name Account Constructors, Edit/Commit, Comparison
@{ */
/** Constructor */
@@ -172,49 +173,49 @@
/** Create a new root level account. */
Account * gnc_account_create_root (QofBook *book);
-/** The xaccCloneAccount() does the same as xaccCloneAccountSimple(),
+/** The xaccCloneAccount() does the same as xaccCloneAccountSimple(),
* except that it also also places a pair of GUID-pointers
* of each account to the other, in the other's kvp slot.
* The guid pointers are stored under the under the kvp
- * path "gemini".
+ * path "gemini".
*/
Account * xaccCloneAccount (const Account *from, QofBook *book);
/** The xaccCloneAccountSimple() routine makes a simple copy of the
* indicated account, placing it in the indicated book. It copies
* the account type, name, description, and the kvp values;
- * it does not copy splits/transactions. The book should have
+ * it does not copy splits/transactions. The book should have
* a commodity table in it that has commodities with the same
- * unique name as the ones being copied in the account (the
+ * unique name as the ones being copied in the account (the
* commodities in the clone will be those from the book).
- * Note that this routines does *NOT* use the 'gemini' kvp value
+ * Note that this routines does *NOT* use the 'gemini' kvp value
* to indicate where it was copied from.
*/
Account * xaccCloneAccountSimple (const Account *from, QofBook *book);
/** The xaccAccountBeginEdit() subroutine is the first phase of
- * a two-phase-commit wrapper for account updates. */
+ * a two-phase-commit wrapper for account updates. */
void xaccAccountBeginEdit (Account *account);
/** ThexaccAccountCommitEdit() subroutine is the second phase of
- * a two-phase-commit wrapper for account updates. */
+ * a two-phase-commit wrapper for account updates. */
void xaccAccountCommitEdit (Account *account);
/** The xaccAccountDestroy() routine can be used to get rid of an
- * account. The account should have been opened for editing
+ * account. The account should have been opened for editing
* (by calling xaccAccountBeginEdit()) before calling this routine.*/
void xaccAccountDestroy (Account *account);
/** Compare two accounts for equality - this is a deep compare. */
-gboolean xaccAccountEqual(const Account *a, const Account* b,
+gboolean xaccAccountEqual(const Account *a, const Account* b,
gboolean check_guids);
-/** The xaccAccountOrder() subroutine defines a sorting order
+/** The xaccAccountOrder() subroutine defines a sorting order
* on accounts. It takes pointers to two accounts, and
* returns -1 if the first account is "less than" the second,
* returns +1 if the first is "greater than" the second, and
* 0 if they are equal. To determine the sort order, first
- * the account codes are compared, and if these are equal, then
+ * the account codes are compared, and if these are equal, then
* account types, and, if these are equal, the account names.
*/
int xaccAccountOrder (const Account *account_1, const Account *account_2);
@@ -223,7 +224,7 @@
/* ------------------ */
-/** @name Account lookup and GUID routines
+/** @name Account lookup and GUID routines
@{ */
/** Returns the account separation character chosen by the user.
@@ -234,7 +235,8 @@
gunichar gnc_get_account_separator (void);
void gnc_set_account_separator (const gchar *separator);
-/*@ dependent @*/ Account *gnc_book_get_root_account(QofBook *book);
+/*@ dependent @*/
+Account *gnc_book_get_root_account(QofBook *book);
void gnc_book_set_root_account(QofBook *book, Account *root);
/** @deprecated */
@@ -251,7 +253,7 @@
/* ------------------ */
-/** @name Account general setters/getters
+/** @name Account general setters/getters
@{ */
QofBook *gnc_account_get_book(const Account *account);
@@ -294,7 +296,7 @@
* the 'starting balance' will represent the summation of the splits
* up to that date. */
void gnc_account_set_start_cleared_balance (Account *acc,
- const gnc_numeric start_baln);
+ const gnc_numeric start_baln);
/** This function will set the starting reconciled commodity balance
* for this account. This routine is intended for use with backends
@@ -304,7 +306,7 @@
* the 'starting balance' will represent the summation of the splits
* up to that date. */
void gnc_account_set_start_reconciled_balance (Account *acc,
- const gnc_numeric start_baln);
+ const gnc_numeric start_baln);
/** Tell the account that the running balances may be incorrect and
* need to be recomputed.
@@ -394,13 +396,13 @@
gboolean gnc_account_get_sort_dirty (Account *acc);
/** The following recompute the partial balances (stored with the
- * transaction) and the total balance, for this account
+ * transaction) and the total balance, for this account
*/
void xaccAccountRecomputeBalance (Account *);
-/** The xaccAccountSortSplits() routine will resort the account's
- * splits if the sort is dirty. If 'force' is true, the account
- * is sorted even if the editlevel is not zero.
+/** The xaccAccountSortSplits() routine will resort the account's
+ * splits if the sort is dirty. If 'force' is true, the account
+ * is sorted even if the editlevel is not zero.
*/
void xaccAccountSortSplits (Account *acc, gboolean force);
@@ -412,7 +414,7 @@
* given account. Each name is separated by the given character.
*
* @note: WAKE UP!
- * Unlike all other gets, the string returned by gnc_account_get_full_name()
+ * Unlike all other gets, the string returned by gnc_account_get_full_name()
* must be freed by you the user !!!
* hack alert -- since it breaks the rule of string allocation, maybe this
* routine should not be in this library, but some utility library?
@@ -438,8 +440,8 @@
charges or pays interest, this flag tells whether to prompt the
user to enter a transaction for the interest charge or
payment. This per-account flag overrides the global preference. */
-gboolean xaccAccountGetAutoInterestXfer (const Account *account,
- gboolean default_value);
+gboolean xaccAccountGetAutoInterestXfer (const Account *account,
+ gboolean default_value);
/** Sets a per-account flag: Prior to reconciling an account which
charges or pays interest, this flag tells whether to prompt the
user to enter a transaction for the interest charge or
@@ -459,11 +461,11 @@
* and 'value'. The 'value' of a split is the value of the amount
* expressed in the currency of the transaction. Thus, for example,
* the 'amount' may be 12 apples, where the account commodity is
- * 'apples'. The value of these 12 apples may be 12 dollars, where
+ * 'apples'. The value of these 12 apples may be 12 dollars, where
* the transaction currency is 'dollars'.
*
* The SCU is the 'Smallest Commodity Unit', signifying the smallest
- * non-zero amount that can be stored in the account. It is
+ * non-zero amount that can be stored in the account. It is
* represented as the integer denominator of a fraction. Thus,
* for example, a SCU of 12 means that 1/12 of something is the
* smallest amount that can be stored in the account. SCU's can
@@ -473,7 +475,7 @@
*
* Normally, the SCU is determined by the commodity of the account.
* However, this default SCU can be over-ridden and set to an
- * account-specific value. This is account-specific value is
+ * account-specific value. This is account-specific value is
* called the 'non-standard' value in the documentation below.
@{
*/
@@ -507,13 +509,13 @@
void xaccAccountSetCommoditySCU (Account *account, int frac);
/** @deprecated -- do not use for future development */
-#define xaccAccountSetCommoditySCUandFlag xaccAccountSetCommoditySCU
+#define xaccAccountSetCommoditySCUandFlag xaccAccountSetCommoditySCU
/** Set the flag indicating that this account uses a non-standard SCU. */
void xaccAccountSetNonStdSCU (Account *account, gboolean flag);
-/** Return boolean, indicating whether this account uses a
- * non-standard SCU. */
+/** Return boolean, indicating whether this account uses a
+ * non-standard SCU. */
gboolean xaccAccountGetNonStdSCU (const Account *account);
/**@}*/
@@ -533,8 +535,8 @@
gnc_numeric xaccAccountGetPresentBalance (const Account *account);
gnc_numeric xaccAccountGetProjectedMinimumBalance (const Account *account);
/** Get the balance of the account as of the date specified */
-gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account,
- time_t date);
+gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account,
+ time_t date);
/* These two functions convert a given balance from one commodity to
another. The account argument is only used to get the Book, and
@@ -561,7 +563,7 @@
const Account *account, const gnc_commodity *report_commodity,
gboolean include_children);
gnc_numeric xaccAccountGetClearedBalanceInCurrency (
- const Account *account, const gnc_commodity *report_commodity,
+ const Account *account, const gnc_commodity *report_commodity,
gboolean include_children);
gnc_numeric xaccAccountGetReconciledBalanceInCurrency (
const Account *account, const gnc_commodity *report_commodity,
@@ -584,17 +586,17 @@
/** @} */
-/** @name Account Children and Parents.
+/** @name Account Children and Parents.
- * The set of accounts is represented as a doubly-linked tree, so that given
- * any account, both its parent and its children can be easily found.
+ * The set of accounts is represented as a doubly-linked tree, so that given
+ * any account, both its parent and its children can be easily found.
* To make the management of sets of accounts easier, an account does not
* directly point at its children, but rather at an 'Account Group' that
* stores the children. At the top of the tree heirarchy lies a single
* root node, the root account group.
- *
- * The account tree heirarchy is unique, in that a given account can
- * have only one parent account.
+ *
+ * The account tree heirarchy is unique, in that a given account can
+ * have only one parent account.
@{
*/
@@ -637,7 +639,8 @@
*
* @return A pointer to the parent account node, or NULL if there is
* no parent account. */
-/*@ dependent @*/ Account * gnc_account_get_parent (const Account *account);
+/*@ dependent @*/
+Account * gnc_account_get_parent (const Account *account);
/** This routine returns the root account of the account tree that the
* specified account belongs to. It is the equivalent of repeatedly
@@ -783,7 +786,7 @@
*
* @param user_data This data will be passed to each call of func. */
void gnc_account_foreach_child (const Account *account,
- AccountCb func, /*@ null @*/ gpointer user_data);
+ AccountCb func, /*@ null @*/ gpointer user_data);
/** This method will traverse the immediate children of this accounts,
* calling 'func' on each account. Traversal will stop when func
@@ -801,7 +804,7 @@
*
* @param user_data This data will be passed to each call of func. */
gpointer gnc_account_foreach_child_until (const Account *account,
- AccountCb2 func, /*@ null @*/ gpointer user_data);
+ AccountCb2 func, /*@ null @*/ gpointer user_data);
/** This method will traverse all children of this accounts and their
@@ -818,7 +821,7 @@
*
* @param user_data This data will be passed to each call of func. */
void gnc_account_foreach_descendant (const Account *account,
- AccountCb func, /*@ null @*/ gpointer user_data);
+ AccountCb func, /*@ null @*/ gpointer user_data);
/** This method will traverse all children of this accounts and their
* descendants, calling 'func' on each account. Traversal will stop
@@ -836,7 +839,7 @@
*
* @param user_data This data will be passed to each call of func. */
gpointer gnc_account_foreach_descendant_until (const Account *account,
- AccountCb2 func, /*@ null @*/ gpointer user_data);
+ AccountCb2 func, /*@ null @*/ gpointer user_data);
/** @} */
@@ -907,7 +910,7 @@
* given separator.
*/
Account *gnc_account_lookup_by_full_name (const Account *any_account,
- const gchar *name);
+ const gchar *name);
/** The gnc_account_lookup_full_name() subroutine works like
* gnc_account_lookup_by_name, but uses the account code.
@@ -927,7 +930,7 @@
* that are used in persistant storage, communications. These
* strings should *not* be translated to the local language.
* Typical converstion is ACCT_TYPE_INCOME -> "INCOME". */
-const char * xaccAccountTypeEnumAsString (GNCAccountType type);
+const char * xaccAccountTypeEnumAsString (GNCAccountType type);
/**
* Conversion routines for the account types to/from strings
* that are used in persistant storage, communications. These
@@ -941,11 +944,11 @@
* Typical converstion is "INCOME" -> ACCT_TYPE_INCOME. */
GNCAccountType xaccAccountStringToEnum (const char* str);
-/** The xaccAccountGetTypeStr() routine returns a string suitable for
+/** The xaccAccountGetTypeStr() routine returns a string suitable for
* use in the GUI/Interface. These strings should be translated
* to the local language. */
-const char * xaccAccountGetTypeStr (GNCAccountType type);
-/** The xaccAccountGetTypeStr() routine returns a string suitable for
+const char * xaccAccountGetTypeStr (GNCAccountType type);
+/** The xaccAccountGetTypeStr() routine returns a string suitable for
* use in the GUI/Interface. These strings should be translated
* to the local language. */
GNCAccountType xaccAccountGetTypeFromStr (const gchar *str);
@@ -967,21 +970,21 @@
/* ------------------ */
-/** @name Account split/transaction list management
+/** @name Account split/transaction list management
@{
*/
/** The xaccAccountInsertSplit() method will insert the indicated
- * split into the indicated account. If the split already
+ * split into the indicated account. If the split already
* belongs to another account, it will be removed from that
* account first.*/
#define xaccAccountInsertSplit(acc, s) xaccSplitSetAccount((s), (acc))
/** The xaccAccountGetSplitList() routine returns a pointer to a GList of
- * the splits in the account.
- * @note This GList is the account's internal
+ * the splits in the account.
+ * @note This GList is the account's internal
* data structure: do not delete it when done; treat it as a read-only
* structure. Note that some routines (such as xaccAccountRemoveSplit())
- * modify this list directly, and could leave you with a corrupted
+ * modify this list directly, and could leave you with a corrupted
* pointer.
* @note This should be changed so that the returned value is a copy
* of the list. No other part of the code should have access to the
@@ -1006,15 +1009,15 @@
* pointed to by at least one split in the given account.
*
* The result of this function will be 0 <em>if and only if</em>
- * every relevant transaction was traversed exactly once.
+ * every relevant transaction was traversed exactly once.
* Else the return value is the last non-zero value returned by proc.
*
* \warning For performance reasons, the transaction callback @a proc
* must never destroy any of the transaction's splits, nor assign any
* of them to a different account. <b>To do so risks a crash.</b>
*
- * \warning The traversal occurs only over the transactions that
- * are locally cached in the local gnucash engine. If the gnucash
+ * \warning The traversal occurs only over the transactions that
+ * are locally cached in the local gnucash engine. If the gnucash
* engine is attached to a remote database, the database may contain
* (many) transactions that are not mirrored in the local cache.
* This routine will not cause an SQL database query to be performed;
@@ -1026,22 +1029,22 @@
void *data);
/** Returns a pointer to the transaction, not a copy. */
-Transaction * xaccAccountFindTransByDesc(const Account *account,
- const char *description);
+Transaction * xaccAccountFindTransByDesc(const Account *account,
+ const char *description);
/** Returns a pointer to the split, not a copy. */
-Split * xaccAccountFindSplitByDesc(const Account *account,
+Split * xaccAccountFindSplitByDesc(const Account *account,
const char *description);
/** @} */
/* ------------------ */
-/** @name Account lots
+/** @name Account lots
@{
*/
-/** The xaccAccountInsertLot() method will register the indicated lot
- * with this account. Any splits later inserted into this lot must
+/** The xaccAccountInsertLot() method will register the indicated lot
+ * with this account. Any splits later inserted into this lot must
* belong to this account. If the lot is already in another account,
* the lot, and all of the splits in it, will be moved from that
* account to this account. */
@@ -1075,41 +1078,41 @@
* The caller must free to returned list.
*/
LotList * xaccAccountFindOpenLots (const Account *acc,
- gboolean (*match_func)(GNCLot *lot,
- gpointer user_data),
- /*@ null @*/ gpointer user_data, GCompareFunc sort_func);
+ gboolean (*match_func)(GNCLot *lot,
+ gpointer user_data),
+ /*@ null @*/ gpointer user_data, GCompareFunc sort_func);
/** @} */
/* ------------------ */
-/** @name Account Reconciliation information getters/setters
+/** @name Account Reconciliation information getters/setters
@{
*/
/** DOCUMENT ME! */
gboolean xaccAccountGetReconcileLastDate (const Account *account,
- time_t *last_date);
+ time_t *last_date);
/** DOCUMENT ME! */
void xaccAccountSetReconcileLastDate (Account *account, time_t last_date);
/** DOCUMENT ME! */
gboolean xaccAccountGetReconcileLastInterval (const Account *account,
- int *months, int *days);
+ int *months, int *days);
/** DOCUMENT ME! */
void xaccAccountSetReconcileLastInterval (Account *account,
- int months, int days);
+ int months, int days);
/** DOCUMENT ME! */
gboolean xaccAccountGetReconcilePostponeDate (const Account *account,
- time_t *postpone_date);
+ time_t *postpone_date);
/** DOCUMENT ME! */
-void xaccAccountSetReconcilePostponeDate (Account *account,
- time_t postpone_date);
+void xaccAccountSetReconcilePostponeDate (Account *account,
+ time_t postpone_date);
/** DOCUMENT ME! */
gboolean xaccAccountGetReconcilePostponeBalance (const Account *account,
- gnc_numeric *balance);
+ gnc_numeric *balance);
/** DOCUMENT ME! */
void xaccAccountSetReconcilePostponeBalance (Account *account,
- gnc_numeric balance);
+ gnc_numeric balance);
/** DOCUMENT ME! */
void xaccAccountClearReconcilePostpone (Account *account);
@@ -1117,14 +1120,14 @@
/** DOCUMENT ME! */
-typedef enum
- {
- PLACEHOLDER_NONE,
- PLACEHOLDER_THIS,
- PLACEHOLDER_CHILD,
- } GNCPlaceholderType;
+typedef enum
+{
+ PLACEHOLDER_NONE,
+ PLACEHOLDER_THIS,
+ PLACEHOLDER_CHILD,
+} GNCPlaceholderType;
-/** @name Account Placeholder flag
+/** @name Account Placeholder flag
@{
*/
@@ -1152,7 +1155,7 @@
GNCPlaceholderType xaccAccountGetDescendantPlaceholder(const Account *account);
/** @} */
-/** @name Account Hidden flag
+/** @name Account Hidden flag
@{
*/
@@ -1209,7 +1212,7 @@
/** @} */
-/** @name Account marking
+/** @name Account marking
@{
*/
/** Set a mark on the account. The meaning of this mark is
@@ -1218,7 +1221,7 @@
* over the account tree. The mark is *not* stored in the database/file
* format. When accounts are newly created, the mark is set to zero.
*/
-void xaccAccountSetMark (Account *account, short mark);
+void xaccAccountSetMark (Account *account, short mark);
/** Get the mark set by xaccAccountSetMark */
short xaccAccountGetMark (const Account *account);
@@ -1237,8 +1240,8 @@
* The following functions provide support for "staged traversals"
* over all of the transactions in an account or group. The idea
* is to be able to perform a sequence of traversals ("stages"),
- * and perform an operation on each transaction exactly once
- * for that stage.
+ * and perform an operation on each transaction exactly once
+ * for that stage.
*
* Only transactions whose current "stage" is less than the
* stage of the current traversal will be affected, and they will
@@ -1252,13 +1255,13 @@
* second account since they had been processed while traversing the
* first account.
*
- * However, if you had traversed the second account using a stage
- * of 2, then all the transactions in the second account would have
+ * However, if you had traversed the second account using a stage
+ * of 2, then all the transactions in the second account would have
* been processed.
*
* Traversal can be aborted by having the callback function return
- * a non-zero value. The traversal is aborted immediately, and the
- * non-zero value is returned. Note that an aborted traversal can
+ * a non-zero value. The traversal is aborted immediately, and the
+ * non-zero value is returned. Note that an aborted traversal can
* be restarted; no information is lost due to an abort.
*
* The initial impetus for this particular approach came from
@@ -1316,9 +1319,9 @@
*/
int xaccAccountStagedTransactionTraversal(const Account *a,
- unsigned int stage,
- TransactionCallback thunk,
- void *data);
+ unsigned int stage,
+ TransactionCallback thunk,
+ void *data);
/** gnc_account_tree_staged_transaction_traversal() calls @a thunk on each
* transaction in the group whose current marker is less than the
@@ -1334,9 +1337,9 @@
*/
int gnc_account_tree_staged_transaction_traversal(const Account *account,
- unsigned int stage,
- TransactionCallback thunk,
- void *data);
+ unsigned int stage,
+ TransactionCallback thunk,
+ void *data);
/** Traverse all of the transactions in the given account group.
* Continue processing IFF @a proc returns 0. This function
@@ -1369,14 +1372,14 @@
* gnc_account_tree_staged_transaction_traversal(g, 42, proc, data);
*/
-int xaccAccountTreeForEachTransaction(Account *acc,
- TransactionCallback proc, void *data);
+int xaccAccountTreeForEachTransaction(Account *acc,
+ TransactionCallback proc, void *data);
/** @} */
-/** @name Deprecated Routines.
- @{
+/** @name Deprecated Routines.
+ @{
*/
/** @deprecated The current API associates only one thing with an
@@ -1409,7 +1412,7 @@
/** @} */
-/** @name Account parameter names
+/** @name Account parameter names
@{
*/
#define ACCOUNT_KVP "kvp"
Modified: gnucash/trunk/src/engine/Period.c
===================================================================
--- gnucash/trunk/src/engine/Period.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Period.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -23,7 +23,7 @@
* Period.c
*
* FUNCTION:
- * Implement accounting periods, using design described in
+ * Implement accounting periods, using design described in
* src/doc/books.txt
*
* CAUTION: poorly tested.
@@ -51,206 +51,206 @@
static inline Account *
xaccAccountLookupTwin (Account *acc, QofBook *book)
{
- return (Account *) qof_instance_lookup_twin (QOF_INSTANCE(acc), book);
+ return (Account *) qof_instance_lookup_twin (QOF_INSTANCE(acc), book);
}
/* ================================================================ */
-/* Reparent transaction to new book. This routine does this by
+/* Reparent transaction to new book. This routine does this by
* deleting the transaction in the old book, and creating a copy
- * in the new book. While technically correct, this is maybe too
- * much churn on the backend ...
+ * in the new book. While technically correct, this is maybe too
+ * much churn on the backend ...
*/
void
gnc_book_insert_trans_clobber (QofBook *book, Transaction *trans)
{
- QofCollection *col;
- Transaction *newtrans;
- GList *node;
+ QofCollection *col;
+ Transaction *newtrans;
+ GList *node;
- if (!trans || !book) return;
-
- /* If this is the same book, its a no-op. */
- if (qof_instance_get_book(trans) == book) return;
+ if (!trans || !book) return;
- ENTER ("trans=%p %s", trans, trans->description);
- newtrans = xaccDupeTransaction (trans);
- for (node = newtrans->splits; node; node = node->next)
- {
- Split *s = node->data;
- s->parent = newtrans;
- }
+ /* If this is the same book, its a no-op. */
+ if (qof_instance_get_book(trans) == book) return;
- /* Utterly wipe out the transaction from the old book. */
- xaccTransBeginEdit (trans);
- xaccTransDestroy (trans);
- xaccTransCommitEdit (trans);
+ ENTER ("trans=%p %s", trans, trans->description);
+ newtrans = xaccDupeTransaction (trans);
+ for (node = newtrans->splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ s->parent = newtrans;
+ }
- /* Fiddle the transaction into place in the new book */
- col = qof_book_get_collection (book, GNC_ID_TRANS);
- qof_collection_insert_entity (col, &newtrans->inst);
- qof_instance_set_book(newtrans, book);
+ /* Utterly wipe out the transaction from the old book. */
+ xaccTransBeginEdit (trans);
+ xaccTransDestroy (trans);
+ xaccTransCommitEdit (trans);
- col = qof_book_get_collection (book, GNC_ID_SPLIT);
- xaccTransBeginEdit (newtrans);
- for (node = newtrans->splits; node; node = node->next)
- {
- Account *twin;
- Split *s = node->data;
+ /* Fiddle the transaction into place in the new book */
+ col = qof_book_get_collection (book, GNC_ID_TRANS);
+ qof_collection_insert_entity (col, &newtrans->inst);
+ qof_instance_set_book(newtrans, book);
- /* move the split into the new book ... */
- qof_instance_set_book(s, book);
- qof_collection_insert_entity(col, &s->inst);
+ col = qof_book_get_collection (book, GNC_ID_SPLIT);
+ xaccTransBeginEdit (newtrans);
+ for (node = newtrans->splits; node; node = node->next)
+ {
+ Account *twin;
+ Split *s = node->data;
- /* find the twin account, and re-parent to that. */
- twin = xaccAccountLookupTwin (s->acc, book);
- if (!twin)
- {
- PERR ("near-fatal: twin account not found");
- }
- else
- {
- xaccAccountInsertSplit (twin, s);
- g_object_set(twin, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
- }
- }
+ /* move the split into the new book ... */
+ qof_instance_set_book(s, book);
+ qof_collection_insert_entity(col, &s->inst);
- xaccTransCommitEdit (newtrans);
- qof_event_gen (&newtrans->inst, QOF_EVENT_CREATE, NULL);
- LEAVE ("trans=%p %s", trans, trans->description);
+ /* find the twin account, and re-parent to that. */
+ twin = xaccAccountLookupTwin (s->acc, book);
+ if (!twin)
+ {
+ PERR ("near-fatal: twin account not found");
+ }
+ else
+ {
+ xaccAccountInsertSplit (twin, s);
+ g_object_set(twin, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
+ }
+ }
+
+ xaccTransCommitEdit (newtrans);
+ qof_event_gen (&newtrans->inst, QOF_EVENT_CREATE, NULL);
+ LEAVE ("trans=%p %s", trans, trans->description);
}
/* ================================================================ */
-/* Reparent transaction to new book. This routine does this by
+/* Reparent transaction to new book. This routine does this by
* moving GUID's to the new book's entity tables.
*/
void
gnc_book_insert_trans (QofBook *book, Transaction *trans)
{
- QofCollection *col;
- QofBook *trans_book;
- GList *node;
+ QofCollection *col;
+ QofBook *trans_book;
+ GList *node;
- if (!trans || !book) return;
-
- /* If this is the same book, its a no-op. */
- trans_book = qof_instance_get_book(trans);
- if (trans_book == book) return;
+ if (!trans || !book) return;
- /* If the old and new book don't share backends, then clobber-copy;
- * i.e. destroy it in one backend, create it in another. */
- if (qof_book_get_backend(book) != qof_book_get_backend(trans_book))
- {
- gnc_book_insert_trans_clobber (book, trans);
- return;
- }
- ENTER ("trans=%p %s", trans, trans->description);
+ /* If this is the same book, its a no-op. */
+ trans_book = qof_instance_get_book(trans);
+ if (trans_book == book) return;
- /* Fiddle the transaction into place in the new book */
- xaccTransBeginEdit (trans);
+ /* If the old and new book don't share backends, then clobber-copy;
+ * i.e. destroy it in one backend, create it in another. */
+ if (qof_book_get_backend(book) != qof_book_get_backend(trans_book))
+ {
+ gnc_book_insert_trans_clobber (book, trans);
+ return;
+ }
+ ENTER ("trans=%p %s", trans, trans->description);
- col = qof_book_get_collection (book, GNC_ID_TRANS);
- qof_instance_set_book(trans, book);
- qof_collection_insert_entity (col, &trans->inst);
+ /* Fiddle the transaction into place in the new book */
+ xaccTransBeginEdit (trans);
- col = qof_book_get_collection (book, GNC_ID_SPLIT);
- for (node = trans->splits; node; node = node->next)
- {
- Account *twin;
- Split *s = node->data;
+ col = qof_book_get_collection (book, GNC_ID_TRANS);
+ qof_instance_set_book(trans, book);
+ qof_collection_insert_entity (col, &trans->inst);
- /* Move the splits over (only if they haven't already been moved). */
- if (qof_instance_get_book(s) != book)
- {
- qof_instance_set_book(s, book);
- qof_collection_insert_entity (col, &s->inst);
- }
+ col = qof_book_get_collection (book, GNC_ID_SPLIT);
+ for (node = trans->splits; node; node = node->next)
+ {
+ Account *twin;
+ Split *s = node->data;
- /* Find the twin account, and re-parent to that. */
- twin = xaccAccountLookupTwin (s->acc, book);
- if (!twin)
- {
- PERR ("near-fatal: twin account not found");
- }
- else
- {
- /* Move the split too, if it hasn't been moved already */
- if (s->acc != twin)
+ /* Move the splits over (only if they haven't already been moved). */
+ if (qof_instance_get_book(s) != book)
{
- xaccAccountInsertSplit (twin, s);
- g_object_set(twin, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
+ qof_instance_set_book(s, book);
+ qof_collection_insert_entity (col, &s->inst);
}
- }
- }
- xaccTransCommitEdit (trans);
- qof_event_gen (&trans->inst, QOF_EVENT_MODIFY, NULL);
- LEAVE ("trans=%p %s", trans, trans->description);
+ /* Find the twin account, and re-parent to that. */
+ twin = xaccAccountLookupTwin (s->acc, book);
+ if (!twin)
+ {
+ PERR ("near-fatal: twin account not found");
+ }
+ else
+ {
+ /* Move the split too, if it hasn't been moved already */
+ if (s->acc != twin)
+ {
+ xaccAccountInsertSplit (twin, s);
+ g_object_set(twin, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
+ }
+ }
+ }
+
+ xaccTransCommitEdit (trans);
+ qof_event_gen (&trans->inst, QOF_EVENT_MODIFY, NULL);
+ LEAVE ("trans=%p %s", trans, trans->description);
}
/* ================================================================ */
-/* Reparent lot to new book. This routine does this by
+/* Reparent lot to new book. This routine does this by
* completely deleting and recreating the lot.
*/
void
gnc_book_insert_lot_clobber (QofBook *book, GNCLot *lot)
{
- PERR ("Not Implemented");
+ PERR ("Not Implemented");
}
/* ================================================================ */
-/* Reparent lot to new book. This routine does this by
+/* Reparent lot to new book. This routine does this by
* moving GUID's to the new book's entity tables.
*/
void
gnc_book_insert_lot (QofBook *book, GNCLot *lot)
{
- QofCollection *col;
- SplitList *snode;
- Account *twin;
+ QofCollection *col;
+ SplitList *snode;
+ Account *twin;
- if (!lot || !book) return;
-
- /* If this is the same book, its a no-op. */
- if (gnc_lot_get_book(lot) == book) return;
+ if (!lot || !book) return;
- if (qof_book_get_backend(book) !=
- qof_book_get_backend(gnc_lot_get_book(lot)))
- {
- gnc_book_insert_lot_clobber (book, lot);
- return;
- }
- ENTER ("lot=%p", lot);
+ /* If this is the same book, its a no-op. */
+ if (gnc_lot_get_book(lot) == book) return;
- col = qof_book_get_collection (book, GNC_ID_LOT);
- qof_instance_set_book(lot, book);
- qof_collection_insert_entity (col, QOF_INSTANCE(lot));
+ if (qof_book_get_backend(book) !=
+ qof_book_get_backend(gnc_lot_get_book(lot)))
+ {
+ gnc_book_insert_lot_clobber (book, lot);
+ return;
+ }
+ ENTER ("lot=%p", lot);
- /* Move the splits over (only if they haven't already been moved). */
- col = qof_book_get_collection (book, GNC_ID_SPLIT);
- for (snode = gnc_lot_get_split_list(lot); snode; snode=snode->next)
- {
- Split *s = snode->data;
- if (qof_instance_get_book(s) != book)
- {
- qof_instance_set_book(s, book);
- qof_collection_insert_entity (col, &s->inst);
- }
- }
+ col = qof_book_get_collection (book, GNC_ID_LOT);
+ qof_instance_set_book(lot, book);
+ qof_collection_insert_entity (col, QOF_INSTANCE(lot));
- twin = xaccAccountLookupTwin (gnc_lot_get_account(lot), book);
- if (!twin)
- {
- PERR ("near-fatal: twin account not found");
- }
- else
- {
- xaccAccountInsertLot (twin, lot);
- }
- LEAVE ("lot=%p", lot);
+ /* Move the splits over (only if they haven't already been moved). */
+ col = qof_book_get_collection (book, GNC_ID_SPLIT);
+ for (snode = gnc_lot_get_split_list(lot); snode; snode = snode->next)
+ {
+ Split *s = snode->data;
+ if (qof_instance_get_book(s) != book)
+ {
+ qof_instance_set_book(s, book);
+ qof_collection_insert_entity (col, &s->inst);
+ }
+ }
+
+ twin = xaccAccountLookupTwin (gnc_lot_get_account(lot), book);
+ if (!twin)
+ {
+ PERR ("near-fatal: twin account not found");
+ }
+ else
+ {
+ xaccAccountInsertLot (twin, lot);
+ }
+ LEAVE ("lot=%p", lot);
}
/* ================================================================ */
@@ -258,39 +258,39 @@
void
gnc_book_insert_price (QofBook *book, GNCPrice *pr)
{
- QofCollection *col;
- QofBook *pr_book;
+ QofCollection *col;
+ QofBook *pr_book;
- if (!pr || !book) return;
-
- /* If this is the same book, its a no-op. */
- pr_book = qof_instance_get_book(pr);
- if (pr_book == book) return;
+ if (!pr || !book) return;
- /* If the old and new book don't share backends, then clobber-copy;
- * i.e. destroy it in one backend, create it in another. */
- if (qof_book_get_backend(book) != qof_book_get_backend(pr_book))
- {
- gnc_book_insert_price_clobber (book, pr);
- return;
- }
- ENTER ("price=%p", pr);
+ /* If this is the same book, its a no-op. */
+ pr_book = qof_instance_get_book(pr);
+ if (pr_book == book) return;
- /* Fiddle the price into place in the new book */
- gnc_price_ref (pr);
- gnc_price_begin_edit (pr);
+ /* If the old and new book don't share backends, then clobber-copy;
+ * i.e. destroy it in one backend, create it in another. */
+ if (qof_book_get_backend(book) != qof_book_get_backend(pr_book))
+ {
+ gnc_book_insert_price_clobber (book, pr);
+ return;
+ }
+ ENTER ("price=%p", pr);
- col = qof_book_get_collection (book, GNC_ID_PRICE);
- qof_instance_set_book(pr, book);
- qof_collection_insert_entity (col, &pr->inst);
+ /* Fiddle the price into place in the new book */
+ gnc_price_ref (pr);
+ gnc_price_begin_edit (pr);
- gnc_pricedb_remove_price (pr->db, pr);
- gnc_pricedb_add_price (gnc_pricedb_get_db (book), pr);
+ col = qof_book_get_collection (book, GNC_ID_PRICE);
+ qof_instance_set_book(pr, book);
+ qof_collection_insert_entity (col, &pr->inst);
- gnc_price_commit_edit (pr);
- gnc_price_unref (pr);
+ gnc_pricedb_remove_price (pr->db, pr);
+ gnc_pricedb_add_price (gnc_pricedb_get_db (book), pr);
- LEAVE ("price=%p", pr);
+ gnc_price_commit_edit (pr);
+ gnc_price_unref (pr);
+
+ LEAVE ("price=%p", pr);
}
/* ================================================================ */
@@ -298,30 +298,30 @@
void
gnc_book_insert_price_clobber (QofBook *book, GNCPrice *pr)
{
- PERR ("Not Implemented");
+ PERR ("Not Implemented");
}
/* ================================================================ */
-/* The following routines determine whether a given lot or
+/* The following routines determine whether a given lot or
* transaction is linked or related to another lot that is 'open'.
* These return true if so.
*
- * An 'open transaction' is a transaction that has a split
+ * An 'open transaction' is a transaction that has a split
* that belongs to an 'open lot'. An 'open lot' is one that
- * is not closed, OR ONE THAT HAS a split in it that belongs to
- * an open transaction.
+ * is not closed, OR ONE THAT HAS a split in it that belongs to
+ * an open transaction.
*
- * The need for this recursive definition is that some lots,
+ * The need for this recursive definition is that some lots,
* even though themselves closed, are participants in transactions
- * that cannot be moved to a closed book, and thus, by association
+ * that cannot be moved to a closed book, and thus, by association
* can't be moved either.
*
- * Lots contain pointers to splits, and transactions contain
+ * Lots contain pointers to splits, and transactions contain
* pointers to splits. Together, these form a graph, which may
* be cyclic. We want to walk the entire graph, and determine
- * whether there are any open lots in it. The walk must be
+ * whether there are any open lots in it. The walk must be
* recursive, and because it might be cyclic, we use a marker
- * to break the cycles.
+ * to break the cycles.
*/
static gboolean trans_has_open_lot_tree (Transaction *trans);
@@ -330,55 +330,55 @@
static gboolean
trans_has_open_lot_tree (Transaction *trans)
{
- SplitList *split_list, *node;
+ SplitList *split_list, *node;
- if (1 == trans->marker) return FALSE;
- if (2 == trans->marker) return TRUE;
- trans->marker = 1;
+ if (1 == trans->marker) return FALSE;
+ if (2 == trans->marker) return TRUE;
+ trans->marker = 1;
- split_list = xaccTransGetSplitList (trans);
- for (node = split_list; node; node=node->next)
- {
- Split *s = node->data;
- GNCLot *lot = s->lot;
- if (NULL == lot) continue;
- if ((FALSE == gnc_lot_is_closed(lot)) ||
- (lot_has_open_trans_tree (lot)))
- {
- trans->marker = 2;
- return TRUE;
- }
- }
- return FALSE;
+ split_list = xaccTransGetSplitList (trans);
+ for (node = split_list; node; node = node->next)
+ {
+ Split *s = node->data;
+ GNCLot *lot = s->lot;
+ if (NULL == lot) continue;
+ if ((FALSE == gnc_lot_is_closed(lot)) ||
+ (lot_has_open_trans_tree (lot)))
+ {
+ trans->marker = 2;
+ return TRUE;
+ }
+ }
+ return FALSE;
}
-static gboolean
+static gboolean
lot_has_open_trans_tree (GNCLot *lot)
{
- SplitList *split_list, *snode;
+ SplitList *split_list, *snode;
- if (1 == gnc_lot_get_marker(lot)) return FALSE;
- if (2 == gnc_lot_get_marker(lot)) return TRUE;
- gnc_lot_set_marker(lot, 1);
+ if (1 == gnc_lot_get_marker(lot)) return FALSE;
+ if (2 == gnc_lot_get_marker(lot)) return TRUE;
+ gnc_lot_set_marker(lot, 1);
- if (FALSE == gnc_lot_is_closed(lot))
- {
- gnc_lot_set_marker(lot, 2);
- return TRUE;
- }
+ if (FALSE == gnc_lot_is_closed(lot))
+ {
+ gnc_lot_set_marker(lot, 2);
+ return TRUE;
+ }
- split_list = gnc_lot_get_split_list (lot);
- for (snode = split_list; snode; snode=snode->next)
- {
- Split *s = snode->data;
- Transaction *trans = s->parent;
- if (trans_has_open_lot_tree (trans))
- {
- gnc_lot_set_marker(lot, 2);
- return TRUE;
- }
- }
- return FALSE;
+ split_list = gnc_lot_get_split_list (lot);
+ for (snode = split_list; snode; snode = snode->next)
+ {
+ Split *s = snode->data;
+ Transaction *trans = s->parent;
+ if (trans_has_open_lot_tree (trans))
+ {
+ gnc_lot_set_marker(lot, 2);
+ return TRUE;
+ }
+ }
+ return FALSE;
}
/* ================================================================ */
@@ -389,44 +389,44 @@
static LotList *
lot_list_preen_open_lots (LotList *lot_list)
{
- LotList *lnode;
- ENTER (" ");
- for (lnode=lot_list; lnode; )
- {
- GNCLot *lot = lnode->data;
- LotList *lnext = lnode->next;
+ LotList *lnode;
+ ENTER (" ");
+ for (lnode = lot_list; lnode; )
+ {
+ GNCLot *lot = lnode->data;
+ LotList *lnext = lnode->next;
- if (lot_has_open_trans_tree (lot))
- lot_list = g_list_delete_link(lot_list, lnode);
- lnode = lnext;
- }
- LEAVE (" ");
- return lot_list;
+ if (lot_has_open_trans_tree (lot))
+ lot_list = g_list_delete_link(lot_list, lnode);
+ lnode = lnext;
+ }
+ LEAVE (" ");
+ return lot_list;
}
static TransList *
trans_list_preen_open_lots (TransList *trans_list)
{
- TransList *tnode;
+ TransList *tnode;
- ENTER (" ");
- for (tnode=trans_list; tnode; )
- {
- Transaction *trans = tnode->data;
- TransList *tnext = tnode->next;
+ ENTER (" ");
+ for (tnode = trans_list; tnode; )
+ {
+ Transaction *trans = tnode->data;
+ TransList *tnext = tnode->next;
- if (trans_has_open_lot_tree (trans))
- {
- trans_list = g_list_remove_link (trans_list, tnode);
- /* XXX freeing this node somehow leads to glib g_list
- * memory corruption which later takes down the system.
- * I don't see why. */
- /* g_list_free_1 (tnode); */
- }
- tnode = tnext;
- }
- LEAVE (" ");
- return trans_list;
+ if (trans_has_open_lot_tree (trans))
+ {
+ trans_list = g_list_remove_link (trans_list, tnode);
+ /* XXX freeing this node somehow leads to glib g_list
+ * memory corruption which later takes down the system.
+ * I don't see why. */
+ /* g_list_free_1 (tnode); */
+ }
+ tnode = tnext;
+ }
+ LEAVE (" ");
+ return trans_list;
}
/* ================================================================ */
@@ -435,17 +435,18 @@
static void
clear_markers (Account *account, gpointer dummy)
{
- GList *lp;
+ GList *lp;
- if (!account) return;
+ if (!account) return;
- for (lp = xaccAccountGetSplitList(account); lp; lp = lp->next) {
- Split *s = lp->data;
- Transaction *trans = s->parent;
- GNCLot *lot = s->lot;
- trans->marker = 0;
- if (lot) gnc_lot_set_marker(lot, 0);
- }
+ for (lp = xaccAccountGetSplitList(account); lp; lp = lp->next)
+ {
+ Split *s = lp->data;
+ Transaction *trans = s->parent;
+ GNCLot *lot = s->lot;
+ trans->marker = 0;
+ if (lot) gnc_lot_set_marker(lot, 0);
+ }
}
/* ================================================================ */
@@ -456,136 +457,136 @@
static LotList *
create_lot_list_from_trans_list (TransList *trans_list)
{
- LotList *lot_list = NULL;
- TransList *tnode;
+ LotList *lot_list = NULL;
+ TransList *tnode;
- for (tnode=trans_list; tnode; tnode=tnode->next)
- {
- Transaction *trans = tnode->data;
- SplitList *split_list = xaccTransGetSplitList (trans);
- SplitList *snode;
- for (snode = split_list; snode; snode=snode->next)
- {
- Split *s = snode->data;
- GNCLot *lot = xaccSplitGetLot(s);
- if (NULL == lot) continue;
- if (g_list_find (lot_list, lot)) continue;
- lot_list = g_list_prepend (lot_list, lot);
- }
- }
- return lot_list;
+ for (tnode = trans_list; tnode; tnode = tnode->next)
+ {
+ Transaction *trans = tnode->data;
+ SplitList *split_list = xaccTransGetSplitList (trans);
+ SplitList *snode;
+ for (snode = split_list; snode; snode = snode->next)
+ {
+ Split *s = snode->data;
+ GNCLot *lot = xaccSplitGetLot(s);
+ if (NULL == lot) continue;
+ if (g_list_find (lot_list, lot)) continue;
+ lot_list = g_list_prepend (lot_list, lot);
+ }
+ }
+ return lot_list;
}
/* ================================================================ */
-void
+void
gnc_book_partition_pricedb (QofBook *dest_book, QofBook *src_book, QofQuery *query)
{
- GNCPriceDB *src_pdb, *dest_pdb;
- GList *price_list, *pnode;
+ GNCPriceDB *src_pdb, *dest_pdb;
+ GList *price_list, *pnode;
- if (!src_book || !dest_book || !query) return;
- ENTER (" src_book=%p dest_book=%p", src_book, dest_book);
+ if (!src_book || !dest_book || !query) return;
+ ENTER (" src_book=%p dest_book=%p", src_book, dest_book);
- src_pdb = gnc_pricedb_get_db (src_book);
- dest_pdb = gnc_pricedb_get_db (dest_book);
+ src_pdb = gnc_pricedb_get_db (src_book);
+ dest_pdb = gnc_pricedb_get_db (dest_book);
- gnc_pricedb_begin_edit (src_pdb);
- gnc_pricedb_begin_edit (dest_pdb);
- gnc_pricedb_set_bulk_update (dest_pdb, TRUE);
+ gnc_pricedb_begin_edit (src_pdb);
+ gnc_pricedb_begin_edit (dest_pdb);
+ gnc_pricedb_set_bulk_update (dest_pdb, TRUE);
- qof_query_set_book (query, src_book);
- price_list = qof_query_run (query);
+ qof_query_set_book (query, src_book);
+ price_list = qof_query_run (query);
-printf ("duude XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX prices\n");
- for (pnode = price_list; pnode; pnode=pnode->next)
- {
- GNCPrice *pr = pnode->data;
- gnc_book_insert_price (dest_book, pr);
- }
+ printf ("duude XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX prices\n");
+ for (pnode = price_list; pnode; pnode = pnode->next)
+ {
+ GNCPrice *pr = pnode->data;
+ gnc_book_insert_price (dest_book, pr);
+ }
- gnc_pricedb_set_bulk_update (dest_pdb, FALSE);
- gnc_pricedb_commit_edit (dest_pdb);
- gnc_pricedb_commit_edit (src_pdb);
+ gnc_pricedb_set_bulk_update (dest_pdb, FALSE);
+ gnc_pricedb_commit_edit (dest_pdb);
+ gnc_pricedb_commit_edit (src_pdb);
- LEAVE (" src_book=%p dest_book=%p", src_book, dest_book);
+ LEAVE (" src_book=%p dest_book=%p", src_book, dest_book);
}
/* ================================================================ */
-void
+void
gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query)
{
- gnc_commodity_table *src_tbl, *dst_tbl;
- Account *src_root, *dst_root;
- time_t now;
- TransList *trans_list, *tnode;
- LotList *lot_list, *lnode;
- QofInstance *book_inst;
+ gnc_commodity_table *src_tbl, *dst_tbl;
+ Account *src_root, *dst_root;
+ time_t now;
+ TransList *trans_list, *tnode;
+ LotList *lot_list, *lnode;
+ QofInstance *book_inst;
- if (!src_book || !dest_book || !query) return;
- ENTER (" src_book=%p dest_book=%p", src_book, dest_book);
+ if (!src_book || !dest_book || !query) return;
+ ENTER (" src_book=%p dest_book=%p", src_book, dest_book);
- /* First, copy the book's KVP tree */
- /* hack alert -- FIXME -- this should really be a merge, not a
- * clobber copy, but I am too lazy to write a kvp merge routine,
- * and it is not needed for the current usage. */
- kvp_frame_delete (qof_book_get_slots(dest_book));
- book_inst = (QofInstance*)dest_book;
- book_inst->kvp_data = kvp_frame_copy (qof_book_get_slots(src_book));
+ /* First, copy the book's KVP tree */
+ /* hack alert -- FIXME -- this should really be a merge, not a
+ * clobber copy, but I am too lazy to write a kvp merge routine,
+ * and it is not needed for the current usage. */
+ kvp_frame_delete (qof_book_get_slots(dest_book));
+ book_inst = (QofInstance*)dest_book;
+ book_inst->kvp_data = kvp_frame_copy (qof_book_get_slots(src_book));
- /* Next, copy the commodity tables */
- src_tbl = gnc_commodity_table_get_table (src_book);
- dst_tbl = gnc_commodity_table_get_table (dest_book);
- gnc_commodity_table_copy (dst_tbl, src_tbl, dest_book);
+ /* Next, copy the commodity tables */
+ src_tbl = gnc_commodity_table_get_table (src_book);
+ dst_tbl = gnc_commodity_table_get_table (dest_book);
+ gnc_commodity_table_copy (dst_tbl, src_tbl, dest_book);
- /* Next, copy all of the accounts */
- /* hack alert -- FIXME -- this should really be a merge, not a
- * clobber copy, but I am too lazy to write an account-group merge
- * routine, and it is not needed for the current usage. */
- src_root = gnc_book_get_root_account (src_book);
- dst_root = gnc_book_get_root_account (dest_book);
- gnc_account_copy_children (dst_root, src_root);
+ /* Next, copy all of the accounts */
+ /* hack alert -- FIXME -- this should really be a merge, not a
+ * clobber copy, but I am too lazy to write an account-group merge
+ * routine, and it is not needed for the current usage. */
+ src_root = gnc_book_get_root_account (src_book);
+ dst_root = gnc_book_get_root_account (dest_book);
+ gnc_account_copy_children (dst_root, src_root);
- /* Next, run the query */
- xaccAccountBeginEdit (dst_root);
- xaccAccountBeginEdit (src_root);
- qof_query_set_book (query, src_book);
- trans_list = qof_query_run (query);
+ /* Next, run the query */
+ xaccAccountBeginEdit (dst_root);
+ xaccAccountBeginEdit (src_root);
+ qof_query_set_book (query, src_book);
+ trans_list = qof_query_run (query);
- /* Preen: remove open lots/ open trnasactions */
- gnc_account_foreach_descendant(src_root, clear_markers, NULL);
- trans_list = trans_list_preen_open_lots (trans_list);
- lot_list = create_lot_list_from_trans_list (trans_list);
- lot_list = lot_list_preen_open_lots (lot_list);
+ /* Preen: remove open lots/ open trnasactions */
+ gnc_account_foreach_descendant(src_root, clear_markers, NULL);
+ trans_list = trans_list_preen_open_lots (trans_list);
+ lot_list = create_lot_list_from_trans_list (trans_list);
+ lot_list = lot_list_preen_open_lots (lot_list);
- /* Move closed lots over to destination. Do this before moving
- * the txn's, so that the lots don't get trashed. */
- for (lnode = lot_list; lnode; lnode = lnode->next)
- {
- GNCLot *lot = lnode->data;
- gnc_book_insert_lot (dest_book, lot);
- }
+ /* Move closed lots over to destination. Do this before moving
+ * the txn's, so that the lots don't get trashed. */
+ for (lnode = lot_list; lnode; lnode = lnode->next)
+ {
+ GNCLot *lot = lnode->data;
+ gnc_book_insert_lot (dest_book, lot);
+ }
- /* Move the transactions over to the destination book. */
- for (tnode = trans_list; tnode; tnode=tnode->next)
- {
- Transaction *trans = tnode->data;
- gnc_book_insert_trans (dest_book, trans);
- }
+ /* Move the transactions over to the destination book. */
+ for (tnode = trans_list; tnode; tnode = tnode->next)
+ {
+ Transaction *trans = tnode->data;
+ gnc_book_insert_trans (dest_book, trans);
+ }
- xaccAccountCommitEdit (src_root);
- xaccAccountCommitEdit (dst_root);
+ xaccAccountCommitEdit (src_root);
+ xaccAccountCommitEdit (dst_root);
- /* Make note of the sibling books */
- now = time(0);
- gnc_kvp_bag_add (qof_book_get_slots(src_book), "gemini", now,
- "book_guid", qof_book_get_guid(dest_book),
- NULL);
- gnc_kvp_bag_add (qof_book_get_slots(dest_book), "gemini", now,
- "book_guid", qof_book_get_guid(src_book),
- NULL);
- LEAVE (" ");
+ /* Make note of the sibling books */
+ now = time(0);
+ gnc_kvp_bag_add (qof_book_get_slots(src_book), "gemini", now,
+ "book_guid", qof_book_get_guid(dest_book),
+ NULL);
+ gnc_kvp_bag_add (qof_book_get_slots(dest_book), "gemini", now,
+ "book_guid", qof_book_get_guid(src_book),
+ NULL);
+ LEAVE (" ");
}
/* ================================================================ */
@@ -594,291 +595,294 @@
static Account *
find_nearest_equity_acct (Account *acc)
{
- QofBook *book;
- GList *acc_list, *node;
- Account *parent, *root, *candidate;
+ QofBook *book;
+ GList *acc_list, *node;
+ Account *parent, *root, *candidate;
- parent = gnc_account_get_parent (acc);
- g_return_val_if_fail (parent, NULL);
+ parent = gnc_account_get_parent (acc);
+ g_return_val_if_fail (parent, NULL);
- /* See if we can find an equity account that is peered to this
- * account. If not, check succssively higher levels. */
- while (parent != NULL) {
- acc_list = gnc_account_get_children(parent);
- for (node=acc_list; node; node=node->next) {
- candidate = (Account *) node->data;
- if ((ACCT_TYPE_EQUITY == xaccAccountGetType (candidate)) &&
- gnc_commodity_equiv(xaccAccountGetCommodity(acc),
- xaccAccountGetCommodity(candidate))) {
- return candidate;
- }
- }
- g_list_free(acc_list);
- parent = gnc_account_get_parent (parent);
- }
+ /* See if we can find an equity account that is peered to this
+ * account. If not, check succssively higher levels. */
+ while (parent != NULL)
+ {
+ acc_list = gnc_account_get_children(parent);
+ for (node = acc_list; node; node = node->next)
+ {
+ candidate = (Account *) node->data;
+ if ((ACCT_TYPE_EQUITY == xaccAccountGetType (candidate)) &&
+ gnc_commodity_equiv(xaccAccountGetCommodity(acc),
+ xaccAccountGetCommodity(candidate)))
+ {
+ return candidate;
+ }
+ }
+ g_list_free(acc_list);
+ parent = gnc_account_get_parent (parent);
+ }
- /* If we got to here, then we are at the root account, and there is no
- * equity account to be found. So we need to create one. */
+ /* If we got to here, then we are at the root account, and there is no
+ * equity account to be found. So we need to create one. */
- book = gnc_account_get_book(acc);
- root = gnc_book_get_root_account(book);
- candidate = xaccMallocAccount (book);
- xaccAccountBeginEdit (candidate);
- gnc_account_append_child (root, candidate);
- xaccAccountSetType (candidate, ACCT_TYPE_EQUITY);
- xaccAccountSetName (candidate, xaccAccountGetTypeStr(ACCT_TYPE_EQUITY));
- xaccAccountSetCommodity (candidate, xaccAccountGetCommodity(acc));
- xaccAccountCommitEdit (candidate);
-
- return candidate;
+ book = gnc_account_get_book(acc);
+ root = gnc_book_get_root_account(book);
+ candidate = xaccMallocAccount (book);
+ xaccAccountBeginEdit (candidate);
+ gnc_account_append_child (root, candidate);
+ xaccAccountSetType (candidate, ACCT_TYPE_EQUITY);
+ xaccAccountSetName (candidate, xaccAccountGetTypeStr(ACCT_TYPE_EQUITY));
+ xaccAccountSetCommodity (candidate, xaccAccountGetCommodity(acc));
+ xaccAccountCommitEdit (candidate);
+
+ return candidate;
}
/* ================================================================ */
/* Traverse all accounts, get account balances */
static void
-add_closing_balances (Account *parent,
+add_closing_balances (Account *parent,
QofBook *open_book,
QofBook *closed_book,
Account *equity_account,
- Timespec *post_date, Timespec *date_entered,
+ Timespec *post_date, Timespec *date_entered,
const char *desc)
{
- GList *acc_list, *node;
+ GList *acc_list, *node;
- if (!parent) return;
+ if (!parent) return;
- ENTER (" enter=%s post=%s desc=%s", gnc_print_date(*date_entered),
- gnc_print_date (*post_date), desc);
- xaccAccountBeginEdit (equity_account);
+ ENTER (" enter=%s post=%s desc=%s", gnc_print_date(*date_entered),
+ gnc_print_date (*post_date), desc);
+ xaccAccountBeginEdit (equity_account);
- /* Walk accounts in closed book */
- acc_list = gnc_account_get_children(parent);
- for (node=acc_list; node; node=node->next)
- {
- KvpFrame *cwd;
- Account *twin;
- Account * candidate = (Account *) node->data;
- GNCAccountType tip = xaccAccountGetType (candidate);
+ /* Walk accounts in closed book */
+ acc_list = gnc_account_get_children(parent);
+ for (node = acc_list; node; node = node->next)
+ {
+ KvpFrame *cwd;
+ Account *twin;
+ Account * candidate = (Account *) node->data;
+ GNCAccountType tip = xaccAccountGetType (candidate);
- /* Find the peer account of this account in the open book */
- twin = xaccAccountLookupTwin (candidate, open_book);
+ /* Find the peer account of this account in the open book */
+ twin = xaccAccountLookupTwin (candidate, open_book);
- /* -------------------------------- */
- /* Add KVP to open account, indicating the progenitor
- * of this account. */
- xaccAccountBeginEdit (twin);
- cwd = xaccAccountGetSlots (twin);
- kvp_frame_set_guid (cwd, "/book/prev-acct", qof_entity_get_guid (QOF_INSTANCE(candidate)));
- kvp_frame_set_guid (cwd, "/book/prev-book", qof_book_get_guid(closed_book));
+ /* -------------------------------- */
+ /* Add KVP to open account, indicating the progenitor
+ * of this account. */
+ xaccAccountBeginEdit (twin);
+ cwd = xaccAccountGetSlots (twin);
+ kvp_frame_set_guid (cwd, "/book/prev-acct", qof_entity_get_guid (QOF_INSTANCE(candidate)));
+ kvp_frame_set_guid (cwd, "/book/prev-book", qof_book_get_guid(closed_book));
- qof_instance_set_slots(QOF_INSTANCE(twin), twin->inst.kvp_data);
-
- /* -------------------------------- */
- /* Add KVP to closed account, indicating where
- * the next book is. */
- xaccAccountBeginEdit (candidate);
- cwd = xaccAccountGetSlots (candidate);
- kvp_frame_set_guid (cwd, "/book/next-book", qof_book_get_guid(open_book));
- kvp_frame_set_guid (cwd, "/book/next-acct", qof_entity_get_guid (QOF_INSTANCE(twin)));
+ qof_instance_set_slots(QOF_INSTANCE(twin), twin->inst.kvp_data);
- qof_instance_set_slots(QOF_INSTANCE(candidate), candidate->inst.kvp_data);
+ /* -------------------------------- */
+ /* Add KVP to closed account, indicating where
+ * the next book is. */
+ xaccAccountBeginEdit (candidate);
+ cwd = xaccAccountGetSlots (candidate);
+ kvp_frame_set_guid (cwd, "/book/next-book", qof_book_get_guid(open_book));
+ kvp_frame_set_guid (cwd, "/book/next-acct", qof_entity_get_guid (QOF_INSTANCE(twin)));
- /* -------------------------------- */
- /* We need to carry a balance on any account that is not
- * and income or expense or equity account */
- if ((ACCT_TYPE_INCOME != tip) && (ACCT_TYPE_EXPENSE != tip) &&
- (ACCT_TYPE_EQUITY != tip && ACCT_TYPE_TRADING != tip))
- {
- gnc_numeric baln;
- baln = xaccAccountGetBalance (candidate);
+ qof_instance_set_slots(QOF_INSTANCE(candidate), candidate->inst.kvp_data);
- /* Don't bother with creating the equity balance if its zero */
- if (FALSE == gnc_numeric_zero_p(baln))
- {
- Split *se, *st;
- Transaction *trans;
- Account *equity;
-
- /* Find the equity account into which we'll poke the
- * balancing transaction */
- if (NULL == equity_account)
+ /* -------------------------------- */
+ /* We need to carry a balance on any account that is not
+ * and income or expense or equity account */
+ if ((ACCT_TYPE_INCOME != tip) && (ACCT_TYPE_EXPENSE != tip) &&
+ (ACCT_TYPE_EQUITY != tip && ACCT_TYPE_TRADING != tip))
+ {
+ gnc_numeric baln;
+ baln = xaccAccountGetBalance (candidate);
+
+ /* Don't bother with creating the equity balance if its zero */
+ if (FALSE == gnc_numeric_zero_p(baln))
{
- equity = find_nearest_equity_acct (twin);
- xaccAccountBeginEdit (equity);
+ Split *se, *st;
+ Transaction *trans;
+ Account *equity;
+
+ /* Find the equity account into which we'll poke the
+ * balancing transaction */
+ if (NULL == equity_account)
+ {
+ equity = find_nearest_equity_acct (twin);
+ xaccAccountBeginEdit (equity);
+ }
+ else
+ {
+ equity = equity_account;
+ }
+
+ /* -------------------------------- */
+ /* Create the balancing transaction */
+ trans = xaccMallocTransaction (open_book);
+ xaccTransBeginEdit (trans);
+
+ xaccTransSetDatePostedTS (trans, post_date);
+ xaccTransSetDateEnteredTS (trans, date_entered);
+ xaccTransSetDescription (trans, desc);
+ xaccTransSetCurrency (trans, xaccAccountGetCommodity(equity));
+
+ st = xaccMallocSplit(open_book);
+ xaccTransAppendSplit(trans, st);
+ xaccAccountInsertSplit (twin, st);
+
+ se = xaccMallocSplit(open_book);
+ xaccTransAppendSplit(trans, se);
+ xaccAccountInsertSplit (equity, se);
+
+ xaccSplitSetAmount (st, baln);
+ xaccSplitSetValue (st, baln);
+ xaccSplitSetAmount (se, gnc_numeric_neg(baln));
+ xaccSplitSetValue (se, gnc_numeric_neg(baln));
+
+ /* Add KVP data showing where the balancing
+ * transaction came from */
+ cwd = xaccTransGetSlots (trans);
+ kvp_frame_set_guid (cwd, "/book/closed-book", qof_book_get_guid(closed_book));
+ kvp_frame_set_guid (cwd, "/book/closed-acct", qof_entity_get_guid(QOF_INSTANCE(candidate)));
+
+ xaccTransCommitEdit (trans);
+
+ if (NULL == equity_account)
+ {
+ xaccAccountCommitEdit (equity);
+ }
+ /* -------------------------------- */
+ /* Add KVP to closed account, indicating where the
+ * balance was carried forward to. */
+ cwd = xaccAccountGetSlots (candidate);
+ kvp_frame_set_guid (cwd, "/book/balancing-trans", xaccTransGetGUID(trans));
}
- else
- {
- equity = equity_account;
- }
-
- /* -------------------------------- */
- /* Create the balancing transaction */
- trans = xaccMallocTransaction (open_book);
- xaccTransBeginEdit (trans);
-
- xaccTransSetDatePostedTS (trans, post_date);
- xaccTransSetDateEnteredTS (trans, date_entered);
- xaccTransSetDescription (trans, desc);
- xaccTransSetCurrency (trans, xaccAccountGetCommodity(equity));
-
- st = xaccMallocSplit(open_book);
- xaccTransAppendSplit(trans, st);
- xaccAccountInsertSplit (twin, st);
-
- se = xaccMallocSplit(open_book);
- xaccTransAppendSplit(trans, se);
- xaccAccountInsertSplit (equity, se);
-
- xaccSplitSetAmount (st, baln);
- xaccSplitSetValue (st, baln);
- xaccSplitSetAmount (se, gnc_numeric_neg(baln));
- xaccSplitSetValue (se, gnc_numeric_neg(baln));
-
- /* Add KVP data showing where the balancing
- * transaction came from */
- cwd = xaccTransGetSlots (trans);
- kvp_frame_set_guid (cwd, "/book/closed-book", qof_book_get_guid(closed_book));
- kvp_frame_set_guid (cwd, "/book/closed-acct", qof_entity_get_guid(QOF_INSTANCE(candidate)));
-
- xaccTransCommitEdit (trans);
-
- if (NULL == equity_account)
- {
- xaccAccountCommitEdit (equity);
- }
- /* -------------------------------- */
- /* Add KVP to closed account, indicating where the
- * balance was carried forward to. */
- cwd = xaccAccountGetSlots (candidate);
- kvp_frame_set_guid (cwd, "/book/balancing-trans", xaccTransGetGUID(trans));
- }
- }
+ }
- /* We left an open dangling above ... */
- xaccAccountCommitEdit (candidate);
- xaccAccountCommitEdit (twin);
+ /* We left an open dangling above ... */
+ xaccAccountCommitEdit (candidate);
+ xaccAccountCommitEdit (twin);
- /* Recurse down to the children */
- if (gnc_account_n_children(candidate) > 0)
- {
- PINFO ("add closing baln to subaccts of %s",
- xaccAccountGetDescription(candidate));
- add_closing_balances (candidate, open_book, closed_book,
- equity_account,
- post_date, date_entered, desc);
- }
- }
- g_list_free(acc_list);
- xaccAccountCommitEdit (equity_account);
- LEAVE (" ");
+ /* Recurse down to the children */
+ if (gnc_account_n_children(candidate) > 0)
+ {
+ PINFO ("add closing baln to subaccts of %s",
+ xaccAccountGetDescription(candidate));
+ add_closing_balances (candidate, open_book, closed_book,
+ equity_account,
+ post_date, date_entered, desc);
+ }
+ }
+ g_list_free(acc_list);
+ xaccAccountCommitEdit (equity_account);
+ LEAVE (" ");
}
/* ================================================================ */
-static void
+static void
period_begin_edit (QofBook *src_book, QofBook *dest_book)
{
/*
- QofBackend *be;
- be = qof_book_get_backend(src_book);
- if (be && be->begin)
- {
+ QofBackend *be;
+ be = qof_book_get_backend(src_book);
+ if (be && be->begin)
+ {
// (*be->begin)(be, GNC_ID_PERIOD, dest_book);
- }
+ }
*/
}
-
-static void
+
+static void
period_commit_edit (QofBook *src_book, QofBook *dest_book)
{
/*
- QofBackend *be;
- be = qof_book_get_backend(src_book);
- if (be && be->commit)
- {
+ QofBackend *be;
+ be = qof_book_get_backend(src_book);
+ if (be && be->commit)
+ {
// (*be->commit)(be, GNC_ID_PERIOD, dest_book);
- }
+ }
*/
}
/* ================================================================ */
/* Split a book into two by date */
-QofBook *
+QofBook *
gnc_book_close_period (QofBook *existing_book, Timespec calve_date,
Account *equity_account,
const char * memo)
{
- QofQuery *txn_query, *prc_query;
- QofQueryPredData *pred_data;
- GSList *param_list;
- QofBook *closing_book;
- KvpFrame *exist_cwd, *partn_cwd;
- Timespec ts;
+ QofQuery *txn_query, *prc_query;
+ QofQueryPredData *pred_data;
+ GSList *param_list;
+ QofBook *closing_book;
+ KvpFrame *exist_cwd, *partn_cwd;
+ Timespec ts;
- if (!existing_book) return NULL;
- ENTER (" date=%s memo=%s", gnc_print_date(calve_date), memo);
+ if (!existing_book) return NULL;
+ ENTER (" date=%s memo=%s", gnc_print_date(calve_date), memo);
- /* Setup closing book */
- closing_book = qof_book_new();
- qof_book_set_backend (closing_book, qof_book_get_backend(existing_book));
- qof_book_mark_closed(closing_book);
+ /* Setup closing book */
+ closing_book = qof_book_new();
+ qof_book_set_backend (closing_book, qof_book_get_backend(existing_book));
+ qof_book_mark_closed(closing_book);
- period_begin_edit (existing_book, closing_book);
+ period_begin_edit (existing_book, closing_book);
- /* Get all transactions that are *earlier* than the calve date,
- * and put them in the new book. */
- txn_query = qof_query_create_for (GNC_ID_TRANS);
- pred_data = qof_query_date_predicate (QOF_COMPARE_LTE,
- QOF_DATE_MATCH_NORMAL,
- calve_date);
- param_list = qof_query_build_param_list (TRANS_DATE_POSTED, NULL);
- qof_query_add_term (txn_query, param_list, pred_data, QOF_QUERY_FIRST_TERM);
+ /* Get all transactions that are *earlier* than the calve date,
+ * and put them in the new book. */
+ txn_query = qof_query_create_for (GNC_ID_TRANS);
+ pred_data = qof_query_date_predicate (QOF_COMPARE_LTE,
+ QOF_DATE_MATCH_NORMAL,
+ calve_date);
+ param_list = qof_query_build_param_list (TRANS_DATE_POSTED, NULL);
+ qof_query_add_term (txn_query, param_list, pred_data, QOF_QUERY_FIRST_TERM);
- gnc_book_partition_txn (closing_book, existing_book, txn_query);
- qof_query_destroy (txn_query);
+ gnc_book_partition_txn (closing_book, existing_book, txn_query);
+ qof_query_destroy (txn_query);
- /* Move prices over too */
- prc_query = qof_query_create_for (GNC_ID_PRICE);
- pred_data = qof_query_date_predicate (QOF_COMPARE_LTE,
- QOF_DATE_MATCH_NORMAL,
- calve_date);
- param_list = qof_query_build_param_list (PRICE_DATE, NULL);
- qof_query_add_term (prc_query, param_list, pred_data, QOF_QUERY_FIRST_TERM);
+ /* Move prices over too */
+ prc_query = qof_query_create_for (GNC_ID_PRICE);
+ pred_data = qof_query_date_predicate (QOF_COMPARE_LTE,
+ QOF_DATE_MATCH_NORMAL,
+ calve_date);
+ param_list = qof_query_build_param_list (PRICE_DATE, NULL);
+ qof_query_add_term (prc_query, param_list, pred_data, QOF_QUERY_FIRST_TERM);
- gnc_book_partition_pricedb (closing_book, existing_book, prc_query);
- qof_query_destroy (prc_query);
+ gnc_book_partition_pricedb (closing_book, existing_book, prc_query);
+ qof_query_destroy (prc_query);
- /* Now add the various identifying kvp's */
- /* cwd == 'current working directory' */
- exist_cwd = qof_book_get_slots(existing_book);
- partn_cwd = qof_book_get_slots(closing_book);
-
- /* Mark the boundary date between the books */
- kvp_frame_set_timespec (exist_cwd, "/book/open-date", calve_date);
- kvp_frame_set_timespec (partn_cwd, "/book/close-date", calve_date);
+ /* Now add the various identifying kvp's */
+ /* cwd == 'current working directory' */
+ exist_cwd = qof_book_get_slots(existing_book);
+ partn_cwd = qof_book_get_slots(closing_book);
- /* Mark partition as being closed */
- ts.tv_sec = time(0);
- ts.tv_nsec = 0;
- kvp_frame_set_timespec (partn_cwd, "/book/log-date", ts);
+ /* Mark the boundary date between the books */
+ kvp_frame_set_timespec (exist_cwd, "/book/open-date", calve_date);
+ kvp_frame_set_timespec (partn_cwd, "/book/close-date", calve_date);
- /* Set up pointers to each book from the other. */
- kvp_frame_set_guid (partn_cwd, "/book/next-book", qof_book_get_guid(existing_book));
- kvp_frame_set_guid (exist_cwd, "/book/prev-book", qof_book_get_guid(closing_book));
+ /* Mark partition as being closed */
+ ts.tv_sec = time(0);
+ ts.tv_nsec = 0;
+ kvp_frame_set_timespec (partn_cwd, "/book/log-date", ts);
- /* add in transactions to equity accounts that will
- * hold the colsing balances */
- add_closing_balances (gnc_book_get_root_account(closing_book),
- existing_book, closing_book,
- equity_account,
- &calve_date, &ts, memo);
+ /* Set up pointers to each book from the other. */
+ kvp_frame_set_guid (partn_cwd, "/book/next-book", qof_book_get_guid(existing_book));
+ kvp_frame_set_guid (exist_cwd, "/book/prev-book", qof_book_get_guid(closing_book));
- period_commit_edit (existing_book, closing_book);
+ /* add in transactions to equity accounts that will
+ * hold the colsing balances */
+ add_closing_balances (gnc_book_get_root_account(closing_book),
+ existing_book, closing_book,
+ equity_account,
+ &calve_date, &ts, memo);
- LEAVE (" ");
- return closing_book;
+ period_commit_edit (existing_book, closing_book);
+
+ LEAVE (" ");
+ return closing_book;
}
/* ============================= END OF FILE ====================== */
Modified: gnucash/trunk/src/engine/Query.c
===================================================================
--- gnucash/trunk/src/engine/Query.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Query.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -48,520 +48,539 @@
static GSList *
build_param_list_internal (const char *first, va_list rest)
{
- GSList *list = NULL;
- char const *param;
+ GSList *list = NULL;
+ char const *param;
- for (param = first; param; param = va_arg (rest, const char *))
- list = g_slist_prepend (list, (gpointer)param);
+ for (param = first; param; param = va_arg (rest, const char *))
+ list = g_slist_prepend (list, (gpointer)param);
- return (g_slist_reverse (list));
+ return (g_slist_reverse (list));
}
/********************************************************************
- * xaccQueryGetSplitsUniqueTrans
+ * xaccQueryGetSplitsUniqueTrans
* Get splits but no more than one from a given transaction.
********************************************************************/
SplitList *
xaccQueryGetSplitsUniqueTrans(Query *q)
{
- GList * splits = xaccQueryGetSplits(q);
- GList * current;
- GList * result = NULL;
- GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+ GList * splits = xaccQueryGetSplits(q);
+ GList * current;
+ GList * result = NULL;
+ GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
- for (current = splits; current; current = current->next)
- {
- Split *split = current->data;
- Transaction *trans = xaccSplitGetParent (split);
+ for (current = splits; current; current = current->next)
+ {
+ Split *split = current->data;
+ Transaction *trans = xaccSplitGetParent (split);
- if (!g_hash_table_lookup (trans_hash, trans))
- {
- g_hash_table_insert (trans_hash, trans, trans);
- result = g_list_prepend (result, split);
+ if (!g_hash_table_lookup (trans_hash, trans))
+ {
+ g_hash_table_insert (trans_hash, trans, trans);
+ result = g_list_prepend (result, split);
+ }
}
- }
- g_hash_table_destroy (trans_hash);
+ g_hash_table_destroy (trans_hash);
- return g_list_reverse (result);
+ return g_list_reverse (result);
}
/********************************************************************
- * xaccQueryGetTransactions
- * Get transactions matching the query terms, specifying whether
- * we require some or all splits to match
+ * xaccQueryGetTransactions
+ * Get transactions matching the query terms, specifying whether
+ * we require some or all splits to match
********************************************************************/
static void
-query_match_all_filter_func(gpointer key, gpointer value, gpointer user_data)
+query_match_all_filter_func(gpointer key, gpointer value, gpointer user_data)
{
- Transaction * t = key;
- int num_matches = GPOINTER_TO_INT(value);
- GList ** matches = user_data;
+ Transaction * t = key;
+ int num_matches = GPOINTER_TO_INT(value);
+ GList ** matches = user_data;
- if(num_matches == xaccTransCountSplits(t)) {
- *matches = g_list_prepend(*matches, t);
- }
+ if (num_matches == xaccTransCountSplits(t))
+ {
+ *matches = g_list_prepend(*matches, t);
+ }
}
static void
-query_match_any_filter_func(gpointer key, gpointer value, gpointer user_data)
+query_match_any_filter_func(gpointer key, gpointer value, gpointer user_data)
{
- Transaction * t = key;
- GList ** matches = user_data;
- *matches = g_list_prepend(*matches, t);
+ Transaction * t = key;
+ GList ** matches = user_data;
+ *matches = g_list_prepend(*matches, t);
}
-TransList *
-xaccQueryGetTransactions (Query * q, query_txn_match_t runtype)
+TransList *
+xaccQueryGetTransactions (Query * q, query_txn_match_t runtype)
{
- GList * splits = xaccQueryGetSplits(q);
- GList * current = NULL;
- GList * retval = NULL;
- GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
- Transaction * trans = NULL;
- gpointer val = NULL;
- int count = 0;
+ GList * splits = xaccQueryGetSplits(q);
+ GList * current = NULL;
+ GList * retval = NULL;
+ GHashTable * trans_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+ Transaction * trans = NULL;
+ gpointer val = NULL;
+ int count = 0;
- /* iterate over matching splits, incrementing a match-count in
- * the hash table */
- for(current = splits; current; current=current->next) {
- trans = xaccSplitGetParent((Split *)(current->data));
-
- /* don't waste time looking up unless we need the count
- * information */
- if(runtype == QUERY_TXN_MATCH_ALL) {
- val = g_hash_table_lookup(trans_hash, trans);
- count = GPOINTER_TO_INT(val);
+ /* iterate over matching splits, incrementing a match-count in
+ * the hash table */
+ for (current = splits; current; current = current->next)
+ {
+ trans = xaccSplitGetParent((Split *)(current->data));
+
+ /* don't waste time looking up unless we need the count
+ * information */
+ if (runtype == QUERY_TXN_MATCH_ALL)
+ {
+ val = g_hash_table_lookup(trans_hash, trans);
+ count = GPOINTER_TO_INT(val);
+ }
+ g_hash_table_insert(trans_hash, trans, GINT_TO_POINTER(count + 1));
}
- g_hash_table_insert(trans_hash, trans, GINT_TO_POINTER(count + 1));
- }
-
- /* now pick out the transactions that match */
- if(runtype == QUERY_TXN_MATCH_ALL) {
- g_hash_table_foreach(trans_hash, query_match_all_filter_func,
- &retval);
- }
- else {
- g_hash_table_foreach(trans_hash, query_match_any_filter_func,
- &retval);
- }
- g_hash_table_destroy(trans_hash);
+ /* now pick out the transactions that match */
+ if (runtype == QUERY_TXN_MATCH_ALL)
+ {
+ g_hash_table_foreach(trans_hash, query_match_all_filter_func,
+ &retval);
+ }
+ else
+ {
+ g_hash_table_foreach(trans_hash, query_match_any_filter_func,
+ &retval);
+ }
- return retval;
+ g_hash_table_destroy(trans_hash);
+
+ return retval;
}
/********************************************************************
* xaccQueryGetLots
- * Get lots matching the query terms, specifying whether
- * we require some or all splits to match
+ * Get lots matching the query terms, specifying whether
+ * we require some or all splits to match
********************************************************************/
static void
-query_match_all_lot_filter_func(gpointer key, gpointer value, gpointer user_data)
+query_match_all_lot_filter_func(gpointer key, gpointer value, gpointer user_data)
{
- GNCLot * l = key;
- int num_matches = GPOINTER_TO_INT(value);
- GList ** matches = user_data;
+ GNCLot * l = key;
+ int num_matches = GPOINTER_TO_INT(value);
+ GList ** matches = user_data;
- if(num_matches == gnc_lot_count_splits(l)) {
- *matches = g_list_prepend(*matches, l);
- }
+ if (num_matches == gnc_lot_count_splits(l))
+ {
+ *matches = g_list_prepend(*matches, l);
+ }
}
static void
-query_match_any_lot_filter_func(gpointer key, gpointer value, gpointer user_data)
+query_match_any_lot_filter_func(gpointer key, gpointer value, gpointer user_data)
{
- GNCLot * t = key;
- GList ** matches = user_data;
- *matches = g_list_prepend(*matches, t);
+ GNCLot * t = key;
+ GList ** matches = user_data;
+ *matches = g_list_prepend(*matches, t);
}
-LotList *
-xaccQueryGetLots (Query * q, query_txn_match_t runtype)
+LotList *
+xaccQueryGetLots (Query * q, query_txn_match_t runtype)
{
- GList * splits = xaccQueryGetSplits(q);
- GList * current = NULL;
- GList * retval = NULL;
- GHashTable * lot_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
- GNCLot * lot = NULL;
- gpointer val = NULL;
- int count = 0;
+ GList * splits = xaccQueryGetSplits(q);
+ GList * current = NULL;
+ GList * retval = NULL;
+ GHashTable * lot_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+ GNCLot * lot = NULL;
+ gpointer val = NULL;
+ int count = 0;
- /* iterate over matching splits, incrementing a match-count in
- * the hash table */
- for(current = splits; current; current=current->next) {
- lot = xaccSplitGetLot((Split *)(current->data));
-
- /* don't waste time looking up unless we need the count
- * information */
- if(runtype == QUERY_TXN_MATCH_ALL) {
- val = g_hash_table_lookup(lot_hash, lot);
- count = GPOINTER_TO_INT(val);
+ /* iterate over matching splits, incrementing a match-count in
+ * the hash table */
+ for (current = splits; current; current = current->next)
+ {
+ lot = xaccSplitGetLot((Split *)(current->data));
+
+ /* don't waste time looking up unless we need the count
+ * information */
+ if (runtype == QUERY_TXN_MATCH_ALL)
+ {
+ val = g_hash_table_lookup(lot_hash, lot);
+ count = GPOINTER_TO_INT(val);
+ }
+ g_hash_table_insert(lot_hash, lot, GINT_TO_POINTER(count + 1));
}
- g_hash_table_insert(lot_hash, lot, GINT_TO_POINTER(count + 1));
- }
-
- /* now pick out the transactions that match */
- if(runtype == QUERY_TXN_MATCH_ALL) {
- g_hash_table_foreach(lot_hash, query_match_all_lot_filter_func,
- &retval);
- }
- else {
- g_hash_table_foreach(lot_hash, query_match_any_lot_filter_func,
- &retval);
- }
- g_hash_table_destroy(lot_hash);
+ /* now pick out the transactions that match */
+ if (runtype == QUERY_TXN_MATCH_ALL)
+ {
+ g_hash_table_foreach(lot_hash, query_match_all_lot_filter_func,
+ &retval);
+ }
+ else
+ {
+ g_hash_table_foreach(lot_hash, query_match_any_lot_filter_func,
+ &retval);
+ }
- return retval;
+ g_hash_table_destroy(lot_hash);
+
+ return retval;
}
/*******************************************************************
- * match-adding API
+ * match-adding API
*******************************************************************/
void
xaccQueryAddAccountMatch(Query *q, AccountList *acct_list,
- QofGuidMatch how, QofQueryOp op)
+ QofGuidMatch how, QofQueryOp op)
{
- GList *list = NULL;
+ GList *list = NULL;
- if (!q) return;
- for (; acct_list; acct_list = acct_list->next) {
- Account *acc = acct_list->data;
- const GUID *guid;
+ if (!q) return;
+ for (; acct_list; acct_list = acct_list->next)
+ {
+ Account *acc = acct_list->data;
+ const GUID *guid;
- if (!acc) {
- PWARN ("acct_list has NULL account");
- continue;
- }
+ if (!acc)
+ {
+ PWARN ("acct_list has NULL account");
+ continue;
+ }
- guid = qof_entity_get_guid (QOF_INSTANCE(acc));
- if (!guid) {
- PWARN ("acct returns NULL GUID");
- continue;
+ guid = qof_entity_get_guid (QOF_INSTANCE(acc));
+ if (!guid)
+ {
+ PWARN ("acct returns NULL GUID");
+ continue;
+ }
+
+ list = g_list_prepend (list, (gpointer)guid);
}
-
- list = g_list_prepend (list, (gpointer)guid);
- }
- xaccQueryAddAccountGUIDMatch (q, list, how, op);
- g_list_free (list);
+ xaccQueryAddAccountGUIDMatch (q, list, how, op);
+ g_list_free (list);
}
void
xaccQueryAddAccountGUIDMatch(Query *q, AccountGUIDList *guid_list,
- QofGuidMatch how, QofQueryOp op)
+ QofGuidMatch how, QofQueryOp op)
{
- QofQueryPredData *pred_data;
- GSList *param_list = NULL;
+ QofQueryPredData *pred_data;
+ GSList *param_list = NULL;
- if (!q) return;
+ if (!q) return;
- pred_data = qof_query_guid_predicate (how, guid_list);
- if (!pred_data)
- return;
+ pred_data = qof_query_guid_predicate (how, guid_list);
+ if (!pred_data)
+ return;
- switch (how) {
- case QOF_GUID_MATCH_ANY:
- case QOF_GUID_MATCH_NONE:
- param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL);
- break;
- case QOF_GUID_MATCH_ALL:
- param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_SPLITLIST,
- SPLIT_ACCOUNT_GUID, NULL);
- break;
- default:
- PERR ("Invalid match type: %d", how);
- }
+ switch (how)
+ {
+ case QOF_GUID_MATCH_ANY:
+ case QOF_GUID_MATCH_NONE:
+ param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL);
+ break;
+ case QOF_GUID_MATCH_ALL:
+ param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_SPLITLIST,
+ SPLIT_ACCOUNT_GUID, NULL);
+ break;
+ default:
+ PERR ("Invalid match type: %d", how);
+ }
- qof_query_add_term (q, param_list, pred_data, op);
+ qof_query_add_term (q, param_list, pred_data, op);
}
void
xaccQueryAddSingleAccountMatch(Query *q, Account *acc, QofQueryOp op)
{
- GList *list;
- const GUID *guid;
+ GList *list;
+ const GUID *guid;
- if (!q || !acc)
- return;
+ if (!q || !acc)
+ return;
- guid = qof_entity_get_guid (QOF_INSTANCE(acc));
- g_return_if_fail (guid);
+ guid = qof_entity_get_guid (QOF_INSTANCE(acc));
+ g_return_if_fail (guid);
- list = g_list_prepend (NULL, (gpointer)guid);
- xaccQueryAddAccountGUIDMatch (q, list, QOF_GUID_MATCH_ANY, op);
- g_list_free (list);
+ list = g_list_prepend (NULL, (gpointer)guid);
+ xaccQueryAddAccountGUIDMatch (q, list, QOF_GUID_MATCH_ANY, op);
+ g_list_free (list);
}
void
xaccQueryAddStringMatch (Query* q, const char *matchstring,
- gboolean case_sens, gboolean use_regexp,
+ gboolean case_sens, gboolean use_regexp,
QofQueryOp op,
- const char * path, ...)
+ const char * path, ...)
{
- QofQueryPredData *pred_data;
- GSList *param_list;
- va_list ap;
+ QofQueryPredData *pred_data;
+ GSList *param_list;
+ va_list ap;
- if (!path || !q)
- return;
+ if (!path || !q)
+ return;
- pred_data = qof_query_string_predicate (QOF_COMPARE_EQUAL, (char *)matchstring,
- (case_sens ? QOF_STRING_MATCH_NORMAL :
- QOF_STRING_MATCH_CASEINSENSITIVE),
- use_regexp);
- if (!pred_data)
- return;
+ pred_data = qof_query_string_predicate (QOF_COMPARE_EQUAL, (char *)matchstring,
+ (case_sens ? QOF_STRING_MATCH_NORMAL :
+ QOF_STRING_MATCH_CASEINSENSITIVE),
+ use_regexp);
+ if (!pred_data)
+ return;
- va_start (ap, path);
- param_list = build_param_list_internal (path, ap);
- va_end (ap);
+ va_start (ap, path);
+ param_list = build_param_list_internal (path, ap);
+ va_end (ap);
- qof_query_add_term (q, param_list, pred_data, op);
+ qof_query_add_term (q, param_list, pred_data, op);
}
void
xaccQueryAddNumericMatch (Query *q, gnc_numeric amount, QofNumericMatch sign,
- QofQueryCompare how, QofQueryOp op,
- const char * path, ...)
+ QofQueryCompare how, QofQueryOp op,
+ const char * path, ...)
{
- QofQueryPredData *pred_data;
- GSList *param_list;
- va_list ap;
+ QofQueryPredData *pred_data;
+ GSList *param_list;
+ va_list ap;
- if (!q || !path)
- return;
+ if (!q || !path)
+ return;
- pred_data = qof_query_numeric_predicate (how, sign, amount);
- if (!pred_data)
- return;
+ pred_data = qof_query_numeric_predicate (how, sign, amount);
+ if (!pred_data)
+ return;
- va_start (ap, path);
- param_list = build_param_list_internal (path, ap);
- va_end (ap);
+ va_start (ap, path);
+ param_list = build_param_list_internal (path, ap);
+ va_end (ap);
- qof_query_add_term (q, param_list, pred_data, op);
+ qof_query_add_term (q, param_list, pred_data, op);
}
/* The DateMatch queries match transactions whose posted date
* is in a date range. If use_start is TRUE, then a matching
- * posted date will be greater than the start date. If
- * use_end is TRUE, then a match occurs for posted dates earlier
- * than the end date. If both flags are set, then *both*
- * conditions must hold ('and'). If neither flag is set, then
+ * posted date will be greater than the start date. If
+ * use_end is TRUE, then a match occurs for posted dates earlier
+ * than the end date. If both flags are set, then *both*
+ * conditions must hold ('and'). If neither flag is set, then
* all transactions are matched.
*/
void
-xaccQueryAddDateMatchTS (Query * q,
- gboolean use_start, Timespec sts,
- gboolean use_end, Timespec ets,
- QofQueryOp op)
+xaccQueryAddDateMatchTS (Query * q,
+ gboolean use_start, Timespec sts,
+ gboolean use_end, Timespec ets,
+ QofQueryOp op)
{
- Query *tmp_q = NULL;
- QofQueryPredData *pred_data;
- GSList *param_list;
+ Query *tmp_q = NULL;
+ QofQueryPredData *pred_data;
+ GSList *param_list;
- if (!q || (!use_start && !use_end))
- return;
+ if (!q || (!use_start && !use_end))
+ return;
- tmp_q = qof_query_create ();
+ tmp_q = qof_query_create ();
- if (use_start) {
- pred_data = qof_query_date_predicate (QOF_COMPARE_GTE, QOF_DATE_MATCH_NORMAL, sts);
- if (!pred_data) {
- qof_query_destroy (tmp_q);
- return;
+ if (use_start)
+ {
+ pred_data = qof_query_date_predicate (QOF_COMPARE_GTE, QOF_DATE_MATCH_NORMAL, sts);
+ if (!pred_data)
+ {
+ qof_query_destroy (tmp_q);
+ return;
+ }
+
+ param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
+ qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND);
}
- param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
- qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND);
- }
+ if (use_end)
+ {
+ pred_data = qof_query_date_predicate (QOF_COMPARE_LTE, QOF_DATE_MATCH_NORMAL, ets);
+ if (!pred_data)
+ {
+ qof_query_destroy (tmp_q);
+ return;
+ }
- if (use_end) {
- pred_data = qof_query_date_predicate (QOF_COMPARE_LTE, QOF_DATE_MATCH_NORMAL, ets);
- if (!pred_data) {
- qof_query_destroy (tmp_q);
- return;
+ param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
+ qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND);
}
- param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
- qof_query_add_term (tmp_q, param_list, pred_data, QOF_QUERY_AND);
- }
-
- qof_query_merge_in_place (q, tmp_q, op);
- qof_query_destroy (tmp_q);
+ qof_query_merge_in_place (q, tmp_q, op);
+ qof_query_destroy (tmp_q);
}
void
-xaccQueryGetDateMatchTS (Query * q,
- Timespec * sts,
- Timespec * ets)
+xaccQueryGetDateMatchTS (Query * q,
+ Timespec * sts,
+ Timespec * ets)
{
- QofQueryPredData *term_data;
- GSList *param_list;
- GSList *terms, *tmp;
+ QofQueryPredData *term_data;
+ GSList *param_list;
+ GSList *terms, *tmp;
- sts->tv_sec = sts->tv_nsec = 0;
- ets->tv_sec = ets->tv_nsec = 0;
+ sts->tv_sec = sts->tv_nsec = 0;
+ ets->tv_sec = ets->tv_nsec = 0;
- param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
- terms = qof_query_get_term_type (q, param_list);
- g_slist_free(param_list);
+ param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
+ terms = qof_query_get_term_type (q, param_list);
+ g_slist_free(param_list);
- for (tmp = terms; tmp; tmp = g_slist_next(tmp)) {
- term_data = tmp->data;
- if (term_data->how == QOF_COMPARE_GTE)
- qof_query_date_predicate_get_date(term_data, sts);
- if (term_data->how == QOF_COMPARE_LTE)
- qof_query_date_predicate_get_date(term_data, ets);
- }
- g_slist_free(terms);
+ for (tmp = terms; tmp; tmp = g_slist_next(tmp))
+ {
+ term_data = tmp->data;
+ if (term_data->how == QOF_COMPARE_GTE)
+ qof_query_date_predicate_get_date(term_data, sts);
+ if (term_data->how == QOF_COMPARE_LTE)
+ qof_query_date_predicate_get_date(term_data, ets);
+ }
+ g_slist_free(terms);
}
/********************************************************************
* xaccQueryAddDateMatch
- * Add a date filter to an existing query.
+ * Add a date filter to an existing query.
********************************************************************/
void
-xaccQueryAddDateMatch(Query * q,
+xaccQueryAddDateMatch(Query * q,
gboolean use_start, int sday, int smonth, int syear,
gboolean use_end, int eday, int emonth, int eyear,
- QofQueryOp op)
+ QofQueryOp op)
{
- /* gcc -O3 will auto-inline this function, avoiding a call overhead */
- xaccQueryAddDateMatchTS (q, use_start,
- gnc_dmy2timespec(sday, smonth, syear),
- use_end,
- gnc_dmy2timespec_end(eday, emonth, eyear),
- op);
+ /* gcc -O3 will auto-inline this function, avoiding a call overhead */
+ xaccQueryAddDateMatchTS (q, use_start,
+ gnc_dmy2timespec(sday, smonth, syear),
+ use_end,
+ gnc_dmy2timespec_end(eday, emonth, eyear),
+ op);
}
/********************************************************************
* xaccQueryAddDateMatchTT
- * Add a date filter to an existing query.
+ * Add a date filter to an existing query.
********************************************************************/
void
-xaccQueryAddDateMatchTT(Query * q,
+xaccQueryAddDateMatchTT(Query * q,
gboolean use_start,
time_t stt,
gboolean use_end,
time_t ett,
- QofQueryOp op)
+ QofQueryOp op)
{
- Timespec sts;
- Timespec ets;
-
- sts.tv_sec = (long long)stt;
- sts.tv_nsec = 0;
+ Timespec sts;
+ Timespec ets;
- ets.tv_sec = (long long)ett;
- ets.tv_nsec = 0;
+ sts.tv_sec = (long long)stt;
+ sts.tv_nsec = 0;
- /* gcc -O3 will auto-inline this function, avoiding a call overhead */
- xaccQueryAddDateMatchTS (q, use_start, sts,
- use_end, ets, op);
-
+ ets.tv_sec = (long long)ett;
+ ets.tv_nsec = 0;
+
+ /* gcc -O3 will auto-inline this function, avoiding a call overhead */
+ xaccQueryAddDateMatchTS (q, use_start, sts,
+ use_end, ets, op);
+
}
void
-xaccQueryGetDateMatchTT (Query * q,
- time_t * stt,
- time_t * ett)
+xaccQueryGetDateMatchTT (Query * q,
+ time_t * stt,
+ time_t * ett)
{
- Timespec sts;
- Timespec ets;
+ Timespec sts;
+ Timespec ets;
- xaccQueryGetDateMatchTS (q, &sts, &ets);
+ xaccQueryGetDateMatchTS (q, &sts, &ets);
- *stt = sts.tv_sec;
- *ett = ets.tv_sec;
+ *stt = sts.tv_sec;
+ *ett = ets.tv_sec;
}
void
xaccQueryAddClearedMatch(Query * q, cleared_match_t how, QofQueryOp op)
{
- QofQueryPredData *pred_data;
- GSList *param_list;
- char chars[6];
- int i = 0;
+ QofQueryPredData *pred_data;
+ GSList *param_list;
+ char chars[6];
+ int i = 0;
- if (!q)
- return;
+ if (!q)
+ return;
- if (how & CLEARED_CLEARED)
- chars[i++] = CREC;
- if (how & CLEARED_RECONCILED)
- chars[i++] = YREC;
- if (how & CLEARED_FROZEN)
- chars[i++] = FREC;
- if (how & CLEARED_NO)
- chars[i++] = NREC;
- if (how & CLEARED_VOIDED)
- chars[i++] = VREC;
- chars[i] = '\0';
+ if (how & CLEARED_CLEARED)
+ chars[i++] = CREC;
+ if (how & CLEARED_RECONCILED)
+ chars[i++] = YREC;
+ if (how & CLEARED_FROZEN)
+ chars[i++] = FREC;
+ if (how & CLEARED_NO)
+ chars[i++] = NREC;
+ if (how & CLEARED_VOIDED)
+ chars[i++] = VREC;
+ chars[i] = '\0';
- pred_data = qof_query_char_predicate (QOF_CHAR_MATCH_ANY, chars);
- if (!pred_data)
- return;
+ pred_data = qof_query_char_predicate (QOF_CHAR_MATCH_ANY, chars);
+ if (!pred_data)
+ return;
- param_list = qof_query_build_param_list (SPLIT_RECONCILE, NULL);
+ param_list = qof_query_build_param_list (SPLIT_RECONCILE, NULL);
- qof_query_add_term (q, param_list, pred_data, op);
+ qof_query_add_term (q, param_list, pred_data, op);
}
void
xaccQueryAddGUIDMatch(Query * q, const GUID *guid,
- QofIdType id_type, QofQueryOp op)
+ QofIdType id_type, QofQueryOp op)
{
- GSList *param_list = NULL;
+ GSList *param_list = NULL;
- if (!q || !guid || !id_type)
- return;
+ if (!q || !guid || !id_type)
+ return;
- if (!safe_strcmp (id_type, GNC_ID_SPLIT))
- param_list = qof_query_build_param_list (QOF_PARAM_GUID, NULL);
- else if (!safe_strcmp (id_type, GNC_ID_TRANS))
- param_list = qof_query_build_param_list (SPLIT_TRANS, QOF_PARAM_GUID, NULL);
- else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT))
- param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL);
- else
- PERR ("Invalid match type: %s", id_type);
+ if (!safe_strcmp (id_type, GNC_ID_SPLIT))
+ param_list = qof_query_build_param_list (QOF_PARAM_GUID, NULL);
+ else if (!safe_strcmp (id_type, GNC_ID_TRANS))
+ param_list = qof_query_build_param_list (SPLIT_TRANS, QOF_PARAM_GUID, NULL);
+ else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT))
+ param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL);
+ else
+ PERR ("Invalid match type: %s", id_type);
- qof_query_add_guid_match (q, param_list, guid, op);
+ qof_query_add_guid_match (q, param_list, guid, op);
}
void
xaccQueryAddKVPMatch(QofQuery *q, GSList *path, const KvpValue *value,
- QofQueryCompare how, QofIdType id_type,
- QofQueryOp op)
+ QofQueryCompare how, QofIdType id_type,
+ QofQueryOp op)
{
- GSList *param_list = NULL;
- QofQueryPredData *pred_data;
+ GSList *param_list = NULL;
+ QofQueryPredData *pred_data;
- if (!q || !path || !value || !id_type)
- return;
+ if (!q || !path || !value || !id_type)
+ return;
- pred_data = qof_query_kvp_predicate (how, path, value);
- if (!pred_data)
- return;
+ pred_data = qof_query_kvp_predicate (how, path, value);
+ if (!pred_data)
+ return;
- if (!safe_strcmp (id_type, GNC_ID_SPLIT))
- param_list = qof_query_build_param_list (SPLIT_KVP, NULL);
- else if (!safe_strcmp (id_type, GNC_ID_TRANS))
- param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_KVP, NULL);
- else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT))
- param_list = qof_query_build_param_list (SPLIT_ACCOUNT, ACCOUNT_KVP, NULL);
- else
- PERR ("Invalid match type: %s", id_type);
+ if (!safe_strcmp (id_type, GNC_ID_SPLIT))
+ param_list = qof_query_build_param_list (SPLIT_KVP, NULL);
+ else if (!safe_strcmp (id_type, GNC_ID_TRANS))
+ param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_KVP, NULL);
+ else if (!safe_strcmp (id_type, GNC_ID_ACCOUNT))
+ param_list = qof_query_build_param_list (SPLIT_ACCOUNT, ACCOUNT_KVP, NULL);
+ else
+ PERR ("Invalid match type: %s", id_type);
- qof_query_add_term (q, param_list, pred_data, op);
+ qof_query_add_term (q, param_list, pred_data, op);
}
/*******************************************************************
@@ -569,26 +588,28 @@
*******************************************************************/
time_t
-xaccQueryGetEarliestDateFound(Query * q)
+xaccQueryGetEarliestDateFound(Query * q)
{
- GList * spl;
- Split * sp;
- time_t earliest;
+ GList * spl;
+ Split * sp;
+ time_t earliest;
- if (!q) return 0;
- spl = qof_query_last_run (q);
- if (!spl) return 0;
+ if (!q) return 0;
+ spl = qof_query_last_run (q);
+ if (!spl) return 0;
- /* Safe until 2038 on archs where time_t is 32bit */
- sp = spl->data;
- earliest = (time_t) sp->parent->date_posted.tv_sec;
- for(; spl; spl=spl->next) {
+ /* Safe until 2038 on archs where time_t is 32bit */
sp = spl->data;
- if(sp->parent->date_posted.tv_sec < earliest) {
- earliest = (time_t) sp->parent->date_posted.tv_sec;
+ earliest = (time_t) sp->parent->date_posted.tv_sec;
+ for (; spl; spl = spl->next)
+ {
+ sp = spl->data;
+ if (sp->parent->date_posted.tv_sec < earliest)
+ {
+ earliest = (time_t) sp->parent->date_posted.tv_sec;
+ }
}
- }
- return earliest;
+ return earliest;
}
/*******************************************************************
@@ -596,23 +617,25 @@
*******************************************************************/
time_t
-xaccQueryGetLatestDateFound(Query * q)
+xaccQueryGetLatestDateFound(Query * q)
{
- Split * sp;
- GList * spl;
- time_t latest = 0;
+ Split * sp;
+ GList * spl;
+ time_t latest = 0;
- if(!q) return 0;
- spl = qof_query_last_run (q);
- if(!spl) return 0;
+ if (!q) return 0;
+ spl = qof_query_last_run (q);
+ if (!spl) return 0;
- for(; spl; spl=spl->next) {
- sp = spl->data;
- if(sp->parent->date_posted.tv_sec > latest) {
- latest = (time_t) sp->parent->date_posted.tv_sec;
+ for (; spl; spl = spl->next)
+ {
+ sp = spl->data;
+ if (sp->parent->date_posted.tv_sec > latest)
+ {
+ latest = (time_t) sp->parent->date_posted.tv_sec;
+ }
}
- }
- return latest;
+ return latest;
}
void
Modified: gnucash/trunk/src/engine/Recurrence.c
===================================================================
--- gnucash/trunk/src/engine/Recurrence.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Recurrence.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -38,11 +38,13 @@
static GDate invalid_gdate;
/* Do not intl. These are used for xml storage. */
-static gchar *period_type_strings[NUM_PERIOD_TYPES] = {
+static gchar *period_type_strings[NUM_PERIOD_TYPES] =
+{
"once", "day", "week", "month", "end of month",
"nth weekday", "last weekday", "year",
};
-static gchar *weekend_adj_strings[NUM_WEEKEND_ADJS] = {
+static gchar *weekend_adj_strings[NUM_WEEKEND_ADJS] =
+{
"none", "back", "forward",
};
@@ -79,35 +81,43 @@
r->ptype = VALID_PERIOD_TYPE(pt) ? pt : PERIOD_MONTH;
r->mult = (pt == PERIOD_ONCE) ? 0 : (mult > 0 ? mult : 1);
- if (_start && g_date_valid(_start)) {
+ if (_start && g_date_valid(_start))
+ {
r->start = *_start;
- } else {
+ }
+ else
+ {
g_date_set_time_t(&r->start, time(NULL));
}
/* Some of the unusual period types also specify phase. For those
types, we ensure that the start date agrees with that phase. */
- switch (r->ptype) {
+ switch (r->ptype)
+ {
case PERIOD_END_OF_MONTH:
g_date_set_day(&r->start, g_date_get_days_in_month
(g_date_get_month(&r->start),
g_date_get_year(&r->start)));
break;
- case PERIOD_LAST_WEEKDAY: {
+ case PERIOD_LAST_WEEKDAY:
+ {
GDateDay dim;
dim = g_date_get_days_in_month(g_date_get_month(&r->start),
g_date_get_year(&r->start));
- while (dim - g_date_get_day(&r->start) >=7)
+ while (dim - g_date_get_day(&r->start) >= 7)
g_date_add_days(&r->start, 7);
- } break;
+ }
+ break;
case PERIOD_NTH_WEEKDAY:
- if ((g_date_get_day(&r->start)-1) / 7 == 4) /* Fifth week */
+ if ((g_date_get_day(&r->start) - 1) / 7 == 4) /* Fifth week */
r->ptype = PERIOD_LAST_WEEKDAY;
break;
- default: break;
+ default:
+ break;
}
- switch (r->ptype) {
+ switch (r->ptype)
+ {
case PERIOD_MONTH:
case PERIOD_END_OF_MONTH:
case PERIOD_YEAR:
@@ -137,12 +147,12 @@
/* matchday has a week part, capped at 3 weeks, and a day part,
capped at 7 days, so max(matchday) == 3*7 + 7 == 28. */
- matchday = 7 * ((sd-1)/7 == 4 ? 3 : (sd-1)/7) +
- (nd - g_date_get_weekday(next) + g_date_get_weekday(start) + 7) % 7;
+ matchday = 7 * ((sd - 1) / 7 == 4 ? 3 : (sd - 1) / 7) +
+ (nd - g_date_get_weekday(next) + g_date_get_weekday(start) + 7) % 7;
/* That " + 7" is to avoid negative modulo in case nd < 6. */
dim = g_date_get_days_in_month(
- g_date_get_month(next), g_date_get_year(next));
+ g_date_get_month(next), g_date_get_year(next));
if ((dim - matchday) >= 7 && pt == PERIOD_LAST_WEEKDAY)
matchday += 7; /* Go to the fifth week, if needed */
@@ -170,7 +180,8 @@
/* If the ref date comes before the start date then the next
occurrence is always the start date, and we're done. */
start = &r->start;
- if (g_date_compare(ref, start) < 0) {
+ if (g_date_compare(ref, start) < 0)
+ {
g_date_set_julian(next, g_date_get_julian(start));
return;
}
@@ -180,7 +191,8 @@
mult = r->mult;
pt = r->ptype;
wadj = r->wadj;
- switch (pt) {
+ switch (pt)
+ {
case PERIOD_YEAR:
mult *= 12; /* fall-through */
case PERIOD_MONTH:
@@ -189,15 +201,17 @@
case PERIOD_END_OF_MONTH:
/* Takes care of short months. */
if (r->wadj == WEEKEND_ADJ_BACK &&
- (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) &&
- (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY)) {
+ (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) &&
+ (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY))
+ {
/* Allows the following Friday-based calculations to proceed if 'next'
is between Friday and the target day. */
g_date_subtract_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 1 : 2);
}
if (r->wadj == WEEKEND_ADJ_BACK &&
- (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) &&
- g_date_get_weekday(next) == G_DATE_FRIDAY) {
+ (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) &&
+ g_date_get_weekday(next) == G_DATE_FRIDAY)
+ {
GDate tmp_sat;
GDate tmp_sun;
g_date_set_julian(&tmp_sat, g_date_get_julian(next));
@@ -205,41 +219,58 @@
g_date_add_days(&tmp_sat, 1);
g_date_add_days(&tmp_sun, 2);
- if (pt == PERIOD_END_OF_MONTH) {
- if (g_date_is_last_of_month(next) ||
- g_date_is_last_of_month(&tmp_sat) ||
- g_date_is_last_of_month(&tmp_sun))
- g_date_add_months(next, mult);
- else
- /* one fewer month fwd because of the occurrence in this month */
- g_date_add_months(next, mult - 1);
- } else {
- if (g_date_get_day(&tmp_sat) == g_date_get_day(start)) {
+ if (pt == PERIOD_END_OF_MONTH)
+ {
+ if (g_date_is_last_of_month(next) ||
+ g_date_is_last_of_month(&tmp_sat) ||
+ g_date_is_last_of_month(&tmp_sun))
+ g_date_add_months(next, mult);
+ else
+ /* one fewer month fwd because of the occurrence in this month */
+ g_date_add_months(next, mult - 1);
+ }
+ else
+ {
+ if (g_date_get_day(&tmp_sat) == g_date_get_day(start))
+ {
g_date_add_days(next, 1);
g_date_add_months(next, mult);
- } else if (g_date_get_day(&tmp_sun) == g_date_get_day(start)) {
+ }
+ else if (g_date_get_day(&tmp_sun) == g_date_get_day(start))
+ {
g_date_add_days(next, 2);
g_date_add_months(next, mult);
- } else if (g_date_get_day(next) >= g_date_get_day(start)) {
+ }
+ else if (g_date_get_day(next) >= g_date_get_day(start))
+ {
g_date_add_months(next, mult);
- } else if (g_date_is_last_of_month(next)) {
- g_date_add_months(next, mult);
- } else if (g_date_is_last_of_month(&tmp_sat)) {
+ }
+ else if (g_date_is_last_of_month(next))
+ {
+ g_date_add_months(next, mult);
+ }
+ else if (g_date_is_last_of_month(&tmp_sat))
+ {
g_date_add_days(next, 1);
- g_date_add_months(next, mult);
- } else if (g_date_is_last_of_month(&tmp_sun)) {
+ g_date_add_months(next, mult);
+ }
+ else if (g_date_is_last_of_month(&tmp_sun))
+ {
g_date_add_days(next, 2);
- g_date_add_months(next, mult);
- } else {
+ g_date_add_months(next, mult);
+ }
+ else
+ {
/* one fewer month fwd because of the occurrence in this month */
g_date_add_months(next, mult - 1);
}
}
- } else if ( g_date_is_last_of_month(next) ||
- ((pt == PERIOD_MONTH || pt == PERIOD_YEAR) &&
- g_date_get_day(next) >= g_date_get_day(start)) ||
- ((pt == PERIOD_NTH_WEEKDAY || pt == PERIOD_LAST_WEEKDAY) &&
- nth_weekday_compare(start, next, pt) <= 0) )
+ }
+ else if ( g_date_is_last_of_month(next) ||
+ ((pt == PERIOD_MONTH || pt == PERIOD_YEAR) &&
+ g_date_get_day(next) >= g_date_get_day(start)) ||
+ ((pt == PERIOD_NTH_WEEKDAY || pt == PERIOD_LAST_WEEKDAY) &&
+ nth_weekday_compare(start, next, pt) <= 0) )
g_date_add_months(next, mult);
else
/* one fewer month fwd because of the occurrence in this month */
@@ -259,16 +290,18 @@
/* Step 2: Back up to align to the base phase. To ensure forward
progress, we never subtract as much as we added (x % mult < mult). */
- switch (pt) {
+ switch (pt)
+ {
case PERIOD_YEAR:
case PERIOD_MONTH:
case PERIOD_NTH_WEEKDAY:
case PERIOD_LAST_WEEKDAY:
- case PERIOD_END_OF_MONTH: {
+ case PERIOD_END_OF_MONTH:
+ {
guint dim, n_months;
n_months = 12 * (g_date_get_year(next) - g_date_get_year(start)) +
- (g_date_get_month(next) - g_date_get_month(start));
+ (g_date_get_month(next) - g_date_get_month(start));
g_date_subtract_months(next, n_months % mult);
/* Ok, now we're in the right month, so we just have to align
@@ -283,9 +316,12 @@
g_date_set_day(next, g_date_get_day(start)); /*same day as start*/
/* Adjust for dates on the weekend. */
- if (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH) {
- if (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY) {
- switch (wadj) {
+ if (pt == PERIOD_YEAR || pt == PERIOD_MONTH || pt == PERIOD_END_OF_MONTH)
+ {
+ if (g_date_get_weekday(next) == G_DATE_SATURDAY || g_date_get_weekday(next) == G_DATE_SUNDAY)
+ {
+ switch (wadj)
+ {
case WEEKEND_ADJ_BACK:
g_date_subtract_days(next, g_date_get_weekday(next) == G_DATE_SATURDAY ? 1 : 2);
break;
@@ -299,7 +335,8 @@
}
}
- } break;
+ }
+ break;
case PERIOD_WEEK:
case PERIOD_DAY:
g_date_subtract_days(next, g_date_days_between(start, next) % mult);
@@ -316,7 +353,8 @@
GDate ref;
guint i;
- for (*date = ref = r->start, i = 0; i < n; i++) {
+ for (*date = ref = r->start, i = 0; i < n; i++)
+ {
recurrenceNextInstance(r, &ref, date);
ref = *date;
}
@@ -327,10 +365,13 @@
{
GDate date;
recurrenceNthInstance(r, period_num + (end ? 1 : 0), &date);
- if (end) {
+ if (end)
+ {
g_date_subtract_days(&date, 1);
return gnc_timet_get_day_end_gdate(&date);
- } else {
+ }
+ else
+ {
return gnc_timet_get_day_start_gdate(&date);
}
}
@@ -356,13 +397,15 @@
g_date_clear(next, 1);
// empty rlist = no recurrence
- if (rlist == NULL) {
+ if (rlist == NULL)
+ {
return;
}
g_return_if_fail(ref && next && g_date_valid(ref));
- for (iter = rlist; iter; iter = iter->next) {
+ for (iter = rlist; iter; iter = iter->next)
+ {
const Recurrence *r = iter->data;
recurrenceNextInstance(r, ref, &nextSingle);
@@ -383,10 +426,11 @@
gchar *tmpPeriod, *ret;
g_return_val_if_fail(g_date_valid(&r->start), NULL);
- tmpDate = g_new0(gchar, MAX_DATE_LENGTH+1);
+ tmpDate = g_new0(gchar, MAX_DATE_LENGTH + 1);
g_date_strftime(tmpDate, MAX_DATE_LENGTH, "%x", &r->start);
- if (r->ptype == PERIOD_ONCE) {
+ if (r->ptype == PERIOD_ONCE)
+ {
ret = g_strdup_printf("once on %s", tmpDate);
goto done;
}
@@ -412,10 +456,14 @@
gchar *s;
str = g_string_new("");
- if (r == NULL) {
+ if (r == NULL)
+ {
g_string_append(str, _("None"));
- } else {
- for(iter = r; iter; iter = iter->next){
+ }
+ else
+ {
+ for (iter = r; iter; iter = iter->next)
+ {
if (iter != r)
{
/* translators: " + " is an separator in a list of string-representations of recurrence frequencies */
@@ -478,11 +526,11 @@
second_period = recurrenceGetPeriodType(second);
if (!((first_period == PERIOD_MONTH
- || first_period == PERIOD_END_OF_MONTH
- || first_period == PERIOD_LAST_WEEKDAY)
- && (second_period == PERIOD_MONTH
- || second_period == PERIOD_END_OF_MONTH
- || second_period == PERIOD_LAST_WEEKDAY)))
+ || first_period == PERIOD_END_OF_MONTH
+ || first_period == PERIOD_LAST_WEEKDAY)
+ && (second_period == PERIOD_MONTH
+ || second_period == PERIOD_END_OF_MONTH
+ || second_period == PERIOD_LAST_WEEKDAY)))
{
/*g_error("unknown 2-recurrence composite with period_types first [%d] second [%d]",
first_period, second_periodD);*/
@@ -534,7 +582,7 @@
if (multiplier > 1)
{
/* translators: %u is the recurrence multipler, i.e. this
- event should occur every %u'th week. */
+ event should occur every %u'th week. */
g_string_append_printf(buf, _(" (x%u)"), multiplier);
}
g_string_append_printf(buf, ": ");
@@ -630,23 +678,30 @@
switch (recurrenceGetPeriodType(r))
{
- case PERIOD_ONCE: {
+ case PERIOD_ONCE:
+ {
g_string_printf(buf, "%s", _("Once"));
- } break;
- case PERIOD_DAY: {
+ }
+ break;
+ case PERIOD_DAY:
+ {
g_string_printf(buf, "%s", _("Daily"));
if (multiplier > 1)
{
/* translators: %u is the recurrence multiplier. */
g_string_append_printf(buf, _(" (x%u)"), multiplier);
}
- } break;
- case PERIOD_WEEK: {
+ }
+ break;
+ case PERIOD_WEEK:
+ {
_weekly_list_to_compact_string(rs, buf);
- } break;
+ }
+ break;
case PERIOD_MONTH:
case PERIOD_END_OF_MONTH:
- case PERIOD_LAST_WEEKDAY: {
+ case PERIOD_LAST_WEEKDAY:
+ {
g_string_printf(buf, "%s", _("Monthly"));
if (multiplier > 1)
{
@@ -655,19 +710,24 @@
}
g_string_append_printf(buf, ": ");
_monthly_append_when(r, buf);
- } break;
- case PERIOD_NTH_WEEKDAY: {
+ }
+ break;
+ case PERIOD_NTH_WEEKDAY:
+ {
g_warning("nth weekday not handled");
g_string_printf(buf, "@fixme: nth weekday not handled");
- } break;
- case PERIOD_YEAR: {
+ }
+ break;
+ case PERIOD_YEAR:
+ {
g_string_printf(buf, "%s", _("Yearly"));
if (multiplier > 1)
{
/* translators: %u is the recurrence multiplier. */
g_string_append_printf(buf, _(" (x%u)"), multiplier);
}
- } break;
+ }
+ break;
default:
g_error("unknown Recurrence period %d", recurrenceGetPeriodType(r));
break;
Modified: gnucash/trunk/src/engine/SX-book.c
===================================================================
--- gnucash/trunk/src/engine/SX-book.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/SX-book.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -57,108 +57,111 @@
static Account *
gnc_collection_get_template_root( const QofCollection *col )
{
- return qof_collection_get_data (col);
+ return qof_collection_get_data (col);
}
Account *
gnc_book_get_template_root( const QofBook *book )
{
- QofCollection *col;
- if (!book) return NULL;
- col = qof_book_get_collection (book, GNC_ID_SXTG);
- return gnc_collection_get_template_root (col);
+ QofCollection *col;
+ if (!book) return NULL;
+ col = qof_book_get_collection (book, GNC_ID_SXTG);
+ return gnc_collection_get_template_root (col);
}
static void
gnc_collection_set_template_root (QofCollection *col,
Account *templateRoot)
{
- Account *old_root;
- if (!col) return;
+ Account *old_root;
+ if (!col) return;
- old_root = gnc_collection_get_template_root (col);
- if (old_root == templateRoot) return;
+ old_root = gnc_collection_get_template_root (col);
+ if (old_root == templateRoot) return;
- qof_collection_set_data (col, templateRoot);
+ qof_collection_set_data (col, templateRoot);
- if (old_root) {
- xaccAccountBeginEdit (old_root);
- xaccAccountDestroy (old_root);
- }
+ if (old_root)
+ {
+ xaccAccountBeginEdit (old_root);
+ xaccAccountDestroy (old_root);
+ }
}
void
gnc_book_set_template_root (QofBook *book, Account *templateRoot)
{
- QofCollection *col;
- if (!book) return;
+ QofCollection *col;
+ if (!book) return;
- if (templateRoot && gnc_account_get_book(templateRoot) != book)
- {
- g_critical("cannot mix and match books freely!");
- return;
- }
+ if (templateRoot && gnc_account_get_book(templateRoot) != book)
+ {
+ g_critical("cannot mix and match books freely!");
+ return;
+ }
- col = qof_book_get_collection (book, GNC_ID_SXTG);
- gnc_collection_set_template_root (col, templateRoot);
+ col = qof_book_get_collection (book, GNC_ID_SXTG);
+ gnc_collection_set_template_root (col, templateRoot);
}
/* ====================================================================== */
/* gncObject function implementation and registration */
-static void
+static void
sxtg_book_begin (QofBook *book)
{
- Account *root;
+ Account *root;
- root = xaccMallocAccount(book);
- xaccAccountBeginEdit(root);
- xaccAccountSetType(root, ACCT_TYPE_ROOT);
- xaccAccountSetName(root, "Template Root");
- xaccAccountCommitEdit(root);
- gnc_book_set_template_root (book, root);
- }
+ root = xaccMallocAccount(book);
+ xaccAccountBeginEdit(root);
+ xaccAccountSetType(root, ACCT_TYPE_ROOT);
+ xaccAccountSetName(root, "Template Root");
+ xaccAccountCommitEdit(root);
+ gnc_book_set_template_root (book, root);
+}
-static void
+static void
sxtg_book_end (QofBook *book)
{
- gnc_book_set_template_root (book, NULL);
+ gnc_book_set_template_root (book, NULL);
}
static gboolean
sxtg_is_dirty(const QofCollection *col)
{
- Account *root;
- GList *descendants, *node;
- gboolean dirty = FALSE;
+ Account *root;
+ GList *descendants, *node;
+ gboolean dirty = FALSE;
- root = gnc_collection_get_template_root(col);
- descendants = gnc_account_get_descendants(root);
- for (node = descendants; node; node = g_list_next(node)) {
- if (qof_instance_is_dirty(node->data)) {
- dirty = TRUE;
- break;
+ root = gnc_collection_get_template_root(col);
+ descendants = gnc_account_get_descendants(root);
+ for (node = descendants; node; node = g_list_next(node))
+ {
+ if (qof_instance_is_dirty(node->data))
+ {
+ dirty = TRUE;
+ break;
+ }
}
- }
- g_list_free(descendants);
+ g_list_free(descendants);
- return dirty;
+ return dirty;
}
-
+
static void
sxtg_mark_clean(QofCollection *col)
{
- Account *root;
- GList *descendants;
+ Account *root;
+ GList *descendants;
- root = gnc_collection_get_template_root(col);
- qof_collection_mark_clean(col);
+ root = gnc_collection_get_template_root(col);
+ qof_collection_mark_clean(col);
- descendants = gnc_account_get_descendants(root);
- g_list_foreach(descendants, (GFunc)qof_instance_mark_clean, NULL);
- g_list_free(descendants);
+ descendants = gnc_account_get_descendants(root);
+ g_list_foreach(descendants, (GFunc)qof_instance_mark_clean, NULL);
+ g_list_free(descendants);
}
#ifdef _MSC_VER
@@ -168,17 +171,17 @@
#else
# define DI(x) x
#endif
-static QofObject sxtg_object_def =
+static QofObject sxtg_object_def =
{
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_ID_SXTG,
- DI(.type_label =) "Scheduled Transaction Templates",
- DI(.book_begin =) sxtg_book_begin,
- DI(.book_end =) sxtg_book_end,
- DI(.is_dirty =) sxtg_is_dirty,
- DI(.mark_clean =) sxtg_mark_clean,
- DI(.foreach =) NULL,
- DI(.printable =) NULL,
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_ID_SXTG,
+ DI(.type_label = ) "Scheduled Transaction Templates",
+ DI(.book_begin = ) sxtg_book_begin,
+ DI(.book_end = ) sxtg_book_end,
+ DI(.is_dirty = ) sxtg_is_dirty,
+ DI(.mark_clean = ) sxtg_mark_clean,
+ DI(.foreach = ) NULL,
+ DI(.printable = ) NULL,
};
/* ====================================================================== */
@@ -186,37 +189,37 @@
SchedXactions*
gnc_collection_get_schedxactions(const QofCollection *col)
{
- SchedXactions *rtn = qof_collection_get_data(col);
- // @@assert(rtn != null);
- return rtn;
+ SchedXactions *rtn = qof_collection_get_data(col);
+ // @@assert(rtn != null);
+ return rtn;
}
SchedXactions*
gnc_book_get_schedxactions(QofBook *book)
{
- QofCollection *col;
- col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
- return gnc_collection_get_schedxactions(col);
+ QofCollection *col;
+ col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
+ return gnc_collection_get_schedxactions(col);
}
void
gnc_sxes_add_sx(SchedXactions *sxes, SchedXaction *sx)
{
- if (g_list_find(sxes->sx_list, sx) != NULL)
- return;
- sxes->sx_list = g_list_append(sxes->sx_list, sx);
- qof_event_gen(&sxes->inst, GNC_EVENT_ITEM_ADDED, (gpointer)sx);
+ if (g_list_find(sxes->sx_list, sx) != NULL)
+ return;
+ sxes->sx_list = g_list_append(sxes->sx_list, sx);
+ qof_event_gen(&sxes->inst, GNC_EVENT_ITEM_ADDED, (gpointer)sx);
}
void
gnc_sxes_del_sx(SchedXactions *sxes, SchedXaction *sx)
{
- GList *to_remove;
- to_remove = g_list_find(sxes->sx_list, sx);
- if (to_remove == NULL)
- return;
- sxes->sx_list = g_list_delete_link(sxes->sx_list, to_remove);
- qof_event_gen(&sxes->inst, GNC_EVENT_ITEM_REMOVED, (gpointer)sx);
+ GList *to_remove;
+ to_remove = g_list_find(sxes->sx_list, sx);
+ if (to_remove == NULL)
+ return;
+ sxes->sx_list = g_list_delete_link(sxes->sx_list, to_remove);
+ qof_event_gen(&sxes->inst, GNC_EVENT_ITEM_REMOVED, (gpointer)sx);
}
/* ====================================================================== */
@@ -243,137 +246,138 @@
static void
mark_sx_clean(gpointer data, gpointer user_data)
{
- SchedXaction *sx = (SchedXaction *) data;
- qof_instance_mark_clean (QOF_INSTANCE(sx));
+ SchedXaction *sx = (SchedXaction *) data;
+ qof_instance_mark_clean (QOF_INSTANCE(sx));
}
static void
book_sxes_setup(QofBook *book)
{
- QofCollection *col;
- SchedXactions *sxes;
+ QofCollection *col;
+ SchedXactions *sxes;
- col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
- sxes = g_object_new (GNC_TYPE_SCHEDXACTIONS, NULL);
- g_assert(sxes);
- qof_instance_init_data(&sxes->inst, GNC_ID_SXES, book);
- sxes->sx_list = NULL;
- sxes->sx_notsaved = TRUE;
- qof_collection_set_data(col, sxes);
+ col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
+ sxes = g_object_new (GNC_TYPE_SCHEDXACTIONS, NULL);
+ g_assert(sxes);
+ qof_instance_init_data(&sxes->inst, GNC_ID_SXES, book);
+ sxes->sx_list = NULL;
+ sxes->sx_notsaved = TRUE;
+ qof_collection_set_data(col, sxes);
}
static void
book_sxes_end(QofBook* book)
{
- QofCollection *col;
- SchedXactions *sxes;
+ QofCollection *col;
+ SchedXactions *sxes;
- col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
- sxes = qof_collection_get_data(col);
- if (sxes != NULL) {
- g_object_unref(sxes);
- qof_collection_set_data(col, NULL);
+ col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
+ sxes = qof_collection_get_data(col);
+ if (sxes != NULL)
+ {
+ g_object_unref(sxes);
+ qof_collection_set_data(col, NULL);
}
}
static void
book_sxns_mark_saved(QofCollection *col)
{
- SchedXactions *sxl;
- sxl = gnc_collection_get_schedxactions(col);
- if (!sxl)
- return;
- sxl->sx_notsaved = FALSE;
- g_list_foreach(sxl->sx_list,
- mark_sx_clean,
- NULL);
+ SchedXactions *sxl;
+ sxl = gnc_collection_get_schedxactions(col);
+ if (!sxl)
+ return;
+ sxl->sx_notsaved = FALSE;
+ g_list_foreach(sxl->sx_list,
+ mark_sx_clean,
+ NULL);
}
static gboolean
book_sxlist_notsaved(const QofCollection *col)
{
- GList *sxlist;
- SchedXactions *sxl;
+ GList *sxlist;
+ SchedXactions *sxl;
- sxl = gnc_collection_get_schedxactions(col);
- if (!sxl) return FALSE;
- if((sxl && sxl->sx_notsaved)) return TRUE;
-
- for(sxlist = sxl->sx_list;
- sxlist != NULL;
- sxlist = g_list_next(sxlist))
- {
- SchedXaction *sx;
- sx = (SchedXaction *) (sxlist->data);
- if (xaccSchedXactionIsDirty( sx ))
- return TRUE;
- }
+ sxl = gnc_collection_get_schedxactions(col);
+ if (!sxl) return FALSE;
+ if ((sxl && sxl->sx_notsaved)) return TRUE;
- return FALSE;
+ for (sxlist = sxl->sx_list;
+ sxlist != NULL;
+ sxlist = g_list_next(sxlist))
+ {
+ SchedXaction *sx;
+ sx = (SchedXaction *) (sxlist->data);
+ if (xaccSchedXactionIsDirty( sx ))
+ return TRUE;
+ }
+
+ return FALSE;
}
static QofObject sxes_object_def =
{
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_ID_SXES,
- DI(.type_label =) "Scheduled Transactions List",
- DI(.create =) NULL,
- DI(.book_begin =) book_sxes_setup,
- DI(.book_end =) book_sxes_end,
- DI(.is_dirty =) book_sxlist_notsaved,
- DI(.mark_clean =) book_sxns_mark_saved,
- DI(.foreach =) NULL,
- DI(.printable =) NULL,
- DI(.version_cmp =) NULL
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_ID_SXES,
+ DI(.type_label = ) "Scheduled Transactions List",
+ DI(.create = ) NULL,
+ DI(.book_begin = ) book_sxes_setup,
+ DI(.book_end = ) book_sxes_end,
+ DI(.is_dirty = ) book_sxlist_notsaved,
+ DI(.mark_clean = ) book_sxns_mark_saved,
+ DI(.foreach = ) NULL,
+ DI(.printable = ) NULL,
+ DI(.version_cmp = ) NULL
};
-
-static QofObject sxtt_object_def =
+
+static QofObject sxtt_object_def =
{
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_ID_SXTT,
- DI(.type_label =) "Scheduled Transaction Templates",
- DI(.create =) NULL,
- DI(.book_begin =) NULL,
- DI(.book_end =) NULL,
- DI(.is_dirty =) NULL,
- DI(.mark_clean =) NULL,
- DI(.foreach =) NULL,
- DI(.printable =) NULL,
- DI(.version_cmp =) NULL,
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_ID_SXTT,
+ DI(.type_label = ) "Scheduled Transaction Templates",
+ DI(.create = ) NULL,
+ DI(.book_begin = ) NULL,
+ DI(.book_end = ) NULL,
+ DI(.is_dirty = ) NULL,
+ DI(.mark_clean = ) NULL,
+ DI(.foreach = ) NULL,
+ DI(.printable = ) NULL,
+ DI(.version_cmp = ) NULL,
};
-gboolean
+gboolean
gnc_sxtt_register (void)
{
- if (!qof_object_register(&sxes_object_def))
- return FALSE;
- if (!qof_object_register(&sxtg_object_def))
- return FALSE;
- return qof_object_register(&sxtt_object_def);
+ if (!qof_object_register(&sxes_object_def))
+ return FALSE;
+ if (!qof_object_register(&sxtg_object_def))
+ return FALSE;
+ return qof_object_register(&sxtt_object_def);
}
GList*
gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct)
{
- GList *rtn = NULL;
- const GUID *acct_guid = qof_entity_get_guid(QOF_INSTANCE(acct));
- GList *sx_list = gnc_book_get_schedxactions(book)->sx_list;
- for (; sx_list != NULL; sx_list = sx_list->next)
- {
- SchedXaction *sx = (SchedXaction*)sx_list->data;
- GList *splits = xaccSchedXactionGetSplits(sx);
- for (; splits != NULL; splits = splits->next)
+ GList *rtn = NULL;
+ const GUID *acct_guid = qof_entity_get_guid(QOF_INSTANCE(acct));
+ GList *sx_list = gnc_book_get_schedxactions(book)->sx_list;
+ for (; sx_list != NULL; sx_list = sx_list->next)
{
- Split *s = (Split*)splits->data;
- KvpFrame *frame = kvp_frame_get_frame(xaccSplitGetSlots(s), GNC_SX_ID);
- GUID *sx_split_acct_guid = kvp_frame_get_guid(frame, GNC_SX_ACCOUNT);
- if (guid_equal(acct_guid, sx_split_acct_guid))
- {
- rtn = g_list_append(rtn, sx);
- }
+ SchedXaction *sx = (SchedXaction*)sx_list->data;
+ GList *splits = xaccSchedXactionGetSplits(sx);
+ for (; splits != NULL; splits = splits->next)
+ {
+ Split *s = (Split*)splits->data;
+ KvpFrame *frame = kvp_frame_get_frame(xaccSplitGetSlots(s), GNC_SX_ID);
+ GUID *sx_split_acct_guid = kvp_frame_get_guid(frame, GNC_SX_ACCOUNT);
+ if (guid_equal(acct_guid, sx_split_acct_guid))
+ {
+ rtn = g_list_append(rtn, sx);
+ }
+ }
}
- }
- return rtn;
+ return rtn;
}
/* ========================== END OF FILE =============================== */
Modified: gnucash/trunk/src/engine/SX-ttinfo.c
===================================================================
--- gnucash/trunk/src/engine/SX-ttinfo.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/SX-ttinfo.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -30,308 +30,308 @@
/* KvpFrame policy? */
struct TTInfo_s
{
- /* FIXME add notes field */
- char *description; /* owned by us */
- char *num; /* owned by us */
- gnc_commodity *common_currency; /* not freed */
-
- GList *splits; /* list of template splits, owned by us */
+ /* FIXME add notes field */
+ char *description; /* owned by us */
+ char *num; /* owned by us */
+ gnc_commodity *common_currency; /* not freed */
+
+ GList *splits; /* list of template splits, owned by us */
};
struct TTSplitInfo_s
{
- char *action; /* owned by us */
- /* FIXME: What about the split's KvpFrame */
- char *memo; /* owned by us */
- char *credit_formula, *debit_formula; /* owned by us */
- Account *acc;
+ char *action; /* owned by us */
+ /* FIXME: What about the split's KvpFrame */
+ char *memo; /* owned by us */
+ char *credit_formula, *debit_formula; /* owned by us */
+ Account *acc;
};
TTInfo *
gnc_ttinfo_malloc(void)
{
- TTInfo *tti = g_new0(TTInfo, 1);
- return tti;
+ TTInfo *tti = g_new0(TTInfo, 1);
+ return tti;
}
static void
delete_splitinfo(gpointer data, gpointer user_data)
{
- gnc_ttsplitinfo_free( (TTSplitInfo *) data);
- return;
+ gnc_ttsplitinfo_free( (TTSplitInfo *) data);
+ return;
}
void gnc_ttinfo_free(TTInfo *info)
{
- g_return_if_fail(info);
-
- g_free(info->description);
- g_free(info->num);
- g_list_foreach(info->splits,
- delete_splitinfo,
- NULL);
+ g_return_if_fail(info);
- g_list_free(info->splits);
+ g_free(info->description);
+ g_free(info->num);
+ g_list_foreach(info->splits,
+ delete_splitinfo,
+ NULL);
- g_free(info);
+ g_list_free(info->splits);
- return;
+ g_free(info);
+
+ return;
}
-void
+void
gnc_ttinfo_set_description(TTInfo *tti, const char *description)
{
- g_return_if_fail(tti);
-
- if(tti->description)
- {
- g_free(tti->description);
- }
-
- tti->description = g_strdup(description);
+ g_return_if_fail(tti);
- return;
+ if (tti->description)
+ {
+ g_free(tti->description);
+ }
+
+ tti->description = g_strdup(description);
+
+ return;
}
const char *
gnc_ttinfo_get_description(TTInfo *tti)
{
- g_return_val_if_fail(tti, NULL);
+ g_return_val_if_fail(tti, NULL);
- return tti->description;
+ return tti->description;
}
-
+
void
gnc_ttinfo_set_num(TTInfo *tti, const char *num)
{
- g_return_if_fail(tti);
-
- if(tti->num)
- {
- g_free(tti->num);
- }
-
- tti->num = g_strdup(num);
+ g_return_if_fail(tti);
- return;
+ if (tti->num)
+ {
+ g_free(tti->num);
+ }
+
+ tti->num = g_strdup(num);
+
+ return;
}
const char*
gnc_ttinfo_get_num(TTInfo *tti)
{
- g_return_val_if_fail(tti, NULL);
+ g_return_val_if_fail(tti, NULL);
- return tti->num;
+ return tti->num;
}
void
gnc_ttinfo_set_currency(TTInfo *tti, gnc_commodity *common_currency)
{
- g_return_if_fail(tti);
+ g_return_if_fail(tti);
- tti->common_currency = common_currency;
- return;
+ tti->common_currency = common_currency;
+ return;
}
gnc_commodity *
gnc_ttinfo_get_currency(TTInfo *tti)
{
- g_return_val_if_fail(tti, NULL);
+ g_return_val_if_fail(tti, NULL);
- return tti->common_currency;
+ return tti->common_currency;
}
void gnc_ttinfo_set_template_splits(TTInfo *tti, GList *splits)
{
- g_return_if_fail(tti);
+ g_return_if_fail(tti);
- tti->splits = splits;
- return;
+ tti->splits = splits;
+ return;
}
void gnc_ttinfo_append_template_split(TTInfo *tti, TTSplitInfo *split_i)
{
- g_return_if_fail(tti && split_i);
+ g_return_if_fail(tti && split_i);
- tti->splits = g_list_append(tti->splits, split_i);
+ tti->splits = g_list_append(tti->splits, split_i);
- return;
+ return;
}
-
+
GList *
gnc_ttinfo_get_template_splits(TTInfo *tti)
{
- g_return_val_if_fail(tti, NULL);
- return tti->splits;
+ g_return_val_if_fail(tti, NULL);
+ return tti->splits;
}
TTSplitInfo *
gnc_ttsplitinfo_malloc(void)
{
- TTSplitInfo *ttsi = g_new0(TTSplitInfo, 1);
- return ttsi;
+ TTSplitInfo *ttsi = g_new0(TTSplitInfo, 1);
+ return ttsi;
}
void
gnc_ttsplitinfo_free(TTSplitInfo *ttsi)
{
- if ( ttsi->action )
- g_free(ttsi->action);
- if ( ttsi->memo )
- g_free(ttsi->memo);
- if ( ttsi->credit_formula )
- g_free(ttsi->credit_formula);
- if ( ttsi->debit_formula )
- g_free(ttsi->debit_formula);
- g_free(ttsi);
- return;
+ if ( ttsi->action )
+ g_free(ttsi->action);
+ if ( ttsi->memo )
+ g_free(ttsi->memo);
+ if ( ttsi->credit_formula )
+ g_free(ttsi->credit_formula);
+ if ( ttsi->debit_formula )
+ g_free(ttsi->debit_formula);
+ g_free(ttsi);
+ return;
}
-void
+void
gnc_ttsplitinfo_set_action(TTSplitInfo *ttsi, const char *action)
{
- g_return_if_fail(ttsi);
+ g_return_if_fail(ttsi);
- if (ttsi->action)
- g_free(ttsi->action);
+ if (ttsi->action)
+ g_free(ttsi->action);
- ttsi->action = g_strdup(action);
- return;
+ ttsi->action = g_strdup(action);
+ return;
}
-const char *
+const char *
gnc_ttsplitinfo_get_action(TTSplitInfo *ttsi)
{
- g_return_val_if_fail(ttsi, NULL);
+ g_return_val_if_fail(ttsi, NULL);
- return ttsi->action;
+ return ttsi->action;
}
-void
+void
gnc_ttsplitinfo_set_memo(TTSplitInfo *ttsi, const char *memo)
{
- g_return_if_fail(ttsi);
+ g_return_if_fail(ttsi);
- if (ttsi->memo)
- g_free(ttsi->memo);
+ if (ttsi->memo)
+ g_free(ttsi->memo);
- ttsi->memo = g_strdup(memo);
- return;
+ ttsi->memo = g_strdup(memo);
+ return;
}
-const char *
+const char *
gnc_ttsplitinfo_get_memo(TTSplitInfo *ttsi)
{
- g_return_val_if_fail(ttsi, NULL);
+ g_return_val_if_fail(ttsi, NULL);
- return ttsi->memo;
+ return ttsi->memo;
}
void
gnc_ttsplitinfo_set_credit_formula_numeric(TTSplitInfo *ttsi, gnc_numeric credit)
{
- g_return_if_fail(ttsi);
+ g_return_if_fail(ttsi);
- if(ttsi->credit_formula)
- g_free(ttsi->credit_formula);
+ if (ttsi->credit_formula)
+ g_free(ttsi->credit_formula);
- ttsi->credit_formula = gnc_numeric_to_string(credit);
-
- if(ttsi->debit_formula)
- {
- g_free(ttsi->debit_formula);
- ttsi->debit_formula = NULL;
- }
+ ttsi->credit_formula = gnc_numeric_to_string(credit);
+
+ if (ttsi->debit_formula)
+ {
+ g_free(ttsi->debit_formula);
+ ttsi->debit_formula = NULL;
+ }
}
-void
+void
gnc_ttsplitinfo_set_credit_formula(TTSplitInfo *ttsi, const char *credit_formula)
{
- g_return_if_fail(ttsi);
+ g_return_if_fail(ttsi);
- if (ttsi->credit_formula)
- g_free(ttsi->credit_formula);
+ if (ttsi->credit_formula)
+ g_free(ttsi->credit_formula);
- ttsi->credit_formula = g_strdup(credit_formula);
-
- if(ttsi->debit_formula)
- {
- g_free(ttsi->debit_formula);
- ttsi->debit_formula = NULL;
- }
- return;
+ ttsi->credit_formula = g_strdup(credit_formula);
+
+ if (ttsi->debit_formula)
+ {
+ g_free(ttsi->debit_formula);
+ ttsi->debit_formula = NULL;
+ }
+ return;
}
-const char *
+const char *
gnc_ttsplitinfo_get_credit_formula(TTSplitInfo *ttsi)
{
- g_return_val_if_fail(ttsi, NULL);
- return ttsi->credit_formula;
+ g_return_val_if_fail(ttsi, NULL);
+ return ttsi->credit_formula;
}
-const char *
+const char *
gnc_ttsplitinfo_get_debit_formula(TTSplitInfo *ttsi)
{
- g_return_val_if_fail(ttsi, NULL);
- return ttsi->debit_formula;
+ g_return_val_if_fail(ttsi, NULL);
+ return ttsi->debit_formula;
}
void
gnc_ttsplitinfo_set_debit_formula_numeric(TTSplitInfo *ttsi, gnc_numeric debit)
{
- g_return_if_fail(ttsi);
+ g_return_if_fail(ttsi);
- if (ttsi->debit_formula)
- {
- g_free(ttsi->debit_formula);
- }
- ttsi->debit_formula = gnc_numeric_to_string(debit);
+ if (ttsi->debit_formula)
+ {
+ g_free(ttsi->debit_formula);
+ }
+ ttsi->debit_formula = gnc_numeric_to_string(debit);
- if (ttsi->credit_formula)
- {
- g_free(ttsi->credit_formula);
- ttsi->credit_formula = NULL;
- }
- return;
+ if (ttsi->credit_formula)
+ {
+ g_free(ttsi->credit_formula);
+ ttsi->credit_formula = NULL;
+ }
+ return;
}
-void
+void
gnc_ttsplitinfo_set_debit_formula(TTSplitInfo *ttsi, const char *debit_formula)
{
- g_return_if_fail(ttsi);
+ g_return_if_fail(ttsi);
- if (ttsi->debit_formula)
- g_free(ttsi->debit_formula);
+ if (ttsi->debit_formula)
+ g_free(ttsi->debit_formula);
- ttsi->debit_formula = g_strdup(debit_formula);
+ ttsi->debit_formula = g_strdup(debit_formula);
- if (ttsi->credit_formula)
- {
- g_free(ttsi->credit_formula);
- ttsi->credit_formula = NULL;
- }
- return;
+ if (ttsi->credit_formula)
+ {
+ g_free(ttsi->credit_formula);
+ ttsi->credit_formula = NULL;
+ }
+ return;
}
void
gnc_ttsplitinfo_set_account(TTSplitInfo *ttsi, Account *acc)
{
- g_return_if_fail(ttsi && acc);
+ g_return_if_fail(ttsi && acc);
- ttsi->acc = acc;
- return;
+ ttsi->acc = acc;
+ return;
}
Account *
gnc_ttsplitinfo_get_account(TTSplitInfo *ttsi)
{
- g_return_val_if_fail(ttsi, NULL);
+ g_return_val_if_fail(ttsi, NULL);
- return ttsi->acc;
+ return ttsi->acc;
}
Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/SchedXaction.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -44,20 +44,21 @@
void sxprivtransactionListMapDelete( gpointer data, gpointer user_data );
-enum {
+enum
+{
PROP_0,
- PROP_NAME,
- PROP_ENABLED,
- PROP_NUM_OCCURANCE,
- PROP_REM_OCCURANCE,
- PROP_AUTO_CREATE,
- PROP_AUTO_CREATE_NOTIFY,
- PROP_ADVANCE_CREATION_DAYS,
- PROP_ADVANCE_REMINDER_DAYS,
- PROP_START_DATE,
- PROP_END_DATE,
- PROP_LAST_OCCURANCE_DATE,
- PROP_INSTANCE_COUNT
+ PROP_NAME,
+ PROP_ENABLED,
+ PROP_NUM_OCCURANCE,
+ PROP_REM_OCCURANCE,
+ PROP_AUTO_CREATE,
+ PROP_AUTO_CREATE_NOTIFY,
+ PROP_ADVANCE_CREATION_DAYS,
+ PROP_ADVANCE_REMINDER_DAYS,
+ PROP_START_DATE,
+ PROP_END_DATE,
+ PROP_LAST_OCCURANCE_DATE,
+ PROP_INSTANCE_COUNT
};
/* GObject initialization */
@@ -66,20 +67,20 @@
static void
gnc_schedxaction_init(SchedXaction* sx)
{
- sx->schedule = NULL;
+ sx->schedule = NULL;
- g_date_clear( &sx->last_date, 1 );
- g_date_clear( &sx->start_date, 1 );
- g_date_clear( &sx->end_date, 1 );
+ g_date_clear( &sx->last_date, 1 );
+ g_date_clear( &sx->start_date, 1 );
+ g_date_clear( &sx->end_date, 1 );
- sx->enabled = 1;
- sx->num_occurances_total = 0;
- sx->autoCreateOption = FALSE;
- sx->autoCreateNotify = FALSE;
- sx->advanceCreateDays = 0;
- sx->advanceRemindDays = 0;
- sx->instance_num = 0;
- sx->deferredList = NULL;
+ sx->enabled = 1;
+ sx->num_occurances_total = 0;
+ sx->autoCreateOption = FALSE;
+ sx->autoCreateNotify = FALSE;
+ sx->advanceCreateDays = 0;
+ sx->advanceRemindDays = 0;
+ sx->instance_num = 0;
+ sx->deferredList = NULL;
}
static void
@@ -96,119 +97,121 @@
static void
gnc_schedxaction_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
SchedXaction *sx;
g_return_if_fail(GNC_IS_SCHEDXACTION(object));
sx = GNC_SCHEDXACTION(object);
- switch(prop_id) {
- case PROP_NAME:
- g_value_set_string(value, sx->name);
- break;
- case PROP_ENABLED:
- g_value_set_boolean(value, sx->enabled);
- break;
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ g_value_set_string(value, sx->name);
+ break;
+ case PROP_ENABLED:
+ g_value_set_boolean(value, sx->enabled);
+ break;
case PROP_NUM_OCCURANCE:
- g_value_set_int(value, sx->num_occurances_total);
- break;
+ g_value_set_int(value, sx->num_occurances_total);
+ break;
case PROP_REM_OCCURANCE:
- g_value_set_int(value, sx->num_occurances_remain);
- break;
- case PROP_AUTO_CREATE:
- g_value_set_boolean(value, sx->autoCreateOption);
- break;
+ g_value_set_int(value, sx->num_occurances_remain);
+ break;
+ case PROP_AUTO_CREATE:
+ g_value_set_boolean(value, sx->autoCreateOption);
+ break;
case PROP_AUTO_CREATE_NOTIFY:
- g_value_set_boolean(value, sx->autoCreateNotify);
- break;
- case PROP_ADVANCE_CREATION_DAYS:
- g_value_set_int(value, sx->advanceCreateDays);
- break;
- case PROP_ADVANCE_REMINDER_DAYS:
- g_value_set_int(value, sx->advanceRemindDays);
- break;
+ g_value_set_boolean(value, sx->autoCreateNotify);
+ break;
+ case PROP_ADVANCE_CREATION_DAYS:
+ g_value_set_int(value, sx->advanceCreateDays);
+ break;
+ case PROP_ADVANCE_REMINDER_DAYS:
+ g_value_set_int(value, sx->advanceRemindDays);
+ break;
case PROP_START_DATE:
- g_value_set_boxed(value, &sx->start_date);
- break;
+ g_value_set_boxed(value, &sx->start_date);
+ break;
case PROP_END_DATE:
- g_value_set_boxed(value, &sx->end_date);
- break;
+ g_value_set_boxed(value, &sx->end_date);
+ break;
case PROP_LAST_OCCURANCE_DATE:
- g_value_set_boxed(value, &sx->last_date);
- break;
+ g_value_set_boxed(value, &sx->last_date);
+ break;
case PROP_INSTANCE_COUNT:
- g_value_set_int(value, sx->instance_num);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
+ g_value_set_int(value, sx->instance_num);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
static void
gnc_schedxaction_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
SchedXaction *sx;
- GDate* date;
+ GDate* date;
g_return_if_fail(GNC_IS_SCHEDXACTION(object));
sx = GNC_SCHEDXACTION(object);
- switch(prop_id) {
- case PROP_NAME:
- xaccSchedXactionSetName(sx, g_value_get_string(value));
- break;
- case PROP_ENABLED:
- xaccSchedXactionSetEnabled(sx, g_value_get_boolean(value));
- break;
+ switch (prop_id)
+ {
+ case PROP_NAME:
+ xaccSchedXactionSetName(sx, g_value_get_string(value));
+ break;
+ case PROP_ENABLED:
+ xaccSchedXactionSetEnabled(sx, g_value_get_boolean(value));
+ break;
case PROP_NUM_OCCURANCE:
- xaccSchedXactionSetNumOccur(sx, g_value_get_int(value));
- break;
+ xaccSchedXactionSetNumOccur(sx, g_value_get_int(value));
+ break;
case PROP_REM_OCCURANCE:
- xaccSchedXactionSetRemOccur(sx, g_value_get_int(value));
- break;
+ xaccSchedXactionSetRemOccur(sx, g_value_get_int(value));
+ break;
case PROP_AUTO_CREATE:
- xaccSchedXactionSetAutoCreate(sx, g_value_get_boolean(value), sx->autoCreateNotify);
- break;
+ xaccSchedXactionSetAutoCreate(sx, g_value_get_boolean(value), sx->autoCreateNotify);
+ break;
case PROP_AUTO_CREATE_NOTIFY:
- xaccSchedXactionSetAutoCreate(sx, sx->autoCreateOption, g_value_get_boolean(value));
- break;
- case PROP_ADVANCE_CREATION_DAYS:
- xaccSchedXactionSetAdvanceCreation(sx, g_value_get_int(value));
- break;
- case PROP_ADVANCE_REMINDER_DAYS:
- xaccSchedXactionSetAdvanceReminder(sx, g_value_get_int(value));
- break;
+ xaccSchedXactionSetAutoCreate(sx, sx->autoCreateOption, g_value_get_boolean(value));
+ break;
+ case PROP_ADVANCE_CREATION_DAYS:
+ xaccSchedXactionSetAdvanceCreation(sx, g_value_get_int(value));
+ break;
+ case PROP_ADVANCE_REMINDER_DAYS:
+ xaccSchedXactionSetAdvanceReminder(sx, g_value_get_int(value));
+ break;
case PROP_START_DATE:
- /* Note: when passed through a boxed gvalue, the julian value of the date is copied.
- The date may appear invalid until a function requiring for dmy calculation is
- called. */
- xaccSchedXactionSetStartDate(sx, g_value_get_boxed(value));
- break;
+ /* Note: when passed through a boxed gvalue, the julian value of the date is copied.
+ The date may appear invalid until a function requiring for dmy calculation is
+ called. */
+ xaccSchedXactionSetStartDate(sx, g_value_get_boxed(value));
+ break;
case PROP_END_DATE:
- /* Note: when passed through a boxed gvalue, the julian value of the date is copied.
- The date may appear invalid until a function requiring for dmy calculation is
- called. */
- xaccSchedXactionSetEndDate(sx, g_value_get_boxed(value));
- break;
+ /* Note: when passed through a boxed gvalue, the julian value of the date is copied.
+ The date may appear invalid until a function requiring for dmy calculation is
+ called. */
+ xaccSchedXactionSetEndDate(sx, g_value_get_boxed(value));
+ break;
case PROP_LAST_OCCURANCE_DATE:
- /* Note: when passed through a boxed gvalue, the julian value of the date is copied.
- The date may appear invalid until a function requiring for dmy calculation is
- called. */
- xaccSchedXactionSetLastOccurDate(sx, g_value_get_boxed(value));
- break;
+ /* Note: when passed through a boxed gvalue, the julian value of the date is copied.
+ The date may appear invalid until a function requiring for dmy calculation is
+ called. */
+ xaccSchedXactionSetLastOccurDate(sx, g_value_get_boxed(value));
+ break;
case PROP_INSTANCE_COUNT:
- gnc_sx_set_instance_count(sx, g_value_get_int(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
+ gnc_sx_set_instance_count(sx, g_value_get_int(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
@@ -216,272 +219,275 @@
gnc_schedxaction_class_init (SchedXactionClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
+
gobject_class->dispose = gnc_schedxaction_dispose;
gobject_class->finalize = gnc_schedxaction_finalize;
gobject_class->set_property = gnc_schedxaction_set_property;
gobject_class->get_property = gnc_schedxaction_get_property;
g_object_class_install_property
- (gobject_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Scheduled Transaction Name",
- "The name is an arbitrary string "
- "assigned by the user. It is intended to "
- "a short, 5 to 30 character long string "
- "that is displayed by the GUI.",
- NULL,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Scheduled Transaction Name",
+ "The name is an arbitrary string "
+ "assigned by the user. It is intended to "
+ "a short, 5 to 30 character long string "
+ "that is displayed by the GUI.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_ENABLED,
- g_param_spec_boolean ("enabled",
- "Enabled",
- "TRUE if the scheduled transaction is enabled.",
- TRUE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_ENABLED,
+ g_param_spec_boolean ("enabled",
+ "Enabled",
+ "TRUE if the scheduled transaction is enabled.",
+ TRUE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_NUM_OCCURANCE,
- g_param_spec_int ("num-occurance",
- "Number of occurances",
- "Total number of occurances for this scheduled transaction.",
- 0,
- G_MAXINT16,
- 1,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_NUM_OCCURANCE,
+ g_param_spec_int ("num-occurance",
+ "Number of occurances",
+ "Total number of occurances for this scheduled transaction.",
+ 0,
+ G_MAXINT16,
+ 1,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_REM_OCCURANCE,
- g_param_spec_int ("rem-occurance",
- "Number of occurances remaining",
- "Remaining number of occurances for this scheduled transaction.",
- 0,
- G_MAXINT16,
- 1,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_REM_OCCURANCE,
+ g_param_spec_int ("rem-occurance",
+ "Number of occurances remaining",
+ "Remaining number of occurances for this scheduled transaction.",
+ 0,
+ G_MAXINT16,
+ 1,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_AUTO_CREATE,
- g_param_spec_boolean ("auto-create",
- "Auto-create",
- "TRUE if the transaction will be automatically "
- "created when its time comes.",
- FALSE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_AUTO_CREATE,
+ g_param_spec_boolean ("auto-create",
+ "Auto-create",
+ "TRUE if the transaction will be automatically "
+ "created when its time comes.",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_AUTO_CREATE_NOTIFY,
- g_param_spec_boolean ("auto-create-notify",
- "Auto-create-notify",
- "TRUE if the the user will be notified when the transaction "
- "is automatically created.",
- FALSE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_AUTO_CREATE_NOTIFY,
+ g_param_spec_boolean ("auto-create-notify",
+ "Auto-create-notify",
+ "TRUE if the the user will be notified when the transaction "
+ "is automatically created.",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_ADVANCE_CREATION_DAYS,
- g_param_spec_int ("advance-creation-days",
- "Days in advance to create",
- "Number of days in advance to create this scheduled transaction.",
- 0,
- G_MAXINT16,
- 0,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_ADVANCE_CREATION_DAYS,
+ g_param_spec_int ("advance-creation-days",
+ "Days in advance to create",
+ "Number of days in advance to create this scheduled transaction.",
+ 0,
+ G_MAXINT16,
+ 0,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_ADVANCE_REMINDER_DAYS,
- g_param_spec_int ("advance-reminder-days",
- "Days in advance to remind",
- "Number of days in advance to remind about this scheduled transaction.",
- 0,
- G_MAXINT16,
- 0,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_ADVANCE_REMINDER_DAYS,
+ g_param_spec_int ("advance-reminder-days",
+ "Days in advance to remind",
+ "Number of days in advance to remind about this scheduled transaction.",
+ 0,
+ G_MAXINT16,
+ 0,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_START_DATE,
- g_param_spec_boxed("start-date",
- "Start Date",
- "Date for the first occurence for the scheduled transaction.",
- G_TYPE_DATE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_START_DATE,
+ g_param_spec_boxed("start-date",
+ "Start Date",
+ "Date for the first occurence for the scheduled transaction.",
+ G_TYPE_DATE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_END_DATE,
- g_param_spec_boxed("end-date",
- "End Date",
- "Date for the scheduled transaction to end.",
- G_TYPE_DATE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_END_DATE,
+ g_param_spec_boxed("end-date",
+ "End Date",
+ "Date for the scheduled transaction to end.",
+ G_TYPE_DATE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_LAST_OCCURANCE_DATE,
- g_param_spec_boxed("last-occurance-date",
- "Last Occurance Date",
- "Date for the last occurance of the scheduled transaction.",
- G_TYPE_DATE,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_LAST_OCCURANCE_DATE,
+ g_param_spec_boxed("last-occurance-date",
+ "Last Occurance Date",
+ "Date for the last occurance of the scheduled transaction.",
+ G_TYPE_DATE,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_INSTANCE_COUNT,
- g_param_spec_int ("instance-count",
- "Instance count",
- "Number of instances of this scheduled transaction.",
- 0,
- G_MAXINT16,
- 0,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_INSTANCE_COUNT,
+ g_param_spec_int ("instance-count",
+ "Instance count",
+ "Number of instances of this scheduled transaction.",
+ 0,
+ G_MAXINT16,
+ 0,
+ G_PARAM_READWRITE));
}
static void
xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
{
- Account *ra;
- const GUID *guid;
+ Account *ra;
+ const GUID *guid;
- qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
+ qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);
- /* create a new template account for our splits */
- sx->template_acct = xaccMallocAccount(book);
- guid = qof_instance_get_guid( sx );
- xaccAccountBeginEdit( sx->template_acct );
- xaccAccountSetName( sx->template_acct, guid_to_string( guid ));
- xaccAccountSetCommodity
- (sx->template_acct,
- gnc_commodity_table_lookup( gnc_commodity_table_get_table(book),
- "template", "template") );
- xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK );
- xaccAccountCommitEdit( sx->template_acct );
- ra = gnc_book_get_template_root( book );
- gnc_account_append_child( ra, sx->template_acct );
+ /* create a new template account for our splits */
+ sx->template_acct = xaccMallocAccount(book);
+ guid = qof_instance_get_guid( sx );
+ xaccAccountBeginEdit( sx->template_acct );
+ xaccAccountSetName( sx->template_acct, guid_to_string( guid ));
+ xaccAccountSetCommodity
+ (sx->template_acct,
+ gnc_commodity_table_lookup( gnc_commodity_table_get_table(book),
+ "template", "template") );
+ xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK );
+ xaccAccountCommitEdit( sx->template_acct );
+ ra = gnc_book_get_template_root( book );
+ gnc_account_append_child( ra, sx->template_acct );
}
SchedXaction*
xaccSchedXactionMalloc(QofBook *book)
{
- SchedXaction *sx;
+ SchedXaction *sx;
- g_return_val_if_fail (book, NULL);
+ g_return_val_if_fail (book, NULL);
- sx = g_object_new(GNC_TYPE_SCHEDXACTION, NULL);
- xaccSchedXactionInit( sx, book );
- qof_event_gen( &sx->inst, QOF_EVENT_CREATE , NULL);
+ sx = g_object_new(GNC_TYPE_SCHEDXACTION, NULL);
+ xaccSchedXactionInit( sx, book );
+ qof_event_gen( &sx->inst, QOF_EVENT_CREATE , NULL);
- return sx;
+ return sx;
}
static void
sxprivTransMapDelete( gpointer data, gpointer user_data )
{
- Transaction *t = (Transaction *) data;
- xaccTransBeginEdit( t );
- xaccTransDestroy( t );
- xaccTransCommitEdit( t );
- return;
+ Transaction *t = (Transaction *) data;
+ xaccTransBeginEdit( t );
+ xaccTransDestroy( t );
+ xaccTransCommitEdit( t );
+ return;
}
static void
delete_template_trans(SchedXaction *sx)
{
- GList *templ_acct_splits, *curr_split_listref;
- Split *curr_split;
- Transaction *split_trans;
- GList *templ_acct_transactions = NULL;
+ GList *templ_acct_splits, *curr_split_listref;
+ Split *curr_split;
+ Transaction *split_trans;
+ GList *templ_acct_transactions = NULL;
- templ_acct_splits
+ templ_acct_splits
= xaccAccountGetSplitList(sx->template_acct);
-
- for(curr_split_listref = templ_acct_splits;
- curr_split_listref;
- curr_split_listref = curr_split_listref->next)
- {
- curr_split = (Split *) curr_split_listref->data;
- split_trans = xaccSplitGetParent(curr_split);
- if(! (g_list_find(templ_acct_transactions, split_trans)))
+
+ for (curr_split_listref = templ_acct_splits;
+ curr_split_listref;
+ curr_split_listref = curr_split_listref->next)
{
- templ_acct_transactions
- = g_list_prepend(templ_acct_transactions, split_trans);
+ curr_split = (Split *) curr_split_listref->data;
+ split_trans = xaccSplitGetParent(curr_split);
+ if (! (g_list_find(templ_acct_transactions, split_trans)))
+ {
+ templ_acct_transactions
+ = g_list_prepend(templ_acct_transactions, split_trans);
+ }
}
- }
-
- g_list_foreach(templ_acct_transactions,
- sxprivTransMapDelete,
- NULL);
-
- return;
+
+ g_list_foreach(templ_acct_transactions,
+ sxprivTransMapDelete,
+ NULL);
+
+ return;
}
void
sx_set_template_account (SchedXaction *sx, Account *account)
{
- Account *old;
+ Account *old;
- old = sx->template_acct;
- sx->template_acct = account;
- if (old) {
- xaccAccountBeginEdit(old);
- xaccAccountDestroy(old);
- }
+ old = sx->template_acct;
+ sx->template_acct = account;
+ if (old)
+ {
+ xaccAccountBeginEdit(old);
+ xaccAccountDestroy(old);
+ }
}
void
xaccSchedXactionDestroy( SchedXaction *sx )
{
qof_instance_set_destroying( QOF_INSTANCE(sx), TRUE );
- gnc_sx_commit_edit( sx );
+ gnc_sx_commit_edit( sx );
}
static void
xaccSchedXactionFree( SchedXaction *sx )
{
- GList *l;
-
- if ( sx == NULL ) return;
-
- qof_event_gen( &sx->inst, QOF_EVENT_DESTROY , NULL);
-
- if ( sx->name )
- g_free( sx->name );
+ GList *l;
- /*
- * we have to delete the transactions in the
- * template account ourselves
- */
-
- delete_template_trans( sx );
-
- /*
- * xaccAccountDestroy removes the account from
- * its group for us AFAICT
- */
-
- xaccAccountBeginEdit(sx->template_acct);
- xaccAccountDestroy(sx->template_acct);
+ if ( sx == NULL ) return;
- for ( l = sx->deferredList; l; l = l->next ) {
- gnc_sx_destroy_temporal_state( l->data );
- l->data = NULL;
- }
- if ( sx->deferredList ) {
- g_list_free( sx->deferredList );
- sx->deferredList = NULL;
- }
-
- /* qof_instance_release (&sx->inst); */
- g_object_unref( sx );
+ qof_event_gen( &sx->inst, QOF_EVENT_DESTROY , NULL);
+
+ if ( sx->name )
+ g_free( sx->name );
+
+ /*
+ * we have to delete the transactions in the
+ * template account ourselves
+ */
+
+ delete_template_trans( sx );
+
+ /*
+ * xaccAccountDestroy removes the account from
+ * its group for us AFAICT
+ */
+
+ xaccAccountBeginEdit(sx->template_acct);
+ xaccAccountDestroy(sx->template_acct);
+
+ for ( l = sx->deferredList; l; l = l->next )
+ {
+ gnc_sx_destroy_temporal_state( l->data );
+ l->data = NULL;
+ }
+ if ( sx->deferredList )
+ {
+ g_list_free( sx->deferredList );
+ sx->deferredList = NULL;
+ }
+
+ /* qof_instance_release (&sx->inst); */
+ g_object_unref( sx );
}
/* ============================================================ */
@@ -489,7 +495,7 @@
void
gnc_sx_begin_edit (SchedXaction *sx)
{
- qof_begin_edit (&sx->inst);
+ qof_begin_edit (&sx->inst);
}
static void sx_free(QofInstance* inst )
@@ -499,20 +505,20 @@
static void commit_err (QofInstance *inst, QofBackendError errcode)
{
- g_critical("Failed to commit: %d", errcode);
- gnc_engine_signal_commit_error( errcode );
+ g_critical("Failed to commit: %d", errcode);
+ gnc_engine_signal_commit_error( errcode );
}
static void commit_done(QofInstance *inst)
{
- qof_event_gen (inst, QOF_EVENT_MODIFY, NULL);
+ qof_event_gen (inst, QOF_EVENT_MODIFY, NULL);
}
void
gnc_sx_commit_edit (SchedXaction *sx)
{
- if (!qof_commit_edit (QOF_INSTANCE(sx))) return;
- qof_commit_edit_part2 (&sx->inst, commit_err, commit_done, sx_free);
+ if (!qof_commit_edit (QOF_INSTANCE(sx))) return;
+ qof_commit_edit_part2 (&sx->inst, commit_err, commit_done, sx_free);
}
/* ============================================================ */
@@ -520,173 +526,175 @@
GList*
gnc_sx_get_schedule(const SchedXaction *sx)
{
- return sx->schedule;
+ return sx->schedule;
}
void
gnc_sx_set_schedule(SchedXaction *sx, GList *schedule)
{
- g_return_if_fail(sx);
- gnc_sx_begin_edit(sx);
- sx->schedule = schedule;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ g_return_if_fail(sx);
+ gnc_sx_begin_edit(sx);
+ sx->schedule = schedule;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
gchar *
xaccSchedXactionGetName( const SchedXaction *sx )
{
- return sx->name;
+ return sx->name;
}
void
xaccSchedXactionSetName( SchedXaction *sx, const gchar *newName )
{
- g_return_if_fail( newName != NULL );
- gnc_sx_begin_edit(sx);
- if ( sx->name != NULL ) {
- g_free( sx->name );
- sx->name = NULL;
- }
- sx->name = g_strdup( newName );
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ g_return_if_fail( newName != NULL );
+ gnc_sx_begin_edit(sx);
+ if ( sx->name != NULL )
+ {
+ g_free( sx->name );
+ sx->name = NULL;
+ }
+ sx->name = g_strdup( newName );
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
GDate*
xaccSchedXactionGetStartDate( SchedXaction *sx )
{
- return &sx->start_date;
+ return &sx->start_date;
}
void
xaccSchedXactionSetStartDate( SchedXaction *sx, GDate* newStart )
{
- gnc_sx_begin_edit(sx);
- sx->start_date = *newStart;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ gnc_sx_begin_edit(sx);
+ sx->start_date = *newStart;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
gboolean
xaccSchedXactionHasEndDate( const SchedXaction *sx )
{
- return g_date_valid( &sx->end_date );
+ return g_date_valid( &sx->end_date );
}
GDate*
xaccSchedXactionGetEndDate( SchedXaction *sx )
{
- return &sx->end_date;
+ return &sx->end_date;
}
void
xaccSchedXactionSetEndDate( SchedXaction *sx, GDate *newEnd )
{
- if ( g_date_valid( newEnd )
- && g_date_compare( newEnd, &sx->start_date ) < 0 ) {
- /* XXX: I reject the bad data - is this the right
- * thing to do <rgmerk>.
- * This warning is only human readable - the caller
- * doesn't know the call failed. This is bad
- */
- g_critical("New end date before start date");
- return;
- }
+ if ( g_date_valid( newEnd )
+ && g_date_compare( newEnd, &sx->start_date ) < 0 )
+ {
+ /* XXX: I reject the bad data - is this the right
+ * thing to do <rgmerk>.
+ * This warning is only human readable - the caller
+ * doesn't know the call failed. This is bad
+ */
+ g_critical("New end date before start date");
+ return;
+ }
- gnc_sx_begin_edit(sx);
- sx->end_date = *newEnd;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ gnc_sx_begin_edit(sx);
+ sx->end_date = *newEnd;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
GDate*
xaccSchedXactionGetLastOccurDate( SchedXaction *sx )
{
- return &sx->last_date;
+ return &sx->last_date;
}
void
xaccSchedXactionSetLastOccurDate(SchedXaction *sx, GDate* new_last_occur)
{
- if (g_date_valid(&sx->last_date)
- && g_date_compare(&sx->last_date, new_last_occur) == 0)
- return;
- gnc_sx_begin_edit(sx);
- sx->last_date = *new_last_occur;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ if (g_date_valid(&sx->last_date)
+ && g_date_compare(&sx->last_date, new_last_occur) == 0)
+ return;
+ gnc_sx_begin_edit(sx);
+ sx->last_date = *new_last_occur;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
gboolean
xaccSchedXactionHasOccurDef( const SchedXaction *sx )
{
- return ( xaccSchedXactionGetNumOccur( sx ) != 0 );
+ return ( xaccSchedXactionGetNumOccur( sx ) != 0 );
}
gint
xaccSchedXactionGetNumOccur( const SchedXaction *sx )
{
- return sx->num_occurances_total;
+ return sx->num_occurances_total;
}
void
xaccSchedXactionSetNumOccur(SchedXaction *sx, gint new_num)
{
- if (sx->num_occurances_total == new_num)
- return;
- gnc_sx_begin_edit(sx);
- sx->num_occurances_remain = sx->num_occurances_total = new_num;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ if (sx->num_occurances_total == new_num)
+ return;
+ gnc_sx_begin_edit(sx);
+ sx->num_occurances_remain = sx->num_occurances_total = new_num;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
gint
xaccSchedXactionGetRemOccur( const SchedXaction *sx )
{
- return sx->num_occurances_remain;
+ return sx->num_occurances_remain;
}
void
xaccSchedXactionSetRemOccur(SchedXaction *sx, gint num_remain)
{
- /* FIXME This condition can be tightened up */
- if (num_remain > sx->num_occurances_total)
- {
- g_warning("number remaining [%d] > total occurrences [%d]",
- num_remain, sx->num_occurances_total);
- }
- else
- {
- if (num_remain == sx->num_occurances_remain)
- return;
- gnc_sx_begin_edit(sx);
- sx->num_occurances_remain = num_remain;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
- }
+ /* FIXME This condition can be tightened up */
+ if (num_remain > sx->num_occurances_total)
+ {
+ g_warning("number remaining [%d] > total occurrences [%d]",
+ num_remain, sx->num_occurances_total);
+ }
+ else
+ {
+ if (num_remain == sx->num_occurances_remain)
+ return;
+ gnc_sx_begin_edit(sx);
+ sx->num_occurances_remain = num_remain;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
+ }
}
KvpValue *
xaccSchedXactionGetSlot( const SchedXaction *sx, const char *slot )
{
- if (!sx) return NULL;
+ if (!sx) return NULL;
- return kvp_frame_get_slot(sx->inst.kvp_data, slot);
+ return kvp_frame_get_slot(sx->inst.kvp_data, slot);
}
void
-xaccSchedXactionSetSlot( SchedXaction *sx,
- const char *slot,
- const KvpValue *value )
+xaccSchedXactionSetSlot( SchedXaction *sx,
+ const char *slot,
+ const KvpValue *value )
{
- if (!sx) return;
+ if (!sx) return;
- gnc_sx_begin_edit(sx);
- kvp_frame_set_slot( sx->inst.kvp_data, slot, value );
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ gnc_sx_begin_edit(sx);
+ kvp_frame_set_slot( sx->inst.kvp_data, slot, value );
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
gboolean
@@ -698,10 +706,10 @@
void
xaccSchedXactionSetEnabled( SchedXaction *sx, gboolean newEnabled)
{
- gnc_sx_begin_edit(sx);
- sx->enabled = newEnabled;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ gnc_sx_begin_edit(sx);
+ sx->enabled = newEnabled;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
void
@@ -709,11 +717,11 @@
gboolean *outAutoCreate,
gboolean *outNotify )
{
- if (outAutoCreate != NULL)
- *outAutoCreate = sx->autoCreateOption;
- if (outNotify != NULL)
- *outNotify = sx->autoCreateNotify;
- return;
+ if (outAutoCreate != NULL)
+ *outAutoCreate = sx->autoCreateOption;
+ if (outNotify != NULL)
+ *outNotify = sx->autoCreateNotify;
+ return;
}
void
@@ -721,107 +729,122 @@
gboolean newAutoCreate,
gboolean newNotify )
{
-
- gnc_sx_begin_edit(sx);
- sx->autoCreateOption = newAutoCreate;
- sx->autoCreateNotify = newNotify;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
- return;
+
+ gnc_sx_begin_edit(sx);
+ sx->autoCreateOption = newAutoCreate;
+ sx->autoCreateNotify = newNotify;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
+ return;
}
gint
xaccSchedXactionGetAdvanceCreation( const SchedXaction *sx )
{
- return sx->advanceCreateDays;
+ return sx->advanceCreateDays;
}
void
xaccSchedXactionSetAdvanceCreation( SchedXaction *sx, gint createDays )
{
- gnc_sx_begin_edit(sx);
- sx->advanceCreateDays = createDays;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ gnc_sx_begin_edit(sx);
+ sx->advanceCreateDays = createDays;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
gint
xaccSchedXactionGetAdvanceReminder( const SchedXaction *sx )
{
- return sx->advanceRemindDays;
+ return sx->advanceRemindDays;
}
void
xaccSchedXactionSetAdvanceReminder( SchedXaction *sx, gint reminderDays )
{
- gnc_sx_begin_edit(sx);
- sx->advanceRemindDays = reminderDays;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ gnc_sx_begin_edit(sx);
+ sx->advanceRemindDays = reminderDays;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
GDate
xaccSchedXactionGetNextInstance( SchedXaction *sx, void *stateData )
{
- GDate last_occur, next_occur, tmpDate;
+ GDate last_occur, next_occur, tmpDate;
- g_date_clear( &last_occur, 1 );
- g_date_clear( &next_occur, 1 );
- g_date_clear( &tmpDate, 1 );
+ g_date_clear( &last_occur, 1 );
+ g_date_clear( &next_occur, 1 );
+ g_date_clear( &tmpDate, 1 );
- if ( g_date_valid( &sx->last_date ) ) {
- last_occur = sx->last_date;
- }
+ if ( g_date_valid( &sx->last_date ) )
+ {
+ last_occur = sx->last_date;
+ }
- if ( stateData != NULL ) {
- temporalStateData *tsd = (temporalStateData*)stateData;
- last_occur = tsd->last_date;
- }
+ if ( stateData != NULL )
+ {
+ temporalStateData *tsd = (temporalStateData*)stateData;
+ last_occur = tsd->last_date;
+ }
- if ( g_date_valid( &sx->start_date ) ) {
- if ( g_date_valid(&last_occur) ) {
- last_occur =
- ( g_date_compare( &last_occur,
- &sx->start_date ) > 0 ?
- last_occur : sx->start_date );
- } else {
- /* Think about this for a second, and you realize that if the
- * start date is _today_, we need a last-occur date such that
- * the 'next instance' is after that date, and equal to the
- * start date... one day should be good.
- *
- * This only holds for the first instance [read: if the
- * last[-occur]_date is invalid] */
- last_occur = sx->start_date;
- g_date_subtract_days( &last_occur, 1 );
- }
- }
+ if ( g_date_valid( &sx->start_date ) )
+ {
+ if ( g_date_valid(&last_occur) )
+ {
+ last_occur =
+ ( g_date_compare( &last_occur,
+ &sx->start_date ) > 0 ?
+ last_occur : sx->start_date );
+ }
+ else
+ {
+ /* Think about this for a second, and you realize that if the
+ * start date is _today_, we need a last-occur date such that
+ * the 'next instance' is after that date, and equal to the
+ * start date... one day should be good.
+ *
+ * This only holds for the first instance [read: if the
+ * last[-occur]_date is invalid] */
+ last_occur = sx->start_date;
+ g_date_subtract_days( &last_occur, 1 );
+ }
+ }
- recurrenceListNextInstance(sx->schedule, &last_occur, &next_occur);
+ recurrenceListNextInstance(sx->schedule, &last_occur, &next_occur);
- /* out-of-bounds check */
- if ( xaccSchedXactionHasEndDate( sx ) ) {
- GDate *end_date = xaccSchedXactionGetEndDate( sx );
- if ( g_date_compare( &next_occur, end_date ) > 0 ) {
- g_debug("next_occur past end date");
- g_date_clear( &next_occur, 1 );
- }
- } else if ( xaccSchedXactionHasOccurDef( sx ) ) {
- if ( stateData ) {
- temporalStateData *tsd = (temporalStateData*)stateData;
- if ( tsd->num_occur_rem == 0 ) {
- g_debug("no more occurances remain");
+ /* out-of-bounds check */
+ if ( xaccSchedXactionHasEndDate( sx ) )
+ {
+ GDate *end_date = xaccSchedXactionGetEndDate( sx );
+ if ( g_date_compare( &next_occur, end_date ) > 0 )
+ {
+ g_debug("next_occur past end date");
g_date_clear( &next_occur, 1 );
- }
- } else {
- if ( sx->num_occurances_remain == 0 ) {
- g_date_clear( &next_occur, 1 );
- }
- }
- }
+ }
+ }
+ else if ( xaccSchedXactionHasOccurDef( sx ) )
+ {
+ if ( stateData )
+ {
+ temporalStateData *tsd = (temporalStateData*)stateData;
+ if ( tsd->num_occur_rem == 0 )
+ {
+ g_debug("no more occurances remain");
+ g_date_clear( &next_occur, 1 );
+ }
+ }
+ else
+ {
+ if ( sx->num_occurances_remain == 0 )
+ {
+ g_date_clear( &next_occur, 1 );
+ }
+ }
+ }
- return next_occur;
+ return next_occur;
}
GDate
@@ -829,259 +852,275 @@
GDate *date,
void *stateData )
{
- GDate prev_occur, next_occur;
+ GDate prev_occur, next_occur;
- g_date_clear( &prev_occur, 1 );
- if ( date ) {
- prev_occur = *date;
- }
+ g_date_clear( &prev_occur, 1 );
+ if ( date )
+ {
+ prev_occur = *date;
+ }
- if ( stateData != NULL ) {
- temporalStateData *tsd = (temporalStateData*)stateData;
- prev_occur = tsd->last_date;
- }
+ if ( stateData != NULL )
+ {
+ temporalStateData *tsd = (temporalStateData*)stateData;
+ prev_occur = tsd->last_date;
+ }
- if ( ! g_date_valid( &prev_occur ) ) {
- /* We must be at the beginning. */
- prev_occur = sx->start_date;
- g_date_subtract_days( &prev_occur, 1 );
- }
+ if ( ! g_date_valid( &prev_occur ) )
+ {
+ /* We must be at the beginning. */
+ prev_occur = sx->start_date;
+ g_date_subtract_days( &prev_occur, 1 );
+ }
- recurrenceListNextInstance(sx->schedule, &prev_occur, &next_occur);
+ recurrenceListNextInstance(sx->schedule, &prev_occur, &next_occur);
- if ( xaccSchedXactionHasEndDate( sx ) ) {
- GDate *end_date;
+ if ( xaccSchedXactionHasEndDate( sx ) )
+ {
+ GDate *end_date;
- end_date = xaccSchedXactionGetEndDate( sx );
- if ( g_date_compare( &next_occur, end_date ) > 0 ) {
- g_date_clear( &next_occur, 1 );
- }
- } else if ( xaccSchedXactionHasOccurDef( sx ) ) {
- if ( stateData ) {
- temporalStateData *tsd = (temporalStateData*)stateData;
- if ( tsd->num_occur_rem == 0 ) {
+ end_date = xaccSchedXactionGetEndDate( sx );
+ if ( g_date_compare( &next_occur, end_date ) > 0 )
+ {
g_date_clear( &next_occur, 1 );
- }
- } else {
- if ( sx->num_occurances_remain == 0 ) {
- g_date_clear( &next_occur, 1 );
- }
- }
- }
- return next_occur;
+ }
+ }
+ else if ( xaccSchedXactionHasOccurDef( sx ) )
+ {
+ if ( stateData )
+ {
+ temporalStateData *tsd = (temporalStateData*)stateData;
+ if ( tsd->num_occur_rem == 0 )
+ {
+ g_date_clear( &next_occur, 1 );
+ }
+ }
+ else
+ {
+ if ( sx->num_occurances_remain == 0 )
+ {
+ g_date_clear( &next_occur, 1 );
+ }
+ }
+ }
+ return next_occur;
}
gint
gnc_sx_get_instance_count( const SchedXaction *sx, void *stateData )
{
- gint toRet = -1;
- temporalStateData *tsd;
+ gint toRet = -1;
+ temporalStateData *tsd;
- if ( stateData ) {
- tsd = (temporalStateData*)stateData;
- toRet = tsd->num_inst;
- } else {
- toRet = sx->instance_num;
- }
+ if ( stateData )
+ {
+ tsd = (temporalStateData*)stateData;
+ toRet = tsd->num_inst;
+ }
+ else
+ {
+ toRet = sx->instance_num;
+ }
- return toRet;
+ return toRet;
}
void
gnc_sx_set_instance_count(SchedXaction *sx, gint instance_num)
{
- g_return_if_fail(sx);
- if (sx->instance_num == instance_num)
- return;
- sx->instance_num = instance_num;
+ g_return_if_fail(sx);
+ if (sx->instance_num == instance_num)
+ return;
+ sx->instance_num = instance_num;
}
GList *
xaccSchedXactionGetSplits( const SchedXaction *sx )
{
- g_return_val_if_fail( sx, NULL );
- return xaccAccountGetSplitList(sx->template_acct);
+ g_return_val_if_fail( sx, NULL );
+ return xaccAccountGetSplitList(sx->template_acct);
}
static Split *
pack_split_info (TTSplitInfo *s_info, Account *parent_acct,
- Transaction *parent_trans, QofBook *book)
+ Transaction *parent_trans, QofBook *book)
{
- Split *split;
- KvpFrame *split_frame;
- KvpValue *tmp_value;
- const GUID *acc_guid;
-
- split = xaccMallocSplit(book);
+ Split *split;
+ KvpFrame *split_frame;
+ KvpValue *tmp_value;
+ const GUID *acc_guid;
- xaccSplitSetMemo(split,
- gnc_ttsplitinfo_get_memo(s_info));
+ split = xaccMallocSplit(book);
- xaccSplitSetAction(split,
- gnc_ttsplitinfo_get_action(s_info));
-
+ xaccSplitSetMemo(split,
+ gnc_ttsplitinfo_get_memo(s_info));
- xaccAccountInsertSplit(parent_acct,
- split);
+ xaccSplitSetAction(split,
+ gnc_ttsplitinfo_get_action(s_info));
- split_frame = xaccSplitGetSlots(split);
-
- tmp_value
+
+ xaccAccountInsertSplit(parent_acct,
+ split);
+
+ split_frame = xaccSplitGetSlots(split);
+
+ tmp_value
= kvp_value_new_string(gnc_ttsplitinfo_get_credit_formula(s_info));
- kvp_frame_set_slot_path(split_frame,
- tmp_value,
- GNC_SX_ID,
- GNC_SX_CREDIT_FORMULA,
- NULL);
- kvp_value_delete(tmp_value);
-
- tmp_value
+ kvp_frame_set_slot_path(split_frame,
+ tmp_value,
+ GNC_SX_ID,
+ GNC_SX_CREDIT_FORMULA,
+ NULL);
+ kvp_value_delete(tmp_value);
+
+ tmp_value
= kvp_value_new_string(gnc_ttsplitinfo_get_debit_formula(s_info));
-
- kvp_frame_set_slot_path(split_frame,
- tmp_value,
- GNC_SX_ID,
- GNC_SX_DEBIT_FORMULA,
- NULL);
- kvp_value_delete(tmp_value);
+ kvp_frame_set_slot_path(split_frame,
+ tmp_value,
+ GNC_SX_ID,
+ GNC_SX_DEBIT_FORMULA,
+ NULL);
- acc_guid = qof_entity_get_guid(QOF_INSTANCE(gnc_ttsplitinfo_get_account(s_info)));
+ kvp_value_delete(tmp_value);
- tmp_value = kvp_value_new_guid(acc_guid);
+ acc_guid = qof_entity_get_guid(QOF_INSTANCE(gnc_ttsplitinfo_get_account(s_info)));
- kvp_frame_set_slot_path(split_frame,
- tmp_value,
- GNC_SX_ID,
- GNC_SX_ACCOUNT,
- NULL);
+ tmp_value = kvp_value_new_guid(acc_guid);
- kvp_value_delete(tmp_value);
+ kvp_frame_set_slot_path(split_frame,
+ tmp_value,
+ GNC_SX_ID,
+ GNC_SX_ACCOUNT,
+ NULL);
- return split;
+ kvp_value_delete(tmp_value);
+
+ return split;
}
-
+
void
xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list,
- QofBook *book)
+ QofBook *book)
{
- Transaction *new_trans;
- TTInfo *tti;
- TTSplitInfo *s_info;
- Split *new_split;
- GList *split_list;
+ Transaction *new_trans;
+ TTInfo *tti;
+ TTSplitInfo *s_info;
+ Split *new_split;
+ GList *split_list;
- g_return_if_fail (book);
+ g_return_if_fail (book);
- /* delete any old transactions, if there are any */
- delete_template_trans( sx );
+ /* delete any old transactions, if there are any */
+ delete_template_trans( sx );
- for(;t_t_list != NULL; t_t_list = t_t_list->next)
- {
- tti = t_t_list->data;
+ for (; t_t_list != NULL; t_t_list = t_t_list->next)
+ {
+ tti = t_t_list->data;
- new_trans = xaccMallocTransaction(book);
+ new_trans = xaccMallocTransaction(book);
- xaccTransBeginEdit(new_trans);
+ xaccTransBeginEdit(new_trans);
- xaccTransSetDescription(new_trans,
- gnc_ttinfo_get_description(tti));
+ xaccTransSetDescription(new_trans,
+ gnc_ttinfo_get_description(tti));
- xaccTransSetDatePostedSecs(new_trans, time(NULL));
+ xaccTransSetDatePostedSecs(new_trans, time(NULL));
- xaccTransSetNum(new_trans,
- gnc_ttinfo_get_num(tti));
- xaccTransSetCurrency( new_trans,
- gnc_ttinfo_get_currency(tti) );
+ xaccTransSetNum(new_trans,
+ gnc_ttinfo_get_num(tti));
+ xaccTransSetCurrency( new_trans,
+ gnc_ttinfo_get_currency(tti) );
- for(split_list = gnc_ttinfo_get_template_splits(tti);
- split_list;
- split_list = split_list->next)
- {
- s_info = split_list->data;
- new_split = pack_split_info(s_info, sx->template_acct,
- new_trans, book);
- xaccTransAppendSplit(new_trans, new_split);
+ for (split_list = gnc_ttinfo_get_template_splits(tti);
+ split_list;
+ split_list = split_list->next)
+ {
+ s_info = split_list->data;
+ new_split = pack_split_info(s_info, sx->template_acct,
+ new_trans, book);
+ xaccTransAppendSplit(new_trans, new_split);
+ }
+ xaccTransCommitEdit(new_trans);
}
- xaccTransCommitEdit(new_trans);
- }
}
void*
gnc_sx_create_temporal_state( SchedXaction *sx )
{
- temporalStateData *toRet =
- g_new0( temporalStateData, 1 );
- toRet->last_date = sx->last_date;
- toRet->num_occur_rem = sx->num_occurances_remain;
- toRet->num_inst = sx->instance_num;
- return (void*)toRet;
+ temporalStateData *toRet =
+ g_new0( temporalStateData, 1 );
+ toRet->last_date = sx->last_date;
+ toRet->num_occur_rem = sx->num_occurances_remain;
+ toRet->num_inst = sx->instance_num;
+ return (void*)toRet;
}
void
gnc_sx_incr_temporal_state( SchedXaction *sx, void *stateData )
{
- GDate unused;
- temporalStateData *tsd = (temporalStateData*)stateData;
+ GDate unused;
+ temporalStateData *tsd = (temporalStateData*)stateData;
- g_date_clear( &unused, 1 );
- tsd->last_date =
- xaccSchedXactionGetInstanceAfter( sx,
- &unused,
- stateData );
- if ( xaccSchedXactionHasOccurDef( sx ) ) {
- tsd->num_occur_rem -= 1;
- }
- tsd->num_inst += 1;
+ g_date_clear( &unused, 1 );
+ tsd->last_date =
+ xaccSchedXactionGetInstanceAfter( sx,
+ &unused,
+ stateData );
+ if ( xaccSchedXactionHasOccurDef( sx ) )
+ {
+ tsd->num_occur_rem -= 1;
+ }
+ tsd->num_inst += 1;
}
void
gnc_sx_revert_to_temporal_state( SchedXaction *sx, void *stateData )
{
- temporalStateData *tsd = (temporalStateData*)stateData;
- gnc_sx_begin_edit(sx);
- sx->last_date = tsd->last_date;
- sx->num_occurances_remain = tsd->num_occur_rem;
- sx->instance_num = tsd->num_inst;
- qof_instance_set_dirty(&sx->inst);
- gnc_sx_commit_edit(sx);
+ temporalStateData *tsd = (temporalStateData*)stateData;
+ gnc_sx_begin_edit(sx);
+ sx->last_date = tsd->last_date;
+ sx->num_occurances_remain = tsd->num_occur_rem;
+ sx->instance_num = tsd->num_inst;
+ qof_instance_set_dirty(&sx->inst);
+ gnc_sx_commit_edit(sx);
}
void
gnc_sx_destroy_temporal_state( void *stateData )
{
- g_free( (temporalStateData*)stateData );
+ g_free( (temporalStateData*)stateData );
}
void*
gnc_sx_clone_temporal_state( void *stateData )
{
- temporalStateData *toRet, *tsd;
- tsd = (temporalStateData*)stateData;
- toRet = g_memdup( tsd, sizeof( temporalStateData ) );
- return (void*)toRet;
+ temporalStateData *toRet, *tsd;
+ tsd = (temporalStateData*)stateData;
+ toRet = g_memdup( tsd, sizeof( temporalStateData ) );
+ return (void*)toRet;
}
static
gint
_temporal_state_data_cmp( gconstpointer a, gconstpointer b )
{
- temporalStateData *tsd_a, *tsd_b;
- tsd_a = (temporalStateData*)a;
- tsd_b = (temporalStateData*)b;
+ temporalStateData *tsd_a, *tsd_b;
+ tsd_a = (temporalStateData*)a;
+ tsd_b = (temporalStateData*)b;
- if ( !tsd_a && !tsd_b )
- return 0;
- if (tsd_a == tsd_b)
- return 0;
- if ( !tsd_a )
- return 1;
- if ( !tsd_b )
- return -1;
- return g_date_compare( &tsd_a->last_date,
- &tsd_b->last_date );
+ if ( !tsd_a && !tsd_b )
+ return 0;
+ if (tsd_a == tsd_b)
+ return 0;
+ if ( !tsd_a )
+ return 1;
+ if ( !tsd_b )
+ return -1;
+ return g_date_compare( &tsd_a->last_date,
+ &tsd_b->last_date );
}
/**
@@ -1092,8 +1131,8 @@
gnc_sx_add_defer_instance( SchedXaction *sx, void *deferStateData )
{
sx->deferredList = g_list_insert_sorted( sx->deferredList,
- deferStateData,
- _temporal_state_data_cmp );
+ deferStateData,
+ _temporal_state_data_cmp );
}
/**
@@ -1106,8 +1145,9 @@
GList *found_by_value;
found_by_value = g_list_find_custom(
- sx->deferredList, deferStateData, _temporal_state_data_cmp);
- if (found_by_value == NULL) {
+ sx->deferredList, deferStateData, _temporal_state_data_cmp);
+ if (found_by_value == NULL)
+ {
g_warning("unable to find deferred instance");
return;
}
@@ -1125,7 +1165,7 @@
GList*
gnc_sx_get_defer_instances( SchedXaction *sx )
{
- return sx->deferredList;
+ return sx->deferredList;
}
#ifdef _MSC_VER
@@ -1135,39 +1175,50 @@
#else
# define DI(x) x
#endif
-static QofObject SXDesc =
+static QofObject SXDesc =
{
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_SX_ID,
- DI(.type_label =) "Scheduled Transaction",
- DI(.create =) (gpointer)xaccSchedXactionMalloc,
- DI(.book_begin =) NULL,
- DI(.book_end =) NULL,
- DI(.is_dirty =) qof_collection_is_dirty,
- DI(.mark_clean =) qof_collection_mark_clean,
- DI(.foreach =) qof_collection_foreach,
- DI(.printable =) NULL,
- DI(.version_cmp =) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_SX_ID,
+ DI(.type_label = ) "Scheduled Transaction",
+ DI(.create = ) (gpointer)xaccSchedXactionMalloc,
+ DI(.book_begin = ) NULL,
+ DI(.book_end = ) NULL,
+ DI(.is_dirty = ) qof_collection_is_dirty,
+ DI(.mark_clean = ) qof_collection_mark_clean,
+ DI(.foreach = ) qof_collection_foreach,
+ DI(.printable = ) NULL,
+ DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
};
gboolean
SXRegister(void)
{
- static QofParam params[] = {
- { GNC_SX_NAME, QOF_TYPE_STRING, (QofAccessFunc)xaccSchedXactionGetName,
- (QofSetterFunc)xaccSchedXactionSetName },
- { GNC_SX_START_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetStartDate,
- (QofSetterFunc)xaccSchedXactionSetStartDate },
- { GNC_SX_LAST_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetLastOccurDate,
- (QofSetterFunc)xaccSchedXactionSetLastOccurDate },
- { GNC_SX_NUM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetNumOccur,
- (QofSetterFunc)xaccSchedXactionSetNumOccur },
- { GNC_SX_REM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetRemOccur,
- (QofSetterFunc)xaccSchedXactionSetRemOccur },
- { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
- { NULL },
- };
- qof_class_register(GNC_SX_ID, NULL, params);
- return qof_object_register(&SXDesc);
+ static QofParam params[] =
+ {
+ {
+ GNC_SX_NAME, QOF_TYPE_STRING, (QofAccessFunc)xaccSchedXactionGetName,
+ (QofSetterFunc)xaccSchedXactionSetName
+ },
+ {
+ GNC_SX_START_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetStartDate,
+ (QofSetterFunc)xaccSchedXactionSetStartDate
+ },
+ {
+ GNC_SX_LAST_DATE, QOF_TYPE_DATE, (QofAccessFunc)xaccSchedXactionGetLastOccurDate,
+ (QofSetterFunc)xaccSchedXactionSetLastOccurDate
+ },
+ {
+ GNC_SX_NUM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetNumOccur,
+ (QofSetterFunc)xaccSchedXactionSetNumOccur
+ },
+ {
+ GNC_SX_REM_OCCUR, QOF_TYPE_INT64, (QofAccessFunc)xaccSchedXactionGetRemOccur,
+ (QofSetterFunc)xaccSchedXactionSetRemOccur
+ },
+ { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
+ { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
+ { NULL },
+ };
+ qof_class_register(GNC_SX_ID, NULL, params);
+ return qof_object_register(&SXDesc);
}
Modified: gnucash/trunk/src/engine/Scrub.c
===================================================================
--- gnucash/trunk/src/engine/Scrub.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Scrub.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -25,8 +25,8 @@
* Scrub.c
*
* FUNCTION:
- * Provides a set of functions and utilities for scrubbing clean
- * single-entry accounts so that they can be promoted into
+ * Provides a set of functions and utilities for scrubbing clean
+ * single-entry accounts so that they can be promoted into
* self-consistent, clean double-entry accounts.
*
* HISTORY:
@@ -61,91 +61,91 @@
void
xaccAccountTreeScrubOrphans (Account *acc)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountScrubOrphans (acc);
- gnc_account_foreach_descendant(acc,
- (AccountCb)xaccAccountScrubOrphans, NULL);
+ xaccAccountScrubOrphans (acc);
+ gnc_account_foreach_descendant(acc,
+ (AccountCb)xaccAccountScrubOrphans, NULL);
}
static void
TransScrubOrphansFast (Transaction *trans, Account *root)
{
- GList *node;
- gchar *accname;
+ GList *node;
+ gchar *accname;
- if (!trans) return;
- g_return_if_fail (root);
+ if (!trans) return;
+ g_return_if_fail (root);
- for (node = trans->splits; node; node = node->next)
- {
- Split *split = node->data;
- Account *orph;
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *split = node->data;
+ Account *orph;
- if (split->acc) continue;
+ if (split->acc) continue;
- DEBUG ("Found an orphan \n");
+ DEBUG ("Found an orphan \n");
- accname = g_strconcat (_("Orphan"), "-",
- gnc_commodity_get_mnemonic (trans->common_currency),
- NULL);
- orph = xaccScrubUtilityGetOrMakeAccount (root, trans->common_currency,
- accname, ACCT_TYPE_BANK, FALSE);
- g_free (accname);
- if (!orph) continue;
+ accname = g_strconcat (_("Orphan"), "-",
+ gnc_commodity_get_mnemonic (trans->common_currency),
+ NULL);
+ orph = xaccScrubUtilityGetOrMakeAccount (root, trans->common_currency,
+ accname, ACCT_TYPE_BANK, FALSE);
+ g_free (accname);
+ if (!orph) continue;
- xaccSplitSetAccount(split, orph);
- }
+ xaccSplitSetAccount(split, orph);
+ }
}
void
xaccAccountScrubOrphans (Account *acc)
{
- GList *node;
- const char *str;
+ GList *node;
+ const char *str;
- if (!acc) return;
+ if (!acc) return;
- str = xaccAccountGetName (acc);
- str = str ? str : "(null)";
- PINFO ("Looking for orphans in account %s \n", str);
+ str = xaccAccountGetName (acc);
+ str = str ? str : "(null)";
+ PINFO ("Looking for orphans in account %s \n", str);
- for (node = xaccAccountGetSplitList(acc); node; node = node->next)
- {
- Split *split = node->data;
+ for (node = xaccAccountGetSplitList(acc); node; node = node->next)
+ {
+ Split *split = node->data;
- TransScrubOrphansFast (xaccSplitGetParent (split),
- gnc_account_get_root (acc));
- }
+ TransScrubOrphansFast (xaccSplitGetParent (split),
+ gnc_account_get_root (acc));
+ }
}
void
xaccTransScrubOrphans (Transaction *trans)
{
- SplitList *node;
- QofBook *book = NULL;
- Account *root = NULL;
- for (node = trans->splits; node; node = node->next)
- {
- Split *split = node->data;
+ SplitList *node;
+ QofBook *book = NULL;
+ Account *root = NULL;
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *split = node->data;
- if (split->acc)
- {
- TransScrubOrphansFast (trans, gnc_account_get_root(split->acc));
- return;
+ if (split->acc)
+ {
+ TransScrubOrphansFast (trans, gnc_account_get_root(split->acc));
+ return;
+ }
}
- }
- /* If we got to here, then *none* of the splits belonged to an
- * account. Not a happy situation. We should dig an account
- * out of the book the transaction belongs to.
- * XXX we should probably *always* to this, instead of the above loop!
- */
- PINFO ("Free Floating Transaction!");
- book = xaccTransGetBook (trans);
- root = gnc_book_get_root_account (book);
- TransScrubOrphansFast (trans, root);
+ /* If we got to here, then *none* of the splits belonged to an
+ * account. Not a happy situation. We should dig an account
+ * out of the book the transaction belongs to.
+ * XXX we should probably *always* to this, instead of the above loop!
+ */
+ PINFO ("Free Floating Transaction!");
+ book = xaccTransGetBook (trans);
+ root = gnc_book_get_root_account (book);
+ TransScrubOrphansFast (trans, root);
}
/* ================================================================ */
@@ -153,117 +153,118 @@
void
xaccAccountTreeScrubSplits (Account *account)
{
- if (!account) return;
+ if (!account) return;
- xaccAccountScrubSplits (account);
- gnc_account_foreach_descendant(account,
- (AccountCb)xaccAccountScrubSplits, NULL);
+ xaccAccountScrubSplits (account);
+ gnc_account_foreach_descendant(account,
+ (AccountCb)xaccAccountScrubSplits, NULL);
}
void
xaccAccountScrubSplits (Account *account)
{
- GList *node;
+ GList *node;
- for (node = xaccAccountGetSplitList (account); node; node = node->next)
- xaccSplitScrub (node->data);
+ for (node = xaccAccountGetSplitList (account); node; node = node->next)
+ xaccSplitScrub (node->data);
}
void
xaccSplitScrub (Split *split)
{
- Account *account;
- Transaction *trans;
- gnc_numeric value, amount;
- gnc_commodity *currency, *acc_commodity;
- int scu;
+ Account *account;
+ Transaction *trans;
+ gnc_numeric value, amount;
+ gnc_commodity *currency, *acc_commodity;
+ int scu;
- if (!split) return;
- ENTER ("(split=%p)", split);
+ if (!split) return;
+ ENTER ("(split=%p)", split);
- trans = xaccSplitGetParent (split);
- if (!trans) {
- LEAVE("no trans");
- return;
- }
+ trans = xaccSplitGetParent (split);
+ if (!trans)
+ {
+ LEAVE("no trans");
+ return;
+ }
- account = xaccSplitGetAccount (split);
-
- /* If there's no account, this split is an orphan.
- * We need to fix that first, before proceeding.
- */
- if (!account)
- {
- xaccTransScrubOrphans (trans);
account = xaccSplitGetAccount (split);
- }
- /* Grrr... the register gnc_split_register_load() line 203 of
- * src/register/ledger-core/split-register-load.c will create
- * free-floating bogus transactions. Ignore these for now ...
- */
- if (!account)
- {
- PINFO ("Free Floating Transaction!");
- LEAVE ("no account");
- return;
- }
+ /* If there's no account, this split is an orphan.
+ * We need to fix that first, before proceeding.
+ */
+ if (!account)
+ {
+ xaccTransScrubOrphans (trans);
+ account = xaccSplitGetAccount (split);
+ }
- /* Split amounts and values should be valid numbers */
- value = xaccSplitGetValue (split);
- if (gnc_numeric_check (value))
- {
- value = gnc_numeric_zero();
- xaccSplitSetValue (split, value);
- }
+ /* Grrr... the register gnc_split_register_load() line 203 of
+ * src/register/ledger-core/split-register-load.c will create
+ * free-floating bogus transactions. Ignore these for now ...
+ */
+ if (!account)
+ {
+ PINFO ("Free Floating Transaction!");
+ LEAVE ("no account");
+ return;
+ }
- amount = xaccSplitGetAmount (split);
- if (gnc_numeric_check (amount))
- {
- amount = gnc_numeric_zero();
- xaccSplitSetAmount (split, amount);
- }
+ /* Split amounts and values should be valid numbers */
+ value = xaccSplitGetValue (split);
+ if (gnc_numeric_check (value))
+ {
+ value = gnc_numeric_zero();
+ xaccSplitSetValue (split, value);
+ }
- currency = xaccTransGetCurrency (trans);
+ amount = xaccSplitGetAmount (split);
+ if (gnc_numeric_check (amount))
+ {
+ amount = gnc_numeric_zero();
+ xaccSplitSetAmount (split, amount);
+ }
- /* If the account doesn't have a commodity,
- * we should attempt to fix that first.
- */
- acc_commodity = xaccAccountGetCommodity(account);
- if (!acc_commodity)
- {
- xaccAccountScrubCommodity (account);
- }
- if (!acc_commodity || !gnc_commodity_equiv(acc_commodity, currency))
- {
- LEAVE ("(split=%p) inequiv currency", split);
- return;
- }
+ currency = xaccTransGetCurrency (trans);
- scu = MIN (xaccAccountGetCommoditySCU (account),
- gnc_commodity_get_fraction (currency));
+ /* If the account doesn't have a commodity,
+ * we should attempt to fix that first.
+ */
+ acc_commodity = xaccAccountGetCommodity(account);
+ if (!acc_commodity)
+ {
+ xaccAccountScrubCommodity (account);
+ }
+ if (!acc_commodity || !gnc_commodity_equiv(acc_commodity, currency))
+ {
+ LEAVE ("(split=%p) inequiv currency", split);
+ return;
+ }
- if (gnc_numeric_same (amount, value, scu, GNC_HOW_RND_ROUND))
- {
- LEAVE("(split=%p) different values", split);
- return;
- }
+ scu = MIN (xaccAccountGetCommoditySCU (account),
+ gnc_commodity_get_fraction (currency));
- /*
- * This will be hit every time you answer yes to the dialog "The
- * current transaction has changed. Would you like to record it.
- */
- PINFO ("Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\""
- " old amount %s %s, new amount %s",
- trans->description, split->memo,
- gnc_num_dbg_to_string (xaccSplitGetAmount(split)),
- gnc_commodity_get_mnemonic (currency),
- gnc_num_dbg_to_string (xaccSplitGetValue(split)));
+ if (gnc_numeric_same (amount, value, scu, GNC_HOW_RND_ROUND))
+ {
+ LEAVE("(split=%p) different values", split);
+ return;
+ }
- xaccTransBeginEdit (trans);
- xaccSplitSetAmount (split, value);
- xaccTransCommitEdit (trans);
- LEAVE ("(split=%p)", split);
+ /*
+ * This will be hit every time you answer yes to the dialog "The
+ * current transaction has changed. Would you like to record it.
+ */
+ PINFO ("Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\""
+ " old amount %s %s, new amount %s",
+ trans->description, split->memo,
+ gnc_num_dbg_to_string (xaccSplitGetAmount(split)),
+ gnc_commodity_get_mnemonic (currency),
+ gnc_num_dbg_to_string (xaccSplitGetValue(split)));
+
+ xaccTransBeginEdit (trans);
+ xaccSplitSetAmount (split, value);
+ xaccTransCommitEdit (trans);
+ LEAVE ("(split=%p)", split);
}
/* ================================================================ */
@@ -271,543 +272,566 @@
void
xaccAccountTreeScrubImbalance (Account *acc)
{
- xaccAccountScrubImbalance (acc);
- gnc_account_foreach_descendant(acc,
- (AccountCb)xaccAccountScrubImbalance, NULL);
+ xaccAccountScrubImbalance (acc);
+ gnc_account_foreach_descendant(acc,
+ (AccountCb)xaccAccountScrubImbalance, NULL);
}
void
xaccAccountScrubImbalance (Account *acc)
{
- GList *node;
- const char *str;
+ GList *node;
+ const char *str;
- if (!acc) return;
+ if (!acc) return;
- str = xaccAccountGetName(acc);
- str = str ? str : "(null)";
- PINFO ("Looking for imbalance in account %s \n", str);
+ str = xaccAccountGetName(acc);
+ str = str ? str : "(null)";
+ PINFO ("Looking for imbalance in account %s \n", str);
- for(node = xaccAccountGetSplitList(acc); node; node = node->next)
- {
- Split *split = node->data;
- Transaction *trans = xaccSplitGetParent(split);
+ for (node = xaccAccountGetSplitList(acc); node; node = node->next)
+ {
+ Split *split = node->data;
+ Transaction *trans = xaccSplitGetParent(split);
- xaccTransScrubCurrencyFromSplits(trans);
-
- xaccTransScrubImbalance (trans, gnc_account_get_root (acc), NULL);
- }
+ xaccTransScrubCurrencyFromSplits(trans);
+
+ xaccTransScrubImbalance (trans, gnc_account_get_root (acc), NULL);
+ }
}
void
xaccTransScrubCurrencyFromSplits(Transaction *trans)
{
- GList *node;
- gnc_commodity *common_currency = NULL;
-
- if (!trans) return;
-
- for (node = xaccTransGetSplitList (trans); node; node = node->next) {
- Split *split = node->data;
+ GList *node;
+ gnc_commodity *common_currency = NULL;
- if (!xaccTransStillHasSplit(trans, split)) continue;
- if (gnc_numeric_equal(xaccSplitGetAmount (split),
- xaccSplitGetValue (split))) {
+ if (!trans) return;
- Account *s_account = xaccSplitGetAccount (split);
- gnc_commodity *s_commodity = xaccAccountGetCommodity (s_account);
-
- if (s_commodity) {
- if (gnc_commodity_is_currency(s_commodity)) {
- /* Found a split where the amount is the same as the value and
- the commodity is a currency. If all splits in the transaction
- that fit this description are in the same currency then the
- transaction should be in that currency too. */
+ for (node = xaccTransGetSplitList (trans); node; node = node->next)
+ {
+ Split *split = node->data;
- if (common_currency == NULL)
- /* First one we've found, save the currency */
- common_currency = s_commodity;
- else if ( !gnc_commodity_equiv (common_currency, s_commodity)) {
- /* Splits are inconsistent, more than one has a value equal to
- the amount, but they aren't all in the same currency. */
- common_currency = NULL;
- break;
- }
+ if (!xaccTransStillHasSplit(trans, split)) continue;
+ if (gnc_numeric_equal(xaccSplitGetAmount (split),
+ xaccSplitGetValue (split)))
+ {
+
+ Account *s_account = xaccSplitGetAccount (split);
+ gnc_commodity *s_commodity = xaccAccountGetCommodity (s_account);
+
+ if (s_commodity)
+ {
+ if (gnc_commodity_is_currency(s_commodity))
+ {
+ /* Found a split where the amount is the same as the value and
+ the commodity is a currency. If all splits in the transaction
+ that fit this description are in the same currency then the
+ transaction should be in that currency too. */
+
+ if (common_currency == NULL)
+ /* First one we've found, save the currency */
+ common_currency = s_commodity;
+ else if ( !gnc_commodity_equiv (common_currency, s_commodity))
+ {
+ /* Splits are inconsistent, more than one has a value equal to
+ the amount, but they aren't all in the same currency. */
+ common_currency = NULL;
+ break;
+ }
+ }
+ }
}
- }
}
- }
-
- if (common_currency &&
- !gnc_commodity_equiv (common_currency, xaccTransGetCurrency (trans))) {
- /* Found a common currency for the splits, and the transaction is not
- in that currency */
- gboolean trans_was_open;
+ if (common_currency &&
+ !gnc_commodity_equiv (common_currency, xaccTransGetCurrency (trans)))
+ {
- PINFO ("transaction in wrong currency");
-
- trans_was_open = xaccTransIsOpen (trans);
+ /* Found a common currency for the splits, and the transaction is not
+ in that currency */
+ gboolean trans_was_open;
- if (!trans_was_open)
- xaccTransBeginEdit (trans);
+ PINFO ("transaction in wrong currency");
- xaccTransSetCurrency (trans, common_currency);
-
- if (!trans_was_open)
- xaccTransCommitEdit (trans);
- }
+ trans_was_open = xaccTransIsOpen (trans);
+
+ if (!trans_was_open)
+ xaccTransBeginEdit (trans);
+
+ xaccTransSetCurrency (trans, common_currency);
+
+ if (!trans_was_open)
+ xaccTransCommitEdit (trans);
+ }
}
static Split *
get_balance_split (Transaction *trans, Account *root, Account *account,
- gnc_commodity *commodity)
+ gnc_commodity *commodity)
{
- Split *balance_split;
- gchar *accname;
-
- if (!account ||
- !gnc_commodity_equiv (commodity, xaccAccountGetCommodity(account)))
- {
- if (!root)
+ Split *balance_split;
+ gchar *accname;
+
+ if (!account ||
+ !gnc_commodity_equiv (commodity, xaccAccountGetCommodity(account)))
{
- root = gnc_book_get_root_account (xaccTransGetBook (trans));
- if (NULL == root)
- {
- /* This can't occur, things should be in books */
- PERR ("Bad data corruption, no root account in book");
- return NULL;
- }
+ if (!root)
+ {
+ root = gnc_book_get_root_account (xaccTransGetBook (trans));
+ if (NULL == root)
+ {
+ /* This can't occur, things should be in books */
+ PERR ("Bad data corruption, no root account in book");
+ return NULL;
+ }
+ }
+ accname = g_strconcat (_("Imbalance"), "-",
+ gnc_commodity_get_mnemonic (commodity), NULL);
+ account = xaccScrubUtilityGetOrMakeAccount (root, commodity,
+ accname, ACCT_TYPE_BANK, FALSE);
+ g_free (accname);
+ if (!account)
+ {
+ PERR ("Can't get balancing account");
+ return NULL;
+ }
}
- accname = g_strconcat (_("Imbalance"), "-",
- gnc_commodity_get_mnemonic (commodity), NULL);
- account = xaccScrubUtilityGetOrMakeAccount (root, commodity,
- accname, ACCT_TYPE_BANK, FALSE);
- g_free (accname);
- if (!account) {
- PERR ("Can't get balancing account");
- return NULL;
- }
- }
- balance_split = xaccTransFindSplitByAccount(trans, account);
+ balance_split = xaccTransFindSplitByAccount(trans, account);
- /* Put split into account before setting split value */
- if (!balance_split)
- {
- balance_split = xaccMallocSplit (qof_instance_get_book(trans));
+ /* Put split into account before setting split value */
+ if (!balance_split)
+ {
+ balance_split = xaccMallocSplit (qof_instance_get_book(trans));
- xaccTransBeginEdit (trans);
- xaccSplitSetParent(balance_split, trans);
- xaccSplitSetAccount(balance_split, account);
- xaccTransCommitEdit (trans);
- }
-
- return balance_split;
+ xaccTransBeginEdit (trans);
+ xaccSplitSetParent(balance_split, trans);
+ xaccSplitSetAccount(balance_split, account);
+ xaccTransCommitEdit (trans);
+ }
+
+ return balance_split;
}
-/* Get the trading split for a given commodity, creating it (and the
+/* Get the trading split for a given commodity, creating it (and the
necessary accounts) if it doesn't exist. */
static Split *
-get_trading_split (Transaction *trans, Account *root,
+get_trading_split (Transaction *trans, Account *root,
gnc_commodity *commodity)
{
- Split *balance_split;
- Account *trading_account;
- Account *ns_account;
- Account *account;
- gnc_commodity *default_currency = NULL;
-
- if (!root)
- {
- root = gnc_book_get_root_account (xaccTransGetBook (trans));
- if (NULL == root)
+ Split *balance_split;
+ Account *trading_account;
+ Account *ns_account;
+ Account *account;
+ gnc_commodity *default_currency = NULL;
+
+ if (!root)
{
- /* This can't occur, things should be in books */
- PERR ("Bad data corruption, no root account in book");
- return NULL;
+ root = gnc_book_get_root_account (xaccTransGetBook (trans));
+ if (NULL == root)
+ {
+ /* This can't occur, things should be in books */
+ PERR ("Bad data corruption, no root account in book");
+ return NULL;
+ }
}
- }
-
- /* Get the default currency. This is harder than it seems. It's not
- possible to call gnc_default_currency() since it's a UI function. One
- might think that the currency of the root account would do, but the root
- account has no currency. Instead look for the Income placeholder account
- and use its currency. */
- default_currency = xaccAccountGetCommodity(gnc_account_lookup_by_name(root,
- _("Income")));
- if (! default_currency) {
- default_currency = commodity;
- }
-
- trading_account = xaccScrubUtilityGetOrMakeAccount (root,
- default_currency,
- _("Trading"),
- ACCT_TYPE_TRADING, TRUE);
- if (!trading_account) {
- PERR ("Can't get trading account");
- return NULL;
- }
-
- ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,
- default_currency,
- gnc_commodity_get_namespace(commodity),
- ACCT_TYPE_TRADING, TRUE);
- if (!ns_account) {
- PERR ("Can't get namespace account");
- return NULL;
- }
-
- account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,
- gnc_commodity_get_mnemonic(commodity),
- ACCT_TYPE_TRADING, FALSE);
- if (!account) {
- PERR ("Can't get commodity account");
- return NULL;
- }
-
-
- balance_split = xaccTransFindSplitByAccount(trans, account);
-
- /* Put split into account before setting split value */
- if (!balance_split)
- {
- balance_split = xaccMallocSplit (qof_instance_get_book(trans));
-
- xaccTransBeginEdit (trans);
- xaccSplitSetParent(balance_split, trans);
- xaccSplitSetAccount(balance_split, account);
- xaccTransCommitEdit (trans);
- }
-
- return balance_split;
+
+ /* Get the default currency. This is harder than it seems. It's not
+ possible to call gnc_default_currency() since it's a UI function. One
+ might think that the currency of the root account would do, but the root
+ account has no currency. Instead look for the Income placeholder account
+ and use its currency. */
+ default_currency = xaccAccountGetCommodity(gnc_account_lookup_by_name(root,
+ _("Income")));
+ if (! default_currency)
+ {
+ default_currency = commodity;
+ }
+
+ trading_account = xaccScrubUtilityGetOrMakeAccount (root,
+ default_currency,
+ _("Trading"),
+ ACCT_TYPE_TRADING, TRUE);
+ if (!trading_account)
+ {
+ PERR ("Can't get trading account");
+ return NULL;
+ }
+
+ ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,
+ default_currency,
+ gnc_commodity_get_namespace(commodity),
+ ACCT_TYPE_TRADING, TRUE);
+ if (!ns_account)
+ {
+ PERR ("Can't get namespace account");
+ return NULL;
+ }
+
+ account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,
+ gnc_commodity_get_mnemonic(commodity),
+ ACCT_TYPE_TRADING, FALSE);
+ if (!account)
+ {
+ PERR ("Can't get commodity account");
+ return NULL;
+ }
+
+
+ balance_split = xaccTransFindSplitByAccount(trans, account);
+
+ /* Put split into account before setting split value */
+ if (!balance_split)
+ {
+ balance_split = xaccMallocSplit (qof_instance_get_book(trans));
+
+ xaccTransBeginEdit (trans);
+ xaccSplitSetParent(balance_split, trans);
+ xaccSplitSetAccount(balance_split, account);
+ xaccTransCommitEdit (trans);
+ }
+
+ return balance_split;
}
/* Find the trading split for a commodity, but don't create any splits
or accounts if they don't already exist. */
static Split *
-find_trading_split (Transaction *trans, Account *root,
+find_trading_split (Transaction *trans, Account *root,
gnc_commodity *commodity)
{
- Account *trading_account;
- Account *ns_account;
- Account *account;
-
- if (!root)
- {
- root = gnc_book_get_root_account (xaccTransGetBook (trans));
- if (NULL == root)
+ Account *trading_account;
+ Account *ns_account;
+ Account *account;
+
+ if (!root)
{
- /* This can't occur, things should be in books */
- PERR ("Bad data corruption, no root account in book");
- return NULL;
+ root = gnc_book_get_root_account (xaccTransGetBook (trans));
+ if (NULL == root)
+ {
+ /* This can't occur, things should be in books */
+ PERR ("Bad data corruption, no root account in book");
+ return NULL;
+ }
}
- }
-
- trading_account = gnc_account_lookup_by_name (root, _("Trading"));
- if (!trading_account) {
- return NULL;
- }
-
- ns_account = gnc_account_lookup_by_name (trading_account,
- gnc_commodity_get_namespace(commodity));
- if (!ns_account) {
- return NULL;
- }
-
- account = gnc_account_lookup_by_name (ns_account,
- gnc_commodity_get_mnemonic(commodity));
- if (!account) {
- return NULL;
- }
-
- return xaccTransFindSplitByAccount(trans, account);
+
+ trading_account = gnc_account_lookup_by_name (root, _("Trading"));
+ if (!trading_account)
+ {
+ return NULL;
+ }
+
+ ns_account = gnc_account_lookup_by_name (trading_account,
+ gnc_commodity_get_namespace(commodity));
+ if (!ns_account)
+ {
+ return NULL;
+ }
+
+ account = gnc_account_lookup_by_name (ns_account,
+ gnc_commodity_get_mnemonic(commodity));
+ if (!account)
+ {
+ return NULL;
+ }
+
+ return xaccTransFindSplitByAccount(trans, account);
}
static void
add_balance_split (Transaction *trans, gnc_numeric imbalance,
Account *root, Account *account)
{
- const gnc_commodity *commodity;
- gnc_numeric old_value, new_value;
- Split *balance_split;
- gnc_commodity *currency = xaccTransGetCurrency (trans);
-
- balance_split = get_balance_split(trans, root, account, currency);
- if (!balance_split)
- {
- /* Error already logged */
- LEAVE("");
- return;
- }
- account = xaccSplitGetAccount(balance_split);
-
- xaccTransBeginEdit (trans);
-
- old_value = xaccSplitGetValue (balance_split);
-
- /* Note: We have to round for the commodity's fraction, NOT any
- * already existing denominator (bug #104343), because either one
- * of the denominators might already be reduced. */
- new_value = gnc_numeric_sub (old_value, imbalance,
- gnc_commodity_get_fraction(currency),
- GNC_HOW_RND_ROUND);
-
- xaccSplitSetValue (balance_split, new_value);
-
- commodity = xaccAccountGetCommodity (account);
- if (gnc_commodity_equiv (currency, commodity))
- {
- xaccSplitSetAmount (balance_split, new_value);
- }
-
- xaccSplitScrub (balance_split);
- xaccTransCommitEdit (trans);
+ const gnc_commodity *commodity;
+ gnc_numeric old_value, new_value;
+ Split *balance_split;
+ gnc_commodity *currency = xaccTransGetCurrency (trans);
+
+ balance_split = get_balance_split(trans, root, account, currency);
+ if (!balance_split)
+ {
+ /* Error already logged */
+ LEAVE("");
+ return;
+ }
+ account = xaccSplitGetAccount(balance_split);
+
+ xaccTransBeginEdit (trans);
+
+ old_value = xaccSplitGetValue (balance_split);
+
+ /* Note: We have to round for the commodity's fraction, NOT any
+ * already existing denominator (bug #104343), because either one
+ * of the denominators might already be reduced. */
+ new_value = gnc_numeric_sub (old_value, imbalance,
+ gnc_commodity_get_fraction(currency),
+ GNC_HOW_RND_ROUND);
+
+ xaccSplitSetValue (balance_split, new_value);
+
+ commodity = xaccAccountGetCommodity (account);
+ if (gnc_commodity_equiv (currency, commodity))
+ {
+ xaccSplitSetAmount (balance_split, new_value);
+ }
+
+ xaccSplitScrub (balance_split);
+ xaccTransCommitEdit (trans);
}
void
xaccTransScrubImbalance (Transaction *trans, Account *root,
Account *account)
{
- const gnc_commodity *currency;
+ const gnc_commodity *currency;
- if (!trans) return;
+ if (!trans) return;
- ENTER ("()");
+ ENTER ("()");
- /* Must look for orphan splits even if there is no imbalance. */
- xaccTransScrubSplits (trans);
+ /* Must look for orphan splits even if there is no imbalance. */
+ xaccTransScrubSplits (trans);
- /* Return immediately if things are balanced. */
- if (xaccTransIsBalanced (trans))
- return;
+ /* Return immediately if things are balanced. */
+ if (xaccTransIsBalanced (trans))
+ return;
- currency = xaccTransGetCurrency (trans);
+ currency = xaccTransGetCurrency (trans);
- if (! xaccTransUseTradingAccounts (trans))
- {
- gnc_numeric imbalance;
-
- /* Make the value sum to zero */
- imbalance = xaccTransGetImbalanceValue (trans);
- if (! gnc_numeric_zero_p (imbalance))
+ if (! xaccTransUseTradingAccounts (trans))
{
- PINFO ("Value unbalanced transaction");
+ gnc_numeric imbalance;
- add_balance_split (trans, imbalance, root, account);
+ /* Make the value sum to zero */
+ imbalance = xaccTransGetImbalanceValue (trans);
+ if (! gnc_numeric_zero_p (imbalance))
+ {
+ PINFO ("Value unbalanced transaction");
+
+ add_balance_split (trans, imbalance, root, account);
+ }
}
- }
- else
- {
- MonetaryList *imbal_list;
- MonetaryList *imbalance_commod;
- GList *splits;
- gnc_numeric imbalance;
- Split *balance_split = NULL;
-
- /* If there are existing trading splits, adjust the price or exchange
- rate in each of them to agree with the non-trading splits for the
- same commodity. If there are multiple non-trading splits for the
- same commodity in the transaction this will use the exchange rate in
- the last such split. This shouldn't happen, and if it does then there's
- not much we can do about it anyway.
-
- While we're at it, compute the value imbalance ignoring existing
- trading splits. */
-
- imbalance = gnc_numeric_zero();
-
- for (splits = trans->splits; splits; splits = splits->next)
+ else
{
- Split *split = splits->data;
- gnc_numeric value, amount;
- gnc_commodity *commodity;
-
- if (! xaccTransStillHasSplit (trans, split)) continue;
-
- commodity = xaccAccountGetCommodity (xaccSplitGetAccount(split));
- if (!commodity)
- {
- PERR("Split has no commodity");
- continue;
- }
-
- balance_split = find_trading_split (trans, root, commodity);
-
- if (balance_split != split)
- /* this is not a trading split */
- imbalance = gnc_numeric_add(imbalance, xaccSplitGetValue (split),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
-
- /* Ignore splits where value or amount is zero */
- value = xaccSplitGetValue (split);
- amount = xaccSplitGetAmount (split);
- if (gnc_numeric_zero_p(amount) || gnc_numeric_zero_p(value))
- continue;
-
- if (balance_split && balance_split != split)
- {
- gnc_numeric convrate = gnc_numeric_div (amount, value,
- GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
- gnc_numeric old_value, new_value;
- old_value = xaccSplitGetValue(balance_split);
- new_value = gnc_numeric_div (xaccSplitGetAmount(balance_split),
- convrate,
- gnc_commodity_get_fraction(currency),
- GNC_RND_ROUND);
- if (! gnc_numeric_equal (old_value, new_value))
+ MonetaryList *imbal_list;
+ MonetaryList *imbalance_commod;
+ GList *splits;
+ gnc_numeric imbalance;
+ Split *balance_split = NULL;
+
+ /* If there are existing trading splits, adjust the price or exchange
+ rate in each of them to agree with the non-trading splits for the
+ same commodity. If there are multiple non-trading splits for the
+ same commodity in the transaction this will use the exchange rate in
+ the last such split. This shouldn't happen, and if it does then there's
+ not much we can do about it anyway.
+
+ While we're at it, compute the value imbalance ignoring existing
+ trading splits. */
+
+ imbalance = gnc_numeric_zero();
+
+ for (splits = trans->splits; splits; splits = splits->next)
{
- xaccTransBeginEdit (trans);
- xaccSplitSetValue (balance_split, new_value);
- xaccSplitScrub (balance_split);
- xaccTransCommitEdit (trans);
+ Split *split = splits->data;
+ gnc_numeric value, amount;
+ gnc_commodity *commodity;
+
+ if (! xaccTransStillHasSplit (trans, split)) continue;
+
+ commodity = xaccAccountGetCommodity (xaccSplitGetAccount(split));
+ if (!commodity)
+ {
+ PERR("Split has no commodity");
+ continue;
+ }
+
+ balance_split = find_trading_split (trans, root, commodity);
+
+ if (balance_split != split)
+ /* this is not a trading split */
+ imbalance = gnc_numeric_add(imbalance, xaccSplitGetValue (split),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
+
+ /* Ignore splits where value or amount is zero */
+ value = xaccSplitGetValue (split);
+ amount = xaccSplitGetAmount (split);
+ if (gnc_numeric_zero_p(amount) || gnc_numeric_zero_p(value))
+ continue;
+
+ if (balance_split && balance_split != split)
+ {
+ gnc_numeric convrate = gnc_numeric_div (amount, value,
+ GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
+ gnc_numeric old_value, new_value;
+ old_value = xaccSplitGetValue(balance_split);
+ new_value = gnc_numeric_div (xaccSplitGetAmount(balance_split),
+ convrate,
+ gnc_commodity_get_fraction(currency),
+ GNC_RND_ROUND);
+ if (! gnc_numeric_equal (old_value, new_value))
+ {
+ xaccTransBeginEdit (trans);
+ xaccSplitSetValue (balance_split, new_value);
+ xaccSplitScrub (balance_split);
+ xaccTransCommitEdit (trans);
+ }
+ }
}
- }
- }
- /* Balance the value, ignoring existing trading splits */
- if (! gnc_numeric_zero_p (imbalance))
- {
- PINFO ("Value unbalanced transaction");
-
- add_balance_split (trans, imbalance, root, account);
- }
-
- /* If the transaction is balanced, nothing more to do */
- imbal_list = xaccTransGetImbalance (trans);
- if (!imbal_list)
- {
- LEAVE("()");
- return;
- }
-
- PINFO ("Currency unbalanced transaction");
-
- for (imbalance_commod = imbal_list; imbalance_commod;
- imbalance_commod = imbalance_commod->next) {
- gnc_monetary *imbal_mon = imbalance_commod->data;
- gnc_commodity *commodity;
- gnc_numeric convrate;
- gnc_numeric old_amount, new_amount;
- gnc_numeric old_value, new_value, val_imbalance;
- GList *splits;
-
- commodity = gnc_monetary_commodity (*imbal_mon);
-
- balance_split = get_trading_split(trans, root, commodity);
- if (!balance_split)
- {
- /* Error already logged */
- gnc_monetary_list_free(imbal_list);
- LEAVE("");
- return;
- }
-
- account = xaccSplitGetAccount(balance_split);
-
- if (! gnc_commodity_equal (currency, commodity)) {
- /* Find the value imbalance in this commodity */
- val_imbalance = gnc_numeric_zero();
- for (splits = trans->splits; splits; splits = splits->next) {
- Split *split = splits->data;
- if (xaccTransStillHasSplit (trans, split) &&
- gnc_commodity_equal (commodity,
- xaccAccountGetCommodity(xaccSplitGetAccount(split))))
- val_imbalance = gnc_numeric_add (val_imbalance, xaccSplitGetValue (split),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
+ /* Balance the value, ignoring existing trading splits */
+ if (! gnc_numeric_zero_p (imbalance))
+ {
+ PINFO ("Value unbalanced transaction");
+
+ add_balance_split (trans, imbalance, root, account);
}
- }
-
- xaccTransBeginEdit (trans);
-
- old_amount = xaccSplitGetAmount (balance_split);
- new_amount = gnc_numeric_sub (old_amount, gnc_monetary_value(*imbal_mon),
- gnc_commodity_get_fraction(commodity),
- GNC_HOW_RND_ROUND);
-
- xaccSplitSetAmount (balance_split, new_amount);
-
- if (gnc_commodity_equal (currency, commodity)) {
- /* Imbalance commodity is the transaction currency, value in the
- split must be the same as the amount */
- xaccSplitSetValue (balance_split, new_amount);
- }
- else {
- old_value = xaccSplitGetValue (balance_split);
- new_value = gnc_numeric_sub (old_value, val_imbalance,
- gnc_commodity_get_fraction(currency),
- GNC_HOW_RND_ROUND);
-
- xaccSplitSetValue (balance_split, new_value);
- }
-
- xaccSplitScrub (balance_split);
- xaccTransCommitEdit (trans);
- }
-
- gnc_monetary_list_free(imbal_list);
-
- if (!gnc_numeric_zero_p(xaccTransGetImbalanceValue(trans))) {
- /* This is probably because there are splits with zero amount
- and non-zero value. These are usually realized gain/loss
- splits. Add a reversing split for each of them to balance
- the value. */
- /* Copy the split list so we don't see the splits we're adding */
- GList *splits_dup = g_list_copy(trans->splits);
- for (splits = splits_dup; splits; splits = splits->next) {
- Split *split = splits->data;
- if (! xaccTransStillHasSplit(trans, split)) continue;
- if (!gnc_numeric_zero_p(xaccSplitGetValue(split)) &&
- gnc_numeric_zero_p(xaccSplitGetAmount(split))) {
- gnc_commodity *commodity;
- gnc_numeric old_value, new_value;
-
- commodity = xaccAccountGetCommodity(xaccSplitGetAccount(split));
- if (!commodity) {
- PERR("Split has no commodity");
- continue;
- }
- balance_split = get_trading_split(trans, root, commodity);
- if (!balance_split)
- {
- /* Error already logged */
- gnc_monetary_list_free(imbal_list);
- LEAVE("");
+ /* If the transaction is balanced, nothing more to do */
+ imbal_list = xaccTransGetImbalance (trans);
+ if (!imbal_list)
+ {
+ LEAVE("()");
return;
- }
- account = xaccSplitGetAccount(balance_split);
-
- xaccTransBeginEdit (trans);
-
- old_value = xaccSplitGetValue (balance_split);
- new_value = gnc_numeric_sub (old_value, xaccSplitGetValue(split),
- gnc_commodity_get_fraction(currency),
- GNC_HOW_RND_ROUND);
- xaccSplitSetValue (balance_split, new_value);
-
- /* Don't change the balance split's amount since the amount
- is zero in the split we're working on */
+ }
- xaccSplitScrub (balance_split);
- xaccTransCommitEdit (trans);
+ PINFO ("Currency unbalanced transaction");
+
+ for (imbalance_commod = imbal_list; imbalance_commod;
+ imbalance_commod = imbalance_commod->next)
+ {
+ gnc_monetary *imbal_mon = imbalance_commod->data;
+ gnc_commodity *commodity;
+ gnc_numeric convrate;
+ gnc_numeric old_amount, new_amount;
+ gnc_numeric old_value, new_value, val_imbalance;
+ GList *splits;
+
+ commodity = gnc_monetary_commodity (*imbal_mon);
+
+ balance_split = get_trading_split(trans, root, commodity);
+ if (!balance_split)
+ {
+ /* Error already logged */
+ gnc_monetary_list_free(imbal_list);
+ LEAVE("");
+ return;
+ }
+
+ account = xaccSplitGetAccount(balance_split);
+
+ if (! gnc_commodity_equal (currency, commodity))
+ {
+ /* Find the value imbalance in this commodity */
+ val_imbalance = gnc_numeric_zero();
+ for (splits = trans->splits; splits; splits = splits->next)
+ {
+ Split *split = splits->data;
+ if (xaccTransStillHasSplit (trans, split) &&
+ gnc_commodity_equal (commodity,
+ xaccAccountGetCommodity(xaccSplitGetAccount(split))))
+ val_imbalance = gnc_numeric_add (val_imbalance, xaccSplitGetValue (split),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
+ }
+ }
+
+ xaccTransBeginEdit (trans);
+
+ old_amount = xaccSplitGetAmount (balance_split);
+ new_amount = gnc_numeric_sub (old_amount, gnc_monetary_value(*imbal_mon),
+ gnc_commodity_get_fraction(commodity),
+ GNC_HOW_RND_ROUND);
+
+ xaccSplitSetAmount (balance_split, new_amount);
+
+ if (gnc_commodity_equal (currency, commodity))
+ {
+ /* Imbalance commodity is the transaction currency, value in the
+ split must be the same as the amount */
+ xaccSplitSetValue (balance_split, new_amount);
+ }
+ else
+ {
+ old_value = xaccSplitGetValue (balance_split);
+ new_value = gnc_numeric_sub (old_value, val_imbalance,
+ gnc_commodity_get_fraction(currency),
+ GNC_HOW_RND_ROUND);
+
+ xaccSplitSetValue (balance_split, new_value);
+ }
+
+ xaccSplitScrub (balance_split);
+ xaccTransCommitEdit (trans);
}
- }
-
- g_list_free(splits_dup);
-
- if (!gnc_numeric_zero_p(xaccTransGetImbalanceValue(trans)))
- PERR("Balancing currencies unbalanced value");
+
+ gnc_monetary_list_free(imbal_list);
+
+ if (!gnc_numeric_zero_p(xaccTransGetImbalanceValue(trans)))
+ {
+ /* This is probably because there are splits with zero amount
+ and non-zero value. These are usually realized gain/loss
+ splits. Add a reversing split for each of them to balance
+ the value. */
+
+ /* Copy the split list so we don't see the splits we're adding */
+ GList *splits_dup = g_list_copy(trans->splits);
+ for (splits = splits_dup; splits; splits = splits->next)
+ {
+ Split *split = splits->data;
+ if (! xaccTransStillHasSplit(trans, split)) continue;
+ if (!gnc_numeric_zero_p(xaccSplitGetValue(split)) &&
+ gnc_numeric_zero_p(xaccSplitGetAmount(split)))
+ {
+ gnc_commodity *commodity;
+ gnc_numeric old_value, new_value;
+
+ commodity = xaccAccountGetCommodity(xaccSplitGetAccount(split));
+ if (!commodity)
+ {
+ PERR("Split has no commodity");
+ continue;
+ }
+ balance_split = get_trading_split(trans, root, commodity);
+ if (!balance_split)
+ {
+ /* Error already logged */
+ gnc_monetary_list_free(imbal_list);
+ LEAVE("");
+ return;
+ }
+ account = xaccSplitGetAccount(balance_split);
+
+ xaccTransBeginEdit (trans);
+
+ old_value = xaccSplitGetValue (balance_split);
+ new_value = gnc_numeric_sub (old_value, xaccSplitGetValue(split),
+ gnc_commodity_get_fraction(currency),
+ GNC_HOW_RND_ROUND);
+ xaccSplitSetValue (balance_split, new_value);
+
+ /* Don't change the balance split's amount since the amount
+ is zero in the split we're working on */
+
+ xaccSplitScrub (balance_split);
+ xaccTransCommitEdit (trans);
+ }
+ }
+
+ g_list_free(splits_dup);
+
+ if (!gnc_numeric_zero_p(xaccTransGetImbalanceValue(trans)))
+ PERR("Balancing currencies unbalanced value");
+ }
}
- }
- LEAVE ("()");
+ LEAVE ("()");
}
/* ================================================================ */
/* The xaccTransFindCommonCurrency () method returns
* a gnc_commodity indicating a currency denomination that all
* of the splits in this transaction have in common, using the
- * old/obsolete currency/security fields of the split accounts.
+ * old/obsolete currency/security fields of the split accounts.
*/
static gnc_commodity *
@@ -815,109 +839,114 @@
gnc_commodity * ra, gnc_commodity * rb,
Split *excl_split)
{
- GList *node;
+ GList *node;
- if (!splits) return NULL;
+ if (!splits) return NULL;
- for (node = splits; node; node = node->next)
- {
- Split *s = node->data;
- gnc_commodity * sa, * sb;
+ for (node = splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ gnc_commodity * sa, * sb;
- if (s == excl_split) continue;
+ if (s == excl_split) continue;
- g_return_val_if_fail (s->acc, NULL);
+ g_return_val_if_fail (s->acc, NULL);
- sa = DxaccAccountGetCurrency (s->acc);
- sb = xaccAccountGetCommodity (s->acc);
+ sa = DxaccAccountGetCurrency (s->acc);
+ sb = xaccAccountGetCommodity (s->acc);
- if (ra && rb) {
- int aa = !gnc_commodity_equiv(ra,sa);
- int ab = !gnc_commodity_equiv(ra,sb);
- int ba = !gnc_commodity_equiv(rb,sa);
- int bb = !gnc_commodity_equiv(rb,sb);
+ if (ra && rb)
+ {
+ int aa = !gnc_commodity_equiv(ra, sa);
+ int ab = !gnc_commodity_equiv(ra, sb);
+ int ba = !gnc_commodity_equiv(rb, sa);
+ int bb = !gnc_commodity_equiv(rb, sb);
- if ( (!aa) && bb) rb = NULL;
- else
- if ( (!ab) && ba) rb = NULL;
- else
- if ( (!ba) && ab) ra = NULL;
- else
- if ( (!bb) && aa) ra = NULL;
- else
- if ( aa && bb && ab && ba ) { ra = NULL; rb = NULL; }
+ if ( (!aa) && bb) rb = NULL;
+ else if ( (!ab) && ba) rb = NULL;
+ else if ( (!ba) && ab) ra = NULL;
+ else if ( (!bb) && aa) ra = NULL;
+ else if ( aa && bb && ab && ba )
+ {
+ ra = NULL;
+ rb = NULL;
+ }
- if (!ra) { ra = rb; rb = NULL; }
+ if (!ra)
+ {
+ ra = rb;
+ rb = NULL;
+ }
+ }
+ else if (ra && !rb)
+ {
+ int aa = !gnc_commodity_equiv(ra, sa);
+ int ab = !gnc_commodity_equiv(ra, sb);
+ if ( aa && ab ) ra = NULL;
+ }
+
+ if ((!ra) && (!rb)) return NULL;
}
- else
- if (ra && !rb) {
- int aa = !gnc_commodity_equiv(ra,sa);
- int ab = !gnc_commodity_equiv(ra,sb);
- if ( aa && ab ) ra = NULL;
- }
- if ((!ra) && (!rb)) return NULL;
- }
-
- return (ra);
+ return (ra);
}
/* This is the wrapper for those calls (i.e. the older ones) which
* don't exclude one split from the splitlist when looking for a
- * common currency.
+ * common currency.
*/
static gnc_commodity *
FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb)
{
- return FindCommonExclSCurrency(splits, ra, rb, NULL);
+ return FindCommonExclSCurrency(splits, ra, rb, NULL);
}
static gnc_commodity *
xaccTransFindOldCommonCurrency (Transaction *trans, QofBook *book)
{
- gnc_commodity *ra, *rb, *retval;
- Split *split;
+ gnc_commodity *ra, *rb, *retval;
+ Split *split;
- if (!trans) return NULL;
+ if (!trans) return NULL;
- if (trans->splits == NULL) return NULL;
+ if (trans->splits == NULL) return NULL;
- g_return_val_if_fail (book, NULL);
+ g_return_val_if_fail (book, NULL);
- split = trans->splits->data;
+ split = trans->splits->data;
- if (!split || NULL == split->acc) return NULL;
+ if (!split || NULL == split->acc) return NULL;
- ra = DxaccAccountGetCurrency (split->acc);
- rb = xaccAccountGetCommodity (split->acc);
+ ra = DxaccAccountGetCurrency (split->acc);
+ rb = xaccAccountGetCommodity (split->acc);
- retval = FindCommonCurrency (trans->splits, ra, rb);
+ retval = FindCommonCurrency (trans->splits, ra, rb);
- /* Compare this value to what we think should be the 'right' value */
- if (!trans->common_currency)
- {
- trans->common_currency = retval;
- }
- else if (!gnc_commodity_equiv (retval,trans->common_currency))
- {
- char guid_str[GUID_ENCODING_LENGTH+1];
- guid_to_string_buff(xaccTransGetGUID(trans), guid_str);
- PWARN ("expected common currency %s but found %s in txn %s\n",
- gnc_commodity_get_unique_name (trans->common_currency),
- gnc_commodity_get_unique_name (retval), guid_str);
- }
+ /* Compare this value to what we think should be the 'right' value */
+ if (!trans->common_currency)
+ {
+ trans->common_currency = retval;
+ }
+ else if (!gnc_commodity_equiv (retval, trans->common_currency))
+ {
+ char guid_str[GUID_ENCODING_LENGTH+1];
+ guid_to_string_buff(xaccTransGetGUID(trans), guid_str);
+ PWARN ("expected common currency %s but found %s in txn %s\n",
+ gnc_commodity_get_unique_name (trans->common_currency),
+ gnc_commodity_get_unique_name (retval), guid_str);
+ }
- if (NULL == retval)
- {
- /* In every situation I can think of, this routine should return
- * common currency. So make note of this ... */
- char guid_str[GUID_ENCODING_LENGTH+1];
- guid_to_string_buff(xaccTransGetGUID(trans), guid_str);
- PWARN ("unable to find a common currency in txn %s, and that is strange.",
- guid_str);
- }
+ if (NULL == retval)
+ {
+ /* In every situation I can think of, this routine should return
+ * common currency. So make note of this ... */
+ char guid_str[GUID_ENCODING_LENGTH+1];
+ guid_to_string_buff(xaccTransGetGUID(trans), guid_str);
+ PWARN ("unable to find a common currency in txn %s, and that is strange.",
+ guid_str);
+ }
- return retval;
+ return retval;
}
/* ================================================================ */
@@ -925,108 +954,108 @@
void
xaccTransScrubCurrency (Transaction *trans)
{
- SplitList *node;
- gnc_commodity *currency;
+ SplitList *node;
+ gnc_commodity *currency;
- if (!trans) return;
+ if (!trans) return;
- /* If there are any orphaned splits in a transaction, then the
- * this routine will fail. Therefore, we want to make sure that
- * there are no orphans (splits without parent account).
- */
- xaccTransScrubOrphans (trans);
+ /* If there are any orphaned splits in a transaction, then the
+ * this routine will fail. Therefore, we want to make sure that
+ * there are no orphans (splits without parent account).
+ */
+ xaccTransScrubOrphans (trans);
- currency = xaccTransGetCurrency (trans);
- if (currency) return;
-
- currency = xaccTransFindOldCommonCurrency (trans, qof_instance_get_book(trans));
- if (currency)
- {
- xaccTransBeginEdit (trans);
- xaccTransSetCurrency (trans, currency);
- xaccTransCommitEdit (trans);
- }
- else
- {
- if (NULL == trans->splits)
+ currency = xaccTransGetCurrency (trans);
+ if (currency) return;
+
+ currency = xaccTransFindOldCommonCurrency (trans, qof_instance_get_book(trans));
+ if (currency)
{
- PWARN ("Transaction \"%s\" has no splits in it!", trans->description);
+ xaccTransBeginEdit (trans);
+ xaccTransSetCurrency (trans, currency);
+ xaccTransCommitEdit (trans);
}
else
{
- SplitList *node;
- char guid_str[GUID_ENCODING_LENGTH+1];
- guid_to_string_buff(xaccTransGetGUID(trans), guid_str);
- PWARN ("no common transaction currency found for trans=\"%s\" (%s)",
- trans->description, guid_str);
-
- for (node=trans->splits; node; node=node->next)
- {
- Split *split = node->data;
- if (NULL == split->acc)
+ if (NULL == trans->splits)
{
- PWARN (" split=\"%s\" is not in any account!", split->memo);
+ PWARN ("Transaction \"%s\" has no splits in it!", trans->description);
}
else
{
- PWARN (" split=\"%s\" account=\"%s\" commodity=\"%s\"",
- split->memo, xaccAccountGetName(split->acc),
- gnc_commodity_get_mnemonic(xaccAccountGetCommodity(split->acc)));
+ SplitList *node;
+ char guid_str[GUID_ENCODING_LENGTH+1];
+ guid_to_string_buff(xaccTransGetGUID(trans), guid_str);
+ PWARN ("no common transaction currency found for trans=\"%s\" (%s)",
+ trans->description, guid_str);
+
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *split = node->data;
+ if (NULL == split->acc)
+ {
+ PWARN (" split=\"%s\" is not in any account!", split->memo);
+ }
+ else
+ {
+ PWARN (" split=\"%s\" account=\"%s\" commodity=\"%s\"",
+ split->memo, xaccAccountGetName(split->acc),
+ gnc_commodity_get_mnemonic(xaccAccountGetCommodity(split->acc)));
+ }
+ }
}
- }
}
- }
- for (node=trans->splits; node; node=node->next)
- {
- Split *sp = node->data;
-
- if (!gnc_numeric_equal(xaccSplitGetAmount (sp),
- xaccSplitGetValue (sp)))
+ for (node = trans->splits; node; node = node->next)
{
- gnc_commodity *acc_currency;
+ Split *sp = node->data;
- acc_currency = sp->acc ? xaccAccountGetCommodity(sp->acc) : NULL;
- if (acc_currency == currency)
- {
- /* This Split needs fixing: The transaction-currency equals
- * the account-currency/commodity, but the amount/values are
- * inequal i.e. they still correspond to the security
- * (amount) and the currency (value). In the new model, the
- * value is the amount in the account-commodity -- so it
- * needs to be set to equal the amount (since the
- * account-currency doesn't exist anymore).
- *
- * Note: Nevertheless we lose some information here. Namely,
- * the information that the 'amount' in 'account-old-security'
- * was worth 'value' in 'account-old-currency'. Maybe it would
- * be better to store that information in the price database?
- * But then, for old currency transactions there is still the
- * 'other' transaction, which is going to keep that
- * information. So I don't bother with that here. -- cstim,
- * 2002/11/20. */
-
- PWARN ("Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\""
- " old amount %s %s, new amount %s",
- trans->description, sp->memo,
- gnc_num_dbg_to_string (xaccSplitGetAmount(sp)),
- gnc_commodity_get_mnemonic (currency),
- gnc_num_dbg_to_string (xaccSplitGetValue(sp)));
- xaccTransBeginEdit (trans);
- xaccSplitSetAmount (sp, xaccSplitGetValue(sp));
- xaccTransCommitEdit (trans);
- }
- /*else
- {
- PINFO ("Ok: Split '%s' Amount %s %s, value %s %s",
- xaccSplitGetMemo (sp),
- gnc_num_dbg_to_string (amount),
- gnc_commodity_get_mnemonic (currency),
- gnc_num_dbg_to_string (value),
- gnc_commodity_get_mnemonic (acc_currency));
- }*/
+ if (!gnc_numeric_equal(xaccSplitGetAmount (sp),
+ xaccSplitGetValue (sp)))
+ {
+ gnc_commodity *acc_currency;
+
+ acc_currency = sp->acc ? xaccAccountGetCommodity(sp->acc) : NULL;
+ if (acc_currency == currency)
+ {
+ /* This Split needs fixing: The transaction-currency equals
+ * the account-currency/commodity, but the amount/values are
+ * inequal i.e. they still correspond to the security
+ * (amount) and the currency (value). In the new model, the
+ * value is the amount in the account-commodity -- so it
+ * needs to be set to equal the amount (since the
+ * account-currency doesn't exist anymore).
+ *
+ * Note: Nevertheless we lose some information here. Namely,
+ * the information that the 'amount' in 'account-old-security'
+ * was worth 'value' in 'account-old-currency'. Maybe it would
+ * be better to store that information in the price database?
+ * But then, for old currency transactions there is still the
+ * 'other' transaction, which is going to keep that
+ * information. So I don't bother with that here. -- cstim,
+ * 2002/11/20. */
+
+ PWARN ("Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\""
+ " old amount %s %s, new amount %s",
+ trans->description, sp->memo,
+ gnc_num_dbg_to_string (xaccSplitGetAmount(sp)),
+ gnc_commodity_get_mnemonic (currency),
+ gnc_num_dbg_to_string (xaccSplitGetValue(sp)));
+ xaccTransBeginEdit (trans);
+ xaccSplitSetAmount (sp, xaccSplitGetValue(sp));
+ xaccTransCommitEdit (trans);
+ }
+ /*else
+ {
+ PINFO ("Ok: Split '%s' Amount %s %s, value %s %s",
+ xaccSplitGetMemo (sp),
+ gnc_num_dbg_to_string (amount),
+ gnc_commodity_get_mnemonic (currency),
+ gnc_num_dbg_to_string (value),
+ gnc_commodity_get_mnemonic (acc_currency));
+ }*/
+ }
}
- }
}
/* ================================================================ */
@@ -1034,32 +1063,32 @@
void
xaccAccountScrubCommodity (Account *account)
{
- gnc_commodity *commodity;
+ gnc_commodity *commodity;
- if (!account) return;
- if (xaccAccountGetType(account) == ACCT_TYPE_ROOT) return;
+ if (!account) return;
+ if (xaccAccountGetType(account) == ACCT_TYPE_ROOT) return;
- commodity = xaccAccountGetCommodity (account);
- if (commodity) return;
+ commodity = xaccAccountGetCommodity (account);
+ if (commodity) return;
- /* Use the 'obsolete' routines to try to figure out what the
- * account commodity should have been. */
- commodity = DxaccAccountGetSecurity (account);
- if (commodity)
- {
- xaccAccountSetCommodity (account, commodity);
- return;
- }
+ /* Use the 'obsolete' routines to try to figure out what the
+ * account commodity should have been. */
+ commodity = DxaccAccountGetSecurity (account);
+ if (commodity)
+ {
+ xaccAccountSetCommodity (account, commodity);
+ return;
+ }
- commodity = DxaccAccountGetCurrency (account);
- if (commodity)
- {
- xaccAccountSetCommodity (account, commodity);
- return;
- }
+ commodity = DxaccAccountGetCurrency (account);
+ if (commodity)
+ {
+ xaccAccountSetCommodity (account, commodity);
+ return;
+ }
- PERR ("Account \"%s\" does not have a commodity!",
- xaccAccountGetName(account));
+ PERR ("Account \"%s\" does not have a commodity!",
+ xaccAccountGetName(account));
}
/* ================================================================ */
@@ -1067,37 +1096,37 @@
static void
xaccAccountDeleteOldData (Account *account)
{
- if (!account) return;
+ if (!account) return;
- kvp_frame_set_slot_nc (account->inst.kvp_data, "old-currency", NULL);
- kvp_frame_set_slot_nc (account->inst.kvp_data, "old-security", NULL);
- kvp_frame_set_slot_nc (account->inst.kvp_data, "old-currency-scu", NULL);
- kvp_frame_set_slot_nc (account->inst.kvp_data, "old-security-scu", NULL);
+ kvp_frame_set_slot_nc (account->inst.kvp_data, "old-currency", NULL);
+ kvp_frame_set_slot_nc (account->inst.kvp_data, "old-security", NULL);
+ kvp_frame_set_slot_nc (account->inst.kvp_data, "old-currency-scu", NULL);
+ kvp_frame_set_slot_nc (account->inst.kvp_data, "old-security-scu", NULL);
}
static int
scrub_trans_currency_helper (Transaction *t, gpointer data)
{
- xaccTransScrubCurrency (t);
- return 0;
+ xaccTransScrubCurrency (t);
+ return 0;
}
static void
scrub_account_commodity_helper (Account *account, gpointer data)
{
- xaccAccountScrubCommodity (account);
- xaccAccountDeleteOldData (account);
+ xaccAccountScrubCommodity (account);
+ xaccAccountDeleteOldData (account);
}
void
xaccAccountTreeScrubCommodities (Account *acc)
{
- if (!acc) return;
+ if (!acc) return;
- xaccAccountTreeForEachTransaction (acc, scrub_trans_currency_helper, NULL);
+ xaccAccountTreeForEachTransaction (acc, scrub_trans_currency_helper, NULL);
- scrub_account_commodity_helper (acc, NULL);
- gnc_account_foreach_descendant (acc, scrub_account_commodity_helper, NULL);
+ scrub_account_commodity_helper (acc, NULL);
+ gnc_account_foreach_descendant (acc, scrub_account_commodity_helper, NULL);
}
/* ================================================================ */
@@ -1105,63 +1134,65 @@
static gboolean
check_quote_source (gnc_commodity *com, gpointer data)
{
- gboolean *commodity_has_quote_src = (gboolean *)data;
- if (com && !gnc_commodity_is_iso(com))
- *commodity_has_quote_src |= gnc_commodity_get_quote_flag(com);
- return TRUE;
+ gboolean *commodity_has_quote_src = (gboolean *)data;
+ if (com && !gnc_commodity_is_iso(com))
+ *commodity_has_quote_src |= gnc_commodity_get_quote_flag(com);
+ return TRUE;
}
static void
move_quote_source (Account *account, gpointer data)
{
- gnc_commodity *com;
- gnc_quote_source *quote_source;
- gboolean new_style = GPOINTER_TO_INT(data);
- const char *source, *tz;
+ gnc_commodity *com;
+ gnc_quote_source *quote_source;
+ gboolean new_style = GPOINTER_TO_INT(data);
+ const char *source, *tz;
- com = xaccAccountGetCommodity(account);
- if (!com)
- return;
+ com = xaccAccountGetCommodity(account);
+ if (!com)
+ return;
- if (!new_style) {
- source = dxaccAccountGetPriceSrc(account);
- if (!source || !*source)
- return;
- tz = dxaccAccountGetQuoteTZ(account);
+ if (!new_style)
+ {
+ source = dxaccAccountGetPriceSrc(account);
+ if (!source || !*source)
+ return;
+ tz = dxaccAccountGetQuoteTZ(account);
- PINFO("to %8s from %s", gnc_commodity_get_mnemonic(com),
- xaccAccountGetName(account));
- gnc_commodity_set_quote_flag(com, TRUE);
- quote_source = gnc_quote_source_lookup_by_internal(source);
- if (!quote_source)
- quote_source = gnc_quote_source_add_new(source, FALSE);
- gnc_commodity_set_quote_source(com, quote_source);
- gnc_commodity_set_quote_tz(com, tz);
- }
+ PINFO("to %8s from %s", gnc_commodity_get_mnemonic(com),
+ xaccAccountGetName(account));
+ gnc_commodity_set_quote_flag(com, TRUE);
+ quote_source = gnc_quote_source_lookup_by_internal(source);
+ if (!quote_source)
+ quote_source = gnc_quote_source_add_new(source, FALSE);
+ gnc_commodity_set_quote_source(com, quote_source);
+ gnc_commodity_set_quote_tz(com, tz);
+ }
- dxaccAccountSetPriceSrc(account, NULL);
- dxaccAccountSetQuoteTZ(account, NULL);
- return;
+ dxaccAccountSetPriceSrc(account, NULL);
+ dxaccAccountSetQuoteTZ(account, NULL);
+ return;
}
void
xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table)
{
- gboolean new_style = FALSE;
- ENTER(" ");
+ gboolean new_style = FALSE;
+ ENTER(" ");
- if (!root || !table) {
- LEAVE("Oops");
- return;
- }
+ if (!root || !table)
+ {
+ LEAVE("Oops");
+ return;
+ }
- gnc_commodity_table_foreach_commodity (table, check_quote_source, &new_style);
+ gnc_commodity_table_foreach_commodity (table, check_quote_source, &new_style);
- move_quote_source(root, GINT_TO_POINTER(new_style));
- gnc_account_foreach_descendant (root, move_quote_source,
- GINT_TO_POINTER(new_style));
- LEAVE("Migration done");
+ move_quote_source(root, GINT_TO_POINTER(new_style));
+ gnc_account_foreach_descendant (root, move_quote_source,
+ GINT_TO_POINTER(new_style));
+ LEAVE("Migration done");
}
/* ================================================================ */
@@ -1169,28 +1200,30 @@
void
xaccAccountScrubKvp (Account *account)
{
- const gchar *str;
- gchar *str2;
- kvp_frame *frame;
+ const gchar *str;
+ gchar *str2;
+ kvp_frame *frame;
- if (!account) return;
+ if (!account) return;
- str = kvp_frame_get_string(account->inst.kvp_data, "notes");
- if (str) {
- str2 = g_strstrip(g_strdup(str));
- if (strlen(str2) == 0)
- kvp_frame_set_slot_nc (account->inst.kvp_data, "notes", NULL);
- g_free(str2);
- }
+ str = kvp_frame_get_string(account->inst.kvp_data, "notes");
+ if (str)
+ {
+ str2 = g_strstrip(g_strdup(str));
+ if (strlen(str2) == 0)
+ kvp_frame_set_slot_nc (account->inst.kvp_data, "notes", NULL);
+ g_free(str2);
+ }
- str = kvp_frame_get_string(account->inst.kvp_data, "placeholder");
- if (str && strcmp(str, "false") == 0)
- kvp_frame_set_slot_nc (account->inst.kvp_data, "placeholder", NULL);
+ str = kvp_frame_get_string(account->inst.kvp_data, "placeholder");
+ if (str && strcmp(str, "false") == 0)
+ kvp_frame_set_slot_nc (account->inst.kvp_data, "placeholder", NULL);
- frame = kvp_frame_get_frame(account->inst.kvp_data, "hbci");
- if (frame && kvp_frame_is_empty(frame)) {
- kvp_frame_set_frame_nc(account->inst.kvp_data, "hbci", NULL);
- }
+ frame = kvp_frame_get_frame(account->inst.kvp_data, "hbci");
+ if (frame && kvp_frame_is_empty(frame))
+ {
+ kvp_frame_set_frame_nc(account->inst.kvp_data, "hbci", NULL);
+ }
}
/* ================================================================ */
@@ -1200,36 +1233,36 @@
const char *accname, GNCAccountType acctype,
gboolean placeholder)
{
- Account * acc;
+ Account * acc;
- g_return_val_if_fail (root, NULL);
+ g_return_val_if_fail (root, NULL);
- /* build the account name */
- if (!currency)
- {
- PERR ("No currency specified!");
- return NULL;
- }
+ /* build the account name */
+ if (!currency)
+ {
+ PERR ("No currency specified!");
+ return NULL;
+ }
- /* See if we've got one of these going already ... */
- acc = gnc_account_lookup_by_name(root, accname);
+ /* See if we've got one of these going already ... */
+ acc = gnc_account_lookup_by_name(root, accname);
- if (acc == NULL)
- {
- /* Guess not. We'll have to build one. */
- acc = xaccMallocAccount(gnc_account_get_book (root));
- xaccAccountBeginEdit (acc);
- xaccAccountSetName (acc, accname);
- xaccAccountSetCommodity (acc, currency);
- xaccAccountSetType (acc, acctype);
- xaccAccountSetPlaceholder (acc, placeholder);
+ if (acc == NULL)
+ {
+ /* Guess not. We'll have to build one. */
+ acc = xaccMallocAccount(gnc_account_get_book (root));
+ xaccAccountBeginEdit (acc);
+ xaccAccountSetName (acc, accname);
+ xaccAccountSetCommodity (acc, currency);
+ xaccAccountSetType (acc, acctype);
+ xaccAccountSetPlaceholder (acc, placeholder);
- /* Hang the account off the root. */
- gnc_account_append_child (root, acc);
- xaccAccountCommitEdit (acc);
- }
+ /* Hang the account off the root. */
+ gnc_account_append_child (root, acc);
+ xaccAccountCommitEdit (acc);
+ }
- return acc;
+ return acc;
}
/* ==================== END OF FILE ==================== */
Modified: gnucash/trunk/src/engine/Scrub2.c
===================================================================
--- gnucash/trunk/src/engine/Scrub2.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Scrub2.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -50,44 +50,44 @@
/* ============================================================== */
/** Loop over all splits, and make sure that every split
- * belongs to some lot. If a split does not belong to
+ * belongs to some lot. If a split does not belong to
* any lots, poke it into one.
*/
void
xaccAccountAssignLots (Account *acc)
{
- SplitList *splits, *node;
+ SplitList *splits, *node;
- if (!acc) return;
+ if (!acc) return;
- ENTER ("acc=%s", xaccAccountGetName(acc));
- xaccAccountBeginEdit (acc);
+ ENTER ("acc=%s", xaccAccountGetName(acc));
+ xaccAccountBeginEdit (acc);
restart_loop:
- splits = xaccAccountGetSplitList(acc);
- for (node=splits; node; node=node->next)
- {
- Split * split = node->data;
+ splits = xaccAccountGetSplitList(acc);
+ for (node = splits; node; node = node->next)
+ {
+ Split * split = node->data;
- /* If already in lot, then no-op */
- if (split->lot) continue;
+ /* If already in lot, then no-op */
+ if (split->lot) continue;
- /* Skip voided transactions */
- if (gnc_numeric_zero_p (split->amount) &&
- xaccTransGetVoidStatus(split->parent)) continue;
+ /* Skip voided transactions */
+ if (gnc_numeric_zero_p (split->amount) &&
+ xaccTransGetVoidStatus(split->parent)) continue;
- if (xaccSplitAssign (split)) goto restart_loop;
- }
- xaccAccountCommitEdit (acc);
- LEAVE ("acc=%s", xaccAccountGetName(acc));
+ if (xaccSplitAssign (split)) goto restart_loop;
+ }
+ xaccAccountCommitEdit (acc);
+ LEAVE ("acc=%s", xaccAccountGetName(acc));
}
/* ============================================================== */
-/** The xaccLotFill() routine attempts to assign splits to the
- * indicated lot until the lot balance goes to zero, or until
- * there are no suitable (i.e. unassigned) splits left in the
+/** The xaccLotFill() routine attempts to assign splits to the
+ * indicated lot until the lot balance goes to zero, or until
+ * there are no suitable (i.e. unassigned) splits left in the
* account. It uses the default accounting policy to choose
* the splits to fill out the lot.
*/
@@ -95,53 +95,53 @@
void
xaccLotFill (GNCLot *lot)
{
- Account *acc;
- Split *split;
- GNCPolicy *pcy;
+ Account *acc;
+ Split *split;
+ GNCPolicy *pcy;
- if (!lot) return;
- acc = gnc_lot_get_account(lot);
- pcy = gnc_account_get_policy(acc);
+ if (!lot) return;
+ acc = gnc_lot_get_account(lot);
+ pcy = gnc_account_get_policy(acc);
- ENTER ("(lot=%s, acc=%s)", gnc_lot_get_title(lot), xaccAccountGetName(acc));
+ ENTER ("(lot=%s, acc=%s)", gnc_lot_get_title(lot), xaccAccountGetName(acc));
- /* If balance already zero, we have nothing to do. */
- if (gnc_lot_is_closed (lot)) return;
+ /* If balance already zero, we have nothing to do. */
+ if (gnc_lot_is_closed (lot)) return;
- split = pcy->PolicyGetSplit (pcy, lot);
- if (!split) return; /* Handle the common case */
+ split = pcy->PolicyGetSplit (pcy, lot);
+ if (!split) return; /* Handle the common case */
- /* Reject voided transactions */
- if (gnc_numeric_zero_p(split->amount) &&
- xaccTransGetVoidStatus(split->parent)) return;
+ /* Reject voided transactions */
+ if (gnc_numeric_zero_p(split->amount) &&
+ xaccTransGetVoidStatus(split->parent)) return;
- xaccAccountBeginEdit (acc);
+ xaccAccountBeginEdit (acc);
- /* Loop until we've filled up the lot, (i.e. till the
- * balance goes to zero) or there are no splits left. */
- while (1)
- {
- Split *subsplit;
+ /* Loop until we've filled up the lot, (i.e. till the
+ * balance goes to zero) or there are no splits left. */
+ while (1)
+ {
+ Split *subsplit;
- subsplit = xaccSplitAssignToLot (split, lot);
- if (subsplit == split)
- {
- PERR ("Accounting Policy gave us a split that "
- "doesn't fit into this lot\n"
- "lot baln=%s, isclosed=%d, aplit amt=%s",
- gnc_num_dbg_to_string (gnc_lot_get_balance(lot)),
- gnc_lot_is_closed (lot),
- gnc_num_dbg_to_string (split->amount));
- break;
- }
+ subsplit = xaccSplitAssignToLot (split, lot);
+ if (subsplit == split)
+ {
+ PERR ("Accounting Policy gave us a split that "
+ "doesn't fit into this lot\n"
+ "lot baln=%s, isclosed=%d, aplit amt=%s",
+ gnc_num_dbg_to_string (gnc_lot_get_balance(lot)),
+ gnc_lot_is_closed (lot),
+ gnc_num_dbg_to_string (split->amount));
+ break;
+ }
- if (gnc_lot_is_closed (lot)) break;
+ if (gnc_lot_is_closed (lot)) break;
- split = pcy->PolicyGetSplit (pcy, lot);
- if (!split) break;
- }
- xaccAccountCommitEdit (acc);
- LEAVE ("(lot=%s, acc=%s)", gnc_lot_get_title(lot), xaccAccountGetName(acc));
+ split = pcy->PolicyGetSplit (pcy, lot);
+ if (!split) break;
+ }
+ xaccAccountCommitEdit (acc);
+ LEAVE ("(lot=%s, acc=%s)", gnc_lot_get_title(lot), xaccAccountGetName(acc));
}
/* ============================================================== */
@@ -149,92 +149,92 @@
void
xaccLotScrubDoubleBalance (GNCLot *lot)
{
- gnc_commodity *currency = NULL;
- SplitList *snode;
- GList *node;
- gnc_numeric zero = gnc_numeric_zero();
- gnc_numeric value = zero;
+ gnc_commodity *currency = NULL;
+ SplitList *snode;
+ GList *node;
+ gnc_numeric zero = gnc_numeric_zero();
+ gnc_numeric value = zero;
- if (!lot) return;
+ if (!lot) return;
- ENTER ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
+ ENTER ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
- for (snode = gnc_lot_get_split_list(lot); snode; snode=snode->next)
- {
- Split *s = snode->data;
- xaccSplitComputeCapGains (s, NULL);
- }
+ for (snode = gnc_lot_get_split_list(lot); snode; snode = snode->next)
+ {
+ Split *s = snode->data;
+ xaccSplitComputeCapGains (s, NULL);
+ }
- /* We double-check only closed lots */
- if (FALSE == gnc_lot_is_closed (lot)) return;
+ /* We double-check only closed lots */
+ if (FALSE == gnc_lot_is_closed (lot)) return;
- for (snode = gnc_lot_get_split_list(lot); snode; snode=snode->next)
- {
- Split *s = snode->data;
- Transaction *trans = s->parent;
+ for (snode = gnc_lot_get_split_list(lot); snode; snode = snode->next)
+ {
+ Split *s = snode->data;
+ Transaction *trans = s->parent;
- /* Check to make sure all splits in the lot have a common currency */
- if (NULL == currency)
- {
- currency = trans->common_currency;
- }
- if (FALSE == gnc_commodity_equiv (currency, trans->common_currency))
- {
- /* This lot has mixed currencies. Can't double-balance.
- * Silently punt */
- PWARN ("Lot with multiple currencies:\n"
- "\ttrans=%s curr=%s", xaccTransGetDescription(trans),
- gnc_commodity_get_fullname(trans->common_currency));
- break;
- }
+ /* Check to make sure all splits in the lot have a common currency */
+ if (NULL == currency)
+ {
+ currency = trans->common_currency;
+ }
+ if (FALSE == gnc_commodity_equiv (currency, trans->common_currency))
+ {
+ /* This lot has mixed currencies. Can't double-balance.
+ * Silently punt */
+ PWARN ("Lot with multiple currencies:\n"
+ "\ttrans=%s curr=%s", xaccTransGetDescription(trans),
+ gnc_commodity_get_fullname(trans->common_currency));
+ break;
+ }
- /* Now, total up the values */
- value = gnc_numeric_add (value, xaccSplitGetValue (s),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
- PINFO ("Split=%p value=%s Accum Lot value=%s", s,
- gnc_num_dbg_to_string (s->value),
- gnc_num_dbg_to_string (value));
-
- }
+ /* Now, total up the values */
+ value = gnc_numeric_add (value, xaccSplitGetValue (s),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
+ PINFO ("Split=%p value=%s Accum Lot value=%s", s,
+ gnc_num_dbg_to_string (s->value),
+ gnc_num_dbg_to_string (value));
- if (FALSE == gnc_numeric_equal (value, zero))
- {
- /* Unhandled error condition. Not sure what to do here,
- * Since the ComputeCapGains should have gotten it right.
- * I suppose there might be small rounding errors, a penny or two,
- * the ideal thing would to figure out why there's a rounding
- * error, and fix that.
- */
- PERR ("Closed lot fails to double-balance !! lot value=%s",
- gnc_num_dbg_to_string (value));
- for (node = gnc_lot_get_split_list(lot); node; node=node->next)
- {
- Split *s = node->data;
- PERR ("s=%p amt=%s val=%s", s,
- gnc_num_dbg_to_string(s->amount),
- gnc_num_dbg_to_string(s->value));
- }
- }
+ }
- LEAVE ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
+ if (FALSE == gnc_numeric_equal (value, zero))
+ {
+ /* Unhandled error condition. Not sure what to do here,
+ * Since the ComputeCapGains should have gotten it right.
+ * I suppose there might be small rounding errors, a penny or two,
+ * the ideal thing would to figure out why there's a rounding
+ * error, and fix that.
+ */
+ PERR ("Closed lot fails to double-balance !! lot value=%s",
+ gnc_num_dbg_to_string (value));
+ for (node = gnc_lot_get_split_list(lot); node; node = node->next)
+ {
+ Split *s = node->data;
+ PERR ("s=%p amt=%s val=%s", s,
+ gnc_num_dbg_to_string(s->amount),
+ gnc_num_dbg_to_string(s->value));
+ }
+ }
+
+ LEAVE ("lot=%s", kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
}
/* ================================================================= */
-static inline gboolean
+static inline gboolean
is_subsplit (Split *split)
{
- KvpValue *kval;
+ KvpValue *kval;
- /* generic stop-progress conditions */
- if (!split) return FALSE;
- g_return_val_if_fail (split->parent, FALSE);
+ /* generic stop-progress conditions */
+ if (!split) return FALSE;
+ g_return_val_if_fail (split->parent, FALSE);
- /* If there are no sub-splits, then there's nothing to do. */
- kval = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
- if (!kval) return FALSE;
+ /* If there are no sub-splits, then there's nothing to do. */
+ kval = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
+ if (!kval) return FALSE;
- return TRUE;
+ return TRUE;
}
/* ================================================================= */
@@ -242,246 +242,246 @@
void
xaccScrubSubSplitPrice (Split *split, int maxmult, int maxamtscu)
{
- gnc_numeric src_amt, src_val;
- SplitList *node;
+ gnc_numeric src_amt, src_val;
+ SplitList *node;
- if (FALSE == is_subsplit (split)) return;
+ if (FALSE == is_subsplit (split)) return;
- ENTER (" ");
- /* Get 'price' of the indicated split */
- src_amt = xaccSplitGetAmount (split);
- src_val = xaccSplitGetValue (split);
+ ENTER (" ");
+ /* Get 'price' of the indicated split */
+ src_amt = xaccSplitGetAmount (split);
+ src_val = xaccSplitGetValue (split);
- /* Loop over splits, adjust each so that it has the same
- * ratio (i.e. price). Change the value to get things
- * right; do not change the amount */
- for (node=split->parent->splits; node; node=node->next)
- {
- Split *s = node->data;
- Transaction *txn = s->parent;
- gnc_numeric dst_amt, dst_val, target_val;
- gnc_numeric frac, delta;
- int scu;
+ /* Loop over splits, adjust each so that it has the same
+ * ratio (i.e. price). Change the value to get things
+ * right; do not change the amount */
+ for (node = split->parent->splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ Transaction *txn = s->parent;
+ gnc_numeric dst_amt, dst_val, target_val;
+ gnc_numeric frac, delta;
+ int scu;
- /* Skip the reference split */
- if (s == split) continue;
+ /* Skip the reference split */
+ if (s == split) continue;
- scu = gnc_commodity_get_fraction (txn->common_currency);
+ scu = gnc_commodity_get_fraction (txn->common_currency);
- dst_amt = xaccSplitGetAmount (s);
- dst_val = xaccSplitGetValue (s);
- frac = gnc_numeric_div (dst_amt, src_amt,
- GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
- target_val = gnc_numeric_mul (frac, src_val,
- scu, GNC_HOW_DENOM_EXACT|GNC_HOW_RND_ROUND);
- if (gnc_numeric_check (target_val))
- {
- PERR ("Numeric overflow of value\n"
- "\tAcct=%s txn=%s\n"
- "\tdst_amt=%s src_val=%s src_amt=%s\n",
- xaccAccountGetName (s->acc),
- xaccTransGetDescription(txn),
- gnc_num_dbg_to_string(dst_amt),
- gnc_num_dbg_to_string(src_val),
- gnc_num_dbg_to_string(src_amt));
- continue;
- }
+ dst_amt = xaccSplitGetAmount (s);
+ dst_val = xaccSplitGetValue (s);
+ frac = gnc_numeric_div (dst_amt, src_amt,
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
+ target_val = gnc_numeric_mul (frac, src_val,
+ scu, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND);
+ if (gnc_numeric_check (target_val))
+ {
+ PERR ("Numeric overflow of value\n"
+ "\tAcct=%s txn=%s\n"
+ "\tdst_amt=%s src_val=%s src_amt=%s\n",
+ xaccAccountGetName (s->acc),
+ xaccTransGetDescription(txn),
+ gnc_num_dbg_to_string(dst_amt),
+ gnc_num_dbg_to_string(src_val),
+ gnc_num_dbg_to_string(src_amt));
+ continue;
+ }
- /* If the required price changes are 'small', do nothing.
- * That is a case that the user will have to deal with
- * manually. This routine is really intended only for
- * a gross level of synchronization.
- */
- delta = gnc_numeric_sub_fixed (target_val, dst_val);
- delta = gnc_numeric_abs (delta);
- if (maxmult * delta.num < delta.denom) continue;
+ /* If the required price changes are 'small', do nothing.
+ * That is a case that the user will have to deal with
+ * manually. This routine is really intended only for
+ * a gross level of synchronization.
+ */
+ delta = gnc_numeric_sub_fixed (target_val, dst_val);
+ delta = gnc_numeric_abs (delta);
+ if (maxmult * delta.num < delta.denom) continue;
- /* If the amount is small, pass on that too */
- if ((-maxamtscu < dst_amt.num) && (dst_amt.num < maxamtscu)) continue;
+ /* If the amount is small, pass on that too */
+ if ((-maxamtscu < dst_amt.num) && (dst_amt.num < maxamtscu)) continue;
- /* Make the actual adjustment */
- xaccTransBeginEdit (txn);
- xaccSplitSetValue (s, target_val);
- xaccTransCommitEdit (txn);
- }
- LEAVE (" ");
+ /* Make the actual adjustment */
+ xaccTransBeginEdit (txn);
+ xaccSplitSetValue (s, target_val);
+ xaccTransCommitEdit (txn);
+ }
+ LEAVE (" ");
}
/* ================================================================= */
-/* Remove the guid of b from a. Note that a may not contain the guid
+/* Remove the guid of b from a. Note that a may not contain the guid
* of b, (and v.v.) in which case, it will contain other guids which
* establish the links. So merge them back in. */
static void
remove_guids (Split *sa, Split *sb)
{
- KvpFrame *ksub;
+ KvpFrame *ksub;
- /* Find and remove the matching guid's */
- ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sa->inst.kvp_data, "lot-split",
- "peer_guid", qof_instance_get_guid(sb));
- if (ksub)
- {
- gnc_kvp_bag_remove_frame (sa->inst.kvp_data, "lot-split", ksub);
- kvp_frame_delete (ksub);
- }
+ /* Find and remove the matching guid's */
+ ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sa->inst.kvp_data, "lot-split",
+ "peer_guid", qof_instance_get_guid(sb));
+ if (ksub)
+ {
+ gnc_kvp_bag_remove_frame (sa->inst.kvp_data, "lot-split", ksub);
+ kvp_frame_delete (ksub);
+ }
- /* Now do it in the other direction */
- ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sb->inst.kvp_data, "lot-split",
- "peer_guid", qof_instance_get_guid(sa));
- if (ksub)
- {
- gnc_kvp_bag_remove_frame (sb->inst.kvp_data, "lot-split", ksub);
- kvp_frame_delete (ksub);
- }
+ /* Now do it in the other direction */
+ ksub = (KvpFrame*)gnc_kvp_bag_find_by_guid (sb->inst.kvp_data, "lot-split",
+ "peer_guid", qof_instance_get_guid(sa));
+ if (ksub)
+ {
+ gnc_kvp_bag_remove_frame (sb->inst.kvp_data, "lot-split", ksub);
+ kvp_frame_delete (ksub);
+ }
- /* Finally, merge b's lot-splits, if any, into a's */
- /* This is an important step, if it got busted into many pieces. */
- gnc_kvp_bag_merge (sa->inst.kvp_data, "lot-split",
- sb->inst.kvp_data, "lot-split");
+ /* Finally, merge b's lot-splits, if any, into a's */
+ /* This is an important step, if it got busted into many pieces. */
+ gnc_kvp_bag_merge (sa->inst.kvp_data, "lot-split",
+ sb->inst.kvp_data, "lot-split");
}
-/* The merge_splits() routine causes the amount & value of sb
+/* The merge_splits() routine causes the amount & value of sb
* to be merged into sa; it then destroys sb. It also performs
* some other misc cleanup */
static void
merge_splits (Split *sa, Split *sb)
{
- Account *act;
- Transaction *txn;
- gnc_numeric amt, val;
+ Account *act;
+ Transaction *txn;
+ gnc_numeric amt, val;
- act = xaccSplitGetAccount (sb);
- xaccAccountBeginEdit (act);
+ act = xaccSplitGetAccount (sb);
+ xaccAccountBeginEdit (act);
- txn = sa->parent;
- xaccTransBeginEdit (txn);
+ txn = sa->parent;
+ xaccTransBeginEdit (txn);
- /* Remove the guid of sb from the 'gemini' of sa */
- remove_guids (sa, sb);
+ /* Remove the guid of sb from the 'gemini' of sa */
+ remove_guids (sa, sb);
- /* Add amount of sb into sa, ditto for value. */
- amt = xaccSplitGetAmount (sa);
- amt = gnc_numeric_add_fixed (amt, xaccSplitGetAmount (sb));
- xaccSplitSetAmount (sa, amt);
+ /* Add amount of sb into sa, ditto for value. */
+ amt = xaccSplitGetAmount (sa);
+ amt = gnc_numeric_add_fixed (amt, xaccSplitGetAmount (sb));
+ xaccSplitSetAmount (sa, amt);
- val = xaccSplitGetValue (sa);
- val = gnc_numeric_add_fixed (val, xaccSplitGetValue (sb));
- xaccSplitSetValue (sa, val);
+ val = xaccSplitGetValue (sa);
+ val = gnc_numeric_add_fixed (val, xaccSplitGetValue (sb));
+ xaccSplitSetValue (sa, val);
- /* Set reconcile to no; after this much violence,
- * no way its reconciled. */
- xaccSplitSetReconcile (sa, NREC);
+ /* Set reconcile to no; after this much violence,
+ * no way its reconciled. */
+ xaccSplitSetReconcile (sa, NREC);
- /* If sb has associated gains splits, trash them. */
- if ((sb->gains_split) &&
- (sb->gains_split->gains & GAINS_STATUS_GAINS))
- {
- Transaction *t = sb->gains_split->parent;
- xaccTransBeginEdit (t);
- xaccTransDestroy (t);
- xaccTransCommitEdit (t);
- }
+ /* If sb has associated gains splits, trash them. */
+ if ((sb->gains_split) &&
+ (sb->gains_split->gains & GAINS_STATUS_GAINS))
+ {
+ Transaction *t = sb->gains_split->parent;
+ xaccTransBeginEdit (t);
+ xaccTransDestroy (t);
+ xaccTransCommitEdit (t);
+ }
- /* Finally, delete sb */
- xaccSplitDestroy(sb);
+ /* Finally, delete sb */
+ xaccSplitDestroy(sb);
- xaccTransCommitEdit (txn);
- xaccAccountCommitEdit (act);
+ xaccTransCommitEdit (txn);
+ xaccAccountCommitEdit (act);
}
-gboolean
+gboolean
xaccScrubMergeSubSplits (Split *split)
{
- gboolean rc = FALSE;
- Transaction *txn;
- SplitList *node;
- GNCLot *lot;
- const GUID *guid;
+ gboolean rc = FALSE;
+ Transaction *txn;
+ SplitList *node;
+ GNCLot *lot;
+ const GUID *guid;
- if (FALSE == is_subsplit (split)) return FALSE;
+ if (FALSE == is_subsplit (split)) return FALSE;
- txn = split->parent;
- lot = xaccSplitGetLot (split);
+ txn = split->parent;
+ lot = xaccSplitGetLot (split);
- ENTER ("(Lot=%s)", gnc_lot_get_title(lot));
+ ENTER ("(Lot=%s)", gnc_lot_get_title(lot));
restart:
- for (node=txn->splits; node; node=node->next)
- {
- Split *s = node->data;
- if (xaccSplitGetLot (s) != lot) continue;
- if (s == split) continue;
- if (qof_instance_get_destroying(s)) continue;
+ for (node = txn->splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ if (xaccSplitGetLot (s) != lot) continue;
+ if (s == split) continue;
+ if (qof_instance_get_destroying(s)) continue;
- /* OK, this split is in the same lot (and thus same account)
- * as the indicated split. Make sure it is really a subsplit
- * of the split we started with. It's possible to have two
- * splits in the same lot and transaction that are not subsplits
- * of each other, the test-period test suite does this, for
- * example. Only worry about adjacent sub-splits. By
- * repeatedly merging adjacent subsplits, we'll get the non-
- * adjacent ones too. */
- guid = qof_instance_get_guid(s);
- if (gnc_kvp_bag_find_by_guid (split->inst.kvp_data, "lot-split",
- "peer_guid", guid) == NULL)
- continue;
-
- merge_splits (split, s);
- rc = TRUE;
- goto restart;
- }
- if (gnc_numeric_zero_p (split->amount))
- {
- PWARN ("Result of merge has zero amt!");
- }
- LEAVE (" splits merged=%d", rc);
- return rc;
+ /* OK, this split is in the same lot (and thus same account)
+ * as the indicated split. Make sure it is really a subsplit
+ * of the split we started with. It's possible to have two
+ * splits in the same lot and transaction that are not subsplits
+ * of each other, the test-period test suite does this, for
+ * example. Only worry about adjacent sub-splits. By
+ * repeatedly merging adjacent subsplits, we'll get the non-
+ * adjacent ones too. */
+ guid = qof_instance_get_guid(s);
+ if (gnc_kvp_bag_find_by_guid (split->inst.kvp_data, "lot-split",
+ "peer_guid", guid) == NULL)
+ continue;
+
+ merge_splits (split, s);
+ rc = TRUE;
+ goto restart;
+ }
+ if (gnc_numeric_zero_p (split->amount))
+ {
+ PWARN ("Result of merge has zero amt!");
+ }
+ LEAVE (" splits merged=%d", rc);
+ return rc;
}
-gboolean
+gboolean
xaccScrubMergeTransSubSplits (Transaction *txn)
{
- gboolean rc = FALSE;
- SplitList *node;
+ gboolean rc = FALSE;
+ SplitList *node;
- if (!txn) return FALSE;
+ if (!txn) return FALSE;
- ENTER (" ");
+ ENTER (" ");
restart:
- for (node=txn->splits; node; node=node->next)
- {
- Split *s = node->data;
- if (!xaccScrubMergeSubSplits(s)) continue;
+ for (node = txn->splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ if (!xaccScrubMergeSubSplits(s)) continue;
- rc = TRUE;
- goto restart;
- }
- LEAVE (" splits merged=%d", rc);
- return rc;
+ rc = TRUE;
+ goto restart;
+ }
+ LEAVE (" splits merged=%d", rc);
+ return rc;
}
-gboolean
+gboolean
xaccScrubMergeLotSubSplits (GNCLot *lot)
{
- gboolean rc = FALSE;
- SplitList *node;
+ gboolean rc = FALSE;
+ SplitList *node;
- if (!lot) return FALSE;
+ if (!lot) return FALSE;
- ENTER (" ");
+ ENTER (" ");
restart:
- for (node=gnc_lot_get_split_list(lot); node; node=node->next)
- {
- Split *s = node->data;
- if (!xaccScrubMergeSubSplits(s)) continue;
+ for (node = gnc_lot_get_split_list(lot); node; node = node->next)
+ {
+ Split *s = node->data;
+ if (!xaccScrubMergeSubSplits(s)) continue;
- rc = TRUE;
- goto restart;
- }
- LEAVE (" splits merged=%d", rc);
- return rc;
+ rc = TRUE;
+ goto restart;
+ }
+ LEAVE (" splits merged=%d", rc);
+ return rc;
}
/* =========================== END OF FILE ======================= */
Modified: gnucash/trunk/src/engine/Scrub3.c
===================================================================
--- gnucash/trunk/src/engine/Scrub3.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Scrub3.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -26,7 +26,7 @@
*
* Provides a set of functions and utilities for checking and
* repairing ('scrubbing clean') the usage of Cap Gains
- * transactions in stock and commodity accounts.
+ * transactions in stock and commodity accounts.
*/
#include "config.h"
@@ -58,21 +58,21 @@
static inline gboolean
gains_possible (GNCLot *lot)
{
- SplitList *node;
- Account *acc;
- Split *split;
- gboolean comeq;
- gnc_commodity *acc_commodity;
+ SplitList *node;
+ Account *acc;
+ Split *split;
+ gboolean comeq;
+ gnc_commodity *acc_commodity;
- acc = gnc_lot_get_account (lot);
+ acc = gnc_lot_get_account (lot);
- node = gnc_lot_get_split_list (lot);
- if (!node) return FALSE;
- split = node->data;
+ node = gnc_lot_get_split_list (lot);
+ if (!node) return FALSE;
+ split = node->data;
- acc_commodity = xaccAccountGetCommodity(acc);
- comeq = gnc_commodity_equiv (acc_commodity, split->parent->common_currency);
- return (FALSE == comeq);
+ acc_commodity = xaccAccountGetCommodity(acc);
+ comeq = gnc_commodity_equiv (acc_commodity, split->parent->common_currency);
+ return (FALSE == comeq);
}
/* ================================================================= */
@@ -84,73 +84,73 @@
gboolean
xaccScrubLot (GNCLot *lot)
{
- gboolean splits_deleted = FALSE;
- gnc_numeric lot_baln;
- gboolean opening_baln_is_pos, lot_baln_is_pos;
- Account *acc;
- GNCPolicy *pcy;
+ gboolean splits_deleted = FALSE;
+ gnc_numeric lot_baln;
+ gboolean opening_baln_is_pos, lot_baln_is_pos;
+ Account *acc;
+ GNCPolicy *pcy;
- if (!lot) return FALSE;
- ENTER ("(lot=%p) %s", lot, gnc_lot_get_title(lot));
+ if (!lot) return FALSE;
+ ENTER ("(lot=%p) %s", lot, gnc_lot_get_title(lot));
- acc = gnc_lot_get_account (lot);
- pcy = gnc_account_get_policy(acc);
- xaccAccountBeginEdit(acc);
- xaccScrubMergeLotSubSplits (lot);
+ acc = gnc_lot_get_account (lot);
+ pcy = gnc_account_get_policy(acc);
+ xaccAccountBeginEdit(acc);
+ xaccScrubMergeLotSubSplits (lot);
- /* If the lot balance is zero, we don't need to rebalance */
- lot_baln = gnc_lot_get_balance (lot);
- PINFO ("lot baln=%s for %s", gnc_num_dbg_to_string (lot_baln),
- gnc_lot_get_title(lot));
- if (! gnc_numeric_zero_p (lot_baln))
- {
- SplitList *node;
- gnc_numeric opening_baln;
+ /* If the lot balance is zero, we don't need to rebalance */
+ lot_baln = gnc_lot_get_balance (lot);
+ PINFO ("lot baln=%s for %s", gnc_num_dbg_to_string (lot_baln),
+ gnc_lot_get_title(lot));
+ if (! gnc_numeric_zero_p (lot_baln))
+ {
+ SplitList *node;
+ gnc_numeric opening_baln;
- /* Get the opening balance for this lot */
- pcy->PolicyGetLotOpening (pcy, lot, &opening_baln, NULL, NULL);
- PINFO ("lot opener baln=%s", gnc_num_dbg_to_string (opening_baln));
+ /* Get the opening balance for this lot */
+ pcy->PolicyGetLotOpening (pcy, lot, &opening_baln, NULL, NULL);
+ PINFO ("lot opener baln=%s", gnc_num_dbg_to_string (opening_baln));
- /* If the lot is fat, give the boot to all the non-opening
- * splits, and refill it */
- opening_baln_is_pos = gnc_numeric_positive_p(opening_baln);
- lot_baln_is_pos = gnc_numeric_positive_p(lot_baln);
- if ((opening_baln_is_pos || lot_baln_is_pos) &&
- ((!opening_baln_is_pos) || (!lot_baln_is_pos)))
- {
+ /* If the lot is fat, give the boot to all the non-opening
+ * splits, and refill it */
+ opening_baln_is_pos = gnc_numeric_positive_p(opening_baln);
+ lot_baln_is_pos = gnc_numeric_positive_p(lot_baln);
+ if ((opening_baln_is_pos || lot_baln_is_pos) &&
+ ((!opening_baln_is_pos) || (!lot_baln_is_pos)))
+ {
rethin:
- for (node=gnc_lot_get_split_list(lot); node; node=node->next)
- {
- Split *s = node->data;
- if (pcy->PolicyIsOpeningSplit (pcy, lot, s)) continue;
- gnc_lot_remove_split (lot, s);
- goto rethin;
- }
- }
+ for (node = gnc_lot_get_split_list(lot); node; node = node->next)
+ {
+ Split *s = node->data;
+ if (pcy->PolicyIsOpeningSplit (pcy, lot, s)) continue;
+ gnc_lot_remove_split (lot, s);
+ goto rethin;
+ }
+ }
- /* At this point the lot is thin, so try to fill it */
- xaccLotFill (lot);
+ /* At this point the lot is thin, so try to fill it */
+ xaccLotFill (lot);
- /* Make sure there are no subsplits. */
- splits_deleted = xaccScrubMergeLotSubSplits (lot);
- }
+ /* Make sure there are no subsplits. */
+ splits_deleted = xaccScrubMergeLotSubSplits (lot);
+ }
- /* Now re-compute cap gains, and then double-check that.
- * But we only compute cap-gains if gains are possible;
- * that is if the lot commodity is not the same as the
- * currency. That is, one can't possibly have gains
- * selling dollars for dollars. The business modules
- * use lots with lot commodity == lot currency.
- */
- if (gains_possible (lot))
- {
- xaccLotComputeCapGains (lot, NULL);
- xaccLotScrubDoubleBalance (lot);
- }
- xaccAccountCommitEdit(acc);
+ /* Now re-compute cap gains, and then double-check that.
+ * But we only compute cap-gains if gains are possible;
+ * that is if the lot commodity is not the same as the
+ * currency. That is, one can't possibly have gains
+ * selling dollars for dollars. The business modules
+ * use lots with lot commodity == lot currency.
+ */
+ if (gains_possible (lot))
+ {
+ xaccLotComputeCapGains (lot, NULL);
+ xaccLotScrubDoubleBalance (lot);
+ }
+ xaccAccountCommitEdit(acc);
- LEAVE ("(lot=%s, deleted=%d)", gnc_lot_get_title(lot), splits_deleted);
- return splits_deleted;
+ LEAVE ("(lot=%s, deleted=%d)", gnc_lot_get_title(lot), splits_deleted);
+ return splits_deleted;
}
/* ============================================================== */
@@ -158,23 +158,23 @@
void
xaccAccountScrubLots (Account *acc)
{
- LotList *lots, *node;
- if (!acc) return;
- if (FALSE == xaccAccountHasTrades (acc)) return;
-
- ENTER ("(acc=%s)", xaccAccountGetName(acc));
- xaccAccountBeginEdit(acc);
- xaccAccountAssignLots (acc);
+ LotList *lots, *node;
+ if (!acc) return;
+ if (FALSE == xaccAccountHasTrades (acc)) return;
- lots = xaccAccountGetLotList(acc);
- for (node = lots; node; node=node->next)
- {
- GNCLot *lot = node->data;
- xaccScrubLot (lot);
- }
- g_list_free(lots);
- xaccAccountCommitEdit(acc);
- LEAVE ("(acc=%s)", xaccAccountGetName(acc));
+ ENTER ("(acc=%s)", xaccAccountGetName(acc));
+ xaccAccountBeginEdit(acc);
+ xaccAccountAssignLots (acc);
+
+ lots = xaccAccountGetLotList(acc);
+ for (node = lots; node; node = node->next)
+ {
+ GNCLot *lot = node->data;
+ xaccScrubLot (lot);
+ }
+ g_list_free(lots);
+ xaccAccountCommitEdit(acc);
+ LEAVE ("(acc=%s)", xaccAccountGetName(acc));
}
/* ============================================================== */
@@ -182,17 +182,17 @@
static void
lot_scrub_cb (Account *acc, gpointer data)
{
- if (FALSE == xaccAccountHasTrades (acc)) return;
- xaccAccountScrubLots (acc);
+ if (FALSE == xaccAccountHasTrades (acc)) return;
+ xaccAccountScrubLots (acc);
}
-void
+void
xaccAccountTreeScrubLots (Account *acc)
{
- if (!acc) return;
+ if (!acc) return;
- gnc_account_foreach_descendant(acc, lot_scrub_cb, NULL);
- xaccAccountScrubLots (acc);
+ gnc_account_foreach_descendant(acc, lot_scrub_cb, NULL);
+ xaccAccountScrubLots (acc);
}
/* ========================== END OF FILE ========================= */
Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Split.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -59,16 +59,17 @@
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_ENGINE;
-enum {
+enum
+{
PROP_0,
- PROP_ACTION,
- PROP_MEMO,
- PROP_VALUE,
- PROP_AMOUNT,
- PROP_RECONCILE_DATE,
- PROP_TX,
- PROP_ACCOUNT,
- PROP_LOT
+ PROP_ACTION,
+ PROP_MEMO,
+ PROP_VALUE,
+ PROP_AMOUNT,
+ PROP_RECONCILE_DATE,
+ PROP_TX,
+ PROP_ACCOUNT,
+ PROP_LOT
};
/* GObject Initialization */
@@ -77,27 +78,27 @@
static void
gnc_split_init(Split* split)
{
- /* fill in some sane defaults */
- split->acc = NULL;
- split->orig_acc = NULL;
- split->parent = NULL;
- split->lot = NULL;
+ /* fill in some sane defaults */
+ split->acc = NULL;
+ split->orig_acc = NULL;
+ split->parent = NULL;
+ split->lot = NULL;
- split->action = CACHE_INSERT("");
- split->memo = CACHE_INSERT("");
- split->reconciled = NREC;
- split->amount = gnc_numeric_zero();
- split->value = gnc_numeric_zero();
+ split->action = CACHE_INSERT("");
+ split->memo = CACHE_INSERT("");
+ split->reconciled = NREC;
+ split->amount = gnc_numeric_zero();
+ split->value = gnc_numeric_zero();
- split->date_reconciled.tv_sec = 0;
- split->date_reconciled.tv_nsec = 0;
+ split->date_reconciled.tv_sec = 0;
+ split->date_reconciled.tv_nsec = 0;
- split->balance = gnc_numeric_zero();
- split->cleared_balance = gnc_numeric_zero();
- split->reconciled_balance = gnc_numeric_zero();
+ split->balance = gnc_numeric_zero();
+ split->cleared_balance = gnc_numeric_zero();
+ split->reconciled_balance = gnc_numeric_zero();
- split->gains = GAINS_STATUS_UNKNOWN;
- split->gains_split = NULL;
+ split->gains = GAINS_STATUS_UNKNOWN;
+ split->gains_split = NULL;
}
static void
@@ -114,89 +115,91 @@
static void
gnc_split_get_property(GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
Split *split;
g_return_if_fail(GNC_IS_SPLIT(object));
split = GNC_SPLIT(object);
- switch (prop_id) {
- case PROP_ACTION:
- g_value_set_string(value, split->action);
- break;
- case PROP_MEMO:
- g_value_set_string(value, split->memo);
- break;
- case PROP_VALUE:
- g_value_set_boxed(value, &split->value);
- break;
- case PROP_AMOUNT:
- g_value_set_boxed(value, &split->amount);
- break;
- case PROP_RECONCILE_DATE:
- g_value_set_boxed(value, &split->date_reconciled);
- break;
- case PROP_TX:
- g_value_set_object(value, split->parent);
- break;
- case PROP_ACCOUNT:
- g_value_set_object(value, split->acc);
- break;
- case PROP_LOT:
- g_value_set_object(value, split->lot);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
+ switch (prop_id)
+ {
+ case PROP_ACTION:
+ g_value_set_string(value, split->action);
+ break;
+ case PROP_MEMO:
+ g_value_set_string(value, split->memo);
+ break;
+ case PROP_VALUE:
+ g_value_set_boxed(value, &split->value);
+ break;
+ case PROP_AMOUNT:
+ g_value_set_boxed(value, &split->amount);
+ break;
+ case PROP_RECONCILE_DATE:
+ g_value_set_boxed(value, &split->date_reconciled);
+ break;
+ case PROP_TX:
+ g_value_set_object(value, split->parent);
+ break;
+ case PROP_ACCOUNT:
+ g_value_set_object(value, split->acc);
+ break;
+ case PROP_LOT:
+ g_value_set_object(value, split->lot);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
}
static void
gnc_split_set_property(GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
Split *split;
- gnc_numeric* number;
+ gnc_numeric* number;
g_return_if_fail(GNC_IS_SPLIT(object));
split = GNC_SPLIT(object);
- switch (prop_id) {
- case PROP_ACTION:
- xaccSplitSetAction(split, g_value_get_string(value));
- break;
- case PROP_MEMO:
- xaccSplitSetMemo(split, g_value_get_string(value));
- break;
- case PROP_VALUE:
- number = g_value_get_boxed(value);
- xaccSplitSetValue(split, *number);
- break;
- case PROP_AMOUNT:
- number = g_value_get_boxed(value);
- xaccSplitSetAmount(split, *number);
- break;
- case PROP_RECONCILE_DATE:
- xaccSplitSetDateReconciledTS(split, g_value_get_boxed(value));
- break;
- case PROP_TX:
- xaccSplitSetParent(split, g_value_get_object(value));
- break;
- case PROP_ACCOUNT:
- xaccSplitSetAccount(split, g_value_get_object(value));
- break;
- case PROP_LOT:
- xaccSplitSetLot(split, g_value_get_object(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
+ switch (prop_id)
+ {
+ case PROP_ACTION:
+ xaccSplitSetAction(split, g_value_get_string(value));
+ break;
+ case PROP_MEMO:
+ xaccSplitSetMemo(split, g_value_get_string(value));
+ break;
+ case PROP_VALUE:
+ number = g_value_get_boxed(value);
+ xaccSplitSetValue(split, *number);
+ break;
+ case PROP_AMOUNT:
+ number = g_value_get_boxed(value);
+ xaccSplitSetAmount(split, *number);
+ break;
+ case PROP_RECONCILE_DATE:
+ xaccSplitSetDateReconciledTS(split, g_value_get_boxed(value));
+ break;
+ case PROP_TX:
+ xaccSplitSetParent(split, g_value_get_object(value));
+ break;
+ case PROP_ACCOUNT:
+ xaccSplitSetAccount(split, g_value_get_object(value));
+ break;
+ case PROP_LOT:
+ xaccSplitSetLot(split, g_value_get_object(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
}
static void
@@ -209,87 +212,87 @@
gobject_class->set_property = gnc_split_set_property;
gobject_class->get_property = gnc_split_get_property;
- g_object_class_install_property
- (gobject_class,
- PROP_ACTION,
- g_param_spec_string("action",
- "Action",
- "The action is an arbitrary string assigned "
- "by the user. It is intended to be a short "
- "string that contains extra information about "
- "this split.",
- NULL,
- G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class,
+ PROP_ACTION,
+ g_param_spec_string("action",
+ "Action",
+ "The action is an arbitrary string assigned "
+ "by the user. It is intended to be a short "
+ "string that contains extra information about "
+ "this split.",
+ NULL,
+ G_PARAM_READWRITE));
- g_object_class_install_property
- (gobject_class,
- PROP_MEMO,
- g_param_spec_string("memo",
- "Memo",
- "The action is an arbitrary string assigned "
- "by the user. It is intended to be a short "
- "string that describes the purpose of "
- "this split.",
- NULL,
- G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class,
+ PROP_MEMO,
+ g_param_spec_string("memo",
+ "Memo",
+ "The action is an arbitrary string assigned "
+ "by the user. It is intended to be a short "
+ "string that describes the purpose of "
+ "this split.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_VALUE,
- g_param_spec_boxed("value",
- "Split Value",
- "The value for this split in the common currency. "
- "The value and the amount provide enough information to "
- "calculate a conversion rate.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_VALUE,
+ g_param_spec_boxed("value",
+ "Split Value",
+ "The value for this split in the common currency. "
+ "The value and the amount provide enough information to "
+ "calculate a conversion rate.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_AMOUNT,
- g_param_spec_boxed("amount",
- "Split Amount",
- "The value for this split in the currency of its account. "
- "The value and the amount provide enough information to "
- "calculate a conversion rate.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_AMOUNT,
+ g_param_spec_boxed("amount",
+ "Split Amount",
+ "The value for this split in the currency of its account. "
+ "The value and the amount provide enough information to "
+ "calculate a conversion rate.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_RECONCILE_DATE,
- g_param_spec_boxed("reconcile-date",
- "Reconcile Date",
- "The date this split was reconciled.",
- GNC_TYPE_TIMESPEC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_RECONCILE_DATE,
+ g_param_spec_boxed("reconcile-date",
+ "Reconcile Date",
+ "The date this split was reconciled.",
+ GNC_TYPE_TIMESPEC,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_TX,
- g_param_spec_object ("transaction",
- "Transaction",
- "The transaction that this split belongs to.",
- GNC_TYPE_TRANSACTION,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_TX,
+ g_param_spec_object ("transaction",
+ "Transaction",
+ "The transaction that this split belongs to.",
+ GNC_TYPE_TRANSACTION,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_ACCOUNT,
- g_param_spec_object ("account",
- "Account",
- "The account that this split belongs to.",
- GNC_TYPE_ACCOUNT,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_ACCOUNT,
+ g_param_spec_object ("account",
+ "Account",
+ "The account that this split belongs to.",
+ GNC_TYPE_ACCOUNT,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_LOT,
- g_param_spec_object ("lot",
- "Lot",
- "The lot that this split belongs to.",
- GNC_TYPE_LOT,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_LOT,
+ g_param_spec_object ("lot",
+ "Lot",
+ "The lot that this split belongs to.",
+ GNC_TYPE_LOT,
+ G_PARAM_READWRITE));
}
/********************************************************************\
@@ -300,38 +303,38 @@
static void
xaccInitSplit(Split * split, QofBook *book)
{
- qof_instance_init_data(&split->inst, GNC_ID_SPLIT, book);
+ qof_instance_init_data(&split->inst, GNC_ID_SPLIT, book);
}
void
xaccSplitReinit(Split * split)
{
- /* fill in some sane defaults */
- split->acc = NULL;
- split->orig_acc = NULL;
- split->parent = NULL;
- split->lot = NULL;
+ /* fill in some sane defaults */
+ split->acc = NULL;
+ split->orig_acc = NULL;
+ split->parent = NULL;
+ split->lot = NULL;
- CACHE_REPLACE(split->action, "");
- CACHE_REPLACE(split->memo, "");
- split->reconciled = NREC;
- split->amount = gnc_numeric_zero();
- split->value = gnc_numeric_zero();
+ CACHE_REPLACE(split->action, "");
+ CACHE_REPLACE(split->memo, "");
+ split->reconciled = NREC;
+ split->amount = gnc_numeric_zero();
+ split->value = gnc_numeric_zero();
- split->date_reconciled.tv_sec = 0;
- split->date_reconciled.tv_nsec = 0;
+ split->date_reconciled.tv_sec = 0;
+ split->date_reconciled.tv_nsec = 0;
- split->balance = gnc_numeric_zero();
- split->cleared_balance = gnc_numeric_zero();
- split->reconciled_balance = gnc_numeric_zero();
+ split->balance = gnc_numeric_zero();
+ split->cleared_balance = gnc_numeric_zero();
+ split->reconciled_balance = gnc_numeric_zero();
- if (split->inst.kvp_data)
- kvp_frame_delete(split->inst.kvp_data);
- split->inst.kvp_data = kvp_frame_new();
- qof_instance_set_idata(split, 0);
+ if (split->inst.kvp_data)
+ kvp_frame_delete(split->inst.kvp_data);
+ split->inst.kvp_data = kvp_frame_new();
+ qof_instance_set_idata(split, 0);
- split->gains = GAINS_STATUS_UNKNOWN;
- split->gains_split = NULL;
+ split->gains = GAINS_STATUS_UNKNOWN;
+ split->gains_split = NULL;
}
/********************************************************************\
@@ -340,19 +343,19 @@
Split *
xaccMallocSplit(QofBook *book)
{
- Split *split;
- g_return_val_if_fail (book, NULL);
+ Split *split;
+ g_return_val_if_fail (book, NULL);
- split = g_object_new (GNC_TYPE_SPLIT, NULL);
- xaccInitSplit (split, book);
+ split = g_object_new (GNC_TYPE_SPLIT, NULL);
+ xaccInitSplit (split, book);
- return split;
+ return split;
}
/********************************************************************\
\********************************************************************/
-/* This routine is not exposed externally, since it does weird things,
- * like not really setting up the parent account correctly, and ditto
+/* This routine is not exposed externally, since it does weird things,
+ * like not really setting up the parent account correctly, and ditto
* the parent transaction. This routine is prone to programmer error
* if not used correctly. It is used only by the edit-rollback code.
* Don't get duped!
@@ -361,99 +364,100 @@
Split *
xaccDupeSplit (const Split *s)
{
- Split *split = g_object_new (GNC_TYPE_SPLIT, NULL);
+ Split *split = g_object_new (GNC_TYPE_SPLIT, NULL);
- /* Trash the entity table. We don't want to mistake the cloned
- * splits as something official. If we ever use this split, we'll
- * have to fix this up.
- */
- split->inst.e_type = NULL;
- qof_instance_copy_guid(split, s);
- qof_instance_copy_book(split, s);
+ /* Trash the entity table. We don't want to mistake the cloned
+ * splits as something official. If we ever use this split, we'll
+ * have to fix this up.
+ */
+ split->inst.e_type = NULL;
+ qof_instance_copy_guid(split, s);
+ qof_instance_copy_book(split, s);
- split->parent = s->parent;
- split->acc = s->acc;
- split->orig_acc = s->orig_acc;
- split->lot = s->lot;
+ split->parent = s->parent;
+ split->acc = s->acc;
+ split->orig_acc = s->orig_acc;
+ split->lot = s->lot;
- split->memo = CACHE_INSERT(s->memo);
- split->action = CACHE_INSERT(s->action);
+ split->memo = CACHE_INSERT(s->memo);
+ split->action = CACHE_INSERT(s->action);
- split->inst.kvp_data = kvp_frame_copy (s->inst.kvp_data);
+ split->inst.kvp_data = kvp_frame_copy (s->inst.kvp_data);
- split->reconciled = s->reconciled;
- split->date_reconciled = s->date_reconciled;
+ split->reconciled = s->reconciled;
+ split->date_reconciled = s->date_reconciled;
- split->value = s->value;
- split->amount = s->amount;
+ split->value = s->value;
+ split->amount = s->amount;
- /* no need to futz with the balances; these get wiped each time ...
- * split->balance = s->balance;
- * split->cleared_balance = s->cleared_balance;
- * split->reconciled_balance = s->reconciled_balance;
- */
+ /* no need to futz with the balances; these get wiped each time ...
+ * split->balance = s->balance;
+ * split->cleared_balance = s->cleared_balance;
+ * split->reconciled_balance = s->reconciled_balance;
+ */
- return split;
+ return split;
}
Split *
xaccSplitClone (const Split *s)
{
- Split *split = g_object_new (GNC_TYPE_SPLIT, NULL);
+ Split *split = g_object_new (GNC_TYPE_SPLIT, NULL);
- split->parent = NULL;
- split->memo = CACHE_INSERT(s->memo);
- split->action = CACHE_INSERT(s->action);
- split->reconciled = s->reconciled;
- split->date_reconciled = s->date_reconciled;
- split->value = s->value;
- split->amount = s->amount;
- split->balance = s->balance;
- split->cleared_balance = s->cleared_balance;
- split->reconciled_balance = s->reconciled_balance;
+ split->parent = NULL;
+ split->memo = CACHE_INSERT(s->memo);
+ split->action = CACHE_INSERT(s->action);
+ split->reconciled = s->reconciled;
+ split->date_reconciled = s->date_reconciled;
+ split->value = s->value;
+ split->amount = s->amount;
+ split->balance = s->balance;
+ split->cleared_balance = s->cleared_balance;
+ split->reconciled_balance = s->reconciled_balance;
- split->gains = GAINS_STATUS_UNKNOWN;
- split->gains_split = NULL;
+ split->gains = GAINS_STATUS_UNKNOWN;
+ split->gains_split = NULL;
- qof_instance_init_data(&split->inst, GNC_ID_SPLIT, qof_instance_get_book(s));
- kvp_frame_delete(split->inst.kvp_data);
- split->inst.kvp_data = kvp_frame_copy(s->inst.kvp_data);
+ qof_instance_init_data(&split->inst, GNC_ID_SPLIT, qof_instance_get_book(s));
+ kvp_frame_delete(split->inst.kvp_data);
+ split->inst.kvp_data = kvp_frame_copy(s->inst.kvp_data);
- xaccAccountInsertSplit(s->acc, split);
- if (s->lot) {
- /* CHECKME: Is this right? */
- gnc_lot_add_split(s->lot, split);
- }
- return split;
+ xaccAccountInsertSplit(s->acc, split);
+ if (s->lot)
+ {
+ /* CHECKME: Is this right? */
+ gnc_lot_add_split(s->lot, split);
+ }
+ return split;
}
#ifdef DUMP_FUNCTIONS
void
xaccSplitDump (const Split *split, const char *tag)
{
- printf(" %s Split %p", tag, split);
- printf(" Book: %p\n", qof_instance_get_book(split));
- printf(" Account: %p (%s)\n", split->acc,
- split->acc ? xaccAccountGetName(split->acc) : "");
- printf(" Commod: %s\n",
- split->acc ?
- gnc_commodity_get_printname(xaccAccountGetCommodity(split->acc))
- : "");
- printf(" Lot: %p\n", split->lot);
- printf(" Parent: %p\n", split->parent);
- printf(" Gains: %p\n", split->gains_split);
- printf(" Memo: %s\n", split->memo ? split->memo : "(null)");
- printf(" Action: %s\n", split->action ? split->action : "(null)");
- printf(" KVP Data: %p\n", split->inst.kvp_data);
- printf(" Recncld: %c (date %s)\n", split->reconciled,
- gnc_print_date(split->date_reconciled));
- printf(" Value: %s\n", gnc_numeric_to_string(split->value));
- printf(" Amount: %s\n", gnc_numeric_to_string(split->amount));
- printf(" Balance: %s\n", gnc_numeric_to_string(split->balance));
- printf(" CBalance: %s\n", gnc_numeric_to_string(split->cleared_balance));
- printf(" RBalance: %s\n",
- gnc_numeric_to_string(split->reconciled_balance));
- printf(" idata: %x\n", qof_instance_get_idata(split));
+ printf(" %s Split %p", tag, split);
+ printf(" Book: %p\n", qof_instance_get_book(split));
+ printf(" Account: %p (%s)\n", split->acc,
+ split->acc ? xaccAccountGetName(split->acc) : "");
+ printf(" Commod: %s\n",
+ split->acc ?
+ gnc_commodity_get_printname(xaccAccountGetCommodity(split->acc))
+ : "");
+ printf(" Lot: %p\n", split->lot);
+ printf(" Parent: %p\n", split->parent);
+ printf(" Gains: %p\n", split->gains_split);
+ printf(" Memo: %s\n", split->memo ? split->memo : "(null)");
+ printf(" Action: %s\n", split->action ? split->action : "(null)");
+ printf(" KVP Data: %p\n", split->inst.kvp_data);
+ printf(" Recncld: %c (date %s)\n", split->reconciled,
+ gnc_print_date(split->date_reconciled));
+ printf(" Value: %s\n", gnc_numeric_to_string(split->value));
+ printf(" Amount: %s\n", gnc_numeric_to_string(split->amount));
+ printf(" Balance: %s\n", gnc_numeric_to_string(split->balance));
+ printf(" CBalance: %s\n", gnc_numeric_to_string(split->cleared_balance));
+ printf(" RBalance: %s\n",
+ gnc_numeric_to_string(split->reconciled_balance));
+ printf(" idata: %x\n", qof_instance_get_idata(split));
}
#endif
@@ -463,45 +467,46 @@
void
xaccFreeSplit (Split *split)
{
- if (!split) return;
+ if (!split) return;
- /* Debug double-free's */
- if (((char *) 1) == split->memo)
- {
- PERR ("double-free %p", split);
- return;
- }
- CACHE_REMOVE(split->memo);
- CACHE_REMOVE(split->action);
+ /* Debug double-free's */
+ if (((char *) 1) == split->memo)
+ {
+ PERR ("double-free %p", split);
+ return;
+ }
+ CACHE_REMOVE(split->memo);
+ CACHE_REMOVE(split->action);
- /* Just in case someone looks up freed memory ... */
- split->memo = (char *) 1;
- split->action = NULL;
- split->reconciled = NREC;
- split->amount = gnc_numeric_zero();
- split->value = gnc_numeric_zero();
- split->parent = NULL;
- split->lot = NULL;
- split->acc = NULL;
- split->orig_acc = NULL;
-
- split->date_reconciled.tv_sec = 0;
- split->date_reconciled.tv_nsec = 0;
+ /* Just in case someone looks up freed memory ... */
+ split->memo = (char *) 1;
+ split->action = NULL;
+ split->reconciled = NREC;
+ split->amount = gnc_numeric_zero();
+ split->value = gnc_numeric_zero();
+ split->parent = NULL;
+ split->lot = NULL;
+ split->acc = NULL;
+ split->orig_acc = NULL;
- // Is this right?
- if (split->gains_split) split->gains_split->gains_split = NULL;
- /* qof_instance_release(&split->inst); */
- g_object_unref(split);
+ split->date_reconciled.tv_sec = 0;
+ split->date_reconciled.tv_nsec = 0;
+
+ // Is this right?
+ if (split->gains_split) split->gains_split->gains_split = NULL;
+ /* qof_instance_release(&split->inst); */
+ g_object_unref(split);
}
void mark_split (Split *s)
{
- if (s->acc) {
- g_object_set(s->acc, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
- }
+ if (s->acc)
+ {
+ g_object_set(s->acc, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
+ }
- /* set dirty flag on lot too. */
- if (s->lot) gnc_lot_set_closed_unknown(s->lot);
+ /* set dirty flag on lot too. */
+ if (s->lot) gnc_lot_set_closed_unknown(s->lot);
}
/*
@@ -510,20 +515,20 @@
static gboolean
xaccSplitEqualCheckBal (const char *tag, gnc_numeric a, gnc_numeric b)
{
- char *str_a, *str_b;
+ char *str_a, *str_b;
- if (gnc_numeric_equal (a, b))
- return TRUE;
+ if (gnc_numeric_equal (a, b))
+ return TRUE;
- str_a = gnc_numeric_to_string (a);
- str_b = gnc_numeric_to_string (b);
+ str_a = gnc_numeric_to_string (a);
+ str_b = gnc_numeric_to_string (b);
- PWARN ("%sbalances differ: %s vs %s", tag, str_a, str_b);
+ PWARN ("%sbalances differ: %s vs %s", tag, str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
+ return FALSE;
}
/********************************************************************
@@ -535,117 +540,119 @@
gboolean check_balances,
gboolean check_txn_splits)
{
- if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
+ if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
- if (!sa || !sb)
- {
- PWARN ("one is NULL");
- return FALSE;
- }
+ if (!sa || !sb)
+ {
+ PWARN ("one is NULL");
+ return FALSE;
+ }
- if (sa == sb) return TRUE;
+ if (sa == sb) return TRUE;
- if (check_guids) {
- if (qof_instance_guid_compare(sa, sb) != 0)
+ if (check_guids)
{
- PWARN ("GUIDs differ");
- return FALSE;
+ if (qof_instance_guid_compare(sa, sb) != 0)
+ {
+ PWARN ("GUIDs differ");
+ return FALSE;
+ }
}
- }
- /* Since these strings are cached we can just use pointer equality */
- if (sa->memo != sb->memo)
- {
- PWARN ("memos differ: (%p)%s vs (%p)%s",
- sa->memo, sa->memo, sb->memo, sb->memo);
- return FALSE;
- }
+ /* Since these strings are cached we can just use pointer equality */
+ if (sa->memo != sb->memo)
+ {
+ PWARN ("memos differ: (%p)%s vs (%p)%s",
+ sa->memo, sa->memo, sb->memo, sb->memo);
+ return FALSE;
+ }
- if (sa->action != sb->action)
- {
- PWARN ("actions differ: %s vs %s", sa->action, sb->action);
- return FALSE;
- }
+ if (sa->action != sb->action)
+ {
+ PWARN ("actions differ: %s vs %s", sa->action, sb->action);
+ return FALSE;
+ }
- if (kvp_frame_compare(sa->inst.kvp_data, sb->inst.kvp_data) != 0)
- {
- char *frame_a;
- char *frame_b;
+ if (kvp_frame_compare(sa->inst.kvp_data, sb->inst.kvp_data) != 0)
+ {
+ char *frame_a;
+ char *frame_b;
- frame_a = kvp_frame_to_string (sa->inst.kvp_data);
- frame_b = kvp_frame_to_string (sb->inst.kvp_data);
+ frame_a = kvp_frame_to_string (sa->inst.kvp_data);
+ frame_b = kvp_frame_to_string (sb->inst.kvp_data);
- PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
+ PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
- g_free (frame_a);
- g_free (frame_b);
+ g_free (frame_a);
+ g_free (frame_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (sa->reconciled != sb->reconciled)
- {
- PWARN ("reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
- return FALSE;
- }
+ if (sa->reconciled != sb->reconciled)
+ {
+ PWARN ("reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
+ return FALSE;
+ }
- if (timespec_cmp(&(sa->date_reconciled), &(sb->date_reconciled)))
- {
- PWARN ("reconciled date differs");
- return FALSE;
- }
+ if (timespec_cmp(&(sa->date_reconciled), &(sb->date_reconciled)))
+ {
+ PWARN ("reconciled date differs");
+ return FALSE;
+ }
- if (!gnc_numeric_eq(xaccSplitGetAmount (sa), xaccSplitGetAmount (sb)))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_eq(xaccSplitGetAmount (sa), xaccSplitGetAmount (sb)))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string (xaccSplitGetAmount (sa));
- str_b = gnc_numeric_to_string (xaccSplitGetAmount (sb));
+ str_a = gnc_numeric_to_string (xaccSplitGetAmount (sa));
+ str_b = gnc_numeric_to_string (xaccSplitGetAmount (sb));
- PWARN ("amounts differ: %s vs %s", str_a, str_b);
+ PWARN ("amounts differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (!gnc_numeric_eq(xaccSplitGetValue (sa), xaccSplitGetValue (sb)))
- {
- char *str_a;
- char *str_b;
+ if (!gnc_numeric_eq(xaccSplitGetValue (sa), xaccSplitGetValue (sb)))
+ {
+ char *str_a;
+ char *str_b;
- str_a = gnc_numeric_to_string (xaccSplitGetValue (sa));
- str_b = gnc_numeric_to_string (xaccSplitGetValue (sb));
+ str_a = gnc_numeric_to_string (xaccSplitGetValue (sa));
+ str_b = gnc_numeric_to_string (xaccSplitGetValue (sb));
- PWARN ("values differ: %s vs %s", str_a, str_b);
+ PWARN ("values differ: %s vs %s", str_a, str_b);
- g_free (str_a);
- g_free (str_b);
+ g_free (str_a);
+ g_free (str_b);
- return FALSE;
- }
+ return FALSE;
+ }
- if (check_balances) {
- if (!xaccSplitEqualCheckBal ("", sa->balance, sb->balance))
- return FALSE;
- if (!xaccSplitEqualCheckBal ("cleared ", sa->cleared_balance,
- sb->cleared_balance))
- return FALSE;
- if (!xaccSplitEqualCheckBal ("reconciled ", sa->reconciled_balance,
- sb->reconciled_balance))
- return FALSE;
- }
+ if (check_balances)
+ {
+ if (!xaccSplitEqualCheckBal ("", sa->balance, sb->balance))
+ return FALSE;
+ if (!xaccSplitEqualCheckBal ("cleared ", sa->cleared_balance,
+ sb->cleared_balance))
+ return FALSE;
+ if (!xaccSplitEqualCheckBal ("reconciled ", sa->reconciled_balance,
+ sb->reconciled_balance))
+ return FALSE;
+ }
- if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
- check_balances, FALSE))
- {
- PWARN ("transactions differ");
- return FALSE;
- }
+ if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
+ check_balances, FALSE))
+ {
+ PWARN ("transactions differ");
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static void
@@ -661,7 +668,8 @@
GList *transList = NULL;
GHashTable *transHash = g_hash_table_new(g_direct_hash, g_direct_equal);
- for(node = splits; node; node = node->next) {
+ for (node = splits; node; node = node->next)
+ {
Transaction *trans = xaccSplitGetParent((Split *)(node->data));
g_hash_table_insert(transHash, trans, trans);
}
@@ -677,7 +685,7 @@
Account *
xaccSplitGetAccount (const Split *s)
{
- return s ? s->acc : NULL;
+ return s ? s->acc : NULL;
}
void
@@ -701,8 +709,8 @@
static void commit_err (QofInstance *inst, QofBackendError errcode)
{
- PERR("commit error: %d", errcode);
- gnc_engine_signal_commit_error( errcode );
+ PERR("commit error: %d", errcode);
+ gnc_engine_signal_commit_error( errcode );
}
/* An engine-private helper for completing xaccTransCommitEdit(). */
@@ -723,32 +731,40 @@
gnc_lot_remove_split (s->lot, s);
/* Possibly remove the split from the original account... */
- if (orig_acc && (orig_acc != acc || qof_instance_get_destroying(s))) {
- if (!gnc_account_remove_split(orig_acc, s)) {
- PERR("Account lost track of moved or deleted split.");
+ if (orig_acc && (orig_acc != acc || qof_instance_get_destroying(s)))
+ {
+ if (!gnc_account_remove_split(orig_acc, s))
+ {
+ PERR("Account lost track of moved or deleted split.");
}
}
/* ... and insert it into the new account if needed */
- if (acc && (orig_acc != acc) && !qof_instance_get_destroying(s)) {
- if (gnc_account_insert_split(acc, s)) {
+ if (acc && (orig_acc != acc) && !qof_instance_get_destroying(s))
+ {
+ if (gnc_account_insert_split(acc, s))
+ {
/* If the split's lot belonged to some other account, we
leave it so. */
if (s->lot && (NULL == gnc_lot_get_account(s->lot)))
xaccAccountInsertLot (acc, s->lot);
- } else {
+ }
+ else
+ {
PERR("Account grabbed split prematurely.");
}
xaccSplitSetAmount(s, xaccSplitGetAmount(s));
}
- if (s->parent != s->orig_parent) {
+ if (s->parent != s->orig_parent)
+ {
//FIXME: find better event
if (s->orig_parent)
- qof_event_gen(&s->orig_parent->inst, QOF_EVENT_MODIFY,
+ qof_event_gen(&s->orig_parent->inst, QOF_EVENT_MODIFY,
NULL);
}
- if (s->lot) {
+ if (s->lot)
+ {
/* A change of value/amnt affects gains display, etc. */
qof_event_gen (QOF_INSTANCE(s->lot), QOF_EVENT_MODIFY, NULL);
}
@@ -758,10 +774,11 @@
original and new transactions, for the _next_ begin/commit cycle. */
s->orig_acc = s->acc;
s->orig_parent = s->parent;
- qof_commit_edit_part2(QOF_INSTANCE(s), commit_err, NULL,
+ qof_commit_edit_part2(QOF_INSTANCE(s), commit_err, NULL,
(void (*) (QofInstance *)) xaccFreeSplit);
- if (acc) {
+ if (acc)
+ {
g_object_set(acc, "sort-dirty", TRUE, "balance-dirty", TRUE, NULL);
xaccAccountRecomputeBalance(acc);
}
@@ -776,10 +793,11 @@
only because we don't emit events for changing accounts until
the final commit. */
if (s->acc != s->orig_acc)
- s->acc = s->orig_acc;
+ s->acc = s->orig_acc;
/* Undestroy if needed */
- if (qof_instance_get_destroying(s) && s->parent) {
+ if (qof_instance_get_destroying(s) && s->parent)
+ {
GncEventData ed;
qof_instance_set_destroying(s, FALSE);
ed.node = s;
@@ -798,10 +816,10 @@
Split *
xaccSplitLookup (const GUID *guid, QofBook *book)
{
- QofCollection *col;
- if (!guid || !book) return NULL;
- col = qof_book_get_collection (book, GNC_ID_SPLIT);
- return (Split *) qof_collection_lookup_entity (col, guid);
+ QofCollection *col;
+ if (!guid || !book) return NULL;
+ col = qof_book_get_collection (book, GNC_ID_SPLIT);
+ return (Split *) qof_collection_lookup_entity (col, guid);
}
/********************************************************************\
@@ -817,32 +835,34 @@
void
xaccSplitDetermineGainStatus (Split *split)
{
- Split *other;
- KvpValue *val;
+ Split *other;
+ KvpValue *val;
- if (GAINS_STATUS_UNKNOWN != split->gains) return;
+ if (GAINS_STATUS_UNKNOWN != split->gains) return;
- other = xaccSplitGetCapGainsSplit (split);
- if (other)
- {
- split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
- split->gains_split = other;
- return;
- }
+ other = xaccSplitGetCapGainsSplit (split);
+ if (other)
+ {
+ split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
+ split->gains_split = other;
+ return;
+ }
- val = kvp_frame_get_slot (split->inst.kvp_data, "gains-source");
- if (!val)
- {
- // CHECKME: We leave split->gains_split alone. Is that correct?
- split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
- } else {
- QofCollection *col;
- col = qof_book_get_collection (qof_instance_get_book(split), GNC_ID_SPLIT);
- split->gains = GAINS_STATUS_GAINS;
- other = (Split *) qof_collection_lookup_entity (col,
- kvp_value_get_guid (val));
- split->gains_split = other;
- }
+ val = kvp_frame_get_slot (split->inst.kvp_data, "gains-source");
+ if (!val)
+ {
+ // CHECKME: We leave split->gains_split alone. Is that correct?
+ split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
+ }
+ else
+ {
+ QofCollection *col;
+ col = qof_book_get_collection (qof_instance_get_book(split), GNC_ID_SPLIT);
+ split->gains = GAINS_STATUS_GAINS;
+ other = (Split *) qof_collection_lookup_entity (col,
+ kvp_value_get_guid (val));
+ split->gains_split = other;
+ }
}
/********************************************************************\
@@ -855,7 +875,7 @@
{
return 0;
}
- else if(!s->parent || !s->parent->common_currency)
+ else if (!s->parent || !s->parent->common_currency)
{
return 100000;
}
@@ -866,7 +886,7 @@
}
static inline int
-get_commodity_denom(const Split * s)
+get_commodity_denom(const Split * s)
{
if (!s)
{
@@ -886,7 +906,7 @@
* xaccSplitGetSlots
********************************************************************/
-KvpFrame *
+KvpFrame *
xaccSplitGetSlots (const Split * s)
{
return qof_instance_get_slots(QOF_INSTANCE(s));
@@ -895,275 +915,283 @@
void
xaccSplitSetSlots_nc(Split *s, KvpFrame *frm)
{
- if (!s || !frm) return;
- xaccTransBeginEdit(s->parent);
- qof_instance_set_slots(QOF_INSTANCE(s), frm);
- xaccTransCommitEdit(s->parent);
+ if (!s || !frm) return;
+ xaccTransBeginEdit(s->parent);
+ qof_instance_set_slots(QOF_INSTANCE(s), frm);
+ xaccTransCommitEdit(s->parent);
}
/********************************************************************\
\********************************************************************/
-void
+void
DxaccSplitSetSharePriceAndAmount (Split *s, double price, double amt)
{
- if (!s) return;
- ENTER (" ");
- xaccTransBeginEdit (s->parent);
+ if (!s) return;
+ ENTER (" ");
+ xaccTransBeginEdit (s->parent);
- s->amount = double_to_gnc_numeric(amt, get_commodity_denom(s),
- GNC_HOW_RND_ROUND);
- s->value = double_to_gnc_numeric(price * amt, get_currency_denom(s),
- GNC_HOW_RND_ROUND);
+ s->amount = double_to_gnc_numeric(amt, get_commodity_denom(s),
+ GNC_HOW_RND_ROUND);
+ s->value = double_to_gnc_numeric(price * amt, get_currency_denom(s),
+ GNC_HOW_RND_ROUND);
- SET_GAINS_A_VDIRTY(s);
- mark_split (s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
- LEAVE("");
+ SET_GAINS_A_VDIRTY(s);
+ mark_split (s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
+ LEAVE("");
}
-void
+void
xaccSplitSetSharePriceAndAmount (Split *s, gnc_numeric price, gnc_numeric amt)
{
- if (!s) return;
- ENTER (" ");
- xaccTransBeginEdit (s->parent);
+ if (!s) return;
+ ENTER (" ");
+ xaccTransBeginEdit (s->parent);
- s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
- GNC_HOW_RND_ROUND);
- s->value = gnc_numeric_mul(s->amount, price,
- get_currency_denom(s), GNC_HOW_RND_ROUND);
+ s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
+ GNC_HOW_RND_ROUND);
+ s->value = gnc_numeric_mul(s->amount, price,
+ get_currency_denom(s), GNC_HOW_RND_ROUND);
- SET_GAINS_A_VDIRTY(s);
- mark_split (s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
- LEAVE ("");
+ SET_GAINS_A_VDIRTY(s);
+ mark_split (s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
+ LEAVE ("");
}
static void
qofSplitSetSharePrice (Split *split, gnc_numeric price)
{
- g_return_if_fail(split);
- split->value = gnc_numeric_mul(xaccSplitGetAmount(split),
- price, get_currency_denom(split),
- GNC_HOW_RND_ROUND);
+ g_return_if_fail(split);
+ split->value = gnc_numeric_mul(xaccSplitGetAmount(split),
+ price, get_currency_denom(split),
+ GNC_HOW_RND_ROUND);
}
-void
-xaccSplitSetSharePrice (Split *s, gnc_numeric price)
+void
+xaccSplitSetSharePrice (Split *s, gnc_numeric price)
{
- if (!s) return;
- ENTER (" ");
- xaccTransBeginEdit (s->parent);
+ if (!s) return;
+ ENTER (" ");
+ xaccTransBeginEdit (s->parent);
- s->value = gnc_numeric_mul(xaccSplitGetAmount(s),
- price, get_currency_denom(s),
- GNC_HOW_RND_ROUND);
+ s->value = gnc_numeric_mul(xaccSplitGetAmount(s),
+ price, get_currency_denom(s),
+ GNC_HOW_RND_ROUND);
- SET_GAINS_VDIRTY(s);
- mark_split (s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
- LEAVE ("");
+ SET_GAINS_VDIRTY(s);
+ mark_split (s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
+ LEAVE ("");
}
-void
-DxaccSplitSetShareAmount (Split *s, double damt)
+void
+DxaccSplitSetShareAmount (Split *s, double damt)
{
- gnc_numeric old_price, old_amt;
- int commodity_denom = get_commodity_denom(s);
- gnc_numeric amt = double_to_gnc_numeric(damt, commodity_denom,
- GNC_HOW_RND_ROUND);
- if (!s) return;
- ENTER (" ");
- xaccTransBeginEdit (s->parent);
-
- old_amt = xaccSplitGetAmount (s);
- if (!gnc_numeric_zero_p(old_amt))
- {
- old_price = gnc_numeric_div(xaccSplitGetValue (s),
- old_amt, GNC_DENOM_AUTO,
- GNC_HOW_DENOM_REDUCE);
- }
- else {
- old_price = gnc_numeric_create(1, 1);
- }
+ gnc_numeric old_price, old_amt;
+ int commodity_denom = get_commodity_denom(s);
+ gnc_numeric amt = double_to_gnc_numeric(damt, commodity_denom,
+ GNC_HOW_RND_ROUND);
+ if (!s) return;
+ ENTER (" ");
+ xaccTransBeginEdit (s->parent);
- s->amount = gnc_numeric_convert(amt, commodity_denom,
- GNC_HOW_RND_NEVER);
- s->value = gnc_numeric_mul(s->amount, old_price,
- get_currency_denom(s), GNC_HOW_RND_ROUND);
+ old_amt = xaccSplitGetAmount (s);
+ if (!gnc_numeric_zero_p(old_amt))
+ {
+ old_price = gnc_numeric_div(xaccSplitGetValue (s),
+ old_amt, GNC_DENOM_AUTO,
+ GNC_HOW_DENOM_REDUCE);
+ }
+ else
+ {
+ old_price = gnc_numeric_create(1, 1);
+ }
- SET_GAINS_A_VDIRTY(s);
- mark_split (s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
- LEAVE ("");
+ s->amount = gnc_numeric_convert(amt, commodity_denom,
+ GNC_HOW_RND_NEVER);
+ s->value = gnc_numeric_mul(s->amount, old_price,
+ get_currency_denom(s), GNC_HOW_RND_ROUND);
+
+ SET_GAINS_A_VDIRTY(s);
+ mark_split (s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
+ LEAVE ("");
}
static void
qofSplitSetAmount (Split *split, gnc_numeric amt)
{
- g_return_if_fail(split);
- if (split->acc)
- {
- split->amount = gnc_numeric_convert(amt,
- get_commodity_denom(split), GNC_HOW_RND_ROUND);
- }
- else { split->amount = amt; }
+ g_return_if_fail(split);
+ if (split->acc)
+ {
+ split->amount = gnc_numeric_convert(amt,
+ get_commodity_denom(split), GNC_HOW_RND_ROUND);
+ }
+ else
+ {
+ split->amount = amt;
+ }
}
/* The amount of the split in the _account's_ commodity. */
-void
-xaccSplitSetAmount (Split *s, gnc_numeric amt)
+void
+xaccSplitSetAmount (Split *s, gnc_numeric amt)
{
- if (!s) return;
- g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
- ENTER ("(split=%p) old amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
- " new amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
- s->amount.num, s->amount.denom, amt.num, amt.denom);
+ if (!s) return;
+ g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
+ ENTER ("(split=%p) old amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
+ " new amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
+ s->amount.num, s->amount.denom, amt.num, amt.denom);
- xaccTransBeginEdit (s->parent);
- if (s->acc)
- s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
- GNC_HOW_RND_ROUND);
- else
- s->amount = amt;
+ xaccTransBeginEdit (s->parent);
+ if (s->acc)
+ s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
+ GNC_HOW_RND_ROUND);
+ else
+ s->amount = amt;
- SET_GAINS_ADIRTY(s);
- mark_split (s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
- LEAVE("");
+ SET_GAINS_ADIRTY(s);
+ mark_split (s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
+ LEAVE("");
}
static void
qofSplitSetValue (Split *split, gnc_numeric amt)
{
- g_return_if_fail(split);
- split->value = gnc_numeric_convert(amt,
- get_currency_denom(split), GNC_HOW_RND_ROUND);
+ g_return_if_fail(split);
+ split->value = gnc_numeric_convert(amt,
+ get_currency_denom(split), GNC_HOW_RND_ROUND);
}
/* The value of the split in the _transaction's_ currency. */
-void
-xaccSplitSetValue (Split *s, gnc_numeric amt)
+void
+xaccSplitSetValue (Split *s, gnc_numeric amt)
{
- gnc_numeric new_val;
- if (!s) return;
-
- g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
- ENTER ("(split=%p) old val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
- " new val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
- s->value.num, s->value.denom, amt.num, amt.denom);
+ gnc_numeric new_val;
+ if (!s) return;
- xaccTransBeginEdit (s->parent);
- new_val = gnc_numeric_convert(amt, get_currency_denom(s),
- GNC_HOW_RND_ROUND);
- if (gnc_numeric_check(new_val) == GNC_ERROR_OK)
- s->value = new_val;
- else PERR("numeric error in converting the split value's denominator");
+ g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
+ ENTER ("(split=%p) old val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
+ " new val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
+ s->value.num, s->value.denom, amt.num, amt.denom);
- SET_GAINS_VDIRTY(s);
- mark_split (s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
- LEAVE ("");
+ xaccTransBeginEdit (s->parent);
+ new_val = gnc_numeric_convert(amt, get_currency_denom(s),
+ GNC_HOW_RND_ROUND);
+ if (gnc_numeric_check(new_val) == GNC_ERROR_OK)
+ s->value = new_val;
+ else PERR("numeric error in converting the split value's denominator");
+
+ SET_GAINS_VDIRTY(s);
+ mark_split (s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
+ LEAVE ("");
}
/********************************************************************\
\********************************************************************/
-gnc_numeric
-xaccSplitGetBalance (const Split *s)
+gnc_numeric
+xaccSplitGetBalance (const Split *s)
{
- return s ? s->balance : gnc_numeric_zero();
+ return s ? s->balance : gnc_numeric_zero();
}
-gnc_numeric
-xaccSplitGetClearedBalance (const Split *s)
+gnc_numeric
+xaccSplitGetClearedBalance (const Split *s)
{
- return s ? s->cleared_balance : gnc_numeric_zero();
+ return s ? s->cleared_balance : gnc_numeric_zero();
}
-gnc_numeric
-xaccSplitGetReconciledBalance (const Split *s)
+gnc_numeric
+xaccSplitGetReconciledBalance (const Split *s)
{
- return s ? s->reconciled_balance : gnc_numeric_zero();
+ return s ? s->reconciled_balance : gnc_numeric_zero();
}
void
-xaccSplitSetBaseValue (Split *s, gnc_numeric value,
+xaccSplitSetBaseValue (Split *s, gnc_numeric value,
const gnc_commodity * base_currency)
{
- const gnc_commodity *currency;
- const gnc_commodity *commodity;
+ const gnc_commodity *currency;
+ const gnc_commodity *commodity;
- if (!s) return;
- xaccTransBeginEdit (s->parent);
+ if (!s) return;
+ xaccTransBeginEdit (s->parent);
- if (!s->acc)
- {
- PERR ("split must have a parent account");
- return;
- }
+ if (!s->acc)
+ {
+ PERR ("split must have a parent account");
+ return;
+ }
- currency = xaccTransGetCurrency (s->parent);
- commodity = xaccAccountGetCommodity (s->acc);
+ currency = xaccTransGetCurrency (s->parent);
+ commodity = xaccAccountGetCommodity (s->acc);
- /* If the base_currency is the transaction's commodity ('currency'),
- * set the value. If it's the account commodity, set the
- * amount. If both, set both. */
- if (gnc_commodity_equiv(currency, base_currency)) {
- if (gnc_commodity_equiv(commodity, base_currency)) {
- s->amount = gnc_numeric_convert(value,
- get_commodity_denom(s),
- GNC_HOW_RND_ROUND);
+ /* If the base_currency is the transaction's commodity ('currency'),
+ * set the value. If it's the account commodity, set the
+ * amount. If both, set both. */
+ if (gnc_commodity_equiv(currency, base_currency))
+ {
+ if (gnc_commodity_equiv(commodity, base_currency))
+ {
+ s->amount = gnc_numeric_convert(value,
+ get_commodity_denom(s),
+ GNC_HOW_RND_ROUND);
+ }
+ s->value = gnc_numeric_convert(value,
+ get_currency_denom(s),
+ GNC_HOW_RND_ROUND);
}
- s->value = gnc_numeric_convert(value,
- get_currency_denom(s),
- GNC_HOW_RND_ROUND);
- }
- else if (gnc_commodity_equiv(commodity, base_currency)) {
- s->amount = gnc_numeric_convert(value, get_commodity_denom(s),
- GNC_HOW_RND_ROUND);
- }
- else {
- PERR ("inappropriate base currency %s "
- "given split currency=%s and commodity=%s\n",
- gnc_commodity_get_printname(base_currency),
- gnc_commodity_get_printname(currency),
- gnc_commodity_get_printname(commodity));
- return;
- }
+ else if (gnc_commodity_equiv(commodity, base_currency))
+ {
+ s->amount = gnc_numeric_convert(value, get_commodity_denom(s),
+ GNC_HOW_RND_ROUND);
+ }
+ else
+ {
+ PERR ("inappropriate base currency %s "
+ "given split currency=%s and commodity=%s\n",
+ gnc_commodity_get_printname(base_currency),
+ gnc_commodity_get_printname(currency),
+ gnc_commodity_get_printname(commodity));
+ return;
+ }
- SET_GAINS_A_VDIRTY(s);
- mark_split (s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
+ SET_GAINS_A_VDIRTY(s);
+ mark_split (s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
}
gnc_numeric
xaccSplitGetBaseValue (const Split *s, const gnc_commodity * base_currency)
{
- if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
+ if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
- /* be more precise -- the value depends on the currency we want it
- * expressed in. */
- if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
- return xaccSplitGetValue(s);
- if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
- return xaccSplitGetAmount(s);
+ /* be more precise -- the value depends on the currency we want it
+ * expressed in. */
+ if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
+ return xaccSplitGetValue(s);
+ if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
+ return xaccSplitGetAmount(s);
- PERR ("inappropriate base currency %s "
- "given split currency=%s and commodity=%s\n",
- gnc_commodity_get_printname(base_currency),
- gnc_commodity_get_printname(xaccTransGetCurrency (s->parent)),
- gnc_commodity_get_printname(xaccAccountGetCommodity(s->acc)));
- return gnc_numeric_zero();
+ PERR ("inappropriate base currency %s "
+ "given split currency=%s and commodity=%s\n",
+ gnc_commodity_get_printname(base_currency),
+ gnc_commodity_get_printname(xaccTransGetCurrency (s->parent)),
+ gnc_commodity_get_printname(xaccAccountGetCommodity(s->acc)));
+ return gnc_numeric_zero();
}
/********************************************************************\
@@ -1173,128 +1201,131 @@
xaccSplitsComputeValue (GList *splits, const Split * skip_me,
const gnc_commodity * base_currency)
{
- GList *node;
- gnc_numeric value = gnc_numeric_zero();
+ GList *node;
+ gnc_numeric value = gnc_numeric_zero();
- g_return_val_if_fail (base_currency, value);
+ g_return_val_if_fail (base_currency, value);
- ENTER (" currency=%s", gnc_commodity_get_mnemonic (base_currency));
+ ENTER (" currency=%s", gnc_commodity_get_mnemonic (base_currency));
- for (node = splits; node; node = node->next)
- {
- const Split *s = node->data;
- const gnc_commodity *currency;
- const gnc_commodity *commodity;
+ for (node = splits; node; node = node->next)
+ {
+ const Split *s = node->data;
+ const gnc_commodity *currency;
+ const gnc_commodity *commodity;
- if (s == skip_me) continue;
+ if (s == skip_me) continue;
- /* value = gnc_numeric_add(value, xaccSplitGetBaseValue(s, base_currency),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD); */
+ /* value = gnc_numeric_add(value, xaccSplitGetBaseValue(s, base_currency),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD); */
- /* The split-editor often sends us 'temp' splits whose account
- * hasn't yet been set. Be lenient, and assume an implied base
- * currency. If there's a problem later, the scrub routines will
- * pick it up.
- */
- commodity = s->acc ? xaccAccountGetCommodity (s->acc) : base_currency;
- currency = xaccTransGetCurrency (s->parent);
+ /* The split-editor often sends us 'temp' splits whose account
+ * hasn't yet been set. Be lenient, and assume an implied base
+ * currency. If there's a problem later, the scrub routines will
+ * pick it up.
+ */
+ commodity = s->acc ? xaccAccountGetCommodity (s->acc) : base_currency;
+ currency = xaccTransGetCurrency (s->parent);
-
- if (gnc_commodity_equiv(currency, base_currency))
- {
- value = gnc_numeric_add(value, xaccSplitGetValue(s),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
+
+ if (gnc_commodity_equiv(currency, base_currency))
+ {
+ value = gnc_numeric_add(value, xaccSplitGetValue(s),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
+ }
+ else if (gnc_commodity_equiv(commodity, base_currency))
+ {
+ value = gnc_numeric_add(value, xaccSplitGetAmount(s),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
+ }
+ else
+ {
+ PERR ("inconsistent currencies\n"
+ "\tbase = '%s', curr='%s', sec='%s'\n",
+ gnc_commodity_get_printname(base_currency),
+ gnc_commodity_get_printname(currency),
+ gnc_commodity_get_printname(commodity));
+ g_return_val_if_fail (FALSE, value);
+ }
}
- else if (gnc_commodity_equiv(commodity, base_currency))
- {
- value = gnc_numeric_add(value, xaccSplitGetAmount(s),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
- }
- else {
- PERR ("inconsistent currencies\n"
- "\tbase = '%s', curr='%s', sec='%s'\n",
- gnc_commodity_get_printname(base_currency),
- gnc_commodity_get_printname(currency),
- gnc_commodity_get_printname(commodity));
- g_return_val_if_fail (FALSE, value);
- }
- }
- /* Note that just because the currencies are equivalent
- * doesn't mean the denominators are the same! */
- value = gnc_numeric_convert(value,
- gnc_commodity_get_fraction (base_currency),
- GNC_HOW_RND_ROUND);
+ /* Note that just because the currencies are equivalent
+ * doesn't mean the denominators are the same! */
+ value = gnc_numeric_convert(value,
+ gnc_commodity_get_fraction (base_currency),
+ GNC_HOW_RND_ROUND);
- LEAVE (" total=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
- value.num, value.denom);
- return value;
+ LEAVE (" total=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+ value.num, value.denom);
+ return value;
}
gnc_numeric
xaccSplitConvertAmount (const Split *split, Account * account)
{
- gnc_commodity *acc_com, *to_commodity;
- Transaction *txn;
- gnc_numeric amount, value, convrate;
- Account * split_acc;
+ gnc_commodity *acc_com, *to_commodity;
+ Transaction *txn;
+ gnc_numeric amount, value, convrate;
+ Account * split_acc;
- amount = xaccSplitGetAmount (split);
+ amount = xaccSplitGetAmount (split);
- /* If this split is attached to this account, OR */
- split_acc = xaccSplitGetAccount (split);
- if (split_acc == account)
- return amount;
+ /* If this split is attached to this account, OR */
+ split_acc = xaccSplitGetAccount (split);
+ if (split_acc == account)
+ return amount;
- /* If split->account->commodity == to_commodity, return the amount */
- acc_com = xaccAccountGetCommodity (split_acc);
- to_commodity = xaccAccountGetCommodity (account);
- if (acc_com && gnc_commodity_equal (acc_com, to_commodity))
- return amount;
+ /* If split->account->commodity == to_commodity, return the amount */
+ acc_com = xaccAccountGetCommodity (split_acc);
+ to_commodity = xaccAccountGetCommodity (account);
+ if (acc_com && gnc_commodity_equal (acc_com, to_commodity))
+ return amount;
- /* Ok, this split is not for the viewed account, and the commodity
- * does not match. So we need to do some conversion.
- *
- * First, we can cheat. If this transaction is balanced and has
- * exactly two splits, then we can implicitly determine the exchange
- * rate and just return the 'other' split amount.
- */
- txn = xaccSplitGetParent (split);
- if (txn && xaccTransIsBalanced (txn)) {
- const Split *osplit = xaccSplitGetOtherSplit (split);
+ /* Ok, this split is not for the viewed account, and the commodity
+ * does not match. So we need to do some conversion.
+ *
+ * First, we can cheat. If this transaction is balanced and has
+ * exactly two splits, then we can implicitly determine the exchange
+ * rate and just return the 'other' split amount.
+ */
+ txn = xaccSplitGetParent (split);
+ if (txn && xaccTransIsBalanced (txn))
+ {
+ const Split *osplit = xaccSplitGetOtherSplit (split);
- if (osplit)
- {
- gnc_commodity* split_comm =
- xaccAccountGetCommodity(xaccSplitGetAccount(osplit));
- if (!gnc_commodity_equal(to_commodity, split_comm))
- {
- PERR("The split's (%s) amount can't be converted from %s into %s.",
- guid_to_string(xaccSplitGetGUID(osplit)),
- gnc_commodity_get_mnemonic(split_comm),
- gnc_commodity_get_mnemonic(to_commodity)
- );
- return gnc_numeric_zero();
+ if (osplit)
+ {
+ gnc_commodity* split_comm =
+ xaccAccountGetCommodity(xaccSplitGetAccount(osplit));
+ if (!gnc_commodity_equal(to_commodity, split_comm))
+ {
+ PERR("The split's (%s) amount can't be converted from %s into %s.",
+ guid_to_string(xaccSplitGetGUID(osplit)),
+ gnc_commodity_get_mnemonic(split_comm),
+ gnc_commodity_get_mnemonic(to_commodity)
+ );
+ return gnc_numeric_zero();
+ }
+ return gnc_numeric_neg (xaccSplitGetAmount (osplit));
}
- return gnc_numeric_neg (xaccSplitGetAmount (osplit));
}
- }
- /* ... otherwise, we need to compute the amount from the conversion
- * rate into _this account_. So, find the split into this account,
- * compute the conversion rate (based on amount/value), and then multiply
- * this times the split value.
- */
- value = xaccSplitGetValue (split);
-
- if (gnc_numeric_zero_p (value)) {
- return value;
- }
-
- convrate = xaccTransGetAccountConvRate(txn, account);
- return gnc_numeric_mul (value, convrate,
- gnc_commodity_get_fraction (to_commodity),
- GNC_RND_ROUND);
+ /* ... otherwise, we need to compute the amount from the conversion
+ * rate into _this account_. So, find the split into this account,
+ * compute the conversion rate (based on amount/value), and then multiply
+ * this times the split value.
+ */
+ value = xaccSplitGetValue (split);
+
+ if (gnc_numeric_zero_p (value))
+ {
+ return value;
+ }
+
+ convrate = xaccTransGetAccountConvRate(txn, account);
+ return gnc_numeric_mul (value, convrate,
+ gnc_commodity_get_fraction (to_commodity),
+ GNC_RND_ROUND);
}
/********************************************************************\
@@ -1303,27 +1334,27 @@
gboolean
xaccSplitDestroy (Split *split)
{
- Account *acc;
- Transaction *trans;
- GncEventData ed;
+ Account *acc;
+ Transaction *trans;
+ GncEventData ed;
- if (!split) return TRUE;
+ if (!split) return TRUE;
- acc = split->acc;
- trans = split->parent;
- if (acc && !qof_instance_get_destroying(acc)
- && xaccTransGetReadOnly(trans))
- return FALSE;
+ acc = split->acc;
+ trans = split->parent;
+ if (acc && !qof_instance_get_destroying(acc)
+ && xaccTransGetReadOnly(trans))
+ return FALSE;
- xaccTransBeginEdit(trans);
- ed.node = split;
- ed.idx = xaccTransGetSplitIndex(trans, split);
- qof_instance_set_dirty(QOF_INSTANCE(split));
- qof_instance_set_destroying(split, TRUE);
- qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
- xaccTransCommitEdit(trans);
+ xaccTransBeginEdit(trans);
+ ed.node = split;
+ ed.idx = xaccTransGetSplitIndex(trans, split);
+ qof_instance_set_dirty(QOF_INSTANCE(split));
+ qof_instance_set_destroying(split, TRUE);
+ qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
+ xaccTransCommitEdit(trans);
- return TRUE;
+ return TRUE;
}
/********************************************************************\
@@ -1332,235 +1363,239 @@
gint
xaccSplitOrder (const Split *sa, const Split *sb)
{
- int retval;
- int comp;
- char *da, *db;
+ int retval;
+ int comp;
+ char *da, *db;
- if (sa == sb) return 0;
- /* nothing is always less than something */
- if (!sa && sb) return -1;
- if (sa && !sb) return +1;
+ if (sa == sb) return 0;
+ /* nothing is always less than something */
+ if (!sa && sb) return -1;
+ if (sa && !sb) return +1;
- retval = xaccTransOrder (sa->parent, sb->parent);
- if (retval) return retval;
+ retval = xaccTransOrder (sa->parent, sb->parent);
+ if (retval) return retval;
- /* otherwise, sort on memo strings */
- da = sa->memo ? sa->memo : "";
- db = sb->memo ? sb->memo : "";
- retval = g_utf8_collate (da, db);
- if (retval)
- return retval;
+ /* otherwise, sort on memo strings */
+ da = sa->memo ? sa->memo : "";
+ db = sb->memo ? sb->memo : "";
+ retval = g_utf8_collate (da, db);
+ if (retval)
+ return retval;
- /* otherwise, sort on action strings */
- da = sa->action ? sa->action : "";
- db = sb->action ? sb->action : "";
- retval = g_utf8_collate (da, db);
- if (retval != 0)
- return retval;
+ /* otherwise, sort on action strings */
+ da = sa->action ? sa->action : "";
+ db = sb->action ? sb->action : "";
+ retval = g_utf8_collate (da, db);
+ if (retval != 0)
+ return retval;
- /* the reconciled flag ... */
- if (sa->reconciled < sb->reconciled) return -1;
- if (sa->reconciled > sb->reconciled) return +1;
+ /* the reconciled flag ... */
+ if (sa->reconciled < sb->reconciled) return -1;
+ if (sa->reconciled > sb->reconciled) return +1;
- /* compare amounts */
- comp = gnc_numeric_compare(xaccSplitGetAmount(sa), xaccSplitGetAmount (sb));
- if (comp < 0) return -1;
- if (comp > 0) return +1;
+ /* compare amounts */
+ comp = gnc_numeric_compare(xaccSplitGetAmount(sa), xaccSplitGetAmount (sb));
+ if (comp < 0) return -1;
+ if (comp > 0) return +1;
- comp = gnc_numeric_compare(xaccSplitGetValue(sa), xaccSplitGetValue (sb));
- if (comp < 0) return -1;
- if (comp > 0) return +1;
+ comp = gnc_numeric_compare(xaccSplitGetValue(sa), xaccSplitGetValue (sb));
+ if (comp < 0) return -1;
+ if (comp > 0) return +1;
- /* if dates differ, return */
- DATE_CMP(sa,sb,date_reconciled);
+ /* if dates differ, return */
+ DATE_CMP(sa, sb, date_reconciled);
- /* else, sort on guid - keeps sort stable. */
- retval = qof_instance_guid_compare(sa, sb);
- if (retval) return retval;
+ /* else, sort on guid - keeps sort stable. */
+ retval = qof_instance_guid_compare(sa, sb);
+ if (retval) return retval;
- return 0;
+ return 0;
}
gint
xaccSplitOrderDateOnly (const Split *sa, const Split *sb)
{
- Transaction *ta, *tb;
+ Transaction *ta, *tb;
- if (sa == sb) return 0;
- /* nothing is always less than something */
- if (!sa && sb) return -1;
- if (sa && !sb) return +1;
+ if (sa == sb) return 0;
+ /* nothing is always less than something */
+ if (!sa && sb) return -1;
+ if (sa && !sb) return +1;
- ta = sa->parent;
- tb = sb->parent;
- if ( ta && !tb ) return -1;
- if ( !ta && tb ) return +1;
- if ( !ta && !tb ) return 0;
+ ta = sa->parent;
+ tb = sb->parent;
+ if ( ta && !tb ) return -1;
+ if ( !ta && tb ) return +1;
+ if ( !ta && !tb ) return 0;
- /* if dates differ, return */
- DATE_CMP(ta,tb,date_posted);
+ /* if dates differ, return */
+ DATE_CMP(ta, tb, date_posted);
- /* If the dates are the same, do not change the order */
- return -1;
+ /* If the dates are the same, do not change the order */
+ return -1;
}
static gboolean
get_corr_account_split(const Split *sa, const Split **retval)
{
-
- const Split *current_split;
- GList *node;
- gnc_numeric sa_value, current_value;
- gboolean sa_value_positive, current_value_positive, seen_one = FALSE;
- *retval = NULL;
- g_return_val_if_fail(sa, FALSE);
-
- sa_value = xaccSplitGetValue (sa);
- sa_value_positive = gnc_numeric_positive_p(sa_value);
+ const Split *current_split;
+ GList *node;
+ gnc_numeric sa_value, current_value;
+ gboolean sa_value_positive, current_value_positive, seen_one = FALSE;
- for (node = sa->parent->splits; node; node = node->next)
- {
- current_split = node->data;
- if (current_split == sa) continue;
+ *retval = NULL;
+ g_return_val_if_fail(sa, FALSE);
- if (!xaccTransStillHasSplit(sa->parent, current_split)) continue;
- current_value = xaccSplitGetValue (current_split);
- current_value_positive = gnc_numeric_positive_p(current_value);
- if ((sa_value_positive && !current_value_positive) ||
- (!sa_value_positive && current_value_positive)) {
- if (seen_one) {
- *retval = NULL;
- return FALSE;
- } else {
- *retval = current_split;
- seen_one = TRUE;
+ sa_value = xaccSplitGetValue (sa);
+ sa_value_positive = gnc_numeric_positive_p(sa_value);
+
+ for (node = sa->parent->splits; node; node = node->next)
+ {
+ current_split = node->data;
+ if (current_split == sa) continue;
+
+ if (!xaccTransStillHasSplit(sa->parent, current_split)) continue;
+ current_value = xaccSplitGetValue (current_split);
+ current_value_positive = gnc_numeric_positive_p(current_value);
+ if ((sa_value_positive && !current_value_positive) ||
+ (!sa_value_positive && current_value_positive))
+ {
+ if (seen_one)
+ {
+ *retval = NULL;
+ return FALSE;
+ }
+ else
+ {
+ *retval = current_split;
+ seen_one = TRUE;
+ }
}
}
- }
- return seen_one;
+ return seen_one;
}
/* TODO: these static consts can be shared. */
const char *
xaccSplitGetCorrAccountName(const Split *sa)
{
- static const char *split_const = NULL;
- const Split *other_split;
+ static const char *split_const = NULL;
+ const Split *other_split;
- if (!get_corr_account_split(sa, &other_split))
- {
- if (!split_const)
- split_const = _("-- Split Transaction --");
+ if (!get_corr_account_split(sa, &other_split))
+ {
+ if (!split_const)
+ split_const = _("-- Split Transaction --");
- return split_const;
- }
+ return split_const;
+ }
- return xaccAccountGetName(other_split->acc);
+ return xaccAccountGetName(other_split->acc);
}
char *
xaccSplitGetCorrAccountFullName(const Split *sa)
{
- static const char *split_const = NULL;
- const Split *other_split;
+ static const char *split_const = NULL;
+ const Split *other_split;
- if (!get_corr_account_split(sa, &other_split))
- {
- if (!split_const)
- split_const = _("-- Split Transaction --");
+ if (!get_corr_account_split(sa, &other_split))
+ {
+ if (!split_const)
+ split_const = _("-- Split Transaction --");
- return g_strdup(split_const);
- }
- return gnc_account_get_full_name(other_split->acc);
+ return g_strdup(split_const);
+ }
+ return gnc_account_get_full_name(other_split->acc);
}
const char *
xaccSplitGetCorrAccountCode(const Split *sa)
{
- static const char *split_const = NULL;
- const Split *other_split;
+ static const char *split_const = NULL;
+ const Split *other_split;
- if (!get_corr_account_split(sa, &other_split))
- {
- if (!split_const)
- /* Translators: This string has a disambiguation prefix */
- split_const = Q_("Displayed account code of the other account in a multi-split transaction|Split");
+ if (!get_corr_account_split(sa, &other_split))
+ {
+ if (!split_const)
+ /* Translators: This string has a disambiguation prefix */
+ split_const = Q_("Displayed account code of the other account in a multi-split transaction|Split");
- return split_const;
- }
- return xaccAccountGetCode(other_split->acc);
+ return split_const;
+ }
+ return xaccAccountGetCode(other_split->acc);
}
/* TODO: It's not too hard to make this function avoid the malloc/free. */
-int
+int
xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb)
{
- Account *aa, *ab;
- char *full_a, *full_b;
- int retval;
- if (!sa && !sb) return 0;
- if (!sa) return -1;
- if (!sb) return 1;
+ Account *aa, *ab;
+ char *full_a, *full_b;
+ int retval;
+ if (!sa && !sb) return 0;
+ if (!sa) return -1;
+ if (!sb) return 1;
- aa = sa->acc;
- ab = sb->acc;
- full_a = gnc_account_get_full_name(aa);
- full_b = gnc_account_get_full_name(ab);
- retval = g_utf8_collate(full_a, full_b);
- g_free(full_a);
- g_free(full_b);
- return retval;
+ aa = sa->acc;
+ ab = sb->acc;
+ full_a = gnc_account_get_full_name(aa);
+ full_b = gnc_account_get_full_name(ab);
+ retval = g_utf8_collate(full_a, full_b);
+ g_free(full_a);
+ g_free(full_b);
+ return retval;
}
-int
+int
xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
{
- Account *aa, *ab;
- if (!sa && !sb) return 0;
- if (!sa) return -1;
- if (!sb) return 1;
+ Account *aa, *ab;
+ if (!sa && !sb) return 0;
+ if (!sa) return -1;
+ if (!sb) return 1;
- aa = sa->acc;
- ab = sb->acc;
-
- return safe_strcmp(xaccAccountGetName(aa), xaccAccountGetName(ab));
+ aa = sa->acc;
+ ab = sb->acc;
+
+ return safe_strcmp(xaccAccountGetName(aa), xaccAccountGetName(ab));
}
-int
+int
xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
{
- char *ca, *cb;
- int retval;
- if (!sa && !sb) return 0;
- if (!sa) return -1;
- if (!sb) return 1;
+ char *ca, *cb;
+ int retval;
+ if (!sa && !sb) return 0;
+ if (!sa) return -1;
+ if (!sb) return 1;
- /* doesn't matter what separator we use
- * as long as they are the same
- */
+ /* doesn't matter what separator we use
+ * as long as they are the same
+ */
- ca = xaccSplitGetCorrAccountFullName(sa);
- cb = xaccSplitGetCorrAccountFullName(sb);
- retval = safe_strcmp(ca, cb);
- g_free(ca);
- g_free(cb);
- return retval;
+ ca = xaccSplitGetCorrAccountFullName(sa);
+ cb = xaccSplitGetCorrAccountFullName(sb);
+ retval = safe_strcmp(ca, cb);
+ g_free(ca);
+ g_free(cb);
+ return retval;
}
int
xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb)
{
- const char *ca, *cb;
- if (!sa && !sb) return 0;
- if (!sa) return -1;
- if (!sb) return 1;
+ const char *ca, *cb;
+ if (!sa && !sb) return 0;
+ if (!sa) return -1;
+ if (!sb) return 1;
- ca = xaccSplitGetCorrAccountCode(sa);
- cb = xaccSplitGetCorrAccountCode(sb);
- return safe_strcmp(ca, cb);
+ ca = xaccSplitGetCorrAccountCode(sa);
+ cb = xaccSplitGetCorrAccountCode(sb);
+ return safe_strcmp(ca, cb);
}
static void
@@ -1573,126 +1608,126 @@
void
xaccSplitSetMemo (Split *split, const char *memo)
{
- if (!split || !memo) return;
- xaccTransBeginEdit (split->parent);
+ if (!split || !memo) return;
+ xaccTransBeginEdit (split->parent);
- CACHE_REPLACE(split->memo, memo);
- qof_instance_set_dirty(QOF_INSTANCE(split));
- xaccTransCommitEdit(split->parent);
+ CACHE_REPLACE(split->memo, memo);
+ qof_instance_set_dirty(QOF_INSTANCE(split));
+ xaccTransCommitEdit(split->parent);
}
static void
qofSplitSetAction (Split *split, const char *actn)
{
- g_return_if_fail(split);
- CACHE_REPLACE(split->action, actn);
+ g_return_if_fail(split);
+ CACHE_REPLACE(split->action, actn);
}
void
xaccSplitSetAction (Split *split, const char *actn)
{
- if (!split || !actn) return;
- xaccTransBeginEdit (split->parent);
+ if (!split || !actn) return;
+ xaccTransBeginEdit (split->parent);
- CACHE_REPLACE(split->action, actn);
- qof_instance_set_dirty(QOF_INSTANCE(split));
- xaccTransCommitEdit(split->parent);
+ CACHE_REPLACE(split->action, actn);
+ qof_instance_set_dirty(QOF_INSTANCE(split));
+ xaccTransCommitEdit(split->parent);
}
static void
qofSplitSetReconcile (Split *split, char recn)
{
- g_return_if_fail(split);
- switch (recn)
- {
- case NREC:
- case CREC:
- case YREC:
- case FREC:
- case VREC:
- split->reconciled = recn;
- mark_split (split);
- xaccAccountRecomputeBalance (split->acc);
- break;
- default:
- PERR("Bad reconciled flag");
- }
+ g_return_if_fail(split);
+ switch (recn)
+ {
+ case NREC:
+ case CREC:
+ case YREC:
+ case FREC:
+ case VREC:
+ split->reconciled = recn;
+ mark_split (split);
+ xaccAccountRecomputeBalance (split->acc);
+ break;
+ default:
+ PERR("Bad reconciled flag");
+ }
}
void
xaccSplitSetReconcile (Split *split, char recn)
{
- if (!split || split->reconciled == recn) return;
- xaccTransBeginEdit (split->parent);
+ if (!split || split->reconciled == recn) return;
+ xaccTransBeginEdit (split->parent);
- switch (recn)
- {
- case NREC:
- case CREC:
- case YREC:
- case FREC:
- case VREC:
- split->reconciled = recn;
- mark_split (split);
- qof_instance_set_dirty(QOF_INSTANCE(split));
- xaccAccountRecomputeBalance (split->acc);
- break;
- default:
- PERR("Bad reconciled flag");
- }
- xaccTransCommitEdit(split->parent);
+ switch (recn)
+ {
+ case NREC:
+ case CREC:
+ case YREC:
+ case FREC:
+ case VREC:
+ split->reconciled = recn;
+ mark_split (split);
+ qof_instance_set_dirty(QOF_INSTANCE(split));
+ xaccAccountRecomputeBalance (split->acc);
+ break;
+ default:
+ PERR("Bad reconciled flag");
+ }
+ xaccTransCommitEdit(split->parent);
}
void
xaccSplitSetDateReconciledSecs (Split *split, time_t secs)
{
- if (!split) return;
- xaccTransBeginEdit (split->parent);
+ if (!split) return;
+ xaccTransBeginEdit (split->parent);
- split->date_reconciled.tv_sec = secs;
- split->date_reconciled.tv_nsec = 0;
- qof_instance_set_dirty(QOF_INSTANCE(split));
- xaccTransCommitEdit(split->parent);
+ split->date_reconciled.tv_sec = secs;
+ split->date_reconciled.tv_nsec = 0;
+ qof_instance_set_dirty(QOF_INSTANCE(split));
+ xaccTransCommitEdit(split->parent);
}
void
xaccSplitSetDateReconciledTS (Split *split, Timespec *ts)
{
- if (!split || !ts) return;
- xaccTransBeginEdit (split->parent);
+ if (!split || !ts) return;
+ xaccTransBeginEdit (split->parent);
- split->date_reconciled = *ts;
- qof_instance_set_dirty(QOF_INSTANCE(split));
- xaccTransCommitEdit(split->parent);
+ split->date_reconciled = *ts;
+ qof_instance_set_dirty(QOF_INSTANCE(split));
+ xaccTransCommitEdit(split->parent);
}
void
xaccSplitGetDateReconciledTS (const Split * split, Timespec *ts)
{
- if (!split || !ts) return;
- *ts = (split->date_reconciled);
+ if (!split || !ts) return;
+ *ts = (split->date_reconciled);
}
Timespec
xaccSplitRetDateReconciledTS (const Split * split)
{
- Timespec ts = {0,0};
- return split ? split->date_reconciled : ts;
+ Timespec ts = {0, 0};
+ return split ? split->date_reconciled : ts;
}
/********************************************************************\
\********************************************************************/
/* return the parent transaction of the split */
-Transaction *
+Transaction *
xaccSplitGetParent (const Split *split)
{
- return split ? split->parent : NULL;
+ return split ? split->parent : NULL;
}
void
@@ -1713,7 +1748,8 @@
xaccTransBeginEdit(old_trans);
ed.node = s;
- if (old_trans) {
+ if (old_trans)
+ {
ed.idx = xaccTransGetSplitIndex(old_trans, s);
qof_event_gen(&old_trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
}
@@ -1722,14 +1758,15 @@
xaccTransCommitEdit(old_trans);
qof_instance_set_dirty(QOF_INSTANCE(s));
- if (t) {
+ if (t)
+ {
/* Convert split to new transaction's commodity denominator */
xaccSplitSetValue(s, xaccSplitGetValue(s));
-
+
/* add ourselves to the new transaction's list of pending splits. */
if (NULL == g_list_find(t->splits, s))
t->splits = g_list_append(t->splits, s);
-
+
ed.idx = -1; /* unused */
qof_event_gen(&t->inst, GNC_EVENT_ITEM_ADDED, &ed);
}
@@ -1740,87 +1777,87 @@
GNCLot *
xaccSplitGetLot (const Split *split)
{
- return split ? split->lot : NULL;
+ return split ? split->lot : NULL;
}
void
xaccSplitSetLot(Split* split, GNCLot* lot)
{
- xaccTransBeginEdit (split->parent);
- split->lot = lot;
- qof_instance_set_dirty(QOF_INSTANCE(split));
- xaccTransCommitEdit(split->parent);
+ xaccTransBeginEdit (split->parent);
+ split->lot = lot;
+ qof_instance_set_dirty(QOF_INSTANCE(split));
+ xaccTransCommitEdit(split->parent);
}
const char *
xaccSplitGetMemo (const Split *split)
{
- return split ? split->memo : NULL;
+ return split ? split->memo : NULL;
}
const char *
xaccSplitGetAction (const Split *split)
{
- return split ? split->action : NULL;
+ return split ? split->action : NULL;
}
-char
-xaccSplitGetReconcile (const Split *split)
+char
+xaccSplitGetReconcile (const Split *split)
{
- return split ? split->reconciled : ' ';
+ return split ? split->reconciled : ' ';
}
gnc_numeric
xaccSplitGetAmount (const Split * split)
{
- return split ? split->amount : gnc_numeric_zero();
+ return split ? split->amount : gnc_numeric_zero();
}
gnc_numeric
-xaccSplitGetValue (const Split * split)
+xaccSplitGetValue (const Split * split)
{
- return split ? split->value : gnc_numeric_zero();
+ return split ? split->value : gnc_numeric_zero();
}
gnc_numeric
-xaccSplitGetSharePrice (const Split * split)
+xaccSplitGetSharePrice (const Split * split)
{
- gnc_numeric amt, val, price;
- if (!split) return gnc_numeric_create(1, 1);
-
+ gnc_numeric amt, val, price;
+ if (!split) return gnc_numeric_create(1, 1);
- /* if amount == 0 and value == 0, then return 1.
- * if amount == 0 and value != 0 then return 0.
- * otherwise return value/amount
- */
- amt = xaccSplitGetAmount(split);
- val = xaccSplitGetValue(split);
- if (gnc_numeric_zero_p(amt))
- {
- if (gnc_numeric_zero_p(val))
- return gnc_numeric_create(1, 1);
- return gnc_numeric_create(0, 1);
- }
- price = gnc_numeric_div(val, amt,
- GNC_DENOM_AUTO,
- GNC_HOW_DENOM_SIGFIGS(PRICE_SIGFIGS) |
- GNC_HOW_RND_ROUND);
+ /* if amount == 0 and value == 0, then return 1.
+ * if amount == 0 and value != 0 then return 0.
+ * otherwise return value/amount
+ */
- /* During random checks we can get some very weird prices. Let's
- * handle some overflow and other error conditions by returning
- * zero. But still print an error to let us know it happened.
- */
- if (gnc_numeric_check(price))
- {
- PERR("Computing share price failed (%d): [ %" G_GINT64_FORMAT " / %"
- G_GINT64_FORMAT " ] / [ %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT " ]",
- gnc_numeric_check(price), val.num, val.denom, amt.num, amt.denom);
- return gnc_numeric_create(0,1);
- }
+ amt = xaccSplitGetAmount(split);
+ val = xaccSplitGetValue(split);
+ if (gnc_numeric_zero_p(amt))
+ {
+ if (gnc_numeric_zero_p(val))
+ return gnc_numeric_create(1, 1);
+ return gnc_numeric_create(0, 1);
+ }
+ price = gnc_numeric_div(val, amt,
+ GNC_DENOM_AUTO,
+ GNC_HOW_DENOM_SIGFIGS(PRICE_SIGFIGS) |
+ GNC_HOW_RND_ROUND);
- return price;
+ /* During random checks we can get some very weird prices. Let's
+ * handle some overflow and other error conditions by returning
+ * zero. But still print an error to let us know it happened.
+ */
+ if (gnc_numeric_check(price))
+ {
+ PERR("Computing share price failed (%d): [ %" G_GINT64_FORMAT " / %"
+ G_GINT64_FORMAT " ] / [ %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT " ]",
+ gnc_numeric_check(price), val.num, val.denom, amt.num, amt.denom);
+ return gnc_numeric_create(0, 1);
+ }
+
+ return price;
}
/********************************************************************\
@@ -1835,11 +1872,11 @@
const char *
xaccSplitGetType(const Split *s)
{
- const char *split_type;
+ const char *split_type;
- if (!s) return NULL;
- split_type = kvp_frame_get_string(s->inst.kvp_data, "split-type");
- return split_type ? split_type : "normal";
+ if (!s) return NULL;
+ split_type = kvp_frame_get_string(s->inst.kvp_data, "split-type");
+ return split_type ? split_type : "normal";
}
/* reconfigure a split to be a stock split - after this, you shouldn't
@@ -1847,14 +1884,14 @@
void
xaccSplitMakeStockSplit(Split *s)
{
- xaccTransBeginEdit (s->parent);
+ xaccTransBeginEdit (s->parent);
- s->value = gnc_numeric_zero();
- kvp_frame_set_str(s->inst.kvp_data, "split-type", "stock-split");
- SET_GAINS_VDIRTY(s);
- mark_split(s);
- qof_instance_set_dirty(QOF_INSTANCE(s));
- xaccTransCommitEdit(s->parent);
+ s->value = gnc_numeric_zero();
+ kvp_frame_set_str(s->inst.kvp_data, "split-type", "stock-split");
+ SET_GAINS_VDIRTY(s);
+ mark_split(s);
+ qof_instance_set_dirty(QOF_INSTANCE(s));
+ xaccTransCommitEdit(s->parent);
}
@@ -1866,52 +1903,63 @@
* in a conceptual sense, if lots hadn't been used, there would be
* only a pair. So we handle this conceptual case: we can still
* identify, unambiguously, the 'other' split when 'this' split
- * as been cut up across lots. We do this by looking for the
+ * as been cut up across lots. We do this by looking for the
* 'lot-split' keyword, which occurs only in cut-up splits.
*/
Split *
xaccSplitGetOtherSplit (const Split *split)
{
- int i;
- Transaction *trans;
- int count, num_splits;
- Split *other = NULL;
- KvpValue *sva;
- gboolean trading_accts;
+ int i;
+ Transaction *trans;
+ int count, num_splits;
+ Split *other = NULL;
+ KvpValue *sva;
+ gboolean trading_accts;
- if (!split) return NULL;
- trans = split->parent;
- if (!trans) return NULL;
+ if (!split) return NULL;
+ trans = split->parent;
+ if (!trans) return NULL;
#ifdef OLD_ALGO_HAS_ONLY_TWO_SPLITS
- Split *s1, *s2;
- if (g_list_length (trans->splits) != 2) return NULL;
+ Split *s1, *s2;
+ if (g_list_length (trans->splits) != 2) return NULL;
- s1 = g_list_nth_data (trans->splits, 0);
- s2 = g_list_nth_data (trans->splits, 1);
+ s1 = g_list_nth_data (trans->splits, 0);
+ s2 = g_list_nth_data (trans->splits, 1);
- if (s1 == split) return s2;
- return s1;
+ if (s1 == split) return s2;
+ return s1;
#endif
- trading_accts = xaccTransUseTradingAccounts (trans);
- num_splits = xaccTransCountSplits(trans);
- count = num_splits;
- sva = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
- if (!sva && !trading_accts && (2 != count)) return NULL;
+ trading_accts = xaccTransUseTradingAccounts (trans);
+ num_splits = xaccTransCountSplits(trans);
+ count = num_splits;
+ sva = kvp_frame_get_slot (split->inst.kvp_data, "lot-split");
+ if (!sva && !trading_accts && (2 != count)) return NULL;
- for (i = 0; i < num_splits; i++) {
- Split *s = xaccTransGetSplit(trans, i);
- if (s == split) { --count; continue; }
- if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split"))
- { --count; continue; }
- if (trading_accts &&
- xaccAccountGetType(xaccSplitGetAccount(s)) == ACCT_TYPE_TRADING)
- { --count; continue; }
- other = s;
- }
- return (1 == count) ? other : NULL;
+ for (i = 0; i < num_splits; i++)
+ {
+ Split *s = xaccTransGetSplit(trans, i);
+ if (s == split)
+ {
+ --count;
+ continue;
+ }
+ if (kvp_frame_get_slot (s->inst.kvp_data, "lot-split"))
+ {
+ --count;
+ continue;
+ }
+ if (trading_accts &&
+ xaccAccountGetType(xaccSplitGetAccount(s)) == ACCT_TYPE_TRADING)
+ {
+ --count;
+ continue;
+ }
+ other = s;
+ }
+ return (1 == count) ? other : NULL;
}
/********************************************************************\
@@ -1920,21 +1968,21 @@
gboolean
xaccIsPeerSplit (const Split *sa, const Split *sb)
{
- return (sa && sb && (sa->parent == sb->parent));
+ return (sa && sb && (sa->parent == sb->parent));
}
gnc_numeric
xaccSplitVoidFormerAmount(const Split *split)
{
- g_return_val_if_fail(split, gnc_numeric_zero());
- return kvp_frame_get_numeric(split->inst.kvp_data, void_former_amt_str);
+ g_return_val_if_fail(split, gnc_numeric_zero());
+ return kvp_frame_get_numeric(split->inst.kvp_data, void_former_amt_str);
}
gnc_numeric
xaccSplitVoidFormerValue(const Split *split)
{
- g_return_val_if_fail(split, gnc_numeric_zero());
- return kvp_frame_get_numeric(split->inst.kvp_data, void_former_val_str);
+ g_return_val_if_fail(split, gnc_numeric_zero());
+ return kvp_frame_get_numeric(split->inst.kvp_data, void_former_val_str);
}
void
@@ -1943,9 +1991,9 @@
gnc_numeric zero = gnc_numeric_zero();
KvpFrame *frame = split->inst.kvp_data;
- kvp_frame_set_gnc_numeric(frame, void_former_amt_str,
+ kvp_frame_set_gnc_numeric(frame, void_former_amt_str,
xaccSplitGetAmount(split));
- kvp_frame_set_gnc_numeric(frame, void_former_val_str,
+ kvp_frame_set_gnc_numeric(frame, void_former_val_str,
xaccSplitGetValue(split));
xaccSplitSetAmount (split, zero);
@@ -1958,7 +2006,7 @@
xaccSplitUnvoid(Split *split)
{
KvpFrame *frame = split->inst.kvp_data;
-
+
xaccSplitSetAmount (split, xaccSplitVoidFormerAmount(split));
xaccSplitSetValue (split, xaccSplitVoidFormerValue(split));
xaccSplitSetReconcile(split, NREC);
@@ -1979,42 +2027,43 @@
#else
# define DI(x) x
#endif
-static QofObject split_object_def = {
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_ID_SPLIT,
- DI(.type_label =) "Split",
- DI(.create =) (gpointer)xaccMallocSplit,
- DI(.book_begin =) NULL,
- DI(.book_end =) NULL,
- DI(.is_dirty =) qof_collection_is_dirty,
- DI(.mark_clean =) qof_collection_mark_clean,
- DI(.foreach =) qof_collection_foreach,
- DI(.printable =) (const char* (*)(gpointer)) xaccSplitGetMemo,
- DI(.version_cmp =) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+static QofObject split_object_def =
+{
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_ID_SPLIT,
+ DI(.type_label = ) "Split",
+ DI(.create = ) (gpointer)xaccMallocSplit,
+ DI(.book_begin = ) NULL,
+ DI(.book_end = ) NULL,
+ DI(.is_dirty = ) qof_collection_is_dirty,
+ DI(.mark_clean = ) qof_collection_mark_clean,
+ DI(.foreach = ) qof_collection_foreach,
+ DI(.printable = ) (const char * (*)(gpointer)) xaccSplitGetMemo,
+ DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
};
-static gpointer
+static gpointer
split_account_guid_getter (gpointer obj, const QofParam *p)
{
- Split *s = obj;
- Account *acc;
+ Split *s = obj;
+ Account *acc;
- if (!s) return NULL;
- acc = xaccSplitGetAccount (s);
- if (!acc) return NULL;
- return ((gpointer)xaccAccountGetGUID (acc));
+ if (!s) return NULL;
+ acc = xaccSplitGetAccount (s);
+ if (!acc) return NULL;
+ return ((gpointer)xaccAccountGetGUID (acc));
}
static double /* internal use only */
-DxaccSplitGetShareAmount (const Split * split)
+DxaccSplitGetShareAmount (const Split * split)
{
- return split ? gnc_numeric_to_double(xaccSplitGetAmount(split)) : 0.0;
+ return split ? gnc_numeric_to_double(xaccSplitGetAmount(split)) : 0.0;
}
-static gpointer
+static gpointer
no_op (gpointer obj, const QofParam *p)
{
- return obj;
+ return obj;
}
static void
@@ -2037,71 +2086,106 @@
gboolean xaccSplitRegister (void)
{
- static const QofParam params[] = {
- { SPLIT_DATE_RECONCILED, QOF_TYPE_DATE,
- (QofAccessFunc)xaccSplitRetDateReconciledTS,
- (QofSetterFunc)xaccSplitSetDateReconciledTS },
+ static const QofParam params[] =
+ {
+ {
+ SPLIT_DATE_RECONCILED, QOF_TYPE_DATE,
+ (QofAccessFunc)xaccSplitRetDateReconciledTS,
+ (QofSetterFunc)xaccSplitSetDateReconciledTS
+ },
- /* d-* are deprecated query params, should not be used in new
- * queries, should be removed from old queries. */
- { "d-share-amount", QOF_TYPE_DOUBLE,
- (QofAccessFunc)DxaccSplitGetShareAmount, NULL },
- { "d-share-int64", QOF_TYPE_INT64,
- (QofAccessFunc)qof_entity_get_guid, NULL },
- { SPLIT_BALANCE, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccSplitGetBalance, NULL },
- { SPLIT_CLEARED_BALANCE, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccSplitGetClearedBalance, NULL },
- { SPLIT_RECONCILED_BALANCE, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccSplitGetReconciledBalance, NULL },
- { SPLIT_MEMO, QOF_TYPE_STRING,
- (QofAccessFunc)xaccSplitGetMemo, (QofSetterFunc)qofSplitSetMemo },
- { SPLIT_ACTION, QOF_TYPE_STRING,
- (QofAccessFunc)xaccSplitGetAction, (QofSetterFunc)qofSplitSetAction },
- { SPLIT_RECONCILE, QOF_TYPE_CHAR,
- (QofAccessFunc)xaccSplitGetReconcile,
- (QofSetterFunc)qofSplitSetReconcile },
- { SPLIT_AMOUNT, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccSplitGetAmount, (QofSetterFunc)qofSplitSetAmount },
- { SPLIT_SHARE_PRICE, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccSplitGetSharePrice,
- (QofSetterFunc)qofSplitSetSharePrice },
- { SPLIT_VALUE, QOF_TYPE_DEBCRED,
- (QofAccessFunc)xaccSplitGetValue, (QofSetterFunc)qofSplitSetValue },
- { SPLIT_TYPE, QOF_TYPE_STRING, (QofAccessFunc)xaccSplitGetType, NULL },
- { SPLIT_VOIDED_AMOUNT, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccSplitVoidFormerAmount, NULL },
- { SPLIT_VOIDED_VALUE, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccSplitVoidFormerValue, NULL },
- { SPLIT_LOT, GNC_ID_LOT, (QofAccessFunc)xaccSplitGetLot, NULL },
- { SPLIT_TRANS, GNC_ID_TRANS,
- (QofAccessFunc)xaccSplitGetParent,
- (QofSetterFunc)qofSplitSetParentTrans },
- { SPLIT_ACCOUNT, GNC_ID_ACCOUNT,
- (QofAccessFunc)xaccSplitGetAccount, (QofSetterFunc)qofSplitSetAccount },
- { SPLIT_ACCOUNT_GUID, QOF_TYPE_GUID, split_account_guid_getter, NULL },
-/* these are no-ops to register the parameter names (for sorting) but
- they return an allocated object which getters cannot do. */
- { SPLIT_ACCT_FULLNAME, SPLIT_ACCT_FULLNAME, no_op, NULL },
- { SPLIT_CORR_ACCT_NAME, SPLIT_CORR_ACCT_NAME, no_op, NULL },
- { SPLIT_CORR_ACCT_CODE, SPLIT_CORR_ACCT_CODE, no_op, NULL },
- { SPLIT_KVP, QOF_TYPE_KVP, (QofAccessFunc)xaccSplitGetSlots, NULL },
- { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)xaccSplitGetBook, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID,
- (QofAccessFunc)qof_entity_get_guid, NULL },
- { NULL },
- };
+ /* d-* are deprecated query params, should not be used in new
+ * queries, should be removed from old queries. */
+ {
+ "d-share-amount", QOF_TYPE_DOUBLE,
+ (QofAccessFunc)DxaccSplitGetShareAmount, NULL
+ },
+ {
+ "d-share-int64", QOF_TYPE_INT64,
+ (QofAccessFunc)qof_entity_get_guid, NULL
+ },
+ {
+ SPLIT_BALANCE, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccSplitGetBalance, NULL
+ },
+ {
+ SPLIT_CLEARED_BALANCE, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccSplitGetClearedBalance, NULL
+ },
+ {
+ SPLIT_RECONCILED_BALANCE, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccSplitGetReconciledBalance, NULL
+ },
+ {
+ SPLIT_MEMO, QOF_TYPE_STRING,
+ (QofAccessFunc)xaccSplitGetMemo, (QofSetterFunc)qofSplitSetMemo
+ },
+ {
+ SPLIT_ACTION, QOF_TYPE_STRING,
+ (QofAccessFunc)xaccSplitGetAction, (QofSetterFunc)qofSplitSetAction
+ },
+ {
+ SPLIT_RECONCILE, QOF_TYPE_CHAR,
+ (QofAccessFunc)xaccSplitGetReconcile,
+ (QofSetterFunc)qofSplitSetReconcile
+ },
+ {
+ SPLIT_AMOUNT, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccSplitGetAmount, (QofSetterFunc)qofSplitSetAmount
+ },
+ {
+ SPLIT_SHARE_PRICE, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccSplitGetSharePrice,
+ (QofSetterFunc)qofSplitSetSharePrice
+ },
+ {
+ SPLIT_VALUE, QOF_TYPE_DEBCRED,
+ (QofAccessFunc)xaccSplitGetValue, (QofSetterFunc)qofSplitSetValue
+ },
+ { SPLIT_TYPE, QOF_TYPE_STRING, (QofAccessFunc)xaccSplitGetType, NULL },
+ {
+ SPLIT_VOIDED_AMOUNT, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccSplitVoidFormerAmount, NULL
+ },
+ {
+ SPLIT_VOIDED_VALUE, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccSplitVoidFormerValue, NULL
+ },
+ { SPLIT_LOT, GNC_ID_LOT, (QofAccessFunc)xaccSplitGetLot, NULL },
+ {
+ SPLIT_TRANS, GNC_ID_TRANS,
+ (QofAccessFunc)xaccSplitGetParent,
+ (QofSetterFunc)qofSplitSetParentTrans
+ },
+ {
+ SPLIT_ACCOUNT, GNC_ID_ACCOUNT,
+ (QofAccessFunc)xaccSplitGetAccount, (QofSetterFunc)qofSplitSetAccount
+ },
+ { SPLIT_ACCOUNT_GUID, QOF_TYPE_GUID, split_account_guid_getter, NULL },
+ /* these are no-ops to register the parameter names (for sorting) but
+ they return an allocated object which getters cannot do. */
+ { SPLIT_ACCT_FULLNAME, SPLIT_ACCT_FULLNAME, no_op, NULL },
+ { SPLIT_CORR_ACCT_NAME, SPLIT_CORR_ACCT_NAME, no_op, NULL },
+ { SPLIT_CORR_ACCT_CODE, SPLIT_CORR_ACCT_CODE, no_op, NULL },
+ { SPLIT_KVP, QOF_TYPE_KVP, (QofAccessFunc)xaccSplitGetSlots, NULL },
+ { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)xaccSplitGetBook, NULL },
+ {
+ QOF_PARAM_GUID, QOF_TYPE_GUID,
+ (QofAccessFunc)qof_entity_get_guid, NULL
+ },
+ { NULL },
+ };
- qof_class_register (GNC_ID_SPLIT, (QofSortFunc)xaccSplitOrder, params);
- qof_class_register (SPLIT_ACCT_FULLNAME,
- (QofSortFunc)xaccSplitCompareAccountFullNames, NULL);
- qof_class_register (SPLIT_CORR_ACCT_NAME,
- (QofSortFunc)xaccSplitCompareOtherAccountFullNames,
- NULL);
- qof_class_register (SPLIT_CORR_ACCT_CODE,
- (QofSortFunc)xaccSplitCompareOtherAccountCodes, NULL);
+ qof_class_register (GNC_ID_SPLIT, (QofSortFunc)xaccSplitOrder, params);
+ qof_class_register (SPLIT_ACCT_FULLNAME,
+ (QofSortFunc)xaccSplitCompareAccountFullNames, NULL);
+ qof_class_register (SPLIT_CORR_ACCT_NAME,
+ (QofSortFunc)xaccSplitCompareOtherAccountFullNames,
+ NULL);
+ qof_class_register (SPLIT_CORR_ACCT_CODE,
+ (QofSortFunc)xaccSplitCompareOtherAccountCodes, NULL);
- return qof_object_register (&split_object_def);
+ return qof_object_register (&split_object_def);
}
/************************ END OF ************************************\
Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/Transaction.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -34,9 +34,10 @@
# include <sys/time.h>
#else
/* We simply define the struct timeval on our own here. */
-struct timeval {
- long tv_sec; /* seconds */
- long tv_usec; /* and microseconds */
+struct timeval
+{
+ long tv_sec; /* seconds */
+ long tv_usec; /* and microseconds */
};
/* include <Winsock2.h> */
#endif
@@ -157,14 +158,14 @@
*
*
*
- * Design notes on event-generation: transaction-modified-events
+ * Design notes on event-generation: transaction-modified-events
* should not be generated until transaction commit or rollback
- * time. They should not be generated as each field is tweaked.
+ * time. They should not be generated as each field is tweaked.
* This for two reasons:
* 1) Most editing events make multiple changes to a transaction,
* which would generate a flurry of (needless) events, if they
* weren't saved up till the commit.
- * 2) Technically, its incorrect to use transaction data
+ * 2) Technically, its incorrect to use transaction data
* until the transaction is commited. The GUI element that
* is changing the data can look at it, but all of the rest
* of the GUI should ignore the data until its commited.
@@ -186,19 +187,20 @@
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_ENGINE;
-enum {
- PROP_0,
- PROP_NUM,
- PROP_DESCRIPTION,
- PROP_CURRENCY,
- PROP_POST_DATE,
- PROP_ENTER_DATE
+enum
+{
+ PROP_0,
+ PROP_NUM,
+ PROP_DESCRIPTION,
+ PROP_CURRENCY,
+ PROP_POST_DATE,
+ PROP_ENTER_DATE
};
void check_open (const Transaction *trans)
{
- if (trans && 0 >= qof_instance_get_editlevel(trans))
- PERR ("transaction %p not open for editing", trans);
+ if (trans && 0 >= qof_instance_get_editlevel(trans))
+ PERR ("transaction %p not open for editing", trans);
}
/********************************************************************\
\********************************************************************/
@@ -223,29 +225,29 @@
G_INLINE_FUNC void mark_trans (Transaction *trans);
void mark_trans (Transaction *trans)
{
- FOR_EACH_SPLIT(trans, mark_split(s));
+ FOR_EACH_SPLIT(trans, mark_split(s));
}
G_INLINE_FUNC void gen_event_trans (Transaction *trans);
void gen_event_trans (Transaction *trans)
{
#ifndef REGISTER_STILL_DEPENDS_ON_ACCOUNT_EVENTS
- GList *node;
+ GList *node;
- for (node = trans->splits; node; node = node->next)
- {
- Split *s = node->data;
- Account *account = s->acc;
- GNCLot *lot = s->lot;
- if (account)
- qof_event_gen (&account->inst, GNC_EVENT_ITEM_CHANGED, s);
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ Account *account = s->acc;
+ GNCLot *lot = s->lot;
+ if (account)
+ qof_event_gen (&account->inst, GNC_EVENT_ITEM_CHANGED, s);
- if (lot)
- {
- /* A change of transaction date might affect opening date of lot */
- qof_event_gen (QOF_INSTANCE(lot), QOF_EVENT_MODIFY, NULL);
+ if (lot)
+ {
+ /* A change of transaction date might affect opening date of lot */
+ qof_event_gen (QOF_INSTANCE(lot), QOF_EVENT_MODIFY, NULL);
+ }
}
- }
#endif
}
@@ -255,23 +257,23 @@
static void
gnc_transaction_init(Transaction* trans)
{
- ENTER ("trans=%p", trans);
- /* Fill in some sane defaults */
- trans->num = CACHE_INSERT("");
- trans->description = CACHE_INSERT("");
+ ENTER ("trans=%p", trans);
+ /* Fill in some sane defaults */
+ trans->num = CACHE_INSERT("");
+ trans->description = CACHE_INSERT("");
- trans->common_currency = NULL;
- trans->splits = NULL;
+ trans->common_currency = NULL;
+ trans->splits = NULL;
- trans->date_entered.tv_sec = 0;
- trans->date_entered.tv_nsec = 0;
+ trans->date_entered.tv_sec = 0;
+ trans->date_entered.tv_nsec = 0;
- trans->date_posted.tv_sec = 0;
- trans->date_posted.tv_nsec = 0;
+ trans->date_posted.tv_sec = 0;
+ trans->date_posted.tv_nsec = 0;
- trans->marker = 0;
- trans->orig = NULL;
- LEAVE (" ");
+ trans->marker = 0;
+ trans->orig = NULL;
+ LEAVE (" ");
}
static void
@@ -288,67 +290,69 @@
static void
gnc_transaction_get_property(GObject* object,
- guint prop_id,
- GValue* value,
- GParamSpec* pspec)
+ guint prop_id,
+ GValue* value,
+ GParamSpec* pspec)
{
Transaction* tx;
- g_return_if_fail(GNC_IS_TRANSACTION(object));
+ g_return_if_fail(GNC_IS_TRANSACTION(object));
- tx = GNC_TRANSACTION(object);
- switch(prop_id) {
- case PROP_NUM:
+ tx = GNC_TRANSACTION(object);
+ switch (prop_id)
+ {
+ case PROP_NUM:
g_value_set_string(value, tx->num);
- break;
- case PROP_DESCRIPTION:
+ break;
+ case PROP_DESCRIPTION:
g_value_set_string(value, tx->description);
- break;
+ break;
case PROP_CURRENCY:
- g_value_set_object(value, tx->common_currency);
- break;
+ g_value_set_object(value, tx->common_currency);
+ break;
case PROP_POST_DATE:
- g_value_set_boxed(value, &tx->date_posted);
- break;
+ g_value_set_boxed(value, &tx->date_posted);
+ break;
case PROP_ENTER_DATE:
- g_value_set_boxed(value, &tx->date_entered);
- break;
+ g_value_set_boxed(value, &tx->date_entered);
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
}
static void
gnc_transaction_set_property(GObject* object,
- guint prop_id,
- const GValue* value,
- GParamSpec* pspec)
+ guint prop_id,
+ const GValue* value,
+ GParamSpec* pspec)
{
Transaction* tx;
- Timespec* ts;
+ Timespec* ts;
- g_return_if_fail(GNC_IS_TRANSACTION(object));
+ g_return_if_fail(GNC_IS_TRANSACTION(object));
- tx = GNC_TRANSACTION(object);
- switch(prop_id) {
- case PROP_NUM:
+ tx = GNC_TRANSACTION(object);
+ switch (prop_id)
+ {
+ case PROP_NUM:
xaccTransSetNum( tx, g_value_get_string(value));
- break;
- case PROP_DESCRIPTION:
+ break;
+ case PROP_DESCRIPTION:
xaccTransSetDescription(tx, g_value_get_string(value));
- break;
+ break;
case PROP_CURRENCY:
- xaccTransSetCurrency(tx, g_value_get_object(value));
- break;
+ xaccTransSetCurrency(tx, g_value_get_object(value));
+ break;
case PROP_POST_DATE:
- xaccTransSetDatePostedTS(tx, g_value_get_boxed(value));
- break;
+ xaccTransSetDatePostedTS(tx, g_value_get_boxed(value));
+ break;
case PROP_ENTER_DATE:
- xaccTransSetDateEnteredTS(tx, g_value_get_boxed(value));
- break;
+ xaccTransSetDateEnteredTS(tx, g_value_get_boxed(value));
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ }
}
static void
@@ -356,63 +360,63 @@
{
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->dispose = gnc_transaction_dispose;
- gobject_class->finalize = gnc_transaction_finalize;
- gobject_class->set_property = gnc_transaction_set_property;
- gobject_class->get_property = gnc_transaction_get_property;
+ gobject_class->dispose = gnc_transaction_dispose;
+ gobject_class->finalize = gnc_transaction_finalize;
+ gobject_class->set_property = gnc_transaction_set_property;
+ gobject_class->get_property = gnc_transaction_get_property;
- g_object_class_install_property
- (gobject_class,
- PROP_NUM,
- g_param_spec_string("num",
- "Transaction Number",
- "The transactionNumber is an arbitrary string "
- "assigned by the user. It is intended to be "
- "a short 1-6 character string that is displayed "
- "by the register. For checks, it is usually the "
- "check number. For other types of transactions, "
- "it can be any string.",
- NULL,
- G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class,
+ PROP_NUM,
+ g_param_spec_string("num",
+ "Transaction Number",
+ "The transactionNumber is an arbitrary string "
+ "assigned by the user. It is intended to be "
+ "a short 1-6 character string that is displayed "
+ "by the register. For checks, it is usually the "
+ "check number. For other types of transactions, "
+ "it can be any string.",
+ NULL,
+ G_PARAM_READWRITE));
- g_object_class_install_property
- (gobject_class,
- PROP_DESCRIPTION,
- g_param_spec_string("description",
- "Transaction Description",
- "The transaction description is an arbitrary string "
- "assigned by the user. It is usually the customer, "
- "vendor or other organization associated with the "
- "transaction.",
- NULL,
- G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class,
+ PROP_DESCRIPTION,
+ g_param_spec_string("description",
+ "Transaction Description",
+ "The transaction description is an arbitrary string "
+ "assigned by the user. It is usually the customer, "
+ "vendor or other organization associated with the "
+ "transaction.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_CURRENCY,
- g_param_spec_object ("currency",
- "Currency",
- "The base currency for this transaction.",
- GNC_TYPE_COMMODITY,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_CURRENCY,
+ g_param_spec_object ("currency",
+ "Currency",
+ "The base currency for this transaction.",
+ GNC_TYPE_COMMODITY,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_POST_DATE,
- g_param_spec_boxed("post-date",
- "Post Date",
- "The date the transaction occurred.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_POST_DATE,
+ g_param_spec_boxed("post-date",
+ "Post Date",
+ "The date the transaction occurred.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READWRITE));
g_object_class_install_property
- (gobject_class,
- PROP_ENTER_DATE,
- g_param_spec_boxed("enter-date",
- "Enter Date",
- "The date the transaction was entered.",
- GNC_TYPE_NUMERIC,
- G_PARAM_READWRITE));
+ (gobject_class,
+ PROP_ENTER_DATE,
+ g_param_spec_boxed("enter-date",
+ "Enter Date",
+ "The date the transaction was entered.",
+ GNC_TYPE_NUMERIC,
+ G_PARAM_READWRITE));
}
/********************************************************************\
@@ -423,9 +427,9 @@
static void
xaccInitTransaction (Transaction * trans, QofBook *book)
{
- ENTER ("trans=%p", trans);
- qof_instance_init_data (&trans->inst, GNC_ID_TRANS, book);
- LEAVE (" ");
+ ENTER ("trans=%p", trans);
+ qof_instance_init_data (&trans->inst, GNC_ID_TRANS, book);
+ LEAVE (" ");
}
/********************************************************************\
@@ -434,120 +438,122 @@
Transaction *
xaccMallocTransaction (QofBook *book)
{
- Transaction *trans;
+ Transaction *trans;
- g_return_val_if_fail (book, NULL);
+ g_return_val_if_fail (book, NULL);
- trans = g_object_new(GNC_TYPE_TRANSACTION, NULL);
- xaccInitTransaction (trans, book);
- qof_event_gen (&trans->inst, QOF_EVENT_CREATE, NULL);
+ trans = g_object_new(GNC_TYPE_TRANSACTION, NULL);
+ xaccInitTransaction (trans, book);
+ qof_event_gen (&trans->inst, QOF_EVENT_CREATE, NULL);
- return trans;
+ return trans;
}
#ifdef DUMP_FUNCTIONS
void
xaccTransDump (const Transaction *trans, const char *tag)
{
- GList *node;
+ GList *node;
- printf("%s Trans %p", tag, trans);
- printf(" Entered: %s\n", gnc_print_date(trans->date_entered));
- printf(" Posted: %s\n", gnc_print_date(trans->date_posted));
- printf(" Num: %s\n", trans->num ? trans->num : "(null)");
- printf(" Description: %s\n",
- trans->description ? trans->description : "(null)");
- printf(" Currency: %s\n",
- gnc_commodity_get_printname(trans->common_currency));
- printf(" version: %x\n", qof_instance_get_version(trans));
- printf(" version_chk: %x\n", qof_instance_get_version_check(trans));
- printf(" editlevel: %x\n", qof_instance_get_editlevel(trans));
- printf(" orig: %p\n", trans->orig);
- printf(" idata: %x\n", qof_instance_get_idata(trans));
- printf(" splits: ");
- for (node = trans->splits; node; node = node->next)
- {
- printf("%p ", node->data);
- }
- printf("\n");
- for (node = trans->splits; node; node = node->next)
- {
- xaccSplitDump(node->data, tag);
- }
- printf("\n");
+ printf("%s Trans %p", tag, trans);
+ printf(" Entered: %s\n", gnc_print_date(trans->date_entered));
+ printf(" Posted: %s\n", gnc_print_date(trans->date_posted));
+ printf(" Num: %s\n", trans->num ? trans->num : "(null)");
+ printf(" Description: %s\n",
+ trans->description ? trans->description : "(null)");
+ printf(" Currency: %s\n",
+ gnc_commodity_get_printname(trans->common_currency));
+ printf(" version: %x\n", qof_instance_get_version(trans));
+ printf(" version_chk: %x\n", qof_instance_get_version_check(trans));
+ printf(" editlevel: %x\n", qof_instance_get_editlevel(trans));
+ printf(" orig: %p\n", trans->orig);
+ printf(" idata: %x\n", qof_instance_get_idata(trans));
+ printf(" splits: ");
+ for (node = trans->splits; node; node = node->next)
+ {
+ printf("%p ", node->data);
+ }
+ printf("\n");
+ for (node = trans->splits; node; node = node->next)
+ {
+ xaccSplitDump(node->data, tag);
+ }
+ printf("\n");
}
#endif
void
xaccTransSortSplits (Transaction *trans)
{
- GList *node, *new_list = NULL;
- Split *split;
+ GList *node, *new_list = NULL;
+ Split *split;
- /* first debits */
- for (node = trans->splits; node; node = node->next) {
- split = node->data;
- if (gnc_numeric_negative_p (xaccSplitGetValue(split)))
- continue;
- new_list = g_list_append(new_list, split);
- }
+ /* first debits */
+ for (node = trans->splits; node; node = node->next)
+ {
+ split = node->data;
+ if (gnc_numeric_negative_p (xaccSplitGetValue(split)))
+ continue;
+ new_list = g_list_append(new_list, split);
+ }
- /* then credits */
- for (node = trans->splits; node; node = node->next) {
- split = node->data;
- if (!gnc_numeric_negative_p (xaccSplitGetValue(split)))
- continue;
- new_list = g_list_append(new_list, split);
- }
+ /* then credits */
+ for (node = trans->splits; node; node = node->next)
+ {
+ split = node->data;
+ if (!gnc_numeric_negative_p (xaccSplitGetValue(split)))
+ continue;
+ new_list = g_list_append(new_list, split);
+ }
- /* install newly sorted list */
- g_list_free(trans->splits);
- trans->splits = new_list;
+ /* install newly sorted list */
+ g_list_free(trans->splits);
+ trans->splits = new_list;
}
/********************************************************************\
\********************************************************************/
-/* This routine is not exposed externally, since it does weird things,
- * like not really owning the splits correctly, and other weirdnesses.
- * This routine is prone to programmer snafu if not used correctly.
+/* This routine is not exposed externally, since it does weird things,
+ * like not really owning the splits correctly, and other weirdnesses.
+ * This routine is prone to programmer snafu if not used correctly.
* It is used only by the edit-rollback code.
*/
/* Actually, it *is* public, and used by Period.c */
Transaction *
xaccDupeTransaction (const Transaction *from)
{
- Transaction *to;
- GList *node;
+ Transaction *to;
+ GList *node;
- to = g_object_new (GNC_TYPE_TRANSACTION, NULL);
+ to = g_object_new (GNC_TYPE_TRANSACTION, NULL);
- to->num = CACHE_INSERT (from->num);
- to->description = CACHE_INSERT (from->description);
+ to->num = CACHE_INSERT (from->num);
+ to->description = CACHE_INSERT (from->description);
- to->splits = g_list_copy (from->splits);
- for (node = to->splits; node; node = node->next)
- {
- node->data = xaccDupeSplit (node->data);
- }
+ to->splits = g_list_copy (from->splits);
+ for (node = to->splits; node; node = node->next)
+ {
+ node->data = xaccDupeSplit (node->data);
+ }
- to->date_entered = from->date_entered;
- to->date_posted = from->date_posted;
- qof_instance_copy_version(to, from);
- to->orig = NULL;
+ to->date_entered = from->date_entered;
+ to->date_posted = from->date_posted;
+ qof_instance_copy_version(to, from);
+ to->orig = NULL;
- to->common_currency = from->common_currency;
+ to->common_currency = from->common_currency;
- /* Trash the guid and entity table. We don't want to mistake
- * the cloned transaction as something official. If we ever
- * use this transaction, we'll have to fix this up.
- */
- to->inst.e_type = NULL;
- qof_instance_set_guid(to, guid_null());
- qof_instance_copy_book(to, from);
- to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data);
+ /* Trash the guid and entity table. We don't want to mistake
+ * the cloned transaction as something official. If we ever
+ * use this transaction, we'll have to fix this up.
+ */
+ to->inst.e_type = NULL;
+ qof_instance_set_guid(to, guid_null());
+ qof_instance_copy_book(to, from);
+ to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data);
- return to;
+ return to;
}
/*
@@ -557,39 +563,39 @@
Transaction *
xaccTransClone (const Transaction *from)
{
- Transaction *to;
- Split *split;
- GList *node;
+ Transaction *to;
+ Split *split;
+ GList *node;
- qof_event_suspend();
- to = g_object_new (GNC_TYPE_TRANSACTION, NULL);
+ qof_event_suspend();
+ to = g_object_new (GNC_TYPE_TRANSACTION, NULL);
- to->date_entered = from->date_entered;
- to->date_posted = from->date_posted;
- to->num = CACHE_INSERT (from->num);
- to->description = CACHE_INSERT (from->description);
- to->common_currency = from->common_currency;
- qof_instance_copy_version(to, from);
- qof_instance_copy_version_check(to, from);
+ to->date_entered = from->date_entered;
+ to->date_posted = from->date_posted;
+ to->num = CACHE_INSERT (from->num);
+ to->description = CACHE_INSERT (from->description);
+ to->common_currency = from->common_currency;
+ qof_instance_copy_version(to, from);
+ qof_instance_copy_version_check(to, from);
- to->orig = NULL;
+ to->orig = NULL;
- qof_instance_init_data (&to->inst, GNC_ID_TRANS, qof_instance_get_book(from));
- kvp_frame_delete (to->inst.kvp_data);
- to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data);
+ qof_instance_init_data (&to->inst, GNC_ID_TRANS, qof_instance_get_book(from));
+ kvp_frame_delete (to->inst.kvp_data);
+ to->inst.kvp_data = kvp_frame_copy (from->inst.kvp_data);
- xaccTransBeginEdit(to);
- for (node = from->splits; node; node = node->next)
- {
- split = xaccSplitClone(node->data);
- split->parent = to;
- to->splits = g_list_append (to->splits, split);
- }
- qof_instance_set_dirty(QOF_INSTANCE(to));
- xaccTransCommitEdit(to);
- qof_event_resume();
+ xaccTransBeginEdit(to);
+ for (node = from->splits; node; node = node->next)
+ {
+ split = xaccSplitClone(node->data);
+ split->parent = to;
+ to->splits = g_list_append (to->splits, split);
+ }
+ qof_instance_set_dirty(QOF_INSTANCE(to));
+ xaccTransCommitEdit(to);
+ qof_event_resume();
- return to;
+ return to;
}
@@ -599,47 +605,47 @@
static void
xaccFreeTransaction (Transaction *trans)
{
- GList *node;
+ GList *node;
- if (!trans) return;
+ if (!trans) return;
- ENTER ("(addr=%p)", trans);
- if (((char *) 1) == trans->num)
- {
- PERR ("double-free %p", trans);
- LEAVE (" ");
- return;
- }
+ ENTER ("(addr=%p)", trans);
+ if (((char *) 1) == trans->num)
+ {
+ PERR ("double-free %p", trans);
+ LEAVE (" ");
+ return;
+ }
- /* free up the destination splits */
- for (node = trans->splits; node; node = node->next)
- xaccFreeSplit (node->data);
- g_list_free (trans->splits);
- trans->splits = NULL;
+ /* free up the destination splits */
+ for (node = trans->splits; node; node = node->next)
+ xaccFreeSplit (node->data);
+ g_list_free (trans->splits);
+ trans->splits = NULL;
- /* free up transaction strings */
- CACHE_REMOVE(trans->num);
- CACHE_REMOVE(trans->description);
+ /* free up transaction strings */
+ CACHE_REMOVE(trans->num);
+ CACHE_REMOVE(trans->description);
- /* Just in case someone looks up freed memory ... */
- trans->num = (char *) 1;
- trans->description = NULL;
+ /* Just in case someone looks up freed memory ... */
+ trans->num = (char *) 1;
+ trans->description = NULL;
- trans->date_entered.tv_sec = 0;
- trans->date_entered.tv_nsec = 0;
- trans->date_posted.tv_sec = 0;
- trans->date_posted.tv_nsec = 0;
+ trans->date_entered.tv_sec = 0;
+ trans->date_entered.tv_nsec = 0;
+ trans->date_posted.tv_sec = 0;
+ trans->date_posted.tv_nsec = 0;
- if (trans->orig)
- {
- xaccFreeTransaction (trans->orig);
- trans->orig = NULL;
- }
+ if (trans->orig)
+ {
+ xaccFreeTransaction (trans->orig);
+ trans->orig = NULL;
+ }
- /* qof_instance_release (&trans->inst); */
- g_object_unref(trans);
+ /* qof_instance_release (&trans->inst); */
+ g_object_unref(trans);
- LEAVE ("(addr=%p)", trans);
+ LEAVE ("(addr=%p)", trans);
}
/********************************************************************
@@ -656,13 +662,13 @@
static gint
compare_split_guids (gconstpointer a, gconstpointer b)
{
- const Split *sa = a;
- const Split *sb = b;
+ const Split *sa = a;
+ const Split *sb = b;
- if (sa == sb) return 0;
- if (!sa || !sb) return 1;
+ if (sa == sb) return 0;
+ if (!sa || !sb) return 1;
- return guid_compare (xaccSplitGetGUID (sa), xaccSplitGetGUID (sb));
+ return guid_compare (xaccSplitGetGUID (sa), xaccSplitGetGUID (sb));
}
gboolean
@@ -672,131 +678,132 @@
gboolean check_balances,
gboolean assume_ordered)
{
- if (!ta && !tb) return TRUE; /* Arguable. FALSE may be better. */
+ if (!ta && !tb) return TRUE; /* Arguable. FALSE may be better. */
- if (!ta || !tb)
- {
- PWARN ("one is NULL");
- return FALSE;
- }
+ if (!ta || !tb)
+ {
+ PWARN ("one is NULL");
+ return FALSE;
+ }
- if (ta == tb) return TRUE;
+ if (ta == tb) return TRUE;
- if (check_guids) {
- if (qof_instance_guid_compare(ta, tb) != 0)
+ if (check_guids)
{
- PWARN ("GUIDs differ");
- return FALSE;
+ if (qof_instance_guid_compare(ta, tb) != 0)
+ {
+ PWARN ("GUIDs differ");
+ return FALSE;
+ }
}
- }
- if (!gnc_commodity_equal(ta->common_currency, tb->common_currency))
- {
- PWARN ("commodities differ %s vs %s",
- gnc_commodity_get_unique_name (ta->common_currency),
- gnc_commodity_get_unique_name (tb->common_currency));
- return FALSE;
- }
+ if (!gnc_commodity_equal(ta->common_currency, tb->common_currency))
+ {
+ PWARN ("commodities differ %s vs %s",
+ gnc_commodity_get_unique_name (ta->common_currency),
+ gnc_commodity_get_unique_name (tb->common_currency));
+ return FALSE;
+ }
- if (timespec_cmp(&(ta->date_entered), &(tb->date_entered)))
- {
- PWARN ("date entered differs");
- return FALSE;
- }
+ if (timespec_cmp(&(ta->date_entered), &(tb->date_entered)))
+ {
+ PWARN ("date entered differs");
+ return FALSE;
+ }
- if (timespec_cmp(&(ta->date_posted), &(tb->date_posted)))
- {
- PWARN ("date posted differs");
- return FALSE;
- }
+ if (timespec_cmp(&(ta->date_posted), &(tb->date_posted)))
+ {
+ PWARN ("date posted differs");
+ return FALSE;
+ }
- /* Since we use cached strings, we can just compare pointer
- * equality for num and description
- */
- if (ta->num != tb->num)
- {
- PWARN ("num differs: %s vs %s", ta->num, tb->num);
- return FALSE;
- }
+ /* Since we use cached strings, we can just compare pointer
+ * equality for num and description
+ */
+ if (ta->num != tb->num)
+ {
+ PWARN ("num differs: %s vs %s", ta->num, tb->num);
+ return FALSE;
+ }
- if (ta->description != tb->description)
- {
- PWARN ("descriptions differ: %s vs %s", ta->description, tb->description);
- return FALSE;
- }
+ if (ta->description != tb->description)
+ {
+ PWARN ("descriptions differ: %s vs %s", ta->description, tb->description);
+ return FALSE;
+ }
- if (kvp_frame_compare(ta->inst.kvp_data, tb->inst.kvp_data) != 0)
- {
- char *frame_a;
- char *frame_b;
+ if (kvp_frame_compare(ta->inst.kvp_data, tb->inst.kvp_data) != 0)
+ {
+ char *frame_a;
+ char *frame_b;
- frame_a = kvp_frame_to_string (ta->inst.kvp_data);
- frame_b = kvp_frame_to_string (tb->inst.kvp_data);
+ frame_a = kvp_frame_to_string (ta->inst.kvp_data);
+ frame_b = kvp_frame_to_string (tb->inst.kvp_data);
- PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
+ PWARN ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
- g_free (frame_a);
- g_free (frame_b);
+ g_free (frame_a);
+ g_free (frame_b);
- return FALSE;
- }
-
- if (check_splits)
- {
- if ((!ta->splits && tb->splits) || (!tb->splits && ta->splits))
- {
- PWARN ("only one has splits");
- return FALSE;
+ return FALSE;
}
- if (ta->splits && tb->splits)
+ if (check_splits)
{
- GList *node_a, *node_b;
+ if ((!ta->splits && tb->splits) || (!tb->splits && ta->splits))
+ {
+ PWARN ("only one has splits");
+ return FALSE;
+ }
- for (node_a = ta->splits, node_b = tb->splits;
- node_a;
- node_a = node_a->next, node_b = node_b->next)
- {
- Split *split_a = node_a->data;
- Split *split_b;
+ if (ta->splits && tb->splits)
+ {
+ GList *node_a, *node_b;
- /* don't presume that the splits are in the same order */
- if (!assume_ordered)
- node_b = g_list_find_custom (tb->splits, split_a,
- compare_split_guids);
+ for (node_a = ta->splits, node_b = tb->splits;
+ node_a;
+ node_a = node_a->next, node_b = node_b->next)
+ {
+ Split *split_a = node_a->data;
+ Split *split_b;
- if (!node_b)
- {
- PWARN ("first has split %s and second does not",
- guid_to_string (xaccSplitGetGUID (split_a)));
- return FALSE;
- }
+ /* don't presume that the splits are in the same order */
+ if (!assume_ordered)
+ node_b = g_list_find_custom (tb->splits, split_a,
+ compare_split_guids);
- split_b = node_b->data;
+ if (!node_b)
+ {
+ PWARN ("first has split %s and second does not",
+ guid_to_string (xaccSplitGetGUID (split_a)));
+ return FALSE;
+ }
- if (!xaccSplitEqual (split_a, split_b, check_guids, check_balances,
- FALSE))
- {
- char str_a[GUID_ENCODING_LENGTH+1];
- char str_b[GUID_ENCODING_LENGTH+1];
+ split_b = node_b->data;
- guid_to_string_buff (xaccSplitGetGUID (split_a), str_a);
- guid_to_string_buff (xaccSplitGetGUID (split_b), str_b);
+ if (!xaccSplitEqual (split_a, split_b, check_guids, check_balances,
+ FALSE))
+ {
+ char str_a[GUID_ENCODING_LENGTH+1];
+ char str_b[GUID_ENCODING_LENGTH+1];
- PWARN ("splits %s and %s differ", str_a, str_b);
- return FALSE;
+ guid_to_string_buff (xaccSplitGetGUID (split_a), str_a);
+ guid_to_string_buff (xaccSplitGetGUID (split_b), str_b);
+
+ PWARN ("splits %s and %s differ", str_a, str_b);
+ return FALSE;
+ }
+ }
+
+ if (g_list_length (ta->splits) != g_list_length (tb->splits))
+ {
+ PWARN ("different number of splits");
+ return FALSE;
+ }
}
- }
-
- if (g_list_length (ta->splits) != g_list_length (tb->splits))
- {
- PWARN ("different number of splits");
- return FALSE;
- }
}
- }
- return TRUE;
+ return TRUE;
}
/********************************************************************\
@@ -808,7 +815,7 @@
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
{
- return qof_book_use_trading_accounts(qof_instance_get_book (trans));
+ return qof_book_use_trading_accounts(qof_instance_get_book (trans));
}
/********************************************************************\
@@ -817,10 +824,10 @@
Transaction *
xaccTransLookup (const GUID *guid, QofBook *book)
{
- QofCollection *col;
- if (!guid || !book) return NULL;
- col = qof_book_get_collection (book, GNC_ID_TRANS);
- return (Transaction *) qof_collection_lookup_entity (col, guid);
+ QofCollection *col;
+ if (!guid || !book) return NULL;
+ col = qof_book_get_collection (book, GNC_ID_TRANS);
+ return (Transaction *) qof_collection_lookup_entity (col, guid);
}
/********************************************************************\
@@ -829,223 +836,230 @@
gnc_numeric
xaccTransGetImbalanceValue (const Transaction * trans)
{
- gnc_numeric imbal = gnc_numeric_zero();
- if (!trans) return imbal;
+ gnc_numeric imbal = gnc_numeric_zero();
+ if (!trans) return imbal;
- ENTER("(trans=%p)", trans);
- /* Could use xaccSplitsComputeValue, except that we want to use
- GNC_HOW_DENOM_EXACT */
- FOR_EACH_SPLIT(trans, imbal =
- gnc_numeric_add(imbal, xaccSplitGetValue(s),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT));
- LEAVE("(trans=%p) imbal=%s", trans, gnc_num_dbg_to_string(imbal));
- return imbal;
+ ENTER("(trans=%p)", trans);
+ /* Could use xaccSplitsComputeValue, except that we want to use
+ GNC_HOW_DENOM_EXACT */
+ FOR_EACH_SPLIT(trans, imbal =
+ gnc_numeric_add(imbal, xaccSplitGetValue(s),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT));
+ LEAVE("(trans=%p) imbal=%s", trans, gnc_num_dbg_to_string(imbal));
+ return imbal;
}
MonetaryList *
xaccTransGetImbalance (const Transaction * trans)
{
- /* imbal_value is used if either (1) the transaction has a non currency
- split or (2) all the splits are in the same currency. If there are
- no non-currency splits and not all splits are in the same currency then
- imbal_list is used to compute the imbalance. */
- MonetaryList *imbal_list = NULL;
- gnc_numeric imbal_value = gnc_numeric_zero();
- gboolean trading_accts;
-
- if (!trans) return imbal_list;
-
- ENTER("(trans=%p)", trans);
-
- trading_accts = xaccTransUseTradingAccounts (trans);
-
- /* If using trading accounts and there is at least one split that is not
- in the transaction currency or a split that has a price or exchange
- rate other than 1, then compute the balance in each commodity in the
- transaction. Otherwise (all splits are in the transaction's currency)
- then compute the balance using the value fields.
-
- Optimize for the common case of only one currency and a balanced
- transaction. */
- FOR_EACH_SPLIT(trans, {
- gnc_commodity *commodity;
- commodity = xaccAccountGetCommodity(xaccSplitGetAccount(s));
- if (trading_accts &&
+ /* imbal_value is used if either (1) the transaction has a non currency
+ split or (2) all the splits are in the same currency. If there are
+ no non-currency splits and not all splits are in the same currency then
+ imbal_list is used to compute the imbalance. */
+ MonetaryList *imbal_list = NULL;
+ gnc_numeric imbal_value = gnc_numeric_zero();
+ gboolean trading_accts;
+
+ if (!trans) return imbal_list;
+
+ ENTER("(trans=%p)", trans);
+
+ trading_accts = xaccTransUseTradingAccounts (trans);
+
+ /* If using trading accounts and there is at least one split that is not
+ in the transaction currency or a split that has a price or exchange
+ rate other than 1, then compute the balance in each commodity in the
+ transaction. Otherwise (all splits are in the transaction's currency)
+ then compute the balance using the value fields.
+
+ Optimize for the common case of only one currency and a balanced
+ transaction. */
+ FOR_EACH_SPLIT(trans,
+ {
+ gnc_commodity *commodity;
+ commodity = xaccAccountGetCommodity(xaccSplitGetAccount(s));
+ if (trading_accts &&
(imbal_list ||
- ! gnc_commodity_equiv(commodity, trans->common_currency) ||
- ! gnc_numeric_equal(xaccSplitGetAmount(s), xaccSplitGetValue(s)))) {
- /* Need to use (or already are using) a list of imbalances in each of
- the currencies used in the transaction. */
- if (! imbal_list) {
- /* All previous splits have been in the transaction's common
- currency, so imbal_value is in this currency. */
- imbal_list = gnc_monetary_list_add_value(imbal_list,
- trans->common_currency,
- imbal_value);
- }
- imbal_list = gnc_monetary_list_add_value(imbal_list, commodity,
- xaccSplitGetAmount(s));
+ ! gnc_commodity_equiv(commodity, trans->common_currency) ||
+ ! gnc_numeric_equal(xaccSplitGetAmount(s), xaccSplitGetValue(s))))
+ {
+ /* Need to use (or already are using) a list of imbalances in each of
+ the currencies used in the transaction. */
+ if (! imbal_list)
+ {
+ /* All previous splits have been in the transaction's common
+ currency, so imbal_value is in this currency. */
+ imbal_list = gnc_monetary_list_add_value(imbal_list,
+ trans->common_currency,
+ imbal_value);
+ }
+ imbal_list = gnc_monetary_list_add_value(imbal_list, commodity,
+ xaccSplitGetAmount(s));
+ }
+
+ /* Add it to the value accumulator in case we need it. */
+ imbal_value = gnc_numeric_add(imbal_value, xaccSplitGetValue(s),
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
+ } );
+
+
+ if (!imbal_list && !gnc_numeric_zero_p(imbal_value))
+ {
+ /* Not balanced and no list, create one. If we found multiple currencies
+ and no non-currency commodity then imbal_list will already exist and
+ we won't get here. */
+ imbal_list = gnc_monetary_list_add_value(imbal_list,
+ trans->common_currency,
+ imbal_value);
}
-
- /* Add it to the value accumulator in case we need it. */
- imbal_value = gnc_numeric_add(imbal_value, xaccSplitGetValue(s),
- GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
- } );
-
- if (!imbal_list && !gnc_numeric_zero_p(imbal_value)) {
- /* Not balanced and no list, create one. If we found multiple currencies
- and no non-currency commodity then imbal_list will already exist and
- we won't get here. */
- imbal_list = gnc_monetary_list_add_value(imbal_list,
- trans->common_currency,
- imbal_value);
- }
-
- /* Delete all the zero entries from the list, perhaps leaving an
- empty list */
- imbal_list = gnc_monetary_list_delete_zeros(imbal_list);
-
- LEAVE("(trans=%p), imbal=%p", trans, imbal_list);
- return imbal_list;
+ /* Delete all the zero entries from the list, perhaps leaving an
+ empty list */
+ imbal_list = gnc_monetary_list_delete_zeros(imbal_list);
+
+ LEAVE("(trans=%p), imbal=%p", trans, imbal_list);
+ return imbal_list;
}
gboolean
xaccTransIsBalanced (const Transaction *trans)
{
- MonetaryList *imbal_list;
- gboolean result;
- if (! gnc_numeric_zero_p(xaccTransGetImbalanceValue(trans)))
- return FALSE;
-
- if (!xaccTransUseTradingAccounts (trans))
- return TRUE;
-
- imbal_list = xaccTransGetImbalance(trans);
- result = imbal_list == NULL;
- gnc_monetary_list_free(imbal_list);
- return result;
+ MonetaryList *imbal_list;
+ gboolean result;
+ if (! gnc_numeric_zero_p(xaccTransGetImbalanceValue(trans)))
+ return FALSE;
+
+ if (!xaccTransUseTradingAccounts (trans))
+ return TRUE;
+
+ imbal_list = xaccTransGetImbalance(trans);
+ result = imbal_list == NULL;
+ gnc_monetary_list_free(imbal_list);
+ return result;
}
gnc_numeric
-xaccTransGetAccountValue (const Transaction *trans,
+xaccTransGetAccountValue (const Transaction *trans,
const Account *acc)
{
- gnc_numeric total = gnc_numeric_zero ();
- if (!trans || !acc) return total;
+ gnc_numeric total = gnc_numeric_zero ();
+ if (!trans || !acc) return total;
- FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s)) {
- total = gnc_numeric_add (total, xaccSplitGetValue (s),
- GNC_DENOM_AUTO,
- GNC_HOW_DENOM_EXACT);
- });
- return total;
+ FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
+{
+ total = gnc_numeric_add (total, xaccSplitGetValue (s),
+ GNC_DENOM_AUTO,
+ GNC_HOW_DENOM_EXACT);
+ });
+ return total;
}
gnc_numeric
xaccTransGetAccountAmount (const Transaction *trans, const Account *acc)
{
- gnc_numeric total = gnc_numeric_zero ();
- if (!trans || !acc) return total;
+ gnc_numeric total = gnc_numeric_zero ();
+ if (!trans || !acc) return total;
- total = gnc_numeric_convert (total, xaccAccountGetCommoditySCU (acc),
- GNC_RND_ROUND);
- FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
- total = gnc_numeric_add_fixed(
- total, xaccSplitGetAmount(s)));
- return total;
+ total = gnc_numeric_convert (total, xaccAccountGetCommoditySCU (acc),
+ GNC_RND_ROUND);
+ FOR_EACH_SPLIT(trans, if (acc == xaccSplitGetAccount(s))
+ total = gnc_numeric_add_fixed(
+ total, xaccSplitGetAmount(s)));
+ return total;
}
gnc_numeric
xaccTransGetAccountConvRate(Transaction *txn, Account *acc)
{
- gnc_numeric amount, value, convrate;
- GList *splits;
- Split *s;
- gboolean found_acc_match = FALSE;
- gnc_commodity *acc_commod = xaccAccountGetCommodity(acc);
+ gnc_numeric amount, value, convrate;
+ GList *splits;
+ Split *s;
+ gboolean found_acc_match = FALSE;
+ gnc_commodity *acc_commod = xaccAccountGetCommodity(acc);
- /* We need to compute the conversion rate into _this account_. So,
- * find the first split into this account, compute the conversion
- * rate (based on amount/value), and then return this conversion
- * rate.
- */
- if (gnc_commodity_equal(acc_commod, xaccTransGetCurrency(txn)))
- return gnc_numeric_create(1, 1);
+ /* We need to compute the conversion rate into _this account_. So,
+ * find the first split into this account, compute the conversion
+ * rate (based on amount/value), and then return this conversion
+ * rate.
+ */
+ if (gnc_commodity_equal(acc_commod, xaccTransGetCurrency(txn)))
+ return gnc_numeric_create(1, 1);
- for (splits = txn->splits; splits; splits = splits->next) {
- Account *split_acc;
- gnc_commodity *split_commod;
-
- s = splits->data;
+ for (splits = txn->splits; splits; splits = splits->next)
+ {
+ Account *split_acc;
+ gnc_commodity *split_commod;
- if (!xaccTransStillHasSplit(txn, s))
- continue;
- split_acc = xaccSplitGetAccount (s);
- split_commod = xaccAccountGetCommodity (split_acc);
- if (! (split_acc == acc ||
- gnc_commodity_equal (split_commod, acc_commod)))
- continue;
+ s = splits->data;
- found_acc_match = TRUE;
- amount = xaccSplitGetAmount (s);
+ if (!xaccTransStillHasSplit(txn, s))
+ continue;
+ split_acc = xaccSplitGetAccount (s);
+ split_commod = xaccAccountGetCommodity (split_acc);
+ if (! (split_acc == acc ||
+ gnc_commodity_equal (split_commod, acc_commod)))
+ continue;
- /* Ignore splits with "zero" amount */
- if (gnc_numeric_zero_p (amount))
- continue;
+ found_acc_match = TRUE;
+ amount = xaccSplitGetAmount (s);
- value = xaccSplitGetValue (s);
- if (gnc_numeric_zero_p (value))
- PWARN("How can amount be nonzero and value be zero?");
+ /* Ignore splits with "zero" amount */
+ if (gnc_numeric_zero_p (amount))
+ continue;
- convrate = gnc_numeric_div(amount, value, GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
- return convrate;
- }
+ value = xaccSplitGetValue (s);
+ if (gnc_numeric_zero_p (value))
+ PWARN("How can amount be nonzero and value be zero?");
- if (acc) {
- /* If we did find a matching account but its amount was zero,
- * then perhaps this is a "special" income/loss transaction
- */
- if (found_acc_match)
- return gnc_numeric_zero();
- else
- PERR("Cannot convert transaction -- no splits with proper conversion ratio");
- }
- return gnc_numeric_create (100, 100);
+ convrate = gnc_numeric_div(amount, value, GNC_DENOM_AUTO, GNC_DENOM_REDUCE);
+ return convrate;
+ }
+
+ if (acc)
+ {
+ /* If we did find a matching account but its amount was zero,
+ * then perhaps this is a "special" income/loss transaction
+ */
+ if (found_acc_match)
+ return gnc_numeric_zero();
+ else
+ PERR("Cannot convert transaction -- no splits with proper conversion ratio");
+ }
+ return gnc_numeric_create (100, 100);
}
gnc_numeric
xaccTransGetAccountBalance (const Transaction *trans,
const Account *account)
{
- GList *node;
- Split *last_split = NULL;
+ GList *node;
+ Split *last_split = NULL;
- // Not really the appropriate error value.
- g_return_val_if_fail(account && trans, gnc_numeric_error(GNC_ERROR_ARG));
+ // Not really the appropriate error value.
+ g_return_val_if_fail(account && trans, gnc_numeric_error(GNC_ERROR_ARG));
- for (node = trans->splits; node; node = node->next)
- {
- Split *split = node->data;
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *split = node->data;
- if (!xaccTransStillHasSplit(trans, split))
- continue;
- if (xaccSplitGetAccount(split) != account)
- continue;
+ if (!xaccTransStillHasSplit(trans, split))
+ continue;
+ if (xaccSplitGetAccount(split) != account)
+ continue;
- if (!last_split)
- {
- last_split = split;
- continue;
+ if (!last_split)
+ {
+ last_split = split;
+ continue;
+ }
+
+ /* This test needs to correspond to the comparison function used when
+ sorting the splits for computing the running balance. */
+ if (xaccSplitOrder (last_split, split) < 0)
+ last_split = split;
}
- /* This test needs to correspond to the comparison function used when
- sorting the splits for computing the running balance. */
- if (xaccSplitOrder (last_split, split) < 0)
- last_split = split;
- }
-
- return xaccSplitGetBalance (last_split);
+ return xaccSplitGetBalance (last_split);
}
/********************************************************************\
@@ -1055,29 +1069,30 @@
gnc_commodity *
xaccTransGetCurrency (const Transaction *trans)
{
- return trans ? trans->common_currency : NULL;
+ return trans ? trans->common_currency : NULL;
}
void
xaccTransSetCurrency (Transaction *trans, gnc_commodity *curr)
{
- gint fraction, old_fraction;
+ gint fraction, old_fraction;
- if (!trans || !curr || trans->common_currency == curr) return;
- xaccTransBeginEdit(trans);
+ if (!trans || !curr || trans->common_currency == curr) return;
+ xaccTransBeginEdit(trans);
- old_fraction = gnc_commodity_get_fraction (trans->common_currency);
- trans->common_currency = curr;
- fraction = gnc_commodity_get_fraction (curr);
+ old_fraction = gnc_commodity_get_fraction (trans->common_currency);
+ trans->common_currency = curr;
+ fraction = gnc_commodity_get_fraction (curr);
- /* avoid needless crud if fraction didn't change */
- if (fraction != old_fraction) {
- FOR_EACH_SPLIT(trans, xaccSplitSetValue(s, xaccSplitGetValue(s)));
- }
+ /* avoid needless crud if fraction didn't change */
+ if (fraction != old_fraction)
+ {
+ FOR_EACH_SPLIT(trans, xaccSplitSetValue(s, xaccSplitGetValue(s)));
+ }
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- mark_trans(trans); /* Dirty balance of every account in trans */
- xaccTransCommitEdit(trans);
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ mark_trans(trans); /* Dirty balance of every account in trans */
+ xaccTransCommitEdit(trans);
}
/********************************************************************\
@@ -1086,17 +1101,17 @@
void
xaccTransBeginEdit (Transaction *trans)
{
- if (!trans) return;
- if (!qof_begin_edit(&trans->inst)) return;
+ if (!trans) return;
+ if (!qof_begin_edit(&trans->inst)) return;
- if (qof_book_shutting_down(qof_instance_get_book(trans))) return;
+ if (qof_book_shutting_down(qof_instance_get_book(trans))) return;
- xaccOpenLog ();
- xaccTransWriteLog (trans, 'B');
+ xaccOpenLog ();
+ xaccTransWriteLog (trans, 'B');
- /* Make a clone of the transaction; we will use this
- * in case we need to roll-back the edit. */
- trans->orig = xaccDupeTransaction (trans);
+ /* Make a clone of the transaction; we will use this
+ * in case we need to roll-back the edit. */
+ trans->orig = xaccDupeTransaction (trans);
}
/********************************************************************\
@@ -1105,64 +1120,67 @@
void
xaccTransDestroy (Transaction *trans)
{
- if (!trans) return;
+ if (!trans) return;
- if (!xaccTransGetReadOnly (trans) ||
- qof_book_shutting_down(qof_instance_get_book(trans))) {
- xaccTransBeginEdit(trans);
- qof_instance_set_destroying(trans, TRUE);
- xaccTransCommitEdit(trans);
- }
+ if (!xaccTransGetReadOnly (trans) ||
+ qof_book_shutting_down(qof_instance_get_book(trans)))
+ {
+ xaccTransBeginEdit(trans);
+ qof_instance_set_destroying(trans, TRUE);
+ xaccTransCommitEdit(trans);
+ }
}
static void
destroy_gains (Transaction *trans)
{
- SplitList *node;
- for (node = trans->splits; node; node = node->next)
- {
- Split *s = node->data;
- if (!xaccTransStillHasSplit(trans, s))
- continue;
+ SplitList *node;
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ if (!xaccTransStillHasSplit(trans, s))
+ continue;
- if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus(s);
- if (s->gains_split && (GAINS_STATUS_GAINS & s->gains_split->gains))
- {
- Transaction *t = s->gains_split->parent;
- xaccTransDestroy (t);
- s->gains_split = NULL;
+ if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus(s);
+ if (s->gains_split && (GAINS_STATUS_GAINS & s->gains_split->gains))
+ {
+ Transaction *t = s->gains_split->parent;
+ xaccTransDestroy (t);
+ s->gains_split = NULL;
+ }
}
- }
}
static void
do_destroy (Transaction *trans)
{
- SplitList *node;
- gboolean shutting_down = qof_book_shutting_down(qof_instance_get_book(trans));
+ SplitList *node;
+ gboolean shutting_down = qof_book_shutting_down(qof_instance_get_book(trans));
- /* If there are capital-gains transactions associated with this,
- * they need to be destroyed too. */
- destroy_gains (trans);
+ /* If there are capital-gains transactions associated with this,
+ * they need to be destroyed too. */
+ destroy_gains (trans);
- /* Make a log in the journal before destruction. */
- if (!shutting_down)
- xaccTransWriteLog (trans, 'D');
+ /* Make a log in the journal before destruction. */
+ if (!shutting_down)
+ xaccTransWriteLog (trans, 'D');
- qof_event_gen (&trans->inst, QOF_EVENT_DESTROY, NULL);
+ qof_event_gen (&trans->inst, QOF_EVENT_DESTROY, NULL);
- /* We only own the splits that still think they belong to us. */
- trans->splits = g_list_copy(trans->splits);
- for (node = trans->splits; node; node = node->next) {
- Split *s = node->data;
- if (s->parent == trans) {
- xaccSplitDestroy(s);
- xaccSplitCommitEdit(s);
- }
- }
- g_list_free (trans->splits);
- trans->splits = NULL;
- xaccFreeTransaction (trans);
+ /* We only own the splits that still think they belong to us. */
+ trans->splits = g_list_copy(trans->splits);
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ if (s->parent == trans)
+ {
+ xaccSplitDestroy(s);
+ xaccSplitCommitEdit(s);
+ }
+ }
+ g_list_free (trans->splits);
+ trans->splits = NULL;
+ xaccFreeTransaction (trans);
}
/********************************************************************\
@@ -1170,8 +1188,14 @@
/* Temporary hack for data consitency */
static int scrub_data = 1;
-void xaccEnableDataScrubbing(void) { scrub_data = 1; }
-void xaccDisableDataScrubbing(void) { scrub_data = 0; }
+void xaccEnableDataScrubbing(void)
+{
+ scrub_data = 1;
+}
+void xaccDisableDataScrubbing(void)
+{
+ scrub_data = 0;
+}
/* Check for an implicitly deleted transaction */
static gboolean was_trans_emptied(Transaction *trans)
@@ -1186,7 +1210,8 @@
* at this point, and let the user know that we failed.
* The GUI should check for error conditions ...
*/
- if (ERR_BACKEND_MODIFIED == errcode) {
+ if (ERR_BACKEND_MODIFIED == errcode)
+ {
PWARN("Another user has modified this transaction\n"
"\tjust a moment ago. Please look at their changes,\n"
"\tand try again, if needed.\n");
@@ -1206,12 +1231,14 @@
/* Iterate over existing splits */
slist = g_list_copy(trans->splits);
- for (node = slist; node; node = node->next) {
+ for (node = slist; node; node = node->next)
+ {
Split *s = node->data;
if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
continue;
- if ((s->parent != trans) || qof_instance_get_destroying(s)) {
+ if ((s->parent != trans) || qof_instance_get_destroying(s))
+ {
/* Existing split either moved to another transaction or
was destroyed, drop from list */
GncEventData ed;
@@ -1221,7 +1248,8 @@
qof_event_gen(&s->inst, QOF_EVENT_REMOVE, &ed);
}
- if (s->parent == trans) {
+ if (s->parent == trans)
+ {
/* Split was either added, destroyed or just changed */
if (qof_instance_get_destroying(s))
qof_event_gen(&s->inst, QOF_EVENT_DESTROY, NULL);
@@ -1254,70 +1282,73 @@
void
xaccTransCommitEdit (Transaction *trans)
{
- if (!trans) return;
- ENTER ("(trans=%p)", trans);
+ if (!trans) return;
+ ENTER ("(trans=%p)", trans);
- if (!qof_commit_edit (QOF_INSTANCE(trans))) {
- LEAVE("editlevel non-zero");
- return;
- }
+ if (!qof_commit_edit (QOF_INSTANCE(trans)))
+ {
+ LEAVE("editlevel non-zero");
+ return;
+ }
- /* We increment this for the duration of the call
- * so other functions don't result in a recursive
- * call to xaccTransCommitEdit. */
- qof_instance_increase_editlevel(trans);
+ /* We increment this for the duration of the call
+ * so other functions don't result in a recursive
+ * call to xaccTransCommitEdit. */
+ qof_instance_increase_editlevel(trans);
- if (was_trans_emptied(trans))
- qof_instance_set_destroying(trans, TRUE);
+ if (was_trans_emptied(trans))
+ qof_instance_set_destroying(trans, TRUE);
- /* Before commiting the transaction, we're gonna enforce certain
- * constraints. In particular, we want to enforce the cap-gains
- * and the balanced lot constraints. These constraints might
- * change the number of splits in this transaction, and the
- * transaction itself might be deleted. This is also why
- * we can't really enforce these constraints elsewhere: they
- * can cause pointers to splits and transactions to disapear out
- * from under the holder.
- */
- if (!qof_instance_get_destroying(trans) && scrub_data &&
- !qof_book_shutting_down(xaccTransGetBook(trans))) {
- /* If scrubbing gains recurses through here, don't call it again. */
- scrub_data = 0;
- /* The total value of the transaction should sum to zero.
- * Call the trans scrub routine to fix it. Indirectly, this
- * routine also performs a number of other transaction fixes too.
- */
- xaccTransScrubImbalance (trans, NULL, NULL);
- /* Get the cap gains into a consistent state as well. */
-
- /* Lot Scrubbing is temporarily disabled. */
- if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
- xaccTransScrubGains (trans, NULL);
+ /* Before commiting the transaction, we're gonna enforce certain
+ * constraints. In particular, we want to enforce the cap-gains
+ * and the balanced lot constraints. These constraints might
+ * change the number of splits in this transaction, and the
+ * transaction itself might be deleted. This is also why
+ * we can't really enforce these constraints elsewhere: they
+ * can cause pointers to splits and transactions to disapear out
+ * from under the holder.
+ */
+ if (!qof_instance_get_destroying(trans) && scrub_data &&
+ !qof_book_shutting_down(xaccTransGetBook(trans)))
+ {
+ /* If scrubbing gains recurses through here, don't call it again. */
+ scrub_data = 0;
+ /* The total value of the transaction should sum to zero.
+ * Call the trans scrub routine to fix it. Indirectly, this
+ * routine also performs a number of other transaction fixes too.
+ */
+ xaccTransScrubImbalance (trans, NULL, NULL);
+ /* Get the cap gains into a consistent state as well. */
- /* Allow scrubbing in transaction commit again */
- scrub_data = 1;
- }
+ /* Lot Scrubbing is temporarily disabled. */
+ if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
+ xaccTransScrubGains (trans, NULL);
- /* Record the time of last modification */
- if (0 == trans->date_entered.tv_sec) {
- struct timeval tv;
+ /* Allow scrubbing in transaction commit again */
+ scrub_data = 1;
+ }
+
+ /* Record the time of last modification */
+ if (0 == trans->date_entered.tv_sec)
+ {
+ struct timeval tv;
#ifdef HAVE_GETTIMEOFDAY
- gettimeofday (&tv, NULL);
+ gettimeofday (&tv, NULL);
#else
- time (&(tv.tv_sec));
- tv.tv_usec = 0;
+ time (&(tv.tv_sec));
+ tv.tv_usec = 0;
#endif
- trans->date_entered.tv_sec = tv.tv_sec;
- trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- }
+ trans->date_entered.tv_sec = tv.tv_sec;
+ trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ }
- qof_commit_edit_part2(QOF_INSTANCE(trans),
- (void (*) (QofInstance *, QofBackendError))
- trans_on_error,
- (void (*) (QofInstance *)) trans_cleanup_commit,
- (void (*) (QofInstance *)) do_destroy);
- LEAVE ("(trans=%p)", trans);
+ qof_commit_edit_part2(QOF_INSTANCE(trans),
+ (void (*) (QofInstance *, QofBackendError))
+ trans_on_error,
+ (void (*) (QofInstance *)) trans_cleanup_commit,
+ (void (*) (QofInstance *)) do_destroy);
+ LEAVE ("(trans=%p)", trans);
}
#define SWAP(a, b) do { gpointer tmp = (a); (a) = (b); (b) = tmp; } while (0);
@@ -1333,138 +1364,146 @@
void
xaccTransRollbackEdit (Transaction *trans)
{
- GList *node, *onode;
- QofBackend *be;
- Transaction *orig;
- GList *slist;
- int num_preexist, i;
- ENTER ("trans addr=%p\n", trans);
+ GList *node, *onode;
+ QofBackend *be;
+ Transaction *orig;
+ GList *slist;
+ int num_preexist, i;
+ ENTER ("trans addr=%p\n", trans);
- check_open(trans);
+ check_open(trans);
- /* copy the original values back in. */
- orig = trans->orig;
- SWAP(trans->num, orig->num);
- SWAP(trans->description, orig->description);
- trans->date_entered = orig->date_entered;
- trans->date_posted = orig->date_posted;
- SWAP(trans->common_currency, orig->common_currency);
- SWAP(trans->inst.kvp_data, orig->inst.kvp_data);
+ /* copy the original values back in. */
+ orig = trans->orig;
+ SWAP(trans->num, orig->num);
+ SWAP(trans->description, orig->description);
+ trans->date_entered = orig->date_entered;
+ trans->date_posted = orig->date_posted;
+ SWAP(trans->common_currency, orig->common_currency);
+ SWAP(trans->inst.kvp_data, orig->inst.kvp_data);
- /* The splits at the front of trans->splits are exactly the same
- splits as in the original, but some of them may have changed, so
- we restore only those. */
- num_preexist = g_list_length(orig->splits);
- slist = g_list_copy(trans->splits);
- for (i = 0, node = slist, onode = orig->splits; node;
- i++, node = node->next, onode = onode ? onode->next : NULL) {
- Split *s = node->data;
+ /* The splits at the front of trans->splits are exactly the same
+ splits as in the original, but some of them may have changed, so
+ we restore only those. */
+ num_preexist = g_list_length(orig->splits);
+ slist = g_list_copy(trans->splits);
+ for (i = 0, node = slist, onode = orig->splits; node;
+ i++, node = node->next, onode = onode ? onode->next : NULL)
+ {
+ Split *s = node->data;
- if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
- continue;
+ if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
+ continue;
- if (i < num_preexist) {
- Split *so = onode->data;
+ if (i < num_preexist)
+ {
+ Split *so = onode->data;
- xaccSplitRollbackEdit(s);
- SWAP(s->action, so->action);
- SWAP(s->memo, so->memo);
- SWAP(s->inst.kvp_data, so->inst.kvp_data);
- s->reconciled = so->reconciled;
- s->amount = so->amount;
- s->value = so->value;
- s->lot = so->lot;
- s->gains_split = s->gains_split;
- //SET_GAINS_A_VDIRTY(s);
- s->date_reconciled = so->date_reconciled;
- qof_instance_mark_clean(QOF_INSTANCE(s));
- xaccFreeSplit(so);
- } else {
- /* Potentially added splits */
- if (trans != xaccSplitGetParent(s)) {
- trans->splits = g_list_remove(trans->splits, s);
- /* New split added, but then moved to another
- transaction */
- continue;
- }
- xaccSplitRollbackEdit(s);
- trans->splits = g_list_remove(trans->splits, s);
- g_assert(trans != xaccSplitGetParent(s));
- /* NB: our memory management policy here is that a new split
- added to the transaction which is then rolled-back still
- belongs to the engine. Specifically, it's freed by the
- transaction to which it was added. Don't add the Split to
- more than one transaction during the begin/commit block! */
- if (NULL == xaccSplitGetParent(s)) {
- xaccFreeSplit(s); // a newly malloc'd split
- }
- }
- }
- g_list_free(slist);
- g_list_free(orig->splits);
- orig->splits = NULL;
+ xaccSplitRollbackEdit(s);
+ SWAP(s->action, so->action);
+ SWAP(s->memo, so->memo);
+ SWAP(s->inst.kvp_data, so->inst.kvp_data);
+ s->reconciled = so->reconciled;
+ s->amount = so->amount;
+ s->value = so->value;
+ s->lot = so->lot;
+ s->gains_split = s->gains_split;
+ //SET_GAINS_A_VDIRTY(s);
+ s->date_reconciled = so->date_reconciled;
+ qof_instance_mark_clean(QOF_INSTANCE(s));
+ xaccFreeSplit(so);
+ }
+ else
+ {
+ /* Potentially added splits */
+ if (trans != xaccSplitGetParent(s))
+ {
+ trans->splits = g_list_remove(trans->splits, s);
+ /* New split added, but then moved to another
+ transaction */
+ continue;
+ }
+ xaccSplitRollbackEdit(s);
+ trans->splits = g_list_remove(trans->splits, s);
+ g_assert(trans != xaccSplitGetParent(s));
+ /* NB: our memory management policy here is that a new split
+ added to the transaction which is then rolled-back still
+ belongs to the engine. Specifically, it's freed by the
+ transaction to which it was added. Don't add the Split to
+ more than one transaction during the begin/commit block! */
+ if (NULL == xaccSplitGetParent(s))
+ {
+ xaccFreeSplit(s); // a newly malloc'd split
+ }
+ }
+ }
+ g_list_free(slist);
+ g_list_free(orig->splits);
+ orig->splits = NULL;
- /* Now that the engine copy is back to its original version,
- * get the backend to fix it in the database */
- be = qof_book_get_backend(qof_instance_get_book(trans));
- /** \todo Fix transrollbackedit in QOF so that rollback
- is exposed via the API. */
- if (be && be->rollback)
- {
- QofBackendError errcode;
+ /* Now that the engine copy is back to its original version,
+ * get the backend to fix it in the database */
+ be = qof_book_get_backend(qof_instance_get_book(trans));
+ /** \todo Fix transrollbackedit in QOF so that rollback
+ is exposed via the API. */
+ if (be && be->rollback)
+ {
+ QofBackendError errcode;
- /* clear errors */
- do {
- errcode = qof_backend_get_error (be);
- } while (ERR_BACKEND_NO_ERR != errcode);
+ /* clear errors */
+ do
+ {
+ errcode = qof_backend_get_error (be);
+ }
+ while (ERR_BACKEND_NO_ERR != errcode);
- (be->rollback) (be, &(trans->inst));
+ (be->rollback) (be, &(trans->inst));
- errcode = qof_backend_get_error (be);
- if (ERR_BACKEND_MOD_DESTROY == errcode)
- {
- /* The backend is asking us to delete this transaction.
- * This typically happens because another (remote) user
- * has deleted this transaction, and we haven't found
- * out about it until this user tried to edit it.
- */
- xaccTransDestroy (trans);
- do_destroy (trans);
+ errcode = qof_backend_get_error (be);
+ if (ERR_BACKEND_MOD_DESTROY == errcode)
+ {
+ /* The backend is asking us to delete this transaction.
+ * This typically happens because another (remote) user
+ * has deleted this transaction, and we haven't found
+ * out about it until this user tried to edit it.
+ */
+ xaccTransDestroy (trans);
+ do_destroy (trans);
- /* push error back onto the stack */
- qof_backend_set_error (be, errcode);
- LEAVE ("deleted trans addr=%p\n", trans);
- return;
- }
- if (ERR_BACKEND_NO_ERR != errcode)
- {
- PERR ("Rollback Failed. Ouch!");
- /* push error back onto the stack */
- qof_backend_set_error (be, errcode);
- }
- }
+ /* push error back onto the stack */
+ qof_backend_set_error (be, errcode);
+ LEAVE ("deleted trans addr=%p\n", trans);
+ return;
+ }
+ if (ERR_BACKEND_NO_ERR != errcode)
+ {
+ PERR ("Rollback Failed. Ouch!");
+ /* push error back onto the stack */
+ qof_backend_set_error (be, errcode);
+ }
+ }
- xaccTransWriteLog (trans, 'R');
+ xaccTransWriteLog (trans, 'R');
- xaccFreeTransaction (trans->orig);
+ xaccFreeTransaction (trans->orig);
- trans->orig = NULL;
- qof_instance_set_destroying(trans, FALSE);
+ trans->orig = NULL;
+ qof_instance_set_destroying(trans, FALSE);
- /* Put back to zero. */
- qof_instance_decrease_editlevel(trans);
- /* FIXME: The register code seems to depend on the engine to
- generate an event during rollback, even though the state is just
- reverting to what it was. */
- gen_event_trans (trans);
+ /* Put back to zero. */
+ qof_instance_decrease_editlevel(trans);
+ /* FIXME: The register code seems to depend on the engine to
+ generate an event during rollback, even though the state is just
+ reverting to what it was. */
+ gen_event_trans (trans);
- LEAVE ("trans addr=%p\n", trans);
+ LEAVE ("trans addr=%p\n", trans);
}
gboolean
xaccTransIsOpen (const Transaction *trans)
{
- return trans ? (0 < qof_instance_get_editlevel(trans)) : FALSE;
+ return trans ? (0 < qof_instance_get_editlevel(trans)) : FALSE;
}
#define SECS_PER_DAY 86400
@@ -1472,34 +1511,34 @@
int
xaccTransOrder (const Transaction *ta, const Transaction *tb)
{
- char *da, *db;
- int na, nb, retval;
+ char *da, *db;
+ int na, nb, retval;
- if ( ta && !tb ) return -1;
- if ( !ta && tb ) return +1;
- if ( !ta && !tb ) return 0;
+ if ( ta && !tb ) return -1;
+ if ( !ta && tb ) return +1;
+ if ( !ta && !tb ) return 0;
- /* if dates differ, return */
- DATE_CMP(ta,tb,date_posted);
+ /* if dates differ, return */
+ DATE_CMP(ta, tb, date_posted);
- /* otherwise, sort on number string */
- na = atoi(ta->num);
- nb = atoi(tb->num);
- if (na < nb) return -1;
- if (na > nb) return +1;
+ /* otherwise, sort on number string */
+ na = atoi(ta->num);
+ nb = atoi(tb->num);
+ if (na < nb) return -1;
+ if (na > nb) return +1;
- /* if dates differ, return */
- DATE_CMP(ta,tb,date_entered);
+ /* if dates differ, return */
+ DATE_CMP(ta, tb, date_entered);
- /* otherwise, sort on description string */
- da = ta->description ? ta->description : "";
- db = tb->description ? tb->description : "";
- retval = g_utf8_collate (da, db);
- if (retval)
- return retval;
+ /* otherwise, sort on description string */
+ da = ta->description ? ta->description : "";
+ db = tb->description ? tb->description : "";
+ retval = g_utf8_collate (da, db);
+ if (retval)
+ return retval;
- /* else, sort on guid - keeps sort stable. */
- return qof_instance_guid_compare(ta, tb);
+ /* else, sort on guid - keeps sort stable. */
+ return qof_instance_guid_compare(ta, tb);
}
/********************************************************************\
@@ -1516,19 +1555,19 @@
PINFO ("addr=%p set date to %" G_GUINT64_FORMAT ".%09ld %s",
trans, val.tv_sec, val.tv_nsec, tstr ? tstr : "(null)");
}
-
+
*dadate = val;
qof_instance_set_dirty(QOF_INSTANCE(trans));
mark_trans(trans);
xaccTransCommitEdit(trans);
- /* Because the date has changed, we need to make sure that each of
- * the splits is properly ordered in each of their accounts. We
- * could do that here, simply by reinserting each split into its
- * account. However, in some ways this is bad behaviour, and it
- * seems much better/nicer to defer that until the commit phase,
- * i.e. until the user has called the xaccTransCommitEdit()
- * routine. So, for now, we are done. */
+ /* Because the date has changed, we need to make sure that each of
+ * the splits is properly ordered in each of their accounts. We
+ * could do that here, simply by reinserting each split into its
+ * account. However, in some ways this is bad behaviour, and it
+ * seems much better/nicer to defer that until the commit phase,
+ * i.e. until the user has called the xaccTransCommitEdit()
+ * routine. So, for now, we are done. */
}
static inline void
@@ -1540,92 +1579,93 @@
void
xaccTransSetDatePostedSecs (Transaction *trans, time_t secs)
{
- Timespec ts = {secs, 0};
- if (!trans) return;
- xaccTransSetDateInternal(trans, &trans->date_posted, ts);
- set_gains_date_dirty (trans);
+ Timespec ts = {secs, 0};
+ if (!trans) return;
+ xaccTransSetDateInternal(trans, &trans->date_posted, ts);
+ set_gains_date_dirty (trans);
}
void
xaccTransSetDateEnteredSecs (Transaction *trans, time_t secs)
{
- Timespec ts = {secs, 0};
- if (!trans) return;
- xaccTransSetDateInternal(trans, &trans->date_entered, ts);
+ Timespec ts = {secs, 0};
+ if (!trans) return;
+ xaccTransSetDateInternal(trans, &trans->date_entered, ts);
}
static void
qofTransSetDatePosted (Transaction *trans, Timespec ts)
{
- if (!trans) return;
- if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
- if (!qof_begin_edit(&trans->inst)) return;
- xaccTransSetDateInternal(trans, &trans->date_posted, ts);
- set_gains_date_dirty(trans);
- qof_commit_edit(&trans->inst);
+ if (!trans) return;
+ if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
+ if (!qof_begin_edit(&trans->inst)) return;
+ xaccTransSetDateInternal(trans, &trans->date_posted, ts);
+ set_gains_date_dirty(trans);
+ qof_commit_edit(&trans->inst);
}
void
xaccTransSetDatePostedTS (Transaction *trans, const Timespec *ts)
{
- if (!trans || !ts) return;
- xaccTransSetDateInternal(trans, &trans->date_posted, *ts);
- set_gains_date_dirty (trans);
+ if (!trans || !ts) return;
+ xaccTransSetDateInternal(trans, &trans->date_posted, *ts);
+ set_gains_date_dirty (trans);
}
static void
qofTransSetDateEntered (Transaction *trans, Timespec ts)
{
- if (!trans) return;
- if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
- if (!qof_begin_edit(&trans->inst)) return;
- xaccTransSetDateInternal(trans, &trans->date_entered, ts);
- qof_commit_edit(&trans->inst);
+ if (!trans) return;
+ if ((ts.tv_nsec == 0) && (ts.tv_sec == 0)) return;
+ if (!qof_begin_edit(&trans->inst)) return;
+ xaccTransSetDateInternal(trans, &trans->date_entered, ts);
+ qof_commit_edit(&trans->inst);
}
void
xaccTransSetDateEnteredTS (Transaction *trans, const Timespec *ts)
{
- if (!trans || !ts) return;
- xaccTransSetDateInternal(trans, &trans->date_entered, *ts);
+ if (!trans || !ts) return;
+ xaccTransSetDateInternal(trans, &trans->date_entered, *ts);
}
void
-xaccTransSetDate (Transaction *trans, int day, int mon, int year)
+xaccTransSetDate (Transaction *trans, int day, int mon, int year)
{
- Timespec ts;
- if (!trans) return;
- ts = gnc_dmy2timespec(day, mon, year);
- xaccTransSetDateInternal(trans, &trans->date_posted, ts);
- set_gains_date_dirty (trans);
+ Timespec ts;
+ if (!trans) return;
+ ts = gnc_dmy2timespec(day, mon, year);
+ xaccTransSetDateInternal(trans, &trans->date_posted, ts);
+ set_gains_date_dirty (trans);
}
void
xaccTransSetDateDueTS (Transaction *trans, const Timespec *ts)
{
- if (!trans || !ts) return;
- xaccTransBeginEdit(trans);
- kvp_frame_set_timespec (trans->inst.kvp_data, TRANS_DATE_DUE_KVP, *ts);
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- xaccTransCommitEdit(trans);
+ if (!trans || !ts) return;
+ xaccTransBeginEdit(trans);
+ kvp_frame_set_timespec (trans->inst.kvp_data, TRANS_DATE_DUE_KVP, *ts);
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ xaccTransCommitEdit(trans);
}
void
xaccTransSetTxnType (Transaction *trans, char type)
{
- char s[2] = {type, '\0'};
- g_return_if_fail(trans);
- xaccTransBeginEdit(trans);
- kvp_frame_set_str (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP, s);
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- xaccTransCommitEdit(trans);
+ char s[2] = {type, '\0'};
+ g_return_if_fail(trans);
+ xaccTransBeginEdit(trans);
+ kvp_frame_set_str (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP, s);
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ xaccTransCommitEdit(trans);
}
void xaccTransClearReadOnly (Transaction *trans)
{
- if (trans) {
+ if (trans)
+ {
xaccTransBeginEdit(trans);
- kvp_frame_set_slot_path (trans->inst.kvp_data, NULL,
+ kvp_frame_set_slot_path (trans->inst.kvp_data, NULL,
TRANS_READ_ONLY_REASON, NULL);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
@@ -1635,9 +1675,10 @@
void
xaccTransSetReadOnly (Transaction *trans, const char *reason)
{
- if (trans && reason) {
+ if (trans && reason)
+ {
xaccTransBeginEdit(trans);
- kvp_frame_set_str (trans->inst.kvp_data,
+ kvp_frame_set_str (trans->inst.kvp_data,
TRANS_READ_ONLY_REASON, reason);
qof_instance_set_dirty(QOF_INSTANCE(trans));
xaccTransCommitEdit(trans);
@@ -1652,66 +1693,66 @@
static void
qofTransSetNum (Transaction *trans, const char *xnum)
{
- if (!qof_begin_edit(&trans->inst)) return;
- xaccTransSetNum(trans, xnum);
- qof_commit_edit(&trans->inst);
+ if (!qof_begin_edit(&trans->inst)) return;
+ xaccTransSetNum(trans, xnum);
+ qof_commit_edit(&trans->inst);
}
void
xaccTransSetNum (Transaction *trans, const char *xnum)
{
- if (!trans || !xnum) return;
- xaccTransBeginEdit(trans);
+ if (!trans || !xnum) return;
+ xaccTransBeginEdit(trans);
- CACHE_REPLACE(trans->num, xnum);
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- mark_trans(trans); /* Dirty balance of every account in trans */
- xaccTransCommitEdit(trans);
+ CACHE_REPLACE(trans->num, xnum);
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ mark_trans(trans); /* Dirty balance of every account in trans */
+ xaccTransCommitEdit(trans);
}
static void
qofTransSetDescription (Transaction *trans, const char *desc)
{
- if (!qof_begin_edit(&trans->inst)) return;
- xaccTransSetDescription(trans, desc);
- qof_commit_edit(&trans->inst);
+ if (!qof_begin_edit(&trans->inst)) return;
+ xaccTransSetDescription(trans, desc);
+ qof_commit_edit(&trans->inst);
}
void
xaccTransSetDescription (Transaction *trans, const char *desc)
{
- if (!trans || !desc) return;
- xaccTransBeginEdit(trans);
+ if (!trans || !desc) return;
+ xaccTransBeginEdit(trans);
- CACHE_REPLACE(trans->description, desc);
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- xaccTransCommitEdit(trans);
+ CACHE_REPLACE(trans->description, desc);
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ xaccTransCommitEdit(trans);
}
static void
qofTransSetNotes (Transaction *trans, const char *notes)
{
- if (!qof_begin_edit(&trans->inst)) return;
- xaccTransSetNotes(trans, notes);
- qof_commit_edit(&trans->inst);
+ if (!qof_begin_edit(&trans->inst)) return;
+ xaccTransSetNotes(trans, notes);
+ qof_commit_edit(&trans->inst);
}
void
xaccTransSetNotes (Transaction *trans, const char *notes)
{
- if (!trans || !notes) return;
- xaccTransBeginEdit(trans);
+ if (!trans || !notes) return;
+ xaccTransBeginEdit(trans);
- kvp_frame_set_str (trans->inst.kvp_data, trans_notes_str, notes);
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- xaccTransCommitEdit(trans);
+ kvp_frame_set_str (trans->inst.kvp_data, trans_notes_str, notes);
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ xaccTransCommitEdit(trans);
}
/********************************************************************\
\********************************************************************/
Split *
-xaccTransGetSplit (const Transaction *trans, int i)
+xaccTransGetSplit (const Transaction *trans, int i)
{
int j = 0;
if (!trans || i < 0) return NULL;
@@ -1721,7 +1762,7 @@
}
int
-xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
+xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
{
int j = 0;
g_return_val_if_fail(trans && split, -1);
@@ -1733,7 +1774,7 @@
SplitList *
xaccTransGetSplitList (const Transaction *trans)
{
- return trans ? trans->splits : NULL;
+ return trans ? trans->splits : NULL;
}
int
@@ -1747,20 +1788,20 @@
const char *
xaccTransGetNum (const Transaction *trans)
{
- return trans ? trans->num : NULL;
+ return trans ? trans->num : NULL;
}
-const char *
+const char *
xaccTransGetDescription (const Transaction *trans)
{
- return trans ? trans->description : NULL;
+ return trans ? trans->description : NULL;
}
-const char *
+const char *
xaccTransGetNotes (const Transaction *trans)
{
- return trans ?
- kvp_frame_get_string (trans->inst.kvp_data, trans_notes_str) : NULL;
+ return trans ?
+ kvp_frame_get_string (trans->inst.kvp_data, trans_notes_str) : NULL;
}
/********************************************************************\
@@ -1769,113 +1810,113 @@
time_t
xaccTransGetDate (const Transaction *trans)
{
- return trans ? trans->date_posted.tv_sec : 0;
+ return trans ? trans->date_posted.tv_sec : 0;
}
void
xaccTransGetDatePostedTS (const Transaction *trans, Timespec *ts)
{
- if (trans && ts)
- *ts = trans->date_posted;
+ if (trans && ts)
+ *ts = trans->date_posted;
}
void
xaccTransGetDateEnteredTS (const Transaction *trans, Timespec *ts)
{
- if (trans && ts)
- *ts = trans->date_entered;
+ if (trans && ts)
+ *ts = trans->date_entered;
}
Timespec
xaccTransRetDatePostedTS (const Transaction *trans)
{
- Timespec ts = {0,0};
- return trans ? trans->date_posted : ts;
+ Timespec ts = {0, 0};
+ return trans ? trans->date_posted : ts;
}
Timespec
xaccTransRetDateEnteredTS (const Transaction *trans)
{
- Timespec ts = {0,0};
- return trans ? trans->date_entered : ts;
+ Timespec ts = {0, 0};
+ return trans ? trans->date_entered : ts;
}
void
xaccTransGetDateDueTS (const Transaction *trans, Timespec *ts)
{
- KvpValue *value;
+ KvpValue *value;
- if (!trans || !ts) return;
+ if (!trans || !ts) return;
- value = kvp_frame_get_slot (trans->inst.kvp_data, TRANS_DATE_DUE_KVP);
- if (value)
- *ts = kvp_value_get_timespec (value);
- else
- xaccTransGetDatePostedTS (trans, ts);
+ value = kvp_frame_get_slot (trans->inst.kvp_data, TRANS_DATE_DUE_KVP);
+ if (value)
+ *ts = kvp_value_get_timespec (value);
+ else
+ xaccTransGetDatePostedTS (trans, ts);
}
Timespec
xaccTransRetDateDueTS (const Transaction *trans)
{
- Timespec ts = {0, 0};
- if (trans) xaccTransGetDateDueTS (trans, &ts);
- return ts;
+ Timespec ts = {0, 0};
+ if (trans) xaccTransGetDateDueTS (trans, &ts);
+ return ts;
}
char
xaccTransGetTxnType (const Transaction *trans)
{
- const char *s;
- if (!trans) return TXN_TYPE_NONE;
- s = kvp_frame_get_string (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP);
- if (s) return *s;
+ const char *s;
+ if (!trans) return TXN_TYPE_NONE;
+ s = kvp_frame_get_string (trans->inst.kvp_data, TRANS_TXN_TYPE_KVP);
+ if (s) return *s;
- return TXN_TYPE_NONE;
+ return TXN_TYPE_NONE;
}
-const char *
+const char *
xaccTransGetReadOnly (const Transaction *trans)
{
- /* XXX This flag should be cached in the transaction structure
- * for performance reasons, since its checked every trans commit.
- */
- return trans ? kvp_frame_get_string (
- trans->inst.kvp_data, TRANS_READ_ONLY_REASON) : NULL;
+ /* XXX This flag should be cached in the transaction structure
+ * for performance reasons, since its checked every trans commit.
+ */
+ return trans ? kvp_frame_get_string (
+ trans->inst.kvp_data, TRANS_READ_ONLY_REASON) : NULL;
}
gboolean
-xaccTransHasReconciledSplitsByAccount (const Transaction *trans,
+xaccTransHasReconciledSplitsByAccount (const Transaction *trans,
const Account *account)
{
- GList *node;
+ GList *node;
- for (node = xaccTransGetSplitList (trans); node; node = node->next)
- {
- Split *split = node->data;
+ for (node = xaccTransGetSplitList (trans); node; node = node->next)
+ {
+ Split *split = node->data;
- if (!xaccTransStillHasSplit(trans, split))
- continue;
- if (account && (xaccSplitGetAccount(split) != account))
- continue;
+ if (!xaccTransStillHasSplit(trans, split))
+ continue;
+ if (account && (xaccSplitGetAccount(split) != account))
+ continue;
- switch (xaccSplitGetReconcile (split))
- {
- case YREC:
- case FREC:
- return TRUE;
+ switch (xaccSplitGetReconcile (split))
+ {
+ case YREC:
+ case FREC:
+ return TRUE;
- default:
- break;
+ default:
+ break;
+ }
}
- }
- return FALSE;
+ return FALSE;
}
gboolean
xaccTransHasReconciledSplits (const Transaction *trans)
{
- return xaccTransHasReconciledSplitsByAccount (trans, NULL);
+ return xaccTransHasReconciledSplitsByAccount (trans, NULL);
}
@@ -1884,28 +1925,28 @@
const char state,
const Account *account)
{
- GList *node;
+ GList *node;
- for (node = xaccTransGetSplitList (trans); node; node = node->next)
- {
- Split *split = node->data;
+ for (node = xaccTransGetSplitList (trans); node; node = node->next)
+ {
+ Split *split = node->data;
- if (!xaccTransStillHasSplit(trans, split))
- continue;
- if (account && (xaccSplitGetAccount(split) != account))
- continue;
+ if (!xaccTransStillHasSplit(trans, split))
+ continue;
+ if (account && (xaccSplitGetAccount(split) != account))
+ continue;
- if (split->reconciled == state)
- return TRUE;
- }
+ if (split->reconciled == state)
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
gboolean
xaccTransHasSplitsInState (const Transaction *trans, const char state)
{
- return xaccTransHasSplitsInStateByAccount (trans, state, NULL);
+ return xaccTransHasSplitsInStateByAccount (trans, state, NULL);
}
@@ -1927,7 +1968,7 @@
{
guint count = 0;
xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
- counter_thunk, (void*)&count);
+ counter_thunk, (void*)&count);
return count;
}
@@ -1937,111 +1978,112 @@
void
xaccTransVoid(Transaction *trans, const char *reason)
{
- KvpFrame *frame;
- KvpValue *val;
- Timespec now;
- char iso8601_str[ISO_DATELENGTH+1] = "";
+ KvpFrame *frame;
+ KvpValue *val;
+ Timespec now;
+ char iso8601_str[ISO_DATELENGTH+1] = "";
- g_return_if_fail(trans && reason);
+ g_return_if_fail(trans && reason);
- xaccTransBeginEdit(trans);
- frame = trans->inst.kvp_data;
+ xaccTransBeginEdit(trans);
+ frame = trans->inst.kvp_data;
- val = kvp_frame_get_slot(frame, trans_notes_str);
- kvp_frame_set_slot(frame, void_former_notes_str, val);
+ val = kvp_frame_get_slot(frame, trans_notes_str);
+ kvp_frame_set_slot(frame, void_former_notes_str, val);
- kvp_frame_set_string(frame, trans_notes_str, _("Voided transaction"));
- kvp_frame_set_string(frame, void_reason_str, reason);
+ kvp_frame_set_string(frame, trans_notes_str, _("Voided transaction"));
+ kvp_frame_set_string(frame, void_reason_str, reason);
- now.tv_sec = time(NULL);
- now.tv_nsec = 0;
- gnc_timespec_to_iso8601_buff(now, iso8601_str);
- kvp_frame_set_string(frame, void_time_str, iso8601_str);
+ now.tv_sec = time(NULL);
+ now.tv_nsec = 0;
+ gnc_timespec_to_iso8601_buff(now, iso8601_str);
+ kvp_frame_set_string(frame, void_time_str, iso8601_str);
- FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
+ FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
- /* Dirtying taken care of by SetReadOnly */
- xaccTransSetReadOnly(trans, _("Transaction Voided"));
- xaccTransCommitEdit(trans);
+ /* Dirtying taken care of by SetReadOnly */
+ xaccTransSetReadOnly(trans, _("Transaction Voided"));
+ xaccTransCommitEdit(trans);
}
-gboolean
+gboolean
xaccTransGetVoidStatus(const Transaction *trans)
{
- g_return_val_if_fail(trans, FALSE);
- return (kvp_frame_get_slot(trans->inst.kvp_data, void_reason_str) != NULL);
+ g_return_val_if_fail(trans, FALSE);
+ return (kvp_frame_get_slot(trans->inst.kvp_data, void_reason_str) != NULL);
}
const char *
xaccTransGetVoidReason(const Transaction *trans)
{
- g_return_val_if_fail(trans, NULL);
- return kvp_frame_get_string(trans->inst.kvp_data, void_reason_str);
+ g_return_val_if_fail(trans, NULL);
+ return kvp_frame_get_string(trans->inst.kvp_data, void_reason_str);
}
Timespec
xaccTransGetVoidTime(const Transaction *tr)
{
- const char *val;
- Timespec void_time = {0,0};
+ const char *val;
+ Timespec void_time = {0, 0};
- g_return_val_if_fail(tr, void_time);
+ g_return_val_if_fail(tr, void_time);
- val = kvp_frame_get_string(tr->inst.kvp_data, void_time_str);
- return val ? gnc_iso8601_to_timespec_gmt(val) : void_time;
+ val = kvp_frame_get_string(tr->inst.kvp_data, void_time_str);
+ return val ? gnc_iso8601_to_timespec_gmt(val) : void_time;
}
void
xaccTransUnvoid (Transaction *trans)
{
- KvpFrame *frame;
- KvpValue *val;
+ KvpFrame *frame;
+ KvpValue *val;
- g_return_if_fail(trans);
+ g_return_if_fail(trans);
- frame = trans->inst.kvp_data;
- val = kvp_frame_get_slot(frame, void_reason_str);
- if (!val) return; /* Transaction isn't voided. Bail. */
+ frame = trans->inst.kvp_data;
+ val = kvp_frame_get_slot(frame, void_reason_str);
+ if (!val) return; /* Transaction isn't voided. Bail. */
- xaccTransBeginEdit(trans);
+ xaccTransBeginEdit(trans);
- val = kvp_frame_get_slot(frame, void_former_notes_str);
- kvp_frame_set_slot(frame, trans_notes_str, val);
- kvp_frame_set_slot_nc(frame, void_former_notes_str, NULL);
- kvp_frame_set_slot_nc(frame, void_reason_str, NULL);
- kvp_frame_set_slot_nc(frame, void_time_str, NULL);
+ val = kvp_frame_get_slot(frame, void_former_notes_str);
+ kvp_frame_set_slot(frame, trans_notes_str, val);
+ kvp_frame_set_slot_nc(frame, void_former_notes_str, NULL);
+ kvp_frame_set_slot_nc(frame, void_reason_str, NULL);
+ kvp_frame_set_slot_nc(frame, void_time_str, NULL);
- FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s));
+ FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s));
- /* Dirtying taken care of by ClearReadOnly */
- xaccTransClearReadOnly(trans);
- xaccTransCommitEdit(trans);
+ /* Dirtying taken care of by ClearReadOnly */
+ xaccTransClearReadOnly(trans);
+ xaccTransCommitEdit(trans);
}
Transaction *
xaccTransReverse (Transaction *orig)
{
- Transaction *trans;
- kvp_value *kvp_val;
- g_return_val_if_fail(orig, NULL);
+ Transaction *trans;
+ kvp_value *kvp_val;
+ g_return_val_if_fail(orig, NULL);
- trans = xaccTransClone(orig);
- xaccTransBeginEdit(trans);
+ trans = xaccTransClone(orig);
+ xaccTransBeginEdit(trans);
- /* Reverse the values on each split. Clear per-split info. */
- FOR_EACH_SPLIT(trans, {
- xaccSplitSetAmount(s, gnc_numeric_neg(xaccSplitGetAmount(s)));
- xaccSplitSetValue(s, gnc_numeric_neg(xaccSplitGetValue(s)));
- xaccSplitSetReconcile(s, NREC);
- qof_instance_set_dirty(QOF_INSTANCE(trans));
- });
+ /* Reverse the values on each split. Clear per-split info. */
+ FOR_EACH_SPLIT(trans,
+ {
+ xaccSplitSetAmount(s, gnc_numeric_neg(xaccSplitGetAmount(s)));
+ xaccSplitSetValue(s, gnc_numeric_neg(xaccSplitGetValue(s)));
+ xaccSplitSetReconcile(s, NREC);
+ qof_instance_set_dirty(QOF_INSTANCE(trans));
+ });
- /* Now update the original with a pointer to the new one */
- kvp_val = kvp_value_new_guid(xaccTransGetGUID(trans));
- kvp_frame_set_slot_nc(orig->inst.kvp_data, TRANS_REVERSED_BY, kvp_val);
+ /* Now update the original with a pointer to the new one */
+ kvp_val = kvp_value_new_guid(xaccTransGetGUID(trans));
+ kvp_frame_set_slot_nc(orig->inst.kvp_data, TRANS_REVERSED_BY, kvp_val);
- xaccTransCommitEdit(trans);
- return trans;
+ xaccTransCommitEdit(trans);
+ return trans;
}
Transaction *
@@ -2075,42 +2117,43 @@
/** The xaccTransScrubGainsDate() routine is used to keep the posted date
* of gains splits in sync with the posted date of the transaction
* that caused the gains.
- *
+ *
* The posted date is kept in sync using a lazy-evaluation scheme.
* If xaccTransactionSetDatePosted() is called, the date change is
* accepted, and the split is marked date-dirty. If the posted date
* is queried for (using GetDatePosted()), then the transaction is
- * evaluated. If it's a gains-transaction, then its date is copied
+ * evaluated. If it's a gains-transaction, then its date is copied
* from the source transaction that created the gains.
*/
static void
xaccTransScrubGainsDate (Transaction *trans)
{
- SplitList *node;
- Timespec ts = {0,0};
+ SplitList *node;
+ Timespec ts = {0, 0};
//restart_search:
- for (node = trans->splits; node; node=node->next) {
- Split *s = node->data;
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *s = node->data;
- if (!xaccTransStillHasSplit(trans, s)) continue;
- xaccSplitDetermineGainStatus(s);
+ if (!xaccTransStillHasSplit(trans, s)) continue;
+ xaccSplitDetermineGainStatus(s);
- if ((GAINS_STATUS_GAINS & s->gains) &&
- s->gains_split &&
- ((s->gains_split->gains & GAINS_STATUS_DATE_DIRTY) ||
- (s->gains & GAINS_STATUS_DATE_DIRTY)))
- {
- Transaction *source_trans = s->gains_split->parent;
- ts = source_trans->date_posted;
- s->gains &= ~GAINS_STATUS_DATE_DIRTY;
- s->gains_split->gains &= ~GAINS_STATUS_DATE_DIRTY;
+ if ((GAINS_STATUS_GAINS & s->gains) &&
+ s->gains_split &&
+ ((s->gains_split->gains & GAINS_STATUS_DATE_DIRTY) ||
+ (s->gains & GAINS_STATUS_DATE_DIRTY)))
+ {
+ Transaction *source_trans = s->gains_split->parent;
+ ts = source_trans->date_posted;
+ s->gains &= ~GAINS_STATUS_DATE_DIRTY;
+ s->gains_split->gains &= ~GAINS_STATUS_DATE_DIRTY;
- xaccTransSetDatePostedTS(trans, &ts);
- FOR_EACH_SPLIT(trans, s->gains &= ~GAINS_STATUS_DATE_DIRTY);
- //goto restart_search;
- }
- }
+ xaccTransSetDatePostedTS(trans, &ts);
+ FOR_EACH_SPLIT(trans, s->gains &= ~GAINS_STATUS_DATE_DIRTY);
+ //goto restart_search;
+ }
+ }
}
/* ============================================================== */
@@ -2118,41 +2161,43 @@
void
xaccTransScrubGains (Transaction *trans, Account *gain_acc)
{
- SplitList *node;
+ SplitList *node;
- ENTER("(trans=%p)", trans);
- /* Lock down posted date, its to be synced to the posted date
- * for the source of the cap gains. */
- xaccTransScrubGainsDate(trans);
+ ENTER("(trans=%p)", trans);
+ /* Lock down posted date, its to be synced to the posted date
+ * for the source of the cap gains. */
+ xaccTransScrubGainsDate(trans);
- /* Fix up the split amount */
+ /* Fix up the split amount */
restart:
- for (node = trans->splits; node; node = node->next) {
- Split *s = node->data;
+ for (node = trans->splits; node; node = node->next)
+ {
+ Split *s = node->data;
- if (!xaccTransStillHasSplit(trans, s)) continue;
+ if (!xaccTransStillHasSplit(trans, s)) continue;
- xaccSplitDetermineGainStatus(s);
- if (s->gains & GAINS_STATUS_ADIRTY) {
- gboolean altered = FALSE;
- s->gains &= ~GAINS_STATUS_ADIRTY;
- if (s->lot)
- altered = xaccScrubLot(s->lot);
- else
- altered = xaccSplitAssign(s);
- if (altered) goto restart;
- }
- }
+ xaccSplitDetermineGainStatus(s);
+ if (s->gains & GAINS_STATUS_ADIRTY)
+ {
+ gboolean altered = FALSE;
+ s->gains &= ~GAINS_STATUS_ADIRTY;
+ if (s->lot)
+ altered = xaccScrubLot(s->lot);
+ else
+ altered = xaccSplitAssign(s);
+ if (altered) goto restart;
+ }
+ }
- /* Fix up gains split value */
- FOR_EACH_SPLIT(trans,
- if ((s->gains & GAINS_STATUS_VDIRTY) ||
- (s->gains_split &&
- (s->gains_split->gains & GAINS_STATUS_VDIRTY)))
- xaccSplitComputeCapGains(s, gain_acc);
+ /* Fix up gains split value */
+ FOR_EACH_SPLIT(trans,
+ if ((s->gains & GAINS_STATUS_VDIRTY) ||
+ (s->gains_split &&
+ (s->gains_split->gains & GAINS_STATUS_VDIRTY)))
+ xaccSplitComputeCapGains(s, gain_acc);
);
-
- LEAVE("(trans=%p)", trans);
+
+ LEAVE("(trans=%p)", trans);
}
Split *
@@ -2176,74 +2221,108 @@
#endif
/* Hook into the QofObject registry */
-static QofObject trans_object_def = {
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_ID_TRANS,
- DI(.type_label =) "Transaction",
- DI(.create =) (gpointer)xaccMallocTransaction,
- DI(.book_begin =) NULL,
- DI(.book_end =) NULL,
- DI(.is_dirty =) qof_collection_is_dirty,
- DI(.mark_clean =) qof_collection_mark_clean,
- DI(.foreach =) qof_collection_foreach,
- DI(.printable =) (const char* (*)(gpointer)) xaccTransGetDescription,
- DI(.version_cmp =) (int (*)(gpointer,gpointer)) qof_instance_version_cmp,
+static QofObject trans_object_def =
+{
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_ID_TRANS,
+ DI(.type_label = ) "Transaction",
+ DI(.create = ) (gpointer)xaccMallocTransaction,
+ DI(.book_begin = ) NULL,
+ DI(.book_end = ) NULL,
+ DI(.is_dirty = ) qof_collection_is_dirty,
+ DI(.mark_clean = ) qof_collection_mark_clean,
+ DI(.foreach = ) qof_collection_foreach,
+ DI(.printable = ) (const char * (*)(gpointer)) xaccTransGetDescription,
+ DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
};
static gboolean
trans_is_balanced_p (const Transaction *trans)
{
- return trans ? xaccTransIsBalanced(trans) : FALSE;
+ return trans ? xaccTransIsBalanced(trans) : FALSE;
}
gboolean xaccTransRegister (void)
{
- static QofParam params[] = {
- { TRANS_NUM, QOF_TYPE_STRING,
- (QofAccessFunc)xaccTransGetNum,
- (QofSetterFunc)qofTransSetNum,
- qof_string_number_compare_func },
- { TRANS_DESCRIPTION, QOF_TYPE_STRING,
- (QofAccessFunc)xaccTransGetDescription,
- (QofSetterFunc)qofTransSetDescription },
- { TRANS_DATE_ENTERED, QOF_TYPE_DATE,
- (QofAccessFunc)xaccTransRetDateEnteredTS,
- (QofSetterFunc)qofTransSetDateEntered },
- { TRANS_DATE_POSTED, QOF_TYPE_DATE,
- (QofAccessFunc)xaccTransRetDatePostedTS,
- (QofSetterFunc)qofTransSetDatePosted },
- { TRANS_DATE_DUE, QOF_TYPE_DATE,
- (QofAccessFunc)xaccTransRetDateDueTS, NULL },
- { TRANS_IMBALANCE, QOF_TYPE_NUMERIC,
- (QofAccessFunc)xaccTransGetImbalanceValue, NULL },
- { TRANS_NOTES, QOF_TYPE_STRING,
- (QofAccessFunc)xaccTransGetNotes,
- (QofSetterFunc)qofTransSetNotes },
- { TRANS_IS_BALANCED, QOF_TYPE_BOOLEAN,
- (QofAccessFunc)trans_is_balanced_p, NULL },
- { TRANS_TYPE, QOF_TYPE_CHAR,
- (QofAccessFunc)xaccTransGetTxnType,
- (QofSetterFunc)xaccTransSetTxnType },
- { TRANS_VOID_STATUS, QOF_TYPE_BOOLEAN,
- (QofAccessFunc)xaccTransGetVoidStatus, NULL },
- { TRANS_VOID_REASON, QOF_TYPE_STRING,
- (QofAccessFunc)xaccTransGetVoidReason, NULL },
- { TRANS_VOID_TIME, QOF_TYPE_DATE,
- (QofAccessFunc)xaccTransGetVoidTime, NULL },
- { TRANS_SPLITLIST, GNC_ID_SPLIT,
- (QofAccessFunc)xaccTransGetSplitList, NULL },
- { TRANS_KVP, QOF_TYPE_KVP,
- (QofAccessFunc)qof_instance_get_slots, NULL },
- { QOF_PARAM_BOOK, QOF_ID_BOOK,
- (QofAccessFunc)qof_instance_get_book, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID,
- (QofAccessFunc)qof_entity_get_guid, NULL },
- { NULL },
- };
+ static QofParam params[] =
+ {
+ {
+ TRANS_NUM, QOF_TYPE_STRING,
+ (QofAccessFunc)xaccTransGetNum,
+ (QofSetterFunc)qofTransSetNum,
+ qof_string_number_compare_func
+ },
+ {
+ TRANS_DESCRIPTION, QOF_TYPE_STRING,
+ (QofAccessFunc)xaccTransGetDescription,
+ (QofSetterFunc)qofTransSetDescription
+ },
+ {
+ TRANS_DATE_ENTERED, QOF_TYPE_DATE,
+ (QofAccessFunc)xaccTransRetDateEnteredTS,
+ (QofSetterFunc)qofTransSetDateEntered
+ },
+ {
+ TRANS_DATE_POSTED, QOF_TYPE_DATE,
+ (QofAccessFunc)xaccTransRetDatePostedTS,
+ (QofSetterFunc)qofTransSetDatePosted
+ },
+ {
+ TRANS_DATE_DUE, QOF_TYPE_DATE,
+ (QofAccessFunc)xaccTransRetDateDueTS, NULL
+ },
+ {
+ TRANS_IMBALANCE, QOF_TYPE_NUMERIC,
+ (QofAccessFunc)xaccTransGetImbalanceValue, NULL
+ },
+ {
+ TRANS_NOTES, QOF_TYPE_STRING,
+ (QofAccessFunc)xaccTransGetNotes,
+ (QofSetterFunc)qofTransSetNotes
+ },
+ {
+ TRANS_IS_BALANCED, QOF_TYPE_BOOLEAN,
+ (QofAccessFunc)trans_is_balanced_p, NULL
+ },
+ {
+ TRANS_TYPE, QOF_TYPE_CHAR,
+ (QofAccessFunc)xaccTransGetTxnType,
+ (QofSetterFunc)xaccTransSetTxnType
+ },
+ {
+ TRANS_VOID_STATUS, QOF_TYPE_BOOLEAN,
+ (QofAccessFunc)xaccTransGetVoidStatus, NULL
+ },
+ {
+ TRANS_VOID_REASON, QOF_TYPE_STRING,
+ (QofAccessFunc)xaccTransGetVoidReason, NULL
+ },
+ {
+ TRANS_VOID_TIME, QOF_TYPE_DATE,
+ (QofAccessFunc)xaccTransGetVoidTime, NULL
+ },
+ {
+ TRANS_SPLITLIST, GNC_ID_SPLIT,
+ (QofAccessFunc)xaccTransGetSplitList, NULL
+ },
+ {
+ TRANS_KVP, QOF_TYPE_KVP,
+ (QofAccessFunc)qof_instance_get_slots, NULL
+ },
+ {
+ QOF_PARAM_BOOK, QOF_ID_BOOK,
+ (QofAccessFunc)qof_instance_get_book, NULL
+ },
+ {
+ QOF_PARAM_GUID, QOF_TYPE_GUID,
+ (QofAccessFunc)qof_entity_get_guid, NULL
+ },
+ { NULL },
+ };
- qof_class_register (GNC_ID_TRANS, (QofSortFunc)xaccTransOrder, params);
+ qof_class_register (GNC_ID_TRANS, (QofSortFunc)xaccTransOrder, params);
- return qof_object_register (&trans_object_def);
+ return qof_object_register (&trans_object_def);
}
/************************ END OF ************************************\
Modified: gnucash/trunk/src/engine/cap-gains.c
===================================================================
--- gnucash/trunk/src/engine/cap-gains.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/cap-gains.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -25,26 +25,26 @@
* @author Copyright (c) 2003,2004 Linas Vepstas <linas at linas.org>
*
* This file implements the various routines to automatically
- * compute and handle Cap Gains/Losses resulting from trading
- * activities. Some of these routines might have broader
- * applicability, for handling depreciation & etc.
+ * compute and handle Cap Gains/Losses resulting from trading
+ * activities. Some of these routines might have broader
+ * applicability, for handling depreciation & etc.
*
* This code is under development, and is 'beta': we think we're
* mostly done, and we've tested and "things work for us", but there
- * may still be something missing, and there might still be some
+ * may still be something missing, and there might still be some
* bugs.
*
- * This code uses a 'gains dirty' flag: A 'dirty' flag on the source
+ * This code uses a 'gains dirty' flag: A 'dirty' flag on the source
* split indicates that the gains transaction needs to be recomputed.
* Another flag, the gains transaction flag, marks the split as
- * being a gains split, and that the source transaction should be
+ * being a gains split, and that the source transaction should be
* checked for dirtiness before returning the date, the amount, the
* value, etc. Finally, these flags make amount and value read-only
* for the gains splits. (the memo is user-modifieable).
- *
+ *
* If the amount in a split is changed, then the lot has to be recomputed.
- * This has a potential trickle-through effect on all later lots.
- * Ideally, later lots are dissolved, and recomputed. However, some
+ * This has a potential trickle-through effect on all later lots.
+ * Ideally, later lots are dissolved, and recomputed. However, some
* lots may have been user-hand-built. These should be left alone.
*
ToDo:
@@ -74,144 +74,144 @@
/* ============================================================== */
-gboolean
+gboolean
xaccAccountHasTrades (const Account *acc)
{
- gnc_commodity *acc_comm;
- SplitList *splits, *node;
+ gnc_commodity *acc_comm;
+ SplitList *splits, *node;
- if (!acc) return FALSE;
+ if (!acc) return FALSE;
- if (xaccAccountIsPriced (acc))
- return TRUE;
-
- acc_comm = xaccAccountGetCommodity(acc);
+ if (xaccAccountIsPriced (acc))
+ return TRUE;
- splits = xaccAccountGetSplitList(acc);
- for (node=splits; node; node=node->next)
- {
- Split *s = node->data;
- Transaction *t = s->parent;
- if (acc_comm != t->common_currency) return TRUE;
- }
+ acc_comm = xaccAccountGetCommodity(acc);
- return FALSE;
+ splits = xaccAccountGetSplitList(acc);
+ for (node = splits; node; node = node->next)
+ {
+ Split *s = node->data;
+ Transaction *t = s->parent;
+ if (acc_comm != t->common_currency) return TRUE;
+ }
+
+ return FALSE;
}
/* ============================================================== */
struct find_lot_s
{
- GNCLot *lot;
- gnc_commodity *currency;
- Timespec ts;
- int (*numeric_pred)(gnc_numeric);
- gboolean (*date_pred)(Timespec e, Timespec tr);
+ GNCLot *lot;
+ gnc_commodity *currency;
+ Timespec ts;
+ int (*numeric_pred)(gnc_numeric);
+ gboolean (*date_pred)(Timespec e, Timespec tr);
};
-static gboolean
+static gboolean
earliest_pred (Timespec earl, Timespec tran)
{
- return ((earl.tv_sec > tran.tv_sec) ||
- ((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec > tran.tv_nsec)));
+ return ((earl.tv_sec > tran.tv_sec) ||
+ ((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec > tran.tv_nsec)));
}
-static gboolean
+static gboolean
latest_pred (Timespec earl, Timespec tran)
{
- return ((earl.tv_sec < tran.tv_sec) ||
- ((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec < tran.tv_nsec)));
+ return ((earl.tv_sec < tran.tv_sec) ||
+ ((earl.tv_sec == tran.tv_sec) && (earl.tv_nsec < tran.tv_nsec)));
}
-static gpointer
+static gpointer
finder_helper (GNCLot *lot, gpointer user_data)
{
- struct find_lot_s *els = user_data;
- Split *s;
- Transaction *trans;
- gnc_numeric bal;
- gboolean opening_is_positive, bal_is_positive;
+ struct find_lot_s *els = user_data;
+ Split *s;
+ Transaction *trans;
+ gnc_numeric bal;
+ gboolean opening_is_positive, bal_is_positive;
- if (gnc_lot_is_closed (lot)) return NULL;
+ if (gnc_lot_is_closed (lot)) return NULL;
- s = gnc_lot_get_earliest_split (lot);
- if (s == NULL) return NULL;
-
- /* We want a lot whose balance is of the correct sign. All splits
- in a lot must be the opposite sign of the opening split. We also
- want to ignore lots that are overfull, i.e., where the balance in
- the lot is of opposite sign to the opening split in the lot. */
- if (0 == (els->numeric_pred) (s->amount)) return NULL;
- bal = gnc_lot_get_balance (lot);
- opening_is_positive = gnc_numeric_positive_p (s->amount);
- bal_is_positive = gnc_numeric_positive_p (bal);
- if (opening_is_positive != bal_is_positive) return NULL;
-
- trans = s->parent;
- if (els->currency &&
- (FALSE == gnc_commodity_equiv (els->currency,
- trans->common_currency)))
- {
- return NULL;
- }
+ s = gnc_lot_get_earliest_split (lot);
+ if (s == NULL) return NULL;
- if (els->date_pred (els->ts, trans->date_posted))
- {
- els->ts = trans->date_posted;
- els->lot = lot;
- }
-
- return NULL;
+ /* We want a lot whose balance is of the correct sign. All splits
+ in a lot must be the opposite sign of the opening split. We also
+ want to ignore lots that are overfull, i.e., where the balance in
+ the lot is of opposite sign to the opening split in the lot. */
+ if (0 == (els->numeric_pred) (s->amount)) return NULL;
+ bal = gnc_lot_get_balance (lot);
+ opening_is_positive = gnc_numeric_positive_p (s->amount);
+ bal_is_positive = gnc_numeric_positive_p (bal);
+ if (opening_is_positive != bal_is_positive) return NULL;
+
+ trans = s->parent;
+ if (els->currency &&
+ (FALSE == gnc_commodity_equiv (els->currency,
+ trans->common_currency)))
+ {
+ return NULL;
+ }
+
+ if (els->date_pred (els->ts, trans->date_posted))
+ {
+ els->ts = trans->date_posted;
+ els->lot = lot;
+ }
+
+ return NULL;
}
static inline GNCLot *
-xaccAccountFindOpenLot (Account *acc, gnc_numeric sign,
- gnc_commodity *currency,
- gint64 guess,
- gboolean (*date_pred)(Timespec, Timespec))
+xaccAccountFindOpenLot (Account *acc, gnc_numeric sign,
+ gnc_commodity *currency,
+ gint64 guess,
+ gboolean (*date_pred)(Timespec, Timespec))
{
- struct find_lot_s es;
+ struct find_lot_s es;
- es.lot = NULL;
- es.currency = currency;
- es.ts.tv_sec = guess;
- es.ts.tv_nsec = 0;
- es.date_pred = date_pred;
+ es.lot = NULL;
+ es.currency = currency;
+ es.ts.tv_sec = guess;
+ es.ts.tv_nsec = 0;
+ es.date_pred = date_pred;
- if (gnc_numeric_positive_p(sign)) es.numeric_pred = gnc_numeric_negative_p;
- else es.numeric_pred = gnc_numeric_positive_p;
-
- xaccAccountForEachLot (acc, finder_helper, &es);
- return es.lot;
+ if (gnc_numeric_positive_p(sign)) es.numeric_pred = gnc_numeric_negative_p;
+ else es.numeric_pred = gnc_numeric_positive_p;
+
+ xaccAccountForEachLot (acc, finder_helper, &es);
+ return es.lot;
}
GNCLot *
-xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign,
+xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign,
gnc_commodity *currency)
{
- GNCLot *lot;
- ENTER (" sign=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, sign.num,
- sign.denom);
-
- lot = xaccAccountFindOpenLot (acc, sign, currency,
- G_MAXINT64, earliest_pred);
- LEAVE ("found lot=%p %s baln=%s", lot, gnc_lot_get_title (lot),
- gnc_num_dbg_to_string(gnc_lot_get_balance(lot)));
- return lot;
+ GNCLot *lot;
+ ENTER (" sign=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, sign.num,
+ sign.denom);
+
+ lot = xaccAccountFindOpenLot (acc, sign, currency,
+ G_MAXINT64, earliest_pred);
+ LEAVE ("found lot=%p %s baln=%s", lot, gnc_lot_get_title (lot),
+ gnc_num_dbg_to_string(gnc_lot_get_balance(lot)));
+ return lot;
}
GNCLot *
xaccAccountFindLatestOpenLot (Account *acc, gnc_numeric sign,
gnc_commodity *currency)
{
- GNCLot *lot;
- ENTER (" sign=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
- sign.num, sign.denom);
-
- lot = xaccAccountFindOpenLot (acc, sign, currency,
- G_MININT64, latest_pred);
- LEAVE ("found lot=%p %s", lot, gnc_lot_get_title (lot));
- return lot;
+ GNCLot *lot;
+ ENTER (" sign=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
+ sign.num, sign.denom);
+
+ lot = xaccAccountFindOpenLot (acc, sign, currency,
+ G_MININT64, latest_pred);
+ LEAVE ("found lot=%p %s", lot, gnc_lot_get_title (lot));
+ return lot;
}
/* ============================================================== */
@@ -220,46 +220,46 @@
static Account *
GetOrMakeLotOrphanAccount (Account *root, gnc_commodity * currency)
{
- char * accname;
- Account * acc;
+ char * accname;
+ Account * acc;
- g_return_val_if_fail (root, NULL);
+ g_return_val_if_fail (root, NULL);
- /* build the account name */
- if (!currency)
- {
- PERR ("No currency specified!");
- return NULL;
- }
+ /* build the account name */
+ if (!currency)
+ {
+ PERR ("No currency specified!");
+ return NULL;
+ }
- accname = g_strconcat (_("Orphaned Gains"), "-",
- gnc_commodity_get_mnemonic (currency), NULL);
+ accname = g_strconcat (_("Orphaned Gains"), "-",
+ gnc_commodity_get_mnemonic (currency), NULL);
- /* See if we've got one of these going already ... */
- acc = gnc_account_lookup_by_name(root, accname);
+ /* See if we've got one of these going already ... */
+ acc = gnc_account_lookup_by_name(root, accname);
- if (acc == NULL)
- {
- /* Guess not. We'll have to build one. */
- acc = xaccMallocAccount (gnc_account_get_book(root));
- xaccAccountBeginEdit (acc);
- xaccAccountSetName (acc, accname);
- xaccAccountSetCommodity (acc, currency);
- xaccAccountSetType (acc, ACCT_TYPE_INCOME);
- xaccAccountSetDescription (acc, _("Realized Gain/Loss"));
- xaccAccountSetNotes (acc,
- _("Realized Gains or Losses from "
- "Commodity or Trading Accounts "
- "that haven't been recorded elsewhere."));
+ if (acc == NULL)
+ {
+ /* Guess not. We'll have to build one. */
+ acc = xaccMallocAccount (gnc_account_get_book(root));
+ xaccAccountBeginEdit (acc);
+ xaccAccountSetName (acc, accname);
+ xaccAccountSetCommodity (acc, currency);
+ xaccAccountSetType (acc, ACCT_TYPE_INCOME);
+ xaccAccountSetDescription (acc, _("Realized Gain/Loss"));
+ xaccAccountSetNotes (acc,
+ _("Realized Gains or Losses from "
+ "Commodity or Trading Accounts "
+ "that haven't been recorded elsewhere."));
- /* Hang the account off the root. */
- gnc_account_append_child (root, acc);
- xaccAccountCommitEdit (acc);
- }
+ /* Hang the account off the root. */
+ gnc_account_append_child (root, acc);
+ xaccAccountCommitEdit (acc);
+ }
- g_free (accname);
+ g_free (accname);
- return acc;
+ return acc;
}
/* ============================================================== */
@@ -267,25 +267,25 @@
void
xaccAccountSetDefaultGainAccount (Account *acc, const Account *gain_acct)
{
- KvpFrame *cwd;
- KvpValue *vvv;
- const char * cur_name;
- gnc_commodity *acc_comm;
+ KvpFrame *cwd;
+ KvpValue *vvv;
+ const char * cur_name;
+ gnc_commodity *acc_comm;
- if (!acc || !gain_acct) return;
+ if (!acc || !gain_acct) return;
- cwd = xaccAccountGetSlots (acc);
- cwd = kvp_frame_get_frame_slash (cwd, "/lot-mgmt/gains-act/");
+ cwd = xaccAccountGetSlots (acc);
+ cwd = kvp_frame_get_frame_slash (cwd, "/lot-mgmt/gains-act/");
- /* Accounts are indexed by thier unique currency name */
- acc_comm = xaccAccountGetCommodity(acc);
- cur_name = gnc_commodity_get_unique_name (acc_comm);
+ /* Accounts are indexed by thier unique currency name */
+ acc_comm = xaccAccountGetCommodity(acc);
+ cur_name = gnc_commodity_get_unique_name (acc_comm);
- xaccAccountBeginEdit (acc);
- vvv = kvp_value_new_guid (xaccAccountGetGUID (gain_acct));
- kvp_frame_set_slot_nc (cwd, cur_name, vvv);
- qof_instance_set_slots(QOF_INSTANCE(acc), acc->inst.kvp_data);
- xaccAccountCommitEdit (acc);
+ xaccAccountBeginEdit (acc);
+ vvv = kvp_value_new_guid (xaccAccountGetGUID (gain_acct));
+ kvp_frame_set_slot_nc (cwd, cur_name, vvv);
+ qof_instance_set_slots(QOF_INSTANCE(acc), acc->inst.kvp_data);
+ xaccAccountCommitEdit (acc);
}
/* ============================================================== */
@@ -293,24 +293,24 @@
Account *
xaccAccountGetDefaultGainAccount (const Account *acc, const gnc_commodity * currency)
{
- Account *gain_acct = NULL;
- KvpFrame *cwd;
- KvpValue *vvv;
- GUID * gain_acct_guid;
- const char * cur_name;
+ Account *gain_acct = NULL;
+ KvpFrame *cwd;
+ KvpValue *vvv;
+ GUID * gain_acct_guid;
+ const char * cur_name;
- if (!acc || !currency) return NULL;
+ if (!acc || !currency) return NULL;
- cwd = xaccAccountGetSlots (acc);
- cwd = kvp_frame_get_frame_slash (cwd, "/lot-mgmt/gains-act/");
+ cwd = xaccAccountGetSlots (acc);
+ cwd = kvp_frame_get_frame_slash (cwd, "/lot-mgmt/gains-act/");
- /* Accounts are indexed by thier unique currency name */
- cur_name = gnc_commodity_get_unique_name (currency);
- vvv = kvp_frame_get_slot (cwd, cur_name);
- gain_acct_guid = kvp_value_get_guid (vvv);
+ /* Accounts are indexed by thier unique currency name */
+ cur_name = gnc_commodity_get_unique_name (currency);
+ vvv = kvp_frame_get_slot (cwd, cur_name);
+ gain_acct_guid = kvp_value_get_guid (vvv);
- gain_acct = xaccAccountLookup (gain_acct_guid, qof_instance_get_book(acc));
- return gain_acct;
+ gain_acct = xaccAccountLookup (gain_acct_guid, qof_instance_get_book(acc));
+ return gain_acct;
}
/* ============================================================== */
@@ -323,39 +323,39 @@
static Account *
GetOrMakeGainAcct (Account *acc, gnc_commodity * currency)
{
- Account *gain_acct = NULL;
- KvpFrame *cwd;
- KvpValue *vvv;
- GUID * gain_acct_guid;
- const char * cur_name;
+ Account *gain_acct = NULL;
+ KvpFrame *cwd;
+ KvpValue *vvv;
+ GUID * gain_acct_guid;
+ const char * cur_name;
- cwd = xaccAccountGetSlots (acc);
- cwd = kvp_frame_get_frame_slash (cwd, "/lot-mgmt/gains-act/");
+ cwd = xaccAccountGetSlots (acc);
+ cwd = kvp_frame_get_frame_slash (cwd, "/lot-mgmt/gains-act/");
- /* Accounts are indexed by thier unique currency name */
- cur_name = gnc_commodity_get_unique_name (currency);
- vvv = kvp_frame_get_slot (cwd, cur_name);
- gain_acct_guid = kvp_value_get_guid (vvv);
+ /* Accounts are indexed by thier unique currency name */
+ cur_name = gnc_commodity_get_unique_name (currency);
+ vvv = kvp_frame_get_slot (cwd, cur_name);
+ gain_acct_guid = kvp_value_get_guid (vvv);
- gain_acct = xaccAccountLookup (gain_acct_guid, qof_instance_get_book(acc));
+ gain_acct = xaccAccountLookup (gain_acct_guid, qof_instance_get_book(acc));
- /* If there is no default place to put gains/losses
- * for this account, then create such a place */
- if (NULL == gain_acct)
- {
- Account *root;
+ /* If there is no default place to put gains/losses
+ * for this account, then create such a place */
+ if (NULL == gain_acct)
+ {
+ Account *root;
- xaccAccountBeginEdit (acc);
- root = gnc_account_get_root(acc);
- gain_acct = GetOrMakeLotOrphanAccount (root, currency);
+ xaccAccountBeginEdit (acc);
+ root = gnc_account_get_root(acc);
+ gain_acct = GetOrMakeLotOrphanAccount (root, currency);
- vvv = kvp_value_new_guid (xaccAccountGetGUID (gain_acct));
- kvp_frame_set_slot_nc (cwd, cur_name, vvv);
- qof_instance_set_slots(QOF_INSTANCE(acc), acc->inst.kvp_data);
- xaccAccountCommitEdit (acc);
+ vvv = kvp_value_new_guid (xaccAccountGetGUID (gain_acct));
+ kvp_frame_set_slot_nc (cwd, cur_name, vvv);
+ qof_instance_set_slots(QOF_INSTANCE(acc), acc->inst.kvp_data);
+ xaccAccountCommitEdit (acc);
- }
- return gain_acct;
+ }
+ return gain_acct;
}
/* ============================================================== */
@@ -363,265 +363,265 @@
Split *
xaccSplitAssignToLot (Split *split, GNCLot *lot)
{
- Account *acc;
- gnc_numeric baln;
- int cmp;
- gboolean baln_is_positive, amt_is_positive;
+ Account *acc;
+ gnc_numeric baln;
+ int cmp;
+ gboolean baln_is_positive, amt_is_positive;
- if (!lot) return split;
- if (!split) return NULL;
+ if (!lot) return split;
+ if (!split) return NULL;
- /* If this split already belongs to a lot, we are done. */
- if (split->lot) return NULL;
+ /* If this split already belongs to a lot, we are done. */
+ if (split->lot) return NULL;
- /* Anomolous situation; except for voided transactions,
- * we don't expect to see splits with no amount ..
- * unless they're gains splits, and we shouldn't see those.
- */
- if (gnc_numeric_zero_p (split->amount))
- {
- if (xaccTransGetVoidStatus(split->parent)) return NULL;
+ /* Anomolous situation; except for voided transactions,
+ * we don't expect to see splits with no amount ..
+ * unless they're gains splits, and we shouldn't see those.
+ */
+ if (gnc_numeric_zero_p (split->amount))
+ {
+ if (xaccTransGetVoidStatus(split->parent)) return NULL;
- PWARN ("split with zero amount; value=%s gflag=%x gsplit=%p",
- gnc_num_dbg_to_string (split->amount),
- split->gains,
- split->gains_split);
- if (split->gains_split)
- {
- PWARN ("gains amt=%s value=%s",
- gnc_num_dbg_to_string (split->gains_split->amount),
- gnc_num_dbg_to_string (split->gains_split->value));
- }
- return NULL;
- }
+ PWARN ("split with zero amount; value=%s gflag=%x gsplit=%p",
+ gnc_num_dbg_to_string (split->amount),
+ split->gains,
+ split->gains_split);
+ if (split->gains_split)
+ {
+ PWARN ("gains amt=%s value=%s",
+ gnc_num_dbg_to_string (split->gains_split->amount),
+ gnc_num_dbg_to_string (split->gains_split->value));
+ }
+ return NULL;
+ }
- /* If the lot is closed, we can't add anything to it */
- baln = gnc_lot_get_balance (lot);
- if (gnc_lot_is_closed (lot)) return split;
+ /* If the lot is closed, we can't add anything to it */
+ baln = gnc_lot_get_balance (lot);
+ if (gnc_lot_is_closed (lot)) return split;
- /* If the lot balance is zero, but the lot is open, then
- * the lot is empty. Unconditionally add the split. */
- if (gnc_numeric_zero_p (baln))
- {
- acc = split->acc;
- xaccAccountBeginEdit (acc);
- gnc_lot_add_split (lot, split);
- PINFO ("added split to empty lot, new lot baln=%s (%s)",
- gnc_num_dbg_to_string (gnc_lot_get_balance(lot)),
- gnc_lot_get_title (lot));
- xaccAccountCommitEdit (acc);
- return NULL;
- }
+ /* If the lot balance is zero, but the lot is open, then
+ * the lot is empty. Unconditionally add the split. */
+ if (gnc_numeric_zero_p (baln))
+ {
+ acc = split->acc;
+ xaccAccountBeginEdit (acc);
+ gnc_lot_add_split (lot, split);
+ PINFO ("added split to empty lot, new lot baln=%s (%s)",
+ gnc_num_dbg_to_string (gnc_lot_get_balance(lot)),
+ gnc_lot_get_title (lot));
+ xaccAccountCommitEdit (acc);
+ return NULL;
+ }
- /* If the sign of the split is the same as the sign of the lot,
- * add the split, but complain about it ... none of the currently
- * implemented accounting policies should be giving us splits
- * that make lots larger. One a lot is open, the FIFO/LIFO
- * policies should be working only to make the lot smaller.
- * We can remove teh warning emssage come the day we have
- * fancier policies.
- */
- baln_is_positive = gnc_numeric_positive_p (baln);
- amt_is_positive = gnc_numeric_positive_p (split->amount);
- if ((baln_is_positive && amt_is_positive) ||
- ((!baln_is_positive) && (!amt_is_positive)))
- {
- PWARN ("accounting policy gave us split that enlarges the lot!\n"
- "old lot baln=%s split amt=%s lot=%s",
- gnc_num_dbg_to_string (gnc_lot_get_balance(lot)),
- gnc_num_dbg_to_string (split->amount),
- gnc_lot_get_title (lot));
+ /* If the sign of the split is the same as the sign of the lot,
+ * add the split, but complain about it ... none of the currently
+ * implemented accounting policies should be giving us splits
+ * that make lots larger. One a lot is open, the FIFO/LIFO
+ * policies should be working only to make the lot smaller.
+ * We can remove teh warning emssage come the day we have
+ * fancier policies.
+ */
+ baln_is_positive = gnc_numeric_positive_p (baln);
+ amt_is_positive = gnc_numeric_positive_p (split->amount);
+ if ((baln_is_positive && amt_is_positive) ||
+ ((!baln_is_positive) && (!amt_is_positive)))
+ {
+ PWARN ("accounting policy gave us split that enlarges the lot!\n"
+ "old lot baln=%s split amt=%s lot=%s",
+ gnc_num_dbg_to_string (gnc_lot_get_balance(lot)),
+ gnc_num_dbg_to_string (split->amount),
+ gnc_lot_get_title (lot));
- acc = split->acc;
- xaccAccountBeginEdit (acc);
- gnc_lot_add_split (lot, split);
- xaccAccountCommitEdit (acc);
- return NULL;
- }
+ acc = split->acc;
+ xaccAccountBeginEdit (acc);
+ gnc_lot_add_split (lot, split);
+ xaccAccountCommitEdit (acc);
+ return NULL;
+ }
- /* If adding the split would make the lot balance change sign,
- * then we split the split into two pieces: one piece that will
- * bring the lot balance to zero, and another to be dealt with
- * later. */
- cmp = gnc_numeric_compare (gnc_numeric_abs(split->amount),
- gnc_numeric_abs(baln));
+ /* If adding the split would make the lot balance change sign,
+ * then we split the split into two pieces: one piece that will
+ * bring the lot balance to zero, and another to be dealt with
+ * later. */
+ cmp = gnc_numeric_compare (gnc_numeric_abs(split->amount),
+ gnc_numeric_abs(baln));
- PINFO ("found open lot with baln=%s (%s)", gnc_num_dbg_to_string (baln),
- gnc_lot_get_title (lot));
+ PINFO ("found open lot with baln=%s (%s)", gnc_num_dbg_to_string (baln),
+ gnc_lot_get_title (lot));
- /* cmp == -1 if amt < baln, ==0 if amt==baln */
- if (0 >= cmp)
- {
- acc = split->acc;
- xaccAccountBeginEdit (acc);
- gnc_lot_add_split (lot, split);
- PINFO ("simple added split to lot, new lot baln=%s",
- gnc_num_dbg_to_string (gnc_lot_get_balance(lot)));
- xaccAccountCommitEdit (acc);
- return NULL;
- }
+ /* cmp == -1 if amt < baln, ==0 if amt==baln */
+ if (0 >= cmp)
+ {
+ acc = split->acc;
+ xaccAccountBeginEdit (acc);
+ gnc_lot_add_split (lot, split);
+ PINFO ("simple added split to lot, new lot baln=%s",
+ gnc_num_dbg_to_string (gnc_lot_get_balance(lot)));
+ xaccAccountCommitEdit (acc);
+ return NULL;
+ }
- /* If we are here, then (cmp == +1 iff (amt > baln)) and we need
- * to split up the split into pieces. Do it. */
- {
- time_t now = time(0);
- Split * new_split;
- gnc_numeric amt_a, amt_b, amt_tot;
- gnc_numeric val_a, val_b, val_tot;
- gnc_numeric frac;
- Transaction *trans;
- Timespec ts;
+ /* If we are here, then (cmp == +1 iff (amt > baln)) and we need
+ * to split up the split into pieces. Do it. */
+ {
+ time_t now = time(0);
+ Split * new_split;
+ gnc_numeric amt_a, amt_b, amt_tot;
+ gnc_numeric val_a, val_b, val_tot;
+ gnc_numeric frac;
+ Transaction *trans;
+ Timespec ts;
- acc = split->acc;
- xaccAccountBeginEdit (acc);
- trans = split->parent;
- xaccTransBeginEdit (trans);
+ acc = split->acc;
+ xaccAccountBeginEdit (acc);
+ trans = split->parent;
+ xaccTransBeginEdit (trans);
- amt_tot = split->amount;
- amt_a = gnc_numeric_neg (baln);
- amt_b = gnc_numeric_sub_fixed (amt_tot, amt_a);
+ amt_tot = split->amount;
+ amt_a = gnc_numeric_neg (baln);
+ amt_b = gnc_numeric_sub_fixed (amt_tot, amt_a);
- PINFO ("++++++++++++++ splitting split=%p into amt = %s + %s",
- split,
- gnc_num_dbg_to_string(amt_a),
- gnc_num_dbg_to_string(amt_b) );
+ PINFO ("++++++++++++++ splitting split=%p into amt = %s + %s",
+ split,
+ gnc_num_dbg_to_string(amt_a),
+ gnc_num_dbg_to_string(amt_b) );
- /* Compute the value so that it holds in the same proportion:
- * i.e. so that (amt_a / amt_tot) = (val_a / val_tot)
- */
- val_tot = split->value;
- frac = gnc_numeric_div (amt_a, amt_tot,
- GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
- val_a = gnc_numeric_mul (frac, val_tot,
- gnc_numeric_denom(val_tot),
- GNC_HOW_RND_ROUND| GNC_HOW_DENOM_EXACT);
-
- val_b = gnc_numeric_sub_fixed (val_tot, val_a);
- if (gnc_numeric_check(val_a))
- {
- PERR("Numeric overflow\n"
- "Acct=%s Txn=%s\n"
- "\tval_tot=%s amt_a=%s amt_tot=%s\n",
- xaccAccountGetName(acc),
- xaccTransGetDescription(trans),
- gnc_num_dbg_to_string(val_tot),
- gnc_num_dbg_to_string(amt_a),
- gnc_num_dbg_to_string(amt_tot));
- }
+ /* Compute the value so that it holds in the same proportion:
+ * i.e. so that (amt_a / amt_tot) = (val_a / val_tot)
+ */
+ val_tot = split->value;
+ frac = gnc_numeric_div (amt_a, amt_tot,
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);
+ val_a = gnc_numeric_mul (frac, val_tot,
+ gnc_numeric_denom(val_tot),
+ GNC_HOW_RND_ROUND | GNC_HOW_DENOM_EXACT);
- if (gnc_numeric_zero_p(val_a) || gnc_numeric_zero_p(val_b))
- {
- PERR ("Failed to split into two!");
- }
+ val_b = gnc_numeric_sub_fixed (val_tot, val_a);
+ if (gnc_numeric_check(val_a))
+ {
+ PERR("Numeric overflow\n"
+ "Acct=%s Txn=%s\n"
+ "\tval_tot=%s amt_a=%s amt_tot=%s\n",
+ xaccAccountGetName(acc),
+ xaccTransGetDescription(trans),
+ gnc_num_dbg_to_string(val_tot),
+ gnc_num_dbg_to_string(amt_a),
+ gnc_num_dbg_to_string(amt_tot));
+ }
- PINFO ("split value is = %s = %s + %s",
- gnc_num_dbg_to_string(val_tot),
- gnc_num_dbg_to_string(val_a),
- gnc_num_dbg_to_string(val_b) );
+ if (gnc_numeric_zero_p(val_a) || gnc_numeric_zero_p(val_b))
+ {
+ PERR ("Failed to split into two!");
+ }
- xaccSplitSetAmount (split, amt_a);
- xaccSplitSetValue (split, val_a);
+ PINFO ("split value is = %s = %s + %s",
+ gnc_num_dbg_to_string(val_tot),
+ gnc_num_dbg_to_string(val_a),
+ gnc_num_dbg_to_string(val_b) );
- /* Adding this split will have the effect of closing this lot,
- * because the new balance should be precisely zero. */
- gnc_lot_add_split (lot, split);
+ xaccSplitSetAmount (split, amt_a);
+ xaccSplitSetValue (split, val_a);
- /* Put the remainder of the balance into a new split,
- * which is in other respects just a clone of this one. */
- new_split = xaccMallocSplit (qof_instance_get_book(acc));
+ /* Adding this split will have the effect of closing this lot,
+ * because the new balance should be precisely zero. */
+ gnc_lot_add_split (lot, split);
- /* Copy most of the split attributes */
- xaccSplitSetMemo (new_split, xaccSplitGetMemo (split));
- xaccSplitSetAction (new_split, xaccSplitGetAction (split));
- xaccSplitSetReconcile (new_split, xaccSplitGetReconcile (split));
- ts = xaccSplitRetDateReconciledTS (split);
- xaccSplitSetDateReconciledTS (new_split, &ts);
+ /* Put the remainder of the balance into a new split,
+ * which is in other respects just a clone of this one. */
+ new_split = xaccMallocSplit (qof_instance_get_book(acc));
- /* We do not copy the KVP tree, as it seems like a dangerous
- * thing to do. If the user wants to access stuff in the 'old'
- * kvp tree from the 'new' split, they shoudl follow the
- * 'split-lot' pointers. Yes, this is complicated, but what
- * else can one do ??
- */
- /* Add kvp markup to indicate that these two splits used
- * to be one before being 'split'
- */
- gnc_kvp_bag_add (split->inst.kvp_data, "lot-split", now,
- "peer_guid", xaccSplitGetGUID (new_split),
- NULL);
+ /* Copy most of the split attributes */
+ xaccSplitSetMemo (new_split, xaccSplitGetMemo (split));
+ xaccSplitSetAction (new_split, xaccSplitGetAction (split));
+ xaccSplitSetReconcile (new_split, xaccSplitGetReconcile (split));
+ ts = xaccSplitRetDateReconciledTS (split);
+ xaccSplitSetDateReconciledTS (new_split, &ts);
- gnc_kvp_bag_add (new_split->inst.kvp_data, "lot-split", now,
- "peer_guid", xaccSplitGetGUID (split),
- NULL);
-
- xaccAccountInsertSplit (acc, new_split);
- xaccTransAppendSplit (trans, new_split);
- /* Set the amount and value after the split is in the transaction
- so it can find the correct denominator to use. Otherwise it
- uses 100000 which may cause an overflow in some of the tests
- in test-period */
- xaccSplitSetAmount (new_split, amt_b);
- xaccSplitSetValue (new_split, val_b);
- xaccTransCommitEdit (trans);
- xaccAccountCommitEdit (acc);
- return new_split;
- }
+ /* We do not copy the KVP tree, as it seems like a dangerous
+ * thing to do. If the user wants to access stuff in the 'old'
+ * kvp tree from the 'new' split, they shoudl follow the
+ * 'split-lot' pointers. Yes, this is complicated, but what
+ * else can one do ??
+ */
+ /* Add kvp markup to indicate that these two splits used
+ * to be one before being 'split'
+ */
+ gnc_kvp_bag_add (split->inst.kvp_data, "lot-split", now,
+ "peer_guid", xaccSplitGetGUID (new_split),
+ NULL);
+
+ gnc_kvp_bag_add (new_split->inst.kvp_data, "lot-split", now,
+ "peer_guid", xaccSplitGetGUID (split),
+ NULL);
+
+ xaccAccountInsertSplit (acc, new_split);
+ xaccTransAppendSplit (trans, new_split);
+ /* Set the amount and value after the split is in the transaction
+ so it can find the correct denominator to use. Otherwise it
+ uses 100000 which may cause an overflow in some of the tests
+ in test-period */
+ xaccSplitSetAmount (new_split, amt_b);
+ xaccSplitSetValue (new_split, val_b);
+ xaccTransCommitEdit (trans);
+ xaccAccountCommitEdit (acc);
+ return new_split;
+ }
}
/* ============================================================== */
-/* Accounting-policy callback. Given an account and an amount,
- * this routine should return a lot. By implementing this as
+/* Accounting-policy callback. Given an account and an amount,
+ * this routine should return a lot. By implementing this as
* a callback, we can 'easily' add other accounting policies.
*/
gboolean
xaccSplitAssign (Split *split)
{
- Account *acc;
- gboolean splits_split_up = FALSE;
- GNCLot *lot;
- GNCPolicy *pcy;
+ Account *acc;
+ gboolean splits_split_up = FALSE;
+ GNCLot *lot;
+ GNCPolicy *pcy;
- if (!split) return FALSE;
-
- /* If this split already belongs to a lot or the account doesn't
- * have lots, we are done.
- */
- if (split->lot) return FALSE;
- acc = split->acc;
- if (!xaccAccountHasTrades (acc))
- return FALSE;
- if (gnc_numeric_zero_p (split->amount))
- return FALSE;
+ if (!split) return FALSE;
- ENTER ("(split=%p)", split);
+ /* If this split already belongs to a lot or the account doesn't
+ * have lots, we are done.
+ */
+ if (split->lot) return FALSE;
+ acc = split->acc;
+ if (!xaccAccountHasTrades (acc))
+ return FALSE;
+ if (gnc_numeric_zero_p (split->amount))
+ return FALSE;
- pcy = gnc_account_get_policy(acc);
- xaccAccountBeginEdit (acc);
+ ENTER ("(split=%p)", split);
- /* If we are here, this split does not belong to any lot.
- * We ask the policy for a lot to assign it to. This
- * block is written in the form of a while loop, since we
- * may have to bust a split across several lots.
- */
- while (split)
- {
- PINFO ("have split %p amount=%s", split,
- gnc_num_dbg_to_string (split->amount));
- split->gains |= GAINS_STATUS_VDIRTY;
- lot = pcy->PolicyGetLot (pcy, split);
- if (!lot)
- {
- lot = gnc_lot_make_default (acc);
- PINFO ("start new lot (%s)", gnc_lot_get_title(lot));
- }
- split = xaccSplitAssignToLot (split, lot);
- if (split) splits_split_up = TRUE;
- }
- xaccAccountCommitEdit (acc);
+ pcy = gnc_account_get_policy(acc);
+ xaccAccountBeginEdit (acc);
- LEAVE (" split_up=%d", splits_split_up);
- return splits_split_up;
+ /* If we are here, this split does not belong to any lot.
+ * We ask the policy for a lot to assign it to. This
+ * block is written in the form of a while loop, since we
+ * may have to bust a split across several lots.
+ */
+ while (split)
+ {
+ PINFO ("have split %p amount=%s", split,
+ gnc_num_dbg_to_string (split->amount));
+ split->gains |= GAINS_STATUS_VDIRTY;
+ lot = pcy->PolicyGetLot (pcy, split);
+ if (!lot)
+ {
+ lot = gnc_lot_make_default (acc);
+ PINFO ("start new lot (%s)", gnc_lot_get_title(lot));
+ }
+ split = xaccSplitAssignToLot (split, lot);
+ if (split) splits_split_up = TRUE;
+ }
+ xaccAccountCommitEdit (acc);
+
+ LEAVE (" split_up=%d", splits_split_up);
+ return splits_split_up;
}
/* ============================================================== */
@@ -629,22 +629,22 @@
Split *
xaccSplitGetCapGainsSplit (const Split *split)
{
- KvpValue *val;
- GUID *gains_guid;
- Split *gains_split;
-
- if (!split) return NULL;
+ KvpValue *val;
+ GUID *gains_guid;
+ Split *gains_split;
- val = kvp_frame_get_slot (split->inst.kvp_data, "gains-split");
- if (!val) return NULL;
- gains_guid = kvp_value_get_guid (val);
- if (!gains_guid) return NULL;
+ if (!split) return NULL;
- /* Both splits will be in the same collection, so search there. */
- gains_split = (Split*) qof_collection_lookup_entity (
- qof_instance_get_collection(split), gains_guid);
- PINFO ("split=%p has gains-split=%p", split, gains_split);
- return gains_split;
+ val = kvp_frame_get_slot (split->inst.kvp_data, "gains-split");
+ if (!val) return NULL;
+ gains_guid = kvp_value_get_guid (val);
+ if (!gains_guid) return NULL;
+
+ /* Both splits will be in the same collection, so search there. */
+ gains_split = (Split*) qof_collection_lookup_entity (
+ qof_instance_get_collection(split), gains_guid);
+ PINFO ("split=%p has gains-split=%p", split, gains_split);
+ return gains_split;
}
/* ============================================================== */
@@ -652,22 +652,22 @@
Split *
xaccSplitGetGainsSourceSplit (const Split *split)
{
- KvpValue *val;
- GUID *source_guid;
- Split *source_split;
-
- if (!split) return NULL;
+ KvpValue *val;
+ GUID *source_guid;
+ Split *source_split;
- val = kvp_frame_get_slot (split->inst.kvp_data, "gains-source");
- if (!val) return NULL;
- source_guid = kvp_value_get_guid (val);
- if (!source_guid) return NULL;
+ if (!split) return NULL;
- /* Both splits will be in the same collection, so search there. */
- source_split = (Split*) qof_collection_lookup_entity(
- qof_instance_get_collection(split), source_guid);
- PINFO ("split=%p has source-split=%p", split, source_split);
- return source_split;
+ val = kvp_frame_get_slot (split->inst.kvp_data, "gains-source");
+ if (!val) return NULL;
+ source_guid = kvp_value_get_guid (val);
+ if (!source_guid) return NULL;
+
+ /* Both splits will be in the same collection, so search there. */
+ source_split = (Split*) qof_collection_lookup_entity(
+ qof_instance_get_collection(split), source_guid);
+ PINFO ("split=%p has source-split=%p", split, source_split);
+ return source_split;
}
/* ============================================================== */
@@ -675,442 +675,442 @@
void
xaccSplitComputeCapGains(Split *split, Account *gain_acc)
{
- SplitList *node;
- GNCLot *lot;
- GNCPolicy *pcy;
- gnc_commodity *currency = NULL;
- gnc_numeric zero = gnc_numeric_zero();
- gnc_numeric value = zero;
- gnc_numeric frac;
- gnc_numeric opening_amount, opening_value;
- gnc_numeric lot_amount, lot_value;
- gnc_commodity *opening_currency;
+ SplitList *node;
+ GNCLot *lot;
+ GNCPolicy *pcy;
+ gnc_commodity *currency = NULL;
+ gnc_numeric zero = gnc_numeric_zero();
+ gnc_numeric value = zero;
+ gnc_numeric frac;
+ gnc_numeric opening_amount, opening_value;
+ gnc_numeric lot_amount, lot_value;
+ gnc_commodity *opening_currency;
- if (!split) return;
- lot = split->lot;
- if (!lot) return;
- pcy = gnc_account_get_policy(gnc_lot_get_account(lot));
- currency = split->parent->common_currency;
+ if (!split) return;
+ lot = split->lot;
+ if (!lot) return;
+ pcy = gnc_account_get_policy(gnc_lot_get_account(lot));
+ currency = split->parent->common_currency;
- ENTER ("(split=%p gains=%p status=0x%x lot=%s)", split,
- split->gains_split, split->gains,
- kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
+ ENTER ("(split=%p gains=%p status=0x%x lot=%s)", split,
+ split->gains_split, split->gains,
+ kvp_frame_get_string (gnc_lot_get_slots (lot), "/title"));
- /* Make sure the status flags and pointers are initialized */
- xaccSplitDetermineGainStatus(split);
+ /* Make sure the status flags and pointers are initialized */
+ xaccSplitDetermineGainStatus(split);
- /* Not possible to have gains if the transaction currency and
- * account commodity are identical. */
- if (gnc_commodity_equal (currency,
- xaccAccountGetCommodity(split->acc)))
- {
- LEAVE ("Currency transfer, gains not possible, returning.");
- return;
- }
+ /* Not possible to have gains if the transaction currency and
+ * account commodity are identical. */
+ if (gnc_commodity_equal (currency,
+ xaccAccountGetCommodity(split->acc)))
+ {
+ LEAVE ("Currency transfer, gains not possible, returning.");
+ return;
+ }
- if (pcy->PolicyIsOpeningSplit (pcy, lot, split))
- {
-#if MOVE_THIS_TO_A_DATA_INTEGRITY_SCRUBBER
- /* Check to make sure that this opening split doesn't
- * have a cap-gain transaction associated with it.
- * If it does, that's wrong, and we ruthlessly destroy it.
- * XXX Don't do this, it leads to infinite loops.
- * We need to scrub out errors like this elsewhere!
- */
- if (xaccSplitGetCapGainsSplit (split))
- {
- Split *gains_split = xaccSplitGetCapGainsSplit(split);
- Transaction *trans = gains_split->parent;
- PERR ("Opening Split must not have cap gains!!\n");
-
- xaccTransBeginEdit (trans);
- xaccTransDestroy (trans);
- xaccTransCommitEdit (trans);
- }
+ if (pcy->PolicyIsOpeningSplit (pcy, lot, split))
+ {
+#if MOVE_THIS_TO_A_DATA_INTEGRITY_SCRUBBER
+ /* Check to make sure that this opening split doesn't
+ * have a cap-gain transaction associated with it.
+ * If it does, that's wrong, and we ruthlessly destroy it.
+ * XXX Don't do this, it leads to infinite loops.
+ * We need to scrub out errors like this elsewhere!
+ */
+ if (xaccSplitGetCapGainsSplit (split))
+ {
+ Split *gains_split = xaccSplitGetCapGainsSplit(split);
+ Transaction *trans = gains_split->parent;
+ PERR ("Opening Split must not have cap gains!!\n");
+
+ xaccTransBeginEdit (trans);
+ xaccTransDestroy (trans);
+ xaccTransCommitEdit (trans);
+ }
#endif
- LEAVE ("Lot opening split, returning.");
- return;
- }
+ LEAVE ("Lot opening split, returning.");
+ return;
+ }
- if (safe_strcmp ("stock-split", xaccSplitGetType (split)) == 0)
- {
- LEAVE ("Stock split split, returning.");
- return;
- }
-
- if (GAINS_STATUS_GAINS & split->gains)
- {
- Split *s;
- PINFO ("split is a gains recording split, switch over");
- /* If this is the split that records the gains, then work with
- * the split that generates the gains.
- */
- /* split = xaccSplitGetCapGainsSplit (split); */
- s = split->gains_split;
+ if (safe_strcmp ("stock-split", xaccSplitGetType (split)) == 0)
+ {
+ LEAVE ("Stock split split, returning.");
+ return;
+ }
- /* This should never be NULL, and if it is, and its matching
- * parent can't be found, then its a bug, and we should be
- * discarding this split. But ... for now .. return.
- * XXX move appropriate actions to a 'scrub' routine'
- */
- if (!s)
- {
- PERR ("Bad gains-split pointer! .. trying to recover.");
- split->gains_split = xaccSplitGetCapGainsSplit (split);
- s = split->gains_split;
- if (!s) return;
-#if MOVE_THIS_TO_A_DATA_INTEGRITY_SCRUBBER
- xaccTransDestroy (trans);
+ if (GAINS_STATUS_GAINS & split->gains)
+ {
+ Split *s;
+ PINFO ("split is a gains recording split, switch over");
+ /* If this is the split that records the gains, then work with
+ * the split that generates the gains.
+ */
+ /* split = xaccSplitGetCapGainsSplit (split); */
+ s = split->gains_split;
+
+ /* This should never be NULL, and if it is, and its matching
+ * parent can't be found, then its a bug, and we should be
+ * discarding this split. But ... for now .. return.
+ * XXX move appropriate actions to a 'scrub' routine'
+ */
+ if (!s)
+ {
+ PERR ("Bad gains-split pointer! .. trying to recover.");
+ split->gains_split = xaccSplitGetCapGainsSplit (split);
+ s = split->gains_split;
+ if (!s) return;
+#if MOVE_THIS_TO_A_DATA_INTEGRITY_SCRUBBER
+ xaccTransDestroy (trans);
#endif
- }
- split = s;
- }
+ }
+ split = s;
+ }
- /* Note: if the value of the 'opening' split(s) has changed,
- * then the cap gains are changed. So we need to check not
- * only if this split is dirty, but also the lot-opening splits. */
- for (node=gnc_lot_get_split_list(lot); node; node=node->next)
- {
- Split *s = node->data;
- if (pcy->PolicyIsOpeningSplit(pcy,lot,s))
- {
- if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus (s);
- if (s->gains & GAINS_STATUS_VDIRTY)
- {
- /* Force a recompute to occur */
- split->gains |= GAINS_STATUS_VDIRTY;
- break;
- }
- }
- }
+ /* Note: if the value of the 'opening' split(s) has changed,
+ * then the cap gains are changed. So we need to check not
+ * only if this split is dirty, but also the lot-opening splits. */
+ for (node = gnc_lot_get_split_list(lot); node; node = node->next)
+ {
+ Split *s = node->data;
+ if (pcy->PolicyIsOpeningSplit(pcy, lot, s))
+ {
+ if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus (s);
+ if (s->gains & GAINS_STATUS_VDIRTY)
+ {
+ /* Force a recompute to occur */
+ split->gains |= GAINS_STATUS_VDIRTY;
+ break;
+ }
+ }
+ }
- /* If it doesn't look like this split is 'dirty', then there's
- * nothing to do. Just return. */
- if ((FALSE == (split->gains & GAINS_STATUS_A_VDIRTY)) &&
- (split->gains_split) &&
- (FALSE == (split->gains_split->gains & GAINS_STATUS_A_VDIRTY)))
- {
- LEAVE ("split not dirty, returning");
- return;
- }
+ /* If it doesn't look like this split is 'dirty', then there's
+ * nothing to do. Just return. */
+ if ((FALSE == (split->gains & GAINS_STATUS_A_VDIRTY)) &&
+ (split->gains_split) &&
+ (FALSE == (split->gains_split->gains & GAINS_STATUS_A_VDIRTY)))
+ {
+ LEAVE ("split not dirty, returning");
+ return;
+ }
- /* Yow! If amount is zero, there's nothing to do! Amount-zero splits
- * may exist if users attempted to manually record gains. */
- if (gnc_numeric_zero_p (split->amount)) return;
+ /* Yow! If amount is zero, there's nothing to do! Amount-zero splits
+ * may exist if users attempted to manually record gains. */
+ if (gnc_numeric_zero_p (split->amount)) return;
- /* If we got to here, then the split or something related is
- * 'dirty' and the gains really do need to be recomputed.
- * So start working things. */
+ /* If we got to here, then the split or something related is
+ * 'dirty' and the gains really do need to be recomputed.
+ * So start working things. */
- /* Get the amount and value in this lot at the time of this transaction. */
- gnc_lot_get_balance_before (lot, split, &lot_amount, &lot_value);
+ /* Get the amount and value in this lot at the time of this transaction. */
+ gnc_lot_get_balance_before (lot, split, &lot_amount, &lot_value);
- pcy->PolicyGetLotOpening (pcy, lot, &opening_amount, &opening_value,
- &opening_currency);
+ pcy->PolicyGetLotOpening (pcy, lot, &opening_amount, &opening_value,
+ &opening_currency);
- /* Check to make sure the lot-opening currency and this split
- * use the same currency */
- if (FALSE == gnc_commodity_equiv (currency, opening_currency))
- {
- /* OK, the purchase and the sale were made in different currencies.
- * I don't know how to compute cap gains for that. This is not
- * an error. Just punt, silently.
- */
- LEAVE ("Can't compute gains, mismatched commodities!");
- return;
- }
+ /* Check to make sure the lot-opening currency and this split
+ * use the same currency */
+ if (FALSE == gnc_commodity_equiv (currency, opening_currency))
+ {
+ /* OK, the purchase and the sale were made in different currencies.
+ * I don't know how to compute cap gains for that. This is not
+ * an error. Just punt, silently.
+ */
+ LEAVE ("Can't compute gains, mismatched commodities!");
+ return;
+ }
- /* Opening amount should be larger (or equal) to current split,
- * and it should be of the opposite sign.
- * XXX This should really be a part of a scrub routine that
- * cleans up the lot, before we get at it!
- */
- if (0 > gnc_numeric_compare (gnc_numeric_abs(lot_amount),
- gnc_numeric_abs(split->amount)))
- {
- GList *n;
- for (n = gnc_lot_get_split_list(lot); n; n = n->next)
- {
- Split *s = n->data;
- PINFO ("split amt=%s", gnc_num_dbg_to_string(s->amount));
- }
- PERR ("Malformed Lot \"%s\"! (too thin!) "
- "opening amt=%s split amt=%s baln=%s",
- gnc_lot_get_title (lot),
- gnc_num_dbg_to_string (lot_amount),
- gnc_num_dbg_to_string (split->amount),
- gnc_num_dbg_to_string (gnc_lot_get_balance(lot)));
- return;
- }
- if ( (gnc_numeric_negative_p(lot_amount) ||
- gnc_numeric_positive_p(split->amount)) &&
- (gnc_numeric_positive_p(lot_amount) ||
- gnc_numeric_negative_p(split->amount)))
- {
- GList *n;
- for (n = gnc_lot_get_split_list(lot); n; n = n->next)
- {
- Split *s = n->data;
- PINFO ("split amt=%s", gnc_num_dbg_to_string(s->amount));
- }
- PERR ("Malformed Lot \"%s\"! (too fat!) "
- "opening amt=%s split amt=%s baln=%s",
- gnc_lot_get_title (lot),
- gnc_num_dbg_to_string (lot_amount),
- gnc_num_dbg_to_string (split->amount),
- gnc_num_dbg_to_string (gnc_lot_get_balance(lot)));
- return;
- }
+ /* Opening amount should be larger (or equal) to current split,
+ * and it should be of the opposite sign.
+ * XXX This should really be a part of a scrub routine that
+ * cleans up the lot, before we get at it!
+ */
+ if (0 > gnc_numeric_compare (gnc_numeric_abs(lot_amount),
+ gnc_numeric_abs(split->amount)))
+ {
+ GList *n;
+ for (n = gnc_lot_get_split_list(lot); n; n = n->next)
+ {
+ Split *s = n->data;
+ PINFO ("split amt=%s", gnc_num_dbg_to_string(s->amount));
+ }
+ PERR ("Malformed Lot \"%s\"! (too thin!) "
+ "opening amt=%s split amt=%s baln=%s",
+ gnc_lot_get_title (lot),
+ gnc_num_dbg_to_string (lot_amount),
+ gnc_num_dbg_to_string (split->amount),
+ gnc_num_dbg_to_string (gnc_lot_get_balance(lot)));
+ return;
+ }
+ if ( (gnc_numeric_negative_p(lot_amount) ||
+ gnc_numeric_positive_p(split->amount)) &&
+ (gnc_numeric_positive_p(lot_amount) ||
+ gnc_numeric_negative_p(split->amount)))
+ {
+ GList *n;
+ for (n = gnc_lot_get_split_list(lot); n; n = n->next)
+ {
+ Split *s = n->data;
+ PINFO ("split amt=%s", gnc_num_dbg_to_string(s->amount));
+ }
+ PERR ("Malformed Lot \"%s\"! (too fat!) "
+ "opening amt=%s split amt=%s baln=%s",
+ gnc_lot_get_title (lot),
+ gnc_num_dbg_to_string (lot_amount),
+ gnc_num_dbg_to_string (split->amount),
+ gnc_num_dbg_to_string (gnc_lot_get_balance(lot)));
+ return;
+ }
- /* The cap gains is the difference between the basis prior to the
- * current split, and the current split, pro-rated for an equal
- * amount of shares.
- * i.e. purchase_price = lot_value / lot_amount
- * cost_basis = purchase_price * current_split_amount
- * cap_gain = current_split_value - cost_basis
- */
- /* Fraction of the lot that this split represents: */
- frac = gnc_numeric_div (split->amount, lot_amount,
- GNC_DENOM_AUTO,
+ /* The cap gains is the difference between the basis prior to the
+ * current split, and the current split, pro-rated for an equal
+ * amount of shares.
+ * i.e. purchase_price = lot_value / lot_amount
+ * cost_basis = purchase_price * current_split_amount
+ * cap_gain = current_split_value - cost_basis
+ */
+ /* Fraction of the lot that this split represents: */
+ frac = gnc_numeric_div (split->amount, lot_amount,
+ GNC_DENOM_AUTO,
GNC_HOW_DENOM_REDUCE);
- /* Basis for this split: */
- value = gnc_numeric_mul (frac, lot_value,
- gnc_numeric_denom(opening_value),
- GNC_HOW_DENOM_EXACT|GNC_HOW_RND_ROUND);
- /* Capital gain for this split: */
- value = gnc_numeric_sub (value, split->value,
- GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
- PINFO ("Open amt=%s val=%s; split amt=%s val=%s; gains=%s\n",
- gnc_num_dbg_to_string (lot_amount),
- gnc_num_dbg_to_string (lot_value),
- gnc_num_dbg_to_string (split->amount),
- gnc_num_dbg_to_string (split->value),
- gnc_num_dbg_to_string (value));
- if (gnc_numeric_check (value))
- {
- PERR ("Numeric overflow during gains calculation\n"
- "Acct=%s Txn=%s\n"
- "\tOpen amt=%s val=%s\n\tsplit amt=%s val=%s\n\tgains=%s\n",
- xaccAccountGetName(split->acc),
- xaccTransGetDescription(split->parent),
- gnc_num_dbg_to_string (lot_amount),
- gnc_num_dbg_to_string (lot_value),
- gnc_num_dbg_to_string (split->amount),
- gnc_num_dbg_to_string (split->value),
- gnc_num_dbg_to_string (value));
- return;
- }
+ /* Basis for this split: */
+ value = gnc_numeric_mul (frac, lot_value,
+ gnc_numeric_denom(opening_value),
+ GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND);
+ /* Capital gain for this split: */
+ value = gnc_numeric_sub (value, split->value,
+ GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED);
+ PINFO ("Open amt=%s val=%s; split amt=%s val=%s; gains=%s\n",
+ gnc_num_dbg_to_string (lot_amount),
+ gnc_num_dbg_to_string (lot_value),
+ gnc_num_dbg_to_string (split->amount),
+ gnc_num_dbg_to_string (split->value),
+ gnc_num_dbg_to_string (value));
+ if (gnc_numeric_check (value))
+ {
+ PERR ("Numeric overflow during gains calculation\n"
+ "Acct=%s Txn=%s\n"
+ "\tOpen amt=%s val=%s\n\tsplit amt=%s val=%s\n\tgains=%s\n",
+ xaccAccountGetName(split->acc),
+ xaccTransGetDescription(split->parent),
+ gnc_num_dbg_to_string (lot_amount),
+ gnc_num_dbg_to_string (lot_value),
+ gnc_num_dbg_to_string (split->amount),
+ gnc_num_dbg_to_string (split->value),
+ gnc_num_dbg_to_string (value));
+ return;
+ }
- /* Are the cap gains zero? If not, add a balancing transaction.
- * As per design doc lots.txt: the transaction has two splits,
- * with equal & opposite values. The amt of one iz zero (so as
- * not to upset the lot balance), the amt of the other is the same
- * as its value (its the realized gain/loss).
- */
- if (FALSE == gnc_numeric_zero_p (value))
- {
- Transaction *trans;
- Split *lot_split, *gain_split;
- Timespec ts;
- gboolean new_gain_split;
- gnc_numeric negvalue = gnc_numeric_neg (value);
+ /* Are the cap gains zero? If not, add a balancing transaction.
+ * As per design doc lots.txt: the transaction has two splits,
+ * with equal & opposite values. The amt of one iz zero (so as
+ * not to upset the lot balance), the amt of the other is the same
+ * as its value (its the realized gain/loss).
+ */
+ if (FALSE == gnc_numeric_zero_p (value))
+ {
+ Transaction *trans;
+ Split *lot_split, *gain_split;
+ Timespec ts;
+ gboolean new_gain_split;
+ gnc_numeric negvalue = gnc_numeric_neg (value);
- /* See if there already is an associated gains transaction.
- * If there is, adjust its value as appropriate. Else, create
- * a new gains transaction.
- */
- /* lot_split = xaccSplitGetCapGainsSplit (split); */
- lot_split = split->gains_split;
+ /* See if there already is an associated gains transaction.
+ * If there is, adjust its value as appropriate. Else, create
+ * a new gains transaction.
+ */
+ /* lot_split = xaccSplitGetCapGainsSplit (split); */
+ lot_split = split->gains_split;
- if (NULL == lot_split)
- {
- Account *lot_acc = gnc_lot_get_account(lot);
- QofBook *book = qof_instance_get_book(lot_acc);
+ if (NULL == lot_split)
+ {
+ Account *lot_acc = gnc_lot_get_account(lot);
+ QofBook *book = qof_instance_get_book(lot_acc);
- new_gain_split = TRUE;
-
- lot_split = xaccMallocSplit (book);
- gain_split = xaccMallocSplit (book);
+ new_gain_split = TRUE;
- /* Check to make sure the gains account currency matches. */
- if ((NULL == gain_acc) ||
- (FALSE == gnc_commodity_equiv (currency,
- xaccAccountGetCommodity(gain_acc))))
- {
- gain_acc = GetOrMakeGainAcct (lot_acc, currency);
- }
+ lot_split = xaccMallocSplit (book);
+ gain_split = xaccMallocSplit (book);
- xaccAccountBeginEdit (gain_acc);
- xaccAccountInsertSplit (gain_acc, gain_split);
- xaccAccountCommitEdit (gain_acc);
+ /* Check to make sure the gains account currency matches. */
+ if ((NULL == gain_acc) ||
+ (FALSE == gnc_commodity_equiv (currency,
+ xaccAccountGetCommodity(gain_acc))))
+ {
+ gain_acc = GetOrMakeGainAcct (lot_acc, currency);
+ }
- xaccAccountBeginEdit (lot_acc);
- xaccAccountInsertSplit (lot_acc, lot_split);
- xaccAccountCommitEdit (lot_acc);
+ xaccAccountBeginEdit (gain_acc);
+ xaccAccountInsertSplit (gain_acc, gain_split);
+ xaccAccountCommitEdit (gain_acc);
- trans = xaccMallocTransaction (book);
+ xaccAccountBeginEdit (lot_acc);
+ xaccAccountInsertSplit (lot_acc, lot_split);
+ xaccAccountCommitEdit (lot_acc);
- xaccTransBeginEdit (trans);
- xaccTransSetCurrency (trans, currency);
- xaccTransSetDescription (trans, _("Realized Gain/Loss"));
-
- xaccTransAppendSplit (trans, lot_split);
- xaccTransAppendSplit (trans, gain_split);
+ trans = xaccMallocTransaction (book);
- xaccSplitSetMemo (lot_split, _("Realized Gain/Loss"));
- xaccSplitSetMemo (gain_split, _("Realized Gain/Loss"));
+ xaccTransBeginEdit (trans);
+ xaccTransSetCurrency (trans, currency);
+ xaccTransSetDescription (trans, _("Realized Gain/Loss"));
- /* For the new transaction, install KVP markup indicating
- * that this is the gains transaction that corresponds
- * to the gains source.
- */
- kvp_frame_set_guid (split->inst.kvp_data, "gains-split",
- xaccSplitGetGUID (lot_split));
- kvp_frame_set_guid (lot_split->inst.kvp_data, "gains-source",
- xaccSplitGetGUID (split));
+ xaccTransAppendSplit (trans, lot_split);
+ xaccTransAppendSplit (trans, gain_split);
- }
- else
- {
- trans = lot_split->parent;
- gain_split = xaccSplitGetOtherSplit (lot_split);
- /* If the gain is already recorded corectly do nothing. This is
- * more than just an optimization since this may be called during
- * gnc_book_partition_txn and depending on the order in which things
- * happen some splits may be in the wrong book at that time. */
- if (split->gains_split == lot_split &&
- lot_split->gains_split == split &&
- gain_split->gains_split == split &&
- gnc_numeric_equal (xaccSplitGetValue (lot_split), value) &&
- gnc_numeric_zero_p (xaccSplitGetAmount (lot_split)) &&
- gnc_numeric_equal (xaccSplitGetValue (gain_split), negvalue) &&
- gnc_numeric_equal (xaccSplitGetAmount (gain_split), negvalue))
- {
- new_gain_split = FALSE;
- }
- else
- {
- new_gain_split = TRUE;
- xaccTransBeginEdit (trans);
+ xaccSplitSetMemo (lot_split, _("Realized Gain/Loss"));
+ xaccSplitSetMemo (gain_split, _("Realized Gain/Loss"));
- /* Make sure the existing gains trans has the correct currency,
- * just in case someone screwed with it! */
- if (FALSE == gnc_commodity_equiv(currency,trans->common_currency))
+ /* For the new transaction, install KVP markup indicating
+ * that this is the gains transaction that corresponds
+ * to the gains source.
+ */
+ kvp_frame_set_guid (split->inst.kvp_data, "gains-split",
+ xaccSplitGetGUID (lot_split));
+ kvp_frame_set_guid (lot_split->inst.kvp_data, "gains-source",
+ xaccSplitGetGUID (split));
+
+ }
+ else
+ {
+ trans = lot_split->parent;
+ gain_split = xaccSplitGetOtherSplit (lot_split);
+ /* If the gain is already recorded corectly do nothing. This is
+ * more than just an optimization since this may be called during
+ * gnc_book_partition_txn and depending on the order in which things
+ * happen some splits may be in the wrong book at that time. */
+ if (split->gains_split == lot_split &&
+ lot_split->gains_split == split &&
+ gain_split->gains_split == split &&
+ gnc_numeric_equal (xaccSplitGetValue (lot_split), value) &&
+ gnc_numeric_zero_p (xaccSplitGetAmount (lot_split)) &&
+ gnc_numeric_equal (xaccSplitGetValue (gain_split), negvalue) &&
+ gnc_numeric_equal (xaccSplitGetAmount (gain_split), negvalue))
{
- PWARN ("Resetting the transaction currency!");
- xaccTransSetCurrency (trans, currency);
+ new_gain_split = FALSE;
}
- }
- }
+ else
+ {
+ new_gain_split = TRUE;
+ xaccTransBeginEdit (trans);
- if (new_gain_split)
- {
- /* Common to both */
- ts = xaccTransRetDatePostedTS (split->parent);
- xaccTransSetDatePostedTS (trans, &ts);
- xaccTransSetDateEnteredSecs (trans, time(0));
-
- xaccSplitSetAmount (lot_split, zero);
- xaccSplitSetValue (lot_split, value);
-
- xaccSplitSetAmount (gain_split, negvalue);
- xaccSplitSetValue (gain_split, negvalue);
-
- /* Some short-cuts to help avoid the above kvp lookup. */
- split->gains = GAINS_STATUS_CLEAN;
- split->gains_split = lot_split;
- lot_split->gains = GAINS_STATUS_GAINS;
- lot_split->gains_split = split;
- gain_split->gains = GAINS_STATUS_GAINS;
- gain_split->gains_split = split;
-
- /* Do this last since it may generate an event that will call us
- recursively. */
- gnc_lot_add_split (lot, lot_split);
-
- xaccTransCommitEdit (trans);
- }
- }
- LEAVE ("(lot=%s)", gnc_lot_get_title(lot));
+ /* Make sure the existing gains trans has the correct currency,
+ * just in case someone screwed with it! */
+ if (FALSE == gnc_commodity_equiv(currency, trans->common_currency))
+ {
+ PWARN ("Resetting the transaction currency!");
+ xaccTransSetCurrency (trans, currency);
+ }
+ }
+ }
+
+ if (new_gain_split)
+ {
+ /* Common to both */
+ ts = xaccTransRetDatePostedTS (split->parent);
+ xaccTransSetDatePostedTS (trans, &ts);
+ xaccTransSetDateEnteredSecs (trans, time(0));
+
+ xaccSplitSetAmount (lot_split, zero);
+ xaccSplitSetValue (lot_split, value);
+
+ xaccSplitSetAmount (gain_split, negvalue);
+ xaccSplitSetValue (gain_split, negvalue);
+
+ /* Some short-cuts to help avoid the above kvp lookup. */
+ split->gains = GAINS_STATUS_CLEAN;
+ split->gains_split = lot_split;
+ lot_split->gains = GAINS_STATUS_GAINS;
+ lot_split->gains_split = split;
+ gain_split->gains = GAINS_STATUS_GAINS;
+ gain_split->gains_split = split;
+
+ /* Do this last since it may generate an event that will call us
+ recursively. */
+ gnc_lot_add_split (lot, lot_split);
+
+ xaccTransCommitEdit (trans);
+ }
+ }
+ LEAVE ("(lot=%s)", gnc_lot_get_title(lot));
}
/* ============================================================== */
-gnc_numeric
+gnc_numeric
xaccSplitGetCapGains(Split * split)
{
- if (!split) return gnc_numeric_zero();
- ENTER("(split=%p)", split);
+ if (!split) return gnc_numeric_zero();
+ ENTER("(split=%p)", split);
- if (GAINS_STATUS_UNKNOWN == split->gains)
- xaccSplitDetermineGainStatus(split);
- if ((split->gains & GAINS_STATUS_A_VDIRTY) ||
- (split->gains_split &&
- (split->gains_split->gains & GAINS_STATUS_A_VDIRTY)))
- {
- xaccSplitComputeCapGains (split, NULL);
- }
+ if (GAINS_STATUS_UNKNOWN == split->gains)
+ xaccSplitDetermineGainStatus(split);
+ if ((split->gains & GAINS_STATUS_A_VDIRTY) ||
+ (split->gains_split &&
+ (split->gains_split->gains & GAINS_STATUS_A_VDIRTY)))
+ {
+ xaccSplitComputeCapGains (split, NULL);
+ }
- /* If this is the source split, get the gains from the one
- * that records the gains. If this already is the gains split,
- * its a no-op. */
- if (!(GAINS_STATUS_GAINS & split->gains))
- {
- /* split = xaccSplitGetCapGainsSplit (split); */
- split = split->gains_split;
- }
+ /* If this is the source split, get the gains from the one
+ * that records the gains. If this already is the gains split,
+ * its a no-op. */
+ if (!(GAINS_STATUS_GAINS & split->gains))
+ {
+ /* split = xaccSplitGetCapGainsSplit (split); */
+ split = split->gains_split;
+ }
- LEAVE("(split=%p)", split);
- if (!split) return gnc_numeric_zero();
+ LEAVE("(split=%p)", split);
+ if (!split) return gnc_numeric_zero();
- return split->value;
+ return split->value;
}
/* ============================================================== */
-void
+void
xaccLotComputeCapGains (GNCLot *lot, Account *gain_acc)
{
- SplitList *node;
- GNCPolicy *pcy;
- gboolean is_dirty = FALSE;
+ SplitList *node;
+ GNCPolicy *pcy;
+ gboolean is_dirty = FALSE;
- /* Note: if the value of the 'opening' split(s) has changed,
- * then the cap gains are changed. To capture this, we need
- * to mark all splits dirty if the opening splits are dirty. */
+ /* Note: if the value of the 'opening' split(s) has changed,
+ * then the cap gains are changed. To capture this, we need
+ * to mark all splits dirty if the opening splits are dirty. */
- ENTER("(lot=%p)", lot);
- pcy = gnc_account_get_policy(gnc_lot_get_account(lot));
- for (node = gnc_lot_get_split_list(lot); node; node = node->next)
- {
- Split *s = node->data;
- if (pcy->PolicyIsOpeningSplit(pcy,lot,s))
- {
- if (GAINS_STATUS_UNKNOWN == s->gains)
- xaccSplitDetermineGainStatus(s);
- if (s->gains & GAINS_STATUS_VDIRTY)
- {
- is_dirty = TRUE;
- s->gains &= ~GAINS_STATUS_VDIRTY;
- }
- }
- }
+ ENTER("(lot=%p)", lot);
+ pcy = gnc_account_get_policy(gnc_lot_get_account(lot));
+ for (node = gnc_lot_get_split_list(lot); node; node = node->next)
+ {
+ Split *s = node->data;
+ if (pcy->PolicyIsOpeningSplit(pcy, lot, s))
+ {
+ if (GAINS_STATUS_UNKNOWN == s->gains)
+ xaccSplitDetermineGainStatus(s);
+ if (s->gains & GAINS_STATUS_VDIRTY)
+ {
+ is_dirty = TRUE;
+ s->gains &= ~GAINS_STATUS_VDIRTY;
+ }
+ }
+ }
- if (is_dirty)
- {
- for (node = gnc_lot_get_split_list(lot); node; node = node->next)
- {
- Split *s = node->data;
- s->gains |= GAINS_STATUS_VDIRTY;
- }
- }
+ if (is_dirty)
+ {
+ for (node = gnc_lot_get_split_list(lot); node; node = node->next)
+ {
+ Split *s = node->data;
+ s->gains |= GAINS_STATUS_VDIRTY;
+ }
+ }
- for (node = gnc_lot_get_split_list(lot); node; node = node->next)
- {
- Split *s = node->data;
- xaccSplitComputeCapGains (s, gain_acc);
- }
- LEAVE("(lot=%p)", lot);
+ for (node = gnc_lot_get_split_list(lot); node; node = node->next)
+ {
+ Split *s = node->data;
+ xaccSplitComputeCapGains (s, gain_acc);
+ }
+ LEAVE("(lot=%p)", lot);
}
/* =========================== END OF FILE ======================= */
Modified: gnucash/trunk/src/engine/engine-helpers.c
===================================================================
--- gnucash/trunk/src/engine/engine-helpers.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/engine-helpers.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -35,7 +35,7 @@
#include "gnc-engine.h"
#include "guile-mappings.h"
#include "qof.h"
-/** \todo Code dependent on the private query headers
+/** \todo Code dependent on the private query headers
qofquery-p.h and qofquerycore-p.h may need to be modified.
These files are temporarily exported for QOF 0.6.0 but
cannot be considered "standard" or public parts of QOF. */
@@ -47,125 +47,125 @@
static QofLogModule log_module = GNC_MOD_ENGINE;
Timespec
-gnc_transaction_get_date_posted(const Transaction *t)
+gnc_transaction_get_date_posted(const Transaction *t)
{
- Timespec result;
- xaccTransGetDatePostedTS(t, &result);
- return(result);
+ Timespec result;
+ xaccTransGetDatePostedTS(t, &result);
+ return(result);
}
Timespec
-gnc_transaction_get_date_entered(const Transaction *t)
+gnc_transaction_get_date_entered(const Transaction *t)
{
- Timespec result;
- xaccTransGetDateEnteredTS(t, &result);
- return(result);
+ Timespec result;
+ xaccTransGetDateEnteredTS(t, &result);
+ return(result);
}
Timespec
-gnc_split_get_date_reconciled(const Split *s)
+gnc_split_get_date_reconciled(const Split *s)
{
- Timespec result;
- xaccSplitGetDateReconciledTS(s, &result);
- return(result);
+ Timespec result;
+ xaccSplitGetDateReconciledTS(s, &result);
+ return(result);
}
void
-gnc_transaction_set_date_posted(Transaction *t, const Timespec d)
+gnc_transaction_set_date_posted(Transaction *t, const Timespec d)
{
- xaccTransSetDatePostedTS(t, &d);
+ xaccTransSetDatePostedTS(t, &d);
}
void
-gnc_transaction_set_date_entered(Transaction *t, const Timespec d)
+gnc_transaction_set_date_entered(Transaction *t, const Timespec d)
{
- xaccTransSetDateEnteredTS(t, &d);
+ xaccTransSetDateEnteredTS(t, &d);
}
void
gnc_transaction_set_date(Transaction *t, Timespec ts)
{
- xaccTransSetDatePostedTS(t, &ts);
+ xaccTransSetDatePostedTS(t, &ts);
}
SCM
gnc_timespec2timepair(Timespec t)
{
- SCM secs;
- SCM nsecs;
+ SCM secs;
+ SCM nsecs;
- secs = gnc_gint64_to_scm(t.tv_sec);
- nsecs = scm_long2num(t.tv_nsec);
- return(scm_cons(secs, nsecs));
+ secs = gnc_gint64_to_scm(t.tv_sec);
+ nsecs = scm_long2num(t.tv_nsec);
+ return(scm_cons(secs, nsecs));
}
Timespec
gnc_timepair2timespec(SCM x)
{
- Timespec result = {0,0};
- if (gnc_timepair_p (x))
- {
- result.tv_sec = gnc_scm_to_gint64(SCM_CAR(x));
- result.tv_nsec = scm_num2long(SCM_CDR(x), SCM_ARG1, G_STRFUNC);
- }
- return(result);
+ Timespec result = {0, 0};
+ if (gnc_timepair_p (x))
+ {
+ result.tv_sec = gnc_scm_to_gint64(SCM_CAR(x));
+ result.tv_nsec = scm_num2long(SCM_CDR(x), SCM_ARG1, G_STRFUNC);
+ }
+ return(result);
}
int
gnc_timepair_p(SCM x)
{
- return(scm_is_pair(x) &&
- gnc_gh_gint64_p(SCM_CAR(x)) &&
- gnc_gh_gint64_p(SCM_CDR(x)));
+ return(scm_is_pair(x) &&
+ gnc_gh_gint64_p(SCM_CAR(x)) &&
+ gnc_gh_gint64_p(SCM_CDR(x)));
}
SCM
gnc_guid2scm(GUID guid)
{
- char string[GUID_ENCODING_LENGTH + 1];
+ char string[GUID_ENCODING_LENGTH + 1];
- if (!guid_to_string_buff(&guid, string))
- return SCM_BOOL_F;
+ if (!guid_to_string_buff(&guid, string))
+ return SCM_BOOL_F;
- return scm_makfrom0str(string);
+ return scm_makfrom0str(string);
}
GUID
-gnc_scm2guid(SCM guid_scm)
+gnc_scm2guid(SCM guid_scm)
{
- GUID guid;
- const gchar * str;
+ GUID guid;
+ const gchar * str;
- if (GUID_ENCODING_LENGTH != scm_i_string_length (guid_scm))
- {
- return *guid_null();
- }
- str = scm_to_locale_string (guid_scm);
- string_to_guid(str, &guid);
- return guid;
+ if (GUID_ENCODING_LENGTH != scm_i_string_length (guid_scm))
+ {
+ return *guid_null();
+ }
+ str = scm_to_locale_string (guid_scm);
+ string_to_guid(str, &guid);
+ return guid;
}
int
-gnc_guid_p(SCM guid_scm)
+gnc_guid_p(SCM guid_scm)
{
- GUID guid;
- const gchar * str;
+ GUID guid;
+ const gchar * str;
- if (!scm_is_string(guid_scm))
- return FALSE;
+ if (!scm_is_string(guid_scm))
+ return FALSE;
- if (GUID_ENCODING_LENGTH != scm_i_string_length (guid_scm))
- {
- return FALSE;
- }
- str = scm_to_locale_string (guid_scm);
+ if (GUID_ENCODING_LENGTH != scm_i_string_length (guid_scm))
+ {
+ return FALSE;
+ }
+ str = scm_to_locale_string (guid_scm);
- return string_to_guid(str, &guid);
+ return string_to_guid(str, &guid);
}
/********************************************************************
- * type converters for query API
+ * type converters for query API
********************************************************************/
/* The query scm representation is a list of pairs, where the
@@ -193,9 +193,10 @@
* ('pd-balance pr-type sense-bool balance-field)
*/
-typedef enum {
- gnc_QUERY_v1 = 1,
- gnc_QUERY_v2
+typedef enum
+{
+ gnc_QUERY_v1 = 1,
+ gnc_QUERY_v2
} query_version_t;
/* QofCompareFunc */
@@ -203,323 +204,327 @@
static QofQueryCompare
gnc_query_scm2compare (SCM how_scm)
{
- return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
+ return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
}
/* QofStringMatch */
static QofStringMatch
gnc_query_scm2string (SCM how_scm)
{
- return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
+ return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
}
/* QofDateMatch */
static QofDateMatch
gnc_query_scm2date (SCM how_scm)
{
- return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
+ return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
}
/* QofNumericMatch */
static QofNumericMatch
gnc_query_scm2numericop (SCM how_scm)
{
- return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
+ return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
}
/* QofGuidMatch */
static QofGuidMatch
gnc_query_scm2guid (SCM how_scm)
{
- return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
+ return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
}
/* QofCharMatch */
static QofCharMatch
gnc_query_scm2char (SCM how_scm)
{
- return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
+ return scm_num2int(how_scm, SCM_ARG1, G_STRFUNC);
}
static QofGuidMatch
gnc_scm2acct_match_how (SCM how_scm)
{
- QofGuidMatch res;
- const gchar *how = SCM_SYMBOL_CHARS (how_scm);
+ QofGuidMatch res;
+ const gchar *how = SCM_SYMBOL_CHARS (how_scm);
- if (!safe_strcmp (how, "acct-match-all"))
- res = QOF_GUID_MATCH_ALL;
- else if (!safe_strcmp (how, "acct-match-any"))
- res = QOF_GUID_MATCH_ANY;
- else if (!safe_strcmp (how, "acct-match-none"))
- res = QOF_GUID_MATCH_NONE;
- else {
- PINFO ("invalid account match: %s", how);
- res = QOF_GUID_MATCH_NULL;
- }
- return res;
+ if (!safe_strcmp (how, "acct-match-all"))
+ res = QOF_GUID_MATCH_ALL;
+ else if (!safe_strcmp (how, "acct-match-any"))
+ res = QOF_GUID_MATCH_ANY;
+ else if (!safe_strcmp (how, "acct-match-none"))
+ res = QOF_GUID_MATCH_NONE;
+ else
+ {
+ PINFO ("invalid account match: %s", how);
+ res = QOF_GUID_MATCH_NULL;
+ }
+ return res;
}
static QofQueryCompare
gnc_scm2amt_match_how (SCM how_scm)
{
- QofQueryCompare res;
- const gchar *how = SCM_SYMBOL_CHARS (how_scm);
+ QofQueryCompare res;
+ const gchar *how = SCM_SYMBOL_CHARS (how_scm);
- if (!safe_strcmp (how, "amt-match-atleast"))
- res = QOF_COMPARE_GTE;
- else if (!safe_strcmp (how, "amt-match-atmost"))
- res = QOF_COMPARE_LTE;
- else if (!safe_strcmp (how, "amt-match-exactly"))
- res = QOF_COMPARE_EQUAL;
- else {
- PINFO ("invalid amount match: %s", how);
- res = QOF_COMPARE_EQUAL;
- }
+ if (!safe_strcmp (how, "amt-match-atleast"))
+ res = QOF_COMPARE_GTE;
+ else if (!safe_strcmp (how, "amt-match-atmost"))
+ res = QOF_COMPARE_LTE;
+ else if (!safe_strcmp (how, "amt-match-exactly"))
+ res = QOF_COMPARE_EQUAL;
+ else
+ {
+ PINFO ("invalid amount match: %s", how);
+ res = QOF_COMPARE_EQUAL;
+ }
- return res;
+ return res;
}
static QofQueryCompare
gnc_scm2kvp_match_how (SCM how_scm)
{
- QofQueryCompare res;
- const gchar *how = SCM_SYMBOL_CHARS (how_scm);
+ QofQueryCompare res;
+ const gchar *how = SCM_SYMBOL_CHARS (how_scm);
- if (!safe_strcmp (how, "kvp-match-lt"))
- res = QOF_COMPARE_LT;
- else if (!safe_strcmp (how, "kvp-match-lte"))
- res = QOF_COMPARE_LTE;
- else if (!safe_strcmp (how, "kvp-match-eq"))
- res = QOF_COMPARE_EQUAL;
- else if (!safe_strcmp (how, "kvp-match-gte"))
- res = QOF_COMPARE_GTE;
- else if (!safe_strcmp (how, "kvp-match-gt"))
- res = QOF_COMPARE_GT;
- else {
- PINFO ("invalid kvp match: %s", how);
- res = QOF_COMPARE_EQUAL;
- }
- return res;
+ if (!safe_strcmp (how, "kvp-match-lt"))
+ res = QOF_COMPARE_LT;
+ else if (!safe_strcmp (how, "kvp-match-lte"))
+ res = QOF_COMPARE_LTE;
+ else if (!safe_strcmp (how, "kvp-match-eq"))
+ res = QOF_COMPARE_EQUAL;
+ else if (!safe_strcmp (how, "kvp-match-gte"))
+ res = QOF_COMPARE_GTE;
+ else if (!safe_strcmp (how, "kvp-match-gt"))
+ res = QOF_COMPARE_GT;
+ else
+ {
+ PINFO ("invalid kvp match: %s", how);
+ res = QOF_COMPARE_EQUAL;
+ }
+ return res;
}
static int
gnc_scm2bitfield (SCM field_scm)
{
- int field = 0;
+ int field = 0;
- if (!scm_is_list (field_scm))
- return 0;
+ if (!scm_is_list (field_scm))
+ return 0;
- while (!scm_is_null (field_scm))
- {
- SCM scm;
- int bit;
+ while (!scm_is_null (field_scm))
+ {
+ SCM scm;
+ int bit;
- scm = SCM_CAR (field_scm);
- field_scm = SCM_CDR (field_scm);
+ scm = SCM_CAR (field_scm);
+ field_scm = SCM_CDR (field_scm);
- bit = scm_num2int(scm, SCM_ARG2, G_STRFUNC);
- field |= bit;
- }
+ bit = scm_num2int(scm, SCM_ARG2, G_STRFUNC);
+ field |= bit;
+ }
- return field;
+ return field;
}
static cleared_match_t
gnc_scm2cleared_match_how (SCM how_scm)
{
- return gnc_scm2bitfield (how_scm);
+ return gnc_scm2bitfield (how_scm);
}
static gboolean
gnc_scm2balance_match_how (SCM how_scm, gboolean *resp)
{
- const gchar *how;
+ const gchar *how;
- if (!scm_is_list (how_scm))
- return FALSE;
+ if (!scm_is_list (how_scm))
+ return FALSE;
- if (scm_is_null (how_scm))
- return FALSE;
+ if (scm_is_null (how_scm))
+ return FALSE;
- /* Only allow a single-entry list */
- if (!scm_is_null (SCM_CDR (how_scm)))
- return FALSE;
+ /* Only allow a single-entry list */
+ if (!scm_is_null (SCM_CDR (how_scm)))
+ return FALSE;
- how = SCM_SYMBOL_CHARS (SCM_CAR(how_scm));
+ how = SCM_SYMBOL_CHARS (SCM_CAR(how_scm));
- if (!safe_strcmp (how, "balance-match-balanced"))
- *resp = TRUE;
- else
- *resp = FALSE;
+ if (!safe_strcmp (how, "balance-match-balanced"))
+ *resp = TRUE;
+ else
+ *resp = FALSE;
- return TRUE;
+ return TRUE;
}
static QofIdType
gnc_scm2kvp_match_where (SCM where_scm)
{
- QofIdType res;
- const gchar *where;
+ QofIdType res;
+ const gchar *where;
- if (!scm_is_list (where_scm))
- return NULL;
+ if (!scm_is_list (where_scm))
+ return NULL;
- where = SCM_SYMBOL_CHARS (SCM_CAR(where_scm));
+ where = SCM_SYMBOL_CHARS (SCM_CAR(where_scm));
- if (!safe_strcmp (where, "kvp-match-split"))
- res = GNC_ID_SPLIT;
- else if (!safe_strcmp (where, "kvp-match-trans"))
- res = GNC_ID_TRANS;
- else if (!safe_strcmp (where, "kvp-match-account"))
- res = GNC_ID_ACCOUNT;
- else {
- PINFO ("Unknown kvp-match-where: %s", where);
- res = NULL;
- }
- return res;
+ if (!safe_strcmp (where, "kvp-match-split"))
+ res = GNC_ID_SPLIT;
+ else if (!safe_strcmp (where, "kvp-match-trans"))
+ res = GNC_ID_TRANS;
+ else if (!safe_strcmp (where, "kvp-match-account"))
+ res = GNC_ID_ACCOUNT;
+ else
+ {
+ PINFO ("Unknown kvp-match-where: %s", where);
+ res = NULL;
+ }
+ return res;
}
static SCM
gnc_guid_glist2scm (const GList *account_guids)
{
- SCM guids = SCM_EOL;
- const GList *node;
+ SCM guids = SCM_EOL;
+ const GList *node;
- for (node = account_guids; node; node = node->next)
- {
- GUID *guid = node->data;
+ for (node = account_guids; node; node = node->next)
+ {
+ GUID *guid = node->data;
- if (guid)
- guids = scm_cons (gnc_guid2scm (*guid), guids);
- }
+ if (guid)
+ guids = scm_cons (gnc_guid2scm (*guid), guids);
+ }
- return scm_reverse (guids);
+ return scm_reverse (guids);
}
static GList *
gnc_scm2guid_glist (SCM guids_scm)
{
- GList *guids = NULL;
+ GList *guids = NULL;
- if (!scm_is_list (guids_scm))
- return NULL;
+ if (!scm_is_list (guids_scm))
+ return NULL;
- while (!scm_is_null (guids_scm))
- {
- SCM guid_scm = SCM_CAR (guids_scm);
- GUID *guid = NULL;
-
- if (guid_scm != SCM_BOOL_F)
+ while (!scm_is_null (guids_scm))
{
- guid = guid_malloc ();
- *guid = gnc_scm2guid (guid_scm);
- }
+ SCM guid_scm = SCM_CAR (guids_scm);
+ GUID *guid = NULL;
- guids = g_list_prepend (guids, guid);
+ if (guid_scm != SCM_BOOL_F)
+ {
+ guid = guid_malloc ();
+ *guid = gnc_scm2guid (guid_scm);
+ }
- guids_scm = SCM_CDR (guids_scm);
- }
+ guids = g_list_prepend (guids, guid);
- return g_list_reverse (guids);
+ guids_scm = SCM_CDR (guids_scm);
+ }
+
+ return g_list_reverse (guids);
}
static void
gnc_guid_glist_free (GList *guids)
{
- GList *node;
+ GList *node;
- for (node = guids; node; node = node->next)
- guid_free (node->data);
+ for (node = guids; node; node = node->next)
+ guid_free (node->data);
- g_list_free (guids);
+ g_list_free (guids);
}
static SCM
gnc_query_numeric2scm (gnc_numeric val)
{
- return scm_cons (gnc_gint64_to_scm (val.num),
- gnc_gint64_to_scm (val.denom));
+ return scm_cons (gnc_gint64_to_scm (val.num),
+ gnc_gint64_to_scm (val.denom));
}
static gboolean
gnc_query_numeric_p (SCM pair)
{
- return (scm_is_pair (pair));
+ return (scm_is_pair (pair));
}
static gnc_numeric
gnc_query_scm2numeric (SCM pair)
{
- SCM denom;
- SCM num;
+ SCM denom;
+ SCM num;
- num = SCM_CAR (pair);
- denom = SCM_CDR (pair);
+ num = SCM_CAR (pair);
+ denom = SCM_CDR (pair);
- return gnc_numeric_create (gnc_scm_to_gint64 (num),
- gnc_scm_to_gint64 (denom));
+ return gnc_numeric_create (gnc_scm_to_gint64 (num),
+ gnc_scm_to_gint64 (denom));
}
static SCM
gnc_query_path2scm (const GSList *path)
{
- SCM path_scm = SCM_EOL;
- const GSList *node;
+ SCM path_scm = SCM_EOL;
+ const GSList *node;
- for (node = path; node; node = node->next)
- {
- const char *key = node->data;
+ for (node = path; node; node = node->next)
+ {
+ const char *key = node->data;
- if (key)
- path_scm = scm_cons (scm_makfrom0str (key), path_scm);
- }
+ if (key)
+ path_scm = scm_cons (scm_makfrom0str (key), path_scm);
+ }
- return scm_reverse (path_scm);
+ return scm_reverse (path_scm);
}
GSList *
gnc_query_scm2path (SCM path_scm)
{
- GSList *path = NULL;
+ GSList *path = NULL;
- if (!scm_is_list (path_scm))
- return NULL;
+ if (!scm_is_list (path_scm))
+ return NULL;
- while (!scm_is_null (path_scm))
- {
- SCM key_scm = SCM_CAR (path_scm);
- char *key;
+ while (!scm_is_null (path_scm))
+ {
+ SCM key_scm = SCM_CAR (path_scm);
+ char *key;
- if (!scm_is_string (key_scm))
- break;
+ if (!scm_is_string (key_scm))
+ break;
- key = g_strdup (scm_to_locale_string (key_scm));
+ key = g_strdup (scm_to_locale_string (key_scm));
- path = g_slist_prepend (path, key);
+ path = g_slist_prepend (path, key);
- path_scm = SCM_CDR (path_scm);
- }
+ path_scm = SCM_CDR (path_scm);
+ }
- return g_slist_reverse (path);
+ return g_slist_reverse (path);
}
static void
gnc_query_path_free (GSList *path)
{
- GSList *node;
+ GSList *node;
- for (node = path; node; node = node->next)
- g_free (node->data);
+ for (node = path; node; node = node->next)
+ g_free (node->data);
- g_slist_free (path);
+ g_slist_free (path);
}
static KvpValueType
gnc_scm2KvpValueTypeype (SCM value_type_scm)
{
- return scm_num2int(value_type_scm, SCM_ARG1, G_STRFUNC);
+ return scm_num2int(value_type_scm, SCM_ARG1, G_STRFUNC);
}
static SCM gnc_kvp_frame2scm (KvpFrame *frame);
@@ -527,104 +532,106 @@
static SCM
gnc_kvp_value2scm (const KvpValue *value)
{
- SCM value_scm = SCM_EOL;
- KvpValueType value_t;
- SCM scm;
+ SCM value_scm = SCM_EOL;
+ KvpValueType value_t;
+ SCM scm;
- if (!value) return SCM_BOOL_F;
+ if (!value) return SCM_BOOL_F;
- value_t = kvp_value_get_type (value);
+ value_t = kvp_value_get_type (value);
- value_scm = scm_cons (scm_long2num (value_t), value_scm);
+ value_scm = scm_cons (scm_long2num (value_t), value_scm);
- switch (value_t)
- {
+ switch (value_t)
+ {
case KVP_TYPE_GINT64:
- scm = gnc_gint64_to_scm (kvp_value_get_gint64 (value));
- break;
+ scm = gnc_gint64_to_scm (kvp_value_get_gint64 (value));
+ break;
case KVP_TYPE_DOUBLE:
- scm = scm_make_real (kvp_value_get_double (value));
- break;
+ scm = scm_make_real (kvp_value_get_double (value));
+ break;
case KVP_TYPE_STRING:
- scm = scm_makfrom0str (kvp_value_get_string (value));
- break;
+ scm = scm_makfrom0str (kvp_value_get_string (value));
+ break;
case KVP_TYPE_GUID:
- scm = gnc_guid2scm (*kvp_value_get_guid (value));
- break;
+ scm = gnc_guid2scm (*kvp_value_get_guid (value));
+ break;
case KVP_TYPE_TIMESPEC:
- scm = gnc_timespec2timepair (kvp_value_get_timespec (value));
- break;
+ scm = gnc_timespec2timepair (kvp_value_get_timespec (value));
+ break;
case KVP_TYPE_BINARY:
- scm = SCM_BOOL_F;
- break;
+ scm = SCM_BOOL_F;
+ break;
- case KVP_TYPE_NUMERIC: {
- gnc_numeric n = kvp_value_get_numeric (value);
- scm = gnc_query_numeric2scm (n);
- break;
+ case KVP_TYPE_NUMERIC:
+ {
+ gnc_numeric n = kvp_value_get_numeric (value);
+ scm = gnc_query_numeric2scm (n);
+ break;
}
- case KVP_TYPE_GLIST: {
- GList *node;
+ case KVP_TYPE_GLIST:
+ {
+ GList *node;
- scm = SCM_EOL;
- for (node = kvp_value_get_glist (value); node; node = node->next)
- scm = scm_cons (gnc_kvp_value2scm (node->data), scm);
- scm = scm_reverse (scm);
- break;
+ scm = SCM_EOL;
+ for (node = kvp_value_get_glist (value); node; node = node->next)
+ scm = scm_cons (gnc_kvp_value2scm (node->data), scm);
+ scm = scm_reverse (scm);
+ break;
}
case KVP_TYPE_FRAME:
- scm = gnc_kvp_frame2scm (kvp_value_get_frame (value));
- break;
+ scm = gnc_kvp_frame2scm (kvp_value_get_frame (value));
+ break;
default:
- scm = SCM_BOOL_F;
- break;
- }
+ scm = SCM_BOOL_F;
+ break;
+ }
- value_scm = scm_cons (scm, value_scm);
+ value_scm = scm_cons (scm, value_scm);
- return scm_reverse (value_scm);
+ return scm_reverse (value_scm);
}
typedef struct
{
- SCM scm;
+ SCM scm;
} KVPSCMData;
static void
kvp_frame_slot2scm (const char *key, KvpValue *value, gpointer data)
{
- KVPSCMData *ksd = data;
- SCM value_scm;
- SCM key_scm;
- SCM pair;
+ KVPSCMData *ksd = data;
+ SCM value_scm;
+ SCM key_scm;
+ SCM pair;
- key_scm = scm_makfrom0str (key);
- value_scm = gnc_kvp_value2scm (value);
- pair = scm_cons (key_scm, value_scm);
+ key_scm = scm_makfrom0str (key);
+ value_scm = gnc_kvp_value2scm (value);
+ pair = scm_cons (key_scm, value_scm);
- ksd->scm = scm_cons (pair, ksd->scm);
+ ksd->scm = scm_cons (pair, ksd->scm);
}
static SCM
gnc_kvp_frame2scm (KvpFrame *frame)
{
- KVPSCMData ksd;
+ KVPSCMData ksd;
- if (!frame) return SCM_BOOL_F;
+ if (!frame) return SCM_BOOL_F;
- ksd.scm = SCM_EOL;
+ ksd.scm = SCM_EOL;
- kvp_frame_for_each_slot (frame, kvp_frame_slot2scm, &ksd);
+ kvp_frame_for_each_slot (frame, kvp_frame_slot2scm, &ksd);
- return ksd.scm;
+ return ksd.scm;
}
static KvpFrame * gnc_scm2KvpFrame (SCM frame_scm);
@@ -632,1524 +639,1707 @@
static KvpValue *
gnc_scm2KvpValue (SCM value_scm)
{
- KvpValueType value_t;
- KvpValue *value;
- SCM type_scm;
- SCM val_scm;
+ KvpValueType value_t;
+ KvpValue *value;
+ SCM type_scm;
+ SCM val_scm;
- if (!scm_is_list (value_scm) || scm_is_null (value_scm))
- return NULL;
+ if (!scm_is_list (value_scm) || scm_is_null (value_scm))
+ return NULL;
- type_scm = SCM_CAR (value_scm);
- value_t = gnc_scm2KvpValueTypeype (type_scm);
+ type_scm = SCM_CAR (value_scm);
+ value_t = gnc_scm2KvpValueTypeype (type_scm);
- value_scm = SCM_CDR (value_scm);
- if (!scm_is_list (value_scm) || scm_is_null (value_scm))
- return NULL;
+ value_scm = SCM_CDR (value_scm);
+ if (!scm_is_list (value_scm) || scm_is_null (value_scm))
+ return NULL;
- val_scm = SCM_CAR (value_scm);
+ val_scm = SCM_CAR (value_scm);
- switch (value_t)
- {
+ switch (value_t)
+ {
case KVP_TYPE_GINT64:
- value = kvp_value_new_gint64 (gnc_scm_to_gint64 (val_scm));
- break;
+ value = kvp_value_new_gint64 (gnc_scm_to_gint64 (val_scm));
+ break;
case KVP_TYPE_DOUBLE:
- value = kvp_value_new_double (scm_num2dbl (val_scm, G_STRFUNC));
- break;
+ value = kvp_value_new_double (scm_num2dbl (val_scm, G_STRFUNC));
+ break;
- case KVP_TYPE_STRING: {
- const gchar * str = scm_to_locale_string (val_scm);
- value = kvp_value_new_string (str);
- break;
+ case KVP_TYPE_STRING:
+ {
+ const gchar * str = scm_to_locale_string (val_scm);
+ value = kvp_value_new_string (str);
+ break;
}
- case KVP_TYPE_GUID: {
- if (val_scm != SCM_BOOL_F)
- {
- GUID guid = gnc_scm2guid (val_scm);
- value = kvp_value_new_guid (&guid);
- }
- else
- value = NULL;
- break;
+ case KVP_TYPE_GUID:
+ {
+ if (val_scm != SCM_BOOL_F)
+ {
+ GUID guid = gnc_scm2guid (val_scm);
+ value = kvp_value_new_guid (&guid);
+ }
+ else
+ value = NULL;
+ break;
}
- case KVP_TYPE_TIMESPEC: {
- Timespec ts = gnc_timepair2timespec (val_scm);
- value = kvp_value_new_timespec(ts);
- break;
+ case KVP_TYPE_TIMESPEC:
+ {
+ Timespec ts = gnc_timepair2timespec (val_scm);
+ value = kvp_value_new_timespec(ts);
+ break;
}
case KVP_TYPE_BINARY:
- return NULL;
- break;
+ return NULL;
+ break;
- case KVP_TYPE_NUMERIC: {
- gnc_numeric n;
+ case KVP_TYPE_NUMERIC:
+ {
+ gnc_numeric n;
- if (!gnc_query_numeric_p (val_scm))
- return NULL;
+ if (!gnc_query_numeric_p (val_scm))
+ return NULL;
- n = gnc_query_scm2numeric (val_scm);
+ n = gnc_query_scm2numeric (val_scm);
- value = kvp_value_new_gnc_numeric (n);
- break;
+ value = kvp_value_new_gnc_numeric (n);
+ break;
}
- case KVP_TYPE_GLIST: {
- GList *list = NULL;
- GList *node;
+ case KVP_TYPE_GLIST:
+ {
+ GList *list = NULL;
+ GList *node;
- for (; scm_is_list (val_scm) && !scm_is_null (val_scm);
- val_scm = SCM_CDR (val_scm))
- {
- SCM scm = SCM_CAR (val_scm);
+ for (; scm_is_list (val_scm) && !scm_is_null (val_scm);
+ val_scm = SCM_CDR (val_scm))
+ {
+ SCM scm = SCM_CAR (val_scm);
- list = g_list_prepend (list, gnc_scm2KvpValue (scm));
- }
+ list = g_list_prepend (list, gnc_scm2KvpValue (scm));
+ }
- list = g_list_reverse (list);
+ list = g_list_reverse (list);
- value = kvp_value_new_glist (list);
+ value = kvp_value_new_glist (list);
- for (node = list; node; node = node->next)
- kvp_value_delete (node->data);
- g_list_free (list);
- break;
+ for (node = list; node; node = node->next)
+ kvp_value_delete (node->data);
+ g_list_free (list);
+ break;
}
- case KVP_TYPE_FRAME: {
- KvpFrame *frame;
+ case KVP_TYPE_FRAME:
+ {
+ KvpFrame *frame;
- frame = gnc_scm2KvpFrame (val_scm);
- value = kvp_value_new_frame (frame);
- kvp_frame_delete (frame);
- break;
+ frame = gnc_scm2KvpFrame (val_scm);
+ value = kvp_value_new_frame (frame);
+ kvp_frame_delete (frame);
+ break;
}
default:
- PWARN ("unexpected type: %d", value_t);
- return NULL;
- }
+ PWARN ("unexpected type: %d", value_t);
+ return NULL;
+ }
- return value;
+ return value;
}
static KvpFrame *
gnc_scm2KvpFrame (SCM frame_scm)
{
- KvpFrame * frame;
+ KvpFrame * frame;
- if (!scm_is_list (frame_scm)) return NULL;
+ if (!scm_is_list (frame_scm)) return NULL;
- frame = kvp_frame_new ();
+ frame = kvp_frame_new ();
- for (; scm_is_list (frame_scm) && !scm_is_null (frame_scm);
- frame_scm = SCM_CDR (frame_scm))
- {
- SCM pair = SCM_CAR (frame_scm);
- KvpValue *value;
- SCM key_scm;
- SCM val_scm;
- const gchar *key;
+ for (; scm_is_list (frame_scm) && !scm_is_null (frame_scm);
+ frame_scm = SCM_CDR (frame_scm))
+ {
+ SCM pair = SCM_CAR (frame_scm);
+ KvpValue *value;
+ SCM key_scm;
+ SCM val_scm;
+ const gchar *key;
- if (!scm_is_pair (pair))
- continue;
+ if (!scm_is_pair (pair))
+ continue;
- key_scm = SCM_CAR (pair);
- val_scm = SCM_CDR (pair);
+ key_scm = SCM_CAR (pair);
+ val_scm = SCM_CDR (pair);
- if (!scm_is_string (key_scm))
- continue;
+ if (!scm_is_string (key_scm))
+ continue;
- key = scm_to_locale_string (key_scm);
- if (!key)
- continue;
+ key = scm_to_locale_string (key_scm);
+ if (!key)
+ continue;
- value = gnc_scm2KvpValue (val_scm);
- if (!value) continue;
+ value = gnc_scm2KvpValue (val_scm);
+ if (!value) continue;
- kvp_frame_set_slot_nc (frame, key, value);
- }
+ kvp_frame_set_slot_nc (frame, key, value);
+ }
- return frame;
+ return frame;
}
static SCM
gnc_queryterm2scm (const QofQueryTerm *qt)
{
- SCM qt_scm = SCM_EOL;
- QofQueryPredData *pd = NULL;
+ SCM qt_scm = SCM_EOL;
+ QofQueryPredData *pd = NULL;
- qt_scm = scm_cons (gnc_query_path2scm (qof_query_term_get_param_path (qt)),
- qt_scm);
- qt_scm = scm_cons (SCM_BOOL (qof_query_term_is_inverted (qt)), qt_scm);
+ qt_scm = scm_cons (gnc_query_path2scm (qof_query_term_get_param_path (qt)),
+ qt_scm);
+ qt_scm = scm_cons (SCM_BOOL (qof_query_term_is_inverted (qt)), qt_scm);
- pd = qof_query_term_get_pred_data (qt);
- qt_scm = scm_cons (scm_str2symbol (pd->type_name), qt_scm);
- qt_scm = scm_cons (scm_long2num (pd->how), qt_scm);
+ pd = qof_query_term_get_pred_data (qt);
+ qt_scm = scm_cons (scm_str2symbol (pd->type_name), qt_scm);
+ qt_scm = scm_cons (scm_long2num (pd->how), qt_scm);
- if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING)) {
- query_string_t pdata = (query_string_t) pd;
+ if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING))
+ {
+ query_string_t pdata = (query_string_t) pd;
- qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
- qt_scm = scm_cons (SCM_BOOL (pdata->is_regex), qt_scm);
- qt_scm = scm_cons (scm_makfrom0str (pdata->matchstring), qt_scm);
+ qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
+ qt_scm = scm_cons (SCM_BOOL (pdata->is_regex), qt_scm);
+ qt_scm = scm_cons (scm_makfrom0str (pdata->matchstring), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_DATE)) {
- query_date_t pdata = (query_date_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_DATE))
+ {
+ query_date_t pdata = (query_date_t) pd;
- qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
- qt_scm = scm_cons (gnc_timespec2timepair (pdata->date), qt_scm);
+ qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
+ qt_scm = scm_cons (gnc_timespec2timepair (pdata->date), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_NUMERIC)) {
- query_numeric_t pdata = (query_numeric_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_NUMERIC))
+ {
+ query_numeric_t pdata = (query_numeric_t) pd;
- qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
- qt_scm = scm_cons (gnc_query_numeric2scm (pdata->amount), qt_scm);
+ qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
+ qt_scm = scm_cons (gnc_query_numeric2scm (pdata->amount), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_GUID)) {
- query_guid_t pdata = (query_guid_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_GUID))
+ {
+ query_guid_t pdata = (query_guid_t) pd;
- qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
- qt_scm = scm_cons (gnc_guid_glist2scm (pdata->guids), qt_scm);
+ qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
+ qt_scm = scm_cons (gnc_guid_glist2scm (pdata->guids), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_INT64)) {
- query_int64_t pdata = (query_int64_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_INT64))
+ {
+ query_int64_t pdata = (query_int64_t) pd;
- qt_scm = scm_cons (gnc_gint64_to_scm (pdata->val), qt_scm);
+ qt_scm = scm_cons (gnc_gint64_to_scm (pdata->val), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_DOUBLE)) {
- query_double_t pdata = (query_double_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_DOUBLE))
+ {
+ query_double_t pdata = (query_double_t) pd;
- qt_scm = scm_cons (scm_make_real (pdata->val), qt_scm);
+ qt_scm = scm_cons (scm_make_real (pdata->val), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_BOOLEAN)) {
- query_boolean_t pdata = (query_boolean_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_BOOLEAN))
+ {
+ query_boolean_t pdata = (query_boolean_t) pd;
- qt_scm = scm_cons (SCM_BOOL (pdata->val), qt_scm);
+ qt_scm = scm_cons (SCM_BOOL (pdata->val), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_CHAR)) {
- query_char_t pdata = (query_char_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_CHAR))
+ {
+ query_char_t pdata = (query_char_t) pd;
- qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
- qt_scm = scm_cons (scm_makfrom0str (pdata->char_list), qt_scm);
+ qt_scm = scm_cons (scm_long2num (pdata->options), qt_scm);
+ qt_scm = scm_cons (scm_makfrom0str (pdata->char_list), qt_scm);
- } else if (!safe_strcmp (pd->type_name, QOF_TYPE_KVP)) {
- query_kvp_t pdata = (query_kvp_t) pd;
+ }
+ else if (!safe_strcmp (pd->type_name, QOF_TYPE_KVP))
+ {
+ query_kvp_t pdata = (query_kvp_t) pd;
- qt_scm = scm_cons (gnc_query_path2scm (pdata->path), qt_scm);
- qt_scm = scm_cons (gnc_kvp_value2scm (pdata->value), qt_scm);
+ qt_scm = scm_cons (gnc_query_path2scm (pdata->path), qt_scm);
+ qt_scm = scm_cons (gnc_kvp_value2scm (pdata->value), qt_scm);
- } else {
- PWARN ("query core type %s not supported", pd->type_name);
- return SCM_BOOL_F;
- }
+ }
+ else
+ {
+ PWARN ("query core type %s not supported", pd->type_name);
+ return SCM_BOOL_F;
+ }
- return scm_reverse (qt_scm);
+ return scm_reverse (qt_scm);
}
static QofQuery *
gnc_scm2query_term_query_v2 (SCM qt_scm)
{
- QofQuery *q = NULL;
- QofQueryPredData *pd = NULL;
- SCM scm;
- const gchar *type = NULL;
- GSList *path = NULL;
- gboolean inverted = FALSE;
- QofQueryCompare compare_how;
+ QofQuery *q = NULL;
+ QofQueryPredData *pd = NULL;
+ SCM scm;
+ const gchar *type = NULL;
+ GSList *path = NULL;
+ gboolean inverted = FALSE;
+ QofQueryCompare compare_how;
- if (!scm_is_list (qt_scm) || scm_is_null (qt_scm))
- return NULL;
+ if (!scm_is_list (qt_scm) || scm_is_null (qt_scm))
+ return NULL;
- do {
- /* param path */
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_list (scm))
- break;
- path = gnc_query_scm2path (scm);
+ do
+ {
+ /* param path */
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_list (scm))
+ break;
+ path = gnc_query_scm2path (scm);
- /* inverted */
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_bool (scm))
- break;
- inverted = scm_is_true (scm);
+ /* inverted */
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_bool (scm))
+ break;
+ inverted = scm_is_true (scm);
- /* type */
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_symbol (scm))
- break;
- type = SCM_SYMBOL_CHARS (scm);
+ /* type */
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_symbol (scm))
+ break;
+ type = SCM_SYMBOL_CHARS (scm);
- /* QofCompareFunc */
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm))
- break;
- compare_how = gnc_query_scm2compare (scm);
+ /* QofCompareFunc */
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ break;
+ compare_how = gnc_query_scm2compare (scm);
- /* Now compute the predicate */
+ /* Now compute the predicate */
- if (!safe_strcmp (type, QOF_TYPE_STRING))
- {
- QofStringMatch options;
- gboolean is_regex;
- const gchar *matchstring;
+ if (!safe_strcmp (type, QOF_TYPE_STRING))
+ {
+ QofStringMatch options;
+ gboolean is_regex;
+ const gchar *matchstring;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm)) break;
- options = gnc_query_scm2string (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm)) break;
+ options = gnc_query_scm2string (scm);
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_bool (scm)) break;
- is_regex = scm_is_true (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_bool (scm)) break;
+ is_regex = scm_is_true (scm);
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_string (scm)) break;
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_string (scm)) break;
- matchstring = scm_to_locale_string (scm);
+ matchstring = scm_to_locale_string (scm);
- pd = qof_query_string_predicate (compare_how, matchstring,
- options, is_regex);
- }
- else if (!safe_strcmp (type, QOF_TYPE_DATE))
- {
- QofDateMatch options;
- Timespec date;
+ pd = qof_query_string_predicate (compare_how, matchstring,
+ options, is_regex);
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_DATE))
+ {
+ QofDateMatch options;
+ Timespec date;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm))
- break;
- options = gnc_query_scm2date (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ break;
+ options = gnc_query_scm2date (scm);
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm))
- break;
- date = gnc_timepair2timespec (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ break;
+ date = gnc_timepair2timespec (scm);
- pd = qof_query_date_predicate (compare_how, options, date);
+ pd = qof_query_date_predicate (compare_how, options, date);
- } else if (!safe_strcmp (type, QOF_TYPE_NUMERIC)) {
- QofNumericMatch options;
- gnc_numeric val;
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_NUMERIC))
+ {
+ QofNumericMatch options;
+ gnc_numeric val;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm))
- break;
- options = gnc_query_scm2numericop (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ break;
+ options = gnc_query_scm2numericop (scm);
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!gnc_query_numeric_p (scm))
- break;
- val = gnc_query_scm2numeric (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!gnc_query_numeric_p (scm))
+ break;
+ val = gnc_query_scm2numeric (scm);
- pd = qof_query_numeric_predicate (compare_how, options, val);
+ pd = qof_query_numeric_predicate (compare_how, options, val);
- } else if (!safe_strcmp (type, QOF_TYPE_GUID)) {
- QofGuidMatch options;
- GList *guids;
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_GUID))
+ {
+ QofGuidMatch options;
+ GList *guids;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm))
- break;
- options = gnc_query_scm2guid (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ break;
+ options = gnc_query_scm2guid (scm);
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_list (scm))
- break;
- guids = gnc_scm2guid_glist (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_list (scm))
+ break;
+ guids = gnc_scm2guid_glist (scm);
- pd = qof_query_guid_predicate (options, guids);
+ pd = qof_query_guid_predicate (options, guids);
- gnc_guid_glist_free (guids);
+ gnc_guid_glist_free (guids);
- } else if (!safe_strcmp (type, QOF_TYPE_INT64)) {
- gint64 val;
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_INT64))
+ {
+ gint64 val;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm))
- break;
- val = gnc_scm_to_gint64 (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ break;
+ val = gnc_scm_to_gint64 (scm);
- pd = qof_query_int64_predicate (compare_how, val);
+ pd = qof_query_int64_predicate (compare_how, val);
- } else if (!safe_strcmp (type, QOF_TYPE_DOUBLE)) {
- double val;
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_DOUBLE))
+ {
+ double val;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_number (scm))
- break;
- val = scm_num2dbl (scm, G_STRFUNC);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_number (scm))
+ break;
+ val = scm_num2dbl (scm, G_STRFUNC);
- pd = qof_query_double_predicate (compare_how, val);
+ pd = qof_query_double_predicate (compare_how, val);
- } else if (!safe_strcmp (type, QOF_TYPE_BOOLEAN)) {
- gboolean val;
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_BOOLEAN))
+ {
+ gboolean val;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_bool (scm))
- break;
- val = scm_is_true (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_bool (scm))
+ break;
+ val = scm_is_true (scm);
- pd = qof_query_boolean_predicate (compare_how, val);
+ pd = qof_query_boolean_predicate (compare_how, val);
- } else if (!safe_strcmp (type, QOF_TYPE_CHAR)) {
- QofCharMatch options;
- const gchar *char_list;
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_CHAR))
+ {
+ QofCharMatch options;
+ const gchar *char_list;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm))
- break;
- options = gnc_query_scm2char (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ break;
+ options = gnc_query_scm2char (scm);
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_string (scm))
- break;
- char_list = scm_to_locale_string (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_string (scm))
+ break;
+ char_list = scm_to_locale_string (scm);
- pd = qof_query_char_predicate (options, char_list);
- }
- else if (!safe_strcmp (type, QOF_TYPE_KVP))
- {
- GSList *kvp_path;
- KvpValue *value;
+ pd = qof_query_char_predicate (options, char_list);
+ }
+ else if (!safe_strcmp (type, QOF_TYPE_KVP))
+ {
+ GSList *kvp_path;
+ KvpValue *value;
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (!scm_is_list (scm))
- break;
- kvp_path = gnc_query_scm2path (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (!scm_is_list (scm))
+ break;
+ kvp_path = gnc_query_scm2path (scm);
- scm = SCM_CAR (qt_scm);
- qt_scm = SCM_CDR (qt_scm);
- if (scm_is_null (scm)) {
- gnc_query_path_free (kvp_path);
- break;
- }
- value = gnc_scm2KvpValue (scm);
+ scm = SCM_CAR (qt_scm);
+ qt_scm = SCM_CDR (qt_scm);
+ if (scm_is_null (scm))
+ {
+ gnc_query_path_free (kvp_path);
+ break;
+ }
+ value = gnc_scm2KvpValue (scm);
- pd = qof_query_kvp_predicate (compare_how, kvp_path, value);
- gnc_query_path_free (kvp_path);
- kvp_value_delete (value);
-
- } else {
- PWARN ("query core type %s not supported", type);
- break;
- }
+ pd = qof_query_kvp_predicate (compare_how, kvp_path, value);
+ gnc_query_path_free (kvp_path);
+ kvp_value_delete (value);
- } while (FALSE);
+ }
+ else
+ {
+ PWARN ("query core type %s not supported", type);
+ break;
+ }
- if (pd) {
- q = qof_query_create ();
- qof_query_add_term (q, path, pd, QOF_QUERY_OR);
- if (inverted) {
- Query *outq = qof_query_invert (q);
- qof_query_destroy (q);
- q = outq;
}
- } else {
- gnc_query_path_free (path);
- }
+ while (FALSE);
- return q;
+ if (pd)
+ {
+ q = qof_query_create ();
+ qof_query_add_term (q, path, pd, QOF_QUERY_OR);
+ if (inverted)
+ {
+ Query *outq = qof_query_invert (q);
+ qof_query_destroy (q);
+ q = outq;
+ }
+ }
+ else
+ {
+ gnc_query_path_free (path);
+ }
+
+ return q;
}
static QofQuery *
gnc_scm2query_term_query_v1 (SCM query_term_scm)
{
- gboolean ok = FALSE;
- const gchar * pd_type = NULL;
- const gchar * pr_type = NULL;
- gboolean sense = FALSE;
- QofQuery *q = NULL;
- SCM scm;
+ gboolean ok = FALSE;
+ const gchar * pd_type = NULL;
+ const gchar * pr_type = NULL;
+ gboolean sense = FALSE;
+ QofQuery *q = NULL;
+ SCM scm;
- if (!scm_is_list (query_term_scm) ||
- scm_is_null (query_term_scm)) {
- PINFO ("null term");
- return NULL;
- }
+ if (!scm_is_list (query_term_scm) ||
+ scm_is_null (query_term_scm))
+ {
+ PINFO ("null term");
+ return NULL;
+ }
- do {
- /* pd_type */
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- pd_type = SCM_SYMBOL_CHARS (scm);
+ do
+ {
+ /* pd_type */
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ pd_type = SCM_SYMBOL_CHARS (scm);
- /* pr_type */
- if (scm_is_null (query_term_scm)) {
- PINFO ("null pr_type");
- break;
- }
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- pr_type = SCM_SYMBOL_CHARS (scm);
+ /* pr_type */
+ if (scm_is_null (query_term_scm))
+ {
+ PINFO ("null pr_type");
+ break;
+ }
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ pr_type = SCM_SYMBOL_CHARS (scm);
- /* sense */
- if (scm_is_null (query_term_scm)) {
- PINFO ("null sense");
- break;
- }
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- sense = scm_is_true (scm);
+ /* sense */
+ if (scm_is_null (query_term_scm))
+ {
+ PINFO ("null sense");
+ break;
+ }
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ sense = scm_is_true (scm);
- q = xaccMallocQuery ();
+ q = xaccMallocQuery ();
- if (!safe_strcmp (pd_type, "pd-date")) {
- gboolean use_start;
- gboolean use_end;
- Timespec start;
- Timespec end;
+ if (!safe_strcmp (pd_type, "pd-date"))
+ {
+ gboolean use_start;
+ gboolean use_end;
+ Timespec start;
+ Timespec end;
- /* use_start */
- if (scm_is_null (query_term_scm)) {
- PINFO ("null use_start");
- break;
- }
+ /* use_start */
+ if (scm_is_null (query_term_scm))
+ {
+ PINFO ("null use_start");
+ break;
+ }
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- use_start = scm_is_true (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ use_start = scm_is_true (scm);
- /* start */
- if (scm_is_null (query_term_scm))
- break;
+ /* start */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- start = gnc_timepair2timespec (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ start = gnc_timepair2timespec (scm);
- /* use_end */
- if (scm_is_null (query_term_scm))
- break;
+ /* use_end */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- use_end = scm_is_true (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ use_end = scm_is_true (scm);
- /* end */
- if (scm_is_null (query_term_scm))
- break;
+ /* end */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- end = gnc_timepair2timespec (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ end = gnc_timepair2timespec (scm);
- xaccQueryAddDateMatchTS (q, use_start, start, use_end, end, QOF_QUERY_OR);
+ xaccQueryAddDateMatchTS (q, use_start, start, use_end, end, QOF_QUERY_OR);
- ok = TRUE;
+ ok = TRUE;
- }
- else if (!safe_strcmp (pd_type, "pd-amount"))
- {
- QofQueryCompare how;
- QofNumericMatch amt_sgn;
- double amount;
- gnc_numeric val;
+ }
+ else if (!safe_strcmp (pd_type, "pd-amount"))
+ {
+ QofQueryCompare how;
+ QofNumericMatch amt_sgn;
+ double amount;
+ gnc_numeric val;
- /* how */
- if (scm_is_null (query_term_scm))
- break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- how = gnc_scm2amt_match_how (scm);
+ /* how */
+ if (scm_is_null (query_term_scm))
+ break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ how = gnc_scm2amt_match_how (scm);
- /* amt_sgn */
- if (scm_is_null (query_term_scm))
- break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- amt_sgn = gnc_query_scm2numericop (scm);
+ /* amt_sgn */
+ if (scm_is_null (query_term_scm))
+ break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ amt_sgn = gnc_query_scm2numericop (scm);
- /* amount */
- if (scm_is_null (query_term_scm))
- break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- amount = scm_num2dbl (scm, G_STRFUNC);
+ /* amount */
+ if (scm_is_null (query_term_scm))
+ break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ amount = scm_num2dbl (scm, G_STRFUNC);
- val = double_to_gnc_numeric (amount, GNC_DENOM_AUTO,
- GNC_HOW_DENOM_SIGFIGS(6) | GNC_HOW_RND_ROUND);
+ val = double_to_gnc_numeric (amount, GNC_DENOM_AUTO,
+ GNC_HOW_DENOM_SIGFIGS(6) | GNC_HOW_RND_ROUND);
- if (!safe_strcmp (pr_type, "pr-price")) {
- xaccQueryAddSharePriceMatch (q, val, how, QOF_QUERY_OR);
- ok = TRUE;
+ if (!safe_strcmp (pr_type, "pr-price"))
+ {
+ xaccQueryAddSharePriceMatch (q, val, how, QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pr_type, "pr-shares")) {
- xaccQueryAddSharesMatch (q, val, how, QOF_QUERY_OR);
- ok = TRUE;
+ }
+ else if (!safe_strcmp (pr_type, "pr-shares"))
+ {
+ xaccQueryAddSharesMatch (q, val, how, QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pr_type, "pr-value")) {
- xaccQueryAddValueMatch (q, val, amt_sgn, how, QOF_QUERY_OR);
- ok = TRUE;
+ }
+ else if (!safe_strcmp (pr_type, "pr-value"))
+ {
+ xaccQueryAddValueMatch (q, val, amt_sgn, how, QOF_QUERY_OR);
+ ok = TRUE;
- } else {
- PINFO ("unknown amount predicate: %s", pr_type);
- }
+ }
+ else
+ {
+ PINFO ("unknown amount predicate: %s", pr_type);
+ }
- }
- else if (!safe_strcmp (pd_type, "pd-account"))
- {
- QofGuidMatch how;
- GList *account_guids;
+ }
+ else if (!safe_strcmp (pd_type, "pd-account"))
+ {
+ QofGuidMatch how;
+ GList *account_guids;
- /* how */
- if (scm_is_null (query_term_scm)) {
- PINFO ("pd-account: null how");
- break;
- }
+ /* how */
+ if (scm_is_null (query_term_scm))
+ {
+ PINFO ("pd-account: null how");
+ break;
+ }
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- how = gnc_scm2acct_match_how (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ how = gnc_scm2acct_match_how (scm);
- /* account guids */
- if (scm_is_null (query_term_scm)) {
- PINFO ("pd-account: null guids");
- break;
- }
+ /* account guids */
+ if (scm_is_null (query_term_scm))
+ {
+ PINFO ("pd-account: null guids");
+ break;
+ }
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
- account_guids = gnc_scm2guid_glist (scm);
+ account_guids = gnc_scm2guid_glist (scm);
- xaccQueryAddAccountGUIDMatch (q, account_guids, how, QOF_QUERY_OR);
+ xaccQueryAddAccountGUIDMatch (q, account_guids, how, QOF_QUERY_OR);
- gnc_guid_glist_free (account_guids);
+ gnc_guid_glist_free (account_guids);
- ok = TRUE;
+ ok = TRUE;
- } else if (!safe_strcmp (pd_type, "pd-string")) {
- gboolean case_sens;
- gboolean use_regexp;
- const gchar *matchstring;
+ }
+ else if (!safe_strcmp (pd_type, "pd-string"))
+ {
+ gboolean case_sens;
+ gboolean use_regexp;
+ const gchar *matchstring;
- /* case_sens */
- if (scm_is_null (query_term_scm))
- break;
+ /* case_sens */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- case_sens = scm_is_true (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ case_sens = scm_is_true (scm);
- /* use_regexp */
- if (scm_is_null (query_term_scm))
- break;
+ /* use_regexp */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- use_regexp = scm_is_true (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ use_regexp = scm_is_true (scm);
- /* matchstring */
- if (scm_is_null (query_term_scm))
- break;
+ /* matchstring */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- matchstring = scm_to_locale_string (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ matchstring = scm_to_locale_string (scm);
- if (!safe_strcmp (pr_type, "pr-action")) {
- xaccQueryAddActionMatch (q, matchstring, case_sens, use_regexp,
- QOF_QUERY_OR);
- ok = TRUE;
+ if (!safe_strcmp (pr_type, "pr-action"))
+ {
+ xaccQueryAddActionMatch (q, matchstring, case_sens, use_regexp,
+ QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pr_type, "pr-desc")) {
- xaccQueryAddDescriptionMatch (q, matchstring, case_sens,
- use_regexp, QOF_QUERY_OR);
- ok = TRUE;
+ }
+ else if (!safe_strcmp (pr_type, "pr-desc"))
+ {
+ xaccQueryAddDescriptionMatch (q, matchstring, case_sens,
+ use_regexp, QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pr_type, "pr-memo")) {
- xaccQueryAddMemoMatch (q, matchstring, case_sens, use_regexp,
- QOF_QUERY_OR);
- ok = TRUE;
+ }
+ else if (!safe_strcmp (pr_type, "pr-memo"))
+ {
+ xaccQueryAddMemoMatch (q, matchstring, case_sens, use_regexp,
+ QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pr_type, "pr-num")) {
- xaccQueryAddNumberMatch (q, matchstring, case_sens, use_regexp,
- QOF_QUERY_OR);
- ok = TRUE;
+ }
+ else if (!safe_strcmp (pr_type, "pr-num"))
+ {
+ xaccQueryAddNumberMatch (q, matchstring, case_sens, use_regexp,
+ QOF_QUERY_OR);
+ ok = TRUE;
- } else {
- PINFO ("Unknown string predicate: %s", pr_type);
- }
+ }
+ else
+ {
+ PINFO ("Unknown string predicate: %s", pr_type);
+ }
- } else if (!safe_strcmp (pd_type, "pd-cleared")) {
- cleared_match_t how;
+ }
+ else if (!safe_strcmp (pd_type, "pd-cleared"))
+ {
+ cleared_match_t how;
- /* how */
- if (scm_is_null (query_term_scm))
- break;
+ /* how */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- how = gnc_scm2cleared_match_how (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ how = gnc_scm2cleared_match_how (scm);
- xaccQueryAddClearedMatch (q, how, QOF_QUERY_OR);
- ok = TRUE;
+ xaccQueryAddClearedMatch (q, how, QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pd_type, "pd-balance")) {
- gboolean how;
+ }
+ else if (!safe_strcmp (pd_type, "pd-balance"))
+ {
+ gboolean how;
- /* how */
- if (scm_is_null (query_term_scm))
- break;
+ /* how */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- if (gnc_scm2balance_match_how (scm, &how) == FALSE)
- break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ if (gnc_scm2balance_match_how (scm, &how) == FALSE)
+ break;
- xaccQueryAddBalanceMatch (q, how, QOF_QUERY_OR);
- ok = TRUE;
+ xaccQueryAddBalanceMatch (q, how, QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pd_type, "pd-guid")) {
- GUID guid;
- QofIdType id_type;
+ }
+ else if (!safe_strcmp (pd_type, "pd-guid"))
+ {
+ GUID guid;
+ QofIdType id_type;
- /* guid */
- if (scm_is_null (query_term_scm))
- break;
+ /* guid */
+ if (scm_is_null (query_term_scm))
+ break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- guid = gnc_scm2guid (scm);
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ guid = gnc_scm2guid (scm);
- /* id type */
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- id_type = g_strdup (scm_to_locale_string (scm));
+ /* id type */
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ id_type = g_strdup (scm_to_locale_string (scm));
- xaccQueryAddGUIDMatch (q, &guid, id_type, QOF_QUERY_OR);
- ok = TRUE;
+ xaccQueryAddGUIDMatch (q, &guid, id_type, QOF_QUERY_OR);
+ ok = TRUE;
- } else if (!safe_strcmp (pd_type, "pd-kvp")) {
- GSList *path;
- KvpValue *value;
- QofQueryCompare how;
- QofIdType where;
+ }
+ else if (!safe_strcmp (pd_type, "pd-kvp"))
+ {
+ GSList *path;
+ KvpValue *value;
+ QofQueryCompare how;
+ QofIdType where;
- /* how */
- if (scm_is_null (query_term_scm))
- break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- how = gnc_scm2kvp_match_how (scm);
+ /* how */
+ if (scm_is_null (query_term_scm))
+ break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ how = gnc_scm2kvp_match_how (scm);
- /* where */
- if (scm_is_null (query_term_scm))
- break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- where = gnc_scm2kvp_match_where (scm);
+ /* where */
+ if (scm_is_null (query_term_scm))
+ break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ where = gnc_scm2kvp_match_where (scm);
- /* path */
- if (scm_is_null (query_term_scm))
- break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- path = gnc_query_scm2path (scm);
+ /* path */
+ if (scm_is_null (query_term_scm))
+ break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ path = gnc_query_scm2path (scm);
- /* value */
- if (scm_is_null (query_term_scm))
- break;
- scm = SCM_CAR (query_term_scm);
- query_term_scm = SCM_CDR (query_term_scm);
- value = gnc_scm2KvpValue (scm);
+ /* value */
+ if (scm_is_null (query_term_scm))
+ break;
+ scm = SCM_CAR (query_term_scm);
+ query_term_scm = SCM_CDR (query_term_scm);
+ value = gnc_scm2KvpValue (scm);
- xaccQueryAddKVPMatch (q, path, value, how, where, QOF_QUERY_OR);
+ xaccQueryAddKVPMatch (q, path, value, how, where, QOF_QUERY_OR);
- gnc_query_path_free (path);
- kvp_value_delete (value);
- ok = TRUE;
+ gnc_query_path_free (path);
+ kvp_value_delete (value);
+ ok = TRUE;
- } else {
- PINFO ("Unknown Predicate: %s", pd_type);
+ }
+ else
+ {
+ PINFO ("Unknown Predicate: %s", pd_type);
+ }
+
}
+ while (FALSE);
- } while (FALSE);
+ if (ok)
+ {
+ Query *out_q;
- if (ok)
- {
- Query *out_q;
+ if (sense)
+ out_q = q;
+ else
+ {
+ out_q = xaccQueryInvert (q);
+ xaccFreeQuery (q);
+ }
- if (sense)
- out_q = q;
- else {
- out_q = xaccQueryInvert (q);
- xaccFreeQuery (q);
+ return out_q;
}
- return out_q;
- }
-
- xaccFreeQuery (q);
- return NULL;
+ xaccFreeQuery (q);
+ return NULL;
}
static Query *
gnc_scm2query_term_query (SCM query_term_scm, query_version_t vers)
{
- switch (vers) {
- case gnc_QUERY_v1:
- return gnc_scm2query_term_query_v1 (query_term_scm);
- case gnc_QUERY_v2:
- return gnc_scm2query_term_query_v2 (query_term_scm);
- default:
- return NULL;
- }
+ switch (vers)
+ {
+ case gnc_QUERY_v1:
+ return gnc_scm2query_term_query_v1 (query_term_scm);
+ case gnc_QUERY_v2:
+ return gnc_scm2query_term_query_v2 (query_term_scm);
+ default:
+ return NULL;
+ }
}
static SCM
gnc_query_terms2scm (const GList *terms)
{
- SCM or_terms = SCM_EOL;
- const GList *or_node;
+ SCM or_terms = SCM_EOL;
+ const GList *or_node;
- for (or_node = terms; or_node; or_node = or_node->next)
- {
- SCM and_terms = SCM_EOL;
- GList *and_node;
-
- for (and_node = or_node->data; and_node; and_node = and_node->next)
+ for (or_node = terms; or_node; or_node = or_node->next)
{
- QofQueryTerm *qt = and_node->data;
- SCM qt_scm;
+ SCM and_terms = SCM_EOL;
+ GList *and_node;
- qt_scm = gnc_queryterm2scm (qt);
+ for (and_node = or_node->data; and_node; and_node = and_node->next)
+ {
+ QofQueryTerm *qt = and_node->data;
+ SCM qt_scm;
- and_terms = scm_cons (qt_scm, and_terms);
- }
+ qt_scm = gnc_queryterm2scm (qt);
- and_terms = scm_reverse (and_terms);
+ and_terms = scm_cons (qt_scm, and_terms);
+ }
- or_terms = scm_cons (and_terms, or_terms);
- }
+ and_terms = scm_reverse (and_terms);
- return scm_reverse (or_terms);
+ or_terms = scm_cons (and_terms, or_terms);
+ }
+
+ return scm_reverse (or_terms);
}
static Query *
gnc_scm2query_and_terms (SCM and_terms, query_version_t vers)
{
- Query *q = NULL;
+ Query *q = NULL;
- if (!scm_is_list (and_terms))
- return NULL;
+ if (!scm_is_list (and_terms))
+ return NULL;
- while (!scm_is_null (and_terms))
- {
- SCM term;
+ while (!scm_is_null (and_terms))
+ {
+ SCM term;
- term = SCM_CAR (and_terms);
- and_terms = SCM_CDR (and_terms);
+ term = SCM_CAR (and_terms);
+ and_terms = SCM_CDR (and_terms);
- if (!q)
- q = gnc_scm2query_term_query (term, vers);
- else
- {
- Query *q_and;
- Query *q_new;
+ if (!q)
+ q = gnc_scm2query_term_query (term, vers);
+ else
+ {
+ Query *q_and;
+ Query *q_new;
- q_and = gnc_scm2query_term_query (term, vers);
+ q_and = gnc_scm2query_term_query (term, vers);
- if (q_and)
- {
- q_new = xaccQueryMerge (q, q_and, QOF_QUERY_AND);
+ if (q_and)
+ {
+ q_new = xaccQueryMerge (q, q_and, QOF_QUERY_AND);
- if (q_new)
- {
- xaccFreeQuery (q);
- q = q_new;
+ if (q_new)
+ {
+ xaccFreeQuery (q);
+ q = q_new;
+ }
+ }
}
- }
}
- }
- return q;
+ return q;
}
static Query *
gnc_scm2query_or_terms (SCM or_terms, query_version_t vers)
{
- Query *q = NULL;
+ Query *q = NULL;
- if (!scm_is_list (or_terms))
- return NULL;
+ if (!scm_is_list (or_terms))
+ return NULL;
- q = xaccMallocQuery ();
+ q = xaccMallocQuery ();
- while (!scm_is_null (or_terms))
- {
- SCM and_terms;
+ while (!scm_is_null (or_terms))
+ {
+ SCM and_terms;
- and_terms = SCM_CAR (or_terms);
- or_terms = SCM_CDR (or_terms);
+ and_terms = SCM_CAR (or_terms);
+ or_terms = SCM_CDR (or_terms);
- if (!q)
- q = gnc_scm2query_and_terms (and_terms, vers);
- else
- {
- Query *q_or;
- Query *q_new;
+ if (!q)
+ q = gnc_scm2query_and_terms (and_terms, vers);
+ else
+ {
+ Query *q_or;
+ Query *q_new;
- q_or = gnc_scm2query_and_terms (and_terms, vers);
+ q_or = gnc_scm2query_and_terms (and_terms, vers);
- if (q_or)
- {
- q_new = xaccQueryMerge (q, q_or, QOF_QUERY_OR);
+ if (q_or)
+ {
+ q_new = xaccQueryMerge (q, q_or, QOF_QUERY_OR);
- if (q_new)
- {
- xaccFreeQuery (q);
- q = q_new;
+ if (q_new)
+ {
+ xaccFreeQuery (q);
+ q = q_new;
+ }
+ }
}
- }
}
- }
- return q;
+ return q;
}
static SCM
gnc_query_sort2scm (const QofQuerySort *qs)
{
- SCM sort_scm = SCM_EOL;
- GSList *path;
+ SCM sort_scm = SCM_EOL;
+ GSList *path;
- path = qof_query_sort_get_param_path (qs);
- if (path == NULL)
- return SCM_BOOL_F;
+ path = qof_query_sort_get_param_path (qs);
+ if (path == NULL)
+ return SCM_BOOL_F;
- sort_scm = scm_cons (gnc_query_path2scm (path), sort_scm);
- sort_scm = scm_cons (scm_int2num (qof_query_sort_get_sort_options (qs)), sort_scm);
- sort_scm = scm_cons (SCM_BOOL (qof_query_sort_get_increasing (qs)), sort_scm);
+ sort_scm = scm_cons (gnc_query_path2scm (path), sort_scm);
+ sort_scm = scm_cons (scm_int2num (qof_query_sort_get_sort_options (qs)), sort_scm);
+ sort_scm = scm_cons (SCM_BOOL (qof_query_sort_get_increasing (qs)), sort_scm);
- return scm_reverse (sort_scm);
+ return scm_reverse (sort_scm);
}
static gboolean
gnc_query_scm2sort (SCM sort_scm, GSList **path, gint *options, gboolean *inc)
{
- SCM val;
- GSList *p;
- gint o;
- gboolean i;
+ SCM val;
+ GSList *p;
+ gint o;
+ gboolean i;
- g_return_val_if_fail (path && options && inc, FALSE);
- g_return_val_if_fail (*path == NULL, FALSE);
+ g_return_val_if_fail (path && options && inc, FALSE);
+ g_return_val_if_fail (*path == NULL, FALSE);
- /* This is ok -- it means we have an empty sort. Don't do anything */
- if (scm_is_bool (sort_scm))
- return TRUE;
+ /* This is ok -- it means we have an empty sort. Don't do anything */
+ if (scm_is_bool (sort_scm))
+ return TRUE;
- /* Ok, this had better be a list */
- if (!scm_is_list (sort_scm))
- return FALSE;
-
- /* Parse the path, options, and increasing */
- val = SCM_CAR (sort_scm);
- sort_scm = SCM_CDR (sort_scm);
- if (!scm_is_list (val))
- return FALSE;
- p = gnc_query_scm2path (val);
+ /* Ok, this had better be a list */
+ if (!scm_is_list (sort_scm))
+ return FALSE;
- /* options */
- val = SCM_CAR (sort_scm);
- sort_scm = SCM_CDR (sort_scm);
- if (!scm_is_number (val)) {
- gnc_query_path_free (p);
- return FALSE;
- }
- o = scm_num2int (val, SCM_ARG1, G_STRFUNC);
+ /* Parse the path, options, and increasing */
+ val = SCM_CAR (sort_scm);
+ sort_scm = SCM_CDR (sort_scm);
+ if (!scm_is_list (val))
+ return FALSE;
+ p = gnc_query_scm2path (val);
- /* increasing */
- val = SCM_CAR (sort_scm);
- sort_scm = SCM_CDR (sort_scm);
- if (!scm_is_bool (val)) {
- gnc_query_path_free (p);
- return FALSE;
- }
- i = scm_is_true (val);
+ /* options */
+ val = SCM_CAR (sort_scm);
+ sort_scm = SCM_CDR (sort_scm);
+ if (!scm_is_number (val))
+ {
+ gnc_query_path_free (p);
+ return FALSE;
+ }
+ o = scm_num2int (val, SCM_ARG1, G_STRFUNC);
- /* EOL */
- if (!scm_is_null (sort_scm)) {
- gnc_query_path_free (p);
- return FALSE;
- }
- *path = p;
- *options = o;
- *inc = i;
+ /* increasing */
+ val = SCM_CAR (sort_scm);
+ sort_scm = SCM_CDR (sort_scm);
+ if (!scm_is_bool (val))
+ {
+ gnc_query_path_free (p);
+ return FALSE;
+ }
+ i = scm_is_true (val);
- return TRUE;
+ /* EOL */
+ if (!scm_is_null (sort_scm))
+ {
+ gnc_query_path_free (p);
+ return FALSE;
+ }
+ *path = p;
+ *options = o;
+ *inc = i;
+
+ return TRUE;
}
SCM
gnc_query2scm (QofQuery *q)
{
- SCM query_scm = SCM_EOL;
- SCM pair;
- QofQuerySort *s1, *s2, *s3;
+ SCM query_scm = SCM_EOL;
+ SCM pair;
+ QofQuerySort *s1, *s2, *s3;
- if (!q) return SCM_BOOL_F;
+ if (!q) return SCM_BOOL_F;
#ifndef HAVE_GUILE18
- ++scm_block_gc;
+ ++scm_block_gc;
#endif
- /* terms */
- pair = scm_cons (gnc_query_terms2scm (qof_query_get_terms (q)), SCM_EOL);
- pair = scm_cons (scm_str2symbol ("terms"), pair);
- query_scm = scm_cons (pair, query_scm);
+ /* terms */
+ pair = scm_cons (gnc_query_terms2scm (qof_query_get_terms (q)), SCM_EOL);
+ pair = scm_cons (scm_str2symbol ("terms"), pair);
+ query_scm = scm_cons (pair, query_scm);
- /* search-for */
- pair = scm_cons (scm_str2symbol (qof_query_get_search_for (q)), SCM_EOL);
- pair = scm_cons (scm_str2symbol ("search-for"), pair);
- query_scm = scm_cons (pair, query_scm);
+ /* search-for */
+ pair = scm_cons (scm_str2symbol (qof_query_get_search_for (q)), SCM_EOL);
+ pair = scm_cons (scm_str2symbol ("search-for"), pair);
+ query_scm = scm_cons (pair, query_scm);
- /* sorts... */
- qof_query_get_sorts (q, &s1, &s2, &s3);
+ /* sorts... */
+ qof_query_get_sorts (q, &s1, &s2, &s3);
- /* primary-sort */
- pair = scm_cons (gnc_query_sort2scm (s1), SCM_EOL);
- pair = scm_cons (scm_str2symbol ("primary-sort"), pair);
- query_scm = scm_cons (pair, query_scm);
+ /* primary-sort */
+ pair = scm_cons (gnc_query_sort2scm (s1), SCM_EOL);
+ pair = scm_cons (scm_str2symbol ("primary-sort"), pair);
+ query_scm = scm_cons (pair, query_scm);
- /* secondary-sort */
- pair = scm_cons (gnc_query_sort2scm (s2), SCM_EOL);
- pair = scm_cons (scm_str2symbol ("secondary-sort"), pair);
- query_scm = scm_cons (pair, query_scm);
+ /* secondary-sort */
+ pair = scm_cons (gnc_query_sort2scm (s2), SCM_EOL);
+ pair = scm_cons (scm_str2symbol ("secondary-sort"), pair);
+ query_scm = scm_cons (pair, query_scm);
- /* tertiary-sort */
- pair = scm_cons (gnc_query_sort2scm (s3), SCM_EOL);
- pair = scm_cons (scm_str2symbol ("tertiary-sort"), pair);
- query_scm = scm_cons (pair, query_scm);
+ /* tertiary-sort */
+ pair = scm_cons (gnc_query_sort2scm (s3), SCM_EOL);
+ pair = scm_cons (scm_str2symbol ("tertiary-sort"), pair);
+ query_scm = scm_cons (pair, query_scm);
- /* max results */
- pair = scm_cons (scm_int2num (qof_query_get_max_results (q)), SCM_EOL);
- pair = scm_cons (scm_str2symbol ("max-results"), pair);
- query_scm = scm_cons (pair, query_scm);
+ /* max results */
+ pair = scm_cons (scm_int2num (qof_query_get_max_results (q)), SCM_EOL);
+ pair = scm_cons (scm_str2symbol ("max-results"), pair);
+ query_scm = scm_cons (pair, query_scm);
- /* Reverse this list; tag it as 'query-v2' */
- pair = scm_reverse (query_scm);
+ /* Reverse this list; tag it as 'query-v2' */
+ pair = scm_reverse (query_scm);
#ifndef HAVE_GUILE18
- --scm_block_gc;
+ --scm_block_gc;
#endif
- return scm_cons (scm_str2symbol ("query-v2"), pair);
+ return scm_cons (scm_str2symbol ("query-v2"), pair);
}
static GSList *
gnc_query_sort_to_list (const gchar * symbol)
{
- GSList *path = NULL;
+ GSList *path = NULL;
- if (!symbol)
- return NULL;
+ if (!symbol)
+ return NULL;
- if (!safe_strcmp (symbol, "by-none")) {
- path = NULL;
- } else if (!safe_strcmp (symbol, "by-standard")) {
- path = g_slist_prepend (path, QUERY_DEFAULT_SORT);
+ if (!safe_strcmp (symbol, "by-none"))
+ {
+ path = NULL;
+ }
+ else if (!safe_strcmp (symbol, "by-standard"))
+ {
+ path = g_slist_prepend (path, QUERY_DEFAULT_SORT);
- } else if (!safe_strcmp (symbol, "by-date") ||
- !safe_strcmp (symbol, "by-date-rounded")) {
- path = g_slist_prepend (path, TRANS_DATE_POSTED);
- path = g_slist_prepend (path, SPLIT_TRANS);
+ }
+ else if (!safe_strcmp (symbol, "by-date") ||
+ !safe_strcmp (symbol, "by-date-rounded"))
+ {
+ path = g_slist_prepend (path, TRANS_DATE_POSTED);
+ path = g_slist_prepend (path, SPLIT_TRANS);
- } else if (!safe_strcmp (symbol, "by-date-entered") ||
- !safe_strcmp (symbol, "by-date-entered-rounded")) {
- path = g_slist_prepend (path, TRANS_DATE_ENTERED);
- path = g_slist_prepend (path, SPLIT_TRANS);
+ }
+ else if (!safe_strcmp (symbol, "by-date-entered") ||
+ !safe_strcmp (symbol, "by-date-entered-rounded"))
+ {
+ path = g_slist_prepend (path, TRANS_DATE_ENTERED);
+ path = g_slist_prepend (path, SPLIT_TRANS);
- } else if (!safe_strcmp (symbol, "by-date-reconciled") ||
- !safe_strcmp (symbol, "by-date-reconciled-rounded")) {
- path = g_slist_prepend (path, SPLIT_DATE_RECONCILED);
+ }
+ else if (!safe_strcmp (symbol, "by-date-reconciled") ||
+ !safe_strcmp (symbol, "by-date-reconciled-rounded"))
+ {
+ path = g_slist_prepend (path, SPLIT_DATE_RECONCILED);
- } else if (!safe_strcmp (symbol, "by-num")) {
- path = g_slist_prepend (path, TRANS_NUM);
- path = g_slist_prepend (path, SPLIT_TRANS);
+ }
+ else if (!safe_strcmp (symbol, "by-num"))
+ {
+ path = g_slist_prepend (path, TRANS_NUM);
+ path = g_slist_prepend (path, SPLIT_TRANS);
- } else if (!safe_strcmp (symbol, "by-amount")) {
- path = g_slist_prepend (path, SPLIT_VALUE);
+ }
+ else if (!safe_strcmp (symbol, "by-amount"))
+ {
+ path = g_slist_prepend (path, SPLIT_VALUE);
- } else if (!safe_strcmp (symbol, "by-memo")) {
- path = g_slist_prepend (path, SPLIT_MEMO);
+ }
+ else if (!safe_strcmp (symbol, "by-memo"))
+ {
+ path = g_slist_prepend (path, SPLIT_MEMO);
- } else if (!safe_strcmp (symbol, "by-desc")) {
- path = g_slist_prepend (path, TRANS_DESCRIPTION);
- path = g_slist_prepend (path, SPLIT_TRANS);
+ }
+ else if (!safe_strcmp (symbol, "by-desc"))
+ {
+ path = g_slist_prepend (path, TRANS_DESCRIPTION);
+ path = g_slist_prepend (path, SPLIT_TRANS);
- } else if (!safe_strcmp (symbol, "by-reconcile")) {
- path = g_slist_prepend (path, SPLIT_RECONCILE);
+ }
+ else if (!safe_strcmp (symbol, "by-reconcile"))
+ {
+ path = g_slist_prepend (path, SPLIT_RECONCILE);
- } else if (!safe_strcmp (symbol, "by-account-full-name")) {
- path = g_slist_prepend (path, SPLIT_ACCT_FULLNAME);
+ }
+ else if (!safe_strcmp (symbol, "by-account-full-name"))
+ {
+ path = g_slist_prepend (path, SPLIT_ACCT_FULLNAME);
- } else if (!safe_strcmp (symbol, "by-account-code")) {
- path = g_slist_prepend (path, ACCOUNT_CODE_);
- path = g_slist_prepend (path, SPLIT_ACCOUNT);
+ }
+ else if (!safe_strcmp (symbol, "by-account-code"))
+ {
+ path = g_slist_prepend (path, ACCOUNT_CODE_);
+ path = g_slist_prepend (path, SPLIT_ACCOUNT);
- } else if (!safe_strcmp (symbol, "by-corr-account-full-name")) {
- path = g_slist_prepend (path, SPLIT_CORR_ACCT_NAME);
+ }
+ else if (!safe_strcmp (symbol, "by-corr-account-full-name"))
+ {
+ path = g_slist_prepend (path, SPLIT_CORR_ACCT_NAME);
- } else if (!safe_strcmp (symbol, "by-corr-account-code")) {
- path = g_slist_prepend (path, SPLIT_CORR_ACCT_CODE);
+ }
+ else if (!safe_strcmp (symbol, "by-corr-account-code"))
+ {
+ path = g_slist_prepend (path, SPLIT_CORR_ACCT_CODE);
- } else {
- PERR ("Unknown sort-type, %s", symbol);
- }
+ }
+ else
+ {
+ PERR ("Unknown sort-type, %s", symbol);
+ }
- return path;
+ return path;
}
static Query *
gnc_scm2query_v1 (SCM query_scm)
{
- Query *q = NULL;
- gboolean ok = TRUE;
- const gchar * primary_sort = NULL;
- const gchar * secondary_sort = NULL;
- const gchar * tertiary_sort = NULL;
- gboolean primary_increasing = TRUE;
- gboolean secondary_increasing = TRUE;
- gboolean tertiary_increasing = TRUE;
- int max_splits = -1;
+ Query *q = NULL;
+ gboolean ok = TRUE;
+ const gchar * primary_sort = NULL;
+ const gchar * secondary_sort = NULL;
+ const gchar * tertiary_sort = NULL;
+ gboolean primary_increasing = TRUE;
+ gboolean secondary_increasing = TRUE;
+ gboolean tertiary_increasing = TRUE;
+ int max_splits = -1;
- while (!scm_is_null (query_scm))
- {
- const gchar *symbol;
- SCM sym_scm;
- SCM value;
- SCM pair;
+ while (!scm_is_null (query_scm))
+ {
+ const gchar *symbol;
+ SCM sym_scm;
+ SCM value;
+ SCM pair;
- pair = SCM_CAR (query_scm);
- query_scm = SCM_CDR (query_scm);
+ pair = SCM_CAR (query_scm);
+ query_scm = SCM_CDR (query_scm);
- if (!scm_is_pair (pair)) {
- PERR ("Not a Pair");
- ok = FALSE;
- break;
- }
+ if (!scm_is_pair (pair))
+ {
+ PERR ("Not a Pair");
+ ok = FALSE;
+ break;
+ }
- sym_scm = SCM_CAR (pair);
- value = SCM_CADR (pair);
+ sym_scm = SCM_CAR (pair);
+ value = SCM_CADR (pair);
- if (!scm_is_symbol (sym_scm)) {
- PERR ("Not a symbol");
- ok = FALSE;
- break;
- }
+ if (!scm_is_symbol (sym_scm))
+ {
+ PERR ("Not a symbol");
+ ok = FALSE;
+ break;
+ }
- symbol = SCM_SYMBOL_CHARS (sym_scm);
- if (!symbol) {
- PERR ("No string found");
- ok = FALSE;
- break;
- }
+ symbol = SCM_SYMBOL_CHARS (sym_scm);
+ if (!symbol)
+ {
+ PERR ("No string found");
+ ok = FALSE;
+ break;
+ }
- if (safe_strcmp ("terms", symbol) == 0) {
- if (q)
- xaccFreeQuery (q);
+ if (safe_strcmp ("terms", symbol) == 0)
+ {
+ if (q)
+ xaccFreeQuery (q);
- q = gnc_scm2query_or_terms (value, gnc_QUERY_v1);
- if (!q) {
- PINFO ("invalid terms");
- ok = FALSE;
- break;
- }
+ q = gnc_scm2query_or_terms (value, gnc_QUERY_v1);
+ if (!q)
+ {
+ PINFO ("invalid terms");
+ ok = FALSE;
+ break;
+ }
- } else if (safe_strcmp ("primary-sort", symbol) == 0) {
- if (!scm_is_symbol (value)) {
- PINFO ("Invalid primary sort");
- ok = FALSE;
- break;
- }
+ }
+ else if (safe_strcmp ("primary-sort", symbol) == 0)
+ {
+ if (!scm_is_symbol (value))
+ {
+ PINFO ("Invalid primary sort");
+ ok = FALSE;
+ break;
+ }
- primary_sort = SCM_SYMBOL_CHARS (value);
+ primary_sort = SCM_SYMBOL_CHARS (value);
- } else if (safe_strcmp ("secondary-sort", symbol) == 0) {
- if (!scm_is_symbol (value)) {
- PINFO ("Invalid secondary sort");
- ok = FALSE;
- break;
- }
+ }
+ else if (safe_strcmp ("secondary-sort", symbol) == 0)
+ {
+ if (!scm_is_symbol (value))
+ {
+ PINFO ("Invalid secondary sort");
+ ok = FALSE;
+ break;
+ }
- secondary_sort = SCM_SYMBOL_CHARS (value);
+ secondary_sort = SCM_SYMBOL_CHARS (value);
- } else if (safe_strcmp ("tertiary-sort", symbol) == 0) {
- if (!scm_is_symbol (value)) {
- PINFO ("Invalid tertiary sort");
- ok = FALSE;
- break;
- }
+ }
+ else if (safe_strcmp ("tertiary-sort", symbol) == 0)
+ {
+ if (!scm_is_symbol (value))
+ {
+ PINFO ("Invalid tertiary sort");
+ ok = FALSE;
+ break;
+ }
- tertiary_sort = SCM_SYMBOL_CHARS (value);
+ tertiary_sort = SCM_SYMBOL_CHARS (value);
- } else if (safe_strcmp ("primary-increasing", symbol) == 0) {
- primary_increasing = scm_is_true (value);
+ }
+ else if (safe_strcmp ("primary-increasing", symbol) == 0)
+ {
+ primary_increasing = scm_is_true (value);
- } else if (safe_strcmp ("secondary-increasing", symbol) == 0) {
- secondary_increasing = scm_is_true (value);
+ }
+ else if (safe_strcmp ("secondary-increasing", symbol) == 0)
+ {
+ secondary_increasing = scm_is_true (value);
- } else if (safe_strcmp ("tertiary-increasing", symbol) == 0) {
- tertiary_increasing = scm_is_true (value);
+ }
+ else if (safe_strcmp ("tertiary-increasing", symbol) == 0)
+ {
+ tertiary_increasing = scm_is_true (value);
- } else if (safe_strcmp ("max-splits", symbol) == 0) {
- if (!scm_is_number (value)) {
- PERR ("invalid max-splits");
- ok = FALSE;
- break;
- }
+ }
+ else if (safe_strcmp ("max-splits", symbol) == 0)
+ {
+ if (!scm_is_number (value))
+ {
+ PERR ("invalid max-splits");
+ ok = FALSE;
+ break;
+ }
- max_splits = scm_num2int (value, SCM_ARG1, G_STRFUNC);
+ max_splits = scm_num2int (value, SCM_ARG1, G_STRFUNC);
- } else {
- PERR ("Unknown symbol: %s", symbol);
- ok = FALSE;
- break;
+ }
+ else
+ {
+ PERR ("Unknown symbol: %s", symbol);
+ ok = FALSE;
+ break;
+ }
}
- }
- if (ok) {
- GSList *s1, *s2, *s3;
- s1 = gnc_query_sort_to_list (primary_sort);
- s2 = gnc_query_sort_to_list (secondary_sort);
- s3 = gnc_query_sort_to_list (tertiary_sort);
+ if (ok)
+ {
+ GSList *s1, *s2, *s3;
+ s1 = gnc_query_sort_to_list (primary_sort);
+ s2 = gnc_query_sort_to_list (secondary_sort);
+ s3 = gnc_query_sort_to_list (tertiary_sort);
- qof_query_set_sort_order (q, s1, s2, s3);
- qof_query_set_sort_increasing (q, primary_increasing, secondary_increasing,
- tertiary_increasing);
- xaccQuerySetMaxSplits (q, max_splits);
+ qof_query_set_sort_order (q, s1, s2, s3);
+ qof_query_set_sort_increasing (q, primary_increasing, secondary_increasing,
+ tertiary_increasing);
+ xaccQuerySetMaxSplits (q, max_splits);
- return q;
- }
+ return q;
+ }
- xaccFreeQuery (q);
- return NULL;
+ xaccFreeQuery (q);
+ return NULL;
}
static Query *
gnc_scm2query_v2 (SCM query_scm)
{
- Query *q = NULL;
- gboolean ok = TRUE;
- const gchar * search_for = NULL;
- GSList *sp1 = NULL, *sp2 = NULL, *sp3 = NULL;
- gint so1 = 0, so2 = 0, so3 = 0;
- gboolean si1 = TRUE, si2 = TRUE, si3 = TRUE;
- int max_results = -1;
+ Query *q = NULL;
+ gboolean ok = TRUE;
+ const gchar * search_for = NULL;
+ GSList *sp1 = NULL, *sp2 = NULL, *sp3 = NULL;
+ gint so1 = 0, so2 = 0, so3 = 0;
+ gboolean si1 = TRUE, si2 = TRUE, si3 = TRUE;
+ int max_results = -1;
#ifndef HAVE_GUILE18
- ++scm_block_gc;
+ ++scm_block_gc;
#endif
- while (!scm_is_null (query_scm))
- {
- const gchar *symbol;
- SCM sym_scm;
- SCM value;
- SCM pair;
+ while (!scm_is_null (query_scm))
+ {
+ const gchar *symbol;
+ SCM sym_scm;
+ SCM value;
+ SCM pair;
- pair = SCM_CAR (query_scm);
- query_scm = SCM_CDR (query_scm);
+ pair = SCM_CAR (query_scm);
+ query_scm = SCM_CDR (query_scm);
- if (!scm_is_pair (pair)) {
- ok = FALSE;
- break;
- }
+ if (!scm_is_pair (pair))
+ {
+ ok = FALSE;
+ break;
+ }
- sym_scm = SCM_CAR (pair);
- value = SCM_CADR (pair);
+ sym_scm = SCM_CAR (pair);
+ value = SCM_CADR (pair);
- if (!scm_is_symbol (sym_scm)) {
- ok = FALSE;
- break;
- }
+ if (!scm_is_symbol (sym_scm))
+ {
+ ok = FALSE;
+ break;
+ }
- symbol = SCM_SYMBOL_CHARS (sym_scm);
- if (!symbol) {
- ok = FALSE;
- break;
- }
+ symbol = SCM_SYMBOL_CHARS (sym_scm);
+ if (!symbol)
+ {
+ ok = FALSE;
+ break;
+ }
- if (!safe_strcmp ("terms", symbol)) {
- if (q)
- xaccFreeQuery (q);
+ if (!safe_strcmp ("terms", symbol))
+ {
+ if (q)
+ xaccFreeQuery (q);
- q = gnc_scm2query_or_terms (value, gnc_QUERY_v2);
- if (!q) {
- ok = FALSE;
- break;
- }
+ q = gnc_scm2query_or_terms (value, gnc_QUERY_v2);
+ if (!q)
+ {
+ ok = FALSE;
+ break;
+ }
- } else if (!safe_strcmp ("search-for", symbol)) {
- if (!scm_is_symbol (value)) {
- ok = FALSE;
- break;
- }
- search_for = SCM_SYMBOL_CHARS (value);
+ }
+ else if (!safe_strcmp ("search-for", symbol))
+ {
+ if (!scm_is_symbol (value))
+ {
+ ok = FALSE;
+ break;
+ }
+ search_for = SCM_SYMBOL_CHARS (value);
- } else if (safe_strcmp ("primary-sort", symbol) == 0) {
- if (! gnc_query_scm2sort (value, &sp1, &so1, &si1)) {
- ok = FALSE;
- break;
- }
+ }
+ else if (safe_strcmp ("primary-sort", symbol) == 0)
+ {
+ if (! gnc_query_scm2sort (value, &sp1, &so1, &si1))
+ {
+ ok = FALSE;
+ break;
+ }
- } else if (!safe_strcmp ("secondary-sort", symbol)) {
- if (! gnc_query_scm2sort (value, &sp2, &so2, &si2)) {
- ok = FALSE;
- break;
- }
+ }
+ else if (!safe_strcmp ("secondary-sort", symbol))
+ {
+ if (! gnc_query_scm2sort (value, &sp2, &so2, &si2))
+ {
+ ok = FALSE;
+ break;
+ }
- } else if (!safe_strcmp ("tertiary-sort", symbol)) {
- if (! gnc_query_scm2sort (value, &sp3, &so3, &si3)) {
- ok = FALSE;
- break;
- }
+ }
+ else if (!safe_strcmp ("tertiary-sort", symbol))
+ {
+ if (! gnc_query_scm2sort (value, &sp3, &so3, &si3))
+ {
+ ok = FALSE;
+ break;
+ }
- } else if (!safe_strcmp ("max-results", symbol)) {
- if (!scm_is_number (value)) {
- ok = FALSE;
- break;
- }
+ }
+ else if (!safe_strcmp ("max-results", symbol))
+ {
+ if (!scm_is_number (value))
+ {
+ ok = FALSE;
+ break;
+ }
- max_results = scm_num2int (value, SCM_ARG1, G_STRFUNC);
+ max_results = scm_num2int (value, SCM_ARG1, G_STRFUNC);
- } else {
- ok = FALSE;
- break;
+ }
+ else
+ {
+ ok = FALSE;
+ break;
+ }
}
- }
#ifndef HAVE_GUILE18
- --scm_block_gc;
+ --scm_block_gc;
#endif
- if (ok && search_for) {
- qof_query_search_for (q, search_for);
- qof_query_set_sort_order (q, sp1, sp2, sp3);
- qof_query_set_sort_options (q, so1, so2, so3);
- qof_query_set_sort_increasing (q, si1, si2, si3);
- qof_query_set_max_results (q, max_results);
+ if (ok && search_for)
+ {
+ qof_query_search_for (q, search_for);
+ qof_query_set_sort_order (q, sp1, sp2, sp3);
+ qof_query_set_sort_options (q, so1, so2, so3);
+ qof_query_set_sort_increasing (q, si1, si2, si3);
+ qof_query_set_max_results (q, max_results);
- return q;
- }
+ return q;
+ }
- xaccFreeQuery (q);
- return NULL;
+ xaccFreeQuery (q);
+ return NULL;
}
Query *
gnc_scm2query (SCM query_scm)
{
- SCM q_type;
- const gchar *type;
- Query *q = NULL;
+ SCM q_type;
+ const gchar *type;
+ Query *q = NULL;
- /* Not a list or NULL? No need to go further */
- if (!scm_is_list (query_scm) || scm_is_null (query_scm))
- return NULL;
+ /* Not a list or NULL? No need to go further */
+ if (!scm_is_list (query_scm) || scm_is_null (query_scm))
+ return NULL;
- /* Grab the 'type' (for v2 and above) */
- q_type = SCM_CAR (query_scm);
+ /* Grab the 'type' (for v2 and above) */
+ q_type = SCM_CAR (query_scm);
- if (!scm_is_symbol (q_type)) {
- if (scm_is_pair (q_type)) {
- /* Version-1 queries are just a list */
- return gnc_scm2query_v1 (query_scm);
- } else {
- return NULL;
+ if (!scm_is_symbol (q_type))
+ {
+ if (scm_is_pair (q_type))
+ {
+ /* Version-1 queries are just a list */
+ return gnc_scm2query_v1 (query_scm);
+ }
+ else
+ {
+ return NULL;
+ }
}
- }
- /* Ok, the LHS is the version and the RHS is the actual query list */
- type = SCM_SYMBOL_CHARS (q_type);
- if (!type)
- return NULL;
+ /* Ok, the LHS is the version and the RHS is the actual query list */
+ type = SCM_SYMBOL_CHARS (q_type);
+ if (!type)
+ return NULL;
- if (!safe_strcmp (type, "query-v2"))
- q = gnc_scm2query_v2 (SCM_CDR (query_scm));
+ if (!safe_strcmp (type, "query-v2"))
+ q = gnc_scm2query_v2 (SCM_CDR (query_scm));
- return q;
+ return q;
}
SCM
gnc_gint64_to_scm(const gint64 x)
{
-#if GUILE_LONG_LONG_OK
- return scm_long_long2num(x);
+#if GUILE_LONG_LONG_OK
+ return scm_long_long2num(x);
#else
- const gchar negative_p = (x < 0);
- const guint64 magnitude = negative_p ? -x : x;
- const guint32 lower_half = (guint32) (magnitude & 0xFFFFFFFF);
- const guint32 upper_half = (guint32) (magnitude >> 32);
- SCM result;
+ const gchar negative_p = (x < 0);
+ const guint64 magnitude = negative_p ? -x : x;
+ const guint32 lower_half = (guint32) (magnitude & 0xFFFFFFFF);
+ const guint32 upper_half = (guint32) (magnitude >> 32);
+ SCM result;
- result = scm_sum(scm_ash(scm_ulong2num(upper_half), SCM_MAKINUM(32)),
- scm_ulong2num(lower_half));
-
- if(negative_p) {
- return scm_difference(SCM_INUM0, result);
- } else {
- return result;
- }
+ result = scm_sum(scm_ash(scm_ulong2num(upper_half), SCM_MAKINUM(32)),
+ scm_ulong2num(lower_half));
+
+ if (negative_p)
+ {
+ return scm_difference(SCM_INUM0, result);
+ }
+ else
+ {
+ return result;
+ }
#endif
}
gint64
gnc_scm_to_gint64(SCM num)
{
-#if GUILE_LONG_LONG_OK
+#if GUILE_LONG_LONG_OK
#ifdef SCM_MINOR_VERSION
- /* Guile 1.6 and later have the SCM_XXX_VERSION macro */
- return scm_num2long_long(num, SCM_ARG1, "gnc_scm_to_gint64");
+ /* Guile 1.6 and later have the SCM_XXX_VERSION macro */
+ return scm_num2long_long(num, SCM_ARG1, "gnc_scm_to_gint64");
#else
- return scm_num2long_long(num, (char *) SCM_ARG1, "gnc_scm_to_gint64");
+ return scm_num2long_long(num, (char *) SCM_ARG1, "gnc_scm_to_gint64");
#endif
#else
- static SCM bits00to15_mask = SCM_BOOL_F;
- SCM magnitude = scm_abs(num);
- SCM bits;
- unsigned long c_bits;
- long long c_result = 0;
- int i;
+ static SCM bits00to15_mask = SCM_BOOL_F;
+ SCM magnitude = scm_abs(num);
+ SCM bits;
+ unsigned long c_bits;
+ long long c_result = 0;
+ int i;
- /* This doesn't work -- atm (bit-extract 4000 0 32) proves it */
- /*
- SCM lower = scm_bit_extract(magnitude, SCM_MAKINUM(0), SCM_MAKINUM(32));
- */
-
- if (bits00to15_mask == SCM_BOOL_F) {
- bits00to15_mask = scm_ulong2num(0xFFFF);
- scm_gc_protect_object (bits00to15_mask);
- }
+ /* This doesn't work -- atm (bit-extract 4000 0 32) proves it */
+ /*
+ SCM lower = scm_bit_extract(magnitude, SCM_MAKINUM(0), SCM_MAKINUM(32));
+ */
- /*
- * This isn't very complicated (IMHO). We work from the "top" of
- * the number downwards. We assume this is no more than a 64-bit
- * number, otherwise it will fail right away. Anyways, we keep
- * taking the top 16 bits of the number and move it to c_result.
- * Then we 'remove' those bits from the original number and continue
- * with the next 16 bits down, and so on. -- warlord at mit.edu
- * 2001/02/13
- */
- for (i = 48; i >=0; i-= 16) {
- bits = scm_ash(magnitude, SCM_MAKINUM(-i));
- c_bits = scm_num2ulong(scm_logand(bits, bits00to15_mask), SCM_ARG1, G_STRFUNC);
- c_result += ((long long)c_bits << i);
- magnitude = scm_difference(magnitude, scm_ash(bits, SCM_MAKINUM(i)));
- }
-
- if(scm_negative_p(num) != SCM_BOOL_F) {
- return(- c_result);
- }
- else {
- return(c_result);
- }
+ if (bits00to15_mask == SCM_BOOL_F)
+ {
+ bits00to15_mask = scm_ulong2num(0xFFFF);
+ scm_gc_protect_object (bits00to15_mask);
+ }
+
+ /*
+ * This isn't very complicated (IMHO). We work from the "top" of
+ * the number downwards. We assume this is no more than a 64-bit
+ * number, otherwise it will fail right away. Anyways, we keep
+ * taking the top 16 bits of the number and move it to c_result.
+ * Then we 'remove' those bits from the original number and continue
+ * with the next 16 bits down, and so on. -- warlord at mit.edu
+ * 2001/02/13
+ */
+ for (i = 48; i >= 0; i -= 16)
+ {
+ bits = scm_ash(magnitude, SCM_MAKINUM(-i));
+ c_bits = scm_num2ulong(scm_logand(bits, bits00to15_mask), SCM_ARG1, G_STRFUNC);
+ c_result += ((long long)c_bits << i);
+ magnitude = scm_difference(magnitude, scm_ash(bits, SCM_MAKINUM(i)));
+ }
+
+ if (scm_negative_p(num) != SCM_BOOL_F)
+ {
+ return(- c_result);
+ }
+ else
+ {
+ return(c_result);
+ }
#endif
}
int
gnc_gh_gint64_p(SCM num)
{
- static int initialized = 0;
- static SCM maxval;
- static SCM minval;
+ static int initialized = 0;
+ static SCM maxval;
+ static SCM minval;
- if (!initialized)
- {
- /* to be super safe, we have to build these manually because
- though we know that we have gint64's here, we *don't* know how
- to portably specify a 64bit constant to the compiler (i.e. like
- 0x7FFFFFFFFFFFFFFF). */
- gint64 tmp;
-
- tmp = 0x7FFFFFFF;
- tmp <<= 32;
- tmp |= 0xFFFFFFFF;
- maxval = gnc_gint64_to_scm(tmp);
+ if (!initialized)
+ {
+ /* to be super safe, we have to build these manually because
+ though we know that we have gint64's here, we *don't* know how
+ to portably specify a 64bit constant to the compiler (i.e. like
+ 0x7FFFFFFFFFFFFFFF). */
+ gint64 tmp;
- tmp = 0x80000000;
- tmp <<= 32;
- minval = gnc_gint64_to_scm(tmp);
+ tmp = 0x7FFFFFFF;
+ tmp <<= 32;
+ tmp |= 0xFFFFFFFF;
+ maxval = gnc_gint64_to_scm(tmp);
- scm_gc_protect_object(maxval);
- scm_gc_protect_object(minval);
- initialized = 1;
- }
+ tmp = 0x80000000;
+ tmp <<= 32;
+ minval = gnc_gint64_to_scm(tmp);
- return (scm_is_exact(num) &&
- (scm_geq_p(num, minval) != SCM_BOOL_F) &&
- (scm_leq_p(num, maxval) != SCM_BOOL_F));
+ scm_gc_protect_object(maxval);
+ scm_gc_protect_object(minval);
+ initialized = 1;
+ }
+
+ return (scm_is_exact(num) &&
+ (scm_geq_p(num, minval) != SCM_BOOL_F) &&
+ (scm_leq_p(num, maxval) != SCM_BOOL_F));
}
gnc_numeric
gnc_scm_to_numeric(SCM gncnum)
{
- static SCM get_num = SCM_BOOL_F;
- static SCM get_denom = SCM_BOOL_F;
-
- if(get_num == SCM_BOOL_F) {
- get_num = scm_c_eval_string("gnc:gnc-numeric-num");
- }
- if(get_denom == SCM_BOOL_F) {
- get_denom = scm_c_eval_string("gnc:gnc-numeric-denom");
- }
-
- return gnc_numeric_create(gnc_scm_to_gint64(scm_call_1(get_num, gncnum)),
- gnc_scm_to_gint64(scm_call_1(get_denom, gncnum)));
+ static SCM get_num = SCM_BOOL_F;
+ static SCM get_denom = SCM_BOOL_F;
+
+ if (get_num == SCM_BOOL_F)
+ {
+ get_num = scm_c_eval_string("gnc:gnc-numeric-num");
+ }
+ if (get_denom == SCM_BOOL_F)
+ {
+ get_denom = scm_c_eval_string("gnc:gnc-numeric-denom");
+ }
+
+ return gnc_numeric_create(gnc_scm_to_gint64(scm_call_1(get_num, gncnum)),
+ gnc_scm_to_gint64(scm_call_1(get_denom, gncnum)));
}
SCM
gnc_numeric_to_scm(gnc_numeric arg)
{
- static SCM maker = SCM_BOOL_F;
+ static SCM maker = SCM_BOOL_F;
- if(maker == SCM_BOOL_F) {
- maker = scm_c_eval_string("gnc:make-gnc-numeric");
- }
-
- return scm_call_2(maker, gnc_gint64_to_scm(gnc_numeric_num(arg)),
- gnc_gint64_to_scm(gnc_numeric_denom(arg)));
+ if (maker == SCM_BOOL_F)
+ {
+ maker = scm_c_eval_string("gnc:make-gnc-numeric");
+ }
+
+ return scm_call_2(maker, gnc_gint64_to_scm(gnc_numeric_num(arg)),
+ gnc_gint64_to_scm(gnc_numeric_denom(arg)));
}
int
gnc_numeric_p(SCM arg)
{
- static SCM type_p = SCM_BOOL_F;
- SCM ret = SCM_BOOL_F;
+ static SCM type_p = SCM_BOOL_F;
+ SCM ret = SCM_BOOL_F;
- if(type_p == SCM_BOOL_F) {
- type_p = scm_c_eval_string("gnc:gnc-numeric?");
- }
- ret = scm_call_1(type_p, arg);
+ if (type_p == SCM_BOOL_F)
+ {
+ type_p = scm_c_eval_string("gnc:gnc-numeric?");
+ }
+ ret = scm_call_1(type_p, arg);
- if(ret == SCM_BOOL_F) {
- return FALSE;
- }
- else {
- return TRUE;
- }
+ if (ret == SCM_BOOL_F)
+ {
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
}
@@ -2162,7 +2352,8 @@
if (!x) return SCM_BOOL_F;
stype = SWIG_TypeQuery(type_str);
- if (!stype) {
+ if (!stype)
+ {
PERR("Unknown SWIG Type: %s ", type_str);
return SCM_BOOL_F;
}
@@ -2176,7 +2367,8 @@
swig_type_info * stype = NULL;
stype = SWIG_TypeQuery(type_str);
- if (!stype) {
+ if (!stype)
+ {
PERR("Unknown SWIG Type: %s ", type_str);
return NULL;
}
Modified: gnucash/trunk/src/engine/glib-helpers.c
===================================================================
--- gnucash/trunk/src/engine/glib-helpers.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/glib-helpers.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -35,13 +35,13 @@
static SCM
glist_to_scm_list_helper(GList *glist, swig_type_info *wct)
{
- SCM list = SCM_EOL;
- GList *node;
+ SCM list = SCM_EOL;
+ GList *node;
- for (node = glist; node; node = node->next)
- list = scm_cons(SWIG_NewPointerObj(node->data, wct, 0), list);
+ for (node = glist; node; node = node->next)
+ list = scm_cons(SWIG_NewPointerObj(node->data, wct, 0), list);
- return scm_reverse (list);
+ return scm_reverse (list);
}
SCM
@@ -55,35 +55,35 @@
GList *
gnc_scm_list_to_glist(SCM rest)
{
- GList *result = NULL;
- SCM scm_item;
+ GList *result = NULL;
+ SCM scm_item;
- SWIG_GetModule(NULL); /* Work-around for SWIG bug. */
- SCM_ASSERT(scm_is_list(rest), rest, SCM_ARG1, "gnc_scm_list_to_glist");
+ SWIG_GetModule(NULL); /* Work-around for SWIG bug. */
+ SCM_ASSERT(scm_is_list(rest), rest, SCM_ARG1, "gnc_scm_list_to_glist");
- while(!scm_is_null(rest))
- {
- void *item;
+ while (!scm_is_null(rest))
+ {
+ void *item;
- scm_item = SCM_CAR(rest);
- rest = SCM_CDR(rest);
+ scm_item = SCM_CAR(rest);
+ rest = SCM_CDR(rest);
- if (scm_item == SCM_BOOL_F)
- {
- result = g_list_prepend(result, NULL);
+ if (scm_item == SCM_BOOL_F)
+ {
+ result = g_list_prepend(result, NULL);
+ }
+ else
+ {
+ if (!SWIG_IsPointer(scm_item))
+ scm_misc_error("gnc_scm_list_to_glist",
+ "Item in list not a wcp.", scm_item);
+
+ item = (void *)SWIG_PointerAddress(scm_item);
+ result = g_list_prepend(result, item);
+ }
}
- else
- {
- if (!SWIG_IsPointer(scm_item))
- scm_misc_error("gnc_scm_list_to_glist",
- "Item in list not a wcp.", scm_item);
-
- item = (void *)SWIG_PointerAddress(scm_item);
- result = g_list_prepend(result, item);
- }
- }
- return g_list_reverse(result);
+ return g_list_reverse(result);
}
/********************************************************************
@@ -95,13 +95,13 @@
SCM
gnc_glist_string_to_scm(GList *glist)
{
- SCM list = SCM_EOL;
- GList *node;
+ SCM list = SCM_EOL;
+ GList *node;
- for (node = glist; node; node = node->next)
- list = scm_cons (scm_makfrom0str(node->data), list);
+ for (node = glist; node; node = node->next)
+ list = scm_cons (scm_makfrom0str(node->data), list);
- return scm_reverse (list);
+ return scm_reverse (list);
}
@@ -117,33 +117,33 @@
GList *
gnc_scm_to_glist_string(SCM list)
{
- GList *glist = NULL;
+ GList *glist = NULL;
- while (!scm_is_null (list))
- {
- const gchar * str = scm_to_locale_string (SCM_CAR(list));
- if (str)
- glist = g_list_prepend (glist, g_strdup (str));
- list = SCM_CDR (list);
- }
+ while (!scm_is_null (list))
+ {
+ const gchar * str = scm_to_locale_string (SCM_CAR(list));
+ if (str)
+ glist = g_list_prepend (glist, g_strdup (str));
+ list = SCM_CDR (list);
+ }
- return g_list_reverse (glist);
+ return g_list_reverse (glist);
}
GSList *
gnc_scm_to_gslist_string(SCM list)
{
- GSList *gslist = NULL;
+ GSList *gslist = NULL;
- while (!scm_is_null (list))
- {
- const gchar * str = scm_to_locale_string (SCM_CAR(list));
- if (str)
- gslist = g_slist_prepend (gslist, g_strdup (str));
- list = SCM_CDR (list);
- }
+ while (!scm_is_null (list))
+ {
+ const gchar * str = scm_to_locale_string (SCM_CAR(list));
+ if (str)
+ gslist = g_slist_prepend (gslist, g_strdup (str));
+ list = SCM_CDR (list);
+ }
- return g_slist_reverse (gslist);
+ return g_slist_reverse (gslist);
}
/********************************************************************
@@ -151,6 +151,7 @@
********************************************************************/
int
-gnc_glist_string_p(SCM list) {
- return scm_is_list(list);
+gnc_glist_string_p(SCM list)
+{
+ return scm_is_list(list);
}
Modified: gnucash/trunk/src/engine/gnc-associate-account.c
===================================================================
--- gnucash/trunk/src/engine/gnc-associate-account.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/gnc-associate-account.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -2,7 +2,7 @@
* gnc-associate-account.h : api for associating income and *
* expense accounts with stock/mutual fund accounts, for tracking *
* dividends, brokerage, and other stock-related expenses and *
- * income so that they can be reported *
+ * income so that they can be reported *
* Copyright 2000 Gnumatic Incorporated *
* Written by Robert Merkel <rgmerk at mira.net> *
* *
@@ -41,149 +41,151 @@
"income-interest",
"income-dividend"
"income-long-term-capital-gain",
- "income-short-term-capital-gain"};
+ "income-short-term-capital-gain"
+ };
/* Maps GNCTrackingExpenseCategory to string keys. If this enum
changes, update */
static char * expense_to_key[] = {"expense-miscellaneous",
- "expense-commission"};
+ "expense-commission"
+ };
static KvpFrame *
get_assoc_acc_frame(KvpFrame *account_frame)
{
- KvpFrame *assoc_acc_frame;
- KvpValue *assoc_acc_frame_kvpvalue =
- kvp_frame_get_slot(account_frame, "associated-accounts");
+ KvpFrame *assoc_acc_frame;
+ KvpValue *assoc_acc_frame_kvpvalue =
+ kvp_frame_get_slot(account_frame, "associated-accounts");
- assoc_acc_frame = kvp_value_get_frame(assoc_acc_frame_kvpvalue);
- if(!assoc_acc_frame)
- {
- assoc_acc_frame = kvp_frame_new();
- assoc_acc_frame_kvpvalue = kvp_value_new_frame(assoc_acc_frame);
- kvp_frame_set_slot(account_frame, "associated-accounts",
- assoc_acc_frame_kvpvalue);
- }
+ assoc_acc_frame = kvp_value_get_frame(assoc_acc_frame_kvpvalue);
+ if (!assoc_acc_frame)
+ {
+ assoc_acc_frame = kvp_frame_new();
+ assoc_acc_frame_kvpvalue = kvp_value_new_frame(assoc_acc_frame);
+ kvp_frame_set_slot(account_frame, "associated-accounts",
+ assoc_acc_frame_kvpvalue);
+ }
- return assoc_acc_frame;
+ return assoc_acc_frame;
}
static void
-back_associate_expense_accounts(Account *stock_account,
- GList *accounts,
- GNCTrackingExpenseCategory category)
+back_associate_expense_accounts(Account *stock_account,
+ GList *accounts,
+ GNCTrackingExpenseCategory category)
{
- KvpFrame *acc_frame;
- KvpValue *val, *stock_acc_guid_kvpval, *stock_acc_category_kvpval;
- const GUID *stock_acc_guid;
- const GUID *existing_acc_guid;
+ KvpFrame *acc_frame;
+ KvpValue *val, *stock_acc_guid_kvpval, *stock_acc_category_kvpval;
+ const GUID *stock_acc_guid;
+ const GUID *existing_acc_guid;
- stock_acc_guid = xaccAccountGetGUID(stock_account);
- stock_acc_guid_kvpval = kvp_value_new_guid(stock_acc_guid);
+ stock_acc_guid = xaccAccountGetGUID(stock_account);
+ stock_acc_guid_kvpval = kvp_value_new_guid(stock_acc_guid);
- stock_acc_category_kvpval = kvp_value_new_string(expense_to_key[category]);
+ stock_acc_category_kvpval = kvp_value_new_string(expense_to_key[category]);
- for(; accounts; accounts = g_list_next(accounts))
- {
- acc_frame = xaccAccountGetSlots(accounts->data);
- g_return_if_fail((val = kvp_frame_get_slot(acc_frame,
- "associated-stock-account")));
- g_return_if_fail(kvp_value_get_type(val) == KVP_TYPE_GUID);
- existing_acc_guid = kvp_value_get_guid(val);
+ for (; accounts; accounts = g_list_next(accounts))
+ {
+ acc_frame = xaccAccountGetSlots(accounts->data);
+ g_return_if_fail((val = kvp_frame_get_slot(acc_frame,
+ "associated-stock-account")));
+ g_return_if_fail(kvp_value_get_type(val) == KVP_TYPE_GUID);
+ existing_acc_guid = kvp_value_get_guid(val);
- kvp_frame_set_slot_nc(acc_frame, "associated-stock-account",
- stock_acc_guid_kvpval);
-
- kvp_frame_set_slot_nc(acc_frame, "associated-stock-account-category",
- stock_acc_category_kvpval);
- }
+ kvp_frame_set_slot_nc(acc_frame, "associated-stock-account",
+ stock_acc_guid_kvpval);
- return;
+ kvp_frame_set_slot_nc(acc_frame, "associated-stock-account-category",
+ stock_acc_category_kvpval);
+ }
+
+ return;
}
static void
-back_associate_income_accounts(Account *stock_account,
- GList *accounts,
- GNCTrackingIncomeCategory category)
+back_associate_income_accounts(Account *stock_account,
+ GList *accounts,
+ GNCTrackingIncomeCategory category)
{
- KvpFrame *acc_frame;
- KvpValue *val, *stock_acc_guid_kvpval, *stock_acc_category_kvpval;
- const GUID *stock_acc_guid;
- const GUID *existing_acc_guid;
+ KvpFrame *acc_frame;
+ KvpValue *val, *stock_acc_guid_kvpval, *stock_acc_category_kvpval;
+ const GUID *stock_acc_guid;
+ const GUID *existing_acc_guid;
- stock_acc_guid = xaccAccountGetGUID(stock_account);
- stock_acc_guid_kvpval = kvp_value_new_guid(stock_acc_guid);
+ stock_acc_guid = xaccAccountGetGUID(stock_account);
+ stock_acc_guid_kvpval = kvp_value_new_guid(stock_acc_guid);
- stock_acc_category_kvpval = kvp_value_new_string(income_to_key[category]);
+ stock_acc_category_kvpval = kvp_value_new_string(income_to_key[category]);
- for(; accounts; accounts = g_list_next(accounts))
- {
- acc_frame = xaccAccountGetSlots(accounts->data);
- g_return_if_fail((val = kvp_frame_get_slot(acc_frame,
- "associated-stock-account")));
- g_return_if_fail(kvp_value_get_type(val) == KVP_TYPE_GUID);
- existing_acc_guid = kvp_value_get_guid(val);
+ for (; accounts; accounts = g_list_next(accounts))
+ {
+ acc_frame = xaccAccountGetSlots(accounts->data);
+ g_return_if_fail((val = kvp_frame_get_slot(acc_frame,
+ "associated-stock-account")));
+ g_return_if_fail(kvp_value_get_type(val) == KVP_TYPE_GUID);
+ existing_acc_guid = kvp_value_get_guid(val);
- kvp_frame_set_slot_nc(acc_frame, "associated-stock-account",
- stock_acc_guid_kvpval);
- kvp_frame_set_slot_nc(acc_frame, "associated-stock-account-category",
- stock_acc_category_kvpval);
- }
+ kvp_frame_set_slot_nc(acc_frame, "associated-stock-account",
+ stock_acc_guid_kvpval);
+ kvp_frame_set_slot_nc(acc_frame, "associated-stock-account-category",
+ stock_acc_category_kvpval);
+ }
- return;
-}
-
+ return;
+}
+
static KvpValue *
make_kvpd_on_list(GList *account_list)
{
- GList *iter;
- KvpValue *retval;
- KvpValue *guid_kvp;
- GList *kvp_acc_list = NULL;
- const GUID *acc_id;
+ GList *iter;
+ KvpValue *retval;
+ KvpValue *guid_kvp;
+ GList *kvp_acc_list = NULL;
+ const GUID *acc_id;
- for(iter = account_list; iter; iter = g_list_next(iter))
- {
- GNCAccountType type;
- Account *current_account;
+ for (iter = account_list; iter; iter = g_list_next(iter))
+ {
+ GNCAccountType type;
+ Account *current_account;
- current_account = iter->data;
- type = xaccAccountGetType(current_account);
- g_return_val_if_fail(type == ACCT_TYPE_INCOME || type == ACCT_TYPE_EXPENSE,
- NULL);
+ current_account = iter->data;
+ type = xaccAccountGetType(current_account);
+ g_return_val_if_fail(type == ACCT_TYPE_INCOME || type == ACCT_TYPE_EXPENSE,
+ NULL);
- acc_id = xaccAccountGetGUID(current_account);
- guid_kvp = kvp_value_new_guid(acc_id);
- kvp_acc_list = g_list_prepend(kvp_acc_list, guid_kvp);
- }
+ acc_id = xaccAccountGetGUID(current_account);
+ guid_kvp = kvp_value_new_guid(acc_id);
+ kvp_acc_list = g_list_prepend(kvp_acc_list, guid_kvp);
+ }
- kvp_acc_list = g_list_reverse(kvp_acc_list);
+ kvp_acc_list = g_list_reverse(kvp_acc_list);
- retval = kvp_value_new_glist_nc(kvp_acc_list);
- return retval;
+ retval = kvp_value_new_glist_nc(kvp_acc_list);
+ return retval;
}
static GList *
de_kvp_account_list(KvpValue *kvpd_list, QofBook *book)
-{
- GList *guid_account_list = kvp_value_get_glist(kvpd_list);
- if (guid_account_list)
- {
- GList *expense_acc_list= NULL;
- for(; guid_account_list; guid_account_list=g_list_next(guid_account_list))
+{
+ GList *guid_account_list = kvp_value_get_glist(kvpd_list);
+ if (guid_account_list)
{
- expense_acc_list = g_list_prepend(expense_acc_list,
- xaccAccountLookup(guid_account_list->data, book));
+ GList *expense_acc_list = NULL;
+ for (; guid_account_list; guid_account_list = g_list_next(guid_account_list))
+ {
+ expense_acc_list = g_list_prepend(expense_acc_list,
+ xaccAccountLookup(guid_account_list->data, book));
+ }
+
+ expense_acc_list = g_list_reverse(expense_acc_list);
+ return expense_acc_list;
}
-
- expense_acc_list = g_list_reverse(expense_acc_list);
- return expense_acc_list;
- }
- else
- {
- return NULL;
- }
-}
+ else
+ {
+ return NULL;
+ }
+}
/*********************************************************************\
* gnc_tracking_associate_income_accounts *
@@ -201,29 +203,29 @@
* Returns : void *
\*********************************************************************/
-void
-gnc_tracking_associate_income_accounts(Account *stock_account,
- GNCTrackingIncomeCategory category,
+void
+gnc_tracking_associate_income_accounts(Account *stock_account,
+ GNCTrackingIncomeCategory category,
GList *account_list)
{
- KvpFrame *account_frame, *inc_account_frame;
- KvpValue *kvpd_on_account_list;
+ KvpFrame *account_frame, *inc_account_frame;
+ KvpValue *kvpd_on_account_list;
- g_return_if_fail(stock_account);
- g_return_if_fail(xaccAccountIsPriced(stock_account));
- account_frame = xaccAccountGetSlots(stock_account);
- g_return_if_fail(account_frame);
- g_return_if_fail(category >= 0);
- g_return_if_fail(category < GNC_TR_INC_N_CATEGORIES);
-
- inc_account_frame = get_assoc_acc_frame(account_frame);
- kvpd_on_account_list = make_kvpd_on_list(account_list);
+ g_return_if_fail(stock_account);
+ g_return_if_fail(xaccAccountIsPriced(stock_account));
+ account_frame = xaccAccountGetSlots(stock_account);
+ g_return_if_fail(account_frame);
+ g_return_if_fail(category >= 0);
+ g_return_if_fail(category < GNC_TR_INC_N_CATEGORIES);
- back_associate_income_accounts(stock_account, account_list, category);
+ inc_account_frame = get_assoc_acc_frame(account_frame);
+ kvpd_on_account_list = make_kvpd_on_list(account_list);
- kvp_frame_set_slot_nc(inc_account_frame,
- income_to_key[category],
- kvpd_on_account_list);
+ back_associate_income_accounts(stock_account, account_list, category);
+
+ kvp_frame_set_slot_nc(inc_account_frame,
+ income_to_key[category],
+ kvpd_on_account_list);
}
/*********************************************************************\
@@ -246,24 +248,24 @@
GNCTrackingExpenseCategory category,
GList *account_list)
{
- KvpFrame *account_frame, *expense_acc_frame;
- KvpValue *kvpd_on_account_list;
+ KvpFrame *account_frame, *expense_acc_frame;
+ KvpValue *kvpd_on_account_list;
- g_return_if_fail(stock_account);
- g_return_if_fail(xaccAccountIsPriced(stock_account));
- account_frame = xaccAccountGetSlots(stock_account);
- g_return_if_fail(account_frame);
- g_return_if_fail(category >= 0);
- g_return_if_fail(category < GNC_TR_EXP_N_CATEGORIES);
-
- expense_acc_frame = get_assoc_acc_frame(account_frame);
- kvpd_on_account_list = make_kvpd_on_list(account_list);
+ g_return_if_fail(stock_account);
+ g_return_if_fail(xaccAccountIsPriced(stock_account));
+ account_frame = xaccAccountGetSlots(stock_account);
+ g_return_if_fail(account_frame);
+ g_return_if_fail(category >= 0);
+ g_return_if_fail(category < GNC_TR_EXP_N_CATEGORIES);
- back_associate_expense_accounts(stock_account, account_list, category);
+ expense_acc_frame = get_assoc_acc_frame(account_frame);
+ kvpd_on_account_list = make_kvpd_on_list(account_list);
- kvp_frame_set_slot_nc(expense_acc_frame,
- expense_to_key[category],
- kvpd_on_account_list);
+ back_associate_expense_accounts(stock_account, account_list, category);
+
+ kvp_frame_set_slot_nc(expense_acc_frame,
+ expense_to_key[category],
+ kvpd_on_account_list);
}
/*********************************************************************\
@@ -279,25 +281,25 @@
\*********************************************************************/
GList *
-gnc_tracking_find_expense_accounts(Account *stock_account,
+gnc_tracking_find_expense_accounts(Account *stock_account,
GNCTrackingExpenseCategory category)
{
- KvpFrame *account_frame, *expense_acc_frame;
- KvpValue *kvpd_on_account_list;
+ KvpFrame *account_frame, *expense_acc_frame;
+ KvpValue *kvpd_on_account_list;
- g_return_val_if_fail(xaccAccountIsPriced(stock_account), NULL);
- g_return_val_if_fail(category >= 0 && category < GNC_TR_EXP_N_CATEGORIES,
- NULL);
+ g_return_val_if_fail(xaccAccountIsPriced(stock_account), NULL);
+ g_return_val_if_fail(category >= 0 && category < GNC_TR_EXP_N_CATEGORIES,
+ NULL);
- account_frame = xaccAccountGetSlots(stock_account);
- g_return_val_if_fail(account_frame, NULL);
+ account_frame = xaccAccountGetSlots(stock_account);
+ g_return_val_if_fail(account_frame, NULL);
- expense_acc_frame = get_assoc_acc_frame(account_frame);
- kvpd_on_account_list = kvp_frame_get_slot(account_frame,
- expense_to_key[category]);
+ expense_acc_frame = get_assoc_acc_frame(account_frame);
+ kvpd_on_account_list = kvp_frame_get_slot(account_frame,
+ expense_to_key[category]);
- return de_kvp_account_list(kvpd_on_account_list,
- gnc_account_get_book(stock_account));
+ return de_kvp_account_list(kvpd_on_account_list,
+ gnc_account_get_book(stock_account));
}
/*********************************************************************\
@@ -312,25 +314,25 @@
* Returns : A GList of Account *'s listing the accounts *
\*********************************************************************/
GList *
-gnc_tracking_find_income_accounts(Account *stock_account,
+gnc_tracking_find_income_accounts(Account *stock_account,
GNCTrackingIncomeCategory category)
{
- KvpFrame *account_frame, *income_acc_frame;
- KvpValue *kvpd_on_account_list;
+ KvpFrame *account_frame, *income_acc_frame;
+ KvpValue *kvpd_on_account_list;
- g_return_val_if_fail(xaccAccountIsPriced(stock_account), NULL);
- g_return_val_if_fail(category >= 0 && category < GNC_TR_INC_N_CATEGORIES,
- NULL);
+ g_return_val_if_fail(xaccAccountIsPriced(stock_account), NULL);
+ g_return_val_if_fail(category >= 0 && category < GNC_TR_INC_N_CATEGORIES,
+ NULL);
- account_frame = xaccAccountGetSlots(stock_account);
- g_return_val_if_fail(account_frame, NULL);
+ account_frame = xaccAccountGetSlots(stock_account);
+ g_return_val_if_fail(account_frame, NULL);
- income_acc_frame = get_assoc_acc_frame(account_frame);
- kvpd_on_account_list = kvp_frame_get_slot(income_acc_frame,
- income_to_key[category]);
-
- return de_kvp_account_list(kvpd_on_account_list,
- gnc_account_get_book(stock_account));
+ income_acc_frame = get_assoc_acc_frame(account_frame);
+ kvpd_on_account_list = kvp_frame_get_slot(income_acc_frame,
+ income_to_key[category]);
+
+ return de_kvp_account_list(kvpd_on_account_list,
+ gnc_account_get_book(stock_account));
}
/*********************************************************************\
@@ -345,17 +347,17 @@
GList *
gnc_tracking_find_all_expense_accounts(Account *stock_account)
{
- GList *complete_list=NULL;
- int i;
+ GList *complete_list = NULL;
+ int i;
- for(i = 0; i < GNC_TR_EXP_N_CATEGORIES; i++)
- {
- complete_list =
- g_list_concat(complete_list,
- gnc_tracking_find_expense_accounts(stock_account, i));
- }
+ for (i = 0; i < GNC_TR_EXP_N_CATEGORIES; i++)
+ {
+ complete_list =
+ g_list_concat(complete_list,
+ gnc_tracking_find_expense_accounts(stock_account, i));
+ }
- return complete_list;
+ return complete_list;
}
/*********************************************************************\
@@ -370,16 +372,16 @@
GList *
gnc_tracking_find_all_income_accounts(Account *stock_account)
{
- GList *complete_list= NULL;
- int i;
+ GList *complete_list = NULL;
+ int i;
- for(i = 0; i < GNC_TR_EXP_N_CATEGORIES; i++)
- {
- complete_list = g_list_concat(complete_list,
- gnc_tracking_find_expense_accounts(stock_account,
- i));
- }
- return complete_list;
+ for (i = 0; i < GNC_TR_EXP_N_CATEGORIES; i++)
+ {
+ complete_list = g_list_concat(complete_list,
+ gnc_tracking_find_expense_accounts(stock_account,
+ i));
+ }
+ return complete_list;
}
/*********************************************************************\
@@ -396,7 +398,7 @@
Account *
gnc_tracking_find_stock_account(Account *inc_or_expense_acc)
{
- return NULL;
+ return NULL;
}
/*********************************************************************\
@@ -411,71 +413,71 @@
* Returns : void *
\*********************************************************************/
-void
+void
gnc_tracking_dissociate_account(Account *inc_or_expense_account)
{
- GNCAccountType type;
- KvpFrame *stock_account_kvpframe, *assoc_acc_kvpframe;
- KvpFrame *current_account_kvpframe;
- KvpValue *stock_account_kvpval, *acc_list_kvpval, *category_kvpval;
- const GUID *stock_account_guid, *inc_or_expense_account_guid, *current_guid;
- Account *stock_account;
- char *category_name;
- GList *assoc_acc_list, *assoc_acc_list_start;
+ GNCAccountType type;
+ KvpFrame *stock_account_kvpframe, *assoc_acc_kvpframe;
+ KvpFrame *current_account_kvpframe;
+ KvpValue *stock_account_kvpval, *acc_list_kvpval, *category_kvpval;
+ const GUID *stock_account_guid, *inc_or_expense_account_guid, *current_guid;
+ Account *stock_account;
+ char *category_name;
+ GList *assoc_acc_list, *assoc_acc_list_start;
- type = xaccAccountGetType(inc_or_expense_account);
-
- g_return_if_fail(type == ACCT_TYPE_INCOME || type == ACCT_TYPE_EXPENSE);
-
- current_account_kvpframe = xaccAccountGetSlots(inc_or_expense_account);
+ type = xaccAccountGetType(inc_or_expense_account);
- stock_account_kvpval = kvp_frame_get_slot(current_account_kvpframe,
- "associated-stock-account");
-
- stock_account_guid = kvp_value_get_guid(stock_account_kvpval);
+ g_return_if_fail(type == ACCT_TYPE_INCOME || type == ACCT_TYPE_EXPENSE);
- category_kvpval = kvp_frame_get_slot(current_account_kvpframe,
- "associated-stock-account-category");
- category_name = kvp_value_get_string(category_kvpval);
+ current_account_kvpframe = xaccAccountGetSlots(inc_or_expense_account);
+ stock_account_kvpval = kvp_frame_get_slot(current_account_kvpframe,
+ "associated-stock-account");
- inc_or_expense_account_guid = xaccAccountGetGUID(inc_or_expense_account);
- stock_account = xaccAccountLookup
- (stock_account_guid, gnc_account_get_book(inc_or_expense_account));
+ stock_account_guid = kvp_value_get_guid(stock_account_kvpval);
- stock_account_kvpframe = xaccAccountGetSlots(stock_account);
+ category_kvpval = kvp_frame_get_slot(current_account_kvpframe,
+ "associated-stock-account-category");
+ category_name = kvp_value_get_string(category_kvpval);
- g_return_if_fail((stock_account_kvpval =
- kvp_frame_get_slot(stock_account_kvpframe,
- "associated-accounts")));
- assoc_acc_kvpframe = kvp_value_get_frame(stock_account_kvpval);
+ inc_or_expense_account_guid = xaccAccountGetGUID(inc_or_expense_account);
+ stock_account = xaccAccountLookup
+ (stock_account_guid, gnc_account_get_book(inc_or_expense_account));
- g_return_if_fail((acc_list_kvpval = kvp_frame_get_slot(assoc_acc_kvpframe,
- category_name)));
- g_return_if_fail((assoc_acc_list_start =
- kvp_value_get_glist(acc_list_kvpval)));
-
- for(assoc_acc_list = assoc_acc_list_start;
- assoc_acc_list;
- assoc_acc_list = g_list_next(assoc_acc_list))
- {
- g_return_if_fail((current_guid = kvp_value_get_guid(assoc_acc_list->data)));
- if(guid_equal(current_guid, inc_or_expense_account_guid))
+ stock_account_kvpframe = xaccAccountGetSlots(stock_account);
+
+ g_return_if_fail((stock_account_kvpval =
+ kvp_frame_get_slot(stock_account_kvpframe,
+ "associated-accounts")));
+
+ assoc_acc_kvpframe = kvp_value_get_frame(stock_account_kvpval);
+
+ g_return_if_fail((acc_list_kvpval = kvp_frame_get_slot(assoc_acc_kvpframe,
+ category_name)));
+ g_return_if_fail((assoc_acc_list_start =
+ kvp_value_get_glist(acc_list_kvpval)));
+
+ for (assoc_acc_list = assoc_acc_list_start;
+ assoc_acc_list;
+ assoc_acc_list = g_list_next(assoc_acc_list))
{
- assoc_acc_list_start =
- g_list_remove_link(assoc_acc_list_start, assoc_acc_list);
- g_list_free_1(assoc_acc_list);
- acc_list_kvpval = kvp_value_new_glist_nc(assoc_acc_list);
- kvp_frame_set_slot_nc(assoc_acc_kvpframe,
- category_name,
- acc_list_kvpval);
- return;
+ g_return_if_fail((current_guid = kvp_value_get_guid(assoc_acc_list->data)));
+ if (guid_equal(current_guid, inc_or_expense_account_guid))
+ {
+ assoc_acc_list_start =
+ g_list_remove_link(assoc_acc_list_start, assoc_acc_list);
+ g_list_free_1(assoc_acc_list);
+ acc_list_kvpval = kvp_value_new_glist_nc(assoc_acc_list);
+ kvp_frame_set_slot_nc(assoc_acc_kvpframe,
+ category_name,
+ acc_list_kvpval);
+ return;
+ }
}
- }
- /* should never happen */
- PERR("Income/Expense account and stock account disagree on association");
+ /* should never happen */
+ PERR("Income/Expense account and stock account disagree on association");
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/trunk/src/engine/gnc-budget.c
===================================================================
--- gnucash/trunk/src/engine/gnc-budget.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/gnc-budget.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -37,34 +37,37 @@
static QofLogModule log_module = GNC_MOD_ENGINE;
-enum {
- PROP_0,
- PROP_NAME,
- PROP_DESCRIPTION,
- PROP_NUM_PERIODS,
- PROP_RECURRENCE,
+enum
+{
+ PROP_0,
+ PROP_NAME,
+ PROP_DESCRIPTION,
+ PROP_NUM_PERIODS,
+ PROP_RECURRENCE,
};
struct budget_s
{
- QofInstance inst;
+ QofInstance inst;
};
-typedef struct {
+typedef struct
+{
QofInstanceClass parent_class;
} BudgetClass;
-typedef struct BudgetPrivate {
+typedef struct BudgetPrivate
+{
/* The name is an arbitrary string assigned by the user. */
gchar* name;
- /* The description is an arbitrary string assigned by the user. */
+ /* The description is an arbitrary string assigned by the user. */
gchar* description;
- /* Recurrence (period info) for the budget */
+ /* Recurrence (period info) for the budget */
Recurrence recurrence;
- /* Number of periods */
+ /* Number of periods */
guint num_periods;
} BudgetPrivate;
@@ -73,7 +76,7 @@
struct _GncBudgetClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
/* GObject Initialization */
@@ -85,13 +88,13 @@
BudgetPrivate* priv;
GDate date;
- priv = GET_PRIVATE(budget);
- priv->name = CACHE_INSERT(_("Unnamed Budget"));
- priv->description = CACHE_INSERT("");
+ priv = GET_PRIVATE(budget);
+ priv->name = CACHE_INSERT(_("Unnamed Budget"));
+ priv->description = CACHE_INSERT("");
- priv->num_periods = 12;
+ priv->num_periods = 12;
g_date_set_time_t(&date, time(NULL));
- g_date_subtract_days(&date, g_date_get_day(&date)-1);
+ g_date_subtract_days(&date, g_date_get_day(&date) - 1);
recurrenceSet(&priv->recurrence, 1, PERIOD_MONTH, &date, WEEKEND_ADJ_NONE);
}
@@ -109,65 +112,67 @@
static void
gnc_budget_get_property( GObject* object,
- guint prop_id,
- GValue* value,
- GParamSpec* pspec)
+ guint prop_id,
+ GValue* value,
+ GParamSpec* pspec)
{
GncBudget* budget;
- BudgetPrivate* priv;
+ BudgetPrivate* priv;
- g_return_if_fail(GNC_IS_BUDGET(object));
+ g_return_if_fail(GNC_IS_BUDGET(object));
- budget = GNC_BUDGET(object);
- priv = GET_PRIVATE(budget);
- switch( prop_id ) {
- case PROP_NAME:
- g_value_set_string(value, priv->name);
- break;
- case PROP_DESCRIPTION:
- g_value_set_string(value, priv->description);
- break;
- case PROP_NUM_PERIODS:
- g_value_set_uint(value, priv->num_periods);
- break;
- case PROP_RECURRENCE:
- /* TODO: Make this a BOXED type */
- g_value_set_pointer(value, &priv->recurrence);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
+ budget = GNC_BUDGET(object);
+ priv = GET_PRIVATE(budget);
+ switch ( prop_id )
+ {
+ case PROP_NAME:
+ g_value_set_string(value, priv->name);
+ break;
+ case PROP_DESCRIPTION:
+ g_value_set_string(value, priv->description);
+ break;
+ case PROP_NUM_PERIODS:
+ g_value_set_uint(value, priv->num_periods);
+ break;
+ case PROP_RECURRENCE:
+ /* TODO: Make this a BOXED type */
+ g_value_set_pointer(value, &priv->recurrence);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
}
static void
gnc_budget_set_property( GObject* object,
- guint prop_id,
- const GValue* value,
- GParamSpec* pspec)
+ guint prop_id,
+ const GValue* value,
+ GParamSpec* pspec)
{
GncBudget* budget;
- g_return_if_fail(GNC_IS_BUDGET(object));
+ g_return_if_fail(GNC_IS_BUDGET(object));
- budget = GNC_BUDGET(object);
- switch( prop_id ) {
- case PROP_NAME:
- gnc_budget_set_name(budget, g_value_get_string(value));
- break;
- case PROP_DESCRIPTION:
- gnc_budget_set_description(budget, g_value_get_string(value));
- break;
- case PROP_NUM_PERIODS:
- gnc_budget_set_num_periods(budget, g_value_get_uint(value));
- break;
- case PROP_RECURRENCE:
- gnc_budget_set_recurrence(budget, g_value_get_pointer(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
+ budget = GNC_BUDGET(object);
+ switch ( prop_id )
+ {
+ case PROP_NAME:
+ gnc_budget_set_name(budget, g_value_get_string(value));
+ break;
+ case PROP_DESCRIPTION:
+ gnc_budget_set_description(budget, g_value_get_string(value));
+ break;
+ case PROP_NUM_PERIODS:
+ gnc_budget_set_num_periods(budget, g_value_get_uint(value));
+ break;
+ case PROP_RECURRENCE:
+ gnc_budget_set_recurrence(budget, g_value_get_pointer(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
}
static void
@@ -175,76 +180,76 @@
{
GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
- gobject_class->dispose = gnc_budget_dispose;
- gobject_class->finalize = gnc_budget_finalize;
- gobject_class->get_property = gnc_budget_get_property;
- gobject_class->set_property = gnc_budget_set_property;
+ gobject_class->dispose = gnc_budget_dispose;
+ gobject_class->finalize = gnc_budget_finalize;
+ gobject_class->get_property = gnc_budget_get_property;
+ gobject_class->set_property = gnc_budget_set_property;
- g_type_class_add_private(klass, sizeof(BudgetPrivate));
+ g_type_class_add_private(klass, sizeof(BudgetPrivate));
- g_object_class_install_property(
- gobject_class,
- PROP_NAME,
- g_param_spec_string( "name",
- "Budget Name",
- "The name is an arbitrary string "
- "assigned by the user. It is intended "
- "to be a short, 5 to 30 character long string "
- "that is displayed by the GUI as the "
- "budget mnemonic",
- NULL,
- G_PARAM_READWRITE));
+ g_object_class_install_property(
+ gobject_class,
+ PROP_NAME,
+ g_param_spec_string( "name",
+ "Budget Name",
+ "The name is an arbitrary string "
+ "assigned by the user. It is intended "
+ "to be a short, 5 to 30 character long string "
+ "that is displayed by the GUI as the "
+ "budget mnemonic",
+ NULL,
+ G_PARAM_READWRITE));
- g_object_class_install_property(
- gobject_class,
- PROP_DESCRIPTION,
- g_param_spec_string( "description",
- "Budget Description",
- "The description is an arbitrary string "
- "assigned by the user. It is intended "
- "to be a longer, 1-5 sentence description of "
- "what the budget is all about.",
- NULL,
- G_PARAM_READWRITE));
+ g_object_class_install_property(
+ gobject_class,
+ PROP_DESCRIPTION,
+ g_param_spec_string( "description",
+ "Budget Description",
+ "The description is an arbitrary string "
+ "assigned by the user. It is intended "
+ "to be a longer, 1-5 sentence description of "
+ "what the budget is all about.",
+ NULL,
+ G_PARAM_READWRITE));
- g_object_class_install_property(
- gobject_class,
- PROP_NUM_PERIODS,
- g_param_spec_uint( "num-periods",
- "Number of Periods",
- "The number of periods for this budget.",
- 0,
- G_MAXUINT32,
- 12,
- G_PARAM_READWRITE));
+ g_object_class_install_property(
+ gobject_class,
+ PROP_NUM_PERIODS,
+ g_param_spec_uint( "num-periods",
+ "Number of Periods",
+ "The number of periods for this budget.",
+ 0,
+ G_MAXUINT32,
+ 12,
+ G_PARAM_READWRITE));
- g_object_class_install_property(
- gobject_class,
- PROP_RECURRENCE,
- g_param_spec_pointer( "recurrence",
- "Budget Recurrence",
- "about.",
- G_PARAM_READWRITE));
+ g_object_class_install_property(
+ gobject_class,
+ PROP_RECURRENCE,
+ g_param_spec_pointer( "recurrence",
+ "Budget Recurrence",
+ "about.",
+ G_PARAM_READWRITE));
}
static void commit_err (QofInstance *inst, QofBackendError errcode)
{
- PERR ("Failed to commit: %d", errcode);
- gnc_engine_signal_commit_error( errcode );
+ PERR ("Failed to commit: %d", errcode);
+ gnc_engine_signal_commit_error( errcode );
}
static void
gnc_budget_free(QofInstance *inst)
{
GncBudget *budget;
- BudgetPrivate* priv;
+ BudgetPrivate* priv;
if (inst == NULL)
return;
g_return_if_fail(GNC_IS_BUDGET(inst));
- budget = GNC_BUDGET(inst);
- priv = GET_PRIVATE(budget);
+ budget = GNC_BUDGET(inst);
+ priv = GET_PRIVATE(budget);
/* We first send the message that this object is about to be
* destroyed so that any GUI elements can remove it before it is
@@ -304,12 +309,12 @@
void
gnc_budget_set_name(GncBudget* budget, const gchar* name)
{
- BudgetPrivate* priv;
+ BudgetPrivate* priv;
g_return_if_fail(GNC_IS_BUDGET(budget) && name);
- priv = GET_PRIVATE(budget);
- if( name == priv->name ) return;
+ priv = GET_PRIVATE(budget);
+ if ( name == priv->name ) return;
gnc_budget_begin_edit(budget);
CACHE_REPLACE(priv->name, name);
@@ -329,13 +334,13 @@
void
gnc_budget_set_description(GncBudget* budget, const gchar* description)
{
- BudgetPrivate* priv;
+ BudgetPrivate* priv;
g_return_if_fail(GNC_IS_BUDGET(budget));
g_return_if_fail(description);
- priv = GET_PRIVATE(budget);
- if( description == priv->description ) return;
+ priv = GET_PRIVATE(budget);
+ if ( description == priv->description ) return;
gnc_budget_begin_edit(budget);
CACHE_REPLACE(priv->description, description);
qof_instance_set_dirty(&budget->inst);
@@ -354,10 +359,10 @@
void
gnc_budget_set_recurrence(GncBudget *budget, const Recurrence *r)
{
- BudgetPrivate* priv;
+ BudgetPrivate* priv;
g_return_if_fail(budget && r);
- priv = GET_PRIVATE(budget);
+ priv = GET_PRIVATE(budget);
gnc_budget_begin_edit(budget);
priv->recurrence = *r;
@@ -385,12 +390,12 @@
void
gnc_budget_set_num_periods(GncBudget* budget, guint num_periods)
{
- BudgetPrivate* priv;
+ BudgetPrivate* priv;
g_return_if_fail(GNC_IS_BUDGET(budget));
- priv = GET_PRIVATE(budget);
- if( priv->num_periods == num_periods ) return;
+ priv = GET_PRIVATE(budget);
+ if ( priv->num_periods == num_periods ) return;
gnc_budget_begin_edit(budget);
priv->num_periods = num_periods;
@@ -414,7 +419,7 @@
/* What happens when account is deleted, after we have an entry for it? */
void
gnc_budget_unset_account_period_value(GncBudget *budget, Account *account,
- guint period_num)
+ guint period_num)
{
const GUID *guid;
KvpFrame *frame;
@@ -488,7 +493,7 @@
comm = xaccAccountGetCommodity(account);
different =
- gnc_account_foreach_descendant_until(account, is_same_commodity, comm);
+ gnc_account_foreach_descendant_until(account, is_same_commodity, comm);
return (different == NULL);
}
#endif
@@ -594,7 +599,8 @@
g_return_val_if_fail(book, NULL);
col = qof_book_get_collection(book, GNC_ID_BUDGET);
- if (qof_collection_count(col) > 0) {
+ if (qof_collection_count(col) > 0)
+ {
qof_collection_foreach(col, just_get_one, &bgt);
}
return bgt;
@@ -611,56 +617,79 @@
/* Define the QofObject. */
static QofObject budget_object_def =
{
- DI(.interface_version =) QOF_OBJECT_VERSION,
- DI(.e_type =) GNC_ID_BUDGET,
- DI(.type_label =) "Budget",
- DI(.create =) (gpointer)gnc_budget_new,
- DI(.book_begin =) NULL,
- DI(.book_end =) NULL,
- DI(.is_dirty =) qof_collection_is_dirty,
- DI(.mark_clean =) qof_collection_mark_clean,
- DI(.foreach =) qof_collection_foreach,
- DI(.printable =) (const char* (*)(gpointer)) gnc_budget_get_name,
- DI(.version_cmp =) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
+ DI(.interface_version = ) QOF_OBJECT_VERSION,
+ DI(.e_type = ) GNC_ID_BUDGET,
+ DI(.type_label = ) "Budget",
+ DI(.create = ) (gpointer)gnc_budget_new,
+ DI(.book_begin = ) NULL,
+ DI(.book_end = ) NULL,
+ DI(.is_dirty = ) qof_collection_is_dirty,
+ DI(.mark_clean = ) qof_collection_mark_clean,
+ DI(.foreach = ) qof_collection_foreach,
+ DI(.printable = ) (const char * (*)(gpointer)) gnc_budget_get_name,
+ DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
};
/* Static wrapper getters for the recurrence params */
static PeriodType gnc_budget_get_rec_pt(const GncBudget *bgt)
-{ return recurrenceGetPeriodType(&(GET_PRIVATE(bgt)->recurrence)); }
+{
+ return recurrenceGetPeriodType(&(GET_PRIVATE(bgt)->recurrence));
+}
static guint gnc_budget_get_rec_mult(const GncBudget *bgt)
-{ return recurrenceGetMultiplier(&(GET_PRIVATE(bgt)->recurrence)); }
+{
+ return recurrenceGetMultiplier(&(GET_PRIVATE(bgt)->recurrence));
+}
static GDate gnc_budget_get_rec_date(const GncBudget *bgt)
-{ return recurrenceGetDate(&(GET_PRIVATE(bgt)->recurrence)); }
+{
+ return recurrenceGetDate(&(GET_PRIVATE(bgt)->recurrence));
+}
/* Register ourselves with the engine. */
gboolean gnc_budget_register (void)
{
- static QofParam params[] = {
- { "name", QOF_TYPE_STRING,
- (QofAccessFunc) gnc_budget_get_name,
- (QofSetterFunc) gnc_budget_set_name },
- { "description", QOF_TYPE_STRING,
- (QofAccessFunc) gnc_budget_get_description,
- (QofSetterFunc) gnc_budget_set_description },
- { "recurrence_period_type", QOF_TYPE_INT32,
- (QofAccessFunc) gnc_budget_get_rec_pt, NULL },
+ static QofParam params[] =
+ {
+ {
+ "name", QOF_TYPE_STRING,
+ (QofAccessFunc) gnc_budget_get_name,
+ (QofSetterFunc) gnc_budget_set_name
+ },
+ {
+ "description", QOF_TYPE_STRING,
+ (QofAccessFunc) gnc_budget_get_description,
+ (QofSetterFunc) gnc_budget_set_description
+ },
+ {
+ "recurrence_period_type", QOF_TYPE_INT32,
+ (QofAccessFunc) gnc_budget_get_rec_pt, NULL
+ },
/* Signedness problem: Should be unsigned. */
- { "recurrence_multiplier", QOF_TYPE_INT32,
- (QofAccessFunc) gnc_budget_get_rec_mult, NULL },
+ {
+ "recurrence_multiplier", QOF_TYPE_INT32,
+ (QofAccessFunc) gnc_budget_get_rec_mult, NULL
+ },
/* This is the same way that SchedXaction.c uses QOF_TYPE_DATE
but I don't think QOF actually supports a GDate, so I think
this is wrong. */
- { "recurrence_date", QOF_TYPE_DATE,
- (QofAccessFunc) gnc_budget_get_rec_date, NULL },
+ {
+ "recurrence_date", QOF_TYPE_DATE,
+ (QofAccessFunc) gnc_budget_get_rec_date, NULL
+ },
/* Signedness problem: Should be unsigned. */
- { "num_periods", QOF_TYPE_INT32,
- (QofAccessFunc) gnc_budget_get_num_periods,
- (QofSetterFunc) gnc_budget_set_num_periods },
- { QOF_PARAM_BOOK, QOF_ID_BOOK,
- (QofAccessFunc) qof_instance_get_book, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID,
- (QofAccessFunc) qof_instance_get_guid, NULL },
+ {
+ "num_periods", QOF_TYPE_INT32,
+ (QofAccessFunc) gnc_budget_get_num_periods,
+ (QofSetterFunc) gnc_budget_set_num_periods
+ },
+ {
+ QOF_PARAM_BOOK, QOF_ID_BOOK,
+ (QofAccessFunc) qof_instance_get_book, NULL
+ },
+ {
+ QOF_PARAM_GUID, QOF_TYPE_GUID,
+ (QofAccessFunc) qof_instance_get_guid, NULL
+ },
{ NULL },
};
Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c 2010-03-02 21:40:02 UTC (rev 18787)
+++ gnucash/trunk/src/engine/gnc-commodity.c 2010-03-02 21:40:28 UTC (rev 18788)
@@ -37,50 +37,51 @@
#include "gnc-commodity.h"
#include "gnc-main.h"
-static QofLogModule log_module = GNC_MOD_COMMODITY;
+static QofLogModule log_module = GNC_MOD_COMMODITY;
/* Parts per unit is nominal, i.e. number of 'partname' units in
* a 'unitname' unit. fraction is transactional, i.e. how many
* of the smallest-transactional-units of the currency are there
- * in a 'unitname' unit. */
+ * in a 'unitname' unit. */
-enum {
- PROP_0,
- PROP_NAMESPACE,
- PROP_FULL_NAME,
- PROP_MNEMONIC,
- PROP_PRINTNAME,
- PROP_CUSIP,
- PROP_FRACTION,
- PROP_UNIQUE_NAME,
- PROP_QUOTE_FLAG,
- PROP_QUOTE_SOURCE,
- PROP_QUOTE_TZ,
+enum
+{
+ PROP_0,
+ PROP_NAMESPACE,
+ PROP_FULL_NAME,
+ PROP_MNEMONIC,
+ PROP_PRINTNAME,
+ PROP_CUSIP,
+ PROP_FRACTION,
+ PROP_UNIQUE_NAME,
+ PROP_QUOTE_FLAG,
+ PROP_QUOTE_SOURCE,
+ PROP_QUOTE_TZ,
};
-struct gnc_commodity_s
-{
- QofInstance inst;
+struct gnc_commodity_s
+{
+ QofInstance inst;
};
typedef struct CommodityPrivate
{
- gnc_commodity_namespace *namespace;
+ gnc_commodity_namespace *namespace;
- char * fullname;
- char * mnemonic;
- char * printname;
- char * cusip; /* CUSIP or other identifying code */
- int fraction;
- char * unique_name;
+ char * fullname;
+ char * mnemonic;
+ char * printname;
+ char * cusip; /* CUSIP or other identifying code */
+ int fraction;
+ char * unique_name;
- gboolean quote_flag; /* user wants price quotes */
- gnc_quote_source * quote_source; /* current/old source of quotes */
- char * quote_tz;
+ gboolean quote_flag; /* user wants price quotes */
+ gnc_quote_source * quote_source; /* current/old source of quotes */
+ char * quote_tz;
- /* the number of accounts using this commodity - this field is not
- * persisted */
- int usage_count;
+ /* the number of accounts using this commodity - this field is not
+ * persisted */
+ int usage_count;
} CommodityPrivate;
#define GET_PRIVATE(o) \
@@ -88,130 +89,134 @@
struct _GncCommodityClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
static void commodity_free(gnc_commodity * cm);
-struct gnc_commodity_namespace_s
+struct gnc_commodity_namespace_s
{
- QofInstance inst;
+ QofInstance inst;
- gchar * name;
- gboolean iso4217;
- GHashTable * cm_table;
- GList * cm_list;
+ gchar * name;
+ gboolean iso4217;
+ GHashTable * cm_table;
+ GList * cm_list;
};
struct _GncCommodityNamespaceClass
{
- QofInstanceClass parent_class;
+ QofInstanceClass parent_class;
};
-struct gnc_commodity_table_s
+struct gnc_commodity_table_s
{
- GHashTable * ns_table;
- GList * ns_list;
+ GHashTable * ns_table;
+ GList * ns_list;
};
struct gnc_new_iso_code
{
- const char *old_code;
- const char *new_code;
-} gnc_new_iso_codes[] = {
- {"RUR", "RUB"}, /* Russian Ruble: RUR through 1997-12, RUB from 1998-01 onwards; see bug #393185 */
- {"PLZ", "PLN"}, /* Polish Zloty */
- {"UAG", "UAH"}, /* Ukraine Hryvnia */
- {"NIS", "ILS"}, /* New Israeli Shekel: The informal abbreviation may be "NIS", but
+ const char *old_code;
+ const char *new_code;
+} gnc_new_iso_codes[] =
+{
+ {"RUR", "RUB"}, /* Russian Ruble: RUR through 1997-12, RUB from 1998-01 onwards; see bug #393185 */
+ {"PLZ", "PLN"}, /* Polish Zloty */
+ {"UAG", "UAH"}, /* Ukraine Hryvnia */
+ {"NIS", "ILS"}, /* New Israeli Shekel: The informal abbreviation may be "NIS", but
its iso-4217 is clearly ILS and only this! Incorrectly changed
due to bug#152755 (Nov 2004) and changed back again by bug#492417
(Oct 2008). */
- {"MXP", "MXN"}, /* Mexican (Nuevo) Peso */
- {"TRL", "TRY"}, /* New Turkish Lira: changed 2005 */
+ {"MXP", "MXN"}, /* Mexican (Nuevo) Peso */
+ {"TRL", "TRY"}, /* New Turkish Lira: changed 2005 */
- /* Only add currencies to this table when the old currency no longer
- * exists in the file iso-4217-currencies.scm */
+ /* Only add currencies to this table when the old currency no longer
+ * exists in the file iso-4217-currencies.scm */
};
#define GNC_NEW_ISO_CODES \
(sizeof(gnc_new_iso_codes) / sizeof(struct gnc_new_iso_code))
static gboolean fq_is_installed = FALSE;
-struct gnc_quote_source_s {
- gboolean supported;
- QuoteSourceType type;
- gint index;
- char *user_name; /* User friendly name */
- char *old_internal_name; /* Name used internally (deprecated) */
- char *internal_name; /* Name used internally and by finance::quote. */
+struct gnc_quote_source_s
+{
+ gboolean supported;
+ QuoteSourceType type;
+ gint index;
+ char *user_name; /* User friendly name */
+ char *old_internal_name; /* Name used internally (deprecated) */
+ char *internal_name; /* Name used internally and by finance::quote. */
};
static gnc_quote_source currency_quote_source =
- { TRUE, 0, 0, "Currency", "CURRENCY", "currency" };
+{ TRUE, 0, 0, "Currency", "CURRENCY", "currency" };
-static gnc_quote_source single_quote_sources[] = {
- { FALSE, 0, 0, "AEX", "AEX", "aex" },
- { FALSE, 0, 0, "AEX Futures", "AEX_FUTURES", "aex_futures" },
- { FALSE, 0, 0, "AEX Options", "AEX_OPTIONS", "aex_options" },
- { FALSE, 0, 0, "AMFI India", "AMFIINDIA", "amfiindia" },
- { FALSE, 0, 0, "ASE", "ASEGR", "asegr" },
- { FALSE, 0, 0, "ASX", "ASX", "asx" },
- { FALSE, 0, 0, "BMO NesbittBurns", "BMONESBITTBURNS", "bmonesbittburns" },
- { FALSE, 0, 0, "Deka Investments", "DEKA", "deka" },
- { FALSE, 0, 0, "DWS", "DWS", "dwsfunds" },
- { FALSE, 0, 0, "Fidelity Direct", "FIDELITY_DIRECT", "fidelity_direct" },
- { FALSE, 0, 0, "Finance Canada", "FINANCECANADA", "financecanada" },
- { FALSE, 0, 0, "First Trust Portfolios", "FTPORTFOLIOS_DIRECT", "ftportfolios_direct" },
- { FALSE, 0, 0, "Fund Library", "FUNDLIBRARY", "fundlibrary" },
- { FALSE, 0, 0, "Man Investments", "maninv", "maninv" },
- { FALSE, 0, 0, "Motley Fool", "FOOL", "fool" },
- { FALSE, 0, 0, "NZX", "NZX", "nzx" },
- { FALSE, 0, 0, "Platinum Asset Management", "PLATINUM", "platinum" },
- { FALSE, 0, 0, "SEB", "SEB_FUNDS", "seb_funds" },
- { FALSE, 0, 0, "Sharenet", "sharenet", "sharenet" },
- { FALSE, 0, 0, "TD Waterhouse Canada", "TDWATERHOUSE", "tdwaterhouse" },
- { FALSE, 0, 0, "TD Efunds", "TDEFUNDS", "tdefunds" },
- { FALSE, 0, 0, "TIAA-CREF", "TIAACREF", "tiaacref" },
- { FALSE, 0, 0, "T. Rowe Price", "TRPRICE_DIRECT", "troweprice_direct" },
- { FALSE, 0, 0, "Trustnet", "TRUSTNET", "trustnet" },
- { FALSE, 0, 0, "Union Investments", "UNIONFUNDS", "unionfunds" },
- { FALSE, 0, 0, "US Treasury Bonds", "usfedbonds", "usfedbonds" },
- { FALSE, 0, 0, "US Govt. Thrift Savings Plan", "TSP", "tsp" },
- { FALSE, 0, 0, "Vanguard", "VANGUARD", "vanguard" },
- { FALSE, 0, 0, "VWD", "VWD", "vwd" },
- { FALSE, 0, 0, "Yahoo", "YAHOO", "yahoo" },
- { FALSE, 0, 0, "Yahoo Asia", "YAHOO_ASIA", "yahoo_asia" },
- { FALSE, 0, 0, "Yahoo Australia", "YAHOO_AUSTRALIA", "yahoo_australia" },
- { FALSE, 0, 0, "Yahoo Brasil", "YAHOO_BRASIL", "yahoo_brasil" },
- { FALSE, 0, 0, "Yahoo Europe", "YAHOO_EUROPE", "yahoo_europe" },
- { FALSE, 0, 0, "Yahoo New Zealand", "YAHOO_NZ", "yahoo_nz" },
- { FALSE, 0, 0, "Zuerich Investments", "ZIFUNDS", "zifunds" }, /* Removed from F::Q 1.11. */
+static gnc_quote_source single_quote_sources[] =
+{
+ { FALSE, 0, 0, "AEX", "AEX", "aex" },
+ { FALSE, 0, 0, "AEX Futures", "AEX_FUTURES", "aex_futures" },
+ { FALSE, 0, 0, "AEX Options", "AEX_OPTIONS", "aex_options" },
+ { FALSE, 0, 0, "AMFI India", "AMFIINDIA", "amfiindia" },
+ { FALSE, 0, 0, "ASE", "ASEGR", "asegr" },
+ { FALSE, 0, 0, "ASX", "ASX", "asx" },
+ { FALSE, 0, 0, "BMO NesbittBurns", "BMONESBITTBURNS", "bmonesbittburns" },
+ { FALSE, 0, 0, "Deka Investments", "DEKA", "deka" },
+ { FALSE, 0, 0, "DWS", "DWS", "dwsfunds" },
+ { FALSE, 0, 0, "Fidelity Direct", "FIDELITY_DIRECT", "fidelity_direct" },
+ { FALSE, 0, 0, "Finance Canada", "FINANCECANADA", "financecanada" },
+ { FALSE, 0, 0, "First Trust Portfolios", "FTPORTFOLIOS_DIRECT", "ftportfolios_direct" },
+ { FALSE, 0, 0, "Fund Library", "FUNDLIBRARY", "fundlibrary" },
+ { FALSE, 0, 0, "Man Investments", "maninv", "maninv" },
+ { FALSE, 0, 0, "Motley Fool", "FOOL", "fool" },
+ { FALSE, 0, 0, "NZX", "NZX", "nzx" },
+ { FALSE, 0, 0, "Platinum Asset Management", "PLATINUM", "platinum" },
+ { FALSE, 0, 0, "SEB", "SEB_FUNDS", "seb_funds" },
+ { FALSE, 0, 0, "Sharenet", "sharenet", "sharenet" },
+ { FALSE, 0, 0, "TD Waterhouse Canada", "TDWATERHOUSE", "tdwaterhouse" },
+ { FALSE, 0, 0, "TD Efunds", "TDEFUNDS", "tdefunds" },
+ { FALSE, 0, 0, "TIAA-CREF", "TIAACREF", "tiaacref" },
+ { FALSE, 0, 0, "T. Rowe Price", "TRPRICE_DIRECT", "troweprice_direct" },
+ { FALSE, 0, 0, "Trustnet", "TRUSTNET", "trustnet" },
+ { FALSE, 0, 0, "Union Investments", "UNIONFUNDS", "unionfunds" },
+ { FALSE, 0, 0, "US Treasury Bonds", "usfedbonds", "usfedbonds" },
+ { FALSE, 0, 0, "US Govt. Thrift Savings Plan", "TSP", "tsp" },
+ { FALSE, 0, 0, "Vanguard", "VANGUARD", "vanguard" },
+ { FALSE, 0, 0, "VWD", "VWD", "vwd" },
+ { FALSE, 0, 0, "Yahoo", "YAHOO", "yahoo" },
+ { FALSE, 0, 0, "Yahoo Asia", "YAHOO_ASIA", "yahoo_asia" },
+ { FALSE, 0, 0, "Yahoo Australia", "YAHOO_AUSTRALIA", "yahoo_australia" },
+ { FALSE, 0, 0, "Yahoo Brasil", "YAHOO_BRASIL", "yahoo_brasil" },
+ { FALSE, 0, 0, "Yahoo Europe", "YAHOO_EUROPE", "yahoo_europe" },
+ { FALSE, 0, 0, "Yahoo New Zealand", "YAHOO_NZ", "yahoo_nz" },
+ { FALSE, 0, 0, "Zuerich Investments", "ZIFUNDS", "zifunds" }, /* Removed from F::Q 1.11. */
};
-static gnc_quote_source multiple_quote_sources[] = {
- { FALSE, 0, 0, "Asia (Yahoo, ...)", "ASIA", "asia" },
- { FALSE, 0, 0, "Australia (ASX, Yahoo, ...)", "AUSTRALIA", "australia" },
- { FALSE, 0, 0, "Brasil (Yahoo, ...)", "BRASIL", "brasil" },
- { FALSE, 0, 0, "Canada (Yahoo, ...)", "CANADA", "canada" },
- { FALSE, 0, 0, "Canada Mutual (Fund Library, ...)", "CANADAMUTUAL", "canadamutual" },
- { FALSE, 0, 0, "Dutch (AEX, ...)", "DUTCH", "dutch" },
- { FALSE, 0, 0, "Europe (Yahoo, ...)", "EUROPE", "europe" },
- { FALSE, 0, 0, "Greece (ASE, ...)", "GREECE", "greece" },
- { FALSE, 0, 0, "India Mutual (AMFI, ...)", "INDIAMUTUAL", "indiamutual" },
- { FALSE, 0, 0, "Fidelity (Fidelity, ...)", "FIDELITY", "fidelity" },
- { FALSE, 0, 0, "First Trust (First Trust, ...)", "FTPORTFOLIOS", "ftportfolios" },
- { FALSE, 0, 0, "Nasdaq (Yahoo, ...)", "NASDAQ", "nasdaq" },
- { FALSE, 0, 0, "New Zealand (Yahoo, ...)", "NZ", "nz" },
- { FALSE, 0, 0, "NYSE (Yahoo, ...)", "NYSE", "nyse" },
- { FALSE, 0, 0, "South Africa (Sharenet, ...)", "ZA", "za" },
- { FALSE, 0, 0, "T. Rowe Price", "TRPRICE", "troweprice" },
- { FALSE, 0, 0, "U.K. Unit Trusts", "UKUNITTRUSTS", "uk_unit_trusts" },
- { FALSE, 0, 0, "USA (Yahoo, Fool ...)", "USA", "usa" },
+static gnc_quote_source multiple_quote_sources[] =
+{
+ { FALSE, 0, 0, "Asia (Yahoo, ...)", "ASIA", "asia" },
+ { FALSE, 0, 0, "Australia (ASX, Yahoo, ...)", "AUSTRALIA", "australia" },
+ { FALSE, 0, 0, "Brasil (Yahoo, ...)", "BRASIL", "brasil" },
+ { FALSE, 0, 0, "Canada (Yahoo, ...)", "CANADA", "canada" },
+ { FALSE, 0, 0, "Canada Mutual (Fund Library, ...)", "CANADAMUTUAL", "canadamutual" },
+ { FALSE, 0, 0, "Dutch (AEX, ...)", "DUTCH", "dutch" },
+ { FALSE, 0, 0, "Europe (Yahoo, ...)", "EUROPE", "europe" },
+ { FALSE, 0, 0, "Greece (ASE, ...)", "GREECE", "greece" },
+ { FALSE, 0, 0, "India Mutual (AMFI, ...)", "INDIAMUTUAL", "indiamutual" },
+ { FALSE, 0, 0, "Fidelity (Fidelity, ...)", "FIDELITY", "fidelity" },
+ { FALSE, 0, 0, "First Trust (First Trust, ...)", "FTPORTFOLIOS", "ftportfolios" },
+ { FALSE, 0, 0, "Nasdaq (Yahoo, ...)", "NASDAQ", "nasdaq" },
+ { FALSE, 0, 0, "New Zealand (Yahoo, ...)", "NZ", "nz" },
+ { FALSE, 0, 0, "NYSE (Yahoo, ...)", "NYSE", "nyse" },
+ { FALSE, 0, 0, "South Africa (Sharenet, ...)", "ZA", "za" },
+ { FALSE, 0, 0, "T. Rowe Price", "TRPRICE", "troweprice" },
+ { FALSE, 0, 0, "U.K. Unit Trusts", "UKUNITTRUSTS", "uk_unit_trusts" },
+ { FALSE, 0, 0, "USA (Yahoo, Fool ...)", "USA", "usa" },
};
static const int num_single_quote_sources =
- sizeof(single_quote_sources) / sizeof(gnc_quote_source);
+ sizeof(single_quote_sources) / sizeof(gnc_quote_source);
static const int num_multiple_quote_sources =
- sizeof(multiple_quote_sources) / sizeof(gnc_quote_source);
+ sizeof(multiple_quote_sources) / sizeof(gnc_quote_source);
static GList *new_quote_sources = NULL;
@@ -224,7 +229,7 @@
gboolean
gnc_quote_source_fq_installed (void)
{
- return fq_is_installed;
+ return fq_is_installed;
}
/********************************************************************
@@ -234,16 +239,16 @@
********************************************************************/
gint gnc_quote_source_num_entries(QuoteSourceType type)
{
- if (type == SOURCE_CURRENCY)
- return 1;
-
- if (type == SOURCE_SINGLE)
- return num_single_quote_sources;
-
- if (type == SOURCE_MULTI)
- return num_multiple_quote_sources;
+ if (type == SOURCE_CURRENCY)
+ return 1;
- return g_list_length(new_quote_sources);
+ if (type == SOURCE_SINGLE)
+ return num_single_quote_sources;
+
+ if (type == SOURCE_MULTI)
+ return num_multiple_quote_sources;
+
+ return g_list_length(new_quote_sources);
}
/********************************************************************
@@ -254,20 +259,22 @@
static void
gnc_quote_source_init_tables (void)
{
- gint i;
+ gint i;
- for (i = 0; i < num_single_quote_sources; i++) {
- single_quote_sources[i].type = SOURCE_SINGLE;
- single_quote_sources[i].index = i;
- }
+ for (i = 0; i < num_single_quote_sources; i++)
+ {
+ single_quote_sources[i].type = SOURCE_SINGLE;
+ single_quote_sources[i].index = i;
+ }
- for (i = 0; i < num_multiple_quote_sources; i++) {
- multiple_quote_sources[i].type = SOURCE_MULTI;
- multiple_quote_sources[i].index = i;
- }
+ for (i = 0; i < num_multiple_quote_sources; i++)
+ {
+ multiple_quote_sources[i].type = SOURCE_MULTI;
+ multiple_quote_sources[i].index = i;
+ }
- currency_quote_source.type = SOURCE_CURRENCY;
- currency_quote_source.index = 0;
+ currency_quote_source.type = SOURCE_CURRENCY;
+ currency_quote_source.index = 0;
}
@@ -282,25 +289,25 @@
gnc_quote_source *
gnc_quote_source_add_new (const char *source_name, gboolean supported)
{
- gnc_quote_source *new_source;
+ gnc_quote_source *new_source;
- DEBUG("Creating new source %s", (source_name == NULL ? "(null)" : source_name));
- new_source = malloc(sizeof(gnc_quote_source));
- new_source->supported = supported;
- new_source->type = SOURCE_UNKNOWN;
- new_source->index = g_list_length(new_quote_sources);
+ DEBUG("Creating new source %s", (source_name == NULL ? "(null)" : source_name));
+ new_source = malloc(sizeof(gnc_quote_source));
+ new_source->supported = supported;
+ new_source->type = SOURCE_UNKNOWN;
+ new_source->index = g_list_length(new_quote_sources);
- /* This name can be changed if/when support for this price source is
- * integrated into gnucash. */
- new_source->user_name = strdup(source_name);
+ /* This name can be changed if/when support for this price source is
+ * integrated into gnucash. */
+ new_source->user_name = strdup(source_name);
- /* This name is permanent and must be kept the same if/when support
- * for this price source is integrated into gnucash (i.e. for a
- * nice user name). */
- new_source->old_internal_name = strdup(source_name);
- new_source->internal_name = strdup(source_name);
- new_quote_sources = g_list_append(new_quote_sources, new_source);
- return new_source;
+ /* This name is permanent and must be kept the same if/when support
+ * for this price source is integrated into gnucash (i.e. for a
+ * nice user name). */
+ new_source->old_internal_name = strdup(source_name);
+ new_source->internal_name = strdup(source_name);
+ new_quote_sources = g_list_append(new_quote_sources, new_source);
+ return new_source;
}
/********************************************************************
@@ -311,84 +318,92 @@
gnc_quote_source *
gnc_quote_source_lookup_by_ti (QuoteSourceType type, gint index)
{
- gnc_quote_source *source;
- GList *node;
+ gnc_quote_source *source;
+ GList *node;
- ENTER("type/index is %d/%d", type, index);
- switch (type) {
- case SOURCE_CURRENCY:
- LEAVE("found %s", currency_quote_source.user_name);
- return ¤cy_quote_source;
- break;
+ ENTER("type/index is %d/%d", type, index);
+ switch (type)
+ {
+ case SOURCE_CURRENCY:
+ LEAVE("found %s", currency_quote_source.user_name);
+ return ¤cy_quote_source;
+ break;
- case SOURCE_SINGLE:
- if (index < num_single_quote_sources) {
- LEAVE("found %s", single_quote_sources[index].user_name);
- return &single_quote_sources[index];
- }
- break;
+ case SOURCE_SINGLE:
+ if (index < num_single_quote_sources)
+ {
+ LEAVE("found %s", single_quote_sources[index].user_name);
+ return &single_quote_sources[index];
+ }
+ break;
- case SOURCE_MULTI:
- if (index < num_multiple_quote_sources) {
- LEAVE("found %s", multiple_quote_sources[index].user_name);
- return &multiple_quote_sources[index];
- }
- break;
+ case SOURCE_MULTI:
+ if (index < num_multiple_quote_sources)
+ {
+ LEAVE("found %s", multiple_quote_sources[index].user_name);
+ return &multiple_quote_sources[index];
+ }
+ break;
- case SOURCE_UNKNOWN:
- default:
- node = g_list_nth(new_quote_sources, index);
- if (node) {
- source = node->data;
- LEAVE("found %s", source->user_name);
- return source;
+ case SOURCE_UNKNOWN:
+ default:
+ node = g_list_nth(new_quote_sources, index);
+ if (node)
+ {
+ source = node->data;
+ LEAVE("found %s", source->user_name);
+ return source;
+ }
}
- }
- LEAVE("not found");
- return NULL;
+ LEAVE("not found");
+ return NULL;
}
gnc_quote_source *
gnc_quote_source_lookup_by_internal(const char * name)
{
- gnc_quote_source *source;
- GList *node;
- gint i;
+ gnc_quote_source *source;
+ GList *node;
+ gint i;
- if ((name == NULL) || (safe_strcmp(name, "") == 0)) {
- return NULL;
- }
+ if ((name == NULL) || (safe_strcmp(name, "") == 0))
+ {
+ return NULL;
+ }
- if (safe_strcmp(name, currency_quote_source.internal_name) == 0)
- return ¤cy_quote_source;
- if (safe_strcmp(name, currency_quote_source.old_internal_name) == 0)
- return ¤cy_quote_source;
+ if (safe_strcmp(name, currency_quote_source.internal_name) == 0)
+ return ¤cy_quote_source;
+ if (safe_strcmp(name, currency_quote_source.old_internal_name) == 0)
+ return ¤cy_quote_source;
- for (i = 0; i < num_single_quote_sources; i++) {
- if (safe_strcmp(name, single_quote_sources[i].internal_name) == 0)
- return &single_quote_sources[i];
- if (safe_strcmp(name, single_quote_sources[i].old_internal_name) == 0)
- return &single_quote_sources[i];
- }
+ for (i = 0; i < num_single_quote_sources; i++)
+ {
+ if (safe_strcmp(name, single_quote_sources[i].internal_name) == 0)
+ return &single_quote_sources[i];
+ if (safe_strcmp(name, single_quote_sources[i].old_internal_name) == 0)
+ return &single_quote_sources[i];
+ }
- for (i = 0; i < num_multiple_quote_sources; i++) {
- if (safe_strcmp(name, multiple_quote_sources[i].internal_name) == 0)
- return &multiple_quote_sources[i];
- if (safe_strcmp(name, multiple_quote_sources[i].old_internal_name) == 0)
- return &multiple_quote_sources[i];
- }
+ for (i = 0; i < num_multiple_quote_sources; i++)
+ {
+ if (safe_strcmp(name, multiple_quote_sources[i].internal_name) == 0)
+ return &multiple_quote_sources[i];
+ if (safe_strcmp(name, multiple_quote_sources[i].old_internal_name) == 0)
+ return &multiple_quote_sources[i];
+ }
- for (i = 0, node = new_quote_sources; node; node = node->next, i++) {
- source = node->data;
- if (safe_strcmp(name, source->internal_name) == 0)
- return source;
- if (safe_strcmp(name, source->old_internal_name) == 0)
- return source;
- }
+ for (i = 0, node = new_quote_sources; node; node = node->next, i++)
+ {
+ source = node->data;
+ if (safe_strcmp(name, source->internal_name) == 0)
+ return source;
+ if (safe_strcmp(name, source->old_internal_name) == 0)
+ return source;
+ }
- DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
- return NULL;
+ DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
+ return NULL;
}
/********************************************************************
@@ -399,76 +414,82 @@
QuoteSourceType
gnc_quote_source_get_type (const gnc_quote_source *source)
{
- ENTER("%p", source);
- if (!source) {
- LEAVE("bad source");
- return SOURCE_SINGLE;
- }
+ ENTER("%p", source);
+ if (!source)
+ {
+ LEAVE("bad source");
+ return SOURCE_SINGLE;
+ }
- LEAVE("type is %d",source->type);
- return source->type;
+ LEAVE("type is %d", source->type);
+ return source->type;
}
gint
gnc_quote_source_get_index (const gnc_quote_source *source)
{
- ENTER("%p", source);
- if (!source) {
- LEAVE("bad source");
- return 0;
- }
+ ENTER("%p", source);
+ if (!source)
+ {
+ LEAVE("bad source");
+ return 0;
+ }
- LEAVE("index is %d", source->index);
- return source->index;
+ LEAVE("index is %d", source->index);
+ return source->index;
}
gboolean
gnc_quote_source_get_supported (const gnc_quote_source *source)
{
- ENTER("%p", source);
- if (!source) {
- LEAVE("bad source");
- return FALSE;
- }
+ ENTER("%p", source);
+ if (!source)
+ {
+ LEAVE("bad source");
+ return FALSE;
+ }
- LEAVE("%ssupported", source && source->supported ? "" : "not ");
- return source->supported;
+ LEAVE("%ssupported", source && source->supported ? "" : "not ");
+ return source->supported;
}
const char *
gnc_quote_source_get_user_name (const gnc_quote_source *source)
{
- ENTER("%p", source);
- if (!source) {
- LEAVE("bad source");
- return NULL;
- }
- LEAVE("user name %s", source->user_name);
- return source->user_name;
+ ENTER("%p", source);
+ if (!source)
+ {
+ LEAVE("bad source");
+ return NULL;
+ }
+ LEAVE("user name %s", source->user_name);
+ return source->user_name;
}
const char *
gnc_quote_source_get_old_internal_name (const gnc_quote_source *source)
{
- ENTER("%p", source);
- if (!source) {
- LEAVE("bad source");
- return NULL;
- }
- LEAVE("old internal name %s", source->old_internal_name);
- return source->old_internal_name;
+ ENTER("%p", source);
+ if (!source)
+ {
+ LEAVE("bad source");
+ return NULL;
+ }
+ LEAVE("old internal name %s", source->old_internal_name);
+ return source->old_internal_name;
}
const char *
gnc_quote_source_get_internal_name (const gnc_quote_source *source)
{
- ENTER("%p", source);
- if (!source) {
- LEAVE("bad source");
- return NULL;
- }
- LEAVE("internal name %s", source->internal_name);
- return source->internal_name;
+ ENTER("%p", source);
+ if (!source)
+ {
+ LEAVE("bad source");
+ return NULL;
+ }
+ LEAVE("internal name %s", source->internal_name);
+ return source->internal_name;
}
/********************************************************************
@@ -480,29 +501,31 @@
void
gnc_quote_source_set_fq_installed (const GList *sources_list)
{
- gnc_quote_source *source;
- char *source_name;
- const GList *node;
+ gnc_quote_source *source;
+ char *source_name;
+ const GList *node;
- ENTER(" ");
- fq_is_installed = TRUE;
+ ENTER(" ");
+ fq_is_installed = TRUE;
- if (!sources_list)
- return;
+ if (!sources_list)
+ return;
- for (node = sources_list; node; node = node->next) {
- source_name = node->data;
+ for (node = sources_list; node; node = node->next)
+ {
+ source_name = node->data;
- source = gnc_quote_source_lookup_by_internal(source_name);
- if (source != NULL) {
- DEBUG("Found source %s: %s", source_name, source->user_name);
- source->supported = TRUE;
- continue;
+ source = gnc_quote_source_lookup_by_internal(source_name);
+ if (source != NULL)
+ {
+ DEBUG("Found source %s: %s", source_name, source->user_name);
+ source->supported = TRUE;
+ continue;
+ }
+
+ gnc_quote_source_add_new(source_name, TRUE);
}
-
- gnc_quote_source_add_new(source_name, TRUE);
- }
- LEAVE(" ");
+ LEAVE(" ");
}
/********************************************************************
@@ -512,13 +535,13 @@
void
gnc_commodity_begin_edit (gnc_commodity *cm)
{
- qof_begin_edit(&cm->inst);
+ qof_begin_edit(&cm->inst);
}
static void commit_err (QofInstance *inst, QofBackendError errcode)
{
- PERR ("Failed to commit: %d", errcode);
- gnc_engine_signal_commit_error( errcode );
+ PERR ("Failed to commit: %d", errcode);
+ gnc_engine_signal_commit_error( errcode );
}
static void noop (QofInstance *inst) {}
@@ -526,14 +549,14 @@
static void
comm_free(QofInstance* inst)
{
- commodity_free( GNC_COMMODITY(inst) );
+ commodity_free( GNC_COMMODITY(inst) );
}
void
gnc_commodity_commit_edit (gnc_commodity *cm)
{
- if (!qof_commit_edit (QOF_INSTANCE(cm))) return;
- qof_commit_edit_part2 (&cm->inst, commit_err, noop, comm_free);
+ if (!qof_commit_edit (QOF_INSTANCE(cm))) return;
+ qof_commit_edit_part2 (&cm->inst, commit_err, noop, comm_free);
}
/********************************************************************
@@ -543,8 +566,8 @@
static void
mark_commodity_dirty (gnc_commodity *cm)
{
- qof_instance_set_dirty(&cm->inst);
- qof_event_gen (&cm->inst, QOF_EVENT_MODIFY, NULL);
+ qof_instance_set_dirty(&cm->inst);
+ qof_event_gen (&cm->inst, QOF_EVENT_MODIFY, NULL);
}
static void
@@ -552,8 +575,8 @@
{
g_free(priv->printname);
priv->printname = g_strdup_printf("%s (%s)",
- priv->mnemonic ? priv->mnemonic : "",
- priv->fullname ? priv->fullname : "");
+ priv->mnemonic ? priv->mnemonic : "",
+ priv->fullname ? priv->fullname : "");
}
static void
@@ -564,8 +587,8 @@
g_free(priv->unique_name);
ns = priv->namespace;
priv->unique_name = g_strdup_printf("%s::%s",
- ns ? ns->name : "",
- priv->mnemonic ? priv->mnemonic : "");
+ ns ? ns->name : "",
+ priv->mnemonic ? priv->mnemonic : "");
}
/* GObject Initialization */
@@ -574,21 +597,21 @@
static void
gnc_commodity_init(gnc_commodity* com)
{
- CommodityPrivate* priv;
+ CommodityPrivate* priv;
- priv = GET_PRIVATE(com);
-
- priv->namespace = NULL;
- priv->fullname = CACHE_INSERT("");
- priv->mnemonic = CACHE_INSERT("");
- priv->cusip = CACHE_INSERT("");
- priv->fraction = 10000;
- priv->quote_flag = 0;
- priv->quote_source = NULL;
- priv->quote_tz = CACHE_INSERT("");
+ priv = GET_PRIVATE(com);
- reset_printname(priv);
- reset_unique_name(priv);
+ priv->namespace = NULL;
+ priv->fullname = CACHE_INSERT("");
+ priv->mnemonic = CACHE_INSERT("");
+ priv->cusip = CACHE_INSERT("");
+ priv->fraction = 10000;
+ priv->quote_flag = 0;
+ priv->quote_source = NULL;
+ priv->quote_tz = CACHE_INSERT("");
+
+ reset_printname(priv);
+ reset_unique_name(priv);
}
static void
@@ -605,59 +628,60 @@
static void
gnc_commodity_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
gnc_commodity *commodity;
- CommodityPrivate* priv;
+ CommodityPrivate* priv;
g_return_if_fail(GNC_IS_COMMODITY(object));
commodity = GNC_COMMODITY(object);
- priv = GET_PRIVATE(commodity);
- switch (prop_id) {
+ priv = GET_PRIVATE(commodity);
+ switch (prop_id)
+ {
case PROP_NAMESPACE:
- g_value_set_object(value, priv->namespace);
- break;
+ g_value_set_object(value, priv->namespace);
+ break;
case PROP_FULL_NAME:
- g_value_set_string(value, priv->fullname);
- break;
+ g_value_set_string(value, priv->fullname);
+ break;
case PROP_MNEMONIC:
- g_value_set_string(value, priv->mnemonic);
- break;
+ g_value_set_string(value, priv->mnemonic);
+ break;
case PROP_PRINTNAME:
- g_value_set_string(value, priv->printname);
- break;
+ g_value_set_string(value, priv->printname);
+ break;
case PROP_CUSIP:
- g_value_set_string(value, priv->cusip);
- break;
+ g_value_set_string(value, priv->cusip);
+ break;
case PROP_FRACTION:
- g_value_set_int(value, priv->fraction);
- break;
+ g_value_set_int(value, priv->fraction);
+ break;
case PROP_UNIQUE_NAME:
- g_value_set_string(value, priv->unique_name);
- break;
+ g_value_set_string(value, priv->unique_name);
+ break;
case PROP_QUOTE_FLAG:
- g_value_set_boolean(value, priv->quote_flag);
- break;
+ g_value_set_boolean(value, priv->quote_flag);
+ break;
case PROP_QUOTE_SOURCE:
- g_value_set_pointer(value, priv->quote_source);
- break;
+ g_value_set_pointer(value, priv->quote_source);
+ break;
case PROP_QUOTE_TZ:
- g_value_set_string(value, priv->quote_tz);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
+ g_value_set_string(value, priv->quote_tz);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
static void
gnc_commodity_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
gnc_commodity *commodity;
gnc_numeric *number;
@@ -666,35 +690,36 @@
commodity = GNC_COMMODITY(object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_NAMESPACE:
- gnc_commodity_set_namespace(commodity, g_value_get_object(value));
- break;
+ gnc_commodity_set_namespace(commodity, g_value_get_object(value));
+ break;
case PROP_FULL_NAME:
- gnc_commodity_set_fullname(commodity, g_value_get_string(value));
- break;
+ gnc_commodity_set_fullname(commodity, g_value_get_string(value));
+ break;
case PROP_MNEMONIC:
- gnc_commodity_set_mnemonic(commodity, g_value_get_string(value));
- break;
+ gnc_commodity_set_mnemonic(commodity, g_value_get_string(value));
+ break;
case PROP_CUSIP:
- gnc_commodity_set_cusip(commodity, g_value_get_string(value));
- break;
+ gnc_commodity_set_cusip(commodity, g_value_get_string(value));
+ break;
case PROP_FRACTION:
- gnc_commodity_set_fraction(commodity, g_value_get_int(value));
- break;
+ gnc_commodity_set_fraction(commodity, g_value_get_int(value));
+ break;
case PROP_QUOTE_FLAG:
- gnc_commodity_set_quote_flag(commodity, g_value_get_boolean(value));
- break;
+ gnc_commodity_set_quote_flag(commodity, g_value_get_boolean(value));
+ break;
case PROP_QUOTE_SOURCE:
- gnc_commodity_set_quote_source(commodity, g_value_get_pointer(value));
- break;
+ gnc_commodity_set_quote_source(commodity, g_value_get_pointer(value));
+ break;
case PROP_QUOTE_TZ:
- gnc_commodity_set_quote_tz(commodity, g_value_get_string(value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
+ gnc_commodity_set_quote_tz(commodity, g_value_get_string(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
}
static void
gnc_commodity_class_init(struct _GncCommodityClass* klass)
@@ -706,115 +731,117 @@
gobject_class->set_property = gnc_commodity_set_property;
gobject_class->get_property = gnc_commodity_get_property;
- g_type_class_add_private(klass, sizeof(CommodityPrivate));
+ g_type_class_add_private(klass, sizeof(CommodityPrivate));
g_object_class_install_property(gobject_class,
- PROP_NAMESPACE,
- g_param_spec_object ("namespace",
- "Namespace",
- "The namespace field denotes the "
- "namespace for this commodity, either "
- "a currency or symbol from a quote source.",
- GNC_TYPE_COMMODITY_NAMESPACE,
- G_PARAM_READWRITE));
+ PROP_NAMESPACE,
+ g_param_spec_object ("namespace",
+ "Namespace",
+ "The namespace field denotes the "
+ "namespace for this commodity, either "
+ "a currency or symbol from a quote source.",
+ GNC_TYPE_COMMODITY_NAMESPACE,
+ G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
- PROP_FULL_NAME,
- g_param_spec_string ("fullname",
- "Full Commodity Name",
- "The fullname is the official full name of"
- "the currency.",
- NULL,
- G_PARAM_READWRITE));
+ PROP_FULL_NAME,
+ g_param_spec_string ("fullname",
+ "Full Commodity Name",
+ "The fullname is the official full name of"
+ "the currency.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
- PROP_MNEMONIC,
- g_param_spec_string ("mnemonic",
- "Commodity Mnemonic",
- "The mnemonic is the official abbreviated"
- "designation for the currency.",
- NULL,
- G_PARAM_READWRITE));
+ PROP_MNEMONIC,
+ g_param_spec_string ("mnemonic",
+ "Commodity Mnemonic",
+ "The mnemonic is the official abbreviated"
+ "designation for the currency.",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
- PROP_PRINTNAME,
- g_param_spec_string ("printname",
- "Commodity Print Name",
- "Printable form of the commodity name.",
- NULL,
- G_PARAM_READABLE));
+ PROP_PRINTNAME,
+ g_param_spec_string ("printname",
+ "Commodity Print Name",
+ "Printable form of the commodity name.",
+ NULL,
+ G_PARAM_READABLE));
g_object_class_install_property(gobject_class,
- PROP_CUSIP,
- g_param_spec_string ("cusip",
- "Commodity CUSIP Code",
- "?????",
- NULL,
- G_PARAM_READWRITE));
+ PROP_CUSIP,
+ g_param_spec_string ("cusip",
+ "Commodity CUSIP Code",
+ "?????",
+ NULL,
+ G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
- PROP_FRACTION,
- g_param_spec_int ("fraction",
- "Fraction",
- "The fraction is the number of sub-units that "
- "the basic commodity can be divided into.",
- 1,
- 1000000,
- 1,
- G_PARAM_READWRITE));
+ PROP_FRACTION,
+ g_param_spec_int ("fraction",
+ "Fraction",
+ "The fraction is the number of sub-units that "
+ "the basic commodity can be divided into.",
+ 1,
+ 1000000,
+ 1,
+ G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
- PROP_UNIQUE_NAME,
- g_param_spec_string ("unique-name",
- "Commodity Unique Name",
- "Unique form of the commodity name which combines "
- "the namespace name and the commodity name.",
- NULL,
- G_PARAM_READABLE));
+ PROP_UNIQUE_NAME,
+ g_param_spec_string ("unique-name",
+ "Commodity Unique Name",
+ "Unique form of the commodity name which combines "
+ "the namespace name and the commodity name.",
+ NULL,
+ G_PARAM_READABLE));
g_object_class_install_property(gobject_class,
- PROP_QUOTE_FLAG,
- g_param_spec_boolean ("quote_flag",
- "Quote Flag",
- "TRUE if prices are to be downloaded for this "
- "commodity from a quote source.",
- FALSE,
- G_PARAM_READWRITE));
+ PROP_QUOTE_FLAG,
+ g_param_spec_boolean ("quote_flag",
+ "Quote Flag",
+ "TRUE if prices are to be downloaded for this "
+ "commodity from a quote source.",
+ FALSE,
+ G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
- PROP_QUOTE_SOURCE,
- g_param_spec_pointer("quote-source",
- "Quote Source",
- "The quote source from which prices are downloaded.",
- G_PARAM_READWRITE));
+ PROP_QUOTE_SOURCE,
+ g_param_spec_pointer("quote-source",
+ "Quote Source",
+ "The quote source from which prices are downloaded.",
+ G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
- PROP_QUOTE_TZ,
- g_param_spec_string ("quote-tz",
- "Commodity Quote Timezone",
- "?????",
- NULL,
- G_PARAM_READWRITE));
+ PROP_QUOTE_TZ,
+ g_param_spec_string ("quote-tz",
+ "Commodity Quote Timezone",
+ "?????",
+ NULL,
+ G_PARAM_READWRITE));
}
gnc_commodity *
-gnc_commodity_new(QofBook *book, const char * fullname,
- const char * namespace, const char * mnemonic,
+gnc_commodity_new(QofBook *book, const char * fullname,
+ const char * namespace, const char * mnemonic,
const char * cusip, int fraction)
{
- gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
- gnc_commodity_table *table;
+ gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
+ gnc_commodity_table *table;
- qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
- gnc_commodity_begin_edit(retval);
+ qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
+ gnc_commodity_begin_edit(retval);
- if( namespace != NULL ) {
- gnc_commodity_set_namespace(retval, namespace);
- if (gnc_commodity_namespace_is_iso(namespace)) {
- gnc_commodity_set_quote_source(retval,
- gnc_quote_source_lookup_by_internal("currency") );
- }
- }
- gnc_commodity_set_fullname(retval, fullname);
- gnc_commodity_set_mnemonic(retval, mnemonic);
- gnc_commodity_set_cusip(retval, cusip);
- gnc_commodity_set_fraction(retval, fraction);
- gnc_commodity_commit_edit(retval);
+ if ( namespace != NULL )
+ {
+ gnc_commodity_set_namespace(retval, namespace);
+ if (gnc_commodity_namespace_is_iso(namespace))
+ {
+ gnc_commodity_set_quote_source(retval,
+ gnc_quote_source_lookup_by_internal("currency") );
+ }
+ }
+ gnc_commodity_set_fullname(retval, fullname);
+ gnc_commodity_set_mnemonic(retval, mnemonic);
+ gnc_commodity_set_cusip(retval, cusip);
+ gnc_commodity_set_fraction(retval, fraction);
+ gnc_commodity_commit_edit(retval);
- qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);
+ qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);
- return retval;
+ return retval;
}
@@ -825,109 +852,110 @@
static void
commodity_free(gnc_commodity * cm)
{
- QofBook *book;
- gnc_commodity_table *table;
- CommodityPrivate* priv;
+ QofBook *book;
+ gnc_commodity_table *table;
+ CommodityPrivate* priv;
- if(!cm) return;
+ if (!cm) return;
- book = qof_instance_get_book(&cm->inst);
- table = gnc_commodity_table_get_table(book);
- gnc_commodity_table_remove(table, cm);
- priv = GET_PRIVATE(cm);
+ book = qof_instance_get_book(&cm->inst);
+ table = gnc_commodity_table_get_table(book);
+ gnc_commodity_table_remove(table, cm);
+ priv = GET_PRIVATE(cm);
- qof_event_gen (&cm->inst, QOF_EVENT_DESTROY, NULL);
+ qof_event_gen (&cm->inst, QOF_EVENT_DESTROY, NULL);
- /* Set at creation */
- CACHE_REMOVE (priv->fullname);
- CACHE_REMOVE (priv->cusip);
- CACHE_REMOVE (priv->mnemonic);
- CACHE_REMOVE (priv->quote_tz);
- priv->namespace = NULL;
+ /* Set at creation */
+ CACHE_REMOVE (priv->fullname);
+ CACHE_REMOVE (priv->cusip);
+ CACHE_REMOVE (priv->mnemonic);
+ CACHE_REMOVE (priv->quote_tz);
+ priv->namespace = NULL;
- /* Set through accessor functions */
- priv->quote_source = NULL;
+ /* Set through accessor functions */
+ priv->quote_source = NULL;
- /* Automatically generated */
- g_free(priv->printname);
- priv->printname = NULL;
+ /* Automatically generated */
+ g_free(priv->printname);
+ priv->printname = NULL;
- g_free(priv->unique_name);
- priv->unique_name = NULL;
+ g_free(priv->unique_name);
+ priv->unique_name = NULL;
#ifdef ACCOUNTS_CLEANED_UP
- /* Account objects are not actually cleaned up when a book is closed (in fact
- * a memory leak), but commodities are, so in currently this warning gets hit
- * quite frequently. Disable the check until cleaning up of accounts objects
- * on close is implemented. */
- if(priv->usage_count != 0) {
- PWARN("Destroying commodity (%p) with non-zero usage_count (%d).", cm,
+ /* Account objects are not actually cleaned up when a book is closed (in fact
+ * a memory leak), but commodities are, so in currently this warning gets hit
+ * quite frequently. Disable the check until cleaning up of accounts objects
+ * on close is implemented. */
+ if (priv->usage_count != 0)
+ {
+ PWARN("Destroying commodity (%p) with non-zero usage_count (%d).", cm,
priv->usage_count);
- }
+ }
#endif
- /* qof_instance_release (&cm->inst); */
- g_object_unref(cm);
+ /* qof_instance_release (&cm->inst); */
+ g_object_unref(cm);
}
void
gnc_commodity_destroy(gnc_commodity * cm)
{
- gnc_commodity_begin_edit(cm);
- qof_instance_set_destroying(cm, TRUE);
- gnc_commodity_commit_edit(cm);
+ gnc_commodity_begin_edit(cm);
+ qof_instance_set_destroying(cm, TRUE);
+ gnc_commodity_commit_edit(cm);
}
void
gnc_commodity_copy(gnc_commodity * dest, const gnc_commodity *src)
{
- CommodityPrivate* src_priv = GET_PRIVATE(src);
- CommodityPrivate* dest_priv = GET_PRIVATE(dest);
+ CommodityPrivate* src_priv = GET_PRIVATE(src);
+ CommodityPrivate* dest_priv = GET_PRIVATE(dest);
- gnc_commodity_set_fullname (dest, src_priv->fullname);
- gnc_commodity_set_mnemonic (dest, src_priv->mnemonic);
- dest_priv->namespace = src_priv->namespace;
- gnc_commodity_set_fraction (dest, src_priv->fraction);
- gnc_commodity_set_cusip (dest, src_priv->cusip);
- gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
- gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
- gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
- kvp_frame_delete (dest->inst.kvp_data);
- dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
- kvp_frame_delete (dest->inst.kvp_data);
- dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
+ gnc_commodity_set_fullname (dest, src_priv->fullname);
+ gnc_commodity_set_mnemonic (dest, src_priv->mnemonic);
+ dest_priv->namespace = src_priv->namespace;
+ gnc_commodity_set_fraction (dest, src_priv->fraction);
+ gnc_commodity_set_cusip (dest, src_priv->cusip);
+ gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
+ gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
+ gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
+ kvp_frame_delete (dest->inst.kvp_data);
+ dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
+ kvp_frame_delete (dest->inst.kvp_data);
+ dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
}
gnc_commodity *
gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
{
- CommodityPrivate* src_priv;
- CommodityPrivate* dest_priv;
+ CommodityPrivate* src_priv;
+ CommodityPrivate* dest_priv;
- gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
- qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book);
- src_priv = GET_PRIVATE(src);
- dest_priv = GET_PRIVATE(dest);
+ gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
+ qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book);
+ src_priv = GET_PRIVATE(src);
+ dest_priv = GET_PRIVATE(dest);
- dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
- dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
- dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
- dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
+ dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
+ dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
+ dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
+ dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
- dest_priv->namespace = src_priv->namespace;
+ dest_priv->namespace = src_priv->namespace;
- dest_priv->fraction = src_priv->fraction;
- dest_priv->quote_flag = src_priv->quote_flag;
+ dest_priv->fraction = src_priv->fraction;
+ dest_priv->quote_flag = src_priv->quote_flag;
- gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
+ gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
- kvp_frame_delete (dest->inst.kvp_data);
- dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
+ kvp_frame_delete (dest->inst.kvp_data);
+ dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
- reset_printname(dest_priv);
- reset_unique_name(dest_priv);
+ reset_printname(dest_priv);
+ reset_unique_name(dest_priv);
- return dest;
+ return dest;
}
/********************************************************************
@@ -935,10 +963,10 @@
********************************************************************/
const char *
-gnc_commodity_get_mnemonic(const gnc_commodity * cm)
+gnc_commodity_get_mnemonic(const gnc_commodity * cm)
{
- if(!cm) return NULL;
- return GET_PRIVATE(cm)->mnemonic;
+ if (!cm) return NULL;
+ return GET_PRIVATE(cm)->mnemonic;
}
/********************************************************************
@@ -946,10 +974,10 @@
********************************************************************/
const char *
-gnc_commodity_get_printname(const gnc_commodity * cm)
+gnc_commodity_get_printname(const gnc_commodity * cm)
{
- if(!cm) return NULL;
- return GET_PRIVATE(cm)->printname;
+ if (!cm) return NULL;
+ return GET_PRIVATE(cm)->printname;
}
@@ -958,32 +986,33 @@
********************************************************************/
const char *
-gnc_commodity_get_namespace(const gnc_commodity * cm)
+gnc_commodity_get_namespace(const gnc_commodity * cm)
{
- if(!cm) return NULL;
- return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->namespace);
+ if (!cm) return NULL;
+ return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->namespace);
}
const char *
-gnc_commodity_get_namespace_compat(const gnc_commodity * cm)
+gnc_commodity_get_namespace_compat(const gnc_commodity * cm)
{
- CommodityPrivate* priv;
+ CommodityPrivate* priv;
- if (!cm) return NULL;
- priv = GET_PRIVATE(cm);
- if(!priv->namespace) return NULL;
- if (priv->namespace->iso4217) {
- /* Data files are still written with ISO4217. */
- return GNC_COMMODITY_NS_ISO;
- }
- return gnc_commodity_namespace_get_name(priv->namespace);
+ if (!cm) return NULL;
+ priv = GET_PRIVATE(cm);
+ if (!priv->namespace) return NULL;
+ if (priv->namespace->iso4217)
+ {
+ /* Data files are still written with ISO4217. */
+ return GNC_COMMODITY_NS_ISO;
+ }
+ return gnc_commodity_namespace_get_name(priv->namespace);
}
gnc_commodity_namespace *
-gnc_commodity_get_namespace_ds(const gnc_commodity * cm)
+gnc_commodity_get_namespace_ds(const gnc_commodity * cm)
{
- if(!cm) return NULL;
- return GET_PRIVATE(cm)->namespace;
+ if (!cm) return NULL;
+ return GET_PRIVATE(cm)->namespace;
}
/********************************************************************
@@ -991,10 +1020,10 @@
********************************************************************/
const char *
-gnc_commodity_get_fullname(const gnc_commodity * cm)
+gnc_commodity_get_fullname(const gnc_commodity * cm)
{
- if(!cm) return NULL;
- return GET_PRIVATE(cm)->fullname;
+ if (!cm) return NULL;
+ return GET_PRIVATE(cm)->fullname;
}
@@ -1003,10 +1032,10 @@
********************************************************************/
const char *
-gnc_commodity_get_unique_name(const gnc_commodity * cm)
+gnc_commodity_get_unique_name(const gnc_commodity * cm)
{
- if(!cm) return NULL;
- return GET_PRIVATE(cm)->unique_name;
+ if (!cm) return NULL;
+ return GET_PRIVATE(cm)->unique_name;
}
@@ -1014,11 +1043,11 @@
* gnc_commodity_get_cusip
********************************************************************/
-const char *
-gnc_commodity_get_cusip(const gnc_commodity * cm)
+const char *
+gnc_commodity_get_cusip(const gnc_commodity * cm)
{
- if(!cm) return NULL;
- return GET_PRIVATE(cm)->cusip;
+ if (!cm) return NULL;
+ return GET_PRIVATE(cm)->cusip;
}
/********************************************************************
@@ -1026,10 +1055,10 @@
********************************************************************/
int
-gnc_commodity_get_fraction(const gnc_commodity * cm)
+gnc_commodity_get_fraction(const gnc_commodity * cm)
{
- if(!cm) return 0;
- return GET_PRIVATE(cm)->fraction;
+ if (!cm) return 0;
+ return GET_PRIVATE(cm)->fraction;
}
/********************************************************************
@@ -1039,12 +1068,12 @@
static gboolean
gnc_commodity_get_auto_quote_cont