static gboolean employee_guid_handler (xmlNodePtr node, gpointer employee_pdata) { struct employee_pdata *pdata = employee_pdata; GncGUID *guid; GncEmployee *employee; guid = dom_tree_to_guid(node); g_return_val_if_fail(guid, FALSE); /* See if we've already created this one */ employee = gncEmployeeLookup (pdata->book, guid); if (employee) { gncEmployeeDestroy (pdata->employee); pdata->employee = employee; gncEmployeeBeginEdit (employee); } else { gncEmployeeSetGUID(pdata->employee, guid); } g_free(guid); return TRUE; }
static void test_bool_fcn (QofBook *book, const char *message, void (*set) (GncEmployee *, gboolean), gboolean (*get) (const GncEmployee *)) { GncEmployee *employee = gncEmployeeCreate (book); gboolean num = get_random_boolean (); do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); gncEmployeeBeginEdit (employee); set (employee, FALSE); set (employee, TRUE); set (employee, num); /* Employee record should be dirty */ do_test (gncEmployeeIsDirty (employee), "test dirty later"); gncEmployeeCommitEdit (employee); /* Employee record should be not dirty */ /* Skip, because will always fail without a backend. * It's not possible to load a backend in the engine code * without having circular dependencies. */ // do_test (!gncEmployeeIsDirty (employee), "test dirty after commit"); do_test (get (employee) == num, message); gncEmployeeSetActive (employee, FALSE); count++; }
void gncOwnerBeginEdit (GncOwner *owner) { if (!owner) return; switch (owner->type) { case GNC_OWNER_NONE : case GNC_OWNER_UNDEFINED : break; case GNC_OWNER_CUSTOMER : { gncCustomerBeginEdit(owner->owner.customer); break; } case GNC_OWNER_JOB : { gncJobBeginEdit(owner->owner.job); break; } case GNC_OWNER_VENDOR : { gncVendorBeginEdit(owner->owner.vendor); break; } case GNC_OWNER_EMPLOYEE : { gncEmployeeBeginEdit(owner->owner.employee); break; } } }
static void destroy_employee_on_book_close(QofInstance *ent, gpointer data) { GncEmployee* e = GNC_EMPLOYEE(ent); gncEmployeeBeginEdit(e); gncEmployeeDestroy(e); }
static void gnc_ui_to_employee (EmployeeWindow *ew, GncEmployee *employee) { GncAddress *addr; addr = gncEmployeeGetAddr (employee); gnc_suspend_gui_refresh (); gncEmployeeBeginEdit (employee); if (ew->dialog_type == NEW_EMPLOYEE) qof_event_gen(QOF_INSTANCE(employee), QOF_EVENT_ADD, NULL); gncEmployeeSetID (employee, gtk_editable_get_chars (GTK_EDITABLE (ew->id_entry), 0, -1)); gncEmployeeSetUsername (employee, gtk_editable_get_chars (GTK_EDITABLE (ew->username_entry), 0, -1)); gncAddressSetName (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->name_entry), 0, -1)); gncAddressSetAddr1 (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->addr1_entry), 0, -1)); gncAddressSetAddr2 (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->addr2_entry), 0, -1)); gncAddressSetAddr3 (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->addr3_entry), 0, -1)); gncAddressSetAddr4 (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->addr4_entry), 0, -1)); gncAddressSetPhone (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->phone_entry), 0, -1)); gncAddressSetFax (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->fax_entry), 0, -1)); gncAddressSetEmail (addr, gtk_editable_get_chars (GTK_EDITABLE (ew->email_entry), 0, -1)); gncEmployeeSetActive (employee, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ew->active_check))); gncEmployeeSetLanguage (employee, gtk_editable_get_chars (GTK_EDITABLE (ew->language_entry), 0, -1)); /* Parse and set the workday and rate amounts */ gncEmployeeSetWorkday (employee, gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (ew->workday_amount))); gncEmployeeSetRate (employee, gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (ew->rate_amount))); gncEmployeeSetCurrency (employee, gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT (ew->currency_edit))); /* Fill in the CCard Acct */ gncEmployeeSetCCard (employee, (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ew->ccard_acct_check)) ? gnc_account_sel_get_account (GNC_ACCOUNT_SEL (ew->ccard_acct_sel)) : NULL)); gncEmployeeCommitEdit (employee); gnc_resume_gui_refresh (); }
void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc) { if (!employee) return; if (ccard_acc == employee->ccard_acc) return; gncEmployeeBeginEdit (employee); employee->ccard_acc = ccard_acc; mark_employee (employee); gncEmployeeCommitEdit (employee); }
void gncEmployeeSetActive (GncEmployee *employee, gboolean active) { if (!employee) return; if (active == employee->active) return; gncEmployeeBeginEdit (employee); employee->active = active; mark_employee (employee); gncEmployeeCommitEdit (employee); }
void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate) { if (!employee) return; if (gnc_numeric_equal (rate, employee->rate)) return; gncEmployeeBeginEdit (employee); employee->rate = rate; mark_employee (employee); gncEmployeeCommitEdit (employee); }
void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday) { if (!employee) return; if (gnc_numeric_equal (workday, employee->workday)) return; gncEmployeeBeginEdit (employee); employee->workday = workday; mark_employee (employee); gncEmployeeCommitEdit (employee); }
void gncEmployeeSetCurrency (GncEmployee *employee, gnc_commodity *currency) { if (!employee || !currency) return; if (employee->currency && gnc_commodity_equal (employee->currency, currency)) return; gncEmployeeBeginEdit (employee); employee->currency = currency; mark_employee (employee); gncEmployeeCommitEdit (employee); }
static void test_numeric_fcn (QofBook *book, const char *message, void (*set) (GncEmployee *, gnc_numeric), gnc_numeric (*get)(const GncEmployee *)) { GncEmployee *employee = gncEmployeeCreate (book); gnc_numeric num = gnc_numeric_create (17, 1); do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); gncEmployeeBeginEdit (employee); set (employee, num); do_test (gncEmployeeIsDirty (employee), "test dirty later"); gncEmployeeCommitEdit (employee); do_test (gncEmployeeIsDirty (employee), "test dirty after commit"); do_test (gnc_numeric_equal (get (employee), num), message); gncEmployeeSetActive (employee, FALSE); count++; }
static void test_string_fcn (QofBook *book, const char *message, void (*set) (GncEmployee *, const char *str), const char * (*get)(const GncEmployee *)) { GncEmployee *employee = gncEmployeeCreate (book); char const *str = get_random_string (); do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); gncEmployeeBeginEdit (employee); set (employee, str); do_test (gncEmployeeIsDirty (employee), "test dirty later"); gncEmployeeCommitEdit (employee); do_test (gncEmployeeIsDirty (employee), "test dirty after commit"); do_test (safe_strcmp (get (employee), str) == 0, message); gncEmployeeSetActive (employee, FALSE); count++; }
static void test_gint_fcn (QofBook *book, const char *message, void (*set) (GncEmployee *, gint), gint (*get) (GncEmployee *)) { GncEmployee *employee = gncEmployeeCreate (book); gint num = 17; do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); gncEmployeeBeginEdit (employee); set (employee, num); do_test (gncEmployeeIsDirty (employee), "test dirty later"); gncEmployeeCommitEdit (employee); do_test (!gncEmployeeIsDirty (employee), "test dirty after commit"); do_test (get (employee) == num, message); gncEmployeeSetActive (employee, FALSE); count++; }
static void test_bool_fcn (QofBook *book, const char *message, void (*set) (GncEmployee *, gboolean), gboolean (*get) (const GncEmployee *)) { GncEmployee *employee = gncEmployeeCreate (book); gboolean num = get_random_boolean (); do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); gncEmployeeBeginEdit (employee); set (employee, FALSE); set (employee, TRUE); set (employee, num); do_test (gncEmployeeIsDirty (employee), "test dirty later"); gncEmployeeCommitEdit (employee); do_test (gncEmployeeIsDirty (employee), "test dirty after commit"); do_test (get (employee) == num, message); gncEmployeeSetActive (employee, FALSE); count++; }
void gnc_employee_window_destroy_cb (GtkWidget *widget, gpointer data) { EmployeeWindow *ew = data; GncEmployee *employee = ew_get_employee (ew); gnc_suspend_gui_refresh (); if (ew->dialog_type == NEW_EMPLOYEE && employee != NULL) { gncEmployeeBeginEdit (employee); gncEmployeeDestroy (employee); ew->employee_guid = *guid_null (); } gnc_unregister_gui_component (ew->component_id); gnc_resume_gui_refresh (); g_free (ew); }
/** * Listens for MODIFY events from addresses. If the address belongs to an employee, * mark the employee as dirty. * * @param entity Entity for the event * @param event_type Event type * @param user_data User data registered with the handler * @param event_data Event data passed with the event. */ static void listen_for_address_events(QofInstance *entity, QofEventId event_type, gpointer user_data, gpointer event_data) { GncEmployee* empl; if ((event_type & QOF_EVENT_MODIFY) == 0) { return; } if (!GNC_IS_ADDRESS(entity)) { return; } if (!GNC_IS_EMPLOYEE(event_data)) { return; } empl = GNC_EMPLOYEE(event_data); gncEmployeeBeginEdit(empl); mark_employee(empl); gncEmployeeCommitEdit(empl); }
static GncEmployee* dom_tree_to_employee (xmlNodePtr node, QofBook *book) { struct employee_pdata employee_pdata; gboolean successful; employee_pdata.employee = gncEmployeeCreate(book); employee_pdata.book = book; gncEmployeeBeginEdit (employee_pdata.employee); successful = dom_tree_generic_parse (node, employee_handlers_v2, &employee_pdata); if (successful) gncEmployeeCommitEdit (employee_pdata.employee); else { PERR ("failed to parse employee tree"); gncEmployeeDestroy (employee_pdata.employee); employee_pdata.employee = NULL; } return employee_pdata.employee; }
void qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent) { GncAddress *addr; if (!employee || !addr_ent) { return; } addr = (GncAddress*)addr_ent; if (addr == employee->addr) { return; } if (employee->addr != NULL) { gncAddressBeginEdit(employee->addr); gncAddressDestroy(employee->addr); } gncEmployeeBeginEdit(employee); employee->addr = addr; gncEmployeeCommitEdit(employee); }
static void test_employee (void) { QofBook *book; GncEmployee *employee; book = qof_book_new(); /* Test creation/destruction */ { do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL"); employee = gncEmployeeCreate (book); do_test (employee != NULL, "employee create"); do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book, "getbook"); gncEmployeeBeginEdit (employee); gncEmployeeDestroy (employee); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID); test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername); test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage); test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl); test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday); test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate); test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive); do_test (gncEmployeeGetAddr (employee) != NULL, "Addr"); guid_replace (&guid); employee = gncEmployeeCreate (book); count++; gncEmployeeSetGUID (employee, &guid); do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare"); } { GList *list; list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE); do_test (list != NULL, "getList all"); do_test (g_list_length (list) == count, "correct length: all"); g_list_free (list); list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE); do_test (list != NULL, "getList active"); do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } { const char *str = get_random_string(); const char *res; GncAddress *addr; addr = gncEmployeeGetAddr (employee); gncAddressSetName (addr, str); res = qof_object_printable (GNC_ID_EMPLOYEE, employee); do_test (res != NULL, "Printable NULL?"); do_test (g_strcmp0 (str, res) == 0, "Printable equals"); } qof_book_destroy (book); }
static void test_employee (void) { QofBackend *be; QofBook *book; QofSession *session; GncEmployee *employee; session = qof_session_new(); qof_session_begin(session, QOF_STDOUT, FALSE, FALSE); book = qof_session_get_book(session); /* The book *must* have a backend to pass the test of the 'dirty' flag */ /* See the README file for details */ be = qof_book_get_backend (book); /* Test creation/destruction */ { do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL"); employee = gncEmployeeCreate (book); do_test (employee != NULL, "employee create"); do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book, "getbook"); gncEmployeeBeginEdit (employee); gncEmployeeDestroy (employee); success ("create/destroy"); } /* Test setting/getting routines; does the active flag get set right? */ { GncGUID guid; test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID); test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername); test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage); test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl); test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday); test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate); test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive); do_test (gncEmployeeGetAddr (employee) != NULL, "Addr"); guid_new (&guid); employee = gncEmployeeCreate (book); count++; gncEmployeeSetGUID (employee, &guid); do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare"); } #if 0 { GList *list; list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE); do_test (list != NULL, "getList all"); do_test (g_list_length (list) == count, "correct length: all"); g_list_free (list); list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE); do_test (list != NULL, "getList active"); do_test (g_list_length (list) == 1, "correct length: active"); g_list_free (list); } #endif { const char *str = get_random_string(); const char *res; GncAddress *addr; addr = gncEmployeeGetAddr (employee); gncAddressSetName (addr, str); res = qof_object_printable (GNC_ID_EMPLOYEE, employee); do_test (res != NULL, "Printable NULL?"); do_test (safe_strcmp (str, res) == 0, "Printable equals"); } }