30#include <glib/gi18n.h>
32#include "dialog-utils.h"
38#include "gnc-gui-query.h"
40#include "gnc-account-sel.h"
41#include "gnc-component-manager.h"
42#include "gnc-date-edit.h"
43#include "gnc-session.h"
46#define DIALOG_BOOK_CLOSE_CM_CLASS "dialog-book-close"
48void gnc_book_close_response_cb(GtkDialog *, gint, GtkDialog *);
51static QofLogModule log_module = GNC_MOD_GUI;
60 GtkWidget* close_date_widget;
61 GtkWidget* income_acct_widget;
62 GtkWidget* expense_acct_widget;
63 GtkWidget* desc_widget;
70 gint component_manager_id;
94 g_return_val_if_fail(cacb, NULL);
95 g_return_val_if_fail(cmdty, NULL);
97 txn = g_hash_table_lookup(cacb->txns, cmdty);
102 txn->total = gnc_numeric_zero();
111 g_hash_table_insert(cacb->txns, cmdty, txn);
123static void close_accounts_cb(
Account *a, gpointer data)
127 gnc_commodity* acct_commodity;
132 g_return_if_fail(cacb);
133 g_return_if_fail(cacb->cbw);
134 g_return_if_fail(cacb->txns);
144 g_assert(acct_commodity);
146 txn = find_or_create_txn(cacb, acct_commodity);
150 xaccSplitSetParent(split, txn->txn);
156 GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER);
160static void finish_txn_cb(gnc_commodity* cmdty,
167 g_return_if_fail(cmdty);
168 g_return_if_fail(txn);
169 g_return_if_fail(cacb);
170 g_return_if_fail(cacb->hash_size);
176 if (cacb->hash_size == 1 &&
178 acc = cacb->base_acct;
206 xaccSplitSetParent(split, txn->txn);
221 g_return_if_fail(cbw);
222 g_return_if_fail(acct);
225 cacb.base_acct = acct;
226 cacb.acct_type = acct_type;
227 cacb.txns = g_hash_table_new_full(g_direct_hash,
232 root_acct = gnc_book_get_root_account(cbw->book);
233 gnc_account_foreach_descendant(root_acct, close_accounts_cb, &cacb);
236 cacb.hash_size = g_hash_table_size(cacb.txns);
238 g_hash_table_foreach(cacb.txns, (GHFunc)finish_txn_cb, &cacb);
241 g_hash_table_destroy(cacb.txns);
244static void close_handler(gpointer data)
246 GtkWidget *dialog = data;
248 gtk_widget_destroy(dialog);
251static void destroy_cb(GObject *
object, gpointer data)
255 cbw = g_object_get_data(G_OBJECT(
object),
"CloseBookWindow");
257 if (cbw->component_manager_id)
259 gnc_unregister_gui_component(cbw->component_manager_id);
260 cbw->component_manager_id = 0;
266gnc_book_close_response_cb(GtkDialog *dialog, gint response, GtkDialog *unused)
272 ENTER(
"dialog %p, response %d, unused %p", dialog, response, unused);
274 g_return_if_fail(dialog);
276 cbw = g_object_get_data(G_OBJECT(dialog),
"CloseBookWindow");
277 g_return_if_fail(cbw);
281 case GTK_RESPONSE_HELP:
284 case GTK_RESPONSE_OK:
285 cbw->close_date = gnc_date_edit_get_date(GNC_DATE_EDIT(cbw->close_date_widget));
286 cbw->desc = gtk_entry_get_text(GTK_ENTRY(cbw->desc_widget));
288 income_acct = gnc_account_sel_get_account(GNC_ACCOUNT_SEL(cbw->income_acct_widget));
289 expense_acct = gnc_account_sel_get_account(GNC_ACCOUNT_SEL(cbw->expense_acct_widget));
293 gnc_error_dialog(GTK_WINDOW (cbw->dialog),
"%s",
294 _(
"Please select an Equity account to hold the total Period Income."));
300 gnc_error_dialog(GTK_WINDOW (cbw->dialog),
"%s",
301 _(
"Please select an Equity account to hold the total Period Expense."));
305 gnc_suspend_gui_refresh();
306 close_accounts_of_type(cbw, income_acct, ACCT_TYPE_INCOME);
307 close_accounts_of_type(cbw, expense_acct, ACCT_TYPE_EXPENSE);
308 gnc_resume_gui_refresh();
312 gtk_widget_destroy(GTK_WIDGET(dialog));
323 GList* equity_list = NULL;
325 g_return_if_fail(book);
328 g_return_if_fail(cbw);
332 builder = gtk_builder_new();
333 gnc_builder_add_from_file (builder,
"dialog-book-close.glade",
"close_book_dialog");
334 cbw->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"close_book_dialog"));
337 gtk_widget_set_name (GTK_WIDGET(cbw->dialog),
"gnc-id-book-close");
341 gtk_window_set_transient_for (GTK_WINDOW(cbw->dialog), GTK_WINDOW(parent));
343 PINFO(
"Closed Book Window is %p, Dialog is %p", cbw, cbw->dialog);
346 box = GTK_WIDGET(gtk_builder_get_object (builder,
"date_box"));
347 cbw->close_date_widget = gnc_date_edit_new(
gnc_time (NULL), FALSE, FALSE);
348 gtk_box_pack_start(GTK_BOX(box), cbw->close_date_widget, TRUE, TRUE, 0);
351 equity_list = g_list_prepend(equity_list, GINT_TO_POINTER(
ACCT_TYPE_EQUITY));
352 box = GTK_WIDGET(gtk_builder_get_object (builder,
"income_acct_box"));
353 cbw->income_acct_widget = gnc_account_sel_new();
354 gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(cbw->income_acct_widget),
356 gnc_account_sel_set_new_account_ability(GNC_ACCOUNT_SEL(cbw->income_acct_widget), TRUE);
357 gtk_box_pack_start(GTK_BOX(box), cbw->income_acct_widget, TRUE, TRUE, 0);
360 box = GTK_WIDGET(gtk_builder_get_object (builder,
"expense_acct_box"));
361 cbw->expense_acct_widget = gnc_account_sel_new();
362 gnc_account_sel_set_acct_filters(GNC_ACCOUNT_SEL(cbw->expense_acct_widget),
364 gnc_account_sel_set_new_account_ability(GNC_ACCOUNT_SEL(cbw->expense_acct_widget), TRUE);
365 gtk_box_pack_start(GTK_BOX(box), cbw->expense_acct_widget, TRUE, TRUE, 0);
368 cbw->desc_widget = GTK_WIDGET(gtk_builder_get_object (builder,
"desc_entry"));
371 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, cbw->dialog);
374 cbw->component_manager_id =
375 gnc_register_gui_component(DIALOG_BOOK_CLOSE_CM_CLASS, NULL, close_handler,
377 gnc_gui_component_set_session(cbw->component_manager_id,
378 gnc_get_current_session());
379 g_signal_connect(cbw->dialog,
"destroy", G_CALLBACK(destroy_cb), NULL);
382 g_object_set_data_full(G_OBJECT(cbw->dialog),
"CloseBookWindow", cbw, g_free);
384 g_object_unref(G_OBJECT(builder));
387 gtk_widget_show_all(cbw->dialog);
389 g_list_free(equity_list);
Account handling public routines.
API for Transactions and Splits (journal entries)
API for Transactions and Splits (journal entries)
This file contains the functions to present a GUI to select a book closing date and accounts into whi...
All type declarations for the whole Gnucash engine.
utility functions for the GnuCash UI
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed.
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship,...
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
void xaccAccountSetName(Account *acc, const char *str)
Set the account's name.
gnc_numeric xaccAccountGetBalanceAsOfDate(Account *acc, time64 date)
Get the balance of the account at the end of the day before the date specified.
void xaccAccountSetDescription(Account *acc, const char *str)
Set the account's description.
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account's type.
Account * xaccMallocAccount(QofBook *book)
Constructor.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Set the account's commodity.
@ ACCT_TYPE_EQUITY
Equity account is used to balance the balance sheet.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
time64 gnc_time64_get_day_end(time64 time_val)
The gnc_time64_get_day_end() routine will take the given time in seconds and adjust it to the last se...
time64 gnc_time(time64 *tbuf)
get the current time
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
void xaccTransSetIsClosingTxn(Transaction *trans, gboolean is_closing)
Sets whether or not this transaction is a "closing transaction".
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
Account * gnc_account_lookup_by_name(const Account *parent, const char *name)
The gnc_account_lookup_by_name() subroutine fetches the account by name from the descendants of the s...
void xaccTransSetDateEnteredSecs(Transaction *trans, time64 secs)
Modify the date of when the transaction was entered.
Transaction * xaccMallocTransaction(QofBook *book)
The xaccMallocTransaction() will malloc memory and initialize it.
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3)).
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated account.
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
void gnc_ui_close_book(QofBook *book, GtkWindow *parent)
Create and run the dialog to close the book.
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome's yelp for linux, and open to a given link within a gi...
gnc_commodity * gnc_account_or_default_currency(const Account *account, gboolean *currency_from_account_found)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
#define PINFO(format, args...)
Print an informational note.
#define LEAVE(format, args...)
Print a function exit debugging message.
#define ENTER(format, args...)
Print a function entry debugging message.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
Split * xaccMallocSplit(QofBook *book)
Constructor.
void xaccSplitSetBaseValue(Split *s, gnc_numeric value, const gnc_commodity *base_currency)
Depending on the base_currency, set either the value or the amount of this split or both: If the base...