diff --git a/src/business/business-core/gncAddress.c b/src/business/business-core/gncAddress.c index b1fa53e5e9..dffd06ca79 100644 --- a/src/business/business-core/gncAddress.c +++ b/src/business/business-core/gncAddress.c @@ -17,7 +17,8 @@ #include "gncAddress.h" #include "gncAddressP.h" -struct _gncAddress { +struct _gncAddress +{ QofBook * book; const GUID * parent_guid; QofIdType parent_type; @@ -30,7 +31,6 @@ struct _gncAddress { char * phone; char * fax; char * email; - }; #define _GNC_MOD_NAME GNC_ADDRESS_MODULE_NAME @@ -49,7 +49,8 @@ mark_address (GncAddress *address) /* Create/Destroy functions */ -GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptype) +GncAddress * +gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptype) { GncAddress *addr; @@ -73,6 +74,31 @@ GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptyp return addr; } +GncAddress * +gncCloneAddress (GncAddress *from, QofBook *book) +{ + GncAddress *addr; + + if (!book) return NULL; + + addr = g_new0 (GncAddress, 1); + addr->book = book; + addr->dirty = TRUE; + addr->parent_guid = from->parent_guid; + addr->parent_type = from->parent_type; + + addr->name = CACHE_INSERT (from->name); + addr->addr1 = CACHE_INSERT (from->addr1); + addr->addr2 = CACHE_INSERT (from->addr2); + addr->addr3 = CACHE_INSERT (from->addr3); + addr->addr4 = CACHE_INSERT (from->addr4); + addr->phone = CACHE_INSERT (from->phone); + addr->fax = CACHE_INSERT (from->fax); + addr->email = CACHE_INSERT (from->email); + + return addr; +} + void gncAddressDestroy (GncAddress *addr){ if (!addr) return; diff --git a/src/business/business-core/gncAddress.h b/src/business/business-core/gncAddress.h index f5ce68c924..bb76b45267 100644 --- a/src/business/business-core/gncAddress.h +++ b/src/business/business-core/gncAddress.h @@ -11,12 +11,13 @@ #define GNC_ADDRESS_MODULE_NAME "gncAddress" -struct _gncAddress; typedef struct _gncAddress GncAddress; /* Create/Destroy functions */ - GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptype); + +/** make a copy of the address, but associate it with a different book */ +GncAddress * gncCloneAddress (GncAddress *from, QofBook *book); void gncAddressDestroy (GncAddress *addr); /* Set functions */ diff --git a/src/business/business-core/gncCustomer.c b/src/business/business-core/gncCustomer.c index f4ac28ced0..6f758e654b 100644 --- a/src/business/business-core/gncCustomer.c +++ b/src/business/business-core/gncCustomer.c @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncCustomer.c -- the Core Customer Interface * + * * + * 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 * + * * +\********************************************************************/ + /* - * gncCustomer.c -- the Core Customer Interface * Copyright (C) 2001,2002 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -98,6 +120,35 @@ GncCustomer *gncCustomerCreate (QofBook *book) return cust; } +/** Create a copy of a customer, placing the copy into a new book. */ +GncCustomer * +gncCloneCustomer (GncCustomer *from, QofBook *book) +{ + GncCustomer *cust; + + cust = g_new0 (GncCustomer, 1); + + qof_instance_init (&cust->inst, book); + qof_instance_gemini (&cust->inst, &from->inst); + + cust->id = CACHE_INSERT (from->id); + cust->name = CACHE_INSERT (from->name); + cust->notes = CACHE_INSERT (from->notes); + cust->discount = from->discount; + cust->credit = from->credit; + cust->taxincluded = from->taxincluded; + cust->active = from->active; + + /* cust->jobs = ??? XXX fixme not sure what to do here */ + /* cust->terms = ??? XXX fixme not sure what to do here */ + /* cust->taxtable = ??? XXX fixme not sure what to do here */ + cust->addr = gncCloneAddress (from->addr, book); + cust->shipaddr = gncCloneAddress (from->shipaddr, book); + addObj (cust); + + return cust; +} + void gncCustomerDestroy (GncCustomer *cust) { if (!cust) return; diff --git a/src/business/business-core/gncCustomer.h b/src/business/business-core/gncCustomer.h index d634b1b7f1..32d953d52d 100644 --- a/src/business/business-core/gncCustomer.h +++ b/src/business/business-core/gncCustomer.h @@ -1,5 +1,26 @@ +/********************************************************************\ + * gncCustomer.h -- the Core Customer Interface * + * * + * 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 * + * * +\********************************************************************/ + /* - * gncCustomer.h -- the Core Customer Interface * Copyright (C) 2001,2002 Derek Atkins * Author: Derek Atkins */ diff --git a/src/business/business-core/gncCustomerP.h b/src/business/business-core/gncCustomerP.h index 426addcbcc..2e9fdfb5c4 100644 --- a/src/business/business-core/gncCustomerP.h +++ b/src/business/business-core/gncCustomerP.h @@ -1,6 +1,28 @@ +/********************************************************************\ + * gncCustomerP.h -- the Core Customer Interface * + * * + * 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 * + * * +\********************************************************************/ + /* - * gncCustomerP.h -- the Core Customer Interface * Copyright (C) 2001 Derek Atkins + * Copyright (C) 2003 Linas Vepstas * Author: Derek Atkins */ @@ -13,4 +35,14 @@ gboolean gncCustomerRegister (void); gint64 gncCustomerNextID (QofBook *book); void gncCustomerSetGUID (GncCustomer *customer, const GUID *guid); +/** The gncCloneCustomer() routine makes a copy of the indicated + * customer, placing it in the indicated book. It copies + * the addresses, credits, etc. + * It does not copy jobs?? or bill terms??. Or tax terms ??? + * XXX the above need fixin.... + * It then adds a pair of 'gemini' kvp pointers so that each copy + * can be found from the other. + */ +GncCustomer * gncCloneCustomer (GncCustomer *from, QofBook *book); + #endif /* GNC_CUSTOMERP_H_ */