Example #1
0
static GncJob*
load_single_job( GncSqlBackend* be, GncSqlRow* row )
{
    const GncGUID* guid;
    GncJob* pJob;

    g_return_val_if_fail( be != NULL, NULL );
    g_return_val_if_fail( row != NULL, NULL );

    guid = gnc_sql_load_guid( be, row );
    pJob = gncJobLookup( be->book, guid );
    if ( pJob == NULL )
    {
        pJob = gncJobCreate( be->book );
    }
    gnc_sql_load_object( be, row, GNC_ID_JOB, pJob, col_table );
    qof_instance_mark_clean( QOF_INSTANCE(pJob) );

    return pJob;
}
Example #2
0
static GncJob*
dom_tree_to_job (xmlNodePtr node, QofBook *book)
{
    struct job_pdata job_pdata;
    gboolean successful;

    job_pdata.job = gncJobCreate(book);
    job_pdata.book = book;
    gncJobBeginEdit (job_pdata.job);

    successful = dom_tree_generic_parse (node, job_handlers_v2,
                                         &job_pdata);

    if (successful)
        gncJobCommitEdit (job_pdata.job);
    else
    {
        PERR ("failed to parse job tree");
        gncJobDestroy (job_pdata.job);
        job_pdata.job = NULL;
    }

    return job_pdata.job;
}
Example #3
0
static void
load_owner( const GncSqlBackend* be, GncSqlRow* row,
            QofSetterFunc setter, gpointer pObject,
            const GncSqlColumnTableEntry* table_row )
{
    const GValue* val;
    gchar* buf;
    GncOwnerType type;
    GncGUID guid;
    QofBook* book;
    GncOwner owner;
    GncGUID* pGuid = NULL;

    g_return_if_fail( be != NULL );
    g_return_if_fail( row != NULL );
    g_return_if_fail( pObject != NULL );
    g_return_if_fail( table_row != NULL );

    book = be->primary_book;
    buf = g_strdup_printf( "%s_type", table_row->col_name );
    val = gnc_sql_row_get_value_at_col_name( row, buf );
    type = (GncOwnerType)gnc_sql_get_integer_value( val );
    g_free( buf );
    buf = g_strdup_printf( "%s_guid", table_row->col_name );
    val = gnc_sql_row_get_value_at_col_name( row, buf );
    g_free( buf );

    if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
    {
        string_to_guid( g_value_get_string( val ), &guid );
        pGuid = &guid;
    }

    switch ( type )
    {
    case GNC_OWNER_CUSTOMER:
    {
        GncCustomer *cust = NULL;

        if ( pGuid != NULL )
        {
            cust = gncCustomerLookup( book, pGuid );
            if ( cust == NULL )
            {
                cust = gncCustomerCreate( book );
                gncCustomerSetGUID( cust, &guid );
            }
        }
        gncOwnerInitCustomer( &owner, cust );
        break;
    }

    case GNC_OWNER_JOB:
    {
        GncJob *job = NULL;

        if ( pGuid != NULL )
        {
            job = gncJobLookup( book, pGuid );
            if ( job == NULL )
            {
                job = gncJobCreate( book );
                gncJobSetGUID( job, &guid );
            }
        }
        gncOwnerInitJob( &owner, job );
        break;
    }

    case GNC_OWNER_VENDOR:
    {
        GncVendor *vendor = NULL;

        if ( pGuid != NULL )
        {
            vendor = gncVendorLookup( book, pGuid );
            if ( vendor == NULL )
            {
                vendor = gncVendorCreate( book );
                gncVendorSetGUID( vendor, &guid );
            }
        }
        gncOwnerInitVendor( &owner, vendor );
        break;
    }

    case GNC_OWNER_EMPLOYEE:
    {
        GncEmployee *employee = NULL;

        if ( pGuid != NULL )
        {
            employee = gncEmployeeLookup( book, pGuid );
            if ( employee == NULL )
            {
                employee = gncEmployeeCreate( book );
                gncEmployeeSetGUID( employee, &guid );
            }
        }
        gncOwnerInitEmployee( &owner, employee );
        break;
    }

    default:
        PWARN("Invalid owner type: %d\n", type );
    }

    if ( table_row->gobj_param_name != NULL )
    {
        g_object_set( pObject, table_row->gobj_param_name, &owner, NULL );
    }
    else
    {
        (*setter)( pObject, &owner );
    }
}
static gboolean
owner_id_handler (xmlNodePtr node, gpointer owner_pdata)
{
    struct owner_pdata* pdata = static_cast<decltype (pdata)> (owner_pdata);
    GncGUID* guid;

    guid = dom_tree_to_guid (node);
    g_return_val_if_fail (guid, FALSE);

    switch (gncOwnerGetType (pdata->owner))
    {
    case GNC_OWNER_CUSTOMER:
    {
        GncCustomer* cust = gncCustomerLookup (pdata->book, guid);
        if (!cust)
        {
            cust = gncCustomerCreate (pdata->book);
            gncCustomerSetGUID (cust, guid);
        }
        gncOwnerInitCustomer (pdata->owner, cust);
        break;
    }
    case GNC_OWNER_JOB:
    {
        GncJob* job = gncJobLookup (pdata->book, guid);
        if (!job)
        {
            job = gncJobCreate (pdata->book);
            gncJobSetGUID (job, guid);
        }
        gncOwnerInitJob (pdata->owner, job);
        break;
    }
    case GNC_OWNER_VENDOR:
    {
        GncVendor* vendor = gncVendorLookup (pdata->book, guid);
        if (!vendor)
        {
            vendor = gncVendorCreate (pdata->book);
            gncVendorSetGUID (vendor, guid);
        }
        gncOwnerInitVendor (pdata->owner, vendor);
        break;
    }
    case GNC_OWNER_EMPLOYEE:
    {
        GncEmployee* employee = gncEmployeeLookup (pdata->book, guid);
        if (!employee)
        {
            employee = gncEmployeeCreate (pdata->book);
            gncEmployeeSetGUID (employee, guid);
        }
        gncOwnerInitEmployee (pdata->owner, employee);
        break;
    }
    default:
        PWARN ("Invalid owner type: %d\n", gncOwnerGetType (pdata->owner));
        g_free (guid);
        return FALSE;
    }

    g_free (guid);
    return TRUE;
}
Example #5
0
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);
}
Example #6
0
static JobWindow *
gnc_job_new_window (QofBook *bookp, GncOwner *owner, GncJob *job)
{
    JobWindow *jw;
    GtkBuilder *builder;
    GtkWidget *owner_box, *owner_label;

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

        job_guid = *gncJobGetGUID (job);
        jw = gnc_find_first_gui_component (DIALOG_EDIT_JOB_CM_CLASS,
                                           find_handler, &job_guid);
        if (jw)
        {
            gtk_window_present (GTK_WINDOW(jw->dialog));
            return(jw);
        }
    }

    /*
     * No existing job window found.  Build a new one.
     */
    jw = g_new0 (JobWindow, 1);
    jw->book = bookp;
    gncOwnerCopy (owner, &(jw->owner)); /* save it off now, we know it's valid */

    /* Load the Glade File */
    builder = gtk_builder_new();
    gnc_builder_add_from_file (builder, "dialog-job.glade", "Job Dialog");

    /* Find the dialog */
    jw->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Job Dialog"));

    /* Get entry points */
    jw->id_entry  = GTK_WIDGET(gtk_builder_get_object (builder, "id_entry"));
    jw->name_entry = GTK_WIDGET(gtk_builder_get_object (builder, "name_entry"));
    jw->desc_entry = GTK_WIDGET(gtk_builder_get_object (builder, "desc_entry"));
    jw->active_check = GTK_WIDGET(gtk_builder_get_object (builder, "active_check"));

    owner_box = GTK_WIDGET(gtk_builder_get_object (builder, "customer_hbox"));
    owner_label = GTK_WIDGET(gtk_builder_get_object (builder, "owner_label"));

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


    /* Set initial entries */
    if (job != NULL)
    {
        jw->job_guid = *gncJobGetGUID (job);

        jw->dialog_type = EDIT_JOB;
        jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box,
                                               bookp, owner);

        gtk_entry_set_text (GTK_ENTRY (jw->id_entry), gncJobGetID (job));
        gtk_entry_set_text (GTK_ENTRY (jw->name_entry), gncJobGetName (job));
        gtk_entry_set_text (GTK_ENTRY (jw->desc_entry), gncJobGetReference (job));
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (jw->active_check),
                                      gncJobGetActive (job));

        jw->component_id = gnc_register_gui_component (DIALOG_EDIT_JOB_CM_CLASS,
                           gnc_job_window_refresh_handler,
                           gnc_job_window_close_handler,
                           jw);
    }
    else
    {
        job = gncJobCreate (bookp);
        gncJobSetOwner (job, owner);
        jw->job_guid = *gncJobGetGUID (job);

        jw->dialog_type = NEW_JOB;

        /* If we are passed a real owner, don't allow the user to change it */
        if (owner->owner.undefined)
        {
            jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box,
                                                   bookp, owner);
        }
        else
        {
            jw->cust_edit = gnc_owner_select_create (owner_label, owner_box,
                            bookp, owner);
        }

        jw->component_id = gnc_register_gui_component (DIALOG_NEW_JOB_CM_CLASS,
                           gnc_job_window_refresh_handler,
                           gnc_job_window_close_handler,
                           jw);
    }

    gnc_job_name_changed_cb (NULL, jw);
    gnc_gui_component_watch_entity_type (jw->component_id,
                                         GNC_JOB_MODULE_NAME,
                                         QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);

    gtk_widget_show_all (jw->dialog);

    // The job name should have keyboard focus
    gtk_widget_grab_focus(jw->name_entry);
    // Or should the owner field have focus?
//    if (GNC_IS_GENERAL_SEARCH(jw->cust_edit))
//    {
//        gnc_general_search_grab_focus(GNC_GENERAL_SEARCH(jw->cust_edit));
//    }

    g_object_unref(G_OBJECT(builder));

    return jw;
}