mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[Scrub.c] refactor xaccAccountTreeScrubOrphans
This commit is contained in:
@@ -107,47 +107,27 @@ get_all_transactions (Account *account, bool descendants)
|
|||||||
|
|
||||||
/* ================================================================ */
|
/* ================================================================ */
|
||||||
|
|
||||||
void
|
|
||||||
xaccAccountTreeScrubOrphans (Account *acc, QofPercentageFunc percentagefunc)
|
|
||||||
{
|
|
||||||
if (!acc) return;
|
|
||||||
|
|
||||||
if (abort_now)
|
|
||||||
(percentagefunc)(NULL, -1.0);
|
|
||||||
|
|
||||||
scrub_depth ++;
|
|
||||||
xaccAccountScrubOrphans (acc, percentagefunc);
|
|
||||||
gnc_account_foreach_descendant(acc,
|
|
||||||
(AccountCb)xaccAccountScrubOrphans, percentagefunc);
|
|
||||||
scrub_depth--;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
TransScrubOrphansFast (Transaction *trans, Account *root)
|
TransScrubOrphansFast (Transaction *trans, Account *root)
|
||||||
{
|
{
|
||||||
GList *node;
|
g_return_if_fail (trans && trans->common_currency && root);
|
||||||
gchar *accname;
|
|
||||||
|
|
||||||
if (!trans) return;
|
for (GList *node = trans->splits; node; node = node->next)
|
||||||
g_return_if_fail (root);
|
|
||||||
g_return_if_fail (trans->common_currency);
|
|
||||||
|
|
||||||
for (node = trans->splits; node; node = node->next)
|
|
||||||
{
|
{
|
||||||
Split *split = node->data;
|
Split *split = node->data;
|
||||||
Account *orph;
|
|
||||||
if (abort_now) break;
|
if (abort_now) break;
|
||||||
|
|
||||||
if (split->acc) continue;
|
if (split->acc) continue;
|
||||||
|
|
||||||
DEBUG ("Found an orphan\n");
|
DEBUG ("Found an orphan\n");
|
||||||
|
|
||||||
accname = g_strconcat (_("Orphan"), "-",
|
gchar *accname = g_strconcat
|
||||||
gnc_commodity_get_mnemonic (trans->common_currency),
|
(_("Orphan"), "-", gnc_commodity_get_mnemonic (trans->common_currency),
|
||||||
NULL);
|
NULL);
|
||||||
orph = xaccScrubUtilityGetOrMakeAccount (root, trans->common_currency,
|
|
||||||
accname, ACCT_TYPE_BANK,
|
Account *orph = xaccScrubUtilityGetOrMakeAccount
|
||||||
FALSE, TRUE);
|
(root, trans->common_currency, accname, ACCT_TYPE_BANK, false, true);
|
||||||
|
|
||||||
g_free (accname);
|
g_free (accname);
|
||||||
if (!orph) continue;
|
if (!orph) continue;
|
||||||
|
|
||||||
@@ -155,43 +135,47 @@ TransScrubOrphansFast (Transaction *trans, Account *root)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
xaccAccountScrubOrphans (Account *acc, QofPercentageFunc percentagefunc)
|
AccountScrubOrphans (Account *acc, bool descendants, QofPercentageFunc percentagefunc)
|
||||||
{
|
{
|
||||||
GList *node, *splits;
|
|
||||||
const char *str;
|
|
||||||
const char *message = _( "Looking for orphans in account %s: %u of %u");
|
|
||||||
guint total_splits = 0;
|
|
||||||
guint current_split = 0;
|
|
||||||
|
|
||||||
if (!acc) return;
|
if (!acc) return;
|
||||||
scrub_depth++;
|
scrub_depth++;
|
||||||
|
|
||||||
str = xaccAccountGetName (acc);
|
GList *transactions = get_all_transactions (acc, descendants);
|
||||||
str = str ? str : "(null)";
|
gint total_trans = g_list_length (transactions);
|
||||||
PINFO ("Looking for orphans in account %s\n", str);
|
const char *message = _( "Looking for orphans in transaction: %u of %u");
|
||||||
splits = xaccAccountGetSplitList(acc);
|
guint current_trans = 0;
|
||||||
total_splits = g_list_length (splits);
|
|
||||||
|
|
||||||
for (node = splits; node; node = node->next)
|
for (GList *node = transactions; node; current_trans++, node = node->next)
|
||||||
{
|
{
|
||||||
Split *split = node->data;
|
Transaction *trans = node->data;
|
||||||
if (current_split % 10 == 0)
|
if (current_trans % 10 == 0)
|
||||||
{
|
{
|
||||||
char *progress_msg = g_strdup_printf (message, str, current_split, total_splits);
|
char *progress_msg = g_strdup_printf (message, current_trans, total_trans);
|
||||||
(percentagefunc)(progress_msg, (100 * current_split) / total_splits);
|
(percentagefunc)(progress_msg, (100 * current_trans) / total_trans);
|
||||||
g_free (progress_msg);
|
g_free (progress_msg);
|
||||||
if (abort_now) break;
|
if (abort_now) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransScrubOrphansFast (xaccSplitGetParent (split),
|
TransScrubOrphansFast (trans, gnc_account_get_root (acc));
|
||||||
gnc_account_get_root (acc));
|
|
||||||
current_split++;
|
|
||||||
}
|
}
|
||||||
(percentagefunc)(NULL, -1.0);
|
(percentagefunc)(NULL, -1.0);
|
||||||
scrub_depth--;
|
scrub_depth--;
|
||||||
|
|
||||||
|
g_list_free (transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccAccountScrubOrphans (Account *acc, QofPercentageFunc percentagefunc)
|
||||||
|
{
|
||||||
|
AccountScrubOrphans (acc, false, percentagefunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccAccountTreeScrubOrphans (Account *acc, QofPercentageFunc percentagefunc)
|
||||||
|
{
|
||||||
|
AccountScrubOrphans (acc, true, percentagefunc);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xaccTransScrubOrphans (Transaction *trans)
|
xaccTransScrubOrphans (Transaction *trans)
|
||||||
|
|||||||
Reference in New Issue
Block a user