|
GnuCash 2.4.99
|
00001 /********************************************************************\ 00002 * gncEmployee.c -- the Core Employee Interface * 00003 * * 00004 * This program is free software; you can redistribute it and/or * 00005 * modify it under the terms of the GNU General Public License as * 00006 * published by the Free Software Foundation; either version 2 of * 00007 * the License, or (at your option) any later version. * 00008 * * 00009 * This program is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00012 * GNU General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU General Public License* 00015 * along with this program; if not, contact: * 00016 * * 00017 * Free Software Foundation Voice: +1-617-542-5942 * 00018 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00019 * Boston, MA 02110-1301, USA gnu@gnu.org * 00020 * * 00021 \********************************************************************/ 00022 00023 /* 00024 * Copyright (C) 2001,2002 Derek Atkins 00025 * Copyright (C) 2003 Linas Vepstas <linas@linas.org> 00026 * Author: Derek Atkins <warlord@MIT.EDU> 00027 */ 00028 00029 #include "config.h" 00030 00031 #include <glib.h> 00032 #include <string.h> 00033 00034 #include "Account.h" 00035 #include "gnc-commodity.h" 00036 #include "gncAddressP.h" 00037 #include "gncEmployee.h" 00038 #include "gncEmployeeP.h" 00039 00040 static gint gs_address_event_handler_id = 0; 00041 static void listen_for_address_events(QofInstance *entity, QofEventId event_type, 00042 gpointer user_data, gpointer event_data); 00043 00044 struct _gncEmployee 00045 { 00046 QofInstance inst; 00047 char * id; 00048 char * username; 00049 GncAddress * addr; 00050 gnc_commodity * currency; 00051 gboolean active; 00052 00053 char * language; 00054 char * acl; 00055 gnc_numeric workday; 00056 gnc_numeric rate; 00057 00058 Account * ccard_acc; 00059 }; 00060 00061 struct _gncEmployeeClass 00062 { 00063 QofInstanceClass parent_class; 00064 }; 00065 00066 static QofLogModule log_module = GNC_MOD_BUSINESS; 00067 00068 #define _GNC_MOD_NAME GNC_ID_EMPLOYEE 00069 00070 G_INLINE_FUNC void mark_employee (GncEmployee *employee); 00071 void mark_employee (GncEmployee *employee) 00072 { 00073 qof_instance_set_dirty(&employee->inst); 00074 qof_event_gen (&employee->inst, QOF_EVENT_MODIFY, NULL); 00075 } 00076 00077 /* ============================================================== */ 00078 00079 enum 00080 { 00081 PROP_0, 00082 PROP_USERNAME, 00083 PROP_ID, 00084 PROP_ACTIVE, 00085 PROP_LANGUAGE, 00086 PROP_CURRENCY, 00087 PROP_ACL, 00088 PROP_ADDRESS, 00089 PROP_WORKDAY, 00090 PROP_RATE, 00091 PROP_CCARD 00092 }; 00093 00094 /* GObject Initialization */ 00095 G_DEFINE_TYPE(GncEmployee, gnc_employee, QOF_TYPE_INSTANCE); 00096 00097 static void 00098 gnc_employee_init(GncEmployee* emp) 00099 { 00100 } 00101 00102 static void 00103 gnc_employee_dispose(GObject *empp) 00104 { 00105 G_OBJECT_CLASS(gnc_employee_parent_class)->dispose(empp); 00106 } 00107 00108 static void 00109 gnc_employee_finalize(GObject* empp) 00110 { 00111 G_OBJECT_CLASS(gnc_employee_parent_class)->finalize(empp); 00112 } 00113 00114 static void 00115 gnc_employee_get_property (GObject *object, 00116 guint prop_id, 00117 GValue *value, 00118 GParamSpec *pspec) 00119 { 00120 GncEmployee *emp; 00121 00122 g_return_if_fail(GNC_IS_EMPLOYEE(object)); 00123 00124 emp = GNC_EMPLOYEE(object); 00125 switch (prop_id) 00126 { 00127 case PROP_USERNAME: 00128 g_value_set_string(value, emp->username); 00129 break; 00130 case PROP_ID: 00131 g_value_set_string(value, emp->id); 00132 break; 00133 case PROP_ACTIVE: 00134 g_value_set_boolean(value, emp->active); 00135 break; 00136 case PROP_LANGUAGE: 00137 g_value_set_string(value, emp->language); 00138 break; 00139 case PROP_CURRENCY: 00140 g_value_set_object(value, emp->currency); 00141 break; 00142 case PROP_ACL: 00143 g_value_set_string(value, emp->acl); 00144 break; 00145 case PROP_ADDRESS: 00146 g_value_set_object(value, emp->addr); 00147 break; 00148 case PROP_WORKDAY: 00149 g_value_set_boxed(value, &emp->workday); 00150 break; 00151 case PROP_RATE: 00152 g_value_set_boxed(value, &emp->rate); 00153 break; 00154 case PROP_CCARD: 00155 g_value_set_object(value, emp->ccard_acc); 00156 break; 00157 default: 00158 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); 00159 break; 00160 } 00161 } 00162 00163 static void 00164 gnc_employee_set_property (GObject *object, 00165 guint prop_id, 00166 const GValue *value, 00167 GParamSpec *pspec) 00168 { 00169 GncEmployee *emp; 00170 00171 g_return_if_fail(GNC_IS_EMPLOYEE(object)); 00172 00173 emp = GNC_EMPLOYEE(object); 00174 switch (prop_id) 00175 { 00176 case PROP_USERNAME: 00177 gncEmployeeSetUsername(emp, g_value_get_string(value)); 00178 break; 00179 case PROP_ID: 00180 gncEmployeeSetID(emp, g_value_get_string(value)); 00181 break; 00182 case PROP_ACTIVE: 00183 gncEmployeeSetActive(emp, g_value_get_boolean(value)); 00184 break; 00185 case PROP_LANGUAGE: 00186 gncEmployeeSetLanguage(emp, g_value_get_string(value)); 00187 break; 00188 case PROP_CURRENCY: 00189 gncEmployeeSetCurrency(emp, g_value_get_object(value)); 00190 break; 00191 case PROP_ACL: 00192 gncEmployeeSetAcl(emp, g_value_get_string(value)); 00193 break; 00194 case PROP_ADDRESS: 00195 qofEmployeeSetAddr(emp, g_value_get_object(value)); 00196 break; 00197 case PROP_WORKDAY: 00198 gncEmployeeSetWorkday(emp, *(gnc_numeric*)g_value_get_boxed(value)); 00199 break; 00200 case PROP_RATE: 00201 gncEmployeeSetRate(emp, *(gnc_numeric*)g_value_get_boxed(value)); 00202 break; 00203 case PROP_CCARD: 00204 gncEmployeeSetCCard(emp, g_value_get_object(value)); 00205 break; 00206 default: 00207 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); 00208 break; 00209 } 00210 } 00211 00213 static gboolean 00214 impl_refers_to_object(const QofInstance* inst, const QofInstance* ref) 00215 { 00216 GncEmployee* emp; 00217 00218 g_return_val_if_fail(inst != NULL, FALSE); 00219 g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE); 00220 00221 emp = GNC_EMPLOYEE(inst); 00222 00223 if (GNC_IS_COMMODITY(ref)) 00224 { 00225 return (emp->currency == GNC_COMMODITY(ref)); 00226 } 00227 else if (GNC_IS_ACCOUNT(ref)) 00228 { 00229 return (emp->ccard_acc == GNC_ACCOUNT(ref)); 00230 } 00231 00232 return FALSE; 00233 } 00234 00241 static GList* 00242 impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref) 00243 { 00244 if (!GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref)) 00245 { 00246 return NULL; 00247 } 00248 00249 return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref); 00250 } 00251 00252 static void 00253 gnc_employee_class_init (GncEmployeeClass *klass) 00254 { 00255 GObjectClass *gobject_class = G_OBJECT_CLASS (klass); 00256 QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass); 00257 00258 gobject_class->dispose = gnc_employee_dispose; 00259 gobject_class->finalize = gnc_employee_finalize; 00260 gobject_class->set_property = gnc_employee_set_property; 00261 gobject_class->get_property = gnc_employee_get_property; 00262 00263 qof_class->get_display_name = NULL; 00264 qof_class->refers_to_object = impl_refers_to_object; 00265 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list; 00266 00267 g_object_class_install_property 00268 (gobject_class, 00269 PROP_USERNAME, 00270 g_param_spec_string ("username", 00271 "Employee Name", 00272 "The employee name is an arbitrary string " 00273 "assigned by the user which provides the employee " 00274 "name.", 00275 NULL, 00276 G_PARAM_READWRITE)); 00277 00278 g_object_class_install_property 00279 (gobject_class, 00280 PROP_ID, 00281 g_param_spec_string ("id", 00282 "Employee ID", 00283 "The employee ID is an arbitrary string " 00284 "assigned by the user which provides the employee " 00285 "ID.", 00286 NULL, 00287 G_PARAM_READWRITE)); 00288 00289 g_object_class_install_property 00290 (gobject_class, 00291 PROP_ACTIVE, 00292 g_param_spec_boolean ("active", 00293 "Active", 00294 "TRUE if the employee is active. FALSE if inactive.", 00295 FALSE, 00296 G_PARAM_READWRITE)); 00297 00298 g_object_class_install_property 00299 (gobject_class, 00300 PROP_LANGUAGE, 00301 g_param_spec_string ("language", 00302 "Employee Language", 00303 "The language is an arbitrary string " 00304 "assigned by the user which provides the language spoken " 00305 " by the employee.", 00306 NULL, 00307 G_PARAM_READWRITE)); 00308 00309 g_object_class_install_property 00310 (gobject_class, 00311 PROP_CURRENCY, 00312 g_param_spec_object ("currency", 00313 "Currency", 00314 "The currency property denotes the currency used by this employee.", 00315 GNC_TYPE_COMMODITY, 00316 G_PARAM_READWRITE)); 00317 00318 g_object_class_install_property 00319 (gobject_class, 00320 PROP_ACL, 00321 g_param_spec_string ("acl", 00322 "Employee ACL", 00323 "The acl is an arbitrary string " 00324 "assigned by the user which provides ??? " 00325 " for the employee.", 00326 NULL, 00327 G_PARAM_READWRITE)); 00328 00329 g_object_class_install_property 00330 (gobject_class, 00331 PROP_ADDRESS, 00332 g_param_spec_object ("address", 00333 "Address", 00334 "The address property contains the address information for this employee.", 00335 GNC_TYPE_ADDRESS, 00336 G_PARAM_READWRITE)); 00337 00338 g_object_class_install_property 00339 (gobject_class, 00340 PROP_WORKDAY, 00341 g_param_spec_boxed("workday", 00342 "Workday rate", 00343 "The daily rate for this employee.", 00344 GNC_TYPE_NUMERIC, 00345 G_PARAM_READWRITE)); 00346 00347 g_object_class_install_property 00348 (gobject_class, 00349 PROP_RATE, 00350 g_param_spec_boxed("rate", 00351 "Hourly rate", 00352 "The hourly rate for this employee.", 00353 GNC_TYPE_NUMERIC, 00354 G_PARAM_READWRITE)); 00355 00356 g_object_class_install_property 00357 (gobject_class, 00358 PROP_CCARD, 00359 g_param_spec_object ("credit-card-account", 00360 "Credit card account", 00361 "The credit card account for this employee.", 00362 GNC_TYPE_ACCOUNT, 00363 G_PARAM_READWRITE)); 00364 } 00365 00366 /* Create/Destroy Functions */ 00367 GncEmployee *gncEmployeeCreate (QofBook *book) 00368 { 00369 GncEmployee *employee; 00370 00371 if (!book) return NULL; 00372 00373 employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL); 00374 qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book); 00375 00376 employee->id = CACHE_INSERT (""); 00377 employee->username = CACHE_INSERT (""); 00378 employee->language = CACHE_INSERT (""); 00379 employee->acl = CACHE_INSERT (""); 00380 employee->addr = gncAddressCreate (book, &employee->inst); 00381 employee->workday = gnc_numeric_zero(); 00382 employee->rate = gnc_numeric_zero(); 00383 employee->active = TRUE; 00384 00385 if (gs_address_event_handler_id == 0) 00386 { 00387 gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL); 00388 } 00389 00390 qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL); 00391 00392 return employee; 00393 } 00394 00395 void gncEmployeeDestroy (GncEmployee *employee) 00396 { 00397 if (!employee) return; 00398 qof_instance_set_destroying(employee, TRUE); 00399 gncEmployeeCommitEdit(employee); 00400 } 00401 00402 static void gncEmployeeFree (GncEmployee *employee) 00403 { 00404 if (!employee) return; 00405 00406 qof_event_gen (&employee->inst, QOF_EVENT_DESTROY, NULL); 00407 00408 CACHE_REMOVE (employee->id); 00409 CACHE_REMOVE (employee->username); 00410 CACHE_REMOVE (employee->language); 00411 CACHE_REMOVE (employee->acl); 00412 gncAddressBeginEdit (employee->addr); 00413 gncAddressDestroy (employee->addr); 00414 00415 /* qof_instance_release (&employee->inst); */ 00416 g_object_unref (employee); 00417 } 00418 00419 /* ============================================================== */ 00420 /* Set Functions */ 00421 00422 #define SET_STR(obj, member, str) { \ 00423 char * tmp; \ 00424 \ 00425 if (!safe_strcmp (member, str)) return; \ 00426 gncEmployeeBeginEdit (obj); \ 00427 tmp = CACHE_INSERT (str); \ 00428 CACHE_REMOVE (member); \ 00429 member = tmp; \ 00430 } 00431 00432 void gncEmployeeSetID (GncEmployee *employee, const char *id) 00433 { 00434 if (!employee) return; 00435 if (!id) return; 00436 SET_STR(employee, employee->id, id); 00437 mark_employee (employee); 00438 gncEmployeeCommitEdit (employee); 00439 } 00440 00441 void gncEmployeeSetUsername (GncEmployee *employee, const char *username) 00442 { 00443 if (!employee) return; 00444 if (!username) return; 00445 SET_STR(employee, employee->username, username); 00446 mark_employee (employee); 00447 gncEmployeeCommitEdit (employee); 00448 } 00449 00450 /* Employees don't have a name property defined, but 00451 * in order to get a consistent interface with other owner types, 00452 * this function fakes one by setting the name property of 00453 * the employee's address. 00454 */ 00455 void gncEmployeeSetName (GncEmployee *employee, const char *name) 00456 { 00457 if (!employee) return; 00458 if (!name) return; 00459 gncAddressSetName (gncEmployeeGetAddr (employee), name); 00460 } 00461 00462 void gncEmployeeSetLanguage (GncEmployee *employee, const char *language) 00463 { 00464 if (!employee) return; 00465 if (!language) return; 00466 SET_STR(employee, employee->language, language); 00467 mark_employee (employee); 00468 gncEmployeeCommitEdit (employee); 00469 } 00470 00471 void gncEmployeeSetAcl (GncEmployee *employee, const char *acl) 00472 { 00473 if (!employee) return; 00474 if (!acl) return; 00475 SET_STR(employee, employee->acl, acl); 00476 mark_employee (employee); 00477 gncEmployeeCommitEdit (employee); 00478 } 00479 00480 void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday) 00481 { 00482 if (!employee) return; 00483 if (gnc_numeric_equal (workday, employee->workday)) return; 00484 gncEmployeeBeginEdit (employee); 00485 employee->workday = workday; 00486 mark_employee (employee); 00487 gncEmployeeCommitEdit (employee); 00488 } 00489 00490 void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate) 00491 { 00492 if (!employee) return; 00493 if (gnc_numeric_equal (rate, employee->rate)) return; 00494 gncEmployeeBeginEdit (employee); 00495 employee->rate = rate; 00496 mark_employee (employee); 00497 gncEmployeeCommitEdit (employee); 00498 } 00499 00500 void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity *currency) 00501 { 00502 if (!employee || !currency) return; 00503 if (employee->currency && 00504 gnc_commodity_equal (employee->currency, currency)) 00505 return; 00506 gncEmployeeBeginEdit (employee); 00507 employee->currency = currency; 00508 mark_employee (employee); 00509 gncEmployeeCommitEdit (employee); 00510 } 00511 00512 void gncEmployeeSetActive (GncEmployee *employee, gboolean active) 00513 { 00514 if (!employee) return; 00515 if (active == employee->active) return; 00516 gncEmployeeBeginEdit (employee); 00517 employee->active = active; 00518 mark_employee (employee); 00519 gncEmployeeCommitEdit (employee); 00520 } 00521 00522 void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc) 00523 { 00524 if (!employee) return; 00525 if (ccard_acc == employee->ccard_acc) return; 00526 gncEmployeeBeginEdit (employee); 00527 employee->ccard_acc = ccard_acc; 00528 mark_employee (employee); 00529 gncEmployeeCommitEdit (employee); 00530 } 00531 00532 void 00533 qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent) 00534 { 00535 GncAddress *addr; 00536 00537 if (!employee || !addr_ent) 00538 { 00539 return; 00540 } 00541 addr = (GncAddress*)addr_ent; 00542 if (addr == employee->addr) 00543 { 00544 return; 00545 } 00546 if (employee->addr != NULL) 00547 { 00548 gncAddressBeginEdit(employee->addr); 00549 gncAddressDestroy(employee->addr); 00550 } 00551 gncEmployeeBeginEdit(employee); 00552 employee->addr = addr; 00553 gncEmployeeCommitEdit(employee); 00554 } 00555 00556 /* ============================================================== */ 00557 /* Get Functions */ 00558 const char * gncEmployeeGetID (const GncEmployee *employee) 00559 { 00560 if (!employee) return NULL; 00561 return employee->id; 00562 } 00563 00564 const char * gncEmployeeGetUsername (const GncEmployee *employee) 00565 { 00566 if (!employee) return NULL; 00567 return employee->username; 00568 } 00569 00570 /* Employees don't have a name property defined, but 00571 * in order to get a consistent interface with other owner types, 00572 * this function fakes one by returning the name property of 00573 * the employee's address. 00574 */ 00575 const char * gncEmployeeGetName (const GncEmployee *employee) 00576 { 00577 if (!employee) return NULL; 00578 return gncAddressGetName ( gncEmployeeGetAddr (employee)); 00579 } 00580 00581 GncAddress * gncEmployeeGetAddr (const GncEmployee *employee) 00582 { 00583 if (!employee) return NULL; 00584 return employee->addr; 00585 } 00586 00587 const char * gncEmployeeGetLanguage (const GncEmployee *employee) 00588 { 00589 if (!employee) return NULL; 00590 return employee->language; 00591 } 00592 00593 const char * gncEmployeeGetAcl (const GncEmployee *employee) 00594 { 00595 if (!employee) return NULL; 00596 return employee->acl; 00597 } 00598 00599 gnc_numeric gncEmployeeGetWorkday (const GncEmployee *employee) 00600 { 00601 if (!employee) return gnc_numeric_zero(); 00602 return employee->workday; 00603 } 00604 00605 gnc_numeric gncEmployeeGetRate (const GncEmployee *employee) 00606 { 00607 if (!employee) return gnc_numeric_zero(); 00608 return employee->rate; 00609 } 00610 00611 gnc_commodity * gncEmployeeGetCurrency (const GncEmployee *employee) 00612 { 00613 if (!employee) return NULL; 00614 return employee->currency; 00615 } 00616 00617 gboolean gncEmployeeGetActive (const GncEmployee *employee) 00618 { 00619 if (!employee) return FALSE; 00620 return employee->active; 00621 } 00622 00623 Account * gncEmployeeGetCCard (const GncEmployee *employee) 00624 { 00625 if (!employee) return NULL; 00626 return employee->ccard_acc; 00627 } 00628 00629 gboolean gncEmployeeIsDirty (const GncEmployee *employee) 00630 { 00631 if (!employee) return FALSE; 00632 return (qof_instance_get_dirty_flag(employee) 00633 || gncAddressIsDirty (employee->addr)); 00634 } 00635 00636 void gncEmployeeBeginEdit (GncEmployee *employee) 00637 { 00638 qof_begin_edit(&employee->inst); 00639 } 00640 00641 static void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode) 00642 { 00643 PERR("Employee QofBackend Failure: %d", errcode); 00644 gnc_engine_signal_commit_error( errcode ); 00645 } 00646 00647 static void gncEmployeeOnDone (QofInstance *inst) 00648 { 00649 GncEmployee *employee = (GncEmployee *) inst; 00650 gncAddressClearDirty (employee->addr); 00651 } 00652 00653 static void emp_free (QofInstance *inst) 00654 { 00655 GncEmployee *employee = (GncEmployee *) inst; 00656 gncEmployeeFree (employee); 00657 } 00658 00659 00660 void gncEmployeeCommitEdit (GncEmployee *employee) 00661 { 00662 if (!qof_commit_edit (QOF_INSTANCE(employee))) return; 00663 qof_commit_edit_part2 (&employee->inst, gncEmployeeOnError, 00664 gncEmployeeOnDone, emp_free); 00665 } 00666 00667 /* ============================================================== */ 00668 /* Other functions */ 00669 00670 int gncEmployeeCompare (const GncEmployee *a, const GncEmployee *b) 00671 { 00672 if (!a && !b) return 0; 00673 if (!a && b) return 1; 00674 if (a && !b) return -1; 00675 00676 return(strcmp(a->username, b->username)); 00677 } 00678 00679 gboolean gncEmployeeEqual(const GncEmployee* a, const GncEmployee* b) 00680 { 00681 if (a == NULL && b == NULL) return TRUE; 00682 if (a == NULL || b == NULL ) return FALSE; 00683 00684 g_return_val_if_fail(GNC_IS_EMPLOYEE(a), FALSE); 00685 g_return_val_if_fail(GNC_IS_EMPLOYEE(b), FALSE); 00686 00687 if (safe_strcmp(a->id, b->id) != 0) 00688 { 00689 PWARN("IDs differ: %s vs %s", a->id, b->id); 00690 return FALSE; 00691 } 00692 00693 if (safe_strcmp(a->username, b->username) != 0) 00694 { 00695 PWARN("Usernames differ: %s vs %s", a->username, b->username); 00696 return FALSE; 00697 } 00698 00699 if (!gncAddressEqual(a->addr, b->addr)) 00700 { 00701 PWARN("Addresses differ"); 00702 return FALSE; 00703 } 00704 00705 if (!gnc_commodity_equal(a->currency, b->currency)) 00706 { 00707 PWARN("Currencies differ"); 00708 return FALSE; 00709 } 00710 00711 if (a->active != b->active) 00712 { 00713 PWARN("Active flags differ"); 00714 return FALSE; 00715 } 00716 00717 if (safe_strcmp(a->language, b->language) != 0) 00718 { 00719 PWARN("Languages differ: %s vs %s", a->language, b->language); 00720 return FALSE; 00721 } 00722 00723 if (safe_strcmp(a->acl, b->acl) != 0) 00724 { 00725 PWARN("ACLs differ: %s vs %s", a->acl, b->acl); 00726 return FALSE; 00727 } 00728 00729 if (!xaccAccountEqual(a->ccard_acc, b->ccard_acc, TRUE)) 00730 { 00731 PWARN("Accounts differ"); 00732 return FALSE; 00733 } 00734 00735 if (!gnc_numeric_equal(a->workday, b->workday)) 00736 { 00737 PWARN("Workdays differ"); 00738 return FALSE; 00739 } 00740 00741 if (!gnc_numeric_equal(a->rate, b->rate)) 00742 { 00743 PWARN("Rates differ"); 00744 return FALSE; 00745 } 00746 00747 return TRUE; 00748 } 00749 00750 /* Package-Private functions */ 00751 00752 static const char * _gncEmployeePrintable (gpointer item) 00753 { 00754 GncEmployee *v = item; 00755 if (!item) return NULL; 00756 return gncAddressGetName(v->addr); 00757 } 00758 00768 static void 00769 listen_for_address_events(QofInstance *entity, QofEventId event_type, 00770 gpointer user_data, gpointer event_data) 00771 { 00772 GncEmployee* empl; 00773 00774 if ((event_type & QOF_EVENT_MODIFY) == 0) 00775 { 00776 return; 00777 } 00778 if (!GNC_IS_ADDRESS(entity)) 00779 { 00780 return; 00781 } 00782 if (!GNC_IS_EMPLOYEE(event_data)) 00783 { 00784 return; 00785 } 00786 empl = GNC_EMPLOYEE(event_data); 00787 gncEmployeeBeginEdit(empl); 00788 mark_employee(empl); 00789 gncEmployeeCommitEdit(empl); 00790 } 00791 00792 static void 00793 destroy_employee_on_book_close(QofInstance *ent, gpointer data) 00794 { 00795 GncEmployee* e = GNC_EMPLOYEE(ent); 00796 00797 gncEmployeeBeginEdit(e); 00798 gncEmployeeDestroy(e); 00799 } 00800 00805 static void 00806 gnc_employee_book_end(QofBook* book) 00807 { 00808 QofCollection *col; 00809 00810 col = qof_book_get_collection(book, GNC_ID_EMPLOYEE); 00811 qof_collection_foreach(col, destroy_employee_on_book_close, NULL); 00812 } 00813 00814 static QofObject gncEmployeeDesc = 00815 { 00816 DI(.interface_version = ) QOF_OBJECT_VERSION, 00817 DI(.e_type = ) _GNC_MOD_NAME, 00818 DI(.type_label = ) "Employee", 00819 DI(.create = ) (gpointer)gncEmployeeCreate, 00820 DI(.book_begin = ) NULL, 00821 DI(.book_end = ) gnc_employee_book_end, 00822 DI(.is_dirty = ) qof_collection_is_dirty, 00823 DI(.mark_clean = ) qof_collection_mark_clean, 00824 DI(.foreach = ) qof_collection_foreach, 00825 DI(.printable = ) _gncEmployeePrintable, 00826 DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp, 00827 }; 00828 00829 gboolean gncEmployeeRegister (void) 00830 { 00831 static QofParam params[] = 00832 { 00833 { EMPLOYEE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetID, (QofSetterFunc)gncEmployeeSetID }, 00834 { 00835 EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername, 00836 (QofSetterFunc)gncEmployeeSetUsername 00837 }, 00838 { 00839 EMPLOYEE_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetName, 00840 (QofSetterFunc)gncEmployeeSetName 00841 }, 00842 { 00843 EMPLOYEE_LANGUAGE, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetLanguage, 00844 (QofSetterFunc)gncEmployeeSetLanguage 00845 }, 00846 { EMPLOYEE_ACL, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetAcl, (QofSetterFunc)gncEmployeeSetAcl }, 00847 { 00848 EMPLOYEE_WORKDAY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetWorkday, 00849 (QofSetterFunc)gncEmployeeSetWorkday 00850 }, 00851 { EMPLOYEE_RATE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEmployeeGetRate, (QofSetterFunc)gncEmployeeSetRate }, 00852 { EMPLOYEE_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncEmployeeGetAddr, (QofSetterFunc)qofEmployeeSetAddr }, 00853 { EMPLOYEE_CC, GNC_ID_ACCOUNT, (QofAccessFunc)gncEmployeeGetCCard, (QofSetterFunc)gncEmployeeSetCCard }, 00854 { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive, (QofSetterFunc)gncEmployeeSetActive }, 00855 { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL }, 00856 { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL }, 00857 { NULL }, 00858 }; 00859 00860 qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare, params); 00861 00862 return qof_object_register (&gncEmployeeDesc); 00863 } 00864 00865 gchar *gncEmployeeNextID (QofBook *book) 00866 { 00867 return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME); 00868 }
1.7.4