2003-10-14 08:46:24 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gncVendor.c -- the Core Vendor 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 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2003-10-14 08:46:24 -05:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
|
|
|
|
2001-11-16 19:17:06 -06:00
|
|
|
/*
|
2002-01-22 11:16:02 -06:00
|
|
|
* Copyright (C) 2001, 2002 Derek Atkins
|
2003-10-21 08:53:55 -05:00
|
|
|
* Copyright (C) 2003 <linas@linas.org>
|
2001-11-16 19:17:06 -06:00
|
|
|
* Author: Derek Atkins <warlord@MIT.EDU>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2003-10-21 00:12:38 -05:00
|
|
|
#include "gnc-commodity.h"
|
|
|
|
#include "gncAddressP.h"
|
|
|
|
#include "gncBillTermP.h"
|
2005-11-01 21:32:36 -06:00
|
|
|
#include "gncInvoice.h"
|
2003-10-21 08:53:55 -05:00
|
|
|
#include "gncJobP.h"
|
|
|
|
#include "gncTaxTableP.h"
|
2001-11-16 19:17:06 -06:00
|
|
|
#include "gncVendor.h"
|
|
|
|
#include "gncVendorP.h"
|
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
struct _gncVendor
|
|
|
|
{
|
|
|
|
QofInstance inst;
|
2002-11-03 14:21:42 -06:00
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
char * id;
|
|
|
|
char * name;
|
|
|
|
char * notes;
|
|
|
|
GncBillTerm * terms;
|
|
|
|
GncAddress * addr;
|
|
|
|
gnc_commodity * currency;
|
|
|
|
GncTaxTable* taxtable;
|
|
|
|
gboolean taxtable_override;
|
|
|
|
GncTaxIncluded taxincluded;
|
|
|
|
gboolean active;
|
|
|
|
GList * jobs;
|
2001-11-16 19:17:06 -06:00
|
|
|
};
|
|
|
|
|
2007-04-04 21:44:36 -05:00
|
|
|
struct _gncVendorClass
|
|
|
|
{
|
|
|
|
QofInstanceClass parent_class;
|
|
|
|
};
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static QofLogModule log_module = GNC_MOD_BUSINESS;
|
2003-10-14 08:46:24 -05:00
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
#define _GNC_MOD_NAME GNC_ID_VENDOR
|
2002-11-03 14:21:42 -06:00
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
/* ============================================================ */
|
|
|
|
/* Misc inline funcs */
|
2001-11-24 23:34:34 -06:00
|
|
|
|
2002-03-02 12:55:01 -06:00
|
|
|
G_INLINE_FUNC void mark_vendor (GncVendor *vendor);
|
2005-11-01 21:32:36 -06:00
|
|
|
void mark_vendor (GncVendor *vendor)
|
2002-03-02 12:55:01 -06:00
|
|
|
{
|
2006-05-02 21:28:18 -05:00
|
|
|
qof_instance_set_dirty(&vendor->inst);
|
2007-04-01 17:18:50 -05:00
|
|
|
qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
|
2002-03-02 12:55:01 -06:00
|
|
|
}
|
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
/* ============================================================== */
|
2007-04-04 21:44:36 -05:00
|
|
|
/* GObject Initialization */
|
|
|
|
QOF_GOBJECT_IMPL(gnc_vendor, GncVendor, QOF_TYPE_INSTANCE);
|
2001-11-16 19:17:06 -06:00
|
|
|
|
2007-04-04 21:44:36 -05:00
|
|
|
static void
|
|
|
|
gnc_vendor_init(GncVendor* vendor)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-04-04 22:10:26 -05:00
|
|
|
static void
|
|
|
|
gnc_vendor_dispose_real (GObject *vendorp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-04-04 21:44:36 -05:00
|
|
|
static void
|
|
|
|
gnc_vendor_finalize_real(GObject* vendorp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create/Destroy Functions */
|
2003-06-26 22:05:25 -05:00
|
|
|
GncVendor *gncVendorCreate (QofBook *book)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
GncVendor *vendor;
|
|
|
|
|
2001-11-24 23:34:34 -06:00
|
|
|
if (!book) return NULL;
|
2001-11-16 19:17:06 -06:00
|
|
|
|
2007-04-04 21:44:36 -05:00
|
|
|
vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
|
|
|
|
qof_instance_init_data (&vendor->inst, _GNC_MOD_NAME, book);
|
2003-10-14 08:46:24 -05:00
|
|
|
|
2001-11-16 19:17:06 -06:00
|
|
|
vendor->id = CACHE_INSERT ("");
|
|
|
|
vendor->name = CACHE_INSERT ("");
|
|
|
|
vendor->notes = CACHE_INSERT ("");
|
2007-04-01 17:18:50 -05:00
|
|
|
vendor->addr = gncAddressCreate (book, &vendor->inst);
|
2002-06-23 23:59:04 -05:00
|
|
|
vendor->taxincluded = GNC_TAXINCLUDED_USEGLOBAL;
|
2001-11-16 19:17:06 -06:00
|
|
|
vendor->active = TRUE;
|
2003-10-14 08:46:24 -05:00
|
|
|
vendor->jobs = NULL;
|
2001-11-16 19:17:06 -06:00
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
|
2002-03-02 12:55:01 -06:00
|
|
|
|
2001-11-16 19:17:06 -06:00
|
|
|
return vendor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gncVendorDestroy (GncVendor *vendor)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return;
|
2007-04-30 00:33:33 -05:00
|
|
|
qof_instance_set_destroying(vendor, TRUE);
|
2002-11-03 14:21:42 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gncVendorFree (GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
qof_event_gen (&vendor->inst, QOF_EVENT_DESTROY, NULL);
|
2002-03-02 12:55:01 -06:00
|
|
|
|
2001-11-16 19:17:06 -06:00
|
|
|
CACHE_REMOVE (vendor->id);
|
|
|
|
CACHE_REMOVE (vendor->name);
|
|
|
|
CACHE_REMOVE (vendor->notes);
|
2007-04-11 10:37:09 -05:00
|
|
|
gncAddressBeginEdit (vendor->addr);
|
2001-11-16 19:17:06 -06:00
|
|
|
gncAddressDestroy (vendor->addr);
|
2002-01-22 11:16:02 -06:00
|
|
|
g_list_free (vendor->jobs);
|
|
|
|
|
2003-06-14 00:17:07 -05:00
|
|
|
if (vendor->terms)
|
|
|
|
gncBillTermDecRef (vendor->terms);
|
|
|
|
if (vendor->taxtable)
|
|
|
|
gncTaxTableDecRef (vendor->taxtable);
|
|
|
|
|
2007-04-04 21:44:36 -05:00
|
|
|
/* qof_instance_release (&vendor->inst); */
|
|
|
|
g_object_unref (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2003-10-20 08:44:41 -05:00
|
|
|
/** Create a copy of a vendor, placing the copy into a new book. */
|
|
|
|
GncVendor *
|
|
|
|
gncCloneVendor (GncVendor *from, QofBook *book)
|
|
|
|
{
|
2003-10-21 08:53:55 -05:00
|
|
|
GList *node;
|
2003-10-20 08:44:41 -05:00
|
|
|
GncVendor *vendor;
|
|
|
|
|
|
|
|
if (!book) return NULL;
|
|
|
|
|
2007-04-04 21:44:36 -05:00
|
|
|
vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
|
|
|
|
qof_instance_init_data (&vendor->inst, _GNC_MOD_NAME, book);
|
2003-10-20 08:44:41 -05:00
|
|
|
qof_instance_gemini (&vendor->inst, &from->inst);
|
|
|
|
|
|
|
|
vendor->id = CACHE_INSERT (from->id);
|
|
|
|
vendor->name = CACHE_INSERT (from->name);
|
|
|
|
vendor->notes = CACHE_INSERT (from->notes);
|
2007-04-01 17:18:50 -05:00
|
|
|
vendor->addr = gncCloneAddress (from->addr, &vendor->inst, book);
|
2003-10-20 08:44:41 -05:00
|
|
|
vendor->taxincluded = from->taxincluded;
|
2003-10-21 08:53:55 -05:00
|
|
|
vendor->taxtable_override = from->taxtable_override;
|
2003-10-20 08:44:41 -05:00
|
|
|
vendor->active = from->active;
|
|
|
|
|
2003-10-21 00:12:38 -05:00
|
|
|
vendor->terms = gncBillTermObtainTwin (from->terms, book);
|
|
|
|
gncBillTermIncRef (vendor->terms);
|
|
|
|
|
|
|
|
vendor->currency = gnc_commodity_obtain_twin (from->currency, book);
|
|
|
|
|
2003-10-21 08:53:55 -05:00
|
|
|
vendor->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
|
|
|
|
gncTaxTableIncRef (vendor->taxtable);
|
2003-10-20 08:44:41 -05:00
|
|
|
|
2003-10-21 08:53:55 -05:00
|
|
|
vendor->jobs = NULL;
|
|
|
|
for (node=g_list_last(from->jobs); node; node=node->prev)
|
|
|
|
{
|
|
|
|
GncJob *job = node->data;
|
|
|
|
job = gncJobObtainTwin (job, book);
|
|
|
|
vendor->jobs = g_list_prepend(vendor->jobs, job);
|
|
|
|
}
|
2003-10-20 08:44:41 -05:00
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
qof_event_gen (&vendor->inst, QOF_EVENT_CREATE, NULL);
|
2003-10-20 08:44:41 -05:00
|
|
|
|
|
|
|
return vendor;
|
|
|
|
}
|
|
|
|
|
|
|
|
GncVendor *
|
|
|
|
gncVendorObtainTwin (GncVendor *from, QofBook *book)
|
|
|
|
{
|
|
|
|
GncVendor *vendor;
|
|
|
|
if (!book) return NULL;
|
|
|
|
|
|
|
|
vendor = (GncVendor *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
|
|
|
if (!vendor)
|
|
|
|
{
|
2003-10-21 00:12:38 -05:00
|
|
|
vendor = gncCloneVendor (from, book);
|
2003-10-20 08:44:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return vendor;
|
|
|
|
}
|
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
/* ============================================================== */
|
2001-11-16 19:17:06 -06:00
|
|
|
/* Set Functions */
|
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
#define SET_STR(obj, member, str) { \
|
2003-10-14 08:46:24 -05:00
|
|
|
char * tmp; \
|
|
|
|
\
|
|
|
|
if (!safe_strcmp (member, str)) return; \
|
|
|
|
gncVendorBeginEdit (obj); \
|
|
|
|
tmp = CACHE_INSERT (str); \
|
|
|
|
CACHE_REMOVE (member); \
|
|
|
|
member = tmp; \
|
|
|
|
}
|
2001-11-16 19:17:06 -06:00
|
|
|
|
|
|
|
void gncVendorSetID (GncVendor *vendor, const char *id)
|
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
if (!id) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR(vendor, vendor->id, id);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncVendorSetName (GncVendor *vendor, const char *name)
|
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
if (!name) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR(vendor, vendor->name, name);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncVendorSetNotes (GncVendor *vendor, const char *notes)
|
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
if (!notes) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
SET_STR(vendor,vendor->notes, notes);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2002-06-21 21:38:13 -05:00
|
|
|
void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2002-06-21 21:38:13 -05:00
|
|
|
if (!vendor) return;
|
|
|
|
if (vendor->terms == terms) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
|
|
|
|
gncVendorBeginEdit (vendor);
|
2002-06-21 21:38:13 -05:00
|
|
|
if (vendor->terms)
|
|
|
|
gncBillTermDecRef (vendor->terms);
|
|
|
|
vendor->terms = terms;
|
|
|
|
if (vendor->terms)
|
2003-10-21 00:12:38 -05:00
|
|
|
gncBillTermIncRef (vendor->terms);
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2002-06-23 23:59:04 -05:00
|
|
|
void gncVendorSetTaxIncluded (GncVendor *vendor, GncTaxIncluded taxincl)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
if (taxincl == vendor->taxincluded) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorBeginEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
vendor->taxincluded = taxincl;
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2003-01-12 16:53:02 -06:00
|
|
|
void gncVendorSetCurrency (GncVendor *vendor, gnc_commodity *currency)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2003-01-12 16:53:02 -06:00
|
|
|
if (!vendor || !currency) return;
|
|
|
|
if (vendor->currency &&
|
|
|
|
gnc_commodity_equal (vendor->currency, currency))
|
2002-06-21 14:00:34 -05:00
|
|
|
return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorBeginEdit (vendor);
|
2003-01-12 16:53:02 -06:00
|
|
|
vendor->currency = currency;
|
2002-03-04 13:34:52 -06:00
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2001-11-16 19:17:06 -06:00
|
|
|
void gncVendorSetActive (GncVendor *vendor, gboolean active)
|
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
if (active == vendor->active) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorBeginEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
vendor->active = active;
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2002-09-16 23:19:57 -05:00
|
|
|
void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean override)
|
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
if (vendor->taxtable_override == override) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorBeginEdit (vendor);
|
2002-09-16 23:19:57 -05:00
|
|
|
vendor->taxtable_override = override;
|
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2002-09-16 23:19:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncVendorSetTaxTable (GncVendor *vendor, GncTaxTable *table)
|
|
|
|
{
|
|
|
|
if (!vendor) return;
|
|
|
|
if (vendor->taxtable == table) return;
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorBeginEdit (vendor);
|
2002-09-16 23:19:57 -05:00
|
|
|
if (vendor->taxtable)
|
|
|
|
gncTaxTableDecRef (vendor->taxtable);
|
|
|
|
if (table)
|
|
|
|
gncTaxTableIncRef (table);
|
|
|
|
vendor->taxtable = table;
|
|
|
|
mark_vendor (vendor);
|
2002-11-03 18:41:01 -06:00
|
|
|
gncVendorCommitEdit (vendor);
|
2002-09-16 23:19:57 -05:00
|
|
|
}
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static void
|
2007-04-01 17:18:50 -05:00
|
|
|
qofVendorSetAddr (GncVendor *vendor, QofInstance *addr_ent)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
|
|
|
GncAddress *addr;
|
|
|
|
|
|
|
|
if(!vendor || !addr_ent) { return; }
|
|
|
|
addr = (GncAddress*)addr_ent;
|
|
|
|
if(addr == vendor->addr) { return; }
|
2007-04-11 10:37:09 -05:00
|
|
|
if(vendor->addr != NULL) {
|
|
|
|
gncAddressBeginEdit(vendor->addr);
|
|
|
|
gncAddressDestroy(vendor->addr);
|
|
|
|
}
|
2005-11-01 21:32:36 -06:00
|
|
|
gncVendorBeginEdit(vendor);
|
|
|
|
vendor->addr = addr;
|
|
|
|
gncVendorCommitEdit(vendor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qofVendorSetTaxIncluded(GncVendor *vendor, const char* type_string)
|
|
|
|
{
|
|
|
|
GncTaxIncluded inc;
|
|
|
|
|
|
|
|
if(!gncTaxIncludedStringToType(type_string, &inc)) { return; }
|
|
|
|
gncVendorBeginEdit(vendor);
|
|
|
|
vendor->taxincluded = inc;
|
|
|
|
gncVendorCommitEdit(vendor);
|
|
|
|
}
|
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
/* ============================================================== */
|
2001-11-16 19:17:06 -06:00
|
|
|
/* Get Functions */
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncVendorGetID (const GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return NULL;
|
|
|
|
return vendor->id;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncVendorGetName (const GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return NULL;
|
|
|
|
return vendor->name;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GncAddress * gncVendorGetAddr (const GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return NULL;
|
|
|
|
return vendor->addr;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncVendorGetNotes (const GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return NULL;
|
|
|
|
return vendor->notes;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GncBillTerm * gncVendorGetTerms (const GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return 0;
|
|
|
|
return vendor->terms;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GncTaxIncluded gncVendorGetTaxIncluded (const GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2002-06-23 23:59:04 -05:00
|
|
|
if (!vendor) return GNC_TAXINCLUDED_USEGLOBAL;
|
2001-11-16 19:17:06 -06:00
|
|
|
return vendor->taxincluded;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gnc_commodity * gncVendorGetCurrency (const GncVendor *vendor)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return NULL;
|
2003-01-12 16:53:02 -06:00
|
|
|
return vendor->currency;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gboolean gncVendorGetActive (const GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return FALSE;
|
|
|
|
return vendor->active;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gboolean gncVendorGetTaxTableOverride (const GncVendor *vendor)
|
2002-09-16 23:19:57 -05:00
|
|
|
{
|
|
|
|
if (!vendor) return FALSE;
|
|
|
|
return vendor->taxtable_override;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GncTaxTable* gncVendorGetTaxTable (const GncVendor *vendor)
|
2002-09-16 23:19:57 -05:00
|
|
|
{
|
|
|
|
if (!vendor) return NULL;
|
|
|
|
return vendor->taxtable;
|
|
|
|
}
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static const char*
|
2008-08-01 11:02:07 -05:00
|
|
|
qofVendorGetTaxIncluded(const GncVendor *vendor)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
|
|
|
return gncTaxIncludedTypeToString(vendor->taxincluded);
|
|
|
|
}
|
|
|
|
|
2002-01-22 11:16:02 -06:00
|
|
|
/* Note that JobList changes do not affect the "dirtiness" of the vendor */
|
|
|
|
void gncVendorAddJob (GncVendor *vendor, GncJob *job)
|
2001-11-24 23:34:34 -06:00
|
|
|
{
|
2002-01-22 11:16:02 -06:00
|
|
|
if (!vendor) return;
|
|
|
|
if (!job) return;
|
|
|
|
|
|
|
|
if (g_list_index(vendor->jobs, job) == -1)
|
2002-02-04 12:54:06 -06:00
|
|
|
vendor->jobs = g_list_insert_sorted (vendor->jobs, job,
|
2003-10-14 08:46:24 -05:00
|
|
|
(GCompareFunc)gncJobCompare);
|
2002-03-02 12:55:01 -06:00
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
|
2001-11-24 23:34:34 -06:00
|
|
|
}
|
|
|
|
|
2002-01-22 11:16:02 -06:00
|
|
|
void gncVendorRemoveJob (GncVendor *vendor, GncJob *job)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2002-01-22 11:16:02 -06:00
|
|
|
GList *node;
|
|
|
|
|
|
|
|
if (!vendor) return;
|
|
|
|
if (!job) return;
|
|
|
|
|
|
|
|
node = g_list_find (vendor->jobs, job);
|
|
|
|
if (!node) {
|
|
|
|
/* PERR ("split not in account"); */
|
|
|
|
} else {
|
|
|
|
vendor->jobs = g_list_remove_link (vendor->jobs, node);
|
|
|
|
g_list_free_1 (node);
|
|
|
|
}
|
2002-03-02 12:55:01 -06:00
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
qof_event_gen (&vendor->inst, QOF_EVENT_MODIFY, NULL);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
void gncVendorBeginEdit (GncVendor *vendor)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2007-04-30 12:06:48 -05:00
|
|
|
qof_begin_edit(&vendor->inst);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
2001-11-16 19:17:06 -06:00
|
|
|
|
2006-11-29 09:13:02 -06:00
|
|
|
static void gncVendorOnError (QofInstance *vendor, QofBackendError errcode)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
2003-06-26 22:36:02 -05:00
|
|
|
PERR("Vendor QofBackend Failure: %d", errcode);
|
2008-10-27 20:07:02 -05:00
|
|
|
gnc_engine_signal_commit_error( errcode );
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2006-11-29 09:13:02 -06:00
|
|
|
static void gncVendorOnDone (QofInstance *inst)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
2003-10-14 08:46:24 -05:00
|
|
|
GncVendor *vendor = (GncVendor *) inst;
|
2002-03-04 13:34:52 -06:00
|
|
|
gncAddressClearDirty (vendor->addr);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2006-11-29 09:13:02 -06:00
|
|
|
static void vendor_free (QofInstance *inst)
|
2003-10-14 08:46:24 -05:00
|
|
|
{
|
|
|
|
GncVendor *vendor = (GncVendor *) inst;
|
|
|
|
gncVendorFree (vendor);
|
|
|
|
}
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
void gncVendorCommitEdit (GncVendor *vendor)
|
|
|
|
{
|
2006-04-21 23:42:29 -05:00
|
|
|
if (!qof_commit_edit (QOF_INSTANCE(vendor))) return;
|
2006-02-26 12:36:05 -06:00
|
|
|
qof_commit_edit_part2 (&vendor->inst, gncVendorOnError,
|
2003-10-14 08:46:24 -05:00
|
|
|
gncVendorOnDone, vendor_free);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
/* ============================================================== */
|
2001-11-16 19:17:06 -06:00
|
|
|
/* Other functions */
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
int gncVendorCompare (const GncVendor *a, const GncVendor *b)
|
2002-02-03 14:01:08 -06:00
|
|
|
{
|
|
|
|
if (!a && !b) return 0;
|
|
|
|
if (!a && b) return 1;
|
|
|
|
if (a && !b) return -1;
|
|
|
|
|
|
|
|
return(strcmp(a->name, b->name));
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GList * gncVendorGetJoblist (const GncVendor *vendor, gboolean show_all)
|
2002-01-22 11:16:02 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return NULL;
|
|
|
|
|
|
|
|
if (show_all) {
|
|
|
|
return (g_list_copy (vendor->jobs));
|
|
|
|
} else {
|
|
|
|
GList *list = NULL, *iterator;
|
|
|
|
for (iterator = vendor->jobs; iterator; iterator=iterator->next) {
|
|
|
|
GncJob *j = iterator->data;
|
|
|
|
if (gncJobGetActive (j))
|
2003-10-14 08:46:24 -05:00
|
|
|
list = g_list_append (list, j);
|
2002-01-22 11:16:02 -06:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gboolean gncVendorIsDirty (const GncVendor *vendor)
|
2002-01-22 11:16:02 -06:00
|
|
|
{
|
|
|
|
if (!vendor) return FALSE;
|
2007-04-30 00:33:33 -05:00
|
|
|
return (qof_instance_get_dirty_flag(vendor)
|
|
|
|
|| gncAddressIsDirty (vendor->addr));
|
2002-01-22 11:16:02 -06:00
|
|
|
}
|
|
|
|
|
2003-10-14 08:46:24 -05:00
|
|
|
/* ============================================================== */
|
2001-11-16 19:17:06 -06:00
|
|
|
/* Package-Private functions */
|
|
|
|
|
|
|
|
static const char * _gncVendorPrintable (gpointer item)
|
|
|
|
{
|
2003-10-19 00:13:59 -05:00
|
|
|
GncVendor *v = item;
|
2001-11-16 19:17:06 -06:00
|
|
|
if (!item) return NULL;
|
|
|
|
return v->name;
|
|
|
|
}
|
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
static QofObject gncVendorDesc =
|
|
|
|
{
|
2008-11-26 08:35:36 -06:00
|
|
|
.interface_version = QOF_OBJECT_VERSION,
|
|
|
|
.e_type = _GNC_MOD_NAME,
|
|
|
|
.type_label = "Vendor",
|
|
|
|
.create = (gpointer)gncVendorCreate,
|
|
|
|
.book_begin = NULL,
|
|
|
|
.book_end = NULL,
|
|
|
|
.is_dirty = qof_collection_is_dirty,
|
|
|
|
.mark_clean = qof_collection_mark_clean,
|
|
|
|
.foreach = qof_collection_foreach,
|
|
|
|
.printable = _gncVendorPrintable,
|
|
|
|
.version_cmp = (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
|
2001-11-16 19:17:06 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
gboolean gncVendorRegister (void)
|
|
|
|
{
|
2003-09-27 05:21:27 -05:00
|
|
|
static QofParam params[] = {
|
2004-07-26 07:41:43 -05:00
|
|
|
{ VENDOR_ID, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetID, (QofSetterFunc)gncVendorSetID },
|
|
|
|
{ VENDOR_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetName, (QofSetterFunc)gncVendorSetName },
|
2005-11-01 21:32:36 -06:00
|
|
|
{ VENDOR_ADDR, GNC_ID_ADDRESS, (QofAccessFunc)gncVendorGetAddr, (QofSetterFunc)qofVendorSetAddr },
|
|
|
|
{ VENDOR_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncVendorGetNotes, (QofSetterFunc)gncVendorSetNotes },
|
|
|
|
{ VENDOR_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncVendorGetTerms, (QofSetterFunc)gncVendorSetTerms },
|
|
|
|
{ VENDOR_TAX_OVERRIDE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncVendorGetTaxTableOverride,
|
|
|
|
(QofSetterFunc)gncVendorSetTaxTableOverride },
|
|
|
|
{ VENDOR_TAX_TABLE, GNC_ID_TAXTABLE, (QofAccessFunc)gncVendorGetTaxTable,
|
|
|
|
(QofSetterFunc)gncVendorSetTaxTable },
|
|
|
|
{ VENDOR_TAX_INC, QOF_TYPE_STRING, (QofAccessFunc)qofVendorGetTaxIncluded,
|
|
|
|
(QofSetterFunc)qofVendorSetTaxIncluded},
|
2004-05-23 12:31:40 -05:00
|
|
|
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
|
|
|
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
|
|
|
{ QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncVendorGetActive, NULL },
|
2002-02-03 14:01:08 -06:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
if(!qof_choice_add_class(GNC_ID_INVOICE, GNC_ID_VENDOR, INVOICE_OWNER)) { return FALSE; }
|
|
|
|
if(!qof_choice_add_class(GNC_ID_JOB, GNC_ID_VENDOR, JOB_OWNER)) { return FALSE; }
|
|
|
|
|
2003-09-27 11:33:06 -05:00
|
|
|
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncVendorCompare, params);
|
2002-02-03 14:01:08 -06:00
|
|
|
|
2003-06-26 22:09:39 -05:00
|
|
|
return qof_object_register (&gncVendorDesc);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|
|
|
|
|
2003-06-26 22:05:25 -05:00
|
|
|
gint64 gncVendorNextID (QofBook *book)
|
2001-11-16 19:17:06 -06:00
|
|
|
{
|
2003-10-17 00:15:56 -05:00
|
|
|
return qof_book_get_counter (book, _GNC_MOD_NAME);
|
2001-11-16 19:17:06 -06:00
|
|
|
}
|