Esempio n. 1
0
xmlNodePtr
gnc_address_to_dom_tree (const char *tag, GncAddress *addr)
{
    xmlNodePtr ret;
    KvpFrame *kf;

    ret = xmlNewNode(NULL, BAD_CAST tag);
    xmlSetProp(ret, BAD_CAST "version", BAD_CAST address_version_string);

    maybe_add_string (ret, addr_name_string, gncAddressGetName (addr));

    maybe_add_string (ret, addr_addr1_string, gncAddressGetAddr1 (addr));
    maybe_add_string (ret, addr_addr2_string, gncAddressGetAddr2 (addr));
    maybe_add_string (ret, addr_addr3_string, gncAddressGetAddr3 (addr));
    maybe_add_string (ret, addr_addr4_string, gncAddressGetAddr4 (addr));

    maybe_add_string (ret, addr_phone_string, gncAddressGetPhone (addr));
    maybe_add_string (ret, addr_fax_string, gncAddressGetFax (addr));
    maybe_add_string (ret, addr_email_string, gncAddressGetEmail (addr));

    kf = qof_instance_get_slots (QOF_INSTANCE(addr));
    if (kf)
    {
        xmlNodePtr kvpnode = kvp_frame_to_dom_tree(addr_slots_string, kf);
        if (kvpnode)
        {
            xmlAddChild(ret, kvpnode);
        }
    }

    return ret;
}
static void address_cb(gpointer data, gpointer user_data)
{
    const GncAddress* address = data;
    AddressQF *s = (AddressQF *) user_data;

    gnc_quickfill_insert (s->qf_addr2,
                          gncAddressGetAddr2(address),
                          s->qf_sort);

    gnc_quickfill_insert (s->qf_addr3,
                          gncAddressGetAddr3(address),
                          s->qf_sort);

    gnc_quickfill_insert (s->qf_addr4,
                          gncAddressGetAddr4(address),
                          s->qf_sort);
}
Esempio n. 3
0
xmlNodePtr
gnc_address_to_dom_tree (const char* tag, GncAddress* addr)
{
    xmlNodePtr ret;

    ret = xmlNewNode (NULL, BAD_CAST tag);
    xmlSetProp (ret, BAD_CAST "version", BAD_CAST address_version_string);

    maybe_add_string (ret, addr_name_string, gncAddressGetName (addr));

    maybe_add_string (ret, addr_addr1_string, gncAddressGetAddr1 (addr));
    maybe_add_string (ret, addr_addr2_string, gncAddressGetAddr2 (addr));
    maybe_add_string (ret, addr_addr3_string, gncAddressGetAddr3 (addr));
    maybe_add_string (ret, addr_addr4_string, gncAddressGetAddr4 (addr));

    maybe_add_string (ret, addr_phone_string, gncAddressGetPhone (addr));
    maybe_add_string (ret, addr_fax_string, gncAddressGetFax (addr));
    maybe_add_string (ret, addr_email_string, gncAddressGetEmail (addr));

    /* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
    xmlAddChild (ret, qof_instance_slots_to_dom_tree (addr_slots_string,
                                                      QOF_INSTANCE (addr)));
    return ret;
}
static CustomerWindow *
gnc_customer_new_window (QofBook *bookp, GncCustomer *cust)
{
    CustomerWindow *cw;
    GtkBuilder *builder;
    GtkWidget *hbox, *edit;
    gnc_commodity *currency;
    GNCPrintAmountInfo print_info;

    /*
     * Find an existing window for this customer.  If found, bring it to
     * the front.
     */
    if (cust)
    {
        GncGUID customer_guid;

        customer_guid = *gncCustomerGetGUID(cust);
        cw = gnc_find_first_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS,
                                           find_handler, &customer_guid);
        if (cw)
        {
            gtk_window_present (GTK_WINDOW(cw->dialog));
            return(cw);
        }
    }

    /* Find the default currency */
    if (cust)
        currency = gncCustomerGetCurrency (cust);
    else
        currency = gnc_default_currency ();

    /*
     * No existing customer window found.  Build a new one.
     */
    cw = g_new0 (CustomerWindow, 1);

    cw->book = bookp;

    /* Find the dialog */
    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-customer.glade", "terms_store");
    gnc_builder_add_from_file (builder, "dialog-customer.glade", "tax_included_store");
    gnc_builder_add_from_file (builder, "dialog-customer.glade", "taxtable_store");
    gnc_builder_add_from_file (builder, "dialog-customer.glade", "Customer Dialog");
    cw->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "Customer Dialog"));

    g_object_set_data (G_OBJECT (cw->dialog), "dialog_info", cw);

    /* Get entry points */
    cw->id_entry = GTK_WIDGET (gtk_builder_get_object (builder, "id_entry"));
    cw->company_entry = GTK_WIDGET (gtk_builder_get_object (builder, "company_entry"));

    cw->name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
    cw->addr1_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr1_entry"));
    cw->addr2_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr2_entry"));
    cw->addr3_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr3_entry"));
    cw->addr4_entry = GTK_WIDGET (gtk_builder_get_object (builder, "addr4_entry"));
    cw->phone_entry = GTK_WIDGET (gtk_builder_get_object (builder, "phone_entry"));
    cw->fax_entry = GTK_WIDGET (gtk_builder_get_object (builder, "fax_entry"));
    cw->email_entry = GTK_WIDGET (gtk_builder_get_object (builder, "email_entry"));

    cw->shipname_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipname_entry"));
    cw->shipaddr1_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr1_entry"));
    cw->shipaddr2_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr2_entry"));
    cw->shipaddr3_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr3_entry"));
    cw->shipaddr4_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipaddr4_entry"));
    cw->shipphone_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipphone_entry"));
    cw->shipfax_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipfax_entry"));
    cw->shipemail_entry = GTK_WIDGET (gtk_builder_get_object (builder, "shipemail_entry"));

    cw->active_check = GTK_WIDGET (gtk_builder_get_object (builder, "active_check"));
    cw->taxincluded_menu = GTK_WIDGET (gtk_builder_get_object (builder, "tax_included_menu"));
    cw->notes_text = GTK_WIDGET (gtk_builder_get_object (builder, "notes_text"));

    cw->terms_menu = GTK_WIDGET (gtk_builder_get_object (builder, "terms_menu"));

    cw->taxtable_check = GTK_WIDGET (gtk_builder_get_object (builder, "taxtable_button"));
    cw->taxtable_menu = GTK_WIDGET (gtk_builder_get_object (builder, "taxtable_menu"));

    /* Currency */
    edit = gnc_currency_edit_new();
    gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(edit), currency);
    cw->currency_edit = edit;

    hbox = GTK_WIDGET (gtk_builder_get_object (builder, "currency_box"));
    gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);

    /* DISCOUNT: Percentage Value */
    edit = gnc_amount_edit_new();
    gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
    print_info = gnc_integral_print_info ();
    print_info.max_decimal_places = 5;
    gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
    gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000);
    cw->discount_amount = edit;
    gtk_widget_show (edit);

    hbox = GTK_WIDGET (gtk_builder_get_object (builder, "discount_box"));
    gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);

    /* CREDIT: Monetary Value */
    edit = gnc_amount_edit_new();
    print_info = gnc_commodity_print_info (currency, FALSE);
    gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
    gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
    gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit),
                                  gnc_commodity_get_fraction (currency));
    cw->credit_amount = edit;
    gtk_widget_show (edit);

    hbox = GTK_WIDGET (gtk_builder_get_object (builder, "credit_box"));
    gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);

    /* Setup signals */
    gtk_builder_connect_signals_full( builder,
                                      gnc_builder_connect_full_func,
                                      cw);

    /* Setup initial values */
    if (cust != NULL)
    {
        GtkTextBuffer* text_buffer;
        GncAddress *addr, *shipaddr;
        const char *string;

        cw->dialog_type = EDIT_CUSTOMER;
        cw->customer_guid = *gncCustomerGetGUID (cust);

        addr = gncCustomerGetAddr (cust);
        shipaddr = gncCustomerGetShipAddr (cust);

        gtk_entry_set_text (GTK_ENTRY (cw->id_entry), gncCustomerGetID (cust));
        gtk_entry_set_text (GTK_ENTRY (cw->company_entry), gncCustomerGetName (cust));

        /* Setup Address */
        gtk_entry_set_text (GTK_ENTRY (cw->name_entry), gncAddressGetName (addr));
        gtk_entry_set_text (GTK_ENTRY (cw->addr1_entry), gncAddressGetAddr1 (addr));
        gtk_entry_set_text (GTK_ENTRY (cw->addr2_entry), gncAddressGetAddr2 (addr));
        gtk_entry_set_text (GTK_ENTRY (cw->addr3_entry), gncAddressGetAddr3 (addr));
        gtk_entry_set_text (GTK_ENTRY (cw->addr4_entry), gncAddressGetAddr4 (addr));
        gtk_entry_set_text (GTK_ENTRY (cw->phone_entry), gncAddressGetPhone (addr));
        gtk_entry_set_text (GTK_ENTRY (cw->fax_entry), gncAddressGetFax (addr));
        gtk_entry_set_text (GTK_ENTRY (cw->email_entry), gncAddressGetEmail (addr));

        /* Setup Ship-to Address */
        gtk_entry_set_text (GTK_ENTRY (cw->shipname_entry), gncAddressGetName (shipaddr));
        gtk_entry_set_text (GTK_ENTRY (cw->shipaddr1_entry), gncAddressGetAddr1 (shipaddr));
        gtk_entry_set_text (GTK_ENTRY (cw->shipaddr2_entry), gncAddressGetAddr2 (shipaddr));
        gtk_entry_set_text (GTK_ENTRY (cw->shipaddr3_entry), gncAddressGetAddr3 (shipaddr));
        gtk_entry_set_text (GTK_ENTRY (cw->shipaddr4_entry), gncAddressGetAddr4 (shipaddr));
        gtk_entry_set_text (GTK_ENTRY (cw->shipphone_entry), gncAddressGetPhone (shipaddr));
        gtk_entry_set_text (GTK_ENTRY (cw->shipfax_entry), gncAddressGetFax (shipaddr));
        gtk_entry_set_text (GTK_ENTRY (cw->shipemail_entry), gncAddressGetEmail (shipaddr));

        /* Set toggle buttons */
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->active_check),
                                      gncCustomerGetActive (cust));

        string = gncCustomerGetNotes (cust);
        text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(cw->notes_text));
        gtk_text_buffer_set_text (text_buffer, string, -1);

        cw->component_id =
            gnc_register_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS,
                                        gnc_customer_window_refresh_handler,
                                        gnc_customer_window_close_handler,
                                        cw);
        cw->terms = gncCustomerGetTerms (cust);

    }
    else
    {
        cust = gncCustomerCreate (bookp);
        cw->customer_guid = *gncCustomerGetGUID (cust);

        cw->dialog_type = NEW_CUSTOMER;
        cw->component_id =
            gnc_register_gui_component (DIALOG_NEW_CUSTOMER_CM_CLASS,
                                        gnc_customer_window_refresh_handler,
                                        gnc_customer_window_close_handler,
                                        cw);

        /* XXX: get the global-default terms */
        cw->terms = NULL;
    }

    /* I know that cust exists here -- either passed in or just created */

    cw->taxincluded = gncCustomerGetTaxIncluded (cust);
    gnc_taxincluded_combo (GTK_COMBO_BOX(cw->taxincluded_menu), cw->taxincluded);
    gnc_billterms_combo (GTK_COMBO_BOX(cw->terms_menu), bookp, TRUE, cw->terms);

    cw->taxtable = gncCustomerGetTaxTable (cust);
    gnc_taxtables_combo (GTK_COMBO_BOX(cw->taxtable_menu), bookp, TRUE, cw->taxtable);
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->taxtable_check),
                                  gncCustomerGetTaxTableOverride (cust));
    gnc_customer_taxtable_check_cb (GTK_TOGGLE_BUTTON (cw->taxtable_check), cw);

    /* Set up the addr line quickfill */
    cw->addr2_quickfill = gnc_get_shared_address_addr2_quickfill(cw->book, ADDR_QUICKFILL);
    cw->addr3_quickfill = gnc_get_shared_address_addr3_quickfill(cw->book, ADDR_QUICKFILL);
    cw->addr4_quickfill = gnc_get_shared_address_addr4_quickfill(cw->book, ADDR_QUICKFILL);

    /* Set the Discount, and Credit amounts */
    gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount),
                                gncCustomerGetDiscount (cust));
    gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->credit_amount),
                                gncCustomerGetCredit (cust));

    gnc_gui_component_watch_entity_type (cw->component_id,
                                         GNC_CUSTOMER_MODULE_NAME,
                                         QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);

    gtk_widget_show_all (cw->dialog);
    g_object_unref(G_OBJECT(builder));

    return cw;
}
static void
listen_for_gncaddress_events(QofInstance *entity,  QofEventId event_type,
                             gpointer user_data, gpointer event_data)
{
    AddressQF *qfb = user_data;
    const char *addr2, *addr3, *addr4;

    /* We only listen for GncAddress events */
    if (!GNC_IS_ADDRESS (entity))
        return;

    /* We listen for MODIFY (if the description was changed into
     * something non-empty, so we add the string to the quickfill) and
     * DESTROY (to remove the description from the quickfill). */
    if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_DESTROY)))
        return;

    /*     g_warning("entity %p, entity type %s, event type %s, user data %p, ecent data %p", */
    /*               entity, entity->e_type, qofeventid_to_string(event_type), user_data, event_data); */

    addr2 = gncAddressGetAddr2(GNC_ADDRESS(entity));
    addr3 = gncAddressGetAddr3(GNC_ADDRESS(entity));
    addr4 = gncAddressGetAddr4(GNC_ADDRESS(entity));
    if (event_type & QOF_EVENT_MODIFY)
    {
        /* If the description was changed into something non-empty, so
         * we add the string to the quickfill */
        if (addr2 && strlen(addr2) > 0)
        {
            /* Add the new string to the quickfill */
            gnc_quickfill_insert (qfb->qf_addr2, addr2, QUICKFILL_LIFO);
        }
        if (addr3 && strlen(addr3) > 0)
        {
            /* Add the new string to the quickfill */
            gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO);
        }
        if (addr4 && strlen(addr4) > 0)
        {
            /* Add the new string to the quickfill */
            gnc_quickfill_insert (qfb->qf_addr4, addr4, QUICKFILL_LIFO);
        }
    }
    else if (event_type & QOF_EVENT_DESTROY)
    {
        if (addr2 && strlen(addr2) > 0)
        {
            /* Remove the description from the quickfill */
            gnc_quickfill_insert (qfb->qf_addr2, addr2, QUICKFILL_LIFO);
        }
        if (addr3 && strlen(addr3) > 0)
        {
            /* Remove the description from the quickfill */
            gnc_quickfill_insert (qfb->qf_addr3, addr3, QUICKFILL_LIFO);
        }
        if (addr4 && strlen(addr4) > 0)
        {
            /* Remove the description from the quickfill */
            gnc_quickfill_insert (qfb->qf_addr4, addr4, QUICKFILL_LIFO);
        }
    }
}
Esempio n. 6
0
static void
gnc_tree_model_owner_get_value (GtkTreeModel *tree_model,
                                GtkTreeIter *iter,
                                int column,
                                GValue *value)
{
    GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
    GncOwner *owner;
    gboolean negative; /* used to set "deficit style" also known as red numbers */
    gchar *string = NULL;

    g_return_if_fail (GNC_IS_TREE_MODEL_OWNER (model));
    g_return_if_fail (iter != NULL);
    g_return_if_fail (iter->user_data != NULL);
    g_return_if_fail (iter->stamp == model->stamp);

    ENTER("model %p, iter %s, col %d", tree_model,
          iter_to_string(iter), column);

    owner = (GncOwner *) iter->user_data;

    switch (column)
    {
    case GNC_TREE_MODEL_OWNER_COL_NAME:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value, gncOwnerGetName (owner));
        break;
    case GNC_TREE_MODEL_OWNER_COL_TYPE:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value,
                            gncOwnerTypeToQofIdType (gncOwnerGetType (owner)));
        break;
    case GNC_TREE_MODEL_OWNER_COL_ID:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value, gncOwnerGetID (owner));
        break;
    case GNC_TREE_MODEL_OWNER_COL_CURRENCY:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value,
                            gnc_commodity_get_fullname(gncOwnerGetCurrency (owner)));
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_NAME:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetName (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_1:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr1 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_2:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr2 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_3:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr3 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_4:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr4 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_PHONE:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetPhone (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_FAX:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetFax (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_EMAIL:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetEmail (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;

    case GNC_TREE_MODEL_OWNER_COL_BALANCE:
        g_value_init (value, G_TYPE_STRING);
        string = gnc_ui_owner_get_print_balance(owner, &negative);
        g_value_take_string (value, string);
        break;

    case GNC_TREE_MODEL_OWNER_COL_BALANCE_REPORT:
        g_value_init (value, G_TYPE_STRING);
        string = gnc_ui_owner_get_print_report_balance(owner, &negative);
        g_value_take_string (value, string);
        break;
    case GNC_TREE_MODEL_OWNER_COL_COLOR_BALANCE:
        g_value_init (value, G_TYPE_STRING);
        string = gnc_ui_owner_get_print_balance(owner, &negative);
        gnc_tree_model_owner_set_color(model, negative, value);
        g_free(string);
        break;

    case GNC_TREE_MODEL_OWNER_COL_NOTES:
        g_value_init (value, G_TYPE_STRING);
        switch (gncOwnerGetType (owner))
        {
        case GNC_OWNER_NONE:
        case GNC_OWNER_UNDEFINED:
        case GNC_OWNER_EMPLOYEE:
        case GNC_OWNER_JOB:
        default:
            g_value_set_static_string (value, "");
            break;
        case GNC_OWNER_VENDOR:
            g_value_set_string (value, gncVendorGetNotes (gncOwnerGetVendor (owner)));
            break;
        case GNC_OWNER_CUSTOMER:
            g_value_set_string (value, gncCustomerGetNotes (gncOwnerGetCustomer (owner)));
            break;
        }
        break;

    case GNC_TREE_MODEL_OWNER_COL_ACTIVE:
        g_value_init (value, G_TYPE_BOOLEAN);
        g_value_set_boolean (value, gncOwnerGetActive (owner));
        break;

    default:
        g_assert_not_reached ();
    }
    LEAVE(" ");
}
Esempio n. 7
0
static EmployeeWindow *
gnc_employee_new_window (QofBook *bookp,
                         GncEmployee *employee)
{
    EmployeeWindow *ew;
    GtkBuilder *builder;
    GtkWidget *hbox, *edit;
    gnc_commodity *currency;
    GNCPrintAmountInfo print_info;
    GList *acct_types;
    Account *ccard_acct;

    /*
     * Find an existing window for this employee.  If found, bring it to
     * the front.
     */
    if (employee)
    {
        GncGUID employee_guid;

        employee_guid = *gncEmployeeGetGUID (employee);
        ew = gnc_find_first_gui_component (DIALOG_EDIT_EMPLOYEE_CM_CLASS,
                                           find_handler, &employee_guid);
        if (ew)
        {
            gtk_window_present (GTK_WINDOW(ew->dialog));
            return(ew);
        }
    }

    /* Find the default currency */
    if (employee)
        currency = gncEmployeeGetCurrency (employee);
    else
        currency = gnc_default_currency ();

    /*
     * No existing employee window found.  Build a new one.
     */
    ew = g_new0 (EmployeeWindow, 1);

    ew->book = bookp;

    /* Find the dialog */
    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-employee.glade", "Employee Dialog");
    ew->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Employee Dialog"));

    g_object_set_data (G_OBJECT (ew->dialog), "dialog_info", ew);

    /* Get entry points */
    ew->id_entry = GTK_WIDGET(gtk_builder_get_object (builder, "id_entry"));
    ew->username_entry = GTK_WIDGET(gtk_builder_get_object (builder, "username_entry"));

    ew->name_entry = GTK_WIDGET(gtk_builder_get_object (builder, "name_entry"));
    ew->addr1_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr1_entry"));
    ew->addr2_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr2_entry"));
    ew->addr3_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr3_entry"));
    ew->addr4_entry = GTK_WIDGET(gtk_builder_get_object (builder, "addr4_entry"));
    ew->phone_entry = GTK_WIDGET(gtk_builder_get_object (builder, "phone_entry"));
    ew->fax_entry = GTK_WIDGET(gtk_builder_get_object (builder, "fax_entry"));
    ew->email_entry = GTK_WIDGET(gtk_builder_get_object (builder, "email_entry"));

    ew->language_entry = GTK_WIDGET(gtk_builder_get_object (builder, "language_entry"));
    ew->active_check = GTK_WIDGET(gtk_builder_get_object (builder, "active_check"));

    /* Currency */
    edit = gnc_currency_edit_new();
    gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(edit), currency);
    ew->currency_edit = edit;

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "currency_box"));
    gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);

    /* WORKDAY: Value */
    edit = gnc_amount_edit_new();
    gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
    print_info = gnc_integral_print_info ();
    print_info.max_decimal_places = 5;
    gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
    gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000);
    ew->workday_amount = edit;
    gtk_widget_show (edit);

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "hours_hbox"));
    gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);

    /* RATE: Monetary Value */
    edit = gnc_amount_edit_new();
    print_info = gnc_commodity_print_info (currency, FALSE);
    gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE);
    gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info);
    gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit),
                                  gnc_commodity_get_fraction (currency));
    ew->rate_amount = edit;
    gtk_widget_show (edit);

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "rate_hbox"));
    gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);

    /* CCard Account Selection */
    ew->ccard_acct_check = GTK_WIDGET(gtk_builder_get_object (builder, "ccard_check"));

    edit = gnc_account_sel_new();
    acct_types = g_list_prepend(NULL, (gpointer)ACCT_TYPE_CREDIT);
    gnc_account_sel_set_acct_filters (GNC_ACCOUNT_SEL(edit), acct_types, NULL);
    g_list_free (acct_types);

    ew->ccard_acct_sel = edit;
    gtk_widget_show (edit);

    hbox = GTK_WIDGET(gtk_builder_get_object (builder, "ccard_acct_hbox"));
    gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0);

    /* Setup signals */
    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, ew);

    /* Setup initial values */
    if (employee != NULL)
    {
        GncAddress *addr;

        ew->dialog_type = EDIT_EMPLOYEE;
        ew->employee_guid = *gncEmployeeGetGUID (employee);

        addr = gncEmployeeGetAddr (employee);

        gtk_entry_set_text (GTK_ENTRY (ew->id_entry), gncEmployeeGetID (employee));
        gtk_entry_set_text (GTK_ENTRY (ew->username_entry), gncEmployeeGetUsername (employee));

        /* Setup Address */
        gtk_entry_set_text (GTK_ENTRY (ew->name_entry), gncAddressGetName (addr));
        gtk_entry_set_text (GTK_ENTRY (ew->addr1_entry), gncAddressGetAddr1 (addr));
        gtk_entry_set_text (GTK_ENTRY (ew->addr2_entry), gncAddressGetAddr2 (addr));
        gtk_entry_set_text (GTK_ENTRY (ew->addr3_entry), gncAddressGetAddr3 (addr));
        gtk_entry_set_text (GTK_ENTRY (ew->addr4_entry), gncAddressGetAddr4 (addr));
        gtk_entry_set_text (GTK_ENTRY (ew->phone_entry), gncAddressGetPhone (addr));
        gtk_entry_set_text (GTK_ENTRY (ew->fax_entry), gncAddressGetFax (addr));
        gtk_entry_set_text (GTK_ENTRY (ew->email_entry), gncAddressGetEmail (addr));

        gtk_entry_set_text (GTK_ENTRY (ew->language_entry),
                            gncEmployeeGetLanguage (employee));

        /* Set toggle buttons */
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ew->active_check),
                                      gncEmployeeGetActive (employee));

        ew->component_id =
            gnc_register_gui_component (DIALOG_EDIT_EMPLOYEE_CM_CLASS,
                                        gnc_employee_window_refresh_handler,
                                        gnc_employee_window_close_handler,
                                        ew);
    }
    else
    {
        employee = gncEmployeeCreate (bookp);
        ew->employee_guid = *gncEmployeeGetGUID (employee);

        ew->dialog_type = NEW_EMPLOYEE;
        ew->component_id =
            gnc_register_gui_component (DIALOG_NEW_EMPLOYEE_CM_CLASS,
                                        gnc_employee_window_refresh_handler,
                                        gnc_employee_window_close_handler,
                                        ew);
    }


    /* I know that employee exists here -- either passed in or just created */
    /* Set the workday and rate values */
    gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ew->workday_amount),
                                gncEmployeeGetWorkday (employee));
    gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ew->rate_amount),
                                gncEmployeeGetRate (employee));


    ccard_acct = gncEmployeeGetCCard (employee);
    if (ccard_acct == NULL)
    {
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ew->ccard_acct_check), FALSE);
        gtk_widget_set_sensitive (ew->ccard_acct_sel, FALSE);
    }
    else
    {
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ew->ccard_acct_check), TRUE);
        gnc_account_sel_set_account (GNC_ACCOUNT_SEL (ew->ccard_acct_sel), ccard_acct, FALSE);
    }

    /* XXX: Set the ACL */

    gnc_gui_component_watch_entity_type (ew->component_id,
                                         GNC_EMPLOYEE_MODULE_NAME,
                                         QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);

    gtk_widget_show_all (ew->dialog);

    if (ccard_acct == NULL)
        gtk_widget_hide (ew->ccard_acct_sel);

    g_object_unref(G_OBJECT(builder));

    return ew;
}