GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
csv-transactions-export.h File Reference

CSV Export Transactions. More...

#include "assistant-csv-export.h"

Go to the source code of this file.

Functions

void csv_transactions_export (CsvExportInfo *info)
 

Detailed Description

CSV Export Transactions.

Author
Copyright (c) 2012 Robert Fewell

Definition in file csv-transactions-export.h.

Function Documentation

void csv_transactions_export ( CsvExportInfo info)

The csv_transactions_export() will let the user export the transactions to a delimited file.

Definition at line 448 of file csv-transactions-export.c.

449 {
450  FILE *fh;
451  Account *acc;
452  GList *ptr;
453  gboolean num_action = qof_book_use_split_action_for_num_field(gnc_get_current_book());
454 
455  ENTER("");
456  DEBUG("File name is : %s", info->file_name);
457 
458  info->failed = FALSE;
459 
460  /* Open File for writing */
461  fh = g_fopen (info->file_name, "w" );
462  if (fh != NULL)
463  {
464  gchar *header;
465  gchar *end_sep;
466  gchar *mid_sep;
467  int i;
468 
469  /* Set up separators */
470  if (info->use_quotes)
471  {
472  end_sep = "\"";
473  mid_sep = g_strconcat ("\"", info->separator_str, "\"", NULL);
474  }
475  else
476  {
477  end_sep = "";
478  mid_sep = g_strconcat (info->separator_str, NULL);
479  }
480 
481  /* Header string */
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);
493 
494  /* Write header line */
495  if (!write_line_to_file (fh, header))
496  {
497  info->failed = TRUE;
498  g_free (mid_sep);
499  g_free (header);
500  return;
501  }
502  g_free (mid_sep);
503  g_free (header);
504 
505  /* Go through list of accounts */
506  for (ptr = info->csva.account_list, i = 0; ptr; ptr = g_list_next(ptr), i++)
507  {
508  acc = ptr->data;
509  DEBUG("Account being processed is : %s", xaccAccountGetName (acc));
510  account_splits (info, acc, fh);
511  }
512  g_list_free (info->trans_list); // free trans_list
513  }
514  else
515  info->failed = TRUE;
516  if (fh)
517  fclose (fh);
518  LEAVE("");
519 }
#define DEBUG(format, args...)
Definition: qoflog.h:255
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
const char * xaccAccountGetName(const Account *acc)
Definition: Account.c:3031