static gboolean test_add_account (const char* tag, gpointer globaldata, gpointer data) { Account* account = static_cast<decltype (account)> (data); act_data* gdata = (act_data*)globaldata; gnc_commodity* com; gnc_commodity* new_com; gnc_commodity_table* t; com = xaccAccountGetCommodity (account); t = gnc_commodity_table_get_table (sixbook); new_com = gnc_commodity_table_lookup (t, gnc_commodity_get_namespace (com), gnc_commodity_get_mnemonic (com)); if (new_com) { xaccAccountSetCommodity (account, new_com); } do_test_args (xaccAccountEqual ((Account*)account, (Account*) (gdata->act), TRUE), "gnc_account_sixtp_parser_create", __FILE__, __LINE__, "%d", gdata->value); return TRUE; }
static gnc_commodity * gnc_commodity_find_currency (QofBook *book, xmlNodePtr tree) { gnc_commodity_table * table; gnc_commodity *currency = NULL; gchar *exchange = NULL, *mnemonic = NULL; xmlNodePtr node; for (node = tree->xmlChildrenNode; node; node = node->next) { if (g_strcmp0((char*) node->name, cmdty_namespace) == 0) exchange = (gchar*) xmlNodeGetContent (node->xmlChildrenNode); if (g_strcmp0((char*) node->name, cmdty_id) == 0) mnemonic = (gchar*) xmlNodeGetContent (node->xmlChildrenNode); } if (exchange && gnc_commodity_namespace_is_iso(exchange) && mnemonic) { table = gnc_commodity_table_get_table(book); currency = gnc_commodity_table_lookup(table, exchange, mnemonic); } if (exchange) xmlFree(exchange); if (mnemonic) xmlFree(mnemonic); return currency; }
static void gnc_currency_edit_mnemonic_changed (GObject *gobject, GParamSpec *pspec, gpointer user_data) { GNCCurrencyEdit *self = GNC_CURRENCY_EDIT (gobject); GNCCurrencyEditPrivate *priv = GET_PRIVATE (self); gnc_commodity *currency = gnc_commodity_table_lookup (gnc_get_current_commodities (), GNC_COMMODITY_NS_CURRENCY, priv->mnemonic); /* If there isn't any such commodity, get the default */ if (!currency) { currency = gnc_locale_default_currency(); DEBUG("gce %p, default currency mnemonic %s", self, gnc_commodity_get_mnemonic(currency)); } g_signal_handlers_block_by_func(G_OBJECT(self), G_CALLBACK(gnc_currency_edit_mnemonic_changed), user_data); gnc_currency_edit_set_currency(self, currency); g_signal_handlers_unblock_by_func(G_OBJECT(self), G_CALLBACK(gnc_currency_edit_mnemonic_changed), user_data); }
gnc_commodity * gnc_get_euro (void) { gnc_commodity_table *table; table = gnc_commodity_table_get_table (gnc_get_current_book ()); return gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, "EUR"); }
static QofSession* create_session(void) { QofSession* session = qof_session_new(); QofBook* book = qof_session_get_book( session ); Account* root = gnc_book_get_root_account( book ); Account* acct1; Account* acct2; KvpFrame* frame; Transaction* tx; Split* spl1; Split* spl2; Timespec ts; struct timeval tv; gnc_commodity_table* table; gnc_commodity* currency; table = gnc_commodity_table_get_table( book ); currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" ); acct1 = xaccMallocAccount( book ); xaccAccountSetType( acct1, ACCT_TYPE_BANK ); xaccAccountSetName( acct1, "Bank 1" ); xaccAccountSetCommodity( acct1, currency ); frame = qof_instance_get_slots( QOF_INSTANCE(acct1) ); kvp_frame_set_gint64( frame, "int64-val", 100 ); kvp_frame_set_double( frame, "double-val", 3.14159 ); kvp_frame_set_numeric( frame, "numeric-val", gnc_numeric_zero() ); time( &(tv.tv_sec) ); tv.tv_usec = 0; ts.tv_sec = tv.tv_sec; ts.tv_nsec = 1000 * tv.tv_usec; kvp_frame_set_timespec( frame, "timespec-val", ts ); kvp_frame_set_string( frame, "string-val", "abcdefghijklmnop" ); kvp_frame_set_guid( frame, "guid-val", qof_instance_get_guid( QOF_INSTANCE(acct1) ) ); gnc_account_append_child( root, acct1 ); acct2 = xaccMallocAccount( book ); xaccAccountSetType( acct2, ACCT_TYPE_BANK ); xaccAccountSetName( acct2, "Bank 1" ); tx = xaccMallocTransaction( book ); xaccTransBeginEdit( tx ); xaccTransSetCurrency( tx, currency ); spl1 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl1 ); spl2 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl2 ); xaccTransCommitEdit( tx ); return session; }
gnc_commodity* parse_commodity (const std::string& comm_str) { if (comm_str.empty()) return nullptr; auto table = gnc_commodity_table_get_table (gnc_get_current_book()); gnc_commodity* comm = nullptr; /* First try commodity as a unique name. */ if (comm_str.find("::")) comm = gnc_commodity_table_lookup_unique (table, comm_str.c_str()); /* Then try mnemonic in the currency namespace */ if (!comm) comm = gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, comm_str.c_str()); if (!comm) { /* If that fails try mnemonic in all other namespaces */ auto namespaces = gnc_commodity_table_get_namespaces(table); for (auto ns = namespaces; ns; ns = ns->next) { gchar* ns_str = (gchar*)ns->data; if (g_utf8_collate(ns_str, GNC_COMMODITY_NS_CURRENCY) == 0) continue; comm = gnc_commodity_table_lookup (table, ns_str, comm_str.c_str()); if (comm) break; } } if (!comm) throw std::invalid_argument (_("Value can't be parsed into a valid commodity.")); else return comm; }
static gboolean tt_act_handler( xmlNodePtr node, gpointer data ) { gnc_template_xaction_data *txd = data; Account *acc; gnc_commodity *com; acc = dom_tree_to_account(node, txd->book); if ( acc == NULL ) { return FALSE; } else { xaccAccountBeginEdit (acc); /* Check for the lack of a commodity [signifying that the pre-7/11/2001-CIT-change SX template Account was parsed [but incorrectly]. */ if ( xaccAccountGetCommodity( acc ) == NULL ) { #if 1 gnc_commodity_table* table; table = gnc_commodity_table_get_table( txd->book ); com = gnc_commodity_table_lookup( table, "template", "template" ); #else /* FIXME: This should first look in the table of the book, maybe? The right thing happens [WRT file load/save] if we just _new all the time, but it doesn't seem right. This whole block should go away at some point, but the same concern still applies for SchedXaction.c:xaccSchedXactionInit... */ com = gnc_commodity_new( txd->book, "template", "template", "template", "template", 1 ); #endif xaccAccountSetCommodity( acc, com ); } txd->accts = g_list_append( txd->accts, acc ); } return TRUE; }
/* Retrieve the displayed currency of the widget. * * @param gce The currency editor widget whose values should be retrieved. * * @return A pointer to the selected currency (a gnc_commodity * structure). */ gnc_commodity * gnc_currency_edit_get_currency (GNCCurrencyEdit *gce) { gnc_commodity *commodity; const char *fullname; char *mnemonic, *name; GtkTreeModel *model; GtkTreeIter iter; GValue value = { 0 }; g_return_val_if_fail(gce != NULL, NULL); g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), NULL); if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter)) { model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce)); gtk_tree_model_get_value(model, &iter, 0, &value); fullname = g_value_get_string(&value); mnemonic = g_strdup(fullname); g_value_unset(&value); name = strchr(mnemonic, ' '); if (name != NULL) *name = '\0'; commodity = gnc_commodity_table_lookup (gnc_get_current_commodities (), GNC_COMMODITY_NS_CURRENCY, mnemonic); g_free(mnemonic); } else { g_warning("Combo box returned 'inactive'. Using locale default currency."); commodity = gnc_locale_default_currency(); } return commodity; }
static void xaccSchedXactionInit(SchedXaction *sx, QofBook *book) { Account *ra; const GncGUID *guid; gchar guidstr[GUID_ENCODING_LENGTH+1]; qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book); /* create a new template account for our splits */ sx->template_acct = xaccMallocAccount(book); guid = qof_instance_get_guid( sx ); xaccAccountBeginEdit( sx->template_acct ); guid_to_string_buff( guid, guidstr ); xaccAccountSetName( sx->template_acct, guidstr); xaccAccountSetCommodity (sx->template_acct, gnc_commodity_table_lookup( gnc_commodity_table_get_table(book), "template", "template") ); xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK ); xaccAccountCommitEdit( sx->template_acct ); ra = gnc_book_get_template_root( book ); gnc_account_append_child( ra, sx->template_acct ); }
static void account_list_changed_cb(GtkTreeSelection *selection, gpointer user_data) { ABInitialInfo *info = user_data; GtkTreeModel *model; GtkTreeIter iter; AB_ACCOUNT *ab_acc; gchar *longname, *gnc_name; Account *old_value, *gnc_acc; const gchar *currency; gnc_commodity *commodity = NULL; gboolean ok_pressed; g_return_if_fail(info); if (!gtk_tree_selection_get_selected(selection, &model, &iter)) return; gtk_tree_model_get(model, &iter, ACCOUNT_LIST_COL_AB_ACCT, &ab_acc, -1); /* Avoid recursion when unselecting the item again */ g_signal_handlers_block_by_func(selection, account_list_changed_cb, info); gtk_tree_selection_unselect_iter(selection, &iter); g_signal_handlers_unblock_by_func(selection, account_list_changed_cb, info); if (ab_acc) { old_value = g_hash_table_lookup(info->gnc_hash, ab_acc); longname = ab_account_longname(ab_acc); currency = AB_Account_GetCurrency(ab_acc); if (currency && *currency) { commodity = gnc_commodity_table_lookup( gnc_commodity_table_get_table(gnc_get_current_book()), GNC_COMMODITY_NS_CURRENCY, currency); } gnc_acc = gnc_import_select_account(info->window, NULL, TRUE, longname, commodity, ACCT_TYPE_BANK, old_value, &ok_pressed); g_free(longname); if (ok_pressed && old_value != gnc_acc) { if (gnc_acc) { RevLookupData data; /* Lookup and clear other mappings to gnc_acc */ data.gnc_acc = gnc_acc; data.ab_acc = NULL; g_hash_table_find(info->gnc_hash, (GHRFunc) find_gnc_acc_cb, &data); if (data.ab_acc) { g_hash_table_remove(info->gnc_hash, data.ab_acc); gtk_tree_model_foreach( GTK_TREE_MODEL(info->account_store), (GtkTreeModelForeachFunc) clear_line_cb, &data); } /* Map ab_acc to gnc_acc */ g_hash_table_insert(info->gnc_hash, ab_acc, gnc_acc); gnc_name = gnc_account_get_full_name(gnc_acc); gtk_list_store_set(info->account_store, &iter, ACCOUNT_LIST_COL_GNC_NAME, gnc_name, ACCOUNT_LIST_COL_CHECKED, TRUE, -1); g_free(gnc_name); } else { g_hash_table_remove(info->gnc_hash, ab_acc); gtk_list_store_set(info->account_store, &iter, ACCOUNT_LIST_COL_GNC_NAME, "", ACCOUNT_LIST_COL_CHECKED, TRUE, -1); } } } }
int ofx_proc_account_cb(struct OfxAccountData data, void * account_user_data) { gnc_commodity_table * commodity_table; gnc_commodity * default_commodity; GNCAccountType default_type = ACCT_TYPE_NONE; gchar * account_description; /* In order to trigger a book options display on the creation of a new book, * we need to detect when we are dealing with a new book. */ gboolean new_book = gnc_is_new_book(); const gchar * account_type_name = _("Unknown OFX account"); if (data.account_id_valid) { commodity_table = gnc_get_current_commodities (); if (data.currency_valid) { DEBUG("Currency from libofx: %s", data.currency); default_commodity = gnc_commodity_table_lookup(commodity_table, GNC_COMMODITY_NS_CURRENCY, data.currency); } else { default_commodity = NULL; } if (data.account_type_valid) { switch (data.account_type) { case OFX_CHECKING : default_type = ACCT_TYPE_BANK; account_type_name = _("Unknown OFX checking account"); break; case OFX_SAVINGS : default_type = ACCT_TYPE_BANK; account_type_name = _("Unknown OFX savings account"); break; case OFX_MONEYMRKT : default_type = ACCT_TYPE_MONEYMRKT; account_type_name = _("Unknown OFX money market account"); break; case OFX_CREDITLINE : default_type = ACCT_TYPE_CREDITLINE; account_type_name = _("Unknown OFX credit line account"); break; case OFX_CMA : default_type = ACCT_TYPE_NONE; account_type_name = _("Unknown OFX CMA account"); break; case OFX_CREDITCARD : default_type = ACCT_TYPE_CREDIT; account_type_name = _("Unknown OFX credit card account"); break; case OFX_INVESTMENT : default_type = ACCT_TYPE_BANK; account_type_name = _("Unknown OFX investment account"); break; default: PERR("WRITEME: ofx_proc_account() This is an unknown account type!"); break; } } /* If the OFX importer was started in Gnucash in a 'new_book' situation, * as described above, the first time the 'ofx_proc_account_cb' function * is called a book is created. (This happens after the 'new_book' flag * is set in 'gnc_get_current_commodities', called above.) So, before * calling 'gnc_import_select_account', allow the user to set book * options. */ if (new_book) new_book = gnc_new_book_option_display(); gnc_utf8_strip_invalid(data.account_name); account_description = g_strdup_printf( /* This string is a default account name. It MUST NOT contain the character ':' anywhere in it or in any translation. */ "%s \"%s\"", account_type_name, data.account_name); gnc_import_select_account(NULL, data.account_id, 1, account_description, default_commodity, default_type, NULL, NULL); g_free(account_description); } else { PERR("account online ID not available"); } return 0; }
int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_user_data) { char dest_string[255]; time64 current_time = gnc_time (NULL); Account *account; Account *investment_account = NULL; Account *income_account = NULL; gchar *investment_account_text, *investment_account_onlineid; gnc_commodity *currency = NULL; gnc_commodity *investment_commodity = NULL; gnc_numeric gnc_amount, gnc_units; QofBook *book; Transaction *transaction; Split *split; gchar *notes, *tmp; g_assert(gnc_ofx_importer_gui); if (!data.account_id_valid) { PERR("account ID for this transaction is unavailable!"); return 0; } account = gnc_import_select_account(gnc_gen_trans_list_widget(gnc_ofx_importer_gui), data.account_id, 0, NULL, NULL, ACCT_TYPE_NONE, NULL, NULL); if (account == NULL) { PERR("Unable to find account for id %s", data.account_id); return 0; } /***** Validate the input strings to ensure utf8 *****/ if (data.name_valid) gnc_utf8_strip_invalid(data.name); if (data.memo_valid) gnc_utf8_strip_invalid(data.memo); if (data.check_number_valid) gnc_utf8_strip_invalid(data.check_number); if (data.reference_number_valid) gnc_utf8_strip_invalid(data.reference_number); /***** Create the transaction and setup transaction data *******/ book = gnc_account_get_book(account); transaction = xaccMallocTransaction(book); xaccTransBeginEdit(transaction); /* Note: Unfortunately libofx <= 0.9.5 will not report a missing * date field as an invalid one. Instead, it will report it as * valid and return a completely bogus date. Starting with * libofx-0.9.6 (not yet released as of 2012-09-09), it will still * be reported as valid but at least the date integer itself is * just plain zero. */ if (data.date_posted_valid && (data.date_posted != 0)) { /* The hopeful case: We have a posted_date */ xaccTransSetDatePostedSecsNormalized(transaction, data.date_posted); } else if (data.date_initiated_valid && (data.date_initiated != 0)) { /* No posted date? Maybe we have an initiated_date */ xaccTransSetDatePostedSecsNormalized(transaction, data.date_initiated); } else { /* Uh no, no valid date. As a workaround use today's date */ xaccTransSetDatePostedSecsNormalized(transaction, current_time); } xaccTransSetDateEnteredSecs(transaction, current_time); /* Put transaction name in Description, or memo if name unavailable */ if (data.name_valid) { xaccTransSetDescription(transaction, data.name); } else if (data.memo_valid) { xaccTransSetDescription(transaction, data.memo); } /* Put everything else in the Notes field */ notes = g_strdup_printf("OFX ext. info: "); if (data.transactiontype_valid) { tmp = notes; notes = g_strdup_printf("%s%s%s", tmp, "|Trans type:", gnc_ofx_ttype_to_string(data.transactiontype)); g_free(tmp); } if (data.invtransactiontype_valid) { tmp = notes; notes = g_strdup_printf("%s%s%s", tmp, "|Investment Trans type:", gnc_ofx_invttype_to_str(data.invtransactiontype)); g_free(tmp); } if (data.memo_valid && data.name_valid) /* Copy only if memo wasn't put in Description */ { tmp = notes; notes = g_strdup_printf("%s%s%s", tmp, "|Memo:", data.memo); g_free(tmp); } if (data.date_funds_available_valid) { Timespec ts; timespecFromTime64(&ts, data.date_funds_available); gnc_timespec_to_iso8601_buff (ts, dest_string); tmp = notes; notes = g_strdup_printf("%s%s%s", tmp, "|Date funds available:", dest_string); g_free(tmp); } if (data.server_transaction_id_valid) { tmp = notes; notes = g_strdup_printf("%s%s%s", tmp, "|Server trans ID (conf. number):", data.server_transaction_id); g_free(tmp); } if (data.standard_industrial_code_valid) { tmp = notes; notes = g_strdup_printf("%s%s%ld", tmp, "|Standard Industrial Code:", data.standard_industrial_code); g_free(tmp); } if (data.payee_id_valid) { tmp = notes; notes = g_strdup_printf("%s%s%s", tmp, "|Payee ID:", data.payee_id); g_free(tmp); } //PERR("WRITEME: GnuCash ofx_proc_transaction():Add PAYEE and ADRESS here once supported by libofx! Notes=%s\n", notes); /* Ideally, gnucash should process the corrected transactions */ if (data.fi_id_corrected_valid) { PERR("WRITEME: GnuCash ofx_proc_transaction(): WARNING: This transaction corrected a previous transaction, but we created a new one instead!\n"); tmp = notes; notes = g_strdup_printf("%s%s%s%s", tmp, "|This corrects transaction #", data.fi_id_corrected, "but GnuCash didn't process the correction!"); g_free(tmp); } xaccTransSetNotes(transaction, notes); g_free(notes); if (data.account_ptr && data.account_ptr->currency_valid) { DEBUG("Currency from libofx: %s", data.account_ptr->currency); currency = gnc_commodity_table_lookup( gnc_get_current_commodities (), GNC_COMMODITY_NS_CURRENCY, data.account_ptr->currency); } else { DEBUG("Currency from libofx unavailable, defaulting to account's default"); currency = xaccAccountGetCommodity(account); } xaccTransSetCurrency(transaction, currency); if (data.amount_valid) { if (!data.invtransactiontype_valid) { /***** Process a normal transaction ******/ DEBUG("Adding split; Ordinary banking transaction, money flows from or into the source account"); split = xaccMallocSplit(book); xaccTransAppendSplit(transaction, split); xaccAccountInsertSplit(account, split); gnc_amount = gnc_ofx_numeric_from_double_txn(data.amount, transaction); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); /* set tran-num and/or split-action per book option */ if (data.check_number_valid) { gnc_set_num_action(transaction, split, data.check_number, NULL); } else if (data.reference_number_valid) { gnc_set_num_action(transaction, split, data.reference_number, NULL); } /* Also put the ofx transaction's memo in the * split's memo field */ if (data.memo_valid) { xaccSplitSetMemo(split, data.memo); } if (data.fi_id_valid) { gnc_import_set_split_online_id(split, data.fi_id); } } else if (data.unique_id_valid && data.security_data_valid && data.security_data_ptr != NULL && data.security_data_ptr->secname_valid) { gboolean choosing_account = TRUE; /********* Process an investment transaction **********/ /* Note that the ACCT_TYPE_STOCK account type should be replaced with something derived from data.invtranstype*/ // We have an investment transaction. First select the correct commodity. investment_commodity = gnc_import_select_commodity(data.unique_id, FALSE, NULL, NULL); if (investment_commodity != NULL) { // As we now have the commodity, select the account with that commodity. investment_account_text = g_strdup_printf( /* This string is a default account name. It MUST NOT contain the character ':' anywhere in it or in any translations. */ _("Stock account for security \"%s\""), data.security_data_ptr->secname); investment_account_onlineid = g_strdup_printf( "%s%s", data.account_id, data.unique_id); investment_account = gnc_import_select_account(NULL, investment_account_onlineid, 1, investment_account_text, investment_commodity, ACCT_TYPE_STOCK, NULL, NULL); // but use it only if that's really the right commodity if (investment_account && xaccAccountGetCommodity(investment_account) != investment_commodity) investment_account = NULL; // Loop until we either have an account, or the user pressed Cancel while (!investment_account && choosing_account) { // No account with correct commodity automatically found. // But are we in auto-create mode and already know a parent? if (auto_create_commodity && ofx_parent_account) { // Yes, so use that as parent when auto-creating the new account below. investment_account = ofx_parent_account; } else { // Let the user choose an account investment_account = gnc_import_select_account( gnc_gen_trans_list_widget(gnc_ofx_importer_gui), data.unique_id, TRUE, investment_account_text, investment_commodity, ACCT_TYPE_STOCK, NULL, &choosing_account); } // Does the chosen account have the right commodity? if (investment_account && xaccAccountGetCommodity(investment_account) != investment_commodity) { if (auto_create_commodity && xaccAccountTypesCompatible(xaccAccountGetType(investment_account), ACCT_TYPE_STOCK)) { // The user chose an account, but it does // not have the right commodity. Also, // auto-creation is on. Hence, we create a // new child account of the selected one, // and this one will have the right // commodity. Account *parent_account = investment_account; investment_account = gnc_ofx_new_account(investment_account_text, investment_commodity, parent_account, ACCT_TYPE_STOCK); if (investment_account) { gnc_import_set_acc_online_id(investment_account, data.unique_id); choosing_account = FALSE; ofx_parent_account = parent_account; } else { ofx_parent_account = NULL; } } else { // No account with matching commodity. Ask the user // whether to continue or abort. choosing_account = gnc_verify_dialog( gnc_gen_trans_list_widget(gnc_ofx_importer_gui), TRUE, "The chosen account \"%s\" does not have the correct " "currency/security \"%s\" (it has \"%s\" instead). " "This account cannot be used. " "Do you want to choose again?", xaccAccountGetName(investment_account), gnc_commodity_get_fullname(investment_commodity), gnc_commodity_get_fullname(xaccAccountGetCommodity(investment_account))); // We must also delete the online_id that was set in gnc_import_select_account() gnc_import_set_acc_online_id(investment_account, ""); investment_account = NULL; } } } if (!investment_account) { PERR("No investment account found for text: %s\n", investment_account_text); } g_free (investment_account_text); g_free (investment_account_onlineid); investment_account_text = NULL; if (investment_account != NULL && data.unitprice_valid && data.units_valid && ( data.invtransactiontype != OFX_INCOME ) ) { DEBUG("Adding investment split; Money flows from or into the stock account"); split = xaccMallocSplit(book); xaccTransAppendSplit(transaction, split); xaccAccountInsertSplit(investment_account, split); gnc_amount = gnc_ofx_numeric_from_double (ofx_get_investment_amount(&data), investment_commodity); gnc_units = gnc_ofx_numeric_from_double (data.units, investment_commodity); xaccSplitSetAmount(split, gnc_units); xaccSplitSetValue(split, gnc_amount); /* set tran-num and/or split-action per book option */ if (data.check_number_valid) { gnc_set_num_action(transaction, split, data.check_number, NULL); } else if (data.reference_number_valid) { gnc_set_num_action(transaction, split, data.reference_number, NULL); } if (data.security_data_ptr->memo_valid) { xaccSplitSetMemo(split, data.security_data_ptr->memo); } if (data.fi_id_valid) { gnc_import_set_split_online_id(split, data.fi_id); } } else { if (investment_account) PERR("The investment account, units or unitprice was not found for the investment transaction"); } } else { PERR("Commodity not found for the investment transaction"); } if (data.invtransactiontype_valid && investment_account) { if (data.invtransactiontype == OFX_REINVEST || data.invtransactiontype == OFX_INCOME) { DEBUG("Now let's find an account for the destination split"); income_account = gnc_ofx_kvp_get_assoc_account(investment_account); if (income_account == NULL) { DEBUG("Couldn't find an associated income account"); investment_account_text = g_strdup_printf( /* This string is a default account name. It MUST NOT contain the character ':' anywhere in it or in any translations. */ _("Income account for security \"%s\""), data.security_data_ptr->secname); income_account = gnc_import_select_account( gnc_gen_trans_list_widget(gnc_ofx_importer_gui), NULL, 1, investment_account_text, currency, ACCT_TYPE_INCOME, NULL, NULL); gnc_ofx_kvp_set_assoc_account(investment_account, income_account); DEBUG("KVP written"); } else { DEBUG("Found at least one associated income account"); } } if (income_account != NULL && data.invtransactiontype == OFX_REINVEST) { DEBUG("Adding investment split; Money flows from the income account"); split = xaccMallocSplit(book); xaccTransAppendSplit(transaction, split); xaccAccountInsertSplit(income_account, split); gnc_amount = gnc_ofx_numeric_from_double_txn (data.amount, transaction); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); // Set split memo from ofx transaction name or memo gnc_ofx_set_split_memo(&data, split); } if (income_account != NULL && data.invtransactiontype == OFX_INCOME) { DEBUG("Adding investment split; Money flows from the income account"); split = xaccMallocSplit(book); xaccTransAppendSplit(transaction, split); xaccAccountInsertSplit(income_account, split); gnc_amount = gnc_ofx_numeric_from_double_txn (-data.amount,/*OFX_INCOME amounts come in as positive numbers*/ transaction); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); // Set split memo from ofx transaction name or memo gnc_ofx_set_split_memo(&data, split); } } if (data.invtransactiontype_valid && data.invtransactiontype != OFX_REINVEST) { DEBUG("Adding investment split; Money flows from or to the cash account"); split = xaccMallocSplit(book); xaccTransAppendSplit(transaction, split); xaccAccountInsertSplit(account, split); gnc_amount = gnc_ofx_numeric_from_double_txn( -ofx_get_investment_amount(&data), transaction); xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction)); // Set split memo from ofx transaction name or memo gnc_ofx_set_split_memo(&data, split); } } /* Send transaction to importer GUI. */ if (xaccTransCountSplits(transaction) > 0) { DEBUG("%d splits sent to the importer gui", xaccTransCountSplits(transaction)); gnc_gen_trans_list_add_trans (gnc_ofx_importer_gui, transaction); } else { PERR("No splits in transaction (missing account?), ignoring."); xaccTransDestroy(transaction); xaccTransCommitEdit(transaction); } } else { PERR("The transaction doesn't have a valid amount"); xaccTransDestroy(transaction); xaccTransCommitEdit(transaction); } return 0; }//end ofx_proc_transaction()