[Gnucash-changes] Implementing QOF_TYPE_COLLECT in business objects
Neil Williams
codehelp at cvs.gnucash.org
Sun May 8 16:42:29 EDT 2005
Log Message:
-----------
Implementing QOF_TYPE_COLLECT in business objects
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash:
ChangeLog
gnucash/src/business/business-core:
gncInvoice.c
gncInvoice.h
gncOwner.c
gncOwner.h
Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.203
retrieving revision 1.1487.2.204
diff -LChangeLog -LChangeLog -u -r1.1487.2.203 -r1.1487.2.204
--- ChangeLog
+++ ChangeLog
@@ -1,4 +1,13 @@
2005-05-08 Neil Williams <linux at codehelp.co.uk>
+ * src/business/business-core/gncInvoice.c: Implementing
+ QOF_TYPE_COLLECT.
+ * src/business/business-core/gncInvoice.h: New functions to
+ support collections.
+ * src/business/business-core/gncOwner.c: Invoice collection
+ support.
+ * src/business/business-core/gncOwner.h: Doxygen and declarations.
+
+2005-05-08 Neil Williams <linux at codehelp.co.uk>
* src/backend/file/test/.cvsignore: Tweak
* src/backend/qsf/qsf-backend.c: Handling collections
in QSF
Index: gncOwner.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-core/gncOwner.c,v
retrieving revision 1.15.4.4
retrieving revision 1.15.4.5
diff -Lsrc/business/business-core/gncOwner.c -Lsrc/business/business-core/gncOwner.c -u -r1.15.4.4 -r1.15.4.5
--- src/business/business-core/gncOwner.c
+++ src/business/business-core/gncOwner.c
@@ -117,6 +117,77 @@
qofOwnerSetOwner(owner, NULL);
}
+QofIdType
+qofOwnerGetType(GncOwner *owner)
+{
+ gchar *type;
+
+ type = NULL;
+ switch(owner->type)
+ {
+ case GNC_OWNER_NONE : {
+ type = NULL;
+ break;
+ }
+ case GNC_OWNER_UNDEFINED : {
+ type = NULL;
+ break;
+ }
+ case GNC_OWNER_CUSTOMER : {
+ type = g_strdup(GNC_ID_CUSTOMER);
+ break;
+ }
+ case GNC_OWNER_JOB : {
+ type = g_strdup(GNC_ID_JOB);
+ break;
+ }
+ case GNC_OWNER_VENDOR : {
+ type = g_strdup(GNC_ID_VENDOR);
+ break;
+ }
+ case GNC_OWNER_EMPLOYEE : {
+ type = g_strdup(GNC_ID_EMPLOYEE);
+ break;
+ }
+ }
+ return (QofIdType)type;
+}
+
+QofEntity*
+qofOwnerGetOwner (GncOwner *owner)
+{
+ QofEntity *ent;
+
+ if(!owner) { return NULL; }
+ ent = NULL;
+ switch(owner->type)
+ {
+ case GNC_OWNER_NONE : {
+ break;
+ }
+ case GNC_OWNER_UNDEFINED : {
+ break;
+ }
+ case GNC_OWNER_CUSTOMER : {
+ ent = (QofEntity*)owner->owner.customer;
+ break;
+ }
+ case GNC_OWNER_JOB : {
+ ent = (QofEntity*)owner->owner.job;
+ break;
+ }
+ case GNC_OWNER_VENDOR : {
+ ent = (QofEntity*)owner->owner.vendor;
+ break;
+ }
+ case GNC_OWNER_EMPLOYEE : {
+ ent = (QofEntity*)owner->owner.employee;
+ break;
+ }
+ }
+ return ent;
+}
+
char*
qofOwnerGetTypeString(GncOwner *owner)
{
@@ -128,6 +199,33 @@
}
void
+qofOwnerSetEntity (GncOwner *owner, QofEntity *ent)
+{
+ if(!owner || !ent) { return; }
+ if(0 == safe_strcmp(ent->e_type, GNC_ID_CUSTOMER))
+ {
+ owner->type = GNC_OWNER_CUSTOMER;
+ gncOwnerInitCustomer(owner, (GncCustomer*)ent);
+ }
+ if(0 == safe_strcmp(ent->e_type, GNC_ID_JOB))
+ {
+ owner->type = GNC_OWNER_JOB;
+ gncOwnerInitJob(owner, (GncJob*)ent);
+ }
+ if(0 == safe_strcmp(ent->e_type, GNC_ID_VENDOR))
+ {
+ owner->type = GNC_OWNER_VENDOR;
+ gncOwnerInitVendor(owner, (GncVendor*)ent);
+ }
+ if(0 == safe_strcmp(ent->e_type, GNC_ID_EMPLOYEE))
+ {
+ owner->type = GNC_OWNER_EMPLOYEE;
+ gncOwnerInitEmployee(owner, (GncEmployee*)ent);
+ }
+}
+
+
+void
qofOwnerSetOwner(GncOwner *owner, gpointer obj)
{
if(!owner) { return; }
Index: gncInvoice.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-core/gncInvoice.c,v
retrieving revision 1.56.4.9
retrieving revision 1.56.4.10
diff -Lsrc/business/business-core/gncInvoice.c -Lsrc/business/business-core/gncInvoice.c -u -r1.56.4.9 -r1.56.4.10
--- src/business/business-core/gncInvoice.c
+++ src/business/business-core/gncInvoice.c
@@ -258,6 +258,44 @@
gncInvoiceCommitEdit (invoice);
}
+static void
+qofInvoiceOwnerCB (QofEntity *ent, gpointer user_data)
+{
+ GncInvoice *invoice;
+
+ invoice = (GncInvoice*)user_data;
+ qofOwnerSetEntity(&invoice->owner, ent);
+}
+
+void
+qofInvoiceSetOwner (GncInvoice *invoice, QofCollection *coll)
+{
+ if(!invoice || !coll) { return; }
+ gncInvoiceBeginEdit (invoice);
+ qof_collection_foreach(coll, qofInvoiceOwnerCB, invoice);
+ mark_invoice (invoice);
+ gncInvoiceCommitEdit (invoice);
+}
+
+static void
+qofInvoiceBillToCB (QofEntity *ent, gpointer user_data)
+{
+ GncInvoice *invoice;
+
+ invoice = (GncInvoice*)user_data;
+ qofOwnerSetEntity(&invoice->billto, ent);
+}
+
+void
+qofInvoiceSetBillTo (GncInvoice *invoice, QofCollection *coll)
+{
+ if(!invoice || !coll) { return; }
+ gncInvoiceBeginEdit (invoice);
+ qof_collection_foreach(coll, qofInvoiceBillToCB, invoice);
+ mark_invoice (invoice);
+ gncInvoiceCommitEdit (invoice);
+}
+
void gncInvoiceSetDateOpened (GncInvoice *invoice, Timespec date)
{
if (!invoice) return;
@@ -449,6 +487,28 @@
return &invoice->owner;
}
+QofCollection*
+qofInvoiceGetOwner (GncInvoice *invoice)
+{
+ QofCollection *owner_coll;
+
+ if(!invoice) { return NULL; }
+ owner_coll = qof_collection_new(qofOwnerGetType(&invoice->owner));
+ qof_collection_add_entity(owner_coll, qofOwnerGetOwner(&invoice->owner));
+ return owner_coll;
+}
+
+QofCollection*
+qofInvoiceGetBillTo (GncInvoice *invoice)
+{
+ QofCollection *bill_coll;
+
+ if(!invoice) { return NULL; }
+ bill_coll = qof_collection_new(qofOwnerGetType(&invoice->billto));
+ qof_collection_add_entity(bill_coll, qofOwnerGetOwner(&invoice->billto));
+ return bill_coll;
+}
+
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice)
{
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
@@ -626,45 +686,49 @@
return invoice->entries;
}
-/* test to see how to get the list of entries. */
-KvpFrame*
+QofCollection*
qofInvoiceGetEntries (GncInvoice *invoice)
{
- KvpFrame *invoice_frame;
- KvpValue *entry_value;
- GList *entry_list, *i;
+ QofCollection *entry_coll;
+ GList *list;
QofEntity *entry;
- const GUID *entry_guid;
- const char *entry_path;
- entry_list = NULL;
- entry_value = NULL;
- entry_path = g_strdup("Invoice/Entry");
- invoice_frame = kvp_frame_new();
- entry_list = gncInvoiceGetEntries(invoice);
- for(i = entry_list; i != NULL; i = i->next)
+ entry_coll = qof_collection_new(GNC_ID_ENTRY);
+ for(list = gncInvoiceGetEntries(invoice); list != NULL; list = list->next)
{
- entry = (QofEntity*)entry_list->data;
- entry_guid = qof_entity_get_guid(entry);
- kvp_frame_add_guid(invoice_frame, entry_path, entry_guid);
+ entry = (QofEntity*)list->data;
+ qof_collection_add_entity(entry_coll, entry);
+ }
+ return entry_coll;
+}
+
+static void
+qofInvoiceEntryCB (QofEntity *ent, gpointer user_data)
+{
+ GncInvoice *invoice;
+
+ invoice = (GncInvoice*)user_data;
+ if(!invoice || !ent) { return; }
+ switch (gncInvoiceGetOwnerType (invoice)) {
+ case GNC_OWNER_VENDOR: {
+ gncBillAddEntry (invoice, (GncEntry*) ent);
+ break;
+ }
+ default : {
+ gncInvoiceAddEntry(invoice, (GncEntry*)ent);
+ break;
+ }
}
- return invoice_frame;
}
void
-qofInvoiceSetEntries(GncInvoice *invoice, KvpFrame *invoice_frame)
+qofInvoiceSetEntries(GncInvoice *invoice, QofCollection *entry_coll)
{
- GList *entry_list;
- KvpValue *entry_value;
- const char *entry_path;
-
- entry_path = g_strdup("Invoice/Entry");
- entry_value = kvp_frame_get_slot_path(invoice_frame, entry_path);
- for(entry_list = kvp_value_get_glist(entry_value); entry_list != NULL; entry_list = entry_list->next)
+ if(!entry_coll) { return; }
+ if(0 == safe_strcmp(qof_collection_get_type(entry_coll), GNC_ID_ENTRY))
{
- gncInvoiceAddEntry(invoice, (GncEntry*)entry_list->data);
+ qof_collection_foreach(entry_coll, qofInvoiceEntryCB, invoice);
}
- kvp_frame_delete(invoice_frame);
}
GncJob*
@@ -1482,7 +1546,7 @@
{
static QofParam params[] = {
{ INVOICE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID, (QofSetterFunc)gncInvoiceSetID },
- { INVOICE_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL },
+ { INVOICE_OWNER, QOF_TYPE_COLLECT, (QofAccessFunc)gncInvoiceGetOwner, (QofSetterFunc)qofInvoiceSetOwner },
{ INVOICE_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened, (QofSetterFunc)gncInvoiceSetDateOpened },
{ INVOICE_DUE, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateDue, NULL },
{ INVOICE_POSTED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted, (QofSetterFunc)gncInvoiceSetDatePosted },
@@ -1495,8 +1559,8 @@
{ INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot, NULL/*(QofSetterFunc)gncInvoiceSetPostedLot*/ },
{ INVOICE_TYPE, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetType, NULL },
{ INVOICE_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms, (QofSetterFunc)gncInvoiceSetTerms },
- { INVOICE_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL },
- { INVOICE_ENTRIES, QOF_TYPE_KVP, (QofAccessFunc)qofInvoiceGetEntries, (QofSetterFunc)qofInvoiceSetEntries },
+ { INVOICE_BILLTO, QOF_TYPE_COLLECT, (QofAccessFunc)qofInvoiceGetBillTo, (QofSetterFunc)qofInvoiceSetBillTo },
+ { INVOICE_ENTRIES, QOF_TYPE_COLLECT, (QofAccessFunc)qofInvoiceGetEntries, (QofSetterFunc)qofInvoiceSetEntries },
{ INVOICE_JOB, GNC_ID_JOB, (QofAccessFunc)qofInvoiceGetJob, (QofSetterFunc)qofInvoiceSetJob },
{ QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive, (QofSetterFunc)gncInvoiceSetActive },
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
Index: gncInvoice.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-core/gncInvoice.h,v
retrieving revision 1.29.4.6
retrieving revision 1.29.4.7
diff -Lsrc/business/business-core/gncInvoice.h -Lsrc/business/business-core/gncInvoice.h -u -r1.29.4.6 -r1.29.4.7
--- src/business/business-core/gncInvoice.h
+++ src/business/business-core/gncInvoice.h
@@ -70,17 +70,16 @@
void gncInvoiceSetActive (GncInvoice *invoice, gboolean active);
void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto);
void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount);
-void qofInvoiceSetOwner (GncInvoice *invoice, QofEntity *ent);
+void qofInvoiceSetOwner (GncInvoice *invoice, QofCollection *coll);
+void qofInvoiceSetBillTo (GncInvoice *invoice, QofCollection *coll);
/** \brief create the entry list from a temporary frame.
An invoice can hold an open ended list of entries that are summed to
make the total payable. To represent these entries within the invoice,
-KVP is used to list the references to the GncEntry's for the invoice.
-
-The KvpFrame of KVP_TYPE_GLIST KvpValues is converted to the internal
-GList of entries for this invoice.
+QOF_TYPE_COLLECT is used to list the references to the GncEntry's for
+the invoice. The collection contains a number of GncEntry objects.
*/
-void qofInvoiceSetEntries(GncInvoice *invoice, KvpFrame *invoice_frame);
+void qofInvoiceSetEntries(GncInvoice *invoice, QofCollection *entry_coll);
void qofInvoiceSetJob (GncInvoice *invoice, GncJob *job);
/** @} */
@@ -110,8 +109,10 @@
Converts the GList of GncEntry inside GncInvoice to a KVP_TYPE_GLIST.
*/
-KvpFrame* qofInvoiceGetEntries (GncInvoice *invoice);
+QofCollection* qofInvoiceGetEntries (GncInvoice *invoice);
GncJob* qofInvoiceGetJob (GncInvoice *invoice);
+QofCollection* qofInvoiceGetOwner (GncInvoice *invoice);
+QofCollection* qofInvoiceGetBillTo (GncInvoice *invoice);
GNCLot * gncInvoiceGetPostedLot (GncInvoice *invoice);
Transaction * gncInvoiceGetPostedTxn (GncInvoice *invoice);
Index: gncOwner.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/business/business-core/gncOwner.h,v
retrieving revision 1.12.4.4
retrieving revision 1.12.4.5
diff -Lsrc/business/business-core/gncOwner.h -Lsrc/business/business-core/gncOwner.h -u -r1.12.4.4 -r1.12.4.5
--- src/business/business-core/gncOwner.h
+++ src/business/business-core/gncOwner.h
@@ -65,6 +65,12 @@
void qofOwnerSetType(GncOwner *owner, const char* type_string);
/** \brief Allow the union to be set independently of the type. */
char* qofOwnerGetTypeString(GncOwner *owner);
+/** return the type for the collection. */
+QofIdType qofOwnerGetType(GncOwner *owner);
+/** return the owner itself as an entity. */
+QofEntity* qofOwnerGetOwner (GncOwner *owner);
+/** set the owner from the entity. */
+void qofOwnerSetEntity (GncOwner *owner, QofEntity *ent);
/** \brief QOF union set routine.
More information about the gnucash-changes
mailing list