static void
gnc_template_register_save_debcred_cell (BasicCell * cell,
        gpointer save_data,
        gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    const char *credit_formula, *debit_formula;
    char *error_loc;
    gnc_numeric credit_amount, debit_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;

    /* amountStr = gnc_numeric_to_string (new_amount); */

    credit_formula = gnc_table_layout_get_cell_value (reg->table->layout,
						      FCRED_CELL);
    /* 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(credit_formula,
						      &credit_amount,
						      &error_loc, NULL);
    if (!parse_result)
        credit_amount = gnc_numeric_zero();

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

    /* 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(debit_formula,
						      &debit_amount,
						      &error_loc, NULL);
    if (!parse_result)
        debit_amount = gnc_numeric_zero();

    qof_instance_set (QOF_INSTANCE (sd->split),
		      "sx-credit-formula", credit_formula,
		      "sx-credit-numeric", &credit_amount,
		      "sx-debit-formula", debit_formula,
		      "sx-debit-numeric", &debit_amount,
		      NULL);
    /* 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;
}
Ejemplo n.º 2
0
static void
gnc_split_register_save_num_cell (BasicCell * cell,
                                  gpointer save_data,
                                  gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    const char *value;

    g_return_if_fail (gnc_basic_cell_has_name (cell, NUM_CELL));

    value = gnc_basic_cell_get_value (cell);

    DEBUG ("NUM: %s\n", value ? value : "(null)");

    /* set per book option */
    gnc_set_num_action (sd->trans, sd->split, value, NULL);

    if (gnc_num_cell_set_last_num ((NumCell *) cell, value))
    {
        SRInfo *info = gnc_split_register_get_info (reg);
        Split *blank_split = xaccSplitLookup (&info->blank_split_guid,
                                                  gnc_get_current_book ());
        Transaction *blank_trans = xaccSplitGetParent (blank_split);

        if (sd->trans == blank_trans)
           gnc_split_register_set_last_num (reg, gnc_basic_cell_get_value (cell));
    }
}
Ejemplo n.º 3
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.º 4
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.º 5
0
static void
gnc_split_register_save_debcred_cell (BasicCell * bcell,
                                      gpointer save_data,
                                      gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;

    g_return_if_fail (gnc_basic_cell_has_name (bcell, DEBT_CELL) ||
                      gnc_basic_cell_has_name (bcell, CRED_CELL));

    if (sd->handled_dc)
        return;

    gnc_split_register_save_amount_values (sd, reg);

    sd->handled_dc = TRUE;
    sd->do_scrub = TRUE;
}
Ejemplo n.º 6
0
static void
gnc_split_register_save_type_cell (BasicCell * cell,
                                   gpointer save_data,
                                   gpointer user_data)
{
    SRSaveData *sd = save_data;
    char value;

    g_return_if_fail (gnc_basic_cell_has_name (cell, TYPE_CELL));

    value = gnc_recn_cell_get_flag ((RecnCell *)cell);

    xaccTransSetTxnType (sd->trans, value);
}
Ejemplo n.º 7
0
static void
gnc_split_register_save_recn_cell (BasicCell * bcell,
                                   gpointer save_data,
                                   gpointer user_data)
{
    SRSaveData *sd = save_data;
    RecnCell *cell = (RecnCell *) bcell;

    g_return_if_fail (gnc_basic_cell_has_name (bcell, RECN_CELL));

    DEBUG ("RECN: %c", gnc_recn_cell_get_flag (cell));

    xaccSplitSetReconcile (sd->split, gnc_recn_cell_get_flag (cell));
}
Ejemplo n.º 8
0
static void
gnc_split_register_save_memo_cell (BasicCell * cell,
                                   gpointer save_data,
                                   gpointer user_data)
{
    SRSaveData *sd = save_data;
    const char *value;

    g_return_if_fail (gnc_basic_cell_has_name (cell, MEMO_CELL));

    value = gnc_basic_cell_get_value (cell);

    DEBUG ("MEMO: %s", value ? value : "(null)");

    xaccSplitSetMemo (sd->split, value);
}
Ejemplo n.º 9
0
static void
gnc_split_register_save_notes_cell (BasicCell * cell,
                                    gpointer save_data,
                                    gpointer user_data)
{
    SRSaveData *sd = save_data;
    const char *value;

    g_return_if_fail (gnc_basic_cell_has_name (cell, NOTES_CELL));

    value = gnc_basic_cell_get_value (cell);

    DEBUG ("NOTES: %s", value ? value : "(null)");

    xaccTransSetNotes (sd->trans, value);
}
Ejemplo n.º 10
0
static void
gnc_split_register_save_mxfrm_cell (BasicCell * cell,
                                    gpointer save_data,
                                    gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    Split * other_split;

    g_return_if_fail (gnc_basic_cell_has_name (cell, MXFRM_CELL));

    other_split = xaccSplitGetOtherSplit (sd->split);

    /* other_split may be null for two very different reasons:
     * (1) the parent transaction has three or more splits in it,
     *     and so the "other" split is ambiguous, and thus null.
     * (2) the parent transaction has only this one split as a child.
     *     and "other" is null because there is no other.
     *
     * In the case (2), we want to create the other split, so that
     * the user's request to transfer actually works out. */

    if (!other_split)
    {
        other_split = xaccTransGetSplit (sd->trans, 1);

        if (!other_split)
        {
            other_split = xaccMallocSplit (gnc_get_current_book ());
            xaccTransAppendSplit (sd->trans, other_split);
        }
    }

    if (other_split)
    {
        Account *old_acc;
        Account *new_acc;

        /* Do some reparenting. Insertion into new account
         * will automatically delete from the old account. */
        old_acc = xaccSplitGetAccount (other_split);
        new_acc = gnc_split_register_get_account (reg, MXFRM_CELL);

        if ((new_acc != NULL) && (old_acc != new_acc))
            xaccAccountInsertSplit (new_acc, other_split);
    }
}
Ejemplo n.º 11
0
static void
gnc_split_register_save_actn_cell (BasicCell * cell,
                                   gpointer save_data,
                                   gpointer user_data)
{
    SRSaveData *sd = save_data;
    const char *value;

    g_return_if_fail (gnc_basic_cell_has_name (cell, ACTN_CELL));

    value = gnc_basic_cell_get_value (cell);

    DEBUG ("ACTN: %s", value ? value : "(null)");

    /* Set split-action with gnc_set_num_action which is the same as
     * xaccSplitSetAction with these arguments */
    gnc_set_num_action (NULL, sd->split, NULL, value);
}
Ejemplo n.º 12
0
static void
gnc_split_register_save_tnum_cell (BasicCell * cell,
                                  gpointer save_data,
                                  gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    const char *value;

    g_return_if_fail (gnc_basic_cell_has_name (cell, TNUM_CELL));

    value = gnc_basic_cell_get_value (cell);

    DEBUG ("TNUM: %s\n", value ? value : "(null)");

    /* set tran-num using utility function */
    gnc_set_num_action (sd->trans, NULL, value, NULL);
}
Ejemplo n.º 13
0
gboolean
gnc_table_get_cell_location (Table *table,
                             const char *cell_name,
                             VirtualCellLocation vcell_loc,
                             VirtualLocation *virt_loc)
{
    VirtualCell *vcell;
    CellBlock *cellblock;
    int cell_row, cell_col;

    if (table == NULL)
        return FALSE;

    vcell = gnc_table_get_virtual_cell (table, vcell_loc);
    if (vcell == NULL)
        return FALSE;

    cellblock = vcell->cellblock;

    for (cell_row = 0; cell_row < cellblock->num_rows; cell_row++)
        for (cell_col = 0; cell_col < cellblock->num_cols; cell_col++)
        {
            BasicCell *cell;

            cell = gnc_cellblock_get_cell (cellblock, cell_row, cell_col);
            if (!cell)
                continue;

            if (gnc_basic_cell_has_name (cell, cell_name))
            {
                if (virt_loc != NULL)
                {
                    virt_loc->vcell_loc = vcell_loc;

                    virt_loc->phys_row_offset = cell_row;
                    virt_loc->phys_col_offset = cell_col;
                }

                return TRUE;
            }
        }

    return FALSE;
}
Ejemplo n.º 14
0
static void
gnc_split_register_save_shares_cell (BasicCell * bcell,
                                     gpointer save_data,
                                     gpointer user_data)
{
    SRSaveData *sd = save_data;
    PriceCell *cell = (PriceCell *) bcell;
    gnc_numeric amount;

    g_return_if_fail (gnc_basic_cell_has_name (bcell, SHRS_CELL));

    amount = gnc_price_cell_get_value (cell);

    DEBUG ("SHRS");

    xaccSplitSetAmount (sd->split, amount);

    sd->do_scrub = TRUE;
}
Ejemplo n.º 15
0
/* OK, the handling of transfers gets complicated because it depends
 * on what was displayed to the user. For a multi-line display, we
 * just reparent the indicated split. For a two-line display, we want
 * to reparent the "other" split, but only if there is one. XFRM is
 * the straight split, MXFRM is the mirrored split. */
static void
gnc_split_register_save_xfrm_cell (BasicCell * cell,
                                   gpointer save_data,
                                   gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    Account *old_acc;
    Account *new_acc;

    g_return_if_fail (gnc_basic_cell_has_name (cell, XFRM_CELL));

    old_acc = xaccSplitGetAccount (sd->split);

    new_acc = gnc_split_register_get_account (reg, XFRM_CELL);

    if ((new_acc != NULL) && (old_acc != new_acc))
        xaccAccountInsertSplit (new_acc, sd->split);
}
Ejemplo n.º 16
0
static void
gnc_template_register_save_shares_cell (BasicCell * cell,
                                        gpointer save_data,
                                        gpointer user_data)
{
    SRSaveData *sd = save_data;
    char *sharesStr = "(x + y)/42";

    g_return_if_fail (gnc_basic_cell_has_name (cell, SHRS_CELL));
    /* FIXME: shares cells are numeric by definition. */
    qof_instance_set (QOF_INSTANCE (sd->split),
		      "sx-shares", sharesStr,
		      NULL);

    /* 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.º 17
0
static void
gnc_split_register_save_price_cell (BasicCell * bcell,
                                    gpointer save_data,
                                    gpointer user_data)
{
    SRSaveData *sd = save_data;
    PriceCell *cell = (PriceCell *) bcell;
    gnc_numeric price;

    g_return_if_fail (gnc_basic_cell_has_name (bcell, PRIC_CELL));

    price = gnc_price_cell_get_value (cell);

    DEBUG ("PRIC");

    /* If we handled the Debcred cell then don't set the share price! */
    if (!sd->handled_dc)
        xaccSplitSetSharePrice (sd->split, price);

    sd->do_scrub = TRUE;
}
Ejemplo n.º 18
0
static void
gnc_split_register_save_due_date_cell (BasicCell * cell,
                                       gpointer save_data,
                                       gpointer user_data)
{
    SRSaveData *sd = save_data;
    const char *value;
    Timespec ts;

    g_return_if_fail (gnc_basic_cell_has_name (cell, DDUE_CELL));

    value = gnc_basic_cell_get_value (cell);

    /* commit any pending changes */
    gnc_date_cell_commit ((DateCell *) cell);

    DEBUG ("DATE: %s", value ? value : "(null)");

    gnc_date_cell_get_date ((DateCell *) cell, &ts);

    xaccTransSetDateDueTS (sd->trans, &ts);
}
Ejemplo n.º 19
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;
}