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 (); }
static void gnc_address_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GncAddress *address; g_return_if_fail(GNC_IS_ADDRESS(object)); address = GNC_ADDRESS(object); switch (prop_id) { case PROP_NAME: gncAddressSetName(address, g_value_get_string(value)); break; case PROP_ADDR1: gncAddressSetAddr1(address, g_value_get_string(value)); break; case PROP_ADDR2: gncAddressSetAddr2(address, g_value_get_string(value)); break; case PROP_ADDR3: gncAddressSetAddr3(address, g_value_get_string(value)); break; case PROP_ADDR4: gncAddressSetAddr4(address, g_value_get_string(value)); break; case PROP_PHONE: gncAddressSetPhone(address, g_value_get_string(value)); break; case PROP_FAX: gncAddressSetFax(address, g_value_get_string(value)); break; case PROP_EMAIL: gncAddressSetEmail(address, g_value_get_string(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
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"); } }
static void gnc_ui_to_customer (CustomerWindow *cw, GncCustomer *cust) { GtkTextBuffer* text_buffer; GtkTextIter start, end; gchar *text; GncAddress *addr, *shipaddr; addr = gncCustomerGetAddr (cust); shipaddr = gncCustomerGetShipAddr (cust); gnc_suspend_gui_refresh (); gncCustomerBeginEdit (cust); if (cw->dialog_type == NEW_CUSTOMER) qof_event_gen(QOF_INSTANCE(cust), QOF_EVENT_ADD, NULL); gncCustomerSetID (cust, gtk_editable_get_chars (GTK_EDITABLE (cw->id_entry), 0, -1)); gncCustomerSetName (cust, gtk_editable_get_chars (GTK_EDITABLE (cw->company_entry), 0, -1)); gncAddressSetName (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->name_entry), 0, -1)); gncAddressSetAddr1 (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->addr1_entry), 0, -1)); gncAddressSetAddr2 (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->addr2_entry), 0, -1)); gncAddressSetAddr3 (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->addr3_entry), 0, -1)); gncAddressSetAddr4 (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->addr4_entry), 0, -1)); gncAddressSetPhone (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->phone_entry), 0, -1)); gncAddressSetFax (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->fax_entry), 0, -1)); gncAddressSetEmail (addr, gtk_editable_get_chars (GTK_EDITABLE (cw->email_entry), 0, -1)); gncAddressSetName (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipname_entry), 0, -1)); gncAddressSetAddr1 (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipaddr1_entry), 0, -1)); gncAddressSetAddr2 (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipaddr2_entry), 0, -1)); gncAddressSetAddr3 (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipaddr3_entry), 0, -1)); gncAddressSetAddr4 (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipaddr4_entry), 0, -1)); gncAddressSetPhone (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipphone_entry), 0, -1)); gncAddressSetFax (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipfax_entry), 0, -1)); gncAddressSetEmail (shipaddr, gtk_editable_get_chars (GTK_EDITABLE (cw->shipemail_entry), 0, -1)); gncCustomerSetActive (cust, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cw->active_check))); gncCustomerSetTaxIncluded (cust, cw->taxincluded); text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(cw->notes_text)); gtk_text_buffer_get_bounds (text_buffer, &start, &end); text = gtk_text_buffer_get_text (text_buffer, &start, &end, FALSE); gncCustomerSetNotes (cust, text); /* Parse and set the currency, terms, discount, and credit amounts */ gncCustomerSetCurrency (cust, gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT (cw->currency_edit))); gncCustomerSetTerms (cust, cw->terms); gncCustomerSetDiscount (cust, gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (cw->discount_amount))); gncCustomerSetCredit (cust, gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (cw->credit_amount))); gncCustomerSetTaxTableOverride (cust, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cw->taxtable_check))); gncCustomerSetTaxTable (cust, cw->taxtable); gncCustomerCommitEdit (cust); gnc_resume_gui_refresh (); }
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 gnc_plugin_business_cmd_test_init_data (GtkAction *action, GncMainWindowActionData *data) { QofBook *book = gnc_get_current_book(); GncCustomer *customer = gncCustomerCreate(book); GncAddress *address = gncCustomerGetAddr(customer); GncInvoice *invoice = gncInvoiceCreate(book); GncOwner *owner = gncOwnerNew(); GncJob *job = gncJobCreate(book); Account *root = gnc_book_get_root_account(book); Account *inc_acct = xaccMallocAccount(book); Account *bank_acct = xaccMallocAccount(book); Account *tax_acct = xaccMallocAccount(book); Account *ar_acct = xaccMallocAccount(book); Timespec now; // Create Customer gncCustomerSetID(customer, "000001"); gncCustomerSetName(customer, "Test Customer"); gncCustomerSetCurrency(customer, gnc_default_currency()); gncAddressSetName(address, "Contact Person"); gncAddressSetAddr1(address, "20 Customer Lane"); gncAddressSetAddr2(address, "Customer M/S"); gncAddressSetAddr3(address, "Addr3, XXX 12345"); // Create the Owner gncOwnerInitCustomer(owner, customer); // Create the Invoice timespecFromTime64(&now, time(NULL)); gncInvoiceSetID(invoice, "000012"); gncInvoiceSetOwner(invoice, owner); gncInvoiceSetDateOpened(invoice, now); gncInvoiceSetCurrency(invoice, gnc_default_currency()); // Create the Job gncJobSetID(job, "000025"); gncJobSetName(job, "Test Job"); gncJobSetReference(job, "Customer's ref#"); gncJobSetOwner(job, owner); // MODIFY THE OWNER gncOwnerInitJob(owner, job); // Create the A/R account xaccAccountSetType(ar_acct, ACCT_TYPE_RECEIVABLE); xaccAccountSetName(ar_acct, "A/R"); xaccAccountSetCommodity(ar_acct, gnc_default_currency()); gnc_account_append_child(root, ar_acct); // Create the Income account xaccAccountSetType(inc_acct, ACCT_TYPE_INCOME); xaccAccountSetName(inc_acct, "Income"); xaccAccountSetCommodity(inc_acct, gnc_default_currency()); gnc_account_append_child(root, inc_acct); // Create the Bank account xaccAccountSetType(bank_acct, ACCT_TYPE_BANK); xaccAccountSetName(bank_acct, "Bank"); xaccAccountSetCommodity(bank_acct, gnc_default_currency()); gnc_account_append_child(root, bank_acct); // Create the Tax account xaccAccountSetType(tax_acct, ACCT_TYPE_LIABILITY); xaccAccountSetName(tax_acct, "Tax-Holding"); xaccAccountSetCommodity(tax_acct, gnc_default_currency()); gnc_account_append_child(root, tax_acct); // Launch the invoice editor gnc_ui_invoice_edit (GTK_WINDOW (data->window), invoice); }