27 #include <glib/gi18n.h>
29 #include "dialog-utils.h"
31 #include "gnc-component-manager.h"
33 #include "gnc-gui-query.h"
36 #include "dialog-search.h"
37 #include "search-param.h"
41 #include "gncVendorP.h"
43 #include "business-gnome-utils.h"
44 #include "dialog-vendor.h"
45 #include "dialog-job.h"
46 #include "dialog-order.h"
47 #include "dialog-invoice.h"
48 #include "dialog-payment.h"
50 #define DIALOG_NEW_VENDOR_CM_CLASS "dialog-new-vendor"
51 #define DIALOG_EDIT_VENDOR_CM_CLASS "dialog-edit-vendor"
53 #define GNC_PREFS_GROUP_SEARCH "dialogs.business.vendor-search"
55 void gnc_vendor_taxtable_check_cb (GtkToggleButton *togglebutton, gpointer user_data);
56 void gnc_vendor_window_ok_cb (GtkWidget *widget, gpointer data);
57 void gnc_vendor_window_cancel_cb (GtkWidget *widget, gpointer data);
58 void gnc_vendor_window_help_cb (GtkWidget *widget, gpointer data);
59 void gnc_vendor_window_destroy_cb (GtkWidget *widget, gpointer data);
60 void gnc_vendor_name_changed_cb (GtkWidget *widget, gpointer data);
61 void gnc_vendor_terms_changed_cb (GtkWidget *widget, gpointer data);
62 void gnc_vendor_taxincluded_changed_cb (GtkWidget *widget, gpointer data);
63 void gnc_vendor_taxtable_changed_cb (GtkWidget *widget, gpointer data);
82 GtkWidget * company_entry;
84 GtkWidget * name_entry;
85 GtkWidget * addr1_entry;
86 GtkWidget * addr2_entry;
87 GtkWidget * addr3_entry;
88 GtkWidget * addr4_entry;
89 GtkWidget * phone_entry;
90 GtkWidget * fax_entry;
91 GtkWidget * email_entry;
92 GtkWidget * terms_menu;
93 GtkWidget * currency_edit;
95 GtkWidget * active_check;
96 GtkWidget * taxincluded_menu;
97 GtkWidget * notes_text;
99 GtkWidget * taxtable_check;
100 GtkWidget * taxtable_menu;
104 VendorDialogType dialog_type;
114 gnc_vendor_taxtable_check_cb (GtkToggleButton *togglebutton,
119 if (gtk_toggle_button_get_active (togglebutton))
120 gtk_widget_set_sensitive (vw->taxtable_menu, TRUE);
122 gtk_widget_set_sensitive (vw->taxtable_menu, FALSE);
131 return gncVendorLookup (vw->book, &vw->vendor_guid);
136 GtkTextBuffer* text_buffer;
137 GtkTextIter start, end;
141 addr = gncVendorGetAddr (vendor);
143 gnc_suspend_gui_refresh ();
144 gncVendorBeginEdit (vendor);
146 if (vw->dialog_type == NEW_VENDOR)
149 gncVendorSetID (vendor, gtk_editable_get_chars
150 (GTK_EDITABLE (vw->id_entry), 0, -1));
151 gncVendorSetName (vendor, gtk_editable_get_chars
152 (GTK_EDITABLE (vw->company_entry), 0, -1));
154 gncAddressSetName (addr, gtk_editable_get_chars
155 (GTK_EDITABLE (vw->name_entry), 0, -1));
156 gncAddressSetAddr1 (addr, gtk_editable_get_chars
157 (GTK_EDITABLE (vw->addr1_entry), 0, -1));
158 gncAddressSetAddr2 (addr, gtk_editable_get_chars
159 (GTK_EDITABLE (vw->addr2_entry), 0, -1));
160 gncAddressSetAddr3 (addr, gtk_editable_get_chars
161 (GTK_EDITABLE (vw->addr3_entry), 0, -1));
162 gncAddressSetAddr4 (addr, gtk_editable_get_chars
163 (GTK_EDITABLE (vw->addr4_entry), 0, -1));
164 gncAddressSetPhone (addr, gtk_editable_get_chars
165 (GTK_EDITABLE (vw->phone_entry), 0, -1));
166 gncAddressSetFax (addr, gtk_editable_get_chars
167 (GTK_EDITABLE (vw->fax_entry), 0, -1));
168 gncAddressSetEmail (addr, gtk_editable_get_chars
169 (GTK_EDITABLE (vw->email_entry), 0, -1));
171 gncVendorSetActive (vendor, gtk_toggle_button_get_active
172 (GTK_TOGGLE_BUTTON (vw->active_check)));
173 gncVendorSetTaxIncluded (vendor, vw->taxincluded);
175 text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(vw->notes_text));
176 gtk_text_buffer_get_bounds (text_buffer, &start, &end);
177 text = gtk_text_buffer_get_text (text_buffer, &start, &end, FALSE);
178 gncVendorSetNotes (vendor, text);
180 gncVendorSetTerms (vendor, vw->terms);
181 gncVendorSetCurrency (vendor,
183 (vw->currency_edit)));
185 gncVendorSetTaxTableOverride
186 (vendor, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (vw->taxtable_check)));
187 gncVendorSetTaxTable (vendor, vw->taxtable);
189 gncVendorCommitEdit (vendor);
190 gnc_resume_gui_refresh ();
193 static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry,
194 const char * error_message)
196 const char *res = gtk_entry_get_text (GTK_ENTRY (entry));
197 if (g_strcmp0 (res,
"") == 0)
200 gnc_error_dialog (dialog,
"%s", error_message);
207 gnc_vendor_window_ok_cb (GtkWidget *widget, gpointer data)
213 if (check_entry_nonempty (vw->dialog, vw->company_entry,
214 _(
"You must enter a company name. "
215 "If this vendor is an individual (and not a company) "
216 "you should enter the same value for:\nIdentification "
217 "- Company Name, and\nPayment Address - Name.")))
221 if (check_entry_nonempty (vw->dialog, vw->addr1_entry, NULL) &&
222 check_entry_nonempty (vw->dialog, vw->addr2_entry, NULL) &&
223 check_entry_nonempty (vw->dialog, vw->addr3_entry, NULL) &&
224 check_entry_nonempty (vw->dialog, vw->addr4_entry, NULL))
226 const char *msg = _(
"You must enter a payment address.");
227 gnc_error_dialog (vw->dialog,
"%s", msg);
232 if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (vw->id_entry)),
"") == 0)
234 string = gncVendorNextID(vw->book);
235 gtk_entry_set_text (GTK_ENTRY (vw->id_entry),
string);
244 gnc_ui_to_vendor (vw, vendor);
246 vw->created_vendor = vendor;
250 gnc_close_gui_component (vw->component_id);
254 gnc_vendor_window_cancel_cb (GtkWidget *widget, gpointer data)
258 gnc_close_gui_component (vw->component_id);
262 gnc_vendor_window_help_cb (GtkWidget *widget, gpointer data)
268 gnc_vendor_window_destroy_cb (GtkWidget *widget, gpointer data)
273 gnc_suspend_gui_refresh ();
275 if (vw->dialog_type == NEW_VENDOR && vendor != NULL)
277 gncVendorBeginEdit (vendor);
278 gncVendorDestroy (vendor);
282 gnc_unregister_gui_component (vw->component_id);
283 gnc_resume_gui_refresh ();
289 gnc_vendor_name_changed_cb (GtkWidget *widget, gpointer data)
292 char *name, *id, *fullname, *title;
297 name = gtk_editable_get_chars (GTK_EDITABLE (vw->company_entry), 0, -1);
298 if (!name || *name ==
'\0')
299 name = g_strdup (_(
"<No name>"));
301 id = gtk_editable_get_chars (GTK_EDITABLE (vw->id_entry), 0, -1);
303 fullname = g_strconcat (name,
" (",
id,
")", (
char *)NULL);
305 if (vw->dialog_type == EDIT_VENDOR)
306 title = g_strconcat (_(
"Edit Vendor"),
" - ", fullname, (
char *)NULL);
308 title = g_strconcat (_(
"New Vendor"),
" - ", fullname, (
char *)NULL);
310 gtk_window_set_title (GTK_WINDOW (vw->dialog), title);
319 gnc_vendor_terms_changed_cb (GtkWidget *widget, gpointer data)
321 GtkComboBox *cbox = GTK_COMBO_BOX (widget);
327 vw->terms = gnc_simple_combo_get_value (cbox);
331 gnc_vendor_taxincluded_changed_cb (GtkWidget *widget, gpointer data)
333 GtkComboBox *cbox = GTK_COMBO_BOX (widget);
339 vw->taxincluded = GPOINTER_TO_INT (gnc_simple_combo_get_value (cbox));
343 gnc_vendor_taxtable_changed_cb (GtkWidget *widget, gpointer data)
345 GtkComboBox *cbox = GTK_COMBO_BOX (widget);
351 vw->taxtable = gnc_simple_combo_get_value (cbox);
355 gnc_vendor_window_close_handler (gpointer user_data)
359 gtk_widget_destroy (vw->dialog);
363 gnc_vendor_window_refresh_handler (GHashTable *changes, gpointer user_data)
372 gnc_close_gui_component (vw->component_id);
379 info = gnc_gui_get_entity_events (changes, &vw->vendor_guid);
380 if (info && (info->event_mask & QOF_EVENT_DESTROY))
382 gnc_close_gui_component (vw->component_id);
389 find_handler (gpointer
find_data, gpointer user_data)
391 const GncGUID *vendor_guid = find_data;
394 return(vw &&
guid_equal(&vw->vendor_guid, vendor_guid));
402 GtkWidget *edit, *hbox;
413 vendor_guid = *gncVendorGetGUID (vendor);
414 vw = gnc_find_first_gui_component (DIALOG_EDIT_VENDOR_CM_CLASS,
415 find_handler, &vendor_guid);
418 gtk_window_present (GTK_WINDOW(vw->dialog));
425 currency = gncVendorGetCurrency (vendor);
437 builder = gtk_builder_new();
438 gnc_builder_add_from_file (builder,
"dialog-vendor.glade",
"terms_store");
439 gnc_builder_add_from_file (builder,
"dialog-vendor.glade",
"tax_included_store");
440 gnc_builder_add_from_file (builder,
"dialog-vendor.glade",
"taxtable_store");
441 gnc_builder_add_from_file (builder,
"dialog-vendor.glade",
"Vendor Dialog");
442 vw->dialog = GTK_WIDGET (gtk_builder_get_object (builder,
"Vendor Dialog"));
445 vw->id_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"id_entry"));
446 vw->company_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"company_entry"));
448 vw->name_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"name_entry"));
449 vw->addr1_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"addr1_entry"));
450 vw->addr2_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"addr2_entry"));
451 vw->addr3_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"addr3_entry"));
452 vw->addr4_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"addr4_entry"));
453 vw->phone_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"phone_entry"));
454 vw->fax_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"fax_entry"));
455 vw->email_entry = GTK_WIDGET (gtk_builder_get_object (builder,
"email_entry"));
457 vw->active_check = GTK_WIDGET (gtk_builder_get_object (builder,
"active_check"));
458 vw->taxincluded_menu = GTK_WIDGET (gtk_builder_get_object (builder,
"tax_included_menu"));
459 vw->notes_text = GTK_WIDGET (gtk_builder_get_object (builder,
"notes_text"));
460 vw->terms_menu = GTK_WIDGET (gtk_builder_get_object (builder,
"terms_menu"));
462 vw->taxtable_check = GTK_WIDGET (gtk_builder_get_object (builder,
"taxtable_button"));
463 vw->taxtable_menu = GTK_WIDGET (gtk_builder_get_object (builder,
"taxtable_menu"));
468 vw->currency_edit = edit;
470 hbox = GTK_WIDGET (gtk_builder_get_object (builder,
"currency_box"));
471 gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
474 gtk_builder_connect_signals_full( builder,
475 gnc_builder_connect_full_func,
481 GtkTextBuffer* text_buffer;
485 vw->dialog_type = EDIT_VENDOR;
486 vw->vendor_guid = *gncVendorGetGUID (vendor);
488 addr = gncVendorGetAddr (vendor);
490 gtk_entry_set_text (GTK_ENTRY (vw->id_entry), gncVendorGetID (vendor));
491 gtk_entry_set_text (GTK_ENTRY (vw->company_entry), gncVendorGetName (vendor));
494 gtk_entry_set_text (GTK_ENTRY (vw->name_entry), gncAddressGetName (addr));
495 gtk_entry_set_text (GTK_ENTRY (vw->addr1_entry), gncAddressGetAddr1 (addr));
496 gtk_entry_set_text (GTK_ENTRY (vw->addr2_entry), gncAddressGetAddr2 (addr));
497 gtk_entry_set_text (GTK_ENTRY (vw->addr3_entry), gncAddressGetAddr3 (addr));
498 gtk_entry_set_text (GTK_ENTRY (vw->addr4_entry), gncAddressGetAddr4 (addr));
499 gtk_entry_set_text (GTK_ENTRY (vw->phone_entry), gncAddressGetPhone (addr));
500 gtk_entry_set_text (GTK_ENTRY (vw->fax_entry), gncAddressGetFax (addr));
501 gtk_entry_set_text (GTK_ENTRY (vw->email_entry), gncAddressGetEmail (addr));
504 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vw->active_check),
505 gncVendorGetActive (vendor));
507 string = gncVendorGetNotes (vendor);
508 text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(vw->notes_text));
509 gtk_text_buffer_set_text (text_buffer,
string, -1);
512 gnc_register_gui_component (DIALOG_EDIT_VENDOR_CM_CLASS,
513 gnc_vendor_window_refresh_handler,
514 gnc_vendor_window_close_handler,
517 vw->terms = gncVendorGetTerms (vendor);
522 vendor = gncVendorCreate (bookp);
523 vw->vendor_guid = *gncVendorGetGUID (vendor);
525 vw->dialog_type = NEW_VENDOR;
527 gnc_register_gui_component (DIALOG_NEW_VENDOR_CM_CLASS,
528 gnc_vendor_window_refresh_handler,
529 gnc_vendor_window_close_handler,
538 vw->taxincluded = gncVendorGetTaxIncluded (vendor);
539 gnc_taxincluded_combo (GTK_COMBO_BOX(vw->taxincluded_menu), vw->taxincluded);
540 gnc_billterms_combo (GTK_COMBO_BOX(vw->terms_menu), bookp, TRUE, vw->terms);
542 vw->taxtable = gncVendorGetTaxTable (vendor);
543 gnc_taxtables_combo (GTK_COMBO_BOX(vw->taxtable_menu), bookp, TRUE, vw->taxtable);
544 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vw->taxtable_check),
545 gncVendorGetTaxTableOverride (vendor));
546 gnc_vendor_taxtable_check_cb (GTK_TOGGLE_BUTTON (vw->taxtable_check), vw);
548 gnc_gui_component_watch_entity_type (vw->component_id,
549 GNC_VENDOR_MODULE_NAME,
550 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
552 gtk_widget_show_all (vw->dialog);
553 g_object_unref(G_OBJECT(builder));
559 gnc_ui_vendor_new (
QofBook *bookp)
564 if (!bookp)
return NULL;
566 vw = gnc_vendor_new_window (bookp, NULL);
575 if (!vendor)
return NULL;
585 invoice_vendor_cb (gpointer *vendor_p, gpointer user_data)
591 g_return_if_fail (vendor_p && user_data);
598 gncOwnerInitVendor (&owner, vendor);
599 gnc_invoice_search (NULL, &owner, sw->book);
604 order_vendor_cb (gpointer *vendor_p, gpointer user_data)
610 g_return_if_fail (vendor_p && user_data);
617 gncOwnerInitVendor (&owner, vendor);
618 gnc_order_search (NULL, &owner, sw->book);
623 jobs_vendor_cb (gpointer *vendor_p, gpointer user_data)
629 g_return_if_fail (vendor_p && user_data);
636 gncOwnerInitVendor (&owner, vendor);
637 gnc_job_search (NULL, &owner, sw->book);
642 payment_vendor_cb (gpointer *vendor_p, gpointer user_data)
648 g_return_if_fail (vendor_p && user_data);
655 gncOwnerInitVendor (&owner, vendor);
656 gnc_ui_payment_new (&owner, sw->book);
661 edit_vendor_cb (gpointer *vendor_p, gpointer user_data)
665 g_return_if_fail (vendor_p && user_data);
672 gnc_ui_vendor_edit (vendor);
677 new_vendor_cb (gpointer user_data)
682 g_return_val_if_fail (user_data, NULL);
684 vw = gnc_ui_vendor_new (sw->book);
685 return vw_get_vendor (vw);
689 free_vendor_cb (gpointer user_data)
692 g_return_if_fail (sw);
704 static GList *params = NULL;
705 static GList *columns = NULL;
708 { N_(
"View/Edit Vendor"), edit_vendor_cb, NULL, TRUE},
709 { N_(
"Vendor's Jobs"), jobs_vendor_cb, NULL, TRUE},
711 { N_(
"Vendor's Bills"), invoice_vendor_cb, NULL, TRUE},
712 { N_(
"Pay Bill"), payment_vendor_cb, NULL, FALSE},
715 (void)order_vendor_cb;
717 g_return_val_if_fail (book, NULL);
722 params = gnc_search_param_prepend (params, _(
"Billing Contact"), NULL, type,
723 VENDOR_ADDR, ADDRESS_NAME, NULL);
724 params = gnc_search_param_prepend (params, _(
"Vendor ID"), NULL, type,
726 params = gnc_search_param_prepend (params, _(
"Company Name"), NULL, type,
733 columns = gnc_search_param_prepend (columns, _(
"Contact"), NULL, type,
734 VENDOR_ADDR, ADDRESS_NAME, NULL);
735 columns = gnc_search_param_prepend (columns, _(
"Company"), NULL, type,
737 columns = gnc_search_param_prepend (columns, _(
"ID #"), NULL, type,
742 q = qof_query_create_for (type);
750 gncVendorGetGUID (start), QOF_QUERY_AND);
759 return gnc_search_dialog_create (type, _(
"Find Vendor"),
760 params, columns, q, q2, buttons, NULL,
761 new_vendor_cb, sw, free_vendor_cb,
762 GNC_PREFS_GROUP_SEARCH, NULL);
766 gnc_vendor_search_select (gpointer start, gpointer book)
768 if (!book)
return NULL;
770 return gnc_vendor_search (start, book);
774 gnc_vendor_search_edit (gpointer start, gpointer book)
777 gnc_ui_vendor_edit (start);
void gnc_currency_edit_set_currency(GNCCurrencyEdit *gce, const gnc_commodity *currency)
utility functions for the GnuCash UI
QofQuery * qof_query_copy(QofQuery *q)
struct _QofQuery QofQuery
gnc_commodity * gnc_default_currency(void)
Currency selection widget.
void qof_query_destroy(QofQuery *q)
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
void qof_query_set_book(QofQuery *q, QofBook *book)
gnc_commodity * gnc_currency_edit_get_currency(GNCCurrencyEdit *gce)
void gnc_gnome_help(const char *file_name, const char *anchor)
#define gncVendorGetBook(X)
void qof_query_add_guid_match(QofQuery *q, QofQueryParamList *param_list, const GncGUID *guid, QofQueryOp op)
GtkWidget * gnc_currency_edit_new(void)
const GncGUID * guid_null(void)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.