gboolean gnc_stock_split_assistant_cash_complete (GtkAssistant *assistant, gpointer user_data) { StockSplitInfo *info = user_data; gnc_numeric amount; gint result; Account *account; result = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT (info->cash_edit), &amount, TRUE); if (result == -1) return TRUE; /* Optional field is empty */ else if ( result > 0) return FALSE; /* Parsing error */ else if (gnc_numeric_negative_p (amount)) return FALSE; /* Negative cash amount is not allowed */ /* We have a positive cash amount */ account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->income_tree)); if (!account) return FALSE; account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->asset_tree)); if (!account) return FALSE; return TRUE; }
static void balance_cell_edited (GtkCellRendererText *cell, gchar *path, gchar *new_text, gpointer user_data) { Account *account; char *error_loc; gnc_numeric amount; hierarchy_data *data = (hierarchy_data *)user_data; g_return_if_fail(data != NULL); account = gnc_tree_view_account_get_selected_account(data->final_account_tree); if (account == NULL) { g_critical("account is null"); return; } error_loc = NULL; if (!gnc_exp_parser_parse (new_text, &amount, &error_loc)) { amount = gnc_numeric_zero(); g_object_set (G_OBJECT(cell), "text", "", NULL); } /* Bug#348364: Emulating price-cell, we need to ensure the denominator of * the amount is in the SCU of the account's commodity (so * gnc-ui-util.c:is_decimal_fraction() on the remainder denom for * fractional values will be a "decimal"). */ { int account_cmdty_fraction = xaccAccountGetCommoditySCU(account); amount = gnc_numeric_convert(amount, account_cmdty_fraction, GNC_HOW_RND_ROUND_HALF_UP); } set_final_balance (data->balance_hash, account, amount); qof_event_gen (QOF_INSTANCE(account), QOF_EVENT_MODIFY, NULL); }
void gnc_stock_split_assistant_finish (GtkAssistant *assistant, gpointer user_data) { StockSplitInfo *info = user_data; GList *account_commits; GList *node; gnc_numeric amount; Transaction *trans; Account *account; Split *split; time64 date; account = info->acct; g_return_if_fail (account != NULL); amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->distribution_edit)); g_return_if_fail (!gnc_numeric_zero_p (amount)); gnc_suspend_gui_refresh (); trans = xaccMallocTransaction (gnc_get_current_book ()); xaccTransBeginEdit (trans); xaccTransSetCurrency (trans, gnc_default_currency ()); date = gnc_date_edit_get_date (GNC_DATE_EDIT (info->date_edit)); xaccTransSetDatePostedSecsNormalized (trans, date); { const char *description; description = gtk_entry_get_text (GTK_ENTRY (info->description_entry)); xaccTransSetDescription (trans, description); } split = xaccMallocSplit (gnc_get_current_book ()); xaccAccountBeginEdit (account); account_commits = g_list_prepend (NULL, account); xaccTransAppendSplit (trans, split); xaccAccountInsertSplit (account, split); xaccSplitSetAmount (split, amount); xaccSplitMakeStockSplit (split); /* Set split-action with gnc_set_num_action which is the same as * xaccSplitSetAction with these arguments */ /* Translators: This string has a disambiguation prefix */ gnc_set_num_action (NULL, split, NULL, Q_("Action Column|Split")); amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->price_edit)); if (gnc_numeric_positive_p (amount)) { QofBook *book; GNCPrice *price; GNCPriceDB *pdb; GNCCurrencyEdit *ce; Timespec ts; ce = GNC_CURRENCY_EDIT (info->price_currency_edit); ts.tv_sec = date; ts.tv_nsec = 0; price = gnc_price_create (gnc_get_current_book ()); gnc_price_begin_edit (price); gnc_price_set_commodity (price, xaccAccountGetCommodity (account)); gnc_price_set_currency (price, gnc_currency_edit_get_currency (ce)); gnc_price_set_time (price, ts); gnc_price_set_source (price, PRICE_SOURCE_STOCK_SPLIT); gnc_price_set_typestr (price, PRICE_TYPE_UNK); gnc_price_set_value (price, amount); gnc_price_commit_edit (price); book = gnc_get_current_book (); pdb = gnc_pricedb_get_db (book); if (!gnc_pricedb_add_price (pdb, price)) gnc_error_dialog (info->window, "%s", _("Error adding price.")); } amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->cash_edit)); if (gnc_numeric_positive_p (amount)) { const char *memo; memo = gtk_entry_get_text (GTK_ENTRY (info->memo_entry)); /* asset split */ account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->asset_tree)); split = xaccMallocSplit (gnc_get_current_book ()); xaccAccountBeginEdit (account); account_commits = g_list_prepend (account_commits, account); xaccAccountInsertSplit (account, split); xaccTransAppendSplit (trans, split); xaccSplitSetAmount (split, amount); xaccSplitSetValue (split, amount); xaccSplitSetMemo (split, memo); /* income split */ account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(info->income_tree)); split = xaccMallocSplit (gnc_get_current_book ()); xaccAccountBeginEdit (account); account_commits = g_list_prepend (account_commits, account); xaccAccountInsertSplit (account, split); xaccTransAppendSplit (trans, split); xaccSplitSetAmount (split, gnc_numeric_neg (amount)); xaccSplitSetValue (split, gnc_numeric_neg (amount)); xaccSplitSetMemo (split, memo); } xaccTransCommitEdit (trans); for (node = account_commits; node; node = node->next) xaccAccountCommitEdit (node->data); g_list_free (account_commits); gnc_resume_gui_refresh (); gnc_close_gui_component_by_data (ASSISTANT_STOCK_SPLIT_CM_CLASS, info); }
static gboolean gnc_payment_window_check_payment (PaymentWindow *pw) { const char *conflict_msg = NULL; Account *post, *acc; gnc_numeric amount_deb, amount_cred; gboolean enable_xfer_acct = TRUE; GtkTreeSelection *selection; if (!pw) return FALSE; /* Verify the "post" account */ if (!pw->post_acct) { conflict_msg = _("You must enter a valid account name for posting."); goto update_cleanup; } /* Verify the user has selected an owner */ gnc_owner_get_owner (pw->owner_choice, &(pw->owner)); if (!gncOwnerIsValid(&pw->owner)) { conflict_msg = _("You must select a company for payment processing."); goto update_cleanup; } /* Test the total amount */ amount_deb = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (pw->amount_debit_edit)); amount_cred = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (pw->amount_credit_edit)); pw->amount_tot = gnc_numeric_sub (amount_cred, amount_deb, gnc_commodity_get_fraction (xaccAccountGetCommodity (pw->post_acct)), GNC_HOW_RND_ROUND_HALF_UP); if (gnc_numeric_check (pw->amount_tot) || gnc_numeric_zero_p (pw->amount_tot)) { enable_xfer_acct = FALSE; } else { /* Verify the user has selected a transfer account */ pw->xfer_acct = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(pw->acct_tree)); if (!pw->xfer_acct) { conflict_msg = _("You must select a transfer account from the account tree."); } } update_cleanup: gtk_widget_set_sensitive (pw->acct_tree, enable_xfer_acct); /* Check if there are issues preventing a successful payment */ gtk_widget_set_tooltip_text (pw->payment_warning, conflict_msg); if (conflict_msg) { gtk_widget_show (pw->payment_warning); gtk_widget_set_sensitive (pw->ok_button, FALSE); return FALSE; } else { gtk_widget_hide (pw->payment_warning); gtk_widget_set_sensitive (pw->ok_button, TRUE); } 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; }