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 (gnc_date_edit_get_date_end(GNC_DATE_EDIT(date_value)) != *statement_date)
823  recn_date_changed_cb(date_value, &data);
824 
825  /* If response is OK but end_value not valid, try again */
826  if (gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT(end_value), NULL))
827  {
828  result = GTK_RESPONSE_OK;
829  break;
830  }
831  }
832 
833  if (result == GTK_RESPONSE_OK)
834  {
835  *new_ending = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (end_value));
836  *statement_date = gnc_date_edit_get_date_end(GNC_DATE_EDIT(date_value));
837 
838  if (gnc_reverse_balance(account))
839  *new_ending = gnc_numeric_neg (*new_ending);
840 
841  xaccAccountSetReconcileChildrenStatus(account, data.include_children);
842 
843  gnc_save_reconcile_interval(account, *statement_date);
844  }
845  // must remove the focus-out handler
846  g_signal_handler_disconnect (G_OBJECT(entry), fo_handler_id);
847  gtk_widget_destroy (dialog);
848  g_object_unref(G_OBJECT(builder));
849 
850  return (result == GTK_RESPONSE_OK);
851 }
852 
853 
854 static void
855 gnc_reconcile_window_set_sensitivity(RecnWindow *recnData)
856 {
857  gboolean sensitive = FALSE;
858  GNCReconcileView *view;
859  GAction *action;
860 
861  view = GNC_RECONCILE_VIEW(recnData->debit);
862  if (gnc_reconcile_view_num_selected(view) == 1)
863  sensitive = TRUE;
864 
865  view = GNC_RECONCILE_VIEW(recnData->credit);
866  if (gnc_reconcile_view_num_selected(view) == 1)
867  sensitive = TRUE;
868 
869  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
870  "TransEditAction");
871  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
872 
873  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
874  "TransDeleteAction");
875  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
876 
877  sensitive = FALSE;
878 
879  view = GNC_RECONCILE_VIEW(recnData->debit);
880  if (gnc_reconcile_view_num_selected(view) > 0)
881  sensitive = TRUE;
882 
883  view = GNC_RECONCILE_VIEW(recnData->credit);
884  if (gnc_reconcile_view_num_selected(view) > 0)
885  sensitive = TRUE;
886 
887  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
888  "TransRecAction");
889  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
890 
891  action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group),
892  "TransUnRecAction");
893  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), sensitive);
894 }
895 
896 
897 static void
898 gnc_reconcile_window_toggled_cb(GNCReconcileView *view, Split *split,
899  gpointer data)
900 {
901  auto recnData = static_cast<RecnWindow*>(data);
902  gnc_reconcile_window_set_sensitivity(recnData);
903  recnRecalculateBalance(recnData);
904 }
905 
906 
907 static void
908 gnc_reconcile_window_row_cb(GNCReconcileView *view, gpointer item,
909  gpointer data)
910 {
911  auto recnData = static_cast<RecnWindow*>(data);
912  gnc_reconcile_window_set_sensitivity(recnData);
913 }
914 
915 
928 static void
929 do_popup_menu(RecnWindow *recnData, GdkEventButton *event)
930 {
931  GMenuModel *menu_model = (GMenuModel *)gtk_builder_get_object (recnData->builder,
932  "recwin-popup");
933  GtkWidget *menu = gtk_menu_new_from_model (menu_model);
934 
935  if (!menu)
936  return;
937 
938  gtk_menu_attach_to_widget (GTK_MENU(menu), GTK_WIDGET(recnData->window), NULL);
939  gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent *) event);
940 }
941 
942 
956 static gboolean
957 gnc_reconcile_window_popup_menu_cb (GtkWidget *widget,
958  RecnWindow *recnData)
959 {
960  do_popup_menu(recnData, NULL);
961  return TRUE;
962 }
963 
964 
965 /* Callback function invoked when the user clicks in the content of
966  * any Gnucash window. If this was a "right-click" then Gnucash will
967  * popup the contextual menu.
968  */
969 static gboolean
970 gnc_reconcile_window_button_press_cb (GtkWidget *widget,
971  GdkEventButton *event,
972  RecnWindow *recnData)
973 {
974  if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
975  {
976  GNCQueryView *qview = GNC_QUERY_VIEW(widget);
977  GtkTreePath *path;
978 
979  /* Get tree path for row that was clicked */
980  gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(qview),
981  (gint) event->x,
982  (gint) event->y,
983  &path, NULL, NULL, NULL);
984 
985  if (path)
986  {
987  GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));
988 
989  if (!gtk_tree_selection_path_is_selected (selection, path))
990  {
991  gtk_tree_selection_unselect_all (selection);
992  gtk_tree_selection_select_path (selection, path);
993  }
994  gtk_tree_path_free (path);
995  }
996  do_popup_menu (recnData, event);
997  return TRUE;
998  }
999  return FALSE;
1000 }
1001 
1002 
1003 static GNCSplitReg *
1004 gnc_reconcile_window_open_register(RecnWindow *recnData)
1005 {
1006  Account *account = recn_get_account (recnData);
1007  GNCSplitReg *gsr;
1008  gboolean include_children;
1009 
1010  if (!account)
1011  return(NULL);
1012 
1013  include_children = xaccAccountGetReconcileChildrenStatus (account);
1014  recnData->page = gnc_plugin_page_register_new (account, include_children);
1015  gnc_main_window_open_page (NULL, recnData->page);
1016  gsr = gnc_plugin_page_register_get_gsr (recnData->page);
1017  gnc_split_reg_raise (gsr);
1018  return gsr;
1019 }
1020 
1021 
1022 static void
1023 gnc_reconcile_window_double_click_cb(GNCReconcileView *view, Split *split,
1024  gpointer data)
1025 {
1026  auto recnData = static_cast<RecnWindow*>(data);
1027  GNCSplitReg *gsr;
1028 
1029  /* This should never be true, but be paranoid */
1030  if (split == NULL)
1031  return;
1032 
1033  gsr = gnc_reconcile_window_open_register(recnData);
1034  if (gsr == NULL)
1035  return;
1036 
1037  /* Test for visibility of split */
1038  if (gnc_split_reg_clear_filter_for_split (gsr, split))
1039  gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(recnData->page));
1040 
1041  gnc_split_reg_jump_to_split( gsr, split );
1042 }
1043 
1044 
1045 static void
1046 gnc_reconcile_window_focus_cb(GtkWidget *widget, GdkEventFocus *event,
1047  gpointer data)
1048 {
1049  auto recnData = static_cast<RecnWindow*>(data);
1050  GNCReconcileView *this_view, *other_view;
1051  GNCReconcileView *debit, *credit;
1052 
1053  this_view = GNC_RECONCILE_VIEW(widget);
1054 
1055  debit = GNC_RECONCILE_VIEW(recnData->debit);
1056  credit = GNC_RECONCILE_VIEW(recnData->credit);
1057 
1058  other_view = GNC_RECONCILE_VIEW(this_view == debit ? credit : debit);
1059 
1060  /* clear the *other* list so we always have no more than one selection */
1061  gnc_reconcile_view_unselect_all(other_view);
1062 }
1063 
1064 
1065 static gboolean
1066 gnc_reconcile_key_press_cb (GtkWidget *widget, GdkEventKey *event,
1067  gpointer data)
1068 {
1069  auto recnData = static_cast<RecnWindow*>(data);
1070  GtkWidget *this_view, *other_view;
1071  GtkWidget *debit, *credit;
1072 
1073  switch (event->keyval)
1074  {
1075  case GDK_KEY_Tab:
1076  case GDK_KEY_ISO_Left_Tab:
1077  break;
1078 
1079  default:
1080  return FALSE;
1081  }
1082 
1083  g_signal_stop_emission_by_name (widget, "key_press_event");
1084 
1085  this_view = widget;
1086 
1087  debit = recnData->debit;
1088  credit = recnData->credit;
1089 
1090  other_view = (this_view == debit ? credit : debit);
1091 
1092  gtk_widget_grab_focus (other_view);
1093 
1094  return TRUE;
1095 }
1096 
1097 
1098 static void
1099 gnc_reconcile_window_set_titles(RecnWindow *recnData)
1100 {
1101  const gchar *title;
1102 
1104  gtk_frame_set_label(GTK_FRAME(recnData->debit_frame), title);
1105 
1107  gtk_frame_set_label(GTK_FRAME(recnData->credit_frame), title);
1108 }
1109 
1110 
1111 static GtkWidget *
1112 gnc_reconcile_window_create_view_box(Account *account,
1113  GNCReconcileViewType type,
1114  RecnWindow *recnData,
1115  GtkWidget **list_save,
1116  GtkWidget **total_save)
1117 {
1118  GtkWidget *frame, *scrollWin, *view, *vbox, *label, *hbox;
1119  GtkWidget *vscroll;
1120  GtkRequisition nat_sb;
1121 
1122  frame = gtk_frame_new(NULL);
1123 
1124  if (type == RECLIST_DEBIT)
1125  recnData->debit_frame = frame;
1126  else
1127  recnData->credit_frame = frame;
1128 
1129  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
1130  gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE);
1131 
1132  view = gnc_reconcile_view_new(account, type, recnData->statement_date);
1133  *list_save = view;
1134 
1135  g_signal_connect(view, "toggle_reconciled",
1136  G_CALLBACK(gnc_reconcile_window_toggled_cb),
1137  recnData);
1138  g_signal_connect(view, "line_selected",
1139  G_CALLBACK(gnc_reconcile_window_row_cb),
1140  recnData);
1141  g_signal_connect(view, "button_press_event",
1142  G_CALLBACK(gnc_reconcile_window_button_press_cb),
1143  recnData);
1144  g_signal_connect(view, "double_click_split",
1145  G_CALLBACK(gnc_reconcile_window_double_click_cb),
1146  recnData);
1147  g_signal_connect(view, "focus_in_event",
1148  G_CALLBACK(gnc_reconcile_window_focus_cb),
1149  recnData);
1150  g_signal_connect(view, "key_press_event",
1151  G_CALLBACK(gnc_reconcile_key_press_cb),
1152  recnData);
1153 
1154  scrollWin = gtk_scrolled_window_new (NULL, NULL);
1155  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrollWin),
1156  GTK_POLICY_AUTOMATIC,
1157  GTK_POLICY_AUTOMATIC);
1158  gtk_container_set_border_width(GTK_CONTAINER(scrollWin), 5);
1159 
1160  gtk_container_add(GTK_CONTAINER(frame), scrollWin);
1161  gtk_container_add(GTK_CONTAINER(scrollWin), view);
1162  gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
1163 
1164  // get the vertical scroll bar width
1165  vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (scrollWin));
1166  gtk_widget_get_preferred_size (vscroll, NULL, &nat_sb);
1167 
1168  // add xpadding to recn column so scrollbar does not cover
1169  gnc_reconcile_view_add_padding (GNC_RECONCILE_VIEW(view), REC_RECN, nat_sb.width);
1170 
1171  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
1172  gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
1173  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
1174 
1175  label = gtk_label_new(_("Total"));
1176  gnc_label_set_alignment(label, 1.0, 0.5);
1177  gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
1178 
1179  label = gtk_label_new("");
1180  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1181  *total_save = label;
1182  gtk_widget_set_margin_end (GTK_WIDGET(label), 10 + nat_sb.width);
1183 
1184  return vbox;
1185 }
1186 
1187 
1188 static Split *
1189 gnc_reconcile_window_get_current_split(RecnWindow *recnData)
1190 {
1191  GNCReconcileView *view;
1192  Split *split;
1193 
1194  view = GNC_RECONCILE_VIEW(recnData->debit);
1195  split = gnc_reconcile_view_get_current_split(view);
1196  if (split != NULL)
1197  return split;
1198 
1199  view = GNC_RECONCILE_VIEW(recnData->credit);
1200  split = gnc_reconcile_view_get_current_split(view);
1201 
1202  return split;
1203 }
1204 
1205 
1206 static void
1207 gnc_ui_reconcile_window_help_cb (GSimpleAction *simple,
1208  GVariant *parameter,
1209  gpointer user_data)
1210 {
1211  auto recnData = static_cast<RecnWindow*>(user_data);
1212  gnc_gnome_help (GTK_WINDOW(recnData->window), DF_MANUAL, DL_RECNWIN);
1213 }
1214 
1215 
1216 static void
1217 gnc_ui_reconcile_window_change_cb (GSimpleAction *simple,
1218  GVariant *parameter,
1219  gpointer user_data)
1220 {
1221  auto recnData = static_cast<RecnWindow*>(user_data);
1222  Account *account = recn_get_account (recnData);
1223  gnc_numeric new_ending = recnData->new_ending;
1224  time64 statement_date = recnData->statement_date;
1225 
1226  if (gnc_reverse_balance (account))
1227  new_ending = gnc_numeric_neg (new_ending);
1228  if (startRecnWindow (recnData->window, account, &new_ending, &statement_date,
1229  FALSE))
1230  {
1231  recnData->new_ending = new_ending;
1232  recnData->statement_date = statement_date;
1233  recnRecalculateBalance (recnData);
1234  }
1235 }
1236 
1237 
1238 static void
1239 gnc_ui_reconcile_window_balance_cb (GSimpleAction *simple,
1240  GVariant *parameter,
1241  gpointer user_data)
1242 {
1243  auto recnData = static_cast<RecnWindow*>(user_data);
1244  GNCSplitReg *gsr;
1245  Account *account;
1246  gnc_numeric balancing_amount;
1247  time64 statement_date;
1248 
1249 
1250  gsr = gnc_reconcile_window_open_register(recnData);
1251  if (gsr == NULL)
1252  return;
1253 
1254  account = recn_get_account(recnData);
1255  if (account == NULL)
1256  return;
1257 
1258  balancing_amount = recnRecalculateBalance(recnData);
1259  if (gnc_numeric_zero_p(balancing_amount))
1260  return;
1261 
1262  statement_date = recnData->statement_date;
1263  if (statement_date == 0)
1264  statement_date = gnc_time (NULL); // default to 'now'
1265 
1266  gnc_split_reg_balancing_entry(gsr, account, statement_date, balancing_amount);
1267 }
1268 
1269 
1270 static void
1271 gnc_ui_reconcile_window_rec_cb (GSimpleAction *simple,
1272  GVariant *parameter,
1273  gpointer user_data)
1274 {
1275  auto recnData = static_cast<RecnWindow*>(user_data);
1276  GNCReconcileView *debit, *credit;
1277 
1278  debit = GNC_RECONCILE_VIEW(recnData->debit);
1279  credit = GNC_RECONCILE_VIEW(recnData->credit);
1280 
1281  gnc_reconcile_view_set_list (debit, TRUE);
1282  gnc_reconcile_view_set_list (credit, TRUE);
1283 }
1284 
1285 
1286 static void
1287 gnc_ui_reconcile_window_unrec_cb (GSimpleAction *simple,
1288  GVariant *parameter,
1289  gpointer user_data)
1290 {
1291  auto recnData = static_cast<RecnWindow*>(user_data);
1292  GNCReconcileView *debit, *credit;
1293 
1294  debit = GNC_RECONCILE_VIEW(recnData->debit);
1295  credit = GNC_RECONCILE_VIEW(recnData->credit);
1296 
1297  gnc_reconcile_view_set_list (debit, FALSE);
1298  gnc_reconcile_view_set_list (credit, FALSE);
1299 }
1300 
1301 
1307 static GNCReconcileView *
1308 gnc_reconcile_window_get_selection_view (RecnWindow *recnData)
1309 {
1310  if (gnc_reconcile_view_num_selected (GNC_RECONCILE_VIEW (recnData->debit)) > 0)
1311  return GNC_RECONCILE_VIEW (recnData->debit);
1312 
1313  if (gnc_reconcile_view_num_selected (GNC_RECONCILE_VIEW (recnData->credit)) > 0)
1314  return GNC_RECONCILE_VIEW (recnData->credit);
1315 
1316  return NULL;
1317 }
1318 
1319 
1326 static void
1327 gnc_reconcile_window_delete_set_next_selection (RecnWindow *recnData, Split *split)
1328 {
1329  GNCReconcileView *view = gnc_reconcile_window_get_selection_view (recnData);
1330  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1331  Split *this_split = NULL;
1332  GtkTreeIter iter;
1333  GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
1334  GList *path_list, *node;
1335  GtkTreePath *save_del_path;
1336  Transaction* trans = xaccSplitGetParent (split); // parent transaction of the split to delete
1337 
1338  if (!view)
1339  return; // no selected split
1340 
1341  path_list = gtk_tree_selection_get_selected_rows (selection, &model);
1342  // get path of the first split selected - there should be only 1 selected
1343  node = g_list_first (path_list);
1344  if (!node)
1345  return;
1346  auto path = static_cast<GtkTreePath*>(node->data);
1347  save_del_path = gtk_tree_path_copy (path);
1348 
1349  gtk_tree_path_next (path);
1350  if (gtk_tree_model_get_iter (model, &iter, path))
1351  {
1352  do
1353  {
1354  gtk_tree_model_get (model, &iter, REC_POINTER, &this_split, -1);
1355  }
1356  while (xaccSplitGetParent (this_split) == trans && gtk_tree_model_iter_next (model, &iter));
1357  }
1358 
1359  if ((!this_split) || xaccSplitGetParent (this_split) == trans)
1360  {
1361  // There aren't any splits for a different transaction after the split to be deleted,
1362  // so find the previous split having a different parent transaction
1363  path = save_del_path; // split to be deleted
1364  if (gtk_tree_path_prev (path) && gtk_tree_model_get_iter (model, &iter, path))
1365  {
1366  do
1367  {
1368  gtk_tree_model_get (model, &iter, REC_POINTER, &this_split, -1);
1369  }
1370  while (xaccSplitGetParent (this_split) == trans && gtk_tree_model_iter_previous (model, &iter));
1371  }
1372  }
1373 
1374  gtk_tree_path_free (save_del_path);
1375  g_list_free_full (path_list, (GDestroyNotify) gtk_tree_path_free);
1376  if ((!this_split) || xaccSplitGetParent (this_split) == trans)
1377  return;
1378 
1379  gtk_tree_selection_select_iter (selection, &iter);
1380 }
1381 
1382 
1383 static void
1384 gnc_ui_reconcile_window_delete_cb (GSimpleAction *simple,
1385  GVariant *parameter,
1386  gpointer user_data)
1387 {
1388  auto recnData = static_cast<RecnWindow*>(user_data);
1389  Transaction *trans;
1390  Split *split;
1391 
1392  split = gnc_reconcile_window_get_current_split(recnData);
1393  /* This should never be true, but be paranoid */
1394  if (split == NULL)
1395  return;
1396 
1397  {
1398  const char *message = _("Are you sure you want to delete the selected "
1399  "transaction?");
1400  gboolean result;
1401 
1402  result = gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message);
1403 
1404  if (!result)
1405  return;
1406  }
1407 
1408  /* select the split that should be visible after the deletion */
1409  gnc_reconcile_window_delete_set_next_selection(recnData, split);
1410 
1411  gnc_suspend_gui_refresh ();
1412 
1413  trans = xaccSplitGetParent(split);
1414  xaccTransDestroy(trans);
1415 
1416  gnc_resume_gui_refresh ();
1417 }
1418 
1419 
1420 static void
1421 gnc_ui_reconcile_window_edit_cb (GSimpleAction *simple,
1422  GVariant *parameter,
1423  gpointer user_data)
1424 {
1425  auto recnData = static_cast<RecnWindow*>(user_data);
1426  GNCSplitReg *gsr;
1427  Split *split;
1428 
1429  split = gnc_reconcile_window_get_current_split (recnData);
1430  /* This should never be true, but be paranoid */
1431  if (split == NULL)
1432  return;
1433 
1434  gsr = gnc_reconcile_window_open_register(recnData);
1435  if (gsr == NULL)
1436  return;
1437 
1438  /* Test for visibility of split */
1439  if (gnc_split_reg_clear_filter_for_split (gsr, split))
1440  gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(recnData->page));
1441 
1442  gnc_split_reg_jump_to_split_amount( gsr, split );
1443 }
1444 
1445 
1446 static char *
1447 gnc_recn_make_window_name(Account *account)
1448 {
1449  char *fullname;
1450  char *title;
1451 
1452  fullname = gnc_account_get_full_name(account);
1453  title = g_strconcat(fullname, " - ", _("Reconcile"), NULL);
1454 
1455  g_free(fullname);
1456 
1457  return title;
1458 }
1459 
1460 
1461 static void
1462 gnc_recn_set_window_name(RecnWindow *recnData)
1463 {
1464  char *title;
1465 
1466  title = gnc_recn_make_window_name (recn_get_account (recnData));
1467 
1468  gtk_window_set_title (GTK_WINDOW (recnData->window), title);
1469 
1470  g_free (title);
1471 }
1472 
1473 
1474 static void
1475 gnc_recn_edit_account_cb (GSimpleAction *simple,
1476  GVariant *parameter,
1477  gpointer user_data)
1478 {
1479  auto recnData = static_cast<RecnWindow*>(user_data);
1480  Account *account = recn_get_account (recnData);
1481 
1482  if (account == NULL)
1483  return;
1484 
1485  gnc_ui_edit_account_window (GTK_WINDOW (recnData->window), account);
1486 }
1487 
1488 
1489 static void
1490 gnc_recn_xfer_cb (GSimpleAction *simple,
1491  GVariant *parameter,
1492  gpointer user_data)
1493 {
1494  auto recnData = static_cast<RecnWindow*>(user_data);
1495  Account *account = recn_get_account (recnData);
1496 
1497  if (account == NULL)
1498  return;
1499 
1500  gnc_xfer_dialog (recnData->window, account);
1501 }
1502 
1503 
1504 static void
1505 gnc_recn_scrub_cb (GSimpleAction *simple,
1506  GVariant *parameter,
1507  gpointer user_data)
1508 {
1509  auto recnData = static_cast<RecnWindow*>(user_data);
1510  Account *account = recn_get_account (recnData);
1511 
1512  if (account == NULL)
1513  return;
1514 
1515  gnc_suspend_gui_refresh ();
1516 
1517  xaccAccountTreeScrubOrphans (account, gnc_window_show_progress);
1518  xaccAccountTreeScrubImbalance (account, gnc_window_show_progress);
1519 
1520  // XXX: Lots are disabled.
1521  if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
1522  xaccAccountTreeScrubLots(account);
1523 
1524  gnc_resume_gui_refresh ();
1525 }
1526 
1527 
1528 static void
1529 gnc_recn_open_cb (GSimpleAction *simple,
1530  GVariant *parameter,
1531  gpointer user_data)
1532 {
1533  auto recnData = static_cast<RecnWindow*>(user_data);
1534 
1535  gnc_reconcile_window_open_register(recnData);
1536 }
1537 
1538 
1539 static void
1540 gnc_get_reconcile_info (Account *account,
1541  gnc_numeric *new_ending,
1542  time64 *statement_date)
1543 {
1544  gboolean always_today;
1545  GDate date;
1546  time64 today;
1547 
1548  g_date_clear(&date, 1);
1549 
1550  always_today = gnc_prefs_get_bool(GNC_PREFS_GROUP_RECONCILE, GNC_PREF_ALWAYS_REC_TO_TODAY);
1551 
1552  if (!always_today &&
1553  xaccAccountGetReconcileLastDate (account, statement_date))
1554  {
1555  int months = 1, days = 0;
1556 
1557  gnc_gdate_set_time64(&date, *statement_date);
1558 
1559  xaccAccountGetReconcileLastInterval (account, &months, &days);
1560 
1561  if (months)
1562  {
1563  gboolean was_last_day_of_month = g_date_is_last_of_month(&date);
1564 
1565  g_date_add_months(&date, months);
1566 
1567  /* Track last day of the month, i.e. 1/31 -> 2/28 -> 3/31 */
1568  if (was_last_day_of_month)
1569  {
1570  g_date_set_day (&date, g_date_get_days_in_month(g_date_get_month(&date),
1571  g_date_get_year( &date)));
1572  }
1573  }
1574  else
1575  {
1576  g_date_add_days (&date, days);
1577  }
1578 
1579  *statement_date = gnc_time64_get_day_end_gdate (&date);
1580 
1581  today = gnc_time64_get_day_end (gnc_time (NULL));
1582  if (*statement_date > today)
1583  *statement_date = today;
1584  }
1585 
1586  xaccAccountGetReconcilePostponeDate (account, statement_date);
1587 
1588  if (xaccAccountGetReconcilePostponeBalance(account, new_ending))
1589  {
1590  if (gnc_reverse_balance(account))
1591  *new_ending = gnc_numeric_neg(*new_ending);
1592  }
1593  else
1594  {
1595  /* if the account wasn't previously postponed, try to predict
1596  * the statement balance based on the statement date.
1597  */
1598  *new_ending =
1599  gnc_ui_account_get_balance_as_of_date
1600  (account, *statement_date,
1602  }
1603 }
1604 
1605 
1606 static gboolean
1607 find_by_account (gpointer find_data, gpointer user_data)
1608 {
1609  auto account = GNC_ACCOUNT(find_data);
1610  auto recnData = static_cast<RecnWindow*>(user_data);
1611 
1612  if (!recnData)
1613  return FALSE;
1614 
1615  return guid_equal (&recnData->account, xaccAccountGetGUID (account));
1616 }
1617 
1618 
1619 static void
1620 recn_set_watches_one_account (gpointer data, gpointer user_data)
1621 {
1622  Account *account = (Account *)data;
1623  RecnWindow *recnData = (RecnWindow *)user_data;
1624 
1625  /* add a watch on the account */
1626  gnc_gui_component_watch_entity (recnData->component_id,
1627  xaccAccountGetGUID (account),
1628  QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1629 
1630  /* add a watch on each split for the account */
1631  for (auto split : xaccAccountGetSplits (account))
1632  {
1633  auto trans = xaccSplitGetParent (split);
1634  gnc_gui_component_watch_entity (recnData->component_id,
1635  xaccTransGetGUID (trans),
1636  QOF_EVENT_MODIFY
1637  | QOF_EVENT_DESTROY
1638  | GNC_EVENT_ITEM_CHANGED);
1639  }
1640 }
1641 
1642 
1643 static void
1644 recn_set_watches (RecnWindow *recnData)
1645 {
1646  gboolean include_children;
1647  Account *account;
1648  GList *accounts = NULL;
1649 
1650  gnc_gui_component_clear_watches (recnData->component_id);
1651 
1652  account = recn_get_account (recnData);
1653 
1654  include_children = xaccAccountGetReconcileChildrenStatus(account);
1655  if (include_children)
1656  accounts = gnc_account_get_descendants(account);
1657 
1658  /* match the account */
1659  accounts = g_list_prepend (accounts, account);
1660 
1661  g_list_foreach(accounts, recn_set_watches_one_account, recnData);
1662 
1663  g_list_free (accounts);
1664 }
1665 
1666 
1667 static void
1668 refresh_handler (GHashTable *changes, gpointer user_data)
1669 {
1670  auto recnData = static_cast<RecnWindow*>(user_data);
1671  const EventInfo *info;
1672  Account *account;
1673 
1674  account = recn_get_account (recnData);
1675  if (!account)
1676  {
1677  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1678  return;
1679  }
1680 
1681  if (changes)
1682  {
1683  info = gnc_gui_get_entity_events (changes, &recnData->account);
1684  if (info && (info->event_mask & QOF_EVENT_DESTROY))
1685  {
1686  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1687  return;
1688  }
1689  }
1690 
1691  gnc_reconcile_window_set_titles(recnData);
1692  recn_set_watches (recnData);
1693 
1694  recnRefresh (recnData);
1695 }
1696 
1697 
1698 static void
1699 close_handler (gpointer user_data)
1700 {
1701  auto recnData = static_cast<RecnWindow*>(user_data);
1702 
1703  gnc_save_window_size(GNC_PREFS_GROUP_RECONCILE, GTK_WINDOW(recnData->window));
1704  gtk_widget_destroy (recnData->window);
1705 }
1706 
1707 
1708 /********************************************************************\
1709  * recnWindow *
1710  * opens up the window to reconcile an account *
1711  * *
1712  * Args: parent - the parent of this window *
1713  * account - the account to reconcile *
1714  * Return: recnData - the instance of this RecnWindow *
1715 \********************************************************************/
1716 RecnWindow *
1717 recnWindow (GtkWidget *parent, Account *account)
1718 {
1719  gnc_numeric new_ending;
1720  gboolean enable_subaccounts;
1721  time64 statement_date;
1722 
1723  if (account == NULL)
1724  return NULL;
1725 
1726  /* The last time reconciliation was attempted during the current execution
1727  * of gnucash, the date was stored. Use that date if possible. This helps
1728  * with balancing multiple accounts for which statements are issued at the
1729  * same time, like multiple bank accounts on a single statement. Otherwise
1730  * use the end of today to ensure we include any transactions posted
1731  * today.
1732  */
1733  if (!gnc_reconcile_last_statement_date)
1734  statement_date = gnc_time64_get_day_end(gnc_time (NULL));
1735  else
1736  statement_date = gnc_reconcile_last_statement_date;
1737 
1738  gnc_get_reconcile_info (account, &new_ending, &statement_date);
1739 
1740  enable_subaccounts = !has_account_different_commodities(account);
1741  /* Popup a little window to prompt the user to enter the
1742  * ending balance for his/her bank statement */
1743  if (!startRecnWindow (parent, account, &new_ending, &statement_date,
1744  enable_subaccounts))
1745  return NULL;
1746 
1747  return recnWindowWithBalance (parent, account, new_ending, statement_date);
1748 }
1749 
1750 
1751 static GActionEntry recWindow_actions_entries [] =
1752 {
1753  { "RecnChangeInfoAction", gnc_ui_reconcile_window_change_cb, NULL, NULL, NULL },
1754  { "RecnFinishAction", recnFinishCB, NULL, NULL, NULL },
1755  { "RecnPostponeAction", recnPostponeCB, NULL, NULL, NULL },
1756  { "RecnCancelAction", recnCancelCB, NULL, NULL, NULL },
1757 
1758  { "AccountOpenAccountAction", gnc_recn_open_cb, NULL, NULL, NULL },
1759  { "AccountEditAccountAction", gnc_recn_edit_account_cb, NULL, NULL, NULL },
1760  { "AccountTransferAction", gnc_recn_xfer_cb, NULL, NULL, NULL },
1761  { "AccountCheckRepairAction", gnc_recn_scrub_cb, NULL, NULL, NULL },
1762 
1763  { "TransBalanceAction", gnc_ui_reconcile_window_balance_cb, NULL, NULL, NULL },
1764  { "TransEditAction", gnc_ui_reconcile_window_edit_cb, NULL, NULL, NULL },
1765  { "TransDeleteAction", gnc_ui_reconcile_window_delete_cb, NULL, NULL, NULL },
1766  { "TransRecAction", gnc_ui_reconcile_window_rec_cb, NULL, NULL, NULL },
1767  { "TransUnRecAction", gnc_ui_reconcile_window_unrec_cb, NULL, NULL, NULL },
1768 
1769  { "HelpHelpAction", gnc_ui_reconcile_window_help_cb, NULL, NULL, NULL },
1770 };
1772 static guint recnWindow_n_actions_entries = G_N_ELEMENTS(recWindow_actions_entries);
1773 
1774 #ifdef MAC_INTEGRATION
1775 /* Enable GtkMenuItem accelerators */
1776 static gboolean
1777 can_activate_cb(GtkWidget *widget, guint signal_id, gpointer data)
1778 {
1779  //return gtk_widget_is_sensitive (widget);
1780  return TRUE;
1781 }
1782 #endif
1783 
1784 /********************************************************************\
1785  * recnWindowWithBalance
1786  *
1787  * Opens up the window to reconcile an account, but with ending
1788  * balance and statement date already given.
1789  *
1790  * Args: parent - The parent widget of the new window
1791  * account - The account to reconcile
1792  * new_ending - The amount for ending balance
1793  * statement_date - The date of the statement
1794  * Return: recnData - the instance of this RecnWindow
1795 \********************************************************************/
1796 RecnWindow *
1797 recnWindowWithBalance (GtkWidget *parent, Account *account, gnc_numeric new_ending,
1798  time64 statement_date)
1799 {
1800  RecnWindow *recnData;
1801  GtkWidget *statusbar;
1802  GtkWidget *vbox;
1803  GtkWidget *dock;
1804 
1805  if (account == NULL)
1806  return NULL;
1807 
1808  recnData = static_cast<RecnWindow*>(gnc_find_first_gui_component (WINDOW_RECONCILE_CM_CLASS,
1809  find_by_account, account));
1810  if (recnData)
1811  return recnData;
1812 
1813  recnData = g_new0 (RecnWindow, 1);
1814 
1815  recnData->account = *xaccAccountGetGUID (account);
1816 
1817 
1818  recnData->component_id =
1819  gnc_register_gui_component (WINDOW_RECONCILE_CM_CLASS,
1820  refresh_handler, close_handler,
1821  recnData);
1822  gnc_gui_component_set_session (recnData->component_id, gnc_get_current_session());
1823 
1824  recn_set_watches (recnData);
1825 
1826  gnc_reconcile_last_statement_date = statement_date;
1827 
1828  recnData->new_ending = new_ending;
1829  recnData->statement_date = statement_date;
1830  recnData->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1831  recnData->delete_refresh = FALSE;
1832 
1833  gnc_recn_set_window_name(recnData);
1834 
1835  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1836  gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE);
1837  gtk_container_add(GTK_CONTAINER(recnData->window), vbox);
1838 
1839  // Set the name for this dialog so it can be easily manipulated with css
1840  gtk_widget_set_name (GTK_WIDGET(recnData->window), "gnc-id-reconcile");
1841 
1842  dock = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1843  gtk_box_set_homogeneous (GTK_BOX (dock), FALSE);
1844  gtk_widget_show(dock);
1845  gtk_box_pack_start(GTK_BOX (vbox), dock, FALSE, TRUE, 0);
1846 
1847  {
1848  GtkToolbar *tool_bar;
1849  GMenuModel *menu_model;
1850  GtkWidget *menu_bar;
1851  GtkAccelGroup *accel_group = gtk_accel_group_new ();
1852  const gchar *ui = GNUCASH_RESOURCE_PREFIX "/gnc-reconcile-window.ui";
1853  GError *error = NULL;
1854 
1855  recnData->builder = gtk_builder_new ();
1856 
1857  gtk_builder_add_from_resource (recnData->builder, ui, &error);
1858 
1859  gtk_builder_set_translation_domain (recnData->builder, PROJECT_NAME);
1860 
1861  if (error)
1862  {
1863  g_critical ("Failed to load ui resource %s, Error %s", ui, error->message);
1864  g_error_free (error);
1865  gnc_unregister_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
1866  g_free (recnData);
1867  return NULL;
1868  }
1869 
1870  menu_model = (GMenuModel *)gtk_builder_get_object (recnData->builder, "recwin-menu");
1871  menu_bar = gtk_menu_bar_new_from_model (menu_model);
1872  gtk_container_add (GTK_CONTAINER(vbox), menu_bar);
1873 #ifdef MAC_INTEGRATION
1874  auto theApp = static_cast<GtkosxApplication*>(g_object_new (GTKOSX_TYPE_APPLICATION, NULL));
1875  gtk_widget_hide (menu_bar);
1876  gtk_widget_set_no_show_all (menu_bar, TRUE);
1877  if (GTK_IS_MENU_ITEM (menu_bar))
1878  menu_bar = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_bar));
1879 
1880  gtkosx_application_set_menu_bar (theApp, GTK_MENU_SHELL (menu_bar));
1881 #endif
1882  tool_bar = (GtkToolbar *)gtk_builder_get_object (recnData->builder, "recwin-toolbar");
1883 
1884  gtk_toolbar_set_style (GTK_TOOLBAR(tool_bar), GTK_TOOLBAR_BOTH);
1885  gtk_toolbar_set_icon_size (GTK_TOOLBAR(tool_bar),
1886  GTK_ICON_SIZE_SMALL_TOOLBAR);
1887 
1888  gtk_container_add (GTK_CONTAINER(vbox), GTK_WIDGET(tool_bar));
1889 
1890  gtk_window_add_accel_group (GTK_WINDOW(recnData->window), accel_group);
1891 
1892  // need to add the accelerator keys
1893  gnc_add_accelerator_keys_for_menu (menu_bar, menu_model, accel_group);
1894 
1895 #ifdef MAC_INTEGRATION
1896  gtkosx_application_sync_menubar (theApp);
1897  g_signal_connect (menu_bar, "can-activate-accel",
1898  G_CALLBACK(can_activate_cb), NULL);
1899  g_object_unref (theApp);
1900  theApp = NULL;
1901 #endif
1902 
1903  recnData->simple_action_group = g_simple_action_group_new ();
1904 
1905  g_action_map_add_action_entries (G_ACTION_MAP(recnData->simple_action_group),
1906  recWindow_actions_entries,
1907  recnWindow_n_actions_entries,
1908  recnData);
1909 
1910  gtk_widget_insert_action_group (GTK_WIDGET(recnData->window), "recwin",
1911  G_ACTION_GROUP(recnData->simple_action_group));
1912  }
1913 
1914  g_signal_connect(recnData->window, "popup-menu",
1915  G_CALLBACK(gnc_reconcile_window_popup_menu_cb), recnData);
1916 
1917  statusbar = gtk_statusbar_new();
1918  gtk_box_pack_end(GTK_BOX(vbox), statusbar, FALSE, FALSE, 0);
1919 
1920  g_signal_connect (recnData->window, "destroy",
1921  G_CALLBACK(recn_destroy_cb), recnData);
1922  g_signal_connect (recnData->window, "delete_event",
1923  G_CALLBACK(recn_delete_cb), recnData);
1924  g_signal_connect (recnData->window, "key_press_event",
1925  G_CALLBACK(recn_key_press_cb), recnData);
1926 
1927 
1928  /* if account has a reconciled split where reconciled_date is
1929  later than statement_date, emit a warning into statusbar */
1930  {
1931  GtkStatusbar *bar = GTK_STATUSBAR (statusbar);
1932  guint context = gtk_statusbar_get_context_id (bar, "future_dates");
1933  GtkWidget *box = gtk_statusbar_get_message_area (bar);
1934  GtkWidget *image = gtk_image_new_from_icon_name
1935  ("dialog-warning", GTK_ICON_SIZE_SMALL_TOOLBAR);
1936 
1937  // find an already reconciled split whose statement date
1938  // is after *this* reconciliation statement date.
1939  auto has_later_recn_statement_date = [statement_date](const Split *split)
1940  { return (xaccSplitGetReconcile (split) == YREC &&
1941  xaccSplitGetDateReconciled (split) > statement_date); };
1942 
1943  if (auto split = gnc_account_find_split (account, has_later_recn_statement_date, true))
1944  {
1945  auto datestr = qof_print_date (xaccTransGetDate (xaccSplitGetParent (split)));
1946  auto recnstr = qof_print_date (xaccSplitGetDateReconciled (split));
1947  PWARN ("split posting_date=%s, recn_date=%s", datestr, recnstr);
1948 
1949  gtk_statusbar_push (bar, context, _("WARNING! Account contains \
1950 splits whose reconcile date is after statement date. Reconciliation may be \
1951 difficult."));
1952 
1953  gtk_widget_set_tooltip_text (GTK_WIDGET (bar), _("This account \
1954 has splits whose Reconciled Date is after this reconciliation statement date. \
1955 These splits may make reconciliation difficult. If this is the case, you may \
1956 use Find Transactions to find them, unreconcile, and re-reconcile."));
1957 
1958  gtk_box_pack_start (GTK_BOX(box), image, FALSE, FALSE, 0);
1959  gtk_box_reorder_child (GTK_BOX(box), image, 0);
1960 
1961  g_free (datestr);
1962  g_free (recnstr);
1963  }
1964  }
1965 
1966  /* The main area */
1967  {
1968  GtkWidget *frame = gtk_frame_new(NULL);
1969  GtkWidget *main_area = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
1970  GtkWidget *debcred_area = gtk_grid_new ();
1971  GtkWidget *debits_box;
1972  GtkWidget *credits_box;
1973 
1974  gtk_box_set_homogeneous (GTK_BOX (main_area), FALSE);
1975  gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 10);
1976 
1977  /* Force a reasonable starting size */
1978  gtk_window_set_default_size(GTK_WINDOW(recnData->window), 800, 600);
1979  gnc_restore_window_size (GNC_PREFS_GROUP_RECONCILE,
1980  GTK_WINDOW(recnData->window), GTK_WINDOW(parent));
1981 
1982  gtk_container_add(GTK_CONTAINER(frame), main_area);
1983  gtk_container_set_border_width(GTK_CONTAINER(main_area), 10);
1984 
1985  debits_box = gnc_reconcile_window_create_view_box
1986  (account, RECLIST_DEBIT, recnData,
1987  &recnData->debit, &recnData->total_debit);
1988 
1989  // Add a style context for this widget so it can be easily manipulated with css
1990  gnc_widget_style_context_add_class (GTK_WIDGET(debits_box), "gnc-class-debits");
1991 
1992  credits_box = gnc_reconcile_window_create_view_box
1993  (account, RECLIST_CREDIT, recnData,
1994  &recnData->credit, &recnData->total_credit);
1995 
1996  // Add a style context for this widget so it can be easily manipulated with css
1997  gnc_widget_style_context_add_class (GTK_WIDGET(credits_box), "gnc-class-credits");
1998 
1999  GNC_RECONCILE_VIEW(recnData->debit)->sibling = GNC_RECONCILE_VIEW(recnData->credit);
2000  GNC_RECONCILE_VIEW(recnData->credit)->sibling = GNC_RECONCILE_VIEW(recnData->debit);
2001 
2002  gtk_box_pack_start(GTK_BOX(main_area), debcred_area, TRUE, TRUE, 0);
2003 
2004  gtk_grid_set_column_homogeneous (GTK_GRID(debcred_area), TRUE);
2005  gtk_grid_set_column_spacing (GTK_GRID(debcred_area), 15);
2006  gtk_grid_attach (GTK_GRID(debcred_area), debits_box, 0, 0, 1, 1);
2007  gtk_widget_set_hexpand (debits_box, TRUE);
2008  gtk_widget_set_vexpand (debits_box, TRUE);
2009  gtk_widget_set_halign (debits_box, GTK_ALIGN_FILL);
2010  gtk_widget_set_valign (debits_box, GTK_ALIGN_FILL);
2011 
2012  gtk_grid_attach (GTK_GRID(debcred_area), credits_box, 1, 0, 1, 1);
2013  gtk_widget_set_hexpand (credits_box, TRUE);
2014  gtk_widget_set_vexpand (credits_box, TRUE);
2015  gtk_widget_set_halign (credits_box, GTK_ALIGN_FILL);
2016  gtk_widget_set_valign (credits_box, GTK_ALIGN_FILL);
2017 
2018  {
2019  GtkWidget *hbox, *title_vbox, *value_vbox;
2020  GtkWidget *totals_hbox, *frame, *title, *value;
2021 
2022  /* lower horizontal bar below reconcile lists */
2023  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
2024  gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
2025  gtk_box_pack_start(GTK_BOX(main_area), hbox, FALSE, FALSE, 0);
2026 
2027  /* frame to hold totals */
2028  frame = gtk_frame_new(NULL);
2029  gtk_box_pack_end(GTK_BOX(hbox), frame, FALSE, FALSE, 0);
2030 
2031  // Set the name for this widget so it can be easily manipulated with css
2032  gtk_widget_set_name (GTK_WIDGET(frame), "gnc-id-reconcile-totals");
2033 
2034  /* hbox to hold title/value vboxes */
2035  totals_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2036  gtk_box_set_homogeneous (GTK_BOX (totals_hbox), FALSE);
2037  gtk_container_add(GTK_CONTAINER(frame), totals_hbox);
2038  gtk_container_set_border_width(GTK_CONTAINER(totals_hbox), 5);
2039 
2040  /* vbox to hold titles */
2041  title_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2042  gtk_box_set_homogeneous (GTK_BOX (title_vbox), FALSE);
2043  gtk_box_pack_start(GTK_BOX(totals_hbox), title_vbox, FALSE, FALSE, 0);
2044 
2045  /* vbox to hold values */
2046  value_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2047  gtk_box_set_homogeneous (GTK_BOX (value_vbox), FALSE);
2048  gtk_box_pack_start(GTK_BOX(totals_hbox), value_vbox, TRUE, TRUE, 0);
2049 
2050  /* statement date title/value */
2051  title = gtk_label_new(_("Statement Date"));
2052  gnc_label_set_alignment(title, 1.0, 0.5);
2053  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2054 
2055  value = gtk_label_new("");
2056  recnData->recn_date = value;
2057  gnc_label_set_alignment(value, 1.0, 0.5);
2058  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2059 
2060  /* starting balance title/value */
2061  title = gtk_label_new(_("Starting Balance"));
2062  gnc_label_set_alignment(title, 1.0, 0.5);
2063  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 3);
2064 
2065  value = gtk_label_new("");
2066  recnData->starting = value;
2067  gnc_label_set_alignment(value, 1.0, 0.5);
2068  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 3);
2069 
2070  /* ending balance title/value */
2071  title = gtk_label_new(_("Ending Balance"));
2072  gnc_label_set_alignment(title, 1.0, 0.5);
2073  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2074 
2075  value = gtk_label_new("");
2076  recnData->ending = value;
2077  gnc_label_set_alignment(value, 1.0, 0.5);
2078  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2079 
2080  /* reconciled balance title/value */
2081  title = gtk_label_new(_("Reconciled Balance"));
2082  gnc_label_set_alignment(title, 1.0, 0.5);
2083  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2084 
2085  value = gtk_label_new("");
2086  recnData->reconciled = value;
2087  gnc_label_set_alignment(value, 1.0, 0.5);
2088  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2089 
2090  /* difference title/value */
2091  title = gtk_label_new(_("Difference"));
2092  gnc_label_set_alignment(title, 1.0, 0.5);
2093  gtk_box_pack_start(GTK_BOX(title_vbox), title, FALSE, FALSE, 0);
2094 
2095  value = gtk_label_new("");
2096  recnData->difference = value;
2097  gnc_label_set_alignment(value, 1.0, 0.5);
2098  gtk_box_pack_start(GTK_BOX(value_vbox), value, FALSE, FALSE, 0);
2099  }
2100 
2101  /* Set up the data */
2102  recnRefresh (recnData);
2103  }
2104 
2105  /* Allow resize */
2106  gtk_window_set_resizable(GTK_WINDOW(recnData->window), TRUE);
2107  gtk_widget_show_all(recnData->window);
2108 
2109  gnc_reconcile_window_set_titles(recnData);
2110 
2111  recnRecalculateBalance(recnData);
2112 
2113  gnc_window_adjust_for_screen(GTK_WINDOW(recnData->window));
2114 
2115  /* Set the sort orders of the debit and credit tree views */
2116  gnc_query_sort_order(GNC_QUERY_VIEW(recnData->debit), REC_DATE, GTK_SORT_ASCENDING);
2117  gnc_query_sort_order(GNC_QUERY_VIEW(recnData->credit), REC_DATE, GTK_SORT_ASCENDING);
2118 
2119  gtk_widget_grab_focus (recnData->debit);
2120 
2121  { // align the Totals value with that of the amount column
2122  gint recn_widthc = gnc_reconcile_view_get_column_width (GNC_RECONCILE_VIEW(recnData->credit), REC_RECN);
2123  gint recn_widthd = gnc_reconcile_view_get_column_width (GNC_RECONCILE_VIEW(recnData->debit), REC_RECN);
2124 
2125  gtk_widget_set_margin_end (GTK_WIDGET(recnData->total_credit), 10 + recn_widthc);
2126  gtk_widget_set_margin_end (GTK_WIDGET(recnData->total_debit), 10 + recn_widthd);
2127  }
2128  return recnData;
2129 }
2130 
2131 
2132 /********************************************************************\
2133  * gnc_ui_reconcile_window_raise *
2134  * shows and raises an account editing window *
2135  * *
2136  * Args: editAccData - the edit window structure *
2137 \********************************************************************/
2138 void
2139 gnc_ui_reconcile_window_raise(RecnWindow * recnData)
2140 {
2141  if (recnData == NULL)
2142  return;
2143 
2144  if (recnData->window == NULL)
2145  return;
2146 
2147  gtk_window_present(GTK_WINDOW(recnData->window));
2148 }
2149 
2150 GtkWindow *
2151 gnc_ui_reconcile_window_get_window (RecnWindow * recnData)
2152 {
2153  if (recnData == NULL || recnData->window == NULL)
2154  return NULL;
2155  return GTK_WINDOW(recnData->window);
2156 }
2157 
2158 
2159 
2160 /********************************************************************\
2161  * recn_destroy_cb *
2162  * frees memory allocated for an recnWindow, and other cleanup *
2163  * stuff *
2164  * *
2165  * Args: w - the widget that called us *
2166  * data - the data struct for this window *
2167  * Return: none *
2168 \********************************************************************/
2169 static void
2170 recn_destroy_cb (GtkWidget *w, gpointer data)
2171 {
2172  auto recnData = static_cast<RecnWindow*>(data);
2173  gchar **actions = g_action_group_list_actions (G_ACTION_GROUP(recnData->simple_action_group));
2174  gint num_actions = g_strv_length (actions);
2175 
2176  gnc_unregister_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2177 
2178  if (recnData->delete_refresh)
2179  gnc_resume_gui_refresh ();
2180 
2181  //Disable the actions, the handlers try to access recnData
2182  for (gint i = 0; i < num_actions; i++)
2183  {
2184  GAction *action = g_action_map_lookup_action (G_ACTION_MAP(recnData->simple_action_group), actions[i]);
2185  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), FALSE);
2186  }
2187  g_strfreev (actions);
2188  g_free (recnData);
2189 }
2190 
2191 
2192 static void
2193 recn_cancel(RecnWindow *recnData)
2194 {
2195  gboolean changed = FALSE;
2196 
2197  if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->credit)))
2198  changed = TRUE;
2199  if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->debit)))
2200  changed = TRUE;
2201 
2202  if (changed)
2203  {
2204  const char *message = _("You have made changes to this reconcile "
2205  "window. Are you sure you want to cancel?");
2206  if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message))
2207  return;
2208  }
2209 
2210  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2211 }
2212 
2213 
2214 static gboolean
2215 recn_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
2216 {
2217  auto recnData = static_cast<RecnWindow*>(data);
2218 
2219  recn_cancel(recnData);
2220  return TRUE;
2221 }
2222 
2223 
2224 static gboolean
2225 recn_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
2226 {
2227  auto recnData = static_cast<RecnWindow*>(data);
2228 
2229  if (event->keyval == GDK_KEY_Escape)
2230  {
2231  recn_cancel(recnData);
2232  return TRUE;
2233  }
2234  else
2235  {
2236  return FALSE;
2237  }
2238 }
2239 
2240 
2241 /********************************************************************\
2242  * find_payment_account *
2243  * find an account that 'looks like' a payment account for the *
2244  * given account. This really only makes sense for credit card *
2245  * accounts. *
2246  * *
2247  * Args: account - the account to look in *
2248  * Return: a candidate payment account or NULL if none was found *
2249 \********************************************************************/
2250 static Account *
2251 find_payment_account(Account *account)
2252 {
2253  if (account == nullptr)
2254  return nullptr;
2255 
2256  const auto& splits = xaccAccountGetSplits (account);
2257 
2258  /* Search backwards to find the latest payment */
2259  for (auto it = splits.rbegin(); it != splits.rend(); it++)
2260  {
2261  auto split = *it;
2262 
2263  /* ignore 'purchases' */
2265  continue;
2266 
2267  for (auto n = xaccTransGetSplitList (xaccSplitGetParent(split)); n; n = n->next)
2268  {
2269  auto s = GNC_SPLIT(n->data);
2270  if (s == split)
2271  continue;
2272 
2273  auto a = xaccSplitGetAccount(s);
2274  if (a == account)
2275  continue;
2276 
2277  auto type = xaccAccountGetType(a);
2278  if (type == ACCT_TYPE_BANK || type == ACCT_TYPE_CASH || type == ACCT_TYPE_ASSET)
2279  return a;
2280  }
2281  }
2282 
2283  return nullptr;
2284 }
2285 
2286 static void
2287 acct_traverse_descendants (Account *acct, std::function<void(Account*)> fn)
2288 {
2289  fn (acct);
2291  gnc_account_foreach_descendant (acct, fn);
2292 }
2293 
2294 /********************************************************************\
2295  * recnFinishCB *
2296  * saves reconcile information *
2297  * *
2298  * Args: w - the widget that called us *
2299  * data - the data struct for this window *
2300  * Return: none *
2301 \********************************************************************/
2302 static void
2303 recnFinishCB (GSimpleAction *simple,
2304  GVariant *parameter,
2305  gpointer user_data)
2306 {
2307  auto recnData = static_cast<RecnWindow*>(user_data);
2308  gboolean auto_payment;
2309  Account *account;
2310  time64 date;
2311 
2312  if (!gnc_numeric_zero_p (recnRecalculateBalance(recnData)))
2313  {
2314  const char *message = _("The account is not balanced. "
2315  "Are you sure you want to finish?");
2316  if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message))
2317  return;
2318  }
2319 
2320  date = recnData->statement_date;
2321 
2322  gnc_suspend_gui_refresh ();
2323 
2324  recnData->delete_refresh = TRUE;
2325  account = recn_get_account (recnData);
2326 
2327  acct_traverse_descendants (account, xaccAccountBeginEdit);
2328  gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->credit), date);
2329  gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->debit), date);
2330  acct_traverse_descendants (account, xaccAccountCommitEdit);
2331 
2332  auto_payment = gnc_prefs_get_bool(GNC_PREFS_GROUP_RECONCILE, GNC_PREF_AUTO_CC_PAYMENT);
2333 
2335  xaccAccountSetReconcileLastDate (account, date);
2336 
2337  if (auto_payment &&
2338  (xaccAccountGetType (account) == ACCT_TYPE_CREDIT) &&
2339  (gnc_numeric_negative_p (recnData->new_ending)))
2340  {
2341  Account *payment_account;
2342  XferDialog *xfer;
2343 
2344  xfer = gnc_xfer_dialog (GTK_WIDGET (gnc_ui_get_main_window (recnData->window)), account);
2345 
2346  gnc_xfer_dialog_set_amount(xfer, gnc_numeric_neg (recnData->new_ending));
2347 
2348  payment_account = find_payment_account (account);
2349  if (payment_account != NULL)
2350  gnc_xfer_dialog_select_from_account (xfer, payment_account);
2351  }
2352 
2353  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2354 }
2355 
2356 
2357 /********************************************************************\
2358  * recnPostponeCB *
2359  * saves reconcile information for later use *
2360  * *
2361  * Args: w - the widget that called us *
2362  * data - the data struct for this window *
2363  * Return: none *
2364 \********************************************************************/
2365 static void
2366 recnPostponeCB (GSimpleAction *simple,
2367  GVariant *parameter,
2368  gpointer user_data)
2369 {
2370  auto recnData = static_cast<RecnWindow*>(user_data);
2371  Account *account;
2372 
2373  {
2374  const char *message = _("Do you want to postpone this reconciliation "
2375  "and finish it later?");
2376  if (!gnc_verify_dialog (GTK_WINDOW (recnData->window), FALSE, "%s", message))
2377  return;
2378  }
2379 
2380  gnc_suspend_gui_refresh ();
2381 
2382  recnData->delete_refresh = TRUE;
2383  account = recn_get_account (recnData);
2384 
2385  acct_traverse_descendants (account, xaccAccountBeginEdit);
2386  gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->credit));
2387  gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->debit));
2388  acct_traverse_descendants (account, xaccAccountCommitEdit);
2389 
2390  xaccAccountSetReconcilePostponeDate (account, recnData->statement_date);
2391  xaccAccountSetReconcilePostponeBalance (account, recnData->new_ending);
2392 
2393  gnc_close_gui_component_by_data (WINDOW_RECONCILE_CM_CLASS, recnData);
2394 }
2395 
2396 
2397 static void
2398 recnCancelCB (GSimpleAction *simple,
2399  GVariant *parameter,
2400  gpointer user_data)
2401 {
2402  auto recnData = static_cast<RecnWindow*>(user_data);
2403  recn_cancel(recnData);
2404 }
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