mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add utility routine to get earliest split in lot
convert tabs to spaces git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8118 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
e701237359
commit
d328d40114
@ -81,7 +81,7 @@ gnc_lot_destroy (GNCLot *lot)
|
||||
GList *node;
|
||||
if (!lot) return;
|
||||
|
||||
ENTER ("(lot=%p)", lot);
|
||||
ENTER ("(lot=%p)", lot);
|
||||
gnc_engine_generate_event (&lot->guid, GNC_EVENT_DESTROY);
|
||||
|
||||
xaccRemoveEntity (lot->book->entity_table, &lot->guid);
|
||||
@ -219,7 +219,7 @@ gnc_lot_add_split (GNCLot *lot, Split *split)
|
||||
Account * acc;
|
||||
if (!lot || !split) return;
|
||||
|
||||
ENTER ("(lot=%p, split=%p)", lot, split);
|
||||
ENTER ("(lot=%p, split=%p)", lot, split);
|
||||
acc = xaccSplitGetAccount (split);
|
||||
if (NULL == lot->account)
|
||||
{
|
||||
@ -251,10 +251,10 @@ gnc_lot_remove_split (GNCLot *lot, Split *split)
|
||||
{
|
||||
if (!lot || !split) return;
|
||||
|
||||
ENTER ("(lot=%p, split=%p)", lot, split);
|
||||
ENTER ("(lot=%p, split=%p)", lot, split);
|
||||
lot->splits = g_list_remove (lot->splits, split);
|
||||
split->lot = NULL;
|
||||
lot->is_closed = -1; /* force an is-closed computation */
|
||||
lot->is_closed = -1; /* force an is-closed computation */
|
||||
|
||||
if (NULL == lot->splits)
|
||||
{
|
||||
@ -263,6 +263,39 @@ gnc_lot_remove_split (GNCLot *lot, Split *split)
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Utility function, get earliest split in lot */
|
||||
|
||||
Split *
|
||||
gnc_lot_get_earliest_split (GNCLot *lot)
|
||||
{
|
||||
SplitList *node;
|
||||
Timespec ts;
|
||||
Split *earliest = NULL;
|
||||
|
||||
ts.tv_sec = 1000000LL * ((long long) LONG_MAX);
|
||||
ts.tv_nsec = 0;
|
||||
if (!lot) return NULL;
|
||||
|
||||
for (node=lot->splits; node; node=node->next)
|
||||
{
|
||||
Split *s = node->data;
|
||||
Transaction *trans = s->parent;
|
||||
if ((ts.tv_sec > trans->date_posted.tv_sec) ||
|
||||
((ts.tv_sec == trans->date_posted.tv_sec) &&
|
||||
(ts.tv_nsec > trans->date_posted.tv_nsec)))
|
||||
|
||||
{
|
||||
ts = trans->date_posted;
|
||||
earliest = s;
|
||||
}
|
||||
}
|
||||
|
||||
return earliest;
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
|
||||
void gnc_lot_register (void)
|
||||
{
|
||||
static const QueryObjectDef params[] = {
|
||||
|
@ -76,6 +76,13 @@ gnc_numeric gnc_lot_get_balance (GNCLot *);
|
||||
*/
|
||||
gboolean gnc_lot_is_closed (GNCLot *);
|
||||
|
||||
/** The gnc_lot_get_earliest_split() routine is a convenience routine
|
||||
* that helps identify the date this lot was opened. It simply
|
||||
* loops over all of the splits in the lot, and returns the split
|
||||
* with the earliest split->transaction->date_posted.
|
||||
*/
|
||||
Split * gnc_lot_get_earliest_split (GNCLot *lot);
|
||||
|
||||
/** Every lot has a place to hang kvp data. This routine returns that
|
||||
* place.
|
||||
* */
|
||||
|
Loading…
Reference in New Issue
Block a user