29 #include <glib/gstdio.h> 33 #include <unordered_set> 40 #include "engine-helpers.h" 41 #include "qofbookslots.h" 45 #include "csv-export-helpers.hpp" 48 static QofLogModule log_module = GNC_MOD_ASSISTANT;
56 get_date (Transaction *trans)
65 get_guid (Transaction *trans)
72 get_reconcile_date (Split *split)
84 get_account_name (Split *split,
bool full)
92 get_number (Transaction *trans)
95 return (num ? num :
"");
100 get_description (Transaction *trans)
103 return (desc ? desc :
"");
108 get_notes (Transaction *trans)
111 return (notes ? notes :
"");
116 get_void_reason (Transaction *trans)
119 return (void_reason ? void_reason :
"");
124 get_memo (Split *split)
127 return (memo ? memo :
"");
132 get_category (Split *split,
bool full)
135 return other ? get_account_name (other, full) : _(
"-- Split Transaction --");
140 get_action (Split *split)
143 return (action ? action :
"");
148 get_reconcile (Split *split)
151 return (recon ? recon :
"");
156 get_commodity (Transaction *trans)
163 get_amount (Split *split,
bool t_void,
bool symbol)
166 auto pinfo{gnc_split_amount_print_info (split, symbol)};
168 pinfo.use_separators = 0;
174 get_value (Split *split,
bool t_void,
bool symbol)
178 auto pai{gnc_commodity_print_info (tcurr, symbol)};
180 pai.use_separators = 0;
187 get_rate (Split *split,
bool t_void)
196 get_price (Split *split,
bool t_void)
211 make_simple_trans_line (Transaction *trans, Split *split)
216 get_account_name (split,
true),
218 get_description (trans),
219 get_category (split,
true),
220 get_reconcile (split),
221 get_amount (split, t_void,
true),
222 get_amount (split, t_void,
false),
223 get_value (split, t_void,
true),
224 get_value (split, t_void,
false),
225 get_rate (split, t_void)
230 make_complex_trans_line (Transaction *trans, Split *split)
237 get_description (trans),
239 get_commodity (trans),
240 get_void_reason (trans),
243 get_account_name (split,
true),
244 get_account_name (split,
false),
245 get_amount (split, t_void,
true),
246 get_amount (split, t_void,
false),
247 get_value (split, t_void,
true),
248 get_value (split, t_void,
false),
249 get_reconcile (split),
250 get_reconcile_date (split),
251 get_price (split, t_void)
255 using TransSet = std::unordered_set<Transaction*>;
264 export_query_splits (
CsvExportInfo *info,
bool is_trading_acct,
265 std::ofstream& ss, TransSet& trans_set)
267 g_return_if_fail (info);
270 for (GList *splits =
qof_query_run (info->query); !info->failed && splits;
271 splits = splits->next)
273 auto split{
static_cast<Split*
>(splits->data)};
277 if (!trans_set.emplace (trans).second)
286 if (!is_trading_acct &&
290 if (info->simple_layout)
293 auto line = make_simple_trans_line (trans, split);
294 info->failed = !gnc_csv_add_line (ss, line, info->use_quotes,
295 info->separator_str);
300 auto line = make_complex_trans_line (trans, split);
301 info->failed = !gnc_csv_add_line (ss, line, info->use_quotes,
302 info->separator_str);
308 auto t_split{
static_cast<Split*
>(node->data)};
311 if (split == t_split)
316 if (!is_trading_acct &&
321 auto line = make_complex_trans_line (trans, t_split);
322 info->failed = !gnc_csv_add_line (ss, line, info->use_quotes,
323 info->separator_str);
330 std::ofstream& ss, TransSet& trans_set)
332 g_return_if_fail (info && GNC_IS_ACCOUNT (acc));
334 auto p1 = g_slist_prepend (g_slist_prepend (
nullptr, (gpointer)TRANS_DATE_POSTED), (gpointer)SPLIT_TRANS);
336 info->query = qof_query_create_for (GNC_ID_SPLIT);
339 xaccQueryAddSingleAccountMatch (info->query, acc, QOF_QUERY_AND);
340 xaccQueryAddDateMatchTT (info->query,
true, info->csvd.start_time,
true, info->csvd.end_time, QOF_QUERY_AND);
353 DEBUG(
"File name is : %s", info->file_name);
359 if (info->simple_layout)
366 (num_action ? _(
"Transaction Number") : _(
"Number")),
368 _(
"Full Category Path"),
370 _(
"Amount With Sym"),
381 (num_action ? _(
"Transaction Number") : _(
"Number")),
384 _(
"Commodity/Currency"),
386 (num_action ? _(
"Number/Action") : _(
"Action")),
388 _(
"Full Account Name"),
390 _(
"Amount With Sym"),
400 auto ss{gnc_open_filestream(info->file_name)};
401 info->failed = !gnc_csv_add_line (ss, headers, info->use_quotes, info->separator_str);
406 switch (info->export_type)
408 case XML_EXPORT_TRANS:
409 for (
auto ptr = info->csva.account_list; !ss.fail() && ptr; ptr = g_list_next(ptr))
410 account_splits (info, GNC_ACCOUNT(ptr->data), ss, trans_set);
412 case XML_EXPORT_REGISTER:
413 export_query_splits (info,
false, ss, trans_set);
416 PERR (
"unknown export_type %d", info->export_type);
419 info->failed = ss.fail();
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
utility functions for the GnuCash UI
void qof_query_set_sort_order(QofQuery *q, QofQueryParamList *params1, QofQueryParamList *params2, QofQueryParamList *params3)
When a query is run, the results are sorted before being returned.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
const char * xaccTransGetVoidReason(const Transaction *trans)
Returns the user supplied textual reason why a transaction was voided.
#define DEBUG(format, args...)
Print a debugging message.
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
Returns TRUE if this book uses split action field as the 'Num' field, FALSE if it uses transaction nu...
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
const char * xaccTransGetNum(const Transaction *trans)
Gets the transaction Number (or ID) field; rather than use this function directly, see 'gnc_get_num_action' and 'gnc_get_action_num' in engine/engine-helpers.c & .h which takes a user-set book option for selecting the source for the num-cell (the transaction-number or the split-action field) in registers/reports into account automatically.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
Account used to record multiple commodity transactions.
const char * xaccTransGetNotes(const Transaction *trans)
Gets the transaction Notes.
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
Returns the original pre-void amount of a split.
void qof_query_destroy(QofQuery *query)
Frees the resources associate with a Query object.
gnc_numeric xaccSplitVoidFormerValue(const Split *split)
Returns the original pre-void value of a split.
#define YREC
The Split has been reconciled.
void qof_query_set_book(QofQuery *query, QofBook *book)
Set the book to be searched.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
gnc_numeric xaccSplitGetSharePrice(const Split *split)
Returns the price of the split, that is, the value divided by the amount.
const GncGUID * qof_entity_get_guid(gconstpointer ent)
time64 xaccSplitGetDateReconciled(const Split *split)
Retrieve the date when the Split was reconciled.
gboolean xaccTransGetVoidStatus(const Transaction *trans)
Retrieve information on whether or not a transaction has been voided.
GList * qof_query_run(QofQuery *query)
Perform the query, return the results.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits...
#define LEAVE(format, args...)
Print a function exit debugging message.
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the 'unique' name for the specified commodity.
#define QUERY_DEFAULT_SORT
Default sort object type.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
void csv_transactions_export(CsvExportInfo *info)
The csv_transactions_export() will let the user export the transactions to a delimited file...
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
File path resolution utility functions.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
API for Transactions and Splits (journal entries)
#define GNC_HOW_DENOM_SIGFIGS(n)
Build a 'how' value that will generate a denominator that will keep at least n significant figures in...
size_t qof_print_date_buff(char *buff, size_t buflen, time64 secs)
Convenience: calls through to qof_print_date_dmy_buff().
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
Commodity handling public routines.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.