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; }
void gnc_ui_payment_window_set_xferaccount (PaymentWindow *pw, const Account* account) { g_assert(pw); g_assert(account); gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree), (Account*)account); }
/******************************************************* * show_acct_type_accounts * * show required accounts in account tree *******************************************************/ static void show_acct_type_accounts (CsvExportInfo *info) { GncTreeViewAccount *tree; AccountViewInfo Viewinfo; GNCAccountType type; tree = GNC_TREE_VIEW_ACCOUNT (info->csva.account_treeview); gnc_tree_view_account_get_view_info (tree, &Viewinfo); for (type = 0; type < NUM_ACCOUNT_TYPES; type++) /* from Account.h */ { Viewinfo.include_type[type] = ((type == ACCT_TYPE_BANK) || (type == ACCT_TYPE_CASH) || (type == ACCT_TYPE_CREDIT) || (type == ACCT_TYPE_ASSET) || (type == ACCT_TYPE_LIABILITY) || (type == ACCT_TYPE_STOCK) || (type == ACCT_TYPE_MUTUAL) || (type == ACCT_TYPE_INCOME) || (type == ACCT_TYPE_EXPENSE) || (type == ACCT_TYPE_EQUITY) || (type == ACCT_TYPE_RECEIVABLE)|| (type == ACCT_TYPE_PAYABLE) || (type == ACCT_TYPE_ROOT) || (type == ACCT_TYPE_TRADING)); } gnc_tree_view_account_set_view_info (tree, &Viewinfo); csv_export_cursor_changed_cb (GTK_WIDGET(tree), info); }
static void gnc_payment_dialog_owner_changed (PaymentWindow *pw) { Account *last_acct = NULL; GncGUID *guid = NULL; GncOwner *owner = &pw->owner; /* If the owner changed, the initial invoice is no longer valid */ pw->invoice = NULL; /* Now handle the account tree */ qof_instance_get (qofOwnerGetOwner (owner), "payment-last-account", &guid, NULL); /* refresh the post and acc available accounts, but cleanup first */ if (pw->acct_types) { g_list_free(pw->acct_types); pw->acct_types = NULL; } if (pw->acct_commodities) { g_list_free(pw->acct_commodities); pw->acct_commodities = NULL; } pw->acct_types = gncOwnerGetAccountTypesList(owner); if (gncOwnerIsValid(owner)) pw->acct_commodities = gncOwnerGetCommoditiesList (owner); pw->post_acct = gnc_account_select_combo_fill (pw->post_combo, pw->book, pw->acct_types, pw->acct_commodities); /* Update list of documents and pre-payments */ gnc_payment_window_fill_docs_list (pw); if (guid) { last_acct = xaccAccountLookup(guid, pw->book); } /* Set the last-used transfer account, but only if we didn't * create this dialog from a pre-existing transaction. */ if (last_acct && !gnc_payment_dialog_has_pre_existing_txn(pw)) { gnc_tree_view_account_set_selected_account(GNC_TREE_VIEW_ACCOUNT(pw->acct_tree), last_acct); } }
/******************************************************* * csv_export_select_subaccounts_clicked_cb * * select all the sub accounts *******************************************************/ static void csv_export_select_subaccounts_clicked_cb (GtkWidget *widget, gpointer user_data) { CsvExportInfo *info = user_data; GncTreeViewAccount *account_tree; Account *account; account_tree = GNC_TREE_VIEW_ACCOUNT (info->csva.account_treeview); account = gnc_tree_view_account_get_cursor_account (account_tree); if (!account) return; gnc_tree_view_account_select_subaccounts (account_tree, account); gtk_widget_grab_focus (info->csva.account_treeview); }
/******************************************************* * csv_export_cursor_changed_cb * * call back for cursor selection in account tree *******************************************************/ static void csv_export_cursor_changed_cb (GtkWidget *widget, gpointer user_data) { CsvExportInfo *info = user_data; GncTreeViewAccount *account_tree; Account *account; gint num_children; account_tree = GNC_TREE_VIEW_ACCOUNT (info->csva.account_treeview); account = gnc_tree_view_account_get_cursor_account (account_tree); if (!account) { gtk_widget_set_sensitive (info->csva.select_button, FALSE); return; } num_children = gnc_tree_view_account_count_children (account_tree, account); gtk_widget_set_sensitive (info->csva.select_button, num_children > 0); }
/******************************************************* * update_accounts_tree * * update the account tree *******************************************************/ static int update_accounts_tree (CsvExportInfo *info) { GncTreeViewAccount *tree; GtkTreeSelection* selection; GtkWidget *label; int num_accounts; char *string; tree = GNC_TREE_VIEW_ACCOUNT(info->csva.account_treeview); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree)); num_accounts = gtk_tree_selection_count_selected_rows (selection); label = info->csva.num_acct_label; string = g_strdup_printf ("%d", num_accounts); gtk_label_set_text (GTK_LABEL (label), string); g_free (string); return num_accounts; }
/******************************************************* * csv_export_account_changed_cb * * update account list after selection changed *******************************************************/ static void csv_export_account_changed_cb (GtkTreeSelection *selection, gpointer user_data) { CsvExportInfo *info = user_data; GtkAssistant *assistant = GTK_ASSISTANT(info->window); gint num = gtk_assistant_get_current_page (assistant); GtkWidget *page = gtk_assistant_get_nth_page (assistant, num); GncTreeViewAccount *view; g_return_if_fail(GTK_IS_TREE_SELECTION(selection)); info->csva.num_accounts = update_accounts_tree (info); /* Enable the Forward Assistant Button if we have accounts */ if (info->csva.num_accounts > 0) gtk_assistant_set_page_complete (assistant, page, TRUE); else gtk_assistant_set_page_complete (assistant, page, FALSE); view = GNC_TREE_VIEW_ACCOUNT(info->csva.account_treeview); info->csva.account_list = gnc_tree_view_account_get_selected_accounts (view); }
void on_final_account_prepare (hierarchy_data *data) { GSList *actlist; GtkTreeView *tree_view; GtkTreeSelection *selection; GtkCellRenderer *renderer; GtkTreeViewColumn *column; gnc_commodity *com; /* Anything to do? */ if (!data->category_set_changed) return; data->category_set_changed = FALSE; gnc_suspend_gui_refresh (); /* Delete any existing account tree */ if (data->final_account_tree) { gtk_widget_destroy(GTK_WIDGET(data->final_account_tree)); data->final_account_tree = NULL; } delete_our_account_tree (data); /* Build a new account list */ actlist = get_selected_account_list (data->categories_tree); com = gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT(data->currency_selector)); data->our_account_tree = hierarchy_merge_accounts (actlist, com); /* Now build a new account tree */ data->final_account_tree = GNC_TREE_VIEW_ACCOUNT(gnc_tree_view_account_new_with_root (data->our_account_tree, FALSE)); tree_view = GTK_TREE_VIEW(data->final_account_tree); gnc_tree_view_account_set_name_edited(data->final_account_tree, gnc_tree_view_account_name_edited_cb); gnc_tree_view_account_set_code_edited(data->final_account_tree, gnc_tree_view_account_code_edited_cb); gnc_tree_view_account_set_description_edited(data->final_account_tree, gnc_tree_view_account_description_edited_cb); gnc_tree_view_account_set_notes_edited(data->final_account_tree, gnc_tree_view_account_notes_edited_cb); gtk_tree_view_set_headers_visible (tree_view, TRUE); column = gnc_tree_view_find_column_by_name ( GNC_TREE_VIEW(data->final_account_tree), "type"); g_object_set_data(G_OBJECT(column), DEFAULT_VISIBLE, GINT_TO_POINTER(1)); gnc_tree_view_configure_columns (GNC_TREE_VIEW(data->final_account_tree)); gnc_tree_view_set_show_column_menu (GNC_TREE_VIEW(data->final_account_tree), FALSE); selection = gtk_tree_view_get_selection (tree_view); gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); // This is a re-definition of the placeholder that the account-tree model // provides, reflecting the to-be-created state of the account tree // post-merge. { renderer = gtk_cell_renderer_toggle_new(); g_object_set(G_OBJECT (renderer), "activatable", FALSE, "sensitive", FALSE, NULL); column = gtk_tree_view_column_new_with_attributes(_("Placeholder"), renderer, NULL); gtk_tree_view_column_set_cell_data_func (column, renderer, placeholder_cell_data_func, (gpointer)data, NULL); gnc_tree_view_append_column (GNC_TREE_VIEW(tree_view), column); } { renderer = gtk_cell_renderer_text_new (); g_object_set (G_OBJECT (renderer), "xalign", 1.0, (char *)NULL); g_signal_connect (G_OBJECT (renderer), "edited", G_CALLBACK (balance_cell_edited), data); column = gtk_tree_view_column_new_with_attributes (_("Opening Balance"), renderer, NULL); gtk_tree_view_column_set_cell_data_func (column, renderer, balance_cell_data_func, (gpointer)data, NULL); gnc_tree_view_append_column (GNC_TREE_VIEW(tree_view), column); } // only in the case where there *are* existing accounts... if (gnc_account_n_descendants(gnc_book_get_root_account(gnc_get_current_book())) > 0) { GList *renderers; column = gnc_tree_view_add_text_column(GNC_TREE_VIEW(tree_view), _("Use Existing"), NULL, NULL, "yes", GNC_TREE_VIEW_COLUMN_DATA_NONE, GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS, NULL); renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column)); g_object_set(G_OBJECT(renderer), "xalign", 1.0, (char*)NULL); gtk_tree_view_column_set_cell_data_func(column, GTK_CELL_RENDERER(renderers->data), use_existing_account_data_func, (gpointer)data, NULL); g_list_free(renderers); } gtk_container_add(GTK_CONTAINER(data->final_account_tree_container), GTK_WIDGET(data->final_account_tree)); /* Expand the entire tree */ gtk_tree_view_expand_all (tree_view); gtk_widget_show(GTK_WIDGET(data->final_account_tree)); gnc_resume_gui_refresh (); }
static GtkWidget * gnc_stock_split_assistant_create (StockSplitInfo *info) { GtkBuilder *builder; GtkWidget *window; builder = gtk_builder_new(); gnc_builder_add_from_file (builder , "assistant-stock-split.glade", "stock_split_assistant"); window = GTK_WIDGET(gtk_builder_get_object (builder, "stock_split_assistant")); info->window = window; // Set the style context for this assistant so it can be easily manipulated with css gnc_widget_set_style_context (GTK_WIDGET(window), "GncAssistStockSplit"); /* Enable buttons on first, second, fourth and last page. */ gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "intro_page_label")), TRUE); gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "stock_account_page")), TRUE); gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "stock_cash_page")), TRUE); gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "finish_page_label")), TRUE); /* Account page Widgets */ { GtkTreeView *view; GtkListStore *store; GtkTreeSelection *selection; GtkCellRenderer *renderer; GtkTreeViewColumn *column; info->account_view = GTK_WIDGET(gtk_builder_get_object(builder, "account_view")); view = GTK_TREE_VIEW(info->account_view); // Set grid lines option to preference gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(view), gnc_tree_view_get_grid_lines_pref ()); store = gtk_list_store_new(NUM_SPLIT_COLS, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); gtk_tree_view_set_model(view, GTK_TREE_MODEL(store)); g_object_unref(store); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Account"), renderer, "text", SPLIT_COL_FULLNAME, NULL); gtk_tree_view_append_column(view, column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Symbol"), renderer, "text", SPLIT_COL_MNEMONIC, NULL); gtk_tree_view_append_column(view, column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(_("Shares"), renderer, "text", SPLIT_COL_SHARES, NULL); gtk_tree_view_append_column(view, column); selection = gtk_tree_view_get_selection(view); gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); g_signal_connect (selection, "changed", G_CALLBACK (selection_changed_cb), info); } /* Details Page Widgets */ { GtkWidget *table; GtkWidget *amount; GtkWidget *date; GtkWidget *label; table = GTK_WIDGET(gtk_builder_get_object(builder, "stock_details_table")); info->description_entry = GTK_WIDGET(gtk_builder_get_object(builder, "description_entry")); date = gnc_date_edit_new (gnc_time (NULL), FALSE, FALSE); gtk_grid_attach (GTK_GRID(table), date, 1, 0, 1, 1); gtk_widget_show (date); info->date_edit = date; label = GTK_WIDGET(gtk_builder_get_object(builder, "date_label")); gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date), label); amount = gnc_amount_edit_new (); g_signal_connect (amount, "changed", G_CALLBACK (gnc_stock_split_details_valid_cb), info); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount), TRUE); gtk_grid_attach (GTK_GRID(table), amount, 1, 1, 1, 1); gtk_widget_show (amount); info->distribution_edit = amount; label = GTK_WIDGET(gtk_builder_get_object(builder, "distribution_label")); gtk_label_set_mnemonic_widget(GTK_LABEL(label), amount); amount = gnc_amount_edit_new (); gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (amount), gnc_default_price_print_info ()); g_signal_connect (amount, "changed", G_CALLBACK (gnc_stock_split_details_valid_cb), info); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount), TRUE); gtk_grid_attach (GTK_GRID(table), amount, 1, 5, 1, 1); gtk_widget_show (amount); info->price_edit = amount; label = GTK_WIDGET(gtk_builder_get_object(builder, "price_label")); gtk_label_set_mnemonic_widget(GTK_LABEL(label), amount); info->price_currency_edit = gnc_currency_edit_new(); gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(info->price_currency_edit), gnc_default_currency()); gtk_widget_show (info->price_currency_edit); gtk_grid_attach (GTK_GRID(table), info->price_currency_edit, 1, 6, 1, 1); } /* Cash page Widgets */ { GtkWidget *box; GtkWidget *tree; GtkWidget *amount; GtkWidget *label; GtkWidget *scroll; GtkTreeSelection *selection; box = GTK_WIDGET(gtk_builder_get_object(builder, "cash_box")); amount = gnc_amount_edit_new (); g_signal_connect (amount, "changed", G_CALLBACK (gnc_stock_split_cash_valid_cb), info); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount), TRUE); gtk_box_pack_start (GTK_BOX (box), amount, TRUE, TRUE, 0); info->cash_edit = amount; label = GTK_WIDGET(gtk_builder_get_object(builder, "cash_label")); gtk_label_set_mnemonic_widget(GTK_LABEL(label), amount); info->memo_entry = GTK_WIDGET(gtk_builder_get_object(builder, "memo_entry")); /* income tree */ tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE)); info->income_tree = tree; gnc_tree_view_account_set_filter (GNC_TREE_VIEW_ACCOUNT (tree), gnc_stock_split_assistant_view_filter_income, NULL, /* user data */ NULL /* destroy callback */); gtk_widget_show (tree); gtk_tree_view_expand_all (GTK_TREE_VIEW(tree)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree)); gtk_tree_selection_unselect_all (selection); g_signal_connect (selection, "changed", G_CALLBACK (gnc_stock_split_cash_valid_cb), info); label = GTK_WIDGET(gtk_builder_get_object(builder, "income_label")); gtk_label_set_mnemonic_widget (GTK_LABEL(label), tree); scroll = GTK_WIDGET(gtk_builder_get_object(builder, "income_scroll")); gtk_container_add (GTK_CONTAINER (scroll), tree); /* asset tree */ tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE)); info->asset_tree = tree; gnc_tree_view_account_set_filter (GNC_TREE_VIEW_ACCOUNT (tree), gnc_stock_split_assistant_view_filter_asset, NULL /* user data */, NULL /* destroy callback */); gtk_widget_show (tree); label = GTK_WIDGET(gtk_builder_get_object(builder, "asset_label")); gtk_label_set_mnemonic_widget (GTK_LABEL(label), tree); scroll = GTK_WIDGET(gtk_builder_get_object(builder, "asset_scroll")); gtk_container_add (GTK_CONTAINER (scroll), tree); gtk_tree_view_expand_all (GTK_TREE_VIEW(tree)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree)); gtk_tree_selection_unselect_all (selection); g_signal_connect (selection, "changed", G_CALLBACK (gnc_stock_split_cash_valid_cb), info); } g_signal_connect (G_OBJECT(window), "destroy", G_CALLBACK (gnc_stock_split_assistant_window_destroy_cb), info); gtk_builder_connect_signals(builder, info); g_object_unref(G_OBJECT(builder)); return window; }
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 PaymentWindow * new_payment_window (GncOwner *owner, QofBook *book, GncInvoice *invoice) { PaymentWindow *pw; GtkBuilder *builder; GtkWidget *box, *label, *credit_box, *debit_box; GtkTreeSelection *selection; GtkTreeViewColumn *column; GtkCellRenderer *renderer; char * cm_class = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER ? DIALOG_PAYMENT_CUSTOMER_CM_CLASS : DIALOG_PAYMENT_VENDOR_CM_CLASS); /* * Find an existing payment window. If found, bring it to * the front. If we have an actual owner, then set it in * the window. */ pw = gnc_find_first_gui_component (cm_class, find_handler, NULL); if (pw) { if (gncOwnerIsValid(owner)) gnc_payment_set_owner (pw, owner); // Reset the setting about the pre-existing TXN pw->pre_existing_txn = NULL; gtk_window_present (GTK_WINDOW(pw->dialog)); return(pw); } /* Ok, we need a new window */ pw = g_new0 (PaymentWindow, 1); pw->book = book; gncOwnerCopy (owner, &(pw->owner)); /* Compute the post-to account types */ pw->acct_types = gncOwnerGetAccountTypesList (owner); if (gncOwnerIsValid(owner)) pw->acct_commodities = gncOwnerGetCommoditiesList (owner); /* Open and read the Glade File */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-payment.glade", "docs_list_hor_adj"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "docs_list_vert_adj"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "docs_list_model"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "post_combo_model"); gnc_builder_add_from_file (builder, "dialog-payment.glade", "Payment Dialog"); pw->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "Payment Dialog")); /* Grab the widgets and build the dialog */ pw->payment_warning = GTK_WIDGET (gtk_builder_get_object (builder, "payment_warning")); pw->ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "okbutton")); pw->num_entry = GTK_WIDGET (gtk_builder_get_object (builder, "num_entry")); pw->memo_entry = GTK_WIDGET (gtk_builder_get_object (builder, "memo_entry")); pw->post_combo = GTK_WIDGET (gtk_builder_get_object (builder, "post_combo")); gtk_combo_box_set_entry_text_column( GTK_COMBO_BOX( pw->post_combo ), 0 ); gnc_cbwe_require_list_item(GTK_COMBO_BOX(pw->post_combo)); label = GTK_WIDGET (gtk_builder_get_object (builder, "owner_label")); box = GTK_WIDGET (gtk_builder_get_object (builder, "owner_box")); pw->owner_choice = gnc_owner_select_create (label, box, book, owner); /* Some terminology: * Invoices are paid, credit notes are refunded. * A customer payment is a credit action, paying a vendor is debit * * So depending on the owner the payment amount should be considered * credit (customer) or debit (vendor/employee) and refunds should be * considered debit (customer) or credit (vendor/employee). * For visual consistency, the dialog box will always show a payment and * a refund field. Internally they are treated as credit or debit depending * on the owner type. */ if (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER) { debit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_refund_box")); credit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_payment_box")); } else { debit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_payment_box")); credit_box = GTK_WIDGET (gtk_builder_get_object (builder, "amount_refund_box")); } pw->amount_debit_edit = gnc_amount_edit_new (); gtk_box_pack_start (GTK_BOX (debit_box), pw->amount_debit_edit, TRUE, TRUE, 0); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (pw->amount_debit_edit), TRUE); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_debit_edit), gnc_numeric_zero()); g_signal_connect(G_OBJECT(gnc_amount_edit_gtk_entry(GNC_AMOUNT_EDIT(pw->amount_debit_edit))), "focus-out-event", G_CALLBACK(gnc_payment_leave_amount_cb), pw); pw->amount_credit_edit = gnc_amount_edit_new (); gtk_box_pack_start (GTK_BOX (credit_box), pw->amount_credit_edit, TRUE, TRUE, 0); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (pw->amount_credit_edit), TRUE); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pw->amount_credit_edit), gnc_numeric_zero()); g_signal_connect(G_OBJECT(gnc_amount_edit_gtk_entry(GNC_AMOUNT_EDIT(pw->amount_credit_edit))), "focus-out-event", G_CALLBACK(gnc_payment_leave_amount_cb), pw); box = GTK_WIDGET (gtk_builder_get_object (builder, "date_box")); pw->date_edit = gnc_date_edit_new (time(NULL), FALSE, FALSE); gtk_box_pack_start (GTK_BOX (box), pw->date_edit, TRUE, TRUE, 0); pw->docs_list_tree_view = GTK_WIDGET (gtk_builder_get_object (builder, "docs_list_tree_view")); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(pw->docs_list_tree_view)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); /* Configure date column */ renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 0); gtk_tree_view_column_pack_start (column, renderer, TRUE); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "31-12-2013"); gtk_tree_view_column_set_cell_data_func (column, renderer, (GtkTreeCellDataFunc) print_date, NULL, NULL); /* Configure document number column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 1); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "INV2013-016"); /* Configure document type column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 2); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, _("Credit Note")); /* Configure debit column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 3); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "11,999.00"); /* Configure credit column */ column = gtk_tree_view_get_column (GTK_TREE_VIEW (pw->docs_list_tree_view), 4); tree_view_column_set_default_width (GTK_TREE_VIEW (pw->docs_list_tree_view), column, "11,999.00"); gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (pw->docs_list_tree_view))), 0, GTK_SORT_ASCENDING); box = GTK_WIDGET (gtk_builder_get_object (builder, "acct_window")); pw->acct_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE)); gtk_container_add (GTK_CONTAINER (box), pw->acct_tree); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(pw->acct_tree), FALSE); gnc_payment_set_account_types (GNC_TREE_VIEW_ACCOUNT (pw->acct_tree)); /* Set the dialog for the 'new' owner. * Note that this also sets the post account tree. */ gnc_payment_dialog_owner_changed(pw); /* Set the dialog for the 'new' invoice */ pw->invoice = invoice; if (invoice) { Account *postacct = gncInvoiceGetPostedAcc (invoice); if (postacct) { gchar *acct_string = gnc_account_get_full_name (postacct); gnc_cbwe_set_by_string(GTK_COMBO_BOX(pw->post_combo), acct_string); gnc_payment_dialog_post_to_changed_cb (pw->post_combo, pw); g_free(acct_string); } } /* Setup signals */ gtk_builder_connect_signals_full( builder, gnc_builder_connect_full_func, pw); g_signal_connect (G_OBJECT (pw->owner_choice), "changed", G_CALLBACK (gnc_payment_dialog_owner_changed_cb), pw); g_signal_connect (G_OBJECT (pw->acct_tree), "row-activated", G_CALLBACK (gnc_payment_acct_tree_row_activated_cb), pw); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(pw->acct_tree)); g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (gnc_payment_dialog_xfer_acct_changed_cb), pw); /* Register with the component manager */ pw->component_id = gnc_register_gui_component (cm_class, gnc_payment_window_refresh_handler, gnc_payment_window_close_handler, pw); /* Watch for any new or changed accounts */ gnc_gui_component_watch_entity_type (pw->component_id, GNC_ID_ACCOUNT, QOF_EVENT_CREATE | QOF_EVENT_MODIFY | QOF_EVENT_DESTROY); /* Show it all */ gtk_widget_show_all (pw->dialog); g_object_unref(G_OBJECT(builder)); // The customer choice widget should have keyboard focus if (GNC_IS_GENERAL_SEARCH(pw->owner_choice)) { gnc_general_search_grab_focus(GNC_GENERAL_SEARCH(pw->owner_choice)); } /* Reflect if the payment could complete now */ gnc_payment_window_check_payment (pw); /* Warn the user if they have no valid post-to accounts */ { const gchar *text; const char *acct_type; text = gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(pw->post_combo))))); if (!text || g_strcmp0 (text, "") == 0) { /* The code below assumes there will only be one account type. * Let's assert this to protect from potential future changes. */ g_assert (g_list_length (pw->acct_types) == 1); acct_type = xaccAccountGetTypeStr(GPOINTER_TO_INT(pw->acct_types->data)); gnc_warning_dialog(pw->dialog, _("You have no valid \"Post To\" accounts. " "Please create an account of type \"%s\" " "before you continue to process this payment. " "Perhaps you want to create an Invoice or " "Bill first?"), acct_type); } } return pw; }
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 void button_clicked (GtkButton *button, GNCSearchAccount *fi) { GNCSearchAccountPrivate *priv; GtkDialog *dialog; GtkWidget *account_tree; GtkWidget *accounts_scroller; GtkWidget *label; char *desc; GtkTreeSelection *selection; /* Create the account tree */ account_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE)); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(account_tree), FALSE); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(account_tree)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); /* Select the currently-selected accounts */ priv = _PRIVATE(fi); if (priv->selected_accounts) gnc_tree_view_account_set_selected_accounts (GNC_TREE_VIEW_ACCOUNT(account_tree), priv->selected_accounts, FALSE); /* Create the account scroller and put the tree in it */ accounts_scroller = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(accounts_scroller), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(accounts_scroller), account_tree); gtk_widget_set_size_request(GTK_WIDGET(accounts_scroller), 300, 300); /* Create the label */ label = gtk_label_new (_("Select Accounts to Match")); /* Create the dialog */ dialog = GTK_DIALOG(gtk_dialog_new_with_buttons(_("Select the Accounts to Compare"), NULL, 0, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_OK"), GTK_RESPONSE_OK, NULL)); /* Put the dialog together */ gtk_box_pack_start ((GtkBox *) gtk_dialog_get_content_area (dialog), label, FALSE, FALSE, 3); gtk_box_pack_start ((GtkBox *) gtk_dialog_get_content_area (dialog), accounts_scroller, TRUE, TRUE, 3); gtk_widget_show_all (GTK_WIDGET (dialog)); /* Now run the dialog */ if (gtk_dialog_run (dialog) == GTK_RESPONSE_OK) { if (priv->selected_accounts) g_list_free (priv->selected_accounts); priv->selected_accounts = gnc_tree_view_account_get_selected_accounts (GNC_TREE_VIEW_ACCOUNT (account_tree)); desc = describe_button (fi); gtk_label_set_text (GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), desc); } gtk_widget_destroy (GTK_WIDGET (dialog)); }
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; }
static GncTaxTable * new_tax_table_dialog (TaxTableWindow *ttw, gboolean new_table, GncTaxTableEntry *entry, const char *name) { GncTaxTable *created_table = NULL; NewTaxTable *ntt; GtkBuilder *builder; GtkWidget *box, *widget, *combo; gboolean done; gint response, index; if (!ttw) return NULL; if (new_table && entry) return NULL; ntt = g_new0 (NewTaxTable, 1); ntt->ttw = ttw; ntt->entry = entry; ntt->new_table = new_table; if (entry) ntt->type = gncTaxTableEntryGetType (entry); else ntt->type = GNC_AMT_TYPE_PERCENT; /* Open and read the Glade File */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-tax-table.glade", "type_liststore"); gnc_builder_add_from_file (builder, "dialog-tax-table.glade", "New Tax Table Dialog"); ntt->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "New Tax Table Dialog")); ntt->name_entry = GTK_WIDGET(gtk_builder_get_object (builder, "name_entry")); if (name) gtk_entry_set_text (GTK_ENTRY (ntt->name_entry), name); /* Create the menu */ combo = GTK_WIDGET(gtk_builder_get_object (builder, "type_combobox")); index = ntt->type ? ntt->type : GNC_AMT_TYPE_VALUE; gtk_combo_box_set_active(GTK_COMBO_BOX(combo), index - 1); g_signal_connect (combo, "changed", G_CALLBACK (combo_changed), ntt); /* Attach our own widgets */ box = GTK_WIDGET(gtk_builder_get_object (builder, "amount_box")); ntt->amount_entry = widget = gnc_amount_edit_new (); gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (widget), TRUE); gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (widget), 100000); gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 0); box = GTK_WIDGET(gtk_builder_get_object (builder, "acct_window")); ntt->acct_tree = GTK_WIDGET(gnc_tree_view_account_new (FALSE)); gtk_container_add (GTK_CONTAINER (box), ntt->acct_tree); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(ntt->acct_tree), FALSE); /* Make 'enter' do the right thing */ gtk_entry_set_activates_default(GTK_ENTRY (gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (ntt->amount_entry))), TRUE); /* Fix mnemonics for generated target widgets */ widget = GTK_WIDGET(gtk_builder_get_object (builder, "value_label")); gtk_label_set_mnemonic_widget (GTK_LABEL (widget), ntt->amount_entry); widget = GTK_WIDGET(gtk_builder_get_object (builder, "account_label")); gtk_label_set_mnemonic_widget (GTK_LABEL (widget), ntt->acct_tree); /* Fill in the widgets appropriately */ if (entry) { gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ntt->amount_entry), gncTaxTableEntryGetAmount (entry)); gnc_tree_view_account_set_selected_account (GNC_TREE_VIEW_ACCOUNT (ntt->acct_tree), gncTaxTableEntryGetAccount (entry)); } /* Set our parent */ gtk_window_set_transient_for (GTK_WINDOW(ntt->dialog), GTK_WINDOW(ttw->dialog)); /* Setup signals */ gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, ntt); /* Show what we should */ gtk_widget_show_all (ntt->dialog); if (new_table == FALSE) { gtk_widget_hide (GTK_WIDGET(gtk_builder_get_object (builder, "table_title"))); gtk_widget_hide (GTK_WIDGET(gtk_builder_get_object (builder, "table_name"))); gtk_widget_hide (GTK_WIDGET(gtk_builder_get_object (builder, "spacer"))); gtk_widget_hide (ntt->name_entry); /* Tables are great for layout, but a pain when you hide widgets */ widget = GTK_WIDGET(gtk_builder_get_object (builder, "ttd_table")); gtk_table_set_row_spacing (GTK_TABLE(widget), 0, 0); gtk_table_set_row_spacing (GTK_TABLE(widget), 1, 0); gtk_table_set_row_spacing (GTK_TABLE(widget), 2, 0); gtk_widget_grab_focus (gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (ntt->amount_entry))); } else gtk_widget_grab_focus (ntt->name_entry); /* Display the dialog now that we're done manipulating it */ gtk_widget_show (ntt->dialog); done = FALSE; while (!done) { response = gtk_dialog_run (GTK_DIALOG (ntt->dialog)); switch (response) { case GTK_RESPONSE_OK: if (new_tax_table_ok_cb (ntt)) { created_table = ntt->created_table; done = TRUE; } break; default: done = TRUE; break; } } g_object_unref(G_OBJECT(builder)); gtk_widget_destroy(ntt->dialog); g_free(ntt); return created_table; }