static void gnc_ledger_display_make_query (GNCLedgerDisplay *ld, gint limit, SplitRegisterType type) { Account *leader; GList *accounts; if (!ld) return; switch (ld->ld_type) { case LD_SINGLE: case LD_SUBACCOUNT: break; case LD_GL: return; default: PERR ("unknown ledger type: %d", ld->ld_type); return; } qof_query_destroy (ld->query); ld->query = qof_query_create_for(GNC_ID_SPLIT); /* This is a bit of a hack. The number of splits should be * configurable, or maybe we should go back a time range instead * of picking a number, or maybe we should be able to exclude * based on reconciled status. Anyway, this works for now. */ if ((limit != 0) && (type != SEARCH_LEDGER)) qof_query_set_max_results (ld->query, limit); qof_query_set_book (ld->query, gnc_get_current_book()); leader = gnc_ledger_display_leader (ld); if (ld->ld_type == LD_SUBACCOUNT) accounts = gnc_account_get_descendants (leader); else accounts = NULL; accounts = g_list_prepend (accounts, leader); xaccQueryAddAccountMatch (ld->query, accounts, QOF_GUID_MATCH_ANY, QOF_QUERY_AND); g_list_free (accounts); }
/* Opens up a general journal window. */ GNCLedgerDisplay * gnc_ledger_display_gl (void) { Query *query; time64 start; struct tm tm; GNCLedgerDisplay *ld; ENTER(" "); query = qof_query_create_for(GNC_ID_SPLIT); qof_query_set_book (query, gnc_get_current_book()); /* In lieu of not "mis-using" some portion of the infrastructure by writing * a bunch of new code, we just filter out the accounts of the template * transactions. While these are in a seperate Account trees just for this * reason, the query engine makes no distinction between Account trees. * See Gnome Bug 86302. * -- jsled */ { Account *tRoot; GList *al; tRoot = gnc_book_get_template_root( gnc_get_current_book() ); al = gnc_account_get_descendants( tRoot ); if (g_list_length(al) != 0) xaccQueryAddAccountMatch( query, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND ); g_list_free (al); al = NULL; tRoot = NULL; } gnc_tm_get_today_start(&tm); tm.tm_mon--; /* Default the register to the last month's worth of transactions. */ start = gnc_mktime (&tm); xaccQueryAddDateMatchTT (query, TRUE, start, FALSE, 0, QOF_QUERY_AND); ld = gnc_ledger_display_internal (NULL, query, LD_GL, GENERAL_JOURNAL, REG_STYLE_JOURNAL, FALSE, FALSE); LEAVE("%p", ld); return ld; }
GNCSearchWindow * gnc_ui_find_transactions_dialog_create2 (GNCLedgerDisplay2 * orig_ledg) { QofIdType type = GNC_ID_SPLIT; struct _ftd_data *ftd; static GList *params = NULL; QofQuery *start_q, *show_q = NULL; gboolean num_action = qof_book_use_split_action_for_num_field(gnc_get_current_book()); /* Build parameter list in reverse order */ if (params == NULL) { params = gnc_search_param_prepend (params, N_("All Accounts"), ACCOUNT_MATCH_ALL_TYPE, type, SPLIT_TRANS, TRANS_SPLITLIST, SPLIT_ACCOUNT_GUID, NULL); params = gnc_search_param_prepend (params, N_("Account"), GNC_ID_ACCOUNT, type, SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL); params = gnc_search_param_prepend (params, N_("Balanced"), NULL, type, SPLIT_TRANS, TRANS_IS_BALANCED, NULL); params = gnc_search_param_prepend (params, N_("Reconcile"), RECONCILED_MATCH_TYPE, type, SPLIT_RECONCILE, NULL); params = gnc_search_param_prepend (params, N_("Share Price"), NULL, type, SPLIT_SHARE_PRICE, NULL); params = gnc_search_param_prepend (params, N_("Shares"), NULL, type, SPLIT_AMOUNT, NULL); params = gnc_search_param_prepend (params, N_("Value"), NULL, type, SPLIT_VALUE, NULL); params = gnc_search_param_prepend (params, N_("Date Posted"), NULL, type, SPLIT_TRANS, TRANS_DATE_POSTED, NULL); params = gnc_search_param_prepend (params, N_("Notes"), NULL, type, SPLIT_TRANS, TRANS_NOTES, NULL); params = gnc_search_param_prepend (params, (num_action ? N_("Number/Action") : N_("Action")), NULL, type, SPLIT_ACTION, NULL); params = gnc_search_param_prepend (params, (num_action ? N_("Transaction Number") : N_("Number")), NULL, type, SPLIT_TRANS, TRANS_NUM, NULL); params = gnc_search_param_prepend (params, N_("Memo"), NULL, type, SPLIT_MEMO, NULL); params = gnc_search_param_prepend (params, N_("Description"), NULL, type, SPLIT_TRANS, TRANS_DESCRIPTION, NULL); } else { GList *l; for (l = params; l; l = l->next) { GNCSearchParam *param = l->data; if (num_action) { if (strcmp (param->title, N_("Action")) == 0) gnc_search_param_set_title (param, N_("Number/Action")); if (strcmp (param->title, N_("Number")) == 0) gnc_search_param_set_title (param, N_("Transaction Number")); } else { if (strcmp (param->title, N_("Number/Action")) == 0) gnc_search_param_set_title (param, N_("Action")); if (strcmp (param->title, N_("Transaction Number")) == 0) gnc_search_param_set_title (param, N_("Number")); } } } ftd = g_new0 (struct _ftd_data, 1); if (orig_ledg) { ftd->ledger_q = gnc_ledger_display2_get_query (orig_ledg); start_q = show_q = qof_query_copy (ftd->ledger_q); } else { start_q = qof_query_create (); qof_query_set_book (start_q, gnc_get_current_book ()); /* In lieu of not "mis-using" some portion of the infrastructure by writing * a bunch of new code, we just filter out the accounts of the template * transactions. While these are in a seperate Account trees just for this * reason, the query engine makes no distinction between Account trees. * See Gnome Bug 86302. * -- jsled * * copied from gnc-ledger-display2.c:gnc_ledger_display2_gl() -- warlord * * <jsled> Alternatively, you could look for a GNC_SX_ACCOUNT [SchedAction.h] * key in the KVP frame of the split. */ { Account *tRoot; GList *al; tRoot = gnc_book_get_template_root( gnc_get_current_book() ); al = gnc_account_get_descendants( tRoot ); xaccQueryAddAccountMatch( start_q, al, QOF_GUID_MATCH_NONE, QOF_QUERY_AND ); g_list_free (al); al = NULL; tRoot = NULL; } ftd->q = start_q; /* save this to destroy it later */ } ftd->sw = gnc_search_dialog_create (type, _("Find Transaction"), params, NULL, start_q, show_q, NULL, do_find_cb, NULL, ftd, free_ftd_cb, GNC_PREFS_GROUP_SEARCH, NULL); if (!ftd->sw) { free_ftd_cb (ftd); return NULL; } return ftd->sw; }
GtkWidget * gnc_reconcile_view_new (Account *account, GNCReconcileViewType type, time64 statement_date) { GNCReconcileView *view; GtkListStore *liststore; gboolean include_children, auto_check; GList *accounts = NULL; GList *splits; Query *query; g_return_val_if_fail (account, NULL); g_return_val_if_fail ((type == RECLIST_DEBIT) || (type == RECLIST_CREDIT), NULL); view = g_object_new (GNC_TYPE_RECONCILE_VIEW, NULL); /* Create the list store with 6 columns and add to treeview, column 0 will be a pointer to the entry */ liststore = gtk_list_store_new (6, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN ); gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (liststore)); g_object_unref (liststore); view->account = account; view->view_type = type; view->statement_date = statement_date; query = qof_query_create_for (GNC_ID_SPLIT); qof_query_set_book (query, gnc_get_current_book ()); include_children = xaccAccountGetReconcileChildrenStatus (account); if (include_children) accounts = gnc_account_get_descendants (account); /* match the account */ accounts = g_list_prepend (accounts, account); xaccQueryAddAccountMatch (query, accounts, QOF_GUID_MATCH_ANY, QOF_QUERY_AND); g_list_free (accounts); /* limit the matches to CREDITs and DEBITs only, depending on the type */ if (type == RECLIST_CREDIT) xaccQueryAddValueMatch(query, gnc_numeric_zero (), QOF_NUMERIC_MATCH_CREDIT, QOF_COMPARE_GTE, QOF_QUERY_AND); else xaccQueryAddValueMatch(query, gnc_numeric_zero (), QOF_NUMERIC_MATCH_DEBIT, QOF_COMPARE_GTE, QOF_QUERY_AND); /* limit the matches only to Cleared and Non-reconciled splits */ xaccQueryAddClearedMatch (query, CLEARED_NO | CLEARED_CLEARED, QOF_QUERY_AND); /* Initialize the QueryList */ gnc_reconcile_view_construct (view, query); /* find the list of splits to auto-reconcile */ auto_check = gnc_prefs_get_bool (GNC_PREFS_GROUP_RECONCILE, GNC_PREF_CHECK_CLEARED); if (auto_check) { time64 statement_date_day_end = gnc_time64_get_day_end(statement_date); for (splits = qof_query_run (query); splits; splits = splits->next) { Split *split = splits->data; char recn = xaccSplitGetReconcile (split); time64 trans_date = xaccTransGetDate (xaccSplitGetParent (split)); /* Just an extra verification that our query is correct ;) */ g_assert (recn == NREC || recn == CREC); if (recn == CREC && gnc_difftime (trans_date, statement_date_day_end) <= 0) g_hash_table_insert (view->reconciled, split, split); } } /* Free the query -- we don't need it anymore */ qof_query_destroy (query); return GTK_WIDGET (view); }