34#include <glib/gi18n.h>
35#ifdef __G_IR_SCANNER__
36#undef __G_IR_SCANNER__
38#include <gdk/gdkkeysyms.h>
46#include "dialog-transfer.h"
47#include "dialog-utils.h"
48#include "gnc-amount-edit.h"
49#include "gnc-autoclear.h"
50#include "gnc-component-manager.h"
52#include "gnc-date-edit.h"
61#include "gnc-ui-balances.h"
63#include "reconcile-view.h"
64#include "window-reconcile.h"
65#include "gnc-session.h"
67#include <gtkmacintegration/gtkosxapplication.h>
70#define WINDOW_RECONCILE_CM_CLASS "window-reconcile"
71#define GNC_PREF_AUTO_CC_PAYMENT "auto-cc-payment"
72#define GNC_PREF_ALWAYS_REC_TO_TODAY "always-reconcile-to-today"
79 gnc_numeric new_ending;
87 GSimpleActionGroup *simple_action_group;
88 GtkWidget *autoclear_button;
89 GtkAccelGroup *accel_group;
93 SplitsVec autoclear_splits;
94 SplitsVec initially_cleared_splits;
99 GtkWidget *reconciled;
100 GtkWidget *difference;
102 GtkWidget *total_debit;
103 GtkWidget *total_credit;
108 GtkWidget *debit_frame;
109 GtkWidget *credit_frame;
111 gboolean delete_refresh;
120typedef struct _startRecnWindowData
125 GtkWidget *startRecnWindow;
126 GtkWidget *xfer_button;
127 GtkWidget *date_value;
128 GtkWidget *future_icon;
129 GtkWidget *future_text;
130 GNCAmountEdit *end_value;
131 gnc_numeric original_value;
132 gboolean user_set_value;
134 XferDialog *xferData;
135 gboolean include_children;
141static gnc_numeric recnRecalculateBalance (RecnWindow *recnData);
143static void recn_destroy_cb (GtkWidget *w, gpointer data);
144static void recn_cancel (RecnWindow *recnData);
145static gboolean recn_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer data);
146static gboolean recn_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer data);
147static void recnAutoClearCB (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
148static void recnFinishCB (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
149static void recnPostponeCB (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
150static void recnCancelCB (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
157static void gnc_reconcile_window_set_sensitivity (RecnWindow *recnData);
158static char * gnc_recn_make_window_name (
Account *account);
159static void gnc_recn_set_window_name (RecnWindow *recnData);
160static gboolean find_by_account (gpointer
find_data, gpointer user_data);
164G_GNUC_UNUSED
static QofLogModule log_module = GNC_MOD_GUI;
166static time64 gnc_reconcile_last_statement_date = 0;
171commodity_compare(
Account *account, gpointer user_data) {
173 (gnc_commodity*) user_data);
175 return equal ? NULL : account;
187has_account_different_commodities(
const Account *account)
189 gnc_commodity *parent_commodity;
201 return result != NULL;
205get_autoclear_icon (GError* error)
207 static std::unordered_map<gint,const char*> icon_names =
209 { Autoclear::ABORT_NONE,
"media-playback-start" },
210 { Autoclear::ABORT_NOP,
"media-playback-stop" },
211 { Autoclear::ABORT_MULTI,
"dialog-information" },
212 { Autoclear::ABORT_TIMEOUT,
"dialog-error" },
213 { Autoclear::ABORT_UNREACHABLE,
"dialog-error" },
215 auto it = icon_names.find (error ? error->code : Autoclear::ABORT_NONE);
216 return it == icon_names.end() ?
"dialog-information" : it->second;
219#define GNC_PREF_ENABLE_AUTOCLEAR "enable-autoclear-in-reconcile"
222calculate_autoclear (RecnWindow *recnData)
224 g_return_if_fail (recnData);
226 bool enabled =
gnc_prefs_get_bool (GNC_PREFS_GROUP_RECONCILE, GNC_PREF_ENABLE_AUTOCLEAR);
227 auto action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
228 "RecnAutoClearAction");
229 g_simple_action_set_enabled (G_SIMPLE_ACTION(action), enabled);
230 gtk_widget_set_visible (recnData->autoclear_button, enabled);
234 GError* error =
nullptr;
237 static const unsigned int MAX_AUTOCLEAR_SECONDS = 1;
239 GList *splits_to_clear = gnc_account_get_autoclear_splits
240 (acct, recnData->new_ending, recnData->statement_date, &error, MAX_AUTOCLEAR_SECONDS);
242 gtk_widget_set_sensitive (recnData->autoclear_button, error ==
nullptr);
244 gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (recnData->autoclear_button),
245 get_autoclear_icon (error));
247 recnData->autoclear_splits = recnData->initially_cleared_splits;
248 for (
auto n = splits_to_clear; n; n = n->next)
249 recnData->autoclear_splits.push_back (GNC_SPLIT (n->data));
253 gtk_widget_set_tooltip_text (recnData->autoclear_button,
_(error->message));
254 g_error_free (error);
258 auto num_splits = g_list_length (splits_to_clear);
261 char* tooltip = g_strdup_printf
262 (ngettext(
"Automatically select %u transaction up to %s that clears to %s",
263 "Automatically select %u transactions up to %s that clear to %s",
265 num_splits, date_buff,
266 xaccPrintAmount (recnData->new_ending, gnc_account_print_info (acct,
true)));
267 gtk_widget_set_tooltip_text (recnData->autoclear_button, tooltip);
270 g_list_free (splits_to_clear);
281recnRefresh (RecnWindow *recnData)
283 if (recnData == NULL)
286 gnc_reconcile_view_refresh(GNC_RECONCILE_VIEW(recnData->debit));
287 gnc_reconcile_view_refresh(GNC_RECONCILE_VIEW(recnData->credit));
289 gnc_reconcile_window_set_sensitivity(recnData);
291 gnc_recn_set_window_name(recnData);
293 recnRecalculateBalance(recnData);
295 gtk_widget_queue_resize(recnData->window);
300recn_get_account (RecnWindow *recnData)
310gnc_add_colorized_amount (gpointer obj, gnc_numeric amt,
315 gnc_set_label_color (GTK_WIDGET (obj), amt);
316 gtk_label_set_text (GTK_LABEL (obj),
xaccPrintAmount (amt, print_info));
328recnRecalculateBalance (RecnWindow *recnData)
333 gnc_numeric starting;
335 gnc_numeric reconciled;
339 gboolean reverse_balance, include_children;
342 account = recn_get_account (recnData);
344 return gnc_numeric_zero ();
346 reverse_balance = gnc_reverse_balance(account);
348 starting = gnc_ui_account_get_reconciled_balance(account, include_children);
349 print_info = gnc_account_print_info (account, TRUE);
351 ending = recnData->new_ending;
352 debit = gnc_reconcile_view_reconciled_balance
353 (GNC_RECONCILE_VIEW(recnData->debit));
354 credit = gnc_reconcile_view_reconciled_balance
355 (GNC_RECONCILE_VIEW(recnData->credit));
357 reconciled = gnc_numeric_sub_fixed (debit, credit);
359 reconciled = gnc_numeric_sub_fixed (reconciled, starting);
361 reconciled = gnc_numeric_add_fixed (reconciled, starting);
363 diff = gnc_numeric_sub_fixed (ending, reconciled);
366 gtk_label_set_text (GTK_LABEL(recnData->recn_date), datestr);
369 gnc_add_colorized_amount (recnData->starting, starting, print_info, FALSE);
370 gnc_add_colorized_amount (recnData->ending, ending, print_info, reverse_balance);
371 gnc_add_colorized_amount (recnData->total_debit, debit, print_info, FALSE);
372 gnc_add_colorized_amount (recnData->total_credit, credit, print_info, FALSE);
373 gnc_add_colorized_amount (recnData->reconciled, reconciled, print_info, reverse_balance);
374 gnc_add_colorized_amount (recnData->difference, diff, print_info, reverse_balance);
376 action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
380 action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
381 "TransBalanceAction");
384 calculate_autoclear (recnData);
404 gint result = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(data->end_value),
407 data->user_set_value = FALSE;
413 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(data->end_value), value);
414 gnc_amount_edit_select_region (GNC_AMOUNT_EDIT(data->end_value), 0, -1);
430amount_edit_focus_out_cb(GtkWidget *widget, GdkEventFocus *event,
433 amount_edit_cb(widget, data);
453 gnc_numeric new_balance;
456 gboolean show_warning = FALSE;
457 gint days_after_today;
458 static const time64 secs_per_day = 86400;
459 static const time64 secs_per_hour = 3600;
461 new_date = gnc_date_edit_get_date_end (gde);
468 secs_per_hour) / secs_per_day;
470 if (days_after_today > 0)
472 gchar *str = g_strdup_printf
474 (ngettext (
"Statement Date is %d day after today.",
475 "Statement Date is %d days after today.",
479 gchar *tip_start = g_strdup_printf
481 (ngettext (
"The statement date you have chosen is %d day in the future.",
482 "The statement date you have chosen is %d days in the future.",
486 gchar *tip_end = g_strdup (
_(
"This may cause issues for future reconciliation \
487actions on this account. Please double-check this is the date you intended."));
488 gchar *tip = g_strdup_printf (
"%s %s", tip_start, tip_end);
492 gtk_label_set_text (GTK_LABEL(data->future_text), str);
493 gtk_widget_set_tooltip_text (GTK_WIDGET(data->future_text), tip);
499 gtk_widget_set_visible (GTK_WIDGET(data->future_icon), show_warning);
500 gtk_widget_set_visible (GTK_WIDGET(data->future_text), show_warning);
502 if (data->user_set_value)
506 new_balance = gnc_ui_account_get_balance_as_of_date (data->account, new_date,
507 data->include_children);
509 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (data->end_value),
511 data->original_value = new_balance;
518 data->include_children =
519 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
522 recn_date_changed_cb (data->date_value, data);
545gnc_recn_make_interest_window_name(
Account *account,
char *text)
551 title = g_strconcat(fullname,
" - ", text && *text ?
_(text) :
"", NULL);
564 if ( !account_type_has_auto_interest_xfer( data->account_type ) )
568 data->xferData = gnc_xfer_dialog( GTK_WIDGET(data->startRecnWindow),
574 if ( account_type_has_auto_interest_payment( data->account_type ) )
575 title = gnc_recn_make_interest_window_name( data->account,
576 _(
"Interest Payment") );
578 title = gnc_recn_make_interest_window_name( data->account,
579 _(
"Interest Charge") );
581 gnc_xfer_dialog_set_title( data->xferData, title );
586 gnc_xfer_dialog_set_information_label( data->xferData,
587 _(
"Payment Information") );
594 if ( account_type_has_auto_interest_payment( data->account_type ) )
596 gnc_xfer_dialog_set_from_account_label( data->xferData,
598 gnc_xfer_dialog_set_from_show_button_active( data->xferData, TRUE );
602 gnc_xfer_dialog_set_to_account_label( data->xferData,
603 _(
"Reconcile Account") );
604 gnc_xfer_dialog_select_to_account( data->xferData, data->account );
605 gnc_xfer_dialog_lock_to_account_tree( data->xferData );
608 gnc_xfer_dialog_quickfill_to_account( data->xferData, TRUE );
612 gnc_xfer_dialog_set_from_account_label( data->xferData,
613 _(
"Reconcile Account") );
614 gnc_xfer_dialog_select_from_account( data->xferData, data->account );
615 gnc_xfer_dialog_lock_from_account_tree( data->xferData );
617 gnc_xfer_dialog_set_to_account_label( data->xferData,
619 gnc_xfer_dialog_set_to_show_button_active( data->xferData, TRUE );
624 gnc_xfer_dialog_quickfill_to_account( data->xferData, FALSE );
628 gnc_xfer_dialog_toggle_currency_table( data->xferData, FALSE );
631 gnc_xfer_dialog_set_date( data->xferData, data->date );
640 if ( ! gnc_xfer_dialog_run_until_done( data->xferData ) )
641 if ( data->xfer_button )
642 gtk_widget_set_sensitive(GTK_WIDGET(data->xfer_button), TRUE);
645 data->xferData = NULL;
655 GtkWidget *entry = gnc_amount_edit_gtk_entry(
656 GNC_AMOUNT_EDIT(data->end_value) );
657 gnc_numeric before = gnc_amount_edit_get_amount(
658 GNC_AMOUNT_EDIT(data->end_value) );
661 recnInterestXferWindow( data );
669 if (gnc_reverse_balance(data->account))
672 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (data->end_value), after);
673 gtk_widget_grab_focus(GTK_WIDGET(entry));
674 gtk_editable_select_region (GTK_EDITABLE(entry), 0, -1);
675 data->original_value = after;
676 data->user_set_value = FALSE;
685 if ( data->xfer_button )
686 gtk_widget_set_sensitive(GTK_WIDGET(data->xfer_button), FALSE);
689 gnc_reconcile_interest_xfer_run( data );
694gnc_save_reconcile_interval(
Account *account,
time64 statement_date)
696 time64 prev_statement_date;
697 int days = 0, months = 0;
705 auto seconds = statement_date - prev_statement_date;
706 days = seconds / 60 / 60 / 24;
714 int prev_days = 0, prev_months = 1;
718 if (prev_months == 1)
726 struct tm current, prev;
730 months = ((12 * current.tm_year + current.tm_mon) -
731 (12 * prev.tm_year + prev.tm_mon));
738 if (months >= 0 && days >= 0)
758startRecnWindow(GtkWidget *parent,
Account *account,
759 gnc_numeric *new_ending,
time64 *statement_date,
760 gboolean enable_subaccount)
762 GtkWidget *dialog, *end_value, *date_value, *include_children_button;
765 gboolean auto_interest_xfer_option;
771 gulong fo_handler_id;
779 data.account = account;
781 data.date = *statement_date;
786 data.include_children = !has_account_different_commodities(account) &&
789 ending = gnc_ui_account_get_reconciled_balance(account,
790 data.include_children);
791 print_info = gnc_account_print_info (account, TRUE);
801 builder = gtk_builder_new();
802 gnc_builder_add_from_file (builder,
"window-reconcile.glade",
"reconcile_start_dialog");
804 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"reconcile_start_dialog"));
807 gtk_widget_set_name (GTK_WIDGET(dialog),
"gnc-id-reconcile-start");
809 title = gnc_recn_make_window_name (account);
810 gtk_window_set_title(GTK_WINDOW(dialog), title);
813 data.startRecnWindow = GTK_WIDGET(dialog);
816 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
819 GtkWidget *start_value, *box;
821 GtkWidget *interest = NULL;
823 start_value = GTK_WIDGET(gtk_builder_get_object (builder,
"start_value"));
824 gtk_label_set_text(GTK_LABEL(start_value),
xaccPrintAmount (ending, print_info));
826 include_children_button = GTK_WIDGET(gtk_builder_get_object (builder,
"subaccount_check"));
827 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(include_children_button),
828 data.include_children);
829 gtk_widget_set_sensitive(include_children_button, enable_subaccount);
831 date_value = gnc_date_edit_new(*statement_date, FALSE, FALSE);
832 data.date_value = date_value;
833 box = GTK_WIDGET(gtk_builder_get_object (builder,
"date_value_box"));
834 gtk_box_pack_start(GTK_BOX(box), date_value, TRUE, TRUE, 0);
835 label = GTK_WIDGET(gtk_builder_get_object (builder,
"date_label"));
836 gnc_date_make_mnemonic_target(GNC_DATE_EDIT(date_value), label);
838 end_value = gnc_amount_edit_new ();
839 data.end_value = GNC_AMOUNT_EDIT(end_value);
840 data.original_value = *new_ending;
841 data.user_set_value = FALSE;
843 data.future_icon = GTK_WIDGET(gtk_builder_get_object (builder,
"future_icon"));
844 data.future_text = GTK_WIDGET(gtk_builder_get_object (builder,
"future_text"));
846 box = GTK_WIDGET(gtk_builder_get_object (builder,
"ending_value_box"));
847 gtk_box_pack_start(GTK_BOX(box), end_value, TRUE, TRUE, 0);
848 label = GTK_WIDGET(gtk_builder_get_object (builder,
"end_label"));
849 gnc_amount_edit_make_mnemonic_target (GNC_AMOUNT_EDIT(end_value), label);
851 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, &data);
853 gnc_date_activates_default(GNC_DATE_EDIT(date_value), TRUE);
856 g_signal_connect ( G_OBJECT (date_value),
"date_changed",
857 G_CALLBACK (recn_date_changed_cb), (gpointer) &data );
859 print_info.use_symbol = 0;
860 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (end_value), print_info);
861 gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (end_value),
864 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (end_value), *new_ending);
866 entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (end_value));
867 gtk_editable_select_region (GTK_EDITABLE(entry), 0, -1);
868 fo_handler_id = g_signal_connect (G_OBJECT(entry),
"focus-out-event",
869 G_CALLBACK(amount_edit_focus_out_cb),
871 g_signal_connect (G_OBJECT(entry),
"activate",
872 G_CALLBACK(amount_edit_cb),
874 gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
880 interest = GTK_WIDGET(gtk_builder_get_object (builder,
"interest_button"));
881 if ( account_type_has_auto_interest_payment( data.account_type ) )
882 gtk_button_set_label(GTK_BUTTON(interest),
_(
"Enter _Interest Payment…") );
883 else if ( account_type_has_auto_interest_charge( data.account_type ) )
884 gtk_button_set_label(GTK_BUTTON(interest),
_(
"Enter _Interest Charge…") );
887 gtk_widget_destroy(interest);
893 data.xfer_button = interest;
894 if ( auto_interest_xfer_option )
895 gtk_widget_set_sensitive(GTK_WIDGET(interest), FALSE);
898 gtk_widget_show_all(dialog);
900 gtk_widget_hide (data.future_text);
901 gtk_widget_hide (data.future_icon);
903 gtk_widget_grab_focus(gnc_amount_edit_gtk_entry
904 (GNC_AMOUNT_EDIT (end_value)));
909 if ( account_type_has_auto_interest_xfer( data.account_type )
910 && auto_interest_xfer_option )
912 gnc_reconcile_interest_xfer_run( &data );
915 while (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
917 if (gnc_date_edit_get_date_end(GNC_DATE_EDIT(date_value)) != *statement_date)
918 recn_date_changed_cb(date_value, &data);
921 if (gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT(end_value), NULL))
923 result = GTK_RESPONSE_OK;
928 if (result == GTK_RESPONSE_OK)
930 *new_ending = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (end_value));
931 *statement_date = gnc_date_edit_get_date_end(GNC_DATE_EDIT(date_value));
933 if (gnc_reverse_balance(account))
938 gnc_save_reconcile_interval(account, *statement_date);
941 g_signal_handler_disconnect (G_OBJECT(entry), fo_handler_id);
942 gtk_widget_destroy (dialog);
943 g_object_unref(G_OBJECT(builder));
945 return (result == GTK_RESPONSE_OK);
950gnc_reconcile_window_set_sensitivity(RecnWindow *recnData)
952 gboolean sensitive = FALSE;
956 view = GNC_RECONCILE_VIEW(recnData->debit);
957 if (gnc_reconcile_view_num_selected(view) == 1)
960 view = GNC_RECONCILE_VIEW(recnData->credit);
961 if (gnc_reconcile_view_num_selected(view) == 1)
964 action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
966 g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
968 action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
969 "TransDeleteAction");
970 g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
974 view = GNC_RECONCILE_VIEW(recnData->debit);
975 if (gnc_reconcile_view_num_selected(view) > 0)
978 view = GNC_RECONCILE_VIEW(recnData->credit);
979 if (gnc_reconcile_view_num_selected(view) > 0)
982 action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
984 g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
986 action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
988 g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
996 auto recnData =
static_cast<RecnWindow*
>(data);
997 gnc_reconcile_window_set_sensitivity(recnData);
998 recnRecalculateBalance(recnData);
1006 auto recnData =
static_cast<RecnWindow*
>(data);
1007 gnc_reconcile_window_set_sensitivity(recnData);
1024do_popup_menu(RecnWindow *recnData, GdkEventButton *event)
1026 GMenuModel *menu_model = (GMenuModel *)gtk_builder_get_object (recnData->builder,
1028 GtkWidget *menu = gtk_menu_new_from_model (menu_model);
1033 gtk_menu_attach_to_widget (GTK_MENU(menu), GTK_WIDGET(recnData->window), NULL);
1034 gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent *) event);
1052gnc_reconcile_window_popup_menu_cb (GtkWidget *widget,
1053 RecnWindow *recnData)
1055 do_popup_menu(recnData, NULL);
1065gnc_reconcile_window_button_press_cb (GtkWidget *widget,
1066 GdkEventButton *event,
1067 RecnWindow *recnData)
1069 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
1071 GNCQueryView *qview = GNC_QUERY_VIEW(widget);
1075 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(qview),
1078 &path, NULL, NULL, NULL);
1082 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));
1084 if (!gtk_tree_selection_path_is_selected (selection, path))
1086 gtk_tree_selection_unselect_all (selection);
1087 gtk_tree_selection_select_path (selection, path);
1089 gtk_tree_path_free (path);
1091 do_popup_menu (recnData, event);
1099gnc_reconcile_window_open_register(RecnWindow *recnData)
1101 Account *account = recn_get_account (recnData);
1103 gboolean include_children;
1112 gnc_split_reg_raise (gsr);
1121 auto recnData =
static_cast<RecnWindow*
>(data);
1128 gsr = gnc_reconcile_window_open_register(recnData);
1133 if (gnc_split_reg_clear_filter_for_split (gsr, split))
1136 gnc_split_reg_jump_to_split( gsr, split );
1141gnc_reconcile_window_focus_cb(GtkWidget *widget, GdkEventFocus *event,
1144 auto recnData =
static_cast<RecnWindow*
>(data);
1148 this_view = GNC_RECONCILE_VIEW(widget);
1150 debit = GNC_RECONCILE_VIEW(recnData->debit);
1151 credit = GNC_RECONCILE_VIEW(recnData->credit);
1153 other_view = GNC_RECONCILE_VIEW(this_view == debit ? credit : debit);
1156 gnc_reconcile_view_unselect_all(other_view);
1161gnc_reconcile_key_press_cb (GtkWidget *widget, GdkEventKey *event,
1164 auto recnData =
static_cast<RecnWindow*
>(data);
1165 GtkWidget *this_view, *other_view;
1166 GtkWidget *debit, *credit;
1168 switch (event->keyval)
1171 case GDK_KEY_ISO_Left_Tab:
1178 g_signal_stop_emission_by_name (widget,
"key_press_event");
1182 debit = recnData->debit;
1183 credit = recnData->credit;
1185 other_view = (this_view == debit ? credit : debit);
1187 gtk_widget_grab_focus (other_view);
1194gnc_reconcile_window_set_titles(RecnWindow *recnData)
1199 gtk_frame_set_label(GTK_FRAME(recnData->debit_frame), title);
1202 gtk_frame_set_label(GTK_FRAME(recnData->credit_frame), title);
1207gnc_reconcile_window_create_view_box(
Account *account,
1208 GNCReconcileViewType type,
1209 RecnWindow *recnData,
1210 GtkWidget **list_save,
1211 GtkWidget **total_save)
1213 GtkWidget *frame, *scrollWin, *view, *vbox, *label, *hbox;
1215 GtkRequisition nat_sb;
1217 frame = gtk_frame_new(NULL);
1219 if (type == RECLIST_DEBIT)
1220 recnData->debit_frame = frame;
1222 recnData->credit_frame = frame;
1224 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
1225 gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE);
1227 view = gnc_reconcile_view_new(account, type, recnData->statement_date);
1230 g_signal_connect(view,
"toggle_reconciled",
1231 G_CALLBACK(gnc_reconcile_window_toggled_cb),
1233 g_signal_connect(view,
"line_selected",
1234 G_CALLBACK(gnc_reconcile_window_row_cb),
1236 g_signal_connect(view,
"button_press_event",
1237 G_CALLBACK(gnc_reconcile_window_button_press_cb),
1239 g_signal_connect(view,
"double_click_split",
1240 G_CALLBACK(gnc_reconcile_window_double_click_cb),
1242 g_signal_connect(view,
"focus_in_event",
1243 G_CALLBACK(gnc_reconcile_window_focus_cb),
1245 g_signal_connect(view,
"key_press_event",
1246 G_CALLBACK(gnc_reconcile_key_press_cb),
1249 scrollWin = gtk_scrolled_window_new (NULL, NULL);
1250 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrollWin),
1251 GTK_POLICY_AUTOMATIC,
1252 GTK_POLICY_AUTOMATIC);
1253 gtk_container_set_border_width(GTK_CONTAINER(scrollWin), 5);
1255 gtk_container_add(GTK_CONTAINER(frame), scrollWin);
1256 gtk_container_add(GTK_CONTAINER(scrollWin), view);
1257 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
1260 vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (scrollWin));
1261 gtk_widget_get_preferred_size (vscroll, NULL, &nat_sb);
1264 gnc_reconcile_view_add_padding (GNC_RECONCILE_VIEW(view), REC_RECN, nat_sb.width);
1266 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
1267 gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
1268 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1270 label = gtk_label_new(
_(
"Total"));
1271 gnc_label_set_alignment(label, 1.0, 0.5);
1272 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1274 label = gtk_label_new(
"");
1275 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1276 *total_save = label;
1277 gtk_widget_set_margin_end (GTK_WIDGET(label), 10 + nat_sb.width);
1284gnc_reconcile_window_get_current_split(RecnWindow *recnData)
1289 view = GNC_RECONCILE_VIEW(recnData->debit);
1290 split = gnc_reconcile_view_get_current_split(view);
1294 view = GNC_RECONCILE_VIEW(recnData->credit);
1295 split = gnc_reconcile_view_get_current_split(view);
1302gnc_ui_reconcile_window_help_cb (GSimpleAction *simple,
1303 GVariant *parameter,
1306 auto recnData =
static_cast<RecnWindow*
>(user_data);
1307 gnc_gnome_help (GTK_WINDOW(recnData->window), DF_MANUAL, DL_RECNWIN);
1312gnc_ui_reconcile_window_change_cb (GSimpleAction *simple,
1313 GVariant *parameter,
1316 auto recnData =
static_cast<RecnWindow*
>(user_data);
1317 Account *account = recn_get_account (recnData);
1318 gnc_numeric new_ending = recnData->new_ending;
1319 time64 statement_date = recnData->statement_date;
1321 if (gnc_reverse_balance (account))
1323 if (startRecnWindow (recnData->window, account, &new_ending, &statement_date,
1326 recnData->new_ending = new_ending;
1327 recnData->statement_date = statement_date;
1328 recnRecalculateBalance (recnData);
1334gnc_ui_reconcile_window_balance_cb (GSimpleAction *simple,
1335 GVariant *parameter,
1338 auto recnData =
static_cast<RecnWindow*
>(user_data);
1341 gnc_numeric balancing_amount;
1345 gsr = gnc_reconcile_window_open_register(recnData);
1349 account = recn_get_account(recnData);
1350 if (account == NULL)
1353 balancing_amount = recnRecalculateBalance(recnData);
1357 statement_date = recnData->statement_date;
1358 if (statement_date == 0)
1361 gnc_split_reg_balancing_entry(gsr, account, statement_date, balancing_amount);
1366gnc_ui_reconcile_window_rec_cb (GSimpleAction *simple,
1367 GVariant *parameter,
1370 auto recnData =
static_cast<RecnWindow*
>(user_data);
1373 debit = GNC_RECONCILE_VIEW(recnData->debit);
1374 credit = GNC_RECONCILE_VIEW(recnData->credit);
1376 gnc_reconcile_view_set_list (debit, TRUE);
1377 gnc_reconcile_view_set_list (credit, TRUE);
1382gnc_ui_reconcile_window_unrec_cb (GSimpleAction *simple,
1383 GVariant *parameter,
1386 auto recnData =
static_cast<RecnWindow*
>(user_data);
1389 debit = GNC_RECONCILE_VIEW(recnData->debit);
1390 credit = GNC_RECONCILE_VIEW(recnData->credit);
1392 gnc_reconcile_view_set_list (debit, FALSE);
1393 gnc_reconcile_view_set_list (credit, FALSE);
1403gnc_reconcile_window_get_selection_view (RecnWindow *recnData)
1405 if (gnc_reconcile_view_num_selected (GNC_RECONCILE_VIEW (recnData->debit)) > 0)
1406 return GNC_RECONCILE_VIEW (recnData->debit);
1408 if (gnc_reconcile_view_num_selected (GNC_RECONCILE_VIEW (recnData->credit)) > 0)
1409 return GNC_RECONCILE_VIEW (recnData->credit);
1422gnc_reconcile_window_delete_set_next_selection (RecnWindow *recnData, Split *split)
1424 GNCReconcileView *view = gnc_reconcile_window_get_selection_view (recnData);
1425 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1426 Split *this_split = NULL;
1428 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1429 GList *path_list, *node;
1430 GtkTreePath *save_del_path;
1436 path_list = gtk_tree_selection_get_selected_rows (selection, &model);
1438 node = g_list_first (path_list);
1441 auto path =
static_cast<GtkTreePath*
>(node->data);
1442 save_del_path = gtk_tree_path_copy (path);
1444 gtk_tree_path_next (path);
1445 if (gtk_tree_model_get_iter (model, &iter, path))
1449 gtk_tree_model_get (model, &iter, REC_POINTER, &this_split, -1);
1451 while (
xaccSplitGetParent (this_split) == trans && gtk_tree_model_iter_next (model, &iter));
1458 path = save_del_path;
1459 if (gtk_tree_path_prev (path) && gtk_tree_model_get_iter (model, &iter, path))
1463 gtk_tree_model_get (model, &iter, REC_POINTER, &this_split, -1);
1465 while (
xaccSplitGetParent (this_split) == trans && gtk_tree_model_iter_previous (model, &iter));
1469 gtk_tree_path_free (save_del_path);
1470 g_list_free_full (path_list, (GDestroyNotify) gtk_tree_path_free);
1474 gtk_tree_selection_select_iter (selection, &iter);
1479gnc_ui_reconcile_window_delete_cb (GSimpleAction *simple,
1480 GVariant *parameter,
1483 auto recnData =
static_cast<RecnWindow*
>(user_data);
1487 split = gnc_reconcile_window_get_current_split(recnData);
1493 const char *message =
_(
"Are you sure you want to delete the selected "
1497 result = gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE,
"%s", message);
1504 gnc_reconcile_window_delete_set_next_selection(recnData, split);
1506 gnc_suspend_gui_refresh ();
1511 gnc_resume_gui_refresh ();
1516gnc_ui_reconcile_window_edit_cb (GSimpleAction *simple,
1517 GVariant *parameter,
1520 auto recnData =
static_cast<RecnWindow*
>(user_data);
1524 split = gnc_reconcile_window_get_current_split (recnData);
1529 gsr = gnc_reconcile_window_open_register(recnData);
1534 if (gnc_split_reg_clear_filter_for_split (gsr, split))
1537 gnc_split_reg_jump_to_split_amount( gsr, split );
1542gnc_recn_make_window_name(
Account *account)
1548 title = g_strconcat(fullname,
" - ",
_(
"Reconcile"), NULL);
1557gnc_recn_set_window_name(RecnWindow *recnData)
1561 title = gnc_recn_make_window_name (recn_get_account (recnData));
1563 gtk_window_set_title (GTK_WINDOW (recnData->window), title);
1570gnc_recn_edit_account_cb (GSimpleAction *simple,
1571 GVariant *parameter,
1574 auto recnData =
static_cast<RecnWindow*
>(user_data);
1575 Account *account = recn_get_account (recnData);
1577 if (account == NULL)
1585gnc_recn_xfer_cb (GSimpleAction *simple,
1586 GVariant *parameter,
1589 auto recnData =
static_cast<RecnWindow*
>(user_data);
1590 Account *account = recn_get_account (recnData);
1592 if (account == NULL)
1595 gnc_xfer_dialog (recnData->window, account);
1600gnc_recn_scrub_cb (GSimpleAction *simple,
1601 GVariant *parameter,
1604 auto recnData =
static_cast<RecnWindow*
>(user_data);
1605 Account *account = recn_get_account (recnData);
1607 if (account == NULL)
1610 gnc_suspend_gui_refresh ();
1613 xaccAccountTreeScrubImbalance (account, gnc_window_show_progress);
1616 if (g_getenv(
"GNC_AUTO_SCRUB_LOTS") != NULL)
1617 xaccAccountTreeScrubLots(account);
1619 gnc_resume_gui_refresh ();
1624gnc_recn_open_cb (GSimpleAction *simple,
1625 GVariant *parameter,
1628 auto recnData =
static_cast<RecnWindow*
>(user_data);
1630 gnc_reconcile_window_open_register(recnData);
1635gnc_get_reconcile_info (
Account *account,
1636 gnc_numeric *new_ending,
1639 gboolean always_today;
1643 g_date_clear(&date, 1);
1645 always_today =
gnc_prefs_get_bool(GNC_PREFS_GROUP_RECONCILE, GNC_PREF_ALWAYS_REC_TO_TODAY);
1647 if (!always_today &&
1650 int months = 1, days = 0;
1658 gboolean was_last_day_of_month = g_date_is_last_of_month(&date);
1660 g_date_add_months(&date, months);
1663 if (was_last_day_of_month)
1665 g_date_set_day (&date, g_date_get_days_in_month(g_date_get_month(&date),
1666 g_date_get_year( &date)));
1671 g_date_add_days (&date, days);
1677 if (*statement_date > today)
1678 *statement_date = today;
1685 if (gnc_reverse_balance(account))
1694 gnc_ui_account_get_balance_as_of_date
1695 (account, *statement_date,
1702find_by_account (gpointer
find_data, gpointer user_data)
1705 auto recnData =
static_cast<RecnWindow*
>(user_data);
1715recn_set_watches_one_account (gpointer data, gpointer user_data)
1718 RecnWindow *recnData = (RecnWindow *)user_data;
1721 gnc_gui_component_watch_entity (recnData->component_id,
1723 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1726 for (
auto split : xaccAccountGetSplits (account))
1729 gnc_gui_component_watch_entity (recnData->component_id,
1733 | GNC_EVENT_ITEM_CHANGED);
1739recn_set_watches (RecnWindow *recnData)
1741 gboolean include_children;
1743 GList *accounts = NULL;
1745 gnc_gui_component_clear_watches (recnData->component_id);
1747 account = recn_get_account (recnData);
1750 if (include_children)
1754 accounts = g_list_prepend (accounts, account);
1756 g_list_foreach(accounts, recn_set_watches_one_account, recnData);
1758 g_list_free (accounts);
1763refresh_handler (GHashTable *changes, gpointer user_data)
1765 auto recnData =
static_cast<RecnWindow*
>(user_data);
1769 account = recn_get_account (recnData);
1772 gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1778 info = gnc_gui_get_entity_events (changes, &recnData->account);
1779 if (info && (info->event_mask & QOF_EVENT_DESTROY))
1781 gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1786 gnc_reconcile_window_set_titles(recnData);
1787 recn_set_watches (recnData);
1789 recnRefresh (recnData);
1794close_handler (gpointer user_data)
1796 auto recnData =
static_cast<RecnWindow*
>(user_data);
1798 gnc_save_window_size(GNC_PREFS_GROUP_RECONCILE, GTK_WINDOW(recnData->window));
1799 gtk_widget_destroy (recnData->window);
1812recnWindow (GtkWidget *parent,
Account *account)
1814 gnc_numeric new_ending;
1815 gboolean enable_subaccounts;
1818 if (account == NULL)
1828 if (!gnc_reconcile_last_statement_date)
1831 statement_date = gnc_reconcile_last_statement_date;
1833 gnc_get_reconcile_info (account, &new_ending, &statement_date);
1835 enable_subaccounts = !has_account_different_commodities(account);
1838 if (!startRecnWindow (parent, account, &new_ending, &statement_date,
1839 enable_subaccounts))
1842 return recnWindowWithBalance (parent, account, new_ending, statement_date);
1846static GActionEntry recWindow_actions_entries [] =
1848 {
"RecnChangeInfoAction", gnc_ui_reconcile_window_change_cb, NULL, NULL, NULL },
1849 {
"RecnFinishAction", recnFinishCB, NULL, NULL, NULL },
1850 {
"RecnPostponeAction", recnPostponeCB, NULL, NULL, NULL },
1851 {
"RecnCancelAction", recnCancelCB, NULL, NULL, NULL },
1852 {
"RecnAutoClearAction", recnAutoClearCB, NULL, NULL, NULL },
1854 {
"AccountOpenAccountAction", gnc_recn_open_cb, NULL, NULL, NULL },
1855 {
"AccountEditAccountAction", gnc_recn_edit_account_cb, NULL, NULL, NULL },
1856 {
"AccountTransferAction", gnc_recn_xfer_cb, NULL, NULL, NULL },
1857 {
"AccountCheckRepairAction", gnc_recn_scrub_cb, NULL, NULL, NULL },
1859 {
"TransBalanceAction", gnc_ui_reconcile_window_balance_cb, NULL, NULL, NULL },
1860 {
"TransEditAction", gnc_ui_reconcile_window_edit_cb, NULL, NULL, NULL },
1861 {
"TransDeleteAction", gnc_ui_reconcile_window_delete_cb, NULL, NULL, NULL },
1862 {
"TransRecAction", gnc_ui_reconcile_window_rec_cb, NULL, NULL, NULL },
1863 {
"TransUnRecAction", gnc_ui_reconcile_window_unrec_cb, NULL, NULL, NULL },
1865 {
"HelpHelpAction", gnc_ui_reconcile_window_help_cb, NULL, NULL, NULL },
1868static guint recnWindow_n_actions_entries = G_N_ELEMENTS(recWindow_actions_entries);
1870#ifdef MAC_INTEGRATION
1873can_activate_cb(GtkWidget *widget, guint signal_id, gpointer data)
1893recnWindowWithBalance (GtkWidget *parent,
Account *account, gnc_numeric new_ending,
1896 RecnWindow *recnData;
1897 GtkWidget *statusbar;
1901 if (account == NULL)
1904 recnData =
static_cast<RecnWindow*
>(gnc_find_first_gui_component (WINDOW_RECONCILE_CM_CLASS,
1905 find_by_account, account));
1909 recnData = g_new0 (RecnWindow, 1);
1914 recnData->component_id =
1915 gnc_register_gui_component (WINDOW_RECONCILE_CM_CLASS,
1916 refresh_handler, close_handler,
1918 gnc_gui_component_set_session (recnData->component_id, gnc_get_current_session());
1920 recn_set_watches (recnData);
1922 gnc_reconcile_last_statement_date = statement_date;
1924 recnData->new_ending = new_ending;
1925 recnData->statement_date = statement_date;
1926 recnData->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1927 recnData->delete_refresh = FALSE;
1928 new (&recnData->autoclear_splits) SplitsVec();
1929 new (&recnData->initially_cleared_splits) SplitsVec();
1931 gnc_recn_set_window_name(recnData);
1933 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1934 gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE);
1935 gtk_container_add(GTK_CONTAINER(recnData->window), vbox);
1938 gtk_widget_set_name (GTK_WIDGET(recnData->window),
"gnc-id-reconcile");
1940 dock = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1941 gtk_box_set_homogeneous (GTK_BOX (dock), FALSE);
1942 gtk_widget_show(dock);
1943 gtk_box_pack_start(GTK_BOX (vbox), dock, FALSE, TRUE, 0);
1945 auto init_cleared = [&recnData](Split* s)
1948 recnData->initially_cleared_splits.push_back (s);
1950 gnc_account_foreach_split_until_date (account, statement_date, init_cleared);
1953 GtkToolbar *tool_bar;
1954 GMenuModel *menu_model;
1955 GtkWidget *menu_bar;
1956 const gchar *ui = GNUCASH_RESOURCE_PREFIX
"/gnc-reconcile-window.ui";
1957 GError *error = NULL;
1959 recnData->accel_group = gtk_accel_group_new ();
1960 recnData->builder = gtk_builder_new ();
1962 gtk_builder_add_from_resource (recnData->builder, ui, &error);
1964 gtk_builder_set_translation_domain (recnData->builder, PROJECT_NAME);
1968 g_critical (
"Failed to load ui resource %s, Error %s", ui, error->message);
1969 g_error_free (error);
1970 gnc_unregister_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1975 recnData->autoclear_button = GTK_WIDGET(gtk_builder_get_object(recnData->builder,
"autoclear_button"));
1977 menu_model = (GMenuModel *)gtk_builder_get_object (recnData->builder,
"recwin-menu");
1978 menu_bar = gtk_menu_bar_new_from_model (menu_model);
1979 gtk_container_add (GTK_CONTAINER(vbox), menu_bar);
1980#ifdef MAC_INTEGRATION
1981 auto theApp =
static_cast<GtkosxApplication*
>(g_object_new (GTKOSX_TYPE_APPLICATION, NULL));
1982 gtk_widget_hide (menu_bar);
1983 gtk_widget_set_no_show_all (menu_bar, TRUE);
1984 if (GTK_IS_MENU_ITEM (menu_bar))
1985 menu_bar = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_bar));
1987 gtkosx_application_set_menu_bar (theApp, GTK_MENU_SHELL (menu_bar));
1989 tool_bar = (GtkToolbar *)gtk_builder_get_object (recnData->builder,
"recwin-toolbar");
1991 gtk_toolbar_set_style (GTK_TOOLBAR(tool_bar), GTK_TOOLBAR_BOTH);
1992 gtk_toolbar_set_icon_size (GTK_TOOLBAR(tool_bar),
1993 GTK_ICON_SIZE_SMALL_TOOLBAR);
1995 gtk_container_add (GTK_CONTAINER(vbox), GTK_WIDGET(tool_bar));
1997 gtk_window_add_accel_group (GTK_WINDOW(recnData->window), recnData->accel_group);
2002#ifdef MAC_INTEGRATION
2003 gtkosx_application_sync_menubar (theApp);
2004 g_signal_connect (menu_bar,
"can-activate-accel",
2005 G_CALLBACK(can_activate_cb), NULL);
2006 g_object_unref (theApp);
2010 recnData->simple_action_group = g_simple_action_group_new ();
2012 g_action_map_add_action_entries (G_ACTION_MAP(recnData->simple_action_group),
2013 recWindow_actions_entries,
2014 recnWindow_n_actions_entries,
2017 gtk_widget_insert_action_group (GTK_WIDGET(recnData->window),
"recwin",
2018 G_ACTION_GROUP(recnData->simple_action_group));
2021 g_signal_connect(recnData->window,
"popup-menu",
2022 G_CALLBACK(gnc_reconcile_window_popup_menu_cb), recnData);
2024 statusbar = gtk_statusbar_new();
2025 gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
2027 g_signal_connect (recnData->window,
"destroy",
2028 G_CALLBACK(recn_destroy_cb), recnData);
2029 g_signal_connect (recnData->window,
"delete_event",
2030 G_CALLBACK(recn_delete_cb), recnData);
2031 g_signal_connect (recnData->window,
"key_press_event",
2032 G_CALLBACK(recn_key_press_cb), recnData);
2038 GtkStatusbar *bar = GTK_STATUSBAR (statusbar);
2039 guint context = gtk_statusbar_get_context_id (bar,
"future_dates");
2040 GtkWidget *box = gtk_statusbar_get_message_area (bar);
2041 GtkWidget *image = gtk_image_new_from_icon_name
2042 (
"dialog-warning", GTK_ICON_SIZE_SMALL_TOOLBAR);
2046 auto has_later_recn_statement_date = [statement_date](
const Split *split)
2054 PWARN (
"split posting_date=%s, recn_date=%s", datestr, recnstr);
2056 gtk_statusbar_push (bar, context,
_(
"WARNING! Account contains \
2057splits whose reconcile date is after statement date. Reconciliation may be \
2060 gtk_widget_set_tooltip_text (GTK_WIDGET (bar),
_(
"This account \
2061has splits whose Reconciled Date is after this reconciliation statement date. \
2062These splits may make reconciliation difficult. If this is the case, you may \
2063use Find Transactions to find them, unreconcile, and re-reconcile."));
2065 gtk_box_pack_start (GTK_BOX(box), image, FALSE, FALSE, 0);
2066 gtk_box_reorder_child (GTK_BOX(box), image, 0);
2075 GtkWidget *frame = gtk_frame_new(NULL);
2076 GtkWidget *main_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
2077 GtkWidget *debcred_area = gtk_grid_new ();
2078 GtkWidget *debits_box;
2079 GtkWidget *credits_box;
2081 gtk_box_set_homogeneous (GTK_BOX (main_area), FALSE);
2082 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 10);
2085 gtk_window_set_default_size(GTK_WINDOW(recnData->window), 800, 600);
2086 gnc_restore_window_size (GNC_PREFS_GROUP_RECONCILE,
2087 GTK_WINDOW(recnData->window), GTK_WINDOW(parent));
2089 gtk_container_add(GTK_CONTAINER(frame), main_area);
2090 gtk_container_set_border_width(GTK_CONTAINER(main_area), 10);
2092 debits_box = gnc_reconcile_window_create_view_box
2093 (account, RECLIST_DEBIT, recnData,
2094 &recnData->debit, &recnData->total_debit);
2097 gnc_widget_style_context_add_class (GTK_WIDGET(debits_box),
"gnc-class-debits");
2099 credits_box = gnc_reconcile_window_create_view_box
2100 (account, RECLIST_CREDIT, recnData,
2101 &recnData->credit, &recnData->total_credit);
2104 gnc_widget_style_context_add_class (GTK_WIDGET(credits_box),
"gnc-class-credits");
2106 GNC_RECONCILE_VIEW(recnData->debit)->sibling = GNC_RECONCILE_VIEW(recnData->credit);
2107 GNC_RECONCILE_VIEW(recnData->credit)->sibling = GNC_RECONCILE_VIEW(recnData->debit);
2109 gtk_box_pack_start(GTK_BOX(main_area), debcred_area, TRUE, TRUE, 0);
2111 gtk_grid_set_column_homogeneous (GTK_GRID(debcred_area), TRUE);
2112 gtk_grid_set_column_spacing (GTK_GRID(debcred_area), 15);
2113 gtk_grid_attach (GTK_GRID(debcred_area), debits_box, 0, 0, 1, 1);
2114 gtk_widget_set_hexpand (debits_box, TRUE);
2115 gtk_widget_set_vexpand (debits_box, TRUE);
2116 gtk_widget_set_halign (debits_box, GTK_ALIGN_FILL);
2117 gtk_widget_set_valign (debits_box, GTK_ALIGN_FILL);
2119 gtk_grid_attach (GTK_GRID(debcred_area), credits_box, 1, 0, 1, 1);
2120 gtk_widget_set_hexpand (credits_box, TRUE);
2121 gtk_widget_set_vexpand (credits_box, TRUE);
2122 gtk_widget_set_halign (credits_box, GTK_ALIGN_FILL);
2123 gtk_widget_set_valign (credits_box, GTK_ALIGN_FILL);
2126 GtkWidget *hbox, *title_vbox, *value_vbox;
2127 GtkWidget *totals_hbox, *frame, *title, *value;
2130 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
2131 gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
2132 gtk_box_pack_start(GTK_BOX(main_area), hbox, FALSE, FALSE, 0);
2135 frame = gtk_frame_new(NULL);
2136 gtk_box_pack_end(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
2139 gtk_widget_set_name (GTK_WIDGET(frame),
"gnc-id-reconcile-totals");
2142 totals_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2143 gtk_box_set_homogeneous (GTK_BOX (totals_hbox), FALSE);
2144 gtk_container_add(GTK_CONTAINER(frame), totals_hbox);
2145 gtk_container_set_border_width(GTK_CONTAINER(totals_hbox), 5);
2148 title_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2149 gtk_box_set_homogeneous (GTK_BOX (title_vbox), FALSE);
2150 gtk_box_pack_start(GTK_BOX(totals_hbox), title_vbox, FALSE, FALSE, 0);
2153 value_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2154 gtk_box_set_homogeneous (GTK_BOX (value_vbox), FALSE);
2155 gtk_box_pack_start(GTK_BOX(totals_hbox), value_vbox, TRUE, TRUE, 0);
2158 title = gtk_label_new(
_(
"Statement Date"));
2159 gnc_label_set_alignment(title, 1.0, 0.5);
2160 gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2162 value = gtk_label_new(
"");
2163 recnData->recn_date = value;
2164 gnc_label_set_alignment(value, 1.0, 0.5);
2165 gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2168 title = gtk_label_new(
_(
"Starting Balance"));
2169 gnc_label_set_alignment(title, 1.0, 0.5);
2170 gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 3);
2172 value = gtk_label_new(
"");
2173 recnData->starting = value;
2174 gnc_label_set_alignment(value, 1.0, 0.5);
2175 gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 3);
2178 title = gtk_label_new(
_(
"Ending Balance"));
2179 gnc_label_set_alignment(title, 1.0, 0.5);
2180 gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2182 value = gtk_label_new(
"");
2183 recnData->ending = value;
2184 gnc_label_set_alignment(value, 1.0, 0.5);
2185 gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2188 title = gtk_label_new(
_(
"Reconciled Balance"));
2189 gnc_label_set_alignment(title, 1.0, 0.5);
2190 gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2192 value = gtk_label_new(
"");
2193 recnData->reconciled = value;
2194 gnc_label_set_alignment(value, 1.0, 0.5);
2195 gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2198 title = gtk_label_new(
_(
"Difference"));
2199 gnc_label_set_alignment(title, 1.0, 0.5);
2200 gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2202 value = gtk_label_new(
"");
2203 recnData->difference = value;
2204 gnc_label_set_alignment(value, 1.0, 0.5);
2205 gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2209 recnRefresh (recnData);
2213 gtk_window_set_resizable(GTK_WINDOW(recnData->window), TRUE);
2214 gtk_widget_show_all(recnData->window);
2216 gnc_reconcile_window_set_titles(recnData);
2218 recnRecalculateBalance(recnData);
2220 gnc_window_adjust_for_screen(GTK_WINDOW(recnData->window));
2223 gnc_query_sort_order(GNC_QUERY_VIEW(recnData->debit), REC_DATE, GTK_SORT_ASCENDING);
2224 gnc_query_sort_order(GNC_QUERY_VIEW(recnData->credit), REC_DATE, GTK_SORT_ASCENDING);
2226 gtk_widget_grab_focus (recnData->debit);
2229 gint recn_widthc = gnc_reconcile_view_get_column_width (GNC_RECONCILE_VIEW(recnData->credit), REC_RECN);
2230 gint recn_widthd = gnc_reconcile_view_get_column_width (GNC_RECONCILE_VIEW(recnData->debit), REC_RECN);
2232 gtk_widget_set_margin_end (GTK_WIDGET(recnData->total_credit), 10 + recn_widthc);
2233 gtk_widget_set_margin_end (GTK_WIDGET(recnData->total_debit), 10 + recn_widthd);
2246gnc_ui_reconcile_window_raise(RecnWindow * recnData)
2248 if (recnData == NULL)
2251 if (recnData->window == NULL)
2254 gtk_window_present(GTK_WINDOW(recnData->window));
2258gnc_ui_reconcile_window_get_window (RecnWindow * recnData)
2260 if (recnData == NULL || recnData->window == NULL)
2262 return GTK_WINDOW(recnData->window);
2277recn_destroy_cb (GtkWidget *w, gpointer data)
2279 auto recnData =
static_cast<RecnWindow*
>(data);
2280 gchar **actions = g_action_group_list_actions (G_ACTION_GROUP(recnData->simple_action_group));
2281 gint num_actions = g_strv_length (actions);
2283 gnc_unregister_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2285 if (recnData->delete_refresh)
2286 gnc_resume_gui_refresh ();
2288 if (recnData->builder)
2289 g_object_unref(recnData->builder);
2291 if (recnData->accel_group)
2292 g_object_unref(recnData->accel_group);
2294 recnData->autoclear_splits.~SplitsVec();
2295 recnData->initially_cleared_splits.~SplitsVec();
2298 for (gint i = 0; i < num_actions; i++)
2300 GAction *action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group), actions[i]);
2301 g_simple_action_set_enabled (G_SIMPLE_ACTION(action), FALSE);
2303 g_strfreev (actions);
2309recn_cancel(RecnWindow *recnData)
2311 gboolean changed = FALSE;
2313 if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->credit)))
2315 if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->debit)))
2320 const char *message =
_(
"You have made changes to this reconcile "
2321 "window. Are you sure you want to cancel?");
2322 if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE,
"%s", message))
2326 gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2331recn_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
2333 auto recnData =
static_cast<RecnWindow*
>(data);
2335 recn_cancel(recnData);
2341recn_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
2343 auto recnData =
static_cast<RecnWindow*
>(data);
2345 if (event->keyval == GDK_KEY_Escape)
2347 recn_cancel(recnData);
2367find_payment_account(
Account *account)
2369 if (account ==
nullptr)
2372 const auto& splits = xaccAccountGetSplits (account);
2375 for (
auto it = splits.rbegin(); it != splits.rend(); it++)
2385 auto s = GNC_SPLIT(n->data);
2394 if (type == ACCT_TYPE_BANK || type == ACCT_TYPE_CASH || type == ACCT_TYPE_ASSET)
2403acct_traverse_descendants (
Account *acct, std::function<
void(
Account*)> fn)
2407 gnc_account_foreach_descendant (acct, fn);
2419recnFinishCB (GSimpleAction *simple,
2420 GVariant *parameter,
2423 auto recnData =
static_cast<RecnWindow*
>(user_data);
2424 gboolean auto_payment;
2430 const char *message =
_(
"The account is not balanced. "
2431 "Are you sure you want to finish?");
2432 if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE,
"%s", message))
2436 date = recnData->statement_date;
2438 gnc_suspend_gui_refresh ();
2440 recnData->delete_refresh = TRUE;
2441 account = recn_get_account (recnData);
2444 gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->credit), date);
2445 gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->debit), date);
2448 auto_payment =
gnc_prefs_get_bool(GNC_PREFS_GROUP_RECONCILE, GNC_PREF_AUTO_CC_PAYMENT);
2462 gnc_xfer_dialog_set_amount(xfer,
gnc_numeric_neg (recnData->new_ending));
2464 payment_account = find_payment_account (account);
2465 if (payment_account != NULL)
2466 gnc_xfer_dialog_select_from_account (xfer, payment_account);
2469 gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2482recnPostponeCB (GSimpleAction *simple,
2483 GVariant *parameter,
2486 auto recnData =
static_cast<RecnWindow*
>(user_data);
2490 const char *message =
_(
"Do you want to postpone this reconciliation "
2491 "and finish it later?");
2492 if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE,
"%s", message))
2496 gnc_suspend_gui_refresh ();
2498 recnData->delete_refresh = TRUE;
2499 account = recn_get_account (recnData);
2502 gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->credit));
2503 gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->debit));
2509 gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2514recnCancelCB (GSimpleAction *simple,
2515 GVariant *parameter,
2518 auto recnData =
static_cast<RecnWindow*
>(user_data);
2519 recn_cancel(recnData);
2532recnAutoClearCB (GSimpleAction *simple,
2533 GVariant *parameter,
2536 auto recnData =
static_cast<RecnWindow*
>(user_data);
2538 if (recnData->autoclear_splits.empty())
2541 gnc_suspend_gui_refresh ();
2542 gnc_reconcile_view_unclear_all (GNC_RECONCILE_VIEW(recnData->debit));
2543 gnc_reconcile_view_unclear_all (GNC_RECONCILE_VIEW(recnData->credit));
2544 std::for_each (recnData->autoclear_splits.begin(),
2545 recnData->autoclear_splits.end(),
2546 [recnData](Split* split)
2548 auto view = gnc_numeric_positive_p (xaccSplitGetAmount (split))
2549 ? recnData->debit : recnData->credit;
2550 gnc_reconcile_view_set_cleared (GNC_RECONCILE_VIEW(view), split);
2552 recnRefresh (recnData);
2553 gnc_resume_gui_refresh ();
Account public routines (C++ api)
High-Level API for imposing Lot constraints.
convert single-entry accounts to clean double-entry
This file contains the functions to present a gui to the user for creating a new account or editing a...
Date and Time handling routines.
Additional event handling code.
File path resolution utility functions.
Gnome specific utility functions.
Functions providing a register page for the GnuCash UI.
Generic api to store and retrieve preferences.
Functions that are supported by all types of windows.
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.
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
GList * gnc_account_get_descendants(const Account *account)
This routine returns a flat list of all of the accounts that are descendants of the specified account...
gnc_numeric xaccAccountGetBalanceAsOfDate(Account *acc, time64 date)
Get the balance of the account at the end of the day before the date specified.
#define xaccAccountGetGUID(X)
gboolean xaccAccountGetReconcileChildrenStatus(const Account *acc)
DOCUMENT ME!
Split * gnc_account_find_split(const Account *acc, std::function< bool(const Split *)> predicate, bool reverse)
scans account split list (in forward or reverse order) until predicate split->bool returns true.
void xaccAccountSetReconcileChildrenStatus(Account *acc, gboolean status)
DOCUMENT ME!
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling 'func' on each...
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id,...
@ ACCT_TYPE_NONE
Not a type.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
struct tm * gnc_localtime_r(const time64 *secs, struct tm *time)
fill out a time struct from a 64-bit time value adjusted for the current time zone.
void gnc_gdate_set_time64(GDate *gd, time64 time)
Set a GDate to a time64.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
size_t qof_print_date_buff(char *buff, const size_t len, time64 t)
Convenience: calls through to qof_print_date_dmy_buff().
char * qof_print_date(time64 t)
Convenience; calls through to qof_print_date_dmy_buff().
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
time64 gnc_time64_get_day_end_gdate(const GDate *date)
The gnc_time64_get_day_end() routine will take the given time in GLib GDate format and adjust it to t...
time64 gnc_time64_get_today_end(void)
The gnc_time64_get_today_end() routine returns a time64 value corresponding to the last second of tod...
const char * gnc_account_get_credit_string(GNCAccountType acct_type)
Get the credit string associated with this account type.
gboolean xaccAccountGetAutoInterest(const Account *acc)
Get the "auto interest" flag for an account.
gboolean xaccAccountGetReconcilePostponeDate(const Account *acc, time64 *postpone_date)
DOCUMENT ME!
void xaccTransDestroy(Transaction *trans)
Destroys a transaction.
const char * gnc_account_get_debit_string(GNCAccountType acct_type)
Get the debit string associated with this account type.
void xaccAccountSetReconcileLastInterval(Account *acc, int months, int days)
DOCUMENT ME!
void xaccAccountSetReconcileLastDate(Account *acc, time64 last_date)
DOCUMENT ME!
void xaccAccountSetReconcilePostponeDate(Account *acc, time64 postpone_date)
DOCUMENT ME!
#define xaccTransGetGUID(X)
gboolean xaccAccountGetReconcileLastInterval(const Account *acc, int *months, int *days)
DOCUMENT ME!
void xaccAccountSetReconcilePostponeBalance(Account *acc, gnc_numeric balance)
DOCUMENT ME!
gboolean xaccAccountGetReconcilePostponeBalance(const Account *acc, gnc_numeric *balance)
DOCUMENT ME!
gboolean xaccAccountGetReconcileLastDate(const Account *acc, time64 *last_date)
DOCUMENT ME!
void xaccAccountClearReconcilePostpone(Account *acc)
DOCUMENT ME!
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
void gnc_add_accelerator_keys_for_menu(GtkWidget *menu, GMenuModel *model, GtkAccelGroup *accel_group)
Add accelerator keys for menu item widgets.
void gnc_ui_edit_account_window(GtkWindow *parent, Account *account)
Display a window for editing the attributes of an existing account.
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...
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
#define PWARN(format, args...)
Log a warning.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
void gnc_plugin_page_register_clear_current_filter(GncPluginPage *plugin_page)
This function clears the registers current filter.
GncPluginPage * gnc_plugin_page_register_new(Account *account, gboolean subaccounts)
Create a new "register" plugin page, given a pointer to an account.
GNCSplitReg * gnc_plugin_page_register_get_gsr(GncPluginPage *plugin_page)
Get the GNCSplitReg data structure associated with this register page.
void xaccAccountTreeScrubOrphans(Account *acc, QofPercentageFunc percentagefunc)
The xaccAccountTreeScrubOrphans() method performs this scrub for the indicated account and its childr...
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
time64 xaccSplitGetDateReconciled(const Split *split)
Retrieve the date when the Split was reconciled.
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
#define CREC
The Split has been cleared
#define YREC
The Split has been reconciled.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
The type used to store guids in C.
The instance data structure for a content plugin.