Skip to content

Commit

Permalink
[window-reconcile] use xaccAccountSetReconcileStatementBalanceAtDate
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Mar 17, 2020
1 parent a5e2a86 commit 59886c5
Showing 1 changed file with 2 additions and 58 deletions.
60 changes: 2 additions & 58 deletions gnucash/gnome/window-reconcile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2140,63 +2140,6 @@ find_payment_account(Account *account)
return NULL;
}

typedef struct DateBalPair
{
time64 date;
gnc_numeric bal;
} DateBalPair_t;

static int compare_date (void* a, void* b)
{
DateBalPair_t* da = (DateBalPair_t *)a;
DateBalPair_t* db = (DateBalPair_t *)b;
if (da->date < db->date) return -1;
if (da->date > db->date) return 1;
return 0;
}

static void
AccountSetReconcileDateBalance (Account *acc, time64 date, gnc_numeric balance)
{
GList *list = NULL;
gint num_recs, i;
DateBalPair_t *datebal;

if (!acc) return;

num_recs = xaccAccountGetReconcileNumDates (acc);
datebal = g_new0 (DateBalPair_t, 1);
datebal->date = date;
datebal->bal = balance;
list = g_list_prepend (list, datebal);

for (gint i = 0; i < num_recs; i++)
{
DateBalPair_t *datebal = g_new0 (DateBalPair_t, 1);

if (xaccAccountGetReconcileDateBalance (acc, i, &datebal->date, &datebal->bal))
{
if (datebal->date != date)
list = g_list_prepend (list, datebal);
}
else
PWARN ("AccountSetReconcileDateBalance error no rec-info %d exists", i);
}

xaccAccountClearReconcileDates (acc);

list = g_list_sort (list, (GCompareFunc) compare_date);

i = 0;
for (GList *node = list; node; node = node->next)
{
datebal = node->data;
xaccAccountSetReconcileDateBalance (acc, i, datebal->date, datebal->bal);
i++;
}
xaccAccountSetReconcileNumDates (acc, i);
return;
}

/********************************************************************\
* recnFinishCB *
Expand Down Expand Up @@ -2237,7 +2180,8 @@ recnFinishCB (GtkAction *action, RecnWindow *recnData)
xaccAccountClearReconcilePostpone (account);
xaccAccountSetReconcileLastDate (account, date);

AccountSetReconcileDateBalance (account, date, recnData->new_ending);
xaccAccountSetReconcileStatementBalanceAtDate (account, date,
recnData->new_ending);

if (auto_payment &&
(xaccAccountGetType (account) == ACCT_TYPE_CREDIT) &&
Expand Down

0 comments on commit 59886c5

Please sign in to comment.