gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Tue Aug 29 16:31:35 EDT 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/a670783e (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6ca85450 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b4852063 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/047bc8d6 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a7abc312 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/89dbc094 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e1d40752 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f16f2022 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c3466b79 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/576b1d07 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/42915a42 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/667f1757 (commit)
	from  https://github.com/Gnucash/gnucash/commit/bbea5061 (commit)



commit a670783eb628476228c27c45a6164d380c670de1
Merge: bbea506 6ca8545
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Tue Aug 29 22:24:43 2017 +0200

    Merge branch 'prices-out2' of https://github.com/Bob-IT/gnucash


commit 6ca85450a8c73f45258569061cbfdfdc43fd9e16
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:59:07 2017 +0100

    Move gnc-gdate-utils functions to gnc-date and remove files.
    
    Also update related files to reflect move of gnc-gdate-util functions

diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c
index 247b5d3..ce62fe6 100644
--- a/gnucash/gnome-utils/dialog-utils.c
+++ b/gnucash/gnome-utils/dialog-utils.c
@@ -35,6 +35,7 @@
 
 #include "dialog-utils.h"
 #include "gnc-commodity.h"
+#include "gnc-date.h"
 #include "gnc-path.h"
 #include "gnc-engine.h"
 #include "gnc-euro.h"
@@ -43,7 +44,6 @@
 #include "gnc-combott.h"
 #include "guile-util.h"
 #include "gnc-main-window.h"
-#include <gnc-gdate-utils.h>
 
 /* This static indicates the debugging module that this .o belongs to. */
 static QofLogModule log_module = GNC_MOD_GUI;
diff --git a/gnucash/gnome-utils/gnc-date-edit.c b/gnucash/gnome-utils/gnc-date-edit.c
index 1c9dcbe..d700f64 100644
--- a/gnucash/gnome-utils/gnc-date-edit.c
+++ b/gnucash/gnome-utils/gnc-date-edit.c
@@ -43,7 +43,6 @@
 #include <ctype.h> /* isdigit */
 #include <stdio.h>
 
-#include <gnc-gdate-utils.h>
 #include "gnc-date.h"
 #include "gnc-engine.h"
 #include "dialog-utils.h"
diff --git a/gnucash/gnome-utils/gnc-dense-cal-store.c b/gnucash/gnome-utils/gnc-dense-cal-store.c
index 9bfce1e..6355348 100644
--- a/gnucash/gnome-utils/gnc-dense-cal-store.c
+++ b/gnucash/gnome-utils/gnc-dense-cal-store.c
@@ -33,11 +33,11 @@
 #include "config.h"
 #include <glib.h>
 #include <glib-object.h>
+#include "gnc-date.h"
 #include "gnc-dense-cal.h"
 #include "gnc-dense-cal-model.h"
 #include "gnc-dense-cal-store.h"
 #include "Recurrence.h"
-#include <gnc-gdate-utils.h>
 
 struct _GncDenseCalStore
 {
diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c
index 8d2bc32..1f4e81b 100644
--- a/gnucash/gnome-utils/gnc-dense-cal.c
+++ b/gnucash/gnome-utils/gnc-dense-cal.c
@@ -30,7 +30,7 @@
 #include <gtk/gtk.h>
 #include <math.h>
 #include <stdlib.h>
-#include <gnc-gdate-utils.h>
+#include "gnc-date.h"
 #include "dialog-utils.h"
 
 /**
diff --git a/gnucash/gnome-utils/gnc-period-select.c b/gnucash/gnome-utils/gnc-period-select.c
index 3fe2f42..179edf4 100644
--- a/gnucash/gnome-utils/gnc-period-select.c
+++ b/gnucash/gnome-utils/gnc-period-select.c
@@ -37,7 +37,6 @@
 #include "gnc-date.h"
 #include "gnc-period-select.h"
 #include "gnc-prefs.h"
-#include <gnc-gdate-utils.h>
 #include "dialog-utils.h"
 
 enum
diff --git a/gnucash/gnome-utils/gnc-recurrence.c b/gnucash/gnome-utils/gnc-recurrence.c
index 67ff550..f2e1197 100644
--- a/gnucash/gnome-utils/gnc-recurrence.c
+++ b/gnucash/gnome-utils/gnc-recurrence.c
@@ -29,11 +29,11 @@
 #include <glib/gi18n.h>
 
 #include "dialog-utils.h"
+#include "gnc-date.h"
 #include "gnc-recurrence.h"
 #include "gnc-date-edit.h"
 #include "Recurrence.h"
 #include "gnc-engine.h"
-#include "gnc-gdate-utils.h"
 
 static QofLogModule log_module = GNC_MOD_GUI;
 
diff --git a/gnucash/gnome-utils/gnc-tree-control-split-reg.c b/gnucash/gnome-utils/gnc-tree-control-split-reg.c
index 25ee798..2383ddf 100644
--- a/gnucash/gnome-utils/gnc-tree-control-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-control-split-reg.c
@@ -36,9 +36,9 @@
 #include "gnc-tree-util-split-reg.h"
 #include "gnc-tree-view-split-reg.h"
 #include "gnc-component-manager.h"
+#include "gnc-date.h"
 #include "gnc-ui.h"
 #include "gnc-prefs.h"
-#include "gnc-gdate-utils.h"
 #include "gnc-warnings.h"
 #include "dialog-utils.h"
 #include "dialog-dup-trans.h"
diff --git a/gnucash/gnome/assistant-acct-period.c b/gnucash/gnome/assistant-acct-period.c
index 9190119..ea6bd1b 100644
--- a/gnucash/gnome/assistant-acct-period.c
+++ b/gnucash/gnome/assistant-acct-period.c
@@ -45,9 +45,9 @@
 #include "assistant-acct-period.h"
 #include "gnc-component-manager.h"
 #include "qof.h"
+#include "gnc-date.h"
 #include "gnc-file.h"
 #include "gnc-frequency.h"
-#include "gnc-gdate-utils.h"
 #include "gnc-gui-query.h"
 #include "gnc-ui-util.h"
 #include "misc-gnome-utils.h"
diff --git a/gnucash/gnome/assistant-loan.c b/gnucash/gnome/assistant-loan.c
index af871fa..7d7f616 100644
--- a/gnucash/gnome/assistant-loan.c
+++ b/gnucash/gnome/assistant-loan.c
@@ -41,7 +41,6 @@
 #include "dialog-utils.h"
 #include "Account.h"
 #include "gnc-ui.h"
-#include "gnc-gdate-utils.h"
 #include "gnc-gui-query.h"
 #include "gnc-ui-util.h"
 #include "gnc-frequency.h"
diff --git a/gnucash/gnome/dialog-invoice.c b/gnucash/gnome/dialog-invoice.c
index 6f59118..5388de8 100644
--- a/gnucash/gnome/dialog-invoice.c
+++ b/gnucash/gnome/dialog-invoice.c
@@ -32,13 +32,13 @@
 
 #include "qof.h"
 
-#include <gnc-gdate-utils.h>
 #include "dialog-utils.h"
 #include "gnc-component-manager.h"
 #include "gnc-ui.h"
 #include "gnc-gui-query.h"
 #include "gnc-prefs.h"
 #include "gnc-ui-util.h"
+#include "gnc-date.h"
 #include "gnc-date-edit.h"
 #include "gnc-amount-edit.h"
 #include "gnucash-sheet.h"
diff --git a/gnucash/gnome/dialog-print-check.c b/gnucash/gnome/dialog-print-check.c
index 0c7f0f2..021b52f 100644
--- a/gnucash/gnome/dialog-print-check.c
+++ b/gnucash/gnome/dialog-print-check.c
@@ -36,7 +36,6 @@
 #include <locale.h>
 #include <math.h>
 
-#include <gnc-gdate-utils.h>
 #include "qof.h"
 #include "gnc-date.h"
 #include "gnc-prefs.h"
diff --git a/gnucash/gnome/dialog-sx-editor.c b/gnucash/gnome/dialog-sx-editor.c
index 76b6948..596d04b 100644
--- a/gnucash/gnome/dialog-sx-editor.c
+++ b/gnucash/gnome/dialog-sx-editor.c
@@ -38,7 +38,6 @@
 #include <glib/gi18n.h>
 #include <locale.h>
 
-#include <gnc-gdate-utils.h>
 #include "qof.h"
 #include "Account.h"
 #include "SchedXaction.h"
diff --git a/gnucash/gnome/dialog-sx-editor2.c b/gnucash/gnome/dialog-sx-editor2.c
index 74c704c..e4c308c 100644
--- a/gnucash/gnome/dialog-sx-editor2.c
+++ b/gnucash/gnome/dialog-sx-editor2.c
@@ -38,7 +38,6 @@
 #include <glib/gi18n.h>
 #include <locale.h>
 
-#include <gnc-gdate-utils.h>
 #include "qof.h"
 #include "Account.h"
 #include "SchedXaction.h"
diff --git a/gnucash/gnome/dialog-sx-from-trans.c b/gnucash/gnome/dialog-sx-from-trans.c
index d9b8df5..c3db976 100644
--- a/gnucash/gnome/dialog-sx-from-trans.c
+++ b/gnucash/gnome/dialog-sx-from-trans.c
@@ -26,11 +26,11 @@
 
 #include "config.h"
 
-#include <gnc-gdate-utils.h>
 #include "dialog-sx-editor.h"
 #include "dialog-sx-from-trans.h"
 #include "dialog-utils.h"
 #include "gnc-component-manager.h"
+#include "gnc-date.h"
 #include "gnc-date-edit.h"
 #include "gnc-dense-cal-store.h"
 #include "gnc-dense-cal.h"
diff --git a/gnucash/gnome/gnc-plugin-page-sx-list.c b/gnucash/gnome/gnc-plugin-page-sx-list.c
index 080558c..e59946e 100644
--- a/gnucash/gnome/gnc-plugin-page-sx-list.c
+++ b/gnucash/gnome/gnc-plugin-page-sx-list.c
@@ -47,7 +47,6 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include <gnc-gdate-utils.h>
 #include <gnc-gobject-utils.h>
 #include "SX-book.h"
 #include "Split.h"
@@ -59,6 +58,7 @@
 #include "dialog-utils.h"
 #include "gnc-commodity.h"
 #include "gnc-component-manager.h"
+#include "gnc-date.h"
 #include "gnc-dense-cal.h"
 #include "gnc-engine.h"
 #include "gnc-event.h"
diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c
index 2adcb39..086be20 100644
--- a/gnucash/gnome/window-reconcile.c
+++ b/gnucash/gnome/window-reconcile.c
@@ -44,10 +44,10 @@
 #include "dialog-utils.h"
 #include "gnc-amount-edit.h"
 #include "gnc-component-manager.h"
+#include "gnc-date.h"
 #include "gnc-date-edit.h"
 #include "gnc-event.h"
 #include "gnc-filepath-utils.h"
-#include <gnc-gdate-utils.h>
 #include "gnc-gnome-utils.h"
 #include "gnc-main-window.h"
 #include "gnc-plugin-page-register.h"
diff --git a/gnucash/gnome/window-reconcile2.c b/gnucash/gnome/window-reconcile2.c
index 3d49bba..8d58d33 100644
--- a/gnucash/gnome/window-reconcile2.c
+++ b/gnucash/gnome/window-reconcile2.c
@@ -44,10 +44,10 @@
 #include "dialog-utils.h"
 #include "gnc-amount-edit.h"
 #include "gnc-component-manager.h"
+#include "gnc-date.h"
 #include "gnc-date-edit.h"
 #include "gnc-event.h"
 #include "gnc-filepath-utils.h"
-#include <gnc-gdate-utils.h>
 #include "gnc-gnome-utils.h"
 #include "gnc-main-window.h"
 #include "gnc-plugin-page-register2.h"
diff --git a/gnucash/import-export/bi-import/dialog-bi-import.c b/gnucash/import-export/bi-import/dialog-bi-import.c
index 33a0944..3675a79 100644
--- a/gnucash/import-export/bi-import/dialog-bi-import.c
+++ b/gnucash/import-export/bi-import/dialog-bi-import.c
@@ -39,6 +39,7 @@
 #include <glib.h>
 #include <glib/gstdio.h>
 
+#include "gnc-date.h"
 #include "gnc-ui.h"
 #include "gnc-ui-util.h"
 #include "gnc-gui-query.h"
@@ -56,7 +57,6 @@
 #include "gncIDSearch.h"
 #include "dialog-bi-import.h"
 #include "dialog-bi-import-helper.h"
-#include <gnc-gdate-utils.h>
 
 // To open the invoices for editing
 #include "gnc-plugin-page-invoice.h"
diff --git a/gnucash/register/ledger-core/split-register-util.c b/gnucash/register/ledger-core/split-register-util.c
index 2211d22..53a4de7 100644
--- a/gnucash/register/ledger-core/split-register-util.c
+++ b/gnucash/register/ledger-core/split-register-util.c
@@ -24,7 +24,7 @@
 
 #include <glib.h>
 
-#include <gnc-gdate-utils.h>
+#include "gnc-date.h"
 #include "pricecell.h"
 #include "split-register-p.h"
 
diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c
index ca5c977..e1f38e3 100644
--- a/gnucash/register/ledger-core/split-register.c
+++ b/gnucash/register/ledger-core/split-register.c
@@ -28,12 +28,12 @@
 #include <glib/gi18n.h>
 #include <libguile.h>
 
-#include <gnc-gdate-utils.h>
 #include "combocell.h"
 #include "datecell.h"
 #include "dialog-utils.h"
 #include "gnc-component-manager.h"
 #include "split-register-p.h"
+#include "gnc-date.h"
 #include "gnc-ledger-display.h"
 #include "gnc-prefs.h"
 #include "gnc-ui.h"
diff --git a/libgnucash/app-utils/gnc-accounting-period.c b/libgnucash/app-utils/gnc-accounting-period.c
index f947e71..41f75e5 100644
--- a/libgnucash/app-utils/gnc-accounting-period.c
+++ b/libgnucash/app-utils/gnc-accounting-period.c
@@ -44,7 +44,6 @@
 #include "config.h"
 #include <string.h>
 #include "gnc-accounting-period.h"
-#include "gnc-gdate-utils.h"
 #include "gnc-date.h"
 #include "gnc-prefs.h"
 #include "qof.h"
diff --git a/libgnucash/app-utils/gnc-sx-instance-model.c b/libgnucash/app-utils/gnc-sx-instance-model.c
index 62c4c73..bc5997a 100644
--- a/libgnucash/app-utils/gnc-sx-instance-model.c
+++ b/libgnucash/app-utils/gnc-sx-instance-model.c
@@ -42,13 +42,13 @@
 #include "Split.h"
 #include "Transaction.h"
 #include "gnc-commodity.h"
+#include "gnc-date.h"
 #include "gnc-event.h"
 #include "gnc-exp-parser.h"
 #include "gnc-glib-utils.h"
 #include "gnc-sx-instance-model.h"
 #include "gnc-ui-util.h"
 #include "qof.h"
-#include <gnc-gdate-utils.h>
 
 #undef G_LOG_DOMAIN
 #define G_LOG_DOMAIN "gnc.app-utils.sx"
diff --git a/libgnucash/app-utils/test/test-sx.cpp b/libgnucash/app-utils/test/test-sx.cpp
index 027731b..71f36c0 100644
--- a/libgnucash/app-utils/test/test-sx.cpp
+++ b/libgnucash/app-utils/test/test-sx.cpp
@@ -24,9 +24,9 @@ extern "C"
 #include <stdlib.h>
 #include <glib.h>
 #include "SX-book.h"
+#include "gnc-date.h"
 #include "gnc-sx-instance-model.h"
 #include "gnc-ui-util.h"
-#include <gnc-gdate-utils.h>
 
 #include "test-stuff.h"
 #include "test-engine-stuff.h"
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index b6d92d1..041ef20 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -54,7 +54,6 @@ SET (engine_HEADERS
   gnc-engine.h
   gnc-event.h
   gnc-features.h
-  gnc-gdate-utils.h
   gnc-hooks.h
   gnc-numeric.h
   gnc-numeric.hpp
@@ -160,7 +159,6 @@ SET (engine_SOURCES
   gnc-engine.c
   gnc-event.c
   gnc-features.c
-  gnc-gdate-utils.c
   gnc-hooks.c
   gnc-int128.cpp
   gnc-lot.c
diff --git a/libgnucash/engine/Makefile.am b/libgnucash/engine/Makefile.am
index 56677e1..4943aef 100644
--- a/libgnucash/engine/Makefile.am
+++ b/libgnucash/engine/Makefile.am
@@ -40,7 +40,6 @@ libgncmod_engine_la_SOURCES = \
   gnc-engine.c \
   gnc-event.c \
   gnc-features.c \
-  gnc-gdate-utils.c \
   gnc-hooks.c \
   gnc-int128.cpp \
   gnc-lot.c \
@@ -125,7 +124,6 @@ gncinclude_HEADERS = \
   gnc-engine.h \
   gnc-event.h \
   gnc-features.h \
-  gnc-gdate-utils.h \
   gnc-hooks.h \
   gnc-numeric.h \
   gnc-numeric.hpp \
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 1e88c32..4f4a13b 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -3,6 +3,7 @@
  *                                                                  *
  * Copyright 1997 Robin D. Clark <rclark at cs.hmc.edu>                *
  * Copyright 1998-2000, 2003 Linas Vepstas <linas at linas.org>        *
+ * Copyright (C) 2005 David Hampton <hampton at employees.org>         *
  * Copyright 2011-2015 John Ralls <jralls at ceridwen.us               *
  *                                                                  *
  * This program is free software; you can redistribute it and/or    *
@@ -1499,3 +1500,257 @@ gnc_date_load_funcs (void)
     tf->timespec_normalize = timespec_normalize;
     return tf;
 }
+
+/* ================================================= */
+
+gboolean
+gnc_gdate_equal(gconstpointer gda, gconstpointer gdb)
+{
+    return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE);
+}
+
+guint
+gnc_gdate_hash( gconstpointer gd )
+{
+    gint val = (g_date_get_year( (GDate*)gd ) * 10000)
+               + (g_date_get_month( (GDate*)gd ) * 100)
+               + g_date_get_day( (GDate*)gd );
+    return g_int_hash( &val );
+}
+
+/* ================================================= */
+
+time64
+gnc_time64_get_day_start_gdate (const GDate *date)
+{
+    struct tm stm;
+    time64 secs;
+
+    /* First convert to a 'struct tm' */
+    g_date_to_struct_tm (date, &stm);
+
+    /* Then convert to number of seconds */
+    secs = gnc_mktime (&stm);
+    return secs;
+}
+
+time64
+gnc_time64_get_day_end_gdate (const GDate *date)
+{
+    struct tm stm;
+    time64 secs;
+
+    /* First convert to a 'struct tm' */
+    g_date_to_struct_tm(date, &stm);
+
+    /* Force to th last second of the day */
+    stm.tm_hour = 23;
+    stm.tm_min = 59;
+    stm.tm_sec = 59;
+    stm.tm_isdst = -1;
+
+    /* Then convert to number of seconds */
+    secs = gnc_mktime (&stm);
+    return secs;
+}
+
+/* ================================================= */
+
+void
+gnc_gdate_set_month_start (GDate *date)
+{
+    g_date_set_day(date, 1);
+}
+
+/** Convert a GDate to the last day of the month.  This routine has no
+ *  knowledge of how many days are in a month, whether its a leap
+ *  year, etc.  All that information is contained in the glib date
+ *  functions.
+ *
+ *  @param date The GDate to modify.
+ */
+void
+gnc_gdate_set_month_end (GDate *date)
+{
+    /* First set the start of next month. */
+    g_date_set_day(date, 1);
+    g_date_add_months(date, 1);
+
+    /* Then back up one day */
+    g_date_subtract_days(date, 1);
+}
+
+/** Convert a GDate to the first day of the prebvious month.  This
+ *  routine has no knowledge of how many days are in a month, whether
+ *  its a leap year, etc.  All that information is contained in the
+ *  glib date functions.
+ *
+ *  @param date The GDate to modify.
+ */
+void
+gnc_gdate_set_prev_month_start (GDate *date)
+{
+    g_date_set_day(date, 1);
+    g_date_subtract_months(date, 1);
+}
+
+/** Convert a GDate to the last day of the prebvious month.  This
+ *  routine has no knowledge of how many days are in a month, whether
+ *  its a leap year, etc.  All that information is contained in the
+ *  glib date functions.
+ *
+ *  @param date The GDate to modify.
+ */
+void
+gnc_gdate_set_prev_month_end (GDate *date)
+{
+    /* This will correctly handle the varying month lengths */
+    g_date_set_day(date, 1);
+    g_date_subtract_days(date, 1);
+}
+
+/* ================================================= */
+
+void
+gnc_gdate_set_quarter_start (GDate *date)
+{
+    gint months;
+
+    /* Set the date to the first day of the specified month. */
+    g_date_set_day(date, 1);
+
+    /* Back up 0-2 months */
+    months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
+    g_date_subtract_months(date, months);
+}
+
+void
+gnc_gdate_set_quarter_end (GDate *date)
+{
+    gint months;
+
+    /* Set the date to the first day of the specified month. */
+    g_date_set_day(date, 1);
+
+    /* Add 1-3 months to get the first day of the next quarter.*/
+    months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
+    g_date_add_months(date, 3 - months);
+
+    /* Now back up one day */
+    g_date_subtract_days(date, 1);
+}
+
+void
+gnc_gdate_set_prev_quarter_start (GDate *date)
+{
+    gnc_gdate_set_quarter_start(date);
+    g_date_subtract_months(date, 3);
+}
+
+void
+gnc_gdate_set_prev_quarter_end (GDate *date)
+{
+    gnc_gdate_set_quarter_end(date);
+    g_date_subtract_months(date, 3);
+}
+
+/* ================================================= */
+
+void
+gnc_gdate_set_year_start (GDate *date)
+{
+    g_date_set_month(date, G_DATE_JANUARY);
+    g_date_set_day(date, 1);
+}
+
+void
+gnc_gdate_set_year_end (GDate *date)
+{
+    g_date_set_month(date, G_DATE_DECEMBER);
+    g_date_set_day(date, 31);
+}
+
+void
+gnc_gdate_set_prev_year_start (GDate *date)
+{
+    gnc_gdate_set_year_start(date);
+    g_date_subtract_years(date, 1);
+}
+
+void
+gnc_gdate_set_prev_year_end (GDate *date)
+{
+    gnc_gdate_set_year_end(date);
+    g_date_subtract_years(date, 1);
+}
+
+/* ================================================= */
+
+void
+gnc_gdate_set_fiscal_year_start (GDate *date,
+                                 const GDate *fy_end)
+{
+    GDate temp;
+    gboolean new_fy;
+
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
+
+    /* Compute the FY end that occurred this CY */
+    temp = *fy_end;
+    g_date_set_year(&temp, g_date_get_year(date));
+
+    /* Has it already passed? */
+    new_fy = (g_date_compare(date, &temp) > 0);
+
+    /* Set start date */
+    *date = temp;
+    g_date_add_days(date, 1);
+    if (!new_fy)
+        g_date_subtract_years(date, 1);
+}
+
+void
+gnc_gdate_set_fiscal_year_end (GDate *date,
+                               const GDate *fy_end)
+{
+    GDate temp;
+    gboolean new_fy;
+
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
+
+    /* Compute the FY end that occurred this CY */
+    temp = *fy_end;
+    g_date_set_year(&temp, g_date_get_year(date));
+
+    /* Has it already passed? */
+    new_fy = (g_date_compare(date, &temp) > 0);
+
+    /* Set end date */
+    *date = temp;
+    if (new_fy)
+        g_date_add_years(date, 1);
+}
+
+void
+gnc_gdate_set_prev_fiscal_year_start (GDate *date,
+                                      const GDate *fy_end)
+{
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
+
+    gnc_gdate_set_fiscal_year_start(date, fy_end);
+    g_date_subtract_years(date, 1);
+}
+
+void
+gnc_gdate_set_prev_fiscal_year_end (GDate *date,
+                                    const GDate *fy_end)
+{
+    g_return_if_fail(date);
+    g_return_if_fail(fy_end);
+
+    gnc_gdate_set_fiscal_year_end(date, fy_end);
+    g_date_subtract_years(date, 1);
+}
diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h
index 432a00e..aaff8d4 100644
--- a/libgnucash/engine/gnc-date.h
+++ b/libgnucash/engine/gnc-date.h
@@ -1,11 +1,12 @@
-/***************************************************************************
+/********************************************************************
  *            gnc-date.h (to be renamed qofdate.h)
  *
  *  Copyright (C) 1997 Robin D. Clark <rclark at cs.hmc.edu>
  *  Copyright (C) 1998-2000, 2003 Linas Vepstas <linas at linas.org>
  *  Copyright  2005  Neil Williams <linux at codehelp.co.uk>
+ *  Copyright (C) 2005 David Hampton <hampton at employees.org>
  *  Copyright 2012 John Ralls <jralls at ceridwen.us>
- ****************************************************************************/
+ ********************************************************************/
 /********************************************************************\
  * This program is free software; you can redistribute it and/or    *
  * modify it under the terms of the GNU General Public License as   *
@@ -54,7 +55,7 @@
     If a file-io backend needs date handling, it should do it itself,
     instead of depending on the routines here.
 
-	(to be renamed qofdate.h in libqof2.)
+    (to be renamed qofdate.h in libqof2.)
 
     @author Copyright (C) 1997 Robin D. Clark <rclark at cs.hmc.edu>
     @author Copyright (C) 1998-2001,2003 Linas Vepstas <linas at linas.org>
@@ -153,6 +154,7 @@ typedef enum
     GNCDATE_MONTH_ABBREV,
     GNCDATE_MONTH_NAME
 } GNCDateMonthFormat;
+
 /* Replacements for POSIX functions which use time_t. Time_t is still
  * 32 bits in Microsoft Windows, Apple OSX, and some BSD versions even
  * when the rest of the system is 64-bits, as well as all 32-bit
@@ -348,7 +350,6 @@ GDate timespec_to_gdate (Timespec ts);
 /** Turns a GDate into a Timespec, returning the first second of the day  */
 Timespec gdate_to_timespec (GDate d);
 
-
 /** Convert a day, month, and year to a Timespec, returning the first second of the day */
 Timespec gnc_dmy2timespec (gint day, gint month, gint year);
 
@@ -410,7 +411,8 @@ void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
 
 // @}
 
-/* ------------------------------------------------------------------------ */
+/* ======================================================== */
+
 /** \name QofDateFormat functions */
 // @{
 /** The qof_date_format_get routine returns the date format that
@@ -448,6 +450,8 @@ const gchar *qof_date_format_get_string(QofDateFormat df);
 const gchar *qof_date_text_format_get_string(QofDateFormat df);
 // @}
 
+/* ======================================================== */
+
 /**
  * The qof_date_completion_set() routing sets the date completion method to
  *    one of QOF_DATE_COMPLETION_THISYEAR (for completing the year to
@@ -467,6 +471,8 @@ void qof_date_completion_set(QofDateCompletion dc, int backmonths);
  */
 gchar dateSeparator(void);
 
+/* ======================================================== */
+
 /** \name Date Printing/Scanning functions
  */
 // @{
@@ -568,6 +574,9 @@ size_t qof_print_date_time_buff (char * buff, size_t len, time64 secs);
 gboolean qof_scan_date (const char *buff, int *day, int *month, int *year);
 
 // @}
+
+/* ======================================================== */
+
 /** \name Date Start/End Adjustment routines
  * Given a time value, adjust it to be the beginning or end of that day.
  */
@@ -665,6 +674,196 @@ char * gnc_date_timestamp (void);
 void gnc_dow_abbrev(gchar *buf, int buf_len, int dow);
 
 //@}
+
+/* ======================================================== */
+
+/** \name GDate hash table support */
+// @{
+
+/** Compares two GDate*'s for equality; useful for using GDate*'s as
+ *  GHashTable keys. */
+gint gnc_gdate_equal(gconstpointer gda, gconstpointer gdb);
+
+
+/** Provides a "hash" of a GDate* value; useful for using GDate*'s as
+ *  GHashTable keys. */
+guint gnc_gdate_hash( gconstpointer gd );
+
+//@}
+
+/* ======================================================== */
+
+/** \name GDate to time64 conversions */
+// @{
+
+/** The gnc_time64_get_day_start() routine will take the given time in
+ *  GLib GDate format and adjust it to the first second of that day.
+ */
+time64 gnc_time64_get_day_start_gdate (const GDate *date);
+
+/** The gnc_time64_get_day_end() routine will take the given time in
+ *  GLib GDate format and adjust it to the last second of that day.
+ */
+time64 gnc_time64_get_day_end_gdate (const GDate *date);
+
+//@}
+
+/* ======================================================== */
+
+/** \name Date Manipulation */
+// @{
+
+/** This function modifies a GDate to set it to the first day of the
+ *  month in which it falls.  For example, if this function is called
+ *  with a date of 2003-09-24 the date will be modified to 2003-09-01.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_month_start (GDate *date);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  month in which it falls.  For example, if this function is called
+ *  with a date of 2003-09-24 the date will be modified to 2003-09-30.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_month_end (GDate *date);
+
+
+/** This function modifies a GDate to set it to the first day of the
+ *  month prior to the one in which it falls.  For example, if this
+ *  function is called with a date of 2003-09-24 the date will be
+ *  modified to 2003-08-01.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_prev_month_start (GDate *date);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  month prior to the one in which it falls.  For example, if this
+ *  function is called with a date of 2003-09-24 the date will be
+ *  modified to 2003-08-31.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_prev_month_end (GDate *date);
+
+
+/** This function modifies a GDate to set it to the first day of the
+ *  quarter in which it falls.  For example, if this function is called
+ *  with a date of 2003-09-24 the date will be modified to 2003-09-01.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_quarter_start (GDate *date);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  quarter in which it falls.  For example, if this function is called
+ *  with a date of 2003-09-24 the date will be modified to 2003-12-31.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_quarter_end (GDate *date);
+
+
+/** This function modifies a GDate to set it to the first day of the
+ *  quarter prior to the one in which it falls.  For example, if this
+ *  function is called with a date of 2003-09-24 the date will be
+ *  modified to 2003-06-01.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_prev_quarter_start (GDate *date);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  quarter prior to the one in which it falls.  For example, if this
+ *  function is called with a date of 2003-09-24 the date will be
+ *  modified to 2003-07-31.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_prev_quarter_end (GDate *date);
+
+
+/** This function modifies a GDate to set it to the first day of the
+ *  year in which it falls.  For example, if this function is called
+ *  with a date of 2003-09-24 the date will be modified to 2003-01-01.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_year_start (GDate *date);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  year in which it falls.  For example, if this function is called
+ *  with a date of 2003-09-24 the date will be modified to 2003-12-31.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_year_end (GDate *date);
+
+
+/** This function modifies a GDate to set it to the first day of the
+ *  year prior to the one in which it falls.  For example, if this
+ *  function is called with a date of 2003-09-24 the date will be
+ *  modified to 2002-01-01.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_prev_year_start (GDate *date);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  year prior to the one in which it falls.  For example, if this
+ *  function is called with a date of 2003-09-24 the date will be
+ *  modified to 2002-12-31.
+ *
+ *  @param date The GDate to modify. */
+void gnc_gdate_set_prev_year_end (GDate *date);
+
+
+/** This function modifies a GDate to set it to the first day of the
+ *  fiscal year in which it falls.  For example, if this function is
+ *  called with a date of 2003-09-24 and a fiscal year ending July
+ *  31st, the date will be modified to 2003-08-01.
+ *
+ *  @param date The GDate to modify.
+ *
+ *  @param year_end A GDate containing the last month and day of the
+ *  fiscal year.  The year field of this argument is ignored. */
+void gnc_gdate_set_fiscal_year_start (GDate *date, const GDate *year_end);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  fiscal year in which it falls.  For example, if this function is
+ *  called with a date of 2003-09-24 and a fiscal year ending July
+ *  31st, the date will be modified to 2004-07-31.
+ *
+ *  @param date The GDate to modify.
+ *
+ *  @param year_end A GDate containing the last month and day of the
+ *  fiscal year.  The year field of this argument is ignored. */
+void gnc_gdate_set_fiscal_year_end (GDate *date, const GDate *year_end);
+
+
+/** This function modifies a GDate to set it to the first day of the
+ *  fiscal year prior to the one in which it falls.  For example, if
+ *  this function is called with a date of 2003-09-24 and a fiscal
+ *  year ending July 31st, the date will be modified to 2002-08-01.
+ *
+ *  @param date The GDate to modify.
+ *
+ *  @param year_end A GDate containing the last month and day of the
+ *  fiscal year.  The year field of this argument is ignored. */
+void gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end);
+
+
+/** This function modifies a GDate to set it to the last day of the
+ *  fiscal year prior to the one in which it falls.  For example, if
+ *  this function is called with a date of 2003-09-24 and a fiscal
+ *  year ending July 31st, the date will be modified to 2003-07-31.
+ *
+ *  @param date The GDate to modify.
+ *
+ *  @param year_end A GDate containing the last month and day of the
+ *  fiscal year.  The year field of this argument is ignored. */
+void gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end);
+
+//@}
+
 //@}
 #ifdef __cplusplus
 }
diff --git a/libgnucash/engine/gnc-gdate-utils.c b/libgnucash/engine/gnc-gdate-utils.c
deleted file mode 100644
index 014a0e2..0000000
--- a/libgnucash/engine/gnc-gdate-utils.c
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * gnc-gdate-utils.c -- utility functions for manipulating
- *              GDate data structures from GLib
- * Copyright (C) 2005 David Hampton <hampton at employees.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-#include "config.h"
-#include <glib.h>
-
-#include "gnc-gdate-utils.h"
-
-gboolean
-gnc_gdate_equal(gconstpointer gda, gconstpointer gdb)
-{
-    return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE);
-}
-
-guint
-gnc_gdate_hash( gconstpointer gd )
-{
-    gint val = (g_date_get_year( (GDate*)gd ) * 10000)
-               + (g_date_get_month( (GDate*)gd ) * 100)
-               + g_date_get_day( (GDate*)gd );
-    return g_int_hash( &val );
-}
-
-
-time64
-gnc_time64_get_day_start_gdate (const GDate *date)
-{
-    struct tm stm;
-    time64 secs;
-
-    /* First convert to a 'struct tm' */
-    g_date_to_struct_tm (date, &stm);
-
-    /* Then convert to number of seconds */
-    secs = gnc_mktime (&stm);
-    return secs;
-}
-
-time64
-gnc_time64_get_day_end_gdate (const GDate *date)
-{
-    struct tm stm;
-    time64 secs;
-
-    /* First convert to a 'struct tm' */
-    g_date_to_struct_tm(date, &stm);
-
-    /* Force to th last second of the day */
-    stm.tm_hour = 23;
-    stm.tm_min = 59;
-    stm.tm_sec = 59;
-    stm.tm_isdst = -1;
-
-    /* Then convert to number of seconds */
-    secs = gnc_mktime (&stm);
-    return secs;
-}
-
-
-void
-gnc_gdate_set_month_start (GDate *date)
-{
-    g_date_set_day(date, 1);
-}
-
-
-/** Convert a GDate to the last day of the month.  This routine has no
- *  knowledge of how many days are in a month, whether its a leap
- *  year, etc.  All that information is contained in the glib date
- *  functions.
- *
- *  @param date The GDate to modify.
- */
-void
-gnc_gdate_set_month_end (GDate *date)
-{
-    /* First set the start of next month. */
-    g_date_set_day(date, 1);
-    g_date_add_months(date, 1);
-
-    /* Then back up one day */
-    g_date_subtract_days(date, 1);
-}
-
-
-/** Convert a GDate to the first day of the prebvious month.  This
- *  routine has no knowledge of how many days are in a month, whether
- *  its a leap year, etc.  All that information is contained in the
- *  glib date functions.
- *
- *  @param date The GDate to modify.
- */
-void
-gnc_gdate_set_prev_month_start (GDate *date)
-{
-    g_date_set_day(date, 1);
-    g_date_subtract_months(date, 1);
-}
-
-
-/** Convert a GDate to the last day of the prebvious month.  This
- *  routine has no knowledge of how many days are in a month, whether
- *  its a leap year, etc.  All that information is contained in the
- *  glib date functions.
- *
- *  @param date The GDate to modify.
- */
-void
-gnc_gdate_set_prev_month_end (GDate *date)
-{
-    /* This will correctly handle the varying month lengths */
-    g_date_set_day(date, 1);
-    g_date_subtract_days(date, 1);
-}
-
-/* ========== */
-
-void
-gnc_gdate_set_quarter_start (GDate *date)
-{
-    gint months;
-
-    /* Set the date to the first day of the specified month. */
-    g_date_set_day(date, 1);
-
-    /* Back up 0-2 months */
-    months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
-    g_date_subtract_months(date, months);
-}
-
-
-void
-gnc_gdate_set_quarter_end (GDate *date)
-{
-    gint months;
-
-    /* Set the date to the first day of the specified month. */
-    g_date_set_day(date, 1);
-
-    /* Add 1-3 months to get the first day of the next quarter.*/
-    months = (g_date_get_month(date) - G_DATE_JANUARY) % 3;
-    g_date_add_months(date, 3 - months);
-
-    /* Now back up one day */
-    g_date_subtract_days(date, 1);
-}
-
-
-void
-gnc_gdate_set_prev_quarter_start (GDate *date)
-{
-    gnc_gdate_set_quarter_start(date);
-    g_date_subtract_months(date, 3);
-}
-
-
-void
-gnc_gdate_set_prev_quarter_end (GDate *date)
-{
-    gnc_gdate_set_quarter_end(date);
-    g_date_subtract_months(date, 3);
-}
-
-/* ========== */
-
-void
-gnc_gdate_set_year_start (GDate *date)
-{
-    g_date_set_month(date, G_DATE_JANUARY);
-    g_date_set_day(date, 1);
-}
-
-
-void
-gnc_gdate_set_year_end (GDate *date)
-{
-    g_date_set_month(date, G_DATE_DECEMBER);
-    g_date_set_day(date, 31);
-}
-
-
-void
-gnc_gdate_set_prev_year_start (GDate *date)
-{
-    gnc_gdate_set_year_start(date);
-    g_date_subtract_years(date, 1);
-}
-
-
-void
-gnc_gdate_set_prev_year_end (GDate *date)
-{
-    gnc_gdate_set_year_end(date);
-    g_date_subtract_years(date, 1);
-}
-
-/* ========== */
-
-void
-gnc_gdate_set_fiscal_year_start (GDate *date,
-                                 const GDate *fy_end)
-{
-    GDate temp;
-    gboolean new_fy;
-
-    g_return_if_fail(date);
-    g_return_if_fail(fy_end);
-
-    /* Compute the FY end that occurred this CY */
-    temp = *fy_end;
-    g_date_set_year(&temp, g_date_get_year(date));
-
-    /* Has it already passed? */
-    new_fy = (g_date_compare(date, &temp) > 0);
-
-    /* Set start date */
-    *date = temp;
-    g_date_add_days(date, 1);
-    if (!new_fy)
-        g_date_subtract_years(date, 1);
-}
-
-void
-gnc_gdate_set_fiscal_year_end (GDate *date,
-                               const GDate *fy_end)
-{
-    GDate temp;
-    gboolean new_fy;
-
-    g_return_if_fail(date);
-    g_return_if_fail(fy_end);
-
-    /* Compute the FY end that occurred this CY */
-    temp = *fy_end;
-    g_date_set_year(&temp, g_date_get_year(date));
-
-    /* Has it already passed? */
-    new_fy = (g_date_compare(date, &temp) > 0);
-
-    /* Set end date */
-    *date = temp;
-    if (new_fy)
-        g_date_add_years(date, 1);
-}
-
-void
-gnc_gdate_set_prev_fiscal_year_start (GDate *date,
-                                      const GDate *fy_end)
-{
-    g_return_if_fail(date);
-    g_return_if_fail(fy_end);
-
-    gnc_gdate_set_fiscal_year_start(date, fy_end);
-    g_date_subtract_years(date, 1);
-}
-
-void
-gnc_gdate_set_prev_fiscal_year_end (GDate *date,
-                                    const GDate *fy_end)
-{
-    g_return_if_fail(date);
-    g_return_if_fail(fy_end);
-
-    gnc_gdate_set_fiscal_year_end(date, fy_end);
-    g_date_subtract_years(date, 1);
-}
diff --git a/libgnucash/engine/gnc-gdate-utils.h b/libgnucash/engine/gnc-gdate-utils.h
deleted file mode 100644
index 3fd8830..0000000
--- a/libgnucash/engine/gnc-gdate-utils.h
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * gnc-gdate-utils.h -- utility functions for manipulating
- *              GDate data structures from GLib
- * Copyright (C) 2005 David Hampton <hampton at employees.org>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, contact:
- *
- * Free Software Foundation           Voice:  +1-617-542-5942
- * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
- * Boston, MA  02110-1301,  USA       gnu at gnu.org
- */
-
-/** @addtogroup GLib
-    @{ */
-/** @addtogroup GDate GDate Utilities
-
-    This file provides routines that help make it easier to use GDates
-    from within Gnucash.  A GDate is a data strucutre provided by GLib
-    that handles dates from year 1 to year 9999.
-
-    @{ */
-/** @file gnc-gdate-utils.h
- *  @brief GDate helper routines.
- *  @author Copyright (C) 2005 David Hampton <hampton at employees.org>
- */
-
-#ifndef GNC_GDATE_UTILS_H
-#define GNC_GDATE_UTILS_H
-
-#include <gnc-date.h>
-
-/** @name GDate hash table support
-    @{ */
-
-/** Compares two GDate*'s for equality; useful for using GDate*'s as
- *  GHashTable keys. */
-gint gnc_gdate_equal(gconstpointer gda, gconstpointer gdb);
-
-
-/** Provides a "hash" of a GDate* value; useful for using GDate*'s as
- *  GHashTable keys. */
-guint gnc_gdate_hash( gconstpointer gd );
-
-/** @} */
-
-/** @name GDate to time64 conversions
-    @{ */
-
-/** The gnc_time64_get_day_start() routine will take the given time in
- *  GLib GDate format and adjust it to the first second of that day.
- */
-time64 gnc_time64_get_day_start_gdate (const GDate *date);
-
-/** The gnc_time64_get_day_end() routine will take the given time in
- *  GLib GDate format and adjust it to the last second of that day.
- */
-time64 gnc_time64_get_day_end_gdate (const GDate *date);
-
-/** @} */
-
-/** @name Date Manipulation
-    @{ */
-
-/** This function modifies a GDate to set it to the first day of the
- *  month in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-09-01.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_month_start (GDate *date);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  month in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-09-30.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_month_end (GDate *date);
-
-
-/** This function modifies a GDate to set it to the first day of the
- *  month prior to the one in which it falls.  For example, if this
- *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2003-08-01.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_prev_month_start (GDate *date);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  month prior to the one in which it falls.  For example, if this
- *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2003-08-31.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_prev_month_end (GDate *date);
-
-
-/** This function modifies a GDate to set it to the first day of the
- *  quarter in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-09-01.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_quarter_start (GDate *date);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  quarter in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-12-31.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_quarter_end (GDate *date);
-
-
-/** This function modifies a GDate to set it to the first day of the
- *  quarter prior to the one in which it falls.  For example, if this
- *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2003-06-01.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_prev_quarter_start (GDate *date);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  quarter prior to the one in which it falls.  For example, if this
- *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2003-07-31.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_prev_quarter_end (GDate *date);
-
-
-/** This function modifies a GDate to set it to the first day of the
- *  year in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-01-01.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_year_start (GDate *date);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  year in which it falls.  For example, if this function is called
- *  with a date of 2003-09-24 the date will be modified to 2003-12-31.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_year_end (GDate *date);
-
-
-/** This function modifies a GDate to set it to the first day of the
- *  year prior to the one in which it falls.  For example, if this
- *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2002-01-01.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_prev_year_start (GDate *date);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  year prior to the one in which it falls.  For example, if this
- *  function is called with a date of 2003-09-24 the date will be
- *  modified to 2002-12-31.
- *
- *  @param date The GDate to modify. */
-void gnc_gdate_set_prev_year_end (GDate *date);
-
-
-/** This function modifies a GDate to set it to the first day of the
- *  fiscal year in which it falls.  For example, if this function is
- *  called with a date of 2003-09-24 and a fiscal year ending July
- *  31st, the date will be modified to 2003-08-01.
- *
- *  @param date The GDate to modify.
- *
- *  @param year_end A GDate containing the last month and day of the
- *  fiscal year.  The year field of this argument is ignored. */
-void gnc_gdate_set_fiscal_year_start (GDate *date, const GDate *year_end);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  fiscal year in which it falls.  For example, if this function is
- *  called with a date of 2003-09-24 and a fiscal year ending July
- *  31st, the date will be modified to 2004-07-31.
- *
- *  @param date The GDate to modify.
- *
- *  @param year_end A GDate containing the last month and day of the
- *  fiscal year.  The year field of this argument is ignored. */
-void gnc_gdate_set_fiscal_year_end (GDate *date, const GDate *year_end);
-
-
-/** This function modifies a GDate to set it to the first day of the
- *  fiscal year prior to the one in which it falls.  For example, if
- *  this function is called with a date of 2003-09-24 and a fiscal
- *  year ending July 31st, the date will be modified to 2002-08-01.
- *
- *  @param date The GDate to modify.
- *
- *  @param year_end A GDate containing the last month and day of the
- *  fiscal year.  The year field of this argument is ignored. */
-void gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end);
-
-
-/** This function modifies a GDate to set it to the last day of the
- *  fiscal year prior to the one in which it falls.  For example, if
- *  this function is called with a date of 2003-09-24 and a fiscal
- *  year ending July 31st, the date will be modified to 2003-07-31.
- *
- *  @param date The GDate to modify.
- *
- *  @param year_end A GDate containing the last month and day of the
- *  fiscal year.  The year field of this argument is ignored. */
-void gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end);
-
-/** @} */
-
-#endif /* GNC_GDATE_UTILS_H */
-/** @} */
-/** @} */
diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index 32fcd31..bd4653c 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -26,9 +26,9 @@
 
 #include <glib.h>
 #include <string.h>
+#include "gnc-date.h"
 #include "gnc-pricedb-p.h"
 #include <qofinstance-p.h>
-#include "gnc-gdate-utils.h"
 
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_PRICE;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8068953..51e94f5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -486,7 +486,6 @@ libgnucash/app-utils/gnc-component-manager.c
 libgnucash/app-utils/gnc-entry-quickfill.c
 libgnucash/app-utils/gnc-euro.c
 libgnucash/app-utils/gnc-exp-parser.c
-libgnucash/app-utils/gnc-gdate-utils.c
 libgnucash/app-utils/gnc-gettext-util.c
 libgnucash/app-utils/gnc-gsettings.c
 libgnucash/app-utils/gnc-helpers.c

commit b485206378625c80962063fba49017eefef67dc0
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:58:21 2017 +0100

    Change tabs to spaces and remove some blank lines

diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index 9fe89ee..1e88c32 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -116,8 +116,8 @@ gnc_localtime (const time64 *secs)
     auto time = static_cast<struct tm*>(calloc(1, sizeof(struct tm)));
     if (gnc_localtime_r (secs, time) == NULL)
     {
-	gnc_tm_free (time);
-	return NULL;
+        gnc_tm_free (time);
+        return NULL;
     }
     return time;
 }
@@ -127,12 +127,12 @@ gnc_localtime_r (const time64 *secs, struct tm* time)
 {
     try
     {
-	*time = static_cast<struct tm>(GncDateTime(*secs));
-	return time;
+        *time = static_cast<struct tm>(GncDateTime(*secs));
+        return time;
     }
     catch(std::invalid_argument)
     {
-	return NULL;
+        return NULL;
     }
 }
 
@@ -199,14 +199,14 @@ gnc_gmtime (const time64 *secs)
 {
     try
     {
-	auto time = static_cast<struct tm*>(calloc(1, sizeof(struct tm)));
-	GncDateTime gncdt(*secs);
-	*time = gncdt.utc_tm();
-	return time;
+        auto time = static_cast<struct tm*>(calloc(1, sizeof(struct tm)));
+        GncDateTime gncdt(*secs);
+        *time = gncdt.utc_tm();
+        return time;
     }
     catch(std::invalid_argument)
     {
-	return NULL;
+        return NULL;
     }
 
 }
@@ -216,13 +216,13 @@ gnc_mktime (struct tm* time)
 {
     try
     {
-	normalize_struct_tm (time);
-	GncDateTime gncdt(*time);
-	return static_cast<time64>(gncdt) - gncdt.offset();
+        normalize_struct_tm (time);
+        GncDateTime gncdt(*time);
+        return static_cast<time64>(gncdt) - gncdt.offset();
     }
     catch(std::invalid_argument)
     {
-	return 0;
+        return 0;
     }
 }
 
@@ -231,12 +231,12 @@ gnc_timegm (struct tm* time)
 {
     try
     {
-	normalize_struct_tm(time);
-	return static_cast<time64>(GncDateTime(*time));
+        normalize_struct_tm(time);
+        return static_cast<time64>(GncDateTime(*time));
     }
     catch(std::invalid_argument)
     {
-	return 0;
+        return 0;
     }
 }
 
@@ -259,12 +259,11 @@ gnc_time (time64 *tbuf)
 gdouble
 gnc_difftime (const time64 secs1, const time64 secs2)
 {
-     return (double)secs1 - (double)secs2;
+    return (double)secs1 - (double)secs2;
 }
 
 /****************************************************************************/
 
-
 const char*
 gnc_date_dateformat_to_string(QofDateFormat format)
 {
@@ -319,7 +318,6 @@ gnc_date_string_to_dateformat(const char* fmt_str, QofDateFormat *format)
     return FALSE;
 }
 
-
 const char*
 gnc_date_monthformat_to_string(GNCDateMonthFormat format)
 {
@@ -411,7 +409,6 @@ timespec_normalize(Timespec *t)
     return;
 }
 
-
 gboolean
 timespec_equal (const Timespec *ta, const Timespec *tb)
 {
@@ -738,14 +735,14 @@ floordiv(int a, int b)
 
     Fully formatted UTC timestamp strings are converted separately.
 
-param   buff - pointer to date string
-param     day -  will store day of the month as 1 ... 31
-param     month - will store month of the year as 1 ... 12
-param     year - will store the year (4-digit)
+    param   buff - pointer to date string
+    param     day -  will store day of the month as 1 ... 31
+    param     month - will store month of the year as 1 ... 12
+    param     year - will store the year (4-digit)
 
-return TRUE if date appeared to be valid.
+    return TRUE if date appeared to be valid.
 
- Globals: global dateFormat value
+    Globals: global dateFormat value
 */
 static gboolean
 qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
@@ -1045,7 +1042,6 @@ char dateSeparator (void)
         }
         break;
     }
-
     return '\0';
 }
 
@@ -1179,7 +1175,6 @@ qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
     return retval;
 }
 
-
 /********************************************************************\
 \********************************************************************/
 
@@ -1248,7 +1243,6 @@ gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
         PWARN("Error processing time64 %" PRId64 ": %s", ts.tv_sec, err.what());
         return buff;
     }
-
 }
 
 void
@@ -1287,7 +1281,6 @@ gnc_dmy2timespec_internal (int day, int month, int year, DayPart day_part)
     }
 }
 
-
 Timespec
 gnc_dmy2timespec (int day, int month, int year)
 {
@@ -1371,11 +1364,8 @@ gnc_gdate_set_time64 (GDate* gd, time64 time)
     g_date_set_dmy (gd, tm.tm_mday,
                     static_cast<GDateMonth>(tm.tm_mon + 1),
                     tm.tm_year + 1900);
-
 }
 
-
-
 Timespec gdate_to_timespec (GDate d)
 {
     return gnc_dmy2timespec_neutral (g_date_get_day(&d),
@@ -1423,7 +1413,6 @@ gnc_time64_get_day_end (time64 time_val)
     return new_time;
 }
 
-
 /* ======================================================== */
 
 void
@@ -1500,7 +1489,6 @@ timespec_get_type( void )
                                              timespec_boxed_copy_func,
                                              timespec_boxed_free_func );
     }
-
     return type;
 }
 

commit 047bc8d69b454633b6448a8ab0fea2084ffd27bd
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:56:07 2017 +0100

    Rename gnc_pricedb_remove_old_prices_keep_last
    
    Rename gnc_pricedb_remove_old_prices_keep_last to reflect that there is
    an option to keep none so new name is gnc_pricedb_process_removal_list

diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index d650716..32fcd31 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -1317,7 +1317,7 @@ check_one_price_date (GNCPrice *price, gpointer user_data)
           user_data);
 
     source = gnc_price_get_source (price);
-        
+
     if ((source == PRICE_SOURCE_FQ) && data->delete_fq)
         PINFO ("Delete Quote Source");
     else if ((source == PRICE_SOURCE_USER_PRICE) && data->delete_user)
@@ -1484,8 +1484,8 @@ get_fiscal_quarter (GDate *date, GDateMonth fiscal_start)
 }
 
 static void
-gnc_pricedb_remove_old_prices_keep_last (GNCPriceDB *db, GDate *fiscal_end_date,
-                                         remove_info data, PriceRemoveKeepOptions keep)
+gnc_pricedb_process_removal_list (GNCPriceDB *db, GDate *fiscal_end_date,
+                                  remove_info data, PriceRemoveKeepOptions keep)
 {
     GSList *item;
     gboolean save_first_price = FALSE;
@@ -1637,7 +1637,7 @@ gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list,
     DEBUG("Number of Prices in list is %d, Cutoff date is %s", g_slist_length (data.list), gnc_print_date (cutoff));
 
     // Check for a valid fiscal end of year date
-    if (fiscal_end_date == NULL )
+    if (fiscal_end_date == NULL)
     {
         GDateYear year_now = g_date_get_year (gnc_g_date_new_today ());
         fiscal_end_date = g_date_new ();
@@ -1649,7 +1649,7 @@ gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list,
         g_date_clear (fiscal_end_date, 1);
         g_date_set_dmy (fiscal_end_date, 31, 12, year_now);
     }
-    gnc_pricedb_remove_old_prices_keep_last (db, fiscal_end_date, data, keep);
+    gnc_pricedb_process_removal_list (db, fiscal_end_date, data, keep);
 
     g_slist_free (data.list);
     LEAVE(" ");

commit a7abc312a934666134e344d90cab913afdd78d25
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:55:23 2017 +0100

    Rename save_cloned_price to clone_price
    
    Renamed save_clone_price to clone_price and changed to pass the address
    of the cloned_price variable instead of returning it.

diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index 3450417..d650716 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -1439,20 +1439,22 @@ gnc_pricedb_remove_old_prices_pinfo (GNCPrice *price, gboolean keep_message)
         PINFO("Keep price date is invalid");
 }
 
-static GNCPrice*
-save_cloned_price (GNCPrice *price, GNCPrice *clone_price)
+static void
+clone_price (GNCPrice **price, GNCPrice *source_price)
 {
-    QofBook *book = qof_instance_get_book (QOF_INSTANCE(clone_price));
-    GNCPrice *cloned_price;
+    QofBook *book;
+
+    if (!source_price) return;
+    if (price == NULL) return;
 
-    if (price)
-        gnc_price_unref (price);
+    book = qof_instance_get_book (QOF_INSTANCE(source_price));
 
-    cloned_price = gnc_price_clone (clone_price, book);
+    if (*price)
+        gnc_price_unref (*price);
 
-    gnc_pricedb_remove_old_prices_pinfo (clone_price, TRUE);
+    *price = gnc_price_clone (source_price, book);
 
-    return cloned_price;
+    gnc_pricedb_remove_old_prices_pinfo (source_price, TRUE);
 }
 
 static gint
@@ -1488,7 +1490,7 @@ gnc_pricedb_remove_old_prices_keep_last (GNCPriceDB *db, GDate *fiscal_end_date,
     GSList *item;
     gboolean save_first_price = FALSE;
     gint saved_test_value = 0, next_test_value = 0;
-    GNCPrice *saved_price = NULL;
+    GNCPrice *cloned_price = NULL;
     GDateMonth fiscal_month_end = g_date_get_month (fiscal_end_date);
     GDateMonth fiscal_month_start;
     GDate *tmp_date = g_date_new_dmy (g_date_get_day (fiscal_end_date),
@@ -1517,16 +1519,16 @@ gnc_pricedb_remove_old_prices_keep_last (GNCPriceDB *db, GDate *fiscal_end_date,
             continue;
         }
 
-        save_first_price = !price_commodity_and_currency_equal (item->data, saved_price); // Not Equal
+        save_first_price = !price_commodity_and_currency_equal (item->data, cloned_price); // Not Equal
         if (save_first_price == TRUE)
         {
-            saved_price = save_cloned_price (saved_price, item->data);
+            clone_price (&cloned_price, item->data);
             save_first_price = FALSE;
             continue;
         }
 
         // get the price dates
-        saved_price_date = timespec_to_gdate (gnc_price_get_time (saved_price));
+        saved_price_date = timespec_to_gdate (gnc_price_get_time (cloned_price));
         next_price_date = timespec_to_gdate (gnc_price_get_time (item->data));
 
         // Keep last price in fiscal year
@@ -1586,10 +1588,10 @@ gnc_pricedb_remove_old_prices_keep_last (GNCPriceDB *db, GDate *fiscal_end_date,
             gnc_pricedb_remove_price (db, item->data);
         }
         else
-            saved_price = save_cloned_price (saved_price, item->data);
+            clone_price (&cloned_price, item->data);
     }
-    if (saved_price)
-        gnc_price_unref (saved_price);
+    if (cloned_price)
+        gnc_price_unref (cloned_price);
 }
 
 gboolean

commit 89dbc094106ebf5320c62fa6469529d8b66dfee6
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:54:48 2017 +0100

    Added second if clause for completeness.

diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index 3a90571..3450417 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -1376,6 +1376,7 @@ compare_prices_by_commodity_date (gconstpointer a, gconstpointer b)
     if (!a && !b) return 0;
     /* nothing is always less than something */
     if (!a) return -1;
+    if (!b) return 1;
 
     comma = gnc_price_get_commodity ((GNCPrice *) a);
     commb = gnc_price_get_commodity ((GNCPrice *) b);

commit e1d4075273feea5b86f05c65228784b43ec272e7
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:54:14 2017 +0100

    Remove the 'if else' blocks by using boolean variable.

diff --git a/gnucash/gnome/dialog-price-edit-db.c b/gnucash/gnome/dialog-price-edit-db.c
index a46c89e..78369d1 100644
--- a/gnucash/gnome/dialog-price-edit-db.c
+++ b/gnucash/gnome/dialog-price-edit-db.c
@@ -310,12 +310,13 @@ gnc_prices_dialog_get_commodities (GtkTreeView *view)
 
     return comm_list;
 }
- 
+
 static void
 change_source_flag (PriceRemoveSourceFlags source, gboolean set, gpointer data)
 {
     PricesDialog *pdb_dialog = data;
     GtkWidget *w = gtk_dialog_get_widget_for_response (GTK_DIALOG(pdb_dialog->remove_dialog), GTK_RESPONSE_OK);
+    gboolean enable_button;
 
     if (set)
         pdb_dialog->remove_source = pdb_dialog->remove_source | source;
@@ -323,10 +324,8 @@ change_source_flag (PriceRemoveSourceFlags source, gboolean set, gpointer data)
         pdb_dialog->remove_source = pdb_dialog->remove_source & (~source);
 
     // Check if we have the required options to enable OK button
-    if (pdb_dialog->remove_source > 8) // commodities flag is 8
-        gtk_widget_set_sensitive (w, TRUE);
-    else
-        gtk_widget_set_sensitive (w, FALSE);
+    enable_button = (pdb_dialog->remove_source > 8 ? TRUE : FALSE); // commodities flag is 8
+    gtk_widget_set_sensitive (w, enable_button);
 
     DEBUG("Source is: %d, remove_source is %d", source, pdb_dialog->remove_source);
 }
@@ -335,33 +334,27 @@ static void
 check_event_fq_cb (GtkWidget *widget, gpointer data)
 {
     PricesDialog *pdb_dialog = data;
+    gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
 
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
-        change_source_flag (PRICE_REMOVE_SOURCE_FQ, TRUE, pdb_dialog);
-    else
-        change_source_flag (PRICE_REMOVE_SOURCE_FQ, FALSE, pdb_dialog);
+    change_source_flag (PRICE_REMOVE_SOURCE_FQ, active, pdb_dialog);
 }
 
 static void
 check_event_user_cb (GtkWidget *widget, gpointer data)
 {
     PricesDialog *pdb_dialog = data;
+    gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
 
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
-        change_source_flag (PRICE_REMOVE_SOURCE_USER, TRUE, pdb_dialog);
-    else
-        change_source_flag (PRICE_REMOVE_SOURCE_USER, FALSE, pdb_dialog);
+    change_source_flag (PRICE_REMOVE_SOURCE_USER, active, pdb_dialog);
 }
 
 static void
 check_event_app_cb (GtkWidget *widget, gpointer data)
 {
     PricesDialog *pdb_dialog = data;
+    gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
 
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
-        change_source_flag (PRICE_REMOVE_SOURCE_APP, TRUE, pdb_dialog);
-    else
-        change_source_flag (PRICE_REMOVE_SOURCE_APP, FALSE, pdb_dialog);
+    change_source_flag (PRICE_REMOVE_SOURCE_APP, active, pdb_dialog);
 }
 
 static void
@@ -370,11 +363,9 @@ selection_changed_cb (GtkTreeSelection *selection, gpointer data)
     PricesDialog *pdb_dialog = data;
     GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->remove_view));
     GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
+    gboolean have_rows = (g_list_length (rows) > 0 ? TRUE : FALSE);
 
-    if (g_list_length (rows) > 0)
-        change_source_flag (PRICE_REMOVE_SOURCE_COMM, TRUE, pdb_dialog);
-    else
-        change_source_flag (PRICE_REMOVE_SOURCE_COMM, FALSE, pdb_dialog);
+    change_source_flag (PRICE_REMOVE_SOURCE_COMM, have_rows, pdb_dialog);
 }
 
 static GDate
@@ -465,7 +456,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
         {
             Timespec last_ts;
             GDate fiscal_end_date = get_fiscal_end_date ();
-            PriceRemoveSourceFlags source = PRICE_REMOVE_SOURCE_FQ; 
+            PriceRemoveSourceFlags source = PRICE_REMOVE_SOURCE_FQ;
             PriceRemoveKeepOptions keep = PRICE_REMOVE_KEEP_NONE;
 
             DEBUG("deleting prices");
@@ -497,7 +488,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
                 GDate tmp_date = timespec_to_gdate (last_ts);
                 g_date_subtract_months (&tmp_date, 6);
                 tmp_ts = gdate_to_timespec (tmp_date);
- 
+
                 gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date, tmp_ts,
                                                pdb_dialog->remove_source, PRICE_REMOVE_KEEP_LAST_WEEKLY);
 

commit f16f2022046ac57113c6dd742cb0c5dec89edcd6
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:53:24 2017 +0100

    Rename function to be plural as more than one commodity returned in list

diff --git a/gnucash/gnome/dialog-price-edit-db.c b/gnucash/gnome/dialog-price-edit-db.c
index ba5d5a7..a46c89e 100644
--- a/gnucash/gnome/dialog-price-edit-db.c
+++ b/gnucash/gnome/dialog-price-edit-db.c
@@ -286,7 +286,7 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
 }
 
 static GList *
-gnc_prices_dialog_get_commodity (GtkTreeView *view)
+gnc_prices_dialog_get_commodities (GtkTreeView *view)
 {
     GtkTreeModel     *model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
     GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
@@ -458,7 +458,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
     if (result == GTK_RESPONSE_OK)
     {
         const char *fmt = _("Are you sure you want to delete these prices ?");
-        GList *comm_list = gnc_prices_dialog_get_commodity (pdb_dialog->remove_view);
+        GList *comm_list = gnc_prices_dialog_get_commodities (pdb_dialog->remove_view);
 
         // Are you sure you want to delete the entries and we have commodities
         if ((g_list_length (comm_list) != 0) && (gnc_verify_dialog (pdb_dialog->remove_dialog, FALSE, fmt, NULL)))

commit c3466b79ef5d443d1359f3d40b8cada07487f28c
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Aug 20 09:56:53 2017 +0100

    Move gnc-gdate-utils.c/h from app-utils to engine

diff --git a/libgnucash/app-utils/CMakeLists.txt b/libgnucash/app-utils/CMakeLists.txt
index 3ceaf39..94e1da8 100644
--- a/libgnucash/app-utils/CMakeLists.txt
+++ b/libgnucash/app-utils/CMakeLists.txt
@@ -22,7 +22,6 @@ SET (app_utils_HEADERS
   gnc-entry-quickfill.h
   gnc-euro.h
   gnc-exp-parser.h
-  gnc-gdate-utils.h
   gnc-gettext-util.h
   gnc-gsettings.h
   gnc-help-utils.h
@@ -64,7 +63,6 @@ SET (app_utils_SOURCES
   gnc-entry-quickfill.c
   gnc-euro.c
   gnc-exp-parser.c
-  gnc-gdate-utils.c
   gnc-gettext-util.c
   gnc-gsettings.c
   gnc-helpers.c
diff --git a/libgnucash/app-utils/Makefile.am b/libgnucash/app-utils/Makefile.am
index a30b8a8..6296bb2 100644
--- a/libgnucash/app-utils/Makefile.am
+++ b/libgnucash/app-utils/Makefile.am
@@ -51,7 +51,6 @@ libgncmod_app_utils_la_SOURCES = \
   gnc-entry-quickfill.c \
   gnc-euro.c \
   gnc-exp-parser.c \
-  gnc-gdate-utils.c \
   gnc-gettext-util.c \
   gnc-gsettings.c \
   gnc-helpers.c \
@@ -79,7 +78,6 @@ gncinclude_HEADERS = \
   gnc-entry-quickfill.h \
   gnc-euro.h \
   gnc-exp-parser.h \
-  gnc-gdate-utils.h \
   gnc-gettext-util.h \
   gnc-gsettings.h \
   gnc-help-utils.h \
diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt
index 041ef20..b6d92d1 100644
--- a/libgnucash/engine/CMakeLists.txt
+++ b/libgnucash/engine/CMakeLists.txt
@@ -54,6 +54,7 @@ SET (engine_HEADERS
   gnc-engine.h
   gnc-event.h
   gnc-features.h
+  gnc-gdate-utils.h
   gnc-hooks.h
   gnc-numeric.h
   gnc-numeric.hpp
@@ -159,6 +160,7 @@ SET (engine_SOURCES
   gnc-engine.c
   gnc-event.c
   gnc-features.c
+  gnc-gdate-utils.c
   gnc-hooks.c
   gnc-int128.cpp
   gnc-lot.c
diff --git a/libgnucash/engine/Makefile.am b/libgnucash/engine/Makefile.am
index 4943aef..56677e1 100644
--- a/libgnucash/engine/Makefile.am
+++ b/libgnucash/engine/Makefile.am
@@ -40,6 +40,7 @@ libgncmod_engine_la_SOURCES = \
   gnc-engine.c \
   gnc-event.c \
   gnc-features.c \
+  gnc-gdate-utils.c \
   gnc-hooks.c \
   gnc-int128.cpp \
   gnc-lot.c \
@@ -124,6 +125,7 @@ gncinclude_HEADERS = \
   gnc-engine.h \
   gnc-event.h \
   gnc-features.h \
+  gnc-gdate-utils.h \
   gnc-hooks.h \
   gnc-numeric.h \
   gnc-numeric.hpp \
diff --git a/libgnucash/app-utils/gnc-gdate-utils.c b/libgnucash/engine/gnc-gdate-utils.c
similarity index 100%
rename from libgnucash/app-utils/gnc-gdate-utils.c
rename to libgnucash/engine/gnc-gdate-utils.c
diff --git a/libgnucash/app-utils/gnc-gdate-utils.h b/libgnucash/engine/gnc-gdate-utils.h
similarity index 100%
rename from libgnucash/app-utils/gnc-gdate-utils.h
rename to libgnucash/engine/gnc-gdate-utils.h

commit 576b1d077ca7872fd62b2fb8f8703ead2e411f59
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Aug 10 15:12:38 2017 +0100

    Fix some missing id's in the glade file

diff --git a/gnucash/gnome/gtkbuilder/dialog-price.glade b/gnucash/gnome/gtkbuilder/dialog-price.glade
index 8da9197..cbf5c51 100644
--- a/gnucash/gnome/gtkbuilder/dialog-price.glade
+++ b/gnucash/gnome/gtkbuilder/dialog-price.glade
@@ -304,7 +304,7 @@
                 <property name="entry_text_column">0</property>
                 <signal name="changed" handler="pedit_commodity_ns_changed_cb" swapped="no"/>
                 <child internal-child="entry">
-                  <object class="GtkEntry">
+                  <object class="GtkEntry" id="combobox-entry3">
                     <property name="can_focus">False</property>
                   </object>
                 </child>
@@ -323,7 +323,7 @@
                 <property name="entry_text_column">0</property>
                 <signal name="changed" handler="pedit_commodity_changed_cb" swapped="no"/>
                 <child internal-child="entry">
-                  <object class="GtkEntry">
+                  <object class="GtkEntry" id="combobox-entry2">
                     <property name="can_focus">False</property>
                   </object>
                 </child>
@@ -565,7 +565,7 @@
                         <property name="can_focus">True</property>
                         <property name="model">liststore4</property>
                         <child internal-child="selection">
-                          <object class="GtkTreeSelection"/>
+                          <object class="GtkTreeSelection" id="selection1"/>
                         </child>
                         <child>
                           <object class="GtkTreeViewColumn" id="name_column">

commit 42915a42d12beea78d58917ea00ae3ac32782c75
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Aug 10 14:03:05 2017 +0100

    Modify the unit tests to reflect changes.

diff --git a/libgnucash/engine/test/utest-gnc-pricedb.c b/libgnucash/engine/test/utest-gnc-pricedb.c
index b8f5d85..8d92c01 100644
--- a/libgnucash/engine/test/utest-gnc-pricedb.c
+++ b/libgnucash/engine/test/utest-gnc-pricedb.c
@@ -1,5 +1,5 @@
 /********************************************************************
- * utest-gnc-pricedb.c: GLib g_test test suite for gnc-pricedb.c.		    *
+ * utest-gnc-pricedb.c: GLib g_test test suite for gnc-pricedb.c.   *
  * Copyright 2015 John Ralls <jralls at ceridwen.us>		    *
  *                                                                  *
  * This program is free software; you can redistribute it and/or    *
@@ -416,6 +416,10 @@ create_some_prices (PriceDBFixture *fixture)
                                               PRICE_SOURCE_FQ,
                                             gnc_numeric_create(131190, 10000)));
     gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
+                                              gnc_dmy2timespec(12, 4, 2009),
+                                              PRICE_SOURCE_USER_PRICE,
+                                            gnc_numeric_create(131190, 10000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
                                               gnc_dmy2timespec(21, 8, 2010),
                                               PRICE_SOURCE_FQ,
                                             gnc_numeric_create(111794, 10000)));
@@ -539,6 +543,42 @@ create_some_prices (PriceDBFixture *fixture)
                                               gnc_dmy2timespec(12, 11, 2014),
                                               PRICE_SOURCE_FQ,
                                               gnc_numeric_create(31151, 100)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(12, 05, 2007),
+                                              PRICE_SOURCE_USER_PRICE,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(12, 05, 2008),
+                                              PRICE_SOURCE_FQ,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(13, 05, 2008),
+                                              PRICE_SOURCE_USER_PRICE,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(14, 05, 2008),
+                                              PRICE_SOURCE_USER_PRICE,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(19, 05, 2008),
+                                              PRICE_SOURCE_FQ,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(22, 05, 2008),
+                                              PRICE_SOURCE_FQ,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(12, 06, 2008),
+                                              PRICE_SOURCE_FQ,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(12, 07, 2008),
+                                              PRICE_SOURCE_FQ,
+                                              gnc_numeric_create(126836, 100000)));
+    gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
+                                              gnc_dmy2timespec(12, 11, 2008),
+                                              PRICE_SOURCE_FQ,
+                                              gnc_numeric_create(126836, 100000)));
     gnc_pricedb_set_bulk_update(db, FALSE);
 }
 
@@ -650,7 +690,7 @@ static void
 test_gnc_pricedb_get_num_prices (PriceDBFixture *fixture, gconstpointer pData)
 {
     int num = gnc_pricedb_get_num_prices(fixture->pricedb);
-    g_assert_cmpint(num, ==, 32);
+    g_assert_cmpint(num, ==, 42);
 }
 /* pricedb_equal_foreach_pricelist
 static void
@@ -743,11 +783,72 @@ gnc_pricedb_remove_old_prices(GNCPriceDB *db,// C: 1  Local: 0:0:0
 */
 static void test_gnc_pricedb_remove_old_prices (PriceDBFixture *fixture, gconstpointer pData)
 {
-    Timespec t = gnc_dmy2timespec(1, 1, 2013);
-    g_assert(gnc_pricedb_remove_old_prices(fixture->pricedb, t, FALSE, FALSE));
-    g_assert_cmpint(gnc_pricedb_get_num_prices(fixture->pricedb), ==, 11);
-    g_assert(gnc_pricedb_remove_old_prices(fixture->pricedb, t, FALSE, TRUE));
-    g_assert_cmpint(gnc_pricedb_get_num_prices(fixture->pricedb), ==, 10);
+    GList *comm_list = NULL;
+    Commodities *c = fixture->com;
+    PriceRemoveSourceFlags source_all = PRICE_REMOVE_SOURCE_FQ |
+                                        PRICE_REMOVE_SOURCE_USER |
+                                        PRICE_REMOVE_SOURCE_APP;
+
+    Timespec t_cut = gnc_dmy2timespec(1, 1, 2008);
+    Timespec t_cut1 = gnc_dmy2timespec(1, 1, 2009);
+    Timespec t_cut2 = gnc_dmy2timespec(1, 1, 2010);
+
+    GDate *fiscal_end_date = g_date_new ();
+    g_date_set_dmy (fiscal_end_date, 31, 12, 2017);
+
+    comm_list = g_list_append (comm_list, c->usd);
+    comm_list = g_list_append (comm_list, c->gbp);
+
+    g_assert_cmpint (gnc_pricedb_num_prices(fixture->pricedb, c->gbp), ==, 23);
+    g_assert_cmpint (gnc_pricedb_num_prices(fixture->pricedb, c->usd), ==, 11);
+
+    g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 42);
+
+    g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
+                                           fiscal_end_date, t_cut1,
+                                           PRICE_REMOVE_SOURCE_USER, // source is USER
+                                           PRICE_REMOVE_KEEP_NONE)); // keep none
+
+    g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 39);
+
+    // there should be no prices before cutoff, returns false
+    g_assert (!gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
+                                           NULL, t_cut,
+                                           PRICE_REMOVE_SOURCE_FQ,   // source is FQ
+                                           PRICE_REMOVE_KEEP_NONE)); // keep none
+
+    g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 39);
+
+    g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
+                                           fiscal_end_date, t_cut1,
+                                           source_all,                      // source is ALL
+                                           PRICE_REMOVE_KEEP_LAST_WEEKLY)); // keep last of week
+
+    g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 38);
+
+    g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
+                                           fiscal_end_date, t_cut2,
+                                           PRICE_REMOVE_SOURCE_FQ,           // source is FQ
+                                           PRICE_REMOVE_KEEP_LAST_MONTHLY)); // keep last of month
+
+    g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 37);
+
+    g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
+                                           fiscal_end_date, t_cut2,
+                                           source_all,                         // source is all
+                                           PRICE_REMOVE_KEEP_LAST_QUARTERLY)); // keep last of quarter
+
+    g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 35);
+
+    g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
+                                           fiscal_end_date, t_cut2,
+                                           source_all,                      // source is all
+                                           PRICE_REMOVE_KEEP_LAST_PERIOD)); // keep last of period
+
+    g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 33);
+
+    g_list_free (comm_list);
+    g_date_free (fiscal_end_date);
 }
 /* price_list_from_hashtable
 static PriceList *
@@ -958,7 +1059,7 @@ test_gnc_pricedb_get_prices (PriceDBFixture *fixture, gconstpointer pData)
     PriceList *prices = gnc_pricedb_get_prices(fixture->pricedb,
                                                fixture->com->usd,
                                                fixture->com->aud);
-    g_assert_cmpint(g_list_length(prices), ==, 4);
+    g_assert_cmpint(g_list_length(prices), ==, 5);
     gnc_price_list_destroy(prices);
 }
 /* gnc_pricedb_lookup_day

commit 667f175757e4d4287cbf758dbfad4baba72a13ea
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Aug 10 13:30:55 2017 +0100

    This change modifies the way old prices can be removed.
    
    There are now options to specify which commodities to remove prices
    from as well as options to leave none or the last one for the week,
    month, Quarter, year and a scaled option.

diff --git a/gnucash/gnome/dialog-price-edit-db.c b/gnucash/gnome/dialog-price-edit-db.c
index 9d8cc04..ba5d5a7 100644
--- a/gnucash/gnome/dialog-price-edit-db.c
+++ b/gnucash/gnome/dialog-price-edit-db.c
@@ -32,6 +32,7 @@
 #include <time.h>
 
 #include "dialog-utils.h"
+#include "gnc-accounting-period.h"
 #include "gnc-amount-edit.h"
 #include "gnc-commodity-edit.h"
 #include "gnc-general-select.h"
@@ -80,6 +81,10 @@ typedef struct
 
     GtkWidget * edit_button;
     GtkWidget * remove_button;
+
+    GtkWidget *remove_dialog;
+    GtkTreeView *remove_view;
+    gint remove_source;
 } PricesDialog;
 
 
@@ -175,13 +180,12 @@ gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
     }
 
     length = g_list_length(price_list);
-    if (length > 1)
+    if (length > 0)
     {
         gchar *message;
 
         message = g_strdup_printf
-                  (/* Translators: %d is the number of prices. This
-	  is a ngettext(3) message. */
+                  (/* Translators: %d is the number of prices. This is a ngettext(3) message. */
                       ngettext("Are you sure you want to delete the selected price?",
                                "Are you sure you want to delete the %d selected prices?",
                                length),
@@ -216,53 +220,297 @@ gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
 }
 
 
+/** Enumeration for the price delete list-store */
+enum GncPriceColumn {PRICED_FULL_NAME, PRICED_COMM, PRICED_DATE, PRICED_COUNT};
+
+static Timespec
+gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
+{
+    GtkTreeModel *model = gtk_tree_view_get_model (view);
+    const gnc_commodity_table *commodity_table = gnc_get_current_commodities ();
+    GList *namespace_list = gnc_commodity_table_get_namespaces (commodity_table);
+    gnc_commodity *tmp_commodity = NULL;
+    char  *tmp_namespace = NULL;
+    GList *commodity_list = NULL;
+    GtkTreeIter iter;
+
+    Timespec oldest_ts = timespec_now ();
+    oldest_ts.tv_nsec = 0;
+
+    namespace_list = g_list_first (namespace_list);
+    while (namespace_list != NULL)
+    {
+        tmp_namespace = namespace_list->data;
+        DEBUG("Looking at namespace %s", tmp_namespace);
+        commodity_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace);
+        commodity_list  = g_list_first (commodity_list);
+        while (commodity_list != NULL)
+        {
+            gint num = 0;
+            tmp_commodity = commodity_list->data;
+            num = gnc_pricedb_num_prices (pdb, tmp_commodity);
+            DEBUG("Looking at commodity %s, Number of prices %d", gnc_commodity_get_fullname (tmp_commodity), num);
+
+            if (num > 0)
+            {
+                PriceList *list = gnc_pricedb_get_prices (pdb, tmp_commodity, NULL);
+                GList *node = g_list_last (list);
+                GNCPrice *price = (GNCPrice*)node->data;
+                Timespec price_ts = gnc_price_get_time (price);
+                const gchar *name_str = gnc_commodity_get_printname (tmp_commodity);
+                gchar *date_str, *num_str;
+
+                if (timespec_cmp(&oldest_ts, &price_ts) >= 0)
+                    oldest_ts.tv_sec = price_ts.tv_sec;
+
+                date_str = g_strdup (gnc_print_date (price_ts));
+                num_str = g_strdup_printf ("%d", num);
+
+                gtk_list_store_append (GTK_LIST_STORE(model), &iter);
+
+                gtk_list_store_set (GTK_LIST_STORE(model), &iter, PRICED_FULL_NAME, name_str,
+                                    PRICED_COMM, tmp_commodity, PRICED_DATE, date_str, PRICED_COUNT, num_str, -1);
+
+                g_free (date_str);
+                g_free (num_str);
+                gnc_price_unref (price);
+            }
+            commodity_list = g_list_next (commodity_list);
+        }
+        namespace_list = g_list_next (namespace_list);
+    }
+    g_list_free (commodity_list);
+    g_list_free (namespace_list);
+
+    return oldest_ts;
+}
+
+static GList *
+gnc_prices_dialog_get_commodity (GtkTreeView *view)
+{
+    GtkTreeModel     *model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
+    GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
+    GList            *list = gtk_tree_selection_get_selected_rows (selection, &model);
+    GList            *row;
+    GList            *comm_list = NULL;
+    GtkTreeIter       iter;
+    gnc_commodity    *comm;
+
+    // Walk the list
+    for (row = g_list_first (list); row; row = g_list_next (row))
+    {
+        if (gtk_tree_model_get_iter (model, &iter, row->data))
+        {
+            gtk_tree_model_get (model, &iter, PRICED_COMM, &comm, -1);
+            comm_list = g_list_append (comm_list, comm);
+        }
+    }
+    g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
+    g_list_free (list);
+
+    return comm_list;
+}
+ 
+static void
+change_source_flag (PriceRemoveSourceFlags source, gboolean set, gpointer data)
+{
+    PricesDialog *pdb_dialog = data;
+    GtkWidget *w = gtk_dialog_get_widget_for_response (GTK_DIALOG(pdb_dialog->remove_dialog), GTK_RESPONSE_OK);
+
+    if (set)
+        pdb_dialog->remove_source = pdb_dialog->remove_source | source;
+    else
+        pdb_dialog->remove_source = pdb_dialog->remove_source & (~source);
+
+    // Check if we have the required options to enable OK button
+    if (pdb_dialog->remove_source > 8) // commodities flag is 8
+        gtk_widget_set_sensitive (w, TRUE);
+    else
+        gtk_widget_set_sensitive (w, FALSE);
+
+    DEBUG("Source is: %d, remove_source is %d", source, pdb_dialog->remove_source);
+}
+
+static void
+check_event_fq_cb (GtkWidget *widget, gpointer data)
+{
+    PricesDialog *pdb_dialog = data;
+
+    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
+        change_source_flag (PRICE_REMOVE_SOURCE_FQ, TRUE, pdb_dialog);
+    else
+        change_source_flag (PRICE_REMOVE_SOURCE_FQ, FALSE, pdb_dialog);
+}
+
+static void
+check_event_user_cb (GtkWidget *widget, gpointer data)
+{
+    PricesDialog *pdb_dialog = data;
+
+    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
+        change_source_flag (PRICE_REMOVE_SOURCE_USER, TRUE, pdb_dialog);
+    else
+        change_source_flag (PRICE_REMOVE_SOURCE_USER, FALSE, pdb_dialog);
+}
+
+static void
+check_event_app_cb (GtkWidget *widget, gpointer data)
+{
+    PricesDialog *pdb_dialog = data;
+
+    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
+        change_source_flag (PRICE_REMOVE_SOURCE_APP, TRUE, pdb_dialog);
+    else
+        change_source_flag (PRICE_REMOVE_SOURCE_APP, FALSE, pdb_dialog);
+}
+
+static void
+selection_changed_cb (GtkTreeSelection *selection, gpointer data)
+{
+    PricesDialog *pdb_dialog = data;
+    GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->remove_view));
+    GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
+
+    if (g_list_length (rows) > 0)
+        change_source_flag (PRICE_REMOVE_SOURCE_COMM, TRUE, pdb_dialog);
+    else
+        change_source_flag (PRICE_REMOVE_SOURCE_COMM, FALSE, pdb_dialog);
+}
+
+static GDate
+get_fiscal_end_date (void)
+{
+    Timespec ts_end;
+    GDate f_end;
+
+    timespecFromTime64 (&ts_end, gnc_accounting_period_fiscal_end());
+    f_end = timespec_to_gdate (ts_end);
+
+    PINFO("Fiscal end date is %s", qof_print_date (gnc_accounting_period_fiscal_end()));
+
+    return f_end;
+}
+
 void
 gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
 {
     PricesDialog *pdb_dialog = data;
     GtkBuilder *builder;
-    GtkWidget *dialog, *button, *date, *label, *box;
+    GtkWidget *date, *label, *box;
+    GtkWidget *button;
+    GtkTreeSelection *selection;
+    GtkTreeViewColumn *tree_column;
+    GtkCellRenderer   *cr;
+    Timespec first_ts;
     gint result;
-    gboolean delete_user, delete_last;
 
     ENTER(" ");
     builder = gtk_builder_new();
+    gnc_builder_add_from_file (builder, "dialog-price.glade", "liststore4");
     gnc_builder_add_from_file (builder, "dialog-price.glade", "deletion_date_dialog");
 
-    dialog = GTK_WIDGET(gtk_builder_get_object (builder, "deletion_date_dialog"));
+    pdb_dialog->remove_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "deletion_date_dialog"));
 
     box = GTK_WIDGET(gtk_builder_get_object (builder, "date_hbox"));
     date = gnc_date_edit_new (time (NULL), FALSE, FALSE);
 
-    gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX (box), date, FALSE, FALSE, 0);
     gtk_widget_show (date);
     gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(date)->date_entry), TRUE);
     label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label"));
     gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date), label);
 
+    // Setup the commodity view
+    pdb_dialog->remove_view = GTK_TREE_VIEW(gtk_builder_get_object (builder, "commodty_treeview"));
+    selection = gtk_tree_view_get_selection (pdb_dialog->remove_view);
+    gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+    // Add Entries column this way as align does not seem to work from builder
+    tree_column = gtk_tree_view_column_new();
+    gtk_tree_view_column_set_title (tree_column, _("Entries"));
+    gtk_tree_view_append_column (GTK_TREE_VIEW(pdb_dialog->remove_view), tree_column);
+    gtk_tree_view_column_set_alignment (tree_column, 0.5);
+    gtk_tree_view_column_set_expand (tree_column, TRUE);
+    cr = gtk_cell_renderer_text_new();
+    gtk_tree_view_column_pack_start (tree_column, cr, TRUE);
+    // set 'xalign' property of the cell renderer
+    gtk_tree_view_column_set_attributes (tree_column, cr, "text", PRICED_COUNT, NULL);
+    gtk_cell_renderer_set_alignment (cr, 0.5, 0.5);
+
+    // Load the view and get the earliest date
+    first_ts = gnc_prices_dialog_load_view (pdb_dialog->remove_view, pdb_dialog->price_db);
+    gtk_tree_selection_select_all (selection);
+    g_signal_connect (selection, "changed", G_CALLBACK(selection_changed_cb), pdb_dialog);
+
     gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pdb_dialog);
 
-    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (pdb_dialog->dialog));
+    gtk_window_set_transient_for (GTK_WINDOW (pdb_dialog->remove_dialog), GTK_WINDOW (pdb_dialog->dialog));
+
+    pdb_dialog->remove_source = 9; // FQ and Commodities highlighted
+    button = GTK_WIDGET(gtk_builder_get_object (builder, "checkbutton_fq"));
+    g_signal_connect (button, "toggled", G_CALLBACK (check_event_fq_cb), pdb_dialog);
+    button = GTK_WIDGET(gtk_builder_get_object (builder, "checkbutton_user"));
+    g_signal_connect (button, "toggled", G_CALLBACK (check_event_user_cb), pdb_dialog);
+    button = GTK_WIDGET(gtk_builder_get_object (builder, "checkbutton_app"));
+    g_signal_connect (button, "toggled", G_CALLBACK (check_event_app_cb), pdb_dialog);
 
-    result = gtk_dialog_run (GTK_DIALOG (dialog));
+    result = gtk_dialog_run (GTK_DIALOG (pdb_dialog->remove_dialog));
     if (result == GTK_RESPONSE_OK)
     {
-        Timespec ts;
-
-        DEBUG("deleting prices");
-        ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
-        ts.tv_nsec = 0;
-
-        button = GTK_WIDGET(gtk_builder_get_object (builder, "delete_manual"));
-        delete_user = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
-        button = GTK_WIDGET(gtk_builder_get_object (builder, "delete_last"));
-        delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
+        const char *fmt = _("Are you sure you want to delete these prices ?");
+        GList *comm_list = gnc_prices_dialog_get_commodity (pdb_dialog->remove_view);
 
-        gnc_pricedb_remove_old_prices(pdb_dialog->price_db, ts,
-                                      delete_user, delete_last);
+        // Are you sure you want to delete the entries and we have commodities
+        if ((g_list_length (comm_list) != 0) && (gnc_verify_dialog (pdb_dialog->remove_dialog, FALSE, fmt, NULL)))
+        {
+            Timespec last_ts;
+            GDate fiscal_end_date = get_fiscal_end_date ();
+            PriceRemoveSourceFlags source = PRICE_REMOVE_SOURCE_FQ; 
+            PriceRemoveKeepOptions keep = PRICE_REMOVE_KEEP_NONE;
+
+            DEBUG("deleting prices");
+            last_ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
+            last_ts.tv_nsec = 0;
+
+            button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_week"));
+            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
+                keep = PRICE_REMOVE_KEEP_LAST_WEEKLY;
+            button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_month"));
+            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
+                keep = PRICE_REMOVE_KEEP_LAST_MONTHLY;
+            button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_quarter"));
+            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
+                keep = PRICE_REMOVE_KEEP_LAST_QUARTERLY;
+            button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_period"));
+            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
+                keep = PRICE_REMOVE_KEEP_LAST_PERIOD;
+            button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_scaled"));
+            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
+                keep = PRICE_REMOVE_KEEP_SCALED;
+
+            if (keep != PRICE_REMOVE_KEEP_SCALED)
+                gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date,
+                                               last_ts, pdb_dialog->remove_source, keep);
+            else
+            {
+                Timespec tmp_ts;
+                GDate tmp_date = timespec_to_gdate (last_ts);
+                g_date_subtract_months (&tmp_date, 6);
+                tmp_ts = gdate_to_timespec (tmp_date);
+ 
+                gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date, tmp_ts,
+                                               pdb_dialog->remove_source, PRICE_REMOVE_KEEP_LAST_WEEKLY);
+
+                g_date_subtract_months (&tmp_date, 6);
+                tmp_ts = gdate_to_timespec (tmp_date);
+
+                gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date, tmp_ts,
+                                               pdb_dialog->remove_source, PRICE_REMOVE_KEEP_LAST_MONTHLY);
+            }
+        }
+        g_list_free (comm_list);
     }
-
-    gtk_widget_destroy(dialog);
+    gtk_widget_destroy (pdb_dialog->remove_dialog);
     LEAVE(" ");
 }
 
diff --git a/gnucash/gnome/gtkbuilder/dialog-price.glade b/gnucash/gnome/gtkbuilder/dialog-price.glade
index 375b17b..8da9197 100644
--- a/gnucash/gnome/gtkbuilder/dialog-price.glade
+++ b/gnucash/gnome/gtkbuilder/dialog-price.glade
@@ -2,173 +2,6 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <object class="GtkDialog" id="deletion_date_dialog">
-    <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="border_width">6</property>
-    <property name="type_hint">dialog</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox19">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">6</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area19">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="cancel_button">
-                <property name="label" translatable="yes">_Cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="ok_button">
-                <property name="label" translatable="yes">_OK</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkGrid" id="table2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="halign">start</property>
-            <property name="valign">start</property>
-            <property name="row_spacing">6</property>
-            <property name="column_spacing">12</property>
-            <child>
-              <object class="GtkLabel" id="label8477429">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">start</property>
-                <property name="valign">start</property>
-                <property name="label" translatable="yes">Delete all stock prices before the date below based upon the following criteria:</property>
-                <property name="wrap">True</property>
-                <property name="width_chars">40</property>
-                <property name="max_width_chars">40</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">0</property>
-                <property name="width">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkCheckButton" id="delete_manual">
-                <property name="label" translatable="yes">Delete _manually entered prices</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="tooltip_text" translatable="yes">If activated, delete manually entered stock prices dated earlier than the specified date. Otherwise only stock prices added by Finance::Quote will be deleted.</property>
-                <property name="halign">start</property>
-                <property name="use_underline">True</property>
-                <property name="draw_indicator">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">3</property>
-                <property name="width">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkCheckButton" id="delete_last">
-                <property name="label" translatable="yes">Delete _last price for a stock</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">False</property>
-                <property name="tooltip_text" translatable="yes">If activated, delete all prices before the specified date. Otherwise the last stock price dated before the date will be kept and all earlier quotes deleted.</property>
-                <property name="halign">start</property>
-                <property name="use_underline">True</property>
-                <property name="draw_indicator">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">4</property>
-                <property name="width">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="label8477431">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">1</property>
-                <property name="width">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="date_label">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">start</property>
-                <property name="label" translatable="yes">_Date:</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="left_attach">0</property>
-                <property name="top_attach">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkBox" id="date_hbox">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">start</property>
-                <property name="valign">start</property>
-                <property name="hexpand">True</property>
-                <child>
-                  <placeholder/>
-                </child>
-              </object>
-              <packing>
-                <property name="left_attach">1</property>
-                <property name="top_attach">2</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget response="-6">cancel_button</action-widget>
-      <action-widget response="-5">ok_button</action-widget>
-    </action-widgets>
-  </object>
   <object class="GtkListStore" id="liststore1">
     <columns>
       <!-- column-name item -->
@@ -279,9 +112,8 @@
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="pack_type">end</property>
             <property name="position">0</property>
           </packing>
         </child>
@@ -472,9 +304,8 @@
                 <property name="entry_text_column">0</property>
                 <signal name="changed" handler="pedit_commodity_ns_changed_cb" swapped="no"/>
                 <child internal-child="entry">
-                  <object class="GtkEntry" id="combobox-entry3">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                  <object class="GtkEntry">
+                    <property name="can_focus">False</property>
                   </object>
                 </child>
               </object>
@@ -492,9 +323,8 @@
                 <property name="entry_text_column">0</property>
                 <signal name="changed" handler="pedit_commodity_changed_cb" swapped="no"/>
                 <child internal-child="entry">
-                  <object class="GtkEntry" id="combobox-entry2">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
+                  <object class="GtkEntry">
+                    <property name="can_focus">False</property>
                   </object>
                 </child>
               </object>
@@ -518,6 +348,437 @@
       <action-widget response="-5">pd_ok_button</action-widget>
     </action-widgets>
   </object>
+  <object class="GtkListStore" id="liststore4">
+    <columns>
+      <!-- column-name full_name -->
+      <column type="gchararray"/>
+      <!-- column-name commodity -->
+      <column type="gpointer"/>
+      <!-- column-name first_date -->
+      <column type="gchararray"/>
+      <!-- column-name number -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
+  <object class="GtkDialog" id="deletion_date_dialog">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="border_width">6</property>
+    <property name="title" translatable="yes">Remove Old Prices</property>
+    <property name="default_height">500</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label">_Cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="ok_button">
+                <property name="label">_OK</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="table2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="row_spacing">10</property>
+            <property name="column_spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="label8477429">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">Delete prices that meet the following criteria:</property>
+                <property name="wrap">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="hbox2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <child>
+                  <object class="GtkRadioButton" id="radiobutton_none">
+                    <property name="label" translatable="yes">_None</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Remove all prices before date.</property>
+                    <property name="use_underline">True</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">radiobutton_last_week</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="radiobutton_last_week">
+                    <property name="label" translatable="yes">Last of _Week</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Keep the last price of each week if present before date.</property>
+                    <property name="use_underline">True</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="radiobutton_last_month">
+                    <property name="label" translatable="yes">Last of _Month</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Keep the last price of each month if present before date.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">radiobutton_last_week</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="radiobutton_last_quarter">
+                    <property name="label" translatable="yes">Last of _Quarter</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Keep the last price of each fiscal quarter if present before date. The fiscal quarter is derived from the accounting period end date.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">radiobutton_last_week</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">3</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="radiobutton_last_period">
+                    <property name="label" translatable="yes">Last of _Period</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Keep the last price of each fiscal period if present before date. The fiscal period is derived from the accounting period end date.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">radiobutton_last_week</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">4</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="radiobutton_scaled">
+                    <property name="label" translatable="yes">_Scaled</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">With the scaled option, prices are removed relative to the date selected. 'One a month' is used for dates older than a year and 'One a week' is used for dates older than six months to a year.</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">radiobutton_last_week</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">5</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">6</property>
+                <property name="width">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="hbox3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="vexpand">True</property>
+                <child>
+                  <object class="GtkScrolledWindow" id="scrolledwindow1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <child>
+                      <object class="GtkTreeView" id="commodty_treeview">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="model">liststore4</property>
+                        <child internal-child="selection">
+                          <object class="GtkTreeSelection"/>
+                        </child>
+                        <child>
+                          <object class="GtkTreeViewColumn" id="name_column">
+                            <property name="title" translatable="yes">Commodity</property>
+                            <child>
+                              <object class="GtkCellRendererText" id="name_cellr"/>
+                              <attributes>
+                                <attribute name="text">0</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkTreeViewColumn" id="date_column">
+                            <property name="title" translatable="yes">First Date</property>
+                            <child>
+                              <object class="GtkCellRendererText" id="date_cellr"/>
+                              <attributes>
+                                <attribute name="text">2</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">4</property>
+                <property name="width">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">From these Commodities:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+                <property name="width">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">Keeping the last available price for option:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">5</property>
+                <property name="width">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="valign">start</property>
+                <property name="hexpand">False</property>
+                <property name="label" translatable="yes">Source:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="vbox1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="hexpand">True</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkCheckButton" id="checkbutton_fq">
+                    <property name="label" translatable="yes">Include _Fetched online prices</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">If activated, prices added by Finance::Quote will be included.</property>
+                    <property name="halign">start</property>
+                    <property name="use_underline">True</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkCheckButton" id="checkbutton_user">
+                    <property name="label" translatable="yes">Include manually _Entered prices</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">If activated, include manually entered prices.</property>
+                    <property name="halign">start</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkBox" id="hbox4">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkCheckButton" id="checkbutton_app">
+                        <property name="label" translatable="yes">_Added by the application</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="tooltip_text" translatable="yes">If activated, include application added prices.
+
+These prices were added so that there's always a "nearest in time" price for every multi-commodity transaction so that the Accounts page and reports are able to correctly report values so removing them may make this less reliable.</property>
+                        <property name="halign">start</property>
+                        <property name="use_underline">True</property>
+                        <property name="image_position">right</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="image_source">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">start</property>
+                        <property name="stock">gtk-dialog-warning</property>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="date_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes">Before _Date:</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="date_hbox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="hexpand">True</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="-5">ok_button</action-widget>
+    </action-widgets>
+  </object>
   <object class="GtkDialog" id="prices_dialog">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
@@ -591,6 +852,23 @@
                 <property name="orientation">vertical</property>
                 <property name="layout_style">spread</property>
                 <child>
+                  <object class="GtkButton" id="get_quotes_button">
+                    <property name="label" translatable="yes">_Get Quotes</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="can_default">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Get new online quotes for stock accounts.</property>
+                    <property name="use_underline">True</property>
+                    <signal name="clicked" handler="gnc_prices_dialog_get_quotes_clicked" swapped="no"/>
+                  </object>
+                  <packing>
+                    <property name="expand">True</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkButton" id="add_button">
                     <property name="label" translatable="yes">_Add</property>
                     <property name="visible">True</property>
@@ -660,27 +938,10 @@
                     <property name="position">3</property>
                   </packing>
                 </child>
-                <child>
-                  <object class="GtkButton" id="get_quotes_button">
-                    <property name="label" translatable="yes">_Get Quotes</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="can_default">True</property>
-                    <property name="receives_default">False</property>
-                    <property name="tooltip_text" translatable="yes">Get new online quotes for stock accounts.</property>
-                    <property name="use_underline">True</property>
-                    <signal name="clicked" handler="gnc_prices_dialog_get_quotes_clicked" swapped="no"/>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">4</property>
-                  </packing>
-                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
-                <property name="fill">False</property>
+                <property name="fill">True</property>
                 <property name="position">1</property>
               </packing>
             </child>
diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index 87ef307..3a90571 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -28,6 +28,7 @@
 #include <string.h>
 #include "gnc-pricedb-p.h"
 #include <qofinstance-p.h>
+#include "gnc-gdate-utils.h"
 
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_PRICE;
@@ -1275,6 +1276,10 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
            qof_instance_get_destroying(p));
 
     gnc_price_ref(p);
+
+    DEBUG("Remove Date is %s, Commodity is %s, Source is %s", gnc_print_date (gnc_price_get_time (p)),
+           gnc_commodity_get_fullname (gnc_price_get_commodity (p)), gnc_price_get_source_string (p));
+
     rc = remove_price (db, p, TRUE);
     gnc_pricedb_begin_edit(db);
     qof_instance_set_dirty(&db->inst);
@@ -1294,8 +1299,9 @@ typedef struct
 {
     GNCPriceDB *db;
     Timespec cutoff;
+    gboolean delete_fq;
     gboolean delete_user;
-    gboolean delete_last;
+    gboolean delete_app;
     GSList *list;
 } remove_info;
 
@@ -1309,14 +1315,19 @@ check_one_price_date (GNCPrice *price, gpointer user_data)
     ENTER("price %p (%s), data %p", price,
           gnc_commodity_get_mnemonic(gnc_price_get_commodity(price)),
           user_data);
-    if (!data->delete_user)
+
+    source = gnc_price_get_source (price);
+        
+    if ((source == PRICE_SOURCE_FQ) && data->delete_fq)
+        PINFO ("Delete Quote Source");
+    else if ((source == PRICE_SOURCE_USER_PRICE) && data->delete_user)
+        PINFO ("Delete User Source");
+    else if ((source != PRICE_SOURCE_FQ) && (source != PRICE_SOURCE_USER_PRICE) && data->delete_app)
+        PINFO ("Delete App Source");
+    else
     {
-        source = gnc_price_get_source (price);
-        if (source != PRICE_SOURCE_FQ)
-        {
-            LEAVE("Not an automatic quote");
-            return TRUE;
-        }
+        LEAVE("Not a matching source");
+        return TRUE;
     }
 
     pt = gnc_price_get_time (price);
@@ -1345,68 +1356,299 @@ pricedb_remove_foreach_pricelist (gpointer key,
 
     ENTER("key %p, value %p, data %p", key, val, user_data);
 
-    /* The most recent price is the first in the list */
-    if (!data->delete_last)
-        node = g_list_next(node);
-
     /* now check each item in the list */
     g_list_foreach(node, (GFunc)check_one_price_date, data);
 
     LEAVE(" ");
 }
 
+static gint
+compare_prices_by_commodity_date (gconstpointer a, gconstpointer b)
+{
+    Timespec time_a;
+    Timespec time_b;
+    gnc_commodity *comma;
+    gnc_commodity *commb;
+    gnc_commodity *curra;
+    gnc_commodity *currb;
+    gint result;
+
+    if (!a && !b) return 0;
+    /* nothing is always less than something */
+    if (!a) return -1;
+
+    comma = gnc_price_get_commodity ((GNCPrice *) a);
+    commb = gnc_price_get_commodity ((GNCPrice *) b);
+
+    if (!gnc_commodity_equal(comma, commb))
+        return gnc_commodity_compare(comma, commb);
+
+    curra = gnc_price_get_currency ((GNCPrice *) a);
+    currb = gnc_price_get_currency ((GNCPrice *) b);
+
+    if (!gnc_commodity_equal(curra, currb))
+        return gnc_commodity_compare(curra, currb);
+
+    time_a = gnc_price_get_time((GNCPrice *) a);
+    time_b = gnc_price_get_time((GNCPrice *) b);
+
+    result = -timespec_cmp(&time_a, &time_b);
+    if (result) return result;
+
+    /* For a stable sort */
+    return guid_compare (gnc_price_get_guid((GNCPrice *) a),
+                         gnc_price_get_guid((GNCPrice *) b));
+}
+
+static gboolean
+price_commodity_and_currency_equal (GNCPrice *a, GNCPrice *b)
+{
+    gboolean ret_comm = FALSE;
+    gboolean ret_curr = FALSE;
+
+    if (gnc_commodity_equal (gnc_price_get_commodity(a), gnc_price_get_commodity (b)))
+        ret_comm = TRUE;
+
+    if (gnc_commodity_equal (gnc_price_get_currency(a), gnc_price_get_currency (b)))
+        ret_curr = TRUE;
+
+    return (ret_comm && ret_curr);
+}
+
 static void
-pricedb_remove_foreach_currencies_hash (gpointer key,
-                                        gpointer val,
-                                        gpointer user_data)
+gnc_pricedb_remove_old_prices_pinfo (GNCPrice *price, gboolean keep_message)
 {
-    GHashTable *currencies_hash = (GHashTable *) val;
+    GDate price_date = timespec_to_gdate (gnc_price_get_time (price));
+    char date_buf[MAX_DATE_LENGTH+1];
 
-    ENTER("key %p, value %p, data %p", key, val, user_data);
-    g_hash_table_foreach(currencies_hash,
-                         pricedb_remove_foreach_pricelist, user_data);
-    LEAVE(" ");
+    if (g_date_valid (&price_date))
+    {
+        qof_print_gdate (date_buf, MAX_DATE_LENGTH, &price_date);
+
+        if (keep_message)
+        {
+            PINFO("#### Keep price with date %s, commodity is %s, currency is %s", date_buf,
+                     gnc_commodity_get_printname(gnc_price_get_commodity(price)),
+                     gnc_commodity_get_printname(gnc_price_get_currency(price)));
+        }
+        else
+            PINFO("## Remove price with date %s", date_buf);
+    }
+    else
+        PINFO("Keep price date is invalid");
+}
+
+static GNCPrice*
+save_cloned_price (GNCPrice *price, GNCPrice *clone_price)
+{
+    QofBook *book = qof_instance_get_book (QOF_INSTANCE(clone_price));
+    GNCPrice *cloned_price;
+
+    if (price)
+        gnc_price_unref (price);
+
+    cloned_price = gnc_price_clone (clone_price, book);
+
+    gnc_pricedb_remove_old_prices_pinfo (clone_price, TRUE);
+
+    return cloned_price;
 }
 
+static gint
+roundUp (gint numToRound, gint multiple)
+{
+    gint remainder;
+
+    if (multiple == 0)
+        return numToRound;
+
+    remainder = numToRound % multiple;
+    if (remainder == 0)
+        return numToRound;
+
+    return numToRound + multiple - remainder;
+}
+
+static gint
+get_fiscal_quarter (GDate *date, GDateMonth fiscal_start)
+{
+    GDateMonth month = g_date_get_month (date);
+
+    gint q = ((roundUp (22 - fiscal_start + month, 3)/3) % 4) + 1;
+
+    PINFO("Return fiscal quarter is %d", q);
+    return q;
+}
+
+static void
+gnc_pricedb_remove_old_prices_keep_last (GNCPriceDB *db, GDate *fiscal_end_date,
+                                         remove_info data, PriceRemoveKeepOptions keep)
+{
+    GSList *item;
+    gboolean save_first_price = FALSE;
+    gint saved_test_value = 0, next_test_value = 0;
+    GNCPrice *saved_price = NULL;
+    GDateMonth fiscal_month_end = g_date_get_month (fiscal_end_date);
+    GDateMonth fiscal_month_start;
+    GDate *tmp_date = g_date_new_dmy (g_date_get_day (fiscal_end_date),
+                                      g_date_get_month (fiscal_end_date),
+                                      g_date_get_year (fiscal_end_date));
+
+    // get the fiscal start month
+    g_date_subtract_months (tmp_date, 12);
+    fiscal_month_start = g_date_get_month (tmp_date) + 1;
+    g_date_free (tmp_date);
+
+    // sort the list by commodity / currency / date
+    data.list = g_slist_sort (data.list, compare_prices_by_commodity_date);
+
+    /* Now run this external list deleting prices */
+    for (item = data.list; item; item = g_slist_next(item))
+    {
+        GDate saved_price_date;
+        GDate next_price_date;
+
+        // Keep None
+        if (keep == PRICE_REMOVE_KEEP_NONE)
+        {
+            gnc_pricedb_remove_old_prices_pinfo (item->data, FALSE);
+            gnc_pricedb_remove_price (db, item->data);
+            continue;
+        }
+
+        save_first_price = !price_commodity_and_currency_equal (item->data, saved_price); // Not Equal
+        if (save_first_price == TRUE)
+        {
+            saved_price = save_cloned_price (saved_price, item->data);
+            save_first_price = FALSE;
+            continue;
+        }
+
+        // get the price dates
+        saved_price_date = timespec_to_gdate (gnc_price_get_time (saved_price));
+        next_price_date = timespec_to_gdate (gnc_price_get_time (item->data));
+
+        // Keep last price in fiscal year
+        if (keep == PRICE_REMOVE_KEEP_LAST_PERIOD && save_first_price == FALSE)
+        {
+            GDate *saved_fiscal_end = g_date_new_dmy (g_date_get_day (&saved_price_date),
+                                                      g_date_get_month (&saved_price_date),
+                                                      g_date_get_year (&saved_price_date));
+
+            GDate *next_fiscal_end = g_date_new_dmy (g_date_get_day (&next_price_date),
+                                                     g_date_get_month (&next_price_date),
+                                                     g_date_get_year (&next_price_date));
+
+            gnc_gdate_set_fiscal_year_end (saved_fiscal_end, fiscal_end_date);
+            gnc_gdate_set_fiscal_year_end (next_fiscal_end, fiscal_end_date);
+
+            saved_test_value = g_date_get_year (saved_fiscal_end);
+            next_test_value = g_date_get_year (next_fiscal_end);
+
+            PINFO("Keep last price in fiscal year");
+
+            g_date_free (saved_fiscal_end);
+            g_date_free (next_fiscal_end);
+        }
+
+        // Keep last price in fiscal quarter
+        if (keep == PRICE_REMOVE_KEEP_LAST_QUARTERLY && save_first_price == FALSE)
+        {
+            saved_test_value = get_fiscal_quarter (&saved_price_date, fiscal_month_start);
+            next_test_value = get_fiscal_quarter (&next_price_date, fiscal_month_start);
+
+            PINFO("Keep last price in fiscal quarter");
+        }
+
+        // Keep last price of every month
+        if (keep == PRICE_REMOVE_KEEP_LAST_MONTHLY && save_first_price == FALSE)
+        {
+            saved_test_value = g_date_get_month (&saved_price_date);
+            next_test_value = g_date_get_month (&next_price_date);
+
+            PINFO("Keep last price of every month");
+        }
+
+        // Keep last price of every week
+        if (keep == PRICE_REMOVE_KEEP_LAST_WEEKLY && save_first_price == FALSE)
+        {
+            saved_test_value = g_date_get_iso8601_week_of_year (&saved_price_date);
+            next_test_value = g_date_get_iso8601_week_of_year (&next_price_date);
+
+            PINFO("Keep last price of every week");
+        }
+
+        // Now compare the values
+        if (saved_test_value == next_test_value)
+        {
+            gnc_pricedb_remove_old_prices_pinfo (item->data, FALSE);
+            gnc_pricedb_remove_price (db, item->data);
+        }
+        else
+            saved_price = save_cloned_price (saved_price, item->data);
+    }
+    if (saved_price)
+        gnc_price_unref (saved_price);
+}
 
 gboolean
-gnc_pricedb_remove_old_prices(GNCPriceDB *db,
-                              Timespec cutoff,
-                              gboolean delete_user,
-                              gboolean delete_last)
+gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list,
+                              GDate *fiscal_end_date, Timespec cutoff,
+                              PriceRemoveSourceFlags source,
+                              PriceRemoveKeepOptions keep)
 {
     remove_info data;
-    GSList *item;
+    GList *node;
 
     data.db = db;
     data.cutoff = cutoff;
-    data.delete_user = delete_user;
-    data.delete_last = delete_last;
     data.list = NULL;
+    data.delete_fq = FALSE;
+    data.delete_user = FALSE;
+    data.delete_app = FALSE;
+
+    ENTER("Remove Prices for Source %d, keeping %d", source, keep);
+
+    // setup the source options
+    if (source & PRICE_REMOVE_SOURCE_APP)
+        data.delete_app = TRUE;
 
-    ENTER("db %p, delet_user %d, delete_last %d", db, delete_user, delete_last);
+    if (source & PRICE_REMOVE_SOURCE_FQ)
+        data.delete_fq = TRUE;
+
+    if (source & PRICE_REMOVE_SOURCE_USER)
+        data.delete_user = TRUE;
+
+    // Walk the list of commodities
+    for (node = g_list_first (comm_list); node; node = g_list_next (node))
     {
-        gchar buf[40];
-        gnc_timespec_to_iso8601_buff(cutoff, buf);
-        DEBUG("checking date %s", buf);
+        GHashTable *currencies_hash = g_hash_table_lookup (db->commodity_hash, node->data);
+        g_hash_table_foreach (currencies_hash, pricedb_remove_foreach_pricelist, &data);
     }
 
-    /* Traverse the database once building up an external list of prices
-     * to be deleted */
-    g_hash_table_foreach(db->commodity_hash,
-                         pricedb_remove_foreach_currencies_hash,
-                         &data);
-
     if (data.list == NULL)
+    {
+        LEAVE("Empty price list");
         return FALSE;
+    }
+    DEBUG("Number of Prices in list is %d, Cutoff date is %s", g_slist_length (data.list), gnc_print_date (cutoff));
 
-    /* Now run this external list deleting prices */
-    for (item = data.list; item; item = g_slist_next(item))
+    // Check for a valid fiscal end of year date
+    if (fiscal_end_date == NULL )
+    {
+        GDateYear year_now = g_date_get_year (gnc_g_date_new_today ());
+        fiscal_end_date = g_date_new ();
+        g_date_set_dmy (fiscal_end_date, 31, 12, year_now);
+    }
+    else if (g_date_valid (fiscal_end_date) == FALSE)
     {
-        gnc_pricedb_remove_price(db, item->data);
+        GDateYear year_now = g_date_get_year (gnc_g_date_new_today ());
+        g_date_clear (fiscal_end_date, 1);
+        g_date_set_dmy (fiscal_end_date, 31, 12, year_now);
     }
+    gnc_pricedb_remove_old_prices_keep_last (db, fiscal_end_date, data, keep);
 
-    g_slist_free(data.list);
+    g_slist_free (data.list);
     LEAVE(" ");
     return TRUE;
 }
diff --git a/libgnucash/engine/gnc-pricedb.h b/libgnucash/engine/gnc-pricedb.h
index 1f8670d..f7eefa3 100644
--- a/libgnucash/engine/gnc-pricedb.h
+++ b/libgnucash/engine/gnc-pricedb.h
@@ -372,17 +372,37 @@ gboolean     gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p);
  */
 gboolean     gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p);
 
+typedef enum
+{
+    PRICE_REMOVE_SOURCE_FQ = 1,   // this flag is set when added by F:Q checked
+    PRICE_REMOVE_SOURCE_USER = 2, // this flag is set when added by the user checked
+    PRICE_REMOVE_SOURCE_APP = 4,  // this flag is set when added by the app checked
+    PRICE_REMOVE_SOURCE_COMM = 8, // this flag is set when we have commodities selected
+} PriceRemoveSourceFlags;
+
+typedef enum
+{
+    PRICE_REMOVE_KEEP_NONE,           // keep none
+    PRICE_REMOVE_KEEP_LAST_WEEKLY,    // leave last one of every week
+    PRICE_REMOVE_KEEP_LAST_MONTHLY,   // leave last one of every month
+    PRICE_REMOVE_KEEP_LAST_QUARTERLY, // leave last one of every quarter
+    PRICE_REMOVE_KEEP_LAST_PERIOD,    // leave last one of every annual period
+    PRICE_REMOVE_KEEP_SCALED,         // leave one every week then one a month
+} PriceRemoveKeepOptions;
+
 /** @brief Remove and unref prices older than a certain time.
  * @param db The pricedb
+ * @param comm_list A list of commodities
+ * @param fiscal_end_date the end date of the current accounting period
  * @param cutoff The time before which prices should be deleted.
- * @param delete_user Whether user-created (i.e. not Finance::Quote) prices
- * should be deleted.
- * @param delete_last Whether a price should be deleted if it's the only
- * remaining price for its commodity.
+ * @param source Whether Finance::Quote, user or all prices should be deleted.
+ * @param keep Whether scaled, monthly, weekly or no prices should be left.
+ * @return True if there were prices to process, False if not.
  */
-gboolean     gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff,
-                                           const gboolean delete_user,
-                                           gboolean delete_last);
+gboolean     gnc_pricedb_remove_old_prices(GNCPriceDB *db, GList *comm_list,
+                                           GDate *fiscal_end_date, Timespec cutoff,
+                                           PriceRemoveSourceFlags source,
+                                           PriceRemoveKeepOptions keep);
 
 /** @brief Find the most recent price between the two commodities.
  *



Summary of changes:
 gnucash/gnome-utils/dialog-utils.c                 |   2 +-
 gnucash/gnome-utils/gnc-date-edit.c                |   1 -
 gnucash/gnome-utils/gnc-dense-cal-store.c          |   2 +-
 gnucash/gnome-utils/gnc-dense-cal.c                |   2 +-
 gnucash/gnome-utils/gnc-period-select.c            |   1 -
 gnucash/gnome-utils/gnc-recurrence.c               |   2 +-
 gnucash/gnome-utils/gnc-tree-control-split-reg.c   |   2 +-
 gnucash/gnome/assistant-acct-period.c              |   2 +-
 gnucash/gnome/assistant-loan.c                     |   1 -
 gnucash/gnome/dialog-invoice.c                     |   2 +-
 gnucash/gnome/dialog-price-edit-db.c               | 281 ++++++++-
 gnucash/gnome/dialog-print-check.c                 |   1 -
 gnucash/gnome/dialog-sx-editor.c                   |   1 -
 gnucash/gnome/dialog-sx-editor2.c                  |   1 -
 gnucash/gnome/dialog-sx-from-trans.c               |   2 +-
 gnucash/gnome/gnc-plugin-page-sx-list.c            |   2 +-
 gnucash/gnome/gtkbuilder/dialog-price.glade        | 643 +++++++++++++++------
 gnucash/gnome/window-reconcile.c                   |   2 +-
 gnucash/gnome/window-reconcile2.c                  |   2 +-
 gnucash/import-export/bi-import/dialog-bi-import.c |   2 +-
 gnucash/register/ledger-core/split-register-util.c |   2 +-
 gnucash/register/ledger-core/split-register.c      |   2 +-
 libgnucash/app-utils/CMakeLists.txt                |   2 -
 libgnucash/app-utils/Makefile.am                   |   2 -
 libgnucash/app-utils/gnc-accounting-period.c       |   1 -
 libgnucash/app-utils/gnc-gdate-utils.c             | 286 ---------
 libgnucash/app-utils/gnc-gdate-utils.h             | 228 --------
 libgnucash/app-utils/gnc-sx-instance-model.c       |   2 +-
 libgnucash/app-utils/test/test-sx.cpp              |   2 +-
 libgnucash/engine/gnc-date.cpp                     | 315 ++++++++--
 libgnucash/engine/gnc-date.h                       | 209 ++++++-
 libgnucash/engine/gnc-pricedb.c                    | 327 +++++++++--
 libgnucash/engine/gnc-pricedb.h                    |  34 +-
 libgnucash/engine/test/utest-gnc-pricedb.c         | 117 +++-
 po/POTFILES.in                                     |   1 -
 35 files changed, 1633 insertions(+), 851 deletions(-)
 delete mode 100644 libgnucash/app-utils/gnc-gdate-utils.c
 delete mode 100644 libgnucash/app-utils/gnc-gdate-utils.h



More information about the gnucash-changes mailing list