您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ xaccTransBeginEdit函数代码示例

51自学网 2021-06-03 10:15:15
  C++
这篇教程C++ xaccTransBeginEdit函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中xaccTransBeginEdit函数的典型用法代码示例。如果您正苦于以下问题:C++ xaccTransBeginEdit函数的具体用法?C++ xaccTransBeginEdit怎么用?C++ xaccTransBeginEdit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了xaccTransBeginEdit函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: dom_tree_to_transaction

Transaction *dom_tree_to_transaction( xmlNodePtr node, QofBook *book ){    Transaction *trn;    gboolean successful;    struct trans_pdata pdata;    g_return_val_if_fail(node, NULL);    g_return_val_if_fail(book, NULL);    trn = xaccMallocTransaction(book);    g_return_val_if_fail(trn, NULL);    xaccTransBeginEdit(trn);    pdata.trans = trn;    pdata.book = book;    successful = dom_tree_generic_parse(node, trn_dom_handlers, &pdata);    xaccTransCommitEdit(trn);    if ( !successful )    {        xmlElemDump(stdout, NULL, node);        xaccTransBeginEdit(trn);        xaccTransDestroy(trn);        xaccTransCommitEdit(trn);        trn = NULL;    }    return trn;}
开发者ID:573,项目名称:gnucash,代码行数:32,


示例2: really_get_rid_of_transaction

static voidreally_get_rid_of_transaction (Transaction* trn){    xaccTransBeginEdit (trn);    xaccTransDestroy (trn);    xaccTransCommitEdit (trn);}
开发者ID:TumbleweedPretzel,项目名称:gnucash,代码行数:7,


示例3: verify_essentials

Transaction* GncPreTrans::create_trans (QofBook* book, gnc_commodity* currency){    if (created)        return nullptr;    /* Gently refuse to create the transaction if the basics are not set correctly     * This should have been tested before calling this function though!     */    auto check = verify_essentials();    if (!check.empty())    {        PWARN ("Refusing to create transaction because essentials not set properly: %s", check.c_str());        return nullptr;    }    auto trans = xaccMallocTransaction (book);    xaccTransBeginEdit (trans);    xaccTransSetCurrency (trans, m_commodity ? *m_commodity : currency);    xaccTransSetDatePostedSecsNormalized (trans,                        static_cast<time64>(GncDateTime(*m_date, DayPart::neutral)));    if (m_num)        xaccTransSetNum (trans, m_num->c_str());    if (m_desc)        xaccTransSetDescription (trans, m_desc->c_str());    if (m_notes)        xaccTransSetNotes (trans, m_notes->c_str());    created = true;    return trans;}
开发者ID:carrot-garden,项目名称:money_gnucash,代码行数:34,


示例4: load_single_tx

static /*@ null @*/ Transaction*load_single_tx( GncSqlBackend* be, GncSqlRow* row ){    const GncGUID* guid;    GncGUID tx_guid;    Transaction* pTx;    g_return_val_if_fail( be != NULL, NULL );    g_return_val_if_fail( row != NULL, NULL );    guid = gnc_sql_load_guid( be, row );    if ( guid == NULL ) return NULL;    tx_guid = *guid;    // Don't overwrite the transaction if it's already been loaded (and possibly modified).    pTx = xaccTransLookup( &tx_guid, be->book );    if ( pTx != NULL )    {        return NULL;    }    pTx = xaccMallocTransaction( be->book );    xaccTransBeginEdit( pTx );    gnc_sql_load_object( be, row, GNC_ID_TRANS, pTx, tx_col_table );    if (pTx != xaccTransLookup( &tx_guid, be->book ))    {	PERR("A malformed transaction with id %s was found in the dataset.",	     guid_to_string(qof_instance_get_guid(pTx)));	qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT);	pTx = NULL;    }    return pTx;}
开发者ID:LievaartR,项目名称:gnucash,代码行数:35,


示例5: gncOwnerReduceSplitTo

gbooleangncOwnerReduceSplitTo (Split *split, gnc_numeric target_value){    gnc_numeric split_val = xaccSplitGetValue (split);    gnc_numeric rem_val;    Split *rem_split;    Transaction *txn;    GNCLot *lot;    if (gnc_numeric_positive_p (split_val) != gnc_numeric_positive_p (target_value))        return FALSE; // Split and target value have to be of the same sign    if (gnc_numeric_equal (split_val, target_value))        return FALSE; // Split already has the target value    rem_val = gnc_numeric_sub (split_val, target_value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD); // note: values are of opposite sign    rem_split = xaccMallocSplit (xaccSplitGetBook (split));    xaccSplitCopyOnto (split, rem_split);    xaccSplitSetValue (rem_split, rem_val);    txn = xaccSplitGetParent (split);    xaccTransBeginEdit (txn);    xaccSplitSetValue (split, target_value);    xaccSplitSetParent (rem_split, txn);    xaccTransCommitEdit (txn);    lot = xaccSplitGetLot (split);    gnc_lot_add_split (lot, rem_split);    return TRUE;}
开发者ID:ShawnMcGough,项目名称:gnucash,代码行数:31,


示例6: merge_splits

static voidmerge_splits (Split *sa, Split *sb){    Account *act;    Transaction *txn;    gnc_numeric amt, val;    act = xaccSplitGetAccount (sb);    xaccAccountBeginEdit (act);    txn = sa->parent;    xaccTransBeginEdit (txn);    /* Remove the guid of sb from the 'gemini' of sa */    remove_guids (sa, sb);    /* Add amount of sb into sa, ditto for value. */    amt = xaccSplitGetAmount (sa);    amt = gnc_numeric_add_fixed (amt, xaccSplitGetAmount (sb));    xaccSplitSetAmount (sa, amt);    val = xaccSplitGetValue (sa);    val = gnc_numeric_add_fixed (val, xaccSplitGetValue (sb));    xaccSplitSetValue (sa, val);    /* Set reconcile to no; after this much violence,     * no way its reconciled. */    xaccSplitSetReconcile (sa, NREC);    /* If sb has associated gains splits, trash them. */    if ((sb->gains_split) &&            (sb->gains_split->gains & GAINS_STATUS_GAINS))    {        Transaction *t = sb->gains_split->parent;        xaccTransBeginEdit (t);        xaccTransDestroy (t);        xaccTransCommitEdit (t);    }    /* Finally, delete sb */    xaccSplitDestroy(sb);    xaccTransCommitEdit (txn);    xaccAccountCommitEdit (act);}
开发者ID:kleopatra999,项目名称:gnucash-2,代码行数:45,


示例7: gnc_import_set_split_online_id

/* Used several places in a transaction edit where many other * parameters are also being set, so individual commits wouldn't be * appropriate. */void gnc_import_set_split_online_id(Split * split,                                    const gchar * string_value){    kvp_frame * frame;    xaccTransBeginEdit (xaccSplitGetParent (split));    frame = xaccSplitGetSlots(split);    kvp_frame_set_str (frame, "online_id", string_value);    qof_instance_set_dirty (QOF_INSTANCE (split));}
开发者ID:KhazMcdust,项目名称:gnucash,代码行数:12,


示例8: create_session

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;}
开发者ID:kleopatra999,项目名称:gnucash-2,代码行数:57,


示例9: sxprivTransMapDelete

static voidsxprivTransMapDelete( gpointer data, gpointer user_data ){    Transaction *t = (Transaction *) data;    xaccTransBeginEdit( t );    xaccTransDestroy( t );    xaccTransCommitEdit( t );    return;}
开发者ID:goodvibes2,项目名称:gnucash,代码行数:9,


示例10: gnc_import_set_trans_online_id

/* Not actually used */void gnc_import_set_trans_online_id(Transaction * transaction,                                    const gchar * string_value){    kvp_frame * frame;    xaccTransBeginEdit (transaction);    frame = xaccTransGetSlots(transaction);    kvp_frame_set_str (frame, "online_id", string_value);    qof_instance_set_dirty (QOF_INSTANCE (transaction));    xaccTransCommitEdit (transaction);}
开发者ID:KhazMcdust,项目名称:gnucash,代码行数:11,


示例11: gnc_transaction_adjust_trading_splits

static gnc_numericgnc_transaction_adjust_trading_splits (Transaction* trans, Account *root){    GList* splits;    gnc_numeric imbalance = gnc_numeric_zero();    for (splits = trans->splits; splits; splits = splits->next)    {        Split *split = splits->data;        Split *balance_split = NULL;        gnc_numeric value, amount;        gnc_commodity *commodity, *txn_curr = xaccTransGetCurrency (trans);        if (! xaccTransStillHasSplit (trans, split)) continue;        commodity = xaccAccountGetCommodity (xaccSplitGetAccount(split));        if (!commodity)        {            PERR("Split has no commodity");            continue;        }        balance_split = find_trading_split (trans, root, commodity);        if (balance_split != split)            /* this is not a trading split */            imbalance = gnc_numeric_add(imbalance, xaccSplitGetValue (split),                                        GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);        /* Ignore splits where value or amount is zero */        value = xaccSplitGetValue (split);        amount = xaccSplitGetAmount (split);        if (gnc_numeric_zero_p(amount) || gnc_numeric_zero_p(value))            continue;        if (balance_split && balance_split != split)        {            gnc_numeric convrate = gnc_numeric_div (amount, value,                                                    GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);            gnc_numeric old_value, new_value;            old_value = xaccSplitGetValue(balance_split);            new_value = gnc_numeric_div (xaccSplitGetAmount(balance_split),                                         convrate,                                         gnc_commodity_get_fraction(txn_curr),                                         GNC_HOW_RND_ROUND_HALF_UP);            if (! gnc_numeric_equal (old_value, new_value))            {                xaccTransBeginEdit (trans);                xaccSplitSetValue (balance_split, new_value);                xaccSplitScrub (balance_split);                xaccTransCommitEdit (trans);            }        }    }    return imbalance;}
开发者ID:Bob-IT,项目名称:gnucash,代码行数:55,


示例12: gnc_transaction_balance_trading_more_splits

/** Balance the transaction by adding more trading splits. This shouldn't * ordinarily be necessary. * @param trans the transaction to balance * @param root the root account */static voidgnc_transaction_balance_trading_more_splits (Transaction *trans, Account *root){    /* Copy the split list so we don't see the splits we're adding */    GList *splits_dup = g_list_copy(trans->splits), *splits = NULL;    const gnc_commodity  *txn_curr = xaccTransGetCurrency (trans);    for (splits = splits_dup; splits; splits = splits->next)    {        Split *split = splits->data;        if (! xaccTransStillHasSplit(trans, split)) continue;        if (!gnc_numeric_zero_p(xaccSplitGetValue(split)) &&            gnc_numeric_zero_p(xaccSplitGetAmount(split)))        {            gnc_commodity *commodity;            gnc_numeric old_value, new_value;            Split *balance_split;            Account *account = NULL;            commodity = xaccAccountGetCommodity(xaccSplitGetAccount(split));            if (!commodity)            {                PERR("Split has no commodity");                continue;            }            balance_split = get_trading_split(trans, root, commodity);            if (!balance_split)            {                /* Error already logged */                LEAVE("");                return;            }            account = xaccSplitGetAccount(balance_split);            xaccTransBeginEdit (trans);            old_value = xaccSplitGetValue (balance_split);            new_value = gnc_numeric_sub (old_value, xaccSplitGetValue(split),                                         gnc_commodity_get_fraction(txn_curr),                                         GNC_HOW_RND_ROUND_HALF_UP);            xaccSplitSetValue (balance_split, new_value);            /* Don't change the balance split's amount since the amount               is zero in the split we're working on */            xaccSplitScrub (balance_split);            xaccTransCommitEdit (trans);        }    }    g_list_free(splits_dup);}
开发者ID:Bob-IT,项目名称:gnucash,代码行数:56,


示例13: xaccSchedXactionSetTemplateTrans

voidxaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list,                                 QofBook *book){    Transaction *new_trans;    TTInfo *tti;    TTSplitInfo *s_info;    Split *new_split;    GList *split_list;    g_return_if_fail (book);    /* delete any old transactions, if there are any */    delete_template_trans( sx );    for (; t_t_list != NULL; t_t_list = t_t_list->next)    {        tti = t_t_list->data;        new_trans = xaccMallocTransaction(book);        xaccTransBeginEdit(new_trans);        xaccTransSetDescription(new_trans,                                gnc_ttinfo_get_description(tti));        xaccTransSetDatePostedSecsNormalized(new_trans, gnc_time (NULL));        /* Set tran-num with gnc_set_num_action which is the same as         * xaccTransSetNum with these arguments */        gnc_set_num_action(new_trans, NULL,                        gnc_ttinfo_get_num(tti), NULL);        xaccTransSetNotes (new_trans, gnc_ttinfo_get_notes (tti));        xaccTransSetCurrency( new_trans,                              gnc_ttinfo_get_currency(tti) );        for (split_list = gnc_ttinfo_get_template_splits(tti);                split_list;                split_list = split_list->next)        {            s_info = split_list->data;            new_split = pack_split_info(s_info, sx->template_acct,                                        new_trans, book);            xaccTransAppendSplit(new_trans, new_split);        }        xaccTransCommitEdit(new_trans);    }}
开发者ID:goodvibes2,项目名称:gnucash,代码行数:48,


示例14: get_balance_split

static Split *get_balance_split (Transaction *trans, Account *root, Account *account,                   gnc_commodity *commodity){    Split *balance_split;    gchar *accname;    if (!account ||        !gnc_commodity_equiv (commodity, xaccAccountGetCommodity(account)))    {        if (!root)        {            root = gnc_book_get_root_account (xaccTransGetBook (trans));            if (NULL == root)            {                /* This can't occur, things should be in books */                PERR ("Bad data corruption, no root account in book");                return NULL;            }        }        accname = g_strconcat (_("Imbalance"), "-",                               gnc_commodity_get_mnemonic (commodity), NULL);        account = xaccScrubUtilityGetOrMakeAccount (root, commodity,                                                    accname, ACCT_TYPE_BANK, FALSE);        g_free (accname);        if (!account)        {            PERR ("Can't get balancing account");            return NULL;        }    }    balance_split = xaccTransFindSplitByAccount(trans, account);    /* Put split into account before setting split value */    if (!balance_split)    {        balance_split = xaccMallocSplit (qof_instance_get_book(trans));        xaccTransBeginEdit (trans);        xaccSplitSetParent(balance_split, trans);        xaccSplitSetAccount(balance_split, account);        xaccTransCommitEdit (trans);    }    return balance_split;}
开发者ID:Bob-IT,项目名称:gnucash,代码行数:47,


示例15: create_blank_split

static Split*create_blank_split (Account *default_account, SRInfo *info){    Transaction *new_trans;    gboolean currency_from_account = TRUE;    Split *blank_split = NULL;    /* Determine the proper currency to use for this transaction.     * if default_account != NULL and default_account->commodity is     * a currency, then use that.  Otherwise use the default currency.     */    gnc_commodity * currency = gnc_account_or_default_currency(default_account, &currency_from_account);    if (default_account != NULL && !currency_from_account)    {	/* If we don't have a currency then pop up a warning dialog */	gnc_info_dialog(NULL, "%s",			_("Could not determine the account currency. "			  "Using the default currency provided by your system."));    }    gnc_suspend_gui_refresh ();    new_trans = xaccMallocTransaction (gnc_get_current_book ());    xaccTransBeginEdit (new_trans);    xaccTransSetCurrency (new_trans, currency);    xaccTransSetDatePostedSecsNormalized(new_trans, info->last_date_entered);    blank_split = xaccMallocSplit (gnc_get_current_book ());    xaccSplitSetParent(blank_split, new_trans);    /* We don't want to commit this transaction yet, because the split       doesn't even belong to an account yet.  But, we don't want to       set this transaction as the pending transaction either, because       we want to pretend that it hasn't been changed.  We depend on       some other code (somewhere) to commit this transaction if we       really edit it, even though it's not marked as the pending       transaction. */    info->blank_split_guid = *xaccSplitGetGUID (blank_split);    info->blank_split_edited = FALSE;    info->auto_complete = FALSE;    DEBUG("created new blank_split=%p", blank_split);    gnc_resume_gui_refresh ();    return blank_split;}
开发者ID:JohannesKlug,项目名称:gnucash,代码行数:45,


示例16: gsr2_create_balancing_transaction

static Transaction*gsr2_create_balancing_transaction (QofBook *book, Account *account,                             time64 statement_date, gnc_numeric balancing_amount){    Transaction *trans;    Split *split;    if (!account)        return NULL;    if (gnc_numeric_zero_p (balancing_amount))        return NULL;    xaccAccountBeginEdit (account);    trans = xaccMallocTransaction (book);    xaccTransBeginEdit (trans);    // fill Transaction    xaccTransSetCurrency (trans, gnc_account_or_default_currency (account, NULL));    xaccTransSetDatePostedSecsNormalized (trans, statement_date);    xaccTransSetDescription (trans, _("Balancing entry from reconciliation"));    // 1. Split    split = xaccMallocSplit (book);    xaccTransAppendSplit (trans, split);    xaccAccountInsertSplit  (account, split);    xaccSplitSetAmount (split, balancing_amount);    xaccSplitSetValue (split, balancing_amount);    // 2. Split (no account is defined: split goes to orphan account)    split = xaccMallocSplit (book);    xaccTransAppendSplit (trans, split);    balancing_amount = gnc_numeric_neg (balancing_amount);    xaccSplitSetAmount (split, balancing_amount);    xaccSplitSetValue (split, balancing_amount);    xaccTransCommitEdit (trans);    xaccAccountCommitEdit (account);    return trans;}
开发者ID:Gnucash,项目名称:gnucash,代码行数:42,


示例17: test_add_transaction

static gbooleantest_add_transaction (const char* tag, gpointer globaldata, gpointer data){    Transaction* trans = static_cast<decltype (trans)> (data);    tran_data* gdata = static_cast<decltype (gdata)> (globaldata);    gboolean retval = TRUE;    xaccTransBeginEdit (trans);    xaccTransSetCurrency (trans, gdata->com);    xaccTransCommitEdit (trans);    if (!do_test_args (xaccTransEqual (gdata->trn, trans, TRUE, TRUE, TRUE, FALSE),                       "gnc_transaction_sixtp_parser_create",                       __FILE__, __LINE__,                       "%d", gdata->value))        retval = FALSE;    gdata->new_trn = trans;    return retval;}
开发者ID:TumbleweedPretzel,项目名称:gnucash,代码行数:21,


示例18: add_balance_split

static voidadd_balance_split (Transaction *trans, gnc_numeric imbalance,                   Account *root, Account *account){    const gnc_commodity *commodity;    gnc_numeric old_value, new_value;    Split *balance_split;    gnc_commodity *currency = xaccTransGetCurrency (trans);    balance_split = get_balance_split(trans, root, account, currency);    if (!balance_split)    {        /* Error already logged */        LEAVE("");        return;    }    account = xaccSplitGetAccount(balance_split);    xaccTransBeginEdit (trans);    old_value = xaccSplitGetValue (balance_split);    /* Note: We have to round for the commodity's fraction, NOT any     * already existing denominator (bug #104343), because either one     * of the denominators might already be reduced.  */    new_value = gnc_numeric_sub (old_value, imbalance,                                 gnc_commodity_get_fraction(currency),                                 GNC_HOW_RND_ROUND_HALF_UP);    xaccSplitSetValue (balance_split, new_value);    commodity = xaccAccountGetCommodity (account);    if (gnc_commodity_equiv (currency, commodity))    {        xaccSplitSetAmount (balance_split, new_value);    }    xaccSplitScrub (balance_split);    xaccTransCommitEdit (trans);}
开发者ID:Bob-IT,项目名称:gnucash,代码行数:40,


示例19: get_trading_split

/* Get the trading split for a given commodity, creating it (and the   necessary accounts) if it doesn't exist. */static Split *get_trading_split (Transaction *trans, Account *root,                   gnc_commodity *commodity){    Split *balance_split;    Account *trading_account;    Account *ns_account;    Account *account;    gnc_commodity *default_currency = NULL;    if (!root)    {        root = gnc_book_get_root_account (xaccTransGetBook (trans));        if (NULL == root)        {            /* This can't occur, things should be in books */            PERR ("Bad data corruption, no root account in book");            return NULL;        }    }    /* Get the default currency.  This is harder than it seems.  It's not       possible to call gnc_default_currency() since it's a UI function.  One       might think that the currency of the root account would do, but the root       account has no currency.  Instead look for the Income placeholder account       and use its currency.  */    default_currency = xaccAccountGetCommodity(gnc_account_lookup_by_name(root,                                                                          _("Income")));    if (! default_currency)    {        default_currency = commodity;    }    trading_account = xaccScrubUtilityGetOrMakeAccount (root,                                                        default_currency,                                                        _("Trading"),                                                        ACCT_TYPE_TRADING, TRUE);    if (!trading_account)    {        PERR ("Can't get trading account");        return NULL;    }    ns_account = xaccScrubUtilityGetOrMakeAccount (trading_account,                                                   default_currency,                                                   gnc_commodity_get_namespace(commodity),                                                   ACCT_TYPE_TRADING, TRUE);    if (!ns_account)    {        PERR ("Can't get namespace account");        return NULL;    }    account = xaccScrubUtilityGetOrMakeAccount (ns_account, commodity,                                                gnc_commodity_get_mnemonic(commodity),                                                ACCT_TYPE_TRADING, FALSE);    if (!account)    {        PERR ("Can't get commodity account");        return NULL;    }    balance_split = xaccTransFindSplitByAccount(trans, account);    /* Put split into account before setting split value */    if (!balance_split)    {        balance_split = xaccMallocSplit (qof_instance_get_book(trans));        xaccTransBeginEdit (trans);        xaccSplitSetParent(balance_split, trans);        xaccSplitSetAccount(balance_split, account);        xaccTransCommitEdit (trans);    }    return balance_split;}
开发者ID:Bob-IT,项目名称:gnucash,代码行数:80,


示例20: xaccSplitScrub

voidxaccSplitScrub (Split *split){    Account *account;    Transaction *trans;    gnc_numeric value, amount;    gnc_commodity *currency, *acc_commodity;    int scu;    if (!split) return;    ENTER ("(split=%p)", split);    trans = xaccSplitGetParent (split);    if (!trans)    {        LEAVE("no trans");        return;    }    account = xaccSplitGetAccount (split);    /* If there's no account, this split is an orphan.     * We need to fix that first, before proceeding.     */    if (!account)    {        xaccTransScrubOrphans (trans);        account = xaccSplitGetAccount (split);    }    /* Grrr... the register gnc_split_register_load() line 203 of     *  src/register/ledger-core/split-register-load.c will create     * free-floating bogus transactions. Ignore these for now ...     */    if (!account)    {        PINFO ("Free Floating Transaction!");        LEAVE ("no account");        return;    }    /* Split amounts and values should be valid numbers */    value = xaccSplitGetValue (split);    if (gnc_numeric_check (value))    {        value = gnc_numeric_zero();        xaccSplitSetValue (split, value);    }    amount = xaccSplitGetAmount (split);    if (gnc_numeric_check (amount))    {        amount = gnc_numeric_zero();        xaccSplitSetAmount (split, amount);    }    currency = xaccTransGetCurrency (trans);    /* If the account doesn't have a commodity,     * we should attempt to fix that first.     */    acc_commodity = xaccAccountGetCommodity(account);    if (!acc_commodity)    {        xaccAccountScrubCommodity (account);    }    if (!acc_commodity || !gnc_commodity_equiv(acc_commodity, currency))    {        LEAVE ("(split=%p) inequiv currency", split);        return;    }    scu = MIN (xaccAccountGetCommoditySCU (account),               gnc_commodity_get_fraction (currency));    if (gnc_numeric_same (amount, value, scu, GNC_HOW_RND_ROUND_HALF_UP))    {        LEAVE("(split=%p) different values", split);        return;    }    /*     * This will be hit every time you answer yes to the dialog "The     * current transaction has changed. Would you like to record it.     */    PINFO ("Adjusted split with mismatched values, desc=/"%s/" memo=/"%s/""           " old amount %s %s, new amount %s",           trans->description, split->memo,           gnc_num_dbg_to_string (xaccSplitGetAmount(split)),           gnc_commodity_get_mnemonic (currency),           gnc_num_dbg_to_string (xaccSplitGetValue(split)));    xaccTransBeginEdit (trans);    xaccSplitSetAmount (split, value);    xaccTransCommitEdit (trans);    LEAVE ("(split=%p)", split);}
开发者ID:Bob-IT,项目名称:gnucash,代码行数:97,


示例21: xaccTransScrubCurrency

voidxaccTransScrubCurrency (Transaction *trans){    SplitList *node;    gnc_commodity *currency;    if (!trans) return;    /* If there are any orphaned splits in a transaction, then the     * this routine will fail.  Therefore, we want to make sure that     * there are no orphans (splits without parent account).     */    xaccTransScrubOrphans (trans);    currency = xaccTransGetCurrency (trans);    if (currency && gnc_commodity_is_currency(currency)) return;    currency = xaccTransFindCommonCurrency (trans, qof_instance_get_book(trans));    if (currency)    {        xaccTransBeginEdit (trans);        xaccTransSetCurrency (trans, currency);        xaccTransCommitEdit (trans);    }    else    {        if (NULL == trans->splits)        {            PWARN ("Transaction /"%s/" has no splits in it!", trans->description);        }        else        {            SplitList *node;            char guid_str[GUID_ENCODING_LENGTH + 1];            guid_to_string_buff(xaccTransGetGUID(trans), guid_str);            PWARN ("no common transaction currency found for trans=/"%s/" (%s);",                   trans->description, guid_str);            for (node = trans->splits; node; node = node->next)            {                Split *split = node->data;                if (NULL == split->acc)                {                    PWARN (" split=/"%s/" is not in any account!", split->memo);                }                else                {		    gnc_commodity *currency = xaccAccountGetCommodity(split->acc);                    PWARN ("setting to split=/"%s/" account=/"%s/" commodity=/"%s/"",                           split->memo, xaccAccountGetName(split->acc),                           gnc_commodity_get_mnemonic(currency));		    xaccTransBeginEdit (trans);		    xaccTransSetCurrency (trans, currency);		    xaccTransCommitEdit (trans);		    return;                }            }        }        return;    }    for (node = trans->splits; node; node = node->next)    {        Split *sp = node->data;        if (!gnc_numeric_equal(xaccSplitGetAmount (sp),                               xaccSplitGetValue (sp)))        {            gnc_commodity *acc_currency;            acc_currency = sp->acc ? xaccAccountGetCommodity(sp->acc) : NULL;            if (acc_currency == currency)            {                /* This Split needs fixing: The transaction-currency equals                 * the account-currency/commodity, but the amount/values are                 * inequal i.e. they still correspond to the security                 * (amount) and the currency (value). In the new model, the                 * value is the amount in the account-commodity -- so it                 * needs to be set to equal the amount (since the                 * account-currency doesn't exist anymore).                 *                 * Note: Nevertheless we lose some information here. Namely,                 * the information that the 'amount' in 'account-old-security'                 * was worth 'value' in 'account-old-currency'. Maybe it would                 * be better to store that information in the price database?                 * But then, for old currency transactions there is still the                 * 'other' transaction, which is going to keep that                 * information. So I don't bother with that here. -- cstim,                 * 2002/11/20. */                PWARN ("Adjusted split with mismatched values, desc=/"%s/" memo=/"%s/""                       " old amount %s %s, new amount %s",                       trans->description, sp->memo,                       gnc_num_dbg_to_string (xaccSplitGetAmount(sp)),                       gnc_commodity_get_mnemonic (currency),                       gnc_num_dbg_to_string (xaccSplitGetValue(sp)));                xaccTransBeginEdit (trans);                xaccSplitSetAmount (sp, xaccSplitGetValue(sp));                xaccTransCommitEdit (trans);//.........这里部分代码省略.........
开发者ID:Bob-IT,项目名称:gnucash,代码行数:101,


示例22: trans_property_list_to_trans

/** Create a Transaction from a TransPropertyList. * @param list The list of properties * @param error Contains an error on failure * @return On success, a GncCsvTransLine; on failure, the trans pointer is NULL */static GncCsvTransLine* trans_property_list_to_trans (TransPropertyList* list, gchar** error){    GncCsvTransLine* trans_line = g_new (GncCsvTransLine, 1);    GList* properties_begin = list->properties;    QofBook* book = gnc_account_get_book (list->account);    gnc_commodity* currency = xaccAccountGetCommodity (list->account);    gnc_numeric amount = double_to_gnc_numeric (0.0, xaccAccountGetCommoditySCU (list->account),                         GNC_HOW_RND_ROUND_HALF_UP);    gchar *num = NULL;    /* This flag is set to TRUE if we can use the "Deposit" or "Withdrawal" column. */    gboolean amount_set = FALSE;    /* The balance is 0 by default. */    trans_line->balance_set = FALSE;    trans_line->balance = amount;    trans_line->num = NULL;    /* We make the line_no -1 just to mark that it hasn't been set. We     * may get rid of line_no soon anyway, so it's not particularly     * important. */    trans_line->line_no = -1;    /* Make sure this is a transaction with all the columns we need. */    if (!trans_property_list_verify_essentials (list, error))    {        g_free(trans_line);        return NULL;    }    trans_line->trans = xaccMallocTransaction (book);    xaccTransBeginEdit (trans_line->trans);    xaccTransSetCurrency (trans_line->trans, currency);    /* Go through each of the properties and edit the transaction accordingly. */    list->properties = properties_begin;    while (list->properties != NULL)    {        TransProperty* prop = (TransProperty*)(list->properties->data);        switch (prop->type)        {        case GNC_CSV_DATE:            xaccTransSetDatePostedSecsNormalized (trans_line->trans, *((time64*)(prop->value)));            break;        case GNC_CSV_DESCRIPTION:            xaccTransSetDescription (trans_line->trans, (char*)(prop->value));            break;        case GNC_CSV_NOTES:            xaccTransSetNotes (trans_line->trans, (char*)(prop->value));            break;        case GNC_CSV_NUM:            /* the 'num' is saved and passed to 'trans_add_split' below where             * 'gnc_set_num_action' is used to set tran-num and/or split-action             * per book option */            num = g_strdup ((char*)(prop->value));            /* the 'num' is also saved and used in 'gnc_csv_parse_to_trans' when             * it calls 'trans_add_split' after deleting the splits added below             * when a balance is used by the user */            trans_line->num = g_strdup ((char*)(prop->value));            break;        case GNC_CSV_DEPOSIT: /* Add deposits to the existing amount. */            if (prop->value != NULL)            {                amount = gnc_numeric_add (*((gnc_numeric*)(prop->value)),                                         amount,                                         xaccAccountGetCommoditySCU (list->account),                                         GNC_HOW_RND_ROUND_HALF_UP);                amount_set = TRUE;                /* We will use the "Deposit" and "Withdrawal" columns in preference to "Balance". */                trans_line->balance_set = FALSE;            }            break;        case GNC_CSV_WITHDRAWAL: /* Withdrawals are just negative deposits. */            if (prop->value != NULL)            {                amount = gnc_numeric_add (gnc_numeric_neg(*((gnc_numeric*)(prop->value))),                                         amount,                                         xaccAccountGetCommoditySCU (list->account),                                         GNC_HOW_RND_ROUND_HALF_UP);                amount_set = TRUE;                /* We will use the "Deposit" and "Withdrawal" columns in preference to "Balance". */                trans_line->balance_set = FALSE;            }            break;        case GNC_CSV_BALANCE: /* The balance gets stored in a separate field in trans_line. */            /* We will use the "Deposit" and "Withdrawal" columns in preference to "Balance". */            if (!amount_set && prop->value != NULL)            {                /* This gets put into the actual transaction at the end of gnc_csv_parse_to_trans. *///.........这里部分代码省略.........
开发者ID:geroldr,项目名称:gnucash,代码行数:101,


示例23: gnc_ab_maketrans

//.........这里部分代码省略.........            successful = FALSE;            goto repeat;        }        if (result == GNC_RESPONSE_NOW)        {            /* Create a context to store possible results */            context = AB_ImExporterContext_new();            gui = gnc_GWEN_Gui_get(parent);            if (!gui)            {                g_warning("gnc_ab_maketrans: Couldn't initialize Gwenhywfar GUI");                aborted = TRUE;                goto repeat;            }            /* Finally, execute the job */            AB_Banking_ExecuteJobs(api, job_list, context#ifndef AQBANKING_VERSION_5_PLUS                                   , 0#endif                                  );            /* Ignore the return value of AB_Banking_ExecuteJobs(), as the job's             * status always describes better whether the job was actually             * transferred to and accepted by the bank.  See also             * http://lists.gnucash.org/pipermail/gnucash-de/2008-September/006389.html             */            job_status = AB_Job_GetStatus(job);            if (job_status != AB_Job_StatusFinished                    && job_status != AB_Job_StatusPending)            {                successful = FALSE;                if (!gnc_verify_dialog(                            parent, FALSE, "%s",                            _("An error occurred while executing the job. Please check "                              "the log window for the exact error message./n"                              "/n"                              "Do you want to enter the job again?")))                {                    aborted = TRUE;                }            }            else            {                successful = TRUE;            }            if (successful)            {                /* Import the results, awaiting nothing */                ieci = gnc_ab_import_context(context, 0, FALSE, NULL, parent);            }        }        /* Simply ignore any other case */repeat:        /* Clean up */        if (gnc_trans && !successful)        {            xaccTransBeginEdit(gnc_trans);            xaccTransDestroy(gnc_trans);            xaccTransCommitEdit(gnc_trans);            gnc_trans = NULL;        }        if (ieci)            g_free(ieci);        if (context)            AB_ImExporterContext_free(context);        if (job_list)        {            AB_Job_List2_free(job_list);            job_list = NULL;        }        if (job)        {            AB_Job_free(job);            job = NULL;        }        if (gui)        {            gnc_GWEN_Gui_release(gui);            gui = NULL;        }    }    while (!successful && !aborted);cleanup:    if (td)        gnc_ab_trans_dialog_free(td);    if (online)#ifdef AQBANKING_VERSION_4_EXACTLY        AB_Banking_OnlineFini(api, 0);#else        AB_Banking_OnlineFini(api);#endif    gnc_AB_BANKING_fini(api);}
开发者ID:Tropicalrambler,项目名称:gnucash,代码行数:101,


示例24: gnc_stock_split_assistant_finish

voidgnc_stock_split_assistant_finish (GtkAssistant *assistant,                                  gpointer user_data){    StockSplitInfo *info = user_data;    GList *account_commits;    GList *node;    gnc_numeric amount;    Transaction *trans;    Account *account;    Split *split;    time64 date;    account = info->acct;    g_return_if_fail (account != NULL);    amount = gnc_amount_edit_get_amount             (GNC_AMOUNT_EDIT (info->distribution_edit));    g_return_if_fail (!gnc_numeric_zero_p (amount));    gnc_suspend_gui_refresh ();    trans = xaccMallocTransaction (gnc_get_current_book ());    xaccTransBeginEdit (trans);    xaccTransSetCurrency (trans, gnc_default_currency ());    date = gnc_date_edit_get_date (GNC_DATE_EDIT (info->date_edit));    xaccTransSetDatePostedSecsNormalized (trans, date);    {        const char *description;        description = gtk_entry_get_text (GTK_ENTRY (info->description_entry));        xaccTransSetDescription (trans, description);    }    split = xaccMallocSplit (gnc_get_current_book ());    xaccAccountBeginEdit (account);    account_commits = g_list_prepend (NULL, account);    xaccTransAppendSplit (trans, split);    xaccAccountInsertSplit (account, split);    xaccSplitSetAmount (split, amount);    xaccSplitMakeStockSplit (split);    /* Set split-action with gnc_set_num_action which is the same as     * xaccSplitSetAction with these arguments */    /* Translators: This string has a disambiguation prefix */    gnc_set_num_action (NULL, split, NULL, Q_("Action Column|Split"));    amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->price_edit));    if (gnc_numeric_positive_p (amount))    {        QofBook *book;        GNCPrice *price;        GNCPriceDB *pdb;        GNCCurrencyEdit *ce;        Timespec ts;        ce = GNC_CURRENCY_EDIT (info->price_currency_edit);        ts.tv_sec = date;        ts.tv_nsec = 0;        price = gnc_price_create (gnc_get_current_book ());        gnc_price_begin_edit (price);        gnc_price_set_commodity (price, xaccAccountGetCommodity (account));        gnc_price_set_currency (price, gnc_currency_edit_get_currency (ce));        gnc_price_set_time (price, ts);        gnc_price_set_source (price, PRICE_SOURCE_STOCK_SPLIT);        gnc_price_set_typestr (price, PRICE_TYPE_UNK);        gnc_price_set_value (price, amount);        gnc_price_commit_edit (price);        book = gnc_get_current_book ();        pdb = gnc_pricedb_get_db (book);        if (!gnc_pricedb_add_price (pdb, price))            gnc_error_dialog (info->window, "%s", _("Error adding price."));    }    amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->cash_edit));    if (gnc_numeric_positive_p (amount))    {        const char *memo;        memo = gtk_entry_get_text (GTK_ENTRY (info->memo_entry));        /* asset split */        account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->asset_tree));        split = xaccMallocSplit (gnc_get_current_book ());//.........这里部分代码省略.........
开发者ID:carrot-garden,项目名称:money_gnucash,代码行数:101,


示例25: gnc_split_register_load

voidgnc_split_register_load (SplitRegister *reg, GList * slist,                         Account *default_account){    SRInfo *info;    Transaction *pending_trans;    CursorBuffer *cursor_buffer;    GHashTable *trans_table = NULL;    CellBlock *cursor_header;    CellBlock *lead_cursor;    CellBlock *split_cursor;    Transaction *blank_trans;    Transaction *find_trans;    Transaction *trans;    CursorClass find_class;    Split *find_trans_split;    Split *blank_split;    Split *find_split;    Split *split;    Table *table;    GList *node;    gboolean start_primary_color = TRUE;    gboolean found_pending = FALSE;    gboolean need_divider_upper = FALSE;    gboolean found_divider_upper = FALSE;    gboolean found_divider = FALSE;    gboolean has_last_num = FALSE;    gboolean multi_line;    gboolean dynamic;    gboolean we_own_slist = FALSE;    gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());    VirtualCellLocation vcell_loc;    VirtualLocation save_loc;    int new_trans_split_row = -1;    int new_trans_row = -1;    int new_split_row = -1;    time64 present, autoreadonly_time = 0;    g_return_if_fail(reg);    table = reg->table;    g_return_if_fail(table);    info = gnc_split_register_get_info (reg);    g_return_if_fail(info);    ENTER("reg=%p, slist=%p, default_account=%p", reg, slist, default_account);    blank_split = xaccSplitLookup (&info->blank_split_guid,                                   gnc_get_current_book ());    pending_trans = xaccTransLookup (&info->pending_trans_guid,                                     gnc_get_current_book ());    /* make sure we have a blank split */    if (blank_split == NULL)    {        Transaction *new_trans;        gboolean currency_from_account = TRUE;        /* Determine the proper currency to use for this transaction.         * if default_account != NULL and default_account->commodity is         * a currency, then use that.  Otherwise use the default currency.         */        gnc_commodity * currency = gnc_account_or_default_currency(default_account, &currency_from_account);        if (default_account != NULL && !currency_from_account)        {            /* If we don't have a currency then pop up a warning dialog */            gnc_info_dialog(NULL, "%s",                            _("Could not determine the account currency. "                              "Using the default currency provided by your system."));        }        gnc_suspend_gui_refresh ();        new_trans = xaccMallocTransaction (gnc_get_current_book ());        xaccTransBeginEdit (new_trans);        xaccTransSetCurrency (new_trans, currency);        xaccTransSetDatePostedSecsNormalized(new_trans, info->last_date_entered);        blank_split = xaccMallocSplit (gnc_get_current_book ());        xaccSplitSetParent(blank_split, new_trans);        /* We don't want to commit this transaction yet, because the split           doesn't even belong to an account yet.  But, we don't want to           set this transaction as the pending transaction either, because           we want to pretend that it hasn't been changed.  We depend on           some other code (somewhere) to commit this transaction if we           really edit it, even though it's not marked as the pending           transaction. */        /* Wouldn't it be a bug to open this transaction if there was already a           pending transaction? */        g_assert(pending_trans == NULL);        info->blank_split_guid = *xaccSplitGetGUID (blank_split);        info->blank_split_edited = FALSE;        info->auto_complete = FALSE;        DEBUG("created new blank_split=%p", blank_split);//.........这里部分代码省略.........
开发者ID:573,项目名称:gnucash,代码行数:101,


示例26: xaccTransScrubImbalance

voidxaccTransScrubImbalance (Transaction *trans, Account *root,                         Account *account){    const gnc_commodity *currency;    if (!trans) return;    ENTER ("()");    /* Must look for orphan splits even if there is no imbalance. */    xaccTransScrubSplits (trans);    /* Return immediately if things are balanced. */    if (xaccTransIsBalanced (trans))    {        LEAVE ("transaction is balanced");        return;    }    currency = xaccTransGetCurrency (trans);    if (! xaccTransUseTradingAccounts (trans))    {        gnc_numeric imbalance;        /* Make the value sum to zero */        imbalance = xaccTransGetImbalanceValue (trans);        if (! gnc_numeric_zero_p (imbalance))        {            PINFO ("Value unbalanced transaction");            add_balance_split (trans, imbalance, root, account);        }    }    else    {        MonetaryList *imbal_list;        MonetaryList *imbalance_commod;        GList *splits;        gnc_numeric imbalance;        Split *balance_split = NULL;        /* If there are existing trading splits, adjust the price or exchange           rate in each of them to agree with the non-trading splits for the           same commodity.  If there are multiple non-trading splits for the           same commodity in the transaction this will use the exchange rate in           the last such split.  This shouldn't happen, and if it does then there's           not much we can do about it anyway.           While we're at it, compute the value imbalance ignoring existing           trading splits. */        imbalance = gnc_numeric_zero();        for (splits = trans->splits; splits; splits = splits->next)        {            Split *split = splits->data;            gnc_numeric value, amount;            gnc_commodity *commodity;            if (! xaccTransStillHasSplit (trans, split)) continue;            commodity = xaccAccountGetCommodity (xaccSplitGetAccount(split));            if (!commodity)            {                PERR("Split has no commodity");                continue;            }            balance_split = find_trading_split (trans, root, commodity);            if (balance_split != split)                /* this is not a trading split */                imbalance = gnc_numeric_add(imbalance, xaccSplitGetValue (split),                                            GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);            /* Ignore splits where value or amount is zero */            value = xaccSplitGetValue (split);            amount = xaccSplitGetAmount (split);            if (gnc_numeric_zero_p(amount) || gnc_numeric_zero_p(value))                continue;            if (balance_split && balance_split != split)            {                gnc_numeric convrate = gnc_numeric_div (amount, value,                                                        GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);                gnc_numeric old_value, new_value;                old_value = xaccSplitGetValue(balance_split);                new_value = gnc_numeric_div (xaccSplitGetAmount(balance_split),                                             convrate,                                             gnc_commodity_get_fraction(currency),                                             GNC_HOW_RND_ROUND_HALF_UP);                if (! gnc_numeric_equal (old_value, new_value))                {                    xaccTransBeginEdit (trans);                    xaccSplitSetValue (balance_split, new_value);                    xaccSplitScrub (balance_split);                    xaccTransCommitEdit (trans);                }//.........这里部分代码省略.........
开发者ID:BenBergman,项目名称:gnucash,代码行数:101,


示例27: gnc_tree_util_split_reg_rotate

gbooleangnc_tree_util_split_reg_rotate (GncTreeViewSplitReg *view, GtkTreeViewColumn *col, Transaction *trans, Split *split){    GtkCellRenderer *cr0 = NULL;    GList *renderers;    ViewCol viewcol;    // Get the first renderer, it has the view-column value.    renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (col));    cr0 = g_list_nth_data (renderers, 0);    g_list_free (renderers);    viewcol = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cr0), "view_column"));    if (viewcol == COL_RECN)    {        const char recn_flags[] = {NREC, CREC, 0}; // List of reconciled flags        const gchar *flags;        const gchar *text;        gchar *this_flag;        gint index = 0;        char rec;        flags = recn_flags;        text = g_strdup_printf("%c", xaccSplitGetReconcile (split));        /* Find the existing text in the list of flags */        this_flag = strstr (flags, text);        if (this_flag != NULL && *this_flag != '/0')        {            /* In the list, choose the next item in the list               (wrapping around as necessary). */            index = this_flag - flags;            if (flags[index + 1] != '/0')                index = index + 1;            else                index = 0;            rec = recn_flags[index];        }        else            rec = NREC;        gnc_tree_view_split_reg_set_dirty_trans (view, trans);        if (!xaccTransIsOpen (trans))            xaccTransBeginEdit (trans);        xaccSplitSetReconcile (split, rec);        return TRUE;    }    if (viewcol == COL_TYPE)    {        const char type_flags[] = {TXN_TYPE_INVOICE, TXN_TYPE_PAYMENT, 0}; // list of type flags        const gchar *flags;        const gchar *text;        gchar *this_flag;        gint index = 0;        char type;        flags = type_flags;        text = g_strdup_printf("%c", xaccTransGetTxnType (trans));        /* Find the existing text in the list of flags */        this_flag = strstr (flags, text);        if (this_flag != NULL && *this_flag != '/0')        {            /* In the list, choose the next item in the list               (wrapping around as necessary). */            index = this_flag - flags;            if (flags[index + 1] != '/0')                index = index + 1;            else                index = 0;            type = type_flags[index];        }        else            type = TXN_TYPE_NONE;        gnc_tree_view_split_reg_set_dirty_trans (view, trans);        if (!xaccTransIsOpen (trans))            xaccTransBeginEdit (trans);        xaccTransSetTxnType (trans, type);        return TRUE;    }    return FALSE;}
开发者ID:573,项目名称:gnucash,代码行数:95,


示例28: gnc_transaction_balance_trading

static voidgnc_transaction_balance_trading (Transaction *trans, Account *root){    MonetaryList *imbal_list;    MonetaryList *imbalance_commod;    Split *balance_split = NULL;    /* If the transaction is balanced, nothing more to do */    imbal_list = xaccTransGetImbalance (trans);    if (!imbal_list)    {        LEAVE("transaction is balanced");        return;    }    PINFO ("Currency unbalanced transaction");    for (imbalance_commod = imbal_list; imbalance_commod;         imbalance_commod = imbalance_commod->next)    {        gnc_monetary *imbal_mon = imbalance_commod->data;        gnc_commodity *commodity;        gnc_numeric old_amount, new_amount;        gnc_numeric old_value, new_value, val_imbalance;        Account *account = NULL;        const gnc_commodity *txn_curr = xaccTransGetCurrency (trans);        commodity = gnc_monetary_commodity (*imbal_mon);        balance_split = get_trading_split(trans, root, commodity);        if (!balance_split)        {            /* Error already logged */            gnc_monetary_list_free(imbal_list);            LEAVE("");            return;        }        account = xaccSplitGetAccount(balance_split);        if (! gnc_commodity_equal (txn_curr, commodity))        {            val_imbalance = gnc_transaction_get_commodity_imbalance (trans, commodity);        }        xaccTransBeginEdit (trans);        old_amount = xaccSplitGetAmount (balance_split);        new_amount = gnc_numeric_sub (old_amount, gnc_monetary_value(*imbal_mon),                                      gnc_commodity_get_fraction(commodity),                                      GNC_HOW_RND_ROUND_HALF_UP);        xaccSplitSetAmount (balance_split, new_amount);        if (gnc_commodity_equal (txn_curr, commodity))        {            /* Imbalance commodity is the transaction currency, value in the               split must be the same as the amount */            xaccSplitSetValue (balance_split, new_amount);        }        else        {            old_value = xaccSplitGetValue (balance_split);            new_value = gnc_numeric_sub (old_value, val_imbalance,                                         gnc_commodity_get_fraction(txn_curr),                                         GNC_HOW_RND_ROUND_HALF_UP);            xaccSplitSetValue (balance_split, new_value);        }        xaccSplitScrub (balance_split);        xaccTransCommitEdit (trans);    }    gnc_monetary_list_free(imbal_list);}
开发者ID:Bob-IT,项目名称:gnucash,代码行数:76,


示例29: gnc_ab_trans_to_gnc

Transaction *gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc){    QofBook *book;    Transaction *gnc_trans;    const gchar *fitid;    const GWEN_TIME *valuta_date;    time64 current_time;    const char *custref;    gchar *description;    Split *split;    gchar *memo;    g_return_val_if_fail(ab_trans && gnc_acc, NULL);    /* Create new GnuCash transaction for the given AqBanking one */    book = gnc_account_get_book(gnc_acc);    gnc_trans = xaccMallocTransaction(book);    xaccTransBeginEdit(gnc_trans);    /* Date / Time */    valuta_date = AB_Transaction_GetValutaDate(ab_trans);    if (!valuta_date)    {        const GWEN_TIME *normal_date = AB_Transaction_GetDate(ab_trans);        if (normal_date)            valuta_date = normal_date;    }    if (valuta_date)        xaccTransSetDatePostedSecsNormalized(gnc_trans, GWEN_Time_toTime_t(valuta_date));    else        g_warning("transaction_cb: Oops, date 'valuta_date' was NULL");    xaccTransSetDateEnteredSecs(gnc_trans, gnc_time (NULL));    /* Currency.  We take simply the default currency of the gnucash account */    xaccTransSetCurrency(gnc_trans, xaccAccountGetCommodity(gnc_acc));    /* Trans-Num or Split-Action set with gnc_set_num_action below per book     * option */    /* Description */    description = gnc_ab_description_to_gnc(ab_trans);    xaccTransSetDescription(gnc_trans, description);    g_free(description);    /* Notes. */    /* xaccTransSetNotes(gnc_trans, g_notes); */    /* But Nobody ever uses the Notes field? */    /* Add one split */    split = xaccMallocSplit(book);    xaccSplitSetParent(split, gnc_trans);    xaccSplitSetAccount(split, gnc_acc);    /* Set the transaction number or split action field based on book option.     * We use the "customer reference", if there is one. */    custref = AB_Transaction_GetCustomerReference(ab_trans);    if (custref && *custref            && g_ascii_strncasecmp(custref, "NONREF", 6) != 0)        gnc_set_num_action (gnc_trans, split, custref, NULL);    /* Set OFX unique transaction ID */    fitid = AB_Transaction_GetFiId(ab_trans);    if (fitid && *fitid)        gnc_import_set_split_online_id(split, fitid);    {        /* Amount into the split */        const AB_VALUE *ab_value = AB_Transaction_GetValue(ab_trans);        double d_value = ab_value ? AB_Value_GetValueAsDouble (ab_value) : 0.0;        AB_TRANSACTION_TYPE ab_type = AB_Transaction_GetType (ab_trans);        gnc_numeric gnc_amount;        /*printf("Transaction with value %f has type %d/n", d_value, ab_type);*/        /* If the value is positive, but the transaction type says the           money is transferred away from our account (Transfer instead of           DebitNote), we switch the value to negative. */        if (d_value > 0.0 && ab_type == AB_Transaction_TypeTransfer)            d_value = -d_value;        gnc_amount = double_to_gnc_numeric(                         d_value,                         xaccAccountGetCommoditySCU(gnc_acc),                         GNC_HOW_RND_ROUND_HALF_UP);        if (!ab_value)            g_warning("transaction_cb: Oops, value was NULL.  Using 0");        xaccSplitSetBaseValue(split, gnc_amount, xaccAccountGetCommodity(gnc_acc));    }    /* Memo in the Split. */    memo = gnc_ab_memo_to_gnc(ab_trans);    xaccSplitSetMemo(split, memo);    g_free(memo);    return gnc_trans;}
开发者ID:Tropicalrambler,项目名称:gnucash,代码行数:97,


示例30: xaccScrubSubSplitPrice

voidxaccScrubSubSplitPrice (Split *split, int maxmult, int maxamtscu){    gnc_numeric src_amt, src_val;    SplitList *node;    if (FALSE == is_subsplit (split)) return;    ENTER (" ");    /* Get 'price' of the indicated split */    src_amt = xaccSplitGetAmount (split);    src_val = xaccSplitGetValue (split);    /* Loop over splits, adjust each so that it has the same     * ratio (i.e. price).  Change the value to get things     * right; do not change the amount */    for (node = split->parent->splits; node; node = node->next)    {        Split *s = node->data;        Transaction *txn = s->parent;        gnc_numeric dst_amt, dst_val, target_val;        gnc_numeric frac, delta;        int scu;        /* Skip the reference split */        if (s == split) continue;        scu = gnc_commodity_get_fraction (txn->common_currency);        dst_amt = xaccSplitGetAmount (s);        dst_val = xaccSplitGetValue (s);        frac = gnc_numeric_div (dst_amt, src_amt,                                GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE);        target_val = gnc_numeric_mul (frac, src_val,                                      scu, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);        if (gnc_numeric_check (target_val))        {            PERR ("Numeric overflow of value/n"                  "/tAcct=%s txn=%s/n"                  "/tdst_amt=%s src_val=%s src_amt=%s/n",                  xaccAccountGetName (s->acc),                  xaccTransGetDescription(txn),                  gnc_num_dbg_to_string(dst_amt),                  gnc_num_dbg_to_string(src_val),                  gnc_num_dbg_to_string(src_amt));            continue;        }        /* If the required price changes are 'small', do nothing.         * That is a case that the user will have to deal with         * manually.  This routine is really intended only for         * a gross level of synchronization.         */        delta = gnc_numeric_sub_fixed (target_val, dst_val);        delta = gnc_numeric_abs (delta);        if (maxmult * delta.num  < delta.denom) continue;        /* If the amount is small, pass on that too */        if ((-maxamtscu < dst_amt.num) && (dst_amt.num < maxamtscu)) continue;        /* Make the actual adjustment */        xaccTransBeginEdit (txn);        xaccSplitSetValue (s, target_val);        xaccTransCommitEdit (txn);    }    LEAVE (" ");}
开发者ID:kleopatra999,项目名称:gnucash-2,代码行数:67,



注:本文中的xaccTransBeginEdit函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ xalloc函数代码示例
C++ xaccSplitGetParent函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。