src/engine/Account.[ch]: add convenience function to find open lots

that meet caller's criteria, and create a
			 sorted list (maybe)


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7023 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2002-06-25 14:58:36 +00:00
parent 7ddf9aa4e8
commit 131add077d
2 changed files with 43 additions and 0 deletions

View File

@@ -1835,6 +1835,39 @@ xaccAccountGetLotList (Account *acc)
return (acc->lots);
}
LotList *
xaccAccountFindOpenLots (Account *acc,
gboolean (*match_func)(GNCLot *lot,
gpointer user_data),
gpointer user_data, GCompareFunc sort_func)
{
GList *lot_list;
GList *retval = NULL;
if (!acc)
return NULL;
lot_list = xaccAccountGetLotList (acc);
for ( ; lot_list ; lot_list = lot_list->next ) {
GNCLot *lot = lot_list->data;
/* If this lot is closed, then ignore it */
if (gnc_lot_is_closed (lot))
continue;
if (match_func && !(match_func)(lot, user_data))
continue;
/* Ok, this is a valid lot. Add it to our list of lots */
if (sort_func)
retval = g_list_insert_sorted (retval, lot, sort_func);
else
retval = g_list_prepend (retval, lot);
}
return retval;
}
/********************************************************************\
\********************************************************************/

View File

@@ -312,6 +312,16 @@ gnc_numeric xaccAccountGetBalanceAsOfDate (Account *account, time_t date);
SplitList* xaccAccountGetSplitList (Account *account);
LotList* xaccAccountGetLotList (Account *account);
/* Find a list of open lots that match the match_func. Sort according
* to sort_func. If match_func is NULL, then all open lots are returned.
* If sort_func is NULL, then the returned list has no particular order.
* The caller must free to returned list.
*/
LotList * xaccAccountFindOpenLots (Account *acc,
gboolean (*match_func)(GNCLot *lot,
gpointer user_data),
gpointer user_data, GCompareFunc sort_func);
gboolean xaccAccountGetTaxRelated (Account *account);
void xaccAccountSetTaxRelated (Account *account,
gboolean tax_related);