28 #include <glib/gi18n.h> 41 #include "business-urls.h" 42 #include "dialog-customer.h" 43 #include "dialog-employee.h" 44 #include "dialog-vendor.h" 45 #include "dialog-invoice.h" 46 #include "dialog-job.h" 48 #define HANDLE_TYPE(URL_TYPE_STR,OBJ_TYPE) { \ 51 QofCollection *coll; \ 53 g_return_val_if_fail (location != NULL, FALSE); \ 54 g_return_val_if_fail (result != NULL, FALSE); \ 55 result->load_to_stream = FALSE; \ 57 if (strncmp (URL_TYPE_STR, location, strlen(URL_TYPE_STR))) \ 59 result->error_message = \ 60 g_strdup_printf (_("Badly formed URL %s"), location); \ 63 if (!string_to_guid (location + strlen(URL_TYPE_STR), &guid)) \ 65 result->error_message = g_strdup_printf (_("Bad URL: %s"), location); \ 69 book = gnc_get_current_book(); \ 70 coll = qof_book_get_collection (book, OBJ_TYPE); \ 71 entity = qof_collection_lookup_entity (coll, &guid); \ 74 result->error_message = g_strdup_printf (_("No such entity: %s"), \ 81 customerCB (
const char *location,
const char *label,
88 HANDLE_TYPE (
"customer=", GNC_ID_CUSTOMER);
90 gnc_ui_customer_edit (result->parent, customer);
96 vendorCB (
const char *location,
const char *label,
103 HANDLE_TYPE (
"vendor=", GNC_ID_VENDOR);
104 vendor = (GncVendor *) entity;
105 gnc_ui_vendor_edit (result->parent, vendor);
111 employeeCB (
const char *location,
const char *label,
115 GncEmployee *employee;
118 HANDLE_TYPE (
"employee=", GNC_ID_EMPLOYEE);
120 employee = (GncEmployee *) entity;
121 gnc_ui_employee_edit (result->parent, employee);
127 invoiceCB (
const char *location,
const char *label,
134 HANDLE_TYPE (
"invoice=", GNC_ID_INVOICE);
135 invoice = (GncInvoice *) entity;
136 gnc_ui_invoice_edit (result->parent, invoice);
142 jobCB (
const char *location,
const char *label,
149 HANDLE_TYPE (
"job=", GNC_ID_JOB);
150 job = (GncJob *) entity;
151 gnc_ui_job_edit (result->parent, job);
158 #define DISABLE_REPORT_IF_NULL(inst) \ 161 result->error_message = \ 162 g_strdup_printf (_("No such owner entity: %s"), location); \ 163 show_report = FALSE; \ 166 #define DISABLE_REPORT_IF_TRUE(inst) \ 169 result->error_message = \ 170 g_strdup_printf (_("Badly formed URL %s"), location); \ 171 show_report = FALSE; \ 177 static GHashTable *parse_parameters (
const gchar *parms)
180 char *query = strdup (parms);
181 const char *key_tok =
"&\n";
182 const char val_tok =
'=';
184 rethash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
186 for (
char *p = strtok (query, key_tok); p; p = strtok (NULL, key_tok))
188 gchar * val = strchr (p, val_tok);
190 if (val && !g_hash_table_contains (rethash, p))
191 g_hash_table_insert (rethash, g_strdup (p), g_strdup (val));
199 ownerreportCB (
const char *location,
const char *label,
202 gchar *ownerptr, *acctptr, *etype, *datestr = NULL;
206 GHashTable *query_ht;
207 time64 enddate = INT64_MAX;
208 gboolean show_report = TRUE;
210 g_return_val_if_fail (location != NULL, FALSE);
211 g_return_val_if_fail (result != NULL, FALSE);
213 result->load_to_stream = FALSE;
216 query_ht = parse_parameters (location);
219 acctptr = g_hash_table_lookup (query_ht,
"acct");
220 DISABLE_REPORT_IF_TRUE (!acctptr || !
string_to_guid (acctptr, &guid));
224 datestr = g_hash_table_lookup (query_ht,
"enddate");
226 enddate = g_ascii_strtoull (datestr, NULL, 10);
229 ownerptr = g_hash_table_lookup (query_ht,
"owner");
230 DISABLE_REPORT_IF_TRUE (!ownerptr || !strchr(
"cvej", ownerptr[0]) ||
231 ownerptr[1] !=
':' ||
233 memset (&owner, 0,
sizeof (owner));
239 gncCustomerLookup (gnc_get_current_book (), &guid);
240 DISABLE_REPORT_IF_NULL (customer);
241 gncOwnerInitCustomer (&owner, customer);
248 gncVendorLookup (gnc_get_current_book (), &guid);
249 DISABLE_REPORT_IF_NULL (vendor);
250 gncOwnerInitVendor (&owner, vendor);
256 GncEmployee *employee =
257 gncEmployeeLookup (gnc_get_current_book (), &guid);
258 DISABLE_REPORT_IF_NULL(employee);
259 gncOwnerInitEmployee (&owner, employee);
266 gncJobLookup (gnc_get_current_book (), &guid);
267 DISABLE_REPORT_IF_NULL(job);
268 gncOwnerInitJob (&owner, job);
277 if (owner.owner.undefined == NULL)
279 result->error_message =
280 g_strdup_printf (_(
"Entity type does not match %s: %s"),
288 if (enddate != INT64_MAX)
289 gnc_business_call_owner_report_with_enddate (result->parent, &owner,
292 gnc_business_call_owner_report (result->parent, &owner, acc);
295 g_hash_table_destroy (query_ht);
300 gnc_business_urls_initialize (
void)
307 GncHTMLUrlCB handler;
310 { GNC_ID_CUSTOMER, GNC_ID_CUSTOMER, customerCB },
311 { GNC_ID_VENDOR, GNC_ID_VENDOR, vendorCB },
312 { GNC_ID_EMPLOYEE, GNC_ID_EMPLOYEE, employeeCB },
313 { GNC_ID_JOB, GNC_ID_JOB, jobCB },
314 { GNC_ID_INVOICE, GNC_ID_INVOICE, invoiceCB },
315 { URL_TYPE_OWNERREPORT,
"gnc-ownerreport", ownerreportCB },
319 for (i = 0; types[i].urltype; i++)
320 gnc_html_register_urltype (types[i].urltype, types[i].protocol);
322 for (i = 0; types[i].urltype; i++)
323 if (types[i].handler)
324 gnc_html_register_url_handler (types[i].urltype, types[i].handler);
utility functions for the GnuCash UI
gboolean string_to_guid(const gchar *string, GncGUID *guid)
Given a string, replace the given guid with the parsed one unless the given value is null...
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr, currency, taxtable, taxtable_override taxincluded, active and jobs are identical to ::GncVendor.
Business Invoice Interface.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
The type used to store guids in C.
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id...