From a15de4f933e07abbf11d1ab8557fb113eb2e0466 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Tue, 14 Oct 2003 03:34:37 +0000 Subject: [PATCH] start work to clone owner git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9499 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/business/business-core/gncBusPeriod.c | 4 ++ src/business/business-core/gncCustomer.c | 14 ++++++ src/business/business-core/gncCustomerP.h | 11 +++++ src/business/business-core/gncJob.c | 2 +- src/business/business-core/gncJobP.h | 2 +- src/business/business-core/gncOwner.c | 58 ++++++++++++++++++++++- src/business/business-core/gncOwnerP.h | 32 ++++++++++++- 7 files changed, 118 insertions(+), 5 deletions(-) diff --git a/src/business/business-core/gncBusPeriod.c b/src/business/business-core/gncBusPeriod.c index f565a25e07..84a8099050 100644 --- a/src/business/business-core/gncBusPeriod.c +++ b/src/business/business-core/gncBusPeriod.c @@ -15,6 +15,10 @@ XXX TODO: -- TaxTable and BillTerm have common parent/child code. this could be abstracted into common code. +======= +-- finish onwer cclone +-- vendor, invoice, entry, order + #include "gncBusiness.h" diff --git a/src/business/business-core/gncCustomer.c b/src/business/business-core/gncCustomer.c index 10daedae60..bd347b424a 100644 --- a/src/business/business-core/gncCustomer.c +++ b/src/business/business-core/gncCustomer.c @@ -224,6 +224,20 @@ static void gncCustomerFree (GncCustomer *cust) g_free (cust); } +GncCustomer * +gncCustomerObtainTwin (GncCustomer *from, QofBook *book) +{ + GncCustomer *cust; + if (!from) return NULL; + + cust = (GncCustomer *) qof_instance_lookup_twin (QOF_INSTANCE(from), book); + if (!cust) + { + cust = gncCloneCustomer (from, book); + } + return cust; +} + /* ============================================================== */ /* Set Functions */ diff --git a/src/business/business-core/gncCustomerP.h b/src/business/business-core/gncCustomerP.h index fae2382dbc..22d183d806 100644 --- a/src/business/business-core/gncCustomerP.h +++ b/src/business/business-core/gncCustomerP.h @@ -43,4 +43,15 @@ void gncCustomerSetGUID (GncCustomer *customer, const GUID *guid); */ GncCustomer * gncCloneCustomer (GncCustomer *from, QofBook *book); +/** The gncCustomerObtainTwin() will find the 'twin' of the + * indicated customer in the indicated book. If the twin doesn't + * yet exist in the book, it will be created (by calling + * gncCloneCustomer()) 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. + */ +GncCustomer * gncCustomerObtainTwin (GncCustomer *from, QofBook *book); + #endif /* GNC_CUSTOMERP_H_ */ diff --git a/src/business/business-core/gncJob.c b/src/business/business-core/gncJob.c index 79d70c2b0f..120df6df89 100644 --- a/src/business/business-core/gncJob.c +++ b/src/business/business-core/gncJob.c @@ -35,10 +35,10 @@ #include "messages.h" #include "gnc-engine-util.h" #include "gnc-numeric.h" -#include "gnc-book.h" #include "gnc-event-p.h" #include "gnc-be-utils.h" +#include "qofbook.h" #include "qofclass.h" #include "qofinstance.h" #include "qofid.h" diff --git a/src/business/business-core/gncJobP.h b/src/business/business-core/gncJobP.h index 5d0746d433..e0f6c16e1c 100644 --- a/src/business/business-core/gncJobP.h +++ b/src/business/business-core/gncJobP.h @@ -44,7 +44,7 @@ void gncJobSetGUID (GncJob *job, const GUID *guid); GncJob * gncCloneJob (GncJob *from, QofBook *book); /** The gncJobObtainTwin() will find the 'twin' of the - * indicated tax table in the indicated book. If the twin doesn't + * indicated job in the indicated book. If the twin doesn't * yet exist in the book, it will be created (by calling * gncCloneJob()) and placed into the book. * diff --git a/src/business/business-core/gncOwner.c b/src/business/business-core/gncOwner.c index 450f0603a6..21540a1e00 100644 --- a/src/business/business-core/gncOwner.c +++ b/src/business/business-core/gncOwner.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncOwner.c -- Business Interface: Object OWNERs * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOwner.c -- Business Interface: Object OWNERs * Copyright (C) 2001, 2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -9,11 +31,13 @@ #include #include /* for memcpy() */ +#include "qofbook.h" #include "qofclass.h" -#include "qofinstance.h" #include "qofquerycore.h" #include "qofquery.h" +#include "gncCustomerP.h" +#include "gncJobP.h" #include "gncOwner.h" #include "gncOwnerP.h" @@ -138,6 +162,36 @@ void gncOwnerCopy (const GncOwner *src, GncOwner *dest) memcpy (dest, src, sizeof (*dest)); } +GncOwner +gncCloneOwner (const GncOwner *from, QofBook *book) +{ + GncOwner owner = {GNC_OWNER_NONE}; + if (!from) return owner; + owner.type = from->type; + switch (from->type) + { + case GNC_OWNER_NONE: + return owner; + case GNC_OWNER_UNDEFINED: + owner.owner.undefined = from->owner.undefined; /* XXX probably wrong ! */ + return owner; + case GNC_OWNER_CUSTOMER: + owner.owner.customer = gncCustomerObtainTwin (from->owner.customer, book); + return owner; + case GNC_OWNER_JOB: + owner.owner.job = gncJobObtainTwin (from->owner.job, book); + return owner; + case GNC_OWNER_VENDOR: +/* XXX unfinished */ + return owner; + case GNC_OWNER_EMPLOYEE: +/* XXX unfinished */ + return owner; + default: + return owner; + } +} + gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b) { if (!a || !b) return FALSE; diff --git a/src/business/business-core/gncOwnerP.h b/src/business/business-core/gncOwnerP.h index c6a352687d..34e16504f7 100644 --- a/src/business/business-core/gncOwnerP.h +++ b/src/business/business-core/gncOwnerP.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncOwnerP.h -- Business Interface: Object OWNERs private file * + * * + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * + * * +\********************************************************************/ + /* - * gncOwnerP.h -- Business Interface: Object OWNERs * Copyright (C) 2001, 2002 Derek Atkins * Author: Derek Atkins */ @@ -7,6 +28,15 @@ #ifndef GNC_OWNERP_H_ #define GNC_OWNERP_H_ +#include "qofbook.h" +#include "gncOwner.h" + gboolean gncOwnerRegister (void); +/** The gncCloneOwner() routine makes a copy of the indicated + * owner, and one of its union elements, depending on the + * owner type. + */ +GncOwner gncCloneOwner (const GncOwner *from, QofBook *book); + #endif /* GNC_OWNERP_H_ */