GnuCash  5.6-38-g01bffa485a+
Modules | Files | Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
Import_Export

Modules

 AqBanking
 

Files

 
file  import-backend.h
 Generic importer backend interface.
 
file  import-commodity-matcher.h
 A Generic commodity matcher/picker.
 
file  import-main-matcher.h
 Transaction matcher main window.
 
file  import-match-picker.h
 The transaction match picker dialog interface.
 
file  import-pending-matches.h
 Tracking container for pending match status.
 
file  import-settings.h
 Import preference handling.
 
file  import-utilities.h
 Utility functions for writing import modules.
 

Data Structures

struct  AccountOnlineMatch
 
struct  AccountPickerDialog
 
struct  GNCImportSelectedMatchInfo
 
struct  GNCImportTransInfo
 
struct  GNCImportMatchInfo
 
struct  GNCImportLastSplitInfo
 
struct  GNCImportMainMatcher
 
class  TreeRowRefDestructor
 
class  RowInfo
 
struct  EntryInfo
 
struct  match_struct
 
struct  GNCImportMatchPicker
 
struct  GNCPendingMatches
 
struct  GNCImportSettings
 
struct  split_record
 
struct  ofx_info
 
struct  InvestmentAcctData
 

Macros

#define STATE_SECTION   "dialogs/import/generic_matcher/account_matcher"
 
#define GNC_PREFS_GROUP   "dialogs.import.generic.account-picker"
 
#define GNCIMPORT_DESC   "desc"
 
#define GNCIMPORT_MEMO   "memo"
 
#define GNCIMPORT_PAYEE   "payee"
 
#define GNC_PREFS_GROUP   "dialogs.import.generic.transaction-list"
 
#define IMPORT_MAIN_MATCHER_CM_CLASS   "transaction-matcher-dialog"
 
#define CSS_INT_REQUIRED_CLASS   "gnc-class-intervention-required"
 
#define CSS_INT_PROB_REQUIRED_CLASS   "gnc-class-intervention-probably-required"
 
#define CSS_INT_NOT_REQUIRED_CLASS   "gnc-class-intervention-not-required"
 
#define G_MOD_IMPORT_MATCHER   "gnc.import.main-matcher"
 
#define GNC_PREFS_GROUP   "dialogs.import.generic.match-picker"
 
#define GNC_PREF_DISPLAY_RECONCILED   "display-reconciled"
 
#define GNC_PREFS_GROUP_IMPORT   "dialogs.import.generic"
 The preferences used by the importer.
 
#define GNC_PREF_ENABLE_SKIP   "enable-skip"
 
#define GNC_PREF_ENABLE_UPDATE   "enable-update"
 
#define GNC_PREF_USE_BAYES   "use-bayes"
 
#define GNC_PREF_ATM_FEE_THRESHOLD   "atm-fee-threshold"
 
#define GNC_PREF_AUTO_CLEAR_THRESHOLD   "auto-clear-threshold"
 
#define GNC_PREF_AUTO_ADD_THRESHOLD   "auto-add-threshold"
 
#define GNC_PREF_MATCH_THRESHOLD   "match-threshold"
 
#define GNC_PREF_MATCH_DATE_THRESHOLD   "match-date-threshold"
 
#define GNC_PREF_MATCH_DATE_NOT_THRESHOLD   "match-date-not-threshold"
 
#define GNC_PREFS_GROUP   "dialogs.log-replay"
 
#define STRING_FIELD_SIZE   256
 
#define GNC_PREFS_GROUP   "dialogs.import.ofx"
 
#define GNC_PREF_AUTO_COMMODITY   "auto-create-commodity"
 

Typedefs

using TreeRowReferencePtr = std::unique_ptr< GtkTreeRowReference, TreeRowRefDestructor >
 
typedef void(* GNCTransactionProcessedCB) (GNCImportTransInfo *trans_info, gboolean imported, gpointer user_data)
 
typedef GHashTable GNCImportPendingMatches
 
typedef struct OfxTransactionData OfxTransactionData
 

Enumerations

enum  GNCImportAction {
  GNCImport_SKIP, GNCImport_ADD, GNCImport_CLEAR, GNCImport_UPDATE,
  GNCImport_LAST_ACTION, GNCImport_INVALID_ACTION
}
 
enum  downloaded_cols {
  DOWNLOADED_COL_DATE_TXT = 0, DOWNLOADED_COL_DATE_INT64, DOWNLOADED_COL_ACCOUNT, DOWNLOADED_COL_AMOUNT,
  DOWNLOADED_COL_AMOUNT_DOUBLE, DOWNLOADED_COL_DESCRIPTION, DOWNLOADED_COL_DESCRIPTION_ORIGINAL, DOWNLOADED_COL_DESCRIPTION_STYLE,
  DOWNLOADED_COL_MEMO, DOWNLOADED_COL_MEMO_ORIGINAL, DOWNLOADED_COL_MEMO_STYLE, DOWNLOADED_COL_NOTES_ORIGINAL,
  DOWNLOADED_COL_ACTION_ADD, DOWNLOADED_COL_ACTION_CLEAR, DOWNLOADED_COL_ACTION_UPDATE, DOWNLOADED_COL_ACTION_INFO,
  DOWNLOADED_COL_ACTION_PIXBUF, DOWNLOADED_COL_DATA, DOWNLOADED_COL_COLOR, DOWNLOADED_COL_ENABLE,
  NUM_DOWNLOADED_COLS, DOWNLOADED_COL_ACCOUNT = 0, DOWNLOADED_COL_DATE, DOWNLOADED_COL_AMOUNT,
  DOWNLOADED_COL_DESCRIPTION, DOWNLOADED_COL_MEMO, DOWNLOADED_COL_BALANCED, DOWNLOADED_COL_INFO_PTR,
  NUM_DOWNLOADED_COLS
}
 
enum  { COMPLETION_LIST_ORIGINAL, COMPLETION_LIST_NORMALIZED_FOLDED, NUM_COMPLETION_COLS }
 
enum  downloaded_cols {
  DOWNLOADED_COL_DATE_TXT = 0, DOWNLOADED_COL_DATE_INT64, DOWNLOADED_COL_ACCOUNT, DOWNLOADED_COL_AMOUNT,
  DOWNLOADED_COL_AMOUNT_DOUBLE, DOWNLOADED_COL_DESCRIPTION, DOWNLOADED_COL_DESCRIPTION_ORIGINAL, DOWNLOADED_COL_DESCRIPTION_STYLE,
  DOWNLOADED_COL_MEMO, DOWNLOADED_COL_MEMO_ORIGINAL, DOWNLOADED_COL_MEMO_STYLE, DOWNLOADED_COL_NOTES_ORIGINAL,
  DOWNLOADED_COL_ACTION_ADD, DOWNLOADED_COL_ACTION_CLEAR, DOWNLOADED_COL_ACTION_UPDATE, DOWNLOADED_COL_ACTION_INFO,
  DOWNLOADED_COL_ACTION_PIXBUF, DOWNLOADED_COL_DATA, DOWNLOADED_COL_COLOR, DOWNLOADED_COL_ENABLE,
  NUM_DOWNLOADED_COLS, DOWNLOADED_COL_ACCOUNT = 0, DOWNLOADED_COL_DATE, DOWNLOADED_COL_AMOUNT,
  DOWNLOADED_COL_DESCRIPTION, DOWNLOADED_COL_MEMO, DOWNLOADED_COL_BALANCED, DOWNLOADED_COL_INFO_PTR,
  NUM_DOWNLOADED_COLS
}
 
enum  matcher_cols {
  MATCHER_COL_CONFIDENCE = 0, MATCHER_COL_CONFIDENCE_PIXBUF, MATCHER_COL_DATE, MATCHER_COL_AMOUNT,
  MATCHER_COL_DESCRIPTION, MATCHER_COL_MEMO, MATCHER_COL_RECONCILED, MATCHER_COL_PENDING,
  MATCHER_COL_INFO_PTR, NUM_MATCHER_COLS
}
 
enum  GNCImportPendingMatchType { GNCImportPending_NONE, GNCImportPending_AUTO, GNCImportPending_MANUAL }
 

Functions

Accountgnc_import_select_account (GtkWidget *parent, const gchar *account_online_id_value, gboolean prompt_on_no_match, const gchar *account_human_description, const gnc_commodity *new_account_default_commodity, GNCAccountType new_account_default_type, Account *default_selection, gboolean *ok_pressed)
 Must be called with a string containing a unique identifier for the account. More...
 
gnc_commodity * gnc_import_select_commodity (const char *cusip, gboolean ask_on_unknown, const char *default_fullname, const char *default_mnemonic)
 Must be called with a string containing a unique identifier for the commodity. More...
 
void on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info)
 
void on_matcher_cancel_clicked (GtkButton *button, gpointer user_data)
 
bool on_matcher_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
 
void on_matcher_help_clicked (GtkButton *button, gpointer user_data)
 This allows for the transaction help dialog to be started from the assistant button callback. More...
 
void on_matcher_help_close_clicked (GtkButton *button, gpointer user_data)
 
void gnc_gen_trans_list_delete (GNCImportMainMatcher *info)
 Deletes the given object. More...
 
bool gnc_gen_trans_list_empty (GNCImportMainMatcher *info)
 Checks whether there are no transactions to match. More...
 
void gnc_gen_trans_list_show_all (GNCImportMainMatcher *info)
 Shows widgets. More...
 
GNCImportMainMatcher * gnc_gen_trans_list_new (GtkWidget *parent, const gchar *heading, bool all_from_same_account, gint match_date_hardlimit, bool show_all)
 Create a new generic transaction dialog window and return it. More...
 
GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent, GtkWidget *assistant_page, const gchar *heading, bool all_from_same_account, gint match_date_hardlimit)
 Add the Transaction matcher to an existing page of an assistant. More...
 
void gnc_gen_trans_assist_start (GNCImportMainMatcher *info)
 This starts the import process for transaction from an assistant. More...
 
void gnc_gen_trans_list_add_tp_cb (GNCImportMainMatcher *info, GNCTransactionProcessedCB trans_processed_cb, gpointer user_data)
 Add transaction processed callback to the transaction importer. More...
 
bool gnc_gen_trans_list_run (GNCImportMainMatcher *info)
 Run this dialog and return only after the user pressed Ok, Cancel, or closed the window. More...
 
void gnc_gen_trans_list_show_reconcile_after_close_button (GNCImportMainMatcher *info, bool reconcile_after_close, bool active)
 Show and set the reconcile after close check button. More...
 
GtkWidget * gnc_gen_trans_list_get_reconcile_after_close_button (GNCImportMainMatcher *info)
 Returns the reconcile after close check button. More...
 
void gnc_gen_trans_list_add_trans (GNCImportMainMatcher *gui, Transaction *trans)
 Add a newly imported Transaction to the Transaction Importer. More...
 
void gnc_gen_trans_list_add_trans_with_ref_id (GNCImportMainMatcher *gui, Transaction *trans, guint32 ref_id)
 Add a newly imported Transaction to the Transaction Importer and provide an external reference id for it. More...
 
void gnc_gen_trans_list_add_trans_with_split_data (GNCImportMainMatcher *gui, Transaction *trans, GNCImportLastSplitInfo *lsplit)
 Add a newly imported Transaction to the Transaction Importer. More...
 
GtkWidget * gnc_gen_trans_list_widget (GNCImportMainMatcher *info)
 Returns the widget of this dialog. More...
 
GtkWidget * gnc_gen_trans_list_append_text_widget (GNCImportMainMatcher *info)
 Returns the append_text widget of this dialog. More...
 
void gnc_import_match_picker_run_and_close (GtkWidget *parent, GNCImportTransInfo *transaction_info, GNCImportPendingMatches *pending_matches)
 Run a match_picker dialog so that the selected-MatchInfo in the given trans_info is updated accordingly. More...
 
GNCImportPendingMatches * gnc_import_PendingMatches_new (void)
 
void gnc_import_PendingMatches_delete (GNCImportPendingMatches *map)
 
void gnc_import_PendingMatches_add_match (GNCImportPendingMatches *map, GNCImportMatchInfo *match_info, gboolean selected_manually)
 
void gnc_import_PendingMatches_remove_match (GNCImportPendingMatches *map, GNCImportMatchInfo *match_info, gboolean selected_manually)
 
GNCImportPendingMatchType gnc_import_PendingMatches_get_match_type (GNCImportPendingMatches *map, GNCImportMatchInfo *match_info)
 
const char * gnc_import_PendingMatches_get_type_str (GNCImportPendingMatchType type)
 
GNCImportSettings * gnc_import_Settings_new (void)
 Allocates a new GNCImportSettings object, and initialize it with the appropriate user prefs.
 
void gnc_import_Settings_delete (GNCImportSettings *settings)
 Destructor.
 
gboolean gnc_import_trans_has_online_id (Transaction *transaction)
 
gboolean gnc_import_split_has_online_id (Split *split)
 
void qof_instance_set_guid (gpointer inst, const GncGUID *guid)
 Set the GncGUID of this instance.
 
void gnc_file_log_replay (GtkWindow *parent)
 The gnc_file_log_replay() routine will pop up a standard file selection dialogue asking the user to pick a log file to replay. More...
 
int ofx_proc_statement_cb (struct OfxStatementData data, void *statement_user_data)
 
int ofx_proc_security_cb (const struct OfxSecurityData data, void *security_user_data)
 
int ofx_proc_transaction_cb (OfxTransactionData data, void *user_data)
 
int ofx_proc_account_cb (struct OfxAccountData data, void *account_user_data)
 
void gnc_file_ofx_import (GtkWindow *parent)
 The gnc_file_ofx_import() routine will pop up a standard file selection dialogue asking the user to pick a OFX/QFX file. More...
 
char * libgncmod_ofx_gnc_module_path (void)
 
char * libgncmod_ofx_gnc_module_description (void)
 
int libgncmod_ofx_gnc_module_init (int refcount)
 
int libgncmod_ofx_gnc_module_end (int refcount)
 

Variables

gint GNCPendingMatches::num_manual_matches
 
gint GNCPendingMatches::num_auto_matches
 
int libgncmod_ofx_gnc_module_system_interface = 0
 
int libgncmod_ofx_gnc_module_current = 0
 
int libgncmod_ofx_gnc_module_revision = 0
 
int libgncmod_ofx_gnc_module_age = 0
 

Non-GUI Functions

GdkPixbuf * gen_probability_pixbuf (gint score, GNCImportSettings *settings, GtkWidget *widget)
 This function generates a new pixmap representing a match score. More...
 
void split_find_match (GNCImportTransInfo *trans_info, Split *split, gint display_threshold, gint date_threshold, gint date_not_threshold, double fuzzy_amount_difference)
 The transaction matching heuristics are here. More...
 
gboolean gnc_import_process_trans_item (Account *base_acc, GNCImportTransInfo *trans_info)
 /brief – Processes one match according to its selected action. More...
 
gboolean gnc_import_exists_online_id (Transaction *trans, GHashTable *acct_id_hash)
 Checks whether the given transaction's online_id already exists in its parent account. More...
 
void gnc_import_TransInfo_init_matches (GNCImportTransInfo *trans_info, GNCImportSettings *settings)
 Iterates through all splits of trans_info's originating account match list. More...
 

Getters/Setters for GNCImportTransInfo

GList * gnc_import_TransInfo_get_match_list (const GNCImportTransInfo *info)
 Returns the stored list of possible matches. More...
 
void gnc_import_TransInfo_remove_top_match (GNCImportTransInfo *info)
 Remove the first match in the list of possible matches.
 
Transaction * gnc_import_TransInfo_get_trans (const GNCImportTransInfo *info)
 Returns the transaction of this TransInfo. More...
 
gboolean gnc_import_TransInfo_is_balanced (const GNCImportTransInfo *info)
 Returns if the transaction stored in the TransInfo is currently balanced. More...
 
Split * gnc_import_TransInfo_get_fsplit (const GNCImportTransInfo *info)
 Returns the first split of the transaction of this TransInfo. More...
 
GNCImportMatchInfognc_import_TransInfo_get_selected_match (const GNCImportTransInfo *info)
 Returns the currently selected match in this TransInfo. More...
 
void gnc_import_TransInfo_set_selected_match_info (GNCImportTransInfo *info, GNCImportMatchInfo *match, gboolean selected_manually)
 Sets the currently selected match in this TransInfo. More...
 
gboolean gnc_import_TransInfo_get_match_selected_manually (const GNCImportTransInfo *info)
 Returns if the currently selected match was selected by the user. More...
 
GNCImportAction gnc_import_TransInfo_get_action (const GNCImportTransInfo *info)
 Returns the currently selected action for this TransInfo. More...
 
void gnc_import_TransInfo_set_action (GNCImportTransInfo *info, GNCImportAction action)
 Set the action for this TransInfo. More...
 
Accountgnc_import_TransInfo_get_destacc (const GNCImportTransInfo *info)
 Returns the 'other account' of this transaction. More...
 
void gnc_import_TransInfo_set_destacc (GNCImportTransInfo *info, Account *acc, gboolean selected_manually)
 Set the 'other account' of this transaction (used for auto-balance if needed). More...
 
gboolean gnc_import_TransInfo_get_destacc_selected_manually (const GNCImportTransInfo *info)
 Returns if the currently selected destination account for auto-matching was selected by the user. More...
 
guint32 gnc_import_TransInfo_get_ref_id (const GNCImportTransInfo *info)
 Returns the reference id for this TransInfo. More...
 
void gnc_import_TransInfo_set_ref_id (GNCImportTransInfo *info, guint32 ref_id)
 Set the reference id for this TransInfo. More...
 
gnc_numeric gnc_import_TransInfo_get_price (const GNCImportTransInfo *info)
 Returns the exchange rate for this TransInfo. More...
 
void gnc_import_TransInfo_set_price (GNCImportTransInfo *info, gnc_numeric lprice)
 Set the exchange rate for this TransInfo. More...
 
gnc_numeric gnc_import_TransInfo_get_dest_amount (const GNCImportTransInfo *info)
 Returns the destination split amount for this TransInfo. More...
 
gnc_numeric gnc_import_TransInfo_get_dest_value (const GNCImportTransInfo *info)
 Returns the destination split value for this TransInfo. More...
 
void gnc_import_TransInfo_set_last_split_info (GNCImportTransInfo *info, GNCImportLastSplitInfo *lsplit)
 Sets additional parameters to be used to generate the closing split.
 
void gnc_import_TransInfo_set_append_text (GNCImportTransInfo *info, gboolean append_text)
 Set the append_text for this TransInfo. More...
 
void gnc_import_TransInfo_delete (GNCImportTransInfo *info)
 Destructor.
 
GNCImportTransInfo * gnc_import_TransInfo_new (Transaction *trans, Account *base_acc)
 Create a new object of GNCImportTransInfo here. More...
 

Getters/Setters for GNCImportMatchInfo

Split * gnc_import_MatchInfo_get_split (const GNCImportMatchInfo *info)
 Get the split ('this-side split') of this MatchInfo. More...
 
gint gnc_import_MatchInfo_get_probability (const GNCImportMatchInfo *info)
 Get the probability (confidence level) of this MatchInfo. More...
 

Getters/Setters for GNCImportSettings

double gnc_import_Settings_get_fuzzy_amount (GNCImportSettings *settings)
 Return the allowed amount range for fuzzy amount matching. More...
 
gboolean gnc_import_Settings_get_action_skip_enabled (GNCImportSettings *settings)
 Return the selected action is enable state.
 
gboolean gnc_import_Settings_get_action_add_enabled (GNCImportSettings *settings)
 Return the selected action is enable state.
 
gboolean gnc_import_Settings_get_action_update_enabled (GNCImportSettings *settings)
 Return the selected action is enable state.
 
gboolean gnc_import_Settings_get_action_clear_enabled (GNCImportSettings *settings)
 Return the selected action is enable state.
 
gint gnc_import_Settings_get_clear_threshold (GNCImportSettings *settings)
 Return the selected threshold.
 
gint gnc_import_Settings_get_add_threshold (GNCImportSettings *settings)
 Return the selected threshold.
 
gint gnc_import_Settings_get_display_threshold (GNCImportSettings *settings)
 Return the selected threshold.
 
gint gnc_import_Settings_get_date_threshold (GNCImportSettings *settings)
 
gint gnc_import_Settings_get_date_not_threshold (GNCImportSettings *settings)
 
void gnc_import_Settings_set_match_date_hardlimit (GNCImportSettings *s, gint m)
 
gint gnc_import_Settings_get_match_date_hardlimit (const GNCImportSettings *settings)
 Returns the hard-limiting number of days that a matching split may differ. More...
 

Setter-getters

Setter and getter functions for the online_id field for Splits.

gchar * gnc_import_get_acc_online_id (Account *account)
 
void gnc_import_set_acc_online_id (Account *account, const gchar *id)
 
gchar * gnc_import_get_trans_online_id (Transaction *transaction)
 
void gnc_import_set_trans_online_id (Transaction *transaction, const gchar *id)
 
gchar * gnc_import_get_split_online_id (Split *split)
 
void gnc_import_set_split_online_id (Split *split, const gchar *id)
 

Detailed Description

Function Documentation

◆ gen_probability_pixbuf()

GdkPixbuf * gen_probability_pixbuf ( gint  score,
GNCImportSettings *  settings,
GtkWidget *  widget 
)

This function generates a new pixmap representing a match score.

It is a series of vertical bars of different colors. -Below or at the add_threshold the bars are red -Above or at the clear_threshold the bars are green -Between the two threshold the bars are yellow

Parameters
scoreThe score for which to generate a pixmap.
settingsThe user settings from which to get the threshold
widgetThe parent widget in which the pixmap will eventually be added. Will be used to generate the colormap.

Definition at line 358 of file import-backend.cpp.

359 {
360  constexpr gint height = 15;
361  constexpr gint width_each_bar = 7;
362  constexpr gint width_first_bar = 1;
363  constexpr gint num_colors = 5;
364  gchar * xpm[2 + num_colors + height];
365 
366  g_assert(settings);
367  g_assert(widget);
368 
369  auto score = std::max (0, score_original);
370 
371  /* Add size definition to xpm */
372  xpm[0] = g_strdup_printf("%d%s%d%s%d%s", (width_each_bar * score) + width_first_bar/*width*/, " ", height, " ", num_colors, " 1"/*characters per pixel*/);
373 
374  /* Define used colors */
375  xpm[1] = g_strdup(" c None");
376  xpm[2] = g_strdup("g c green");
377  xpm[3] = g_strdup("y c yellow");
378  xpm[4] = g_strdup("r c red");
379  xpm[5] = g_strdup("b c black");
380 
381  auto add_threshold = gnc_import_Settings_get_add_threshold(settings);
382  auto clear_threshold = gnc_import_Settings_get_clear_threshold(settings);
383  for (int i = 0; i < height; i++)
384  {
385  xpm[num_colors+1+i] = g_new0(char, (width_each_bar * score) + width_first_bar + 1);
386  for (int j = 0; j <= score; j++)
387  {
388  if (j == 0)
389  strcat(xpm[num_colors+1+i], "b");
390  else if (i == 0 || i == height - 1)
391  strcat(xpm[num_colors+1+i], "bbbbbb ");
392  else if (j <= add_threshold)
393  strcat(xpm[num_colors+1+i], "brrrrb ");
394  else if (j >= clear_threshold)
395  strcat(xpm[num_colors+1+i], "bggggb ");
396  else
397  strcat(xpm[num_colors+1+i], "byyyyb ");
398  }
399  }
400 
401  auto retval = gdk_pixbuf_new_from_xpm_data((const gchar **)xpm);
402  for (int i = 0; i <= num_colors + height; i++)
403  g_free(xpm[i]);
404 
405  return retval;
406 }
gint gnc_import_Settings_get_clear_threshold(GNCImportSettings *settings)
Return the selected threshold.
gint gnc_import_Settings_get_add_threshold(GNCImportSettings *settings)
Return the selected threshold.

◆ gnc_file_log_replay()

void gnc_file_log_replay ( GtkWindow *  parent)

The gnc_file_log_replay() routine will pop up a standard file selection dialogue asking the user to pick a log file to replay.

If one is selected the .log file is opened and read. Its contents are then silently merged in the current log file.

Definition at line 544 of file gnc-log-replay.c.

545 {
546  char *selected_filename;
547  char *default_dir;
548  char read_buf[256];
549  char *read_retval;
550  GtkFileFilter *filter;
551  FILE *log_file;
552  char * record_start_str = "===== START";
553  /* NOTE: This string must match src/engine/TransLog.c (sans newline) */
554  char * expected_header_orig = "mod\ttrans_guid\tsplit_guid\ttime_now\t"
555  "date_entered\tdate_posted\tacc_guid\tacc_name\tnum\tdescription\t"
556  "notes\tmemo\taction\treconciled\tamount\tvalue\tdate_reconciled";
557  static char *expected_header = NULL;
558 
559  /* Use g_strdup_printf so we don't get accidental tab -> space conversion */
560  if (!expected_header)
561  expected_header = g_strdup(expected_header_orig);
562 
563  qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG);
564  ENTER(" ");
565 
566  /* Don't log the log replay. This would only result in redundant logs */
567  xaccLogDisable();
568 
569  default_dir = gnc_get_default_directory(GNC_PREFS_GROUP);
570 
571  filter = gtk_file_filter_new();
572  gtk_file_filter_set_name(filter, "*.log");
573  gtk_file_filter_add_pattern(filter, "*.[Ll][Oo][Gg]");
574  selected_filename = gnc_file_dialog(parent,
575  _("Select a .log file to replay"),
576  g_list_prepend(NULL, filter),
577  default_dir,
578  GNC_FILE_DIALOG_OPEN);
579  g_free(default_dir);
580 
581  if (selected_filename != NULL)
582  {
583  /* Remember the directory as the default. */
584  default_dir = g_path_get_dirname(selected_filename);
585  gnc_set_default_directory(GNC_PREFS_GROUP, default_dir);
586  g_free(default_dir);
587 
588  /*strncpy(file,selected_filename, 255);*/
589  DEBUG("Filename found: %s", selected_filename);
590  if (xaccFileIsCurrentLog(selected_filename))
591  {
592  g_warning("Cannot open the current log file: %s", selected_filename);
593  gnc_error_dialog(NULL,
594  /* Translators: %s is the file name. */
595  _("Cannot open the current log file: %s"),
596  selected_filename);
597  }
598  else
599  {
600  DEBUG("Opening selected file");
601  log_file = g_fopen(selected_filename, "r");
602  if (!log_file || ferror(log_file) != 0)
603  {
604  int err = errno;
605  perror("File open failed");
606  /* Translators: First argument is the filename,
607  * second argument is the error.
608  */
609  gnc_error_dialog(NULL,
610  _("Failed to open log file: %s: %s"),
611  selected_filename,
612  strerror(err));
613  }
614  else
615  {
616  if ((read_retval = fgets(read_buf, sizeof(read_buf), log_file)) == NULL)
617  {
618  DEBUG("Read error or EOF");
619  gnc_info_dialog(NULL, "%s",
620  _("The log file you selected was empty."));
621  }
622  else
623  {
624  if (strncmp(expected_header, read_buf, strlen(expected_header)) != 0)
625  {
626  PERR("File header not recognised:\n%s", read_buf);
627  PERR("Expected:\n%s", expected_header);
628  gnc_error_dialog(NULL, "%s",
629  _("The log file you selected cannot be read. "
630  "The file header was not recognized."));
631  }
632  else
633  {
634  do
635  {
636  read_retval = fgets(read_buf, sizeof(read_buf), log_file);
637  /*DEBUG("Chunk read: %s",read_retval);*/
638  if (read_retval && strncmp(record_start_str, read_buf, strlen(record_start_str)) == 0) /* If a record started */
639  {
640  process_trans_record(log_file);
641  }
642  }
643  while (feof(log_file) == 0);
644  }
645  }
646  fclose(log_file);
647  }
648  }
649  g_free(selected_filename);
650  }
651  /* Start logging again */
652  xaccLogEnable();
653 
654  LEAVE("");
655 }
void qof_log_set_level(QofLogModule log_module, QofLogLevel level)
Set the logging level of the given log_module.
Definition: qoflog.cpp:291
void xaccLogDisable(void)
document me
Definition: TransLog.cpp:95
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
gboolean xaccFileIsCurrentLog(const gchar *name)
Test a filename to see if it is the name of the current logfile.
Definition: TransLog.cpp:141
void xaccLogEnable(void)
document me
Definition: TransLog.cpp:99

◆ gnc_file_ofx_import()

void gnc_file_ofx_import ( GtkWindow *  parent)

The gnc_file_ofx_import() routine will pop up a standard file selection dialogue asking the user to pick a OFX/QFX file.

If one is selected the OFX file is opened and read. Its contents are merged into the existing session (if any). The current session continues to remain open for editing.

Definition at line 1429 of file gnc-ofx-import.cpp.

1430 {
1431  extern int ofx_PARSER_msg;
1432  extern int ofx_DEBUG_msg;
1433  extern int ofx_WARNING_msg;
1434  extern int ofx_ERROR_msg;
1435  extern int ofx_INFO_msg;
1436  extern int ofx_STATUS_msg;
1437  GSList* selected_filenames = NULL;
1438  char *default_dir;
1439  GList *filters = NULL;
1440  ofx_info* info = NULL;
1441  GtkFileFilter* filter = gtk_file_filter_new ();
1442 
1443 
1444  ofx_PARSER_msg = false;
1445  ofx_DEBUG_msg = false;
1446  ofx_WARNING_msg = true;
1447  ofx_ERROR_msg = true;
1448  ofx_INFO_msg = true;
1449  ofx_STATUS_msg = false;
1450 
1451  DEBUG("gnc_file_ofx_import(): Begin...\n");
1452 
1453  default_dir = gnc_get_default_directory(GNC_PREFS_GROUP);
1454  gtk_file_filter_set_name (filter, _("Open/Quicken Financial Exchange file (*.ofx, *.qfx)"));
1455  gtk_file_filter_add_pattern (filter, "*.[oqOQ][fF][xX]");
1456  filters = g_list_prepend( filters, filter );
1457 
1458  selected_filenames = gnc_file_dialog_multi (parent,
1459  _("Select one or multiple OFX/QFX file(s) to process"),
1460  filters,
1461  default_dir,
1462  GNC_FILE_DIALOG_IMPORT);
1463  g_free(default_dir);
1464 
1465  if (selected_filenames)
1466  {
1467  /* Remember the directory as the default. */
1468  default_dir = g_path_get_dirname(static_cast<char*>(selected_filenames->data));
1469  gnc_set_default_directory(GNC_PREFS_GROUP, default_dir);
1470  g_free(default_dir);
1471 
1472  /* Look up the needed preferences */
1473  auto_create_commodity =
1474  gnc_prefs_get_bool (GNC_PREFS_GROUP_IMPORT, GNC_PREF_AUTO_COMMODITY);
1475 
1476  DEBUG("Opening selected file(s)");
1477  // Create the structure that holds the list of files to process and the statement info.
1478  info = g_new(ofx_info,1);
1479  info->num_trans_processed = 0;
1480  info->statement = NULL;
1481  info->last_investment_account = NULL;
1482  info->last_import_account = NULL;
1483  info->last_income_account = NULL;
1484  info->parent = parent;
1485  info->run_reconcile = FALSE;
1486  info->file_list = selected_filenames;
1487  info->trans_list = NULL;
1488  info->response = 0;
1489  // Call the aux import function.
1490  gnc_file_ofx_import_process_file (info);
1491  }
1492 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
#define GNC_PREFS_GROUP_IMPORT
The preferences used by the importer.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.

◆ gnc_gen_trans_assist_new()

GNCImportMainMatcher * gnc_gen_trans_assist_new ( GtkWidget *  parent,
GtkWidget *  assistant_page,
const gchar *  heading,
bool  all_from_same_account,
gint  match_date_hardlimit 
)

Add the Transaction matcher to an existing page of an assistant.

Must be called with the parent widget, ie. a vbox that the transaction matcher will be packed into. The data structure GNCImportMainMatcher is returned.

Parameters
parentThe parent widget
assistant_pageThe parent widget. This is the place the transaction matcher will be packed into.
headingThe heading label in the Importer window. May be NULL.
all_from_same_accountSet this to TRUE if ALL the transaction that will be added with gnc_gen_trans_list_add_trans are from the same source account. This will cause the account column to be hidden.
match_date_hardlimitThe number of days that a matching split may differ from the given transaction before it is discarded immediately. In other words, any split that is more distant from the given transaction than this match_date_hardlimit days will be ignored altogether. For use cases without paper checks (e.g. HBCI), values like 14 (days) might be appropriate, whereas for use cases with paper checks (e.g. OFX, QIF), values like 42 (days) seem more appropriate.
Returns
A pointer to the GNCImportMainMatcher which has been setup.

Definition at line 1775 of file import-main-matcher.cpp.

1780 {
1781  GNCImportMainMatcher *info = g_new0 (GNCImportMainMatcher, 1);
1782  info->main_widget = GTK_WIDGET(parent);
1783 
1784  /* load the interface */
1785  GtkBuilder *builder = gtk_builder_new ();
1786  gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_content");
1787 
1788  /* Pack content into Assistant page widget */
1789  GtkWidget *box = GTK_WIDGET(gtk_builder_get_object (builder, "transaction_matcher_content"));
1790  g_assert (box != NULL);
1791  gtk_box_pack_start (GTK_BOX(assistant_page), box, true, true, 6);
1792 
1793  // Set the name for this dialog so it can be easily manipulated with css
1794  gtk_widget_set_name (GTK_WIDGET(box), "gnc-id-import-transaction-content");
1795 
1796  /* setup the common parts */
1797  gnc_gen_trans_common_setup (info, parent, builder, heading,
1798  all_from_same_account, match_date_hardlimit);
1799 
1800  return info;
1801 }

◆ gnc_gen_trans_assist_start()

void gnc_gen_trans_assist_start ( GNCImportMainMatcher *  info)

This starts the import process for transaction from an assistant.

assistant button callback.

Parameters
info.A pointer to the GNCImportMainMatcher structure

Definition at line 1804 of file import-main-matcher.cpp.

1805 {
1806  on_matcher_ok_clicked (NULL, info);
1807 }

◆ gnc_gen_trans_list_add_tp_cb()

void gnc_gen_trans_list_add_tp_cb ( GNCImportMainMatcher *  info,
GNCTransactionProcessedCB  trans_processed_cb,
gpointer  user_data 
)

Add transaction processed callback to the transaction importer.

Parameters
infoThe Transaction Importer to use.
trans_processed_cbThe callback function.

Definition at line 1814 of file import-main-matcher.cpp.

1817 {
1818  info->user_data = user_data;
1819  info->transaction_processed_cb = trans_processed_cb;
1820 }

◆ gnc_gen_trans_list_add_trans()

void gnc_gen_trans_list_add_trans ( GNCImportMainMatcher *  gui,
Transaction *  trans 
)

Add a newly imported Transaction to the Transaction Importer.

The Importer takes over ownership of the passed transaction.

Parameters
guiThe Transaction Importer to use.
transThe Transaction to add. The must contain at least one split, and this split must have been associated with an account Only the first split will be used for matching. The transaction must NOT be committed. The Importer takes over ownership of the passed transaction.

Definition at line 2247 of file import-main-matcher.cpp.

2248 {
2249  gnc_gen_trans_list_add_trans_internal (gui, trans, 0, NULL);
2250 }

◆ gnc_gen_trans_list_add_trans_with_ref_id()

void gnc_gen_trans_list_add_trans_with_ref_id ( GNCImportMainMatcher *  gui,
Transaction *  trans,
guint32  ref_id 
)

Add a newly imported Transaction to the Transaction Importer and provide an external reference id for it.

The Importer takes over ownership of the passed transaction.

Parameters
guiThe Transaction Importer to use.
transThe Transaction to add. The must contain at least one split, and this split must have been associated with an account Only the first split will be used for matching. The transaction must NOT be committed. The Importer takes over ownership of the passed transaction.
ref_idReference id which links an external object to the transaction.

Definition at line 2253 of file import-main-matcher.cpp.

2254 {
2255  gnc_gen_trans_list_add_trans_internal (gui, trans, ref_id, NULL);
2256 }

◆ gnc_gen_trans_list_add_trans_with_split_data()

void gnc_gen_trans_list_add_trans_with_split_data ( GNCImportMainMatcher *  gui,
Transaction *  trans,
GNCImportLastSplitInfo lsplit 
)

Add a newly imported Transaction to the Transaction Importer.

The Importer takes over ownership of the passed transaction.

Parameters
guiThe Transaction Importer to use.
transThe Transaction to add. The must contain at least one split, and this split must have been associated with an account Only the first split will be used for matching. The transaction must NOT be committed. The Importer takes over ownership of the passed transaction.
lsplitStruct with additional parameters that may be used to generate the final split.

Definition at line 2258 of file import-main-matcher.cpp.

2261 {
2262  gnc_gen_trans_list_add_trans_internal (gui, trans, 0, lsplit);
2263 }

◆ gnc_gen_trans_list_append_text_widget()

GtkWidget * gnc_gen_trans_list_append_text_widget ( GNCImportMainMatcher *  info)

Returns the append_text widget of this dialog.

Parameters
infoA pointer to the GNCImportMainMatcher structure.
Returns
A GtkWidget pointer to the append_text widget.

Definition at line 2432 of file import-main-matcher.cpp.

2433 {
2434  g_assert (info);
2435  return info->append_text;
2436 }

◆ gnc_gen_trans_list_delete()

void gnc_gen_trans_list_delete ( GNCImportMainMatcher *  info)

Deletes the given object.

Definition at line 197 of file import-main-matcher.cpp.

198 {
199 
200  if (info == NULL)
201  return;
202 
203  GtkTreeModel *model = gtk_tree_view_get_model (info->view);
204  GtkTreeIter iter;
205  if (gtk_tree_model_get_iter_first (model, &iter))
206  {
207  do
208  {
209  GNCImportTransInfo *trans_info;
210  gtk_tree_model_get (model, &iter,
211  DOWNLOADED_COL_DATA, &trans_info,
212  -1);
213 
214  if (info->transaction_processed_cb)
215  {
216  info->transaction_processed_cb (trans_info, false,
217  info->user_data);
218  }
219  }
220  while (gtk_tree_model_iter_next (model, &iter));
221  }
222 
223  if (GTK_IS_DIALOG(info->main_widget))
224  {
225  gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->main_widget));
226  gnc_import_Settings_delete (info->user_settings);
227  gnc_unregister_gui_component (info->id);
228  gtk_widget_destroy (GTK_WIDGET(info->main_widget));
229  }
230  else
231  gnc_import_Settings_delete (info->user_settings);
232 
233  g_slist_free_full (info->temp_trans_list, (GDestroyNotify) gnc_import_TransInfo_delete);
234  info->temp_trans_list = NULL;
235 
236  // We've deferred balance computations on many accounts. Let's do it now that we're done.
237  update_all_balances (info);
238 
239  gnc_import_PendingMatches_delete (info->pending_matches);
240  g_hash_table_destroy (info->acct_id_hash);
241  g_hash_table_destroy (info->desc_hash);
242  g_hash_table_destroy (info->notes_hash);
243  g_hash_table_destroy (info->memo_hash);
244 
245  g_list_free_full (info->new_strings, (GDestroyNotify)g_free);
246 
247  g_free (info);
248 
249  gnc_gui_refresh_all ();
250 }
void gnc_import_TransInfo_delete(GNCImportTransInfo *info)
Destructor.
void gnc_import_Settings_delete(GNCImportSettings *settings)
Destructor.

◆ gnc_gen_trans_list_empty()

bool gnc_gen_trans_list_empty ( GNCImportMainMatcher *  info)

Checks whether there are no transactions to match.

Parameters
infoA pointer to the GNCImportMainMatcher structure.
Returns
A boolean indicating whether the transaction list is empty.

Definition at line 253 of file import-main-matcher.cpp.

254 {
255  g_assert (info);
256 
257  GtkTreeIter iter;
258  GtkTreeModel *model = gtk_tree_view_get_model (info->view);
259  // Check that both the tree model and the temporary list are empty.
260  return !gtk_tree_model_get_iter_first (model, &iter) && !info->temp_trans_list;
261 }

◆ gnc_gen_trans_list_get_reconcile_after_close_button()

GtkWidget * gnc_gen_trans_list_get_reconcile_after_close_button ( GNCImportMainMatcher *  info)

Returns the reconcile after close check button.

Parameters
infoA pointer to the GNCImportMainMatcher structure.
Returns
The check button.

Definition at line 2211 of file import-main-matcher.cpp.

2212 {
2213  return info->reconcile_after_close;
2214 }

◆ gnc_gen_trans_list_new()

GNCImportMainMatcher * gnc_gen_trans_list_new ( GtkWidget *  parent,
const gchar *  heading,
bool  all_from_same_account,
gint  match_date_hardlimit,
bool  show_all 
)

Create a new generic transaction dialog window and return it.

Parameters
parentThe parent GtkWidget. May be NULL.
headingThe heading label in the Importer window. May be NULL.
all_from_same_accountSet this to TRUE if ALL the transaction that will be added with gnc_gen_trans_list_add_trans are from the same source account. This will cause the account column to be hidden.
match_date_hardlimitThe number of days that a matching split may differ from the given transaction before it is discarded immediately. In other words, any split that is more distant from the given transaction than this match_date_hardlimit days will be ignored altogether. For use cases without paper checks (e.g. HBCI), values like 14 (days) might be appropriate, whereas for use cases with paper checks (e.g. OFX, QIF), values like 42 (days) seem more appropriate.
show_allif true, all widgets are shown
Returns
A pointer to the GNCImportMainMatcher which has been setup.

Definition at line 1721 of file import-main-matcher.cpp.

1726 {
1727  GNCImportMainMatcher *info = g_new0 (GNCImportMainMatcher, 1);
1728 
1729  /* Initialize the GtkDialog. */
1730  GtkBuilder *builder = gtk_builder_new ();
1731  gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_dialog");
1732  gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_matcher_content");
1733 
1734  info->main_widget = GTK_WIDGET(gtk_builder_get_object (builder, "transaction_matcher_dialog"));
1735  g_assert (info->main_widget != NULL);
1736 
1737  /* Pack the content into the dialog vbox */
1738  GtkWidget *pbox = GTK_WIDGET(gtk_builder_get_object (builder, "transaction_matcher_vbox"));
1739  GtkWidget *box = GTK_WIDGET(gtk_builder_get_object (builder, "transaction_matcher_content"));
1740  gtk_box_pack_start (GTK_BOX(pbox), box, true, true, 0);
1741 
1742  // Set the name for this dialog so it can be easily manipulated with css
1743  gtk_widget_set_name (GTK_WIDGET(info->main_widget), "gnc-id-import-matcher-transactions");
1744  gtk_widget_set_name (GTK_WIDGET(box), "gnc-id-import-transaction-content");
1745  gnc_widget_style_context_add_class (GTK_WIDGET(info->main_widget), "gnc-class-imports");
1746 
1747  /* setup the common parts */
1748  gnc_gen_trans_common_setup (info, parent, builder, heading,
1749  all_from_same_account, match_date_hardlimit);
1750 
1751  if (parent)
1752  gtk_window_set_transient_for (GTK_WINDOW(info->main_widget), GTK_WINDOW(parent));
1753 
1754  gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->main_widget), GTK_WINDOW(parent));
1755 
1756  if (show_all)
1757  gtk_widget_show_all (GTK_WIDGET(info->main_widget));
1758 
1759  // Register this UI, it needs to be closed when the session is closed.
1760  info->id = gnc_register_gui_component (IMPORT_MAIN_MATCHER_CM_CLASS,
1761  NULL, /* no refresh handler */
1762  (GNCComponentCloseHandler)gnc_gen_trans_list_delete,
1763  info);
1764  // This ensure this dialog is closed when the session is closed.
1765  gnc_gui_component_set_session (info->id, gnc_get_current_session());
1766 
1767  return info;
1768 }
void gnc_gen_trans_list_delete(GNCImportMainMatcher *info)
Deletes the given object.

◆ gnc_gen_trans_list_run()

bool gnc_gen_trans_list_run ( GNCImportMainMatcher *  info)

Run this dialog and return only after the user pressed Ok, Cancel, or closed the window.

This means that all actual importing will have been finished upon returning.

Parameters
infoA pointer to the GNCImportMainMatcher structure.
Returns
The boolean return value of the dialog run.

Definition at line 1823 of file import-main-matcher.cpp.

1824 {
1825  /* DEBUG("Begin"); */
1826  bool result = gtk_dialog_run (GTK_DIALOG (info->main_widget));
1827  /* DEBUG("Result was %d", result); */
1828 
1829  /* No destroying here since the dialog was already destroyed through
1830  the ok_clicked handlers. */
1831 
1832  return result;
1833 }

◆ gnc_gen_trans_list_show_all()

void gnc_gen_trans_list_show_all ( GNCImportMainMatcher *  info)

Shows widgets.

Parameters
infoA pointer to the GNCImportMainMatcher structure.

Definition at line 493 of file import-main-matcher.cpp.

494 {
495  g_assert (info);
496 
497  // Set initial state of Append checkbox to same as last import for this account.
498  // Get the import account from the first split in first transaction.
499  GSList *temp_trans_list = info->temp_trans_list;
500  if (!temp_trans_list)
501  {
502  gnc_info_dialog (GTK_WINDOW (info->main_widget), "%s", _("No new transactions were found in this import."));
503  return;
504  }
505  auto trans_info = static_cast<GNCImportTransInfo *>(temp_trans_list->data);
506  Split *first_split = gnc_import_TransInfo_get_fsplit (trans_info);
507  Account *account = xaccSplitGetAccount(first_split);
508  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (info->append_text),
509  xaccAccountGetAppendText(account));
510 
511  gnc_gen_trans_list_create_matches (info);
512  load_hash_tables (info);
513  resolve_conflicts (info);
514  gtk_widget_show_all (GTK_WIDGET(info->main_widget));
515  gnc_gen_trans_list_show_accounts_column (info);
516 }
gboolean xaccAccountGetAppendText(const Account *acc)
Get the "import-append-text" flag for an account.
Definition: Account.cpp:4284
Split * gnc_import_TransInfo_get_fsplit(const GNCImportTransInfo *info)
Returns the first split of the transaction of this TransInfo.
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53

◆ gnc_gen_trans_list_show_reconcile_after_close_button()

void gnc_gen_trans_list_show_reconcile_after_close_button ( GNCImportMainMatcher *  info,
bool  reconcile_after_close,
bool  active 
)

Show and set the reconcile after close check button.

Parameters
infoA pointer to the GNCImportMainMatcher structure.
reconcile_after_closeA bool that shows or hides the button.
activeA bool to set or clear the check button.

Definition at line 2202 of file import-main-matcher.cpp.

2205 {
2206  gtk_widget_set_visible (info->reconcile_after_close, reconcile_after_close);
2207  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->reconcile_after_close), active);
2208 }

◆ gnc_gen_trans_list_widget()

GtkWidget * gnc_gen_trans_list_widget ( GNCImportMainMatcher *  info)

Returns the widget of this dialog.

Parameters
infoA pointer to the GNCImportMainMatcher structure.
Returns
A GtkWidget pointer to the dialog's widget.

Definition at line 2425 of file import-main-matcher.cpp.

2426 {
2427  g_assert (info);
2428  return info->main_widget;
2429 }

◆ gnc_import_exists_online_id()

gboolean gnc_import_exists_online_id ( Transaction *  trans,
GHashTable *  acct_id_hash 
)

Checks whether the given transaction's online_id already exists in its parent account.

The given transaction has to be open for editing. If a matching online_id exists, the transaction is destroyed (!) and TRUE is returned, otherwise FALSE is returned.

Parameters
transThe transaction for which to check for an existing online_id.

Definition at line 1010 of file import-backend.cpp.

1011 {
1012 
1013  /* Look for an online_id in the first split */
1014  auto source_split = xaccTransGetSplit(trans, 0);
1015  g_assert(source_split);
1016 
1017  auto source_online_id = gnc_import_get_split_online_id (source_split);
1018 
1019  // No online id, no point in continuing. We'd crash if we tried.
1020  if (!source_online_id)
1021  return false;
1022 
1023  // Create a hash per account of a hash of all split IDs. Then the
1024  // test below will be fast if we have many transactions to import.
1025  auto dest_acct = xaccSplitGetAccount (source_split);
1026 
1027  auto online_id_hash = static_cast<GHashTable*>(g_hash_table_lookup (acct_id_hash, dest_acct));
1028 
1029  if (!online_id_hash)
1030  {
1031  online_id_hash = hash_account_online_ids (dest_acct);
1032  g_hash_table_insert (acct_id_hash, dest_acct, online_id_hash);
1033  }
1034 
1035  auto online_id_exists = g_hash_table_contains (online_id_hash, source_online_id);
1036  g_free (source_online_id);
1037  return online_id_exists;
1038 }
Split * xaccTransGetSplit(const Transaction *trans, int i)
Return a pointer to the indexed split in this transaction&#39;s split list.
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition: gmock-Split.cpp:53

◆ gnc_import_match_picker_run_and_close()

void gnc_import_match_picker_run_and_close ( GtkWidget *  parent,
GNCImportTransInfo *  transaction_info,
GNCImportPendingMatches *  pending_matches 
)

Run a match_picker dialog so that the selected-MatchInfo in the given trans_info is updated accordingly.

Run a match_picker dialog where the user should pick the best match for 'one' given transaction, so that the selected-MatchInfo in the given trans_info is updated accordingly.

This functions will only return after the user clicked Ok, Cancel, or Window-Close.

This functions will only return after the user clicked Ok, Cancel, or Window-Close.

The dialog uses the same functionality as the one created through gnc_import_add_trans(), except that its two listviews are shown above one another, and the listview of downloaded transactions shows only one transaction, namely, the given trans_info.

This function is used from the gnc-gen-transaction code.

Parameters
parentThe parent widget
transaction_infoThe TransInfo for which the user is supposed to pick a matching transaction.
pending_matchesList of transactions

Definition at line 432 of file import-match-picker.cpp.

434 {
435  GNCImportMatchPicker *matcher;
436  gint response;
437  GNCImportMatchInfo *old;
438  gboolean old_selected_manually;
439  g_assert (transaction_info);
440 
441  /* Create a new match_picker, even though it's stored in a
442  transmatcher struct :-) */
443  matcher = g_new0(GNCImportMatchPicker, 1);
444 
445  matcher->pending_matches = pending_matches;
446 
447  /* DEBUG("Init match_picker"); */
448  init_match_picker_gui(parent, matcher);
449 
450  /* Append this single transaction to the view and select it */
451  downloaded_transaction_append(matcher, transaction_info);
452 
453  old = gnc_import_TransInfo_get_selected_match (transaction_info);
454  old_selected_manually =
456 
457  /* Let this dialog run and close. */
458  /*DEBUG("Right before run and close");*/
459  gtk_window_set_modal(GTK_WINDOW(matcher->transaction_matcher), TRUE);
460  response = gtk_dialog_run (GTK_DIALOG (matcher->transaction_matcher));
461 
462  gnc_save_window_size(GNC_PREFS_GROUP,
463  GTK_WINDOW (matcher->transaction_matcher));
464  gtk_widget_destroy (matcher->transaction_matcher);
465  /*DEBUG("Right after run and close");*/
466  /* DEBUG("Response was %d.", response); */
467  if (response == GTK_RESPONSE_OK && matcher->selected_match_info != old)
468  {
469  /* OK was pressed */
471  matcher->selected_match_info,
472  TRUE);
473 
474  gnc_import_PendingMatches_remove_match (pending_matches,
475  old,
476  old_selected_manually);
477  gnc_import_PendingMatches_add_match (pending_matches,
478  matcher->selected_match_info,
479  TRUE);
480  }
481  gnc_import_Settings_delete (matcher->user_settings);
482  g_free (matcher);
483 }
void gnc_import_TransInfo_set_selected_match_info(GNCImportTransInfo *info, GNCImportMatchInfo *match, gboolean selected_manually)
Sets the currently selected match in this TransInfo.
void gnc_import_Settings_delete(GNCImportSettings *settings)
Destructor.
gboolean gnc_import_TransInfo_get_match_selected_manually(const GNCImportTransInfo *info)
Returns if the currently selected match was selected by the user.
GNCImportMatchInfo * gnc_import_TransInfo_get_selected_match(const GNCImportTransInfo *info)
Returns the currently selected match in this TransInfo.

◆ gnc_import_MatchInfo_get_probability()

gint gnc_import_MatchInfo_get_probability ( const GNCImportMatchInfo info)

Get the probability (confidence level) of this MatchInfo.

Parameters
infoCan be NULL, in which case the function returns 0

Definition at line 331 of file import-backend.cpp.

332 {
333  if (info)
334  return info->probability;
335  else
336  return 0;
337 }

◆ gnc_import_MatchInfo_get_split()

Split * gnc_import_MatchInfo_get_split ( const GNCImportMatchInfo info)

Get the split ('this-side split') of this MatchInfo.

Definition at line 324 of file import-backend.cpp.

325 {
326  g_assert (info);
327  return info->split;
328 }

◆ gnc_import_process_trans_item()

gboolean gnc_import_process_trans_item ( Account base_acc,
GNCImportTransInfo *  trans_info 
)

/brief – Processes one match according to its selected action.

This function is intended to be called when the importer dialog is finished.

It should be called once for each imported transaction and processes each ImportTransInfo according to its selected action: For GNCImport_ADD, the transaction is added etc. etc.

Each successful match is also stored in the match map of the given account, or if that argument is NULL, in the match map of each originating account.

Parameters
base_accThe account where each match should be stored. May be NULL, in which case each originating account will be used.
trans_infoThe ImportTransInfo item to process.
Returns
TRUE if the item has been processed.

Definition at line 846 of file import-backend.cpp.

848 {
849  g_assert (trans_info);
850  /*DEBUG("Iteration %d, action %d, split %s", i,
851  trans_info->action,
852  xaccTransGetDescription (gnc_import_TransInfo_get_trans
853  (trans_info)))*/
854  switch (gnc_import_TransInfo_get_action (trans_info))
855  {
856  case GNCImport_SKIP:
857  return false;
858  case GNCImport_ADD:
859  /* Transaction gets imported. */
860  if (!gnc_import_TransInfo_is_balanced(trans_info)
861  && gnc_import_TransInfo_get_destacc(trans_info))
862  {
863  /* Create the 'other' split. */
864  auto trans = gnc_import_TransInfo_get_trans (trans_info);
865  auto acct = gnc_import_TransInfo_get_destacc (trans_info);
866  auto split = xaccMallocSplit (gnc_account_get_book (acct));
867  xaccTransAppendSplit (trans, split);
868  xaccAccountInsertSplit (acct, split);
869  xaccSplitSetValue (split, trans_info->lsplit_value);
870  if (!gnc_numeric_zero_p (trans_info->lsplit_amount))
871  xaccSplitSetAmount (split, trans_info->lsplit_amount);
872  else
873  {
874  /* Bad! user asked to create a balancing split in an account with
875  * different currency/commodit than the transaction but didn't provide
876  * an exchange rate.
877  * Continue anyway pretenting split is in transaction currency. */
878  xaccSplitSetAmount (split, trans_info->lsplit_value);
879  PWARN("Missing exchange rate while adding transaction '%s', will assume rate of 1",
881  }
882  }
883 
885  /*Set reconcile date to today*/
887  gnc_time (nullptr));
888  /* Done editing. */
889  xaccTransCommitEdit(trans_info->trans);
890  xaccTransRecordPrice(trans_info->trans, PRICE_SOURCE_SPLIT_IMPORT);
891  return true;
892  case GNCImport_UPDATE:
893  {
894  auto selected_match = gnc_import_TransInfo_get_selected_match(trans_info);
895 
896  /* If there is no selection, ignore this transaction. */
897  if (!selected_match)
898  {
899  PWARN("No matching transaction to be cleared was chosen. Imported transaction will be ignored.");
900  break;
901  }
902 
903  /* Transaction gets not imported but the matching one gets
904  updated and reconciled. */
905  if (!gnc_import_MatchInfo_get_split(selected_match))
906  PERR("The split I am trying to update and reconcile is nullptr, shouldn't happen!");
907  else
908  {
909  /* Update and reconcile the matching transaction */
910  /*DEBUG("BeginEdit selected_match")*/
911  xaccTransBeginEdit(selected_match->trans);
912 
913  auto fsplit = gnc_import_TransInfo_get_fsplit(trans_info);
914  xaccTransSetDatePostedSecsNormalized(selected_match->trans,
916 
917  auto match_split_amount = xaccSplitGetAmount(selected_match->split);
918  xaccSplitSetAmount(selected_match->split, xaccSplitGetAmount(fsplit));
919  xaccSplitSetValue(selected_match->split, xaccSplitGetValue(fsplit));
920 
921  auto imbalance_value = gnc_import_TransInfo_get_dest_value(trans_info);
922  auto other_split = xaccSplitGetOtherSplit(selected_match->split);
923  if (!gnc_numeric_zero_p(imbalance_value) && other_split)
924  {
925  if (xaccSplitGetReconcile(other_split) == NREC)
926  {
927  xaccSplitSetValue(other_split, imbalance_value);
928  auto new_amt = gnc_import_TransInfo_get_dest_value(trans_info);
929  if (gnc_numeric_zero_p(new_amt))
930  {
931  auto other_split_amount = xaccSplitGetAmount(other_split);
932  auto price = gnc_numeric_div(match_split_amount, other_split_amount,
935 
936  new_amt = gnc_numeric_mul(xaccSplitGetAmount(fsplit), price,
939  }
940  xaccSplitSetAmount(other_split, new_amt);
941  }
942  else
943  {
944  /* else GC will automatically insert a split to equity
945  to balance the transaction */
946  PWARN("Updated transaction '%s', but not other split.",
947  xaccTransGetDescription(selected_match->trans));
948  }
949  }
950 
951  auto fs_memo = xaccSplitGetMemo (trans_info->first_split);
952  if (fs_memo && *fs_memo)
953  xaccSplitSetMemo(selected_match->split, fs_memo);
954 
955  update_desc_and_notes(trans_info);
956 
957  /*DEBUG("CommitEdit selected_match")*/
958  xaccTransCommitEdit(selected_match->trans);
959 
960  process_reconcile (base_acc, trans_info, selected_match);
961  }
962  }
963  return true;
964  case GNCImport_CLEAR:
965  {
966  auto selected_match = gnc_import_TransInfo_get_selected_match (trans_info);
967 
968  /* If there is no selection, ignore this transaction. */
969  if (!selected_match)
970  {
971  PWARN("No matching translaction to be cleared was chosen. Imported transaction will be ignored.");
972  break;
973  }
974 
975  /* Transaction gets not imported but the matching one gets
976  reconciled. */
977  if (!gnc_import_MatchInfo_get_split (selected_match))
978  PERR("The split I am trying to reconcile is nullptr, shouldn't happen!");
979  else
980  {
981  /* Reconcile the matching transaction */
982  process_reconcile(base_acc, trans_info, selected_match);
983  }
984  }
985  return true;
986  default:
987  DEBUG("Invalid GNCImportAction for this imported transaction.");
988  break;
989  }
990  /*DEBUG("End");*/
991  return false;
992 }
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:92
#define xaccTransAppendSplit(t, s)
Add a split to the transaction.
Definition: Transaction.h:381
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3))...
gnc_numeric gnc_import_TransInfo_get_dest_value(const GNCImportTransInfo *info)
Returns the destination split value for this TransInfo.
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
Split * gnc_import_TransInfo_get_fsplit(const GNCImportTransInfo *info)
Returns the first split of the transaction of this TransInfo.
Transaction * gnc_import_TransInfo_get_trans(const GNCImportTransInfo *info)
Returns the transaction of this TransInfo.
void xaccTransRecordPrice(Transaction *trans, PriceSource source)
The xaccTransRecordPrice() method iterates through the splits and and record the non-currency equival...
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
GNCImportAction gnc_import_TransInfo_get_action(const GNCImportTransInfo *info)
Returns the currently selected action for this TransInfo.
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
Split * gnc_import_MatchInfo_get_split(const GNCImportMatchInfo *info)
Get the split (&#39;this-side split&#39;) of this MatchInfo.
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account&#39;s commodity that the split should have...
Definition: gmock-Split.cpp:77
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
#define CREC
The Split has been cleared.
Definition: Split.h:71
Split * xaccMallocSplit(QofBook *book)
Constructor.
Definition: gmock-Split.cpp:37
void xaccSplitSetDateReconciledSecs(Split *split, time64 secs)
Set the date on which this split was reconciled by specifying the time as time64. ...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction&#39;s commodity.
Definition: gmock-Split.cpp:84
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated account...
Definition: Account.h:1048
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits...
Account * gnc_import_TransInfo_get_destacc(const GNCImportTransInfo *info)
Returns the &#39;other account&#39; of this transaction.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
Definition: gnc-numeric.h:167
time64 gnc_time(time64 *tbuf)
get the current time
Definition: gnc-date.cpp:261
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition: gmock-Split.cpp:99
GNCImportMatchInfo * gnc_import_TransInfo_get_selected_match(const GNCImportTransInfo *info)
Returns the currently selected match in this TransInfo.
#define GNC_DENOM_AUTO
Values that can be passed as the &#39;denom&#39; argument.
Definition: gnc-numeric.h:247
gboolean gnc_import_TransInfo_is_balanced(const GNCImportTransInfo *info)
Returns if the transaction stored in the TransInfo is currently balanced.
#define NREC
not reconciled or cleared
Definition: Split.h:74
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69

◆ gnc_import_select_account()

Account * gnc_import_select_account ( GtkWidget *  parent,
const gchar *  account_online_id_value,
gboolean  prompt_on_no_match,
const gchar *  account_human_description,
const gnc_commodity *  new_account_default_commodity,
GNCAccountType  new_account_default_type,
Account default_selection,
gboolean *  ok_pressed 
)

Must be called with a string containing a unique identifier for the account.

If an account with a matching online_id is found, the function immediately returns with a pointer to that account. Otherwise, the user is prompted to select a GnuCash account or create a new one (in both cases, the unique identifier is written to the account, so the user won't be prompted again). If the user refuses to select or create an account, NULL is returned.

Parameters
parentThe parent widget. Can be NULL.
account_online_id_valueThe string containing your unique account_id coming from some string of your module. This is the normal mode of operation. Can be NULL.

If account_online_id_value==NULL, you basically end up with an account selector that allows you to select an account whose GncGUID will be remembered elsewhere. You would fill account_human_description to tell the user what he is looking for. In this mode, the online_id field of the found account will not be touched. To use this mode, prompt_on_no_match must NOT be set to 0.

Parameters
account_human_descriptionA human-readable description of the account. Can be NULL. If it is not NULL, it will be shown before the id in the account matching dialog. It will also be used as the default account name if a new account is created.
new_account_default_commodityDefault commodity of the new account. Can be NULL. If not NULL, it will be the account's commodity if a new account is created. Also, if not NULL, the function will also warn the user if the found or created account's commodity doesn't match.
new_account_default_typeDefault account type of a new account. Can be NULL. If not ACCT_TYPE_NONE, it will be the account's type if a new account is created. If not ACCT_TYPE_NONE, the function will also warn the user if the found or created account's commodity doesn't match.
prompt_on_no_matchOnly active if no account with the account_online_id_value could be found in gnucash, or if online-id was NULL. In that case, if prompt_on_no_match is TRUE (nonzero), the user will be asked to create a new account. If prompt_on_no_match is FALSE (zero), this function will simply return NULL but will neither select nor create any account.
default_selectionIf not NULL, that account will be pre-selected by default.
ok_pressedA pointer to gboolean. If non-NULL, whether or not the picker dialog was closed by the user pressing ok will be stored in the parameter. If no dialog was created by the gnc_import_select_account() call, TRUE is always returned.
Returns
A pointer to the found or created Account, or NULL if no account was found or created.

Definition at line 339 of file import-account-matcher.cpp.

347 {
348 #define ACCOUNT_DESCRIPTION_MAX_SIZE 255
349  AccountPickerDialog * picker;
350  gint response;
351  Account * retval = NULL;
352  const gchar *retval_name = NULL;
353  GtkBuilder *builder;
354  GtkTreeSelection *selection;
355  GtkWidget * online_id_label;
356  gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE + 1] = "";
357  gboolean ok_pressed_retval = FALSE;
358 
359  ENTER("Default commodity received: %s", gnc_commodity_get_fullname( new_account_default_commodity));
360  DEBUG("Default account type received: %s", xaccAccountGetTypeStr( new_account_default_type));
361  picker = g_new0(AccountPickerDialog, 1);
362 
363  picker->account_human_description = account_human_description;
364  picker->new_account_default_commodity = new_account_default_commodity;
365  picker->new_account_default_type = new_account_default_type;
366 
367  /*DEBUG("Looking for account with online_id: \"%s\"", account_online_id_value);*/
368  if (account_online_id_value)
369  {
370  AccountOnlineMatch match = {NULL, 0, account_online_id_value};
371  retval = static_cast<Account*>(gnc_account_foreach_descendant_until (gnc_get_current_root_account (),
372  test_acct_online_id_match,
373  (void*)&match));
374  if (!retval && match.count == 1 &&
375  new_account_default_type == ACCT_TYPE_NONE)
376  retval = match.partial_match;
377  }
378  if (!retval && prompt_on_no_match)
379  {
380  /* load the interface */
381  builder = gtk_builder_new();
382  gnc_builder_add_from_file (builder, "dialog-import.glade", "account_new_icon");
383  gnc_builder_add_from_file (builder, "dialog-import.glade", "account_picker_dialog");
384  /* connect the signals in the interface */
385  if (builder == NULL)
386  {
387  PERR("Error opening the glade builder interface");
388  }
389  picker->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_picker_dialog"));
390  picker->whbox = GTK_WIDGET(gtk_builder_get_object (builder, "warning_hbox"));
391  picker->warning = GTK_WIDGET(gtk_builder_get_object (builder, "warning_label"));
392  picker->ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "okbutton"));
393 
394  // Set the name for this dialog so it can be easily manipulated with css
395  gtk_widget_set_name (GTK_WIDGET(picker->dialog), "gnc-id-import-account-picker");
396  gnc_widget_style_context_add_class (GTK_WIDGET(picker->dialog), "gnc-class-imports");
397 
398  if (parent)
399  gtk_window_set_transient_for (GTK_WINDOW (picker->dialog),
400  GTK_WINDOW (parent));
401 
402  gnc_restore_window_size (GNC_PREFS_GROUP,
403  GTK_WINDOW(picker->dialog), GTK_WINDOW (parent));
404 
405  picker->account_tree_sw = GTK_WIDGET(gtk_builder_get_object (builder, "account_tree_sw"));
406  online_id_label = GTK_WIDGET(gtk_builder_get_object (builder, "online_id_label"));
407 
408  //printf("gnc_import_select_account(): Fin get widget\n");
409 
410  if (account_human_description != NULL)
411  {
412  strncat(account_description_text, account_human_description,
413  ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
414  strncat(account_description_text, "\n",
415  ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
416  }
417  if (account_online_id_value != NULL)
418  {
419  strncat(account_description_text, _("(Full account ID: "),
420  ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
421  strncat(account_description_text, account_online_id_value,
422  ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
423  strncat(account_description_text, ")",
424  ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
425  }
426  gtk_label_set_text((GtkLabel*)online_id_label, account_description_text);
427  build_acct_tree(picker);
428  gtk_window_set_modal(GTK_WINDOW(picker->dialog), TRUE);
429  g_signal_connect(picker->account_tree, "row-activated",
430  G_CALLBACK(account_tree_row_activated_cb), picker);
431 
432  /* Connect key press event so we can expand the tree when the user starts typing, allowing
433  * any subaccount to match */
434  g_signal_connect (picker->account_tree, "key-press-event", G_CALLBACK (account_tree_key_press_cb), picker->account_tree);
435 
436  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(picker->account_tree));
437  g_signal_connect(selection, "changed",
438  G_CALLBACK(account_tree_row_changed_cb), picker);
439 
440  gnc_tree_view_account_set_selected_account(picker->account_tree, default_selection);
441 
442  do
443  {
444  response = gtk_dialog_run(GTK_DIALOG(picker->dialog));
445  switch (response)
446  {
447  case GNC_RESPONSE_NEW:
448  gnc_import_add_account(NULL, picker);
449  response = GTK_RESPONSE_OK;
450  /* no break */
451 
452  case GTK_RESPONSE_OK:
453  retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
454  if (!retval)
455  {
456  response = GNC_RESPONSE_NEW;
457  break;
458  }
459  retval_name = xaccAccountGetName(retval);
460  DEBUG("Selected account %p, %s", retval, retval_name ? retval_name : "(null)");
461 
462  /* See if the selected account is a placeholder. */
463  if (retval && xaccAccountGetPlaceholder (retval))
464  {
465  show_placeholder_warning (picker, retval_name);
466  response = GNC_RESPONSE_NEW;
467  break;
468  }
469 
470  if (account_online_id_value)
471  {
472  gnc_import_set_acc_online_id(retval, account_online_id_value);
473  }
474  ok_pressed_retval = TRUE;
475  break;
476 
477  default:
478  ok_pressed_retval = FALSE;
479  break;
480  }
481  }
482  while (response == GNC_RESPONSE_NEW);
483 
484  g_object_unref(G_OBJECT(builder));
485  gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(picker->dialog));
486  gtk_widget_destroy(picker->dialog);
487  }
488  else
489  {
490  retval_name = retval ? xaccAccountGetName(retval) : NULL;
491  ok_pressed_retval = TRUE; /* There was no dialog involved, so the computer "pressed" ok */
492  }
493  /*FIXME: DEBUG("WRITEME: gnc_import_select_account() Here we should check if account type is compatible, currency matches, etc.\n"); */
494  g_free(picker);
495  /*DEBUG("Return value: %p%s%s%s",retval,", account name:",xaccAccountGetName(retval),"\n");*/
496  if (ok_pressed != NULL)
497  {
498  *ok_pressed = ok_pressed_retval;
499  }
500  LEAVE("Selected account %p, %s", retval, retval_name ? retval_name : "(null)");
501  return retval;
502 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling &#39;func&#39; on each...
Definition: Account.cpp:3232
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
void gnc_tree_view_account_set_selected_account(GncTreeViewAccount *view, Account *account)
This function selects an account in the account tree view.
gboolean xaccAccountGetPlaceholder(const Account *acc)
Get the "placeholder" flag for an account.
Definition: Account.cpp:4272
Account * gnc_tree_view_account_get_selected_account(GncTreeViewAccount *view)
This function returns the account associated with the selected item in the account tree view...
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
const char * xaccAccountGetName(const Account *acc)
Get the account&#39;s name.
Definition: Account.cpp:3280
const char * xaccAccountGetTypeStr(GNCAccountType type)
The xaccAccountGetTypeStr() routine returns a string suitable for use in the GUI/Interface.
Definition: Account.cpp:4523
Not a type.
Definition: Account.h:105

◆ gnc_import_select_commodity()

gnc_commodity * gnc_import_select_commodity ( const char *  cusip,
gboolean  ask_on_unknown,
const char *  default_fullname,
const char *  default_mnemonic 
)

Must be called with a string containing a unique identifier for the commodity.

If an commodity with a matching cusip is found, the function immediately returns with a pointer to that commodity. Otherwise, the user may be prompted to select a GnuCash commodity or create a new one (in both cases, the cusip is written to the commodity's cusip field, overwriting anything that was there before.

Parameters
cusipThe string containing the code for which you want a matching commodity. A CUISP code or similar UNIQUE code. The stock ticker is NOT appropriate, unless you have no other option. Must be non-NULL.
ask_on_unknownIf the cusip value is unknown and this parameter is false (zero), the function returns NULL. Otherwise the user will be asked to select an existing or create a new commodity.
default_fullnameA human-readable description of the commodity, such as the stock name. Can be NULL. If it is not NULL, it will be shown to the user when selecting a commodity. It will also be used as the default if a new commodity is created.
default_mnemonicUsually the stock ticker or similar. Can be NULL. If it is not NULL, it will be shown to the user when selecting a commodity. It will also be used as the default if a new commodity is created.
Returns
A pointer to the found or created commodity, or NULL if no commodity was found or created.

Definition at line 53 of file import-commodity-matcher.cpp.

57 {
58  const gnc_commodity_table * commodity_table = gnc_get_current_commodities ();
59  gnc_commodity * retval = NULL;
60  DEBUG("Default fullname received: %s", default_fullname);
61  DEBUG("Default mnemonic received: %s", default_mnemonic);
62 
63  g_return_val_if_fail(cusip, NULL);
64  DEBUG("Looking for commodity with exchange_code: %s", cusip);
65 
66  g_assert(commodity_table);
67  GList *namespace_list = gnc_commodity_table_get_namespaces(commodity_table);
68 
69  for (GList *n = namespace_list; !retval && n; n = g_list_next (n))
70  {
71  auto ns = static_cast<const char*>(n->data);
72  DEBUG("Looking at namespace %s", ns);
73  GList *comm_list = gnc_commodity_table_get_commodities (commodity_table, ns);
74  for (GList *m = comm_list; !retval && m; m = g_list_next (m))
75  {
76  auto com = static_cast<gnc_commodity*>(m->data);
77  DEBUG("Looking at commodity %s", gnc_commodity_get_fullname (com));
78  if (!g_strcmp0 (gnc_commodity_get_cusip (com), cusip))
79  {
80  retval = com;
81  DEBUG("Commodity %s matches.", gnc_commodity_get_fullname (com));
82  }
83  }
84  g_list_free (comm_list);
85  }
86 
87  g_list_free(namespace_list);
88 
89  if (retval == NULL && ask_on_unknown != 0)
90  {
91  const gchar *message =
92  _("Please select a commodity to match the following exchange "
93  "specific code. Please note that the exchange code of the "
94  "commodity you select will be overwritten.");
96  NULL,
98  message,
99  cusip,
100  default_fullname,
101  default_mnemonic);
102 
103  }
104  /* There seems to be a problem here - if the matched commodity does not
105  have a cusip defined (gnc_commodity_get_cusip returns NULL) then
106  it does not get overwritten - which is not consistent with the
107  message - so Im adding it to do this. Looks like this is all
108  that was needed to fix the cash value used as stock units problem
109  for pre-defined commodities which didn't have the cusip defined! */
110  if (retval != NULL &&
111  gnc_commodity_get_cusip(retval) != NULL &&
112  cusip != NULL &&
113  (strncmp(gnc_commodity_get_cusip(retval), cusip, strlen(cusip)) != 0))
114  {
115  gnc_commodity_set_cusip(retval, cusip);
116  }
117  else if (gnc_commodity_get_cusip(retval) == NULL && cusip != NULL)
118  {
119  gnc_commodity_set_cusip(retval, cusip);
120  }
121  return retval;
122 }
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
Retrieve the &#39;exchange code&#39; for the specified commodity.
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
Dialog box should allow selection of anything.
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
Return a list of all namespaces in the commodity table.
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the &#39;exchange code&#39; for the specified commodity.
gnc_commodity * gnc_ui_select_commodity_modal_full(gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode, const char *user_message, const char *cusip, const char *fullname, const char *mnemonic)
Ask the user to select a commodity from the existing set of commodities.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
Return a list of all commodities in the commodity table that are in the given namespace.

◆ gnc_import_Settings_get_fuzzy_amount()

double gnc_import_Settings_get_fuzzy_amount ( GNCImportSettings *  settings)

Return the allowed amount range for fuzzy amount matching.

Returns
The allowed amount range for fuzzy amount matching, in the users default commodity.

Definition at line 122 of file import-settings.cpp.

123 {
124  g_assert (settings);
125  return settings->fuzzy_amount;
126 }

◆ gnc_import_Settings_get_match_date_hardlimit()

gint gnc_import_Settings_get_match_date_hardlimit ( const GNCImportSettings *  settings)

Returns the hard-limiting number of days that a matching split may differ.

Definition at line 188 of file import-settings.cpp.

189 {
190  g_assert(s);
191  return s->match_date_hardlimit;
192 }

◆ gnc_import_Settings_set_match_date_hardlimit()

void gnc_import_Settings_set_match_date_hardlimit ( GNCImportSettings *  settings,
gint  match_date_hardlimit 
)
Parameters
match_date_hardlimitThe number of days that a matching split may differ from the given transaction before it is discarded immediately. In other words, any split that is more distant from the given transaction than this match_date_hardlimit days will be ignored altogether. For use cases without paper checks (e.g. HBCI), values like 14 (days) might be appropriate, whereas for use cases with paper checks (e.g. OFX, QIF), values like 42 (days) seem more appropriate.

Definition at line 182 of file import-settings.cpp.

183 {
184  g_assert(s);
185  s->match_date_hardlimit = m;
186 }

◆ gnc_import_TransInfo_get_action()

GNCImportAction gnc_import_TransInfo_get_action ( const GNCImportTransInfo *  info)

Returns the currently selected action for this TransInfo.

Definition at line 191 of file import-backend.cpp.

192 {
193  g_assert (info);
194  return info->action;
195 }

◆ gnc_import_TransInfo_get_dest_amount()

gnc_numeric gnc_import_TransInfo_get_dest_amount ( const GNCImportTransInfo *  info)

Returns the destination split amount for this TransInfo.

Definition at line 276 of file import-backend.cpp.

277 {
278  g_assert (info);
279  return info->lsplit_amount;
280 }

◆ gnc_import_TransInfo_get_dest_value()

gnc_numeric gnc_import_TransInfo_get_dest_value ( const GNCImportTransInfo *  info)

Returns the destination split value for this TransInfo.

Definition at line 283 of file import-backend.cpp.

284 {
285  g_assert (info);
286  return info->lsplit_value;
287 }

◆ gnc_import_TransInfo_get_destacc()

Account * gnc_import_TransInfo_get_destacc ( const GNCImportTransInfo *  info)

Returns the 'other account' of this transaction.

May return NULL.

Definition at line 210 of file import-backend.cpp.

211 {
212  g_assert (info);
213  return info->dest_acc;
214 }

◆ gnc_import_TransInfo_get_destacc_selected_manually()

gboolean gnc_import_TransInfo_get_destacc_selected_manually ( const GNCImportTransInfo *  info)

Returns if the currently selected destination account for auto-matching was selected by the user.

Definition at line 231 of file import-backend.cpp.

232 {
233  g_assert (info);
234  return info->dest_acc_selected_manually;
235 }

◆ gnc_import_TransInfo_get_fsplit()

Split * gnc_import_TransInfo_get_fsplit ( const GNCImportTransInfo *  info)

Returns the first split of the transaction of this TransInfo.

Definition at line 160 of file import-backend.cpp.

161 {
162  g_assert (info);
163  return info->first_split;
164 }

◆ gnc_import_TransInfo_get_match_list()

GList * gnc_import_TransInfo_get_match_list ( const GNCImportTransInfo *  info)

Returns the stored list of possible matches.

Definition at line 125 of file import-backend.cpp.

126 {
127  g_assert (info);
128  return info->match_list;
129 }

◆ gnc_import_TransInfo_get_match_selected_manually()

gboolean gnc_import_TransInfo_get_match_selected_manually ( const GNCImportTransInfo *  info)

Returns if the currently selected match was selected by the user.

Definition at line 184 of file import-backend.cpp.

185 {
186  g_assert (info);
187  return info->selected_match_info.selected_manually;
188 }

◆ gnc_import_TransInfo_get_price()

gnc_numeric gnc_import_TransInfo_get_price ( const GNCImportTransInfo *  info)

Returns the exchange rate for this TransInfo.

Definition at line 253 of file import-backend.cpp.

254 {
255  g_assert (info);
256  return info->lsplit_price;
257 }

◆ gnc_import_TransInfo_get_ref_id()

guint32 gnc_import_TransInfo_get_ref_id ( const GNCImportTransInfo *  info)

Returns the reference id for this TransInfo.

Definition at line 238 of file import-backend.cpp.

239 {
240  g_assert (info);
241  return info->ref_id;
242 }

◆ gnc_import_TransInfo_get_selected_match()

GNCImportMatchInfo * gnc_import_TransInfo_get_selected_match ( const GNCImportTransInfo *  info)

Returns the currently selected match in this TransInfo.

Definition at line 167 of file import-backend.cpp.

168 {
169  g_assert (info);
170  return info->selected_match_info.selected_match;
171 }

◆ gnc_import_TransInfo_get_trans()

Transaction * gnc_import_TransInfo_get_trans ( const GNCImportTransInfo *  info)

Returns the transaction of this TransInfo.

Definition at line 146 of file import-backend.cpp.

147 {
148  g_assert (info);
149  return info->trans;
150 }

◆ gnc_import_TransInfo_init_matches()

void gnc_import_TransInfo_init_matches ( GNCImportTransInfo *  trans_info,
GNCImportSettings *  settings 
)

Iterates through all splits of trans_info's originating account match list.

Iterates through all splits of the originating account of trans_info.

Sorts the resulting list and sets the selected_match and action fields in the trans_info.

Sorts the resulting list and sets the selected_match and action fields in the trans_info.

Parameters
trans_infoThe TransInfo for which the matches should be found, sorted, and selected.
settingsThe structure that holds all the user preferences.

Definition at line 1118 of file import-backend.cpp.

1120 {
1121  g_assert (trans_info);
1122 
1123  if (trans_info->match_list)
1124  {
1125  trans_info->match_list = g_list_sort(trans_info->match_list,
1126  compare_probability);
1127  auto best_match = static_cast<GNCImportMatchInfo*>(g_list_nth_data(trans_info->match_list, 0));
1128  gnc_import_TransInfo_set_selected_match_info (trans_info, best_match, false);
1129  if (best_match &&
1130  best_match->probability >= gnc_import_Settings_get_clear_threshold(settings))
1131  {
1133  best_match->update_proposed)
1134  trans_info->action = GNCImport_UPDATE;
1135  else
1136  trans_info->action = GNCImport_CLEAR;
1137  }
1138  else if (!best_match ||
1139  best_match->probability <= gnc_import_Settings_get_add_threshold(settings))
1140  trans_info->action = GNCImport_ADD;
1142  trans_info->action = GNCImport_SKIP;
1144  trans_info->action = GNCImport_UPDATE;
1145  else
1146  trans_info->action = GNCImport_ADD;
1147  }
1148  else
1149  trans_info->action = GNCImport_ADD;
1150 
1151 
1152  trans_info->previous_action = trans_info->action;
1153 }
gint gnc_import_Settings_get_clear_threshold(GNCImportSettings *settings)
Return the selected threshold.
void gnc_import_TransInfo_set_selected_match_info(GNCImportTransInfo *info, GNCImportMatchInfo *match, gboolean selected_manually)
Sets the currently selected match in this TransInfo.
gboolean gnc_import_Settings_get_action_update_enabled(GNCImportSettings *settings)
Return the selected action is enable state.
gboolean gnc_import_Settings_get_action_skip_enabled(GNCImportSettings *settings)
Return the selected action is enable state.
gint gnc_import_Settings_get_add_threshold(GNCImportSettings *settings)
Return the selected threshold.

◆ gnc_import_TransInfo_is_balanced()

gboolean gnc_import_TransInfo_is_balanced ( const GNCImportTransInfo *  info)

Returns if the transaction stored in the TransInfo is currently balanced.

Definition at line 153 of file import-backend.cpp.

154 {
155  g_assert (info);
157 }
Transaction * gnc_import_TransInfo_get_trans(const GNCImportTransInfo *info)
Returns the transaction of this TransInfo.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
The xaccTransGetImbalanceValue() method returns the total value of the transaction.

◆ gnc_import_TransInfo_new()

GNCImportTransInfo * gnc_import_TransInfo_new ( Transaction *  trans,
Account base_acc 
)

Create a new object of GNCImportTransInfo here.

Allocates a new TransInfo object, with the Transaction 'trans' already stored in there.

Also, this already checks the account's match map for automated destination account matching. The given account may be NULL, in which case the match map of the originating account will be used.

Parameters
transThe transaction that this TransInfo should work with.
base_accAccount that will provide the match map to lookup a destination account. This may be NULL, in which case the match map of the originating account will be used.

Definition at line 1083 of file import-backend.cpp.

1084 {
1085  g_assert (trans);
1086 
1087  auto t_info = g_new0(GNCImportTransInfo, 1);
1088 
1089  t_info->trans = trans;
1090  /* Only use first split, the source split */
1091  auto split = xaccTransGetSplit(trans, 0);
1092  g_assert(split);
1093  t_info->first_split = split;
1094 
1095  /* Try to find a previously selected destination account
1096  string match for the ADD action */
1098  matchmap_find_destination (base_acc, t_info),
1099  false);
1100 
1101  return t_info;
1102 }
Split * xaccTransGetSplit(const Transaction *trans, int i)
Return a pointer to the indexed split in this transaction&#39;s split list.
void gnc_import_TransInfo_set_destacc(GNCImportTransInfo *info, Account *acc, gboolean selected_manually)
Set the &#39;other account&#39; of this transaction (used for auto-balance if needed).

◆ gnc_import_TransInfo_set_action()

void gnc_import_TransInfo_set_action ( GNCImportTransInfo *  info,
GNCImportAction  action 
)

Set the action for this TransInfo.

Also sets the previous action.

Definition at line 198 of file import-backend.cpp.

200 {
201  g_assert (info);
202  if (action != info->action)
203  {
204  info->previous_action = info->action;
205  info->action = action;
206  }
207 }

◆ gnc_import_TransInfo_set_append_text()

void gnc_import_TransInfo_set_append_text ( GNCImportTransInfo *  info,
gboolean  append_text 
)

Set the append_text for this TransInfo.

Definition at line 315 of file import-backend.cpp.

317 {
318  g_assert (info);
319  info->append_text = append_text;
320 }

◆ gnc_import_TransInfo_set_destacc()

void gnc_import_TransInfo_set_destacc ( GNCImportTransInfo *  info,
Account acc,
gboolean  selected_manually 
)

Set the 'other account' of this transaction (used for auto-balance if needed).

May be set to NULL.

Parameters
selected_manuallyTRUE or FALSE; Was this account set as a result of a selection by the user or by an algorithm?

Definition at line 215 of file import-backend.cpp.

218 {
219  g_assert (info);
220  info->dest_acc = acc;
221  info->dest_acc_selected_manually = selected_manually;
222 
223  /* Store the mapping to the other account in the MatchMap. */
224  if (selected_manually)
225  matchmap_store_destination (nullptr, info, false);
226 
227  trans_info_calculate_dest_amount (info);
228 }

◆ gnc_import_TransInfo_set_price()

void gnc_import_TransInfo_set_price ( GNCImportTransInfo *  info,
gnc_numeric  lprice 
)

Set the exchange rate for this TransInfo.

Definition at line 260 of file import-backend.cpp.

262 {
263  g_assert (info);
264  info->lsplit_price = lprice;
265  /* if a valid price is explicitly set, assume the user wants to
266  * use it to calculate balance split amount.
267  * Ensure this gets recalculated */
268  if (gnc_numeric_check (lprice) == 0)
269  {
270  info->lsplit_amount_selected_manually = false;
271  trans_info_calculate_dest_amount(info);
272  }
273 }
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.

◆ gnc_import_TransInfo_set_ref_id()

void gnc_import_TransInfo_set_ref_id ( GNCImportTransInfo *  info,
guint32  ref_id 
)

Set the reference id for this TransInfo.

Definition at line 245 of file import-backend.cpp.

247 {
248  g_assert (info);
249  info->ref_id = ref_id;
250 }

◆ gnc_import_TransInfo_set_selected_match_info()

void gnc_import_TransInfo_set_selected_match_info ( GNCImportTransInfo *  info,
GNCImportMatchInfo match,
gboolean  selected_manually 
)

Sets the currently selected match in this TransInfo.

Parameters
selected_manuallyTRUE or FALSE; Was this match set as a result of a selection by the user or by an algorithm?

Definition at line 174 of file import-backend.cpp.

177 {
178  g_assert (info);
179  info->selected_match_info.selected_match = match;
180  info->selected_match_info.selected_manually = selected_manually;
181 }

◆ on_matcher_help_clicked()

void on_matcher_help_clicked ( GtkButton *  button,
gpointer  user_data 
)

This allows for the transaction help dialog to be started from the assistant button callback.

Parameters
button.The button widget clicked on in the call back.
user_data.A pointer to a structure.

Definition at line 623 of file import-main-matcher.cpp.

624 {
625  auto info = static_cast<GNCImportMainMatcher*>(user_data);
626 
627  GtkBuilder *builder = gtk_builder_new ();
628  gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer2");
629  gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer3");
630  gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer4");
631  gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer5");
632  gnc_builder_add_from_file (builder, "dialog-import.glade", "textbuffer1");
633  gnc_builder_add_from_file (builder, "dialog-import.glade", "matcher_help_dialog");
634 
635  const gchar *class_extension = NULL;
636  if (info->dark_theme == true)
637  class_extension = "-dark";
638 
639  gchar *int_required_class = g_strconcat (CSS_INT_REQUIRED_CLASS, class_extension, NULL);
640  gchar *int_prob_required_class = g_strconcat (CSS_INT_PROB_REQUIRED_CLASS, class_extension, NULL);
641  gchar *int_not_required_class = g_strconcat (CSS_INT_NOT_REQUIRED_CLASS, class_extension, NULL);
642 
643  GtkWidget *box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_required_box"));
644  gnc_widget_style_context_add_class (GTK_WIDGET(box), int_required_class);
645 
646  box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_probably_required_box"));
647  gnc_widget_style_context_add_class (GTK_WIDGET(box), int_prob_required_class);
648 
649  box = GTK_WIDGET(gtk_builder_get_object (builder, "intervention_not_required_box"));
650  gnc_widget_style_context_add_class (GTK_WIDGET(box), int_not_required_class);
651 
652  GtkWidget *help_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "matcher_help_dialog"));
653  gtk_window_set_transient_for (GTK_WINDOW(help_dialog), GTK_WINDOW(info->main_widget));
654 
655  // Set the name for this dialog so it can be easily manipulated with css
656  gtk_widget_set_name (GTK_WIDGET(help_dialog), "gnc-id-import-matcher-help");
657  gnc_widget_style_context_add_class (GTK_WIDGET(help_dialog), "gnc-class-imports");
658 
659  /* Connect the signals */
660  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, help_dialog);
661 
662  g_object_unref (G_OBJECT(builder));
663 
664  g_free (int_required_class);
665  g_free (int_prob_required_class);
666  g_free (int_not_required_class);
667 
668  gtk_widget_show (help_dialog);
669 }

◆ split_find_match()

void split_find_match ( GNCImportTransInfo *  trans_info,
Split *  split,
gint  display_threshold,
gint  date_threshold,
gint  date_not_threshold,
double  fuzzy_amount_difference 
)

The transaction matching heuristics are here.

Evaluates the match between trans_info and split using the provided parameters.

Parameters
trans_infoThe TransInfo for the imported transaction
splitThe register split that should be evaluated for a match.
display_thresholdMinimum match score to include split in the list of matches.
date_thresholdMaximum number of days a match considered likely.
date_not_thresholdMinimum number of days a match is considered unlikely.
fuzzy_amount_differenceMaximum amount difference to consider the match good.

Definition at line 560 of file import-backend.cpp.

566 {
567  gint prob = 0;
568 
569  auto new_trans = gnc_import_TransInfo_get_trans (trans_info);
570  auto new_trans_fsplit = gnc_import_TransInfo_get_fsplit (trans_info);
571 
572  /* Matching heuristics */
573 
574  /* Amount heuristics */
575  auto downloaded_split_amount =
576  gnc_numeric_to_double (xaccSplitGetAmount(new_trans_fsplit));
577  /*DEBUG(" downloaded_split_amount=%f", downloaded_split_amount);*/
578  auto match_split_amount = gnc_numeric_to_double(xaccSplitGetAmount(split));
579  /*DEBUG(" match_split_amount=%f", match_split_amount);*/
580  if (fabs(downloaded_split_amount - match_split_amount) < 1e-6)
581  /* bug#347791: Double type shouldn't be compared for exact
582  equality, so we're using fabs() instead. */
583  /*if (gnc_numeric_equal(xaccSplitGetAmount
584  (new_trans_fsplit),
585  xaccSplitGetAmount(split)))
586  -- gnc_numeric_equal is an expensive function call */
587  {
588  prob = prob + 3;
589  /*DEBUG("heuristics: probability + 3 (amount)");*/
590  }
591  else if (fabs (downloaded_split_amount - match_split_amount) <=
592  fuzzy_amount_difference)
593  {
594  /* ATM fees are sometimes added directly in the transaction.
595  So you withdraw 100$ and get charged 101,25$ in the same
596  transaction */
597  prob = prob + 2;
598  /*DEBUG("heuristics: probability + 2 (amount)");*/
599  }
600  else
601  {
602  /* If a transaction's amount doesn't match within the
603  threshold, it's very unlikely to be the same transaction
604  so we give it an extra -5 penalty */
605  prob = prob - 5;
606  /* DEBUG("heuristics: probability - 1 (amount)"); */
607  }
608 
609  /* Date heuristics */
610  auto match_time = xaccTransGetDate (xaccSplitGetParent (split));
611  auto download_time = xaccTransGetDate (new_trans);
612  auto datediff_day = llabs(match_time - download_time) / 86400;
613  /* Sorry, there are not really functions around at all that
614  provide for less hacky calculation of days of date
615  differences. Whatever. On the other hand, the difference
616  calculation itself will work regardless of month/year
617  turnarounds. */
618  /*DEBUG("diff day %d", datediff_day);*/
619  if (datediff_day == 0)
620  {
621  prob = prob + 3;
622  /*DEBUG("heuristics: probability + 3 (date)");*/
623  }
624  else if (datediff_day <= date_threshold)
625  {
626  prob = prob + 2;
627  /*DEBUG("heuristics: probability + 2 (date)");*/
628  }
629  else if (datediff_day > date_not_threshold)
630  {
631  /* Extra penalty if that split lies awfully far away from
632  the given one. */
633  prob = prob - 5;
634  /*DEBUG("heuristics: probability - 5 (date)"); */
635  /* Changed 2005-02-21: Revert the hard-limiting behaviour
636  back to the previous large penalty. (Changed 2004-11-27:
637  The penalty is so high that we can forget about this
638  split anyway and skip the rest of the tests.) */
639  }
640 
641  /* Check if date and amount are identical */
642  auto update_proposed = (prob < 6);
643 
644  /* Check number heuristics */
645  auto new_trans_str = gnc_get_num_action(new_trans, new_trans_fsplit);
646  if (new_trans_str && *new_trans_str)
647  {
648  char *endptr;
649  auto conversion_ok = true;
650 
651  /* To distinguish success/failure after strtol call */
652  errno = 0;
653  auto new_trans_number = strtol(new_trans_str, &endptr, 10);
654  /* Possible addressed problems: over/underflow, only non
655  numbers on string and string empty */
656  conversion_ok = !(errno || endptr == new_trans_str);
657 
658  auto split_str = gnc_get_num_action (xaccSplitGetParent (split), split);
659  errno = 0;
660  auto split_number = strtol(split_str, &endptr, 10);
661  conversion_ok = !(errno || endptr == split_str);
662 
663  if ( (conversion_ok && (split_number == new_trans_number)) ||
664  (g_strcmp0(new_trans_str, split_str) == 0) )
665  {
666  /* An exact match of the Check number gives a +4 */
667  prob += 4;
668  /*DEBUG("heuristics: probability + 4 (Check number)");*/
669  }
670  else if (strlen(new_trans_str) > 0 && strlen(split_str) > 0)
671  {
672  /* If both number are not empty yet do not match, add a
673  little extra penalty */
674  prob -= 2;
675  }
676  }
677 
678  /* Memo heuristics */
679  auto memo = xaccSplitGetMemo(new_trans_fsplit);
680  if (memo && *memo)
681  {
682  if (safe_strcasecmp(memo, xaccSplitGetMemo(split)) == 0)
683  {
684  /* An exact match of memo gives a +2 */
685  prob = prob + 2;
686  /* DEBUG("heuristics: probability + 2 (memo)"); */
687  }
688  else if ((strncasecmp(memo, xaccSplitGetMemo(split),
689  strlen(xaccSplitGetMemo(split)) / 2) == 0))
690  {
691  /* Very primitive fuzzy match worth +1. This matches the
692  first 50% of the strings to skip annoying transaction
693  number some banks seem to include in the memo but someone
694  should write something more sophisticated */
695  prob = prob + 1;
696  /*DEBUG("heuristics: probability + 1 (memo)"); */
697  }
698  }
699 
700  /* Description heuristics */
701  auto descr = xaccTransGetDescription(new_trans);
702  if (descr && *descr)
703  {
704  if (safe_strcasecmp(descr,
706  {
707  /*An exact match of Description gives a +2 */
708  prob = prob + 2;
709  /*DEBUG("heuristics: probability + 2 (description)");*/
710  }
711  else if ((strncasecmp(descr,
713  strlen(xaccTransGetDescription (new_trans)) / 2) == 0))
714  {
715  /* Very primitive fuzzy match worth +1. This matches the
716  first 50% of the strings to skip annoying transaction
717  number some banks seem to include in the description but someone
718  should write something more sophisticated */
719  prob = prob + 1;
720  /*DEBUG("heuristics: probability + 1 (description)"); */
721  }
722  }
723 
724  /* Is the probability high enough? Otherwise do nothing and return. */
725  if (prob < display_threshold)
726  return;
727 
728  /* The probability is high enough, so allocate an object
729  here. Allocating it only when it's actually being used is
730  probably quite some performance gain. */
731  auto match_info = g_new0(GNCImportMatchInfo, 1);
732 
733  match_info->probability = prob;
734  match_info->update_proposed = update_proposed;
735  match_info->split = split;
736  match_info->trans = xaccSplitGetParent(split);
737 
738 
739  /* Append that to the list. Do not use g_list_append because
740  it is slow. The list is sorted afterwards anyway. */
741  trans_info->match_list = g_list_prepend(trans_info->match_list, match_info);
742 }
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
gint safe_strcasecmp(const gchar *da, const gchar *db)
case sensitive comparison of strings da and db - either may be NULL.
Definition: qofutil.cpp:100
Split * gnc_import_TransInfo_get_fsplit(const GNCImportTransInfo *info)
Returns the first split of the transaction of this TransInfo.
Transaction * gnc_import_TransInfo_get_trans(const GNCImportTransInfo *info)
Returns the transaction of this TransInfo.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
double gnc_numeric_to_double(gnc_numeric in)
Convert numeric to floating-point value.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition: gmock-Split.cpp:99
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account&#39;s commodity.
Definition: gmock-Split.cpp:69