mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[Scrub.cpp] convert to cpp
This commit is contained in:
parent
dab32807ef
commit
ddfa664601
@ -142,7 +142,7 @@ set (engine_SOURCES
|
|||||||
SchedXaction.c
|
SchedXaction.c
|
||||||
SX-book.c
|
SX-book.c
|
||||||
SX-ttinfo.c
|
SX-ttinfo.c
|
||||||
Scrub.c
|
Scrub.cpp
|
||||||
Scrub2.c
|
Scrub2.c
|
||||||
Scrub3.c
|
Scrub3.c
|
||||||
ScrubBusiness.c
|
ScrubBusiness.c
|
||||||
|
@ -92,7 +92,7 @@ gnc_get_ongoing_scrub (void)
|
|||||||
static void add_transactions (const Account *account, GHashTable **ht)
|
static void add_transactions (const Account *account, GHashTable **ht)
|
||||||
{
|
{
|
||||||
for (GList *m = xaccAccountGetSplitList (account); m; m = g_list_next (m))
|
for (GList *m = xaccAccountGetSplitList (account); m; m = g_list_next (m))
|
||||||
g_hash_table_add (*ht, xaccSplitGetParent (m->data));
|
g_hash_table_add (*ht, xaccSplitGetParent (GNC_SPLIT(m->data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static GList*
|
static GList*
|
||||||
@ -116,7 +116,7 @@ TransScrubOrphansFast (Transaction *trans, Account *root)
|
|||||||
|
|
||||||
for (GList *node = trans->splits; node; node = node->next)
|
for (GList *node = trans->splits; node; node = node->next)
|
||||||
{
|
{
|
||||||
Split *split = node->data;
|
Split *split = GNC_SPLIT(node->data);
|
||||||
if (abort_now) break;
|
if (abort_now) break;
|
||||||
|
|
||||||
if (split->acc) continue;
|
if (split->acc) continue;
|
||||||
@ -125,7 +125,7 @@ TransScrubOrphansFast (Transaction *trans, Account *root)
|
|||||||
|
|
||||||
gchar *accname = g_strconcat
|
gchar *accname = g_strconcat
|
||||||
(_("Orphan"), "-", gnc_commodity_get_mnemonic (trans->common_currency),
|
(_("Orphan"), "-", gnc_commodity_get_mnemonic (trans->common_currency),
|
||||||
NULL);
|
nullptr);
|
||||||
|
|
||||||
Account *orph = xaccScrubUtilityGetOrMakeAccount
|
Account *orph = xaccScrubUtilityGetOrMakeAccount
|
||||||
(root, trans->common_currency, accname, ACCT_TYPE_BANK, false, true);
|
(root, trans->common_currency, accname, ACCT_TYPE_BANK, false, true);
|
||||||
@ -150,7 +150,7 @@ AccountScrubOrphans (Account *acc, bool descendants, QofPercentageFunc percentag
|
|||||||
|
|
||||||
for (GList *node = transactions; node; current_trans++, node = node->next)
|
for (GList *node = transactions; node; current_trans++, node = node->next)
|
||||||
{
|
{
|
||||||
Transaction *trans = node->data;
|
Transaction *trans = GNC_TRANSACTION(node->data);
|
||||||
if (current_trans % 10 == 0)
|
if (current_trans % 10 == 0)
|
||||||
{
|
{
|
||||||
char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
|
char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
|
||||||
@ -161,7 +161,7 @@ AccountScrubOrphans (Account *acc, bool descendants, QofPercentageFunc percentag
|
|||||||
|
|
||||||
TransScrubOrphansFast (trans, gnc_account_get_root (acc));
|
TransScrubOrphansFast (trans, gnc_account_get_root (acc));
|
||||||
}
|
}
|
||||||
(percentagefunc)(NULL, -1.0);
|
(percentagefunc)(nullptr, -1.0);
|
||||||
scrub_depth--;
|
scrub_depth--;
|
||||||
|
|
||||||
g_list_free (transactions);
|
g_list_free (transactions);
|
||||||
@ -183,14 +183,14 @@ void
|
|||||||
xaccTransScrubOrphans (Transaction *trans)
|
xaccTransScrubOrphans (Transaction *trans)
|
||||||
{
|
{
|
||||||
SplitList *node;
|
SplitList *node;
|
||||||
QofBook *book = NULL;
|
QofBook *book = nullptr;
|
||||||
Account *root = NULL;
|
Account *root = nullptr;
|
||||||
|
|
||||||
if (!trans) return;
|
if (!trans) return;
|
||||||
|
|
||||||
for (node = trans->splits; node; node = node->next)
|
for (node = trans->splits; node; node = node->next)
|
||||||
{
|
{
|
||||||
Split *split = node->data;
|
Split *split = GNC_SPLIT(node->data);
|
||||||
if (abort_now) break;
|
if (abort_now) break;
|
||||||
|
|
||||||
if (split->acc)
|
if (split->acc)
|
||||||
@ -220,7 +220,7 @@ xaccAccountTreeScrubSplits (Account *account)
|
|||||||
|
|
||||||
xaccAccountScrubSplits (account);
|
xaccAccountScrubSplits (account);
|
||||||
gnc_account_foreach_descendant(account,
|
gnc_account_foreach_descendant(account,
|
||||||
(AccountCb)xaccAccountScrubSplits, NULL);
|
(AccountCb)xaccAccountScrubSplits, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -231,7 +231,7 @@ xaccAccountScrubSplits (Account *account)
|
|||||||
for (node = xaccAccountGetSplitList (account); node; node = node->next)
|
for (node = xaccAccountGetSplitList (account); node; node = node->next)
|
||||||
{
|
{
|
||||||
if (abort_now) break;
|
if (abort_now) break;
|
||||||
xaccSplitScrub (node->data);
|
xaccSplitScrub (GNC_SPLIT(node->data));
|
||||||
}
|
}
|
||||||
scrub_depth--;
|
scrub_depth--;
|
||||||
}
|
}
|
||||||
@ -371,7 +371,7 @@ AccountScrubImbalance (Account *acc, bool descendants,
|
|||||||
scrub_depth++;
|
scrub_depth++;
|
||||||
for (GList *node = transactions; node; node = node->next, curr_trans++)
|
for (GList *node = transactions; node; node = node->next, curr_trans++)
|
||||||
{
|
{
|
||||||
Transaction *trans = node->data;
|
Transaction *trans = GNC_TRANSACTION(node->data);
|
||||||
if (abort_now) break;
|
if (abort_now) break;
|
||||||
|
|
||||||
PINFO("Start processing transaction %d of %d", curr_trans + 1, count);
|
PINFO("Start processing transaction %d of %d", curr_trans + 1, count);
|
||||||
@ -387,11 +387,11 @@ AccountScrubImbalance (Account *acc, bool descendants,
|
|||||||
|
|
||||||
TransScrubOrphansFast (trans, root);
|
TransScrubOrphansFast (trans, root);
|
||||||
xaccTransScrubCurrency(trans);
|
xaccTransScrubCurrency(trans);
|
||||||
xaccTransScrubImbalance (trans, root, NULL);
|
xaccTransScrubImbalance (trans, root, nullptr);
|
||||||
|
|
||||||
PINFO("Finished processing transaction %d of %d", curr_trans + 1, count);
|
PINFO("Finished processing transaction %d of %d", curr_trans + 1, count);
|
||||||
}
|
}
|
||||||
(percentagefunc)(NULL, -1.0);
|
(percentagefunc)(nullptr, -1.0);
|
||||||
scrub_depth--;
|
scrub_depth--;
|
||||||
|
|
||||||
g_list_free (transactions);
|
g_list_free (transactions);
|
||||||
@ -409,7 +409,7 @@ xaccTransScrubSplits (Transaction *trans)
|
|||||||
bool must_scrub = false;
|
bool must_scrub = false;
|
||||||
|
|
||||||
for (GList *n = xaccTransGetSplitList (trans); !must_scrub && n; n = g_list_next (n))
|
for (GList *n = xaccTransGetSplitList (trans); !must_scrub && n; n = g_list_next (n))
|
||||||
if (split_scrub_or_dry_run (n->data, true))
|
if (split_scrub_or_dry_run (GNC_SPLIT(n->data), true))
|
||||||
must_scrub = true;
|
must_scrub = true;
|
||||||
|
|
||||||
if (!must_scrub)
|
if (!must_scrub)
|
||||||
@ -419,7 +419,7 @@ xaccTransScrubSplits (Transaction *trans)
|
|||||||
/* The split scrub expects the transaction to have a currency! */
|
/* The split scrub expects the transaction to have a currency! */
|
||||||
|
|
||||||
for (GList *n = xaccTransGetSplitList (trans); n; n = g_list_next (n))
|
for (GList *n = xaccTransGetSplitList (trans); n; n = g_list_next (n))
|
||||||
xaccSplitScrub (n->data);
|
xaccSplitScrub (GNC_SPLIT(n->data));
|
||||||
|
|
||||||
xaccTransCommitEdit(trans);
|
xaccTransCommitEdit(trans);
|
||||||
}
|
}
|
||||||
@ -460,15 +460,15 @@ get_balance_split (Transaction *trans, Account *root, Account *account,
|
|||||||
if (!root)
|
if (!root)
|
||||||
{
|
{
|
||||||
root = gnc_book_get_root_account (xaccTransGetBook (trans));
|
root = gnc_book_get_root_account (xaccTransGetBook (trans));
|
||||||
if (NULL == root)
|
if (nullptr == root)
|
||||||
{
|
{
|
||||||
/* This can't occur, things should be in books */
|
/* This can't occur, things should be in books */
|
||||||
PERR ("Bad data corruption, no root account in book");
|
PERR ("Bad data corruption, no root account in book");
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accname = g_strconcat (_("Imbalance"), "-",
|
accname = g_strconcat (_("Imbalance"), "-",
|
||||||
gnc_commodity_get_mnemonic (commodity), NULL);
|
gnc_commodity_get_mnemonic (commodity), nullptr);
|
||||||
account = xaccScrubUtilityGetOrMakeAccount (root, commodity,
|
account = xaccScrubUtilityGetOrMakeAccount (root, commodity,
|
||||||
accname, ACCT_TYPE_BANK,
|
accname, ACCT_TYPE_BANK,
|
||||||
FALSE, TRUE);
|
FALSE, TRUE);
|
||||||
@ -476,7 +476,7 @@ get_balance_split (Transaction *trans, Account *root, Account *account,
|
|||||||
if (!account)
|
if (!account)
|
||||||
{
|
{
|
||||||
PERR ("Can't get balancing account");
|
PERR ("Can't get balancing account");
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,25 +534,25 @@ get_trading_split (Transaction *trans, Account *base,
|
|||||||
Account* root = gnc_book_get_root_account (xaccTransGetBook (trans));
|
Account* root = gnc_book_get_root_account (xaccTransGetBook (trans));
|
||||||
|
|
||||||
trading_account = xaccScrubUtilityGetOrMakeAccount (root,
|
trading_account = xaccScrubUtilityGetOrMakeAccount (root,
|
||||||
NULL,
|
nullptr,
|
||||||
_("Trading"),
|
_("Trading"),
|
||||||
ACCT_TYPE_TRADING,
|
ACCT_TYPE_TRADING,
|
||||||
TRUE, FALSE);
|
TRUE, FALSE);
|
||||||
if (!trading_account)
|
if (!trading_account)
|
||||||
{
|
{
|
||||||
PERR ("Can't get trading account");
|
PERR ("Can't get trading account");
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,
|
ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,
|
||||||
NULL,
|
nullptr,
|
||||||
gnc_commodity_get_namespace(commodity),
|
gnc_commodity_get_namespace(commodity),
|
||||||
ACCT_TYPE_TRADING,
|
ACCT_TYPE_TRADING,
|
||||||
TRUE, TRUE);
|
TRUE, TRUE);
|
||||||
if (!ns_account)
|
if (!ns_account)
|
||||||
{
|
{
|
||||||
PERR ("Can't get namespace account");
|
PERR ("Can't get namespace account");
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,
|
account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,
|
||||||
@ -562,7 +562,7 @@ get_trading_split (Transaction *trans, Account *base,
|
|||||||
if (!account)
|
if (!account)
|
||||||
{
|
{
|
||||||
PERR ("Can't get commodity account");
|
PERR ("Can't get commodity account");
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -646,10 +646,10 @@ gnc_transaction_get_commodity_imbalance (Transaction *trans,
|
|||||||
{
|
{
|
||||||
/* Find the value imbalance in this commodity */
|
/* Find the value imbalance in this commodity */
|
||||||
gnc_numeric val_imbalance = gnc_numeric_zero();
|
gnc_numeric val_imbalance = gnc_numeric_zero();
|
||||||
GList *splits = NULL;
|
GList *splits = nullptr;
|
||||||
for (splits = trans->splits; splits; splits = splits->next)
|
for (splits = trans->splits; splits; splits = splits->next)
|
||||||
{
|
{
|
||||||
Split *split = splits->data;
|
Split *split = GNC_SPLIT(splits->data);
|
||||||
gnc_commodity *split_commodity =
|
gnc_commodity *split_commodity =
|
||||||
xaccAccountGetCommodity(xaccSplitGetAccount(split));
|
xaccAccountGetCommodity(xaccSplitGetAccount(split));
|
||||||
if (xaccTransStillHasSplit (trans, split) &&
|
if (xaccTransStillHasSplit (trans, split) &&
|
||||||
@ -677,12 +677,12 @@ destroy_split (void* ptr)
|
|||||||
static void
|
static void
|
||||||
xaccTransClearTradingSplits (Transaction *trans)
|
xaccTransClearTradingSplits (Transaction *trans)
|
||||||
{
|
{
|
||||||
GList *trading_splits = NULL;
|
GList *trading_splits = nullptr;
|
||||||
|
|
||||||
for (GList* node = trans->splits; node; node = node->next)
|
for (GList* node = trans->splits; node; node = node->next)
|
||||||
{
|
{
|
||||||
Split* split = GNC_SPLIT(node->data);
|
Split* split = GNC_SPLIT(node->data);
|
||||||
Account* acc = NULL;
|
Account* acc = nullptr;
|
||||||
if (!split)
|
if (!split)
|
||||||
continue;
|
continue;
|
||||||
acc = xaccSplitGetAccount(split);
|
acc = xaccSplitGetAccount(split);
|
||||||
@ -706,7 +706,7 @@ gnc_transaction_balance_trading (Transaction *trans, Account *root)
|
|||||||
{
|
{
|
||||||
MonetaryList *imbal_list;
|
MonetaryList *imbal_list;
|
||||||
MonetaryList *imbalance_commod;
|
MonetaryList *imbalance_commod;
|
||||||
Split *balance_split = NULL;
|
Split *balance_split = nullptr;
|
||||||
|
|
||||||
/* If the transaction is balanced, nothing more to do */
|
/* If the transaction is balanced, nothing more to do */
|
||||||
imbal_list = xaccTransGetImbalance (trans);
|
imbal_list = xaccTransGetImbalance (trans);
|
||||||
@ -721,7 +721,7 @@ gnc_transaction_balance_trading (Transaction *trans, Account *root)
|
|||||||
for (imbalance_commod = imbal_list; imbalance_commod;
|
for (imbalance_commod = imbal_list; imbalance_commod;
|
||||||
imbalance_commod = imbalance_commod->next)
|
imbalance_commod = imbalance_commod->next)
|
||||||
{
|
{
|
||||||
gnc_monetary *imbal_mon = imbalance_commod->data;
|
auto imbal_mon = static_cast<gnc_monetary*>(imbalance_commod->data);
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
gnc_numeric old_amount, new_amount;
|
gnc_numeric old_amount, new_amount;
|
||||||
const gnc_commodity *txn_curr = xaccTransGetCurrency (trans);
|
const gnc_commodity *txn_curr = xaccTransGetCurrency (trans);
|
||||||
@ -780,11 +780,11 @@ static void
|
|||||||
gnc_transaction_balance_trading_more_splits (Transaction *trans, Account *root)
|
gnc_transaction_balance_trading_more_splits (Transaction *trans, Account *root)
|
||||||
{
|
{
|
||||||
/* Copy the split list so we don't see the splits we're adding */
|
/* Copy the split list so we don't see the splits we're adding */
|
||||||
GList *splits_dup = g_list_copy(trans->splits), *splits = NULL;
|
GList *splits_dup = g_list_copy(trans->splits), *splits = nullptr;
|
||||||
const gnc_commodity *txn_curr = xaccTransGetCurrency (trans);
|
const gnc_commodity *txn_curr = xaccTransGetCurrency (trans);
|
||||||
for (splits = splits_dup; splits; splits = splits->next)
|
for (splits = splits_dup; splits; splits = splits->next)
|
||||||
{
|
{
|
||||||
Split *split = splits->data;
|
Split *split = GNC_SPLIT(splits->data);
|
||||||
if (! xaccTransStillHasSplit(trans, split)) continue;
|
if (! xaccTransStillHasSplit(trans, split)) continue;
|
||||||
if (!gnc_numeric_zero_p(xaccSplitGetValue(split)) &&
|
if (!gnc_numeric_zero_p(xaccSplitGetValue(split)) &&
|
||||||
gnc_numeric_zero_p(xaccSplitGetAmount(split)))
|
gnc_numeric_zero_p(xaccSplitGetAmount(split)))
|
||||||
@ -898,16 +898,16 @@ FindCommonExclSCurrency (SplitList *splits,
|
|||||||
{
|
{
|
||||||
GList *node;
|
GList *node;
|
||||||
|
|
||||||
if (!splits) return NULL;
|
if (!splits) return nullptr;
|
||||||
|
|
||||||
for (node = splits; node; node = node->next)
|
for (node = splits; node; node = node->next)
|
||||||
{
|
{
|
||||||
Split *s = node->data;
|
Split *s = GNC_SPLIT(node->data);
|
||||||
gnc_commodity * sa, * sb;
|
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, nullptr);
|
||||||
|
|
||||||
sa = DxaccAccountGetCurrency (s->acc);
|
sa = DxaccAccountGetCurrency (s->acc);
|
||||||
sb = xaccAccountGetCommodity (s->acc);
|
sb = xaccAccountGetCommodity (s->acc);
|
||||||
@ -919,36 +919,36 @@ FindCommonExclSCurrency (SplitList *splits,
|
|||||||
int ba = !gnc_commodity_equiv(rb, sa);
|
int ba = !gnc_commodity_equiv(rb, sa);
|
||||||
int bb = !gnc_commodity_equiv(rb, sb);
|
int bb = !gnc_commodity_equiv(rb, sb);
|
||||||
|
|
||||||
if ( (!aa) && bb) rb = NULL;
|
if ( (!aa) && bb) rb = nullptr;
|
||||||
else if ( (!ab) && ba) rb = NULL;
|
else if ( (!ab) && ba) rb = nullptr;
|
||||||
else if ( (!ba) && ab) ra = NULL;
|
else if ( (!ba) && ab) ra = nullptr;
|
||||||
else if ( (!bb) && aa) ra = NULL;
|
else if ( (!bb) && aa) ra = nullptr;
|
||||||
else if ( aa && bb && ab && ba )
|
else if ( aa && bb && ab && ba )
|
||||||
{
|
{
|
||||||
ra = NULL;
|
ra = nullptr;
|
||||||
rb = NULL;
|
rb = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ra)
|
if (!ra)
|
||||||
{
|
{
|
||||||
ra = rb;
|
ra = rb;
|
||||||
rb = NULL;
|
rb = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ra && !rb)
|
else if (ra && !rb)
|
||||||
{
|
{
|
||||||
int aa = !gnc_commodity_equiv(ra, sa);
|
int aa = !gnc_commodity_equiv(ra, sa);
|
||||||
int ab = !gnc_commodity_equiv(ra, sb);
|
int ab = !gnc_commodity_equiv(ra, sb);
|
||||||
if ( aa && ab ) ra = NULL;
|
if ( aa && ab ) ra = nullptr;
|
||||||
}
|
}
|
||||||
else if (!ra && rb)
|
else if (!ra && rb)
|
||||||
{
|
{
|
||||||
int aa = !gnc_commodity_equiv(rb, sa);
|
int aa = !gnc_commodity_equiv(rb, sa);
|
||||||
int ab = !gnc_commodity_equiv(rb, sb);
|
int ab = !gnc_commodity_equiv(rb, sb);
|
||||||
ra = ( aa && ab ) ? NULL : rb;
|
ra = ( aa && ab ) ? nullptr : rb;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!ra) && (!rb)) return NULL;
|
if ((!ra) && (!rb)) return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ra);
|
return (ra);
|
||||||
@ -961,7 +961,7 @@ FindCommonExclSCurrency (SplitList *splits,
|
|||||||
static gnc_commodity *
|
static gnc_commodity *
|
||||||
FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb)
|
FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb)
|
||||||
{
|
{
|
||||||
return FindCommonExclSCurrency(splits, ra, rb, NULL);
|
return FindCommonExclSCurrency(splits, ra, rb, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gnc_commodity *
|
static gnc_commodity *
|
||||||
@ -970,15 +970,15 @@ xaccTransFindOldCommonCurrency (Transaction *trans, QofBook *book)
|
|||||||
gnc_commodity *ra, *rb, *retval;
|
gnc_commodity *ra, *rb, *retval;
|
||||||
Split *split;
|
Split *split;
|
||||||
|
|
||||||
if (!trans) return NULL;
|
if (!trans) return nullptr;
|
||||||
|
|
||||||
if (trans->splits == NULL) return NULL;
|
if (trans->splits == nullptr) return nullptr;
|
||||||
|
|
||||||
g_return_val_if_fail (book, NULL);
|
g_return_val_if_fail (book, nullptr);
|
||||||
|
|
||||||
split = trans->splits->data;
|
split = GNC_SPLIT(trans->splits->data);
|
||||||
|
|
||||||
if (!split || NULL == split->acc) return NULL;
|
if (!split || nullptr == split->acc) return nullptr;
|
||||||
|
|
||||||
ra = DxaccAccountGetCurrency (split->acc);
|
ra = DxaccAccountGetCurrency (split->acc);
|
||||||
rb = xaccAccountGetCommodity (split->acc);
|
rb = xaccAccountGetCommodity (split->acc);
|
||||||
@ -986,13 +986,13 @@ xaccTransFindOldCommonCurrency (Transaction *trans, QofBook *book)
|
|||||||
retval = FindCommonCurrency (trans->splits, ra, rb);
|
retval = FindCommonCurrency (trans->splits, ra, rb);
|
||||||
|
|
||||||
if (retval && !gnc_commodity_is_currency(retval))
|
if (retval && !gnc_commodity_is_currency(retval))
|
||||||
retval = NULL;
|
retval = nullptr;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the currency of the splits and find the most common and return
|
/* Test the currency of the splits and find the most common and return
|
||||||
* it, or NULL if there is no currency more common than the
|
* it, or nullptr if there is no currency more common than the
|
||||||
* others -- or none at all.
|
* others -- or none at all.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -1006,9 +1006,9 @@ commodity_equal (gconstpointer a, gconstpointer b)
|
|||||||
{
|
{
|
||||||
CommodityCount *cc = (CommodityCount*)a;
|
CommodityCount *cc = (CommodityCount*)a;
|
||||||
gnc_commodity *com = (gnc_commodity*)b;
|
gnc_commodity *com = (gnc_commodity*)b;
|
||||||
if ( cc == NULL || cc->commodity == NULL ||
|
if ( cc == nullptr || cc->commodity == nullptr ||
|
||||||
!GNC_IS_COMMODITY( cc->commodity ) ) return -1;
|
!GNC_IS_COMMODITY( cc->commodity ) ) return -1;
|
||||||
if ( com == NULL || !GNC_IS_COMMODITY( com ) ) return 1;
|
if ( com == nullptr || !GNC_IS_COMMODITY( com ) ) return 1;
|
||||||
if ( gnc_commodity_equal(cc->commodity, com) )
|
if ( gnc_commodity_equal(cc->commodity, com) )
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
@ -1018,15 +1018,15 @@ static gint
|
|||||||
commodity_compare( gconstpointer a, gconstpointer b)
|
commodity_compare( gconstpointer a, gconstpointer b)
|
||||||
{
|
{
|
||||||
CommodityCount *ca = (CommodityCount*)a, *cb = (CommodityCount*)b;
|
CommodityCount *ca = (CommodityCount*)a, *cb = (CommodityCount*)b;
|
||||||
if (ca == NULL || ca->commodity == NULL ||
|
if (ca == nullptr || ca->commodity == nullptr ||
|
||||||
!GNC_IS_COMMODITY( ca->commodity ) )
|
!GNC_IS_COMMODITY( ca->commodity ) )
|
||||||
{
|
{
|
||||||
if (cb == NULL || cb->commodity == NULL ||
|
if (cb == nullptr || cb->commodity == nullptr ||
|
||||||
!GNC_IS_COMMODITY( cb->commodity ) )
|
!GNC_IS_COMMODITY( cb->commodity ) )
|
||||||
return 0;
|
return 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (cb == NULL || cb->commodity == NULL ||
|
if (cb == nullptr || cb->commodity == nullptr ||
|
||||||
!GNC_IS_COMMODITY( cb->commodity ) )
|
!GNC_IS_COMMODITY( cb->commodity ) )
|
||||||
return 1;
|
return 1;
|
||||||
if (ca->count == cb->count)
|
if (ca->count == cb->count)
|
||||||
@ -1046,14 +1046,14 @@ static gnc_commodity *
|
|||||||
xaccTransFindCommonCurrency (Transaction *trans, QofBook *book)
|
xaccTransFindCommonCurrency (Transaction *trans, QofBook *book)
|
||||||
{
|
{
|
||||||
gnc_commodity *com_scratch;
|
gnc_commodity *com_scratch;
|
||||||
GList *node = NULL;
|
GList *node = nullptr;
|
||||||
GSList *comlist = NULL, *found = NULL;
|
GSList *comlist = nullptr, *found = nullptr;
|
||||||
|
|
||||||
if (!trans) return NULL;
|
if (!trans) return nullptr;
|
||||||
|
|
||||||
if (trans->splits == NULL) return NULL;
|
if (trans->splits == nullptr) return nullptr;
|
||||||
|
|
||||||
g_return_val_if_fail (book, NULL);
|
g_return_val_if_fail (book, nullptr);
|
||||||
|
|
||||||
/* Find the most commonly used currency among the splits. If a given split
|
/* Find the most commonly used currency among the splits. If a given split
|
||||||
is in a non-currency commodity, then look for an ancestor account in a
|
is in a non-currency commodity, then look for an ancestor account in a
|
||||||
@ -1061,10 +1061,10 @@ xaccTransFindCommonCurrency (Transaction *trans, QofBook *book)
|
|||||||
account splits in this whole process, they don't add any value to this algorithm. */
|
account splits in this whole process, they don't add any value to this algorithm. */
|
||||||
for (node = trans->splits; node; node = node->next)
|
for (node = trans->splits; node; node = node->next)
|
||||||
{
|
{
|
||||||
Split *s = node->data;
|
Split *s = GNC_SPLIT(node->data);
|
||||||
unsigned int curr_weight;
|
unsigned int curr_weight;
|
||||||
|
|
||||||
if (s == NULL || s->acc == NULL) continue;
|
if (s == nullptr || s->acc == nullptr) continue;
|
||||||
if (xaccAccountGetType(s->acc) == ACCT_TYPE_TRADING) continue;
|
if (xaccAccountGetType(s->acc) == ACCT_TYPE_TRADING) continue;
|
||||||
com_scratch = xaccAccountGetCommodity(s->acc);
|
com_scratch = xaccAccountGetCommodity(s->acc);
|
||||||
if (com_scratch && gnc_commodity_is_currency(com_scratch))
|
if (com_scratch && gnc_commodity_is_currency(com_scratch))
|
||||||
@ -1074,14 +1074,14 @@ xaccTransFindCommonCurrency (Transaction *trans, QofBook *book)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
com_scratch = gnc_account_get_currency_or_parent(s->acc);
|
com_scratch = gnc_account_get_currency_or_parent(s->acc);
|
||||||
if (com_scratch == NULL) continue;
|
if (com_scratch == nullptr) continue;
|
||||||
curr_weight = 1;
|
curr_weight = 1;
|
||||||
}
|
}
|
||||||
if ( comlist )
|
if ( comlist )
|
||||||
{
|
{
|
||||||
found = g_slist_find_custom(comlist, com_scratch, commodity_equal);
|
found = g_slist_find_custom(comlist, com_scratch, commodity_equal);
|
||||||
}
|
}
|
||||||
if (comlist == NULL || found == NULL)
|
if (comlist == nullptr || found == nullptr)
|
||||||
{
|
{
|
||||||
CommodityCount *count = g_slice_new0(CommodityCount);
|
CommodityCount *count = g_slice_new0(CommodityCount);
|
||||||
count->commodity = com_scratch;
|
count->commodity = com_scratch;
|
||||||
@ -1096,7 +1096,7 @@ xaccTransFindCommonCurrency (Transaction *trans, QofBook *book)
|
|||||||
}
|
}
|
||||||
found = g_slist_sort( comlist, commodity_compare);
|
found = g_slist_sort( comlist, commodity_compare);
|
||||||
|
|
||||||
if ( found && found->data && (((CommodityCount*)(found->data))->commodity != NULL))
|
if ( found && found->data && (((CommodityCount*)(found->data))->commodity != nullptr))
|
||||||
{
|
{
|
||||||
return ((CommodityCount*)(found->data))->commodity;
|
return ((CommodityCount*)(found->data))->commodity;
|
||||||
}
|
}
|
||||||
@ -1133,7 +1133,7 @@ xaccTransScrubCurrency (Transaction *trans)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (NULL == trans->splits)
|
if (nullptr == trans->splits)
|
||||||
{
|
{
|
||||||
PWARN ("Transaction \"%s\" has no splits in it!", trans->description);
|
PWARN ("Transaction \"%s\" has no splits in it!", trans->description);
|
||||||
}
|
}
|
||||||
@ -1147,8 +1147,8 @@ xaccTransScrubCurrency (Transaction *trans)
|
|||||||
|
|
||||||
for (node = trans->splits; node; node = node->next)
|
for (node = trans->splits; node; node = node->next)
|
||||||
{
|
{
|
||||||
Split *split = node->data;
|
Split *split = GNC_SPLIT(node->data);
|
||||||
if (NULL == split->acc)
|
if (nullptr == split->acc)
|
||||||
{
|
{
|
||||||
PWARN (" split=\"%s\" is not in any account!", split->memo);
|
PWARN (" split=\"%s\" is not in any account!", split->memo);
|
||||||
}
|
}
|
||||||
@ -1171,14 +1171,14 @@ xaccTransScrubCurrency (Transaction *trans)
|
|||||||
|
|
||||||
for (node = trans->splits; node; node = node->next)
|
for (node = trans->splits; node; node = node->next)
|
||||||
{
|
{
|
||||||
Split *sp = node->data;
|
Split *sp = GNC_SPLIT(node->data);
|
||||||
|
|
||||||
if (!gnc_numeric_equal(xaccSplitGetAmount (sp),
|
if (!gnc_numeric_equal(xaccSplitGetAmount (sp),
|
||||||
xaccSplitGetValue (sp)))
|
xaccSplitGetValue (sp)))
|
||||||
{
|
{
|
||||||
gnc_commodity *acc_currency;
|
gnc_commodity *acc_currency;
|
||||||
|
|
||||||
acc_currency = sp->acc ? xaccAccountGetCommodity(sp->acc) : NULL;
|
acc_currency = sp->acc ? xaccAccountGetCommodity(sp->acc) : nullptr;
|
||||||
if (acc_currency == currency)
|
if (acc_currency == currency)
|
||||||
{
|
{
|
||||||
/* This Split needs fixing: The transaction-currency equals
|
/* This Split needs fixing: The transaction-currency equals
|
||||||
@ -1265,10 +1265,10 @@ xaccAccountDeleteOldData (Account *account)
|
|||||||
{
|
{
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
xaccAccountBeginEdit (account);
|
xaccAccountBeginEdit (account);
|
||||||
qof_instance_set_kvp (QOF_INSTANCE (account), NULL, 1, "old-currency");
|
qof_instance_set_kvp (QOF_INSTANCE (account), nullptr, 1, "old-currency");
|
||||||
qof_instance_set_kvp (QOF_INSTANCE (account), NULL, 1, "old-security");
|
qof_instance_set_kvp (QOF_INSTANCE (account), nullptr, 1, "old-security");
|
||||||
qof_instance_set_kvp (QOF_INSTANCE (account), NULL, 1, "old-currency-scu");
|
qof_instance_set_kvp (QOF_INSTANCE (account), nullptr, 1, "old-currency-scu");
|
||||||
qof_instance_set_kvp (QOF_INSTANCE (account), NULL, 1, "old-security-scu");
|
qof_instance_set_kvp (QOF_INSTANCE (account), nullptr, 1, "old-security-scu");
|
||||||
qof_instance_set_dirty (QOF_INSTANCE (account));
|
qof_instance_set_dirty (QOF_INSTANCE (account));
|
||||||
xaccAccountCommitEdit (account);
|
xaccAccountCommitEdit (account);
|
||||||
}
|
}
|
||||||
@ -1294,10 +1294,10 @@ xaccAccountTreeScrubCommodities (Account *acc)
|
|||||||
{
|
{
|
||||||
if (!acc) return;
|
if (!acc) return;
|
||||||
scrub_depth++;
|
scrub_depth++;
|
||||||
xaccAccountTreeForEachTransaction (acc, scrub_trans_currency_helper, NULL);
|
xaccAccountTreeForEachTransaction (acc, scrub_trans_currency_helper, nullptr);
|
||||||
|
|
||||||
scrub_account_commodity_helper (acc, NULL);
|
scrub_account_commodity_helper (acc, nullptr);
|
||||||
gnc_account_foreach_descendant (acc, scrub_account_commodity_helper, NULL);
|
gnc_account_foreach_descendant (acc, scrub_account_commodity_helper, nullptr);
|
||||||
scrub_depth--;
|
scrub_depth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1341,8 +1341,8 @@ move_quote_source (Account *account, gpointer data)
|
|||||||
gnc_commodity_set_quote_tz(com, tz);
|
gnc_commodity_set_quote_tz(com, tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
dxaccAccountSetPriceSrc(account, NULL);
|
dxaccAccountSetPriceSrc(account, nullptr);
|
||||||
dxaccAccountSetQuoteTZ(account, NULL);
|
dxaccAccountSetQuoteTZ(account, nullptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1425,10 +1425,11 @@ xaccAccountScrubColorNotSet (QofBook *book)
|
|||||||
|
|
||||||
for (ptr = accts; ptr; ptr = g_list_next (ptr))
|
for (ptr = accts; ptr; ptr = g_list_next (ptr))
|
||||||
{
|
{
|
||||||
const gchar *color = xaccAccountGetColor (ptr->data);
|
auto acct = GNC_ACCOUNT(ptr->data);
|
||||||
|
auto color = xaccAccountGetColor (acct);
|
||||||
|
|
||||||
if (g_strcmp0 (color, "Not Set") == 0)
|
if (g_strcmp0 (color, "Not Set") == 0)
|
||||||
xaccAccountSetColor (ptr->data, "");
|
xaccAccountSetColor (acct, "");
|
||||||
}
|
}
|
||||||
g_list_free (accts);
|
g_list_free (accts);
|
||||||
|
|
||||||
@ -1470,14 +1471,14 @@ find_root_currency_account_in_list (GList *acc_list)
|
|||||||
for (GList *node = acc_list; node; node = g_list_next (node))
|
for (GList *node = acc_list; node; node = g_list_next (node))
|
||||||
{
|
{
|
||||||
Account *acc = GNC_ACCOUNT (node->data);
|
Account *acc = GNC_ACCOUNT (node->data);
|
||||||
gnc_commodity *acc_commodity = NULL;
|
gnc_commodity *acc_commodity = nullptr;
|
||||||
if (G_UNLIKELY (!acc)) continue;
|
if (G_UNLIKELY (!acc)) continue;
|
||||||
acc_commodity = xaccAccountGetCommodity(acc);
|
acc_commodity = xaccAccountGetCommodity(acc);
|
||||||
if (gnc_commodity_equiv (acc_commodity, root_currency))
|
if (gnc_commodity_equiv (acc_commodity, root_currency))
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Account*
|
static Account*
|
||||||
@ -1490,7 +1491,7 @@ find_account_matching_name_in_list (GList *acc_list, const char* accname)
|
|||||||
if (g_strcmp0 (accname, xaccAccountGetName (acc)) == 0)
|
if (g_strcmp0 (accname, xaccAccountGetName (acc)) == 0)
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Account *
|
Account *
|
||||||
@ -1499,13 +1500,13 @@ xaccScrubUtilityGetOrMakeAccount (Account *root, gnc_commodity * currency,
|
|||||||
gboolean placeholder, gboolean checkname)
|
gboolean placeholder, gboolean checkname)
|
||||||
{
|
{
|
||||||
GList* acc_list;
|
GList* acc_list;
|
||||||
Account *acc = NULL;
|
Account *acc = nullptr;
|
||||||
|
|
||||||
g_return_val_if_fail (root, NULL);
|
g_return_val_if_fail (root, nullptr);
|
||||||
|
|
||||||
acc_list =
|
acc_list =
|
||||||
gnc_account_lookup_by_type_and_commodity (root,
|
gnc_account_lookup_by_type_and_commodity (root,
|
||||||
checkname ? accname : NULL,
|
checkname ? accname : nullptr,
|
||||||
acctype, currency);
|
acctype, currency);
|
||||||
|
|
||||||
if (!acc_list)
|
if (!acc_list)
|
@ -690,7 +690,7 @@ libgnucash/engine/Scrub2.c
|
|||||||
libgnucash/engine/Scrub3.c
|
libgnucash/engine/Scrub3.c
|
||||||
libgnucash/engine/ScrubBudget.c
|
libgnucash/engine/ScrubBudget.c
|
||||||
libgnucash/engine/ScrubBusiness.c
|
libgnucash/engine/ScrubBusiness.c
|
||||||
libgnucash/engine/Scrub.c
|
libgnucash/engine/Scrub.cpp
|
||||||
libgnucash/engine/Split.cpp
|
libgnucash/engine/Split.cpp
|
||||||
libgnucash/engine/SX-book.c
|
libgnucash/engine/SX-book.c
|
||||||
libgnucash/engine/SX-ttinfo.c
|
libgnucash/engine/SX-ttinfo.c
|
||||||
|
Loading…
Reference in New Issue
Block a user