GnuCash  5.6-150-g038405b370+
gnc-plugin-business.c
1 /*
2  * gnc-plugin-business.c --
3  *
4  * Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
5  * Copyright (C) 2003 Jan Arne Petersen
6  * Copyright (C) 2005 David Hampton <hampton@employees.org>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, contact:
20  *
21  * Free Software Foundation Voice: +1-617-542-5942
22  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
23  * Boston, MA 02110-1301, USA gnu@gnu.org
24  */
25 
26 #include <config.h>
27 
28 #include <gtk/gtk.h>
29 #include <glib/gi18n.h>
30 #include <string.h>
31 
32 #include "dialog-doclink.h"
33 #include "dialog-billterms.h"
34 #include "dialog-customer.h"
35 #include "dialog-employee.h"
36 #include "dialog-invoice.h"
37 #include "dialog-job.h"
38 #include "dialog-payment.h"
39 #include "dialog-tax-table.h"
40 #include "dialog-vendor.h"
41 #include "business-gnome-utils.h"
42 #include "gnc-plugin-business.h"
45 #include "gncOwner.h"
46 #include "gnc-ui-util.h"
47 #include "gnc-date.h"
48 #include "gnc-file.h"
49 #include "guile-mappings.h"
50 #include "gnc-session.h"
51 #include "gnc-icons.h" /* for GNC_ICON_INVOICE_NEW */
52 
53 #include "gnc-prefs.h"
54 #include "gnc-main-window.h"
55 #include "gnc-window.h"
56 #include "gnc-gtk-utils.h"
57 
59 
60 /* This static indicates the debugging module that this .o belongs to. */
61 G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
62 
63 /* g_object functions */
64 static void gnc_plugin_business_finalize (GObject *object);
65 static void gnc_plugin_business_add_to_window (GncPlugin *plugin,
66  GncMainWindow *window,
67  GQuark type);
68 
69 /* Command callbacks */
70 static void gnc_plugin_business_cmd_customer_page (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
71 static void gnc_plugin_business_cmd_customer_new_customer (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
72 static void gnc_plugin_business_cmd_customer_find_customer (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
73 static void gnc_plugin_business_cmd_customer_new_invoice (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
74 static void gnc_plugin_business_cmd_customer_find_invoice (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
75 static void gnc_plugin_business_cmd_customer_new_job (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
76 static void gnc_plugin_business_cmd_customer_find_job (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
77 static void gnc_plugin_business_cmd_customer_process_payment (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
78 
79 static void gnc_plugin_business_cmd_vendor_page (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
80 static void gnc_plugin_business_cmd_vendor_new_vendor (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
81 static void gnc_plugin_business_cmd_vendor_find_vendor (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
82 static void gnc_plugin_business_cmd_vendor_new_bill (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
83 static void gnc_plugin_business_cmd_vendor_find_bill (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
84 static void gnc_plugin_business_cmd_vendor_new_job (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
85 static void gnc_plugin_business_cmd_vendor_find_job (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
86 static void gnc_plugin_business_cmd_vendor_process_payment (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
87 
88 static void gnc_plugin_business_cmd_employee_page (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
89 static void gnc_plugin_business_cmd_employee_new_employee (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
90 static void gnc_plugin_business_cmd_employee_find_employee (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
91 static void gnc_plugin_business_cmd_employee_new_expense_voucher (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
92 static void gnc_plugin_business_cmd_employee_find_expense_voucher (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
93 static void gnc_plugin_business_cmd_employee_process_payment (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
94 
95 static void gnc_plugin_business_cmd_doclink (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
96 static void gnc_plugin_business_cmd_tax_tables (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
97 static void gnc_plugin_business_cmd_billing_terms (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
98 static void gnc_plugin_business_cmd_bills_due_reminder (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
99 static void gnc_plugin_business_cmd_invoices_due_reminder (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
100 
101 static void gnc_plugin_business_cmd_test_search (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
102 static void gnc_plugin_business_cmd_test_init_data (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
103 
104 static void gnc_plugin_business_cmd_assign_payment (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
105 
106 static void update_inactive_actions (GncPluginPage *page);
107 static void bind_extra_toolbuttons_visibility (GncMainWindow *mainwindow);
108 
109 #define PLUGIN_ACTIONS_NAME "gnc-plugin-business-actions"
110 #define PLUGIN_UI_FILENAME "gnc-plugin-business.ui"
111 
112 #define GNC_PREF_EXTRA_TOOLBUTTONS "enable-toolbuttons"
113 
120 static GncMainWindow *last_window = NULL;
121 
122 static GActionEntry gnc_plugin_actions [] =
123 {
124  { "CustomerOverviewPageAction", gnc_plugin_business_cmd_customer_page, NULL, NULL, NULL },
125  { "CustomerNewCustomerOpenAction", gnc_plugin_business_cmd_customer_new_customer, NULL, NULL, NULL },
126  { "CustomerFindCustomerOpenAction", gnc_plugin_business_cmd_customer_find_customer, NULL, NULL, NULL },
127  { "CustomerNewInvoiceOpenAction", gnc_plugin_business_cmd_customer_new_invoice, NULL, NULL, NULL },
128  { "CustomerFindInvoiceOpenAction", gnc_plugin_business_cmd_customer_find_invoice, NULL, NULL, NULL },
129  { "CustomerNewJobOpenAction", gnc_plugin_business_cmd_customer_new_job, NULL, NULL, NULL },
130  { "CustomerFindJobOpenAction", gnc_plugin_business_cmd_customer_find_job, NULL, NULL, NULL },
131  { "CustomerProcessPaymentAction", gnc_plugin_business_cmd_customer_process_payment, NULL, NULL, NULL },
132 
133  { "VendorOverviewPageAction", gnc_plugin_business_cmd_vendor_page, NULL, NULL, NULL },
134  { "VendorNewVendorOpenAction", gnc_plugin_business_cmd_vendor_new_vendor, NULL, NULL, NULL },
135  { "VendorFindVendorOpenAction", gnc_plugin_business_cmd_vendor_find_vendor, NULL, NULL, NULL },
136  { "VendorNewBillOpenAction", gnc_plugin_business_cmd_vendor_new_bill, NULL, NULL, NULL },
137  { "VendorFindBillOpenAction", gnc_plugin_business_cmd_vendor_find_bill, NULL, NULL, NULL },
138  { "VendorNewJobOpenAction", gnc_plugin_business_cmd_vendor_new_job, NULL, NULL, NULL },
139  { "VendorFindJobOpenAction", gnc_plugin_business_cmd_vendor_find_job, NULL, NULL, NULL },
140  { "VendorProcessPaymentAction", gnc_plugin_business_cmd_vendor_process_payment, NULL, NULL, NULL },
141 
142  { "EmployeeOverviewPageAction", gnc_plugin_business_cmd_employee_page, NULL, NULL, NULL },
143  { "EmployeeNewEmployeeOpenAction", gnc_plugin_business_cmd_employee_new_employee, NULL, NULL, NULL },
144  { "EmployeeFindEmployeeOpenAction", gnc_plugin_business_cmd_employee_find_employee, NULL, NULL, NULL },
145  { "EmployeeNewExpenseVoucherOpenAction", gnc_plugin_business_cmd_employee_new_expense_voucher, NULL, NULL, NULL },
146  { "EmployeeFindExpenseVoucherOpenAction", gnc_plugin_business_cmd_employee_find_expense_voucher, NULL, NULL, NULL },
147  { "EmployeeProcessPaymentAction", gnc_plugin_business_cmd_employee_process_payment, NULL, NULL, NULL },
148 
149  { "BusinessLinkedDocsAction", gnc_plugin_business_cmd_doclink, NULL, NULL, NULL },
150  { "TaxTablesOpenAction", gnc_plugin_business_cmd_tax_tables, NULL, NULL, NULL },
151  { "BillingTermsOpenAction", gnc_plugin_business_cmd_billing_terms, NULL, NULL, NULL },
152  { "BillsDueReminderOpenAction", gnc_plugin_business_cmd_bills_due_reminder, NULL, NULL, NULL },
153  { "InvoicesDueReminderOpenAction", gnc_plugin_business_cmd_invoices_due_reminder, NULL, NULL, NULL },
154 
155  { "BusinessTestSearchAction", gnc_plugin_business_cmd_test_search, NULL, NULL, NULL },
156  { "BusinessTestInitDataAction", gnc_plugin_business_cmd_test_init_data, NULL, NULL, NULL },
157  { "ToolbarNewInvoiceAction", gnc_plugin_business_cmd_customer_new_invoice, NULL, NULL, NULL },
158  { "RegisterAssignPayment", gnc_plugin_business_cmd_assign_payment, NULL, NULL, NULL },
159  { "RegisterEditPayment", gnc_plugin_business_cmd_assign_payment, NULL, NULL, NULL },
160 };
162 static guint gnc_plugin_n_actions = G_N_ELEMENTS(gnc_plugin_actions);
163 
165 static const gchar *gnc_plugin_load_ui_items [] =
166 {
167  "BusinessPlaceholder0",
168  "BusinessPlaceholder1",
169  "ExtensionsPlaceholder0",
170  NULL,
171 };
172 
173 /************************************************************
174  * Plugin Function Implementation *
175  ************************************************************/
176 
178 {
179  GncPlugin gnc_plugin;
180 
181  GncOwner *last_customer;
182  GncOwner *last_vendor;
183  GncOwner *last_employee;
184 };
185 
186 GncPlugin *
187 gnc_plugin_business_new (void)
188 {
189  GncPluginBusiness *plugin;
190 
191  /* Reference the invoice page plugin to ensure it exists in
192  * the gtk type system. */
193  GNC_TYPE_PLUGIN_PAGE_INVOICE;
194  GNC_TYPE_PLUGIN_PAGE_OWNER_TREE;
195 
196  plugin = g_object_new (GNC_TYPE_PLUGIN_BUSINESS,
197  (char *)NULL);
198 
199  return GNC_PLUGIN (plugin);
200 }
201 
202 G_DEFINE_TYPE(GncPluginBusiness, gnc_plugin_business, GNC_TYPE_PLUGIN)
203 
204 static void
205 gnc_plugin_business_class_init (GncPluginBusinessClass *klass)
206 {
207  GObjectClass *object_class = G_OBJECT_CLASS (klass);
208  GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
209 
210  object_class->finalize = gnc_plugin_business_finalize;
211 
212  /* plugin info */
213  plugin_class->plugin_name = GNC_PLUGIN_BUSINESS_NAME;
214 
215  /* function overrides */
216  plugin_class->add_to_window = gnc_plugin_business_add_to_window;
217 
218  /* widget addition/removal */
219  plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
220  plugin_class->actions = gnc_plugin_actions;
221  plugin_class->n_actions = gnc_plugin_n_actions;
222  plugin_class->ui_filename = PLUGIN_UI_FILENAME;
223  plugin_class->ui_updates = gnc_plugin_load_ui_items;
224 }
225 
226 static void
227 gnc_plugin_business_init (GncPluginBusiness *plugin)
228 {
229  plugin->last_customer = gncOwnerNew ();
230  gncOwnerInitCustomer (plugin->last_customer, NULL);
231 
232  plugin->last_vendor = gncOwnerNew ();
233  gncOwnerInitVendor (plugin->last_vendor, NULL);
234 
235  plugin->last_employee = gncOwnerNew ();
236  gncOwnerInitEmployee (plugin->last_employee, NULL);
237 }
238 
239 static void
240 gnc_plugin_business_finalize (GObject *object)
241 {
242  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (object));
243 
244  GncPluginBusiness *plugin = (GncPluginBusiness*) object;
245  gncOwnerFree (plugin->last_customer);
246  gncOwnerFree (plugin->last_vendor);
247  gncOwnerFree (plugin->last_employee);
248 
249  G_OBJECT_CLASS (gnc_plugin_business_parent_class)->finalize (object);
250 }
251 
252 /************************************************************
253  * Helper Functions *
254  ************************************************************/
255 
256 GncMainWindow*
257 gnc_plugin_business_get_window()
258 {
259  return last_window;
260 }
261 
262 /************************************************************
263  * Command Callbacks *
264  ************************************************************/
265 
266 static void
267 gnc_plugin_business_cmd_customer_page (GSimpleAction *simple,
268  GVariant *parameter,
269  gpointer user_data)
270 {
271  GncMainWindowActionData *mw = user_data;
272  GncPluginPage *page;
273 
274  g_return_if_fail (mw != NULL);
275  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
276 
277  page = gnc_plugin_page_owner_tree_new (GNC_OWNER_CUSTOMER);
278  gnc_main_window_open_page (mw->window, page);
279 }
280 
281 static void
282 gnc_plugin_business_cmd_customer_new_customer (GSimpleAction *simple,
283  GVariant *parameter,
284  gpointer user_data)
285 {
286  GncMainWindowActionData *mw = user_data;
287 
288  g_return_if_fail (mw != NULL);
289  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
290 
291  gnc_ui_customer_new (GTK_WINDOW (mw->window), gnc_get_current_book ());
292 }
293 
294 static void
295 gnc_plugin_business_cmd_customer_find_customer (GSimpleAction *simple,
296  GVariant *parameter,
297  gpointer user_data)
298 {
299  GncMainWindowActionData *mw = user_data;
300  GncPluginBusiness *plugin;
301  GncCustomer*customer;
302 
303  g_return_if_fail (mw != NULL);
304  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
305 
306  plugin = GNC_PLUGIN_BUSINESS (mw->data);
307  customer = gncOwnerGetCustomer (plugin->last_customer);
308  gnc_customer_search (GTK_WINDOW (mw->window), customer, gnc_get_current_book ());
309 }
310 
311 static void
312 gnc_plugin_business_cmd_customer_new_invoice (GSimpleAction *simple,
313  GVariant *parameter,
314  gpointer user_data)
315 {
316  GncMainWindowActionData *mw = user_data;
317  GncPluginBusiness *plugin;
318 
319  g_return_if_fail (mw != NULL);
320  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
321 
322  plugin = GNC_PLUGIN_BUSINESS (mw->data);
323  last_window = mw->window;
324  gnc_ui_invoice_new (GTK_WINDOW (mw->window), plugin->last_customer, gnc_get_current_book ());
325 }
326 
327 static void
328 gnc_plugin_business_cmd_customer_find_invoice (GSimpleAction *simple,
329  GVariant *parameter,
330  gpointer user_data)
331 {
332  GncMainWindowActionData *mw = user_data;
333  GncPluginBusiness *plugin;
334 
335  g_return_if_fail (mw != NULL);
336  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
337 
338  plugin = GNC_PLUGIN_BUSINESS (mw->data);
339  last_window = mw->window;
340  gnc_invoice_search (GTK_WINDOW (mw->window), NULL, plugin->last_customer, gnc_get_current_book ());
341 }
342 
343 static void
344 gnc_plugin_business_cmd_customer_new_job (GSimpleAction *simple,
345  GVariant *parameter,
346  gpointer user_data)
347 {
348  GncMainWindowActionData *mw = user_data;
349  GncPluginBusiness *plugin;
350 
351  g_return_if_fail (mw != NULL);
352  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
353 
354  plugin = GNC_PLUGIN_BUSINESS (mw->data);
355  gnc_ui_job_new (GTK_WINDOW (mw->window), plugin->last_customer, gnc_get_current_book ());
356 }
357 
358 static void
359 gnc_plugin_business_cmd_customer_find_job (GSimpleAction *simple,
360  GVariant *parameter,
361  gpointer user_data)
362 {
363  GncMainWindowActionData *mw = user_data;
364  GncPluginBusiness *plugin;
365 
366  g_return_if_fail (mw != NULL);
367  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
368 
369  plugin = GNC_PLUGIN_BUSINESS (mw->data);
370  gnc_job_search (GTK_WINDOW (mw->window), NULL, plugin->last_customer, gnc_get_current_book ());
371 }
372 
373 static void
374 gnc_plugin_business_cmd_customer_process_payment (GSimpleAction *simple,
375  GVariant *parameter,
376  gpointer user_data)
377 {
378  GncMainWindowActionData *mw = user_data;
379  GncPluginBusiness *plugin;
380 
381  g_return_if_fail (mw != NULL);
382  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
383 
384  plugin = GNC_PLUGIN_BUSINESS (mw->data);
385  gnc_ui_payment_new (GTK_WINDOW (mw->window), plugin->last_customer, gnc_get_current_book ());
386 }
387 
388 static void
389 gnc_plugin_business_cmd_vendor_page (GSimpleAction *simple,
390  GVariant *parameter,
391  gpointer user_data)
392 {
393  GncMainWindowActionData *mw = user_data;
394  GncPluginPage *page;
395 
396  g_return_if_fail (mw != NULL);
397  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
398 
399  page = gnc_plugin_page_owner_tree_new (GNC_OWNER_VENDOR);
400  gnc_main_window_open_page (mw->window, page);
401 }
402 
403 static void
404 gnc_plugin_business_cmd_vendor_new_vendor (GSimpleAction *simple,
405  GVariant *parameter,
406  gpointer user_data)
407 {
408  GncMainWindowActionData *mw = user_data;
409  g_return_if_fail (mw != NULL);
410  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
411 
412  gnc_ui_vendor_new (GTK_WINDOW (mw->window), gnc_get_current_book ());
413 }
414 
415 static void
416 gnc_plugin_business_cmd_vendor_find_vendor (GSimpleAction *simple,
417  GVariant *parameter,
418  gpointer user_data)
419 {
420  GncMainWindowActionData *mw = user_data;
421  GncPluginBusiness *plugin;
422  GncVendor *vendor;
423 
424  g_return_if_fail (mw != NULL);
425  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
426 
427  plugin = GNC_PLUGIN_BUSINESS (mw->data);
428  vendor = gncOwnerGetVendor (plugin->last_vendor);
429  gnc_vendor_search (GTK_WINDOW (mw->window), vendor, gnc_get_current_book ());
430 }
431 
432 static void
433 gnc_plugin_business_cmd_vendor_new_bill (GSimpleAction *simple,
434  GVariant *parameter,
435  gpointer user_data)
436 {
437  GncMainWindowActionData *mw = user_data;
438  GncPluginBusiness *plugin;
439 
440  g_return_if_fail (mw != NULL);
441  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
442 
443  plugin = GNC_PLUGIN_BUSINESS (mw->data);
444  last_window = mw->window;
445  gnc_ui_invoice_new (GTK_WINDOW (mw->window), plugin->last_vendor, gnc_get_current_book ());
446 }
447 
448 static void
449 gnc_plugin_business_cmd_vendor_find_bill (GSimpleAction *simple,
450  GVariant *parameter,
451  gpointer user_data)
452 {
453  GncMainWindowActionData *mw = user_data;
454  GncPluginBusiness *plugin;
455 
456  g_return_if_fail (mw != NULL);
457  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
458 
459  plugin = GNC_PLUGIN_BUSINESS (mw->data);
460  last_window = mw->window;
461  gnc_invoice_search (GTK_WINDOW (mw->window), NULL, plugin->last_vendor, gnc_get_current_book ());
462 }
463 
464 static void
465 gnc_plugin_business_cmd_vendor_new_job (GSimpleAction *simple,
466  GVariant *parameter,
467  gpointer user_data)
468 {
469  GncMainWindowActionData *mw = user_data;
470  GncPluginBusiness *plugin;
471 
472  g_return_if_fail (mw != NULL);
473  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
474 
475  plugin = GNC_PLUGIN_BUSINESS (mw->data);
476  gnc_ui_job_new (GTK_WINDOW (mw->window), plugin->last_vendor, gnc_get_current_book ());
477 }
478 
479 static void
480 gnc_plugin_business_cmd_vendor_find_job (GSimpleAction *simple,
481  GVariant *parameter,
482  gpointer user_data)
483 {
484  GncMainWindowActionData *mw = user_data;
485  GncPluginBusiness *plugin;
486 
487  g_return_if_fail (mw != NULL);
488  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
489 
490  plugin = GNC_PLUGIN_BUSINESS (mw->data);
491  gnc_job_search (GTK_WINDOW (mw->window), NULL, plugin->last_vendor, gnc_get_current_book ());
492 }
493 
494 static void
495 gnc_plugin_business_cmd_vendor_process_payment (GSimpleAction *simple,
496  GVariant *parameter,
497  gpointer user_data)
498 {
499  GncMainWindowActionData *mw = user_data;
500  GncPluginBusiness *plugin;
501 
502  g_return_if_fail (mw != NULL);
503  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
504 
505  plugin = GNC_PLUGIN_BUSINESS (mw->data);
506  gnc_ui_payment_new (GTK_WINDOW (mw->window), plugin->last_vendor, gnc_get_current_book ());
507 }
508 
509 static void
510 gnc_plugin_business_cmd_employee_page (GSimpleAction *simple,
511  GVariant *parameter,
512  gpointer user_data)
513 {
514  GncMainWindowActionData *mw = user_data;
515  GncPluginPage *page;
516 
517  g_return_if_fail (mw != NULL);
518  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
519 
520  page = gnc_plugin_page_owner_tree_new (GNC_OWNER_EMPLOYEE);
521  gnc_main_window_open_page (mw->window, page);
522 }
523 
524 static void
525 gnc_plugin_business_cmd_employee_new_employee (GSimpleAction *simple,
526  GVariant *parameter,
527  gpointer user_data)
528 {
529  GncMainWindowActionData *mw = user_data;
530  g_return_if_fail (mw != NULL);
531  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
532 
533  gnc_ui_employee_new (GTK_WINDOW (mw->window), gnc_get_current_book ());
534 }
535 
536 static void
537 gnc_plugin_business_cmd_employee_find_employee (GSimpleAction *simple,
538  GVariant *parameter,
539  gpointer user_data)
540 {
541  GncMainWindowActionData *mw = user_data;
542  GncPluginBusiness *plugin;
543  GncEmployee *employee;
544 
545  g_return_if_fail (mw != NULL);
546  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
547 
548  plugin = GNC_PLUGIN_BUSINESS (mw->data);
549  employee = gncOwnerGetEmployee (plugin->last_employee);
550  gnc_employee_search (GTK_WINDOW (mw->window), employee, gnc_get_current_book ());
551 }
552 
553 static void
554 gnc_plugin_business_cmd_employee_new_expense_voucher (GSimpleAction *simple,
555  GVariant *parameter,
556  gpointer user_data)
557 {
558  GncMainWindowActionData *mw = user_data;
559  GncPluginBusiness *plugin;
560 
561  g_return_if_fail (mw != NULL);
562  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
563 
564  plugin = GNC_PLUGIN_BUSINESS (mw->data);
565  last_window = mw->window;
566  gnc_ui_invoice_new (GTK_WINDOW (mw->window), plugin->last_employee, gnc_get_current_book ());
567 }
568 
569 static void
570 gnc_plugin_business_cmd_employee_find_expense_voucher (GSimpleAction *simple,
571  GVariant *parameter,
572  gpointer user_data)
573 {
574  GncMainWindowActionData *mw = user_data;
575  GncPluginBusiness *plugin;
576 
577  g_return_if_fail (mw != NULL);
578  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
579 
580  plugin = GNC_PLUGIN_BUSINESS (mw->data);
581  last_window = mw->window;
582  gnc_invoice_search (GTK_WINDOW (mw->window), NULL, plugin->last_employee, gnc_get_current_book ());
583 }
584 
585 static void
586 gnc_plugin_business_cmd_employee_process_payment (GSimpleAction *simple,
587  GVariant *parameter,
588  gpointer user_data)
589 {
590  GncMainWindowActionData *mw = user_data;
591  GncPluginBusiness *plugin;
592 
593  g_return_if_fail (mw != NULL);
594  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
595 
596  plugin = GNC_PLUGIN_BUSINESS (mw->data);
597  gnc_ui_payment_new (GTK_WINDOW (mw->window), plugin->last_employee, gnc_get_current_book ());
598 }
599 
600 static void
601 gnc_plugin_business_cmd_doclink (GSimpleAction *simple,
602  GVariant *parameter,
603  gpointer user_data)
604 {
605  GncMainWindowActionData *mw = user_data;
606  g_return_if_fail (mw != NULL);
607  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
608 
609  gnc_doclink_business_dialog (GTK_WINDOW (mw->window));
610 }
611 
612 static void
613 gnc_plugin_business_cmd_tax_tables (GSimpleAction *simple,
614  GVariant *parameter,
615  gpointer user_data)
616 {
617  GncMainWindowActionData *mw = user_data;
618  g_return_if_fail (mw != NULL);
619  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
620 
621  gnc_ui_tax_table_window_new (GTK_WINDOW (mw->window), gnc_get_current_book());
622 }
623 
624 static void
625 gnc_plugin_business_cmd_billing_terms (GSimpleAction *simple,
626  GVariant *parameter,
627  gpointer user_data)
628 {
629  GncMainWindowActionData *mw = user_data;
630  g_return_if_fail (mw != NULL);
631  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
632 
633  gnc_ui_billterms_window_new (GTK_WINDOW (mw->window), gnc_get_current_book());
634 }
635 
636 
637 static void
638 gnc_plugin_business_cmd_bills_due_reminder (GSimpleAction *simple,
639  GVariant *parameter,
640  gpointer user_data)
641 {
642  GncMainWindowActionData *mw = user_data;
643  g_return_if_fail (mw != NULL);
644  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
645 
646  gnc_invoice_remind_bills_due (GTK_WINDOW (mw->window));
647 }
648 
649 
650 static void
651 gnc_plugin_business_cmd_invoices_due_reminder (GSimpleAction *simple,
652  GVariant *parameter,
653  gpointer user_data)
654 {
655  GncMainWindowActionData *mw = user_data;
656  g_return_if_fail (mw != NULL);
657  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
658 
659  gnc_invoice_remind_invoices_due (GTK_WINDOW (mw->window));
660 }
661 
662 static void
663 gnc_plugin_business_cmd_test_search (GSimpleAction *simple,
664  GVariant *parameter,
665  gpointer user_data)
666 {
667  gnc_search_dialog_test();
668 }
669 
670 static void
671 gnc_business_assign_payment (GtkWindow *parent,
672  Transaction *trans,
673  GncOwner *owner)
674 {
675  g_return_if_fail(trans);
676 
677  // Do nothing if we don't have more than one split (e.g. in the empty line at the end of the register)
678  if (xaccTransCountSplits(trans) <= 1)
679  return;
680 
681  //PINFO("Creating payment dialog with trans %p", trans);
682  gnc_ui_payment_new_with_txn(parent, owner, trans);
683 }
684 
685 static void
686 gnc_plugin_business_cmd_assign_payment (GSimpleAction *simple,
687  GVariant *parameter,
688  gpointer user_data)
689 {
690  GncMainWindowActionData *mw = user_data;
691  GncPluginBusiness *plugin_business;
692  GncPluginPage *plugin_page;
693  GNCSplitReg *gsr;
694  SplitRegister *reg;
695  Split *split;
696  Transaction *trans;
697  gboolean have_owner;
698  GncOwner owner;
699  GncOwner *owner_p;
700 
701  g_return_if_fail (mw != NULL);
702  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
703 
704  plugin_page = gnc_main_window_get_current_page(mw->window);
705 
706  // We continue only if the current page is a plugin page and more
707  // specifically a register plugin page
708  if (!GNC_IS_PLUGIN_PAGE(plugin_page)
709  || !GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page))
710  return;
711 
712  gsr = gnc_plugin_page_register_get_gsr(plugin_page);
713  g_return_if_fail(gsr);
714 
715  reg = gnc_ledger_display_get_split_register( gsr->ledger );
716  g_return_if_fail(reg);
717 
719  g_return_if_fail(split);
720 
721  trans = xaccSplitGetParent(split);
722  g_return_if_fail(trans);
723 
724  plugin_business = GNC_PLUGIN_BUSINESS (mw->data);
725 
726  have_owner = gncOwnerGetOwnerFromTxn (trans, &owner);
727  if (have_owner)
728  owner_p = &owner;
729  else if (gnc_ui_payment_is_customer_payment(trans))
730  owner_p = plugin_business->last_customer;
731  else
732  owner_p = plugin_business->last_vendor;
733 
734  gnc_business_assign_payment (GTK_WINDOW (mw->window),
735  trans, owner_p);
736 }
737 
738 static const gchar *register_txn_actions[] =
739 {
740  "RegisterAssignPayment",
741  NULL
742 };
743 
744 static const gchar *register_bus_txn_actions[] =
745 {
746  "RegisterEditPayment",
747  NULL
748 };
749 
750 static void
751 gnc_plugin_business_update_menus (GncPluginPage *plugin_page)
752 {
753  GSimpleActionGroup *simple_action_group;
754  gboolean is_txn_register, is_bus_txn = FALSE, is_bus_doc = FALSE;
755 
756  // We continue only if the current page is a plugin page
757  if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
758  return;
759 
760  // Check that this is a main window and not embedded sx
761  if (!GNC_IS_MAIN_WINDOW(plugin_page->window))
762  return;
763 
764  // We are readonly - we have already set particular actions to inactive.
765  if (qof_book_is_readonly (gnc_get_current_book()))
766  return;
767 
768  is_txn_register = GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page);
769  simple_action_group = gnc_main_window_get_action_group (GNC_MAIN_WINDOW(plugin_page->window),
771  g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP(simple_action_group));
772 
773  if (is_txn_register)
774  {
775  Transaction *trans = gnc_plugin_page_register_get_current_txn (GNC_PLUGIN_PAGE_REGISTER(plugin_page));
776  if (trans && xaccTransCountSplits(trans) > 0)
777  is_bus_txn = (xaccTransGetFirstAPARAcctSplit(trans, TRUE) != NULL);
778  is_bus_doc = (xaccTransGetTxnType (trans) == TXN_TYPE_INVOICE);
779  }
780  // Change visibility and also sensitivity according to whether we are in a txn register
781  gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), register_txn_actions,
782  is_txn_register && !is_bus_txn && !is_bus_doc);
783 
784  gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), register_bus_txn_actions,
785  is_txn_register && is_bus_txn && !is_bus_doc);
786 }
787 
788 static void
789 gnc_plugin_business_main_window_page_changed (GncMainWindow *window,
790  GncPluginPage *page,
791  gpointer user_data)
792 {
793  update_inactive_actions(page);
794  gnc_plugin_business_update_menus(page);
795 }
796 
797 static void
798 gnc_plugin_business_main_window_menu_changed (GncMainWindow *window,
799  GncPluginPage *page,
800  gpointer user_data)
801 {
802  // page could be NULL when gnucash started with --nofile
803  if (page == gnc_main_window_get_current_page (window))
804  {
805  if (page)
806  gnc_plugin_business_main_window_page_changed (window, page, user_data);
807  bind_extra_toolbuttons_visibility (window);
808  }
809 }
810 
811 void
812 gnc_plugin_business_split_reg_ui_update (GncPluginPage *plugin_page)
813 {
814  gnc_plugin_business_main_window_page_changed(NULL, plugin_page, NULL);
815 }
816 
817 static void
818 gnc_plugin_business_cmd_test_init_data (GSimpleAction *simple,
819  GVariant *parameter,
820  gpointer user_data)
821 {
822  GncMainWindowActionData *mw = user_data;
823  QofBook *book = gnc_get_current_book();
824  GncCustomer *customer = gncCustomerCreate(book);
825  GncAddress *address = gncCustomerGetAddr(customer);
826  GncInvoice *invoice = gncInvoiceCreate(book);
827  GncOwner *owner = gncOwnerNew();
828  GncJob *job = gncJobCreate(book);
829  Account *root = gnc_book_get_root_account(book);
830  Account *inc_acct = xaccMallocAccount(book);
831  Account *bank_acct = xaccMallocAccount(book);
832  Account *tax_acct = xaccMallocAccount(book);
833  Account *ar_acct = xaccMallocAccount(book);
834 
835  // Create Customer
836  gncCustomerSetID(customer, "000001");
837  gncCustomerSetName(customer, "Test Customer");
838  gncCustomerSetCurrency(customer, gnc_default_currency());
839  gncAddressSetName(address, "Contact Person");
840  gncAddressSetAddr1(address, "20 Customer Lane");
841  gncAddressSetAddr2(address, "Customer M/S");
842  gncAddressSetAddr3(address, "Addr3, XXX 12345");
843 
844  // Create the Owner
845  gncOwnerInitCustomer(owner, customer);
846 
847  // Create the Invoice
848  gncInvoiceSetID(invoice, "000012");
849  gncInvoiceSetOwner(invoice, owner);
850  gncInvoiceSetDateOpened(invoice, gnc_time (NULL));
851  gncInvoiceSetCurrency(invoice, gnc_default_currency());
852 
853  // Create the Job
854  gncJobSetID(job, "000025");
855  gncJobSetName(job, "Test Job");
856  gncJobSetReference(job, "Customer's ref#");
857  gncJobSetOwner(job, owner);
858 
859  // MODIFY THE OWNER
860  gncOwnerInitJob(owner, job);
861 
862  // Create the A/R account
864  xaccAccountSetName(ar_acct, "A/R");
866  gnc_account_append_child(root, ar_acct);
867 
868  // Create the Income account
870  xaccAccountSetName(inc_acct, "Income");
872  gnc_account_append_child(root, inc_acct);
873 
874  // Create the Bank account
876  xaccAccountSetName(bank_acct, "Bank");
878  gnc_account_append_child(root, bank_acct);
879 
880  // Create the Tax account
882  xaccAccountSetName(tax_acct, "Tax-Holding");
884  gnc_account_append_child(root, tax_acct);
885 
886  // Launch the invoice editor
887  gnc_ui_invoice_edit (GTK_WINDOW (mw->window), invoice);
888 }
889 
890 /* This is the list of actions which are switched inactive in a read-only book. */
891 static const gchar* readonly_inactive_actions[] =
892 {
893  "CustomerNewCustomerOpenAction",
894  "CustomerNewInvoiceOpenAction",
895  "CustomerNewInvoiceOpenAction",
896  "CustomerNewJobOpenAction",
897  "CustomerProcessPaymentAction",
898  "VendorNewVendorOpenAction",
899  "VendorNewBillOpenAction",
900  "VendorNewJobOpenAction",
901  "VendorProcessPaymentAction",
902  "EmployeeNewEmployeeOpenAction",
903  "EmployeeNewExpenseVoucherOpenAction",
904  "EmployeeProcessPaymentAction",
905  "ToolbarNewInvoiceAction",
906  "RegisterAssignPayment",
907  "RegisterEditPayment",
908  NULL
909 };
910 
911 static void
912 update_inactive_actions (GncPluginPage *plugin_page)
913 {
914  GncMainWindow *window;
915  GSimpleActionGroup *simple_action_group;
916 
917  // We are readonly - so we have to switch particular actions to inactive.
918  gboolean is_readwrite = !qof_book_is_readonly(gnc_get_current_book());
919 
920  // We continue only if the current page is a plugin page
921  if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
922  return;
923 
924  // Check that this is a main window and not embedded sx
925  if (!GNC_IS_MAIN_WINDOW(plugin_page->window))
926  return;
927 
928  window = GNC_MAIN_WINDOW(plugin_page->window);
929  g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
930  simple_action_group = gnc_main_window_get_action_group (window, PLUGIN_ACTIONS_NAME);
931  g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP(simple_action_group));
932 
933  /* Set the action's sensitivity */
934  gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), readonly_inactive_actions,
935  is_readwrite);
936 }
937 
938 /* This is the list of actions which are switched invisible or visible
939  * depending on the preference "extra_toolbuttons". */
940 static const char* extra_toolbar_actions[] =
941 {
942  "ToolbarNewInvoiceAction",
943  NULL
944 };
945 
946 /* Bind the visibility of the extra toolbar buttons to the
947  * enable_toolbuttons preference. */
948 static void
949 bind_extra_toolbuttons_visibility (GncMainWindow *mainwindow)
950 {
951  GtkWidget *toolbar;
952  const char **iter;
953 
954  g_return_if_fail (mainwindow);
955  g_return_if_fail (GNC_IS_MAIN_WINDOW(mainwindow));
956 
957  toolbar = gnc_window_get_toolbar (GNC_WINDOW(mainwindow));
958 
959  if (!toolbar)
960  return;
961 
962  // Set the 'extra' tool items visibility
963  for (iter = extra_toolbar_actions; *iter; ++iter)
964  {
965  GtkWidget *tool_item = gnc_find_toolbar_item (toolbar, *iter);
966 
967  if (tool_item)
968  {
969  gnc_prefs_bind (GNC_PREFS_GROUP_INVOICE,
970  GNC_PREF_EXTRA_TOOLBUTTONS,
971  NULL, G_OBJECT(tool_item), "visible");
972  }
973  }
974 
975  // Set the 'extra' tool item separator visibility
976  for (gint i = 0; i < gtk_toolbar_get_n_items (GTK_TOOLBAR(toolbar)); i++)
977  {
978  GtkToolItem *tool_item = gtk_toolbar_get_nth_item (GTK_TOOLBAR(toolbar), i);
979 
980  if (GTK_IS_SEPARATOR_TOOL_ITEM(tool_item))
981  {
982  if (g_str_has_prefix (gtk_buildable_get_name (GTK_BUILDABLE(tool_item)),
983  "extra_separator"))
984  {
985  gnc_prefs_bind (GNC_PREFS_GROUP_INVOICE,
986  GNC_PREF_EXTRA_TOOLBUTTONS,
987  NULL, G_OBJECT(tool_item), "visible");
988  }
989  }
990  }
991 }
992 
999 static void
1000 gnc_plugin_business_add_to_window (GncPlugin *plugin,
1001  GncMainWindow *mainwindow,
1002  GQuark type)
1003 {
1004  g_signal_connect (mainwindow, "page_changed",
1005  G_CALLBACK(gnc_plugin_business_main_window_page_changed),
1006  plugin);
1007 
1008  g_signal_connect (mainwindow, "menu_changed",
1009  G_CALLBACK(gnc_plugin_business_main_window_menu_changed),
1010  plugin);
1011 }
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account&#39;s type.
Definition: Account.cpp:2422
utility functions for the GnuCash UI
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.
Definition: Account.cpp:2807
Business Interface: Object OWNERs.
The instance data structure for a content plugin.
Date and Time handling routines.
gboolean gncOwnerGetOwnerFromTxn(Transaction *txn, GncOwner *owner)
Convenience function to get the owner from a transaction.
Definition: gncOwner.c:674
utility functions for the GnuCash UI
char xaccTransGetTxnType(Transaction *trans)
Returns the Transaction Type: note this type will be derived from the transaction splits...
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define TXN_TYPE_INVOICE
Transaction is an invoice.
Definition: Transaction.h:126
gtk helper routines.
STRUCTS.
Functions that are supported by all types of windows.
GtkWidget * window
The window that contains the display widget for this plugin.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
GncPluginPage * gnc_main_window_get_current_page(GncMainWindow *window)
Retrieve a pointer to the page that is currently at the front of the specified window.
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
Functions for adding content to a window.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
int xaccTransCountSplits(const Transaction *trans)
Returns the number of splits in this transaction.
Functions providing a register page for the GnuCash UI.
Functions providing a page which lists owners of one type.
Income accounts are used to denote income.
Definition: Account.h:140
Transaction * gnc_plugin_page_register_get_current_txn(GncPluginPageRegister *page)
Get the currently selected transaction in this register page.
The bank account type denotes a savings or checking account held at a bank.
Definition: Account.h:107
void gnc_plugin_set_actions_enabled(GActionMap *action_map, const gchar **action_names, gboolean enable)
This function sets the sensitivity of a GAction in a specific group.
Definition: gnc-plugin.c:250
GtkWidget * gnc_find_toolbar_item(GtkWidget *toolbar, const gchar *action_name)
Search the toolbar for the tool item based on the action name.
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, const gchar *pref_value, gpointer object, const gchar *property)
Bind a setting to a g_object property.
Definition: gnc-prefs.c:181
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.
Generic api to store and retrieve preferences.
Split * xaccTransGetFirstAPARAcctSplit(const Transaction *trans, gboolean strict)
The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first split in this transacti...
gboolean qof_book_is_readonly(const QofBook *book)
Return whether the book is read only.
Definition: qofbook.cpp:497
liability (and asset) accounts indicate generic, generalized accounts that are none of the above...
Definition: Account.h:119
A/R account type.
Definition: Account.h:149
#define PLUGIN_ACTIONS_NAME
The label given to the main window for this plugin.
Account * xaccMallocAccount(QofBook *book)
Constructor.
Definition: Account.cpp:1273
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object...
Definition: gncOwner.c:383
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object...
Definition: gncOwner.c:369
time64 gnc_time(time64 *tbuf)
get the current time
Definition: gnc-date.cpp:261
GSimpleActionGroup * gnc_main_window_get_action_group(GncMainWindow *window, const gchar *group_name)
Retrieve a specific set of user interface actions from a window.
SplitRegister * gnc_ledger_display_get_split_register(GNCLedgerDisplay *ld)
return the split register associated with a ledger display
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object...
Definition: gncOwner.c:390
GNCSplitReg * gnc_plugin_page_register_get_gsr(GncPluginPage *plugin_page)
Get the GNCSplitReg data structure associated with this register page.
GncOwner * gncOwnerNew(void)
These two functions are mainly for the convenience of scheme code.
Definition: gncOwner.c:57
void xaccAccountSetName(Account *acc, const char *str)
Set the account&#39;s name.
Definition: Account.cpp:2443
Split * gnc_split_register_get_current_split(SplitRegister *reg)
Returns the split at which the cursor is currently located.
GncPluginPage * gnc_plugin_page_owner_tree_new(GncOwnerType owner_type)
Create a new "owner tree" plugin page.
#define PLUGIN_UI_FILENAME
The name of the UI description file for this plugin.
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Set the account&#39;s commodity.
Definition: Account.cpp:2649