mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Minor code cleanup in ofx importer; improve const-correctness.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20373 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
5483672ad2
commit
92e138b06b
@ -51,12 +51,12 @@ static QofLogModule log_module = GNC_MOD_IMPORT;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
gnc_commodity * gnc_import_select_commodity(char * cusip,
|
gnc_commodity * gnc_import_select_commodity(const char * cusip,
|
||||||
char auto_create,
|
gboolean auto_create,
|
||||||
char * default_fullname,
|
const char * default_fullname,
|
||||||
char * default_mnemonic)
|
const char * default_mnemonic)
|
||||||
{
|
{
|
||||||
gnc_commodity_table * commodity_table = gnc_get_current_commodities ();
|
const gnc_commodity_table * commodity_table = gnc_get_current_commodities ();
|
||||||
gnc_commodity * retval = NULL;
|
gnc_commodity * retval = NULL;
|
||||||
gnc_commodity * tmp_commodity = NULL;
|
gnc_commodity * tmp_commodity = NULL;
|
||||||
char * tmp_namespace = NULL;
|
char * tmp_namespace = NULL;
|
||||||
@ -67,8 +67,10 @@ gnc_commodity * gnc_import_select_commodity(char * cusip,
|
|||||||
DEBUG("Default mnemonic received: %s",
|
DEBUG("Default mnemonic received: %s",
|
||||||
default_mnemonic ? default_mnemonic : "(null)");
|
default_mnemonic ? default_mnemonic : "(null)");
|
||||||
|
|
||||||
|
g_return_val_if_fail(cusip, NULL);
|
||||||
DEBUG("Looking for commodity with exchange_code: %s", cusip);
|
DEBUG("Looking for commodity with exchange_code: %s", cusip);
|
||||||
|
|
||||||
|
g_assert(commodity_table);
|
||||||
namespace_list = gnc_commodity_table_get_namespaces(commodity_table);
|
namespace_list = gnc_commodity_table_get_namespaces(commodity_table);
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,39 +29,39 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Must be called with a string containing a unique identifier for the
|
Must be called with a string containing a unique identifier for the
|
||||||
commodity. If an commodity with a matching cusip is
|
commodity. If an commodity with a matching cusip is found, the
|
||||||
found, the function immediately returns with a pointer to that
|
function immediately returns with a pointer to that commodity.
|
||||||
commodity. Otherwise, the user may be prompted to select a GnuCash
|
Otherwise, the user may be prompted to select a GnuCash commodity or
|
||||||
account or create a new one (in both cases, the cusip is
|
create a new one (in both cases, the cusip is written to the
|
||||||
written to the commodity's cusip field, overwriting anything that
|
commodity's cusip field, overwriting anything that was there before.
|
||||||
was there before.
|
|
||||||
|
|
||||||
@param cusip The string containing the code for which you
|
@param cusip The string containing the code for which you want a
|
||||||
want a matching commodity. A CUISP code or similar UNIQUE code.
|
matching commodity. A CUISP code or similar UNIQUE code. The stock
|
||||||
The stock ticker is NOT appropriate, unless you have no other option.
|
ticker is NOT appropriate, unless you have no other option. Must be
|
||||||
|
non-NULL.
|
||||||
|
|
||||||
@param auto_create If 0, if the cusip value in unknown,
|
@param auto_create If the cusip value is unknown and this parameter
|
||||||
the function returns NULL, otherwise, the user will be asked to
|
is false (zero), the function returns NULL. Otherwise the user will
|
||||||
create a new account.
|
be asked to select an existing or create a new commodity.
|
||||||
|
|
||||||
@param default_fullname A human-readable description of the commodity, such
|
@param default_fullname A human-readable description of the
|
||||||
as the stock name. Can be NULL. If it is not NULL, it will be shown
|
commodity, such as the stock name. Can be NULL. If it is not NULL,
|
||||||
to the user when selecting a commodity. It will also be used as
|
it will be shown to the user when selecting a commodity. It will
|
||||||
the default if a new commodity is created.
|
also be used as the default if a new commodity is created.
|
||||||
|
|
||||||
@param default_mnemonic Usually the stock ticker or similar. Can be NULL.
|
@param default_mnemonic Usually the stock ticker or similar. Can be
|
||||||
If it is not NULL, it will be shown
|
NULL. If it is not NULL, it will be shown to the user when
|
||||||
to the user when selecting a commodity. It will also be used as
|
selecting a commodity. It will also be used as the default if a new
|
||||||
the default if a new commodity is created.
|
commodity is created.
|
||||||
|
|
||||||
@return A pointer to the found or created commodity, or NULL if no
|
@return A pointer to the found or created commodity, or NULL if no
|
||||||
account was found or created.
|
commodity was found or created.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
gnc_commodity * gnc_import_select_commodity(char * cusip,
|
gnc_commodity * gnc_import_select_commodity(const char * cusip,
|
||||||
char auto_create,
|
gboolean auto_create,
|
||||||
char * default_fullname,
|
const char * default_fullname,
|
||||||
char * default_mnemonic);
|
const char * default_mnemonic);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
@ -75,21 +75,21 @@ double ofx_get_investment_amount(struct OfxTransactionData data);
|
|||||||
|
|
||||||
int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data)
|
int ofx_proc_security_cb(const struct OfxSecurityData data, void * security_user_data)
|
||||||
{
|
{
|
||||||
char * tmp_cusip = NULL;
|
const char* tmp_cusip = NULL;
|
||||||
char * tmp_default_fullname = NULL;
|
const char* tmp_default_fullname = NULL;
|
||||||
char * tmp_default_mnemonic = NULL;
|
const char* tmp_default_mnemonic = NULL;
|
||||||
|
|
||||||
if (data.unique_id_valid == true)
|
if (data.unique_id_valid == true)
|
||||||
{
|
{
|
||||||
tmp_cusip = (char *)data.unique_id;
|
tmp_cusip = data.unique_id;
|
||||||
}
|
}
|
||||||
if (data.secname_valid == true)
|
if (data.secname_valid == true)
|
||||||
{
|
{
|
||||||
tmp_default_fullname = (char *)data.secname;
|
tmp_default_fullname = data.secname;
|
||||||
}
|
}
|
||||||
if (data.ticker_valid == true)
|
if (data.ticker_valid == true)
|
||||||
{
|
{
|
||||||
tmp_default_mnemonic = (char *)data.ticker;
|
tmp_default_mnemonic = data.ticker;
|
||||||
}
|
}
|
||||||
|
|
||||||
gnc_import_select_commodity(tmp_cusip,
|
gnc_import_select_commodity(tmp_cusip,
|
||||||
@ -126,7 +126,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
ACCT_TYPE_NONE, NULL, NULL);
|
ACCT_TYPE_NONE, NULL, NULL);
|
||||||
if (account != NULL)
|
if (account != NULL)
|
||||||
{
|
{
|
||||||
/********** Validate the input strings to ensure utf8 ********************/
|
/***** Validate the input strings to ensure utf8 *****/
|
||||||
if (data.name_valid)
|
if (data.name_valid)
|
||||||
gnc_utf8_strip_invalid(data.name);
|
gnc_utf8_strip_invalid(data.name);
|
||||||
if (data.memo_valid)
|
if (data.memo_valid)
|
||||||
@ -136,7 +136,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
if (data.reference_number_valid)
|
if (data.reference_number_valid)
|
||||||
gnc_utf8_strip_invalid(data.reference_number);
|
gnc_utf8_strip_invalid(data.reference_number);
|
||||||
|
|
||||||
/********** Create the transaction and setup transaction data ************/
|
/***** Create the transaction and setup transaction data *******/
|
||||||
book = gnc_account_get_book(account);
|
book = gnc_account_get_book(account);
|
||||||
transaction = xaccMallocTransaction(book);
|
transaction = xaccMallocTransaction(book);
|
||||||
xaccTransBeginEdit(transaction);
|
xaccTransBeginEdit(transaction);
|
||||||
@ -377,7 +377,7 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
{
|
{
|
||||||
if (data.invtransactiontype_valid == false)
|
if (data.invtransactiontype_valid == false)
|
||||||
{
|
{
|
||||||
/*************Process a normal transaction ***************************/
|
/***** Process a normal transaction ******/
|
||||||
DEBUG("Adding split; Ordinary banking transaction, money flows from or into the source account");
|
DEBUG("Adding split; Ordinary banking transaction, money flows from or into the source account");
|
||||||
split = xaccMallocSplit(book);
|
split = xaccMallocSplit(book);
|
||||||
xaccTransAppendSplit(transaction, split);
|
xaccTransAppendSplit(transaction, split);
|
||||||
@ -388,7 +388,8 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
GNC_HOW_RND_ROUND_HALF_UP);
|
GNC_HOW_RND_ROUND_HALF_UP);
|
||||||
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
||||||
|
|
||||||
/* Also put the ofx transaction's memo in the split's memo field */
|
/* Also put the ofx transaction's memo in the
|
||||||
|
* split's memo field */
|
||||||
if (data.memo_valid == true)
|
if (data.memo_valid == true)
|
||||||
{
|
{
|
||||||
xaccSplitSetMemo(split, data.memo);
|
xaccSplitSetMemo(split, data.memo);
|
||||||
@ -403,9 +404,10 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
&& data.security_data_ptr != NULL
|
&& data.security_data_ptr != NULL
|
||||||
&& data.security_data_ptr->secname_valid == true)
|
&& data.security_data_ptr->secname_valid == true)
|
||||||
{
|
{
|
||||||
/************************ Process an investment transaction ******************************/
|
/********* Process an investment transaction **********/
|
||||||
/* Note that the ACCT_TYPE_STOCK account type should be replaced with something
|
/* Note that the ACCT_TYPE_STOCK account type
|
||||||
derived from data.invtranstype*/
|
should be replaced with something derived from
|
||||||
|
data.invtranstype*/
|
||||||
investment_commodity = gnc_import_select_commodity(data.unique_id,
|
investment_commodity = gnc_import_select_commodity(data.unique_id,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
@ -526,7 +528,9 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
GNC_HOW_RND_ROUND_HALF_UP);
|
GNC_HOW_RND_ROUND_HALF_UP);
|
||||||
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
||||||
|
|
||||||
/* Also put the ofx transaction name in the splits memo field, or ofx memo if name is unavailable */
|
/* Also put the ofx transaction name in
|
||||||
|
* the splits memo field, or ofx memo if
|
||||||
|
* name is unavailable */
|
||||||
if (data.name_valid == true)
|
if (data.name_valid == true)
|
||||||
{
|
{
|
||||||
xaccSplitSetMemo(split, data.name);
|
xaccSplitSetMemo(split, data.name);
|
||||||
@ -549,7 +553,9 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
GNC_HOW_RND_ROUND_HALF_UP);
|
GNC_HOW_RND_ROUND_HALF_UP);
|
||||||
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
||||||
|
|
||||||
/* Also put the ofx transaction name in the splits memo field, or ofx memo if name is unavailable */
|
/* Also put the ofx transaction name in
|
||||||
|
* the splits memo field, or ofx memo if
|
||||||
|
* name is unavailable */
|
||||||
if (data.name_valid == true)
|
if (data.name_valid == true)
|
||||||
{
|
{
|
||||||
xaccSplitSetMemo(split, data.name);
|
xaccSplitSetMemo(split, data.name);
|
||||||
@ -573,7 +579,9 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
|||||||
GNC_HOW_RND_ROUND_HALF_UP);
|
GNC_HOW_RND_ROUND_HALF_UP);
|
||||||
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
|
||||||
|
|
||||||
/* Also put the ofx transaction name in the splits memo field, or ofx memo if name is unavailable */
|
/* Also put the ofx transaction name in
|
||||||
|
* the splits memo field, or ofx memo if
|
||||||
|
* name is unavailable */
|
||||||
if (data.name_valid == true)
|
if (data.name_valid == true)
|
||||||
{
|
{
|
||||||
xaccSplitSetMemo(split, data.name);
|
xaccSplitSetMemo(split, data.name);
|
||||||
|
Loading…
Reference in New Issue
Block a user