diff --git a/src/engine/Account.c b/src/engine/Account.c index f5a0552c4b..6baca391dc 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -804,7 +804,7 @@ xaccAccountSortSplits (Account *acc, gboolean force) { if (!acc || !acc->sort_dirty || (!force && acc->inst.editlevel > 0)) return; - acc->splits = g_list_sort(acc->splits, (GCompareFunc)xaccSplitDateOrder); + acc->splits = g_list_sort(acc->splits, (GCompareFunc)xaccSplitOrder); acc->sort_dirty = FALSE; acc->balance_dirty = TRUE; } diff --git a/src/engine/Split.c b/src/engine/Split.c index ea6dc7be81..71551858e9 100644 --- a/src/engine/Split.c +++ b/src/engine/Split.c @@ -525,7 +525,7 @@ xaccSplitCommitEdit(Split *s) if (!g_list_find(acc->splits, s)) { if (acc->inst.editlevel == 0) { acc->splits = g_list_insert_sorted( - acc->splits, s, (GCompareFunc)xaccSplitDateOrder); + acc->splits, s, (GCompareFunc)xaccSplitOrder); } else { acc->splits = g_list_prepend(acc->splits, s); acc->sort_dirty = TRUE; @@ -1126,8 +1126,8 @@ xaccSplitDestroy (Split *split) /********************************************************************\ \********************************************************************/ -int -xaccSplitDateOrder (const Split *sa, const Split *sb) +gint +xaccSplitOrder (const Split *sa, const Split *sb) { int retval; int comp; @@ -1178,6 +1178,30 @@ xaccSplitDateOrder (const Split *sa, const Split *sb) return 0; } +gint +xaccSplitOrderDateOnly (const Split *sa, const Split *sb) +{ + Transaction *ta, *tb; + + if (sa == sb) return 0; + /* nothing is always less than something */ + if (!sa && sb) return -1; + if (sa && !sb) return +1; + + ta = sa->parent; + tb = sb->parent; + if ( ta && !tb ) return -1; + if ( !ta && tb ) return +1; + if ( !ta && !tb ) return 0; + + /* if dates differ, return */ + DATE_CMP(ta,tb,date_posted); + + /* If the dates are the same, do not change the order */ + return -1; +} + + static gboolean get_corr_account_split(const Split *sa, const Split **retval) { @@ -1843,7 +1867,7 @@ gboolean xaccSplitRegister (void) { NULL }, }; - qof_class_register (GNC_ID_SPLIT, (QofSortFunc)xaccSplitDateOrder, params); + qof_class_register (GNC_ID_SPLIT, (QofSortFunc)xaccSplitOrder, params); qof_class_register (SPLIT_ACCT_FULLNAME, (QofSortFunc)xaccSplitCompareAccountFullNames, NULL); qof_class_register (SPLIT_CORR_ACCT_NAME, diff --git a/src/engine/Split.h b/src/engine/Split.h index 9eca38ba96..72faf6710b 100644 --- a/src/engine/Split.h +++ b/src/engine/Split.h @@ -348,7 +348,7 @@ const char *xaccSplitGetType(const Split *s); void xaccSplitMakeStockSplit(Split *s); /** - * The xaccSplitDateOrder(sa,sb) method is useful for sorting. + * The xaccSplitOrder(sa,sb) method is useful for sorting. * if sa and sb have different transactions, return their xaccTransOrder * return a negative value if split sa has a smaller currency-value than sb, * return a positive value if split sa has a larger currency-value than sb, @@ -359,7 +359,8 @@ void xaccSplitMakeStockSplit(Split *s); * Then it compares the reconciled flags, then the reconciled dates, * Finally, it returns zero if all of the above match. */ -int xaccSplitDateOrder (const Split *sa, const Split *sb); +gint xaccSplitOrder (const Split *sa, const Split *sb); +gint xaccSplitOrderDateOnly (const Split *sa, const Split *sb); /* diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 24d46d71e5..a07cf53e71 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -777,7 +777,7 @@ xaccTransGetAccountBalance (const Transaction *trans, /* This test needs to correspond to the comparison function used when sorting the splits for computing the running balance. */ - if (xaccSplitDateOrder (last_split, split) < 0) + if (xaccSplitOrder (last_split, split) < 0) last_split = split; } diff --git a/src/engine/gnc-lot.c b/src/engine/gnc-lot.c index d8f916266f..918d46afc9 100644 --- a/src/engine/gnc-lot.c +++ b/src/engine/gnc-lot.c @@ -375,7 +375,7 @@ gnc_lot_get_earliest_split (GNCLot *lot) { if (! lot->splits) return NULL; - lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder); + lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitOrderDateOnly); return lot->splits->data; } @@ -386,7 +386,7 @@ gnc_lot_get_latest_split (GNCLot *lot) if (! lot->splits) return NULL; - lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitDateOrder); + lot->splits = g_list_sort (lot->splits, (GCompareFunc) xaccSplitOrderDateOnly); for (node = lot->splits; node->next; node = node->next) ;