コード例 #1
0
// Split line start
static gchar*
begin_split_string (Transaction *trans, Split *split, gboolean t_void, CsvExportInfo *info)
{
    const gchar *str_rec_date;
    const gchar *start;
    gchar       *conv;
    gchar       *result;
    Timespec     ts = {0,0};

    if (xaccSplitGetReconcile (split) == YREC)
    {
        xaccSplitGetDateReconciledTS (split, &ts);
        str_rec_date = gnc_print_date (ts);
    }
    else
        str_rec_date = "";

    if (t_void)
    {
        start = xaccTransGetVoidReason (trans) ? xaccTransGetVoidReason (trans) : "" ;
        conv = csv_txn_test_field_string (info, start);
        result = g_strconcat (info->end_sep, info->mid_sep, info->mid_sep, str_rec_date,
                              info->mid_sep, info->mid_sep, info->mid_sep, info->mid_sep, conv, info->mid_sep, NULL);
        g_free (conv);
    }
    else
         result = g_strconcat (info->end_sep, info->mid_sep, info->mid_sep, str_rec_date,
                               info->mid_sep, info->mid_sep, info->mid_sep, info->mid_sep, info->mid_sep, NULL);

    return result;
}
コード例 #2
0
// Amount with Symbol or not
static gchar*
add_amount (gchar *so_far, Split *split, gboolean t_void, gboolean symbol, gint line_type, CsvExportInfo *info)
{
    const gchar *amt;
    gchar       *conv;
    gchar       *result;

    if (line_type == TRANS_COMPLEX)
        result = g_strconcat (so_far, "", info->mid_sep, NULL);
    else
    {
        if (symbol)
        {
            if (t_void)
                amt = xaccPrintAmount (gnc_numeric_zero(), gnc_split_amount_print_info (split, TRUE));
            else
                amt = xaccPrintAmount (xaccSplitGetAmount (split), gnc_split_amount_print_info (split, TRUE));
        }
        else
        {
            if (t_void)
                amt = xaccPrintAmount (xaccSplitVoidFormerAmount (split), gnc_split_amount_print_info (split, FALSE));
            else
                amt = xaccPrintAmount (xaccSplitGetAmount (split), gnc_split_amount_print_info (split, FALSE));
        }
        conv = csv_txn_test_field_string (info, amt);
        result = g_strconcat (so_far, conv, info->mid_sep, NULL);
        g_free (conv);
    }
    g_free (so_far);
    return result;
}
コード例 #3
0
// Account Name short or Long
static gchar*
add_account_name (gchar *so_far, Account *acc, Split *split, gboolean full, CsvExportInfo *info)
{
    gchar       *name = NULL;
    gchar       *conv;
    gchar       *result;
    Account     *account = NULL;

    if (split == NULL)
    {
        if (acc == NULL)
            name = g_strdup (" ");
        else
            account = acc;
    }
    else
        account = xaccSplitGetAccount (split);

    if (account != NULL)
    {
        if (full)
            name = gnc_account_get_full_name (account);
        else
            name = g_strdup (xaccAccountGetName (account));
    }
    conv = csv_txn_test_field_string (info, name);
    result = g_strconcat (so_far, conv, info->mid_sep, NULL);
    g_free (name);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #4
0
// Reconcile
static gchar*
add_reconcile (gchar *so_far, Split *split, CsvExportInfo *info)
{
    const gchar *recon;
    gchar       *conv;
    gchar       *result;

    recon = gnc_get_reconcile_str (xaccSplitGetReconcile (split));
    conv = csv_txn_test_field_string (info, recon);
    result = g_strconcat (so_far, conv, info->mid_sep, NULL);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #5
0
// Memo
static gchar*
add_memo (gchar *so_far, Split *split, CsvExportInfo *info)
{
    const gchar *memo;
    gchar       *conv;
    gchar       *result;

    memo = xaccSplitGetMemo (split) ? xaccSplitGetMemo (split) : "" ;
    conv = csv_txn_test_field_string (info, memo);
    result = g_strconcat (so_far, conv, info->mid_sep, NULL);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #6
0
// Notes
static gchar*
add_notes (gchar *so_far, Transaction *trans, CsvExportInfo *info)
{
    const gchar *notes;
    gchar       *conv;
    gchar       *result;

    notes = xaccTransGetNotes (trans) ? xaccTransGetNotes (trans) : "" ;
    conv = csv_txn_test_field_string (info, notes);
    result = g_strconcat (so_far, conv, info->mid_sep, NULL);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #7
0
// Description
static gchar*
add_description (gchar *so_far, Transaction *trans, CsvExportInfo *info)
{
    const gchar *desc;
    gchar       *conv;
    gchar       *result;

    desc = xaccTransGetDescription (trans) ? xaccTransGetDescription (trans) : "" ;
    conv = csv_txn_test_field_string (info, desc);
    result = g_strconcat (so_far, conv, info->mid_sep, NULL);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #8
0
// Share Price / Conversion factor
static gchar*
add_rate (gchar *so_far, Split *split, gboolean t_void, CsvExportInfo *info)
{
    const gchar *amt;
    gchar       *conv;
    gchar       *result;

    if (t_void)
        amt = xaccPrintAmount (gnc_numeric_zero(), gnc_split_amount_print_info (split, FALSE));
    else
        amt = xaccPrintAmount (xaccSplitGetSharePrice (split), gnc_split_amount_print_info (split, FALSE));

    conv = csv_txn_test_field_string (info, amt);
    result = g_strconcat (so_far, conv, info->end_sep, EOLSTR, NULL);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #9
0
// Commodity Namespace
static gchar*
add_comm_namespace (gchar *so_far, Transaction *trans, Split *split, CsvExportInfo *info)
{
    const gchar *comm_n;
    gchar       *conv;
    gchar       *result;

    if (split == NULL)
        comm_n = gnc_commodity_get_namespace (xaccTransGetCurrency (trans));
    else
        comm_n = gnc_commodity_get_namespace (xaccAccountGetCommodity (xaccSplitGetAccount(split)));

    conv = csv_txn_test_field_string (info, comm_n);
    result = g_strconcat (so_far, conv, info->mid_sep, NULL);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #10
0
// Action
static gchar*
add_action (gchar *so_far, Split *split, gint line_type, CsvExportInfo *info)
{
    const gchar *action;
    gchar       *conv;
    gchar       *result;

    if ((line_type == TRANS_COMPLEX)||(line_type == TRANS_SIMPLE))
        result = g_strconcat (so_far, "", info->mid_sep, NULL);
    else
    {
        action = xaccSplitGetAction (split);
        conv = csv_txn_test_field_string (info, action);
        result = g_strconcat (so_far, conv, info->mid_sep, NULL);
        g_free (conv);
    }
    g_free (so_far);
    return result;
}
コード例 #11
0
// Full Category Path or Not
static gchar*
add_category (gchar *so_far, Split *split, gboolean full, CsvExportInfo *info)
{
    gchar       *cat;
    gchar       *conv;
    gchar       *result;

    if (full)
        cat = xaccSplitGetCorrAccountFullName (split);
    else
        cat = g_strdup(xaccSplitGetCorrAccountName (split));

    conv = csv_txn_test_field_string (info, cat);
    result = g_strconcat (so_far, conv, info->mid_sep, NULL);
    g_free (cat);
    g_free (conv);
    g_free (so_far);
    return result;
}
コード例 #12
0
// Share Price / Conversion factor
static gchar*
add_price (gchar *so_far, Split *split, gboolean t_void, CsvExportInfo *info)
{
    const gchar *string_amount;
    gchar       *conv;
    gchar       *result;

    if (t_void)
    {
        gnc_numeric cf = gnc_numeric_div (xaccSplitVoidFormerValue (split), xaccSplitVoidFormerAmount (split), GNC_DENOM_AUTO,
                                                   GNC_HOW_DENOM_SIGFIGS(6) | GNC_HOW_RND_ROUND_HALF_UP);
        string_amount = xaccPrintAmount (cf, gnc_split_amount_print_info (split, FALSE));
    }
    else
        string_amount = xaccPrintAmount (xaccSplitGetSharePrice (split), gnc_split_amount_print_info (split, FALSE));

    conv = csv_txn_test_field_string (info, string_amount);
    result = g_strconcat (so_far, conv, info->end_sep, EOLSTR, NULL);
    g_free (conv);
    return result;
}
コード例 #13
0
/*******************************************************
 * account_splits
 *
 * gather the splits / transactions for an account and
 * send them to a file
 *******************************************************/
static
void account_splits (CsvExportInfo *info, Account *acc, FILE *fh )
{
    Query   *q;
    GSList  *p1, *p2;
    GList   *splits;
    QofBook *book;

    gchar   *end_sep;
    gchar   *mid_sep;

    q = qof_query_create_for (GNC_ID_SPLIT);
    book = gnc_get_current_book();
    qof_query_set_book (q, book);

    /* Set up separators */
    if (info->use_quotes)
    {
        end_sep = "\"";
        mid_sep = g_strconcat ("\"", info->separator_str, "\"", NULL);
    }
    else
    {
        end_sep = "";
        mid_sep = g_strconcat (info->separator_str, NULL);
    }

    /* Sort by transaction date */
    p1 = g_slist_prepend (NULL, TRANS_DATE_POSTED);
    p1 = g_slist_prepend (p1, SPLIT_TRANS);
    p2 = g_slist_prepend (NULL, QUERY_DEFAULT_SORT);
    qof_query_set_sort_order (q, p1, p2, NULL);

    xaccQueryAddSingleAccountMatch (q, acc, QOF_QUERY_AND);
    xaccQueryAddDateMatchTT (q, TRUE, info->csvd.start_time, TRUE, info->csvd.end_time, QOF_QUERY_AND);

    /* Run the query */
    for (splits = qof_query_run (q); splits; splits = splits->next)
    {
        Split       *split;
        Transaction *trans;
        SplitList   *s_list;
        GList       *node;
        Split       *t_split;
        int          nSplits;
        int          cnt;
        gchar       *part1;
        gchar       *part2;
        gchar       *date;
        const gchar *currentSel;
        const gchar *split_amount;
        gchar       *str_temp = NULL;

        split = splits->data;
        trans = xaccSplitGetParent (split);
        nSplits = xaccTransCountSplits (trans);
        s_list = xaccTransGetSplitList (trans);

        /* Date */
        date = qof_print_date (xaccTransGetDate (trans));
        part1 = g_strconcat (end_sep, date, mid_sep, NULL);
        g_free (date);
        /* Name */
        currentSel = xaccAccountGetName (acc);
        str_temp = csv_txn_test_field_string (info, currentSel);
        part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part1);
        /* Number */
        currentSel = gnc_get_num_action (trans, NULL);
        str_temp = csv_txn_test_field_string (info, currentSel);
        part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part2);
        /* Description */
        currentSel = xaccTransGetDescription (trans) ? xaccTransGetDescription (trans) : "" ;
        str_temp = csv_txn_test_field_string (info, currentSel);
        part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part1);
        /* Notes */
        currentSel = xaccTransGetNotes (trans) ? xaccTransGetNotes (trans) : "" ;
        str_temp = csv_txn_test_field_string (info, currentSel);
        part1 = g_strconcat (part2, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part2);
        /* Memo */
        currentSel = xaccSplitGetMemo (split) ? xaccSplitGetMemo (split) : "" ;
        str_temp = csv_txn_test_field_string (info, currentSel);
        part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part1);
        /* Category */
        currentSel = xaccSplitGetCorrAccountName (split);
        str_temp = csv_txn_test_field_string (info, currentSel);
        part1 = g_strconcat (part2, str_temp, mid_sep, "T", mid_sep, NULL);
        g_free (str_temp);
        g_free (part2);
        /* Action */
        currentSel = gnc_get_num_action (NULL, split);
        str_temp = csv_txn_test_field_string (info, currentSel);
        part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part1);
        /* Reconcile */
        switch (xaccSplitGetReconcile (split))
        {
        case NREC:
            currentSel = "N";
            break;
        case CREC:
            currentSel = "C";
            break;
        case YREC:
            currentSel = "Y";
            break;
        case FREC:
            currentSel = "F";
            break;
        case VREC:
            currentSel = "V";
            break;
        default:
            currentSel = "N";
        }
        part1 = g_strconcat (part2, currentSel, mid_sep, NULL);
        g_free (part2);
        /* To with Symbol */
        split_amount = xaccPrintAmount (xaccSplitGetAmount (split), gnc_split_amount_print_info (split, TRUE));
        str_temp = csv_txn_test_field_string (info, split_amount);
        part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part1);

        /* From with Symbol */
        part1 = g_strconcat (part2, "", mid_sep, NULL);
        g_free (part2);

        /* To Number Only */
        split_amount = xaccPrintAmount (xaccSplitGetAmount (split), gnc_split_amount_print_info (split, FALSE));
        str_temp = csv_txn_test_field_string (info, split_amount);
        part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
        g_free (str_temp);
        g_free (part1);

        /* From Number Only */
        part1 = g_strconcat (part2, "", mid_sep, "", mid_sep, "", end_sep, EOLSTR, NULL);
        g_free (part2);

        /* Write to file */
        if (!write_line_to_file(fh, part1))
        {
            info->failed = TRUE;
            break;
        }
        g_free (part1);

        /* Loop through the list of splits for the Transcation */
        node = s_list;
        cnt = 0;
        while ((cnt < nSplits) && (info->failed == FALSE))
        {
            t_split = node->data;

            /* Start of line */
            part1 = g_strconcat (end_sep, mid_sep, mid_sep, mid_sep, mid_sep, mid_sep, NULL);

            /* Memo */
            currentSel = xaccSplitGetMemo (t_split) ? xaccSplitGetMemo (t_split) : "" ;
            str_temp = csv_txn_test_field_string (info, currentSel);
            part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
            g_free (str_temp);
            g_free (part1);

            /* Account */
            currentSel = xaccAccountGetName (xaccSplitGetAccount (t_split));
            str_temp = csv_txn_test_field_string (info, currentSel);
            part1 = g_strconcat (part2, str_temp, mid_sep, "S", mid_sep, NULL);
            g_free (str_temp);
            g_free (part2);

            /* Action */
            currentSel = gnc_get_num_action (NULL, t_split);
            str_temp = csv_txn_test_field_string (info, currentSel);
            part2 = g_strconcat (part1, str_temp, mid_sep, NULL);
            g_free (str_temp);
            g_free (part1);

            /* Reconcile */
            switch (xaccSplitGetReconcile (split))
            {
            case NREC:
                currentSel = "N";
                break;
            case CREC:
                currentSel = "C";
                break;
            case YREC:
                currentSel = "Y";
                break;
            case FREC:
                currentSel = "F";
                break;
            case VREC:
                currentSel = "V";
                break;
            default:
                currentSel = "N";
            }
            part1 = g_strconcat (part2, currentSel, mid_sep, NULL);
            g_free (part2);

            /* From / To with Symbol */
            split_amount = xaccPrintAmount (xaccSplitGetAmount (t_split), gnc_split_amount_print_info (t_split, TRUE));
            str_temp = csv_txn_test_field_string (info, split_amount);
            if (xaccSplitGetAccount(t_split) == acc)
                part2 = g_strconcat (part1,  str_temp, mid_sep, mid_sep, NULL);
            else
                part2 = g_strconcat (part1, mid_sep, str_temp, mid_sep, NULL);
            g_free (str_temp);
            g_free (part1);

            /* From / To Numbers only */
            split_amount = xaccPrintAmount (xaccSplitGetAmount (t_split), gnc_split_amount_print_info (t_split, FALSE));
            str_temp = csv_txn_test_field_string (info, split_amount);
            if (xaccSplitGetAccount (t_split) == acc)
                part1 = g_strconcat (part2,  str_temp, mid_sep, mid_sep, NULL);
            else
                part1 = g_strconcat (part2, mid_sep, str_temp, mid_sep, NULL);
            g_free (str_temp);
            g_free (part2);

            /* From / To - Share Price / Conversion factor */
            split_amount = xaccPrintAmount (xaccSplitGetSharePrice (t_split), gnc_split_amount_print_info (t_split, FALSE));
            str_temp = csv_txn_test_field_string (info, split_amount);
            if (xaccSplitGetAccount (t_split) == acc)
                part2 = g_strconcat (part1,  str_temp, mid_sep, end_sep, EOLSTR, NULL);
             else
                part2 = g_strconcat (part1, mid_sep, str_temp, end_sep, EOLSTR, NULL);
            g_free (str_temp);
            g_free (part1);

            if (!write_line_to_file (fh, part2))
                info->failed = TRUE;

            g_free (part2);
            cnt++;
            node = node->next;
        }
    }
    g_free (mid_sep);
    qof_query_destroy (q);
    g_list_free (splits);
}