Ejemplo n.º 1
0
static void
gnc_template_register_save_shares_cell (BasicCell * cell,
                                        gpointer save_data,
                                        gpointer user_data)
{
    SRSaveData *sd = save_data;
    kvp_frame *kvpf;
    char *sharesStr = "(x + y)/42";

    g_return_if_fail (gnc_basic_cell_has_name (cell, SHRS_CELL));

    kvpf = xaccSplitGetSlots (sd->split);

    /* FIXME: shares cells are numeric by definition. */
    DEBUG ("kvp_frame before: %s\n", kvp_frame_to_string (kvpf));

    /* sharesStr = gnc_numeric_to_string( sharesStr ); */
    kvp_frame_set_slot_path (kvpf,
                             kvp_value_new_string (sharesStr),
                             GNC_SX_ID,
                             GNC_SX_SHARES,
                             NULL);

    DEBUG ("kvp_frame  after: %s\n", kvp_frame_to_string (kvpf));

    /* set the shares to an innocuous value */
    /* Note that this marks the split dirty */
    xaccSplitSetSharePriceAndAmount (sd->split,
                                     gnc_numeric_create (0, 1),
                                     gnc_numeric_create (0, 1));
}
Ejemplo n.º 2
0
static void
gnc_template_register_save_xfrm_cell (BasicCell * cell,
                                      gpointer save_data,
                                      gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    SRInfo *info = gnc_split_register_get_info (reg);
    Account *template_acc;
    const GncGUID *acctGUID;
    kvp_frame *kvpf;
    Account *acct;

    g_return_if_fail (gnc_basic_cell_has_name (cell, XFRM_CELL));

    /* save the account GncGUID into the kvp_data. */
    acct = gnc_split_register_get_account (reg, XFRM_CELL);
    if (!acct)
    {
        PERR ("unknown account");
        return;
    }

    acctGUID = xaccAccountGetGUID (acct);
    kvpf = xaccSplitGetSlots (sd->split);
    kvp_frame_set_slot_path (kvpf, kvp_value_new_guid(acctGUID),
                             GNC_SX_ID, GNC_SX_ACCOUNT, NULL);

    template_acc = xaccAccountLookup (&info->template_account,
                                      gnc_get_current_book ());

    /* set the actual account to the fake account for these templates */
    xaccAccountInsertSplit (template_acc, sd->split);
    qof_instance_set_dirty (QOF_INSTANCE (sd->split));
}
Ejemplo n.º 3
0
gint64
qof_book_get_counter (QofBook *book, const char *counter_name)
{
    QofBackend *be;
    KvpFrame *kvp;
    KvpValue *value;
    gint64 counter;

    if (!book)
    {
        PWARN ("No book!!!");
        return -1;
    }

    if (!counter_name || *counter_name == '\0')
    {
        PWARN ("Invalid counter name.");
        return -1;
    }

    /* If we've got a backend with a counter method, call it */
    be = book->backend;
    if (be && be->counter)
        return ((be->counter)(be, counter_name));

    /* If not, then use the KVP in the book */
    kvp = qof_book_get_slots (book);

    if (!kvp)
    {
        PWARN ("Book has no KVP_Frame");
        return -1;
    }

    value = kvp_frame_get_slot_path (kvp, "counters", counter_name, NULL);
    if (value)
    {
        /* found it */
        counter = kvp_value_get_gint64 (value);
    }
    else
    {
        /* New counter */
        counter = 0;
    }

    /* Counter is now valid; increment it */
    counter++;

    /* Save off the new counter */
    qof_book_begin_edit(book);
    value = kvp_value_new_gint64 (counter);
    kvp_frame_set_slot_path (kvp, value, "counters", counter_name, NULL);
    kvp_value_delete (value);
    qof_book_mark_dirty(book);
    qof_book_commit_edit(book);

    /* and return the value */
    return counter;
}
Ejemplo n.º 4
0
static void
gnc_template_register_save_debcred_cell (BasicCell * cell,
        gpointer save_data,
        gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    kvp_frame *kvpf;
    const char *value;
    char *error_loc;
    gnc_numeric new_amount;
    gboolean parse_result;

    g_return_if_fail (gnc_basic_cell_has_name (cell, FDEBT_CELL) ||
                      gnc_basic_cell_has_name (cell, FCRED_CELL));

    if (sd->handled_dc)
        return;

    kvpf = xaccSplitGetSlots (sd->split);

    DEBUG ("kvp_frame before: %s\n", kvp_frame_to_string (kvpf));

    /* amountStr = gnc_numeric_to_string (new_amount); */

    value = gnc_table_layout_get_cell_value (reg->table->layout, FCRED_CELL);
    kvp_frame_set_slot_path (kvpf, kvp_value_new_string (value),
                             GNC_SX_ID,
                             GNC_SX_CREDIT_FORMULA,
                             NULL);

    /* If the value can be parsed into a numeric result (without any
     * further variable definitions), store that numeric value
     * additionally in the kvp. Otherwise store a zero numeric
     * there.*/
    parse_result = gnc_exp_parser_parse_separate_vars(value, &new_amount, &error_loc, NULL);
    if (!parse_result)
    {
        new_amount = gnc_numeric_zero();
    }
    kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_amount),
                             GNC_SX_ID,
                             GNC_SX_CREDIT_NUMERIC,
                             NULL);

    value = gnc_table_layout_get_cell_value (reg->table->layout, FDEBT_CELL);

    kvp_frame_set_slot_path (kvpf,
                             kvp_value_new_string (value),
                             GNC_SX_ID,
                             GNC_SX_DEBIT_FORMULA,
                             NULL);

    /* If the value can be parsed into a numeric result, store that
     * numeric value additionally. See above comment.*/
    parse_result = gnc_exp_parser_parse_separate_vars(value, &new_amount, &error_loc, NULL);
    if (!parse_result)
    {
        new_amount = gnc_numeric_zero();
    }
    kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_amount),
                             GNC_SX_ID,
                             GNC_SX_DEBIT_NUMERIC,
                             NULL);

    DEBUG ("kvp_frame  after: %s\n", kvp_frame_to_string (kvpf));

    /* set the amount to an innocuous value */
    /* Note that this marks the split dirty */
    xaccSplitSetValue (sd->split, gnc_numeric_create (0, 1));

    sd->handled_dc = TRUE;
}