42 #include <glib/gi18n.h> 48 #include <unordered_set> 55 #include "TransactionP.hpp" 57 #include "qofinstance-p.h" 58 #include "gnc-session.h" 61 #define G_LOG_DOMAIN "gnc.engine.scrub" 64 static gboolean abort_now = FALSE;
65 static gint scrub_depth = 0;
69 gnc_commodity* currency,
82 gnc_get_abort_scrub (
void)
90 return scrub_depth > 0;
95 using TransSet = std::unordered_set<Transaction*>;
98 get_all_transactions (
Account *account,
bool descendants)
101 auto add_transactions = [&
set](
auto a)
102 { gnc_account_foreach_split (a, [&
set](
auto s){
set.insert (
xaccSplitGetParent (s)); }); };
103 add_transactions (account);
105 gnc_account_foreach_descendant (account, add_transactions);
112 TransScrubOrphansFast (Transaction *trans,
Account *root)
114 g_return_if_fail (trans && trans->common_currency && root);
116 for (GList *node = trans->splits; node; node = node->next)
118 Split *split = GNC_SPLIT(node->data);
119 if (abort_now)
break;
121 if (split->acc)
continue;
123 DEBUG (
"Found an orphan\n");
125 gchar *accname = g_strconcat
129 Account *orph = xaccScrubUtilityGetOrMakeAccount
130 (root, trans->common_currency, accname,
ACCT_TYPE_BANK,
false,
true);
135 xaccSplitSetAccount(split, orph);
145 auto transactions = get_all_transactions (acc, descendants);
146 auto total_trans = transactions.size();
147 const char *message = _(
"Looking for orphans in transaction: %u of %zu");
148 guint current_trans = 0;
150 for (
auto trans : transactions)
152 if (current_trans % 10 == 0)
154 char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
155 (percentagefunc)(progress_msg, (100 * current_trans) / total_trans);
156 g_free (progress_msg);
157 if (abort_now)
break;
163 (percentagefunc)(
nullptr, -1.0);
170 AccountScrubOrphans (acc,
false, percentagefunc);
176 AccountScrubOrphans (acc,
true, percentagefunc);
188 for (node = trans->splits; node; node = node->next)
190 Split *split = GNC_SPLIT(node->data);
191 if (abort_now)
break;
205 PINFO (
"Free Floating Transaction!");
207 root = gnc_book_get_root_account (book);
208 TransScrubOrphansFast (trans, root);
214 xaccAccountTreeScrubSplits (
Account *account)
216 if (!account)
return;
218 xaccAccountScrubSplits (account);
219 gnc_account_foreach_descendant(account,
220 (AccountCb)xaccAccountScrubSplits,
nullptr);
224 xaccAccountScrubSplits (
Account *account)
227 for (
auto s : xaccAccountGetSplits (account))
229 if (abort_now)
break;
236 make_imbalance_account_name (
const gnc_commodity* currency)
244 split_scrub_or_dry_run (Split *split,
bool dry_run)
248 gnc_numeric value, amount;
249 gnc_commodity *currency, *acc_commodity;
252 if (!split)
return false;
253 ENTER (
"(split=%p)", split);
271 LEAVE (
"(split=%p) no account. must scrub orphans.", split);
285 PINFO (
"Free Floating Transaction!");
286 LEAVE (
"no account");
294 value = gnc_numeric_zero();
297 LEAVE (
"(split=%p) invalid value, reset to zero", split);
307 amount = gnc_numeric_zero();
310 LEAVE (
"(split=%p) invalid amount, reset to zero", split);
327 LEAVE (
"(split=%p) account without commodity", split);
335 LEAVE (
"(split=%p) inequiv currency", split);
339 auto null_or_empty = [](
const char* str) ->
bool {
return !str || !*str; };
340 if (xaccTransStillHasSplit (trans, split) &&
350 LEAVE (
"(split=%p) zero imbalance", split);
359 LEAVE(
"(split=%p) different values", split);
365 LEAVE(
"(split=%p) trans->currency == split->account->currency but amount != value, reset to value", split);
373 PINFO (
"Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\"" 374 " old amount %s %s, new amount %s",
375 trans->description, split->memo,
383 LEAVE (
"(split=%p)", split);
391 AccountScrubImbalance (
Account *acc,
bool descendants,
394 const char *message = _(
"Looking for imbalances in transaction date %s: %u of %zu");
399 Account *root = gnc_book_get_root_account (book);
400 auto transactions = get_all_transactions (acc, descendants);
401 auto count = transactions.size();
405 for (
auto trans : transactions)
407 if (abort_now)
break;
409 PINFO(
"Start processing transaction %d of %zu", curr_trans + 1, count);
411 if (curr_trans % 10 == 0)
414 char *progress_msg = g_strdup_printf (message, date, curr_trans, count);
415 (percentagefunc)(progress_msg, (100 * curr_trans) / count);
416 g_free (progress_msg);
420 TransScrubOrphansFast (trans, root);
424 PINFO(
"Finished processing transaction %d of %zu", curr_trans + 1, count);
427 (percentagefunc)(
nullptr, -1.0);
438 PERR (
"Transaction doesn't have a currency!");
440 bool must_scrub =
false;
443 if (split_scrub_or_dry_run (GNC_SPLIT(n->data),
true))
463 split_scrub_or_dry_run (split,
false);
472 AccountScrubImbalance (acc,
true, percentagefunc);
478 AccountScrubImbalance (acc,
false, percentagefunc);
482 get_balance_split (Transaction *trans,
Account *root,
Account *account,
483 gnc_commodity *commodity)
485 Split *balance_split;
496 PERR (
"Bad data corruption, no root account in book");
500 auto accname = make_imbalance_account_name (commodity);
501 account = xaccScrubUtilityGetOrMakeAccount (root, commodity,
506 PERR (
"Can't get balancing account");
511 balance_split = xaccTransFindSplitByAccount(trans, account);
519 xaccSplitSetParent(balance_split, trans);
520 xaccSplitSetAccount(balance_split, account);
524 return balance_split;
527 static gnc_commodity*
528 find_root_currency(
void)
530 QofSession *sess = gnc_get_current_session ();
540 for (GList *node = children; node && !root_currency;
541 node = g_list_next (node))
543 Account *child = GNC_ACCOUNT (node->data);
547 g_list_free (children);
549 return root_currency;
555 get_trading_split (Transaction *trans,
Account *base,
556 gnc_commodity *commodity)
558 Split *balance_split;
564 trading_account = xaccScrubUtilityGetOrMakeAccount (root,
569 if (!trading_account)
571 PERR (
"Can't get trading account");
575 ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,
582 PERR (
"Can't get namespace account");
586 account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,
592 PERR (
"Can't get commodity account");
597 balance_split = xaccTransFindSplitByAccount(trans, account);
603 xaccDisableDataScrubbing();
606 xaccSplitSetParent(balance_split, trans);
607 xaccSplitSetAccount(balance_split, account);
609 xaccEnableDataScrubbing();
612 return balance_split;
616 add_balance_split (Transaction *trans, gnc_numeric imbalance,
619 const gnc_commodity *commodity;
620 gnc_numeric old_value, new_value;
621 Split *balance_split;
624 balance_split = get_balance_split(trans, root, account, currency);
672 gnc_transaction_balance_no_trading (Transaction *trans,
Account *root,
680 PINFO (
"Value unbalanced transaction");
682 add_balance_split (trans, imbalance, root, account);
688 gnc_transaction_get_commodity_imbalance (Transaction *trans,
689 gnc_commodity *commodity)
692 gnc_numeric val_imbalance = gnc_numeric_zero();
693 GList *splits =
nullptr;
694 for (splits = trans->splits; splits; splits = splits->next)
696 Split *split = GNC_SPLIT(splits->data);
697 gnc_commodity *split_commodity =
699 if (xaccTransStillHasSplit (trans, split) &&
706 return val_imbalance;
711 destroy_split (
void* ptr)
713 Split *split = GNC_SPLIT (ptr);
722 xaccTransClearTradingSplits (Transaction *trans)
724 GList *trading_splits =
nullptr;
726 for (GList* node = trans->splits; node; node = node->next)
728 Split* split = GNC_SPLIT(node->data);
734 trading_splits = g_list_prepend (trading_splits, node->data);
744 g_list_free_full (trading_splits, destroy_split);
749 gnc_transaction_balance_trading (Transaction *trans,
Account *root)
751 MonetaryList *imbal_list;
752 MonetaryList *imbalance_commod;
753 Split *balance_split =
nullptr;
759 LEAVE(
"transaction is balanced");
763 PINFO (
"Currency unbalanced transaction");
765 for (imbalance_commod = imbal_list; imbalance_commod;
766 imbalance_commod = imbalance_commod->next)
768 auto imbal_mon =
static_cast<gnc_monetary*
>(imbalance_commod->data);
769 gnc_commodity *commodity;
770 gnc_numeric old_amount, new_amount;
773 commodity = gnc_monetary_commodity (*imbal_mon);
775 balance_split = get_trading_split(trans, root, commodity);
787 new_amount =
gnc_numeric_sub (old_amount, gnc_monetary_value(*imbal_mon),
801 gnc_numeric val_imbalance = gnc_transaction_get_commodity_imbalance (trans, commodity);
824 gnc_transaction_balance_trading_more_splits (Transaction *trans,
Account *root)
827 GList *splits_dup = g_list_copy(trans->splits), *splits =
nullptr;
829 for (splits = splits_dup; splits; splits = splits->next)
831 Split *split = GNC_SPLIT(splits->data);
832 if (! xaccTransStillHasSplit(trans, split))
continue;
836 gnc_commodity *commodity;
837 gnc_numeric old_value, new_value;
838 Split *balance_split;
843 PERR(
"Split has no commodity");
846 balance_split = get_trading_split(trans, root, commodity);
869 g_list_free(splits_dup);
882 gnc_numeric imbalance;
894 LEAVE (
"transaction is balanced");
900 gnc_transaction_balance_no_trading (trans, root, account);
901 LEAVE (
"transaction balanced, no managed trading accounts");
905 xaccTransClearTradingSplits (trans);
909 PINFO (
"Value unbalanced transaction");
911 add_balance_split (trans, imbalance, root, account);
914 gnc_transaction_balance_trading (trans, root);
925 gnc_transaction_balance_trading_more_splits (trans, root);
927 PERR(
"Balancing currencies unbalanced value");
938 static gnc_commodity *
939 FindCommonExclSCurrency (
SplitList *splits,
940 gnc_commodity * ra, gnc_commodity * rb,
945 if (!splits)
return nullptr;
947 for (node = splits; node; node = node->next)
949 Split *s = GNC_SPLIT(node->data);
950 gnc_commodity * sa, * sb;
952 if (s == excl_split)
continue;
954 g_return_val_if_fail (s->acc,
nullptr);
966 if ( (!aa) && bb) rb =
nullptr;
967 else if ( (!ab) && ba) rb =
nullptr;
968 else if ( (!ba) && ab) ra =
nullptr;
969 else if ( (!bb) && aa) ra =
nullptr;
970 else if ( aa && bb && ab && ba )
986 if ( aa && ab ) ra =
nullptr;
992 ra = ( aa && ab ) ?
nullptr : rb;
995 if ((!ra) && (!rb))
return nullptr;
1005 static gnc_commodity *
1006 FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb)
1008 return FindCommonExclSCurrency(splits, ra, rb,
nullptr);
1011 static gnc_commodity *
1012 xaccTransFindOldCommonCurrency (Transaction *trans,
QofBook *book)
1014 gnc_commodity *ra, *rb, *retval;
1017 if (!trans)
return nullptr;
1019 if (trans->splits ==
nullptr)
return nullptr;
1021 g_return_val_if_fail (book,
nullptr);
1023 split = GNC_SPLIT(trans->splits->data);
1025 if (!split ||
nullptr == split->acc)
return nullptr;
1030 retval = FindCommonCurrency (trans->splits, ra, rb);
1044 gnc_commodity *commodity;
1049 commodity_equal (gconstpointer a, gconstpointer b)
1052 gnc_commodity *com = (gnc_commodity*)b;
1053 if ( cc ==
nullptr || cc->commodity ==
nullptr ||
1054 !GNC_IS_COMMODITY( cc->commodity ) )
return -1;
1055 if ( com ==
nullptr || !GNC_IS_COMMODITY( com ) )
return 1;
1062 commodity_compare( gconstpointer a, gconstpointer b)
1065 if (ca ==
nullptr || ca->commodity ==
nullptr ||
1066 !GNC_IS_COMMODITY( ca->commodity ) )
1068 if (cb ==
nullptr || cb->commodity ==
nullptr ||
1069 !GNC_IS_COMMODITY( cb->commodity ) )
1073 if (cb ==
nullptr || cb->commodity ==
nullptr ||
1074 !GNC_IS_COMMODITY( cb->commodity ) )
1076 if (ca->count == cb->count)
1078 return ca->count > cb->count ? 1 : -1;
1089 static gnc_commodity *
1090 xaccTransFindCommonCurrency (Transaction *trans,
QofBook *book)
1092 gnc_commodity *com_scratch;
1093 GList *node =
nullptr;
1094 GSList *comlist =
nullptr, *found =
nullptr;
1096 if (!trans)
return nullptr;
1098 if (trans->splits ==
nullptr)
return nullptr;
1100 g_return_val_if_fail (book,
nullptr);
1106 for (node = trans->splits; node; node = node->next)
1108 Split *s = GNC_SPLIT(node->data);
1109 unsigned int curr_weight;
1111 if (s ==
nullptr || s->acc ==
nullptr)
continue;
1121 if (com_scratch ==
nullptr)
continue;
1126 found = g_slist_find_custom(comlist, com_scratch, commodity_equal);
1128 if (comlist ==
nullptr || found ==
nullptr)
1131 count->commodity = com_scratch;
1132 count->count = curr_weight;
1133 comlist = g_slist_append(comlist, count);
1138 count->count += curr_weight;
1141 found = g_slist_sort( comlist, commodity_compare);
1143 if ( found && found->data && (((
CommodityCount*)(found->data))->commodity !=
nullptr))
1149 return xaccTransFindOldCommonCurrency( trans, book );
1158 gnc_commodity *currency;
1180 if (
nullptr == trans->splits)
1182 PWARN (
"Transaction \"%s\" has no splits in it!", trans->description);
1189 PWARN (
"no common transaction currency found for trans=\"%s\" (%s);",
1190 trans->description, guid_str);
1192 for (node = trans->splits; node; node = node->next)
1194 Split *split = GNC_SPLIT(node->data);
1195 if (
nullptr == split->acc)
1197 PWARN (
" split=\"%s\" is not in any account!", split->memo);
1202 PWARN (
"setting to split=\"%s\" account=\"%s\" commodity=\"%s\"",
1216 for (node = trans->splits; node; node = node->next)
1218 Split *sp = GNC_SPLIT(node->data);
1223 gnc_commodity *acc_currency;
1226 if (acc_currency == currency)
1245 PWARN (
"Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\"" 1246 " old amount %s %s, new amount %s",
1247 trans->description, sp->memo,
1274 gnc_commodity *commodity;
1276 if (!account)
return;
1280 if (commodity)
return;
1298 PERR (
"Account \"%s\" does not have a commodity!",
1305 extern void qof_instance_set_dirty (
QofInstance*);
1308 xaccAccountDeleteOldData (
Account *account)
1310 if (!account)
return;
1316 qof_instance_set_dirty (QOF_INSTANCE (account));
1321 scrub_trans_currency_helper (Transaction *t, gpointer data)
1328 scrub_account_commodity_helper (
Account *account, gpointer data)
1332 xaccAccountDeleteOldData (account);
1343 scrub_account_commodity_helper (acc,
nullptr);
1344 gnc_account_foreach_descendant (acc, scrub_account_commodity_helper,
nullptr);
1351 check_quote_source (gnc_commodity *com, gpointer data)
1353 gboolean *commodity_has_quote_src = (gboolean *)data;
1360 move_quote_source (
Account *account, gpointer data)
1363 gnc_quote_source *quote_source;
1364 gboolean new_style = GPOINTER_TO_INT(data);
1365 const char *source, *tz;
1374 if (!source || !*source)
1397 gboolean new_style = FALSE;
1400 if (!root || !
table)
1408 move_quote_source(root, GINT_TO_POINTER(new_style));
1409 gnc_account_foreach_descendant (root, move_quote_source,
1410 GINT_TO_POINTER(new_style));
1411 LEAVE(
"Migration done");
1420 GValue v = G_VALUE_INIT;
1423 if (!account)
return;
1427 if (G_VALUE_HOLDS_STRING (&v))
1429 str2 = g_strstrip(g_value_dup_string(&v));
1430 if (strlen(str2) == 0)
1431 qof_instance_slot_delete (QOF_INSTANCE (account),
"notes");
1436 if ((G_VALUE_HOLDS_STRING (&v) &&
1437 strcmp(g_value_get_string (&v),
"false") == 0) ||
1438 (G_VALUE_HOLDS_BOOLEAN (&v) && ! g_value_get_boolean (&v)))
1439 qof_instance_slot_delete (QOF_INSTANCE (account),
"placeholder");
1442 qof_instance_slot_delete_if_empty (QOF_INSTANCE (account),
"hbci");
1451 GValue value_s = G_VALUE_INIT;
1452 gboolean already_scrubbed;
1457 already_scrubbed = (G_VALUE_HOLDS_STRING (&value_s) &&
1458 !g_strcmp0 (g_value_get_string (&value_s),
"true"));
1459 g_value_unset (&value_s);
1461 if (already_scrubbed)
1465 GValue value_b = G_VALUE_INIT;
1466 Account *root = gnc_book_get_root_account (book);
1470 for (ptr = accts; ptr; ptr = g_list_next (ptr))
1472 auto acct = GNC_ACCOUNT(ptr->data);
1475 if (g_strcmp0 (color,
"Not Set") == 0)
1478 g_list_free (accts);
1480 g_value_init (&value_b, G_TYPE_BOOLEAN);
1481 g_value_set_boolean (&value_b, TRUE);
1485 g_value_unset (&value_b);
1492 construct_account (
Account *root, gnc_commodity *currency,
const char *accname,
1495 gnc_commodity* root_currency = find_root_currency ();
1498 if (accname && *accname)
1500 if (currency || root_currency)
1512 find_root_currency_account_in_list (GList *acc_list)
1514 gnc_commodity* root_currency = find_root_currency();
1515 for (GList *node = acc_list; node; node = g_list_next (node))
1517 Account *acc = GNC_ACCOUNT (node->data);
1518 gnc_commodity *acc_commodity =
nullptr;
1519 if (G_UNLIKELY (!acc))
continue;
1529 find_account_matching_name_in_list (GList *acc_list,
const char* accname)
1531 for (GList* node = acc_list; node; node = g_list_next(node))
1533 Account *acc = GNC_ACCOUNT (node->data);
1534 if (G_UNLIKELY (!acc))
continue;
1542 xaccScrubUtilityGetOrMakeAccount (
Account *root, gnc_commodity * currency,
1544 gboolean placeholder, gboolean checkname)
1549 g_return_val_if_fail (root,
nullptr);
1553 checkname ? accname :
nullptr,
1557 return construct_account (root, currency, accname,
1558 acctype, placeholder);
1560 if (g_list_next(acc_list))
1563 acc = find_root_currency_account_in_list (acc_list);
1566 acc = find_account_matching_name_in_list (acc_list, accname);
1570 acc = GNC_ACCOUNT (acc_list->data);
1572 g_list_free (acc_list);
1580 if(orig == INT64_MAX)
1584 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)
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 a)
Check for error signal in value.
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
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 ...
gint 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.