42 #include <glib/gi18n.h> 47 #include <unordered_set> 54 #include "TransactionP.hpp" 56 #include "qofinstance-p.h" 57 #include "gnc-session.h" 60 #define G_LOG_DOMAIN "gnc.engine.scrub" 63 static gboolean abort_now = FALSE;
64 static gint scrub_depth = 0;
68 gnc_commodity* currency,
81 gnc_get_abort_scrub (
void)
89 return scrub_depth > 0;
94 using TransSet = std::unordered_set<Transaction*>;
97 get_all_transactions (
Account *account,
bool descendants)
100 auto add_transactions = [&
set](
auto a)
101 { gnc_account_foreach_split (a, [&
set](
auto s){
set.insert (
xaccSplitGetParent (s)); },
false); };
102 add_transactions (account);
104 gnc_account_foreach_descendant (account, add_transactions);
111 TransScrubOrphansFast (Transaction *trans,
Account *root)
113 g_return_if_fail (trans && trans->common_currency && root);
115 for (GList *node = trans->splits; node; node = node->next)
117 Split *split = GNC_SPLIT(node->data);
118 if (abort_now)
break;
120 if (split->acc)
continue;
122 DEBUG (
"Found an orphan\n");
124 gchar *accname = g_strconcat
128 Account *orph = xaccScrubUtilityGetOrMakeAccount
129 (root, trans->common_currency, accname,
ACCT_TYPE_BANK,
false,
true);
134 xaccSplitSetAccount(split, orph);
144 auto transactions = get_all_transactions (acc, descendants);
145 auto total_trans = transactions.size();
146 const char *message = _(
"Looking for orphans in transaction: %u of %zu");
147 guint current_trans = 0;
149 for (
auto trans : transactions)
151 if (current_trans % 10 == 0)
153 char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
154 (percentagefunc)(progress_msg, (100 * current_trans) / total_trans);
155 g_free (progress_msg);
156 if (abort_now)
break;
162 (percentagefunc)(
nullptr, -1.0);
169 AccountScrubOrphans (acc,
false, percentagefunc);
175 AccountScrubOrphans (acc,
true, percentagefunc);
182 QofBook *book =
nullptr;
187 for (node = trans->splits; node; node = node->next)
189 Split *split = GNC_SPLIT(node->data);
190 if (abort_now)
break;
204 PINFO (
"Free Floating Transaction!");
206 root = gnc_book_get_root_account (book);
207 TransScrubOrphansFast (trans, root);
213 xaccAccountTreeScrubSplits (
Account *account)
215 if (!account)
return;
217 xaccAccountScrubSplits (account);
218 gnc_account_foreach_descendant(account,
219 (AccountCb)xaccAccountScrubSplits,
nullptr);
223 xaccAccountScrubSplits (
Account *account)
226 for (
auto s : xaccAccountGetSplits (account))
228 if (abort_now)
break;
237 split_scrub_or_dry_run (Split *split,
bool dry_run)
241 gnc_numeric value, amount;
242 gnc_commodity *currency, *acc_commodity;
245 if (!split)
return false;
246 ENTER (
"(split=%p)", split);
275 PINFO (
"Free Floating Transaction!");
276 LEAVE (
"no account");
284 value = gnc_numeric_zero();
294 amount = gnc_numeric_zero();
316 LEAVE (
"(split=%p) inequiv currency", split);
325 LEAVE(
"(split=%p) different values", split);
336 PINFO (
"Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\"" 337 " old amount %s %s, new amount %s",
338 trans->description, split->memo,
346 LEAVE (
"(split=%p)", split);
354 AccountScrubImbalance (
Account *acc,
bool descendants,
357 const char *message = _(
"Looking for imbalances in transaction date %s: %u of %zu");
362 Account *root = gnc_book_get_root_account (book);
363 auto transactions = get_all_transactions (acc, descendants);
364 auto count = transactions.size();
368 for (
auto trans : transactions)
370 if (abort_now)
break;
372 PINFO(
"Start processing transaction %d of %zu", curr_trans + 1, count);
374 if (curr_trans % 10 == 0)
377 char *progress_msg = g_strdup_printf (message, date, curr_trans, count);
378 (percentagefunc)(progress_msg, (100 * curr_trans) / count);
379 g_free (progress_msg);
383 TransScrubOrphansFast (trans, root);
387 PINFO(
"Finished processing transaction %d of %zu", curr_trans + 1, count);
390 (percentagefunc)(
nullptr, -1.0);
401 PERR (
"Transaction doesn't have a currency!");
403 bool must_scrub =
false;
406 if (split_scrub_or_dry_run (GNC_SPLIT(n->data),
true))
426 split_scrub_or_dry_run (split,
false);
435 AccountScrubImbalance (acc,
true, percentagefunc);
441 AccountScrubImbalance (acc,
false, percentagefunc);
445 get_balance_split (Transaction *trans,
Account *root,
Account *account,
446 gnc_commodity *commodity)
448 Split *balance_split;
460 PERR (
"Bad data corruption, no root account in book");
464 accname = g_strconcat (_(
"Imbalance"),
"-",
466 account = xaccScrubUtilityGetOrMakeAccount (root, commodity,
472 PERR (
"Can't get balancing account");
477 balance_split = xaccTransFindSplitByAccount(trans, account);
485 xaccSplitSetParent(balance_split, trans);
486 xaccSplitSetAccount(balance_split, account);
490 return balance_split;
493 static gnc_commodity*
494 find_root_currency(
void)
496 QofSession *sess = gnc_get_current_session ();
506 for (GList *node = children; node && !root_currency;
507 node = g_list_next (node))
509 Account *child = GNC_ACCOUNT (node->data);
513 g_list_free (children);
515 return root_currency;
521 get_trading_split (Transaction *trans,
Account *base,
522 gnc_commodity *commodity)
524 Split *balance_split;
530 trading_account = xaccScrubUtilityGetOrMakeAccount (root,
535 if (!trading_account)
537 PERR (
"Can't get trading account");
541 ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,
548 PERR (
"Can't get namespace account");
552 account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,
558 PERR (
"Can't get commodity account");
563 balance_split = xaccTransFindSplitByAccount(trans, account);
571 xaccSplitSetParent(balance_split, trans);
572 xaccSplitSetAccount(balance_split, account);
576 return balance_split;
580 add_balance_split (Transaction *trans, gnc_numeric imbalance,
583 const gnc_commodity *commodity;
584 gnc_numeric old_value, new_value;
585 Split *balance_split;
588 balance_split = get_balance_split(trans, root, account, currency);
622 gnc_transaction_balance_no_trading (Transaction *trans,
Account *root,
630 PINFO (
"Value unbalanced transaction");
632 add_balance_split (trans, imbalance, root, account);
638 gnc_transaction_get_commodity_imbalance (Transaction *trans,
639 gnc_commodity *commodity)
642 gnc_numeric val_imbalance = gnc_numeric_zero();
643 GList *splits =
nullptr;
644 for (splits = trans->splits; splits; splits = splits->next)
646 Split *split = GNC_SPLIT(splits->data);
647 gnc_commodity *split_commodity =
649 if (xaccTransStillHasSplit (trans, split) &&
656 return val_imbalance;
661 destroy_split (
void* ptr)
663 Split *split = GNC_SPLIT (ptr);
672 xaccTransClearTradingSplits (Transaction *trans)
674 GList *trading_splits =
nullptr;
676 for (GList* node = trans->splits; node; node = node->next)
678 Split* split = GNC_SPLIT(node->data);
684 trading_splits = g_list_prepend (trading_splits, node->data);
694 g_list_free_full (trading_splits, destroy_split);
699 gnc_transaction_balance_trading (Transaction *trans,
Account *root)
701 MonetaryList *imbal_list;
702 MonetaryList *imbalance_commod;
703 Split *balance_split =
nullptr;
709 LEAVE(
"transaction is balanced");
713 PINFO (
"Currency unbalanced transaction");
715 for (imbalance_commod = imbal_list; imbalance_commod;
716 imbalance_commod = imbalance_commod->next)
718 auto imbal_mon =
static_cast<gnc_monetary*
>(imbalance_commod->data);
719 gnc_commodity *commodity;
720 gnc_numeric old_amount, new_amount;
723 commodity = gnc_monetary_commodity (*imbal_mon);
725 balance_split = get_trading_split(trans, root, commodity);
737 new_amount =
gnc_numeric_sub (old_amount, gnc_monetary_value(*imbal_mon),
751 gnc_numeric val_imbalance = gnc_transaction_get_commodity_imbalance (trans, commodity);
774 gnc_transaction_balance_trading_more_splits (Transaction *trans,
Account *root)
777 GList *splits_dup = g_list_copy(trans->splits), *splits =
nullptr;
779 for (splits = splits_dup; splits; splits = splits->next)
781 Split *split = GNC_SPLIT(splits->data);
782 if (! xaccTransStillHasSplit(trans, split))
continue;
786 gnc_commodity *commodity;
787 gnc_numeric old_value, new_value;
788 Split *balance_split;
793 PERR(
"Split has no commodity");
796 balance_split = get_trading_split(trans, root, commodity);
819 g_list_free(splits_dup);
832 gnc_numeric imbalance;
844 LEAVE (
"transaction is balanced");
850 gnc_transaction_balance_no_trading (trans, root, account);
851 LEAVE (
"transaction balanced, no managed trading accounts");
855 xaccTransClearTradingSplits (trans);
859 PINFO (
"Value unbalanced transaction");
861 add_balance_split (trans, imbalance, root, account);
864 gnc_transaction_balance_trading (trans, root);
875 gnc_transaction_balance_trading_more_splits (trans, root);
877 PERR(
"Balancing currencies unbalanced value");
888 static gnc_commodity *
889 FindCommonExclSCurrency (
SplitList *splits,
890 gnc_commodity * ra, gnc_commodity * rb,
895 if (!splits)
return nullptr;
897 for (node = splits; node; node = node->next)
899 Split *s = GNC_SPLIT(node->data);
900 gnc_commodity * sa, * sb;
902 if (s == excl_split)
continue;
904 g_return_val_if_fail (s->acc,
nullptr);
916 if ( (!aa) && bb) rb =
nullptr;
917 else if ( (!ab) && ba) rb =
nullptr;
918 else if ( (!ba) && ab) ra =
nullptr;
919 else if ( (!bb) && aa) ra =
nullptr;
920 else if ( aa && bb && ab && ba )
936 if ( aa && ab ) ra =
nullptr;
942 ra = ( aa && ab ) ?
nullptr : rb;
945 if ((!ra) && (!rb))
return nullptr;
955 static gnc_commodity *
956 FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb)
958 return FindCommonExclSCurrency(splits, ra, rb,
nullptr);
961 static gnc_commodity *
962 xaccTransFindOldCommonCurrency (Transaction *trans, QofBook *book)
964 gnc_commodity *ra, *rb, *retval;
967 if (!trans)
return nullptr;
969 if (trans->splits ==
nullptr)
return nullptr;
971 g_return_val_if_fail (book,
nullptr);
973 split = GNC_SPLIT(trans->splits->data);
975 if (!split ||
nullptr == split->acc)
return nullptr;
980 retval = FindCommonCurrency (trans->splits, ra, rb);
994 gnc_commodity *commodity;
999 commodity_equal (gconstpointer a, gconstpointer b)
1002 gnc_commodity *com = (gnc_commodity*)b;
1003 if ( cc ==
nullptr || cc->commodity ==
nullptr ||
1004 !GNC_IS_COMMODITY( cc->commodity ) )
return -1;
1005 if ( com ==
nullptr || !GNC_IS_COMMODITY( com ) )
return 1;
1012 commodity_compare( gconstpointer a, gconstpointer b)
1015 if (ca ==
nullptr || ca->commodity ==
nullptr ||
1016 !GNC_IS_COMMODITY( ca->commodity ) )
1018 if (cb ==
nullptr || cb->commodity ==
nullptr ||
1019 !GNC_IS_COMMODITY( cb->commodity ) )
1023 if (cb ==
nullptr || cb->commodity ==
nullptr ||
1024 !GNC_IS_COMMODITY( cb->commodity ) )
1026 if (ca->count == cb->count)
1028 return ca->count > cb->count ? 1 : -1;
1039 static gnc_commodity *
1040 xaccTransFindCommonCurrency (Transaction *trans, QofBook *book)
1042 gnc_commodity *com_scratch;
1043 GList *node =
nullptr;
1044 GSList *comlist =
nullptr, *found =
nullptr;
1046 if (!trans)
return nullptr;
1048 if (trans->splits ==
nullptr)
return nullptr;
1050 g_return_val_if_fail (book,
nullptr);
1056 for (node = trans->splits; node; node = node->next)
1058 Split *s = GNC_SPLIT(node->data);
1059 unsigned int curr_weight;
1061 if (s ==
nullptr || s->acc ==
nullptr)
continue;
1071 if (com_scratch ==
nullptr)
continue;
1076 found = g_slist_find_custom(comlist, com_scratch, commodity_equal);
1078 if (comlist ==
nullptr || found ==
nullptr)
1081 count->commodity = com_scratch;
1082 count->count = curr_weight;
1083 comlist = g_slist_append(comlist, count);
1088 count->count += curr_weight;
1091 found = g_slist_sort( comlist, commodity_compare);
1093 if ( found && found->data && (((
CommodityCount*)(found->data))->commodity !=
nullptr))
1099 return xaccTransFindOldCommonCurrency( trans, book );
1108 gnc_commodity *currency;
1130 if (
nullptr == trans->splits)
1132 PWARN (
"Transaction \"%s\" has no splits in it!", trans->description);
1139 PWARN (
"no common transaction currency found for trans=\"%s\" (%s);",
1140 trans->description, guid_str);
1142 for (node = trans->splits; node; node = node->next)
1144 Split *split = GNC_SPLIT(node->data);
1145 if (
nullptr == split->acc)
1147 PWARN (
" split=\"%s\" is not in any account!", split->memo);
1152 PWARN (
"setting to split=\"%s\" account=\"%s\" commodity=\"%s\"",
1166 for (node = trans->splits; node; node = node->next)
1168 Split *sp = GNC_SPLIT(node->data);
1173 gnc_commodity *acc_currency;
1176 if (acc_currency == currency)
1195 PWARN (
"Adjusted split with mismatched values, desc=\"%s\" memo=\"%s\"" 1196 " old amount %s %s, new amount %s",
1197 trans->description, sp->memo,
1224 gnc_commodity *commodity;
1226 if (!account)
return;
1230 if (commodity)
return;
1248 PERR (
"Account \"%s\" does not have a commodity!",
1255 extern void qof_instance_set_dirty (
QofInstance*);
1258 xaccAccountDeleteOldData (
Account *account)
1260 if (!account)
return;
1266 qof_instance_set_dirty (QOF_INSTANCE (account));
1271 scrub_trans_currency_helper (Transaction *t, gpointer data)
1278 scrub_account_commodity_helper (
Account *account, gpointer data)
1282 xaccAccountDeleteOldData (account);
1293 scrub_account_commodity_helper (acc,
nullptr);
1294 gnc_account_foreach_descendant (acc, scrub_account_commodity_helper,
nullptr);
1301 check_quote_source (gnc_commodity *com, gpointer data)
1303 gboolean *commodity_has_quote_src = (gboolean *)data;
1310 move_quote_source (
Account *account, gpointer data)
1313 gnc_quote_source *quote_source;
1314 gboolean new_style = GPOINTER_TO_INT(data);
1315 const char *source, *tz;
1324 if (!source || !*source)
1347 gboolean new_style = FALSE;
1350 if (!root || !
table)
1358 move_quote_source(root, GINT_TO_POINTER(new_style));
1359 gnc_account_foreach_descendant (root, move_quote_source,
1360 GINT_TO_POINTER(new_style));
1361 LEAVE(
"Migration done");
1370 GValue v = G_VALUE_INIT;
1373 if (!account)
return;
1377 if (G_VALUE_HOLDS_STRING (&v))
1379 str2 = g_strstrip(g_value_dup_string(&v));
1380 if (strlen(str2) == 0)
1381 qof_instance_slot_delete (QOF_INSTANCE (account),
"notes");
1386 if ((G_VALUE_HOLDS_STRING (&v) &&
1387 strcmp(g_value_get_string (&v),
"false") == 0) ||
1388 (G_VALUE_HOLDS_BOOLEAN (&v) && ! g_value_get_boolean (&v)))
1389 qof_instance_slot_delete (QOF_INSTANCE (account),
"placeholder");
1392 qof_instance_slot_delete_if_empty (QOF_INSTANCE (account),
"hbci");
1401 GValue value_s = G_VALUE_INIT;
1402 gboolean already_scrubbed;
1407 already_scrubbed = (G_VALUE_HOLDS_STRING (&value_s) &&
1408 !g_strcmp0 (g_value_get_string (&value_s),
"true"));
1409 g_value_unset (&value_s);
1411 if (already_scrubbed)
1415 GValue value_b = G_VALUE_INIT;
1416 Account *root = gnc_book_get_root_account (book);
1420 for (ptr = accts; ptr; ptr = g_list_next (ptr))
1422 auto acct = GNC_ACCOUNT(ptr->data);
1425 if (g_strcmp0 (color,
"Not Set") == 0)
1428 g_list_free (accts);
1430 g_value_init (&value_b, G_TYPE_BOOLEAN);
1431 g_value_set_boolean (&value_b, TRUE);
1435 g_value_unset (&value_b);
1442 construct_account (
Account *root, gnc_commodity *currency,
const char *accname,
1445 gnc_commodity* root_currency = find_root_currency ();
1448 if (accname && *accname)
1450 if (currency || root_currency)
1462 find_root_currency_account_in_list (GList *acc_list)
1464 gnc_commodity* root_currency = find_root_currency();
1465 for (GList *node = acc_list; node; node = g_list_next (node))
1467 Account *acc = GNC_ACCOUNT (node->data);
1468 gnc_commodity *acc_commodity =
nullptr;
1469 if (G_UNLIKELY (!acc))
continue;
1479 find_account_matching_name_in_list (GList *acc_list,
const char* accname)
1481 for (GList* node = acc_list; node; node = g_list_next(node))
1483 Account *acc = GNC_ACCOUNT (node->data);
1484 if (G_UNLIKELY (!acc))
continue;
1492 xaccScrubUtilityGetOrMakeAccount (
Account *root, gnc_commodity * currency,
1494 gboolean placeholder, gboolean checkname)
1499 g_return_val_if_fail (root,
nullptr);
1503 checkname ? accname :
nullptr,
1507 return construct_account (root, currency, accname,
1508 acctype, placeholder);
1510 if (g_list_next(acc_list))
1513 acc = find_root_currency_account_in_list (acc_list);
1516 acc = find_account_matching_name_in_list (acc_list, accname);
1520 acc = GNC_ACCOUNT (acc_list->data);
1522 g_list_free (acc_list);
1530 if(orig == INT64_MAX)
1534 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 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.