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; }
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; }
/** 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; }