static gboolean taxtable_entries_handler (xmlNodePtr node, gpointer taxtable_pdata) { struct taxtable_pdata *pdata = taxtable_pdata; xmlNodePtr mark; g_return_val_if_fail (node, FALSE); g_return_val_if_fail (node->xmlChildrenNode, FALSE); for (mark = node->xmlChildrenNode; mark; mark = mark->next) { GncTaxTableEntry *entry; if (g_strcmp0 ("text", (char*)mark->name) == 0) continue; if (g_strcmp0 (gnc_taxtableentry_string, (char*)mark->name)) return FALSE; entry = dom_tree_to_ttentry (mark, pdata->book); if (entry) gncTaxTableAddEntry (pdata->table, entry); else return FALSE; } return TRUE; }
static void load_single_ttentry (GncSqlBackend* sql_be, GncSqlRow& row, GncTaxTable* tt) { GncTaxTableEntry* e = gncTaxTableEntryCreate (); g_return_if_fail (sql_be != NULL); g_return_if_fail (tt != NULL); gnc_sql_load_object (sql_be, row, GNC_ID_TAXTABLE, e, ttentries_col_table); gncTaxTableAddEntry (tt, e); }
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; }
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; }