42 #include <glib/gi18n.h> 53 #include "TransactionP.hpp" 55 #include "qofinstance-p.h" 56 #include "gnc-session.h" 59 #define G_LOG_DOMAIN "gnc.engine.scrub" 62 static gboolean abort_now = FALSE;
63 static gint scrub_depth = 0;
67 gnc_commodity* currency,
80 gnc_get_abort_scrub (
void)
88 return scrub_depth > 0;
93 static void add_transactions (
const Account *account, GHashTable **ht)
95 for (
auto s : xaccAccountGetSplits (account))
100 get_all_transactions (
Account *account,
bool descendants)
102 GHashTable *ht = g_hash_table_new (g_direct_hash, g_direct_equal);
103 add_transactions (account, &ht);
106 GList *rv = g_hash_table_get_keys (ht);
107 g_hash_table_destroy (ht);
114 TransScrubOrphansFast (Transaction *trans,
Account *root)
116 g_return_if_fail (trans && trans->common_currency && root);
118 for (GList *node = trans->splits; node; node = node->next)
120 Split *split = GNC_SPLIT(node->data);
121 if (abort_now)
break;
123 if (split->acc)
continue;
125 DEBUG (
"Found an orphan\n");
127 gchar *accname = g_strconcat
131 Account *orph = xaccScrubUtilityGetOrMakeAccount
132 (root, trans->common_currency, accname,
ACCT_TYPE_BANK,
false,
true);
137 xaccSplitSetAccount(split, orph);
147 GList *transactions = get_all_transactions (acc, descendants);
148 gint total_trans = g_list_length (transactions);
149 const char *message = _(
"Looking for orphans in transaction: %u of %u");
150 guint current_trans = 0;
152 for (GList *node = transactions; node; current_trans++, node = node->next)
154 Transaction *trans = GNC_TRANSACTION(node->data);
155 if (current_trans % 10 == 0)
157 char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
158 (percentagefunc)(progress_msg, (100 * current_trans) / total_trans);
159 g_free (progress_msg);
160 if (abort_now)
break;
165 (percentagefunc)(
nullptr, -1.0);
168 g_list_free (transactions);
174 AccountScrubOrphans (acc,
false, percentagefunc);
180 AccountScrubOrphans (acc,
true, percentagefunc);
187 QofBook *book =
nullptr;
192 for (node = trans->splits; node; node = node->next)
194 Split *split = GNC_SPLIT(node->data);
195 if (abort_now)
break;
209 PINFO (
"Free Floating Transaction!");
211 root = gnc_book_get_root_account (book);
212 TransScrubOrphansFast (trans, root);
218 xaccAccountTreeScrubSplits (
Account *account)
220 if (!account)
return;
222 xaccAccountScrubSplits (account);
224 (AccountCb)xaccAccountScrubSplits,
nullptr);
228 xaccAccountScrubSplits (
Account *account)
231 for (
auto s : xaccAccountGetSplits (account))
233 if (abort_now)
break;
242 split_scrub_or_dry_run (Split *split,
bool dry_run)
246 gnc_numeric value, amount;
247 gnc_commodity *currency, *acc_commodity;
250 if (!split)
return false;
251 ENTER (
"(split=%p)", split);
280 PINFO (
"Free Floating Transaction!");
281 LEAVE (
"no account");
289 value = gnc_numeric_zero();
299 amount = gnc_numeric_zero();
321 LEAVE (
"(split=%p) inequiv currency", split);
330 LEAVE(
"(split=%p) different values", split);
341 PINFO (
"Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\"" 342 " old amount %s %s, new amount %s",
343 trans->description, split->memo,
351 LEAVE (
"(split=%p)", split);
359 AccountScrubImbalance (
Account *acc,
bool descendants,
362 const char *message = _(
"Looking for imbalances in transaction date %s: %u of %u");
367 Account *root = gnc_book_get_root_account (book);
368 GList *transactions = get_all_transactions (acc, descendants);
369 guint count = g_list_length (transactions), curr_trans = 0;
372 for (GList *node = transactions; node; node = node->next, curr_trans++)
374 Transaction *trans = GNC_TRANSACTION(node->data);
375 if (abort_now)
break;
377 PINFO(
"Start processing transaction %d of %d", curr_trans + 1, count);
379 if (curr_trans % 10 == 0)
382 char *progress_msg = g_strdup_printf (message, date, curr_trans, count);
383 (percentagefunc)(progress_msg, (100 * curr_trans) / count);
384 g_free (progress_msg);
388 TransScrubOrphansFast (trans, root);
392 PINFO(
"Finished processing transaction %d of %d", curr_trans + 1, count);
394 (percentagefunc)(
nullptr, -1.0);
397 g_list_free (transactions);
407 PERR (
"Transaction doesn't have a currency!");
409 bool must_scrub =
false;
412 if (split_scrub_or_dry_run (GNC_SPLIT(n->data),
true))
432 split_scrub_or_dry_run (split,
false);
441 AccountScrubImbalance (acc,
true, percentagefunc);
447 AccountScrubImbalance (acc,
false, percentagefunc);
451 get_balance_split (Transaction *trans,
Account *root,
Account *account,
452 gnc_commodity *commodity)
454 Split *balance_split;
466 PERR (
"Bad data corruption, no root account in book");
470 accname = g_strconcat (_(
"Imbalance"),
"-",
472 account = xaccScrubUtilityGetOrMakeAccount (root, commodity,
478 PERR (
"Can't get balancing account");
483 balance_split = xaccTransFindSplitByAccount(trans, account);
491 xaccSplitSetParent(balance_split, trans);
492 xaccSplitSetAccount(balance_split, account);
496 return balance_split;
499 static gnc_commodity*
500 find_root_currency(
void)
502 QofSession *sess = gnc_get_current_session ();
512 for (GList *node = children; node && !root_currency;
513 node = g_list_next (node))
515 Account *child = GNC_ACCOUNT (node->data);
519 g_list_free (children);
521 return root_currency;
527 get_trading_split (Transaction *trans,
Account *base,
528 gnc_commodity *commodity)
530 Split *balance_split;
536 trading_account = xaccScrubUtilityGetOrMakeAccount (root,
541 if (!trading_account)
543 PERR (
"Can't get trading account");
547 ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,
554 PERR (
"Can't get namespace account");
558 account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,
564 PERR (
"Can't get commodity account");
569 balance_split = xaccTransFindSplitByAccount(trans, account);
577 xaccSplitSetParent(balance_split, trans);
578 xaccSplitSetAccount(balance_split, account);
582 return balance_split;
586 add_balance_split (Transaction *trans, gnc_numeric imbalance,
589 const gnc_commodity *commodity;
590 gnc_numeric old_value, new_value;
591 Split *balance_split;
594 balance_split = get_balance_split(trans, root, account, currency);
628 gnc_transaction_balance_no_trading (Transaction *trans,
Account *root,
636 PINFO (
"Value unbalanced transaction");
638 add_balance_split (trans, imbalance, root, account);
644 gnc_transaction_get_commodity_imbalance (Transaction *trans,
645 gnc_commodity *commodity)
648 gnc_numeric val_imbalance = gnc_numeric_zero();
649 GList *splits =
nullptr;
650 for (splits = trans->splits; splits; splits = splits->next)
652 Split *split = GNC_SPLIT(splits->data);
653 gnc_commodity *split_commodity =
655 if (xaccTransStillHasSplit (trans, split) &&
662 return val_imbalance;
667 destroy_split (
void* ptr)
669 Split *split = GNC_SPLIT (ptr);
678 xaccTransClearTradingSplits (Transaction *trans)
680 GList *trading_splits =
nullptr;
682 for (GList* node = trans->splits; node; node = node->next)
684 Split* split = GNC_SPLIT(node->data);
690 trading_splits = g_list_prepend (trading_splits, node->data);
700 g_list_free_full (trading_splits, destroy_split);
705 gnc_transaction_balance_trading (Transaction *trans,
Account *root)
707 MonetaryList *imbal_list;
708 MonetaryList *imbalance_commod;
709 Split *balance_split =
nullptr;
715 LEAVE(
"transaction is balanced");
719 PINFO (
"Currency unbalanced transaction");
721 for (imbalance_commod = imbal_list; imbalance_commod;
722 imbalance_commod = imbalance_commod->next)
724 auto imbal_mon =
static_cast<gnc_monetary*
>(imbalance_commod->data);
725 gnc_commodity *commodity;
726 gnc_numeric old_amount, new_amount;
729 commodity = gnc_monetary_commodity (*imbal_mon);
731 balance_split = get_trading_split(trans, root, commodity);
743 new_amount =
gnc_numeric_sub (old_amount, gnc_monetary_value(*imbal_mon),
757 gnc_numeric val_imbalance = gnc_transaction_get_commodity_imbalance (trans, commodity);
780 gnc_transaction_balance_trading_more_splits (Transaction *trans,
Account *root)
783 GList *splits_dup = g_list_copy(trans->splits), *splits =
nullptr;
785 for (splits = splits_dup; splits; splits = splits->next)
787 Split *split = GNC_SPLIT(splits->data);
788 if (! xaccTransStillHasSplit(trans, split))
continue;
792 gnc_commodity *commodity;
793 gnc_numeric old_value, new_value;
794 Split *balance_split;
799 PERR(
"Split has no commodity");
802 balance_split = get_trading_split(trans, root, commodity);
825 g_list_free(splits_dup);
838 gnc_numeric imbalance;
850 LEAVE (
"transaction is balanced");
856 gnc_transaction_balance_no_trading (trans, root, account);
857 LEAVE (
"transaction balanced, no managed trading accounts");
861 xaccTransClearTradingSplits (trans);
865 PINFO (
"Value unbalanced transaction");
867 add_balance_split (trans, imbalance, root, account);
870 gnc_transaction_balance_trading (trans, root);
881 gnc_transaction_balance_trading_more_splits (trans, root);
883 PERR(
"Balancing currencies unbalanced value");
894 static gnc_commodity *
895 FindCommonExclSCurrency (
SplitList *splits,
896 gnc_commodity * ra, gnc_commodity * rb,
901 if (!splits)
return nullptr;
903 for (node = splits; node; node = node->next)
905 Split *s = GNC_SPLIT(node->data);
906 gnc_commodity * sa, * sb;
908 if (s == excl_split)
continue;
910 g_return_val_if_fail (s->acc,
nullptr);
922 if ( (!aa) && bb) rb =
nullptr;
923 else if ( (!ab) && ba) rb =
nullptr;
924 else if ( (!ba) && ab) ra =
nullptr;
925 else if ( (!bb) && aa) ra =
nullptr;
926 else if ( aa && bb && ab && ba )
942 if ( aa && ab ) ra =
nullptr;
948 ra = ( aa && ab ) ?
nullptr : rb;
951 if ((!ra) && (!rb))
return nullptr;
961 static gnc_commodity *
962 FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb)
964 return FindCommonExclSCurrency(splits, ra, rb,
nullptr);
967 static gnc_commodity *
968 xaccTransFindOldCommonCurrency (Transaction *trans, QofBook *book)
970 gnc_commodity *ra, *rb, *retval;
973 if (!trans)
return nullptr;
975 if (trans->splits ==
nullptr)
return nullptr;
977 g_return_val_if_fail (book,
nullptr);
979 split = GNC_SPLIT(trans->splits->data);
981 if (!split ||
nullptr == split->acc)
return nullptr;
986 retval = FindCommonCurrency (trans->splits, ra, rb);
1000 gnc_commodity *commodity;
1005 commodity_equal (gconstpointer a, gconstpointer b)
1008 gnc_commodity *com = (gnc_commodity*)b;
1009 if ( cc ==
nullptr || cc->commodity ==
nullptr ||
1010 !GNC_IS_COMMODITY( cc->commodity ) )
return -1;
1011 if ( com ==
nullptr || !GNC_IS_COMMODITY( com ) )
return 1;
1018 commodity_compare( gconstpointer a, gconstpointer b)
1021 if (ca ==
nullptr || ca->commodity ==
nullptr ||
1022 !GNC_IS_COMMODITY( ca->commodity ) )
1024 if (cb ==
nullptr || cb->commodity ==
nullptr ||
1025 !GNC_IS_COMMODITY( cb->commodity ) )
1029 if (cb ==
nullptr || cb->commodity ==
nullptr ||
1030 !GNC_IS_COMMODITY( cb->commodity ) )
1032 if (ca->count == cb->count)
1034 return ca->count > cb->count ? 1 : -1;
1045 static gnc_commodity *
1046 xaccTransFindCommonCurrency (Transaction *trans, QofBook *book)
1048 gnc_commodity *com_scratch;
1049 GList *node =
nullptr;
1050 GSList *comlist =
nullptr, *found =
nullptr;
1052 if (!trans)
return nullptr;
1054 if (trans->splits ==
nullptr)
return nullptr;
1056 g_return_val_if_fail (book,
nullptr);
1062 for (node = trans->splits; node; node = node->next)
1064 Split *s = GNC_SPLIT(node->data);
1065 unsigned int curr_weight;
1067 if (s ==
nullptr || s->acc ==
nullptr)
continue;
1077 if (com_scratch ==
nullptr)
continue;
1082 found = g_slist_find_custom(comlist, com_scratch, commodity_equal);
1084 if (comlist ==
nullptr || found ==
nullptr)
1087 count->commodity = com_scratch;
1088 count->count = curr_weight;
1089 comlist = g_slist_append(comlist, count);
1094 count->count += curr_weight;
1097 found = g_slist_sort( comlist, commodity_compare);
1099 if ( found && found->data && (((
CommodityCount*)(found->data))->commodity !=
nullptr))
1105 return xaccTransFindOldCommonCurrency( trans, book );
1114 gnc_commodity *currency;
1136 if (
nullptr == trans->splits)
1138 PWARN (
"Transaction \"%s\" has no splits in it!", trans->description);
1145 PWARN (
"no common transaction currency found for trans=\"%s\" (%s);",
1146 trans->description, guid_str);
1148 for (node = trans->splits; node; node = node->next)
1150 Split *split = GNC_SPLIT(node->data);
1151 if (
nullptr == split->acc)
1153 PWARN (
" split=\"%s\" is not in any account!", split->memo);
1158 PWARN (
"setting to split=\"%s\" account=\"%s\" commodity=\"%s\"",
1172 for (node = trans->splits; node; node = node->next)
1174 Split *sp = GNC_SPLIT(node->data);
1179 gnc_commodity *acc_currency;
1182 if (acc_currency == currency)
1201 PWARN (
"Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\"" 1202 " old amount %s %s, new amount %s",
1203 trans->description, sp->memo,
1230 gnc_commodity *commodity;
1232 if (!account)
return;
1236 if (commodity)
return;
1254 PERR (
"Account \"%s\" does not have a commodity!",
1261 extern void qof_instance_set_dirty (
QofInstance*);
1264 xaccAccountDeleteOldData (
Account *account)
1266 if (!account)
return;
1272 qof_instance_set_dirty (QOF_INSTANCE (account));
1277 scrub_trans_currency_helper (Transaction *t, gpointer data)
1284 scrub_account_commodity_helper (
Account *account, gpointer data)
1288 xaccAccountDeleteOldData (account);
1299 scrub_account_commodity_helper (acc,
nullptr);
1307 check_quote_source (gnc_commodity *com, gpointer data)
1309 gboolean *commodity_has_quote_src = (gboolean *)data;
1316 move_quote_source (
Account *account, gpointer data)
1319 gnc_quote_source *quote_source;
1320 gboolean new_style = GPOINTER_TO_INT(data);
1321 const char *source, *tz;
1330 if (!source || !*source)
1353 gboolean new_style = FALSE;
1356 if (!root || !
table)
1364 move_quote_source(root, GINT_TO_POINTER(new_style));
1366 GINT_TO_POINTER(new_style));
1367 LEAVE(
"Migration done");
1376 GValue v = G_VALUE_INIT;
1379 if (!account)
return;
1383 if (G_VALUE_HOLDS_STRING (&v))
1385 str2 = g_strstrip(g_value_dup_string(&v));
1386 if (strlen(str2) == 0)
1387 qof_instance_slot_delete (QOF_INSTANCE (account),
"notes");
1392 if ((G_VALUE_HOLDS_STRING (&v) &&
1393 strcmp(g_value_get_string (&v),
"false") == 0) ||
1394 (G_VALUE_HOLDS_BOOLEAN (&v) && ! g_value_get_boolean (&v)))
1395 qof_instance_slot_delete (QOF_INSTANCE (account),
"placeholder");
1398 qof_instance_slot_delete_if_empty (QOF_INSTANCE (account),
"hbci");
1407 GValue value_s = G_VALUE_INIT;
1408 gboolean already_scrubbed;
1413 already_scrubbed = (G_VALUE_HOLDS_STRING (&value_s) &&
1414 !g_strcmp0 (g_value_get_string (&value_s),
"true"));
1415 g_value_unset (&value_s);
1417 if (already_scrubbed)
1421 GValue value_b = G_VALUE_INIT;
1422 Account *root = gnc_book_get_root_account (book);
1426 for (ptr = accts; ptr; ptr = g_list_next (ptr))
1428 auto acct = GNC_ACCOUNT(ptr->data);
1431 if (g_strcmp0 (color,
"Not Set") == 0)
1434 g_list_free (accts);
1436 g_value_init (&value_b, G_TYPE_BOOLEAN);
1437 g_value_set_boolean (&value_b, TRUE);
1441 g_value_unset (&value_b);
1448 construct_account (
Account *root, gnc_commodity *currency,
const char *accname,
1451 gnc_commodity* root_currency = find_root_currency ();
1454 if (accname && *accname)
1456 if (currency || root_currency)
1468 find_root_currency_account_in_list (GList *acc_list)
1470 gnc_commodity* root_currency = find_root_currency();
1471 for (GList *node = acc_list; node; node = g_list_next (node))
1473 Account *acc = GNC_ACCOUNT (node->data);
1474 gnc_commodity *acc_commodity =
nullptr;
1475 if (G_UNLIKELY (!acc))
continue;
1485 find_account_matching_name_in_list (GList *acc_list,
const char* accname)
1487 for (GList* node = acc_list; node; node = g_list_next(node))
1489 Account *acc = GNC_ACCOUNT (node->data);
1490 if (G_UNLIKELY (!acc))
continue;
1498 xaccScrubUtilityGetOrMakeAccount (
Account *root, gnc_commodity * currency,
1500 gboolean placeholder, gboolean checkname)
1505 g_return_val_if_fail (root,
nullptr);
1509 checkname ? accname :
nullptr,
1513 return construct_account (root, currency, accname,
1514 acctype, placeholder);
1516 if (g_list_next(acc_list))
1519 acc = find_root_currency_account_in_list (acc_list);
1522 acc = find_account_matching_name_in_list (acc_list, accname);
1526 acc = GNC_ACCOUNT (acc_list->data);
1528 g_list_free (acc_list);
1536 if(orig == INT64_MAX)
1540 if(time != INT64_MAX)
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account's type.
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
int xaccAccountTreeForEachTransaction(Account *acc, TransactionCallback proc, void *data)
Traverse all of the transactions in the given account group.
This is the private header for the account structure.
void xaccAccountScrubKvp(Account *account)
Removes empty "notes", "placeholder", and "hbci" KVP slots from Accounts.
gboolean gnc_commodity_table_foreach_commodity(const gnc_commodity_table *table, gboolean(*f)(gnc_commodity *cm, gpointer user_data), gpointer user_data)
Call a function once for each commodity in the commodity table.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
void xaccTransScrubCurrency(Transaction *trans)
The xaccTransScrubCurrency method fixes transactions without a common_currency by looking for the mos...
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency...
gchar * gnc_num_dbg_to_string(gnc_numeric n)
Convert to string.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
void(* QofPercentageFunc)(const char *message, double percent)
The qof_session_load() method causes the QofBook to be made ready to to use with this URL/datastore...
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
GList * gnc_account_get_descendants_sorted(const Account *account)
This function returns a GList containing all the descendants of the specified account, sorted at each level.
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Determine whether this transaction should use commodity trading accounts.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
void xaccAccountTreeScrubCommodities(Account *acc)
The xaccAccountTreeScrubCommodities will scrub the currency/commodity of all accounts & transactions ...
gnc_commodity * DxaccAccountGetCurrency(const Account *acc)
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling 'func' on each...
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
Create a new quote source.
gboolean gnc_get_ongoing_scrub(void)
The gnc_get_ongoing_scrub () method returns TRUE if a scrub operation is ongoing. ...
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define PINFO(format, args...)
Print an informational note.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
gboolean xaccSplitDestroy(Split *split)
Destructor.
void xaccAccountScrubCommodity(Account *account)
The xaccAccountScrubCommodity method fixed accounts without a commodity by using the old account curr...
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
Retrieve the automatic price quote flag for the specified commodity.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
Set the automatic price quote timezone for the specified commodity.
#define DEBUG(format, args...)
Print a debugging message.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
Use any denominator which gives an exactly correct ratio of numerator to denominator.
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
gboolean xaccTransIsBalanced(const Transaction *trans)
Returns true if the transaction is balanced according to the rules currently in effect.
void xaccTransScrubPostedDate(Transaction *trans)
Changes Transaction date_posted timestamps from 00:00 local to 11:00 UTC.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
Account used to record multiple commodity transactions.
#define PWARN(format, args...)
Log a warning.
const char * xaccAccountGetColor(const Account *acc)
Get the account's color.
void gnc_set_abort_scrub(gboolean abort)
The gnc_set_abort_scrub () method causes a currently running scrub operation to stop, if abort is TRUE; gnc_set_abort_scrub(FALSE) must be called before any scrubbing operation.
convert single-entry accounts to clean double-entry
char * qof_print_date(time64 secs)
Convenience; calls through to qof_print_date_dmy_buff().
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
GList SplitList
GList of Split.
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
Account handling public routines.
void xaccAccountSetPlaceholder(Account *acc, gboolean val)
Set the "placeholder" flag for an account.
void xaccAccountSetColor(Account *acc, const char *str)
Set the account's Color.
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
The xaccTransGetImbalanceValue() method returns the total value of the transaction.
Income accounts are used to denote income.
Account public routines (C++ api)
void xaccAccountTreeScrubOrphans(Account *acc, QofPercentageFunc percentagefunc)
The xaccAccountTreeScrubOrphans() method performs this scrub for the indicated account and its childr...
void dxaccAccountSetPriceSrc(Account *acc, const char *src)
Set a string that identifies the Finance::Quote backend that should be used to retrieve online prices...
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
void gnc_monetary_list_free(MonetaryList *list)
Free a MonetaryList and all the monetaries it points to.
void xaccTransScrubImbalance(Transaction *trans, Account *root, Account *account)
Correct transaction imbalances.
const char * dxaccAccountGetQuoteTZ(const Account *acc)
Get the timezone to be used when interpreting the results from a given Finance::Quote backend...
void xaccSplitScrub(Split *split)
The xaccSplitScrub method ensures that if this split has the same commodity and currency, then it will have the same amount and value.
void xaccTransScrubSplits(Transaction *trans)
The xacc*ScrubSplits() calls xaccSplitScrub() on each split in the respective structure: transaction...
The bank account type denotes a savings or checking account held at a bank.
void xaccAccountScrubOrphans(Account *acc, QofPercentageFunc percentagefunc)
The xaccAccountScrubOrphans() method performs this scrub only for the indicated account, and not for any of its children.
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
void xaccTransScrubOrphans(Transaction *trans)
The xaccTransScrubOrphans() method scrubs only the splits in the given transaction.
#define xaccTransGetBook(X)
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
void dxaccAccountSetQuoteTZ(Account *acc, const char *tz)
Set the timezone to be used when interpreting the results from a given Finance::Quote backend...
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
gnc_commodity * gnc_account_get_currency_or_parent(const Account *account)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
Split * xaccMallocSplit(QofBook *book)
Constructor.
#define xaccTransGetGUID(X)
gnc_numeric gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a-b.
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by th...
void xaccTransSetDatePostedSecs(Transaction *trans, time64 secs)
The xaccTransSetDatePostedSecs() method will modify the posted date of the transaction, specified by a time64 (see ctime(3)).
const char * dxaccAccountGetPriceSrc(const Account *acc)
Get a string that identifies the Finance::Quote backend that should be used to retrieve online prices...
GList * gnc_account_get_children(const Account *account)
This routine returns a GList of all children accounts of the specified account.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
MonetaryList * xaccTransGetImbalance(const Transaction *trans)
The xaccTransGetImbalance method returns a list giving the value of the transaction in each currency ...
#define LEAVE(format, args...)
Print a function exit debugging message.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Account * xaccMallocAccount(QofBook *book)
Constructor.
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Account * gnc_account_get_root(Account *acc)
This routine returns the root account of the account tree that the specified account belongs to...
void xaccAccountScrubColorNotSet(QofBook *book)
Remove color slots that have a "Not Set" value, since 2.4.0, fixed in 3.4 This should only be run onc...
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
void xaccAccountTreeScrubQuoteSources(Account *root, gnc_commodity_table *table)
This routine will migrate the information about price quote sources from the account data structures ...
int gnc_numeric_same(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Equivalence predicate: Convert both a and b to denom using the specified DENOM and method HOW...
GDate xaccTransGetDatePostedGDate(const Transaction *trans)
Retrieve the posted date of the transaction.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
API for Transactions and Splits (journal entries)
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountSetName(Account *acc, const char *str)
Set the account's name.
The hidden root account of an account tree.
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
Commodity handling public routines.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Set the account's commodity.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
GList * gnc_account_lookup_by_type_and_commodity(Account *root, const char *name, GNCAccountType acctype, gnc_commodity *commodity)
Find a direct child account matching name, GNCAccountType, and/or commodity.