38 #include "TransactionP.h" 46 #include <glib/gi18n.h> 48 #define N_(string) string 51 #define FIFO_POLICY "fifo" 52 #define FIFO_POLICY_DESC N_("First In, First Out") 53 #define FIFO_POLICY_HINT N_("Use oldest lots first.") 54 #define LIFO_POLICY "lifo" 55 #define LIFO_POLICY_DESC N_("Last In, First Out") 56 #define LIFO_POLICY_HINT N_("Use newest lots first.") 57 #define AVERAGE_POLICY "average" 58 #define AVERAGE_POLICY_DESC N_("Average") 59 #define AVERAGE_POLICY_HINT N_("Average cost of open lots.") 60 #define MANUAL_POLICY "manual" 61 #define MANUAL_POLICY_DESC N_("Manual") 62 #define MANUAL_POLICY_HINT N_("Manually select lots.") 67 DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot,
short reverse)
71 gnc_commodity *common_currency;
72 gboolean want_positive;
81 if (!lot_account)
return NULL;
91 common_currency = split->parent->common_currency;
107 node = g_list_last (node);
112 gboolean is_positive;
115 if (split->lot)
goto donext;
119 if (this_time < open_time)
129 split->parent->common_currency);
130 if (FALSE == is_match)
goto donext;
136 if ((want_positive && is_positive) ||
137 ((!want_positive) && (!is_positive)))
return split;
154 FIFOPolicyGetLot (GNCPolicy *pcy, Split *split)
156 if (!split)
return NULL;
158 split->parent->common_currency);
162 FIFOPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot)
164 return DirectionPolicyGetSplit (pcy, lot, 0);
168 FIFOPolicyGetLotOpening (GNCPolicy *pcy,
170 gnc_numeric *ret_amount, gnc_numeric *ret_value,
171 gnc_commodity **ret_currency)
173 Split *opening_split;
176 if (ret_amount) *ret_amount = opening_split->amount;
177 if (ret_value) *ret_value = opening_split->value;
178 if (ret_currency) *ret_currency = opening_split->parent->common_currency;
182 FIFOPolicyIsOpeningSplit (GNCPolicy *pcy, GNCLot *lot, Split *split)
184 Split *opening_split;
186 return (split == opening_split);
192 static GNCPolicy *pcy = NULL;
196 pcy = g_new (GNCPolicy, 1);
197 pcy->PolicyGetLot = FIFOPolicyGetLot;
198 pcy->PolicyGetSplit = FIFOPolicyGetSplit;
199 pcy->PolicyGetLotOpening = FIFOPolicyGetLotOpening;
200 pcy->PolicyIsOpeningSplit = FIFOPolicyIsOpeningSplit;
GNCLot * xaccAccountFindEarliestOpenLot(Account *acc, gnc_numeric sign, gnc_commodity *currency)
The xaccAccountFindEarliestOpenLot() method is a handy utility routine for finding the earliest open ...
SplitList * xaccAccountGetSplitList(const Account *acc)
The xaccAccountGetSplitList() routine returns a pointer to a GList of the splits in the account...
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
Split * gnc_lot_get_earliest_split(GNCLot *lot)
The gnc_lot_get_earliest_split() routine is a convenience routine that helps identify the earliest da...
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
Split * gnc_lot_get_latest_split(GNCLot *lot)
The gnc_lot_get_latest_split() routine is a convenience routine that helps identify the date this lot...
GList SplitList
GList of Split.
Account handling public routines.
Implement Accounting Policy.
Implement Accounting Policy Private header File.
SplitList * gnc_lot_get_split_list(const GNCLot *lot)
The gnc_lot_get_split_list() routine returns a GList of all the splits in this lot.
time64 xaccTransRetDatePosted(const Transaction *trans)
Retrieve the posted date of the transaction.
All type declarations for the whole Gnucash engine.
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.
gboolean gnc_lot_is_closed(GNCLot *lot)
The gnc_lot_is_closed() routine returns a boolean flag: is this lot closed? A lot is closed if its ba...
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Account * gnc_lot_get_account(const GNCLot *lot)
The gnc_lot_get_account() routine returns the account with which this lot is associated.
API for Transactions and Splits (journal entries)
Utilities to Automatically Compute Capital Gains/Losses.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gnc_numeric gnc_lot_get_balance(GNCLot *lot)
The gnc_lot_get_balance() routine returns the balance of the lot.
GNCPolicy * xaccGetFIFOPolicy(void)
First-in, First-out Policy This policy will create FIFO Lots.