39 #include "TransactionP.hpp" 47 #include <glib/gi18n.h> 49 #define N_(string) string 52 #define FIFO_POLICY "fifo" 53 #define FIFO_POLICY_DESC N_("First In, First Out") 54 #define FIFO_POLICY_HINT N_("Use oldest lots first.") 55 #define LIFO_POLICY "lifo" 56 #define LIFO_POLICY_DESC N_("Last In, First Out") 57 #define LIFO_POLICY_HINT N_("Use newest lots first.") 58 #define AVERAGE_POLICY "average" 59 #define AVERAGE_POLICY_DESC N_("Average") 60 #define AVERAGE_POLICY_HINT N_("Average cost of open lots.") 61 #define MANUAL_POLICY "manual" 62 #define MANUAL_POLICY_DESC N_("Manual") 63 #define MANUAL_POLICY_HINT N_("Manually select lots.") 68 DirectionPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot,
short reverse)
71 gnc_commodity *common_currency;
72 gboolean want_positive;
81 if (!lot_account)
return nullptr;
91 common_currency = split->parent->common_currency;
104 auto find_split = [open_time, common_currency, want_positive](
const Split* split)
106 return (!split->lot &&
119 FIFOPolicyGetLot (GNCPolicy *pcy, Split *split)
121 if (!split)
return nullptr;
123 split->parent->common_currency);
127 FIFOPolicyGetSplit (GNCPolicy *pcy, GNCLot *lot)
129 return DirectionPolicyGetSplit (pcy, lot, 0);
133 FIFOPolicyGetLotOpening (GNCPolicy *pcy,
135 gnc_numeric *ret_amount, gnc_numeric *ret_value,
136 gnc_commodity **ret_currency)
138 Split *opening_split;
141 if (ret_amount) *ret_amount = opening_split->amount;
142 if (ret_value) *ret_value = opening_split->value;
143 if (ret_currency) *ret_currency = opening_split->parent->common_currency;
147 FIFOPolicyIsOpeningSplit (GNCPolicy *pcy, GNCLot *lot, Split *split)
149 Split *opening_split;
151 return (split == opening_split);
157 static GNCPolicy *pcy =
nullptr;
161 pcy = g_new (GNCPolicy, 1);
162 pcy->PolicyGetLot = FIFOPolicyGetLot;
163 pcy->PolicyGetSplit = FIFOPolicyGetSplit;
164 pcy->PolicyGetLotOpening = FIFOPolicyGetLotOpening;
165 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 ...
def find_split(split_list, search_string)
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)
Convenience routine to identify the earliest date in the lot.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
Split * gnc_lot_get_latest_split(GNCLot *lot)
Convenience routineto identify the date this lot was closed.
Account handling public routines.
Account public routines (C++ api)
Implement Accounting Policy.
Implement Accounting Policy Private header File.
SplitList * gnc_lot_get_split_list(const GNCLot *lot)
Returns a list 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)
Returns closed status of the given lot.
Split * gnc_account_find_split(const Account *acc, std::function< bool(const Split *)> predicate, bool reverse)
scans account split list (in forward or reverse order) until predicate split->bool returns true...
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Account * gnc_lot_get_account(const GNCLot *lot)
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)
Returns the lot balance.
GNCPolicy * xaccGetFIFOPolicy(void)
First-in, First-out Policy This policy will create FIFO Lots.