GnuCash  5.6-150-g038405b370+
window-reconcile.cpp
1 /********************************************************************\
2  * window-reconcile.c -- the reconcile window *
3  * Copyright (C) 1997 Robin D. Clark *
4  * Copyright (C) 1998-2000 Linas Vepstas *
5  * Copyright (C) 2002 Christian Stimming *
6  * Copyright (C) 2006 David Hampton *
7  * *
8  * This program is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License as *
10  * published by the Free Software Foundation; either version 2 of *
11  * the License, or (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License*
19  * along with this program; if not, contact: *
20  * *
21  * Free Software Foundation Voice: +1-617-542-5942 *
22  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
23  * Boston, MA 02110-1301, USA gnu@gnu.org *
24  * *
25  * Author: Rob Clark *
26  * Internet: rclark@cs.hmc.edu *
27  * Address: 609 8th Street *
28  * Huntington Beach, CA 92648-4632 *
29 \********************************************************************/
30 
31 #include <config.h>
32 
33 #include <gtk/gtk.h>
34 #include <glib/gi18n.h>
35 #ifdef __G_IR_SCANNER__
36 #undef __G_IR_SCANNER__
37 #endif
38 #include <gdk/gdkkeysyms.h>
39 
40 #include "Account.hpp"
41 #include "Scrub.h"
42 #include "Scrub3.h"
43 #include "dialog-account.h"
44 #include "dialog-transfer.h"
45 #include "dialog-utils.h"
46 #include "gnc-amount-edit.h"
47 #include "gnc-component-manager.h"
48 #include "gnc-date.h"
49 #include "gnc-date-edit.h"
50 #include "gnc-event.h"
51 #include "gnc-filepath-utils.h"
52 #include "gnc-gnome-utils.h"
53 #include "gnc-gtk-utils.h"
54 //#include "gnc-main-window.h"
56 #include "gnc-prefs.h"
57 #include "gnc-ui.h"
58 #include "gnc-ui-balances.h"
59 #include "gnc-window.h"
60 #include "reconcile-view.h"
61 #include "window-reconcile.h"
62 #include "gnc-session.h"
63 #ifdef MAC_INTEGRATION
64 #include <gtkmacintegration/gtkosxapplication.h>
65 #endif
66 
67 #define WINDOW_RECONCILE_CM_CLASS "window-reconcile"
68 #define GNC_PREF_AUTO_CC_PAYMENT "auto-cc-payment"
69 #define GNC_PREF_ALWAYS_REC_TO_TODAY "always-reconcile-to-today"
70 
71 
74 {
75  GncGUID account; /* The account that we are reconciling */
76  gnc_numeric new_ending; /* The new ending balance */
77  time64 statement_date; /* The statement date */
78 
79  gint component_id; /* id of component */
80 
81  GtkWidget *window; /* The reconcile window */
82 
83  GtkBuilder *builder; /* The builder object */
84  GSimpleActionGroup *simple_action_group; /* The action group for the window */
85 
86  GncPluginPage *page;
87 
88  GtkWidget *starting; /* The starting balance */
89  GtkWidget *ending; /* The ending balance */
90  GtkWidget *recn_date; /* The statement date */
91  GtkWidget *reconciled; /* The reconciled balance */
92  GtkWidget *difference; /* Text field, amount left to reconcile */
93 
94  GtkWidget *total_debit; /* Text field, total debit reconciled */
95  GtkWidget *total_credit; /* Text field, total credit reconciled */
96 
97  GtkWidget *debit; /* Debit matrix show unreconciled debit */
98  GtkWidget *credit; /* Credit matrix, shows credits... */
99 
100  GtkWidget *debit_frame; /* Frame around debit matrix */
101  GtkWidget *credit_frame; /* Frame around credit matrix */
102 
103  gboolean delete_refresh; /* do a refresh upon a window deletion */
104 };
105 
106 
107 /* This structure doesn't contain everything involved in the
108  * startRecnWindow, just pointers that have to be passed in to
109  * callbacks that need more than one piece of data to operate on.
110  * This is also used by the interest transfer dialog code.
111  */
112 typedef struct _startRecnWindowData
113 {
114  Account *account; /* the account being reconciled */
115  GNCAccountType account_type; /* the type of the account */
116 
117  GtkWidget *startRecnWindow; /* the startRecnWindow dialog */
118  GtkWidget *xfer_button; /* the dialog's interest transfer button */
119  GtkWidget *date_value; /* the dialog's ending date field */
120  GtkWidget *future_icon;
121  GtkWidget *future_text;
122  GNCAmountEdit *end_value; /* the dialog's ending balance amount edit */
123  gnc_numeric original_value; /* the dialog's original ending balance */
124  gboolean user_set_value; /* the user changed the ending value */
125 
126  XferDialog *xferData; /* the interest xfer dialog (if it exists) */
127  gboolean include_children;
128 
129  time64 date; /* the interest xfer reconcile date */
131 
133 static gnc_numeric recnRecalculateBalance (RecnWindow *recnData);
134 
135 static void recn_destroy_cb (GtkWidget *w, gpointer data);
136 static void recn_cancel (RecnWindow *recnData);
137 static gboolean recn_delete_cb (GtkWidget *widget, GdkEvent *event, gpointer data);
138 static gboolean recn_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer data);
139 static void recnFinishCB (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
140 static void recnPostponeCB (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
141 static void recnCancelCB (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
142 
143 extern "C" {
144 void gnc_start_recn_children_changed (GtkWidget *widget, startRecnWindowData *data);
145 void gnc_start_recn_interest_clicked_cb (GtkButton *button, startRecnWindowData *data);
146 }
147 
148 static void gnc_reconcile_window_set_sensitivity (RecnWindow *recnData);
149 static char * gnc_recn_make_window_name (Account *account);
150 static void gnc_recn_set_window_name (RecnWindow *recnData);
151 static gboolean find_by_account (gpointer find_data, gpointer user_data);
152 
154 /* This static indicates the debugging module that this .o belongs to. */
155 G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_GUI;
156 
157 static time64 gnc_reconcile_last_statement_date = 0;
158 
161 static gpointer
162 commodity_compare(Account *account, gpointer user_data) {
163  gboolean equal = gnc_commodity_equiv (xaccAccountGetCommodity (account),
164  (gnc_commodity*) user_data);
165 
166  return equal ? NULL : account;
167 }
168 
169 
170 /********************************************************************\
171  * has_account_different_commodities *
172  * *
173  * Args: parent account - the account to look in *
174  * Return: true if there exists a subaccount with different *
175  * commodity then the parent account. *
176 \********************************************************************/
177 static gboolean
178 has_account_different_commodities(const Account *account)
179 {
180  gnc_commodity *parent_commodity;
181  gpointer result;
182 
183  if (account == NULL)
184  return FALSE;
185 
186  parent_commodity = xaccAccountGetCommodity (account);
187 
188  result = gnc_account_foreach_descendant_until (account,
189  commodity_compare,
190  parent_commodity);
191 
192  return result != NULL;
193 }
194 
195 
196 /********************************************************************\
197  * recnRefresh *
198  * refreshes the transactions in the reconcile window *
199  * *
200  * Args: account - the account of the reconcile window to refresh *
201  * Return: none *
202 \********************************************************************/
203 static void
204 recnRefresh (RecnWindow *recnData)
205 {
206  if (recnData == NULL)
207  return;
208 
209  gnc_reconcile_view_refresh(GNC_RECONCILE_VIEW(recnData->debit));
210  gnc_reconcile_view_refresh(GNC_RECONCILE_VIEW(recnData->credit));
211 
212  gnc_reconcile_window_set_sensitivity(recnData);
213 
214  gnc_recn_set_window_name(recnData);
215 
216  recnRecalculateBalance(recnData);
217 
218  gtk_widget_queue_resize(recnData->window);
219 }
220 
221 
222 static Account *
223 recn_get_account (RecnWindow *recnData)
224 {
225  if (!recnData)
226  return NULL;
227 
228  return xaccAccountLookup (&recnData->account, gnc_get_current_book ());
229 }
230 
231 
232 static void
233 gnc_add_colorized_amount (gpointer obj, gnc_numeric amt,
234  GNCPrintAmountInfo print_info, gboolean reverse)
235 {
236  if (!obj) return;
237  if (reverse) amt = gnc_numeric_neg (amt);
238  gnc_set_label_color (GTK_WIDGET (obj), amt);
239  gtk_label_set_text (GTK_LABEL (obj), xaccPrintAmount (amt, print_info));
240 }
241 
242 /********************************************************************\
243  * recnRecalculateBalance *
244  * refreshes the balances in the reconcile window *
245  * *
246  * Args: recnData -- the reconcile window to refresh *
247  * Return: the difference between the nominal ending balance *
248  * and the 'effective' ending balance. *
249 \********************************************************************/
250 static gnc_numeric
251 recnRecalculateBalance (RecnWindow *recnData)
252 {
253  Account *account;
254  gnc_numeric debit;
255  gnc_numeric credit;
256  gnc_numeric starting;
257  gnc_numeric ending;
258  gnc_numeric reconciled;
259  gnc_numeric diff;
260  gchar *datestr;
261  GNCPrintAmountInfo print_info;
262  gboolean reverse_balance, include_children;
263  GAction *action;
264 
265  account = recn_get_account (recnData);
266  if (!account)
267  return gnc_numeric_zero ();
268 
269  reverse_balance = gnc_reverse_balance(account);
270  include_children = xaccAccountGetReconcileChildrenStatus(account);
271  starting = gnc_ui_account_get_reconciled_balance(account, include_children);
272  print_info = gnc_account_print_info (account, TRUE);
273 
274  ending = recnData->new_ending;
275  debit = gnc_reconcile_view_reconciled_balance
276  (GNC_RECONCILE_VIEW(recnData->debit));
277  credit = gnc_reconcile_view_reconciled_balance
278  (GNC_RECONCILE_VIEW(recnData->credit));
279 
280  reconciled = gnc_numeric_sub_fixed (debit, credit);
281  if (reverse_balance)
282  reconciled = gnc_numeric_sub_fixed (reconciled, starting);
283  else
284  reconciled = gnc_numeric_add_fixed (reconciled, starting);
285 
286  diff = gnc_numeric_sub_fixed (ending, reconciled);
287 
288  datestr = qof_print_date (recnData->statement_date);
289  gtk_label_set_text (GTK_LABEL(recnData->recn_date), datestr);
290  g_free (datestr);
291 
292  gnc_add_colorized_amount (recnData->starting, starting, print_info, FALSE);
293  gnc_add_colorized_amount (recnData->ending, ending, print_info, reverse_balance);
294  gnc_add_colorized_amount (recnData->total_debit, debit, print_info, FALSE);
295  gnc_add_colorized_amount (recnData->total_credit, credit, print_info, FALSE);
296  gnc_add_colorized_amount (recnData->reconciled, reconciled, print_info, reverse_balance);
297  gnc_add_colorized_amount (recnData->difference, diff, print_info, reverse_balance);
298 
299  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
300  "RecnFinishAction");
301  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), gnc_numeric_zero_p (diff));
302 
303  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
304  "TransBalanceAction");
305  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), !gnc_numeric_zero_p (diff));
306 
307  return diff;
308 }
309 
310 
311 /* amount_edit_focus_out_cb
312  * Callback on focus-out event for statement Ending Balance.
313  * Sets the user_set_value flag true if the amount entered is
314  * different to the calculated Ending Balance as at the default
315  * Statement Date. This prevents the entered Ending Balance
316  * being recalculated if the Statement Date is changed.
317  *
318  * Args: widget - Ending Balance widget
319  * event - event triggering this callback
320  * data - structure containing info about this
321  * reconciliation process.
322  * Returns: False - propagate the event to the widget's parent.
323  */
324 static gboolean
325 amount_edit_focus_out_cb(GtkWidget *widget, GdkEventFocus *event,
326  startRecnWindowData *data)
327 {
328  gnc_numeric value;
329  gint result = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(data->end_value),
330  &value, TRUE, NULL);
331 
332  data->user_set_value = FALSE;
333 
334  if (result < 1) // OK
335  {
336  if (result == -1) // blank entry is valid
337  {
338  gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(data->end_value), value);
339  gnc_amount_edit_select_region (GNC_AMOUNT_EDIT(data->end_value), 0, -1);
340  }
341  data->user_set_value = !gnc_numeric_equal (value, data->original_value);
342  }
343  return FALSE;
344 }
345 
346 
347 /* recn_date_changed_cb
348  * Callback on date_changed event for Statement Date.
349  * If the user changed the date edit widget, and the Ending
350  * Balance wasn't entered, update the Ending Balance to reflect
351  * the ending balance of the account as at Statement Date.
352  *
353  * Args: widget - Statement Date edit widget
354  * data - structure containing info about this
355  * reconciliation.
356  * Returns: none.
357  */
358 static void
359 recn_date_changed_cb (GtkWidget *widget, startRecnWindowData *data)
360 {
361  GNCDateEdit *gde = GNC_DATE_EDIT (widget);
362  gnc_numeric new_balance;
363  time64 new_date;
364 
365  gboolean show_warning = FALSE;
366  gint days_after_today;
367  static const time64 secs_per_day = 86400;
368  static const time64 secs_per_hour = 3600;
369 
370  new_date = gnc_date_edit_get_date_end (gde);
371 
372  /* Add secs_per_hour to the difference to compensate for the short
373  * day when transitioning from standard to daylight time.
374  */
375  days_after_today = (gnc_time64_get_day_end (new_date) -
377  secs_per_hour) / secs_per_day;
378 
379  if (days_after_today > 0)
380  {
381  gchar *str = g_strdup_printf
382  /* Translators: %d is the number of days in the future */
383  (ngettext ("Statement Date is %d day after today.",
384  "Statement Date is %d days after today.",
385  days_after_today),
386  days_after_today);
387 
388  gchar *tip_start = g_strdup_printf
389  /* Translators: %d is the number of days in the future */
390  (ngettext ("The statement date you have chosen is %d day in the future.",
391  "The statement date you have chosen is %d days in the future.",
392  days_after_today),
393  days_after_today);
394 
395  gchar *tip_end = g_strdup (_("This may cause issues for future reconciliation \
396 actions on this account. Please double-check this is the date you intended."));
397  gchar *tip = g_strdup_printf ("%s %s", tip_start, tip_end);
398 
399  show_warning = TRUE;
400 
401  gtk_label_set_text (GTK_LABEL(data->future_text), str);
402  gtk_widget_set_tooltip_text (GTK_WIDGET(data->future_text), tip);
403  g_free (str);
404  g_free (tip_end);
405  g_free (tip_start);
406  g_free (tip);
407  }
408  gtk_widget_set_visible (GTK_WIDGET(data->future_icon), show_warning);
409  gtk_widget_set_visible (GTK_WIDGET(data->future_text), show_warning);
410 
411  if (data->user_set_value)
412  return;
413 
414  /* get the balance for the account as of the new date */
415  new_balance = gnc_ui_account_get_balance_as_of_date (data->account, new_date,
416  data->include_children);
417  /* update the amount edit with the amount */
418  gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (data->end_value),
419  new_balance);
420 }
421 
422 
423 void
424 gnc_start_recn_children_changed (GtkWidget *widget, startRecnWindowData *data)
425 {
426  data->include_children =
427  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
428 
429  /* Force an update of the ending balance */
430  recn_date_changed_cb (data->date_value, data);
431 }
432 
433 
434 /********************************************************************\
435  * recnInterestXferWindow *
436  * opens up a window to prompt the user to enter an interest *
437  * charge or payment for an account prior to reconciling it. *
438  * Only to be called for some types of accounts, as defined *
439  * in the macros at the top of this file. *
440  * *
441  * NOTE: This function does not return until the user presses "Ok" *
442  * or "Cancel", which means that the transaction must be *
443  * resolved before the startRecnWindow will work. *
444  * *
445  * Args: data - jumbo structure containing info *
446  * about the start of the reconcile *
447  * process needed by this function. *
448  * Returns: none. *
449 \********************************************************************/
450 
451 /* helper function */
452 static char *
453 gnc_recn_make_interest_window_name(Account *account, char *text)
454 {
455  char *fullname;
456  char *title;
457 
458  fullname = gnc_account_get_full_name(account);
459  title = g_strconcat(fullname, " - ", text && *text ? _(text) : "", NULL);
460 
461  g_free(fullname);
462 
463  return title;
464 }
465 
466 
467 static void
468 recnInterestXferWindow( startRecnWindowData *data)
469 {
470  gchar *title;
471 
472  if ( !account_type_has_auto_interest_xfer( data->account_type ) )
473  return;
474 
475  /* get a normal transfer dialog... */
476  data->xferData = gnc_xfer_dialog( GTK_WIDGET(data->startRecnWindow),
477  data->account );
478 
479  /* ...and start changing things: */
480 
481  /* change title */
482  if ( account_type_has_auto_interest_payment( data->account_type ) )
483  title = gnc_recn_make_interest_window_name( data->account,
484  _("Interest Payment") );
485  else
486  title = gnc_recn_make_interest_window_name( data->account,
487  _("Interest Charge") );
488 
489  gnc_xfer_dialog_set_title( data->xferData, title );
490  g_free( title );
491 
492 
493  /* change frame labels */
494  gnc_xfer_dialog_set_information_label( data->xferData,
495  _("Payment Information") );
496 
497  /* Interest accrued is a transaction from an income account
498  * to a bank account. Interest charged is a transaction from
499  * a credit account to an expense account. The user isn't allowed
500  * to change the account (bank or credit) being reconciled.
501  */
502  if ( account_type_has_auto_interest_payment( data->account_type ) )
503  {
504  gnc_xfer_dialog_set_from_account_label( data->xferData,
505  _("Payment From") );
506  gnc_xfer_dialog_set_from_show_button_active( data->xferData, TRUE );
507 
508  // XXX: Set "from" account from previous interest payment.
509 
510  gnc_xfer_dialog_set_to_account_label( data->xferData,
511  _("Reconcile Account") );
512  gnc_xfer_dialog_select_to_account( data->xferData, data->account );
513  gnc_xfer_dialog_lock_to_account_tree( data->xferData );
514 
515  /* Quickfill based on the reconcile account, which is the "To" acct. */
516  gnc_xfer_dialog_quickfill_to_account( data->xferData, TRUE );
517  }
518  else /* interest charged to account rather than paid to it */
519  {
520  gnc_xfer_dialog_set_from_account_label( data->xferData,
521  _("Reconcile Account") );
522  gnc_xfer_dialog_select_from_account( data->xferData, data->account );
523  gnc_xfer_dialog_lock_from_account_tree( data->xferData );
524 
525  gnc_xfer_dialog_set_to_account_label( data->xferData,
526  _("Payment To") );
527  gnc_xfer_dialog_set_to_show_button_active( data->xferData, TRUE );
528 
529  // XXX: Set "to" account from previous interest payment.
530 
531  /* Quickfill based on the reconcile account, which is the "From" acct. */
532  gnc_xfer_dialog_quickfill_to_account( data->xferData, FALSE );
533  }
534 
535  /* no currency frame */
536  gnc_xfer_dialog_toggle_currency_table( data->xferData, FALSE );
537 
538  /* set the reconcile date for the transaction date */
539  gnc_xfer_dialog_set_date( data->xferData, data->date );
540 
541  /* Now run the transfer dialog. This blocks until done.
542  * If the user hit Cancel, make the button clickable so that
543  * the user can retry if they want. We don't make the button
544  * clickable if they successfully entered a transaction, since
545  * the fact that the button was clickable again might make
546  * the user think that the transaction didn't actually go through.
547  */
548  if ( ! gnc_xfer_dialog_run_until_done( data->xferData ) )
549  if ( data->xfer_button )
550  gtk_widget_set_sensitive(GTK_WIDGET(data->xfer_button), TRUE);
551 
552  /* done with the XferDialog */
553  data->xferData = NULL;
554 }
555 
556 
557 /* Set up for the interest xfer window, run the window, and update
558  * the startRecnWindow if the interest xfer changed anything that matters.
559  */
560 static void
561 gnc_reconcile_interest_xfer_run(startRecnWindowData *data)
562 {
563  GtkWidget *entry = gnc_amount_edit_gtk_entry(
564  GNC_AMOUNT_EDIT(data->end_value) );
565  gnc_numeric before = gnc_amount_edit_get_amount(
566  GNC_AMOUNT_EDIT(data->end_value) );
567  gnc_numeric after;
568 
569  recnInterestXferWindow( data );
570 
571  /* recompute the ending balance */
572  after = xaccAccountGetBalanceAsOfDate(data->account, data->date);
573 
574  /* update the ending balance in the startRecnWindow if it has changed. */
575  if ( gnc_numeric_compare( before, after ) )
576  {
577  if (gnc_reverse_balance(data->account))
578  after = gnc_numeric_neg (after);
579 
580  gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (data->end_value), after);
581  gtk_widget_grab_focus(GTK_WIDGET(entry));
582  gtk_editable_select_region (GTK_EDITABLE(entry), 0, -1);
583  data->original_value = after;
584  data->user_set_value = FALSE;
585  }
586 }
587 
588 
589 void
590 gnc_start_recn_interest_clicked_cb(GtkButton *button, startRecnWindowData *data)
591 {
592  /* make the button unclickable since we're popping up the window */
593  if ( data->xfer_button )
594  gtk_widget_set_sensitive(GTK_WIDGET(data->xfer_button), FALSE);
595 
596  /* run the account window */
597  gnc_reconcile_interest_xfer_run( data );
598 }
599 
600 
601 static void
602 gnc_save_reconcile_interval(Account *account, time64 statement_date)
603 {
604  time64 prev_statement_date;
605  int days = 0, months = 0;
606 
607  if (!xaccAccountGetReconcileLastDate (account, &prev_statement_date))
608  return;
609 
610  /*
611  * Compute the number of days difference.
612  */
613  auto seconds = statement_date - prev_statement_date;
614  days = seconds / 60 / 60 / 24;
615 
616  /*
617  * See if we need to remember days(weeks) or months. The only trick
618  * value is 28 days which could be either 4 weeks or 1 month.
619  */
620  if (days == 28)
621  {
622  int prev_days = 0, prev_months = 1;
623 
624  /* What was it last time? */
625  xaccAccountGetReconcileLastInterval (account, &prev_months, &prev_days);
626  if (prev_months == 1)
627  {
628  months = 1;
629  days = 0;
630  }
631  }
632  else if (days > 28)
633  {
634  struct tm current, prev;
635 
636  gnc_localtime_r (&statement_date, &current);
637  gnc_localtime_r (&prev_statement_date, &prev);
638  months = ((12 * current.tm_year + current.tm_mon) -
639  (12 * prev.tm_year + prev.tm_mon));
640  days = 0;
641  }
642 
643  /*
644  * Remember for next time unless it is negative.
645  */
646  if (months >= 0 && days >= 0)
647  xaccAccountSetReconcileLastInterval(account, months, days);
648 }
649 
650 
651 /********************************************************************\
652  * startRecnWindow *
653  * opens up the window to prompt the user to enter the ending *
654  * balance from bank statement *
655  * *
656  * NOTE: This function does not return until the user presses "Ok" *
657  * or "Cancel" *
658  * *
659  * Args: parent - the parent of this window *
660  * account - the account to reconcile *
661  * new_ending - returns the amount for ending balance *
662  * statement_date - returns date of the statement :) *
663  * Return: True, if the user presses "Ok", else False *
664 \********************************************************************/
665 static gboolean
666 startRecnWindow(GtkWidget *parent, Account *account,
667  gnc_numeric *new_ending, time64 *statement_date,
668  gboolean enable_subaccount)
669 {
670  GtkWidget *dialog, *end_value, *date_value, *include_children_button;
671  GtkBuilder *builder;
672  startRecnWindowData data = { NULL };
673  gboolean auto_interest_xfer_option;
674  GNCPrintAmountInfo print_info;
675  gnc_numeric ending;
676  GtkWidget *entry;
677  char *title;
678  int result = -6;
679  gulong fo_handler_id;
680 
681  /* Initialize the data structure that will be used for several callbacks
682  * throughout this file with the relevant info. Some initialization is
683  * done below as well. Note that local storage should be OK for this,
684  * since any callbacks using it will only work while the startRecnWindow
685  * is running.
686  */
687  data.account = account;
688  data.account_type = xaccAccountGetType(account);
689  data.date = *statement_date;
690 
691  /* whether to have an automatic interest xfer dialog or not */
692  auto_interest_xfer_option = xaccAccountGetAutoInterest (account);
693 
694  data.include_children = !has_account_different_commodities(account) &&
696 
697  ending = gnc_ui_account_get_reconciled_balance(account,
698  data.include_children);
699  print_info = gnc_account_print_info (account, TRUE);
700 
701  /*
702  * Do not reverse the balance here. It messes up the math in the
703  * reconciliation window. Also, the balance should show up as a
704  * positive number in the reconciliation window to match the positive
705  * number that shows in the register window.
706  */
707 
708  /* Create the dialog box */
709  builder = gtk_builder_new();
710  gnc_builder_add_from_file (builder, "window-reconcile.glade", "reconcile_start_dialog");
711 
712  dialog = GTK_WIDGET(gtk_builder_get_object (builder, "reconcile_start_dialog"));
713 
714  // Set the name for this dialog so it can be easily manipulated with css
715  gtk_widget_set_name (GTK_WIDGET(dialog), "gnc-id-reconcile-start");
716 
717  title = gnc_recn_make_window_name (account);
718  gtk_window_set_title(GTK_WINDOW(dialog), title);
719  g_free (title);
720 
721  data.startRecnWindow = GTK_WIDGET(dialog);
722 
723  if (parent != NULL)
724  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
725 
726  {
727  GtkWidget *start_value, *box;
728  GtkWidget *label;
729  GtkWidget *interest = NULL;
730 
731  start_value = GTK_WIDGET(gtk_builder_get_object (builder, "start_value"));
732  gtk_label_set_text(GTK_LABEL(start_value), xaccPrintAmount (ending, print_info));
733 
734  include_children_button = GTK_WIDGET(gtk_builder_get_object (builder, "subaccount_check"));
735  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(include_children_button),
736  data.include_children);
737  gtk_widget_set_sensitive(include_children_button, enable_subaccount);
738 
739  date_value = gnc_date_edit_new(*statement_date, FALSE, FALSE);
740  data.date_value = date_value;
741  box = GTK_WIDGET(gtk_builder_get_object (builder, "date_value_box"));
742  gtk_box_pack_start(GTK_BOX(box), date_value, TRUE, TRUE, 0);
743  label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label"));
744  gnc_date_make_mnemonic_target(GNC_DATE_EDIT(date_value), label);
745 
746  end_value = gnc_amount_edit_new ();
747  data.end_value = GNC_AMOUNT_EDIT(end_value);
748  data.original_value = *new_ending;
749  data.user_set_value = FALSE;
750 
751  data.future_icon = GTK_WIDGET(gtk_builder_get_object (builder, "future_icon"));
752  data.future_text = GTK_WIDGET(gtk_builder_get_object (builder, "future_text"));
753 
754  box = GTK_WIDGET(gtk_builder_get_object (builder, "ending_value_box"));
755  gtk_box_pack_start(GTK_BOX(box), end_value, TRUE, TRUE, 0);
756  label = GTK_WIDGET(gtk_builder_get_object (builder, "end_label"));
757  gnc_amount_edit_make_mnemonic_target (GNC_AMOUNT_EDIT(end_value), label);
758 
759  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, &data);
760 
761  gnc_date_activates_default(GNC_DATE_EDIT(date_value), TRUE);
762 
763  /* need to get a callback on date changes to update the recn balance */
764  g_signal_connect ( G_OBJECT (date_value), "date_changed",
765  G_CALLBACK (recn_date_changed_cb), (gpointer) &data );
766 
767  print_info.use_symbol = 0;
768  gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (end_value), print_info);
769  gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (end_value),
770  xaccAccountGetCommoditySCU (account));
771 
772  gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (end_value), *new_ending);
773 
774  entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (end_value));
775  gtk_editable_select_region (GTK_EDITABLE(entry), 0, -1);
776  fo_handler_id = g_signal_connect (G_OBJECT(entry), "focus-out-event",
777  G_CALLBACK(amount_edit_focus_out_cb),
778  (gpointer) &data);
779  gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
780 
781  /* if it's possible to enter an interest payment or charge for this
782  * account, add a button so that the user can pop up the appropriate
783  * dialog if it isn't automatically popping up.
784  */
785  interest = GTK_WIDGET(gtk_builder_get_object (builder, "interest_button"));
786  if ( account_type_has_auto_interest_payment( data.account_type ) )
787  gtk_button_set_label(GTK_BUTTON(interest), _("Enter _Interest Payment…") );
788  else if ( account_type_has_auto_interest_charge( data.account_type ) )
789  gtk_button_set_label(GTK_BUTTON(interest), _("Enter _Interest Charge…") );
790  else
791  {
792  gtk_widget_destroy(interest);
793  interest = NULL;
794  }
795 
796  if ( interest )
797  {
798  data.xfer_button = interest;
799  if ( auto_interest_xfer_option )
800  gtk_widget_set_sensitive(GTK_WIDGET(interest), FALSE);
801  }
802 
803  gtk_widget_show_all(dialog);
804 
805  gtk_widget_hide (data.future_text);
806  gtk_widget_hide (data.future_icon);
807 
808  gtk_widget_grab_focus(gnc_amount_edit_gtk_entry
809  (GNC_AMOUNT_EDIT (end_value)));
810  }
811 
812  /* Allow the user to enter an interest payment
813  * or charge prior to reconciling */
814  if ( account_type_has_auto_interest_xfer( data.account_type )
815  && auto_interest_xfer_option )
816  {
817  gnc_reconcile_interest_xfer_run( &data );
818  }
819 
820  while (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
821  {
822  /* If response is OK but end_value not valid, try again */
823  if (gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT(end_value), NULL))
824  {
825  result = GTK_RESPONSE_OK;
826  break;
827  }
828  }
829 
830  if (result == GTK_RESPONSE_OK)
831  {
832  *new_ending = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (end_value));
833  *statement_date = gnc_date_edit_get_date_end(GNC_DATE_EDIT(date_value));
834 
835  if (gnc_reverse_balance(account))
836  *new_ending = gnc_numeric_neg (*new_ending);
837 
838  xaccAccountSetReconcileChildrenStatus(account, data.include_children);
839 
840  gnc_save_reconcile_interval(account, *statement_date);
841  }
842  // must remove the focus-out handler
843  g_signal_handler_disconnect (G_OBJECT(entry), fo_handler_id);
844  gtk_widget_destroy (dialog);
845  g_object_unref(G_OBJECT(builder));
846 
847  return (result == GTK_RESPONSE_OK);
848 }
849 
850 
851 static void
852 gnc_reconcile_window_set_sensitivity(RecnWindow *recnData)
853 {
854  gboolean sensitive = FALSE;
855  GNCReconcileView *view;
856  GAction *action;
857 
858  view = GNC_RECONCILE_VIEW(recnData->debit);
859  if (gnc_reconcile_view_num_selected(view) == 1)
860  sensitive = TRUE;
861 
862  view = GNC_RECONCILE_VIEW(recnData->credit);
863  if (gnc_reconcile_view_num_selected(view) == 1)
864  sensitive = TRUE;
865 
866  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
867  "TransEditAction");
868  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
869 
870  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
871  "TransDeleteAction");
872  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
873 
874  sensitive = FALSE;
875 
876  view = GNC_RECONCILE_VIEW(recnData->debit);
877  if (gnc_reconcile_view_num_selected(view) > 0)
878  sensitive = TRUE;
879 
880  view = GNC_RECONCILE_VIEW(recnData->credit);
881  if (gnc_reconcile_view_num_selected(view) > 0)
882  sensitive = TRUE;
883 
884  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
885  "TransRecAction");
886  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
887 
888  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
889  "TransUnRecAction");
890  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
891 }
892 
893 
894 static void
895 gnc_reconcile_window_toggled_cb(GNCReconcileView *view, Split *split,
896  gpointer data)
897 {
898  auto recnData = static_cast<RecnWindow*>(data);
899  gnc_reconcile_window_set_sensitivity(recnData);
900  recnRecalculateBalance(recnData);
901 }
902 
903 
904 static void
905 gnc_reconcile_window_row_cb(GNCReconcileView *view, gpointer item,
906  gpointer data)
907 {
908  auto recnData = static_cast<RecnWindow*>(data);
909  gnc_reconcile_window_set_sensitivity(recnData);
910 }
911 
912 
925 static void
926 do_popup_menu(RecnWindow *recnData, GdkEventButton *event)
927 {
928  GMenuModel *menu_model = (GMenuModel *)gtk_builder_get_object (recnData->builder,
929  "recwin-popup");
930  GtkWidget *menu = gtk_menu_new_from_model (menu_model);
931 
932  if (!menu)
933  return;
934 
935  gtk_menu_attach_to_widget (GTK_MENU(menu), GTK_WIDGET(recnData->window), NULL);
936  gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent *) event);
937 }
938 
939 
953 static gboolean
954 gnc_reconcile_window_popup_menu_cb (GtkWidget *widget,
955  RecnWindow *recnData)
956 {
957  do_popup_menu(recnData, NULL);
958  return TRUE;
959 }
960 
961 
962 /* Callback function invoked when the user clicks in the content of
963  * any Gnucash window. If this was a "right-click" then Gnucash will
964  * popup the contextual menu.
965  */
966 static gboolean
967 gnc_reconcile_window_button_press_cb (GtkWidget *widget,
968  GdkEventButton *event,
969  RecnWindow *recnData)
970 {
971  if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
972  {
973  GNCQueryView *qview = GNC_QUERY_VIEW(widget);
974  GtkTreePath *path;
975 
976  /* Get tree path for row that was clicked */
977  gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(qview),
978  (gint) event->x,
979  (gint) event->y,
980  &path, NULL, NULL, NULL);
981 
982  if (path)
983  {
984  GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));
985 
986  if (!gtk_tree_selection_path_is_selected (selection, path))
987  {
988  gtk_tree_selection_unselect_all (selection);
989  gtk_tree_selection_select_path (selection, path);
990  }
991  gtk_tree_path_free (path);
992  }
993  do_popup_menu (recnData, event);
994  return TRUE;
995  }
996  return FALSE;
997 }
998 
999 
1000 static GNCSplitReg *
1001 gnc_reconcile_window_open_register(RecnWindow *recnData)
1002 {
1003  Account *account = recn_get_account (recnData);
1004  GNCSplitReg *gsr;
1005  gboolean include_children;
1006 
1007  if (!account)
1008  return(NULL);
1009 
1010  include_children = xaccAccountGetReconcileChildrenStatus (account);
1011  recnData->page = gnc_plugin_page_register_new (account, include_children);
1012  gnc_main_window_open_page (NULL, recnData->page);
1013  gsr = gnc_plugin_page_register_get_gsr (recnData->page);
1014  gnc_split_reg_raise (gsr);
1015  return gsr;
1016 }
1017 
1018 
1019 static void
1020 gnc_reconcile_window_double_click_cb(GNCReconcileView *view, Split *split,
1021  gpointer data)
1022 {
1023  auto recnData = static_cast<RecnWindow*>(data);
1024  GNCSplitReg *gsr;
1025 
1026  /* This should never be true, but be paranoid */
1027  if (split == NULL)
1028  return;
1029 
1030  gsr = gnc_reconcile_window_open_register(recnData);
1031  if (gsr == NULL)
1032  return;
1033 
1034  /* Test for visibility of split */
1035  if (gnc_split_reg_clear_filter_for_split (gsr, split))
1036  gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(recnData->page));
1037 
1038  gnc_split_reg_jump_to_split( gsr, split );
1039 }
1040 
1041 
1042 static void
1043 gnc_reconcile_window_focus_cb(GtkWidget *widget, GdkEventFocus *event,
1044  gpointer data)
1045 {
1046  auto recnData = static_cast<RecnWindow*>(data);
1047  GNCReconcileView *this_view, *other_view;
1048  GNCReconcileView *debit, *credit;
1049 
1050  this_view = GNC_RECONCILE_VIEW(widget);
1051 
1052  debit = GNC_RECONCILE_VIEW(recnData->debit);
1053  credit = GNC_RECONCILE_VIEW(recnData->credit);
1054 
1055  other_view = GNC_RECONCILE_VIEW(this_view == debit ? credit : debit);
1056 
1057  /* clear the *other* list so we always have no more than one selection */
1058  gnc_reconcile_view_unselect_all(other_view);
1059 }
1060 
1061 
1062 static gboolean
1063 gnc_reconcile_key_press_cb (GtkWidget *widget, GdkEventKey *event,
1064  gpointer data)
1065 {
1066  auto recnData = static_cast<RecnWindow*>(data);
1067  GtkWidget *this_view, *other_view;
1068  GtkWidget *debit, *credit;
1069 
1070  switch (event->keyval)
1071  {
1072  case GDK_KEY_Tab:
1073  case GDK_KEY_ISO_Left_Tab:
1074  break;
1075 
1076  default:
1077  return FALSE;
1078  }
1079 
1080  g_signal_stop_emission_by_name (widget, "key_press_event");
1081 
1082  this_view = widget;
1083 
1084  debit = recnData->debit;
1085  credit = recnData->credit;
1086 
1087  other_view = (this_view == debit ? credit : debit);
1088 
1089  gtk_widget_grab_focus (other_view);
1090 
1091  return TRUE;
1092 }
1093 
1094 
1095 static void
1096 gnc_reconcile_window_set_titles(RecnWindow *recnData)
1097 {
1098  const gchar *title;
1099 
1101  gtk_frame_set_label(GTK_FRAME(recnData->debit_frame), title);
1102 
1104  gtk_frame_set_label(GTK_FRAME(recnData->credit_frame), title);
1105 }
1106 
1107 
1108 static GtkWidget *
1109 gnc_reconcile_window_create_view_box(Account *account,
1110  GNCReconcileViewType type,
1111  RecnWindow *recnData,
1112  GtkWidget **list_save,
1113  GtkWidget **total_save)
1114 {
1115  GtkWidget *frame, *scrollWin, *view, *vbox, *label, *hbox;
1116  GtkWidget *vscroll;
1117  GtkRequisition nat_sb;
1118 
1119  frame = gtk_frame_new(NULL);
1120 
1121  if (type == RECLIST_DEBIT)
1122  recnData->debit_frame = frame;
1123  else
1124  recnData->credit_frame = frame;
1125 
1126  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
1127  gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE);
1128 
1129  view = gnc_reconcile_view_new(account, type, recnData->statement_date);
1130  *list_save = view;
1131 
1132  g_signal_connect(view, "toggle_reconciled",
1133  G_CALLBACK(gnc_reconcile_window_toggled_cb),
1134  recnData);
1135  g_signal_connect(view, "line_selected",
1136  G_CALLBACK(gnc_reconcile_window_row_cb),
1137  recnData);
1138  g_signal_connect(view, "button_press_event",
1139  G_CALLBACK(gnc_reconcile_window_button_press_cb),
1140  recnData);
1141  g_signal_connect(view, "double_click_split",
1142  G_CALLBACK(gnc_reconcile_window_double_click_cb),
1143  recnData);
1144  g_signal_connect(view, "focus_in_event",
1145  G_CALLBACK(gnc_reconcile_window_focus_cb),
1146  recnData);
1147  g_signal_connect(view, "key_press_event",
1148  G_CALLBACK(gnc_reconcile_key_press_cb),
1149  recnData);
1150 
1151  scrollWin = gtk_scrolled_window_new (NULL, NULL);
1152  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrollWin),
1153  GTK_POLICY_AUTOMATIC,
1154  GTK_POLICY_AUTOMATIC);
1155  gtk_container_set_border_width(GTK_CONTAINER(scrollWin), 5);
1156 
1157  gtk_container_add(GTK_CONTAINER(frame), scrollWin);
1158  gtk_container_add(GTK_CONTAINER(scrollWin), view);
1159  gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
1160 
1161  // get the vertical scroll bar width
1162  vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (scrollWin));
1163  gtk_widget_get_preferred_size (vscroll, NULL, &nat_sb);
1164 
1165  // add xpadding to recn column so scrollbar does not cover
1166  gnc_reconcile_view_add_padding (GNC_RECONCILE_VIEW(view), REC_RECN, nat_sb.width);
1167 
1168  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
1169  gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
1170  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1171 
1172  label = gtk_label_new(_("Total"));
1173  gnc_label_set_alignment(label, 1.0, 0.5);
1174  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1175 
1176  label = gtk_label_new("");
1177  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1178  *total_save = label;
1179  gtk_widget_set_margin_end (GTK_WIDGET(label), 10 + nat_sb.width);
1180 
1181  return vbox;
1182 }
1183 
1184 
1185 static Split *
1186 gnc_reconcile_window_get_current_split(RecnWindow *recnData)
1187 {
1188  GNCReconcileView *view;
1189  Split *split;
1190 
1191  view = GNC_RECONCILE_VIEW(recnData->debit);
1192  split = gnc_reconcile_view_get_current_split(view);
1193  if (split != NULL)
1194  return split;
1195 
1196  view = GNC_RECONCILE_VIEW(recnData->credit);
1197  split = gnc_reconcile_view_get_current_split(view);
1198 
1199  return split;
1200 }
1201 
1202 
1203 static void
1204 gnc_ui_reconcile_window_help_cb (GSimpleAction *simple,
1205  GVariant *parameter,
1206  gpointer user_data)
1207 {
1208  auto recnData = static_cast<RecnWindow*>(user_data);
1209  gnc_gnome_help (GTK_WINDOW(recnData->window), DF_MANUAL, DL_RECNWIN);
1210 }
1211 
1212 
1213 static void
1214 gnc_ui_reconcile_window_change_cb (GSimpleAction *simple,
1215  GVariant *parameter,
1216  gpointer user_data)
1217 {
1218  auto recnData = static_cast<RecnWindow*>(user_data);
1219  Account *account = recn_get_account (recnData);
1220  gnc_numeric new_ending = recnData->new_ending;
1221  time64 statement_date = recnData->statement_date;
1222 
1223  if (gnc_reverse_balance (account))
1224  new_ending = gnc_numeric_neg (new_ending);
1225  if (startRecnWindow (recnData->window, account, &new_ending, &statement_date,
1226  FALSE))
1227  {
1228  recnData->new_ending = new_ending;
1229  recnData->statement_date = statement_date;
1230  recnRecalculateBalance (recnData);
1231  }
1232 }
1233 
1234 
1235 static void
1236 gnc_ui_reconcile_window_balance_cb (GSimpleAction *simple,
1237  GVariant *parameter,
1238  gpointer user_data)
1239 {
1240  auto recnData = static_cast<RecnWindow*>(user_data);
1241  GNCSplitReg *gsr;
1242  Account *account;
1243  gnc_numeric balancing_amount;
1244  time64 statement_date;
1245 
1246 
1247  gsr = gnc_reconcile_window_open_register(recnData);
1248  if (gsr == NULL)
1249  return;
1250 
1251  account = recn_get_account(recnData);
1252  if (account == NULL)
1253  return;
1254 
1255  balancing_amount = recnRecalculateBalance(recnData);
1256  if (gnc_numeric_zero_p(balancing_amount))
1257  return;
1258 
1259  statement_date = recnData->statement_date;
1260  if (statement_date == 0)
1261  statement_date = gnc_time (NULL); // default to 'now'
1262 
1263  gnc_split_reg_balancing_entry(gsr, account, statement_date, balancing_amount);
1264 }
1265 
1266 
1267 static void
1268 gnc_ui_reconcile_window_rec_cb (GSimpleAction *simple,
1269  GVariant *parameter,
1270  gpointer user_data)
1271 {
1272  auto recnData = static_cast<RecnWindow*>(user_data);
1273  GNCReconcileView *debit, *credit;
1274 
1275  debit = GNC_RECONCILE_VIEW(recnData->debit);
1276  credit = GNC_RECONCILE_VIEW(recnData->credit);
1277 
1278  gnc_reconcile_view_set_list (debit, TRUE);
1279  gnc_reconcile_view_set_list (credit, TRUE);
1280 }
1281 
1282 
1283 static void
1284 gnc_ui_reconcile_window_unrec_cb (GSimpleAction *simple,
1285  GVariant *parameter,
1286  gpointer user_data)
1287 {
1288  auto recnData = static_cast<RecnWindow*>(user_data);
1289  GNCReconcileView *debit, *credit;
1290 
1291  debit = GNC_RECONCILE_VIEW(recnData->debit);
1292  credit = GNC_RECONCILE_VIEW(recnData->credit);
1293 
1294  gnc_reconcile_view_set_list (debit, FALSE);
1295  gnc_reconcile_view_set_list (credit, FALSE);
1296 }
1297 
1298 
1304 static GNCReconcileView *
1305 gnc_reconcile_window_get_selection_view (RecnWindow *recnData)
1306 {
1307  if (gnc_reconcile_view_num_selected (GNC_RECONCILE_VIEW (recnData->debit)) > 0)
1308  return GNC_RECONCILE_VIEW (recnData->debit);
1309 
1310  if (gnc_reconcile_view_num_selected (GNC_RECONCILE_VIEW (recnData->credit)) > 0)
1311  return GNC_RECONCILE_VIEW (recnData->credit);
1312 
1313  return NULL;
1314 }
1315 
1316 
1323 static void
1324 gnc_reconcile_window_delete_set_next_selection (RecnWindow *recnData, Split *split)
1325 {
1326  GNCReconcileView *view = gnc_reconcile_window_get_selection_view (recnData);
1327  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1328  Split *this_split = NULL;
1329  GtkTreeIter iter;
1330  GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1331  GList *path_list, *node;
1332  GtkTreePath *save_del_path;
1333  Transaction* trans = xaccSplitGetParent (split); // parent transaction of the split to delete
1334 
1335  if (!view)
1336  return; // no selected split
1337 
1338  path_list = gtk_tree_selection_get_selected_rows (selection, &model);
1339  // get path of the first split selected - there should be only 1 selected
1340  node = g_list_first (path_list);
1341  if (!node)
1342  return;
1343  auto path = static_cast<GtkTreePath*>(node->data);
1344  save_del_path = gtk_tree_path_copy (path);
1345 
1346  gtk_tree_path_next (path);
1347  if (gtk_tree_model_get_iter (model, &iter, path))
1348  {
1349  do
1350  {
1351  gtk_tree_model_get (model, &iter, REC_POINTER, &this_split, -1);
1352  }
1353  while (xaccSplitGetParent (this_split) == trans && gtk_tree_model_iter_next (model, &iter));
1354  }
1355 
1356  if ((!this_split) || xaccSplitGetParent (this_split) == trans)
1357  {
1358  // There aren't any splits for a different transaction after the split to be deleted,
1359  // so find the previous split having a different parent transaction
1360  path = save_del_path; // split to be deleted
1361  if (gtk_tree_path_prev (path) && gtk_tree_model_get_iter (model, &iter, path))
1362  {
1363  do
1364  {
1365  gtk_tree_model_get (model, &iter, REC_POINTER, &this_split, -1);
1366  }
1367  while (xaccSplitGetParent (this_split) == trans && gtk_tree_model_iter_previous (model, &iter));
1368  }
1369  }
1370 
1371  gtk_tree_path_free (save_del_path);
1372  g_list_free_full (path_list, (GDestroyNotify) gtk_tree_path_free);
1373  if ((!this_split) || xaccSplitGetParent (this_split) == trans)
1374  return;
1375 
1376  gtk_tree_selection_select_iter (selection, &iter);
1377 }
1378 
1379 
1380 static void
1381 gnc_ui_reconcile_window_delete_cb (GSimpleAction *simple,
1382  GVariant *parameter,
1383  gpointer user_data)
1384 {
1385  auto recnData = static_cast<RecnWindow*>(user_data);
1386  Transaction *trans;
1387  Split *split;
1388 
1389  split = gnc_reconcile_window_get_current_split(recnData);
1390  /* This should never be true, but be paranoid */
1391  if (split == NULL)
1392  return;
1393 
1394  {
1395  const char *message = _("Are you sure you want to delete the selected "
1396  "transaction?");
1397  gboolean result;
1398 
1399  result = gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message);
1400 
1401  if (!result)
1402  return;
1403  }
1404 
1405  /* select the split that should be visible after the deletion */
1406  gnc_reconcile_window_delete_set_next_selection(recnData, split);
1407 
1408  gnc_suspend_gui_refresh ();
1409 
1410  trans = xaccSplitGetParent(split);
1411  xaccTransDestroy(trans);
1412 
1413  gnc_resume_gui_refresh ();
1414 }
1415 
1416 
1417 static void
1418 gnc_ui_reconcile_window_edit_cb (GSimpleAction *simple,
1419  GVariant *parameter,
1420  gpointer user_data)
1421 {
1422  auto recnData = static_cast<RecnWindow*>(user_data);
1423  GNCSplitReg *gsr;
1424  Split *split;
1425 
1426  split = gnc_reconcile_window_get_current_split (recnData);
1427  /* This should never be true, but be paranoid */
1428  if (split == NULL)
1429  return;
1430 
1431  gsr = gnc_reconcile_window_open_register(recnData);
1432  if (gsr == NULL)
1433  return;
1434 
1435  /* Test for visibility of split */
1436  if (gnc_split_reg_clear_filter_for_split (gsr, split))
1437  gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(recnData->page));
1438 
1439  gnc_split_reg_jump_to_split_amount( gsr, split );
1440 }
1441 
1442 
1443 static char *
1444 gnc_recn_make_window_name(Account *account)
1445 {
1446  char *fullname;
1447  char *title;
1448 
1449  fullname = gnc_account_get_full_name(account);
1450  title = g_strconcat(fullname, " - ", _("Reconcile"), NULL);
1451 
1452  g_free(fullname);
1453 
1454  return title;
1455 }
1456 
1457 
1458 static void
1459 gnc_recn_set_window_name(RecnWindow *recnData)
1460 {
1461  char *title;
1462 
1463  title = gnc_recn_make_window_name (recn_get_account (recnData));
1464 
1465  gtk_window_set_title (GTK_WINDOW (recnData->window), title);
1466 
1467  g_free (title);
1468 }
1469 
1470 
1471 static void
1472 gnc_recn_edit_account_cb (GSimpleAction *simple,
1473  GVariant *parameter,
1474  gpointer user_data)
1475 {
1476  auto recnData = static_cast<RecnWindow*>(user_data);
1477  Account *account = recn_get_account (recnData);
1478 
1479  if (account == NULL)
1480  return;
1481 
1482  gnc_ui_edit_account_window (GTK_WINDOW (recnData->window), account);
1483 }
1484 
1485 
1486 static void
1487 gnc_recn_xfer_cb (GSimpleAction *simple,
1488  GVariant *parameter,
1489  gpointer user_data)
1490 {
1491  auto recnData = static_cast<RecnWindow*>(user_data);
1492  Account *account = recn_get_account (recnData);
1493 
1494  if (account == NULL)
1495  return;
1496 
1497  gnc_xfer_dialog (recnData->window, account);
1498 }
1499 
1500 
1501 static void
1502 gnc_recn_scrub_cb (GSimpleAction *simple,
1503  GVariant *parameter,
1504  gpointer user_data)
1505 {
1506  auto recnData = static_cast<RecnWindow*>(user_data);
1507  Account *account = recn_get_account (recnData);
1508 
1509  if (account == NULL)
1510  return;
1511 
1512  gnc_suspend_gui_refresh ();
1513 
1514  xaccAccountTreeScrubOrphans (account, gnc_window_show_progress);
1515  xaccAccountTreeScrubImbalance (account, gnc_window_show_progress);
1516 
1517  // XXX: Lots are disabled.
1518  if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
1519  xaccAccountTreeScrubLots(account);
1520 
1521  gnc_resume_gui_refresh ();
1522 }
1523 
1524 
1525 static void
1526 gnc_recn_open_cb (GSimpleAction *simple,
1527  GVariant *parameter,
1528  gpointer user_data)
1529 {
1530  auto recnData = static_cast<RecnWindow*>(user_data);
1531 
1532  gnc_reconcile_window_open_register(recnData);
1533 }
1534 
1535 
1536 static void
1537 gnc_get_reconcile_info (Account *account,
1538  gnc_numeric *new_ending,
1539  time64 *statement_date)
1540 {
1541  gboolean always_today;
1542  GDate date;
1543  time64 today;
1544 
1545  g_date_clear(&date, 1);
1546 
1547  always_today = gnc_prefs_get_bool(GNC_PREFS_GROUP_RECONCILE, GNC_PREF_ALWAYS_REC_TO_TODAY);
1548 
1549  if (!always_today &&
1550  xaccAccountGetReconcileLastDate (account, statement_date))
1551  {
1552  int months = 1, days = 0;
1553 
1554  gnc_gdate_set_time64(&date, *statement_date);
1555 
1556  xaccAccountGetReconcileLastInterval (account, &months, &days);
1557 
1558  if (months)
1559  {
1560  gboolean was_last_day_of_month = g_date_is_last_of_month(&date);
1561 
1562  g_date_add_months(&date, months);
1563 
1564  /* Track last day of the month, i.e. 1/31 -> 2/28 -> 3/31 */
1565  if (was_last_day_of_month)
1566  {
1567  g_date_set_day (&date, g_date_get_days_in_month(g_date_get_month(&date),
1568  g_date_get_year( &date)));
1569  }
1570  }
1571  else
1572  {
1573  g_date_add_days (&date, days);
1574  }
1575 
1576  *statement_date = gnc_time64_get_day_end_gdate (&date);
1577 
1578  today = gnc_time64_get_day_end (gnc_time (NULL));
1579  if (*statement_date > today)
1580  *statement_date = today;
1581  }
1582 
1583  xaccAccountGetReconcilePostponeDate (account, statement_date);
1584 
1585  if (xaccAccountGetReconcilePostponeBalance(account, new_ending))
1586  {
1587  if (gnc_reverse_balance(account))
1588  *new_ending = gnc_numeric_neg(*new_ending);
1589  }
1590  else
1591  {
1592  /* if the account wasn't previously postponed, try to predict
1593  * the statement balance based on the statement date.
1594  */
1595  *new_ending =
1596  gnc_ui_account_get_balance_as_of_date
1597  (account, *statement_date,
1599  }
1600 }
1601 
1602 
1603 static gboolean
1604 find_by_account (gpointer find_data, gpointer user_data)
1605 {
1606  auto account = GNC_ACCOUNT(find_data);
1607  auto recnData = static_cast<RecnWindow*>(user_data);
1608 
1609  if (!recnData)
1610  return FALSE;
1611 
1612  return guid_equal (&recnData->account, xaccAccountGetGUID (account));
1613 }
1614 
1615 
1616 static void
1617 recn_set_watches_one_account (gpointer data, gpointer user_data)
1618 {
1619  Account *account = (Account *)data;
1620  RecnWindow *recnData = (RecnWindow *)user_data;
1621 
1622  /* add a watch on the account */
1623  gnc_gui_component_watch_entity (recnData->component_id,
1624  xaccAccountGetGUID (account),
1625  QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1626 
1627  /* add a watch on each split for the account */
1628  for (auto split : xaccAccountGetSplits (account))
1629  {
1630  auto trans = xaccSplitGetParent (split);
1631  gnc_gui_component_watch_entity (recnData->component_id,
1632  xaccTransGetGUID (trans),
1633  QOF_EVENT_MODIFY
1634  | QOF_EVENT_DESTROY
1635  | GNC_EVENT_ITEM_CHANGED);
1636  }
1637 }
1638 
1639 
1640 static void
1641 recn_set_watches (RecnWindow *recnData)
1642 {
1643  gboolean include_children;
1644  Account *account;
1645  GList *accounts = NULL;
1646 
1647  gnc_gui_component_clear_watches (recnData->component_id);
1648 
1649  account = recn_get_account (recnData);
1650 
1651  include_children = xaccAccountGetReconcileChildrenStatus(account);
1652  if (include_children)
1653  accounts = gnc_account_get_descendants(account);
1654 
1655  /* match the account */
1656  accounts = g_list_prepend (accounts, account);
1657 
1658  g_list_foreach(accounts, recn_set_watches_one_account, recnData);
1659 
1660  g_list_free (accounts);
1661 }
1662 
1663 
1664 static void
1665 refresh_handler (GHashTable *changes, gpointer user_data)
1666 {
1667  auto recnData = static_cast<RecnWindow*>(user_data);
1668  const EventInfo *info;
1669  Account *account;
1670 
1671  account = recn_get_account (recnData);
1672  if (!account)
1673  {
1674  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1675  return;
1676  }
1677 
1678  if (changes)
1679  {
1680  info = gnc_gui_get_entity_events (changes, &recnData->account);
1681  if (info && (info->event_mask & QOF_EVENT_DESTROY))
1682  {
1683  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1684  return;
1685  }
1686  }
1687 
1688  gnc_reconcile_window_set_titles(recnData);
1689  recn_set_watches (recnData);
1690 
1691  recnRefresh (recnData);
1692 }
1693 
1694 
1695 static void
1696 close_handler (gpointer user_data)
1697 {
1698  auto recnData = static_cast<RecnWindow*>(user_data);
1699 
1700  gnc_save_window_size(GNC_PREFS_GROUP_RECONCILE, GTK_WINDOW(recnData->window));
1701  gtk_widget_destroy (recnData->window);
1702 }
1703 
1704 
1705 /********************************************************************\
1706  * recnWindow *
1707  * opens up the window to reconcile an account *
1708  * *
1709  * Args: parent - the parent of this window *
1710  * account - the account to reconcile *
1711  * Return: recnData - the instance of this RecnWindow *
1712 \********************************************************************/
1713 RecnWindow *
1714 recnWindow (GtkWidget *parent, Account *account)
1715 {
1716  gnc_numeric new_ending;
1717  gboolean enable_subaccounts;
1718  time64 statement_date;
1719 
1720  if (account == NULL)
1721  return NULL;
1722 
1723  /* The last time reconciliation was attempted during the current execution
1724  * of gnucash, the date was stored. Use that date if possible. This helps
1725  * with balancing multiple accounts for which statements are issued at the
1726  * same time, like multiple bank accounts on a single statement. Otherwise
1727  * use the end of today to ensure we include any transactions posted
1728  * today.
1729  */
1730  if (!gnc_reconcile_last_statement_date)
1731  statement_date = gnc_time64_get_day_end(gnc_time (NULL));
1732  else
1733  statement_date = gnc_reconcile_last_statement_date;
1734 
1735  gnc_get_reconcile_info (account, &new_ending, &statement_date);
1736 
1737  enable_subaccounts = !has_account_different_commodities(account);
1738  /* Popup a little window to prompt the user to enter the
1739  * ending balance for his/her bank statement */
1740  if (!startRecnWindow (parent, account, &new_ending, &statement_date,
1741  enable_subaccounts))
1742  return NULL;
1743 
1744  return recnWindowWithBalance (parent, account, new_ending, statement_date);
1745 }
1746 
1747 
1748 static GActionEntry recWindow_actions_entries [] =
1749 {
1750  { "RecnChangeInfoAction", gnc_ui_reconcile_window_change_cb, NULL, NULL, NULL },
1751  { "RecnFinishAction", recnFinishCB, NULL, NULL, NULL },
1752  { "RecnPostponeAction", recnPostponeCB, NULL, NULL, NULL },
1753  { "RecnCancelAction", recnCancelCB, NULL, NULL, NULL },
1754 
1755  { "AccountOpenAccountAction", gnc_recn_open_cb, NULL, NULL, NULL },
1756  { "AccountEditAccountAction", gnc_recn_edit_account_cb, NULL, NULL, NULL },
1757  { "AccountTransferAction", gnc_recn_xfer_cb, NULL, NULL, NULL },
1758  { "AccountCheckRepairAction", gnc_recn_scrub_cb, NULL, NULL, NULL },
1759 
1760  { "TransBalanceAction", gnc_ui_reconcile_window_balance_cb, NULL, NULL, NULL },
1761  { "TransEditAction", gnc_ui_reconcile_window_edit_cb, NULL, NULL, NULL },
1762  { "TransDeleteAction", gnc_ui_reconcile_window_delete_cb, NULL, NULL, NULL },
1763  { "TransRecAction", gnc_ui_reconcile_window_rec_cb, NULL, NULL, NULL },
1764  { "TransUnRecAction", gnc_ui_reconcile_window_unrec_cb, NULL, NULL, NULL },
1765 
1766  { "HelpHelpAction", gnc_ui_reconcile_window_help_cb, NULL, NULL, NULL },
1767 };
1769 static guint recnWindow_n_actions_entries = G_N_ELEMENTS(recWindow_actions_entries);
1770 
1771 #ifdef MAC_INTEGRATION
1772 /* Enable GtkMenuItem accelerators */
1773 static gboolean
1774 can_activate_cb(GtkWidget *widget, guint signal_id, gpointer data)
1775 {
1776  //return gtk_widget_is_sensitive (widget);
1777  return TRUE;
1778 }
1779 #endif
1780 
1781 /********************************************************************\
1782  * recnWindowWithBalance
1783  *
1784  * Opens up the window to reconcile an account, but with ending
1785  * balance and statement date already given.
1786  *
1787  * Args: parent - The parent widget of the new window
1788  * account - The account to reconcile
1789  * new_ending - The amount for ending balance
1790  * statement_date - The date of the statement
1791  * Return: recnData - the instance of this RecnWindow
1792 \********************************************************************/
1793 RecnWindow *
1794 recnWindowWithBalance (GtkWidget *parent, Account *account, gnc_numeric new_ending,
1795  time64 statement_date)
1796 {
1797  RecnWindow *recnData;
1798  GtkWidget *statusbar;
1799  GtkWidget *vbox;
1800  GtkWidget *dock;
1801 
1802  if (account == NULL)
1803  return NULL;
1804 
1805  recnData = static_cast<RecnWindow*>(gnc_find_first_gui_component (WINDOW_RECONCILE_CM_CLASS,
1806  find_by_account, account));
1807  if (recnData)
1808  return recnData;
1809 
1810  recnData = g_new0 (RecnWindow, 1);
1811 
1812  recnData->account = *xaccAccountGetGUID (account);
1813 
1814 
1815  recnData->component_id =
1816  gnc_register_gui_component (WINDOW_RECONCILE_CM_CLASS,
1817  refresh_handler, close_handler,
1818  recnData);
1819  gnc_gui_component_set_session (recnData->component_id, gnc_get_current_session());
1820 
1821  recn_set_watches (recnData);
1822 
1823  gnc_reconcile_last_statement_date = statement_date;
1824 
1825  recnData->new_ending = new_ending;
1826  recnData->statement_date = statement_date;
1827  recnData->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1828  recnData->delete_refresh = FALSE;
1829 
1830  gnc_recn_set_window_name(recnData);
1831 
1832  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1833  gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE);
1834  gtk_container_add(GTK_CONTAINER(recnData->window), vbox);
1835 
1836  // Set the name for this dialog so it can be easily manipulated with css
1837  gtk_widget_set_name (GTK_WIDGET(recnData->window), "gnc-id-reconcile");
1838 
1839  dock = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1840  gtk_box_set_homogeneous (GTK_BOX (dock), FALSE);
1841  gtk_widget_show(dock);
1842  gtk_box_pack_start(GTK_BOX (vbox), dock, FALSE, TRUE, 0);
1843 
1844  {
1845  GtkToolbar *tool_bar;
1846  GMenuModel *menu_model;
1847  GtkWidget *menu_bar;
1848  GtkAccelGroup *accel_group = gtk_accel_group_new ();
1849  const gchar *ui = GNUCASH_RESOURCE_PREFIX "/gnc-reconcile-window.ui";
1850  GError *error = NULL;
1851 
1852  recnData->builder = gtk_builder_new ();
1853 
1854  gtk_builder_add_from_resource (recnData->builder, ui, &error);
1855 
1856  gtk_builder_set_translation_domain (recnData->builder, PROJECT_NAME);
1857 
1858  if (error)
1859  {
1860  g_critical ("Failed to load ui resource %s, Error %s", ui, error->message);
1861  g_error_free (error);
1862  gnc_unregister_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1863  g_free (recnData);
1864  return NULL;
1865  }
1866 
1867  menu_model = (GMenuModel *)gtk_builder_get_object (recnData->builder, "recwin-menu");
1868  menu_bar = gtk_menu_bar_new_from_model (menu_model);
1869  gtk_container_add (GTK_CONTAINER(vbox), menu_bar);
1870 #ifdef MAC_INTEGRATION
1871  auto theApp = static_cast<GtkosxApplication*>(g_object_new (GTKOSX_TYPE_APPLICATION, NULL));
1872  gtk_widget_hide (menu_bar);
1873  gtk_widget_set_no_show_all (menu_bar, TRUE);
1874  if (GTK_IS_MENU_ITEM (menu_bar))
1875  menu_bar = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_bar));
1876 
1877  gtkosx_application_set_menu_bar (theApp, GTK_MENU_SHELL (menu_bar));
1878 #endif
1879  tool_bar = (GtkToolbar *)gtk_builder_get_object (recnData->builder, "recwin-toolbar");
1880 
1881  gtk_toolbar_set_style (GTK_TOOLBAR(tool_bar), GTK_TOOLBAR_BOTH);
1882  gtk_toolbar_set_icon_size (GTK_TOOLBAR(tool_bar),
1883  GTK_ICON_SIZE_SMALL_TOOLBAR);
1884 
1885  gtk_container_add (GTK_CONTAINER(vbox), GTK_WIDGET(tool_bar));
1886 
1887  gtk_window_add_accel_group (GTK_WINDOW(recnData->window), accel_group);
1888 
1889  // need to add the accelerator keys
1890  gnc_add_accelerator_keys_for_menu (menu_bar, menu_model, accel_group);
1891 
1892 #ifdef MAC_INTEGRATION
1893  gtkosx_application_sync_menubar (theApp);
1894  g_signal_connect (menu_bar, "can-activate-accel",
1895  G_CALLBACK(can_activate_cb), NULL);
1896  g_object_unref (theApp);
1897  theApp = NULL;
1898 #endif
1899 
1900  recnData->simple_action_group = g_simple_action_group_new ();
1901 
1902  g_action_map_add_action_entries (G_ACTION_MAP(recnData->simple_action_group),
1903  recWindow_actions_entries,
1904  recnWindow_n_actions_entries,
1905  recnData);
1906 
1907  gtk_widget_insert_action_group (GTK_WIDGET(recnData->window), "recwin",
1908  G_ACTION_GROUP(recnData->simple_action_group));
1909  }
1910 
1911  g_signal_connect(recnData->window, "popup-menu",
1912  G_CALLBACK(gnc_reconcile_window_popup_menu_cb), recnData);
1913 
1914  statusbar = gtk_statusbar_new();
1915  gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
1916 
1917  g_signal_connect (recnData->window, "destroy",
1918  G_CALLBACK(recn_destroy_cb), recnData);
1919  g_signal_connect (recnData->window, "delete_event",
1920  G_CALLBACK(recn_delete_cb), recnData);
1921  g_signal_connect (recnData->window, "key_press_event",
1922  G_CALLBACK(recn_key_press_cb), recnData);
1923 
1924 
1925  /* if account has a reconciled split where reconciled_date is
1926  later than statement_date, emit a warning into statusbar */
1927  {
1928  GtkStatusbar *bar = GTK_STATUSBAR (statusbar);
1929  guint context = gtk_statusbar_get_context_id (bar, "future_dates");
1930  GtkWidget *box = gtk_statusbar_get_message_area (bar);
1931  GtkWidget *image = gtk_image_new_from_icon_name
1932  ("dialog-warning", GTK_ICON_SIZE_SMALL_TOOLBAR);
1933 
1934  // find an already reconciled split whose statement date
1935  // is after *this* reconciliation statement date.
1936  auto has_later_recn_statement_date = [statement_date](const Split *split)
1937  { return (xaccSplitGetReconcile (split) == YREC &&
1938  xaccSplitGetDateReconciled (split) > statement_date); };
1939 
1940  if (auto split = gnc_account_find_split (account, has_later_recn_statement_date, true))
1941  {
1942  auto datestr = qof_print_date (xaccTransGetDate (xaccSplitGetParent (split)));
1943  auto recnstr = qof_print_date (xaccSplitGetDateReconciled (split));
1944  PWARN ("split posting_date=%s, recn_date=%s", datestr, recnstr);
1945 
1946  gtk_statusbar_push (bar, context, _("WARNING! Account contains \
1947 splits whose reconcile date is after statement date. Reconciliation may be \
1948 difficult."));
1949 
1950  gtk_widget_set_tooltip_text (GTK_WIDGET (bar), _("This account \
1951 has splits whose Reconciled Date is after this reconciliation statement date. \
1952 These splits may make reconciliation difficult. If this is the case, you may \
1953 use Find Transactions to find them, unreconcile, and re-reconcile."));
1954 
1955  gtk_box_pack_start (GTK_BOX(box), image, FALSE, FALSE, 0);
1956  gtk_box_reorder_child (GTK_BOX(box), image, 0);
1957 
1958  g_free (datestr);
1959  g_free (recnstr);
1960  }
1961  }
1962 
1963  /* The main area */
1964  {
1965  GtkWidget *frame = gtk_frame_new(NULL);
1966  GtkWidget *main_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
1967  GtkWidget *debcred_area = gtk_grid_new ();
1968  GtkWidget *debits_box;
1969  GtkWidget *credits_box;
1970 
1971  gtk_box_set_homogeneous (GTK_BOX (main_area), FALSE);
1972  gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 10);
1973 
1974  /* Force a reasonable starting size */
1975  gtk_window_set_default_size(GTK_WINDOW(recnData->window), 800, 600);
1976  gnc_restore_window_size (GNC_PREFS_GROUP_RECONCILE,
1977  GTK_WINDOW(recnData->window), GTK_WINDOW(parent));
1978 
1979  gtk_container_add(GTK_CONTAINER(frame), main_area);
1980  gtk_container_set_border_width(GTK_CONTAINER(main_area), 10);
1981 
1982  debits_box = gnc_reconcile_window_create_view_box
1983  (account, RECLIST_DEBIT, recnData,
1984  &recnData->debit, &recnData->total_debit);
1985 
1986  // Add a style context for this widget so it can be easily manipulated with css
1987  gnc_widget_style_context_add_class (GTK_WIDGET(debits_box), "gnc-class-debits");
1988 
1989  credits_box = gnc_reconcile_window_create_view_box
1990  (account, RECLIST_CREDIT, recnData,
1991  &recnData->credit, &recnData->total_credit);
1992 
1993  // Add a style context for this widget so it can be easily manipulated with css
1994  gnc_widget_style_context_add_class (GTK_WIDGET(credits_box), "gnc-class-credits");
1995 
1996  GNC_RECONCILE_VIEW(recnData->debit)->sibling = GNC_RECONCILE_VIEW(recnData->credit);
1997  GNC_RECONCILE_VIEW(recnData->credit)->sibling = GNC_RECONCILE_VIEW(recnData->debit);
1998 
1999  gtk_box_pack_start(GTK_BOX(main_area), debcred_area, TRUE, TRUE, 0);
2000 
2001  gtk_grid_set_column_homogeneous (GTK_GRID(debcred_area), TRUE);
2002  gtk_grid_set_column_spacing (GTK_GRID(debcred_area), 15);
2003  gtk_grid_attach (GTK_GRID(debcred_area), debits_box, 0, 0, 1, 1);
2004  gtk_widget_set_hexpand (debits_box, TRUE);
2005  gtk_widget_set_vexpand (debits_box, TRUE);
2006  gtk_widget_set_halign (debits_box, GTK_ALIGN_FILL);
2007  gtk_widget_set_valign (debits_box, GTK_ALIGN_FILL);
2008 
2009  gtk_grid_attach (GTK_GRID(debcred_area), credits_box, 1, 0, 1, 1);
2010  gtk_widget_set_hexpand (credits_box, TRUE);
2011  gtk_widget_set_vexpand (credits_box, TRUE);
2012  gtk_widget_set_halign (credits_box, GTK_ALIGN_FILL);
2013  gtk_widget_set_valign (credits_box, GTK_ALIGN_FILL);
2014 
2015  {
2016  GtkWidget *hbox, *title_vbox, *value_vbox;
2017  GtkWidget *totals_hbox, *frame, *title, *value;
2018 
2019  /* lower horizontal bar below reconcile lists */
2020  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
2021  gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
2022  gtk_box_pack_start(GTK_BOX(main_area), hbox, FALSE, FALSE, 0);
2023 
2024  /* frame to hold totals */
2025  frame = gtk_frame_new(NULL);
2026  gtk_box_pack_end(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
2027 
2028  // Set the name for this widget so it can be easily manipulated with css
2029  gtk_widget_set_name (GTK_WIDGET(frame), "gnc-id-reconcile-totals");
2030 
2031  /* hbox to hold title/value vboxes */
2032  totals_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2033  gtk_box_set_homogeneous (GTK_BOX (totals_hbox), FALSE);
2034  gtk_container_add(GTK_CONTAINER(frame), totals_hbox);
2035  gtk_container_set_border_width(GTK_CONTAINER(totals_hbox), 5);
2036 
2037  /* vbox to hold titles */
2038  title_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2039  gtk_box_set_homogeneous (GTK_BOX (title_vbox), FALSE);
2040  gtk_box_pack_start(GTK_BOX(totals_hbox), title_vbox, FALSE, FALSE, 0);
2041 
2042  /* vbox to hold values */
2043  value_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2044  gtk_box_set_homogeneous (GTK_BOX (value_vbox), FALSE);
2045  gtk_box_pack_start(GTK_BOX(totals_hbox), value_vbox, TRUE, TRUE, 0);
2046 
2047  /* statement date title/value */
2048  title = gtk_label_new(_("Statement Date"));
2049  gnc_label_set_alignment(title, 1.0, 0.5);
2050  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2051 
2052  value = gtk_label_new("");
2053  recnData->recn_date = value;
2054  gnc_label_set_alignment(value, 1.0, 0.5);
2055  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2056 
2057  /* starting balance title/value */
2058  title = gtk_label_new(_("Starting Balance"));
2059  gnc_label_set_alignment(title, 1.0, 0.5);
2060  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 3);
2061 
2062  value = gtk_label_new("");
2063  recnData->starting = value;
2064  gnc_label_set_alignment(value, 1.0, 0.5);
2065  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 3);
2066 
2067  /* ending balance title/value */
2068  title = gtk_label_new(_("Ending Balance"));
2069  gnc_label_set_alignment(title, 1.0, 0.5);
2070  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2071 
2072  value = gtk_label_new("");
2073  recnData->ending = value;
2074  gnc_label_set_alignment(value, 1.0, 0.5);
2075  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2076 
2077  /* reconciled balance title/value */
2078  title = gtk_label_new(_("Reconciled Balance"));
2079  gnc_label_set_alignment(title, 1.0, 0.5);
2080  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2081 
2082  value = gtk_label_new("");
2083  recnData->reconciled = value;
2084  gnc_label_set_alignment(value, 1.0, 0.5);
2085  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2086 
2087  /* difference title/value */
2088  title = gtk_label_new(_("Difference"));
2089  gnc_label_set_alignment(title, 1.0, 0.5);
2090  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2091 
2092  value = gtk_label_new("");
2093  recnData->difference = value;
2094  gnc_label_set_alignment(value, 1.0, 0.5);
2095  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2096  }
2097 
2098  /* Set up the data */
2099  recnRefresh (recnData);
2100  }
2101 
2102  /* Allow resize */
2103  gtk_window_set_resizable(GTK_WINDOW(recnData->window), TRUE);
2104  gtk_widget_show_all(recnData->window);
2105 
2106  gnc_reconcile_window_set_titles(recnData);
2107 
2108  recnRecalculateBalance(recnData);
2109 
2110  gnc_window_adjust_for_screen(GTK_WINDOW(recnData->window));
2111 
2112  /* Set the sort orders of the debit and credit tree views */
2113  gnc_query_sort_order(GNC_QUERY_VIEW(recnData->debit), REC_DATE, GTK_SORT_ASCENDING);
2114  gnc_query_sort_order(GNC_QUERY_VIEW(recnData->credit), REC_DATE, GTK_SORT_ASCENDING);
2115 
2116  gtk_widget_grab_focus (recnData->debit);
2117 
2118  { // align the Totals value with that of the amount column
2119  gint recn_widthc = gnc_reconcile_view_get_column_width (GNC_RECONCILE_VIEW(recnData->credit), REC_RECN);
2120  gint recn_widthd = gnc_reconcile_view_get_column_width (GNC_RECONCILE_VIEW(recnData->debit), REC_RECN);
2121 
2122  gtk_widget_set_margin_end (GTK_WIDGET(recnData->total_credit), 10 + recn_widthc);
2123  gtk_widget_set_margin_end (GTK_WIDGET(recnData->total_debit), 10 + recn_widthd);
2124  }
2125  return recnData;
2126 }
2127 
2128 
2129 /********************************************************************\
2130  * gnc_ui_reconcile_window_raise *
2131  * shows and raises an account editing window *
2132  * *
2133  * Args: editAccData - the edit window structure *
2134 \********************************************************************/
2135 void
2136 gnc_ui_reconcile_window_raise(RecnWindow * recnData)
2137 {
2138  if (recnData == NULL)
2139  return;
2140 
2141  if (recnData->window == NULL)
2142  return;
2143 
2144  gtk_window_present(GTK_WINDOW(recnData->window));
2145 }
2146 
2147 GtkWindow *
2148 gnc_ui_reconcile_window_get_window (RecnWindow * recnData)
2149 {
2150  if (recnData == NULL || recnData->window == NULL)
2151  return NULL;
2152  return GTK_WINDOW(recnData->window);
2153 }
2154 
2155 
2156 
2157 /********************************************************************\
2158  * recn_destroy_cb *
2159  * frees memory allocated for an recnWindow, and other cleanup *
2160  * stuff *
2161  * *
2162  * Args: w - the widget that called us *
2163  * data - the data struct for this window *
2164  * Return: none *
2165 \********************************************************************/
2166 static void
2167 recn_destroy_cb (GtkWidget *w, gpointer data)
2168 {
2169  auto recnData = static_cast<RecnWindow*>(data);
2170  gchar **actions = g_action_group_list_actions (G_ACTION_GROUP(recnData->simple_action_group));
2171  gint num_actions = g_strv_length (actions);
2172 
2173  gnc_unregister_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2174 
2175  if (recnData->delete_refresh)
2176  gnc_resume_gui_refresh ();
2177 
2178  //Disable the actions, the handlers try to access recnData
2179  for (gint i = 0; i < num_actions; i++)
2180  {
2181  GAction *action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group), actions[i]);
2182  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), FALSE);
2183  }
2184  g_strfreev (actions);
2185  g_free (recnData);
2186 }
2187 
2188 
2189 static void
2190 recn_cancel(RecnWindow *recnData)
2191 {
2192  gboolean changed = FALSE;
2193 
2194  if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->credit)))
2195  changed = TRUE;
2196  if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->debit)))
2197  changed = TRUE;
2198 
2199  if (changed)
2200  {
2201  const char *message = _("You have made changes to this reconcile "
2202  "window. Are you sure you want to cancel?");
2203  if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message))
2204  return;
2205  }
2206 
2207  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2208 }
2209 
2210 
2211 static gboolean
2212 recn_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
2213 {
2214  auto recnData = static_cast<RecnWindow*>(data);
2215 
2216  recn_cancel(recnData);
2217  return TRUE;
2218 }
2219 
2220 
2221 static gboolean
2222 recn_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
2223 {
2224  auto recnData = static_cast<RecnWindow*>(data);
2225 
2226  if (event->keyval == GDK_KEY_Escape)
2227  {
2228  recn_cancel(recnData);
2229  return TRUE;
2230  }
2231  else
2232  {
2233  return FALSE;
2234  }
2235 }
2236 
2237 
2238 /********************************************************************\
2239  * find_payment_account *
2240  * find an account that 'looks like' a payment account for the *
2241  * given account. This really only makes sense for credit card *
2242  * accounts. *
2243  * *
2244  * Args: account - the account to look in *
2245  * Return: a candidate payment account or NULL if none was found *
2246 \********************************************************************/
2247 static Account *
2248 find_payment_account(Account *account)
2249 {
2250  if (account == nullptr)
2251  return nullptr;
2252 
2253  const auto& splits = xaccAccountGetSplits (account);
2254 
2255  /* Search backwards to find the latest payment */
2256  for (auto it = splits.rbegin(); it != splits.rend(); it++)
2257  {
2258  auto split = *it;
2259 
2260  /* ignore 'purchases' */
2262  continue;
2263 
2264  for (auto n = xaccTransGetSplitList (xaccSplitGetParent(split)); n; n = n->next)
2265  {
2266  auto s = GNC_SPLIT(n->data);
2267  if (s == split)
2268  continue;
2269 
2270  auto a = xaccSplitGetAccount(s);
2271  if (a == account)
2272  continue;
2273 
2274  auto type = xaccAccountGetType(a);
2275  if (type == ACCT_TYPE_BANK || type == ACCT_TYPE_CASH || type == ACCT_TYPE_ASSET)
2276  return a;
2277  }
2278  }
2279 
2280  return nullptr;
2281 }
2282 
2283 static void
2284 acct_traverse_descendants (Account *acct, std::function<void(Account*)> fn)
2285 {
2286  fn (acct);
2288  gnc_account_foreach_descendant (acct, fn);
2289 }
2290 
2291 /********************************************************************\
2292  * recnFinishCB *
2293  * saves reconcile information *
2294  * *
2295  * Args: w - the widget that called us *
2296  * data - the data struct for this window *
2297  * Return: none *
2298 \********************************************************************/
2299 static void
2300 recnFinishCB (GSimpleAction *simple,
2301  GVariant *parameter,
2302  gpointer user_data)
2303 {
2304  auto recnData = static_cast<RecnWindow*>(user_data);
2305  gboolean auto_payment;
2306  Account *account;
2307  time64 date;
2308 
2309  if (!gnc_numeric_zero_p (recnRecalculateBalance(recnData)))
2310  {
2311  const char *message = _("The account is not balanced. "
2312  "Are you sure you want to finish?");
2313  if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message))
2314  return;
2315  }
2316 
2317  date = recnData->statement_date;
2318 
2319  gnc_suspend_gui_refresh ();
2320 
2321  recnData->delete_refresh = TRUE;
2322  account = recn_get_account (recnData);
2323 
2324  acct_traverse_descendants (account, xaccAccountBeginEdit);
2325  gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->credit), date);
2326  gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->debit), date);
2327  acct_traverse_descendants (account, xaccAccountCommitEdit);
2328 
2329  auto_payment = gnc_prefs_get_bool(GNC_PREFS_GROUP_RECONCILE, GNC_PREF_AUTO_CC_PAYMENT);
2330 
2332  xaccAccountSetReconcileLastDate (account, date);
2333 
2334  if (auto_payment &&
2335  (xaccAccountGetType (account) == ACCT_TYPE_CREDIT) &&
2336  (gnc_numeric_negative_p (recnData->new_ending)))
2337  {
2338  Account *payment_account;
2339  XferDialog *xfer;
2340 
2341  xfer = gnc_xfer_dialog (GTK_WIDGET (gnc_ui_get_main_window (recnData->window)), account);
2342 
2343  gnc_xfer_dialog_set_amount(xfer, gnc_numeric_neg (recnData->new_ending));
2344 
2345  payment_account = find_payment_account (account);
2346  if (payment_account != NULL)
2347  gnc_xfer_dialog_select_from_account (xfer, payment_account);
2348  }
2349 
2350  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2351 }
2352 
2353 
2354 /********************************************************************\
2355  * recnPostponeCB *
2356  * saves reconcile information for later use *
2357  * *
2358  * Args: w - the widget that called us *
2359  * data - the data struct for this window *
2360  * Return: none *
2361 \********************************************************************/
2362 static void
2363 recnPostponeCB (GSimpleAction *simple,
2364  GVariant *parameter,
2365  gpointer user_data)
2366 {
2367  auto recnData = static_cast<RecnWindow*>(user_data);
2368  Account *account;
2369 
2370  {
2371  const char *message = _("Do you want to postpone this reconciliation "
2372  "and finish it later?");
2373  if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message))
2374  return;
2375  }
2376 
2377  gnc_suspend_gui_refresh ();
2378 
2379  recnData->delete_refresh = TRUE;
2380  account = recn_get_account (recnData);
2381 
2382  acct_traverse_descendants (account, xaccAccountBeginEdit);
2383  gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->credit));
2384  gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->debit));
2385  acct_traverse_descendants (account, xaccAccountCommitEdit);
2386 
2387  xaccAccountSetReconcilePostponeDate (account, recnData->statement_date);
2388  xaccAccountSetReconcilePostponeBalance (account, recnData->new_ending);
2389 
2390  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2391 }
2392 
2393 
2394 static void
2395 recnCancelCB (GSimpleAction *simple,
2396  GVariant *parameter,
2397  gpointer user_data)
2398 {
2399  auto recnData = static_cast<RecnWindow*>(user_data);
2400  recn_cancel(recnData);
2401 }
GncPluginPage * gnc_plugin_page_register_new(Account *account, gboolean subaccounts)
Create a new "register" plugin page, given a pointer to an account.
High-Level API for imposing Lot constraints.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
gboolean xaccAccountGetAutoInterest(const Account *acc)
Get the "auto interest" flag for an account.
Definition: Account.cpp:4130
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
The instance data structure for a content plugin.
Date and Time handling routines.
This file contains the functions to present a gui to the user for creating a new account or editing a...
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account&#39;s account type.
Definition: Account.cpp:3237
gtk helper routines.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
Definition: Account.cpp:2716
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
void xaccAccountSetReconcileLastDate(Account *acc, time64 last_date)
DOCUMENT ME!
Definition: Account.cpp:4539
STRUCTS.
Functions that are supported by all types of windows.
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
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 &#39;func&#39; on each...
Definition: Account.cpp:3214
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
void xaccAccountSetReconcileLastInterval(Account *acc, int months, int days)
DOCUMENT ME!
Definition: Account.cpp:4569
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
gint gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b.
The cash account type is used to denote a shoe-box or pillowcase stuffed with * cash.
Definition: Account.h:110
const char * gnc_account_get_debit_string(GNCAccountType acct_type)
Get the debit string associated with this account type.
Definition: Account.cpp:4046
void gnc_ui_edit_account_window(GtkWindow *parent, Account *account)
Display a window for editing the attributes of an existing account.
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.
Definition: gnc-date.cpp:114
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
gboolean xaccAccountGetReconcilePostponeDate(const Account *acc, time64 *postpone_date)
DOCUMENT ME!
Definition: Account.cpp:4579
void xaccTransDestroy(Transaction *trans)
Destroys a transaction.
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
#define xaccAccountGetGUID(X)
Definition: Account.h:252
convert single-entry accounts to clean double-entry
char * qof_print_date(time64 secs)
Convenience; calls through to qof_print_date_dmy_buff().
Definition: gnc-date.cpp:609
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...
Definition: Account.cpp:3275
Functions providing a register page for the GnuCash UI.
Account public routines (C++ api)
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome&#39;s yelp for linux, and open to a given link within a gi...
#define YREC
The Split has been reconciled.
Definition: Split.h:74
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
Definition: guid.cpp:204
void xaccAccountTreeScrubOrphans(Account *acc, QofPercentageFunc percentagefunc)
The xaccAccountTreeScrubOrphans() method performs this scrub for the indicated account and its childr...
Definition: Scrub.cpp:173
void xaccAccountClearReconcilePostpone(Account *acc)
DOCUMENT ME!
Definition: Account.cpp:4629
The bank account type denotes a savings or checking account held at a bank.
Definition: Account.h:107
void xaccAccountSetReconcilePostponeDate(Account *acc, time64 postpone_date)
DOCUMENT ME!
Definition: Account.cpp:4594
Gnome specific utility functions.
Additional event handling code.
void xaccAccountSetReconcilePostponeBalance(Account *acc, gnc_numeric balance)
DOCUMENT ME!
Definition: Account.cpp:4619
asset (and liability) accounts indicate generic, generalized accounts that are none of the above...
Definition: Account.h:116
gnc_numeric xaccAccountGetBalanceAsOfDate(Account *acc, time64 date)
Get the balance of the account at the end of the day before the date specified.
Definition: Account.cpp:3489
gboolean xaccAccountGetReconcileLastDate(const Account *acc, time64 *last_date)
DOCUMENT ME!
Definition: Account.cpp:4521
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
Definition: Account.h:101
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.
#define xaccTransGetGUID(X)
Definition: Transaction.h:788
Generic api to store and retrieve preferences.
void gnc_add_accelerator_keys_for_menu(GtkWidget *menu, GMenuModel *model, GtkAccelGroup *accel_group)
Add accelerator keys for menu item widgets.
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...
Definition: Account.cpp:3014
gboolean xaccAccountGetReconcileChildrenStatus(const Account *acc)
DOCUMENT ME!
Definition: Account.cpp:4853
gboolean xaccAccountGetReconcileLastInterval(const Account *acc, int *months, int *days)
DOCUMENT ME!
Definition: Account.cpp:4548
time64 xaccSplitGetDateReconciled(const Split *split)
Retrieve the date when the Split was reconciled.
Definition: Split.cpp:1825
const char * gnc_account_get_credit_string(GNCAccountType acct_type)
Get the credit string associated with this account type.
Definition: Account.cpp:4058
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...
Definition: Account.cpp:1170
void gnc_gdate_set_time64(GDate *gd, time64 time)
Set a GDate to a time64.
Definition: gnc-date.cpp:1244
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1477
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53
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...
Definition: gnc-date.cpp:1432
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account&#39;s commodity.
Definition: Account.cpp:3371
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...
Definition: gnc-date.cpp:1356
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
time64 gnc_time(time64 *tbuf)
get the current time
Definition: gnc-date.cpp:261
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition: gnc-date.h:87
void gnc_plugin_page_register_clear_current_filter(GncPluginPage *plugin_page)
This function clears the registers current filter.
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...
Definition: gnc-date.cpp:1316
File path resolution utility functions.
Not a type.
Definition: Account.h:105
The type used to store guids in C.
Definition: guid.h:75
GNCSplitReg * gnc_plugin_page_register_get_gsr(GncPluginPage *plugin_page)
Get the GNCSplitReg data structure associated with this register page.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1518
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
void xaccAccountSetReconcileChildrenStatus(Account *acc, gboolean status)
DOCUMENT ME!
Definition: Account.cpp:4840
The Credit card account is used to denote credit (e.g.
Definition: Account.h:113
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69
gboolean xaccAccountGetReconcilePostponeBalance(const Account *acc, gnc_numeric *balance)
DOCUMENT ME!
Definition: Account.cpp:4603
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id...
Definition: Account.cpp:2052