From 78cbc3d0979e108b1a9dad2c250e52878b026a45 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Mon, 26 Mar 2012 20:15:04 +0000 Subject: [PATCH] Take read-only date setting of QofBook into account (no pun intended) when entering transaction into accounts. The code will silently revert the entered date to the threshold and just not allow any older date to be entered. I wonder whether we can display some useful error message additionally, but unfortunately I didn't find the place in the code where one single error message would have resulted, only places where multiply (annoying) error messages would have resulted. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22124 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/register/register-gnome/datecell-gnome.c | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/register/register-gnome/datecell-gnome.c b/src/register/register-gnome/datecell-gnome.c index 5c2adf6676..afc9b80733 100644 --- a/src/register/register-gnome/datecell-gnome.c +++ b/src/register/register-gnome/datecell-gnome.c @@ -94,12 +94,44 @@ static void gnc_parse_date (struct tm *parsed, const char * datestr) { int day, month, year; + gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book()); if (!parsed) return; if (!datestr) return; qof_scan_date (datestr, &day, &month, &year); + // If we have an auto-read-only threshold, do not accept a date that is + // older than the threshold. + if (use_autoreadonly) + { + GDate *d = g_date_new_dmy(day, month, year); + GDate *readonly_threshold = qof_book_get_autoreadonly_gdate(gnc_get_current_book()); + if (g_date_compare(d, readonly_threshold) < 0) + { + g_warning("Entered date %s is before the \"auto-read-only threshold\"; resetting to the threshold.", datestr); +#if 0 + GtkWidget *dialog = gtk_message_dialog_new(NULL, + 0, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s", _("Cannot store a transaction at this date")); + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), + "%s", _("The entered date of the new transaction is older than the \"Read-Only Threshold\" set for this book. " + "This setting can be changed in File -> Properties -> Accounts.")); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +#endif + + // Reset the date to the threshold date + day = g_date_get_day(readonly_threshold); + month = g_date_get_month(readonly_threshold); + year = g_date_get_year(readonly_threshold); + } + g_date_free(d); + g_date_free(readonly_threshold); + } + parsed->tm_mday = day; parsed->tm_mon = month - 1; parsed->tm_year = year - 1900;