static int get_num_xactions_before_date(QofBook *book, time_t close_date) { QofQuery *q; GSList *param; QofQueryPredData *pred; Timespec ts; GList *res, *n; int cnt = 0; q = qof_query_create_for(GNC_ID_TRANS); qof_query_set_max_results(q, -1); qof_query_set_book (q, book); /* Look for transactions earlier than the closing date */ param = g_slist_prepend (NULL, TRANS_DATE_POSTED); timespecFromTime_t (&ts, close_date); pred = qof_query_date_predicate (QOF_COMPARE_LTE, QOF_DATE_MATCH_NORMAL, ts); qof_query_add_term (q, param, pred, QOF_QUERY_FIRST_TERM); /* Run the query, find how many transactions there are */ res = qof_query_run (q); cnt = 0; for (n = res; n; n = n->next) cnt ++; qof_query_destroy (q); return cnt; }
static gboolean gettrans_dates(GtkWidget *parent, Account *gnc_acc, GWEN_TIME **from_date, GWEN_TIME **to_date) { Timespec last_timespec, until_timespec; time_t now = time(NULL); gboolean use_last_date = TRUE; gboolean use_earliest_date = TRUE; gboolean use_until_now = TRUE; g_return_val_if_fail(from_date && to_date, FALSE); /* Get time of last retrieval */ last_timespec = gnc_ab_get_account_trans_retrieval(gnc_acc); if (last_timespec.tv_sec == 0) { use_last_date = FALSE; timespecFromTime_t(&last_timespec, now); } timespecFromTime_t(&until_timespec, now); /* Let the user choose the date range of retrieval */ if (!gnc_ab_enter_daterange(parent, NULL, &last_timespec, &use_last_date, &use_earliest_date, &until_timespec, &use_until_now)) return FALSE; /* Now calculate from date */ if (use_earliest_date) { *from_date = NULL; } else { if (use_last_date) last_timespec = gnc_ab_get_account_trans_retrieval(gnc_acc); *from_date = GWEN_Time_fromSeconds(timespecToTime_t(last_timespec)); } /* Now calculate to date */ if (use_until_now) timespecFromTime_t(&until_timespec, now); *to_date = GWEN_Time_fromSeconds(timespecToTime_t(until_timespec)); return TRUE; }
/*********************************************************************** * @todo Maybe invoice checking should be done in gnc_bi_import_fix_bis (...) * rather than in here? But that is more concerned with ensuring the csv is consistent. * @param GtkListStore *store * @param guint *n_invoices_created * @param guint *n_invoices_updated * @return void ***********************************************************************/ void gnc_bi_import_create_bis (GtkListStore * store, QofBook * book, guint * n_invoices_created, guint * n_invoices_updated, gchar * type, gchar * open_mode ) { gboolean valid; GtkTreeIter iter; gchar *id, *date_opened, *owner_id, *billing_id, *notes; gchar *date, *desc, *action, *account, *quantity, *price, *disc_type, *disc_how, *discount, *taxable, *taxincluded, *tax_table; gchar *date_posted, *due_date, *account_posted, *memo_posted, *accumulatesplits; guint dummy; GncInvoice *invoice; GncOrder *order; GncEntry *entry; gint day, month, year; gnc_numeric n; GncOwner *owner; Account *acc; enum update {YES = GTK_RESPONSE_YES, NO = GTK_RESPONSE_NO} update; GtkWidget *dialog; Timespec today; GncPluginPage *new_page; InvoiceWindow *iw; // these arguments are needed g_return_if_fail (store && book); // allow to call this function without statistics if (!n_invoices_created) n_invoices_created = &dummy; if (!n_invoices_updated) n_invoices_updated = &dummy; *n_invoices_created = 0; *n_invoices_updated = 0; invoice = NULL; order = NULL; update = NO; valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); while (valid) { // Walk through the list, reading each row gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ID, &id, DATE_OPENED, &date_opened, DATE_POSTED, &date_posted, // if autoposting requested DUE_DATE, &due_date, // if autoposting requested ACCOUNT_POSTED, &account_posted, // if autoposting requested MEMO_POSTED, &memo_posted, // if autoposting requested ACCU_SPLITS, &accumulatesplits, // if autoposting requested OWNER_ID, &owner_id, BILLING_ID, &billing_id, NOTES, ¬es, DATE, &date, DESC, &desc, ACTION, &action, ACCOUNT, &account, QUANTITY, &quantity, PRICE, &price, DISC_TYPE, &disc_type, DISC_HOW, &disc_how, DISCOUNT, &discount, TAXABLE, &taxable, TAXINCLUDED, &taxincluded, TAX_TABLE, &tax_table, -1); // TODO: Assign a new invoice number if one is absent. BUT we don't want to assign a new invoice for every line!! // so we'd have to flag this up somehow or add an option in the import GUI. The former implies that we make // an assumption about what the importer (person) wants to do. It seems resonable that a CSV file full of items with // If an invoice exists then we add to it in this current schema. // no predefined invoice number is a new invoice that's in need of a new number. // This was not designed to satisfy the need for repeat invoices however, so maybe we need a another method for this, after all // It should be easier to copy an invoice with a new ID than to go through all this malarky. if (g_ascii_strcasecmp (type, "BILL") == 0) invoice = gnc_search_bill_on_id (book, id); else if (g_ascii_strcasecmp (type, "INVOICE") == 0) invoice = gnc_search_invoice_on_id (book, id); if (!invoice) { // new invoice invoice = gncInvoiceCreate (book); gncInvoiceSetID (invoice, id); owner = gncOwnerNew (); if (g_ascii_strcasecmp (type, "BILL") == 0) gncOwnerInitVendor (owner, gnc_search_vendor_on_id (book, owner_id)); else if (g_ascii_strcasecmp (type, "INVOICE") == 0) gncOwnerInitCustomer (owner, gnc_search_customer_on_id (book, owner_id)); gncInvoiceSetOwner (invoice, owner); gncInvoiceSetCurrency (invoice, gncOwnerGetCurrency (owner)); // Set the invoice currency based on the owner if (strlen (date_opened) != 0) // If a date is specified in CSV { qof_scan_date (date_opened, &day, &month, &year); gncInvoiceSetDateOpened (invoice, gnc_dmy2timespec (day, month, year)); } else // If no date in CSV { time_t now = time (NULL); Timespec now_timespec; timespecFromTime_t (&now_timespec, now); gncInvoiceSetDateOpened (invoice, now_timespec); } gncInvoiceSetBillingID (invoice, billing_id); gncInvoiceSetNotes (invoice, notes); gncInvoiceSetActive (invoice, TRUE); //if (g_ascii_strcasecmp(type,"INVOICE"))gncInvoiceSetBillTo( invoice, billto ); (*n_invoices_created)++; update = YES; // open new bill / invoice in a tab, if requested if (g_ascii_strcasecmp(open_mode, "ALL") == 0 || (g_ascii_strcasecmp(open_mode, "NOT_POSTED") == 0 && strlen(date_posted) == 0)) { iw = gnc_ui_invoice_edit (invoice); new_page = gnc_plugin_page_invoice_new (iw); } } // I want to warn the user that an existing billvoice exists, but not every // time. // An import can contain many lines usually referring to the same invoice. // NB: Posted invoices are NEVER updated. else // if invoice exists { if (gncInvoiceIsPosted (invoice)) // Is it already posted? { valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); continue; // If already posted then never import } if (update != YES) // Pop up a dialog to ask if updates are the expected action { dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_YES_NO, "%s", _("Are you sure you have bills/invoices to update?")); update = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); if (update == NO) { // Cleanup and leave g_free (id); g_free (date_opened); g_free (owner_id); g_free (billing_id); g_free (notes); g_free (date); g_free (desc); g_free (action); g_free (account); g_free (quantity); g_free (price); g_free (disc_type); g_free (disc_how); g_free (discount); g_free (taxable); g_free (taxincluded); g_free (tax_table); g_free (date_posted); g_free (due_date); g_free (account_posted); g_free (memo_posted); g_free (accumulatesplits); return; } } (*n_invoices_updated)++; } // add entry to invoice/bill entry = gncEntryCreate (book); qof_scan_date (date, &day, &month, &year); { GDate *date = g_date_new_dmy(day, month, year); gncEntrySetDateGDate (entry, date); g_date_free (date); } timespecFromTime_t (&today, time (NULL)); // set today to the current date gncEntrySetDateEntered (entry, today); gncEntrySetDescription (entry, desc); gncEntrySetAction (entry, action); n = gnc_numeric_zero (); gnc_exp_parser_parse (quantity, &n, NULL); gncEntrySetQuantity (entry, n); acc = gnc_account_lookup_for_register (gnc_get_current_root_account (), account); if (g_ascii_strcasecmp (type, "BILL") == 0) { gncEntrySetBillAccount (entry, acc); n = gnc_numeric_zero (); gnc_exp_parser_parse (price, &n, NULL); gncEntrySetBillPrice (entry, n); gncEntrySetBillTaxable (entry, text2bool (taxable)); gncEntrySetBillTaxIncluded (entry, text2bool (taxincluded)); gncEntrySetBillTaxTable (entry, gncTaxTableLookupByName (book, tax_table)); n = gnc_numeric_zero (); gnc_exp_parser_parse (discount, &n, NULL); gncBillAddEntry (invoice, entry); } else if (g_ascii_strcasecmp (type, "INVOICE") == 0) { gncEntrySetNotes (entry, notes); gncEntrySetInvAccount (entry, acc); n = gnc_numeric_zero (); gnc_exp_parser_parse (price, &n, NULL); gncEntrySetInvPrice (entry, n); gncEntrySetInvTaxable (entry, text2bool (taxable)); gncEntrySetInvTaxIncluded (entry, text2bool (taxincluded)); gncEntrySetInvTaxTable (entry, gncTaxTableLookupByName (book, tax_table)); n = gnc_numeric_zero (); gnc_exp_parser_parse (discount, &n, NULL); gncEntrySetInvDiscount (entry, n); gncEntrySetInvDiscountType (entry, text2disc_type (disc_type)); gncEntrySetInvDiscountHow (entry, text2disc_how (disc_how)); gncInvoiceAddEntry (invoice, entry); } valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter); // handle auto posting of invoices { gchar *new_id = NULL; Transaction *tnx; if (valid) gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, ID, &new_id, -1); if (g_strcmp0 (id, new_id) != 0) { // the next invoice id is different => try to autopost this invoice if (qof_scan_date (date_posted, &day, &month, &year)) { // autopost this invoice Timespec d1, d2; d1 = gnc_dmy2timespec (day, month, year); qof_scan_date (due_date, &day, &month, &year); // obtains the due date, or leaves it at date_posted d2 = gnc_dmy2timespec (day, month, year); acc = gnc_account_lookup_for_register (gnc_get_current_root_account (), account_posted); tnx = gncInvoicePostToAccount (invoice, acc, &d1, &d2, memo_posted, text2bool (accumulatesplits)); } } g_free (new_id); } // cleanup g_free (id); g_free (date_opened); g_free (owner_id); g_free (billing_id); g_free (notes); g_free (date); g_free (desc); g_free (action); g_free (account); g_free (quantity); g_free (price); g_free (disc_type); g_free (disc_how); g_free (discount); g_free (taxable); g_free (taxincluded); g_free (tax_table); g_free (date_posted); g_free (due_date); g_free (account_posted); g_free (memo_posted); g_free (accumulatesplits); } }
/** * @fixme Move this non-GUI code into the engine. **/ static void gnc_ui_accounts_recurse (Account *parent, GList **currency_list, GNCSummarybarOptions options) { gnc_numeric start_amount; gnc_numeric start_amount_default_currency; gnc_numeric end_amount; gnc_numeric end_amount_default_currency; GNCAccountType account_type; gnc_commodity * account_currency; gnc_commodity * euro_commodity; GNCCurrencyAcc *currency_accum = NULL; GNCCurrencyAcc *euro_accum = NULL; GNCCurrencyAcc *grand_total_accum = NULL; GNCCurrencyAcc *non_curr_accum = NULL; GList *children, *node; gboolean non_currency = FALSE; Timespec end_timespec; Timespec start_timespec; if (parent == NULL) return; children = gnc_account_get_children(parent); for (node = children; node; node = g_list_next(node)) { Account *account = node->data; account_type = xaccAccountGetType(account); account_currency = xaccAccountGetCommodity(account); if (options.grand_total) grand_total_accum = gnc_ui_get_currency_accumulator(currency_list, options.default_currency, TOTAL_GRAND_TOTAL); if (options.euro) { euro_commodity = gnc_get_euro (); euro_accum = gnc_ui_get_currency_accumulator(currency_list, euro_commodity, TOTAL_CURR_TOTAL); } else euro_commodity = NULL; if (!gnc_commodity_is_currency(account_currency)) { non_currency = TRUE; non_curr_accum = gnc_ui_get_currency_accumulator(currency_list, options.default_currency, TOTAL_NON_CURR_TOTAL); } if (!non_currency || options.non_currency) { currency_accum = gnc_ui_get_currency_accumulator(currency_list, account_currency, TOTAL_SINGLE); } switch (account_type) { case ACCT_TYPE_BANK: case ACCT_TYPE_CASH: case ACCT_TYPE_ASSET: case ACCT_TYPE_STOCK: case ACCT_TYPE_MUTUAL: case ACCT_TYPE_CREDIT: case ACCT_TYPE_LIABILITY: case ACCT_TYPE_PAYABLE: case ACCT_TYPE_RECEIVABLE: end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date); timespecFromTime_t(&end_timespec, options.end_date); end_amount_default_currency = xaccAccountConvertBalanceToCurrencyAsOfDate (account, end_amount, account_currency, options.default_currency, timespecToTime_t(timespecCanonicalDayTime(end_timespec))); if (!non_currency || options.non_currency) { currency_accum->assets = gnc_numeric_add (currency_accum->assets, end_amount, gnc_commodity_get_fraction (account_currency), GNC_HOW_RND_ROUND_HALF_UP); } if (non_currency) { non_curr_accum->assets = gnc_numeric_add (non_curr_accum->assets, end_amount_default_currency, gnc_commodity_get_fraction (options.default_currency), GNC_HOW_RND_ROUND_HALF_UP); } if (options.grand_total) { grand_total_accum->assets = gnc_numeric_add (grand_total_accum->assets, end_amount_default_currency, gnc_commodity_get_fraction (options.default_currency), GNC_HOW_RND_ROUND_HALF_UP); } if (options.euro && (currency_accum != euro_accum)) { euro_accum->assets = gnc_numeric_add (euro_accum->assets, gnc_convert_to_euro(account_currency, end_amount), gnc_commodity_get_fraction (euro_commodity), GNC_HOW_RND_ROUND_HALF_UP); } gnc_ui_accounts_recurse(account, currency_list, options); break; case ACCT_TYPE_INCOME: case ACCT_TYPE_EXPENSE: start_amount = xaccAccountGetBalanceAsOfDate(account, options.start_date); timespecFromTime_t(&start_timespec, options.start_date); start_amount_default_currency = xaccAccountConvertBalanceToCurrencyAsOfDate (account, start_amount, account_currency, options.default_currency, timespecToTime_t(timespecCanonicalDayTime(start_timespec))); end_amount = xaccAccountGetBalanceAsOfDate(account, options.end_date); timespecFromTime_t(&end_timespec, options.end_date); end_amount_default_currency = xaccAccountConvertBalanceToCurrencyAsOfDate (account, end_amount, account_currency, options.default_currency, timespecToTime_t(timespecCanonicalDayTime(end_timespec))); if (!non_currency || options.non_currency) { currency_accum->profits = gnc_numeric_add (currency_accum->profits, start_amount, gnc_commodity_get_fraction (account_currency), GNC_HOW_RND_ROUND_HALF_UP); currency_accum->profits = gnc_numeric_sub (currency_accum->profits, end_amount, gnc_commodity_get_fraction (account_currency), GNC_HOW_RND_ROUND_HALF_UP); } if (non_currency) { non_curr_accum->profits = gnc_numeric_add (non_curr_accum->profits, start_amount_default_currency, gnc_commodity_get_fraction (options.default_currency), GNC_HOW_RND_ROUND_HALF_UP); non_curr_accum->profits = gnc_numeric_sub (non_curr_accum->profits, end_amount_default_currency, gnc_commodity_get_fraction (options.default_currency), GNC_HOW_RND_ROUND_HALF_UP); } if (options.grand_total) { grand_total_accum->profits = gnc_numeric_add (grand_total_accum->profits, start_amount_default_currency, gnc_commodity_get_fraction (options.default_currency), GNC_HOW_RND_ROUND_HALF_UP); grand_total_accum->profits = gnc_numeric_sub (grand_total_accum->profits, end_amount_default_currency, gnc_commodity_get_fraction (options.default_currency), GNC_HOW_RND_ROUND_HALF_UP); } if (options.euro && (currency_accum != euro_accum)) { euro_accum->profits = gnc_numeric_add (euro_accum->profits, gnc_convert_to_euro(account_currency, start_amount), gnc_commodity_get_fraction (euro_commodity), GNC_HOW_RND_ROUND_HALF_UP); euro_accum->profits = gnc_numeric_sub (euro_accum->profits, gnc_convert_to_euro(account_currency, end_amount), gnc_commodity_get_fraction (euro_commodity), GNC_HOW_RND_ROUND_HALF_UP); } gnc_ui_accounts_recurse(account, currency_list, options); break; case ACCT_TYPE_EQUITY: /* no-op, see comments at top about summing assets */ break; /** * @fixme I don't know if this is right or if trading accounts should be * treated like income and expense accounts. **/ case ACCT_TYPE_TRADING: break; case ACCT_TYPE_CURRENCY: default: break; } } g_list_free(children); }
void gnc_ab_gettrans(GtkWidget *parent, Account *gnc_acc) { AB_BANKING *api; gboolean online = FALSE; AB_ACCOUNT *ab_acc; GWEN_TIME *from_date = NULL, *to_date = NULL; Timespec until_timespec; AB_JOB *job = NULL; AB_JOB_LIST2 *job_list = NULL; GncGWENGui *gui = NULL; AB_IMEXPORTER_CONTEXT *context = NULL; GncABImExContextImport *ieci = NULL; AB_JOB_STATUS job_status; g_return_if_fail(parent && gnc_acc); /* Get the API */ api = gnc_AB_BANKING_new(); if (!api) { g_warning("gnc_ab_gettrans: Couldn't get AqBanking API"); return; } if (AB_Banking_OnlineInit(api #ifdef AQBANKING_VERSION_4_EXACTLY , 0 #endif ) != 0) { g_warning("gnc_ab_gettrans: Couldn't initialize AqBanking API"); goto cleanup; } online = TRUE; /* Get the AqBanking Account */ ab_acc = gnc_ab_get_ab_account(api, gnc_acc); if (!ab_acc) { g_warning("gnc_ab_gettrans: No AqBanking account found"); gnc_error_dialog(parent, _("No valid online banking account assigned.")); goto cleanup; } /* Get the start and end dates for the GetTransactions job. */ if (!gettrans_dates(parent, gnc_acc, &from_date, &to_date)) { g_debug("gnc_ab_gettrans: gettrans_dates aborted"); goto cleanup; } /* Use this as a local storage for the until_time below. */ timespecFromTime_t(&until_timespec, GWEN_Time_toTime_t(to_date)); /* Get a GetTransactions job and enqueue it */ job = AB_JobGetTransactions_new(ab_acc); if (!job || AB_Job_CheckAvailability(job #ifndef AQBANKING_VERSION_5_PLUS , 0 #endif )) { g_warning("gnc_ab_gettrans: JobGetTransactions not available for this " "account"); gnc_error_dialog(parent, _("Online action \"Get Transactions\" not available for this account.")); goto cleanup; } AB_JobGetTransactions_SetFromTime(job, from_date); AB_JobGetTransactions_SetToTime(job, to_date); job_list = AB_Job_List2_new(); AB_Job_List2_PushBack(job_list, job); /* Get a GUI object */ gui = gnc_GWEN_Gui_get(parent); if (!gui) { g_warning("gnc_ab_gettrans: Couldn't initialize Gwenhywfar GUI"); goto cleanup; } /* Create a context to store the results */ context = AB_ImExporterContext_new(); /* Execute the job */ AB_Banking_ExecuteJobs(api, job_list, context #ifndef AQBANKING_VERSION_5_PLUS , 0 #endif ); /* Ignore the return value of AB_Banking_ExecuteJobs(), as the job's * status always describes better whether the job was actually * transferred to and accepted by the bank. See also * http://lists.gnucash.org/pipermail/gnucash-de/2008-September/006389.html */ job_status = AB_Job_GetStatus(job); if (job_status != AB_Job_StatusFinished && job_status != AB_Job_StatusPending) { g_warning("gnc_ab_gettrans: Error on executing job"); gnc_error_dialog(parent, _("Error on executing job.\n\nStatus: %s - %s") , AB_Job_Status2Char(job_status) , AB_Job_GetResultText(job)); goto cleanup; } /* Import the results */ ieci = gnc_ab_import_context(context, AWAIT_TRANSACTIONS, FALSE, NULL, parent); if (!(gnc_ab_ieci_get_found(ieci) & FOUND_TRANSACTIONS)) { /* No transaction found */ GtkWidget *dialog = gtk_message_dialog_new( GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", _("The Online Banking import returned no transactions " "for the selected time period.")); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } /* Store the date of this retrieval */ gnc_ab_set_account_trans_retrieval(gnc_acc, until_timespec); cleanup: if (ieci) g_free(ieci); if (context) AB_ImExporterContext_free(context); if (gui) gnc_GWEN_Gui_release(gui); if (job_list) AB_Job_List2_free(job_list); if (job) AB_Job_free(job); if (to_date) GWEN_Time_free(to_date); if (from_date) GWEN_Time_free(from_date); if (online) #ifdef AQBANKING_VERSION_4_EXACTLY AB_Banking_OnlineFini(api, 0); #else AB_Banking_OnlineFini(api); #endif gnc_AB_BANKING_fini(api); }
static gboolean ap_close_period (GnomeDruidPage *druidpage, GtkWidget *druid, gpointer user_data) { AcctPeriodInfo *info = user_data; QofBook *closed_book = NULL, *current_book; const char *btitle; char *bnotes; Timespec closing_date; KvpFrame *book_frame; gboolean really_do_close_books = FALSE; ENTER("info=%p", info); current_book = gnc_get_current_book (); btitle = gtk_entry_get_text (info->book_title); bnotes = xxxgtk_textview_get_text (info->book_notes); PINFO("book title=%s\n", btitle); timespecFromTime_t (&closing_date, gnc_timet_get_day_end_gdate (&info->closing_date)); #define REALLY_DO_CLOSE_BOOKS #ifdef REALLY_DO_CLOSE_BOOKS really_do_close_books = TRUE; #endif /* REALLY_DO_CLOSE_BOOKS */ if (really_do_close_books) { /* Close the books ! */ qof_event_suspend (); gnc_suspend_gui_refresh (); scrub_all(); closed_book = gnc_book_close_period (current_book, closing_date, NULL, btitle); book_frame = qof_book_get_slots(closed_book); kvp_frame_set_str (book_frame, "/book/title", btitle); kvp_frame_set_str (book_frame, "/book/notes", bnotes); qof_session_add_book (gnc_get_current_session(), closed_book); /* We must save now; if we don't, and the user bails without saving, * then opening account balances will be incorrect, and this can only * lead to unhappiness. */ gnc_file_save (); gnc_resume_gui_refresh (); qof_event_resume (); gnc_gui_refresh_all (); /* resume above should have been enough ??? */ } g_free(bnotes); /* Report the status back to the user. */ info->close_status = 0; /* XXX fixme success or failure? */ /* Find the next closing date ... */ info->prev_closing_date = info->closing_date; recurrenceListNextInstance(info->period, &info->prev_closing_date, &info->closing_date); /* If the next closing date is in the future, then we are done. */ if (time(NULL) < gnc_timet_get_day_end_gdate (&info->closing_date)) { return FALSE; } /* Load up the GUI for the next closing period. */ gnc_frequency_setup_recurrence(info->period_menu, NULL, &info->closing_date); show_book_details (info); return TRUE; }
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); }
static void gnc_plugin_business_cmd_test_init_data (GtkAction *action, GncMainWindowActionData *data) { QofBook *book = gnc_get_current_book(); GncCustomer *customer = gncCustomerCreate(book); GncAddress *address = gncCustomerGetAddr(customer); GncInvoice *invoice = gncInvoiceCreate(book); GncOwner *owner = gncOwnerCreate(); GncJob *job = gncJobCreate(book); Account *root = gnc_book_get_root_account(book); Account *inc_acct = xaccMallocAccount(book); Account *bank_acct = xaccMallocAccount(book); Account *tax_acct = xaccMallocAccount(book); Account *ar_acct = xaccMallocAccount(book); Timespec now; // Create Customer gncCustomerSetID(customer, "000001"); gncCustomerSetName(customer, "Test Customer"); gncCustomerSetCurrency(customer, gnc_default_currency()); gncAddressSetName(address, "Contact Person"); gncAddressSetAddr1(address, "20 Customer Lane"); gncAddressSetAddr2(address, "Customer M/S"); gncAddressSetAddr3(address, "Addr3, XXX 12345"); // Create the Owner gncOwnerInitCustomer(owner, customer); // Create the Invoice timespecFromTime_t(&now, time(NULL)); gncInvoiceSetID(invoice, "000012"); gncInvoiceSetOwner(invoice, owner); gncInvoiceSetDateOpened(invoice, now); gncInvoiceSetCurrency(invoice, gnc_default_currency()); // Create the Job gncJobSetID(job, "000025"); gncJobSetName(job, "Test Job"); gncJobSetReference(job, "Customer's ref#"); gncJobSetOwner(job, owner); // MODIFY THE OWNER gncOwnerInitJob(owner, job); // Create the A/R account xaccAccountSetType(ar_acct, ACCT_TYPE_RECEIVABLE); xaccAccountSetName(ar_acct, "A/R"); xaccAccountSetCommodity(ar_acct, gnc_default_currency()); gnc_account_append_child(root, ar_acct); // Create the Income account xaccAccountSetType(inc_acct, ACCT_TYPE_INCOME); xaccAccountSetName(inc_acct, "Income"); xaccAccountSetCommodity(inc_acct, gnc_default_currency()); gnc_account_append_child(root, inc_acct); // Create the Bank account xaccAccountSetType(bank_acct, ACCT_TYPE_BANK); xaccAccountSetName(bank_acct, "Bank"); xaccAccountSetCommodity(bank_acct, gnc_default_currency()); gnc_account_append_child(root, bank_acct); // Create the Tax account xaccAccountSetType(tax_acct, ACCT_TYPE_LIABILITY); xaccAccountSetName(tax_acct, "Tax-Holding"); xaccAccountSetCommodity(tax_acct, gnc_default_currency()); gnc_account_append_child(root, tax_acct); // Launch the invoice editor gnc_ui_invoice_edit(invoice); }