Skip to content

Commit

Permalink
[window-reconcile] save reconciliation info
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Mar 16, 2020
1 parent 6564b39 commit 36a5127
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions gnucash/gnome/window-reconcile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,63 @@ 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 All @@ -2155,6 +2212,7 @@ recnFinishCB (GtkAction *action, RecnWindow *recnData)
gboolean auto_payment;
Account *account;
time64 date;
gint num_rec;

if (!gnc_numeric_zero_p (recnRecalculateBalance(recnData)))
{
Expand All @@ -2180,6 +2238,8 @@ recnFinishCB (GtkAction *action, RecnWindow *recnData)
xaccAccountClearReconcilePostpone (account);
xaccAccountSetReconcileLastDate (account, date);

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

if (auto_payment &&
(xaccAccountGetType (account) == ACCT_TYPE_CREDIT) &&
(gnc_numeric_negative_p (recnData->new_ending)))
Expand Down

0 comments on commit 36a5127

Please sign in to comment.