gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Thu Nov 24 12:07:24 EST 2016


Updated	 via  https://github.com/Gnucash/gnucash/commit/e4bb9b70 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/bc33d564 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a56f031d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a67b4922 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5ce88787 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/d56c3d3a (commit)
	 via  https://github.com/Gnucash/gnucash/commit/12562bcc (commit)
	 via  https://github.com/Gnucash/gnucash/commit/da0b3b51 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/74091fbc (commit)
	 via  https://github.com/Gnucash/gnucash/commit/372b3cc8 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/371222cb (commit)
	 via  https://github.com/Gnucash/gnucash/commit/49014f47 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/891dcbc3 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/51277bcd (commit)
	 via  https://github.com/Gnucash/gnucash/commit/12994ca6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/62e449f3 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1b2f89e1 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/d7648a2b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1339c116 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ecb43e7d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5b832c7f (commit)
	 via  https://github.com/Gnucash/gnucash/commit/96c22f54 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/254b4fbc (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a9c624bf (commit)
	 via  https://github.com/Gnucash/gnucash/commit/396117ee (commit)
	 via  https://github.com/Gnucash/gnucash/commit/d52f44a8 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0bcd3030 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/673888de (commit)
	 via  https://github.com/Gnucash/gnucash/commit/32c4d145 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5fcdfba6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6695ef95 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c68452a4 (commit)
	from  https://github.com/Gnucash/gnucash/commit/427d4671 (commit)



commit e4bb9b70f80be576c3304e5ceca42bc9d01f7024
Merge: 427d467 bc33d56
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Thu Nov 24 14:19:50 2016 +0100

    Merge branch 'maint'

diff --cc src/engine/gncInvoice.c
index 44129d9,222553f..bd3fcb5
--- a/src/engine/gncInvoice.c
+++ b/src/engine/gncInvoice.c
@@@ -1151,20 -1130,25 +1151,20 @@@ qofInvoiceSetJob (GncInvoice *invoice, 
      invoice->job = job;
  }
  
- static void
+ void
  gncInvoiceDetachFromLot (GNCLot *lot)
  {
 -    KvpFrame *kvp;
 -
      if (!lot) return;
 +
      gnc_lot_begin_edit (lot);
 -    kvp = gnc_lot_get_slots (lot);
 -    kvp_frame_set_slot_path (kvp, NULL, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
 -    qof_instance_set_dirty (QOF_INSTANCE (lot));
 +    qof_instance_set (QOF_INSTANCE (lot), "invoice", NULL, NULL);
      gnc_lot_commit_edit (lot);
  }
  
- static void
+ void
  gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
  {
 -    KvpFrame *kvp;
 -    KvpValue *value;
 -
 +    GncGUID *guid;
      if (!invoice || !lot)
          return;
  
@@@ -1188,9 -1182,12 +1188,9 @@@ GncInvoice * gncInvoiceGetInvoiceFromLo
      return gncInvoiceLookup(book, guid);
  }
  
- static void
+ void
  gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
  {
 -    KvpFrame *kvp;
 -    KvpValue *value;
 -
      if (!invoice || !txn)
          return;
  

commit bc33d564a8f6533936521d3276ce9c300b56afdd
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 16 19:23:58 2016 +0000

    Changed the default value for date format
    
    Set the default value to the new 'No Fancy Date Format'.

diff --git a/src/gnome/gschemas/org.gnucash.dialogs.checkprinting.gschema.xml.in.in b/src/gnome/gschemas/org.gnucash.dialogs.checkprinting.gschema.xml.in.in
index 887aa3d..9ca5dc8 100644
--- a/src/gnome/gschemas/org.gnucash.dialogs.checkprinting.gschema.xml.in.in
+++ b/src/gnome/gschemas/org.gnucash.dialogs.checkprinting.gschema.xml.in.in
@@ -16,7 +16,7 @@
       <description>Number of checks to print on the first page.</description>
     </key>
     <key name="date-format" type="i">
-      <default>0</default>
+      <default>7</default>
       <summary>Date format to use</summary>
       <description>This is the numerical identifier of the predefined date format to use.</description>
     </key>

commit a56f031d4591b610e468fcc305ac091ed410198e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 16 19:22:21 2016 +0000

    Fix check printing custom preference value
    
    The scheme option is 'date-format-user' so corrected here.

diff --git a/src/gnome/dialog-print-check.c b/src/gnome/dialog-print-check.c
index 6d6a7c4..fa3d150 100644
--- a/src/gnome/dialog-print-check.c
+++ b/src/gnome/dialog-print-check.c
@@ -68,7 +68,7 @@ G_GNUC_UNUSED static QofLogModule log_module = "gnc.printing.checks";
 #define GNC_PREF_CHECK_FORMAT_GUID  "check-format-guid"
 #define GNC_PREF_CHECK_POSITION     "check-position"
 #define GNC_PREF_FIRST_PAGE_COUNT   "first-page-count"
-#define GNC_PREF_DATE_FORMAT_USER   "date-format-custom"
+#define GNC_PREF_DATE_FORMAT_USER   "date-format-user"
 #define GNC_PREF_CUSTOM_PAYEE       "custom-payee"
 #define GNC_PREF_CUSTOM_DATE        "custom-date"
 #define GNC_PREF_CUSTOM_WORDS       "custom-amount-words"

commit a67b4922c250004a16457dd58d7f21003cb7d9b4
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 16 19:20:15 2016 +0000

    Correct the default options if default invalid
    
    The default value should be a list and have set the default to the new
    "No Fancy Date Format" option.

diff --git a/src/app-utils/options.scm b/src/app-utils/options.scm
index e9120be..86b1734 100644
--- a/src/app-utils/options.scm
+++ b/src/app-utils/options.scm
@@ -1319,7 +1319,7 @@
   (define (def-value)
     (if (list? default-value)
         default-value
-        '(locale number #t "")))
+        (list 'unset 'number #t "")))
 
   (let* ((value (def-value))
          (value->string (lambda () 

commit 5ce8878764a47f0ff9f98f5bc7cc50858229fd72
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Nov 16 19:13:50 2016 +0000

    Add an unset option to date-format
    
    Added an option of "No Fancy Date Format" to date-format so it can be
    the default. In this position, the format returned is that of what ever
    the preference date is set to.

diff --git a/src/gnome-utils/gnc-date-format.c b/src/gnome-utils/gnc-date-format.c
index 27fabba..f5c4696 100644
--- a/src/gnome-utils/gnc-date-format.c
+++ b/src/gnome-utils/gnc-date-format.c
@@ -188,7 +188,7 @@ gnc_date_format_init (GNCDateFormat *gdf)
     priv->sample_label = GTK_WIDGET(gtk_builder_get_object (builder, "sample_label"));
 
     /* Set initial format to gnucash default */
-    gnc_date_format_set_format(gdf, qof_date_format_get());
+    gnc_date_format_set_format(gdf, QOF_DATE_FORMAT_UNSET);
 
     /* pull in the dialog and table widgets and play the reconnect game */
     dialog = GTK_WIDGET(gtk_builder_get_object (builder, "GNC Date Format"));
diff --git a/src/gnome-utils/gtkbuilder/gnc-date-format.glade b/src/gnome-utils/gtkbuilder/gnc-date-format.glade
index 6e7469d..6c2dbb4 100644
--- a/src/gnome-utils/gtkbuilder/gnc-date-format.glade
+++ b/src/gnome-utils/gtkbuilder/gnc-date-format.glade
@@ -305,14 +305,17 @@
         <col id="0" translatable="yes">ISO (2001-12-31)</col>
       </row>
       <row>
-        <col id="0" translatable="yes">UTC</col>
+        <col id="0" translatable="yes">Locale</col>
       </row>
       <row>
-        <col id="0" translatable="yes">Locale</col>
+        <col id="0" translatable="yes">UTC - Coordinated Universal Time</col>
       </row>
       <row>
         <col id="0" translatable="yes">Custom</col>
       </row>
+      <row>
+        <col id="0" translatable="yes">No Fancy Date Format</col>
+      </row>
     </data>
   </object>
 </interface>
diff --git a/src/libqof/qof/gnc-date.c b/src/libqof/qof/gnc-date.c
index 5f4133c..d23d197 100644
--- a/src/libqof/qof/gnc-date.c
+++ b/src/libqof/qof/gnc-date.c
@@ -456,6 +456,8 @@ gnc_date_dateformat_to_string(QofDateFormat format)
         return "locale";
     case QOF_DATE_FORMAT_CUSTOM:
         return "custom";
+    case QOF_DATE_FORMAT_UNSET:
+        return "unset";
     default:
         return NULL;
     }
@@ -481,6 +483,8 @@ gnc_date_string_to_dateformat(const char* fmt_str, QofDateFormat *format)
         *format = QOF_DATE_FORMAT_LOCALE;
     else if (!strcmp(fmt_str, "custom"))
         *format = QOF_DATE_FORMAT_CUSTOM;
+    else if (!strcmp(fmt_str, "unset"))
+        *format = QOF_DATE_FORMAT_UNSET;
     else
         return TRUE;
 
@@ -769,6 +773,8 @@ const gchar *qof_date_format_get_string(QofDateFormat df)
         return "%Y-%m-%dT%H:%M:%SZ";
     case QOF_DATE_FORMAT_ISO:
         return "%Y-%m-%d";
+    case QOF_DATE_FORMAT_UNSET: // use global
+        return qof_date_format_get_string (dateFormat);
     case QOF_DATE_FORMAT_LOCALE:
     default:
         break;
@@ -798,6 +804,8 @@ const gchar *qof_date_text_format_get_string(QofDateFormat df)
         return "%Y-%m-%dT%H:%M:%SZ";
     case QOF_DATE_FORMAT_ISO:
         return "%Y-%b-%d";
+    case QOF_DATE_FORMAT_UNSET: // use global
+        return qof_date_text_format_get_string (dateFormat);
     case QOF_DATE_FORMAT_LOCALE:
     default:
         break;
diff --git a/src/libqof/qof/gnc-date.h b/src/libqof/qof/gnc-date.h
index 51fa353..acdbe65 100644
--- a/src/libqof/qof/gnc-date.h
+++ b/src/libqof/qof/gnc-date.h
@@ -122,7 +122,8 @@ typedef enum
     QOF_DATE_FORMAT_ISO,      /**< ISO: yyyy-mm-dd */
     QOF_DATE_FORMAT_LOCALE,   /**< Take from locale information */
     QOF_DATE_FORMAT_UTC,      /**< UTC: 2004-12-12T23:39:11Z */
-    QOF_DATE_FORMAT_CUSTOM    /**< Used by the check printing code */
+    QOF_DATE_FORMAT_CUSTOM,   /**< Used by the check printing code */
+    QOF_DATE_FORMAT_UNSET     /**< No Fancy Date Format, use Global */
 } QofDateFormat;
 
 #define DATE_FORMAT_FIRST QOF_DATE_FORMAT_US
diff --git a/src/libqof/qof/test/test-gnc-date.c b/src/libqof/qof/test/test-gnc-date.c
index fa3625d..6aefd3f 100644
--- a/src/libqof/qof/test/test-gnc-date.c
+++ b/src/libqof/qof/test/test-gnc-date.c
@@ -361,6 +361,7 @@ test_gnc_date_dateformat_to_string (void)
     g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_UTC), ==, "utc");
     g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_LOCALE), ==, "locale");
     g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_CUSTOM), ==, "custom");
+    g_assert_cmpstr (gnc_date_dateformat_to_string (QOF_DATE_FORMAT_UNSET), ==, "unset");
 
 }
 /* gnc_date_string_to_dateformat
@@ -387,6 +388,8 @@ test_gnc_date_string_to_dateformat (void)
     g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_LOCALE);
     g_assert (!gnc_date_string_to_dateformat ("custom", &fmt));
     g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_CUSTOM);
+    g_assert (!gnc_date_string_to_dateformat ("unset", &fmt));
+    g_assert_cmpint (fmt, ==, QOF_DATE_FORMAT_UNSET);
     fmt = 123;
     g_assert (gnc_date_string_to_dateformat ("", &fmt));
     g_assert_cmpint (fmt, ==, 123);

commit d56c3d3ac801251c60a8371e873d773ac3dee81a
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 15:59:44 2016 +0000

    Added a default currency to the currency option
    
    This was causing an error when the dialog options was raised.

diff --git a/src/report/business-reports/taxinvoice.scm b/src/report/business-reports/taxinvoice.scm
index 982039a..16a925e 100644
--- a/src/report/business-reports/taxinvoice.scm
+++ b/src/report/business-reports/taxinvoice.scm
@@ -160,7 +160,10 @@
       "a" "" (lambda () '()) 
       #f))        ;customers-only)) ;-- see above
 
-(add-option (gnc:make-currency-option		gnc:pagename-general	optname-report-currency		"b" "" ""))
+  (add-option
+    (gnc:make-currency-option
+      gnc:pagename-general optname-report-currency
+      "b" "" (gnc-default-report-currency)))
 
   ;; Elements page options
 (add-option (gnc:make-simple-boolean-option	elementspage	optname-col-date		"a" (N_ "Display the date?") #t))

commit 12562bcc0ccc5ae3f05f65fc74e14291d73ecec3
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 15:24:38 2016 +0000

    Add plot size option for future compatibility
    
    This is really just a copy of the number-range-option with some tests
    for the saved value being a pair which is used in later versions. If the
    pair is a pixel setting, then that value will be used, otherwise the
    default value is used. Should any report get saved, the saved values
    will be over written in the old format.

diff --git a/src/app-utils/app-utils.scm b/src/app-utils/app-utils.scm
index 0afe7eb..0a490af 100644
--- a/src/app-utils/app-utils.scm
+++ b/src/app-utils/app-utils.scm
@@ -110,6 +110,7 @@
 (export gnc:options-make-date-interval!)
 
 (export gnc:make-number-range-option)
+(export gnc:make-number-plot-size-option)
 (export gnc:make-internal-option)
 (export gnc:make-query-option)
 (export gnc:make-color-option)
diff --git a/src/app-utils/options.scm b/src/app-utils/options.scm
index 276174d..e9120be 100644
--- a/src/app-utils/options.scm
+++ b/src/app-utils/options.scm
@@ -1143,6 +1143,48 @@
      (list lower-bound upper-bound num-decimals step-size)
      #f #f #f)))
 
+
+;; plot size options use the option-data as a list whose
+;; elements are: (lower-bound upper-bound num-decimals step-size)
+(define (gnc:make-number-plot-size-option
+         section
+         name
+         sort-tag
+         documentation-string
+         default-value
+         lower-bound
+         upper-bound
+         num-decimals
+         step-size)
+  (let* ((value default-value)
+         (value->string (lambda () (number->string value))))
+    (gnc:make-option
+     section name sort-tag 'number-range documentation-string
+     (lambda () value)
+     (lambda (x)
+       (cond ((and (pair? x) ;; new pair value
+                   (eq? 'pixels (car x)))
+              (set! value (cdr x)))
+             (else (set! value default-value)))
+
+       (if (number? x) ;; old single value
+         (set! value x)))
+     (lambda () default-value)
+     (gnc:restore-form-generator value->string)
+     (lambda (f p) (kvp-frame-set-slot-path-gslist f value p))
+     (lambda (f p)
+       (let ((v (kvp-frame-get-slot-path-gslist f p)))
+         (if (and v (number? v))
+             (set! value v))))
+     (lambda (x)
+       (cond ((not (number? x)) (list #f "number-plot-size-option: not a number"))
+             ((and (>= value lower-bound)
+                   (<= value upper-bound))
+              (list #t x))
+             (else (list #f "number-plot-size-option: out of range"))))
+     (list lower-bound upper-bound num-decimals step-size)
+     #f #f #f)))
+
 (define (gnc:make-internal-option
          section
          name
diff --git a/src/gnome-utils/dialog-options.c b/src/gnome-utils/dialog-options.c
index 3b7bab7..0233c44 100644
--- a/src/gnome-utils/dialog-options.c
+++ b/src/gnome-utils/dialog-options.c
@@ -1981,6 +1981,71 @@ gnc_option_set_ui_widget_number_range (GNCOption *option, GtkBox *page_box,
 }
 
 static GtkWidget *
+gnc_option_set_ui_widget_plot_size (GNCOption *option, GtkBox *page_box,
+                                    char *name, char *documentation,
+                                    /* Return values */
+                                    GtkWidget **enclosing, gboolean *packed)
+{
+    GtkWidget *value;
+    GtkWidget *label;
+    gchar *colon_name;
+    GtkAdjustment *adj;
+    gdouble lower_bound = G_MINDOUBLE;
+    gdouble upper_bound = G_MAXDOUBLE;
+    gdouble step_size = 1.0;
+    int num_decimals = 0;
+
+    colon_name = g_strconcat(name, ":", NULL);
+    label = gtk_label_new(colon_name);
+    gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
+    g_free(colon_name);
+
+    *enclosing = gtk_hbox_new(FALSE, 5);
+
+    gnc_option_get_range_info(option, &lower_bound, &upper_bound,
+                              &num_decimals, &step_size);
+    adj = GTK_ADJUSTMENT(gtk_adjustment_new(lower_bound, lower_bound,
+                                            upper_bound, step_size,
+                                            step_size * 5.0,
+                                            0));
+    value = gtk_spin_button_new(adj, step_size, num_decimals);
+    gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(value), TRUE);
+
+    {
+        gdouble biggest;
+        gint num_digits;
+
+        biggest = ABS(lower_bound);
+        biggest = MAX(biggest, ABS(upper_bound));
+
+        num_digits = 0;
+        while (biggest >= 1)
+        {
+            num_digits++;
+            biggest = biggest / 10;
+        }
+
+        if (num_digits == 0)
+            num_digits = 1;
+
+        num_digits += num_decimals;
+
+        gtk_entry_set_width_chars(GTK_ENTRY(value), num_digits);
+    }
+
+    gnc_option_set_widget (option, value);
+    gnc_option_set_ui_value(option, FALSE);
+
+    g_signal_connect(G_OBJECT(value), "changed",
+                     G_CALLBACK(gnc_option_changed_widget_cb), option);
+
+    gtk_box_pack_start(GTK_BOX(*enclosing), label, FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(*enclosing), value, FALSE, FALSE, 0);
+    gtk_widget_show_all(*enclosing);
+    return value;
+}
+
+static GtkWidget *
 gnc_option_set_ui_widget_color (GNCOption *option, GtkBox *page_box,
                                 char *name, char *documentation,
                                 /* Return values */
@@ -2469,6 +2534,25 @@ gnc_option_set_ui_value_number_range (GNCOption *option, gboolean use_default,
 }
 
 static gboolean
+gnc_option_set_ui_value_plot_size (GNCOption *option, gboolean use_default,
+                                   GtkWidget *widget, SCM value)
+{
+    GtkSpinButton *spinner;
+    gdouble d_value;;
+
+    spinner = GTK_SPIN_BUTTON(widget);
+
+    if (scm_is_number(value))
+    {
+        d_value = scm_to_double(value);
+        gtk_spin_button_set_value(spinner, d_value);
+        return FALSE;
+    }
+    else
+        return TRUE;
+}
+
+static gboolean
 gnc_option_set_ui_value_color (GNCOption *option, gboolean use_default,
                                GtkWidget *widget, SCM value)
 {
@@ -2863,6 +2947,19 @@ gnc_option_get_ui_value_number_range (GNCOption *option, GtkWidget *widget)
 }
 
 static SCM
+gnc_option_get_ui_value_plot_size (GNCOption *option, GtkWidget *widget)
+{
+    GtkSpinButton *spinner;
+    gdouble value;
+
+    spinner = GTK_SPIN_BUTTON(widget);
+
+    value = gtk_spin_button_get_value(spinner);
+
+    return (scm_from_double (value));
+}
+
+static SCM
 gnc_option_get_ui_value_color (GNCOption *option, GtkWidget *widget)
 {
     SCM result;
@@ -2996,6 +3093,10 @@ static void gnc_options_initialize_options (void)
             gnc_option_set_ui_value_number_range, gnc_option_get_ui_value_number_range
         },
         {
+            "plot-size", gnc_option_set_ui_widget_plot_size,
+            gnc_option_set_ui_value_plot_size, gnc_option_get_ui_value_plot_size
+        },
+        {
             "color", gnc_option_set_ui_widget_color,
             gnc_option_set_ui_value_color, gnc_option_get_ui_value_color
         },
diff --git a/src/report/report-system/options-utilities.scm b/src/report/report-system/options-utilities.scm
index f5e288f..c901851 100644
--- a/src/report/report-system/options-utilities.scm
+++ b/src/report/report-system/options-utilities.scm
@@ -193,7 +193,7 @@
 	 default-width default-height)
   (gnc:register-option
    options
-   (gnc:make-number-range-option
+   (gnc:make-number-plot-size-option
     pagename name-width
     (string-append sort-tag "a")
     (N_ "Width of plot in pixels.") default-width
@@ -201,7 +201,7 @@
 
   (gnc:register-option
    options
-   (gnc:make-number-range-option
+   (gnc:make-number-plot-size-option
     pagename name-height
     (string-append sort-tag "b")
     (N_ "Height of plot in pixels.") default-height

commit da0b3b51313080ebf9d61f3a66f88a342788d790
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 12:12:30 2016 +0000

    Fix warning from glib when saving reports.
    
    Glib complains about an already initialised pointer, there is no need
    to initialise when used with gtk_tree_model_get_value.

diff --git a/src/report/report-gnome/dialog-custom-report.c b/src/report/report-gnome/dialog-custom-report.c
index b4277bc..a048a89 100644
--- a/src/report/report-gnome/dialog-custom-report.c
+++ b/src/report/report-gnome/dialog-custom-report.c
@@ -145,7 +145,6 @@ update_report_list(GtkListStore *store, CustomReportDialog *crd)
     {
         GValue value = { 0, };
         GncGUID *row_guid;
-        g_value_init ( &value, G_TYPE_POINTER);
         gtk_tree_model_get_value (model, &iter, COL_NUM, &value);
         row_guid = (GncGUID *) g_value_get_pointer (&value);
         guid_free (row_guid);
@@ -578,7 +577,6 @@ void gnc_ui_custom_report_edit_name (GncMainWindow * window, SCM scm_guid)
     {
         GValue value = { 0, };
         GncGUID *row_guid;
-        g_value_init (&value, G_TYPE_POINTER);
         gtk_tree_model_get_value (model, &iter, COL_NUM, &value);
         row_guid = (GncGUID *) g_value_get_pointer (&value);
 

commit 74091fbcfab4e5d731bb6283c07c38ccc58326e1
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 12:05:13 2016 +0000

    Change report resizing when not in view
    
    When you have reports open but they are not selected, resizing the
    window does not always resize the hidden report views properly. Use
    the expose call back so the reports are reloaded on expose event.

diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index d756029..728ea2d 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -119,9 +119,6 @@ typedef struct GncPluginPageReportPrivate
      * the window is closed. */
     SCM          edited_reports;
 
-    /* This is set to mark the fact that we need to reload the html */
-    gboolean	need_reload;
-
     /* The page is in the process of reloading the html */
     gboolean	reloading;
 
@@ -132,6 +129,9 @@ typedef struct GncPluginPageReportPrivate
     // keep the view size
     gint view_width, view_height;
 
+    // This is set to mark that we need to reload the html
+    gboolean need_reload;
+
     /// the container the above HTML widget is in.
     GtkContainer *container;
 } GncPluginPageReportPrivate;
@@ -160,7 +160,7 @@ static int gnc_plugin_page_report_check_urltype(URLType t);
 static void gnc_plugin_page_report_load_cb(GncHtml * html, URLType type,
         const gchar * location, const gchar * label,
         gpointer data);
-static void gnc_plugin_page_report_expose_event_cb(GtkWidget *unused, GdkEventExpose *unused1, gpointer data);
+static gboolean gnc_plugin_page_report_expose_event_cb(GtkWidget *widget, GdkEventExpose *event, gpointer user_data);
 static void gnc_plugin_page_report_refresh (gpointer data);
 static void gnc_plugin_page_report_set_fwd_button(GncPluginPageReport * page, int enabled);
 static void gnc_plugin_page_report_set_back_button(GncPluginPageReport * page, int enabled);
@@ -333,8 +333,7 @@ gnc_plugin_page_report_view_size (GtkWidget *widget, GtkAllocation *allocation,
 
     if ((allocation->width != priv->view_width)||(allocation->height != priv->view_height))
     {
-        gnc_html_reload (priv->html, FALSE); //reload by view
-
+        priv->need_reload = TRUE;
         priv->view_width = allocation->width;
         priv->view_height = allocation->height;
     }
@@ -427,6 +426,7 @@ gnc_plugin_page_report_create_widget( GncPluginPage *page )
 
     priv->view_width = 0; // default
     priv->view_height = 0; // default
+    priv->need_reload = FALSE;
 
     gnc_html_history_set_node_destroy_cb(gnc_html_get_history(priv->html),
                                          gnc_plugin_page_report_history_destroy_cb,
@@ -453,8 +453,8 @@ gnc_plugin_page_report_create_widget( GncPluginPage *page )
     /* load uri when view idle */
     g_idle_add ((GSourceFunc)gnc_plugin_page_report_load_uri, page);
 
-//    g_signal_connect(priv->container, "expose_event",
-//                     G_CALLBACK(gnc_plugin_page_report_expose_event_cb), report);
+    g_signal_connect(priv->container, "expose-event",
+                     G_CALLBACK(gnc_plugin_page_report_expose_event_cb), report);
 
     gtk_widget_show_all( GTK_WIDGET(priv->container) );
 
@@ -688,11 +688,6 @@ gnc_plugin_page_report_option_change_cb(gpointer data)
     /* it's probably already dirty, but make sure */
     scm_call_2(dirty_report, priv->cur_report, SCM_BOOL_T);
 
-    /* Now queue the fact that we need to reload this report */
-    priv->need_reload = TRUE;
-    // jsled: this doesn't seem to cause any effect.
-    gtk_widget_queue_draw( GTK_WIDGET(priv->container) );
-    // jsled: this does.
     // this sets the window for the progressbar
     gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
 
@@ -737,27 +732,25 @@ gnc_plugin_page_report_history_destroy_cb(gnc_html_history_node * node,
 }
 
 /* We got a draw event.  See if we need to reload the report */
-static void
-gnc_plugin_page_report_expose_event_cb(GtkWidget *unused, GdkEventExpose *unused1, gpointer data)
+static gboolean
+gnc_plugin_page_report_expose_event_cb(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 {
-    GncPluginPageReport *page = data;
+    GncPluginPageReport *page = user_data;
     GncPluginPageReportPrivate *priv;
 
-    g_return_if_fail(GNC_IS_PLUGIN_PAGE_REPORT(page));
+    g_return_val_if_fail(GNC_IS_PLUGIN_PAGE_REPORT(page), FALSE);
 
     priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(page);
     ENTER( "report_draw" );
     if (!priv->need_reload)
     {
         LEAVE( "no reload needed" );
-        return;
+        return FALSE;
     }
-
     priv->need_reload = FALSE;
-    gnc_window_set_progressbar_window( GNC_WINDOW(GNC_PLUGIN_PAGE(page)->window) );
-    gnc_html_reload (priv->html, FALSE); //reload by view
-    gnc_window_set_progressbar_window( NULL );
+    gnc_html_reload(priv->html, FALSE);
     LEAVE( "reload forced" );
+    return FALSE;
 }
 
 // @param data is actually GncPluginPageReportPrivate
@@ -1386,14 +1379,9 @@ gnc_plugin_page_report_reload_cb( GtkAction *action, GncPluginPageReport *report
     dirty_report = scm_c_eval_string("gnc:report-set-dirty?!");
     scm_call_2(dirty_report, priv->cur_report, SCM_BOOL_T);
 
-    priv->need_reload = TRUE;
     /* now queue the fact that we need to reload this report */
-
-    // this doens't seem to do anything...
-    gtk_widget_queue_draw( GTK_WIDGET(priv->container) );
-
-    // this does...
     priv->reloading = TRUE;
+
     // this sets the window for the progressbar
     gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
 

commit 372b3cc8226704ed747de693bdfde0ddc8e55a1b
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 12:03:55 2016 +0000

    Forgot to add the png file to previous commit

diff --git a/src/pixmaps/gnc-account-report-16.png b/src/pixmaps/gnc-account-report-16.png
new file mode 100644
index 0000000..5ef812d
Binary files /dev/null and b/src/pixmaps/gnc-account-report-16.png differ
diff --git a/src/pixmaps/gnc-account-report.png b/src/pixmaps/gnc-account-report.png
new file mode 100644
index 0000000..d4f2055
Binary files /dev/null and b/src/pixmaps/gnc-account-report.png differ

commit 371222cb6af4929a9bdcd875db13f4cfcb608a27
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 11:29:37 2016 +0000

    Add an image for the report tab
    
    There was an entry in plugin-page-report about a missing image for the
    report tab so have created one and added it.

diff --git a/src/gnome-utils/gnc-icons.c b/src/gnome-utils/gnc-icons.c
index a76239b..6d56719 100644
--- a/src/gnome-utils/gnc-icons.c
+++ b/src/gnome-utils/gnc-icons.c
@@ -55,6 +55,7 @@ typedef struct _item_file
 static item_file item_files[] =
 {
     { GNC_STOCK_ACCOUNT,        "gnc-account.png",        "gnc-account-16.png"},
+    { GNC_STOCK_ACCOUNT_REPORT, "gnc-account-report.png", "gnc-account-report-16.png"},
     { GNC_STOCK_DELETE_ACCOUNT, "gnc-account-delete.png", "gnc-account-delete-16.png"},
     { GNC_STOCK_EDIT_ACCOUNT,   "gnc-account-edit.png",   "gnc-account-edit-16.png"},
     { GNC_STOCK_NEW_ACCOUNT,    "gnc-account-new.png",    "gnc-account-new-16.png"},
diff --git a/src/gnome-utils/gnc-icons.h b/src/gnome-utils/gnc-icons.h
index 2015c9c..395a9dd 100644
--- a/src/gnome-utils/gnc-icons.h
+++ b/src/gnome-utils/gnc-icons.h
@@ -30,6 +30,7 @@
 G_BEGIN_DECLS
 
 #define GNC_STOCK_ACCOUNT "gnc-account"
+#define GNC_STOCK_ACCOUNT_REPORT "gnc-account-report"
 #define GNC_STOCK_DELETE_ACCOUNT "gnc-delete-account"
 #define GNC_STOCK_EDIT_ACCOUNT "gnc-edit-account"
 #define GNC_STOCK_NEW_ACCOUNT "gnc-new-account"
diff --git a/src/pixmaps/Makefile.am b/src/pixmaps/Makefile.am
index 183ae79..eea54e7 100644
--- a/src/pixmaps/Makefile.am
+++ b/src/pixmaps/Makefile.am
@@ -11,6 +11,8 @@ gncpixmap_DATA = \
   gnc-account-open-16.png \
   gnc-account-open.png \
   gnc-account.png \
+  gnc-account-report-16.png \
+  gnc-account-report.png \
   gnc-gnome-pdf-16.png \
   gnc-gnome-pdf-24.png \
   gnc-invoice-16.png \
diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index 44162b8..d756029 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -277,8 +277,7 @@ gnc_plugin_page_report_class_init (GncPluginPageReportClass *klass)
     object_class->set_property = gnc_plugin_page_report_set_property;
     object_class->get_property = gnc_plugin_page_report_get_property;
 
-    // FIXME: stock reporting icon?
-    //gnc_plugin_page_class->tab_icon        = GNC_STOCK_ACCOUNT;
+    gnc_plugin_page_class->tab_icon        = GNC_STOCK_ACCOUNT_REPORT;
     gnc_plugin_page_class->plugin_name     = GNC_PLUGIN_PAGE_REPORT_NAME;
 
     gnc_plugin_page_class->create_widget   = gnc_plugin_page_report_create_widget;

commit 49014f4714adb31d860b4ef18aab08989585cc55
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 11:27:51 2016 +0000

    Change the reload to include using web_view_reload
    
    In the resize call backs, use the webkit view reload function instead of
    recreating the report.

diff --git a/src/html/gnc-html-webkit.c b/src/html/gnc-html-webkit.c
index 98e80ec..af1d36b 100644
--- a/src/html/gnc-html-webkit.c
+++ b/src/html/gnc-html-webkit.c
@@ -104,7 +104,7 @@ static void impl_webkit_show_url( GncHtml* self, URLType type,
                                   const gchar* location, const gchar* label,
                                   gboolean new_window_hint );
 static void impl_webkit_show_data( GncHtml* self, const gchar* data, int datalen );
-static void impl_webkit_reload( GncHtml* self );
+static void impl_webkit_reload( GncHtml* self, gboolean force_rebuild );
 static void impl_webkit_copy_to_clipboard( GncHtml* self );
 static gboolean impl_webkit_export_to_file( GncHtml* self, const gchar* filepath );
 static void impl_webkit_print( GncHtml* self, const gchar* jobname, gboolean export_pdf );
@@ -952,10 +952,12 @@ impl_webkit_show_url( GncHtml* self, URLType type,
 /********************************************************************
  * gnc_html_reload
  * reload the current page
+ * if force_rebuild is TRUE, the report is recreated, if FALSE, report
+ * is reloaded by webkit
  ********************************************************************/
 
 static void
-impl_webkit_reload( GncHtml* self )
+impl_webkit_reload( GncHtml* self, gboolean force_rebuild )
 {
     gnc_html_history_node * n;
     GncHtmlWebkitPrivate* priv;
@@ -965,10 +967,14 @@ impl_webkit_reload( GncHtml* self )
 
     priv = GNC_HTML_WEBKIT_GET_PRIVATE(self);
     n = gnc_html_history_get_current( priv->base.history );
-    if ( n != NULL )
+
+    if ( force_rebuild )
     {
-        gnc_html_show_url( self, n->type, n->location, n->label, 0 );
+        if ( n != NULL )
+            gnc_html_show_url( self, n->type, n->location, n->label, 0 );
     }
+    else
+        webkit_web_view_reload( priv->web_view );
 }
 
 
diff --git a/src/html/gnc-html.c b/src/html/gnc-html.c
index 4046d09..13a2c98 100644
--- a/src/html/gnc-html.c
+++ b/src/html/gnc-html.c
@@ -98,7 +98,7 @@ static void
 gnc_html_scroll_vis_cb( GtkWidget *widget, gpointer user_data )
 {
     GncHtml* self = user_data;
-    gnc_html_reload( self );
+    gnc_html_reload( self, FALSE ); //reload by view
 }
 
 static void
@@ -391,17 +391,19 @@ gnc_html_show_url( GncHtml* self, URLType type,
 /********************************************************************
  * gnc_html_reload
  * reload the current page
+ * if force_rebuild is TRUE, the report is recreated, if FALSE, report
+ * is reloaded ib the view
  ********************************************************************/
 
 void
-gnc_html_reload( GncHtml* self )
+gnc_html_reload( GncHtml* self, gboolean force_rebuild )
 {
     g_return_if_fail( self != NULL );
     g_return_if_fail( GNC_IS_HTML(self) );
 
     if ( GNC_HTML_GET_CLASS(self)->reload != NULL )
     {
-        GNC_HTML_GET_CLASS(self)->reload( self );
+        GNC_HTML_GET_CLASS(self)->reload( self, force_rebuild );
     }
     else
     {
diff --git a/src/html/gnc-html.h b/src/html/gnc-html.h
index 8e77e9f..5ec7db1 100644
--- a/src/html/gnc-html.h
+++ b/src/html/gnc-html.h
@@ -132,7 +132,7 @@ struct _GncHtmlClass
                       const gchar* label,
                       gboolean new_window_hint );
     void (*show_data)( GncHtml* html, const gchar* data, int datalen );
-    void (*reload)( GncHtml* html );
+    void (*reload)( GncHtml* html, gboolean force_rebuild );
     void (*copy_to_clipboard)( GncHtml* html );
     gboolean (*export_to_file)( GncHtml* html, const gchar* file );
     void (*print)( GncHtml* html, const gchar* jobname, gboolean export_pdf );
@@ -176,8 +176,9 @@ void gnc_html_show_data( GncHtml* html, const gchar* data, int datalen );
  * Reloads the current GncHtml object.
  *
  * @param html GncHtml object
+ * @param view if TRUE, view is reloaded, if FALSE, report is recreated
  */
-void gnc_html_reload( GncHtml* html );
+void gnc_html_reload( GncHtml* html, gboolean view );
 
 /**
  * Copies the html to the clipboard
diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index e67f13c..44162b8 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -334,7 +334,7 @@ gnc_plugin_page_report_view_size (GtkWidget *widget, GtkAllocation *allocation,
 
     if ((allocation->width != priv->view_width)||(allocation->height != priv->view_height))
     {
-        gnc_html_reload (priv->html);
+        gnc_html_reload (priv->html, FALSE); //reload by view
 
         priv->view_width = allocation->width;
         priv->view_height = allocation->height;
@@ -700,7 +700,7 @@ gnc_plugin_page_report_option_change_cb(gpointer data)
     // this sets the minimum size of the progressbar to that allocated
     gnc_plugin_page_report_set_progressbar( page, TRUE );
 
-    gnc_html_reload( priv->html );
+    gnc_html_reload( priv->html, TRUE ); //reload by rebuild
 
     gnc_plugin_page_report_set_progressbar( page, FALSE );
 
@@ -756,7 +756,7 @@ gnc_plugin_page_report_expose_event_cb(GtkWidget *unused, GdkEventExpose *unused
 
     priv->need_reload = FALSE;
     gnc_window_set_progressbar_window( GNC_WINDOW(GNC_PLUGIN_PAGE(page)->window) );
-    gnc_html_reload(priv->html);
+    gnc_html_reload (priv->html, FALSE); //reload by view
     gnc_window_set_progressbar_window( NULL );
     LEAVE( "reload forced" );
 }
@@ -1401,7 +1401,7 @@ gnc_plugin_page_report_reload_cb( GtkAction *action, GncPluginPageReport *report
     // this sets the minimum size of the progressbar to that allocated
     gnc_plugin_page_report_set_progressbar( page, TRUE );
 
-    gnc_html_reload( priv->html );
+    gnc_html_reload( priv->html, TRUE ); //reload by rebuild
 
     gnc_plugin_page_report_set_progressbar( page, FALSE );
 

commit 891dcbc339567eb857491f4593548d72a9a265ff
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 11:18:44 2016 +0000

    Track visibility of the view scroll bars
    
    When the scroll bars show they can affect the chart so force a reload
    when they show.

diff --git a/src/html/gnc-html.c b/src/html/gnc-html.c
index d3fa6bd..4046d09 100644
--- a/src/html/gnc-html.c
+++ b/src/html/gnc-html.c
@@ -95,15 +95,30 @@ gnc_html_class_init( GncHtmlClass* klass )
 }
 
 static void
+gnc_html_scroll_vis_cb( GtkWidget *widget, gpointer user_data )
+{
+    GncHtml* self = user_data;
+    gnc_html_reload( self );
+}
+
+static void
 gnc_html_init( GncHtml* self )
 {
     GncHtmlPrivate* priv;
+    GtkWidget *vscroll, *hscroll;
     priv = self->priv = g_new0( GncHtmlPrivate, 1 );
 
     priv->container = gtk_scrolled_window_new( NULL, NULL );
     gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(priv->container),
                                     GTK_POLICY_AUTOMATIC,
                                     GTK_POLICY_AUTOMATIC );
+
+    vscroll = GTK_WIDGET(gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(priv->container)));
+    hscroll = GTK_WIDGET(gtk_scrolled_window_get_hscrollbar(GTK_SCROLLED_WINDOW(priv->container)));
+
+    g_signal_connect(GTK_WIDGET(vscroll), "show", G_CALLBACK(gnc_html_scroll_vis_cb), self);
+    g_signal_connect(GTK_WIDGET(hscroll), "show", G_CALLBACK(gnc_html_scroll_vis_cb), self);
+
     priv->request_info = g_hash_table_new( g_str_hash, g_str_equal );
     priv->history = gnc_html_history_new();
 }

commit 51277bcd81c806a327c17265bd46c2dc7d4464e4
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 11:16:36 2016 +0000

    Add progress bar updates for reload / Update
    
    Added progress bar updates for refresh/reload button press and also for
    when the options change. Created a new function to set progress bar
    height from previous commit to be used for above changes.

diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index 2759475..e67f13c 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -341,12 +341,27 @@ gnc_plugin_page_report_view_size (GtkWidget *widget, GtkAllocation *allocation,
     }
 }
 
+static void
+gnc_plugin_page_report_set_progressbar (GncPluginPage *page, gboolean set)
+{
+    GtkWidget *progressbar;
+    GtkAllocation allocation;
+
+    progressbar = gnc_window_get_progressbar (GNC_WINDOW(page->window));
+    gtk_widget_get_allocation (GTK_WIDGET(progressbar), &allocation); 
+
+    // this sets the minimum size of the progressbar to that allocated
+    if (set)
+        gtk_widget_set_size_request (GTK_WIDGET(progressbar), -1, allocation.height);
+    else
+        gtk_widget_set_size_request (GTK_WIDGET(progressbar), -1, -1); //reset
+}
+
 static gboolean
 gnc_plugin_page_report_load_uri (GncPluginPage *page)
 {
     GncPluginPageReport *report;
     GncPluginPageReportPrivate *priv;
-    GtkWidget *progressbar;
     GtkAllocation allocation;
     URLType type;
     char * id_name;
@@ -379,14 +394,14 @@ gnc_plugin_page_report_load_uri (GncPluginPage *page)
     // this sets the window for the progressbar
     gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
 
-    progressbar = gnc_window_get_progressbar (GNC_WINDOW(page->window));
-    gtk_widget_get_allocation (GTK_WIDGET(progressbar), &allocation); 
-
     // this sets the minimum size of the progressbar to that allocated
-    gtk_widget_set_size_request (GTK_WIDGET(progressbar), -1, allocation.height);
+    gnc_plugin_page_report_set_progressbar( page, TRUE );
 
     gnc_html_show_url(priv->html, type, url_location, url_label, 0);
     g_free(url_location);
+
+    gnc_plugin_page_report_set_progressbar( page, FALSE );
+
     // this resets the window for the progressbar to NULL
     gnc_window_set_progressbar_window( NULL );
 
@@ -639,6 +654,7 @@ gnc_plugin_page_report_load_cb(GncHtml * html, URLType type,
 static void
 gnc_plugin_page_report_option_change_cb(gpointer data)
 {
+    GncPluginPage *page;
     GncPluginPageReport *report;
     GncPluginPageReportPrivate *priv;
     SCM dirty_report = scm_c_eval_string("gnc:report-set-dirty?!");
@@ -649,6 +665,7 @@ gnc_plugin_page_report_option_change_cb(gpointer data)
     g_return_if_fail(GNC_IS_PLUGIN_PAGE_REPORT(data));
     report = GNC_PLUGIN_PAGE_REPORT(data);
     priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
+    page = GNC_PLUGIN_PAGE(report);
 
     DEBUG( "option_change" );
     if (priv->cur_report == SCM_BOOL_F)
@@ -677,7 +694,18 @@ gnc_plugin_page_report_option_change_cb(gpointer data)
     // jsled: this doesn't seem to cause any effect.
     gtk_widget_queue_draw( GTK_WIDGET(priv->container) );
     // jsled: this does.
+    // this sets the window for the progressbar
+    gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
+
+    // this sets the minimum size of the progressbar to that allocated
+    gnc_plugin_page_report_set_progressbar( page, TRUE );
+
     gnc_html_reload( priv->html );
+
+    gnc_plugin_page_report_set_progressbar( page, FALSE );
+
+    // this resets the window for the progressbar to NULL
+    gnc_window_set_progressbar_window( NULL );
 }
 
 /* FIXME: This function does... nothing.  */
@@ -1345,10 +1373,12 @@ gnc_plugin_page_report_back_cb( GtkAction *action, GncPluginPageReport *report )
 static void
 gnc_plugin_page_report_reload_cb( GtkAction *action, GncPluginPageReport *report )
 {
+    GncPluginPage *page;
     GncPluginPageReportPrivate *priv;
     SCM dirty_report;
 
     DEBUG( "reload" );
+    page = GNC_PLUGIN_PAGE(report);
     priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
     if (priv->cur_report == SCM_BOOL_F)
         return;
@@ -1365,7 +1395,18 @@ gnc_plugin_page_report_reload_cb( GtkAction *action, GncPluginPageReport *report
 
     // this does...
     priv->reloading = TRUE;
+    // this sets the window for the progressbar
+    gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
+
+    // this sets the minimum size of the progressbar to that allocated
+    gnc_plugin_page_report_set_progressbar( page, TRUE );
+
     gnc_html_reload( priv->html );
+
+    gnc_plugin_page_report_set_progressbar( page, FALSE );
+
+    // this resets the window for the progressbar to NULL
+    gnc_window_set_progressbar_window( NULL );
     priv->reloading = FALSE;
 }
 

commit 12994ca6e77cba58cf9de5a2f6b2b3f4323e77b3
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 11:15:23 2016 +0000

    Add call back to track page size changes
    
    Add call back to track size-allocate events for the webkit view. Also
    commented out expose event as that may not be required.

diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index f99c596..2759475 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -129,6 +129,9 @@ typedef struct GncPluginPageReportPrivate
 //        gnc_html *html;
     GncHtml *html;
 
+    // keep the view size
+    gint view_width, view_height;
+
     /// the container the above HTML widget is in.
     GtkContainer *container;
 } GncPluginPageReportPrivate;
@@ -324,6 +327,20 @@ gnc_plugin_page_report_finalize (GObject *object)
     LEAVE(" ");
 }
 
+static void
+gnc_plugin_page_report_view_size (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data)
+{
+    GncPluginPageReportPrivate *priv = user_data;
+
+    if ((allocation->width != priv->view_width)||(allocation->height != priv->view_height))
+    {
+        gnc_html_reload (priv->html);
+
+        priv->view_width = allocation->width;
+        priv->view_height = allocation->height;
+    }
+}
+
 static gboolean
 gnc_plugin_page_report_load_uri (GncPluginPage *page)
 {
@@ -340,6 +357,14 @@ gnc_plugin_page_report_load_uri (GncPluginPage *page)
     report = GNC_PLUGIN_PAGE_REPORT(page);
     priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
 
+    gtk_widget_get_allocation (GTK_WIDGET(gnc_html_get_widget(priv->html)), &allocation); 
+
+    priv->view_width = allocation.width;
+    priv->view_height = allocation.height;
+
+    g_signal_connect(GTK_WIDGET(gnc_html_get_widget(priv->html)), "size-allocate",
+                     G_CALLBACK(gnc_plugin_page_report_view_size), priv);
+
     id_name = g_strdup_printf("id=%d", priv->reportId );
     child_name = gnc_build_url( URL_TYPE_REPORT, id_name, NULL );
     type = gnc_html_parse_url( priv->html, child_name, &url_location, &url_label);
@@ -386,6 +411,9 @@ gnc_plugin_page_report_create_widget( GncPluginPage *page )
     priv->html = gnc_html_factory_create_html();
     gnc_html_set_parent( priv->html, topLvl );
 
+    priv->view_width = 0; // default
+    priv->view_height = 0; // default
+
     gnc_html_history_set_node_destroy_cb(gnc_html_get_history(priv->html),
                                          gnc_plugin_page_report_history_destroy_cb,
                                          (gpointer)priv);
@@ -411,8 +439,8 @@ gnc_plugin_page_report_create_widget( GncPluginPage *page )
     /* load uri when view idle */
     g_idle_add ((GSourceFunc)gnc_plugin_page_report_load_uri, page);
 
-    g_signal_connect(priv->container, "expose_event",
-                     G_CALLBACK(gnc_plugin_page_report_expose_event_cb), report);
+//    g_signal_connect(priv->container, "expose_event",
+//                     G_CALLBACK(gnc_plugin_page_report_expose_event_cb), report);
 
     gtk_widget_show_all( GTK_WIDGET(priv->container) );
 

commit 62e449f37b227ca0c954f39249c5d22cbc2a42d4
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 11:09:43 2016 +0000

    Stop the progress bar changing height
    
    When the report is run and the progress bar is updated, the height
    changes and then changes back forcing the webkit view to change height
    and ultimately use the wrong value.

diff --git a/src/gnome-utils/gnc-window.c b/src/gnome-utils/gnc-window.c
index 0d9dceb..c6549a0 100644
--- a/src/gnome-utils/gnc-window.c
+++ b/src/gnome-utils/gnc-window.c
@@ -88,7 +88,7 @@ gnc_window_get_statusbar (GncWindow *window)
     return GNC_WINDOW_GET_IFACE (window)->get_statusbar (window);
 }
 
-static GtkWidget *
+GtkWidget *
 gnc_window_get_progressbar (GncWindow *window)
 {
     g_return_val_if_fail(GNC_WINDOW (window), NULL);
diff --git a/src/gnome-utils/gnc-window.h b/src/gnome-utils/gnc-window.h
index 3e5f42d..3173142 100644
--- a/src/gnome-utils/gnc-window.h
+++ b/src/gnome-utils/gnc-window.h
@@ -76,6 +76,7 @@ void           gnc_window_set_status (GncWindow *window, GncPluginPage *page, co
 
 void           gnc_window_set_progressbar_window (GncWindow *window);
 GncWindow     *gnc_window_get_progressbar_window (void);
+GtkWidget     *gnc_window_get_progressbar (GncWindow *window);
 void           gnc_window_show_progress (const char *message, double percentage);
 
 G_END_DECLS
diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index 253a5b2..f99c596 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -329,6 +329,8 @@ gnc_plugin_page_report_load_uri (GncPluginPage *page)
 {
     GncPluginPageReport *report;
     GncPluginPageReportPrivate *priv;
+    GtkWidget *progressbar;
+    GtkAllocation allocation;
     URLType type;
     char * id_name;
     char * child_name;
@@ -348,9 +350,19 @@ gnc_plugin_page_report_load_uri (GncPluginPage *page)
 
     g_free(id_name);
     g_free(child_name);
+
+    // this sets the window for the progressbar
     gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
+
+    progressbar = gnc_window_get_progressbar (GNC_WINDOW(page->window));
+    gtk_widget_get_allocation (GTK_WIDGET(progressbar), &allocation); 
+
+    // this sets the minimum size of the progressbar to that allocated
+    gtk_widget_set_size_request (GTK_WIDGET(progressbar), -1, allocation.height);
+
     gnc_html_show_url(priv->html, type, url_location, url_label, 0);
     g_free(url_location);
+    // this resets the window for the progressbar to NULL
     gnc_window_set_progressbar_window( NULL );
 
     return FALSE;

commit 1b2f89e1948b9bff9406da45b639a2ecaa14647e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 11:07:42 2016 +0000

    Add idle function to load report
    
    The reason for webkit not using the full report area is that this area
    has not been realized when the report is created and so webkit does not
    know the correct size. By using the idle function, the page is created
    and realized before loading the report with the added advantage the
    progress bar updates on the blank report page.

diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c
index 4dc1a90..253a5b2 100644
--- a/src/report/report-gnome/gnc-plugin-page-report.c
+++ b/src/report/report-gnome/gnc-plugin-page-report.c
@@ -324,19 +324,46 @@ gnc_plugin_page_report_finalize (GObject *object)
     LEAVE(" ");
 }
 
-static
-GtkWidget*
-gnc_plugin_page_report_create_widget( GncPluginPage *page )
+static gboolean
+gnc_plugin_page_report_load_uri (GncPluginPage *page)
 {
     GncPluginPageReport *report;
     GncPluginPageReportPrivate *priv;
-    GtkWindow *topLvl;
     URLType type;
     char * id_name;
     char * child_name;
     char * url_location = NULL;
     char * url_label = NULL;
 
+    report = GNC_PLUGIN_PAGE_REPORT(page);
+    priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
+
+    id_name = g_strdup_printf("id=%d", priv->reportId );
+    child_name = gnc_build_url( URL_TYPE_REPORT, id_name, NULL );
+    type = gnc_html_parse_url( priv->html, child_name, &url_location, &url_label);
+    DEBUG( "passing id_name=[%s] child_name=[%s] type=[%s], location=[%s], label=[%s]",
+           id_name, child_name ? child_name : "(null)",
+           type ? type : "(null)", url_location ? url_location : "(null)",
+           url_label ? url_label : "(null)" );
+
+    g_free(id_name);
+    g_free(child_name);
+    gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
+    gnc_html_show_url(priv->html, type, url_location, url_label, 0);
+    g_free(url_location);
+    gnc_window_set_progressbar_window( NULL );
+
+    return FALSE;
+}
+
+static
+GtkWidget*
+gnc_plugin_page_report_create_widget( GncPluginPage *page )
+{
+    GncPluginPageReport *report;
+    GncPluginPageReportPrivate *priv;
+    GtkWindow *topLvl;
+
     ENTER("page %p", page);
 
     report = GNC_PLUGIN_PAGE_REPORT(page);
@@ -368,20 +395,9 @@ gnc_plugin_page_report_create_widget( GncPluginPage *page )
 
     // FIXME.  This is f^-1(f(x)), isn't it?
     DEBUG( "id=%d", priv->reportId );
-    id_name = g_strdup_printf("id=%d", priv->reportId );
-    child_name = gnc_build_url( URL_TYPE_REPORT, id_name, NULL );
-    type = gnc_html_parse_url( priv->html, child_name, &url_location, &url_label);
-    DEBUG( "passing id_name=[%s] child_name=[%s] type=[%s], location=[%s], label=[%s]",
-           id_name, child_name ? child_name : "(null)",
-           type ? type : "(null)", url_location ? url_location : "(null)",
-           url_label ? url_label : "(null)" );
 
-    g_free(id_name);
-    g_free(child_name);
-    gnc_window_set_progressbar_window( GNC_WINDOW(page->window) );
-    gnc_html_show_url(priv->html, type, url_location, url_label, 0);
-    g_free(url_location);
-    gnc_window_set_progressbar_window( NULL );
+    /* load uri when view idle */
+    g_idle_add ((GSourceFunc)gnc_plugin_page_report_load_uri, page);
 
     g_signal_connect(priv->container, "expose_event",
                      G_CALLBACK(gnc_plugin_page_report_expose_event_cb), report);

commit d7648a2ba72354348b03a3bc6dfcc97fa1fdec52
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Tue Nov 15 10:44:14 2016 +0000

    Remove macros/as-scrub-include.m4 from makefile
    
    This has already been removed in previous commit.

diff --git a/Makefile.am b/Makefile.am
index 00baca8..0e507e7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -54,7 +54,6 @@ dist_doc_DATA = \
 EXTRA_DIST = \
   $(SWIG_DIST_FAIL) \
   make-gnucash-potfiles.in \
-  macros/as-scrub-include.m4 \
   macros/binreloc.m4 \
   macros/compiler-flags.m4 \
   macros/ax_pkg_swig.m4 \

commit 1339c1161fcd8bd76b0d8a57ea5a3946cddfb9f6
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Sun Nov 13 17:26:43 2016 +0100

    Fix make check after commit 673888dee7c
    
    - Update the lot list of the lot's account only when the account itself is not being destroyed
    - Fix the test cases to accept the new (improved) lot destruction handling

diff --git a/src/engine/gnc-lot.c b/src/engine/gnc-lot.c
index 3afb296..1c90bf5 100644
--- a/src/engine/gnc-lot.c
+++ b/src/engine/gnc-lot.c
@@ -227,7 +227,7 @@ gnc_lot_free(GNCLot* lot)
     }
     g_list_free (priv->splits);
 
-    if (priv->account)
+    if (priv->account && !qof_instance_get_destroying(priv->account))
         xaccAccountRemoveLot (priv->account, lot);
 
     priv->account = NULL;
diff --git a/src/engine/test/utest-Account.c b/src/engine/test/utest-Account.c
index f0f2aba..e94760e 100644
--- a/src/engine/test/utest-Account.c
+++ b/src/engine/test/utest-Account.c
@@ -1274,15 +1274,11 @@ test_xaccAccountInsertRemoveLot (Fixture *fixture, gconstpointer pData)
     g_assert_cmpuint (g_list_length (p_priv->lots), == , 1);
     g_assert (gnc_lot_get_account (lot) == parent);
     gnc_lot_destroy (lot);
-    /* Destroying the lot should remove it from the account; Not Happening. */
-    g_assert_cmpuint (g_list_length (p_priv->lots), != , 0);
+    /* Destroying the lot should remove it from the account. */
+    g_assert_cmpuint (g_list_length (p_priv->lots), == , 0);
     test_signal_assert_hits (sig1, 3);
-    /* We get a modify only on the insert, since there is no remove when
-     * the lot is destroyed. */
-    test_signal_assert_hits (sig4, 3);
-    /* Same thing: There should be a "removed" signal on the lot, but
-     * since it isn't removed, no signal. */
-    test_signal_assert_hits (sig3, 1);
+    test_signal_assert_hits (sig3, 2);
+    test_signal_assert_hits (sig4, 4);
     test_signal_free (sig1);
     test_signal_free (sig2);
     test_signal_free (sig3);

commit ecb43e7d72941c32bc7bee3d3698029bfd643080
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Sat Nov 12 10:30:31 2016 +0100

    Bug 770364 - Sign of Value in Lots in Account window seems inconsistent
    
    Two parts to this bug:
    1. never reverse signs in the free splits list. Sign reversals don't
    make sense there.
    
    2. Sign reversal only makes sense for capital gains, not for business
    transactions. So only to the sign dance for non-business lots in the
    list of splits in the selected lot.

diff --git a/src/gnome/dialog-lot-viewer.c b/src/gnome/dialog-lot-viewer.c
index a4c64e4..2d6e2b5 100644
--- a/src/gnome/dialog-lot-viewer.c
+++ b/src/gnome/dialog-lot-viewer.c
@@ -485,8 +485,12 @@ gnc_split_viewer_fill (GNCLotViewer *lv, GtkListStore *store, SplitList *split_l
 {
     SplitList *node;
     GtkTreeIter iter;
-
+    gboolean is_business_lot = FALSE;
     gnc_numeric baln = gnc_numeric_zero();
+
+    if (lv->selected_lot)
+        is_business_lot = xaccAccountIsAPARType (xaccAccountGetType (gnc_lot_get_account (lv->selected_lot)));
+
     gtk_list_store_clear (lv->split_in_lot_store);
     for (node = split_list; node; node = node->next)
     {
@@ -501,8 +505,7 @@ gnc_split_viewer_fill (GNCLotViewer *lv, GtkListStore *store, SplitList *split_l
         gnc_numeric amnt, valu, gains;
 
         /* Do not show gains splits, however do show empty business splits */
-        if (!xaccAccountIsAPARType (xaccAccountGetType (xaccSplitGetAccount (split)))
-                && gnc_numeric_zero_p (xaccSplitGetAmount(split))) continue;
+        if (!is_business_lot && gnc_numeric_zero_p (xaccSplitGetAmount(split))) continue;
 
         gtk_list_store_append(store, &iter);
 
@@ -522,13 +525,13 @@ gnc_split_viewer_fill (GNCLotViewer *lv, GtkListStore *store, SplitList *split_l
                           gnc_account_print_info (lv->account, TRUE));
         gtk_list_store_set (store, &iter, SPLIT_COL_AMOUNT, amtbuff, -1);
 
-        /* Value. Invert the sign on the first, opening entry. */
+        /* Value.
+         * For non-business accounts which are part of a lot,
+         * invert the sign on the first. */
         currency = xaccTransGetCurrency (trans);
         valu = xaccSplitGetValue (split);
-        if (node != split_list)
-        {
-            valu = gnc_numeric_neg (valu);
-        }
+        if (lv->selected_lot && !is_business_lot && (node != split_list))
+                valu = gnc_numeric_neg (valu);
         xaccSPrintAmount (valbuff, valu,
                           gnc_commodity_print_info (currency, TRUE));
         gtk_list_store_set (store, &iter, SPLIT_COL_VALUE, valbuff, -1);

commit 5b832c7f9bec7e65077c139262e09070ada3e664
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Sat Nov 12 09:22:09 2016 +0100

    Use G_MAXINT64 instead of 0 to indicate an invalid date

diff --git a/src/gnome/dialog-lot-viewer.c b/src/gnome/dialog-lot-viewer.c
index 141da29..a4c64e4 100644
--- a/src/gnome/dialog-lot-viewer.c
+++ b/src/gnome/dialog-lot-viewer.c
@@ -393,7 +393,7 @@ gnc_lot_viewer_fill (GNCLotViewer *lv)
         }
         else
         {
-            gtk_list_store_set(store, &iter, LOT_COL_CLOSE, 0LL, -1);
+            gtk_list_store_set(store, &iter, LOT_COL_CLOSE, G_MAXINT64, -1);
         }
 
         /* Title */
@@ -800,7 +800,7 @@ static void print_date (GtkTreeViewColumn *tree_column,
     doc_date_time = (time64) g_value_get_int64 (&value);
     g_value_unset (&value);
 
-    if (doc_date_time) /* assumes 0 represents an invalid date/time */
+    if (doc_date_time != G_MAXINT64) /* assumes INT64_MAX represents an invalid date/time */
     {
         g_free (doc_date_str);
         doc_date_str = qof_print_date (doc_date_time);

commit 96c22f54a38420c7c3d2e981711e685edc63675c
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Fri Nov 11 21:32:30 2016 +0100

    Show empty business splits in lot viewer

diff --git a/src/gnome/dialog-lot-viewer.c b/src/gnome/dialog-lot-viewer.c
index 0bc919d..141da29 100644
--- a/src/gnome/dialog-lot-viewer.c
+++ b/src/gnome/dialog-lot-viewer.c
@@ -500,8 +500,9 @@ gnc_split_viewer_fill (GNCLotViewer *lv, GtkListStore *store, SplitList *split_l
         time64 date = xaccTransGetDate (trans);
         gnc_numeric amnt, valu, gains;
 
-        /* Do not show gains splits */
-        if (gnc_numeric_zero_p (xaccSplitGetAmount(split))) continue;
+        /* Do not show gains splits, however do show empty business splits */
+        if (!xaccAccountIsAPARType (xaccAccountGetType (xaccSplitGetAccount (split)))
+                && gnc_numeric_zero_p (xaccSplitGetAmount(split))) continue;
 
         gtk_list_store_append(store, &iter);
 

commit 254b4fbc2fcdf697096fe7fd6aed6c97618472a0
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Fri Nov 11 20:58:52 2016 +0100

    Check more splits while running check & repair on business accounts
    
    In addition, speed up the process a bit by already deleting empty splits as soon as they're encountered

diff --git a/src/engine/ScrubBusiness.c b/src/engine/ScrubBusiness.c
index 5212b5b..aa48ea3 100644
--- a/src/engine/ScrubBusiness.c
+++ b/src/engine/ScrubBusiness.c
@@ -200,7 +200,6 @@ scrub_start:
         if (!sl_split)
             continue; // next scrub lot split
 
-        // Only lot link transactions need to be scrubbed
         ll_txn = xaccSplitGetParent (sl_split);
 
         if (!ll_txn)
@@ -212,9 +211,19 @@ scrub_start:
             continue;
         }
 
-        if (xaccTransGetTxnType (ll_txn) != TXN_TYPE_LINK)
+        // Don't scrub invoice type transactions
+        if (xaccTransGetTxnType (ll_txn) == TXN_TYPE_INVOICE)
             continue; // next scrub lot split
 
+        // Empty splits can be removed immediately
+        if (gnc_numeric_zero_p (xaccSplitGetValue (sl_split)) ||
+                gnc_numeric_zero_p(xaccSplitGetValue (sl_split)))
+        {
+            xaccSplitDestroy (sl_split);
+            modified = TRUE;
+            goto scrub_start;
+        }
+
         // Iterate over all splits in the lot link transaction
         for (lts_iter = xaccTransGetSplitList (ll_txn); lts_iter; lts_iter = lts_iter->next)
         {
@@ -229,20 +238,22 @@ scrub_start:
             if (sl_split == ll_txn_split)
                 continue; // next lot link transaction split
 
+            // Skip empty other splits. They'll be scrubbed in the outer for loop later
+            if (gnc_numeric_zero_p (xaccSplitGetValue (ll_txn_split)) ||
+                    gnc_numeric_zero_p(xaccSplitGetValue (ll_txn_split)))
+                continue;
+
             // Only splits of opposite signed values can be scrubbed
             if (gnc_numeric_positive_p (xaccSplitGetValue (sl_split)) ==
                 gnc_numeric_positive_p (xaccSplitGetValue (ll_txn_split)))
                 continue; // next lot link transaction split
 
-            // Find linked lot via split
+            // We can only scrub if the other split is in a lot as well
+            // Link transactions always have their other split in another lot
+            // however ordinary payment transactions may not
             remote_lot = xaccSplitGetLot (ll_txn_split);
             if (!remote_lot)
-            {
-                // This is unexpected - write a warning message and skip this split
-                PWARN("Encountered a Lot Link transaction with a split that's not in any lot. "
-                      "This is unexpected! Skipping split %p from transaction %p.", ll_txn_split, ll_txn);
                 continue;
-            }
 
             sl_is_doc_lot = (gncInvoiceGetInvoiceFromLot (scrub_lot) != NULL);
             rl_is_doc_lot = (gncInvoiceGetInvoiceFromLot (remote_lot) != NULL);
@@ -550,10 +561,16 @@ gncScrubBusinessSplit (Split *split)
          */
         else if (gnc_numeric_zero_p (xaccSplitGetAmount(split)) && !gncInvoiceGetInvoiceFromTxn (txn))
         {
+            GNCLot *lot = xaccSplitGetLot (split);
             time64 pdate = xaccTransGetDate (txn);
             gchar *pdatestr = gnc_ctime (&pdate);
             PINFO ("Destroying empty split %p from transaction %s (%s)", split, pdatestr, xaccTransGetDescription(txn));
             xaccSplitDestroy (split);
+
+            // Also delete the lot containing this split if it was the last split in that lot
+            if (lot && (gnc_lot_count_splits (lot) == 0))
+                gnc_lot_destroy (lot);
+
             deleted_split = TRUE;
         }
 

commit a9c624bfad7d98cd95a39788b399914eea01ea7c
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Fri Nov 11 14:03:13 2016 +0100

    Business check & repair - correct lot invoice state
    
    There have been situations where a lot refered to an invoice while
    it doesn't actually contain splits for that invoice (any more).
    The new code corrects this by removing the invoice reference from the lot.
    Also if the lot and its splits don't agree on the invoice they belong to
    set the lot invoice to whatever the splits indicate.

diff --git a/src/engine/ScrubBusiness.c b/src/engine/ScrubBusiness.c
index 8ce5667..5212b5b 100644
--- a/src/engine/ScrubBusiness.c
+++ b/src/engine/ScrubBusiness.c
@@ -37,6 +37,7 @@
 #include "policy-p.h"
 #include "Account.h"
 #include "gncInvoice.h"
+#include "gncInvoiceP.h"
 #include "Scrub2.h"
 #include "ScrubBusiness.h"
 #include "Transaction.h"
@@ -46,6 +47,41 @@
 
 static QofLogModule log_module = G_LOG_DOMAIN;
 
+static void
+gncScrubInvoiceState (GNCLot *lot)
+{
+    SplitList *ls_iter = NULL;
+    Transaction *txn = NULL; // ll_txn = "Lot Link Transaction"
+    GncInvoice *invoice = NULL;
+    GncInvoice *lot_invoice = gncInvoiceGetInvoiceFromLot (lot);
+
+    for (ls_iter = gnc_lot_get_split_list (lot); ls_iter; ls_iter = ls_iter->next)
+    {
+        Split *split = ls_iter->data;
+        Transaction *txn = NULL; // ll_txn = "Lot Link Transaction"
+
+        if (!split)
+            continue; // next scrub lot split
+
+        txn = xaccSplitGetParent (split);
+        invoice = gncInvoiceGetInvoiceFromTxn (txn);
+        if (invoice)
+            break;
+
+    }
+
+    if (invoice != lot_invoice)
+    {
+        PINFO("Correcting lot invoice associaton. Old invoice: %p, new invoice %p", lot_invoice, invoice);
+        gncInvoiceDetachFromLot(lot);
+
+        if (invoice)
+            gncInvoiceAttachToLot (invoice, lot);
+        else
+            gncOwnerAttachToLot (gncInvoiceGetOwner(lot_invoice), lot);
+    }
+}
+
 // A helper function that takes two splits. If the splits are  of opposite sign
 // it reduces the biggest split to have the same value (but with opposite sign)
 // of the smaller split.
@@ -214,7 +250,7 @@ scrub_start:
             // Depending on the type of lots we're comparing, we need different actions
             // - Two document lots (an invoice and a credit note):
             //   Special treatment - look for all document lots linked via ll_txn
-            //   and update the memo to be of more use to the uses.
+            //   and update the memo to be of more use to the users.
             // - Two payment lots:
             //   (Part of) the link will be eliminated and instead (part of)
             //   one payment will be added to the other lot to keep the balance.
@@ -424,6 +460,13 @@ gncScrubBusinessLot (GNCLot *lot)
     if (acc)
         xaccAccountBeginEdit(acc);
 
+    /* Check invoice link consistency
+     * A lot should have both or neither of:
+     * - one split from an invoice transaction
+     * - an invoice-guid set
+     */
+    gncScrubInvoiceState (lot);
+
     // Scrub lot links.
     // They should only remain when two document lots are linked together
     xaccScrubMergeLotSubSplits (lot, FALSE);
diff --git a/src/engine/gncInvoice.c b/src/engine/gncInvoice.c
index 9b6c33f..222553f 100644
--- a/src/engine/gncInvoice.c
+++ b/src/engine/gncInvoice.c
@@ -1130,7 +1130,7 @@ qofInvoiceSetJob (GncInvoice *invoice, GncJob *job)
     invoice->job = job;
 }
 
-static void
+void
 gncInvoiceDetachFromLot (GNCLot *lot)
 {
     KvpFrame *kvp;
@@ -1143,7 +1143,7 @@ gncInvoiceDetachFromLot (GNCLot *lot)
     gnc_lot_commit_edit (lot);
 }
 
-static void
+void
 gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
 {
     KvpFrame *kvp;
@@ -1182,7 +1182,7 @@ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
     return gncInvoiceLookup(book, guid);
 }
 
-static void
+void
 gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
 {
     KvpFrame *kvp;
diff --git a/src/engine/gncInvoiceP.h b/src/engine/gncInvoiceP.h
index 537dc2e..5b4942a 100644
--- a/src/engine/gncInvoiceP.h
+++ b/src/engine/gncInvoiceP.h
@@ -41,5 +41,9 @@ void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
 void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);
 //void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);
 
+void gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot);
+void gncInvoiceDetachFromLot (GNCLot *lot);
+void gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn);
+
 #define gncInvoiceSetGUID(I,G) qof_instance_set_guid(QOF_INSTANCE(I),(G))
 #endif /* GNC_INVOICEP_H_ */

commit 396117eec9514f20916df858c9477857e6c92b9a
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Wed Nov 9 18:44:21 2016 +0100

    Various small improvements to check & repair on business accounts
    
    - don't attempt to merge splits that belong to an invoice transaction. These splits are managed by the business code.
    - lot link cleanup can leave empty splits, remove these as well

diff --git a/src/engine/Scrub2.c b/src/engine/Scrub2.c
index 10ee3f8..e6a60af 100644
--- a/src/engine/Scrub2.c
+++ b/src/engine/Scrub2.c
@@ -43,6 +43,7 @@
 #include "ScrubP.h"
 #include "cap-gains.h"
 #include "gnc-engine.h"
+#include "gncInvoice.h"
 #include "gnc-lot.h"
 #include "policy-p.h"
 
@@ -355,6 +356,11 @@ xaccScrubMergeSubSplits (Split *split, gboolean strict)
     if (strict && (FALSE == is_subsplit (split))) return FALSE;
 
     txn = split->parent;
+
+    // Don't mess with splits from an invoice transaction
+    // Those are the responsibility of the business code
+    if (gncInvoiceGetInvoiceFromTxn (txn)) return FALSE;
+
     lot = xaccSplitGetLot (split);
 
     ENTER ("(Lot=%s)", gnc_lot_get_title(lot));
@@ -366,6 +372,10 @@ restart:
         if (s == split) continue;
         if (qof_instance_get_destroying(s)) continue;
 
+        // Don't mess with splits from an invoice transaction
+        // Those are the responsibility of the business code
+        if (gncInvoiceGetInvoiceFromTxn (s->parent)) return FALSE;
+
         if (strict)
         {
             /* OK, this split is in the same lot (and thus same account)
@@ -386,9 +396,13 @@ restart:
         rc = TRUE;
         goto restart;
     }
-    if (gnc_numeric_zero_p (split->amount))
+    if (rc && gnc_numeric_zero_p (split->amount))
     {
+        time64 pdate = xaccTransGetDate (txn);
+        gchar *pdatestr = gnc_ctime (&pdate);
         PWARN ("Result of merge has zero amt!");
+        PWARN ("Transaction details - posted date %s - description %s", pdatestr, xaccTransGetDescription(txn));
+        g_free (pdatestr);
     }
     LEAVE (" splits merged=%d", rc);
     return rc;
diff --git a/src/engine/ScrubBusiness.c b/src/engine/ScrubBusiness.c
index cd69468..8ce5667 100644
--- a/src/engine/ScrubBusiness.c
+++ b/src/engine/ScrubBusiness.c
@@ -462,13 +462,14 @@ gncScrubBusinessLot (GNCLot *lot)
     return splits_deleted;
 }
 
-void
+gboolean
 gncScrubBusinessSplit (Split *split)
 {
     const gchar *memo = _("Please delete this transaction. Explanation at http://wiki.gnucash.org/wiki/Business_Features_Issues#Double_Posting");
     Transaction *txn;
+    gboolean deleted_split = FALSE;
 
-    if (!split) return;
+    if (!split) return FALSE;
     ENTER ("(split=%p)", split);
 
     txn = xaccSplitGetParent (split);
@@ -500,10 +501,23 @@ gncScrubBusinessSplit (Split *split)
                   txn_date);
             g_free (txn_date);
         }
+        /* Next delete any empty splits that aren't part of an invoice transaction
+         * Such splits may be the result of scrubbing the business lots, which can
+         * merge splits together while reducing superfluous lot links
+         */
+        else if (gnc_numeric_zero_p (xaccSplitGetAmount(split)) && !gncInvoiceGetInvoiceFromTxn (txn))
+        {
+            time64 pdate = xaccTransGetDate (txn);
+            gchar *pdatestr = gnc_ctime (&pdate);
+            PINFO ("Destroying empty split %p from transaction %s (%s)", split, pdatestr, xaccTransGetDescription(txn));
+            xaccSplitDestroy (split);
+            deleted_split = TRUE;
+        }
 
     }
 
     LEAVE ("(split=%p)", split);
+    return deleted_split;
 }
 
 /* ============================================================== */
@@ -563,7 +577,7 @@ gncScrubBusinessAccountSplits (Account *acc, QofPercentageFunc percentagefunc)
 {
     SplitList *splits, *node;
     gint split_count = 0;
-    gint curr_split_no = 0;
+    gint curr_split_no;
     const gchar *str;
     const char *message = _( "Checking business splits in account %s: %u of %u");
 
@@ -577,6 +591,8 @@ gncScrubBusinessAccountSplits (Account *acc, QofPercentageFunc percentagefunc)
     PINFO ("Cleaning up superfluous lot links in account %s \n", str);
     xaccAccountBeginEdit(acc);
 
+restart:
+    curr_split_no = 0;
     splits = xaccAccountGetSplitList(acc);
     split_count = g_list_length (splits);
     for (node = splits; node; node = node->next)
@@ -594,7 +610,10 @@ gncScrubBusinessAccountSplits (Account *acc, QofPercentageFunc percentagefunc)
         }
 
         if (split)
-            gncScrubBusinessSplit (split);
+            // If gncScrubBusinessSplit returns true, a split was deleted and hence
+            // The account split list has become invalid, so we need to start over
+            if (gncScrubBusinessSplit (split))
+                goto restart;
 
         PINFO("Finished processing split %d of %d",
               curr_split_no + 1, split_count);
diff --git a/src/engine/ScrubBusiness.h b/src/engine/ScrubBusiness.h
index e4be74f..0cfce50 100644
--- a/src/engine/ScrubBusiness.h
+++ b/src/engine/ScrubBusiness.h
@@ -57,7 +57,9 @@ gboolean gncScrubBusinessLot (GNCLot *lot);
 /** The gncScrubBusinessSplit() function will fix all issues found with
  *    the given split.
  *
- *    Currently this function only does one thing: check if the split is
+ *    Current checks are:
+ *
+ *    * check if the split is
  *    part of a transaction that was generated as the result of a doubly
  *    posted invoice/bill/credit note. Refer to
  *    https://bugzilla.gnome.org/show_bug.cgi?id=754209 to learn how this
@@ -66,8 +68,11 @@ gboolean gncScrubBusinessLot (GNCLot *lot);
  *    a warning is written to the trace file. Considering the user may
  *    already have added a correcting transaction we leave it up to the user
  *    to decide whether to also delete the transaction or not.
+ *
+ *    * remove empty splits, on condition they aren't part of an invoice transaction.
+ *    In this case the function returns true so the caller knows a split was removed.
  */
-void gncScrubBusinessSplit (Split *split);
+gboolean gncScrubBusinessSplit (Split *split);
 
 /** The gncScrubBusinessAccountLots() function will call
  *    gncScrubBusinessLot() on each lot in the given account.

commit d52f44a8c7055a1c91477abacfae5130de9cf569
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Sun Nov 6 17:11:30 2016 +0100

    When juggling business splits while scrubbing set both value and amount
    
    With only value there were several warnings in the log file during scrubbing

diff --git a/src/engine/gncOwner.c b/src/engine/gncOwner.c
index c55dd5c..e8e6295 100644
--- a/src/engine/gncOwner.c
+++ b/src/engine/gncOwner.c
@@ -971,10 +971,12 @@ gncOwnerReduceSplitTo (Split *split, gnc_numeric target_value)
     rem_val = gnc_numeric_sub (split_val, target_value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD); // note: values are of opposite sign
     rem_split = xaccMallocSplit (xaccSplitGetBook (split));
     xaccSplitCopyOnto (split, rem_split);
+    xaccSplitSetAmount (rem_split, rem_val);
     xaccSplitSetValue (rem_split, rem_val);
 
     txn = xaccSplitGetParent (split);
     xaccTransBeginEdit (txn);
+    xaccSplitSetAmount (split, target_value);
     xaccSplitSetValue (split, target_value);
     xaccSplitSetParent (rem_split, txn);
     xaccTransCommitEdit (txn);

commit 0bcd30301e8ae747bff8bea53a19a432a0ed9d5e
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Sun Nov 6 17:10:30 2016 +0100

    Update progress bar while running Check & Repair
    
    Not complete - should still be added for check & repair invoked from a split register

diff --git a/src/engine/Scrub.c b/src/engine/Scrub.c
index 4146f9b..8588656 100644
--- a/src/engine/Scrub.c
+++ b/src/engine/Scrub.c
@@ -59,13 +59,13 @@ static QofLogModule log_module = G_LOG_DOMAIN;
 /* ================================================================ */
 
 void
-xaccAccountTreeScrubOrphans (Account *acc)
+xaccAccountTreeScrubOrphans (Account *acc, QofPercentageFunc percentagefunc)
 {
     if (!acc) return;
 
-    xaccAccountScrubOrphans (acc);
+    xaccAccountScrubOrphans (acc, percentagefunc);
     gnc_account_foreach_descendant(acc,
-                                   (AccountCb)xaccAccountScrubOrphans, NULL);
+                                   (AccountCb)xaccAccountScrubOrphans, percentagefunc);
 }
 
 static void
@@ -99,24 +99,38 @@ TransScrubOrphansFast (Transaction *trans, Account *root)
 }
 
 void
-xaccAccountScrubOrphans (Account *acc)
+xaccAccountScrubOrphans (Account *acc, QofPercentageFunc percentagefunc)
 {
-    GList *node;
+    GList *node, *splits;
     const char *str;
+    const char *message = _( "Looking for orphans in account %s: %u of %u");
+    guint total_splits = 0;
+    guint current_split = 0;
 
     if (!acc) return;
 
     str = xaccAccountGetName (acc);
     str = str ? str : "(null)";
     PINFO ("Looking for orphans in account %s \n", str);
+    splits = xaccAccountGetSplitList(acc);
+    total_splits = g_list_length (splits);
 
-    for (node = xaccAccountGetSplitList(acc); node; node = node->next)
+    for (node = splits; node; node = node->next)
     {
         Split *split = node->data;
 
+        if (current_split % 100 == 0)
+        {
+            char *progress_msg = g_strdup_printf (message, str, current_split, total_splits);
+            (percentagefunc)(progress_msg, (100 * current_split) / total_splits);
+            g_free (progress_msg);
+        }
+
         TransScrubOrphansFast (xaccSplitGetParent (split),
                                gnc_account_get_root (acc));
+        current_split++;
     }
+    (percentagefunc)(NULL, -1.0);
 }
 
 
@@ -273,25 +287,26 @@ xaccSplitScrub (Split *split)
 /* ================================================================ */
 
 void
-xaccAccountTreeScrubImbalance (Account *acc)
+xaccAccountTreeScrubImbalance (Account *acc, QofPercentageFunc percentagefunc)
 {
-    xaccAccountScrubImbalance (acc);
+    xaccAccountScrubImbalance (acc, percentagefunc);
     gnc_account_foreach_descendant(acc,
-                                   (AccountCb)xaccAccountScrubImbalance, NULL);
+                                   (AccountCb)xaccAccountScrubImbalance, percentagefunc);
 }
 
 void
-xaccAccountScrubImbalance (Account *acc)
+xaccAccountScrubImbalance (Account *acc, QofPercentageFunc percentagefunc)
 {
     GList *node, *splits;
     const char *str;
-    gint split_count = 0, curr_split_no = 1;
+    const char *message = _( "Looking for imbalances in account %s: %u of %u");
+    gint split_count = 0, curr_split_no = 0;
 
     if (!acc) return;
 
     str = xaccAccountGetName(acc);
     str = str ? str : "(null)";
-    PINFO ("Looking for imbalance in account %s \n", str);
+    PINFO ("Looking for imbalances in account %s \n", str);
 
     splits = xaccAccountGetSplitList(acc);
     split_count = g_list_length (splits);
@@ -301,16 +316,28 @@ xaccAccountScrubImbalance (Account *acc)
         Transaction *trans = xaccSplitGetParent(split);
 
         PINFO("Start processing split %d of %d",
-              curr_split_no, split_count);
+              curr_split_no + 1, split_count);
+
+        if (curr_split_no % 100 == 0)
+        {
+            char *progress_msg = g_strdup_printf (message, str, curr_split_no, split_count);
+            (percentagefunc)(progress_msg, (100 * curr_split_no) / split_count);
+            g_free (progress_msg);
+        }
+
+        TransScrubOrphansFast (xaccSplitGetParent (split),
+                               gnc_account_get_root (acc));
+        (percentagefunc)(NULL, 0.0);
 
         xaccTransScrubCurrency(trans);
 
         xaccTransScrubImbalance (trans, gnc_account_get_root (acc), NULL);
 
         PINFO("Finished processing split %d of %d",
-              curr_split_no, split_count);
+              curr_split_no + 1, split_count);
         curr_split_no++;
     }
+    (percentagefunc)(NULL, -1.0);
 }
 
 static Split *
diff --git a/src/engine/Scrub.h b/src/engine/Scrub.h
index efdad1b..d57fadf 100644
--- a/src/engine/Scrub.h
+++ b/src/engine/Scrub.h
@@ -77,12 +77,12 @@ void xaccTransScrubOrphans (Transaction *trans);
 /** The xaccAccountScrubOrphans() method performs this scrub only for the
  *    indicated account, and not for any of its children.
  */
-void xaccAccountScrubOrphans (Account *acc);
+void xaccAccountScrubOrphans (Account *acc, QofPercentageFunc percentagefunc);
 
 /** The xaccAccountTreeScrubOrphans() method performs this scrub for the
  *    indicated account and its children.
  */
-void xaccAccountTreeScrubOrphans (Account *acc);
+void xaccAccountTreeScrubOrphans (Account *acc, QofPercentageFunc percentagefunc);
 
 /** The xaccSplitScrub method ensures that if this split has the same
  *   commodity and currency, then it will have the same amount and value.
@@ -108,8 +108,8 @@ void xaccAccountTreeScrubSplits (Account *account);
  */
 void xaccTransScrubImbalance (Transaction *trans, Account *root,
                               Account *parent);
-void xaccAccountScrubImbalance (Account *acc);
-void xaccAccountTreeScrubImbalance (Account *acc);
+void xaccAccountScrubImbalance (Account *acc, QofPercentageFunc percentagefunc);
+void xaccAccountTreeScrubImbalance (Account *acc, QofPercentageFunc percentagefunc);
 
 /** The xaccTransScrubCurrency method fixes transactions without a
  * common_currency by looking for the most commonly used currency
diff --git a/src/engine/ScrubBusiness.c b/src/engine/ScrubBusiness.c
index f93619b..cd69468 100644
--- a/src/engine/ScrubBusiness.c
+++ b/src/engine/ScrubBusiness.c
@@ -509,12 +509,13 @@ gncScrubBusinessSplit (Split *split)
 /* ============================================================== */
 
 void
-gncScrubBusinessAccountLots (Account *acc)
+gncScrubBusinessAccountLots (Account *acc, QofPercentageFunc percentagefunc)
 {
     LotList *lots, *node;
     gint lot_count = 0;
-    gint curr_lot_no = 1;
+    gint curr_lot_no = 0;
     const gchar *str;
+    const char *message = _( "Checking business lots in account %s: %u of %u");
 
     if (!acc) return;
     if (FALSE == xaccAccountIsAPARType (xaccAccountGetType (acc))) return;
@@ -533,29 +534,38 @@ gncScrubBusinessAccountLots (Account *acc)
         GNCLot *lot = node->data;
 
         PINFO("Start processing lot %d of %d",
-              curr_lot_no, lot_count);
+              curr_lot_no + 1, lot_count);
+
+        if (curr_lot_no % 100 == 0)
+        {
+            char *progress_msg = g_strdup_printf (message, str, curr_lot_no, lot_count);
+            (percentagefunc)(progress_msg, (100 * curr_lot_no) / lot_count);
+            g_free (progress_msg);
+        }
 
         if (lot)
             gncScrubBusinessLot (lot);
 
         PINFO("Finished processing lot %d of %d",
-              curr_lot_no, lot_count);
+              curr_lot_no + 1, lot_count);
         curr_lot_no++;
     }
     g_list_free(lots);
     xaccAccountCommitEdit(acc);
+    (percentagefunc)(NULL, -1.0);
     LEAVE ("(acc=%s)", str);
 }
 
 /* ============================================================== */
 
 void
-gncScrubBusinessAccountSplits (Account *acc)
+gncScrubBusinessAccountSplits (Account *acc, QofPercentageFunc percentagefunc)
 {
     SplitList *splits, *node;
     gint split_count = 0;
-    gint curr_split_no = 1;
+    gint curr_split_no = 0;
     const gchar *str;
+    const char *message = _( "Checking business splits in account %s: %u of %u");
 
     if (!acc) return;
     if (FALSE == xaccAccountIsAPARType (xaccAccountGetType (acc))) return;
@@ -574,29 +584,37 @@ gncScrubBusinessAccountSplits (Account *acc)
         Split *split = node->data;
 
         PINFO("Start processing split %d of %d",
-              curr_split_no, split_count);
+              curr_split_no + 1, split_count);
+
+        if (curr_split_no % 100 == 0)
+        {
+            char *progress_msg = g_strdup_printf (message, str, curr_split_no, split_count);
+            (percentagefunc)(progress_msg, (100 * curr_split_no) / split_count);
+            g_free (progress_msg);
+        }
 
         if (split)
             gncScrubBusinessSplit (split);
 
         PINFO("Finished processing split %d of %d",
-              curr_split_no, split_count);
+              curr_split_no + 1, split_count);
         curr_split_no++;
     }
     xaccAccountCommitEdit(acc);
+    (percentagefunc)(NULL, -1.0);
     LEAVE ("(acc=%s)", str);
 }
 
 /* ============================================================== */
 
 void
-gncScrubBusinessAccount (Account *acc)
+gncScrubBusinessAccount (Account *acc, QofPercentageFunc percentagefunc)
 {
     if (!acc) return;
     if (FALSE == xaccAccountIsAPARType (xaccAccountGetType (acc))) return;
 
-    gncScrubBusinessAccountLots (acc);
-    gncScrubBusinessAccountSplits (acc);
+    gncScrubBusinessAccountLots (acc, percentagefunc);
+    gncScrubBusinessAccountSplits (acc, percentagefunc);
 }
 
 /* ============================================================== */
@@ -605,16 +623,16 @@ static void
 lot_scrub_cb (Account *acc, gpointer data)
 {
     if (FALSE == xaccAccountIsAPARType (xaccAccountGetType (acc))) return;
-    gncScrubBusinessAccount (acc);
+    gncScrubBusinessAccount (acc, data);
 }
 
 void
-gncScrubBusinessAccountTree (Account *acc)
+gncScrubBusinessAccountTree (Account *acc, QofPercentageFunc percentagefunc)
 {
     if (!acc) return;
 
-    gnc_account_foreach_descendant(acc, lot_scrub_cb, NULL);
-    gncScrubBusinessAccount (acc);
+    gnc_account_foreach_descendant(acc, lot_scrub_cb, percentagefunc);
+    gncScrubBusinessAccount (acc, percentagefunc);
 }
 
 /* ========================== END OF FILE  ========================= */
diff --git a/src/engine/ScrubBusiness.h b/src/engine/ScrubBusiness.h
index cbf31d5..e4be74f 100644
--- a/src/engine/ScrubBusiness.h
+++ b/src/engine/ScrubBusiness.h
@@ -76,12 +76,12 @@ void gncScrubBusinessSplit (Split *split);
  *    lot structure of every lot of a business account is in good
  *    order.
  */
-void gncScrubBusinessAccountLots (Account *acc);
+void gncScrubBusinessAccountLots (Account *acc, QofPercentageFunc percentagefunc);
 
 /** The gncScrubBusinessAccountSplits() function will call
  *    gncScrubBusinessSplit() on each split in the given account.
  */
-void gncScrubBusinessAccountSplits (Account *acc);
+void gncScrubBusinessAccountSplits (Account *acc, QofPercentageFunc percentagefunc);
 
 /** The gncScrubBusinessAccount() function will call
  *    all scrub functions relevant for a given account
@@ -91,13 +91,13 @@ void gncScrubBusinessAccountSplits (Account *acc);
  *    This routine is the primary routine for fixing all
  *    (known) issues in a business account.
  */
-void gncScrubBusinessAccount (Account *acc);
+void gncScrubBusinessAccount (Account *acc, QofPercentageFunc percentagefunc);
 
 /** The gncScrubBusinessAccountTreeLots() function will call
  *    gncScrubBusinessAccount() on the given account
  *    and its sub accounts.
  */
-void gncScrubBusinessAccountTree (Account *acc);
+void gncScrubBusinessAccountTree (Account *acc, QofPercentageFunc percentagefunc);
 
 /** @} */
 #endif /* GNC_SCRUBBUSINESS_H */
diff --git a/src/gnome/dialog-lot-viewer.c b/src/gnome/dialog-lot-viewer.c
index b5e44b3..0bc919d 100644
--- a/src/gnome/dialog-lot-viewer.c
+++ b/src/gnome/dialog-lot-viewer.c
@@ -48,6 +48,7 @@
 #include "gnc-component-manager.h"
 #include "gnc-prefs.h"
 #include "gnc-ui-util.h"
+#include "gnc-window.h"
 #include "misc-gnome-utils.h"
 #include "tree-view-utils.h"
 
@@ -762,7 +763,7 @@ lv_response_cb (GtkDialog *dialog, gint response, gpointer data)
     case RESPONSE_SCRUB_ACCOUNT:
         gnc_suspend_gui_refresh ();
         if (xaccAccountIsAPARType (xaccAccountGetType(lv->account)))
-            gncScrubBusinessAccountLots (lv->account);
+            gncScrubBusinessAccountLots (lv->account, gnc_window_show_progress);
         else
             xaccAccountScrubLots (lv->account);
         gnc_resume_gui_refresh ();
diff --git a/src/gnome/gnc-plugin-page-account-tree.c b/src/gnome/gnc-plugin-page-account-tree.c
index 7864e57..ce67bd6 100644
--- a/src/gnome/gnc-plugin-page-account-tree.c
+++ b/src/gnome/gnc-plugin-page-account-tree.c
@@ -63,6 +63,7 @@
 #include "gnc-tree-model-account-types.h"
 #include "gnc-ui.h"
 #include "gnc-ui-util.h"
+#include "gnc-window.h"
 #include "dialog-lot-viewer.h"
 #include "window-reconcile.h"
 #include "window-autoclear.h"
@@ -1561,19 +1562,23 @@ static void
 gnc_plugin_page_account_tree_cmd_scrub (GtkAction *action, GncPluginPageAccountTree *page)
 {
     Account *account = gnc_plugin_page_account_tree_get_current_account (page);
+    GncWindow *window;
 
     g_return_if_fail (account != NULL);
 
     gnc_suspend_gui_refresh ();
 
-    xaccAccountScrubOrphans (account);
-    xaccAccountScrubImbalance (account);
+    window = GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window);
+    gnc_window_set_progressbar_window (window);
+
+    xaccAccountScrubOrphans (account, gnc_window_show_progress);
+    xaccAccountScrubImbalance (account, gnc_window_show_progress);
 
     // XXX: Lots/capital gains scrubbing is disabled
     if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
         xaccAccountScrubLots(account);
 
-    gncScrubBusinessAccount(account);
+    gncScrubBusinessAccount(account, gnc_window_show_progress);
 
 
     gnc_resume_gui_refresh ();
@@ -1583,19 +1588,23 @@ static void
 gnc_plugin_page_account_tree_cmd_scrub_sub (GtkAction *action, GncPluginPageAccountTree *page)
 {
     Account *account = gnc_plugin_page_account_tree_get_current_account (page);
+    GncWindow *window;
 
     g_return_if_fail (account != NULL);
 
     gnc_suspend_gui_refresh ();
 
-    xaccAccountTreeScrubOrphans (account);
-    xaccAccountTreeScrubImbalance (account);
+    window = GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window);
+    gnc_window_set_progressbar_window (window);
+
+    xaccAccountTreeScrubOrphans (account, gnc_window_show_progress);
+    xaccAccountTreeScrubImbalance (account, gnc_window_show_progress);
 
     // XXX: Lots/capital gains scrubbing is disabled
     if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
         xaccAccountTreeScrubLots(account);
 
-    gncScrubBusinessAccountTree(account);
+    gncScrubBusinessAccountTree(account, gnc_window_show_progress);
 
     gnc_resume_gui_refresh ();
 }
@@ -1604,16 +1613,20 @@ static void
 gnc_plugin_page_account_tree_cmd_scrub_all (GtkAction *action, GncPluginPageAccountTree *page)
 {
     Account *root = gnc_get_current_root_account ();
+    GncWindow *window;
 
     gnc_suspend_gui_refresh ();
 
-    xaccAccountTreeScrubOrphans (root);
-    xaccAccountTreeScrubImbalance (root);
+    window = GNC_WINDOW(GNC_PLUGIN_PAGE (page)->window);
+    gnc_window_set_progressbar_window (window);
+
+    xaccAccountTreeScrubOrphans (root, gnc_window_show_progress);
+    xaccAccountTreeScrubImbalance (root, gnc_window_show_progress);
     // XXX: Lots/capital gains scrubbing is disabled
     if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
         xaccAccountTreeScrubLots(root);
 
-    gncScrubBusinessAccountTree(root);
+    gncScrubBusinessAccountTree(root, gnc_window_show_progress);
 
     gnc_resume_gui_refresh ();
 }
diff --git a/src/gnome/gnc-plugin-page-register.c b/src/gnome/gnc-plugin-page-register.c
index 88b03a5..0585617 100644
--- a/src/gnome/gnc-plugin-page-register.c
+++ b/src/gnome/gnc-plugin-page-register.c
@@ -3792,8 +3792,10 @@ gnc_plugin_page_register_cmd_scrub_all (GtkAction *action,
     GncPluginPageRegisterPrivate *priv;
     Query *query;
     Account *root;
+    GncWindow *window;
     GList *node, *splits;
-    gint split_count = 0, curr_split_no = 1;
+    gint split_count = 0, curr_split_no = 0;
+    const char *message = _( "Checking splits in current register: %u of %u");
 
     g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
 
@@ -3808,6 +3810,9 @@ gnc_plugin_page_register_cmd_scrub_all (GtkAction *action,
     }
 
     gnc_suspend_gui_refresh();
+    window = GNC_WINDOW(GNC_PLUGIN_PAGE (plugin_page)->window);
+    gnc_window_set_progressbar_window (window);
+
     root = gnc_get_current_root_account();
 
     splits = qof_query_run(query);
@@ -3818,9 +3823,17 @@ gnc_plugin_page_register_cmd_scrub_all (GtkAction *action,
         Split *split = node->data;
         Transaction *trans = xaccSplitGetParent(split);
 
+        if (!split) continue;
 
         PINFO("Start processing split %d of %d",
-              curr_split_no, split_count);
+              curr_split_no + 1, split_count);
+
+        if (curr_split_no % 100 == 0)
+        {
+            char *progress_msg = g_strdup_printf (message, curr_split_no, split_count);
+            gnc_window_show_progress (progress_msg, (100 * curr_split_no) / split_count);
+            g_free (progress_msg);
+        }
 
         xaccTransScrubOrphans(trans);
         xaccTransScrubImbalance(trans, root, NULL);
@@ -3833,10 +3846,11 @@ gnc_plugin_page_register_cmd_scrub_all (GtkAction *action,
         }
 
         PINFO("Finished processing split %d of %d",
-              curr_split_no, split_count);
+              curr_split_no + 1, split_count);
         curr_split_no++;
     }
 
+    gnc_window_show_progress (NULL, -1.0);
     gnc_resume_gui_refresh();
     LEAVE(" ");
 }
diff --git a/src/gnome/window-reconcile.c b/src/gnome/window-reconcile.c
index 6813161..c1fb12b 100644
--- a/src/gnome/window-reconcile.c
+++ b/src/gnome/window-reconcile.c
@@ -54,6 +54,7 @@
 #include "gnc-prefs.h"
 #include "gnc-ui.h"
 #include "gnc-ui-balances.h"
+#include "gnc-window.h"
 #include "guile-util.h"
 #include "reconcile-view.h"
 #include "window-reconcile.h"
@@ -1407,8 +1408,8 @@ gnc_recn_scrub_cb(GtkAction *action, gpointer data)
 
     gnc_suspend_gui_refresh ();
 
-    xaccAccountTreeScrubOrphans (account);
-    xaccAccountTreeScrubImbalance (account);
+    xaccAccountTreeScrubOrphans (account, gnc_window_show_progress);
+    xaccAccountTreeScrubImbalance (account, gnc_window_show_progress);
 
     // XXX: Lots are disabled.
     if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)
diff --git a/src/gnome/window-reconcile2.c b/src/gnome/window-reconcile2.c
index 4409b37..bcb121f 100644
--- a/src/gnome/window-reconcile2.c
+++ b/src/gnome/window-reconcile2.c
@@ -54,6 +54,7 @@
 #include "gnc-prefs.h"
 #include "gnc-ui.h"
 #include "gnc-ui-balances.h"
+#include "gnc-window.h"
 #include "guile-util.h"
 #include "reconcile-view.h"
 #include "window-reconcile2.h"
@@ -1370,8 +1371,8 @@ gnc_recn_scrub_cb (GtkAction *action, gpointer data)
 
     gnc_suspend_gui_refresh ();
 
-    xaccAccountTreeScrubOrphans (account);
-    xaccAccountTreeScrubImbalance (account);
+    xaccAccountTreeScrubOrphans (account, gnc_window_show_progress);
+    xaccAccountTreeScrubImbalance (account, gnc_window_show_progress);
 
     // XXX: Lots are disabled.
     if (g_getenv("GNC_AUTO_SCRUB_LOTS") != NULL)

commit 673888dee7c972d2ed8470ccc28c466162910a6d
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Wed Nov 9 18:41:05 2016 +0100

    Remove lot from account while deleting the lot
    
    There was no way the account was informed about the lot being deleted.
    This was resulting into invalid lot lists in an account while scrubbing.
    Which would bomb at later stages like when re-running check & repair or
    opening the lot viewer. Also saving would report a number of critical messages
    about invalid objects, but these didn't result in a segfault.

diff --git a/src/engine/gnc-lot.c b/src/engine/gnc-lot.c
index ce780c4..3afb296 100644
--- a/src/engine/gnc-lot.c
+++ b/src/engine/gnc-lot.c
@@ -227,6 +227,9 @@ gnc_lot_free(GNCLot* lot)
     }
     g_list_free (priv->splits);
 
+    if (priv->account)
+        xaccAccountRemoveLot (priv->account, lot);
+
     priv->account = NULL;
     priv->is_closed = TRUE;
     /* qof_instance_release (&lot->inst); */

commit 32c4d1458870bdbcdbed1b47f23c2957af1f8f3d
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Nov 10 13:56:09 2016 -0800

    Ensure that the Namespace combo box is initialized to a valid iter.
    
    Thanks to David T. for noticing that it wasn't.

diff --git a/src/gnome-utils/dialog-commodity.c b/src/gnome-utils/dialog-commodity.c
index ca3c564..a30ffd6 100644
--- a/src/gnome-utils/dialog-commodity.c
+++ b/src/gnome-utils/dialog-commodity.c
@@ -646,6 +646,7 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
     GtkTreeModel *model;
     GtkTreeIter iter, match;
     GList *namespaces, *node;
+    gboolean matched = FALSE;
 
     g_return_if_fail(GTK_IS_COMBO_BOX (cbwe));
 
@@ -653,8 +654,6 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
     combo_box = GTK_COMBO_BOX(cbwe);
     model = gtk_combo_box_get_model(combo_box);
     gtk_list_store_clear(GTK_LIST_STORE(model));
-    gtk_tree_model_get_iter_first(model, &match);
-    gtk_combo_box_set_active_iter(combo_box, &match);
 
     /* fetch a list of the namespaces */
     switch (mode)
@@ -698,9 +697,14 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
         }
 
         if (init_string && (g_utf8_collate(node->data, init_string) == 0))
+        {
+            matched = TRUE;
             match = iter;
+        }
     }
 
+    if (!matched)
+        gtk_tree_model_get_iter_first(model, &match);
     gtk_combo_box_set_active_iter(combo_box, &match);
     g_list_free(namespaces);
 }

commit 5fcdfba69c9a630767d56db45a52c0087ba2c594
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Oct 24 11:21:12 2016 +1100

    Bug 769124 - Australian (GMT-10) OFX transactions imported have previous
    
    day's date. Previous efforts didn't work on Windows and shouldn't have
    elsewhere because gnc_localtime and gnc_mktime are inverse functions;
    in particular gnc_mktime doesn't adjust the time based on the value
    of tm_isdst, though some implementations of STDC mktime do.
    
    Rather than being too clever about trying to find the DST offset this
    implementation just uses 1 hour.

diff --git a/src/import-export/ofx/gnc-ofx-import.c b/src/import-export/ofx/gnc-ofx-import.c
index 4f84cb2..da6a479 100644
--- a/src/import-export/ofx/gnc-ofx-import.c
+++ b/src/import-export/ofx/gnc-ofx-import.c
@@ -337,13 +337,8 @@ fix_ofx_bug_39 (time64 t)
 #if HAVE_OFX_BUG_39
     struct tm stm;
     gnc_localtime_r(&t, &stm);
-    if (!stm.tm_isdst)
-    {
-        time64 new_t;
-        stm.tm_isdst = 1;
-        new_t = gnc_mktime(&stm);
-    t += t - new_t;
-    }
+    if (daylight && !stm.tm_isdst)
+      t += 3600;
 #endif
     return t;
 }

commit 6695ef9585c638650b97ce1dd9122095b9485008
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Oct 20 10:40:18 2016 -0700

    Bug 769124 - Australian (GMT-10) OFX transactions imported have previous days date.
    
    Fix on Windows, where the test failed to build.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 308d9a8..d48b2b5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -292,8 +292,12 @@ ENDIF (WITH_AQBANKING)
 IF (WITH_OFX)
   GNC_PKG_CHECK_MODULES (LIBOFX REQUIRED libofx)
   INCLUDE(CheckCXXSourceRuns)
-  SET(CMAKE_REQUIRED_LIBRARIES "-lofx")
-  CHECK_CXX_SOURCE_RUNS("
+  IF (WIN32)
+      SET(CMAKE_REQUIRED_LIBRARIES "-L ${CMAKE_PREFIX_PATH}/libofx/lib -lofx")
+  ELSE (WIN32)
+      SET(CMAKE_REQUIRED_LIBRARIES "-lofx")
+  ENDIF (WIN32)
+      CHECK_CXX_SOURCE_RUNS("
 #include <time.h>
 #include <stdlib.h>
 #include <string>
@@ -306,8 +310,11 @@ int main(int argc, char** argv)
     ts.tm_year = 116;
     ts.tm_mon = 2;
     ts.tm_mday = 19;
-
-    setenv(\"TZ\", \"PST 08 PDT 07 M 4.1.0, M 10.6.0\", 1);
+#ifdef _WIN32
+    putenv(\"TZ=PST-8PDT-7,M 4.1.0/0,M 10.6.0/0\");
+#else
+    setenv(\"TZ\", \"PST 08P DT 07 M 4.1.0, M 10.6.0\", 1);
+#endif
     time_t t = ofxdate_to_time_t(timestr);
     if (t == mktime(&ts))
         exit(1);
diff --git a/configure.ac b/configure.ac
index 3ee4e69..76dd371 100644
--- a/configure.ac
+++ b/configure.ac
@@ -808,8 +808,11 @@ struct tm ts;
 ts.tm_year = 116;
 ts.tm_mon = 2;
 ts.tm_mday = 19;
-
+#ifdef _WIN32
+putenv(\"TZ=PST-8PDT-7,M 4.1.0/0,M 10.6.0/0\");
+#else
 setenv("TZ", "PST 08 PDT 07 M 4.1.0, M 10.6.0", 1);
+#endif
 time_t t = ofxdate_to_time_t(timestr);
 if (t == mktime(&ts))
   exit(0);

commit c68452a497ce707c662df2efc5bef9ef9123a6ce
Author: Rob.Gowin <robgowin at gmail.com>
Date:   Fri Oct 14 14:17:04 2016 -0500

    Remove configuration of HAVE_PUTENV.
    
    The Python includes files for Windows define HAVE_PUTENV to be
    empty. GnuCash under MINGW (only) defines it to be 1. This causes
    redefinition errors when building the Python bindings on Windows.
    HAVE_PUTENV is not used in the GnuCash code base, so the best
    solution seems to be to just get rid of it.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1465093..a4397c0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,10 +13,6 @@ IF (WIN32)
   SET (HAVE_HTMLHELPW 1)
 ENDIF (WIN32)
 
-IF (MINGW)
-  SET (HAVE_PUTENV 1)
-ENDIF (MINGW)
-
 CHECK_INCLUDE_FILES (X11/Xlib.h HAVE_X11_XLIB_H)
 CHECK_INCLUDE_FILES (dirent.h HAVE_DIRENT_H)
 CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H)
diff --git a/src/config.h.cmake.in b/src/config.h.cmake.in
index 2c85bc4..0d0334b 100644
--- a/src/config.h.cmake.in
+++ b/src/config.h.cmake.in
@@ -197,9 +197,6 @@
 /* Have PTHREAD_PRIO_INHERIT. */
 #cmakedefine HAVE_PTHREAD_PRIO_INHERIT 1
 
-/* Define to 1 if you have the `putenv' function. */
-#cmakedefine HAVE_PUTENV 1
-
 /* If available, contains the Python version number currently in use. */
 #cmakedefine HAVE_PYTHON 1
 



Summary of changes:
 CMakeLists.txt                                     |  15 +-
 configure.ac                                       |   5 +-
 src/CMakeLists.txt                                 |   4 -
 src/app-utils/app-utils.scm                        |   1 +
 src/app-utils/options.scm                          |  44 +++++-
 src/config.h.cmake.in                              |   3 -
 src/engine/Scrub.c                                 |  55 +++++--
 src/engine/Scrub.h                                 |   8 +-
 src/engine/Scrub2.c                                |  16 +-
 src/engine/ScrubBusiness.c                         | 151 ++++++++++++++----
 src/engine/ScrubBusiness.h                         |  17 +-
 src/engine/gnc-lot.c                               |   3 +
 src/engine/gncInvoice.c                            |   6 +-
 src/engine/gncInvoiceP.h                           |   4 +
 src/engine/gncOwner.c                              |   2 +
 src/engine/test/utest-Account.cpp                  |  12 +-
 src/gnome-utils/dialog-commodity.c                 |   8 +-
 src/gnome-utils/dialog-options.c                   | 101 ++++++++++++
 src/gnome-utils/gnc-date-format.c                  |   2 +-
 src/gnome-utils/gnc-icons.c                        |   1 +
 src/gnome-utils/gnc-icons.h                        |   1 +
 src/gnome-utils/gnc-window.c                       |   2 +-
 src/gnome-utils/gnc-window.h                       |   1 +
 src/gnome-utils/gtkbuilder/gnc-date-format.glade   |   7 +-
 src/gnome/dialog-lot-viewer.c                      |  27 ++--
 src/gnome/dialog-print-check.c                     |   2 +-
 src/gnome/gnc-plugin-page-account-tree.c           |  31 ++--
 src/gnome/gnc-plugin-page-register.c               |  20 ++-
 ...gnucash.dialogs.checkprinting.gschema.xml.in.in |   2 +-
 src/gnome/window-reconcile.c                       |   5 +-
 src/gnome/window-reconcile2.c                      |   5 +-
 src/html/gnc-html-webkit.c                         |  14 +-
 src/html/gnc-html.c                                |  21 ++-
 src/html/gnc-html.h                                |   5 +-
 src/import-export/ofx/gnc-ofx-import.c             |   9 +-
 src/libqof/qof/gnc-date.cpp                        |   8 +
 src/libqof/qof/gnc-date.h                          |   3 +-
 src/libqof/qof/test/test-gnc-date.c                |   3 +
 src/pixmaps/Makefile.am                            |   2 +
 src/pixmaps/gnc-account-report-16.png              | Bin 0 -> 417 bytes
 src/pixmaps/gnc-account-report.png                 | Bin 0 -> 359 bytes
 src/report/business-reports/taxinvoice.scm         |   5 +-
 src/report/report-gnome/dialog-custom-report.c     |   2 -
 src/report/report-gnome/gnc-plugin-page-report.c   | 174 +++++++++++++++------
 src/report/report-system/options-utilities.scm     |   4 +-
 45 files changed, 634 insertions(+), 177 deletions(-)
 create mode 100644 src/pixmaps/gnc-account-report-16.png
 create mode 100644 src/pixmaps/gnc-account-report.png



More information about the gnucash-changes mailing list