// 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; }
static void add_quickfill_completions(TableLayout *layout, Transaction *trans, Split *split, gboolean has_last_num) { Split *s; int i = 0; gnc_quickfill_cell_add_completion( (QuickFillCell *) gnc_table_layout_get_cell(layout, DESC_CELL), xaccTransGetDescription(trans)); gnc_quickfill_cell_add_completion( (QuickFillCell *) gnc_table_layout_get_cell(layout, NOTES_CELL), xaccTransGetNotes(trans)); if (!has_last_num) gnc_num_cell_set_last_num( (NumCell *) gnc_table_layout_get_cell(layout, NUM_CELL), gnc_get_num_action(trans, split)); while ((s = xaccTransGetSplit(trans, i)) != NULL) { gnc_quickfill_cell_add_completion( (QuickFillCell *) gnc_table_layout_get_cell(layout, MEMO_CELL), xaccSplitGetMemo(s)); i++; } }
static guint sxftd_add_template_trans(SXFromTransInfo *sxfti) { Transaction *tr = sxfti->trans; GList *tt_list = NULL; GList *splits, *template_splits = NULL; TTInfo *tti = gnc_ttinfo_malloc(); TTSplitInfo *ttsi; Split *sp; gnc_numeric runningBalance; gnc_numeric split_value; const char *tmpStr; runningBalance = gnc_numeric_zero(); gnc_ttinfo_set_description(tti, xaccTransGetDescription(tr)); gnc_ttinfo_set_num(tti, gnc_get_num_action(tr, NULL)); gnc_ttinfo_set_notes (tti, xaccTransGetNotes (tr)); gnc_ttinfo_set_currency(tti, xaccTransGetCurrency(tr)); for (splits = xaccTransGetSplitList(tr); splits; splits = splits->next) { sp = splits->data; ttsi = gnc_ttsplitinfo_malloc(); gnc_ttsplitinfo_set_action(ttsi, gnc_get_num_action(NULL, sp)); split_value = xaccSplitGetValue(sp); gnc_ttsplitinfo_set_memo(ttsi, xaccSplitGetMemo(sp)); runningBalance = gnc_numeric_add( runningBalance, split_value, 100, (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); if (gnc_numeric_positive_p(split_value)) { tmpStr = xaccPrintAmount( split_value, gnc_default_print_info(FALSE) ); gnc_ttsplitinfo_set_debit_formula( ttsi, tmpStr ); } else { /* Negate the numeric so it prints w/o the sign at the front. */ tmpStr = xaccPrintAmount( gnc_numeric_neg( split_value ), gnc_default_print_info(FALSE) ); gnc_ttsplitinfo_set_credit_formula( ttsi, tmpStr ); } /* Copy over per-split account info */ gnc_ttsplitinfo_set_account( ttsi, xaccSplitGetAccount( sp ) ); template_splits = g_list_append(template_splits, ttsi); } if ( ! gnc_numeric_zero_p( runningBalance ) && !gnc_verify_dialog( (GtkWidget *)sxfti->dialog, FALSE, "%s", _("The Scheduled Transaction Editor " "cannot automatically balance " "this transaction. " "Should it still be " "entered?") ) ) { return SXFTD_ERRNO_UNBALANCED_XACTION; } gnc_ttinfo_set_template_splits(tti, template_splits); tt_list = g_list_append(tt_list, tti); gnc_suspend_gui_refresh (); xaccSchedXactionSetTemplateTrans(sxfti->sx, tt_list, gnc_get_current_book ()); gnc_resume_gui_refresh (); return 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; 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 gboolean create_each_transaction_helper(Transaction *template_txn, void *user_data) { Transaction *new_txn; GList *txn_splits, *template_splits; Split *copying_split; gnc_commodity *first_cmdty = NULL; gboolean err_flag = FALSE; SxTxnCreationData *creation_data; creation_data = (SxTxnCreationData*)user_data; /* FIXME: In general, this should [correctly] deal with errors such as not finding the approrpiate Accounts and not being able to parse the formula|credit/debit strings. */ new_txn = xaccTransClone(template_txn); xaccTransBeginEdit(new_txn); g_debug("creating template txn desc [%s] for sx [%s]", xaccTransGetDescription(new_txn), xaccSchedXactionGetName(creation_data->instance->parent->sx)); /* clear any copied KVP data */ qof_instance_set_slots(QOF_INSTANCE(new_txn), kvp_frame_new()); /* Bug#500427: copy the notes, if any */ if (xaccTransGetNotes(template_txn) != NULL) { xaccTransSetNotes(new_txn, g_strdup(xaccTransGetNotes(template_txn))); } xaccTransSetDate(new_txn, g_date_get_day(&creation_data->instance->date), g_date_get_month(&creation_data->instance->date), g_date_get_year(&creation_data->instance->date)); /* the accounts and amounts are in the kvp_frames of the splits. */ template_splits = xaccTransGetSplitList(template_txn); txn_splits = xaccTransGetSplitList(new_txn); if ((template_splits == NULL) || (txn_splits == NULL)) { g_critical("transaction w/o splits for sx [%s]", xaccSchedXactionGetName(creation_data->instance->parent->sx)); xaccTransDestroy(new_txn); xaccTransCommitEdit(new_txn); return FALSE; } for (; txn_splits && template_splits; txn_splits = txn_splits->next, template_splits = template_splits->next) { Split *template_split; Account *split_acct; gnc_commodity *split_cmdty = NULL; /* FIXME: Ick. This assumes that the split lists will be ordered identically. :( They are, but we'd rather not have to count on it. --jsled */ template_split = (Split*)template_splits->data; copying_split = (Split*)txn_splits->data; if (!_get_template_split_account(creation_data->instance, template_split, &split_acct, creation_data->creation_errors)) { err_flag = TRUE; break; } /* clear out any copied Split frame data. */ qof_instance_set_slots(QOF_INSTANCE(copying_split), kvp_frame_new()); split_cmdty = xaccAccountGetCommodity(split_acct); if (first_cmdty == NULL) { first_cmdty = split_cmdty; xaccTransSetCurrency(new_txn, first_cmdty); } xaccSplitSetAccount(copying_split, split_acct); { gnc_numeric credit_num, debit_num, final; gint gncn_error; credit_num = gnc_numeric_zero(); debit_num = gnc_numeric_zero(); _get_credit_formula_value(creation_data->instance, template_split, &credit_num, creation_data->creation_errors); _get_debit_formula_value(creation_data->instance, template_split, &debit_num, creation_data->creation_errors); final = gnc_numeric_sub_fixed( debit_num, credit_num ); gncn_error = gnc_numeric_check(final); if (gncn_error != GNC_ERROR_OK) { GString *err = g_string_new(""); g_string_printf(err, "error %d in SX [%s] final gnc_numeric value, using 0 instead", gncn_error, xaccSchedXactionGetName(creation_data->instance->parent->sx)); g_critical("%s", err->str); if (creation_data->creation_errors != NULL) *creation_data->creation_errors = g_list_append(*creation_data->creation_errors, err); else g_string_free(err, TRUE); final = gnc_numeric_zero(); }
void xaccTransWriteLog (Transaction *trans, char flag) { GList *node; char trans_guid_str[GUID_ENCODING_LENGTH + 1]; char split_guid_str[GUID_ENCODING_LENGTH + 1]; const char *trans_notes; char dnow[100], dent[100], dpost[100], drecn[100]; Timespec ts; if (!gen_logs) return; if (!trans_log) return; timespecFromTime_t(&ts, time(NULL)); gnc_timespec_to_iso8601_buff (ts, dnow); timespecFromTime_t(&ts, trans->date_entered.tv_sec); gnc_timespec_to_iso8601_buff (ts, dent); timespecFromTime_t(&ts, trans->date_posted.tv_sec); gnc_timespec_to_iso8601_buff (ts, dpost); guid_to_string_buff (xaccTransGetGUID(trans), trans_guid_str); trans_notes = xaccTransGetNotes(trans); fprintf (trans_log, "===== START\n"); for (node = trans->splits; node; node = node->next) { Split *split = node->data; const char * accname = ""; char acc_guid_str[GUID_ENCODING_LENGTH + 1]; gnc_numeric amt, val; if (xaccSplitGetAccount(split)) { accname = xaccAccountGetName (xaccSplitGetAccount(split)); guid_to_string_buff(xaccAccountGetGUID(xaccSplitGetAccount(split)), acc_guid_str); } else { acc_guid_str[0] = '\0'; } timespecFromTime_t(&ts, split->date_reconciled.tv_sec); gnc_timespec_to_iso8601_buff (ts, drecn); guid_to_string_buff (xaccSplitGetGUID(split), split_guid_str); amt = xaccSplitGetAmount (split); val = xaccSplitGetValue (split); /* use tab-separated fields */ fprintf (trans_log, "%c\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t" "%s\t%s\t%s\t%s\t%c\t%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT "\t%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT "\t%s\n", flag, trans_guid_str, split_guid_str, /* trans+split make up unique id */ /* Note that the next three strings always exist, * so we don't need to test them. */ dnow, dent, dpost, acc_guid_str, accname ? accname : "", trans->num ? trans->num : "", trans->description ? trans->description : "", trans_notes ? trans_notes : "", split->memo ? split->memo : "", split->action ? split->action : "", split->reconciled, gnc_numeric_num(amt), gnc_numeric_denom(amt), gnc_numeric_num(val), gnc_numeric_denom(val), /* The next string always exists. No need to test it. */ drecn); } fprintf (trans_log, "===== END\n"); /* get data out to the disk */ fflush (trans_log); }