GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
GncTxImport Class Reference

The actual TxImport class It's intended to use in the following sequence of actions: More...

#include <gnc-import-tx.hpp>

Public Member Functions

 GncTxImport (GncImpFileFormat format=GncImpFileFormat::UNKNOWN)
 Constructor for GncTxImport.
 
 ~GncTxImport ()
 Destructor for GncTxImport.
 
void file_format (GncImpFileFormat format)
 Sets the file format for the file to import, which may cause the file to be reloaded as well if the previously set file format was different and a filename was already set.
 
GncImpFileFormat file_format ()
 
void multi_split (bool multi_split)
 Toggles the multi-split state of the importer and will subsequently sanitize the column_types list.
 
bool multi_split ()
 
void base_account (Account *base_account)
 Sets a base account.
 
Accountbase_account ()
 
void currency_format (int currency_format)
 
int currency_format ()
 
void date_format (int date_format)
 
int date_format ()
 
void encoding (const std::string &encoding)
 Converts raw file data using a new encoding.
 
std::string encoding ()
 
void update_skipped_lines (std::optional< uint32_t > start, std::optional< uint32_t > end, std::optional< bool > alt, std::optional< bool > errors)
 
uint32_t skip_start_lines ()
 
uint32_t skip_end_lines ()
 
bool skip_alt_lines ()
 
bool skip_err_lines ()
 
void separators (std::string separators)
 
std::string separators ()
 
void enable_escape (bool enable)
 
bool enable_escape ()
 
void settings (const CsvTransImpSettings &settings)
 
bool save_settings ()
 
void settings_name (std::string name)
 
std::string settings_name ()
 
void load_file (const std::string &filename)
 Loads a file into a GncTxImport.
 
void tokenize (bool guessColTypes)
 Splits a file into cells.
 
std::string verify (bool with_acct_errors)
 
void create_transactions ()
 This function will attempt to convert all tokenized lines into transactions using the column types the user has set.
 
bool check_for_column_type (GncTransPropType type)
 
void set_column_type (uint32_t position, GncTransPropType type, bool force=false)
 
std::vector< GncTransPropType > column_types ()
 
std::set< std::string > accounts ()
 

Data Fields

std::unique_ptr< GncTokenizerm_tokenizer
 Will handle file loading/encoding conversion/splitting into fields.
 
std::vector< parse_line_tm_parsed_lines
 source file parsed into a two-dimensional array of strings.
 
std::multimap< time64, std::shared_ptr< DraftTransaction > > m_transactions
 map of transaction objects created from parsed_lines and column_types, ordered by date
 

Detailed Description

The actual TxImport class It's intended to use in the following sequence of actions:

Definition at line 104 of file gnc-import-tx.hpp.

Constructor & Destructor Documentation

◆ GncTxImport()

GncTxImport::GncTxImport ( GncImpFileFormat  format = GncImpFileFormat::UNKNOWN)

Constructor for GncTxImport.

Definition at line 65 of file gnc-import-tx.cpp.

66{
67 /* All of the data pointers are initially NULL. This is so that, if
68 * gnc_csv_parse_data_free is called before all of the data is
69 * initialized, only the data that needs to be freed is freed. */
70 m_skip_errors = false;
71 file_format(m_settings.m_file_format = format);
72}
void file_format(GncImpFileFormat format)
Sets the file format for the file to import, which may cause the file to be reloaded as well if the p...

◆ ~GncTxImport()

GncTxImport::~GncTxImport ( )

Destructor for GncTxImport.

Definition at line 76 of file gnc-import-tx.cpp.

77{
78}

Member Function Documentation

◆ accounts()

std::set< std::string > GncTxImport::accounts ( )

Definition at line 926 of file gnc-import-tx.cpp.

927{
928 auto accts = std::set<std::string>();
929 auto acct_col_it = std::find (m_settings.m_column_types.begin(),
930 m_settings.m_column_types.end(), GncTransPropType::ACCOUNT);
931 uint32_t acct_col = acct_col_it - m_settings.m_column_types.begin();
932 auto tacct_col_it = std::find (m_settings.m_column_types.begin(),
933 m_settings.m_column_types.end(), GncTransPropType::TACCOUNT);
934 uint32_t tacct_col = tacct_col_it - m_settings.m_column_types.begin();
935
936 /* Iterate over all parsed lines */
937 for (auto parsed_line : m_parsed_lines)
938 {
939 /* Skip current line if the user specified so */
940 if ((std::get<PL_SKIP>(parsed_line)))
941 continue;
942
943 auto col_strs = std::get<PL_INPUT>(parsed_line);
944 if ((acct_col_it != m_settings.m_column_types.end()) &&
945 (acct_col < col_strs.size()) &&
946 !col_strs[acct_col].empty())
947 accts.insert(col_strs[acct_col]);
948 if ((tacct_col_it != m_settings.m_column_types.end()) &&
949 (tacct_col < col_strs.size()) &&
950 !col_strs[tacct_col].empty())
951 accts.insert(col_strs[tacct_col]);
952 }
953
954 return accts;
955}
std::vector< parse_line_t > m_parsed_lines
source file parsed into a two-dimensional array of strings.

◆ base_account() [1/2]

Account * GncTxImport::base_account ( )

Definition at line 211 of file gnc-import-tx.cpp.

211{ return m_settings.m_base_account; }

◆ base_account() [2/2]

void GncTxImport::base_account ( Account base_account)

Sets a base account.

This is the account all import data relates to. As such at least one split of each transaction that will be generated will be in this account. When a base account is set, there can't be an account column selected in the import data. In multi-split mode the user has to select an account column so in that mode the base_account can't be set.

Parameters
base_accountPointer to an account or NULL.

Definition at line 180 of file gnc-import-tx.cpp.

181{
182 if (m_settings.m_multi_split)
183 {
184 m_settings.m_base_account = nullptr;
185 return;
186 }
187
188 auto base_account_is_new = m_settings.m_base_account == nullptr;
189 m_settings.m_base_account = base_account;
190
191 if (m_settings.m_base_account)
192 {
193 auto col_type_it = std::find (m_settings.m_column_types.begin(),
194 m_settings.m_column_types.end(), GncTransPropType::ACCOUNT);
195 if (col_type_it != m_settings.m_column_types.end())
196 set_column_type(col_type_it - m_settings.m_column_types.begin(),
197 GncTransPropType::NONE);
198
199 if (base_account_is_new)
200 {
201 /* Set default account for each line's split properties */
202 for (auto line : m_parsed_lines)
203 std::get<PL_PRESPLIT>(line)->set_account (m_settings.m_base_account);
204 }
205
206 /* Reparse all of the lines with the new base account's commodity. */
207 tokenize(false);
208 }
209}
void tokenize(bool guessColTypes)
Splits a file into cells.

◆ check_for_column_type()

bool GncTxImport::check_for_column_type ( GncTransPropType  type)

Definition at line 768 of file gnc-import-tx.cpp.

769{
770 return (std::find (m_settings.m_column_types.begin(),
771 m_settings.m_column_types.end(), type)
772 != m_settings.m_column_types.end());
773}

◆ column_types()

std::vector< GncTransPropType > GncTxImport::column_types ( )

Definition at line 920 of file gnc-import-tx.cpp.

921{
922 return m_settings.m_column_types;
923}

◆ create_transactions()

void GncTxImport::create_transactions ( )

This function will attempt to convert all tokenized lines into transactions using the column types the user has set.

Creates a list of transactions from parsed data.

The parsed data will first be validated. If any errors are found in lines that are marked for processing (ie not marked to skip) this function will throw an error.

Parameters
skip_errorstrue skip over lines with errors
Exceptions
throwsstd::invalid_argument if data validation or processing fails.

Definition at line 740 of file gnc-import-tx.cpp.

741{
742 /* Start with verifying the current data. */
743 auto verify_result = verify (true);
744 if (!verify_result.empty())
745 throw std::invalid_argument (verify_result);
746
747 /* Drop all existing draft transactions */
748 m_transactions.clear();
749
750 m_parent = nullptr;
751
752 /* Iterate over all parsed lines */
753 for (auto parsed_lines_it = m_parsed_lines.begin();
754 parsed_lines_it != m_parsed_lines.end();
755 ++parsed_lines_it)
756 {
757 /* Skip current line if the user specified so */
758 if ((std::get<PL_SKIP>(*parsed_lines_it)))
759 continue;
760
761 /* Should not throw anymore, otherwise verify needs revision */
762 create_transaction (parsed_lines_it);
763 }
764}
std::multimap< time64, std::shared_ptr< DraftTransaction > > m_transactions
map of transaction objects created from parsed_lines and column_types, ordered by date

◆ currency_format() [1/2]

int GncTxImport::currency_format ( )

Definition at line 240 of file gnc-import-tx.cpp.

240{ return m_settings.m_currency_format; }

◆ currency_format() [2/2]

void GncTxImport::currency_format ( int  currency_format)

Definition at line 227 of file gnc-import-tx.cpp.

228{
229 m_settings.m_currency_format = currency_format;
230
231 /* Reparse all currency related columns */
232 std::vector<GncTransPropType> commodities = {
233 GncTransPropType::AMOUNT,
234 GncTransPropType::AMOUNT_NEG,
235 GncTransPropType::TAMOUNT,
236 GncTransPropType::TAMOUNT_NEG,
237 GncTransPropType::PRICE};
238 reset_formatted_column (commodities);
239}

◆ date_format() [1/2]

int GncTxImport::date_format ( )

Definition at line 252 of file gnc-import-tx.cpp.

252{ return m_settings.m_date_format; }

◆ date_format() [2/2]

void GncTxImport::date_format ( int  date_format)

Definition at line 242 of file gnc-import-tx.cpp.

243{
244 m_settings.m_date_format = date_format;
245
246 /* Reparse all date related columns */
247 std::vector<GncTransPropType> dates = { GncTransPropType::DATE,
248 GncTransPropType::REC_DATE,
249 GncTransPropType::TREC_DATE};
250 reset_formatted_column (dates);
251}

◆ enable_escape() [1/2]

bool GncTxImport::enable_escape ( )

Definition at line 327 of file gnc-import-tx.cpp.

327{ return m_settings.m_enable_escape; }

◆ enable_escape() [2/2]

void GncTxImport::enable_escape ( bool  enable)

Definition at line 319 of file gnc-import-tx.cpp.

320{
321 if (file_format() != GncImpFileFormat::CSV)
322 return;
323 m_settings.m_enable_escape = enable;
324 auto csvtok = dynamic_cast<GncCsvTokenizer*>(m_tokenizer.get());
325 csvtok->set_enable_escape (enable);
326}
std::unique_ptr< GncTokenizer > m_tokenizer
Will handle file loading/encoding conversion/splitting into fields.

◆ encoding() [1/2]

std::string GncTxImport::encoding ( )

Definition at line 277 of file gnc-import-tx.cpp.

277{ return m_settings.m_encoding; }

◆ encoding() [2/2]

void GncTxImport::encoding ( const std::string &  encoding)

Converts raw file data using a new encoding.

This function must be called after load_file only if load_file guessed the wrong encoding.

Parameters
encodingEncoding that data should be translated using

Definition at line 259 of file gnc-import-tx.cpp.

260{
261
262 // TODO investigate if we can catch conversion errors and report them
263 if (m_tokenizer)
264 {
265 m_tokenizer->encoding(encoding); // May throw
266 try
267 {
268 tokenize(false);
269 }
270 catch (...)
271 { };
272 }
273
274 m_settings.m_encoding = encoding;
275}
void encoding(const std::string &encoding)
Converts raw file data using a new encoding.

◆ file_format() [1/2]

GncImpFileFormat GncTxImport::file_format ( )

Definition at line 132 of file gnc-import-tx.cpp.

133{
134 return m_settings.m_file_format;
135}

◆ file_format() [2/2]

void GncTxImport::file_format ( GncImpFileFormat  format)

Sets the file format for the file to import, which may cause the file to be reloaded as well if the previously set file format was different and a filename was already set.

Parameters
formatthe new format to set
Exceptions
std::ifstream::failureif file reloading fails

Definition at line 87 of file gnc-import-tx.cpp.

88{
89 if (m_tokenizer && m_settings.m_file_format == format)
90 return;
91
92 auto new_encoding = std::string("UTF-8");
93 auto new_imp_file = std::string();
94
95 // Recover common settings from old tokenizer
96 if (m_tokenizer)
97 {
98 new_encoding = m_tokenizer->encoding();
99 new_imp_file = m_tokenizer->current_file();
100 if (file_format() == GncImpFileFormat::FIXED_WIDTH)
101 {
102 auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
103 if (!fwtok->get_columns().empty())
104 m_settings.m_column_widths = fwtok->get_columns();
105 }
106 }
107
108 m_settings.m_file_format = format;
109 m_tokenizer = gnc_tokenizer_factory(m_settings.m_file_format);
110
111 // Set up new tokenizer with common settings
112 // recovered from old tokenizer
113 m_tokenizer->encoding(new_encoding);
114 load_file(new_imp_file);
115
116 // Restore potentially previously set separators or column_widths
117 if (file_format() == GncImpFileFormat::CSV)
118 {
119 if (!m_settings.m_separators.empty())
120 separators (m_settings.m_separators);
121 enable_escape (m_settings.m_enable_escape);
122 }
123 else if ((file_format() == GncImpFileFormat::FIXED_WIDTH)
124 && !m_settings.m_column_widths.empty())
125 {
126 auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
127 fwtok->columns (m_settings.m_column_widths);
128 }
129
130}
void load_file(const std::string &filename)
Loads a file into a GncTxImport.

◆ load_file()

void GncTxImport::load_file ( const std::string &  filename)

Loads a file into a GncTxImport.

This is the first function that must be called after creating a new GncTxImport. As long as this function didn't run successfully, the importer can't proceed.

Parameters
filenameName of the file that should be opened
Exceptions
maythrow std::ifstream::failure on any io error

Definition at line 393 of file gnc-import-tx.cpp.

394{
395
396 /* Get the raw data first and handle an error if one occurs. */
397 try
398 {
399 m_tokenizer->load_file (filename);
400 return;
401 }
402 catch (std::ifstream::failure& ios_err)
403 {
404 // Just log the error and pass it on the call stack for proper handling
405 PWARN ("Error: %s", ios_err.what());
406 throw;
407 }
408}
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250

◆ multi_split() [1/2]

bool GncTxImport::multi_split ( )

Definition at line 169 of file gnc-import-tx.cpp.

169{ return m_settings.m_multi_split; }

◆ multi_split() [2/2]

void GncTxImport::multi_split ( bool  multi_split)

Toggles the multi-split state of the importer and will subsequently sanitize the column_types list.

All types that don't make sense in the new state are reset to type GncTransPropType::NONE. Additionally the interpretation of the columns with transaction properties changes when changing multi-split mode. So this function will force a reparsing of the transaction properties (if there are any) by resetting the first column with a transaction property it encounters.

Parameters
multi_splitBoolean value with desired state (multi-split vs two-split).

Definition at line 148 of file gnc-import-tx.cpp.

149{
150 auto trans_prop_seen = false;
151 m_settings.m_multi_split = multi_split;
152 for (uint32_t i = 0; i < m_settings.m_column_types.size(); i++)
153 {
154 auto old_prop = m_settings.m_column_types[i];
155 auto is_trans_prop = ((old_prop > GncTransPropType::NONE)
156 && (old_prop <= GncTransPropType::TRANS_PROPS));
157 auto san_prop = sanitize_trans_prop (old_prop, m_settings.m_multi_split);
158 if (san_prop != old_prop)
159 set_column_type (i, san_prop);
160 else if (is_trans_prop && !trans_prop_seen)
161 set_column_type (i, old_prop, true);
162 trans_prop_seen |= is_trans_prop;
163
164 }
165 if (m_settings.m_multi_split)
166 m_settings.m_base_account = nullptr;
167}
void multi_split(bool multi_split)
Toggles the multi-split state of the importer and will subsequently sanitize the column_types list.

◆ save_settings()

bool GncTxImport::save_settings ( )

Definition at line 365 of file gnc-import-tx.cpp.

366{
367
368 if (preset_is_reserved_name (m_settings.m_name))
369 return true;
370
371 /* separators are already copied to m_settings in the separators
372 * function above. However this is not the case for the column
373 * widths in fw mode, so do this now.
374 */
375 if (file_format() == GncImpFileFormat::FIXED_WIDTH)
376 {
377 auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
378 m_settings.m_column_widths = fwtok->get_columns();
379 }
380
381 return m_settings.save();
382}
bool preset_is_reserved_name(const std::string &name)
Check whether name can be used as a preset name.
bool save(void)
Save the gathered widget properties to a key File.

◆ separators() [1/2]

std::string GncTxImport::separators ( )

Definition at line 317 of file gnc-import-tx.cpp.

317{ return m_settings.m_separators; }

◆ separators() [2/2]

void GncTxImport::separators ( std::string  separators)

Definition at line 307 of file gnc-import-tx.cpp.

308{
309 if (file_format() != GncImpFileFormat::CSV)
310 return;
311
312 m_settings.m_separators = separators;
313 auto csvtok = dynamic_cast<GncCsvTokenizer*>(m_tokenizer.get());
314 csvtok->set_separators (separators);
315
316}

◆ set_column_type()

void GncTxImport::set_column_type ( uint32_t  position,
GncTransPropType  type,
bool  force = false 
)

Definition at line 889 of file gnc-import-tx.cpp.

890{
891 if (position >= m_settings.m_column_types.size())
892 return;
893
894 auto old_type = m_settings.m_column_types[position];
895 if ((type == old_type) && !force)
896 return; /* Nothing to do */
897
898 // Column types except amount and negated amount should be unique,
899 // so remove any previous occurrence of the new type
900 if (!is_multi_col_prop(type))
901 std::replace(m_settings.m_column_types.begin(), m_settings.m_column_types.end(),
902 type, GncTransPropType::NONE);
903
904 m_settings.m_column_types.at (position) = type;
905
906 // If the user has set an Account column, we can't have a base account set
907 if (type == GncTransPropType::ACCOUNT)
908 base_account (nullptr);
909
910 /* Update the preparsed data */
911 m_parent = nullptr;
912 m_multi_currency = false;
913 for (auto& parsed_lines_it: m_parsed_lines)
914 {
915 update_pre_trans_props (parsed_lines_it, position, old_type, type);
916 update_pre_split_props (parsed_lines_it, position, old_type, type);
917 }
918}
void base_account(Account *base_account)
Sets a base account.

◆ settings()

void GncTxImport::settings ( const CsvTransImpSettings settings)

Definition at line 329 of file gnc-import-tx.cpp.

330{
331 /* First apply file format as this may recreate the tokenizer */
332 file_format (settings.m_file_format);
333 /* Only then apply the other settings */
334 m_settings = settings;
335 multi_split (m_settings.m_multi_split);
336 base_account (m_settings.m_base_account);
337 encoding (m_settings.m_encoding);
338
339 if (file_format() == GncImpFileFormat::CSV)
340 {
341 separators (m_settings.m_separators);
342 enable_escape (m_settings.m_enable_escape);
343 }
344 else if (file_format() == GncImpFileFormat::FIXED_WIDTH)
345 {
346 auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
347 fwtok->columns (m_settings.m_column_widths);
348 }
349 try
350 {
351 tokenize(false);
352 }
353 catch (...)
354 { };
355
356 /* Tokenizing will clear column types, reset them here
357 * based on the loaded settings.
358 */
359 std::copy_n (settings.m_column_types.begin(),
360 std::min (m_settings.m_column_types.size(), settings.m_column_types.size()),
361 m_settings.m_column_types.begin());
362
363}

◆ settings_name() [1/2]

std::string GncTxImport::settings_name ( )

Definition at line 385 of file gnc-import-tx.cpp.

385{ return m_settings.m_name; }

◆ settings_name() [2/2]

void GncTxImport::settings_name ( std::string  name)

Definition at line 384 of file gnc-import-tx.cpp.

384{ m_settings.m_name = name; }

◆ skip_alt_lines()

bool GncTxImport::skip_alt_lines ( )

Definition at line 304 of file gnc-import-tx.cpp.

304{ return m_settings.m_skip_alt_lines; }

◆ skip_end_lines()

uint32_t GncTxImport::skip_end_lines ( )

Definition at line 303 of file gnc-import-tx.cpp.

303{ return m_settings.m_skip_end_lines; }

◆ skip_err_lines()

bool GncTxImport::skip_err_lines ( )

Definition at line 305 of file gnc-import-tx.cpp.

305{ return m_skip_errors; }

◆ skip_start_lines()

uint32_t GncTxImport::skip_start_lines ( )

Definition at line 302 of file gnc-import-tx.cpp.

302{ return m_settings.m_skip_start_lines; }

◆ tokenize()

void GncTxImport::tokenize ( bool  guessColTypes)

Splits a file into cells.

This requires having an encoding that works (see GncTxImport::convert_encoding). Tokenizing related options should be set to the user's selections before calling this function. Notes: - this function must be called with guessColTypes set to true once before calling it with guessColTypes set to false.

  • if guessColTypes is true, all the column types will be set GncTransPropType::NONE right now as real guessing isn't implemented yet
    Parameters
    guessColTypestrue to guess what the types of columns are based on the cell contents
    Exceptions
    std::range_errorif tokenizing failed

Definition at line 421 of file gnc-import-tx.cpp.

422{
423 if (!m_tokenizer)
424 return;
425
426 uint32_t max_cols = 0;
427 m_tokenizer->tokenize();
428 m_parsed_lines.clear();
429 for (auto tokenized_line : m_tokenizer->get_tokens())
430 {
431 auto length = tokenized_line.size();
432 if (length > 0)
433 {
434 auto pretrans = std::make_shared<GncPreTrans>(date_format(), m_settings.m_multi_split);
435 auto presplit = std::make_shared<GncPreSplit>(date_format(), currency_format());
436 presplit->set_pre_trans (std::move (pretrans));
437 m_parsed_lines.push_back (std::make_tuple (tokenized_line, ErrMap(),
438 presplit->get_pre_trans(), std::move (presplit), false));
439 }
440 if (length > max_cols)
441 max_cols = length;
442 }
443
444 /* If it failed, generate an error. */
445 if (m_parsed_lines.size() == 0)
446 {
447 throw (std::range_error (N_("There was an error parsing the file.")));
448 return;
449 }
450
451 m_settings.m_column_types.resize(max_cols, GncTransPropType::NONE);
452
453 /* Force reinterpretation of already set columns and/or base_account */
454 for (uint32_t i = 0; i < m_settings.m_column_types.size(); i++)
455 set_column_type (i, m_settings.m_column_types[i], true);
456 if (m_settings.m_base_account)
457 {
458 for (auto line : m_parsed_lines)
459 std::get<PL_PRESPLIT>(line)->set_account (m_settings.m_base_account);
460 }
461
462 if (guessColTypes)
463 {
464 /* Guess column_types based
465 * on the contents of each column. */
466 /* TODO Make it actually guess. */
467 }
468}

◆ update_skipped_lines()

void GncTxImport::update_skipped_lines ( std::optional< uint32_t >  start,
std::optional< uint32_t >  end,
std::optional< bool >  alt,
std::optional< bool >  errors 
)

Definition at line 279 of file gnc-import-tx.cpp.

281{
282 if (start)
283 m_settings.m_skip_start_lines = *start;
284 if (end)
285 m_settings.m_skip_end_lines = *end;
286 if (alt)
287 m_settings.m_skip_alt_lines = *alt;
288 if (errors)
289 m_skip_errors = *errors;
290
291 for (uint32_t i = 0; i < m_parsed_lines.size(); i++)
292 {
293 std::get<PL_SKIP>(m_parsed_lines[i]) =
294 ((i < skip_start_lines()) || // start rows to skip
295 (i >= m_parsed_lines.size() - skip_end_lines()) || // end rows to skip
296 (((i - skip_start_lines()) % 2 == 1) && // skip every second row...
297 skip_alt_lines()) || // ...if requested
298 (m_skip_errors && !std::get<PL_ERROR>(m_parsed_lines[i]).empty())); // skip lines with errors
299 }
300}

◆ verify()

std::string GncTxImport::verify ( bool  with_acct_errors)

Definition at line 568 of file gnc-import-tx.cpp.

569{
570 auto newline = std::string();
571 auto error_msg = ErrorList();
572
573 /* Check if the import file did actually contain any information */
574 if (m_parsed_lines.size() == 0)
575 {
576 error_msg.add_error(_("No valid data found in the selected file. It may be empty or the selected encoding is wrong."));
577 return error_msg.str();
578 }
579
580 /* Check if at least one line is selected for importing */
581 auto skip_alt_offset = m_settings.m_skip_alt_lines ? 1 : 0;
582 if (m_settings.m_skip_start_lines + m_settings.m_skip_end_lines + skip_alt_offset >= m_parsed_lines.size())
583 {
584 error_msg.add_error(_("No lines are selected for importing. Please reduce the number of lines to skip."));
585 return error_msg.str();
586 }
587
588 verify_column_selections (error_msg);
589
590 update_skipped_lines (std::nullopt, std::nullopt, std::nullopt, std::nullopt);
591
592 auto have_line_errors = false;
593 for (auto line : m_parsed_lines)
594 {
595 auto errors = std::get<PL_ERROR>(line);
596 if (std::get<PL_SKIP>(line))
597 continue;
598 if (with_acct_errors && !errors.empty())
599 {
600 have_line_errors = true;
601 break;
602 }
603 auto non_acct_error = [](ErrPair curr_err)
604 {
605 return !((curr_err.first == GncTransPropType::ACCOUNT) ||
606 (curr_err.first == GncTransPropType::TACCOUNT));
607 };
608 if (!with_acct_errors &&
609 std::any_of(errors.cbegin(), errors.cend(), non_acct_error))
610 {
611 have_line_errors = true;
612 break;
613 }
614 }
615
616 if (have_line_errors)
617 error_msg.add_error( _("Not all fields could be parsed. Please correct the issues reported for each line or adjust the lines to skip."));
618
619 return error_msg.str();
620}

Field Documentation

◆ m_parsed_lines

std::vector<parse_line_t> GncTxImport::m_parsed_lines

source file parsed into a two-dimensional array of strings.

Per line also holds possible error messages and objects with extracted transaction and split properties.

Definition at line 166 of file gnc-import-tx.hpp.

◆ m_tokenizer

std::unique_ptr<GncTokenizer> GncTxImport::m_tokenizer

Will handle file loading/encoding conversion/splitting into fields.

Definition at line 165 of file gnc-import-tx.hpp.

◆ m_transactions

std::multimap<time64, std::shared_ptr<DraftTransaction> > GncTxImport::m_transactions

map of transaction objects created from parsed_lines and column_types, ordered by date

Definition at line 169 of file gnc-import-tx.hpp.


The documentation for this class was generated from the following files: