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;
}
void
tax_table_delete_entry_cb (GtkButton *button, TaxTableWindow *ttw)
{
    g_return_if_fail (ttw);
    if (!ttw->current_table || !ttw->current_entry)
        return;

    if (g_list_length (gncTaxTableGetEntries (ttw->current_table)) <= 1)
    {
        char *message = _("You cannot remove the last entry from the tax table. "
                          "Try deleting the tax table if you want to do that.");
        gnc_error_dialog (ttw->dialog, "%s", message);
        return;
    }

    if (gnc_verify_dialog (ttw->dialog, FALSE, "%s",
                           _("Are you sure you want to delete this entry?")))
    {
        /* Ok, let's remove it */
        gnc_suspend_gui_refresh ();
        gncTaxTableBeginEdit (ttw->current_table);
        gncTaxTableRemoveEntry (ttw->current_table, ttw->current_entry);
        gncTaxTableEntryDestroy (ttw->current_entry);
        gncTaxTableChanged (ttw->current_table);
        gncTaxTableCommitEdit (ttw->current_table);
        ttw->current_entry = NULL;
        gnc_resume_gui_refresh ();
    }
}
示例#3
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableChanged (GncTaxTable *table)
{
    if (!table) return;
    gncTaxTableBeginEdit (table);
    table->child = NULL;
    gncTaxTableCommitEdit (table);
}
示例#4
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableSetName (GncTaxTable *table, const char *name)
{
    if (!table || !name) return;
    SET_STR (table, table->name, name);
    mark_table (table);
    maybe_resort_list (table);
    gncTaxTableCommitEdit (table);
}
示例#5
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child)
{
    if (!table) return;
    gncTaxTableBeginEdit (table);
    table->child = child;
    mark_table (table);
    gncTaxTableCommitEdit (table);
}
示例#6
0
文件: gncTaxTable.c 项目: mlq/gnucash
void
gncTaxTableDestroy (GncTaxTable *table)
{
    if (!table) return;
    qof_instance_set_destroying(table, TRUE);
    qof_instance_set_dirty (&table->inst);
    gncTaxTableCommitEdit (table);
}
示例#7
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount)
{
    if (!table) return;
    g_return_if_fail (refcount >= 0);
    gncTaxTableBeginEdit (table);
    table->refcount = refcount;
    mark_table (table);
    gncTaxTableCommitEdit (table);
}
示例#8
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableIncRef (GncTaxTable *table)
{
    if (!table) return;
    if (table->parent || table->invisible) return;        /* children dont need refcounts */
    gncTaxTableBeginEdit (table);
    table->refcount++;
    mark_table (table);
    gncTaxTableCommitEdit (table);
}
示例#9
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableMakeInvisible (GncTaxTable *table)
{
    struct _book_info *bi;
    if (!table) return;
    gncTaxTableBeginEdit (table);
    table->invisible = TRUE;
    bi = qof_book_get_data (qof_instance_get_book(table), _GNC_MOD_NAME);
    bi->tables = g_list_remove (bi->tables, table);
    gncTaxTableCommitEdit (table);
}
示例#10
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableDecRef (GncTaxTable *table)
{
    if (!table) return;
    if (table->parent || table->invisible) return;        /* children dont need refcounts */
    g_return_if_fail (table->refcount > 0);
    gncTaxTableBeginEdit (table);
    table->refcount--;
    mark_table (table);
    gncTaxTableCommitEdit (table);
}
示例#11
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableRemoveEntry (GncTaxTable *table, GncTaxTableEntry *entry)
{
    if (!table || !entry) return;
    gncTaxTableBeginEdit (table);
    entry->table = NULL;
    table->entries = g_list_remove (table->entries, entry);
    mark_table (table);
    mod_table (table);
    gncTaxTableCommitEdit (table);
}
示例#12
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableSetParent (GncTaxTable *table, GncTaxTable *parent)
{
    if (!table) return;
    gncTaxTableBeginEdit (table);
    if (table->parent)
        gncTaxTableRemoveChild(table->parent, table);
    table->parent = parent;
    if (parent)
        gncTaxTableAddChild(parent, table);
    table->refcount = 0;
    gncTaxTableMakeInvisible (table);
    mark_table (table);
    gncTaxTableCommitEdit (table);
}
示例#13
0
文件: gncTaxTable.c 项目: mlq/gnucash
void gncTaxTableAddEntry (GncTaxTable *table, GncTaxTableEntry *entry)
{
    if (!table || !entry) return;
    if (entry->table == table) return; /* already mine */

    gncTaxTableBeginEdit (table);
    if (entry->table)
        gncTaxTableRemoveEntry (entry->table, entry);

    entry->table = table;
    table->entries = g_list_insert_sorted (table->entries, entry,
                                           (GCompareFunc)gncTaxTableEntryCompare);
    mark_table (table);
    mod_table (table);
    gncTaxTableCommitEdit (table);
}
示例#14
0
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;
}
示例#15
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;
}
示例#16
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;
}
示例#17
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;
}