GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gncEmployee.c
1 /********************************************************************\
2  * gncEmployee.c -- the Core Employee Interface *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License as *
6  * published by the Free Software Foundation; either version 2 of *
7  * the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License*
15  * along with this program; if not, contact: *
16  * *
17  * Free Software Foundation Voice: +1-617-542-5942 *
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
19  * Boston, MA 02110-1301, USA [email protected] *
20  * *
21 \********************************************************************/
22 
23 /*
24  * Copyright (C) 2001,2002 Derek Atkins
25  * Copyright (C) 2003 Linas Vepstas <[email protected]>
26  * Author: Derek Atkins <[email protected]>
27  */
28 
29 #include <config.h>
30 
31 #include <glib.h>
32 #include <string.h>
33 #include <qofinstance-p.h>
34 
35 #include "Account.h"
36 #include "gnc-commodity.h"
37 #include "gncAddressP.h"
38 #include "gncEmployee.h"
39 #include "gncEmployeeP.h"
40 
41 static gint gs_address_event_handler_id = 0;
42 static void listen_for_address_events(QofInstance *entity, QofEventId event_type,
43  gpointer user_data, gpointer event_data);
44 
46 {
47  QofInstance inst;
48  char * id;
49  char * username;
50  GncAddress * addr;
51  gnc_commodity * currency;
52  gboolean active;
53 
54  char * language;
55  char * acl;
56  gnc_numeric workday;
57  gnc_numeric rate;
58 
59  Account * ccard_acc;
60 };
61 
63 {
64  QofInstanceClass parent_class;
65 };
66 
67 static QofLogModule log_module = GNC_MOD_BUSINESS;
68 
69 #define _GNC_MOD_NAME GNC_ID_EMPLOYEE
70 
71 G_INLINE_FUNC void mark_employee (GncEmployee *employee);
72 void mark_employee (GncEmployee *employee)
73 {
74  qof_instance_set_dirty(&employee->inst);
75  qof_event_gen (&employee->inst, QOF_EVENT_MODIFY, NULL);
76 }
77 
78 /* ============================================================== */
79 
80 enum
81 {
82  PROP_0,
83  PROP_USERNAME, /* Table */
84  PROP_ID, /* Table */
85  PROP_LANGUAGE, /* Table */
86  PROP_ACL, /* Table */
87  PROP_ACTIVE, /* Table */
88  PROP_CURRENCY, /* Table */
89  PROP_CCARD, /* Table */
90  PROP_WORKDAY, /* Table (numeric) */
91  PROP_RATE, /* Table (numeric) */
92  PROP_ADDRESS, /* Table, 8 fields */
93  PROP_PDF_DIRNAME, /* KVP */
94  PROP_LAST_POSTED, /* KVP */
95  PROP_PAYMENT_LAST_ACCT, /* KVP */
96 };
97 
98 /* GObject Initialization */
99 G_DEFINE_TYPE(GncEmployee, gnc_employee, QOF_TYPE_INSTANCE);
100 
101 static void
102 gnc_employee_init(GncEmployee* emp)
103 {
104 }
105 
106 static void
107 gnc_employee_dispose(GObject *empp)
108 {
109  G_OBJECT_CLASS(gnc_employee_parent_class)->dispose(empp);
110 }
111 
112 static void
113 gnc_employee_finalize(GObject* empp)
114 {
115  G_OBJECT_CLASS(gnc_employee_parent_class)->finalize(empp);
116 }
117 
118 /* Note that g_value_set_object() refs the object, as does
119  * g_object_get(). But g_object_get() only unrefs once when it disgorges
120  * the object, leaving an unbalanced ref, which leaks. So instead of
121  * using g_value_set_object(), use g_value_take_object() which doesn't
122  * ref the object when used in get_property().
123  */
124 static void
125 gnc_employee_get_property (GObject *object,
126  guint prop_id,
127  GValue *value,
128  GParamSpec *pspec)
129 {
130  GncEmployee *emp;
131  gchar *key;
132 
133  g_return_if_fail(GNC_IS_EMPLOYEE(object));
134 
135  emp = GNC_EMPLOYEE(object);
136  switch (prop_id)
137  {
138  case PROP_USERNAME:
139  g_value_set_string(value, emp->username);
140  break;
141  case PROP_ID:
142  g_value_set_string(value, emp->id);
143  break;
144  case PROP_ACTIVE:
145  g_value_set_boolean(value, emp->active);
146  break;
147  case PROP_LANGUAGE:
148  g_value_set_string(value, emp->language);
149  break;
150  case PROP_CURRENCY:
151  g_value_take_object(value, emp->currency);
152  break;
153  case PROP_ACL:
154  g_value_set_string(value, emp->acl);
155  break;
156  case PROP_ADDRESS:
157  g_value_take_object(value, emp->addr);
158  break;
159  case PROP_WORKDAY:
160  g_value_set_boxed(value, &emp->workday);
161  break;
162  case PROP_RATE:
163  g_value_set_boxed(value, &emp->rate);
164  break;
165  case PROP_CCARD:
166  g_value_take_object(value, emp->ccard_acc);
167  break;
168  case PROP_PDF_DIRNAME:
169  key = OWNER_EXPORT_PDF_DIRNAME;
170  qof_instance_get_kvp (QOF_INSTANCE (emp), key, value);
171  break;
172  case PROP_LAST_POSTED:
173  key = LAST_POSTED_TO_ACCT;
174  qof_instance_get_kvp (QOF_INSTANCE (emp), key, value);
175  break;
176  case PROP_PAYMENT_LAST_ACCT:
177  key = GNC_PAYMENT "/" GNC_LAST_ACCOUNT;
178  qof_instance_get_kvp (QOF_INSTANCE (emp), key, value);
179  break;
180  default:
181  G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
182  break;
183  }
184 }
185 
186 static void
187 gnc_employee_set_property (GObject *object,
188  guint prop_id,
189  const GValue *value,
190  GParamSpec *pspec)
191 {
192  GncEmployee *emp;
193  gchar *key;
194 
195  g_return_if_fail(GNC_IS_EMPLOYEE(object));
196 
197  emp = GNC_EMPLOYEE(object);
198  g_assert (qof_instance_get_editlevel(emp));
199 
200  switch (prop_id)
201  {
202  case PROP_USERNAME:
203  gncEmployeeSetUsername(emp, g_value_get_string(value));
204  break;
205  case PROP_ID:
206  gncEmployeeSetID(emp, g_value_get_string(value));
207  break;
208  case PROP_ACTIVE:
209  gncEmployeeSetActive(emp, g_value_get_boolean(value));
210  break;
211  case PROP_LANGUAGE:
212  gncEmployeeSetLanguage(emp, g_value_get_string(value));
213  break;
214  case PROP_CURRENCY:
215  gncEmployeeSetCurrency(emp, g_value_get_object(value));
216  break;
217  case PROP_ACL:
218  gncEmployeeSetAcl(emp, g_value_get_string(value));
219  break;
220  case PROP_ADDRESS:
221  qofEmployeeSetAddr(emp, g_value_get_object(value));
222  break;
223  case PROP_WORKDAY:
224  gncEmployeeSetWorkday(emp, *(gnc_numeric*)g_value_get_boxed(value));
225  break;
226  case PROP_RATE:
227  gncEmployeeSetRate(emp, *(gnc_numeric*)g_value_get_boxed(value));
228  break;
229  case PROP_CCARD:
230  gncEmployeeSetCCard(emp, g_value_get_object(value));
231  break;
232  case PROP_PDF_DIRNAME:
233  key = OWNER_EXPORT_PDF_DIRNAME;
234  qof_instance_set_kvp (QOF_INSTANCE (emp), key, value);
235  break;
236  case PROP_LAST_POSTED:
237  key = LAST_POSTED_TO_ACCT;
238  qof_instance_set_kvp (QOF_INSTANCE (emp), key, value);
239  break;
240  case PROP_PAYMENT_LAST_ACCT:
241  key = GNC_PAYMENT "/" GNC_LAST_ACCOUNT;
242  qof_instance_set_kvp (QOF_INSTANCE (emp), key, value);
243  break;
244  default:
245  G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
246  break;
247  }
248 }
249 
251 static gboolean
252 impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
253 {
254  GncEmployee* emp;
255 
256  g_return_val_if_fail(inst != NULL, FALSE);
257  g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
258 
259  emp = GNC_EMPLOYEE(inst);
260 
261  if (GNC_IS_COMMODITY(ref))
262  {
263  return (emp->currency == GNC_COMMODITY(ref));
264  }
265  else if (GNC_IS_ACCOUNT(ref))
266  {
267  return (emp->ccard_acc == GNC_ACCOUNT(ref));
268  }
269 
270  return FALSE;
271 }
272 
279 static GList*
280 impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
281 {
282  if (!GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref))
283  {
284  return NULL;
285  }
286 
288 }
289 
290 static void
291 gnc_employee_class_init (GncEmployeeClass *klass)
292 {
293  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
294  QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
295 
296  gobject_class->dispose = gnc_employee_dispose;
297  gobject_class->finalize = gnc_employee_finalize;
298  gobject_class->set_property = gnc_employee_set_property;
299  gobject_class->get_property = gnc_employee_get_property;
300 
301  qof_class->get_display_name = NULL;
302  qof_class->refers_to_object = impl_refers_to_object;
303  qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
304 
305  g_object_class_install_property
306  (gobject_class,
307  PROP_USERNAME,
308  g_param_spec_string ("username",
309  "Employee Name",
310  "The employee name is an arbitrary string "
311  "assigned by the user which provides the employee "
312  "name.",
313  NULL,
314  G_PARAM_READWRITE));
315 
316  g_object_class_install_property
317  (gobject_class,
318  PROP_ID,
319  g_param_spec_string ("id",
320  "Employee ID",
321  "The employee ID is an arbitrary string "
322  "assigned by the user which provides the employee "
323  "ID.",
324  NULL,
325  G_PARAM_READWRITE));
326 
327  g_object_class_install_property
328  (gobject_class,
329  PROP_ACTIVE,
330  g_param_spec_boolean ("active",
331  "Active",
332  "TRUE if the employee is active. FALSE if inactive.",
333  FALSE,
334  G_PARAM_READWRITE));
335 
336  g_object_class_install_property
337  (gobject_class,
338  PROP_LANGUAGE,
339  g_param_spec_string ("language",
340  "Employee Language",
341  "The language is an arbitrary string "
342  "assigned by the user which provides the language spoken "
343  " by the employee.",
344  NULL,
345  G_PARAM_READWRITE));
346 
347  g_object_class_install_property
348  (gobject_class,
349  PROP_CURRENCY,
350  g_param_spec_object ("currency",
351  "Currency",
352  "The currency property denotes the currency used by this employee.",
353  GNC_TYPE_COMMODITY,
354  G_PARAM_READWRITE));
355 
356  g_object_class_install_property
357  (gobject_class,
358  PROP_ACL,
359  g_param_spec_string ("acl",
360  "Employee ACL",
361  "The acl is an arbitrary string "
362  "assigned by the user which provides ??? "
363  " for the employee.",
364  NULL,
365  G_PARAM_READWRITE));
366 
367  g_object_class_install_property
368  (gobject_class,
369  PROP_ADDRESS,
370  g_param_spec_object ("address",
371  "Address",
372  "The address property contains the address information for this employee.",
373  GNC_TYPE_ADDRESS,
374  G_PARAM_READWRITE));
375 
376  g_object_class_install_property
377  (gobject_class,
378  PROP_WORKDAY,
379  g_param_spec_boxed("workday",
380  "Workday rate",
381  "The daily rate for this employee.",
382  GNC_TYPE_NUMERIC,
383  G_PARAM_READWRITE));
384 
385  g_object_class_install_property
386  (gobject_class,
387  PROP_RATE,
388  g_param_spec_boxed("rate",
389  "Hourly rate",
390  "The hourly rate for this employee.",
391  GNC_TYPE_NUMERIC,
392  G_PARAM_READWRITE));
393 
394  g_object_class_install_property
395  (gobject_class,
396  PROP_CCARD,
397  g_param_spec_object ("credit-card-account",
398  "Credit card account",
399  "The credit card account for this employee.",
400  GNC_TYPE_ACCOUNT,
401  G_PARAM_READWRITE));
402 
403  g_object_class_install_property
404  (gobject_class,
405  PROP_PDF_DIRNAME,
406  g_param_spec_string ("export-pdf-dir",
407  "Export PDF Directory Name",
408  "A subdirectory for exporting PDF reports which is "
409  "appended to the target directory when writing them "
410  "out. It is retrieved from preferences and stored on "
411  "each 'Owner' object which prints items after "
412  "printing.",
413  NULL,
414  G_PARAM_READWRITE));
415 
416  g_object_class_install_property(
417  gobject_class,
418  PROP_LAST_POSTED,
419  g_param_spec_boxed("invoice-last-posted-account",
420  "Invoice Last Posted Account",
421  "The last account to which an invoice belonging to "
422  "this owner was posted.",
423  GNC_TYPE_GUID,
424  G_PARAM_READWRITE));
425 
426  g_object_class_install_property(
427  gobject_class,
428  PROP_PAYMENT_LAST_ACCT,
429  g_param_spec_boxed("payment-last-account",
430  "Payment Last Account",
431  "The last account to which an payment belonging to "
432  "this owner was posted.",
433  GNC_TYPE_GUID,
434  G_PARAM_READWRITE));
435 }
436 
437 /* Create/Destroy Functions */
438 GncEmployee *gncEmployeeCreate (QofBook *book)
439 {
440  GncEmployee *employee;
441 
442  if (!book) return NULL;
443 
444  employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
445  qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book);
446 
447  employee->id = CACHE_INSERT ("");
448  employee->username = CACHE_INSERT ("");
449  employee->language = CACHE_INSERT ("");
450  employee->acl = CACHE_INSERT ("");
451  employee->addr = gncAddressCreate (book, &employee->inst);
452  employee->workday = gnc_numeric_zero();
453  employee->rate = gnc_numeric_zero();
454  employee->active = TRUE;
455 
456  if (gs_address_event_handler_id == 0)
457  {
458  gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
459  }
460 
461  qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);
462 
463  return employee;
464 }
465 
466 void gncEmployeeDestroy (GncEmployee *employee)
467 {
468  if (!employee) return;
469  qof_instance_set_destroying(employee, TRUE);
470  gncEmployeeCommitEdit(employee);
471 }
472 
473 static void gncEmployeeFree (GncEmployee *employee)
474 {
475  if (!employee) return;
476 
477  qof_event_gen (&employee->inst, QOF_EVENT_DESTROY, NULL);
478 
479  CACHE_REMOVE (employee->id);
480  CACHE_REMOVE (employee->username);
481  CACHE_REMOVE (employee->language);
482  CACHE_REMOVE (employee->acl);
483  gncAddressBeginEdit (employee->addr);
484  gncAddressDestroy (employee->addr);
485 
486  /* qof_instance_release (&employee->inst); */
487  g_object_unref (employee);
488 }
489 
490 /* ============================================================== */
491 /* Set Functions */
492 
493 #define SET_STR(obj, member, str) { \
494  char * tmp; \
495  \
496  if (!g_strcmp0 (member, str)) return; \
497  gncEmployeeBeginEdit (obj); \
498  tmp = CACHE_INSERT (str); \
499  CACHE_REMOVE (member); \
500  member = tmp; \
501  }
502 
503 void gncEmployeeSetID (GncEmployee *employee, const char *id)
504 {
505  if (!employee) return;
506  if (!id) return;
507  SET_STR(employee, employee->id, id);
508  mark_employee (employee);
509  gncEmployeeCommitEdit (employee);
510 }
511 
512 void gncEmployeeSetUsername (GncEmployee *employee, const char *username)
513 {
514  if (!employee) return;
515  if (!username) return;
516  SET_STR(employee, employee->username, username);
517  mark_employee (employee);
518  gncEmployeeCommitEdit (employee);
519 }
520 
521 /* Employees don't have a name property defined, but
522  * in order to get a consistent interface with other owner types,
523  * this function fakes one by setting the name property of
524  * the employee's address.
525  */
526 void gncEmployeeSetName (GncEmployee *employee, const char *name)
527 {
528  if (!employee) return;
529  if (!name) return;
530  gncAddressSetName (gncEmployeeGetAddr (employee), name);
531 }
532 
533 void gncEmployeeSetLanguage (GncEmployee *employee, const char *language)
534 {
535  if (!employee) return;
536  if (!language) return;
537  SET_STR(employee, employee->language, language);
538  mark_employee (employee);
539  gncEmployeeCommitEdit (employee);
540 }
541 
542 void gncEmployeeSetAcl (GncEmployee *employee, const char *acl)
543 {
544  if (!employee) return;
545  if (!acl) return;
546  SET_STR(employee, employee->acl, acl);
547  mark_employee (employee);
548  gncEmployeeCommitEdit (employee);
549 }
550 
551 void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday)
552 {
553  if (!employee) return;
554  if (gnc_numeric_equal (workday, employee->workday)) return;
555  gncEmployeeBeginEdit (employee);
556  employee->workday = workday;
557  mark_employee (employee);
558  gncEmployeeCommitEdit (employee);
559 }
560 
561 void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate)
562 {
563  if (!employee) return;
564  if (gnc_numeric_equal (rate, employee->rate)) return;
565  gncEmployeeBeginEdit (employee);
566  employee->rate = rate;
567  mark_employee (employee);
568  gncEmployeeCommitEdit (employee);
569 }
570 
571 void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity *currency)
572 {
573  if (!employee || !currency) return;
574  if (employee->currency &&
575  gnc_commodity_equal (employee->currency, currency))
576  return;
577  gncEmployeeBeginEdit (employee);
578  employee->currency = currency;
579  mark_employee (employee);
580  gncEmployeeCommitEdit (employee);
581 }
582 
583 void gncEmployeeSetActive (GncEmployee *employee, gboolean active)
584 {
585  if (!employee) return;
586  if (active == employee->active) return;
587  gncEmployeeBeginEdit (employee);
588  employee->active = active;
589  mark_employee (employee);
590  gncEmployeeCommitEdit (employee);
591 }
592 
593 void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc)
594 {
595  if (!employee) return;
596  if (ccard_acc == employee->ccard_acc) return;
597  gncEmployeeBeginEdit (employee);
598  employee->ccard_acc = ccard_acc;
599  mark_employee (employee);
600  gncEmployeeCommitEdit (employee);
601 }
602 
603 void
604 qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent)
605 {
606  GncAddress *addr;
607 
608  if (!employee || !addr_ent)
609  {
610  return;
611  }
612  addr = (GncAddress*)addr_ent;
613  if (addr == employee->addr)
614  {
615  return;
616  }
617  if (employee->addr != NULL)
618  {
619  gncAddressBeginEdit(employee->addr);
620  gncAddressDestroy(employee->addr);
621  }
622  gncEmployeeBeginEdit(employee);
623  employee->addr = addr;
624  mark_employee (employee);
625  gncEmployeeCommitEdit(employee);
626 }
627 
628 /* ============================================================== */
629 /* Get Functions */
630 const char * gncEmployeeGetID (const GncEmployee *employee)
631 {
632  if (!employee) return NULL;
633  return employee->id;
634 }
635 
636 const char * gncEmployeeGetUsername (const GncEmployee *employee)
637 {
638  if (!employee) return NULL;
639  return employee->username;
640 }
641 
642 /* Employees don't have a name property defined, but
643  * in order to get a consistent interface with other owner types,
644  * this function fakes one by returning the name property of
645  * the employee's address.
646  */
647 const char * gncEmployeeGetName (const GncEmployee *employee)
648 {
649  if (!employee) return NULL;
650  return gncAddressGetName ( gncEmployeeGetAddr (employee));
651 }
652 
653 GncAddress * gncEmployeeGetAddr (const GncEmployee *employee)
654 {
655  if (!employee) return NULL;
656  return employee->addr;
657 }
658 
659 const char * gncEmployeeGetLanguage (const GncEmployee *employee)
660 {
661  if (!employee) return NULL;
662  return employee->language;
663 }
664 
665 const char * gncEmployeeGetAcl (const GncEmployee *employee)
666 {
667  if (!employee) return NULL;
668  return employee->acl;
669 }
670 
671 gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee)
672 {
673  if (!employee) return gnc_numeric_zero();
674  return employee->workday;
675 }
676 
677 gnc_numeric gncEmployeeGetRate (const GncEmployee *employee)
678 {
679  if (!employee) return gnc_numeric_zero();
680  return employee->rate;
681 }
682 
683 gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee)
684 {
685  if (!employee) return NULL;
686  return employee->currency;
687 }
688 
689 gboolean gncEmployeeGetActive (const GncEmployee *employee)
690 {
691  if (!employee) return FALSE;
692  return employee->active;
693 }
694 
695 Account * gncEmployeeGetCCard (const GncEmployee *employee)
696 {
697  if (!employee) return NULL;
698  return employee->ccard_acc;
699 }
700 
701 gboolean gncEmployeeIsDirty (const GncEmployee *employee)
702 {
703  if (!employee) return FALSE;
704  return (qof_instance_get_dirty_flag(employee)
705  || gncAddressIsDirty (employee->addr));
706 }
707 
708 void gncEmployeeBeginEdit (GncEmployee *employee)
709 {
710  qof_begin_edit(&employee->inst);
711 }
712 
713 static void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode)
714 {
715  PERR("Employee QofBackend Failure: %d", errcode);
716  gnc_engine_signal_commit_error( errcode );
717 }
718 
719 static void gncEmployeeOnDone (QofInstance *inst)
720 {
721  GncEmployee *employee = (GncEmployee *) inst;
722  gncAddressClearDirty (employee->addr);
723 }
724 
725 static void emp_free (QofInstance *inst)
726 {
727  GncEmployee *employee = (GncEmployee *) inst;
728  gncEmployeeFree (employee);
729 }
730 
731 
732 void gncEmployeeCommitEdit (GncEmployee *employee)
733 {
734  if (!qof_commit_edit (QOF_INSTANCE(employee))) return;
735  qof_commit_edit_part2 (&employee->inst, gncEmployeeOnError,
736  gncEmployeeOnDone, emp_free);
737 }
738 
739 /* ============================================================== */
740 /* Other functions */
741 
742 int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b)
743 {
744  if (!a && !b) return 0;
745  if (!a && b) return 1;
746  if (a && !b) return -1;
747 
748  return(strcmp(a->username, b->username));
749 }
750 
751 gboolean gncEmployeeEqual(const GncEmployee* a, const GncEmployee* b)
752 {
753  if (a == NULL && b == NULL) return TRUE;
754  if (a == NULL || b == NULL ) return FALSE;
755 
756  g_return_val_if_fail(GNC_IS_EMPLOYEE(a), FALSE);
757  g_return_val_if_fail(GNC_IS_EMPLOYEE(b), FALSE);
758 
759  if (g_strcmp0(a->id, b->id) != 0)
760  {
761  PWARN("IDs differ: %s vs %s", a->id, b->id);
762  return FALSE;
763  }
764 
765  if (g_strcmp0(a->username, b->username) != 0)
766  {
767  PWARN("Usernames differ: %s vs %s", a->username, b->username);
768  return FALSE;
769  }
770 
771  if (!gncAddressEqual(a->addr, b->addr))
772  {
773  PWARN("Addresses differ");
774  return FALSE;
775  }
776 
777  if (!gnc_commodity_equal(a->currency, b->currency))
778  {
779  PWARN("Currencies differ");
780  return FALSE;
781  }
782 
783  if (a->active != b->active)
784  {
785  PWARN("Active flags differ");
786  return FALSE;
787  }
788 
789  if (g_strcmp0(a->language, b->language) != 0)
790  {
791  PWARN("Languages differ: %s vs %s", a->language, b->language);
792  return FALSE;
793  }
794 
795  if (g_strcmp0(a->acl, b->acl) != 0)
796  {
797  PWARN("ACLs differ: %s vs %s", a->acl, b->acl);
798  return FALSE;
799  }
800 
801  if (!xaccAccountEqual(a->ccard_acc, b->ccard_acc, TRUE))
802  {
803  PWARN("Accounts differ");
804  return FALSE;
805  }
806 
807  if (!gnc_numeric_equal(a->workday, b->workday))
808  {
809  PWARN("Workdays differ");
810  return FALSE;
811  }
812 
813  if (!gnc_numeric_equal(a->rate, b->rate))
814  {
815  PWARN("Rates differ");
816  return FALSE;
817  }
818 
819  return TRUE;
820 }
821 
822 /* Package-Private functions */
823 
824 static const char * _gncEmployeePrintable (gpointer item)
825 {
826  GncEmployee *v = item;
827  if (!item) return NULL;
828  return gncAddressGetName(v->addr);
829 }
830 
840 static void
841 listen_for_address_events(QofInstance *entity, QofEventId event_type,
842  gpointer user_data, gpointer event_data)
843 {
844  GncEmployee* empl;
845 
846  if ((event_type & QOF_EVENT_MODIFY) == 0)
847  {
848  return;
849  }
850  if (!GNC_IS_ADDRESS(entity))
851  {
852  return;
853  }
854  if (!GNC_IS_EMPLOYEE(event_data))
855  {
856  return;
857  }
858  empl = GNC_EMPLOYEE(event_data);
859  gncEmployeeBeginEdit(empl);
860  mark_employee(empl);
861  gncEmployeeCommitEdit(empl);
862 }
863 
864 static void
865 destroy_employee_on_book_close(QofInstance *ent, gpointer data)
866 {
867  GncEmployee* e = GNC_EMPLOYEE(ent);
868 
869  gncEmployeeBeginEdit(e);
870  gncEmployeeDestroy(e);
871 }
872 
877 static void
878 gnc_employee_book_end(QofBook* book)
879 {
880  QofCollection *col;
881 
882  col = qof_book_get_collection(book, GNC_ID_EMPLOYEE);
883  qof_collection_foreach(col, destroy_employee_on_book_close, NULL);
884 }
885 
886 static QofObject gncEmployeeDesc =
887 {
888  DI(.interface_version = ) QOF_OBJECT_VERSION,
889  DI(.e_type = ) _GNC_MOD_NAME,
890  DI(.type_label = ) "Employee",
891  DI(.create = ) (gpointer)gncEmployeeCreate,
892  DI(.book_begin = ) NULL,
893  DI(.book_end = ) gnc_employee_book_end,
894  DI(.is_dirty = ) qof_collection_is_dirty,
895  DI(.mark_clean = ) qof_collection_mark_clean,
896  DI(.foreach = ) qof_collection_foreach,
897  DI(.printable = ) _gncEmployeePrintable,
898  DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
899 };
900 
901 gboolean gncEmployeeRegister (void)
902 {
903  static QofParam params[] =
904  {
905  { EMPLOYEE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetID, (QofSetterFunc)gncEmployeeSetID },
906  {
907  EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername,
908  (QofSetterFunc)gncEmployeeSetUsername
909  },
910  {
911  EMPLOYEE_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetName,
912  (QofSetterFunc)gncEmployeeSetName
913  },
914  {
915  EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetLanguage,
916  (QofSetterFunc)gncEmployeeSetLanguage
917  },
918  { EMPLOYEE_ACL, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetAcl, (QofSetterFunc)gncEmployeeSetAcl },
919  {
920  EMPLOYEE_WORKDAY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetWorkday,
921  (QofSetterFunc)gncEmployeeSetWorkday
922  },
923  { EMPLOYEE_RATE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetRate, (QofSetterFunc)gncEmployeeSetRate },
924  { EMPLOYEE_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncEmployeeGetAddr, (QofSetterFunc)qofEmployeeSetAddr },
925  { EMPLOYEE_CC, GNC_ID_ACCOUNT, (QofAccessFunc)gncEmployeeGetCCard, (QofSetterFunc)gncEmployeeSetCCard },
926  { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive, (QofSetterFunc)gncEmployeeSetActive },
927  { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
928  { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
929  { NULL },
930  };
931 
932  qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare, params);
933 
934  return qof_object_register (&gncEmployeeDesc);
935 }
936 
937 gchar *gncEmployeeNextID (QofBook *book)
938 {
939  return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
940 }
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
const GncGUID * qof_instance_get_guid(gconstpointer)
QofBook * qof_instance_get_book(gconstpointer)
gboolean qof_collection_is_dirty(const QofCollection *col)
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition: qofbackend.h:59
gchar * qof_book_increment_and_format_counter(QofBook *book, const char *counter_name)
GList * qof_instance_get_referring_object_list_from_collection(const QofCollection *coll, const QofInstance *ref)
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_fcn, const QofParam *params)
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
QofCollection * qof_instance_get_collection(gconstpointer inst)
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
Definition: qofclass.h:177
#define QOF_OBJECT_VERSION
Definition: qofobject.h:64
gboolean qof_commit_edit(QofInstance *inst)
#define PERR(format, args...)
Definition: qoflog.h:237
#define QOF_PARAM_BOOK
Definition: qofquery.h:109
void qof_collection_foreach(const QofCollection *, QofInstanceForeachCB, gpointer user_data)
gint qof_event_register_handler(QofEventHandler handler, gpointer handler_data)
Register a handler for events.
#define PWARN(format, args...)
Definition: qoflog.h:243
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean qof_begin_edit(QofInstance *inst)
Account handling public routines.
gint QofEventId
Definition: qofevent.h:45
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
int(* QofSortFunc)(gconstpointer, gconstpointer)
Definition: qofclass.h:222
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
void qof_collection_mark_clean(QofCollection *)
gboolean xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
Definition: Account.c:1475
gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b)
Deeply compare two addresses.
Definition: gncAddress.c:579
Employee Interface.
void(* QofSetterFunc)(gpointer, gpointer)
Definition: qofclass.h:184
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
gboolean qof_object_register(const QofObject *object)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Commodity handling public routines.
const gchar * QofLogModule
Definition: qofid.h:89
gboolean gncEmployeeEqual(const GncEmployee *a, const GncEmployee *b)
Definition: gncEmployee.c:751