void
tax_table_delete_table_cb (GtkButton *button, TaxTableWindow *ttw)
{
    g_return_if_fail (ttw);

    if (!ttw->current_table)
        return;

    if (gncTaxTableGetRefcount (ttw->current_table) > 0)
    {
        char *message =
            g_strdup_printf (_("Tax table \"%s\" is in use.  You cannot delete it."),
                             gncTaxTableGetName (ttw->current_table));
        gnc_error_dialog (ttw->dialog, "%s", message);
        g_free (message);
        return;
    }

    if (gnc_verify_dialog (ttw->dialog, FALSE,
                           _("Are you sure you want to delete \"%s\"?"),
                           gncTaxTableGetName (ttw->current_table)))
    {
        /* Ok, let's remove it */
        gnc_suspend_gui_refresh ();
        gncTaxTableBeginEdit (ttw->current_table);
        gncTaxTableDestroy (ttw->current_table);
        ttw->current_table = NULL;
        ttw->current_entry = NULL;
        gnc_resume_gui_refresh ();
    }
}
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 ();
    }
}
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;
}
static gboolean
taxtable_guid_handler (xmlNodePtr node, gpointer taxtable_pdata)
{
    struct taxtable_pdata *pdata = taxtable_pdata;
    GncGUID *guid;
    GncTaxTable *table;

    guid = dom_tree_to_guid(node);
    g_return_val_if_fail (guid, FALSE);
    table = gncTaxTableLookup (pdata->book, guid);
    if (table)
    {
        gncTaxTableDestroy (pdata->table);
        pdata->table = table;
        gncTaxTableBeginEdit (table);
    }
    else
    {
        gncTaxTableSetGUID(pdata->table, guid);
    }

    g_free(guid);

    return TRUE;
}
Exemple #5
0
void gncTaxTableChanged (GncTaxTable *table)
{
    if (!table) return;
    gncTaxTableBeginEdit (table);
    table->child = NULL;
    gncTaxTableCommitEdit (table);
}
Exemple #6
0
void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child)
{
    if (!table) return;
    gncTaxTableBeginEdit (table);
    table->child = child;
    mark_table (table);
    gncTaxTableCommitEdit (table);
}
Exemple #7
0
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);
}
Exemple #8
0
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);
}
Exemple #9
0
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);
}
Exemple #10
0
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);
}
Exemple #11
0
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);
}
Exemple #12
0
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);
}
Exemple #13
0
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);
}
static void
taxtable_scrub (QofBook *book)
{
    GList *list = NULL;
    GList *node;
    GncTaxTable *parent, *table;
    GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);

    qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht);
    qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht);
    qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht);
    qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list);

    /* destroy the list of "grandchildren" tax tables */
    for (node = list; node; node = node->next)
    {
        gchar guidstr[GUID_ENCODING_LENGTH+1];
        table = static_cast<decltype(table)>(node->data);

        guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr);
        PINFO ("deleting grandchild taxtable: %s\n", guidstr);

        /* Make sure the parent has no children */
        parent = gncTaxTableGetParent(table);
        gncTaxTableSetChild(parent, NULL);

        /* Destroy this tax table */
        gncTaxTableBeginEdit(table);
        gncTaxTableDestroy(table);
    }

    /* reset the refcounts as necessary */
    g_hash_table_foreach(ht, taxtable_reset_refcount, NULL);

    g_list_free(list);
    g_hash_table_destroy(ht);
}
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;
}
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;
}
Exemple #17
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;
}
Exemple #18
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;
}
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;
}