mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
- register the GncOwner as another queriable type
- add to EntryLedger query for invoices; moving from an order->invoice will show the appropriate entries for the customer/vendor. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6682 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2a0f766c34
commit
b7fb090444
@ -40,6 +40,7 @@ noinst_HEADERS = \
|
|||||||
gncOrder.h \
|
gncOrder.h \
|
||||||
gncOrderP.h \
|
gncOrderP.h \
|
||||||
gncOwner.h \
|
gncOwner.h \
|
||||||
|
gncOwnerP.h \
|
||||||
gncVendor.h \
|
gncVendor.h \
|
||||||
gncVendorP.h
|
gncVendorP.h
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "gncInvoiceP.h"
|
#include "gncInvoiceP.h"
|
||||||
#include "gncJobP.h"
|
#include "gncJobP.h"
|
||||||
#include "gncOrderP.h"
|
#include "gncOrderP.h"
|
||||||
|
#include "gncOwnerP.h"
|
||||||
#include "gncVendorP.h"
|
#include "gncVendorP.h"
|
||||||
|
|
||||||
/* version of the gnc module system interface we require */
|
/* version of the gnc module system interface we require */
|
||||||
@ -58,6 +59,7 @@ gnc_module_init(int refcount)
|
|||||||
gncInvoiceRegister ();
|
gncInvoiceRegister ();
|
||||||
gncJobRegister ();
|
gncJobRegister ();
|
||||||
gncOrderRegister ();
|
gncOrderRegister ();
|
||||||
|
gncOwnerRegister ();
|
||||||
gncVendorRegister ();
|
gncVendorRegister ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,6 +342,7 @@ gboolean gncOrderRegister (void)
|
|||||||
{
|
{
|
||||||
static QueryObjectDef params[] = {
|
static QueryObjectDef params[] = {
|
||||||
{ ORDER_GUID, QUERYCORE_GUID, (QueryAccess)gncOrderGetGUID },
|
{ ORDER_GUID, QUERYCORE_GUID, (QueryAccess)gncOrderGetGUID },
|
||||||
|
{ ORDER_OWNER, GNC_OWNER_MODULE_NAME, (QueryAccess)gncOrderGetOwner },
|
||||||
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncOrderGetBook },
|
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncOrderGetBook },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
@ -54,5 +54,6 @@ void gncOrderCommitEdit (GncOrder *order);
|
|||||||
int gncOrderCompare (GncOrder *a, GncOrder *b);
|
int gncOrderCompare (GncOrder *a, GncOrder *b);
|
||||||
|
|
||||||
#define ORDER_GUID "guid"
|
#define ORDER_GUID "guid"
|
||||||
|
#define ORDER_OWNER "owner"
|
||||||
|
|
||||||
#endif /* GNC_ORDER_H_ */
|
#endif /* GNC_ORDER_H_ */
|
||||||
|
@ -9,7 +9,12 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <string.h> /* for memcpy() */
|
#include <string.h> /* for memcpy() */
|
||||||
|
|
||||||
|
#include "QueryObject.h"
|
||||||
|
|
||||||
#include "gncOwner.h"
|
#include "gncOwner.h"
|
||||||
|
#include "gncOwnerP.h"
|
||||||
|
|
||||||
|
#define _GNC_MOD_NAME GNC_OWNER_MODULE_NAME
|
||||||
|
|
||||||
void gncOwnerInitUndefined (GncOwner *owner, gpointer obj)
|
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;
|
||||||
|
}
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
typedef struct gnc_owner_s GncOwner;
|
typedef struct gnc_owner_s GncOwner;
|
||||||
|
|
||||||
|
#define GNC_OWNER_MODULE_NAME "gncOwner"
|
||||||
|
|
||||||
#include "gncCustomer.h"
|
#include "gncCustomer.h"
|
||||||
#include "gncJob.h"
|
#include "gncJob.h"
|
||||||
#include "gncVendor.h"
|
#include "gncVendor.h"
|
||||||
@ -47,4 +49,23 @@ gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
|
|||||||
|
|
||||||
const char * gncOwnerGetName (GncOwner *owner);
|
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_ */
|
#endif /* GNC_OWNER_H_ */
|
||||||
|
12
src/business/business-core/gncOwnerP.h
Normal file
12
src/business/business-core/gncOwnerP.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* gncOwnerP.h -- Business Interface: Object OWNERs
|
||||||
|
* Copyright (C) 2001, 2002 Derek Atkins
|
||||||
|
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GNC_OWNERP_H_
|
||||||
|
#define GNC_OWNERP_H_
|
||||||
|
|
||||||
|
gboolean gncOwnerRegister (void);
|
||||||
|
|
||||||
|
#endif /* GNC_OWNERP_H_ */
|
@ -285,8 +285,8 @@ static void create_invoice_query (GncEntryLedger *ledger)
|
|||||||
* 3. ( Entry->Invoice == NULL AND
|
* 3. ( Entry->Invoice == NULL AND
|
||||||
* Entry->Order->real-parent == Invoice->parent ) )
|
* Entry->Order->real-parent == Invoice->parent ) )
|
||||||
*
|
*
|
||||||
* Note that term 3 is only for Editable invoices, and only when
|
* Note that term 3 is only for Editable invoices where the 'owner'
|
||||||
* we've already got an 'owner'.
|
* is valid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Term 1 */
|
/* Term 1 */
|
||||||
@ -301,20 +301,27 @@ static void create_invoice_query (GncEntryLedger *ledger)
|
|||||||
gncInvoiceGetGUID (ledger->invoice), QUERY_OR);
|
gncInvoiceGetGUID (ledger->invoice), QUERY_OR);
|
||||||
|
|
||||||
/* Term 3 */
|
/* Term 3 */
|
||||||
if (ledger->type == GNCENTRY_INVOICE_ENTRY) {
|
if (ledger->type == GNCENTRY_INVOICE_ENTRY &&
|
||||||
|
gncOwnerGetEndGUID (gncInvoiceGetOwner (ledger->invoice)) != NULL) {
|
||||||
QueryNew *q2 = gncQueryCreate ();
|
QueryNew *q2 = gncQueryCreate ();
|
||||||
|
|
||||||
/* Note that this is a bogus search -- it will find all entries that
|
/* entry_invoice->invoice_guid == NULL */
|
||||||
* exist (including "blank" entries)
|
|
||||||
*/
|
|
||||||
gncQueryAddGUIDMatch (q2,
|
gncQueryAddGUIDMatch (q2,
|
||||||
g_slist_prepend (g_slist_prepend (NULL,
|
g_slist_prepend (g_slist_prepend (NULL,
|
||||||
INVOICE_GUID),
|
INVOICE_GUID),
|
||||||
ENTRY_INVOICE),
|
ENTRY_INVOICE),
|
||||||
NULL, QUERY_AND);
|
NULL, QUERY_OR);
|
||||||
|
|
||||||
/* XXX Check entry's order's real-parent matches this invoice's parent */
|
|
||||||
|
|
||||||
|
/* 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 */
|
/* Combine terms 2 and 3 */
|
||||||
q1 = gncQueryMerge (q, q2, QUERY_OR);
|
q1 = gncQueryMerge (q, q2, QUERY_OR);
|
||||||
gncQueryDestroy (q);
|
gncQueryDestroy (q);
|
||||||
|
Loading…
Reference in New Issue
Block a user