30 #include <glib/gi18n.h>
31 #include <glib/gstdio.h>
37 #include "engine-helpers.h"
38 #include "qofbookslots.h"
50 # define EOLSTR "\r\n"
63 gboolean write_line_to_file (FILE *fh,
char * line)
66 DEBUG(
"Account String: %s", line);
70 written = fwrite (line, 1, len, fh);
85 gchar *csv_txn_test_field_string (
CsvExportInfo *info,
const gchar *string_in)
87 gboolean need_quote = FALSE;
93 parts = g_strsplit (string_in,
"\"", -1);
94 string_parts = g_strjoinv (
"\"\"", parts);
99 if (g_strrstr (string_parts, info->separator_str) != NULL)
101 if (g_strrstr (string_parts,
"\n") != NULL)
103 if (g_strrstr (string_parts,
"\"") != NULL)
106 if (!info->use_quotes && need_quote)
107 string_out = g_strconcat (
"\"", string_parts,
"\"", NULL);
109 string_out = g_strdup (string_parts);
111 g_free (string_parts);
133 q = qof_query_create_for (GNC_ID_SPLIT);
134 book = gnc_get_current_book();
138 if (info->use_quotes)
141 mid_sep = g_strconcat (
"\"", info->separator_str,
"\"", NULL);
146 mid_sep = g_strconcat (info->separator_str, NULL);
150 p1 = g_slist_prepend (NULL, TRANS_DATE_POSTED);
151 p1 = g_slist_prepend (p1, SPLIT_TRANS);
155 xaccQueryAddSingleAccountMatch (q, acc, QOF_QUERY_AND);
156 xaccQueryAddDateMatchTT (q, TRUE, info->csvd.start_time, TRUE, info->csvd.end_time, QOF_QUERY_AND);
159 for (splits =
qof_query_run (q); splits; splits = splits->next)
171 const gchar *currentSel;
172 const gchar *split_amount;
173 gchar *str_temp = NULL;
174 gchar *full_path = NULL;
179 split = splits->data;
186 if (g_list_find (info->trans_list, trans) != NULL)
191 part1 = g_strconcat (end_sep, date, mid_sep, NULL);
198 part2 = g_strconcat (part1, ss, mid_sep, NULL);
205 part1 = g_strconcat (part2, currentSel, mid_sep, NULL);
210 part1 = g_strconcat (part2, mid_sep, NULL);
215 str_temp = csv_txn_test_field_string (info, currentSel);
216 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
221 str_temp = csv_txn_test_field_string (info, currentSel);
222 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
227 str_temp = csv_txn_test_field_string (info, currentSel);
228 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
233 str_temp = csv_txn_test_field_string (info, currentSel);
234 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
239 str_temp = csv_txn_test_field_string (info, currentSel);
240 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
245 str_temp = csv_txn_test_field_string (info, full_path);
246 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
250 part2 = g_strconcat (part1, NULL);
254 str_temp = csv_txn_test_field_string (info, currentSel);
255 part1 = g_strconcat (part2, str_temp, mid_sep,
"T", mid_sep,
"", mid_sep, NULL);
259 part2 = g_strconcat (part1, NULL);
264 part1 = g_strconcat (part2, currentSel, mid_sep, NULL);
268 part2 = g_strconcat (part1,
"", mid_sep, NULL);
272 part1 = g_strconcat (part2,
"", mid_sep, NULL);
277 str_temp = csv_txn_test_field_string (info, currentSel);
278 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
284 str_temp = csv_txn_test_field_string (info, currentSel);
285 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
290 part2 = g_strconcat (part1,
"", mid_sep, NULL);
294 part1 = g_strconcat (part2,
"", mid_sep,
"", mid_sep,
"", end_sep, EOLSTR, NULL);
298 if (!write_line_to_file (fh, part1))
308 while ((cnt < nSplits) && (info->failed == FALSE))
310 gchar *fullname = NULL;
311 const gchar *str_rec_date;
313 t_split = node->data;
328 str_temp = csv_txn_test_field_string (info, currentSel);
329 part1 = g_strconcat (end_sep, mid_sep, mid_sep, str_rec_date, mid_sep, mid_sep, mid_sep, mid_sep, str_temp, mid_sep, NULL);
333 part1 = g_strconcat (end_sep, mid_sep, mid_sep, str_rec_date, mid_sep, mid_sep, mid_sep, mid_sep, mid_sep, NULL);
337 str_temp = csv_txn_test_field_string (info, currentSel);
338 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
344 str_temp = csv_txn_test_field_string (info, fullname);
345 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
350 part2 = g_strconcat (part1, NULL);
355 str_temp = csv_txn_test_field_string (info, currentSel);
356 part1 = g_strconcat (part2, str_temp, mid_sep,
"S", mid_sep, NULL);
362 str_temp = csv_txn_test_field_string (info, currentSel);
363 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
369 part1 = g_strconcat (part2, currentSel, mid_sep, NULL);
373 split_amount = xaccPrintAmount (
xaccSplitGetAmount (t_split), gnc_split_amount_print_info (t_split, TRUE));
374 str_temp = csv_txn_test_field_string (info, split_amount);
376 part2 = g_strconcat (part1, str_temp, mid_sep, mid_sep, NULL);
378 part2 = g_strconcat (part1, mid_sep, str_temp, mid_sep, NULL);
384 str_temp = csv_txn_test_field_string (info, currentSel);
385 part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
391 str_temp = csv_txn_test_field_string (info, currentSel);
392 part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
400 split_amount = xaccPrintAmount (
xaccSplitGetAmount (t_split), gnc_split_amount_print_info (t_split, FALSE));
401 str_temp = csv_txn_test_field_string (info, split_amount);
403 part1 = g_strconcat (part2, str_temp, mid_sep, mid_sep, NULL);
405 part1 = g_strconcat (part2, mid_sep, str_temp, mid_sep, NULL);
414 split_amount = xaccPrintAmount (cf, gnc_split_amount_print_info (t_split, FALSE));
417 split_amount = xaccPrintAmount (
xaccSplitGetSharePrice (t_split), gnc_split_amount_print_info (t_split, FALSE));
418 str_temp = csv_txn_test_field_string (info, split_amount);
420 part2 = g_strconcat (part1, str_temp, mid_sep, end_sep, EOLSTR, NULL);
422 part2 = g_strconcat (part1, mid_sep, str_temp, end_sep, EOLSTR, NULL);
426 if (!write_line_to_file (fh, part2))
434 info->trans_list = g_list_prepend (info->trans_list, trans);
439 g_list_free (splits);
456 DEBUG(
"File name is : %s", info->file_name);
458 info->failed = FALSE;
461 fh = g_fopen (info->file_name,
"w" );
470 if (info->use_quotes)
473 mid_sep = g_strconcat (
"\"", info->separator_str,
"\"", NULL);
478 mid_sep = g_strconcat (info->separator_str, NULL);
482 header = g_strconcat (end_sep, _(
"Date"), mid_sep, _(
"Transaction Type"), mid_sep, _(
"Second Date"),
483 mid_sep, _(
"Account Name"), mid_sep, (num_action ? _(
"Transaction Number") : _(
"Number")),
484 mid_sep, _(
"Description"), mid_sep, _(
"Notes"), mid_sep, _(
"Memo"),
485 mid_sep, _(
"Full Category Path"), mid_sep, _(
"Category"), mid_sep, _(
"Row Type"),
486 mid_sep, (num_action ? _(
"Number/Action") : _(
"Action")),
487 mid_sep, _(
"Reconcile"), mid_sep, _(
"To With Sym"), mid_sep, _(
"From With Sym"),
488 mid_sep, _(
"Commodity Mnemonic"), mid_sep, _(
"Commodity Namespace"),
489 mid_sep, _(
"To Num."), mid_sep, _(
"From Num."), mid_sep, _(
"To Rate/Price"),
490 mid_sep, _(
"From Rate/Price"),
491 end_sep, EOLSTR, NULL);
492 DEBUG(
"Header String: %s", header);
495 if (!write_line_to_file (fh, header))
506 for (ptr = info->csva.account_list, i = 0; ptr; ptr = g_list_next(ptr), i++)
510 account_splits (info, acc, fh);
512 g_list_free (info->trans_list);
char xaccTransGetTxnType(const Transaction *trans)
void xaccTransGetDateDueTS(const Transaction *trans, Timespec *ts)
time64 xaccTransGetDate(const Transaction *trans)
const char * gnc_print_date(Timespec ts)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
utility functions for the GnuCash UI
void qof_query_set_sort_order(QofQuery *q, QofQueryParamList *primary_sort_params, QofQueryParamList *secondary_sort_params, QofQueryParamList *tertiary_sort_params)
const char * xaccTransGetVoidReason(const Transaction *trans)
#define DEBUG(format, args...)
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
char xaccSplitGetReconcile(const Split *split)
Use a 64-bit unsigned int timespec.
void csv_transactions_export(CsvExportInfo *info)
Transaction * xaccSplitGetParent(const Split *split)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
const char * xaccTransGetNum(const Transaction *trans)
#define ENTER(format, args...)
void xaccSplitGetDateReconciledTS(const Split *split, Timespec *ts)
const char * xaccTransGetNotes(const Transaction *trans)
char * qof_print_date(time64 secs)
int xaccTransCountSplits(const Transaction *trans)
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
gchar * gnc_account_get_full_name(const Account *account)
void qof_query_destroy(QofQuery *q)
gnc_numeric xaccSplitVoidFormerValue(const Split *split)
void qof_query_set_book(QofQuery *q, QofBook *book)
char * xaccSplitGetCorrAccountFullName(const Split *sa)
const char * xaccTransGetDescription(const Transaction *trans)
gnc_numeric gnc_numeric_div(gnc_numeric x, gnc_numeric y, gint64 denom, gint how)
gnc_numeric xaccSplitGetSharePrice(const Split *split)
const char * xaccSplitGetCorrAccountName(const Split *sa)
gboolean xaccTransGetVoidStatus(const Transaction *trans)
GList * qof_query_run(QofQuery *query)
Account * xaccSplitGetAccount(const Split *s)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
#define LEAVE(format, args...)
#define QUERY_DEFAULT_SORT
const char * xaccSplitGetMemo(const Split *split)
const char * xaccSplitGetAction(const Split *split)
const char * xaccAccountGetName(const Account *acc)
API for Transactions and Splits (journal entries)
#define GNC_HOW_DENOM_SIGFIGS(n)
SplitList * xaccTransGetSplitList(const Transaction *trans)
Commodity handling public routines.
const gchar * QofLogModule
gnc_numeric xaccSplitGetAmount(const Split *split)