static gboolean
set_parent_child (xmlNodePtr node, struct taxtable_pdata *pdata,
                  void (*func)(GncTaxTable *, GncTaxTable *))
{
    GncGUID *guid;
    GncTaxTable *table;

    guid = dom_tree_to_guid(node);
    g_return_val_if_fail (guid, FALSE);
    table = gncTaxTableLookup (pdata->book, guid);

    /* Ignore pointers to self */
    if (table == pdata->table)
    {
        PINFO ("found a self-referential parent/child; ignoring.\n");
        return TRUE;
    }

    if (!table)
    {
        table = gncTaxTableCreate (pdata->book);
        gncTaxTableBeginEdit (table);
        gncTaxTableSetGUID (table, guid);
        gncTaxTableCommitEdit (table);
    }
    g_free (guid);
    g_return_val_if_fail (table, FALSE);
    func (pdata->table, table);

    return TRUE;
}
示例#2
0
文件: gncTaxTable.c 项目: mlq/gnucash
static GncTaxTable *gncTaxTableCopy (const GncTaxTable *table)
{
    GncTaxTable *t;
    GList *list;

    if (!table) return NULL;
    t = gncTaxTableCreate (qof_instance_get_book(table));
    gncTaxTableSetName (t, table->name);
    for (list = table->entries; list; list = list->next)
    {
        GncTaxTableEntry *entry, *e;
        entry = list->data;
        e = gncTaxTableEntryCopy (entry);
        gncTaxTableAddEntry (t, e);
    }
    return t;
}
示例#3
0
static void
load_single_taxtable( GncSqlBackend* be, GncSqlRow* row,
                      GList** l_tt_needing_parents )
{
    const GncGUID* guid;
    GncTaxTable* tt;

    g_return_if_fail( be != NULL );
    g_return_if_fail( row != NULL );

    guid = gnc_sql_load_guid( be, row );
    tt = gncTaxTableLookup( be->book, guid );
    if ( tt == NULL )
    {
        tt = gncTaxTableCreate( be->book );
    }
    gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, tt, tt_col_table );
    gnc_sql_slots_load( be, QOF_INSTANCE(tt) );
    load_taxtable_entries( be, tt );

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

        s->tt = tt;
        s->have_guid = FALSE;
        gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, tt_parent_col_table );
        if ( s->have_guid )
        {
            *l_tt_needing_parents = g_list_prepend( *l_tt_needing_parents, s );
        }
        else
        {
            g_free( s );
        }
    }

    qof_instance_mark_clean( QOF_INSTANCE(tt) );
}
示例#4
0
static void
load_single_taxtable (GncSqlBackend* sql_be, GncSqlRow& row,
                      TaxTblParentGuidVec& l_tt_needing_parents)
{
    const GncGUID* guid;
    GncTaxTable* tt;

    g_return_if_fail (sql_be != NULL);

    guid = gnc_sql_load_guid (sql_be, row);
    tt = gncTaxTableLookup (sql_be->book(), guid);
    if (tt == nullptr)
    {
        tt = gncTaxTableCreate (sql_be->book());
    }
    gnc_sql_load_object (sql_be, row, GNC_ID_TAXTABLE, tt, tt_col_table);
    gnc_sql_slots_load (sql_be, QOF_INSTANCE (tt));
    load_taxtable_entries (sql_be, tt);

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

        s.tt = tt;
        s.have_guid = false;
        gnc_sql_load_object (sql_be, row, GNC_ID_TAXTABLE, &s,
                             tt_parent_col_table);
        if (s.have_guid)
            l_tt_needing_parents.push_back(new TaxTblParentGuid(s));

    }

    qof_instance_mark_clean (QOF_INSTANCE (tt));
}
static GncTaxTable*
dom_tree_to_taxtable (xmlNodePtr node, QofBook *book)
{
    struct taxtable_pdata taxtable_pdata;
    gboolean successful;

    taxtable_pdata.table = gncTaxTableCreate (book);
    taxtable_pdata.book = book;
    gncTaxTableBeginEdit (taxtable_pdata.table);

    successful = dom_tree_generic_parse (node, taxtable_handlers_v2,
                                         &taxtable_pdata);

    if (successful)
        gncTaxTableCommitEdit (taxtable_pdata.table);
    else
    {
        PERR ("failed to parse tax table tree");
        gncTaxTableDestroy (taxtable_pdata.table);
        taxtable_pdata.table = NULL;
    }

    return taxtable_pdata.table;
}
示例#6
0
static inline gboolean
set_taxtable (xmlNodePtr node, struct entry_pdata *pdata,
              void (*func)(GncEntry *entry, GncTaxTable *taxtable))
{
    GncGUID *guid;
    GncTaxTable *taxtable;

    guid = dom_tree_to_guid (node);
    g_return_val_if_fail (guid, FALSE);
    taxtable = gncTaxTableLookup (pdata->book, guid);
    if (!taxtable)
    {
        taxtable = gncTaxTableCreate (pdata->book);
        gncTaxTableBeginEdit (taxtable);
        gncTaxTableSetGUID (taxtable, guid);
        gncTaxTableCommitEdit (taxtable);
    }
    else
        gncTaxTableDecRef (taxtable);

    func (pdata->entry, taxtable);
    g_free(guid);
    return TRUE;
}
示例#7
0
static gboolean
customer_taxtable_handler (xmlNodePtr node, gpointer cust_pdata)
{
    struct customer_pdata *pdata = cust_pdata;
    GncGUID *guid;
    GncTaxTable *taxtable;

    guid = dom_tree_to_guid (node);
    g_return_val_if_fail (guid, FALSE);
    taxtable = gncTaxTableLookup (pdata->book, guid);
    if (!taxtable)
    {
        taxtable = gncTaxTableCreate (pdata->book);
        gncTaxTableBeginEdit (taxtable);
        gncTaxTableSetGUID (taxtable, guid);
        gncTaxTableCommitEdit (taxtable);
    }
    else
        gncTaxTableDecRef (taxtable);

    gncCustomerSetTaxTable (pdata->customer, taxtable);
    g_free(guid);
    return TRUE;
}
示例#8
0
static gboolean
vendor_taxtable_handler (xmlNodePtr node, gpointer vendor_pdata)
{
    struct vendor_pdata* pdata = static_cast<decltype (pdata)> (vendor_pdata);
    GncGUID* guid;
    GncTaxTable* taxtable;

    guid = dom_tree_to_guid (node);
    g_return_val_if_fail (guid, FALSE);
    taxtable = gncTaxTableLookup (pdata->book, guid);
    if (!taxtable)
    {
        taxtable = gncTaxTableCreate (pdata->book);
        gncTaxTableBeginEdit (taxtable);
        gncTaxTableSetGUID (taxtable, guid);
        gncTaxTableCommitEdit (taxtable);
    }
    else
        gncTaxTableDecRef (taxtable);

    gncVendorSetTaxTable (pdata->vendor, taxtable);
    g_free (guid);
    return TRUE;
}
static gboolean
new_tax_table_ok_cb (NewTaxTable *ntt)
{
    TaxTableWindow *ttw;
    const char *name = NULL;
    char *message;
    Account *acc;
    gnc_numeric amount;

    g_return_val_if_fail (ntt, FALSE);
    ttw = ntt->ttw;

    /* Verify that we've got real, valid data */

    /* verify the name, maybe */
    if (ntt->new_table)
    {
        name = gtk_entry_get_text (GTK_ENTRY (ntt->name_entry));
        if (name == NULL || *name == '\0')
        {
            message = _("You must provide a name for this Tax Table.");
            gnc_error_dialog (ntt->dialog, "%s", message);
            return FALSE;
        }
        if (gncTaxTableLookupByName (ttw->book, name))
        {
            message = g_strdup_printf(_(
                                          "You must provide a unique name for this Tax Table. "
                                          "Your choice \"%s\" is already in use."), name);
            gnc_error_dialog (ntt->dialog, "%s", message);
            g_free (message);
            return FALSE;
        }
    }

    /* verify the amount. Note that negative values are allowed (required for European tax rules) */
    amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (ntt->amount_entry));
    if (ntt->type == GNC_AMT_TYPE_PERCENT &&
            gnc_numeric_compare (gnc_numeric_abs (amount),
                                 gnc_numeric_create (100, 1)) > 0)
    {
        message = _("Percentage amount must be between -100 and 100.");
        gnc_error_dialog (ntt->dialog, "%s", message);
        return FALSE;
    }

    /* verify the account */
    acc = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(ntt->acct_tree));
    if (acc == NULL)
    {
        message = _("You must choose a Tax Account.");
        gnc_error_dialog (ntt->dialog, "%s", message);
        return FALSE;
    }

    gnc_suspend_gui_refresh ();

    /* Ok, it's all valid, now either change to add this thing */
    if (ntt->new_table)
    {
        GncTaxTable *table = gncTaxTableCreate (ttw->book);
        gncTaxTableBeginEdit (table);
        gncTaxTableSetName (table, name);
        /* Reset the current table */
        ttw->current_table = table;
        ntt->created_table = table;
    }
    else
        gncTaxTableBeginEdit (ttw->current_table);

    /* Create/edit the entry */
    {
        GncTaxTableEntry *entry;

        if (ntt->entry)
        {
            entry = ntt->entry;
        }
        else
        {
            entry = gncTaxTableEntryCreate ();
            gncTaxTableAddEntry (ttw->current_table, entry);
            ttw->current_entry = entry;
        }

        gncTaxTableEntrySetAccount (entry, acc);
        gncTaxTableEntrySetType (entry, ntt->type);
        gncTaxTableEntrySetAmount (entry, amount);
    }

    /* Mark the table as changed and commit it */
    gncTaxTableChanged (ttw->current_table);
    gncTaxTableCommitEdit (ttw->current_table);

    gnc_resume_gui_refresh();
    return TRUE;
}