static void search_new_item_cb (GtkButton *button, GNCSearchWindow *sw) { gpointer res; g_return_if_fail (sw->new_item_cb); res = (sw->new_item_cb)(sw->user_data); if (res) { const GncGUID *guid = (const GncGUID *) ((sw->get_guid->param_getfcn)(res, sw->get_guid)); QofQueryOp op = QOF_QUERY_OR; if (!sw->q) { if (!sw->start_q) { sw->start_q = qof_query_create_for (sw->search_for); qof_query_set_book (sw->start_q, gnc_get_current_book ()); } sw->q = qof_query_copy (sw->start_q); op = QOF_QUERY_AND; } qof_query_add_guid_match (sw->q, g_slist_prepend (NULL, QOF_PARAM_GUID), guid, op); /* Watch this entity so we'll refresh once it's actually changed */ gnc_gui_component_watch_entity (sw->component_id, guid, QOF_EVENT_MODIFY); } }
/** Creates a new query that searches for an GncEntry item with * description string equal to the given "desc" argument. The query * will find the single GncEntry with the latest (=newest) * DATE_ENTERED. */ static QofQuery *new_query_for_entry_desc(GncEntryLedger *reg, const char* desc, gboolean use_invoice) { QofQuery *query = NULL; QofQueryPredData *predData = NULL; GSList *param_list = NULL; GSList *primary_sort_params = NULL; const char* should_be_null = (use_invoice ? ENTRY_BILL : ENTRY_INVOICE); g_assert(reg); g_assert(desc); /* The query itself and its book */ query = qof_query_create_for (GNC_ID_ENTRY); qof_query_set_book (query, reg->book); /* Predicate data: We want to compare one string, namely the given * argument */ predData = qof_query_string_predicate (QOF_COMPARE_EQUAL, desc, QOF_STRING_MATCH_CASEINSENSITIVE, FALSE); /* Search Parameter: We want to query on the ENTRY_DESC column */ param_list = qof_query_build_param_list (ENTRY_DESC, NULL); /* Register this in the query */ qof_query_add_term (query, param_list, predData, QOF_QUERY_FIRST_TERM); /* For invoice entries, Entry->Bill must be NULL, and vice versa */ qof_query_add_guid_match (query, qof_query_build_param_list (should_be_null, QOF_PARAM_GUID, NULL), NULL, QOF_QUERY_AND); /* Set the sort order: By DATE_ENTERED, increasing, and returning * only one single resulting item. */ primary_sort_params = qof_query_build_param_list(ENTRY_DATE_ENTERED, NULL); qof_query_set_sort_order (query, primary_sort_params, NULL, NULL); qof_query_set_sort_increasing (query, TRUE, TRUE, TRUE); qof_query_set_max_results(query, 1); return query; }
void xaccQueryAddGUIDMatch(QofQuery * q, const GncGUID *guid, QofIdType id_type, QofQueryOp op) { GSList *param_list = NULL; if (!q || !guid || !id_type) return; if (!g_strcmp0 (id_type, GNC_ID_SPLIT)) param_list = qof_query_build_param_list (QOF_PARAM_GUID, NULL); else if (!g_strcmp0 (id_type, GNC_ID_TRANS)) param_list = qof_query_build_param_list (SPLIT_TRANS, QOF_PARAM_GUID, NULL); else if (!g_strcmp0 (id_type, GNC_ID_ACCOUNT)) param_list = qof_query_build_param_list (SPLIT_ACCOUNT, QOF_PARAM_GUID, NULL); else PERR ("Invalid match type: %s", id_type); qof_query_add_guid_match (q, param_list, guid, op); }
GNCSearchWindow * gnc_customer_search (GncCustomer *start, QofBook *book) { QofQuery *q, *q2 = NULL; QofIdType type = GNC_CUSTOMER_MODULE_NAME; struct _customer_select_window *sw; static GList *params = NULL; static GList *columns = NULL; static GNCSearchCallbackButton buttons[] = { { N_("View/Edit Customer"), edit_customer_cb, NULL, TRUE}, { N_("Customer's Jobs"), jobs_customer_cb, NULL, TRUE}, // { N_("Customer's Orders"), order_customer_cb, NULL, TRUE}, { N_("Customer's Invoices"), invoice_customer_cb, NULL, TRUE}, { N_("Process Payment"), payment_customer_cb, NULL, FALSE}, { NULL }, }; (void)order_customer_cb; g_return_val_if_fail (book, NULL); /* Build parameter list in reverse order */ if (params == NULL) { params = gnc_search_param_prepend (params, _("Shipping Contact"), NULL, type, CUSTOMER_SHIPADDR, ADDRESS_NAME, NULL); params = gnc_search_param_prepend (params, _("Billing Contact"), NULL, type, CUSTOMER_ADDR, ADDRESS_NAME, NULL); params = gnc_search_param_prepend (params, _("Customer ID"), NULL, type, CUSTOMER_ID, NULL); params = gnc_search_param_prepend (params, _("Company Name"), NULL, type, CUSTOMER_NAME, NULL); } /* Build the column list in reverse order */ if (columns == NULL) { columns = gnc_search_param_prepend (columns, _("Contact"), NULL, type, CUSTOMER_ADDR, ADDRESS_NAME, NULL); columns = gnc_search_param_prepend (columns, _("Company"), NULL, type, CUSTOMER_NAME, NULL); columns = gnc_search_param_prepend (columns, _("ID #"), NULL, type, CUSTOMER_ID, NULL); } /* Build the queries */ q = qof_query_create_for (type); qof_query_set_book (q, book); #if 0 if (start) { q2 = qof_query_copy (q); qof_query_add_guid_match (q2, g_slist_prepend (NULL, QOF_PARAM_GUID), gncCustomerGetGUID (start), QOF_QUERY_AND); } #endif /* launch select dialog and return the result */ sw = g_new0 (struct _customer_select_window, 1); sw->book = book; sw->q = q; return gnc_search_dialog_create (type, _("Find Customer"), params, columns, q, q2, buttons, NULL, new_customer_cb, sw, free_userdata_cb, GCONF_SECTION_SEARCH, NULL); }
GNCSearchWindow * gnc_job_search (GncJob *start, GncOwner *owner, QofBook *book) { QofQuery *q, *q2 = NULL; QofIdType type = GNC_JOB_MODULE_NAME; struct _job_select_window *sw; static GList *params = NULL; static GList *columns = NULL; static GNCSearchCallbackButton buttons[] = { { N_("View/Edit Job"), edit_job_cb, NULL, TRUE}, { N_("View Invoices"), invoice_job_cb, NULL, TRUE}, { N_("Process Payment"), payment_job_cb, NULL, FALSE}, { NULL }, }; g_return_val_if_fail (book, NULL); /* Build parameter list in reverse order */ if (params == NULL) { params = gnc_search_param_prepend (params, _("Owner's Name"), NULL, type, JOB_OWNER, OWNER_NAME, NULL); params = gnc_search_param_prepend (params, _("Only Active?"), NULL, type, JOB_ACTIVE, NULL); params = gnc_search_param_prepend (params, _("Billing ID"), NULL, type, JOB_REFERENCE, NULL); params = gnc_search_param_prepend (params, _("Job Number"), NULL, type, JOB_ID, NULL); params = gnc_search_param_prepend (params, _("Job Name"), NULL, type, JOB_NAME, NULL); } /* Build the column list in reverse order */ if (columns == NULL) { columns = gnc_search_param_prepend (columns, _("Billing ID"), NULL, type, JOB_REFERENCE, NULL); columns = gnc_search_param_prepend (columns, _("Company"), NULL, type, JOB_OWNER, OWNER_NAME, NULL); columns = gnc_search_param_prepend (columns, _("Job Name"), NULL, type, JOB_NAME, NULL); columns = gnc_search_param_prepend (columns, _("ID #"), NULL, type, JOB_ID, NULL); } /* Build the queries */ q = qof_query_create_for (type); qof_query_set_book (q, book); /* If we have a start job but, for some reason, not an owner -- grab * the owner from the starting job. */ if ((!owner || !gncOwnerGetGUID (owner)) && start) owner = gncJobGetOwner (start); /* If owner is supplied, limit all searches to invoices who's owner * is the supplied owner! Show all invoices by this owner. */ if (owner && gncOwnerGetGUID (owner)) { qof_query_add_guid_match (q, g_slist_prepend (g_slist_prepend (NULL, QOF_PARAM_GUID), JOB_OWNER), gncOwnerGetGUID (owner), QOF_QUERY_AND); q2 = qof_query_copy (q); } #if 0 if (start) { if (q2 == NULL) q2 = qof_query_copy (q); qof_query_add_guid_match (q2, g_slist_prepend (NULL, QOF_PARAM_GUID), gncJobGetGUID (start), QOF_QUERY_AND); } #endif /* launch select dialog and return the result */ sw = g_new0 (struct _job_select_window, 1); if (owner) { gncOwnerCopy (owner, &(sw->owner_def)); sw->owner = &(sw->owner_def); } sw->book = book; sw->q = q; return gnc_search_dialog_create (type, _("Find Job"), params, columns, q, q2, buttons, NULL, new_job_cb, sw, free_userdata_cb, GCONF_SECTION_SEARCH, NULL); }
GNCSearchWindow * gnc_employee_search (GncEmployee *start, QofBook *book) { QofIdType type = GNC_EMPLOYEE_MODULE_NAME; struct _employee_select_window *sw; QofQuery *q, *q2 = NULL; static GList *params = NULL; static GList *columns = NULL; static GNCSearchCallbackButton buttons[] = { { N_("View/Edit Employee"), edit_employee_cb, NULL, TRUE}, { N_("Expense Vouchers"), invoice_employee_cb, NULL, TRUE}, { N_("Process Payment"), payment_employee_cb, NULL, FALSE}, { NULL }, }; g_return_val_if_fail (book, NULL); /* Build parameter list in reverse order */ if (params == NULL) { params = gnc_search_param_prepend (params, _("Employee ID"), NULL, type, EMPLOYEE_ID, NULL); params = gnc_search_param_prepend (params, _("Employee Username"), NULL, type, EMPLOYEE_USERNAME, NULL); params = gnc_search_param_prepend (params, _("Employee Name"), NULL, type, EMPLOYEE_ADDR, ADDRESS_NAME, NULL); } /* Build the column list in reverse order */ if (columns == NULL) { columns = gnc_search_param_prepend (columns, _("Username"), NULL, type, EMPLOYEE_USERNAME, NULL); columns = gnc_search_param_prepend (columns, _("ID #"), NULL, type, EMPLOYEE_ID, NULL); columns = gnc_search_param_prepend (columns, _("Name"), NULL, type, EMPLOYEE_ADDR, ADDRESS_NAME, NULL); } /* Build the queries */ q = qof_query_create_for (type); qof_query_set_book (q, book); #if 0 if (start) { q2 = qof_query_copy (q); qof_query_add_guid_match (q2, g_slist_prepend (NULL, QOF_PARAM_GUID), gncEmployeeGetGUID (start), QOF_QUERY_AND); } #endif /* launch select dialog and return the result */ sw = g_new0 (struct _employee_select_window, 1); sw->book = book; sw->q = q; return gnc_search_dialog_create (type, _("Find Employee"), params, columns, q, q2, buttons, NULL, new_employee_cb, sw, free_employee_cb, GNC_PREFS_GROUP_SEARCH, NULL); }