示例#1
0
GList*
gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct)
{
    GList *rtn = NULL;
    const GncGUID *acct_guid = qof_entity_get_guid(QOF_INSTANCE(acct));
    GList *sx_list;
    SchedXactions *sxactions = gnc_book_get_schedxactions(book);
    g_return_val_if_fail( sxactions != NULL, rtn);
    for (sx_list = sxactions->sx_list; sx_list != NULL; sx_list = sx_list->next)
    {
        SchedXaction *sx = (SchedXaction*)sx_list->data;
        GList *splits = xaccSchedXactionGetSplits(sx);
        for (; splits != NULL; splits = splits->next)
        {
            Split *s = (Split*)splits->data;
            GncGUID *guid = NULL;
            qof_instance_get (QOF_INSTANCE (s), "sx-account", &guid, NULL);
            if (guid_equal(acct_guid, guid))
            {
                rtn = g_list_append(rtn, sx);
            }
        }
    }
    return rtn;
}
示例#2
0
static void
sxftd_ok_clicked(SXFromTransInfo *sxfti)
{
    QofBook *book;
    SchedXactions *sxes;
    guint sx_error = sxftd_compute_sx(sxfti);

    if (sx_error != 0
            && sx_error != SXFTD_ERRNO_UNBALANCED_XACTION)
    {
        g_critical("sxftd_compute_sx after ok_clicked [%d]", sx_error);
    }
    else
    {
        if ( sx_error == SXFTD_ERRNO_UNBALANCED_XACTION )
        {
            gnc_error_dialog( gnc_ui_get_toplevel(), "%s",
                              _( "The Scheduled Transaction is unbalanced. "
                                 "You are strongly encouraged to correct this situation." ) );
        }
        book = gnc_get_current_book ();
        sxes = gnc_book_get_schedxactions(book);
        gnc_sxes_add_sx(sxes, sxfti->sx);
    }

    sxftd_close(sxfti, FALSE);
    return;
}
void
GncSqlSchedXactionBackend::load_all (GncSqlBackend* sql_be)
{
    g_return_if_fail (sql_be != NULL);

    std::stringstream sql;
    sql << "SELECT * FROM " << SCHEDXACTION_TABLE;
    auto stmt = sql_be->create_statement_from_sql(sql.str());
    if (stmt == NULL) return;
    auto result = sql_be->execute_select_statement(stmt);
    SchedXactions* sxes;
    InstanceVec instances;
    sxes = gnc_book_get_schedxactions (sql_be->book());

    for (auto row : *result)
    {
        SchedXaction* sx;

        sx = load_single_sx (sql_be, row);
        if (sx != nullptr)
        {
            gnc_sxes_add_sx (sxes, sx);
            instances.push_back(QOF_INSTANCE(sx));
        }
    }

    if (!instances.empty())
        gnc_sql_slots_load_for_instancevec (sql_be, instances);
}
static void
_destroy_sx(gpointer data, gpointer user_data)
{
    SchedXactions *sxes;
    SchedXaction *sx = (SchedXaction*)data;
    QofBook *book;
    book = gnc_get_current_book();
    sxes = gnc_book_get_schedxactions(book);
    gnc_sxes_del_sx(sxes, sx);
    gnc_sx_begin_edit(sx);
    xaccSchedXactionDestroy(sx);
}
示例#5
0
xmlNodePtr
gnc_book_dom_tree_create(QofBook *book)
{
    xmlNodePtr ret;
    G_GNUC_UNUSED gboolean allow_incompat = TRUE;

    ret = xmlNewNode(NULL, BAD_CAST gnc_book_string);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST gnc_v2_book_version_string);

    xmlAddChild(ret, guid_to_dom_tree(book_id_string,
                                      qof_book_get_guid(book)));

    if (qof_instance_get_slots (QOF_INSTANCE (book)))
    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree(book_slots_string,
                             qof_instance_get_slots (QOF_INSTANCE (book)));
        if (kvpnode)
            xmlAddChild(ret, kvpnode);
    }

#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
    /* theoretically, we should be adding all the below to the book
     * but in fact, there's enough brain damage in the code already
     * that we are only going to hand-edit the file at a higher layer.
     * And that's OK, since its probably a performance boost anyway.
     */
    xmlAddChild(ret, gnc_commodity_dom_tree_create(
                    gnc_commodity_table_get_table(book)));
    xmlAddChild(ret, gnc_pricedb_dom_tree_create(gnc_pricedb_get_db(book)));
    if (allow_incompat)
    {
        accnode = gnc_account_dom_tree_create(account, FALSE);
        xmlAddChild (ret, rootAccNode);
    }
    append_account_tree (ret, gnc_book_get_root(book));

    xaccAccountTreeForEachTransaction (gnc_book_get_root_account(book),
                                       traverse_txns, ret);

    /* xxx FIXME hack alert how are we going to handle
     *  gnc_book_get_template_group handled ???   */
    xmlAddChild(ret, gnc_schedXaction_dom_tree_create(
                    gnc_book_get_schedxactions(book)));

#endif

    return ret;
}
示例#6
0
bool
GncSqlBackend::write_schedXactions()
{
    GList* schedXactions;
    SchedXaction* tmpSX;
    bool is_ok = true;

    schedXactions = gnc_book_get_schedxactions (m_book)->sx_list;
    auto obe = m_backend_registry.get_object_backend(GNC_ID_SCHEDXACTION);

    for (; schedXactions != NULL && is_ok; schedXactions = schedXactions->next)
    {
        tmpSX = static_cast<decltype (tmpSX)> (schedXactions->data);
        is_ok = obe->commit (this, QOF_INSTANCE (tmpSX));
    }
    update_progress();

    return is_ok;
}
示例#7
0
GList*
gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct)
{
    GList *rtn = NULL;
    const GncGUID *acct_guid = qof_entity_get_guid(QOF_INSTANCE(acct));
    GList *sx_list = gnc_book_get_schedxactions(book)->sx_list;
    for (; sx_list != NULL; sx_list = sx_list->next)
    {
        SchedXaction *sx = (SchedXaction*)sx_list->data;
        GList *splits = xaccSchedXactionGetSplits(sx);
        for (; splits != NULL; splits = splits->next)
        {
            Split *s = (Split*)splits->data;
            KvpFrame *frame = kvp_frame_get_frame(xaccSplitGetSlots(s), GNC_SX_ID);
            GncGUID *sx_split_acct_guid = kvp_frame_get_guid(frame, GNC_SX_ACCOUNT);
            if (guid_equal(acct_guid, sx_split_acct_guid))
            {
                rtn = g_list_append(rtn, sx);
            }
        }
    }
    return rtn;
}
示例#8
0
GncSxInstanceModel*
gnc_sx_get_instances(GDate *range_end, gboolean include_disabled)
{
    GList *all_sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
    GncSxInstanceModel *instances;

    g_assert(range_end != NULL);
    g_assert(g_date_valid(range_end));

    instances = gnc_sx_instance_model_new();
    instances->include_disabled = include_disabled;
    instances->range_end = *range_end;

    if (include_disabled)
    {
        instances->sx_instance_list = gnc_g_list_map(all_sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
    }
    else
    {
        GList *sx_iter = g_list_first(all_sxes);
        GList *enabled_sxes = NULL;

        for (; sx_iter != NULL; sx_iter = sx_iter->next)
        {
            SchedXaction *sx = (SchedXaction*)sx_iter->data;
            if (xaccSchedXactionGetEnabled(sx))
            {
                enabled_sxes = g_list_append(enabled_sxes, sx);
            }
        }
        instances->sx_instance_list = gnc_g_list_map(enabled_sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
        g_list_free(enabled_sxes);
    }

    return instances;
}
示例#9
0
static void
_gnc_sx_instance_event_handler(QofInstance *ent, QofEventId event_type, gpointer user_data, gpointer evt_data)
{
    GncSxInstanceModel *instances = GNC_SX_INSTANCE_MODEL(user_data);

    /* selection rules {
    //   (gnc_collection_get_schedxaction_list(book), GNC_EVENT_ITEM_ADDED)
    //   (gnc_collection_get_schedxaction_list(book), GNC_EVENT_ITEM_REMOVED)
    //   (GNC_IS_SX(ent), QOF_EVENT_MODIFIED)
    // } */
    if (!(GNC_IS_SX(ent) || GNC_IS_SXES(ent)))
        return;

    if (GNC_IS_SX(ent))
    {
        SchedXaction *sx;
        gboolean sx_is_in_model = FALSE;

        sx = GNC_SX(ent);
        // only send `updated` if it's actually in the model
        sx_is_in_model = (g_list_find_custom(instances->sx_instance_list, sx, (GCompareFunc)_gnc_sx_instance_find_by_sx) != NULL);
        if (event_type & QOF_EVENT_MODIFY)
        {
            if (sx_is_in_model)
            {
                if (instances->include_disabled || xaccSchedXactionGetEnabled(sx))
                {
                    g_signal_emit_by_name(instances, "updated", (gpointer)sx);
                }
                else
                {
                    /* the sx was enabled but is now disabled */
                    g_signal_emit_by_name(instances, "removing", (gpointer)sx);
                }
            }
            else
            {
                /* determine if this is a legitimate SX or just a "one-off" / being created */
                GList *all_sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
                if (g_list_find(all_sxes, sx) && (!instances->include_disabled && xaccSchedXactionGetEnabled(sx)))
                {
                    /* it's moved from disabled to enabled, add the instances */
                    instances->sx_instance_list
                    = g_list_append(instances->sx_instance_list,
                                    _gnc_sx_gen_instances((gpointer)sx, (gpointer) & instances->range_end));
                    g_signal_emit_by_name(instances, "added", (gpointer)sx);
                }
            }
        }
        /* else { unsupported event type; ignore } */
    }
    else if (GNC_IS_SXES(ent))
    {
        SchedXactions *sxes = GNC_SXES(ent);
        SchedXaction *sx = GNC_SX(evt_data);

        sxes = NULL;
        if (event_type & GNC_EVENT_ITEM_REMOVED)
        {
            GList *instances_link;
            instances_link = g_list_find_custom(instances->sx_instance_list, sx, (GCompareFunc)_gnc_sx_instance_find_by_sx);
            if (instances_link != NULL)
            {
                g_signal_emit_by_name(instances, "removing", (gpointer)sx);
            }
            else if (instances->include_disabled)
            {
                g_warning("could not remove instances that do not exist in the model");
            }
        }
        else if (event_type & GNC_EVENT_ITEM_ADDED)
        {
            if (instances->include_disabled || xaccSchedXactionGetEnabled(sx))
            {
                /* generate instances, add to instance list, emit update. */
                instances->sx_instance_list
                = g_list_append(instances->sx_instance_list,
                                _gnc_sx_gen_instances((gpointer)sx, (gpointer) & instances->range_end));
                g_signal_emit_by_name(instances, "added", (gpointer)sx);
            }
        }
        /* else { g_critical("unsupported event type [%d]\n", event_type); } */
    }
}