void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child) { if (!term) return; gncBillTermBeginEdit (term); term->child = child; gncBillTermCommitEdit (term); }
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; }
static gboolean billterm_guid_handler (xmlNodePtr node, gpointer billterm_pdata) { struct billterm_pdata *pdata = billterm_pdata; GncGUID *guid; GncBillTerm *term; guid = dom_tree_to_guid(node); g_return_val_if_fail (guid, FALSE); term = gncBillTermLookup (pdata->book, guid); if (term) { gncBillTermDestroy (pdata->term); pdata->term = term; gncBillTermBeginEdit (term); } else { gncBillTermSetGUID(pdata->term, guid); } g_free(guid); return TRUE; }
void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount) { if (!term) return; gncBillTermBeginEdit (term); term->refcount = refcount; mark_term (term); gncBillTermCommitEdit (term); }
void gncBillTermMakeInvisible (GncBillTerm *term) { if (!term) return; gncBillTermBeginEdit (term); term->invisible = TRUE; remObj (term); gncBillTermCommitEdit (term); }
void gncBillTermIncRef (GncBillTerm *term) { if (!term) return; if (term->parent || term->invisible) return; /* children dont need refcounts */ gncBillTermBeginEdit (term); term->refcount++; gncBillTermCommitEdit (term); }
void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff) { if (!term) return; if (term->cutoff == cutoff) return; gncBillTermBeginEdit (term); term->cutoff = cutoff; mark_term (term); gncBillTermCommitEdit (term); }
void gncBillTermSetDiscount (GncBillTerm *term, gnc_numeric discount) { if (!term) return; if (gnc_numeric_eq (term->discount, discount)) return; gncBillTermBeginEdit (term); term->discount = discount; mark_term (term); gncBillTermCommitEdit (term); }
void gncBillTermSetType (GncBillTerm *term, GncBillTermType type) { if (!term) return; if (term->type == type) return; gncBillTermBeginEdit (term); term->type = type; mark_term (term); gncBillTermCommitEdit (term); }
void gncBillTermDecRef (GncBillTerm *term) { if (!term) return; if (term->parent || term->invisible) return; /* children dont need refcounts */ gncBillTermBeginEdit (term); term->refcount--; g_return_if_fail (term->refcount >= 0); gncBillTermCommitEdit (term); }
void gncBillTermSetDiscountDays (GncBillTerm *term, gint days) { if (!term) return; if (term->disc_days == days) return; gncBillTermBeginEdit (term); term->disc_days = days; mark_term (term); gncBillTermCommitEdit (term); }
/* XXX this doesn't seem right. If the parent/child relationship * is a doubly-linked list, then there shouldn't be separate set-parent, * set-child routines, else misuse of the routines will goof up * relationships. These ops should be atomic, I think. */ void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent) { if (!term) return; gncBillTermBeginEdit (term); if (term->parent) gncBillTermRemoveChild(term->parent, term); term->parent = parent; if (parent) gncBillTermAddChild(parent, term); term->refcount = 0; if ( parent != NULL ) { gncBillTermMakeInvisible (term); } gncBillTermCommitEdit (term); }
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; }
static void billterm_scrub (QofBook *book) { GList *list = NULL; GList *node; GncBillTerm *parent, *term; GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); DEBUG("scrubbing billterms..."); qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht); qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht); qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht); qof_object_foreach (GNC_ID_BILLTERM, book, billterm_scrub_cb, &list); /* destroy the list of "grandchildren" bill terms */ for (node = list; node; node = node->next) { gchar termstr[GUID_ENCODING_LENGTH+1]; term = node->data; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)), termstr); PWARN ("deleting grandchild billterm: %s\n", termstr); /* Make sure the parent has no children */ parent = gncBillTermGetParent(term); gncBillTermSetChild(parent, NULL); /* Destroy this bill term */ gncBillTermBeginEdit(term); gncBillTermDestroy(term); } /* reset the refcounts as necessary */ g_hash_table_foreach(ht, billterm_reset_refcount, NULL); g_list_free(list); g_hash_table_destroy(ht); }
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; }
/* build a list of bill terms that are grandchildren or bogus (empty entry list). */ static void billterm_scrub_cb (QofInstance *term_p, gpointer list_p) { GncBillTerm *term = GNC_BILLTERM(term_p); GList **list = list_p; if (billterm_is_grandchild(term)) { *list = g_list_prepend(*list, term); } else if (!gncBillTermGetType(term)) { GncBillTerm *t = gncBillTermGetParent(term); if (t) { /* Fix up the broken "copy" function */ gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),guidstr); PWARN("Fixing broken child billterm: %s", guidstr); gncBillTermBeginEdit(term); gncBillTermSetType(term, gncBillTermGetType(t)); gncBillTermSetDueDays (term, gncBillTermGetDueDays(t)); gncBillTermSetDiscountDays (term, gncBillTermGetDiscountDays(t)); gncBillTermSetDiscount (term, gncBillTermGetDiscount(t)); gncBillTermSetCutoff (term, gncBillTermGetCutoff(t)); gncBillTermCommitEdit(term); } else { /* No parent? Must be a standalone */ *list = g_list_prepend(*list, term); } } }