// 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; }
// 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; }
// 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; }
/******************************************************* * 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; 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); part2 = g_strconcat ( part1, currentSel, mid_sep, NULL); g_free(part1); /* Number */ currentSel = gnc_get_num_action(trans, NULL); part1 = g_strconcat ( part2, currentSel, mid_sep, NULL); g_free(part2); /* Description */ currentSel = xaccTransGetDescription(trans); part2 = g_strconcat ( part1, currentSel, mid_sep, NULL); g_free(part1); /* Notes */ currentSel = xaccTransGetNotes(trans); if (currentSel == NULL) part1 = g_strconcat ( part2, mid_sep, NULL); else part1 = g_strconcat ( part2, currentSel, mid_sep, NULL); g_free(part2); /* Memo */ currentSel = xaccSplitGetMemo(split); part2 = g_strconcat ( part1, currentSel, mid_sep, NULL); g_free(part1); /* Category */ currentSel = xaccSplitGetCorrAccountName(split); part1 = g_strconcat ( part2, currentSel, mid_sep, "T", mid_sep, NULL); g_free(part2); /* Action */ currentSel = gnc_get_num_action(NULL, split); part2 = g_strconcat ( part1, currentSel, mid_sep, NULL); 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)); part2 = g_strconcat ( part1, split_amount, mid_sep, NULL); 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)); part2 = g_strconcat ( part1, split_amount, mid_sep, NULL); g_free(part1); /* From Number Only */ part1 = g_strconcat ( part2, "", mid_sep, "", mid_sep, "", end_sep, "\n", 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); part2 = g_strconcat ( part1, currentSel, mid_sep, NULL); g_free(part1); /* Account */ currentSel = xaccAccountGetName( xaccSplitGetAccount(t_split)); part1 = g_strconcat ( part2, currentSel, mid_sep, "S", mid_sep, NULL); g_free(part2); /* Action */ currentSel = gnc_get_num_action(NULL, t_split); part2 = g_strconcat ( part1, currentSel, mid_sep, NULL); 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)); if (xaccSplitGetAccount(t_split) == acc) part2 = g_strconcat ( part1, split_amount, mid_sep, mid_sep, NULL); else part2 = g_strconcat ( part1, mid_sep, split_amount, mid_sep, NULL); g_free(part1); /* From / To Numbers only */ split_amount = xaccPrintAmount(xaccSplitGetAmount(t_split), gnc_split_amount_print_info(t_split, FALSE)); if (xaccSplitGetAccount(t_split) == acc) part1 = g_strconcat ( part2, split_amount, mid_sep, mid_sep, NULL); else part1 = g_strconcat ( part2, mid_sep, split_amount, mid_sep, NULL); g_free(part2); /* From / To - Share Price / Conversion factor */ split_amount = xaccPrintAmount(xaccSplitGetSharePrice(t_split), gnc_split_amount_print_info(t_split, FALSE)); if (xaccSplitGetAccount(t_split) == acc) part2 = g_strconcat ( part1, split_amount, mid_sep, end_sep, "\n", NULL); else part2 = g_strconcat ( part1, mid_sep, split_amount, end_sep, "\n", NULL); 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 ); }
static void downloaded_transaction_append(GNCImportMatchPicker * matcher, GNCImportTransInfo * transaction_info) { GtkListStore *store; GtkTreeIter iter; GtkTreeSelection *selection; Transaction *trans; Split *split; gchar *text; const gchar *ro_text; gboolean found = FALSE; GNCImportTransInfo *local_info; g_assert(matcher); g_assert(transaction_info); /*DEBUG("Begin");*/ /* Has the transaction already been added? */ store = GTK_LIST_STORE(gtk_tree_view_get_model(matcher->downloaded_view)); if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) { do { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DOWNLOADED_COL_INFO_PTR, &local_info, -1); if (local_info == transaction_info) { found = TRUE; break; } } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)); } if (!found) gtk_list_store_append(store, &iter); split = gnc_import_TransInfo_get_fsplit(transaction_info); trans = gnc_import_TransInfo_get_trans(transaction_info); /*Account*/ ro_text = xaccAccountGetName(xaccSplitGetAccount(split)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_ACCOUNT, ro_text, -1); /*Date*/ text = qof_print_date(xaccTransGetDate(trans)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_DATE, text, -1); g_free(text); /*Amount*/ ro_text = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_AMOUNT, ro_text, -1); /*Description*/ ro_text = xaccTransGetDescription(trans); gtk_list_store_set(store, &iter, DOWNLOADED_COL_DESCRIPTION, ro_text, -1); /*Memo*/ ro_text = xaccSplitGetMemo(split); gtk_list_store_set(store, &iter, DOWNLOADED_COL_MEMO, ro_text, -1); /*Imbalance*/ /* Assume that the importer won't create a transaction that involves two or more currencies and no non-currency commodity. In that case can use the simpler value imbalance check. */ ro_text = xaccPrintAmount(xaccTransGetImbalanceValue(trans), gnc_default_print_info(TRUE)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_BALANCED, ro_text, -1); gtk_list_store_set(store, &iter, DOWNLOADED_COL_INFO_PTR, transaction_info, -1); selection = gtk_tree_view_get_selection(matcher->downloaded_view); gtk_tree_selection_select_iter(selection, &iter); }
static void downloaded_transaction_changed_cb (GtkTreeSelection *selection, GNCImportMatchPicker *matcher) { GNCImportMatchInfo * match_info; GtkTreeModel *dl_model; GtkListStore *match_store; GtkTreeIter iter; GList * list_element; gchar *text; const gchar *ro_text; /*DEBUG("row: %d%s%d",row,", column: ",column);*/ /* Get the transaction info from the "downloaded" model. */ if (!gtk_tree_selection_get_selected(selection, &dl_model, &iter)) { matcher->selected_trans_info = NULL; return; } gtk_tree_model_get(dl_model, &iter, DOWNLOADED_COL_INFO_PTR, &matcher->selected_trans_info, -1); /* Now rewrite the "match" model based on that trans. */ match_store = GTK_LIST_STORE(gtk_tree_view_get_model(matcher->match_view)); gtk_list_store_clear(match_store); list_element = g_list_first (gnc_import_TransInfo_get_match_list (matcher->selected_trans_info)); while (list_element != NULL) { match_info = list_element->data; gtk_list_store_append(match_store, &iter); /* Print fields. */ /* Probability */ text = g_strdup_printf("%d", gnc_import_MatchInfo_get_probability (match_info)); gtk_list_store_set(match_store, &iter, MATCHER_COL_CONFIDENCE, text, -1); g_free(text); /* Date */ text = qof_print_date ( xaccTransGetDate ( xaccSplitGetParent ( gnc_import_MatchInfo_get_split(match_info) ) )); gtk_list_store_set(match_store, &iter, MATCHER_COL_DATE, text, -1); g_free(text); /* Amount */ ro_text = xaccPrintAmount( xaccSplitGetAmount ( gnc_import_MatchInfo_get_split(match_info) ), gnc_split_amount_print_info(gnc_import_MatchInfo_get_split(match_info), TRUE) ); gtk_list_store_set(match_store, &iter, MATCHER_COL_AMOUNT, ro_text, -1); /*Description*/ ro_text = xaccTransGetDescription ( xaccSplitGetParent( gnc_import_MatchInfo_get_split(match_info)) ); gtk_list_store_set(match_store, &iter, MATCHER_COL_DESCRIPTION, ro_text, -1); /*Split memo*/ ro_text = xaccSplitGetMemo(gnc_import_MatchInfo_get_split(match_info) ); gtk_list_store_set(match_store, &iter, MATCHER_COL_MEMO, ro_text, -1); gtk_list_store_set(match_store, &iter, MATCHER_COL_INFO_PTR, match_info, -1); if (gnc_import_MatchInfo_get_probability(match_info) != 0) { if (SHOW_NUMERIC_SCORE == TRUE) { gtk_list_store_set(match_store, &iter, MATCHER_COL_CONFIDENCE_PIXBUF, gen_probability_pixbuf(gnc_import_MatchInfo_get_probability(match_info), matcher->user_settings, GTK_WIDGET(matcher->match_view)), -1); } else { gtk_list_store_set(match_store, &iter, MATCHER_COL_CONFIDENCE_PIXBUF, gen_probability_pixbuf(gnc_import_MatchInfo_get_probability(match_info), matcher->user_settings, GTK_WIDGET(matcher->match_view)), -1); } } if (match_info == gnc_import_TransInfo_get_selected_match (matcher->selected_trans_info)) { GtkTreeSelection *selection; selection = gtk_tree_view_get_selection(matcher->match_view); gtk_tree_selection_select_iter(selection, &iter); } list_element = g_list_next(list_element); } }
static void refresh_model_row (GNCImportMainMatcher *gui, GtkTreeModel *model, GtkTreeIter *iter, GNCImportTransInfo *info) { GtkListStore *store; GtkTreeSelection *selection; gchar *tmp, *imbalance, *text, *color; const gchar *ro_text; Split *split; g_assert (gui); g_assert (model); g_assert (info); /*DEBUG("Begin");*/ store = GTK_LIST_STORE(model); gtk_list_store_set(store, iter, DOWNLOADED_COL_DATA, info, -1); /*Account:*/ split = gnc_import_TransInfo_get_fsplit (info); g_assert(split); // Must not be NULL ro_text = xaccAccountGetName(xaccSplitGetAccount(split)); gtk_list_store_set(store, iter, DOWNLOADED_COL_ACCOUNT, ro_text, -1); /*Date*/ text = qof_print_date ( xaccTransGetDate( gnc_import_TransInfo_get_trans(info) ) ); gtk_list_store_set(store, iter, DOWNLOADED_COL_DATE, text, -1); g_free(text); /*Amount*/ ro_text = xaccPrintAmount (xaccSplitGetAmount (split), gnc_split_amount_print_info(split, TRUE) ); gtk_list_store_set(store, iter, DOWNLOADED_COL_AMOUNT, ro_text, -1); /*Description*/ ro_text = xaccTransGetDescription(gnc_import_TransInfo_get_trans(info) ); gtk_list_store_set(store, iter, DOWNLOADED_COL_DESCRIPTION, ro_text, -1); /*Memo*/ ro_text = xaccSplitGetMemo(split); gtk_list_store_set(store, iter, DOWNLOADED_COL_MEMO, ro_text, -1); /*Actions*/ /* Action informations */ ro_text = text = color = NULL; switch (gnc_import_TransInfo_get_action(info)) { case GNCImport_ADD: if (gnc_import_TransInfo_is_balanced(info) == TRUE) { ro_text = _("New, already balanced"); color = COLOR_GREEN; } else { /* Assume that importers won't create transactions in two or more currencies so we can use xaccTransGetImbalanceValue */ imbalance = g_strdup (xaccPrintAmount (gnc_numeric_neg(xaccTransGetImbalanceValue (gnc_import_TransInfo_get_trans(info) )), gnc_commodity_print_info (xaccTransGetCurrency(gnc_import_TransInfo_get_trans (info)), TRUE) )); if (gnc_import_TransInfo_get_destacc (info) != NULL) { color = COLOR_GREEN; tmp = gnc_account_get_full_name (gnc_import_TransInfo_get_destacc (info)); if (gnc_import_TransInfo_get_destacc_selected_manually(info) == TRUE) { text = /* Translators: %1$s is the amount to be transferred. %2$s is the destination account. */ g_strdup_printf(_("New, transfer %s to (manual) \"%s\""), imbalance, tmp); } else { text = /* Translators: %1$s is the amount to be transferred. %2$s is the destination account. */ g_strdup_printf(_("New, transfer %s to (auto) \"%s\""), imbalance, tmp); } g_free (tmp); } else { color = COLOR_YELLOW; text = /* Translators: %s is the amount to be transferred. */ g_strdup_printf(_("New, UNBALANCED (need acct to transfer %s)!"), imbalance); } g_free (imbalance); } break; case GNCImport_CLEAR: if (gnc_import_TransInfo_get_selected_match(info)) { color = COLOR_GREEN; if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Reconcile (manual) match"); } else { ro_text = _("Reconcile (auto) match"); } } else { color = COLOR_RED; ro_text = _("Match missing!"); } break; case GNCImport_UPDATE: if (gnc_import_TransInfo_get_selected_match(info)) { color = COLOR_GREEN; if (gnc_import_TransInfo_get_match_selected_manually(info) == TRUE) { ro_text = _("Update and reconcile (manual) match"); } else { ro_text = _("Update and reconcile (auto) match"); } } else { color = COLOR_RED; ro_text = _("Match missing!"); } break; case GNCImport_SKIP: color = COLOR_RED; ro_text = _("Do not import (no action selected)"); break; default: color = "white"; ro_text = "WRITEME, this is an unknown action"; break; } gtk_list_store_set(store, iter, DOWNLOADED_COL_COLOR, color, DOWNLOADED_COL_ACTION_INFO, ro_text ? ro_text : text, -1); if (text) g_free(text); /* Set the pixmaps */ gtk_list_store_set(store, iter, DOWNLOADED_COL_ACTION_ADD, gnc_import_TransInfo_get_action(info) == GNCImport_ADD, -1); if (gnc_import_TransInfo_get_action(info) == GNCImport_SKIP) { /*Show the best match's confidence pixmap in the info column*/ gtk_list_store_set(store, iter, DOWNLOADED_COL_ACTION_PIXBUF, gen_probability_pixbuf( gnc_import_MatchInfo_get_probability ( gnc_import_TransInfo_get_selected_match (info)), gui->user_settings, GTK_WIDGET(gui->view)), -1); } gtk_list_store_set(store, iter, DOWNLOADED_COL_ACTION_CLEAR, gnc_import_TransInfo_get_action(info) == GNCImport_CLEAR, -1); if (gnc_import_TransInfo_get_action(info) == GNCImport_CLEAR) { /*Show the best match's confidence pixmap in the info column*/ gtk_list_store_set(store, iter, DOWNLOADED_COL_ACTION_PIXBUF, gen_probability_pixbuf( gnc_import_MatchInfo_get_probability ( gnc_import_TransInfo_get_selected_match (info)), gui->user_settings, GTK_WIDGET(gui->view)), -1); } gtk_list_store_set(store, iter, DOWNLOADED_COL_ACTION_UPDATE, gnc_import_TransInfo_get_action(info) == GNCImport_UPDATE, -1); if (gnc_import_TransInfo_get_action(info) == GNCImport_UPDATE) { /*Show the best match's confidence pixmap in the info column*/ gtk_list_store_set(store, iter, DOWNLOADED_COL_ACTION_PIXBUF, gen_probability_pixbuf( gnc_import_MatchInfo_get_probability ( gnc_import_TransInfo_get_selected_match (info)), gui->user_settings, GTK_WIDGET(gui->view)), -1); } selection = gtk_tree_view_get_selection(gui->view); gtk_tree_selection_unselect_all(selection); }