diff --git a/src/business/business-core/Makefile.am b/src/business/business-core/Makefile.am index 86f2fd334c..8e2086e480 100644 --- a/src/business/business-core/Makefile.am +++ b/src/business/business-core/Makefile.am @@ -40,6 +40,7 @@ noinst_HEADERS = \ gncOrder.h \ gncOrderP.h \ gncOwner.h \ + gncOwnerP.h \ gncVendor.h \ gncVendorP.h diff --git a/src/business/business-core/businessmod-core.c b/src/business/business-core/businessmod-core.c index 5faefff233..b0c9b73c8e 100644 --- a/src/business/business-core/businessmod-core.c +++ b/src/business/business-core/businessmod-core.c @@ -19,6 +19,7 @@ #include "gncInvoiceP.h" #include "gncJobP.h" #include "gncOrderP.h" +#include "gncOwnerP.h" #include "gncVendorP.h" /* version of the gnc module system interface we require */ @@ -58,6 +59,7 @@ gnc_module_init(int refcount) gncInvoiceRegister (); gncJobRegister (); gncOrderRegister (); + gncOwnerRegister (); gncVendorRegister (); } diff --git a/src/business/business-core/gncOrder.c b/src/business/business-core/gncOrder.c index 1db4aa6f86..43476c980e 100644 --- a/src/business/business-core/gncOrder.c +++ b/src/business/business-core/gncOrder.c @@ -342,6 +342,7 @@ gboolean gncOrderRegister (void) { static QueryObjectDef params[] = { { ORDER_GUID, QUERYCORE_GUID, (QueryAccess)gncOrderGetGUID }, + { ORDER_OWNER, GNC_OWNER_MODULE_NAME, (QueryAccess)gncOrderGetOwner }, { QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncOrderGetBook }, { NULL }, }; diff --git a/src/business/business-core/gncOrder.h b/src/business/business-core/gncOrder.h index 47489bba88..73d6318510 100644 --- a/src/business/business-core/gncOrder.h +++ b/src/business/business-core/gncOrder.h @@ -54,5 +54,6 @@ void gncOrderCommitEdit (GncOrder *order); int gncOrderCompare (GncOrder *a, GncOrder *b); #define ORDER_GUID "guid" +#define ORDER_OWNER "owner" #endif /* GNC_ORDER_H_ */ diff --git a/src/business/business-core/gncOwner.c b/src/business/business-core/gncOwner.c index 755451ac16..30ab7128d9 100644 --- a/src/business/business-core/gncOwner.c +++ b/src/business/business-core/gncOwner.c @@ -9,7 +9,12 @@ #include #include /* for memcpy() */ +#include "QueryObject.h" + #include "gncOwner.h" +#include "gncOwnerP.h" + +#define _GNC_MOD_NAME GNC_OWNER_MODULE_NAME void gncOwnerInitUndefined (GncOwner *owner, gpointer obj) { @@ -104,4 +109,63 @@ const char * gncOwnerGetName (GncOwner *owner) } } +const GUID * gncOwnerGetGUID (GncOwner *owner) +{ + if (!owner) return NULL; + switch (owner->type) { + case GNC_OWNER_NONE: + case GNC_OWNER_UNDEFINED: + default: + return NULL; + case GNC_OWNER_CUSTOMER: + return gncCustomerGetGUID (owner->owner.customer); + case GNC_OWNER_JOB: + return gncJobGetGUID (owner->owner.job); + case GNC_OWNER_VENDOR: + return gncVendorGetGUID (owner->owner.vendor); + } +} + +GncOwner * gncOwnerGetEndOwner (GncOwner *owner) +{ + if (!owner) return NULL; + switch (owner->type) { + case GNC_OWNER_NONE: + case GNC_OWNER_UNDEFINED: + default: + return NULL; + case GNC_OWNER_CUSTOMER: + case GNC_OWNER_VENDOR: + return owner; + case GNC_OWNER_JOB: + return gncJobGetOwner (owner->owner.job); + } +} + +const GUID * gncOwnerGetEndGUID (GncOwner *owner) +{ + if (!owner) return NULL; + owner = gncOwnerGetEndOwner (owner); + return gncOwnerGetGUID (owner); +} + +gboolean gncOwnerRegister (void) +{ + static QueryObjectDef params[] = { + { OWNER_TYPE, QUERYCORE_INT64, (QueryAccess)gncOwnerGetType }, + { OWNER_CUSTOMER, GNC_CUSTOMER_MODULE_NAME, + (QueryAccess)gncOwnerGetCustomer }, + { OWNER_JOB, GNC_JOB_MODULE_NAME, (QueryAccess)gncOwnerGetJob }, + { OWNER_VENDOR, GNC_VENDOR_MODULE_NAME, (QueryAccess)gncOwnerGetVendor }, + { OWNER_GUID, QUERYCORE_GUID, (QueryAccess)gncOwnerGetGUID }, + { OWNER_PARENT, _GNC_MOD_NAME, (QueryAccess)gncOwnerGetEndOwner }, + { OWNER_PARENTG, QUERYCORE_GUID, (QueryAccess)gncOwnerGetEndGUID }, + { OWNER_NAME, QUERYCORE_STRING, (QueryAccess)gncOwnerGetName }, + { NULL }, + }; + + gncQueryObjectRegister (_GNC_MOD_NAME, (QuerySort)gncCustomerCompare,params); + + return TRUE; +} diff --git a/src/business/business-core/gncOwner.h b/src/business/business-core/gncOwner.h index 16bae8343a..5b4f5d5138 100644 --- a/src/business/business-core/gncOwner.h +++ b/src/business/business-core/gncOwner.h @@ -9,6 +9,8 @@ typedef struct gnc_owner_s GncOwner; +#define GNC_OWNER_MODULE_NAME "gncOwner" + #include "gncCustomer.h" #include "gncJob.h" #include "gncVendor.h" @@ -47,4 +49,23 @@ gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b); const char * gncOwnerGetName (GncOwner *owner); +/* Get the GUID of the immediate owner */ +const GUID * gncOwnerGetGUID (GncOwner *owner); + +/* + * Get the "parent" Owner or GUID thereof. The "parent" owner + * is the Customer or Vendor, or the Owner of a Job + */ +GncOwner * gncOwnerGetEndOwner (GncOwner *owner); +const GUID * gncOwnerGetEndGUID (GncOwner *owner); + +#define OWNER_TYPE "type" +#define OWNER_CUSTOMER "customer" +#define OWNER_JOB "job" +#define OWNER_VENDOR "vendor" +#define OWNER_GUID "guid" +#define OWNER_PARENT "parent" +#define OWNER_PARENTG "parent-guid" +#define OWNER_NAME "name" + #endif /* GNC_OWNER_H_ */ diff --git a/src/business/business-core/gncOwnerP.h b/src/business/business-core/gncOwnerP.h new file mode 100644 index 0000000000..c6a352687d --- /dev/null +++ b/src/business/business-core/gncOwnerP.h @@ -0,0 +1,12 @@ +/* + * gncOwnerP.h -- Business Interface: Object OWNERs + * Copyright (C) 2001, 2002 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_OWNERP_H_ +#define GNC_OWNERP_H_ + +gboolean gncOwnerRegister (void); + +#endif /* GNC_OWNERP_H_ */ diff --git a/src/business/business-ledger/gncEntryLedger.c b/src/business/business-ledger/gncEntryLedger.c index 68c9bc44cc..7c31c0fc5f 100644 --- a/src/business/business-ledger/gncEntryLedger.c +++ b/src/business/business-ledger/gncEntryLedger.c @@ -285,8 +285,8 @@ static void create_invoice_query (GncEntryLedger *ledger) * 3. ( Entry->Invoice == NULL AND * Entry->Order->real-parent == Invoice->parent ) ) * - * Note that term 3 is only for Editable invoices, and only when - * we've already got an 'owner'. + * Note that term 3 is only for Editable invoices where the 'owner' + * is valid. */ /* Term 1 */ @@ -301,20 +301,27 @@ static void create_invoice_query (GncEntryLedger *ledger) gncInvoiceGetGUID (ledger->invoice), QUERY_OR); /* Term 3 */ - if (ledger->type == GNCENTRY_INVOICE_ENTRY) { + if (ledger->type == GNCENTRY_INVOICE_ENTRY && + gncOwnerGetEndGUID (gncInvoiceGetOwner (ledger->invoice)) != NULL) { QueryNew *q2 = gncQueryCreate (); - /* Note that this is a bogus search -- it will find all entries that - * exist (including "blank" entries) - */ + /* entry_invoice->invoice_guid == NULL */ gncQueryAddGUIDMatch (q2, g_slist_prepend (g_slist_prepend (NULL, INVOICE_GUID), ENTRY_INVOICE), - NULL, QUERY_AND); - - /* XXX Check entry's order's real-parent matches this invoice's parent */ + NULL, QUERY_OR); + /* entry_order->owner->end_guid == invoice->owner->guid */ + gncQueryAddGUIDMatch (q2, + g_slist_prepend + (g_slist_prepend + (g_slist_prepend (NULL, OWNER_PARENTG), + ORDER_OWNER), ENTRY_ORDER), + gncOwnerGetGUID (gncInvoiceGetOwner + (ledger->invoice)), + QUERY_AND); + /* Combine terms 2 and 3 */ q1 = gncQueryMerge (q, q2, QUERY_OR); gncQueryDestroy (q);