mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
fill in more functions to clean up lots
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8120 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
c39c2be3be
commit
18cc347bae
@ -30,8 +30,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gnc-engine.h"
|
||||
#include "AccountP.h"
|
||||
#include "TransactionP.h"
|
||||
#include "Scrub2.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-lot.h"
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
@ -57,6 +60,58 @@ xaccAccountHasTrades (Account *acc)
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
struct early_lot_s
|
||||
{
|
||||
GNCLot *lot;
|
||||
Timespec ts;
|
||||
int (*numeric_pred)(gnc_numeric);
|
||||
};
|
||||
|
||||
static gpointer earliest_helper (GNCLot *lot, gpointer user_data)
|
||||
{
|
||||
struct early_lot_s *els = user_data;
|
||||
Split *s;
|
||||
Transaction *trans;
|
||||
gnc_numeric bal;
|
||||
|
||||
if (gnc_lot_is_closed (lot)) return NULL;
|
||||
|
||||
/* We want a lot whose balance is of the correct sign */
|
||||
bal = gnc_lot_get_balance (lot);
|
||||
if (0 == (els->numeric_pred) (bal)) return NULL;
|
||||
|
||||
s = gnc_lot_get_earliest_split (lot);
|
||||
trans = s->parent;
|
||||
if ((els->ts.tv_sec > trans->date_posted.tv_sec) ||
|
||||
((els->ts.tv_sec == trans->date_posted.tv_sec) &&
|
||||
(els->ts.tv_nsec > trans->date_posted.tv_nsec)))
|
||||
{
|
||||
els->ts = trans->date_posted;
|
||||
els->lot = lot;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GNCLot *
|
||||
xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign)
|
||||
{
|
||||
struct early_lot_s es;
|
||||
|
||||
es.lot = NULL;
|
||||
es.ts.tv_sec = 10000000LL * ((long long) LONG_MAX);
|
||||
es.ts.tv_nsec = 0;
|
||||
|
||||
if (gnc_numeric_positive_p(sign)) es.numeric_pred = gnc_numeric_positive_p;
|
||||
else es.numeric_pred = gnc_numeric_negative_p;
|
||||
|
||||
xaccAccountForEachLot (acc, earliest_helper, &es);
|
||||
return es.lot;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
#if 0
|
||||
void
|
||||
xaccAccountScrubLots (Account *acc)
|
||||
{
|
||||
@ -71,5 +126,6 @@ xaccAccountScrubLots (Account *acc)
|
||||
gnc_lot_is_closed (lot);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* =========================== END OF FILE ======================= */
|
||||
|
@ -47,5 +47,21 @@
|
||||
*/
|
||||
gboolean xaccAccountHasTrades (Account *);
|
||||
|
||||
/** The xaccAccountFindEarliestOpenLot() method is a handy
|
||||
* utility routine for finding the earliest open lot in
|
||||
* an account whose lot balance is *opposite* to the
|
||||
* passed argument 'sign'. By 'earliest lot', we mean
|
||||
* the lot that has a split with the earliest 'date_posted'.
|
||||
* The sign comparison helps identify a lot that can be
|
||||
* added to: usually, one wants to add splits to a lot so
|
||||
* that the balance only decreases.
|
||||
*/
|
||||
GNCLot * xaccAccountFindEarliestOpenLot (Account *acc, gnc_numeric sign);
|
||||
|
||||
|
||||
/** XXX need docos
|
||||
*/
|
||||
|
||||
|
||||
#endif /* XACC_SCRUB2_H */
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user