mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-29 20:24:25 -06:00
add clone functions to employee, misc minor cleanup to bill term entity funcs
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9594 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
30914441f3
commit
77fd3e74ce
@ -94,9 +94,6 @@ static short module = MOD_BUSINESS;
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
static void add_or_rem_object (GncBillTerm *term, gboolean add);
|
||||
static void maybe_resort_list (GncBillTerm *term);
|
||||
|
||||
/* ============================================================== */
|
||||
/* Misc inline utilities */
|
||||
|
||||
@ -117,49 +114,32 @@ static inline void maybe_resort_list (GncBillTerm *term)
|
||||
bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare);
|
||||
}
|
||||
|
||||
static inline void add_or_rem_object (GncBillTerm *term, gboolean add)
|
||||
{
|
||||
struct _book_info *bi;
|
||||
|
||||
if (!term) return;
|
||||
bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME);
|
||||
|
||||
if (add)
|
||||
bi->terms = g_list_insert_sorted (bi->terms, term,
|
||||
(GCompareFunc)gncBillTermCompare);
|
||||
else
|
||||
bi->terms = g_list_remove (bi->terms, term);
|
||||
}
|
||||
|
||||
static inline void addObj (GncBillTerm *term)
|
||||
{
|
||||
add_or_rem_object (term, TRUE);
|
||||
struct _book_info *bi;
|
||||
bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME);
|
||||
bi->terms = g_list_insert_sorted (bi->terms, term,
|
||||
(GCompareFunc)gncBillTermCompare);
|
||||
}
|
||||
|
||||
static inline void remObj (GncBillTerm *term)
|
||||
{
|
||||
add_or_rem_object (term, FALSE);
|
||||
struct _book_info *bi;
|
||||
bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME);
|
||||
bi->terms = g_list_remove (bi->terms, term);
|
||||
}
|
||||
|
||||
static inline void
|
||||
gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child)
|
||||
{
|
||||
g_return_if_fail(table);
|
||||
g_return_if_fail(child);
|
||||
g_return_if_fail(table->inst.do_free == FALSE);
|
||||
|
||||
table->children = g_list_prepend(table->children, child);
|
||||
}
|
||||
|
||||
static inline void
|
||||
gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child)
|
||||
{
|
||||
g_return_if_fail(table);
|
||||
g_return_if_fail(child);
|
||||
|
||||
if (table->inst.do_free)
|
||||
return;
|
||||
|
||||
if (table->inst.do_free) return;
|
||||
table->children = g_list_remove(table->children, child);
|
||||
}
|
||||
|
||||
@ -225,7 +205,7 @@ gncCloneBillTerm (GncBillTerm *from, QofBook *book)
|
||||
GList *node;
|
||||
GncBillTerm *term;
|
||||
|
||||
if (!book) return NULL;
|
||||
if (!book || !from) return NULL;
|
||||
|
||||
term = g_new0 (GncBillTerm, 1);
|
||||
qof_instance_init(&term->inst, _GNC_MOD_NAME, book);
|
||||
@ -284,16 +264,6 @@ gncBillTermObtainTwin (GncBillTerm *from, QofBook *book)
|
||||
/* ============================================================== */
|
||||
/* Set Functions */
|
||||
|
||||
void gncBillTermSetGUID (GncBillTerm *term, const GUID *guid)
|
||||
{
|
||||
if (!term || !guid) return;
|
||||
if (guid_equal (guid, &term->inst.entity.guid)) return;
|
||||
|
||||
remObj (term);
|
||||
qof_entity_set_guid (&term->inst.entity, guid);
|
||||
addObj (term);
|
||||
}
|
||||
|
||||
void gncBillTermSetName (GncBillTerm *term, const char *name)
|
||||
{
|
||||
if (!term || !name) return;
|
||||
@ -419,7 +389,7 @@ void gncBillTermMakeInvisible (GncBillTerm *term)
|
||||
if (!term) return;
|
||||
gncBillTermBeginEdit (term);
|
||||
term->invisible = TRUE;
|
||||
add_or_rem_object (term, FALSE);
|
||||
remObj (term);
|
||||
gncBillTermCommitEdit (term);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ typedef struct _gncBillTerm GncBillTerm;
|
||||
#include "gnc-date.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
#include "qofinstance.h"
|
||||
#include "gncBusiness.h"
|
||||
|
||||
|
@ -29,11 +29,11 @@
|
||||
#ifndef GNC_BILLTERMP_H_
|
||||
#define GNC_BILLTERMP_H_
|
||||
|
||||
#include "qofid-p.h"
|
||||
#include "gncBillTerm.h"
|
||||
|
||||
gboolean gncBillTermRegister (void);
|
||||
|
||||
void gncBillTermSetGUID (GncBillTerm *term, const GUID *guid);
|
||||
void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent);
|
||||
void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child);
|
||||
void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount);
|
||||
@ -65,5 +65,7 @@ GncBillTerm * gncCloneBillTerm (GncBillTerm *from, QofBook *);
|
||||
*/
|
||||
GncBillTerm * gncBillTermObtainTwin (GncBillTerm *from, QofBook *book);
|
||||
|
||||
#define gncBillTermSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
|
||||
|
||||
|
||||
#endif /* GNC_BILLTERMP_H_ */
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@ -54,13 +55,13 @@
|
||||
|
||||
struct _gncEmployee
|
||||
{
|
||||
QofInstance inst;
|
||||
QofInstance inst;
|
||||
char * id;
|
||||
char * username;
|
||||
GncAddress * addr;
|
||||
gnc_commodity * currency;
|
||||
gboolean active;
|
||||
|
||||
|
||||
char * language;
|
||||
char * acl;
|
||||
gnc_numeric workday;
|
||||
@ -85,6 +86,7 @@ mark_employee (GncEmployee *employee)
|
||||
gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncEmployee *gncEmployeeCreate (QofBook *book)
|
||||
@ -133,6 +135,49 @@ static void gncEmployeeFree (GncEmployee *employee)
|
||||
g_free (employee);
|
||||
}
|
||||
|
||||
GncEmployee *
|
||||
gncCloneEmployee (GncEmployee *from, QofBook *book)
|
||||
{
|
||||
GncEmployee *employee;
|
||||
if (!book || !from) return NULL;
|
||||
|
||||
employee = g_new0 (GncEmployee, 1);
|
||||
qof_instance_init(&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, book);
|
||||
employee->workday = from->workday;
|
||||
employee->rate = from->rate;
|
||||
employee->active = from->active;
|
||||
employee->currency = from->currency;
|
||||
employee->ccard_acc =
|
||||
GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book));
|
||||
|
||||
gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return employee;
|
||||
}
|
||||
|
||||
GncEmployee *
|
||||
gncEmployeeObtainTwin (GncEmployee *from, QofBook *book)
|
||||
{
|
||||
GncEmployee *employee;
|
||||
if (!book) return NULL;
|
||||
|
||||
employee = (GncEmployee *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!employee)
|
||||
{
|
||||
employee = gncCloneEmployee (from, book);
|
||||
}
|
||||
|
||||
return employee;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Set Functions */
|
||||
|
||||
#define SET_STR(obj, member, str) { \
|
||||
@ -233,6 +278,7 @@ void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc)
|
||||
gncEmployeeCommitEdit (employee);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Get Functions */
|
||||
const char * gncEmployeeGetID (GncEmployee *employee)
|
||||
{
|
||||
@ -330,6 +376,7 @@ void gncEmployeeCommitEdit (GncEmployee *employee)
|
||||
gncEmployeeOnDone, emp_free);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Other functions */
|
||||
|
||||
int gncEmployeeCompare (GncEmployee *a, GncEmployee *b)
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@ -34,6 +35,29 @@
|
||||
gboolean gncEmployeeRegister (void);
|
||||
gint64 gncEmployeeNextID (QofBook *book);
|
||||
|
||||
/** The gncCloneEmployee() routine makes a copy of the indicated
|
||||
* employee, placing it in the indicated book. It copies
|
||||
* the username, address, currency, ccard account, etc.
|
||||
* It also copies (as needed) both parents and children, so that
|
||||
* the parent-child relationship is correctly mirrored in the
|
||||
* clone.
|
||||
* It then adds a pair of 'gemini' kvp pointers so that each copy
|
||||
* can be found from the other.
|
||||
*/
|
||||
|
||||
GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *);
|
||||
|
||||
/** The gncEmployeeObtainTwin() will find the 'twin' of the
|
||||
* indicated employee in the indicated book. If the twin doesn't
|
||||
* yet exist in the book, it will be created (by calling
|
||||
* gncCloneEmployee()) and placed into the book.
|
||||
*
|
||||
* We called this routine 'Obtain' instead of "Get" to distinguish
|
||||
* it from the other Get routines, which work in fundamentally
|
||||
* different ways.
|
||||
*/
|
||||
GncEmployee * gncEmployeeObtainTwin (GncEmployee *from, QofBook *book);
|
||||
|
||||
#define gncEmployeeSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
|
||||
|
||||
#endif /* GNC_EMPLOYEEP_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user