GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-plugin-business.c
1 /*
2  * gnc-plugin-business.c --
3  *
4  * Author: Jan Arne Petersen <[email protected]>
5  * Copyright (C) 2003 Jan Arne Petersen
6  * Copyright (C) 2005 David Hampton <[email protected]>
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 [email protected]
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-billterms.h"
33 #include "dialog-customer.h"
34 #include "dialog-employee.h"
35 #include "dialog-invoice.h"
36 #include "dialog-job.h"
37 #include "dialog-payment.h"
38 #include "dialog-tax-table.h"
39 #include "dialog-vendor.h"
40 #include "business-gnome-utils.h"
41 #include "gnc-plugin-business.h"
44 #include "gncOwner.h"
45 #include "gnc-ui-util.h"
46 #include "gnc-date.h"
47 #include "gnc-file.h"
48 #include "guile-mappings.h"
49 #include "gnc-session.h"
50 #include "gnome-utils/gnc-icons.h" /* for GNC_STOCK_INVOICE_NEW */
51 
52 #include "gnc-prefs.h"
54 
56 
57 /* This static indicates the debugging module that this .o belongs to. */
58 G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
59 
60 /* g_object functions */
61 static void gnc_plugin_business_class_init (GncPluginBusinessClass *klass);
62 static void gnc_plugin_business_init (GncPluginBusiness *plugin);
63 static void gnc_plugin_business_finalize (GObject *object);
64 static void gnc_plugin_business_add_to_window (GncPlugin *plugin,
65  GncMainWindow *window,
66  GQuark type);
67 
68 /* Command callbacks */
69 static void gnc_plugin_business_cmd_customer_page (GtkAction *action,
71 static void gnc_plugin_business_cmd_customer_new_customer (GtkAction *action,
73 static void gnc_plugin_business_cmd_customer_find_customer (GtkAction *action,
75 static void gnc_plugin_business_cmd_customer_new_invoice (GtkAction *action,
77 static void gnc_plugin_business_cmd_customer_find_invoice (GtkAction *action,
79 static void gnc_plugin_business_cmd_customer_new_job (GtkAction *action,
81 static void gnc_plugin_business_cmd_customer_find_job (GtkAction *action,
83 static void gnc_plugin_business_cmd_customer_process_payment (GtkAction *action,
85 
86 static void gnc_plugin_business_cmd_vendor_page (GtkAction *action,
88 static void gnc_plugin_business_cmd_vendor_new_vendor (GtkAction *action,
90 static void gnc_plugin_business_cmd_vendor_find_vendor (GtkAction *action,
92 static void gnc_plugin_business_cmd_vendor_new_bill (GtkAction *action,
94 static void gnc_plugin_business_cmd_vendor_find_bill (GtkAction *action,
96 static void gnc_plugin_business_cmd_vendor_new_job (GtkAction *action,
98 static void gnc_plugin_business_cmd_vendor_find_job (GtkAction *action,
100 static void gnc_plugin_business_cmd_vendor_process_payment (GtkAction *action,
102 
103 static void gnc_plugin_business_cmd_employee_page (GtkAction *action,
105 static void gnc_plugin_business_cmd_employee_new_employee (GtkAction *action,
107 static void gnc_plugin_business_cmd_employee_find_employee (GtkAction *action,
109 static void gnc_plugin_business_cmd_employee_new_expense_voucher (GtkAction *action,
111 static void gnc_plugin_business_cmd_employee_find_expense_voucher (GtkAction *action,
113 static void gnc_plugin_business_cmd_employee_process_payment (GtkAction *action,
115 
116 static void gnc_plugin_business_cmd_tax_tables (GtkAction *action,
118 static void gnc_plugin_business_cmd_billing_terms (GtkAction *action,
120 static void gnc_plugin_business_cmd_bills_due_reminder (GtkAction *action,
122 
123 static void gnc_plugin_business_cmd_test_search (GtkAction *action,
125 
126 static void gnc_plugin_business_cmd_test_init_data (GtkAction *action,
128 
129 static void gnc_plugin_business_cmd_assign_payment (GtkAction *action,
131 static void update_inactive_actions(GncPluginPage *page);
132 
133 #define PLUGIN_ACTIONS_NAME "gnc-plugin-business-actions"
134 #define PLUGIN_UI_FILENAME "gnc-plugin-business-ui.xml"
135 
136 #define GNC_PREF_EXTRA_TOOLBUTTONS "enable-toolbuttons"
137 #define GNC_PREF_INV_PRINT_RPT "invoice-printreport"
138 
145 static GncMainWindow *last_window = NULL;
146 
147 static GtkActionEntry gnc_plugin_actions [] =
148 {
149  /* Toplevel */
150  { "BusinessAction", NULL, N_("_Business"), NULL, NULL, NULL },
151 
152  /* Customer submenu */
153  { "CustomerMenuAction", NULL, N_("_Customer"), NULL, NULL, NULL },
154  {
155  "CustomerOverviewPageAction", NULL, N_("Customers Overview"), NULL,
156  N_("Open a Customer overview page"),
157  G_CALLBACK (gnc_plugin_business_cmd_customer_page)
158  },
159  {
160  "CustomerNewCustomerOpenAction", NULL, N_("_New Customer..."), NULL,
161  N_("Open the New Customer dialog"),
162  G_CALLBACK (gnc_plugin_business_cmd_customer_new_customer)
163  },
164  {
165  "CustomerFindCustomerOpenAction", NULL, N_("_Find Customer..."), NULL,
166  N_("Open the Find Customer dialog"),
167  G_CALLBACK (gnc_plugin_business_cmd_customer_find_customer)
168  },
169  {
170  "CustomerNewInvoiceOpenAction", NULL, N_("New _Invoice..."), NULL,
171  N_("Open the New Invoice dialog"),
172  G_CALLBACK (gnc_plugin_business_cmd_customer_new_invoice)
173  },
174  {
175  "CustomerFindInvoiceOpenAction", NULL, N_("Find In_voice..."), NULL,
176  N_("Open the Find Invoice dialog"),
177  G_CALLBACK (gnc_plugin_business_cmd_customer_find_invoice)
178  },
179  {
180  "CustomerNewJobOpenAction", NULL, N_("New _Job..."), NULL,
181  N_("Open the New Job dialog"),
182  G_CALLBACK (gnc_plugin_business_cmd_customer_new_job)
183  },
184  {
185  "CustomerFindJobOpenAction", NULL, N_("Find Jo_b..."), NULL,
186  N_("Open the Find Job dialog"),
187  G_CALLBACK (gnc_plugin_business_cmd_customer_find_job)
188  },
189  {
190  "CustomerProcessPaymentAction", NULL, N_("_Process Payment..."), NULL,
191  N_("Open the Process Payment dialog"),
192  G_CALLBACK (gnc_plugin_business_cmd_customer_process_payment)
193  },
194 
195  /* Vendor submenu */
196  {
197  "VendorOverviewPageAction", NULL, N_("Vendors Overview"), NULL,
198  N_("Open a Vendor overview page"),
199  G_CALLBACK (gnc_plugin_business_cmd_vendor_page)
200  },
201  { "VendorMenuAction", NULL, N_("_Vendor"), NULL, NULL, NULL },
202  {
203  "VendorNewVendorOpenAction", NULL, N_("_New Vendor..."), NULL,
204  N_("Open the New Vendor dialog"),
205  G_CALLBACK (gnc_plugin_business_cmd_vendor_new_vendor)
206  },
207  {
208  "VendorFindVendorOpenAction", NULL, N_("_Find Vendor..."), NULL,
209  N_("Open the Find Vendor dialog"),
210  G_CALLBACK (gnc_plugin_business_cmd_vendor_find_vendor)
211  },
212  {
213  "VendorNewBillOpenAction", NULL, N_("New _Bill..."), NULL,
214  N_("Open the New Bill dialog"),
215  G_CALLBACK (gnc_plugin_business_cmd_vendor_new_bill)
216  },
217  {
218  "VendorFindBillOpenAction", NULL, N_("Find Bi_ll..."), NULL,
219  N_("Open the Find Bill dialog"),
220  G_CALLBACK (gnc_plugin_business_cmd_vendor_find_bill)
221  },
222  {
223  "VendorNewJobOpenAction", NULL, N_("New _Job..."), NULL,
224  N_("Open the New Job dialog"),
225  G_CALLBACK (gnc_plugin_business_cmd_vendor_new_job)
226  },
227  {
228  "VendorFindJobOpenAction", NULL, N_("Find Jo_b..."), NULL,
229  N_("Open the Find Job dialog"),
230  G_CALLBACK (gnc_plugin_business_cmd_vendor_find_job)
231  },
232  {
233  "VendorProcessPaymentAction", NULL, N_("_Process Payment..."), NULL,
234  N_("Open the Process Payment dialog"),
235  G_CALLBACK (gnc_plugin_business_cmd_vendor_process_payment)
236  },
237 
238  /* Employee submenu */
239  {
240  "EmployeeOverviewPageAction", NULL, N_("Employees Overview"), NULL,
241  N_("Open a Employee overview page"),
242  G_CALLBACK (gnc_plugin_business_cmd_employee_page)
243  },
244  { "EmployeeMenuAction", NULL, N_("_Employee"), NULL, NULL, NULL },
245  {
246  "EmployeeNewEmployeeOpenAction", NULL, N_("_New Employee..."), NULL,
247  N_("Open the New Employee dialog"),
248  G_CALLBACK (gnc_plugin_business_cmd_employee_new_employee)
249  },
250  {
251  "EmployeeFindEmployeeOpenAction", NULL, N_("_Find Employee..."), NULL,
252  N_("Open the Find Employee dialog"),
253  G_CALLBACK (gnc_plugin_business_cmd_employee_find_employee)
254  },
255  {
256  "EmployeeNewExpenseVoucherOpenAction", NULL, N_("New _Expense Voucher..."), NULL,
257  N_("Open the New Expense Voucher dialog"),
258  G_CALLBACK (gnc_plugin_business_cmd_employee_new_expense_voucher)
259  },
260  {
261  "EmployeeFindExpenseVoucherOpenAction", NULL, N_("Find Expense _Voucher..."), NULL,
262  N_("Open the Find Expense Voucher dialog"),
263  G_CALLBACK (gnc_plugin_business_cmd_employee_find_expense_voucher)
264  },
265  {
266  "EmployeeProcessPaymentAction", NULL, N_("_Process Payment..."), NULL,
267  N_("Open the Process Payment dialog"),
268  G_CALLBACK (gnc_plugin_business_cmd_employee_process_payment)
269  },
270 
271  /* Other menu items */
272  {
273  "TaxTablesOpenAction", NULL, N_("Sales _Tax Table"), NULL,
274  N_("View and edit the list of Sales Tax Tables (GST/VAT)"),
275  G_CALLBACK (gnc_plugin_business_cmd_tax_tables)
276  },
277  {
278  "BillingTermsOpenAction", NULL, N_("_Billing Terms Editor"), NULL,
279  N_("View and edit the list of Billing Terms"),
280  G_CALLBACK (gnc_plugin_business_cmd_billing_terms)
281  },
282  {
283  "BillsDueReminderOpenAction", NULL, N_("Bills _Due Reminder"), NULL,
284  N_("Open the Bills Due Reminder dialog"),
285  G_CALLBACK (gnc_plugin_business_cmd_bills_due_reminder)
286  },
287  { "ExportMenuAction", NULL, N_("E_xport"), NULL, NULL, NULL },
288 
289  /* Extensions Menu */
290  { "BusinessTestAction", NULL, N_("_Business"), NULL, NULL, NULL },
291  {
292  "BusinessTestSearchAction", NULL, N_("Test Search Dialog"), NULL,
293  N_("Test Search Dialog"),
294  G_CALLBACK (gnc_plugin_business_cmd_test_search)
295  },
296  {
297  "BusinessTestInitDataAction", NULL, N_("Initialize Test Data"), NULL,
298  N_("Initialize Test Data"),
299  G_CALLBACK (gnc_plugin_business_cmd_test_init_data)
300  },
301 
302  /* Toolbar */
303  {
304  "ToolbarNewInvoiceAction", GNC_STOCK_INVOICE_NEW, N_("New _Invoice..."), NULL,
305  N_("Open the New Invoice dialog"),
306  G_CALLBACK (gnc_plugin_business_cmd_customer_new_invoice)
307  },
308 
309  /* Register popup menu */
310  {
311  "RegisterAssignPayment", NULL, N_("Assign as payment..."), NULL,
312  N_("Assign the selected transaction as payment"),
313  G_CALLBACK (gnc_plugin_business_cmd_assign_payment)
314  },
315 };
316 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
317 
318 
319 /************************************************************
320  * Plugin Function Implementation *
321  ************************************************************/
322 
324 {
325  GncOwner *last_customer;
326  GncOwner *last_vendor;
327  GncOwner *last_employee;
329 
330 #define GNC_PLUGIN_BUSINESS_GET_PRIVATE(o) \
331  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_BUSINESS, GncPluginBusinessPrivate))
332 
333 static GObjectClass *parent_class = NULL;
334 
335 GType
336 gnc_plugin_business_get_type (void)
337 {
338  static GType gnc_plugin_business_type = 0;
339 
340  if (gnc_plugin_business_type == 0)
341  {
342  static const GTypeInfo our_info =
343  {
344  sizeof (GncPluginBusinessClass),
345  NULL, /* base_init */
346  NULL, /* base_finalize */
347  (GClassInitFunc) gnc_plugin_business_class_init,
348  NULL, /* class_finalize */
349  NULL, /* class_data */
350  sizeof (GncPluginBusiness),
351  0, /* n_preallocs */
352  (GInstanceInitFunc) gnc_plugin_business_init
353  };
354 
355  gnc_plugin_business_type = g_type_register_static (GNC_TYPE_PLUGIN,
356  "GncPluginBusiness",
357  &our_info, 0);
358  }
359 
360  return gnc_plugin_business_type;
361 }
362 
363 GncPlugin *
364 gnc_plugin_business_new (void)
365 {
366  GncPluginBusiness *plugin;
367 
368  /* Reference the invoice page plugin to ensure it exists in
369  * the gtk type system. */
370  GNC_TYPE_PLUGIN_PAGE_INVOICE;
371  GNC_TYPE_PLUGIN_PAGE_OWNER_TREE;
372 
373  plugin = g_object_new (GNC_TYPE_PLUGIN_BUSINESS,
374  (char *)NULL);
375 
376  return GNC_PLUGIN (plugin);
377 }
378 
379 static void
380 gnc_plugin_business_class_init (GncPluginBusinessClass *klass)
381 {
382  GObjectClass *object_class = G_OBJECT_CLASS (klass);
383  GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
384 
385  parent_class = g_type_class_peek_parent (klass);
386 
387  object_class->finalize = gnc_plugin_business_finalize;
388 
389  /* plugin info */
390  plugin_class->plugin_name = GNC_PLUGIN_BUSINESS_NAME;
391 
392  /* function overrides */
393  plugin_class->add_to_window = gnc_plugin_business_add_to_window;
394 
395  /* widget addition/removal */
396  plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
397  plugin_class->actions = gnc_plugin_actions;
398  plugin_class->n_actions = gnc_plugin_n_actions;
399  plugin_class->ui_filename = PLUGIN_UI_FILENAME;
400 
401  g_type_class_add_private(klass, sizeof(GncPluginBusinessPrivate));
402 }
403 
404 static void
405 gnc_plugin_business_init (GncPluginBusiness *plugin)
406 {
408 
409  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
410  priv->last_customer = gncOwnerNew ();
411  gncOwnerInitCustomer (priv->last_customer, NULL);
412 
413  priv->last_vendor = gncOwnerNew ();
414  gncOwnerInitVendor (priv->last_vendor, NULL);
415 
416  priv->last_employee = gncOwnerNew ();
417  gncOwnerInitEmployee (priv->last_employee, NULL);
418 }
419 
420 static void
421 gnc_plugin_business_finalize (GObject *object)
422 {
423  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (object));
424 
425  G_OBJECT_CLASS (parent_class)->finalize (object);
426 }
427 
428 /************************************************************
429  * Helper Functions *
430  ************************************************************/
431 
433 gnc_plugin_business_get_window()
434 {
435  return last_window;
436 }
437 
438 /************************************************************
439  * Command Callbacks *
440  ************************************************************/
441 
442 static void
443 gnc_plugin_business_cmd_customer_page (GtkAction *action,
445 {
446  GncPluginPage *page;
447 
448  g_return_if_fail (mw != NULL);
449  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
450 
451  page = gnc_plugin_page_owner_tree_new (GNC_OWNER_CUSTOMER);
452  gnc_main_window_open_page (mw->window, page);
453 }
454 
455 static void
456 gnc_plugin_business_cmd_customer_new_customer (GtkAction *action,
458 {
459  g_return_if_fail (mw != NULL);
460  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
461 
462  gnc_ui_customer_new (gnc_get_current_book());
463 }
464 
465 static void
466 gnc_plugin_business_cmd_customer_find_customer (GtkAction *action,
468 {
469  GncPluginBusiness *plugin;
471  GncCustomer*customer;
472 
473  g_return_if_fail (mw != NULL);
474  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
475 
476  plugin = GNC_PLUGIN_BUSINESS (mw->data);
477  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
478  customer = gncOwnerGetCustomer (priv->last_customer);
479  gnc_customer_search (customer, gnc_get_current_book());
480 }
481 
482 static void
483 gnc_plugin_business_cmd_customer_new_invoice (GtkAction *action,
485 {
486  GncPluginBusiness *plugin;
488 
489  g_return_if_fail (mw != NULL);
490  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
491 
492  plugin = GNC_PLUGIN_BUSINESS (mw->data);
493  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
494  last_window = mw->window;
495  gnc_ui_invoice_new (priv->last_customer, gnc_get_current_book());
496 }
497 
498 static void
499 gnc_plugin_business_cmd_customer_find_invoice (GtkAction *action,
501 {
502  GncPluginBusiness *plugin;
504 
505  g_return_if_fail (mw != NULL);
506  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
507 
508  plugin = GNC_PLUGIN_BUSINESS (mw->data);
509  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
510  last_window = mw->window;
511  gnc_invoice_search (NULL, priv->last_customer, gnc_get_current_book());
512 }
513 
514 static void
515 gnc_plugin_business_cmd_customer_new_job (GtkAction *action,
517 {
518  GncPluginBusiness *plugin;
520 
521  g_return_if_fail (mw != NULL);
522  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
523 
524  plugin = GNC_PLUGIN_BUSINESS (mw->data);
525  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
526  gnc_ui_job_new (priv->last_customer, gnc_get_current_book());
527 }
528 
529 static void
530 gnc_plugin_business_cmd_customer_find_job (GtkAction *action,
532 {
533  GncPluginBusiness *plugin;
535 
536  g_return_if_fail (mw != NULL);
537  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
538 
539  plugin = GNC_PLUGIN_BUSINESS (mw->data);
540  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
541  gnc_job_search (NULL, priv->last_customer, gnc_get_current_book());
542 }
543 
544 static void
545 gnc_plugin_business_cmd_customer_process_payment (GtkAction *action,
547 {
548  GncPluginBusiness *plugin;
550 
551  g_return_if_fail (mw != NULL);
552  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
553 
554  plugin = GNC_PLUGIN_BUSINESS (mw->data);
555  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
556  gnc_ui_payment_new (priv->last_customer, gnc_get_current_book());
557 }
558 
559 static void
560 gnc_plugin_business_cmd_vendor_page (GtkAction *action,
562 {
563  GncPluginPage *page;
564 
565  g_return_if_fail (mw != NULL);
566  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
567 
568  page = gnc_plugin_page_owner_tree_new (GNC_OWNER_VENDOR);
569  gnc_main_window_open_page (mw->window, page);
570 }
571 
572 static void
573 gnc_plugin_business_cmd_vendor_new_vendor (GtkAction *action,
575 {
576  g_return_if_fail (mw != NULL);
577  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
578 
579  gnc_ui_vendor_new (gnc_get_current_book());
580 }
581 
582 static void
583 gnc_plugin_business_cmd_vendor_find_vendor (GtkAction *action,
585 {
586  GncPluginBusiness *plugin;
588  GncVendor *vendor;
589 
590  g_return_if_fail (mw != NULL);
591  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
592 
593  plugin = GNC_PLUGIN_BUSINESS (mw->data);
594  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
595  vendor = gncOwnerGetVendor (priv->last_vendor);
596  gnc_vendor_search (vendor, gnc_get_current_book());
597 }
598 
599 static void
600 gnc_plugin_business_cmd_vendor_new_bill (GtkAction *action,
602 {
603  GncPluginBusiness *plugin;
605 
606  g_return_if_fail (mw != NULL);
607  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
608 
609  plugin = GNC_PLUGIN_BUSINESS (mw->data);
610  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
611  last_window = mw->window;
612  gnc_ui_invoice_new (priv->last_vendor, gnc_get_current_book());
613 }
614 
615 static void
616 gnc_plugin_business_cmd_vendor_find_bill (GtkAction *action,
618 {
619  GncPluginBusiness *plugin;
621 
622  g_return_if_fail (mw != NULL);
623  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
624 
625  plugin = GNC_PLUGIN_BUSINESS (mw->data);
626  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
627  last_window = mw->window;
628  gnc_invoice_search (NULL, priv->last_vendor, gnc_get_current_book());
629 }
630 
631 static void
632 gnc_plugin_business_cmd_vendor_new_job (GtkAction *action,
634 {
635  GncPluginBusiness *plugin;
637 
638  g_return_if_fail (mw != NULL);
639  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
640 
641  plugin = GNC_PLUGIN_BUSINESS (mw->data);
642  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
643  gnc_ui_job_new (priv->last_vendor, gnc_get_current_book());
644 }
645 
646 static void
647 gnc_plugin_business_cmd_vendor_find_job (GtkAction *action,
649 {
650  GncPluginBusiness *plugin;
652 
653  g_return_if_fail (mw != NULL);
654  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
655 
656  plugin = GNC_PLUGIN_BUSINESS (mw->data);
657  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
658  gnc_job_search (NULL, priv->last_vendor, gnc_get_current_book());
659 }
660 
661 static void
662 gnc_plugin_business_cmd_vendor_process_payment (GtkAction *action,
664 {
665  GncPluginBusiness *plugin;
667 
668  g_return_if_fail (mw != NULL);
669  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
670 
671  plugin = GNC_PLUGIN_BUSINESS (mw->data);
672  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
673  gnc_ui_payment_new (priv->last_vendor, gnc_get_current_book());
674 }
675 
676 static void
677 gnc_plugin_business_cmd_employee_page (GtkAction *action,
679 {
680  GncPluginPage *page;
681 
682  g_return_if_fail (mw != NULL);
683  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
684 
685  page = gnc_plugin_page_owner_tree_new (GNC_OWNER_EMPLOYEE);
686  gnc_main_window_open_page (mw->window, page);
687 }
688 
689 static void
690 gnc_plugin_business_cmd_employee_new_employee (GtkAction *action,
692 {
693  g_return_if_fail (mw != NULL);
694  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
695 
696  gnc_ui_employee_new (gnc_get_current_book());
697 }
698 
699 static void
700 gnc_plugin_business_cmd_employee_find_employee (GtkAction *action,
702 {
703  GncPluginBusiness *plugin;
705  GncEmployee *employee;
706 
707  g_return_if_fail (mw != NULL);
708  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
709 
710  plugin = GNC_PLUGIN_BUSINESS (mw->data);
711  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
712  employee = gncOwnerGetEmployee (priv->last_employee);
713  gnc_employee_search (employee, gnc_get_current_book());
714 }
715 
716 static void
717 gnc_plugin_business_cmd_employee_new_expense_voucher (GtkAction *action,
719 {
720  GncPluginBusiness *plugin;
722 
723  g_return_if_fail (mw != NULL);
724  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
725 
726  plugin = GNC_PLUGIN_BUSINESS (mw->data);
727  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
728  last_window = mw->window;
729  gnc_ui_invoice_new (priv->last_employee, gnc_get_current_book());
730 }
731 
732 static void
733 gnc_plugin_business_cmd_employee_find_expense_voucher (GtkAction *action,
735 {
736  GncPluginBusiness *plugin;
738 
739  g_return_if_fail (mw != NULL);
740  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
741 
742  plugin = GNC_PLUGIN_BUSINESS (mw->data);
743  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
744  last_window = mw->window;
745  gnc_invoice_search (NULL, priv->last_employee, gnc_get_current_book());
746 }
747 
748 static void
749 gnc_plugin_business_cmd_employee_process_payment (GtkAction *action,
751 {
752  GncPluginBusiness *plugin;
754 
755  g_return_if_fail (mw != NULL);
756  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
757 
758  plugin = GNC_PLUGIN_BUSINESS (mw->data);
759  priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin);
760  gnc_ui_payment_new (priv->last_employee, gnc_get_current_book());
761 }
762 
763 static void
764 gnc_plugin_business_cmd_tax_tables (GtkAction *action,
766 {
767  g_return_if_fail (mw != NULL);
768  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
769 
770  gnc_ui_tax_table_window_new (gnc_get_current_book());
771 }
772 
773 static void
774 gnc_plugin_business_cmd_billing_terms (GtkAction *action,
776 {
777  g_return_if_fail (mw != NULL);
778  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
779 
780  gnc_ui_billterms_window_new (gnc_get_current_book());
781 }
782 
783 
784 static void
785 gnc_plugin_business_cmd_bills_due_reminder (GtkAction *action,
787 {
788  g_return_if_fail (mw != NULL);
789  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
790 
791  gnc_invoice_remind_bills_due();
792 }
793 
794 static void
795 gnc_plugin_business_cmd_test_search (GtkAction *action,
797 {
798  gnc_search_dialog_test();
799 }
800 
801 static void gnc_business_assign_payment (GtkWidget *parent,
802  Transaction *trans,
803  GncOwner *owner)
804 {
805  g_return_if_fail(trans);
806 
807  // Do nothing if we don't have more than one split (e.g. in the empty line at the end of the register)
808  if (xaccTransCountSplits(trans) <= 1)
809  return;
810 
811  //g_message("Creating payment dialog with trans %p", trans);
812  gnc_ui_payment_new_with_txn(owner, trans);
813 }
814 
815 static void gnc_plugin_business_cmd_assign_payment (GtkAction *action,
817 {
818  GncPluginBusiness *plugin_business;
819  GncPluginBusinessPrivate *plugin_business_priv;
820  GncPluginPage *plugin_page;
821  GNCSplitReg *gsr;
822  SplitRegister *reg;
823  Split *split;
824  Transaction *trans;
825  gboolean is_customer;
826 
827  g_return_if_fail (mw != NULL);
828  g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
829 
830  plugin_page = gnc_main_window_get_current_page(mw->window);
831 
832  // We continue only if the current page is a plugin page and more
833  // specifically a register plugin page
834  if (!GNC_IS_PLUGIN_PAGE(plugin_page)
835  || !GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page))
836  return;
837 
838  gsr = gnc_plugin_page_register_get_gsr(plugin_page);
839  g_return_if_fail(gsr);
840 
841  reg = gnc_ledger_display_get_split_register( gsr->ledger );
842  g_return_if_fail(reg);
843 
845  g_return_if_fail(split);
846 
847  trans = xaccSplitGetParent(split);
848  g_return_if_fail(trans);
849  is_customer = gnc_ui_payment_is_customer_payment(trans);
850 
851  plugin_business = GNC_PLUGIN_BUSINESS (mw->data);
852  plugin_business_priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin_business);
853 
854  gnc_business_assign_payment (gnc_plugin_page_get_window(plugin_page),
855  trans,
856  is_customer
857  ? plugin_business_priv->last_customer
858  : plugin_business_priv->last_vendor);
859 }
860 
861 static const gchar *register_txn_actions[] =
862 {
863  "RegisterAssignPayment",
864  NULL
865 };
866 
867 static void
868 gnc_plugin_business_update_menus (GncPluginPage *plugin_page)
869 {
870  GncMainWindow *window;
871  GtkActionGroup *action_group;
872  gboolean is_txn_register;
873 
874  // We continue only if the current page is a plugin page
875  if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
876  return;
877 
878  is_txn_register = GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page);
879  window = GNC_MAIN_WINDOW(plugin_page->window);
880  g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
882  g_return_if_fail(GTK_IS_ACTION_GROUP(action_group));
883 
884  // Change visibility and also sensitivity according to whether we are in a txn register
885  gnc_plugin_update_actions (action_group, register_txn_actions,
886  "sensitive", is_txn_register);
887  gnc_plugin_update_actions (action_group, register_txn_actions,
888  "visible", is_txn_register);
889 }
890 
891 
892 static void gnc_plugin_business_main_window_page_changed(GncMainWindow *window,
893  GncPluginPage *page,
894  gpointer user_data)
895 {
896  gnc_plugin_business_update_menus(page);
897  update_inactive_actions(page);
898 }
899 
900 static void
901 gnc_plugin_business_cmd_test_init_data (GtkAction *action,
903 {
904  QofBook *book = gnc_get_current_book();
905  GncCustomer *customer = gncCustomerCreate(book);
906  GncAddress *address = gncCustomerGetAddr(customer);
907  GncInvoice *invoice = gncInvoiceCreate(book);
908  GncOwner *owner = gncOwnerNew();
909  GncJob *job = gncJobCreate(book);
910  Account *root = gnc_book_get_root_account(book);
911  Account *inc_acct = xaccMallocAccount(book);
912  Account *bank_acct = xaccMallocAccount(book);
913  Account *tax_acct = xaccMallocAccount(book);
914  Account *ar_acct = xaccMallocAccount(book);
915  Timespec now;
916 
917  // Create Customer
918  gncCustomerSetID(customer, "000001");
919  gncCustomerSetName(customer, "Test Customer");
920  gncCustomerSetCurrency(customer, gnc_default_currency());
921  gncAddressSetName(address, "Contact Person");
922  gncAddressSetAddr1(address, "20 Customer Lane");
923  gncAddressSetAddr2(address, "Customer M/S");
924  gncAddressSetAddr3(address, "Addr3, XXX 12345");
925 
926  // Create the Owner
927  gncOwnerInitCustomer(owner, customer);
928 
929  // Create the Invoice
930  timespecFromTime64(&now, time(NULL));
931  gncInvoiceSetID(invoice, "000012");
932  gncInvoiceSetOwner(invoice, owner);
933  gncInvoiceSetDateOpened(invoice, now);
934  gncInvoiceSetCurrency(invoice, gnc_default_currency());
935 
936  // Create the Job
937  gncJobSetID(job, "000025");
938  gncJobSetName(job, "Test Job");
939  gncJobSetReference(job, "Customer's ref#");
940  gncJobSetOwner(job, owner);
941 
942  // MODIFY THE OWNER
943  gncOwnerInitJob(owner, job);
944 
945  // Create the A/R account
947  xaccAccountSetName(ar_acct, "A/R");
949  gnc_account_append_child(root, ar_acct);
950 
951  // Create the Income account
953  xaccAccountSetName(inc_acct, "Income");
955  gnc_account_append_child(root, inc_acct);
956 
957  // Create the Bank account
959  xaccAccountSetName(bank_acct, "Bank");
961  gnc_account_append_child(root, bank_acct);
962 
963  // Create the Tax account
965  xaccAccountSetName(tax_acct, "Tax-Holding");
967  gnc_account_append_child(root, tax_acct);
968 
969  // Launch the invoice editor
970  gnc_ui_invoice_edit(invoice);
971 }
972 
973 /* This is the list of actions which are switched inactive in a read-only book. */
974 static const gchar* readonly_inactive_actions[] =
975 {
976  "CustomerNewCustomerOpenAction",
977  "CustomerNewInvoiceOpenAction",
978  "CustomerNewInvoiceOpenAction",
979  "CustomerNewJobOpenAction",
980  "CustomerProcessPaymentAction",
981  "VendorNewVendorOpenAction",
982  "VendorNewBillOpenAction",
983  "VendorNewJobOpenAction",
984  "VendorProcessPaymentAction",
985  "EmployeeNewEmployeeOpenAction",
986  "EmployeeNewExpenseVoucherOpenAction",
987  "EmployeeProcessPaymentAction",
988  "ToolbarNewInvoiceAction",
989  "RegisterAssignPayment",
990  NULL
991 };
992 
993 static void update_inactive_actions(GncPluginPage *plugin_page)
994 {
995  GncMainWindow *window;
996  GtkActionGroup *action_group;
997 
998  // We are readonly - so we have to switch particular actions to inactive.
999  gboolean is_readwrite = !qof_book_is_readonly(gnc_get_current_book());
1000 
1001  // We continue only if the current page is a plugin page
1002  if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
1003  return;
1004 
1005  window = GNC_MAIN_WINDOW(plugin_page->window);
1006  g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
1007  action_group = gnc_main_window_get_action_group(window, PLUGIN_ACTIONS_NAME);
1008  g_return_if_fail(GTK_IS_ACTION_GROUP(action_group));
1009 
1010  /* Set the action's sensitivity */
1011  gnc_plugin_update_actions (action_group, readonly_inactive_actions,
1012  "sensitive", is_readwrite);
1013 }
1014 
1015 /* This is the list of actions which are switched invisible or visible
1016  * depending on the preference "extra_toolbuttons". */
1017 static const char* extra_toolbar_actions[] =
1018 {
1019  "ToolbarNewInvoiceAction",
1020  NULL
1021 };
1022 
1023 /* Bind the visibility of the extra toolbar buttons to the
1024  * enable_toolbuttons preference. */
1025 static void bind_toolbuttons_visibility (GncMainWindow *mainwindow)
1026 {
1027  GtkActionGroup *action_group;
1028  const char **iter;
1029 
1030  g_return_if_fail(mainwindow);
1031  g_return_if_fail(GNC_IS_MAIN_WINDOW(mainwindow));
1032 
1033  /* Get the action group */
1034  action_group =
1036  g_assert(action_group);
1037 
1038  for (iter = extra_toolbar_actions; *iter; ++iter)
1039  {
1040  /* Set the action's visibility */
1041  GtkAction *action = gtk_action_group_get_action (action_group, *iter);
1042  gnc_prefs_bind (GNC_PREFS_GROUP_INVOICE, GNC_PREF_EXTRA_TOOLBUTTONS, G_OBJECT (action), "visible");
1043  }
1044 }
1045 
1052 static void gnc_plugin_business_add_to_window (GncPlugin *plugin,
1053  GncMainWindow *mainwindow,
1054  GQuark type)
1055 {
1056  bind_toolbuttons_visibility (mainwindow);
1057 
1058  g_signal_connect(mainwindow, "page_changed",
1059  G_CALLBACK(gnc_plugin_business_main_window_page_changed),
1060  plugin);
1061 }
1062 
1063 static const char* invoice_printreport_values[] =
1064 {
1065  /* The list below are the guids of reports that can
1066  * be used to print an invoice.
1067  * Important: this list must be kept in sync with the one at the end
1068  * of business-prefs.glade
1069  */
1070  "5123a759ceb9483abf2182d01c140e8d", // "Printable Invoice"
1071  "0769e242be474010b4acf264a5512e6e", // "Tax Invoice"
1072  "67112f318bef4fc496bdc27d106bbda4", // "Easy Invoice"
1073  "3ce293441e894423a2425d7a22dd1ac6", // "Fancy Invoice"
1074  NULL
1075 };
1076 
1077 const char *gnc_plugin_business_get_invoice_printreport(void)
1078 {
1079  int value = gnc_prefs_get_int (GNC_PREFS_GROUP_INVOICE, GNC_PREF_INV_PRINT_RPT);
1080  if (value >= 0 && value < 4)
1081  return invoice_printreport_values[value];
1082  else
1083  return NULL;
1084 }
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Definition: Account.c:2208
utility functions for the GnuCash UI
GtkWidget * gnc_plugin_page_get_window(GncPluginPage *page)
void gnc_account_append_child(Account *new_parent, Account *child)
Definition: Account.c:2525
Business Interface: Object OWNERs.
Date and Time handling routines.
utility functions for the GnuCash UI
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
The type, style and table for the register.
Split * gnc_split_register_get_current_split(SplitRegister *reg)
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
GtkWidget * window
Transaction * xaccSplitGetParent(const Split *split)
Definition: Split.c:1903
const gchar * ui_filename
Definition: gnc-plugin.h:137
GncPluginPage * gnc_main_window_get_current_page(GncMainWindow *window)
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
gint gnc_prefs_get_int(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:206
Functions for adding content to a window.
gnc_commodity * gnc_default_currency(void)
Definition: gnc-ui-util.c:939
int xaccTransCountSplits(const Transaction *trans)
Definition: Transaction.c:2170
GtkActionEntry * actions
Definition: gnc-plugin.h:122
Functions providing a register page for the GnuCash UI.
Functions providing a page which lists owners of one type. This type can be vendors, customers or employees.
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, gpointer object, const gchar *property)
Definition: gnc-prefs.c:186
Definition: gncJob.c:41
const gchar * actions_name
Definition: gnc-plugin.h:119
Generic api to store and retrieve preferences.
GtkActionGroup * gnc_main_window_get_action_group(GncMainWindow *window, const gchar *group_name)
gboolean qof_book_is_readonly(const QofBook *book)
const gchar * plugin_name
Definition: gnc-plugin.h:112
void gnc_plugin_update_actions(GtkActionGroup *action_group, const gchar **action_names, const gchar *property_name, gboolean value)
Definition: gnc-plugin.c:313
Definition: SplitP.h:71
GNCLedgerDisplay * ledger
Definition: gnc-split-reg.h:79
#define PLUGIN_ACTIONS_NAME
void(* add_to_window)(GncPlugin *plugin, GncMainWindow *window, GQuark type)
Definition: gnc-plugin.h:155
Account * xaccMallocAccount(QofBook *book)
Definition: Account.c:1083
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
Definition: gncOwner.c:361
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
Definition: gncOwner.c:347
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
Definition: gncOwner.c:368
GNCSplitReg * gnc_plugin_page_register_get_gsr(GncPluginPage *plugin_page)
GncOwner * gncOwnerNew(void)
Definition: gncOwner.c:58
void xaccAccountSetName(Account *acc, const char *str)
Definition: Account.c:2229
GncPluginPage * gnc_plugin_page_owner_tree_new(GncOwnerType owner_type)
#define PLUGIN_UI_FILENAME
const gchar * QofLogModule
Definition: qofid.h:89
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Definition: Account.c:2389
void timespecFromTime64(Timespec *ts, time64 t)