示例#1
0
static GncBillTerm*
dom_tree_to_billterm (xmlNodePtr node, QofBook *book)
{
    struct billterm_pdata billterm_pdata;
    gboolean successful;

    billterm_pdata.term = gncBillTermCreate (book);
    billterm_pdata.book = book;
    gncBillTermBeginEdit (billterm_pdata.term);

    successful = dom_tree_generic_parse (node, billterm_handlers_v2,
                                         &billterm_pdata);

    if (successful)
    {
        gncBillTermCommitEdit (billterm_pdata.term);
    }
    else
    {
        PERR ("failed to parse billing term tree");
        gncBillTermDestroy (billterm_pdata.term);
        billterm_pdata.term = NULL;
    }

    return billterm_pdata.term;
}
示例#2
0
static GncBillTerm*
load_single_billterm (GncSqlBackend* sql_be, GncSqlRow& row,
                      BillTermParentGuidVec& l_billterms_needing_parents)
{
    g_return_val_if_fail (sql_be != NULL, NULL);

    auto guid = gnc_sql_load_guid (sql_be, row);
    auto pBillTerm = gncBillTermLookup (sql_be->book(), guid);
    if (pBillTerm == nullptr)
    {
        pBillTerm = gncBillTermCreate (sql_be->book());
    }
    gnc_sql_load_object (sql_be, row, GNC_ID_BILLTERM, pBillTerm, col_table);

    /* If the billterm doesn't have a parent, it might be because it hasn't been
       loaded yet.  If so, add this billterm to the list of billterms with no
       parent, along with the parent GncGUID so that after they are all loaded,
       the parents can be fixed up. */
    if (gncBillTermGetParent (pBillTerm) == NULL)
    {
        BillTermParentGuid s;

        s.billterm = pBillTerm;
        s.have_guid = false;
        gnc_sql_load_object (sql_be, row, GNC_ID_TAXTABLE, &s,
                             billterm_parent_col_table);
        if (s.have_guid)
            l_billterms_needing_parents.push_back(new BillTermParentGuid(s));

    }

    qof_instance_mark_clean (QOF_INSTANCE (pBillTerm));

    return pBillTerm;
}
示例#3
0
static GncBillTerm*
load_single_billterm (GncSqlBackend* be, GncSqlRow* row,
                      GList** l_billterms_needing_parents)
{
    const GncGUID* guid;
    GncBillTerm* pBillTerm;

    g_return_val_if_fail (be != NULL, NULL);
    g_return_val_if_fail (row != NULL, NULL);

    guid = gnc_sql_load_guid (be, row);
    pBillTerm = gncBillTermLookup (be->book, guid);
    if (pBillTerm == NULL)
    {
        pBillTerm = gncBillTermCreate (be->book);
    }
    gnc_sql_load_object (be, row, GNC_ID_BILLTERM, pBillTerm, col_table);

    /* If the billterm doesn't have a parent, it might be because it hasn't been loaded yet.
       If so, add this billterm to the list of billterms with no parent, along with the parent
       GncGUID so that after they are all loaded, the parents can be fixed up. */
    if (gncBillTermGetParent (pBillTerm) == NULL)
    {
        billterm_parent_guid_struct* s = static_cast<decltype (s)> (
                                             g_malloc (sizeof (billterm_parent_guid_struct)));
        g_assert (s != NULL);

        s->billterm = pBillTerm;
        s->have_guid = FALSE;
        gnc_sql_load_object (be, row, GNC_ID_TAXTABLE, s, billterm_parent_col_table);
        if (s->have_guid)
        {
            *l_billterms_needing_parents = g_list_prepend (*l_billterms_needing_parents,
                                                           s);
        }
        else
        {
            g_free (s);
        }
    }

    qof_instance_mark_clean (QOF_INSTANCE (pBillTerm));

    return pBillTerm;
}
示例#4
0
static GncBillTerm *gncBillTermCopy (const GncBillTerm *term)
{
    GncBillTerm *t;

    if (!term) return NULL;
    t = gncBillTermCreate (qof_instance_get_book(term));

    gncBillTermBeginEdit(t);

    gncBillTermSetName (t, term->name);
    gncBillTermSetDescription (t, term->desc);

    t->type = term->type;
    t->due_days = term->due_days;
    t->disc_days = term->disc_days;
    t->discount = term->discount;
    t->cutoff = term->cutoff;

    gncBillTermCommitEdit(t);

    return t;
}
GncBillTerm *
gnc_billterm_xml_find_or_create(QofBook *book, GncGUID *guid)
{
    GncBillTerm *term;

    g_return_val_if_fail(book, NULL);
    g_return_val_if_fail(guid, NULL);
    term = gncBillTermLookup(book, guid);
    DEBUG("looking for billterm %s, found %p", guid_to_string(guid), term);
    if (!term)
    {
        term = gncBillTermCreate(book);
        gncBillTermBeginEdit(term);
        gncBillTermSetGUID(term, guid);
        gncBillTermCommitEdit(term);
        DEBUG("Created term: %p", term);
    }
    else
        gncBillTermDecRef(term);

    return term;
}
示例#6
0
static gboolean
set_parent_child (xmlNodePtr node, struct billterm_pdata *pdata,
                  void (*func)(GncBillTerm *, GncBillTerm *))
{
    GncGUID *guid;
    GncBillTerm *term;

    guid = dom_tree_to_guid(node);
    g_return_val_if_fail (guid, FALSE);
    term = gncBillTermLookup (pdata->book, guid);
    if (!term)
    {
        term = gncBillTermCreate (pdata->book);
        gncBillTermBeginEdit (term);
        gncBillTermSetGUID (term, guid);
        gncBillTermCommitEdit (term);
    }
    g_free (guid);
    g_return_val_if_fail (term, FALSE);
    func (pdata->term, term);

    return TRUE;
}