Example #1
0
/* Create/Destroy Functions */
GncCustomer *gncCustomerCreate (QofBook *book)
{
    GncCustomer *cust;

    if (!book) return NULL;

    cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
    qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);

    cust->id = CACHE_INSERT ("");
    cust->name = CACHE_INSERT ("");
    cust->notes = CACHE_INSERT ("");
    cust->addr = gncAddressCreate (book, &cust->inst);
    cust->taxincluded = GNC_TAXINCLUDED_USEGLOBAL;
    cust->active = TRUE;
    cust->jobs = NULL;

    cust->discount = gnc_numeric_zero();
    cust->credit = gnc_numeric_zero();
    cust->shipaddr = gncAddressCreate (book, &cust->inst);

    if (gs_address_event_handler_id == 0)
    {
        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
    }

    qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);

    return cust;
}
Example #2
0
/* Create/Destroy Functions */
GncEntry *gncEntryCreate (QofBook *book)
{
    GncEntry *entry;
    gnc_numeric zero = gnc_numeric_zero ();

    if (!book) return NULL;

    entry = g_object_new (GNC_TYPE_ENTRY, NULL);
    qof_instance_init_data (&entry->inst, _GNC_MOD_NAME, book);

    entry->desc = CACHE_INSERT ("");
    entry->action = CACHE_INSERT ("");
    entry->notes = CACHE_INSERT ("");
    entry->quantity = zero;

    entry->i_price = zero;
    entry->i_taxable = TRUE;
    entry->i_discount = zero;
    entry->i_disc_type = GNC_AMT_TYPE_PERCENT;
    entry->i_disc_how = GNC_DISC_PRETAX;

    entry->b_price = zero;
    entry->b_taxable = TRUE;
    entry->billto.type = GNC_OWNER_CUSTOMER;
    entry->b_payment = GNC_PAYMENT_CASH;

    entry->values_dirty = TRUE;

    qof_event_gen (&entry->inst, QOF_EVENT_CREATE, NULL);

    return entry;
}
Example #3
0
/* Create/Destroy Functions */
GncEmployee *gncEmployeeCreate (QofBook *book)
{
    GncEmployee *employee;

    if (!book) return NULL;

    employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
    qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book);

    employee->id = CACHE_INSERT ("");
    employee->username = CACHE_INSERT ("");
    employee->language = CACHE_INSERT ("");
    employee->acl = CACHE_INSERT ("");
    employee->addr = gncAddressCreate (book, &employee->inst);
    employee->workday = gnc_numeric_zero();
    employee->rate = gnc_numeric_zero();
    employee->active = TRUE;

    if (gs_address_event_handler_id == 0)
    {
        gs_address_event_handler_id = qof_event_register_handler(listen_for_address_events, NULL);
    }

    qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);

    return employee;
}
Example #4
0
GncEmployee *
gncCloneEmployee (GncEmployee *from, QofBook *book)
{
    GncEmployee *employee;
    if (!book || !from) return NULL;

    employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
    qof_instance_init_data(&employee->inst, _GNC_MOD_NAME, book);
    qof_instance_gemini (&employee->inst, &from->inst);

    employee->id = CACHE_INSERT (from->id);
    employee->username = CACHE_INSERT (from->username);
    employee->language = CACHE_INSERT (from->language);
    employee->acl = CACHE_INSERT (from->acl);
    employee->addr = gncCloneAddress (from->addr, &employee->inst, book);
    employee->workday = from->workday;
    employee->rate = from->rate;
    employee->active = from->active;
    employee->currency = gnc_commodity_obtain_twin(from->currency, book);
    employee->ccard_acc =
        GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book));

    qof_event_gen (&employee->inst, QOF_EVENT_CREATE, NULL);

    return employee;
}
Example #5
0
/* Create/Destroy Functions */
GncTaxTable *
gncTaxTableCreate (QofBook *book)
{
    GncTaxTable *table;
    if (!book) return NULL;

    table = g_object_new (GNC_TYPE_TAXTABLE, NULL);
    qof_instance_init_data (&table->inst, _GNC_MOD_NAME, book);
    table->name = CACHE_INSERT ("");
    addObj (table);
    qof_event_gen (&table->inst, QOF_EVENT_CREATE, NULL);
    return table;
}
Example #6
0
static void
book_sxes_setup(QofBook *book)
{
    QofCollection *col;
    SchedXactions *sxes;

    col = qof_book_get_collection(book, GNC_ID_SCHEDXACTION);
    sxes = g_object_new (GNC_TYPE_SCHEDXACTIONS, NULL);
    g_assert(sxes);
    qof_instance_init_data(&sxes->inst, GNC_ID_SXES, book);
    sxes->sx_list = NULL;
    sxes->sx_notsaved = TRUE;
    qof_collection_set_data(col, sxes);
}
Example #7
0
/* Create/Destroy Functions */
GncBillTerm * gncBillTermCreate (QofBook *book)
{
    GncBillTerm *term;
    if (!book) return NULL;

    term = g_object_new (GNC_TYPE_BILLTERM, NULL);
    qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book);
    term->name = CACHE_INSERT ("");
    term->desc = CACHE_INSERT ("");
    term->discount = gnc_numeric_zero ();
    addObj (term);
    qof_event_gen (&term->inst,  QOF_EVENT_CREATE, NULL);
    return term;
}
Example #8
0
GncBillTerm *
gncCloneBillTerm (GncBillTerm *from, QofBook *book)
{
    GList *node;
    GncBillTerm *term;

    if (!book || !from) return NULL;

    term = g_object_new (GNC_TYPE_BILLTERM, NULL);
    qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book);
    qof_instance_gemini (&term->inst, &from->inst);

    term->name = CACHE_INSERT (from->name);
    term->desc = CACHE_INSERT (from->desc);
    term->type = from->type;
    term->due_days = from->due_days;
    term->disc_days = from->disc_days;
    term->discount = from->discount;
    term->cutoff = from->cutoff;
    term->invisible = from->invisible;

    term->refcount = 0;

    /* Make copies of parents and children. Note that this can be
     * a recursive copy ... treat as doubly-linked list. */
    if (from->child)
    {
        term->child = gncBillTermObtainTwin (from->child, book);
        term->child->parent = term;
    }
    if (from->parent)
    {
        term->parent = gncBillTermObtainTwin (from->parent, book);
        term->parent->child = term;
    }
    for (node = g_list_last(from->children); node; node = node->next)
    {
        GncBillTerm *btrm = node->data;
        btrm = gncBillTermObtainTwin (btrm, book);
        btrm->parent = term;
        term->children = g_list_prepend(term->children, btrm);
    }

    addObj (term);
    qof_event_gen (&term->inst, QOF_EVENT_CREATE, NULL);
    return term;
}
Example #9
0
static void
qof_book_init (QofBook *book)
{
    if (!book) return;

    book->hash_of_collections = g_hash_table_new_full(
                                    g_str_hash, g_str_equal,
                                    (GDestroyNotify)qof_util_string_cache_remove,  /* key_destroy_func   */
                                    coll_destroy);                            /* value_destroy_func */

    qof_instance_init_data (&book->inst, QOF_ID_BOOK, book);

    book->data_tables = g_hash_table_new (g_str_hash, g_str_equal);
    book->data_table_finalizers = g_hash_table_new (g_str_hash, g_str_equal);

    book->book_open = 'y';
    book->version = 0;
}
Example #10
0
mychild*
child_create(QofBook *book)
{
    mychild *g;

    g_return_val_if_fail(book, NULL);
    g = g_object_new(GNC_TYPE_MYCHILD, NULL);
    qof_instance_init_data (&g->inst, CHILD_MODULE_NAME, book);
    g->date = *get_random_timespec();
    g->discount = get_random_double();
    g->active = get_random_boolean();
    g->version = get_random_int_in_range(1, 10000);
    g->minor = get_random_int_in_range(100001, 99999999);
    g->flag = get_random_character();
    g->Name = get_random_string();
    g->Amount = get_random_gnc_numeric();
    qof_event_gen(&g->inst, QOF_EVENT_CREATE, NULL);
    return g;
}
Example #11
0
File: gncJob.c Project: 573/gnucash
/* Create/Destroy Functions */
GncJob *gncJobCreate (QofBook *book)
{
    GncJob *job;

    if (!book) return NULL;

    job = g_object_new (GNC_TYPE_JOB, NULL);
    qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book);

    job->id = CACHE_INSERT ("");
    job->name = CACHE_INSERT ("");
    job->desc = CACHE_INSERT ("");
    job->active = TRUE;

    /* GncOwner not initialized */
    qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);

    return job;
}
Example #12
0
/** Create a copy of a customer, placing the copy into a new book. */
GncCustomer *
gncCloneCustomer (GncCustomer *from, QofBook *book)
{
    GList *node;
    GncCustomer *cust;

    cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);

    qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);
    qof_instance_gemini (&cust->inst, &from->inst);

    cust->id = CACHE_INSERT (from->id);
    cust->name = CACHE_INSERT (from->name);
    cust->notes = CACHE_INSERT (from->notes);
    cust->discount = from->discount;
    cust->credit = from->credit;
    cust->taxincluded = from->taxincluded;
    cust->active = from->active;
    cust->taxtable_override = from->taxtable_override;

    cust->addr = gncCloneAddress (from->addr, &cust->inst, book);
    cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst, book);

    /* Find the matching currency in the new book, assumes
     * currency has already been copied into new book. */
    cust->currency = gnc_commodity_obtain_twin (from->currency, book);

    /* Find the matching bill term, tax table in the new book */
    cust->terms = gncBillTermObtainTwin(from->terms, book);
    cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);

    for (node = g_list_last(cust->jobs); node; node = node->next)
    {
        GncJob *job = node->data;
        job = gncJobObtainTwin (job, book);
        cust->jobs = g_list_prepend(cust->jobs, job);
    }

    qof_event_gen (&cust->inst, QOF_EVENT_CREATE, NULL);

    return cust;
}
Example #13
0
static void
xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
{
    Account        *ra;
    const GncGUID *guid;
    gchar guidstr[GUID_ENCODING_LENGTH+1];

    qof_instance_init_data (&sx->inst, GNC_ID_SCHEDXACTION, book);

    /* create a new template account for our splits */
    sx->template_acct = xaccMallocAccount(book);
    guid = qof_instance_get_guid( sx );
    xaccAccountBeginEdit( sx->template_acct );
    guid_to_string_buff( guid, guidstr );
    xaccAccountSetName( sx->template_acct, guidstr);
    xaccAccountSetCommodity
    (sx->template_acct,
     gnc_commodity_table_lookup( gnc_commodity_table_get_table(book),
                                 "template", "template") );
    xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK );
    xaccAccountCommitEdit( sx->template_acct );
    ra = gnc_book_get_template_root( book );
    gnc_account_append_child( ra, sx->template_acct );
}
Example #14
0
GncAddress *
gncAddressCreate (QofBook *book, QofInstance *prnt)
{
    GncAddress *addr;

    if (!book) return NULL;

    addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
    qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book);
    addr->book = book;
    addr->dirty = FALSE;
    addr->parent = prnt;

    addr->name = CACHE_INSERT ("");
    addr->addr1 = CACHE_INSERT ("");
    addr->addr2 = CACHE_INSERT ("");
    addr->addr3 = CACHE_INSERT ("");
    addr->addr4 = CACHE_INSERT ("");
    addr->phone = CACHE_INSERT ("");
    addr->fax = CACHE_INSERT ("");
    addr->email = CACHE_INSERT ("");

    return addr;
}