From 4c4ed307bccd98d9001a76f1dc942abc2a44c9a8 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 30 Mar 2024 08:55:15 +0800 Subject: [PATCH] [import-main-matcher.cpp] warn if trans_date < recn_date --- gnucash/import-export/import-main-matcher.cpp | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/gnucash/import-export/import-main-matcher.cpp b/gnucash/import-export/import-main-matcher.cpp index 8a234d3bc28..0824957b3a1 100644 --- a/gnucash/import-export/import-main-matcher.cpp +++ b/gnucash/import-export/import-main-matcher.cpp @@ -40,7 +40,9 @@ #include #include +#include #include +#include #include "import-main-matcher.h" @@ -59,6 +61,7 @@ #include "guid.h" #include "gnc-session.h" #include "Query.h" +#include #define GNC_PREFS_GROUP "dialogs.import.generic.transaction-list" #define IMPORT_MAIN_MATCHER_CM_CLASS "transaction-matcher-dialog" @@ -116,6 +119,7 @@ enum downloaded_cols DOWNLOADED_COL_ACTION_UPDATE, DOWNLOADED_COL_ACTION_INFO, DOWNLOADED_COL_ACTION_PIXBUF, + DOWNLOADED_COL_ACTION_PIXBUF_TOOLTIP, DOWNLOADED_COL_DATA, DOWNLOADED_COL_COLOR, DOWNLOADED_COL_ENABLE, @@ -1559,7 +1563,7 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, //memo stuff G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, - GDK_TYPE_PIXBUF, G_TYPE_POINTER, G_TYPE_STRING, + GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN); gtk_tree_view_set_model (view, GTK_TREE_MODEL(store)); g_object_unref (store); @@ -1909,6 +1913,16 @@ get_peer_acct_names (Split *split) return retval; } +static inline std::optional +acct_recndate_warning (time64 trans_date, const Account* acc) +{ + time64 recn_date; + if (xaccAccountGetReconcileLastDate (acc, &recn_date) && trans_date < recn_date) + return recn_date; + else + return {}; +} + static void refresh_model_row (GNCImportMainMatcher *gui, GtkTreeModel *model, @@ -1976,6 +1990,7 @@ refresh_model_row (GNCImportMainMatcher *gui, ro_text = text = NULL; const gchar *color = NULL; bool show_pixbuf = true; + std::vector warnings; switch (gnc_import_TransInfo_get_action (info)) { case GNCImport_ADD: @@ -2028,6 +2043,22 @@ refresh_model_row (GNCImportMainMatcher *gui, imbalance, acct_full_name); } + if (auto recn_date = acct_recndate_warning (date, dest_acc)) + { + static const char* recn_date_warning = N_("The import date %s is \ +earlier than destination account %s whose last reconciled date is %s. Further \ +reconciliation of the destination account may be difficult."); + auto trans_date_str = qof_print_date (date); + auto recn_date_str = qof_print_date (*recn_date); + auto acc_full_name = gnc_account_get_full_name (dest_acc); + auto s = g_strdup_printf (_(recn_date_warning), trans_date_str, + acc_full_name, recn_date_str); + warnings.push_back (s); + g_free (s); + g_free (acc_full_name); + g_free (recn_date_str); + g_free (trans_date_str); + } g_free (acct_full_name); } @@ -2136,6 +2167,19 @@ refresh_model_row (GNCImportMainMatcher *gui, DOWNLOADED_COL_ACTION_ADD, gnc_import_TransInfo_get_action (info) == GNCImport_ADD, -1); + + if (gnc_import_TransInfo_get_action (info) == GNCImport_ADD && !warnings.empty()) + { + auto pixbuf = gen_warning_pixbuf (); + auto warnings_str = std::accumulate (warnings.begin(), warnings.end(), std::string{}, + [](const std::string& a, const std::string& b) + { return a.empty() ? b : a + "\n" + b; }); + gtk_tree_store_set (store, iter, + DOWNLOADED_COL_ACTION_PIXBUF, pixbuf, + DOWNLOADED_COL_ACTION_PIXBUF_TOOLTIP, warnings_str.c_str(), + -1); + } + if (gnc_import_TransInfo_get_action (info) == GNCImport_SKIP) { /*If skipping the row, there is no best match's confidence pixmap*/ @@ -2475,6 +2519,10 @@ query_tooltip_tree_view_cb (GtkWidget *widget, gint x, gint y, -1); break; default: + if (!g_strcmp0 (gtk_tree_view_column_get_title (column), _("Info"))) + gtk_tree_model_get (model, &iter, + DOWNLOADED_COL_ACTION_PIXBUF_TOOLTIP, &tooltip_text, + -1); break; }