static gboolean
owner_type_handler (xmlNodePtr node, gpointer owner_pdata)
{
    struct owner_pdata* pdata = static_cast<decltype (pdata)> (owner_pdata);
    char* txt = dom_tree_to_text (node);
    g_return_val_if_fail (txt, FALSE);

    if (!g_strcmp0 (txt, GNC_ID_CUSTOMER))
        gncOwnerInitCustomer (pdata->owner, NULL);
    else if (!g_strcmp0 (txt, GNC_ID_JOB))
        gncOwnerInitJob (pdata->owner, NULL);
    else if (!g_strcmp0 (txt, GNC_ID_VENDOR))
        gncOwnerInitVendor (pdata->owner, NULL);
    else if (!g_strcmp0 (txt, GNC_ID_EMPLOYEE))
        gncOwnerInitEmployee (pdata->owner, NULL);
    else
    {
        PWARN ("Unknown owner type: %s", txt);
        g_free (txt);
        return FALSE;
    }

    g_free (txt);
    return TRUE;
}
Exemple #2
0
static GtkWidget *
create_owner_widget (GNCOption *option, GncOwnerType type, GtkWidget *hbox)
{
    GtkWidget *widget;
    GncOwner owner;

    switch (type)
    {
    case GNC_OWNER_CUSTOMER:
        gncOwnerInitCustomer (&owner, NULL);
        break;
    case GNC_OWNER_VENDOR:
        gncOwnerInitVendor (&owner, NULL);
        break;
    case GNC_OWNER_EMPLOYEE:
        gncOwnerInitEmployee (&owner, NULL);
        break;
    case GNC_OWNER_JOB:
        gncOwnerInitJob (&owner, NULL);
        break;
    default:
        return NULL;
    }

    widget = gnc_owner_select_create (NULL, hbox,
                                      gnc_get_current_book (), &owner);
    gnc_option_set_widget (option, widget);

    g_signal_connect (G_OBJECT (widget), "changed",
                      G_CALLBACK (gnc_option_changed_option_cb), option);

    return widget;
}
Exemple #3
0
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
{
    GncGUID *guid = NULL;
    QofBook *book;
    GncOwnerType type = GNC_OWNER_NONE;

    if (!lot || !owner) return FALSE;

    book = gnc_lot_get_book (lot);
    qof_instance_get (QOF_INSTANCE (lot),
		      "owner-type", &type,
		      "owner-guid", &guid,
		      NULL);
    switch (type)
    {
    case GNC_OWNER_CUSTOMER:
        gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
        break;
    case GNC_OWNER_VENDOR:
        gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
        break;
    case GNC_OWNER_EMPLOYEE:
        gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
        break;
    case GNC_OWNER_JOB:
        gncOwnerInitJob (owner, gncJobLookup (book, guid));
        break;
    default:
        return FALSE;
    }

    return (owner->owner.undefined != NULL);
}
Exemple #4
0
void
qofOwnerSetEntity (GncOwner *owner, QofInstance *ent)
{
    if (!owner || !ent)
    {
        return;
    }
    if (0 == g_strcmp0(ent->e_type, GNC_ID_CUSTOMER))
    {
        owner->type = GNC_OWNER_CUSTOMER;
        gncOwnerInitCustomer(owner, (GncCustomer*)ent);
    }
    else if (0 == g_strcmp0(ent->e_type, GNC_ID_JOB))
    {
        owner->type = GNC_OWNER_JOB;
        gncOwnerInitJob(owner, (GncJob*)ent);
    }
    else if (0 == g_strcmp0(ent->e_type, GNC_ID_VENDOR))
    {
        owner->type = GNC_OWNER_VENDOR;
        gncOwnerInitVendor(owner, (GncVendor*)ent);
    }
    else if (0 == g_strcmp0(ent->e_type, GNC_ID_EMPLOYEE))
    {
        owner->type = GNC_OWNER_EMPLOYEE;
        gncOwnerInitEmployee(owner, (GncEmployee*)ent);
    }
    else
    {
        owner->type = GNC_OWNER_NONE;
        owner->owner.undefined = NULL;
    }
}
Exemple #5
0
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid)
{
    if (!book || !owner || !type || !guid) return FALSE;

    if (0 == g_strcmp0(type, GNC_ID_CUSTOMER))
    {
        GncCustomer *customer = gncCustomerLookup(book, guid);
        gncOwnerInitCustomer(owner, customer);
        return (NULL != customer);
    }
    else if (0 == g_strcmp0(type, GNC_ID_JOB))
    {
        GncJob *job = gncJobLookup(book, guid);
        gncOwnerInitJob(owner, job);
        return (NULL != job);
    }
    else if (0 == g_strcmp0(type, GNC_ID_VENDOR))
    {
        GncVendor *vendor = gncVendorLookup(book, guid);
        gncOwnerInitVendor(owner, vendor);
        return (NULL != vendor);
    }
    else if (0 == g_strcmp0(type, GNC_ID_EMPLOYEE))
    {
        GncEmployee *employee = gncEmployeeLookup(book, guid);
        gncOwnerInitEmployee(owner, employee);
        return (NULL != employee);
    }
    return 0;
}
Exemple #6
0
static void
invoice_job_cb (gpointer *job_p, gpointer user_data)
{
    struct _job_select_window * sw = user_data;
    GncJob *job;
    GncOwner owner;

    g_return_if_fail (job_p && user_data);

    job = *job_p;
    if (!job)
        return;

    gncOwnerInitJob (&owner, job);
    gnc_invoice_search (NULL, &owner, sw->book);
}
static void
gnc_plugin_page_owner_tree_cmd_new_invoice (GtkAction *action,
        GncPluginPageOwnerTree *page)
{
    GncPluginPageOwnerTreePrivate *priv;
    GncOwner current_owner;

    ENTER("action %p, page %p", action, page);

    priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
    switch (priv->owner_type)
    {
    case GNC_OWNER_NONE :
    case GNC_OWNER_UNDEFINED :
        gncOwnerInitUndefined(&current_owner, NULL);
        break;
    case GNC_OWNER_CUSTOMER :
    {
        gncOwnerInitCustomer(&current_owner,
                             gncOwnerGetCustomer(gnc_plugin_page_owner_tree_get_current_owner (page)) );
        break;
    }
    case GNC_OWNER_JOB :
    {
        gncOwnerInitJob(&current_owner,
                        gncOwnerGetJob(gnc_plugin_page_owner_tree_get_current_owner (page)) );
        break;
    }
    case GNC_OWNER_VENDOR :
    {
        gncOwnerInitVendor(&current_owner,
                           gncOwnerGetVendor(gnc_plugin_page_owner_tree_get_current_owner (page)) );
        break;
    }
    case GNC_OWNER_EMPLOYEE :
    {
        gncOwnerInitEmployee(&current_owner,
                             gncOwnerGetEmployee(gnc_plugin_page_owner_tree_get_current_owner (page)) );
        break;
    }
    }

    if (gncOwnerGetType(&current_owner) != GNC_OWNER_UNDEFINED)
        gnc_ui_invoice_new (&current_owner, gnc_get_current_book());

    LEAVE(" ");
}
Exemple #8
0
static void
payment_job_cb (gpointer *job_p, gpointer user_data)
{
    struct _job_select_window *sw = user_data;
    GncOwner owner;
    GncJob *job;

    g_return_if_fail (job_p && user_data);

    job = *job_p;

    if (!job)
        return;

    gncOwnerInitJob (&owner, job);
    gnc_ui_payment_new (&owner, sw->book);
    return;
}
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;
}
Exemple #11
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);
}