30 #include <glib/gi18n.h> 35 #include "gnc-component-manager.h" 44 #include "gnc-general-search.h" 47 #include "business-gnome-utils.h" 48 #include "dialog-customer.h" 49 #include "dialog-job.h" 50 #include "dialog-vendor.h" 51 #include "dialog-employee.h" 52 #include "dialog-invoice.h" 54 #include "guile-mappings.h" 55 #include "gnc-guile-utils.h" 58 #include "gnc-report-combo.h" 66 GNCSEARCH_TYPE_SELECT,
78 #define PRINTABLE_INVOICE_GUID "5123a759ceb9483abf2182d01c140e8d" 79 #define TAX_INVOICE_GUID "0769e242be474010b4acf264a5512e6e" 80 #define EASY_INVOICE_GUID "67112f318bef4fc496bdc27d106bbda4" 81 #define FANCY_INVOICE_GUID "3ce293441e894423a2425d7a22dd1ac6" 85 PRINTABLE_INVOICE_PREF_NUM = 0,
87 EASY_INVOICE_PREF_NUM,
88 FANCY_INVOICE_PREF_NUM,
91 static const char* invoice_printreport_values[] =
99 PRINTABLE_INVOICE_GUID,
106 #define GNC_PREFS_GROUP_INVOICE "dialogs.business.invoice" 107 #define GNC_PREF_INV_PRINT_RPT "invoice-printreport" 110 gnc_get_builtin_default_invoice_print_report (
void)
112 return PRINTABLE_INVOICE_GUID;
116 gnc_migrate_default_invoice_print_report (
void)
118 QofBook *book = gnc_get_current_book ();
120 GNC_PREF_INV_PRINT_RPT);
122 if (old_style_value >= TAX_INVOICE_PREF_NUM &&
123 old_style_value <= FANCY_INVOICE_PREF_NUM)
125 const gchar *ret = invoice_printreport_values[old_style_value];
130 return gnc_get_builtin_default_invoice_print_report ();
134 gnc_get_default_invoice_print_report (
void)
136 QofBook *book = gnc_get_current_book ();
140 return g_strdup (gnc_migrate_default_invoice_print_report ());
146 gnc_default_invoice_report_combo (
const char* guid_scm_function)
148 GSList *invoice_list = NULL;
149 SCM template_menu_name = scm_c_eval_string (
"gnc:report-template-menu-name/report-guid");
150 SCM get_rpt_guids = scm_c_eval_string (guid_scm_function);
154 if (!scm_is_procedure (get_rpt_guids))
157 reportlist = scm_call_0 (get_rpt_guids);
158 rpt_guids = reportlist;
160 if (scm_is_list (rpt_guids))
162 while (!scm_is_null (rpt_guids))
164 gchar *guid_str = scm_to_utf8_string (SCM_CAR(rpt_guids));
165 gchar *name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name,
166 SCM_CAR(rpt_guids), SCM_BOOL_F));
171 rle->report_guid = guid_str;
172 rle->report_name = name;
174 invoice_list = g_slist_append (invoice_list, rle);
176 rpt_guids = SCM_CDR(rpt_guids);
179 return gnc_report_combo_new (invoice_list);
182 static GtkWidget * gnc_owner_new (GtkWidget *label, GtkWidget *hbox,
187 GNCSearchCB search_cb = NULL;
188 const char *type_name = NULL;
189 const char *text = NULL;
190 gboolean text_editable = FALSE;
194 case GNCSEARCH_TYPE_SELECT:
196 text_editable = TRUE;
198 case GNCSEARCH_TYPE_EDIT:
200 text_editable = FALSE;
207 case GNC_OWNER_UNDEFINED:
210 case GNC_OWNER_CUSTOMER:
211 if (type == GNCSEARCH_TYPE_SELECT)
212 search_cb = gnc_customer_search_select;
214 search_cb = gnc_customer_search_edit;
215 type_name = GNC_CUSTOMER_MODULE_NAME;
219 if (type == GNCSEARCH_TYPE_SELECT)
220 search_cb = gnc_job_search_select;
222 search_cb = gnc_job_search_edit;
223 type_name = GNC_JOB_MODULE_NAME;
226 case GNC_OWNER_VENDOR:
227 if (type == GNCSEARCH_TYPE_SELECT)
228 search_cb = gnc_vendor_search_select;
230 search_cb = gnc_vendor_search_edit;
231 type_name = GNC_VENDOR_MODULE_NAME;
234 case GNC_OWNER_EMPLOYEE:
235 if (type == GNCSEARCH_TYPE_SELECT)
236 search_cb = gnc_employee_search_select;
238 search_cb = gnc_employee_search_edit;
239 type_name = GNC_EMPLOYEE_MODULE_NAME;
243 g_warning (
"Unknown type");
247 edit = gnc_general_search_new (type_name, text, text_editable, search_cb, book, book);
251 gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit),
252 owner->owner.undefined);
253 gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);
260 GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
263 g_return_val_if_fail (hbox != NULL, NULL);
264 g_return_val_if_fail (book != NULL, NULL);
265 g_return_val_if_fail (owner != NULL, NULL);
267 return gnc_owner_new (label, hbox, book, owner, GNCSEARCH_TYPE_SELECT);
270 GtkWidget * gnc_owner_edit_create (GtkWidget *label, GtkWidget *hbox,
273 g_return_val_if_fail (hbox != NULL, NULL);
274 g_return_val_if_fail (book != NULL, NULL);
275 g_return_val_if_fail (owner != NULL, NULL);
277 return gnc_owner_new (label, hbox, book, owner, GNCSEARCH_TYPE_EDIT);
280 void gnc_owner_get_owner (GtkWidget *widget,
GncOwner *owner)
282 g_return_if_fail (widget != NULL);
283 g_return_if_fail (owner != NULL);
286 gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
291 if (owner->type == GNC_OWNER_NONE ||
296 PWARN(
"Owner type mismatch: Instance %s, Owner %s",
298 owner->owner.undefined = instance;
302 void gnc_owner_set_owner (GtkWidget *widget,
const GncOwner *owner)
304 g_return_if_fail (widget != NULL);
305 g_return_if_fail (owner != NULL);
311 gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget),
312 owner->owner.undefined);
315 typedef struct _invoice_select_info
323 static GNCSearchWindow *
324 gnc_invoice_select_search_cb (GtkWindow *parent, gpointer start, gpointer isip)
328 if (!isi)
return NULL;
331 return gnc_invoice_search (parent, start,
332 isi->have_owner ? &isi->owner : NULL,
337 gnc_invoice_select_search_set_label(
GncISI* isi)
339 GncOwnerType owner_type;
343 if (!isi->label)
return;
350 case GNC_OWNER_VENDOR:
353 case GNC_OWNER_EMPLOYEE:
354 label = _(
"Voucher");
357 label = _(
"Invoice");
361 gtk_label_set_text(GTK_LABEL(isi->label), label);
364 GtkWidget * gnc_invoice_select_create (GtkWidget *hbox, QofBook *book,
372 g_return_val_if_fail (hbox != NULL, NULL);
373 g_return_val_if_fail (book != NULL, NULL);
382 gncOwnerCopy(owner, &isi->owner);
383 isi->have_owner = TRUE;
387 gncOwnerInitCustomer(&isi->owner, NULL);
392 edit = gnc_general_search_new (GNC_INVOICE_MODULE_NAME, _(
"Select…"),
393 TRUE, gnc_invoice_select_search_cb, isi, isi->book);
400 gnc_general_search_set_selected (GNC_GENERAL_SEARCH (edit), invoice);
401 gtk_box_pack_start (GTK_BOX (hbox), edit, FALSE, FALSE, 0);
402 g_object_set_data_full(G_OBJECT(edit),
"isi-state", isi, g_free);
405 gnc_invoice_select_search_set_label(isi);
410 GncInvoice * gnc_invoice_get_invoice (GtkWidget *widget)
412 g_return_val_if_fail (widget != NULL, NULL);
414 return gnc_general_search_get_selected (GNC_GENERAL_SEARCH (widget));
417 void gnc_invoice_set_invoice (GtkWidget *widget, GncInvoice *invoice)
419 g_return_if_fail (widget != NULL);
420 g_return_if_fail (invoice != NULL);
422 gnc_general_search_set_selected (GNC_GENERAL_SEARCH (widget), invoice);
425 void gnc_invoice_set_owner (GtkWidget *widget,
GncOwner *owner)
429 g_return_if_fail (widget != NULL);
430 g_return_if_fail (owner != NULL);
432 isi = g_object_get_data(G_OBJECT(widget),
"isi-state");
435 if (isi->owner.owner.undefined == owner->owner.undefined)
438 gncOwnerCopy(owner, &isi->owner);
439 isi->have_owner = TRUE;
440 gnc_general_search_set_selected(GNC_GENERAL_SEARCH(widget), NULL);
443 gnc_invoice_select_search_set_label(isi);
447 gnc_account_select_combo_fill (GtkWidget *combo, QofBook *book,
448 GList *acct_types, GList *acct_commodities)
454 g_return_val_if_fail (combo && GTK_IS_COMBO_BOX(combo), NULL);
455 g_return_val_if_fail (book, NULL);
456 g_return_val_if_fail (acct_types, NULL);
460 g_strdup (gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(combo))))));
462 g_object_set_data (G_OBJECT(combo),
"book", book);
466 store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
467 gtk_list_store_clear(store);
470 for (node = list; node; node = node->next)
482 if (acct_commodities)
484 if ( g_list_find_custom( acct_commodities,
493 gtk_list_store_append(store, &iter);
494 gtk_list_store_set (store, &iter, 0, name, -1);
497 if (!text || g_strcmp0 (text,
"") == 0)
500 text = g_strdup (name);
504 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
511 return gnc_account_select_combo_get_active (combo);
515 gnc_account_select_combo_get_active (GtkWidget *combo)
520 if (!combo || !GTK_IS_COMBO_BOX(combo))
523 book = g_object_get_data (G_OBJECT(combo),
"book");
527 text = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(combo)))));
529 if (!text || g_strcmp0 (text,
"") == 0)
539 typedef const char * (*GenericLookup_t)(gpointer);
540 typedef gboolean (*GenericEqual_t)(gpointer, gpointer);
548 const char * (*get_name)(gpointer);
549 GList * (*get_list)(QofBook*);
550 gboolean (*is_equal)(gpointer, gpointer);
555 gnc_simple_combo_add_item (GtkListStore *liststore,
const char *label, gpointer this_item)
559 gtk_list_store_append (liststore, &iter);
560 gtk_list_store_set (liststore, &iter, 0, label, 1, this_item, -1);
567 GtkListStore *liststore;
569 if (!(lsd->get_list))
571 if (!(lsd->get_name))
575 items = (lsd->get_list)(lsd->book);
578 liststore = GTK_LIST_STORE (gtk_combo_box_get_model (lsd->cbox));
579 gtk_list_store_clear (liststore);
581 if (lsd->none_ok || !items)
582 gnc_simple_combo_add_item (liststore, _(
"None"), NULL);
584 for ( ; items; items = items->next)
585 gnc_simple_combo_add_item (liststore, (lsd->get_name)(items->data), items->data);
589 gnc_simple_combo_refresh_handler (GHashTable *changes, gpointer user_data)
592 gnc_simple_combo_generate_liststore (lsd);
596 gnc_simple_combo_destroy_cb (GtkWidget *widget, gpointer data)
600 gnc_unregister_gui_component (lsd->component_id);
605 gnc_simple_combo_make (GtkComboBox *cbox, QofBook *book,
607 GList * (*get_list)(QofBook*),
608 GenericLookup_t get_name,
609 GenericEqual_t is_equal,
610 gpointer initial_choice)
614 lsd = g_object_get_data (G_OBJECT (cbox),
"liststore-data");
627 lsd->none_ok = none_ok;
628 lsd->get_name = get_name;
629 lsd->get_list = get_list;
630 lsd->is_equal = is_equal;
631 g_object_set_data (G_OBJECT (cbox),
"liststore-data", lsd);
634 gnc_register_gui_component (
"gnc-simple-combo-refresh-hook",
635 gnc_simple_combo_refresh_handler,
639 gnc_gui_component_watch_entity_type (lsd->component_id,
641 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
643 g_signal_connect (G_OBJECT (cbox),
"destroy",
644 G_CALLBACK (gnc_simple_combo_destroy_cb), lsd);
647 gnc_simple_combo_generate_liststore (lsd);
648 gnc_simple_combo_set_value (cbox, initial_choice);
662 gnc_billterms_combo (GtkComboBox *cbox, QofBook *book,
663 gboolean none_ok, GncBillTerm *initial_choice)
665 if (!cbox || !book)
return;
667 gnc_simple_combo_make (cbox, book, none_ok, GNC_BILLTERM_MODULE_NAME,
669 (GenericLookup_t)gncBillTermGetName,
671 (gpointer)initial_choice);
675 gnc_taxtables_combo (GtkComboBox *cbox, QofBook *book,
678 if (!cbox || !book)
return;
680 gnc_simple_combo_make (cbox, book, none_ok, GNC_TAXTABLE_MODULE_NAME,
681 gncTaxTableGetTables,
682 (GenericLookup_t)gncTaxTableGetName,
684 (gpointer)initial_choice);
688 gnc_taxincluded_combo (GtkComboBox *cbox,
GncTaxIncluded initial_choice)
690 GtkListStore *liststore;
694 gnc_simple_combo_make (cbox, NULL, FALSE, NULL, NULL, NULL, NULL,
695 GINT_TO_POINTER(initial_choice));
696 liststore = GTK_LIST_STORE (gtk_combo_box_get_model (cbox));
698 gnc_simple_combo_add_item (liststore, _(
"Yes"),
700 gnc_simple_combo_add_item (liststore, _(
"No"),
702 gnc_simple_combo_add_item (liststore, _(
"Use Global"),
705 gnc_simple_combo_set_value (cbox, GINT_TO_POINTER(initial_choice));
712 gnc_simple_combo_get_value (GtkComboBox *cbox)
718 if (!cbox)
return NULL;
720 model = gtk_combo_box_get_model (cbox);
721 if (!gtk_combo_box_get_active_iter (cbox, &iter))
723 gtk_tree_model_get (model, &iter, 1, &retval, -1);
730 gnc_simple_combo_set_value (GtkComboBox *cbox, gpointer data)
735 ListStoreData *lsd = g_object_get_data (G_OBJECT (cbox),
"liststore-data");
739 model = gtk_combo_box_get_model (cbox);
740 valid_iter = gtk_tree_model_get_iter_first (model, &iter);
746 gtk_tree_model_get (model, &iter, 1, &ptr, -1);
747 if (lsd && lsd->is_equal)
749 if ((lsd->is_equal)(ptr, data))
751 gtk_combo_box_set_active_iter (cbox, &iter);
759 gtk_combo_box_set_active_iter (cbox, &iter);
763 valid_iter = gtk_tree_model_iter_next (model, &iter);
void gnc_cbwe_set_by_string(GtkComboBox *cbwe, const gchar *text)
Find an entry in the GtkComboBox by its text value, and set the widget to that value.
Business Interface: Object OWNERs.
const char * qof_object_get_type_label(QofIdTypeConst type_name)
Get the printable label for a type.
utility functions for the GnuCash UI
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
GncTaxIncluded
How to interpret the TaxIncluded.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
int gnc_commodity_compare_void(const void *a, const void *b)
A wrapper around gnc_commodity_compare() which offers the function declaration that is needed for g_l...
Object instance holds common fields that most gnucash objects use.
gint gnc_prefs_get_int(const gchar *group, const gchar *pref_name)
Get an integer value from the preferences backend.
#define PWARN(format, args...)
Log a warning.
gboolean gncBillTermIsFamily(const GncBillTerm *a, const GncBillTerm *b)
Check only if the bill terms are "family".
const gchar * QofIdType
QofIdType declaration.
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
Account handling public routines.
QofIdTypeConst qofOwnerGetType(const GncOwner *owner)
return the type for the collection.
void qofOwnerSetEntity(GncOwner *owner, QofInstance *ent)
set the owner from the entity.
Account * gnc_account_lookup_by_full_name(const Account *any_acc, const gchar *name)
The gnc_account_lookup_full_name() subroutine works like gnc_account_lookup_by_name, but uses fully-qualified names using the given separator.
Encapsulate all the information about a dataset.
Generic api to store and retrieve preferences.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
GList * gnc_account_get_descendants(const Account *account)
This routine returns a flat list of all of the accounts that are descendants of the specified account...
Business Invoice Interface.
QofIdType e_type
Entity type.
void qof_book_set_default_invoice_report(QofBook *book, const gchar *guid, const gchar *name)
Save the Invoice Report name / guid to be used as the default for printing Invoices.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
gchar * qof_book_get_default_invoice_report_guid(const QofBook *book)
Get the guid of the Invoice Report to be used as the default for printing Invoices.
Commodity handling public routines.
modtime is the internal date of the last modtime See libgnucash/engine/TaxTableBillTermImmutability.txt for an explanation of the following Code that handles refcount, parent, child, invisible and children is identical to that in ::GncBillTerm