33 #include <qofinstance-p.h> 37 #include "gncAddressP.h" 39 #include "gncEmployeeP.h" 43 static gint empl_qof_event_handler_id = 0;
45 gpointer user_data, gpointer event_data);
51 const char * username;
53 gnc_commodity * currency;
55 gnc_numeric * balance;
57 const char * language;
67 QofInstanceClass parent_class;
70 static QofLogModule log_module = GNC_MOD_BUSINESS;
72 #define _GNC_MOD_NAME GNC_ID_EMPLOYEE 74 static inline void mark_employee (GncEmployee *employee);
75 void mark_employee (GncEmployee *employee)
77 qof_instance_set_dirty(&employee->inst);
98 PROP_PAYMENT_LAST_ACCT,
102 G_DEFINE_TYPE(GncEmployee, gnc_employee, QOF_TYPE_INSTANCE)
105 gnc_employee_init(GncEmployee* emp)
110 gnc_employee_dispose(GObject *empp)
112 G_OBJECT_CLASS(gnc_employee_parent_class)->dispose(empp);
116 gnc_employee_finalize(GObject* empp)
118 G_OBJECT_CLASS(gnc_employee_parent_class)->finalize(empp);
128 gnc_employee_get_property (GObject *
object,
134 g_return_if_fail(GNC_IS_EMPLOYEE(
object));
135 emp = GNC_EMPLOYEE(
object);
139 g_value_set_string(value, emp->username);
142 g_value_set_string(value, emp->id);
145 g_value_set_boolean(value, emp->active);
148 g_value_set_string(value, emp->language);
151 g_value_take_object(value, emp->currency);
154 g_value_set_string(value, emp->acl);
157 g_value_take_object(value, emp->addr);
160 g_value_set_boxed(value, &emp->workday);
163 g_value_set_boxed(value, &emp->rate);
166 g_value_take_object(value, emp->ccard_acc);
168 case PROP_PDF_DIRNAME:
171 case PROP_LAST_POSTED:
174 case PROP_PAYMENT_LAST_ACCT:
178 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
184 gnc_employee_set_property (GObject *
object,
190 g_return_if_fail(GNC_IS_EMPLOYEE(
object));
191 emp = GNC_EMPLOYEE(
object);
192 g_assert (qof_instance_get_editlevel(emp));
196 gncEmployeeSetUsername(emp, g_value_get_string(value));
199 gncEmployeeSetID(emp, g_value_get_string(value));
202 gncEmployeeSetActive(emp, g_value_get_boolean(value));
205 gncEmployeeSetLanguage(emp, g_value_get_string(value));
208 gncEmployeeSetCurrency(emp, g_value_get_object(value));
211 gncEmployeeSetAcl(emp, g_value_get_string(value));
214 qofEmployeeSetAddr(emp, g_value_get_object(value));
217 gncEmployeeSetWorkday(emp, *(gnc_numeric*)g_value_get_boxed(value));
220 gncEmployeeSetRate(emp, *(gnc_numeric*)g_value_get_boxed(value));
223 gncEmployeeSetCCard(emp, g_value_get_object(value));
225 case PROP_PDF_DIRNAME:
228 case PROP_LAST_POSTED:
231 case PROP_PAYMENT_LAST_ACCT:
235 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
246 g_return_val_if_fail(inst != NULL, FALSE);
247 g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE);
249 emp = GNC_EMPLOYEE(inst);
251 if (GNC_IS_COMMODITY(ref))
253 return (emp->currency == GNC_COMMODITY(ref));
255 else if (GNC_IS_ACCOUNT(ref))
257 return (emp->ccard_acc == GNC_ACCOUNT(ref));
272 if (!GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref))
281 gnc_employee_class_init (GncEmployeeClass *klass)
283 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
284 QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
286 gobject_class->dispose = gnc_employee_dispose;
287 gobject_class->finalize = gnc_employee_finalize;
288 gobject_class->set_property = gnc_employee_set_property;
289 gobject_class->get_property = gnc_employee_get_property;
291 qof_class->get_display_name = NULL;
292 qof_class->refers_to_object = impl_refers_to_object;
293 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
295 g_object_class_install_property
298 g_param_spec_string (
"username",
300 "The employee name is an arbitrary string " 301 "assigned by the user which provides the employee " 306 g_object_class_install_property
309 g_param_spec_string (
"id",
311 "The employee ID is an arbitrary string " 312 "assigned by the user which provides the employee " 317 g_object_class_install_property
320 g_param_spec_boolean (
"active",
322 "TRUE if the employee is active. FALSE if inactive.",
326 g_object_class_install_property
329 g_param_spec_string (
"language",
331 "The language is an arbitrary string " 332 "assigned by the user which provides the language spoken " 337 g_object_class_install_property
340 g_param_spec_object (
"currency",
342 "The currency property denotes the currency used by this employee.",
346 g_object_class_install_property
349 g_param_spec_string (
"acl",
351 "The acl is an arbitrary string " 352 "assigned by the user which provides ??? " 353 " for the employee.",
357 g_object_class_install_property
360 g_param_spec_object (
"address",
362 "The address property contains the address information for this employee.",
366 g_object_class_install_property
369 g_param_spec_boxed(
"workday",
371 "The daily rate for this employee.",
375 g_object_class_install_property
378 g_param_spec_boxed(
"rate",
380 "The hourly rate for this employee.",
384 g_object_class_install_property
387 g_param_spec_object (
"credit-card-account",
388 "Credit card account",
389 "The credit card account for this employee.",
393 g_object_class_install_property
396 g_param_spec_string (
"export-pdf-dir",
397 "Export PDF Directory Name",
398 "A subdirectory for exporting PDF reports which is " 399 "appended to the target directory when writing them " 400 "out. It is retrieved from preferences and stored on " 401 "each 'Owner' object which prints items after " 406 g_object_class_install_property(
409 g_param_spec_boxed(
"invoice-last-posted-account",
410 "Invoice Last Posted Account",
411 "The last account to which an invoice belonging to " 412 "this owner was posted.",
416 g_object_class_install_property(
418 PROP_PAYMENT_LAST_ACCT,
419 g_param_spec_boxed(
"payment-last-account",
420 "Payment Last Account",
421 "The last account to which an payment belonging to " 422 "this owner was posted.",
428 GncEmployee *gncEmployeeCreate (QofBook *book)
430 GncEmployee *employee;
432 if (!book)
return NULL;
434 employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
437 employee->id = CACHE_INSERT (
"");
438 employee->username = CACHE_INSERT (
"");
439 employee->language = CACHE_INSERT (
"");
440 employee->acl = CACHE_INSERT (
"");
441 employee->addr = gncAddressCreate (book, &employee->inst);
442 employee->workday = gnc_numeric_zero();
443 employee->rate = gnc_numeric_zero();
444 employee->active = TRUE;
445 employee->balance = NULL;
447 if (empl_qof_event_handler_id == 0)
455 void gncEmployeeDestroy (GncEmployee *employee)
457 if (!employee)
return;
458 qof_instance_set_destroying(employee, TRUE);
459 gncEmployeeCommitEdit(employee);
462 static void gncEmployeeFree (GncEmployee *employee)
464 if (!employee)
return;
468 CACHE_REMOVE (employee->id);
469 CACHE_REMOVE (employee->username);
470 CACHE_REMOVE (employee->language);
471 CACHE_REMOVE (employee->acl);
472 gncAddressBeginEdit (employee->addr);
473 gncAddressDestroy (employee->addr);
474 g_free (employee->balance);
477 g_object_unref (employee);
483 #define SET_STR(obj, member, str) { \ 484 if (!g_strcmp0 (member, str)) return; \ 485 gncEmployeeBeginEdit (obj); \ 486 CACHE_REPLACE (member, str); \ 489 void gncEmployeeSetID (GncEmployee *employee,
const char *
id)
491 if (!employee)
return;
493 SET_STR(employee, employee->id,
id);
494 mark_employee (employee);
495 gncEmployeeCommitEdit (employee);
498 void gncEmployeeSetUsername (GncEmployee *employee,
const char *username)
500 if (!employee)
return;
501 if (!username)
return;
502 SET_STR(employee, employee->username, username);
503 mark_employee (employee);
504 gncEmployeeCommitEdit (employee);
512 void gncEmployeeSetName (GncEmployee *employee,
const char *name)
514 if (!employee)
return;
516 gncAddressSetName (gncEmployeeGetAddr (employee), name);
519 void gncEmployeeSetLanguage (GncEmployee *employee,
const char *language)
521 if (!employee)
return;
522 if (!language)
return;
523 SET_STR(employee, employee->language, language);
524 mark_employee (employee);
525 gncEmployeeCommitEdit (employee);
528 void gncEmployeeSetAcl (GncEmployee *employee,
const char *acl)
530 if (!employee)
return;
532 SET_STR(employee, employee->acl, acl);
533 mark_employee (employee);
534 gncEmployeeCommitEdit (employee);
537 void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday)
539 if (!employee)
return;
541 gncEmployeeBeginEdit (employee);
542 employee->workday = workday;
543 mark_employee (employee);
544 gncEmployeeCommitEdit (employee);
547 void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate)
549 if (!employee)
return;
551 gncEmployeeBeginEdit (employee);
552 employee->rate = rate;
553 mark_employee (employee);
554 gncEmployeeCommitEdit (employee);
557 void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity *currency)
559 if (!employee || !currency)
return;
560 if (employee->currency &&
563 gncEmployeeBeginEdit (employee);
564 employee->currency = currency;
565 mark_employee (employee);
566 gncEmployeeCommitEdit (employee);
569 void gncEmployeeSetActive (GncEmployee *employee, gboolean active)
571 if (!employee)
return;
572 if (active == employee->active)
return;
573 gncEmployeeBeginEdit (employee);
574 employee->active = active;
575 mark_employee (employee);
576 gncEmployeeCommitEdit (employee);
579 void gncEmployeeSetCCard (GncEmployee *employee,
Account* ccard_acc)
581 if (!employee)
return;
582 if (ccard_acc == employee->ccard_acc)
return;
583 gncEmployeeBeginEdit (employee);
584 employee->ccard_acc = ccard_acc;
585 mark_employee (employee);
586 gncEmployeeCommitEdit (employee);
590 qofEmployeeSetAddr (GncEmployee *employee,
QofInstance *addr_ent)
594 if (!employee || !addr_ent)
599 if (addr == employee->addr)
603 if (employee->addr != NULL)
605 gncAddressBeginEdit(employee->addr);
606 gncAddressDestroy(employee->addr);
608 gncEmployeeBeginEdit(employee);
609 employee->addr = addr;
610 mark_employee (employee);
611 gncEmployeeCommitEdit(employee);
616 const char * gncEmployeeGetID (
const GncEmployee *employee)
618 if (!employee)
return NULL;
622 const char * gncEmployeeGetUsername (
const GncEmployee *employee)
624 if (!employee)
return NULL;
625 return employee->username;
633 const char * gncEmployeeGetName (
const GncEmployee *employee)
635 if (!employee)
return NULL;
636 return gncAddressGetName ( gncEmployeeGetAddr (employee));
639 GncAddress * gncEmployeeGetAddr (
const GncEmployee *employee)
641 if (!employee)
return NULL;
642 return employee->addr;
645 const char * gncEmployeeGetLanguage (
const GncEmployee *employee)
647 if (!employee)
return NULL;
648 return employee->language;
651 const char * gncEmployeeGetAcl (
const GncEmployee *employee)
653 if (!employee)
return NULL;
654 return employee->acl;
657 gnc_numeric gncEmployeeGetWorkday (
const GncEmployee *employee)
659 if (!employee)
return gnc_numeric_zero();
660 return employee->workday;
663 gnc_numeric gncEmployeeGetRate (
const GncEmployee *employee)
665 if (!employee)
return gnc_numeric_zero();
666 return employee->rate;
669 gnc_commodity * gncEmployeeGetCurrency (
const GncEmployee *employee)
671 if (!employee)
return NULL;
672 return employee->currency;
675 gboolean gncEmployeeGetActive (
const GncEmployee *employee)
677 if (!employee)
return FALSE;
678 return employee->active;
681 Account * gncEmployeeGetCCard (
const GncEmployee *employee)
683 if (!employee)
return NULL;
684 return employee->ccard_acc;
687 gboolean gncEmployeeIsDirty (
const GncEmployee *employee)
689 if (!employee)
return FALSE;
691 || gncAddressIsDirty (employee->addr));
694 void gncEmployeeBeginEdit (GncEmployee *employee)
701 PERR(
"Employee QofBackend Failure: %d", errcode);
702 gnc_engine_signal_commit_error( errcode );
707 GncEmployee *employee = (GncEmployee *) inst;
708 gncAddressClearDirty (employee->addr);
713 GncEmployee *employee = (GncEmployee *) inst;
714 gncEmployeeFree (employee);
718 void gncEmployeeCommitEdit (GncEmployee *employee)
722 gncEmployeeOnDone, emp_free);
728 int gncEmployeeCompare (
const GncEmployee *a,
const GncEmployee *b)
730 if (!a && !b)
return 0;
731 if (!a && b)
return 1;
732 if (a && !b)
return -1;
734 return(strcmp(a->username, b->username));
739 if (a == NULL && b == NULL)
return TRUE;
740 if (a == NULL || b == NULL )
return FALSE;
742 g_return_val_if_fail(GNC_IS_EMPLOYEE(a), FALSE);
743 g_return_val_if_fail(GNC_IS_EMPLOYEE(b), FALSE);
745 if (g_strcmp0(a->id, b->id) != 0)
747 PWARN(
"IDs differ: %s vs %s", a->id, b->id);
751 if (g_strcmp0(a->username, b->username) != 0)
753 PWARN(
"Usernames differ: %s vs %s", a->username, b->username);
759 PWARN(
"Addresses differ");
765 PWARN(
"Currencies differ");
769 if (a->active != b->active)
771 PWARN(
"Active flags differ");
775 if (g_strcmp0(a->language, b->language) != 0)
777 PWARN(
"Languages differ: %s vs %s", a->language, b->language);
781 if (g_strcmp0(a->acl, b->acl) != 0)
783 PWARN(
"ACLs differ: %s vs %s", a->acl, b->acl);
789 PWARN(
"Accounts differ");
795 PWARN(
"Workdays differ");
801 PWARN(
"Rates differ");
810 static const char * _gncEmployeePrintable (gpointer item)
812 GncEmployee *v = item;
813 if (!item)
return NULL;
814 return gncAddressGetName(v->addr);
831 gpointer user_data, gpointer event_data)
835 if ((GNC_IS_ADDRESS (entity) &&
836 (event_type & QOF_EVENT_MODIFY) != 0))
838 if (GNC_IS_EMPLOYEE (event_data))
840 GncEmployee* empl = GNC_EMPLOYEE (event_data);
841 gncEmployeeBeginEdit (empl);
842 mark_employee (empl);
843 gncEmployeeCommitEdit (empl);
849 if (GNC_IS_LOT (entity))
851 GNCLot *lot = GNC_LOT (entity);
868 g_free (empl->balance);
869 empl->balance = NULL;
876 destroy_employee_on_book_close(
QofInstance *ent, gpointer data)
878 GncEmployee* e = GNC_EMPLOYEE(ent);
880 gncEmployeeBeginEdit(e);
881 gncEmployeeDestroy(e);
889 gnc_employee_book_end(QofBook* book)
894 qof_collection_foreach(col, destroy_employee_on_book_close, NULL);
897 static QofObject gncEmployeeDesc =
900 DI(.e_type = ) _GNC_MOD_NAME,
901 DI(.type_label = ) "Employee",
902 DI(.create = ) (gpointer)gncEmployeeCreate,
903 DI(.book_begin = ) NULL,
904 DI(.book_end = ) gnc_employee_book_end,
907 DI(.foreach = ) qof_collection_foreach,
908 DI(.printable = ) _gncEmployeePrintable,
912 gboolean gncEmployeeRegister (
void)
914 static QofParam params[] =
918 EMPLOYEE_USERNAME, QOF_TYPE_STRING, (
QofAccessFunc)gncEmployeeGetUsername,
922 EMPLOYEE_NAME, QOF_TYPE_STRING, (
QofAccessFunc)gncEmployeeGetName,
926 EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (
QofAccessFunc)gncEmployeeGetLanguage,
931 EMPLOYEE_WORKDAY, QOF_TYPE_NUMERIC, (
QofAccessFunc)gncEmployeeGetWorkday,
948 gchar *gncEmployeeNextID (QofBook *book)
954 gncEmployeeGetCachedBalance (GncEmployee *empl)
956 return empl->balance;
959 void gncEmployeeSetCachedBalance (GncEmployee *empl,
const gnc_numeric *new_bal)
965 g_free (empl->balance);
966 empl->balance = NULL;
972 empl->balance = g_new0 (gnc_numeric, 1);
974 *empl->balance = *new_bal;
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
Business Interface: Object OWNERs.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
gchar * qof_book_increment_and_format_counter(QofBook *book, const char *counter_name)
This will increment the named counter for this book and format it.
GList * qof_instance_get_referring_object_list_from_collection(const QofCollection *coll, const QofInstance *ref)
Returns a list of objects from the collection which refer to the specific object. ...
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
QofCollection * qof_instance_get_collection(gconstpointer ptr)
Return the collection this instance belongs to.
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
#define PERR(format, args...)
Log a serious error.
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
gint qof_event_register_handler(QofEventHandler handler, gpointer user_data)
Register a handler for events.
#define PWARN(format, args...)
Log a warning.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
Account handling public routines.
gint QofEventId
Define the type of events allowed.
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object has been modified.
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gboolean gncOwnerGetOwnerFromLot(GNCLot *lot, GncOwner *owner)
Get the owner from the lot.
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
gboolean xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
Compare two accounts for equality - this is a deep compare.
gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b)
Deeply compare two addresses.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object...
Commodity handling public routines.
gboolean gncEmployeeEqual(const GncEmployee *a, const GncEmployee *b)
Test support function, used by test-dbi-business-stuff.c.