mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Sync the g2 branch with the gnome2-merge-4 tag. (2003-10-24)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gnucash-gnome2-dev@9638 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
/********************************************************************\
|
||||
* option-util.c -- GNOME<->guile option interface *
|
||||
* Copyright (C) 1998,1999 Linas Vepstas *
|
||||
* Copyright (C) 2000 Dave Peticolas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
@@ -32,7 +31,9 @@
|
||||
#include "glib-helpers.h"
|
||||
#include "guile-util.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-err-popup.h"
|
||||
#include "guile-mappings.h"
|
||||
#include "messages.h"
|
||||
|
||||
#include <g-wrap-wct.h>
|
||||
|
||||
@@ -1731,7 +1732,7 @@ gnc_commit_option(GNCOption *option)
|
||||
name = gnc_option_name(option);
|
||||
section = gnc_option_section(option);
|
||||
|
||||
gnc_send_gui_error("There is a problem with option %s:%s.\n%s",
|
||||
gnc_send_gui_error(_("There is a problem with option %s:%s.\n%s"),
|
||||
section ? section : "(null)",
|
||||
name ? name : "(null)",
|
||||
message ? message : "(null)");
|
||||
|
||||
@@ -181,6 +181,11 @@
|
||||
"d" (N_ "Enables support for the European Union EURO currency")
|
||||
(gnc:is-euro-currency-code (gnc:locale-default-iso-currency-code))))
|
||||
|
||||
(gnc:register-configuration-option
|
||||
(gnc:make-dateformat-option
|
||||
(N_ "International") (N_ "Fancy Date Format")
|
||||
"e" (N_ "The default date format used for fancy printed dates") #f))
|
||||
|
||||
|
||||
;;; Register options
|
||||
|
||||
|
||||
@@ -183,7 +183,7 @@ book_id_handler (xmlNodePtr node, gpointer book_pdata)
|
||||
GUID *guid;
|
||||
|
||||
guid = dom_tree_to_guid(node);
|
||||
qof_book_set_guid(book, *guid);
|
||||
qof_book_set_guid(book, guid);
|
||||
|
||||
g_free(guid);
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ gnc_freqSpec_dom_tree_create( FreqSpec *fs )
|
||||
ret = xmlNewNode( NULL, "gnc:freqspec" );
|
||||
xmlSetProp( ret, "version", freqspec_version_string );
|
||||
|
||||
xmlAddChild( ret, guid_to_dom_tree( "fs:id", &fs->guid ) );
|
||||
xmlAddChild( ret, guid_to_dom_tree( "fs:id", &fs->entity.guid ) );
|
||||
|
||||
xmlSub = text_to_dom_tree( "fs:ui_type",
|
||||
uiFreqTypeStrs[ xaccFreqSpecGetUIType(fs) ].str );
|
||||
@@ -507,7 +507,7 @@ fs_guid_handler( xmlNodePtr node, gpointer data)
|
||||
fsParseData *fspd = data;
|
||||
GUID *guid;
|
||||
guid = dom_tree_to_guid( node );
|
||||
fspd->fs->guid = *guid;
|
||||
fspd->fs->entity.guid = *guid;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ sx_id_handler( xmlNodePtr node, gpointer sx_pdata )
|
||||
GUID *tmp = dom_tree_to_guid( node );
|
||||
|
||||
g_return_val_if_fail( tmp, FALSE );
|
||||
xaccSchedXactionSetGUID(sx, *tmp);
|
||||
xaccSchedXactionSetGUID(sx, tmp);
|
||||
g_free( tmp );
|
||||
|
||||
return TRUE;
|
||||
@@ -668,15 +668,13 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
|
||||
xaccAccountGetName( acct ), id );
|
||||
|
||||
/* FIXME: free existing template account.
|
||||
* HUH????? We only execute this if there isn't
|
||||
* currently an existing template account, don't we?
|
||||
* <rgmerk>
|
||||
*/
|
||||
* HUH????? We only execute this if there isn't
|
||||
* currently an existing template account, don't we?
|
||||
* <rgmerk>
|
||||
*/
|
||||
|
||||
sx->template_acct = acct;
|
||||
}
|
||||
|
||||
xaccSchedXactionSetDirtyness(sx, FALSE);
|
||||
xmlFreeNode( tree );
|
||||
|
||||
return successful;
|
||||
|
||||
@@ -312,7 +312,7 @@ spl_account_handler(xmlNodePtr node, gpointer data)
|
||||
|
||||
account = xaccAccountLookup (id, pdata->book);
|
||||
if (!account && gnc_transaction_xml_v2_testing &&
|
||||
!guid_equal (id, xaccGUIDNULL ()))
|
||||
!guid_equal (id, guid_null ()))
|
||||
{
|
||||
account = xaccMallocAccount (pdata->book);
|
||||
xaccAccountSetGUID (account, id);
|
||||
@@ -338,7 +338,7 @@ spl_lot_handler(xmlNodePtr node, gpointer data)
|
||||
|
||||
lot = gnc_lot_lookup (id, pdata->book);
|
||||
if (!lot && gnc_transaction_xml_v2_testing &&
|
||||
!guid_equal (id, xaccGUIDNULL ()))
|
||||
!guid_equal (id, guid_null ()))
|
||||
{
|
||||
lot = gnc_lot_new (pdata->book);
|
||||
gnc_lot_set_guid (lot, *id);
|
||||
|
||||
@@ -556,7 +556,9 @@ qof_session_load_from_binfile(QofBook *book, const char * datafile)
|
||||
return;
|
||||
}
|
||||
|
||||
xaccDisableDataScrubbing();
|
||||
gnc_load_financials_from_fd(book, fd);
|
||||
xaccEnableDataScrubbing();
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
*
|
||||
* NOTE: These routines should not be used directly for file IO. They
|
||||
* are not inherently safe against file-locking errors. For direct
|
||||
* file IO, the gnc-book's higher level functions should be used.
|
||||
* file IO, the QofBook's higher level functions should be used.
|
||||
*
|
||||
* qof_session_load_from_binfile() will load the financial data
|
||||
* represented by the book's file_path into the indicated book.
|
||||
|
||||
@@ -370,6 +370,7 @@ qof_session_load_from_xml_file(QofBook *book, const char *filename)
|
||||
g_return_val_if_fail(book, FALSE);
|
||||
g_return_val_if_fail(filename, FALSE);
|
||||
|
||||
xaccDisableDataScrubbing();
|
||||
top_level_pr = gncxml_setup_for_read (&global_parse_status);
|
||||
g_return_val_if_fail(top_level_pr, FALSE);
|
||||
|
||||
@@ -380,6 +381,7 @@ qof_session_load_from_xml_file(QofBook *book, const char *filename)
|
||||
&parse_result);
|
||||
|
||||
sixtp_destroy(top_level_pr);
|
||||
xaccEnableDataScrubbing();
|
||||
|
||||
if(parse_ok)
|
||||
{
|
||||
@@ -1384,8 +1386,8 @@ account_restore_after_child_handler(gpointer data_for_children,
|
||||
if(strcmp(child_result->tag, "slots") == 0) {
|
||||
kvp_frame *f = (kvp_frame *) child_result->data;
|
||||
g_return_val_if_fail(f, FALSE);
|
||||
if(a->kvp_data) kvp_frame_delete(a->kvp_data);
|
||||
a->kvp_data = f;
|
||||
if(a->inst.kvp_data) kvp_frame_delete(a->inst.kvp_data);
|
||||
a->inst.kvp_data = f;
|
||||
child_result->should_cleanup = FALSE;
|
||||
}
|
||||
else if(strcmp(child_result->tag, "currency") == 0) {
|
||||
@@ -2819,8 +2821,7 @@ txn_restore_after_child_handler(gpointer data_for_children,
|
||||
if(strcmp(child_result->tag, "slots") == 0) {
|
||||
kvp_frame *f = (kvp_frame *) child_result->data;
|
||||
g_return_val_if_fail(f, FALSE);
|
||||
if(trans->kvp_data) kvp_frame_delete(trans->kvp_data);
|
||||
trans->kvp_data = f;
|
||||
qof_instance_set_slots(QOF_INSTANCE(trans),f);
|
||||
child_result->should_cleanup = FALSE;
|
||||
}
|
||||
return(TRUE);
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "SX-book.h"
|
||||
#include "SX-book-p.h"
|
||||
#include "Transaction.h"
|
||||
#include "TransactionP.h"
|
||||
#include "TransLog.h"
|
||||
#include "qofbackend-p.h"
|
||||
#include "qofbook.h"
|
||||
@@ -420,22 +421,20 @@ gnc_counter_sixtp_parser_create(void)
|
||||
return sixtp_dom_parser_new(gnc_counter_end_handler, NULL, NULL);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
print_counter_data(load_counter *data)
|
||||
{
|
||||
PINFO("Transactions: Total: %d, Loaded: %d\n",
|
||||
PINFO("Transactions: Total: %d, Loaded: %d",
|
||||
data->transactions_total, data->transactions_loaded);
|
||||
PINFO("Accounts: Total: %d, Loaded: %d\n",
|
||||
PINFO("Accounts: Total: %d, Loaded: %d",
|
||||
data->accounts_total, data->accounts_loaded);
|
||||
PINFO("Books: Total: %d, Loaded: %d\n",
|
||||
PINFO("Books: Total: %d, Loaded: %d",
|
||||
data->books_total, data->books_loaded);
|
||||
PINFO("Commodities: Total: %d, Loaded: %d\n",
|
||||
PINFO("Commodities: Total: %d, Loaded: %d",
|
||||
data->commodities_total, data->commodities_loaded);
|
||||
PINFO("Scheduled Tansactions: Total: %d, Loaded: %d\n",
|
||||
PINFO("Scheduled Tansactions: Total: %d, Loaded: %d",
|
||||
data->schedXactions_total, data->schedXactions_loaded);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
file_rw_feedback (sixtp_gdv2 *gd, const char *type)
|
||||
@@ -700,14 +699,23 @@ qof_session_load_from_xml_file_v2(FileBackend *fbe, QofBook *book)
|
||||
|
||||
/* stop logging while we load */
|
||||
xaccLogDisable ();
|
||||
xaccDisableDataScrubbing();
|
||||
|
||||
if(!gnc_xml_parse_file(top_parser, fbe->fullpath,
|
||||
generic_callback, gd, book))
|
||||
{
|
||||
sixtp_destroy(top_parser);
|
||||
xaccLogEnable ();
|
||||
xaccEnableDataScrubbing();
|
||||
goto bail;
|
||||
}
|
||||
DEBUGCMD (print_counter_data(&gd->counter));
|
||||
|
||||
/* destroy the parser */
|
||||
sixtp_destroy (top_parser);
|
||||
g_free(gd);
|
||||
|
||||
xaccEnableDataScrubbing();
|
||||
|
||||
/* Mark the book as saved */
|
||||
qof_book_mark_saved (book);
|
||||
@@ -732,16 +740,9 @@ qof_session_load_from_xml_file_v2(FileBackend *fbe, QofBook *book)
|
||||
*/
|
||||
xaccAccountGroupCommitEdit (grp);
|
||||
|
||||
/* destroy the parser */
|
||||
sixtp_destroy (top_parser);
|
||||
|
||||
/* start logging again */
|
||||
xaccLogEnable ();
|
||||
|
||||
g_free(gd);
|
||||
/* DEBUG */
|
||||
/* print_counter_data(&gd->counter); */
|
||||
|
||||
return TRUE;
|
||||
|
||||
bail:
|
||||
|
||||
@@ -29,10 +29,10 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-xml.h"
|
||||
#include "gnc-xml.h"
|
||||
#include "io-utils.h"
|
||||
#include "qofbook.h"
|
||||
|
||||
/*
|
||||
<!-- Local variables: -->
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "Group.h"
|
||||
#include "io-gncxml-v2.h"
|
||||
#include "qofbook.h"
|
||||
|
||||
void write_account_group(FILE *out, AccountGroup *grp, sixtp_gdv2 *gd);
|
||||
void write_accounts(FILE *out, QofBook *book, sixtp_gdv2 *gd);
|
||||
|
||||
@@ -33,9 +33,9 @@
|
||||
#include "sixtp-dom-generators.h"
|
||||
#include "sixtp-utils.h"
|
||||
|
||||
#include "GNCId.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "qofid.h"
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
#include "gnc-xml-helper.h"
|
||||
|
||||
#include "sixtp-dom-generators.h"
|
||||
#include "GNCId.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-date.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "qofid.h"
|
||||
|
||||
xmlNodePtr text_to_dom_tree(const char *tag, const char *str);
|
||||
xmlNodePtr int_to_dom_tree(const char *tag, gint64 val);
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "qofid.h"
|
||||
|
||||
#include "sixtp-utils.h"
|
||||
#include "sixtp-dom-parsers.h"
|
||||
#include "GNCId.h"
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
|
||||
@@ -31,11 +31,11 @@
|
||||
#include "gnc-xml-helper.h"
|
||||
|
||||
#include "FreqSpec.h"
|
||||
#include "GNCId.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-date.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
|
||||
|
||||
GUID* dom_tree_to_guid(xmlNodePtr node);
|
||||
|
||||
@@ -181,7 +181,7 @@ equals_node_val_vs_guid(xmlNodePtr node, const GUID *id)
|
||||
}
|
||||
|
||||
gboolean
|
||||
equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com, GNCBook *book)
|
||||
equals_node_val_vs_commodity(xmlNodePtr node, const gnc_commodity *com, QofBook *book)
|
||||
{
|
||||
gnc_commodity *cmpcom;
|
||||
|
||||
@@ -301,7 +301,7 @@ grab_file_doc(const char *filename)
|
||||
static void
|
||||
test_load_file(const char *filename, gxpf_callback cb,
|
||||
sixtp *parser, const char *parser_tag,
|
||||
GNCBook *book)
|
||||
QofBook *book)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
sixtp *main_parser;
|
||||
@@ -347,7 +347,7 @@ test_load_file(const char *filename, gxpf_callback cb,
|
||||
void
|
||||
test_files_in_dir(int argc, char **argv, gxpf_callback cb,
|
||||
sixtp *parser, const char *parser_tag,
|
||||
GNCBook *book)
|
||||
QofBook *book)
|
||||
{
|
||||
int count;
|
||||
|
||||
|
||||
@@ -102,10 +102,10 @@ AM_CFLAGS = \
|
||||
|
||||
$(M4_SRC): table.m4
|
||||
|
||||
%-autogen.c: %-objects.m4
|
||||
%-autogen.c: %-objects.m4 table.m4
|
||||
m4 -I ${srcdir} $< > $@
|
||||
|
||||
%-autogen.h: %-objects-header.m4
|
||||
%-autogen.h: %-objects-header.m4 table.m4
|
||||
m4 -I ${srcdir} $< > $@
|
||||
|
||||
.sql.c:
|
||||
|
||||
@@ -197,18 +197,38 @@ pgendSplitLookup (PGBackend *be, const GUID *split_guid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct _iter {
|
||||
const GUID *guid;
|
||||
QofEntity *ent;
|
||||
};
|
||||
|
||||
static void
|
||||
cforeach (QofCollection *col, gpointer data)
|
||||
{
|
||||
struct _iter *iter = data;
|
||||
if (iter->ent) return;
|
||||
iter->ent = qof_collection_lookup_entity (col, iter->guid);
|
||||
}
|
||||
|
||||
QofIdType
|
||||
pgendGUIDType (PGBackend *be, const GUID *guid)
|
||||
{
|
||||
GList *node;
|
||||
QofIdType tip = GNC_ID_NONE;
|
||||
struct _iter iter;
|
||||
|
||||
iter.guid = guid;
|
||||
iter.ent = NULL;
|
||||
|
||||
ENTER("guid = %s", guid_to_string(guid));
|
||||
for (node=be->blist; node; node=node->next)
|
||||
{
|
||||
QofBook *book = node->data;
|
||||
tip = qof_entity_type (qof_book_get_entity_table(book), guid);
|
||||
if (GNC_ID_NONE != tip) { LEAVE("tip = %s", tip); return tip; }
|
||||
qof_book_foreach_collection (book, cforeach, &iter);
|
||||
if (iter.ent)
|
||||
{
|
||||
LEAVE("tip = %s", iter.ent->e_type);
|
||||
return iter.ent->e_type;
|
||||
}
|
||||
}
|
||||
|
||||
LEAVE("tip = NULL");
|
||||
@@ -559,7 +579,7 @@ pgendFillOutToCheckpoint (PGBackend *be, const char *query_string)
|
||||
Transaction *trans = (Transaction *) node->data;
|
||||
GList *engine_splits, *snode;
|
||||
|
||||
trans->kvp_data = pgendKVPFetch (be, trans->idata, trans->kvp_data);
|
||||
trans->inst.kvp_data = pgendKVPFetch (be, trans->idata, trans->inst.kvp_data);
|
||||
|
||||
engine_splits = xaccTransGetSplitList(trans);
|
||||
for (snode = engine_splits; snode; snode=snode->next)
|
||||
@@ -911,7 +931,7 @@ pgendSync (QofBackend *bend, QofBook *book)
|
||||
/* hack alert -- In some deranged theory, we should be
|
||||
* syncing prices here, as well as syncing any/all other
|
||||
* engine structures that need to be stored. But instead,
|
||||
* price syn is handled as a separate routine ...
|
||||
* price sync is handled as a separate routine ...
|
||||
*/
|
||||
|
||||
/* re-enable events */
|
||||
|
||||
@@ -1,11 +1,43 @@
|
||||
|
||||
This directory contains code for SQL/Postgres support. The
|
||||
SQL backend allows multiple users to view/edit the same data
|
||||
at the same time, as well as allowing a single user to
|
||||
keep data in an SQL database. This code is 'beta': it seems
|
||||
to work, but really has not been heavily tested by lots
|
||||
of users, and may still contain bugs. See also the
|
||||
'to be done' list at the bottom.
|
||||
GnuCash SQL/Postgres Support/HOWTO
|
||||
----------------------------------
|
||||
|
||||
This directory contains code for SQL/Postgres support.
|
||||
|
||||
The SQL backend allows multiple users to view/edit the same data
|
||||
at the same time, as well as allowing a single user to keep data
|
||||
in an SQL database.
|
||||
|
||||
|
||||
Status
|
||||
------
|
||||
The SQL code has been "finished" for many years, and hasn't been
|
||||
in recent active development. This means that the current SQL
|
||||
backend does not support some of the newer GnuCash features;
|
||||
in particular, it doesn't support the business objects needed for
|
||||
the business accounting. It also doesn't currently support
|
||||
scheduled/recurring transactions. Although the development is
|
||||
currently dormant, we believe that it may heat up real soon,
|
||||
since there is a core group of developers who are interested
|
||||
in making SQL the default for all future versions of GnuCash.
|
||||
|
||||
As long as development is dormant, note that you may not get
|
||||
prompt support on the mailing list, and, if you find bugs, they
|
||||
might not be fixed quickly.
|
||||
|
||||
Currently, only Postgres is supported, but other databases are
|
||||
planned. See also the 'to be done' list at the bottom for more
|
||||
detail.
|
||||
|
||||
Table of Contents
|
||||
-----------------
|
||||
-- Postgres Install Instructions
|
||||
-- GnuCash Build Instructions
|
||||
-- How To Use GnuCash with Postgres
|
||||
-- Remote Access
|
||||
-- Access Modes
|
||||
-- Performance
|
||||
-- ToDo List
|
||||
|
||||
|
||||
Postgres Install Instructions
|
||||
@@ -13,9 +45,9 @@ Postgres Install Instructions
|
||||
1) Install PostgresSQL server, client and devel packages.
|
||||
(Both the 6.x and the 7.x versions of Postgres should work).
|
||||
|
||||
2) if installed from redhat, then running /etc/rc.d/init.d/postgresql
|
||||
2) If installed from RedHat, then running /etc/rc.d/init.d/postgresql
|
||||
will setup and initialize basic Postgres first-time setup & config.
|
||||
3) as root, 'su - postgres' then run 'createuser' to add your user id
|
||||
3) As root, 'su - postgres' then run 'createuser' to add your user id
|
||||
(don't set a password on your postgres db name, yet, GnuCash doesn't
|
||||
have a GUI to ask for your password yet)
|
||||
If you've forgotten what users are on the system, you can check
|
||||
@@ -76,45 +108,49 @@ Same as usual, but you must specify the flag '--enable-sql' in order
|
||||
to build in Postgres support.
|
||||
i.e.
|
||||
./configure --enable-sql
|
||||
and then 'make'.
|
||||
and then 'make' and then 'make install'
|
||||
|
||||
|
||||
How To Use This Thing
|
||||
---------------------
|
||||
How To Use GnuCash with Postgres
|
||||
--------------------------------
|
||||
a) Open your favorite datafile in the usual fashion.
|
||||
b) Click on 'Save As'
|
||||
c) enter the following URL instead of a filename in the file picker:
|
||||
c) Enter the following URL instead of a filename in the file picker:
|
||||
postgres://localhost/some_dbname_you_pick
|
||||
|
||||
The above steps will copy your data into that database. You can
|
||||
then restart gnucash (or keep working) and type in the same URL
|
||||
in the file open dialogs. Or try it on the command line:
|
||||
|
||||
/usr/local/bin/gnucash postgres://localhost/dbname_whatever
|
||||
home:~ $ gnucash postgres://localhost/dbname_whatever
|
||||
|
||||
Note: GnuCash will automatically create the database if it does
|
||||
not already exist. Do *not* try to create the database by hand,
|
||||
or to specify a database that wasn't created by GnuCash.
|
||||
|
||||
Warning: the postgres backend is in active development,
|
||||
and occasionally the database format changes in a way that is
|
||||
not backwards compatible. If you have data that you want to
|
||||
move from older to newer versions, you can do the following:
|
||||
-- start up older version of gnucash, open your postgres://...
|
||||
URL.
|
||||
-- 'save as' to an ordinary gnucash file (its a flat XML file)
|
||||
-- exit the program.
|
||||
-- start the newer version of gnucash, open the XML file.
|
||||
-- 'save as' a new postgres database. (be sure to pick a new name).
|
||||
|
||||
You can also "copy" from the SQL database to an XML file.
|
||||
If you don't trust the SQL backend, this might be a good way to
|
||||
backup your data. To do this:
|
||||
|
||||
a) Open the SQL database in "single user mode":
|
||||
postgres://localhost/dbname_whatever?mode=single-update
|
||||
It is important to specify the single-user mode
|
||||
(if you don't, not all of your data will be saved to the file)
|
||||
b) Click on 'Save As' and enter an ordinary file name.
|
||||
|
||||
We promise that future versions of GnuCash will be backwards
|
||||
compatible with the current SQL database layout. There is a
|
||||
specific upgrade module designed into the system that handles
|
||||
version upgrades.
|
||||
|
||||
|
||||
Remote Access
|
||||
-------------
|
||||
In principle, you can use URL's such as:
|
||||
postgres://some.where.com/dbname
|
||||
However, these URL's require that the host 'some.where.com' have
|
||||
TCPIP access enabled (by following instructions (6) above).
|
||||
This is true even if the hostname is your local machine. Thus,
|
||||
TCPIP access enabled (by following the postgres install instruction (6)
|
||||
above). This is true even if the hostname is your local machine. Thus,
|
||||
unless you've setup Postgres TCPIP connections, you *MUST* use
|
||||
URL's of the form postgres://localhost/dbname
|
||||
|
||||
@@ -209,7 +245,7 @@ probably fix any weird account balances you are seeing.
|
||||
a test case that can reliably recreate these, you should
|
||||
submit a bug report).
|
||||
|
||||
(Note to developers: think of this as an fsck: balances
|
||||
(Note to developers: think of this as a safe fsck: balances
|
||||
shouldn't get wacky, but if you've been running a long time
|
||||
and something weird has happened, then a periodic cleanup
|
||||
is good to have. Maybe this should be automated ...)
|
||||
@@ -261,9 +297,27 @@ To Be Done
|
||||
----------
|
||||
Core bugs/features that still need work:
|
||||
|
||||
(none in this list are truly critical at this point, except possibly
|
||||
High Priority:
|
||||
--------------
|
||||
Currently, the database backend is completely missing support for
|
||||
"lots", and thus cannot support capital gains computations. It is
|
||||
also missing support for business objects.
|
||||
|
||||
-- remove the bogus 'price query' call in the backend, change it to
|
||||
use the qof query infrastructure.
|
||||
|
||||
-- port to use SQLLite as a possible backend. Will need to abandon
|
||||
balance checkpoints to do this.
|
||||
|
||||
|
||||
Medium/Low Priority Work:
|
||||
-------------------------
|
||||
Nothing in this list is truly critical at this point, except possibly
|
||||
the username/password dialog, and its effect with regards to initial db
|
||||
access).
|
||||
access.
|
||||
|
||||
-- port to use libdbi bindings, instead of the postgres native
|
||||
call interface. This should be easy.
|
||||
|
||||
-- Wire in the GUI to ask user for username/password to log onto the
|
||||
server. (GUI already implemented, just not yet used).
|
||||
|
||||
@@ -92,7 +92,7 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct,
|
||||
const gnc_commodity *com;
|
||||
|
||||
if (!be || !acct) return;
|
||||
if ((FALSE == do_mark) && (FALSE == acct->core_dirty)) return;
|
||||
if ((FALSE == do_mark) && (FALSE == acct->inst.dirty)) return;
|
||||
|
||||
ENTER ("acct=%p, mark=%d", acct, do_mark);
|
||||
|
||||
@@ -139,7 +139,7 @@ pgendStoreAccountNoLock (PGBackend *be, Account *acct,
|
||||
if (acct->idata)
|
||||
{
|
||||
pgendKVPDelete (be, acct->idata);
|
||||
pgendKVPStore (be, acct->idata, acct->kvp_data);
|
||||
pgendKVPStore (be, acct->idata, acct->inst.kvp_data);
|
||||
}
|
||||
LEAVE(" ");
|
||||
}
|
||||
@@ -227,7 +227,7 @@ restore_cb (Account *acc, void * cb_data)
|
||||
{
|
||||
PGBackend *be = (PGBackend *) cb_data;
|
||||
if (0 == acc->idata) return NULL;
|
||||
acc->kvp_data = pgendKVPFetch (be, acc->idata, acc->kvp_data);
|
||||
acc->inst.kvp_data = pgendKVPFetch (be, acc->idata, acc->inst.kvp_data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid)
|
||||
{
|
||||
if (acc->idata)
|
||||
{
|
||||
acc->kvp_data = pgendKVPFetch (be, acc->idata, acc->kvp_data);
|
||||
acc->inst.kvp_data = pgendKVPFetch (be, acc->idata, acc->inst.kvp_data);
|
||||
}
|
||||
|
||||
acc->version_check = be->version_check;
|
||||
@@ -585,7 +585,7 @@ pgend_account_commit_edit (QofBackend * bend,
|
||||
ENTER ("be=%p, acct=%p", be, acct);
|
||||
if (!be || !acct) return;
|
||||
|
||||
if (FALSE == acct->core_dirty)
|
||||
if (FALSE == acct->inst.dirty)
|
||||
{
|
||||
parent = xaccAccountGetParent(acct);
|
||||
if (parent) parent->saved = 1;
|
||||
@@ -607,7 +607,7 @@ pgend_account_commit_edit (QofBackend * bend,
|
||||
* made changes, and we must roll back. */
|
||||
if (0 < pgendAccountCompareVersion (be, acct))
|
||||
{
|
||||
acct->do_free = FALSE;
|
||||
acct->inst.do_free = FALSE;
|
||||
p = "ROLLBACK;";
|
||||
SEND_QUERY (be,p,);
|
||||
FINISH_QUERY(be->connection);
|
||||
@@ -624,7 +624,7 @@ pgend_account_commit_edit (QofBackend * bend,
|
||||
acct->version ++; /* be sure to update the version !! */
|
||||
acct->version_check = be->version_check;
|
||||
|
||||
if (acct->do_free)
|
||||
if (acct->inst.do_free)
|
||||
{
|
||||
const GUID *guid = xaccAccountGetGUID(acct);
|
||||
pgendKVPDelete (be, acct->idata);
|
||||
|
||||
@@ -145,7 +145,7 @@ get_one_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
guid = nullguid; /* just in case the read fails ... */
|
||||
string_to_guid (DB_GET_VAL("bookGuid",j), &guid);
|
||||
|
||||
qof_book_set_guid (book, guid);
|
||||
qof_book_set_guid (book, &guid);
|
||||
|
||||
book->book_open = (DB_GET_VAL("book_open",j))[0];
|
||||
book->version = atoi(DB_GET_VAL("version",j));
|
||||
@@ -200,14 +200,14 @@ get_book_cb (PGBackend *be, PGresult *result, int j, gpointer data)
|
||||
for (node=blist; node; node=node->next)
|
||||
{
|
||||
book = node->data;
|
||||
if (guid_equal (&book->guid, &guid)) break;
|
||||
if (guid_equal (&book->entity.guid, &guid)) break;
|
||||
book = NULL;
|
||||
}
|
||||
|
||||
if (!book)
|
||||
{
|
||||
book = qof_book_new();
|
||||
qof_book_set_guid (book, guid);
|
||||
qof_book_set_guid (book, &guid);
|
||||
}
|
||||
|
||||
book->book_open = (DB_GET_VAL("book_open",j))[0];
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
#include "qofquery.h"
|
||||
#include "qofquery-p.h"
|
||||
#include "qofquerycore-p.h"
|
||||
#include "qofqueryobject.h"
|
||||
#include "qofclass.h"
|
||||
|
||||
#include "gncquery.h"
|
||||
#include "builder.h"
|
||||
@@ -755,13 +755,13 @@ sqlQuery_build(sqlQuery * sq, Query * q)
|
||||
} else if (!safe_strcmp(path->data, SPLIT_VALUE)) {
|
||||
need_entry = TRUE;
|
||||
need_trans_commodity = TRUE;
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_GUID)) {
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID)) {
|
||||
if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID))
|
||||
need_entry = TRUE;
|
||||
else if (!safe_strcmp(path->data, SPLIT_ACCOUNT)) {
|
||||
need_account = TRUE;
|
||||
}
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_KVP)) {
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP)) {
|
||||
if (!safe_strcmp(path->data, SPLIT_KVP))
|
||||
need_entry = TRUE;
|
||||
else if (!safe_strcmp(path->data, SPLIT_ACCOUNT))
|
||||
@@ -855,12 +855,12 @@ sqlQuery_build(sqlQuery * sq, Query * q)
|
||||
path = qof_query_term_get_param_path(qt);
|
||||
invert = qof_query_term_is_inverted(qt);
|
||||
|
||||
if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_GUID)) {
|
||||
if (!safe_strcmp(pd->type_name, QOF_TYPE_GUID)) {
|
||||
query_guid_t pdata = (query_guid_t) pd;
|
||||
GList *node;
|
||||
char *field = NULL;
|
||||
|
||||
PINFO("term is QOF_QUERYCORE_GUID");
|
||||
PINFO("term is QOF_TYPE_GUID");
|
||||
|
||||
if (!safe_strcmp(path->data, QOF_QUERY_PARAM_GUID)) {
|
||||
field = "gncSplit.splitGuid";
|
||||
@@ -959,7 +959,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
|
||||
more_and = 0;
|
||||
}
|
||||
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_STRING)) {
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING)) {
|
||||
query_string_t pdata = (query_string_t) pd;
|
||||
|
||||
if (!safe_strcmp(path->data, SPLIT_ACTION)) {
|
||||
@@ -991,7 +991,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
|
||||
(char *)(path->data));
|
||||
|
||||
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_NUMERIC)) {
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_TYPE_NUMERIC)) {
|
||||
query_numeric_t pdata = (query_numeric_t) pd;
|
||||
|
||||
|
||||
@@ -1022,7 +1022,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
|
||||
PINFO("Unknown NUMERIC: %s", (char *)(path->data));
|
||||
}
|
||||
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_DATE)) {
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_TYPE_DATE)) {
|
||||
query_date_t pdata = (query_date_t) pd;
|
||||
char *field = NULL;
|
||||
const char *op = NULL;
|
||||
@@ -1049,7 +1049,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
|
||||
if (invert)
|
||||
sq->pq = stpcpy(sq->pq, ") ");
|
||||
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_CHAR)) {
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_TYPE_CHAR)) {
|
||||
query_char_t pdata = (query_char_t) pd;
|
||||
int got_one = 0;
|
||||
|
||||
@@ -1076,7 +1076,7 @@ sqlQuery_build(sqlQuery * sq, Query * q)
|
||||
} else
|
||||
PINFO("Unknown CHAR type, %s", (char *)(path->data));
|
||||
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_QUERYCORE_KVP)) {
|
||||
} else if (!safe_strcmp(pd->type_name, QOF_TYPE_KVP)) {
|
||||
query_kvp_t pdata = (query_kvp_t) pd;
|
||||
|
||||
PINFO("term is a KVP");
|
||||
|
||||
@@ -489,7 +489,7 @@ pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr)
|
||||
* made changes, and we must roll back. */
|
||||
if (0 < pgendPriceCompareVersion (be, pr))
|
||||
{
|
||||
pr->do_free = FALSE;
|
||||
pr->inst.do_free = FALSE;
|
||||
bufp = "ROLLBACK;";
|
||||
SEND_QUERY (be,bufp,);
|
||||
FINISH_QUERY(be->connection);
|
||||
@@ -506,7 +506,7 @@ pgend_price_commit_edit (QofBackend * bend, GNCPrice *pr)
|
||||
pr->version ++; /* be sure to update the version !! */
|
||||
pr->version_check = be->version_check;
|
||||
|
||||
if (pr->do_free)
|
||||
if (pr->inst.do_free)
|
||||
{
|
||||
pgendStoreAuditPrice (be, pr, SQL_DELETE);
|
||||
bufp = be->buff; *bufp = 0;
|
||||
|
||||
@@ -348,25 +348,25 @@ int finishQuery(PGBackend *be);
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
|
||||
#define FIND_BOOK(book) { \
|
||||
if (NULL == book) \
|
||||
{ \
|
||||
GList *node; \
|
||||
GUID book_guid; \
|
||||
\
|
||||
/* Find the book that holds this item */ \
|
||||
book_guid = nullguid; /* just in case the read fails */ \
|
||||
string_to_guid (DB_GET_VAL("bookGUID",j), &book_guid); \
|
||||
\
|
||||
book = NULL; \
|
||||
for (node=be->blist; node; node=node->next) \
|
||||
{ \
|
||||
book = node->data; \
|
||||
if (guid_equal (&book->guid, &book_guid)) break; \
|
||||
book = NULL; \
|
||||
} \
|
||||
if (!book) return data; \
|
||||
} \
|
||||
#define FIND_BOOK(book) { \
|
||||
if (NULL == book) \
|
||||
{ \
|
||||
GList *node; \
|
||||
GUID book_guid; \
|
||||
\
|
||||
/* Find the book that holds this item */ \
|
||||
book_guid = nullguid; /* just in case the read fails */ \
|
||||
string_to_guid (DB_GET_VAL("bookGUID",j), &book_guid); \
|
||||
\
|
||||
book = NULL; \
|
||||
for (node=be->blist; node; node=node->next) \
|
||||
{ \
|
||||
book = node->data; \
|
||||
if (guid_equal (&book->entity.guid, &book_guid)) break; \
|
||||
book = NULL; \
|
||||
} \
|
||||
if (!book) return data; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -362,7 +362,7 @@ define(`compare_version',
|
||||
|
||||
p = be->buff; *p = 0;
|
||||
p = stpcpy (p, "SELECT version FROM tablename($@) WHERE key_fieldname($@) = ''`");
|
||||
p = guid_to_string_buff (&(ptr->guid), p);
|
||||
p = guid_to_string_buff (qof_entity_get_guid(QOF_ENTITY(ptr)), p);
|
||||
p = stpcpy (p, "''`;");
|
||||
SEND_QUERY (be,be->buff, -1);
|
||||
sql_version = (int) pgendGetResults (be, get_version_cb, (gpointer) -1);
|
||||
@@ -392,7 +392,7 @@ define(`is_deleted',
|
||||
|
||||
p = be->buff; *p = 0;
|
||||
p = stpcpy (p, "SELECT version FROM tablename($@)" "Trail WHERE key_fieldname($@) = ''`");
|
||||
p = guid_to_string_buff (&(ptr->guid), p);
|
||||
p = guid_to_string_buff (qof_entity_get_guid(QOF_ENTITY(ptr)), p);
|
||||
p = stpcpy (p, "''` AND change = ''`d''`;");
|
||||
SEND_QUERY (be,be->buff, -1);
|
||||
sql_version = (int) pgendGetResults (be, get_version_cb, (gpointer) -1);
|
||||
|
||||
@@ -178,7 +178,7 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
|
||||
{
|
||||
Split *s = split_node->data;
|
||||
|
||||
if (s && guid_equal (&s->guid, &dti->guid))
|
||||
if (s && guid_equal (&s->entity.guid, &dti->guid))
|
||||
{
|
||||
pgendStoreAuditSplit (be, s, SQL_DELETE);
|
||||
break;
|
||||
@@ -218,8 +218,8 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
|
||||
/* Update the rest */
|
||||
start = xaccTransGetSplitList(trans);
|
||||
|
||||
PINFO ("split-list=%p, do_free=%d", start, trans->do_free);
|
||||
if ((start) && !(trans->do_free))
|
||||
PINFO ("split-list=%p, do_free=%d", start, trans->inst.do_free);
|
||||
if ((start) && !(trans->inst.do_free))
|
||||
{
|
||||
gnc_commodity *com;
|
||||
|
||||
@@ -255,7 +255,7 @@ pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans,
|
||||
if (trans->idata)
|
||||
{
|
||||
pgendKVPDelete (be, trans->idata);
|
||||
pgendKVPStore (be, trans->idata, trans->kvp_data);
|
||||
pgendKVPStore (be, trans->idata, trans->inst.kvp_data);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -473,7 +473,7 @@ pgendCopySplitsToEngine (PGBackend *be, Transaction *trans)
|
||||
s = pgendSplitLookup (be, &guid);
|
||||
if (!s)
|
||||
{
|
||||
s = xaccMallocSplit(trans->book);
|
||||
s = xaccMallocSplit(trans->inst.book);
|
||||
xaccSplitSetGUID(s, &guid);
|
||||
}
|
||||
|
||||
@@ -809,13 +809,13 @@ pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid)
|
||||
|
||||
if (0 != trans->idata)
|
||||
{
|
||||
if (!kvp_frame_is_empty (trans->kvp_data))
|
||||
if (!kvp_frame_is_empty (trans->inst.kvp_data))
|
||||
{
|
||||
kvp_frame_delete (trans->kvp_data);
|
||||
trans->kvp_data = kvp_frame_new ();
|
||||
kvp_frame_delete (trans->inst.kvp_data);
|
||||
trans->inst.kvp_data = kvp_frame_new ();
|
||||
}
|
||||
|
||||
trans->kvp_data = pgendKVPFetch (be, trans->idata, trans->kvp_data);
|
||||
trans->inst.kvp_data = pgendKVPFetch (be, trans->idata, trans->inst.kvp_data);
|
||||
}
|
||||
|
||||
engine_splits = xaccTransGetSplitList(trans);
|
||||
@@ -1003,7 +1003,7 @@ pgend_trans_commit_edit (QofBackend * bend,
|
||||
"\ttransaction is '%s' %s\n",
|
||||
xaccTransGetDescription (trans), buf);
|
||||
rollback = 0;
|
||||
trans->do_free = TRUE;
|
||||
trans->inst.do_free = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -269,7 +269,7 @@ pgendGetMassTransactions (PGBackend *be, QofBook *book)
|
||||
|
||||
if (trans->idata)
|
||||
{
|
||||
trans->kvp_data = pgendKVPFetch (be, trans->idata, trans->kvp_data);
|
||||
trans->inst.kvp_data = pgendKVPFetch (be, trans->idata, trans->inst.kvp_data);
|
||||
}
|
||||
|
||||
splits = xaccTransGetSplitList(trans);
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef RPC_BACKEND_H
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef RPC_SERVER_H
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef RPC_SERVERP_H
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <netdb.h>
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef RPC_SOCK_H
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "RpcUtils.h"
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef RPC_UTILS_H
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_ACCOUNT_X
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_COMMODITY_X
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_GUID_X
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_KVP_X
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_PRICE_X
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_QUERY_X
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifdef RPC_XDR
|
||||
|
||||
@@ -11,6 +11,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "gncRpc.h"
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_SPLIT_X
|
||||
|
||||
@@ -8,6 +8,23 @@
|
||||
* HISTORY:
|
||||
* Created By: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001, Derek Atkins
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __GNC_TXN_X
|
||||
|
||||
@@ -7,7 +7,24 @@
|
||||
* received.
|
||||
*
|
||||
* Created by: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -9,7 +9,24 @@
|
||||
* received.
|
||||
*
|
||||
* Created by: Derek Atkins <warlord@MIT.EDU>
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef RPC_XPRT_THRD_H
|
||||
|
||||
@@ -3,6 +3,24 @@
|
||||
* module definition/initialization for the core Business module
|
||||
*
|
||||
* Copyright (c) 2001 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
/* gnc-address-xml-v2.h -- Address XML header
|
||||
*
|
||||
* Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_ADDRESS_XML_V2_H
|
||||
|
||||
@@ -42,13 +42,16 @@
|
||||
#include "io-gncxml-v2.h"
|
||||
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "gnc-bill-term-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofobject.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_BILLTERM_MODULE_NAME
|
||||
#include "xml-helpers.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_BILLTERM
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -76,36 +79,15 @@ const gchar *billterm_version_string = "2.0.0";
|
||||
#define prox_discount_string "bt-prox:discount"
|
||||
#define prox_cutoff_string "bt-prox:cutoff-day"
|
||||
|
||||
static void
|
||||
maybe_add_guid (xmlNodePtr ptr, const char *tag, GncBillTerm *term)
|
||||
{
|
||||
if (term)
|
||||
xmlAddChild (ptr, guid_to_dom_tree (tag, gncBillTermGetGUID (term)));
|
||||
}
|
||||
|
||||
static void
|
||||
maybe_add_int (xmlNodePtr ptr, const char *tag, gint val)
|
||||
{
|
||||
if (val)
|
||||
xmlAddChild (ptr, int_to_dom_tree (tag, val));
|
||||
}
|
||||
|
||||
static void
|
||||
maybe_add_numeric (xmlNodePtr ptr, const char *tag, gnc_numeric val)
|
||||
{
|
||||
if (!gnc_numeric_zero_p (val))
|
||||
xmlAddChild (ptr, gnc_numeric_to_dom_tree (tag, &val));
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
billterm_dom_tree_create (GncBillTerm *term)
|
||||
{
|
||||
xmlNodePtr ret, data;
|
||||
xmlNodePtr ret, data, kvpnode;
|
||||
|
||||
ret = xmlNewNode(NULL, gnc_billterm_string);
|
||||
xmlSetProp(ret, "version", billterm_version_string);
|
||||
|
||||
maybe_add_guid(ret, billterm_guid_string, term);
|
||||
maybe_add_guid(ret, billterm_guid_string, QOF_INSTANCE(term));
|
||||
xmlAddChild(ret, text_to_dom_tree (billterm_name_string,
|
||||
gncBillTermGetName (term)));
|
||||
xmlAddChild(ret, text_to_dom_tree (billterm_desc_string,
|
||||
@@ -116,11 +98,18 @@ billterm_dom_tree_create (GncBillTerm *term)
|
||||
xmlAddChild(ret, int_to_dom_tree (billterm_invisible_string,
|
||||
gncBillTermGetInvisible (term)));
|
||||
|
||||
kvpnode = kvp_frame_to_dom_tree (billterm_slots_string,
|
||||
qof_instance_get_slots (QOF_INSTANCE(term)));
|
||||
if (kvpnode) xmlAddChild (ret, kvpnode);
|
||||
|
||||
|
||||
/* We should not be our own child */
|
||||
if (gncBillTermGetChild(term) != term)
|
||||
maybe_add_guid(ret, billterm_child_string, gncBillTermGetChild (term));
|
||||
maybe_add_guid(ret, billterm_child_string,
|
||||
QOF_INSTANCE(gncBillTermGetChild (term)));
|
||||
|
||||
maybe_add_guid(ret, billterm_parent_string, gncBillTermGetParent (term));
|
||||
maybe_add_guid(ret, billterm_parent_string,
|
||||
QOF_INSTANCE(gncBillTermGetParent (term)));
|
||||
|
||||
switch (gncBillTermGetType (term)) {
|
||||
case GNC_TERM_TYPE_DAYS:
|
||||
@@ -407,7 +396,9 @@ billterm_prox_data_handler (xmlNodePtr node, gpointer billterm_pdata)
|
||||
static gboolean
|
||||
billterm_slots_handler (xmlNodePtr node, gpointer billterm_pdata)
|
||||
{
|
||||
return TRUE;
|
||||
struct billterm_pdata *pdata = billterm_pdata;
|
||||
return dom_tree_to_kvp_frame_given (node,
|
||||
qof_instance_get_slots (QOF_INSTANCE(pdata->term)));
|
||||
}
|
||||
|
||||
static struct dom_tree_handler billterm_handlers_v2[] = {
|
||||
@@ -494,7 +485,7 @@ billterm_sixtp_parser_create(void)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer term_p, gpointer count_p)
|
||||
do_count (QofEntity *term_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
(*count)++;
|
||||
@@ -504,15 +495,15 @@ static int
|
||||
billterm_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_billterm (gpointer term_p, gpointer out_p)
|
||||
xml_add_billterm (QofEntity *term_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncBillTerm *term = term_p;
|
||||
GncBillTerm *term = (GncBillTerm *) term_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
node = billterm_dom_tree_create (term);
|
||||
@@ -524,7 +515,7 @@ xml_add_billterm (gpointer term_p, gpointer out_p)
|
||||
static void
|
||||
billterm_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_billterm, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_billterm, (gpointer) out);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -568,9 +559,9 @@ billterm_find_senior (GncBillTerm *term)
|
||||
|
||||
/* build a list of bill terms that are grandchildren or bogus (empty entry list). */
|
||||
static void
|
||||
billterm_scrub_cb (gpointer term_p, gpointer list_p)
|
||||
billterm_scrub_cb (QofEntity *term_p, gpointer list_p)
|
||||
{
|
||||
GncBillTerm *term = term_p;
|
||||
GncBillTerm *term = GNC_BILLTERM(term_p);
|
||||
GList **list = list_p;
|
||||
|
||||
if (billterm_is_grandchild(term)) {
|
||||
@@ -581,7 +572,7 @@ billterm_scrub_cb (gpointer term_p, gpointer list_p)
|
||||
if (t) {
|
||||
/* Fix up the broken "copy" function */
|
||||
PWARN("Fixing broken child billterm: %s",
|
||||
guid_to_string(gncBillTermGetGUID(term)));
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
|
||||
|
||||
gncBillTermBeginEdit(term);
|
||||
gncBillTermSetType(term, gncBillTermGetType(t));
|
||||
@@ -602,10 +593,10 @@ billterm_scrub_cb (gpointer term_p, gpointer list_p)
|
||||
* grandchildren, then fix them to point to the most senior child
|
||||
*/
|
||||
static void
|
||||
billterm_scrub_invoices (gpointer invoice_p, gpointer ht_p)
|
||||
billterm_scrub_invoices (QofEntity * invoice_p, gpointer ht_p)
|
||||
{
|
||||
GHashTable *ht = ht_p;
|
||||
GncInvoice *invoice = invoice_p;
|
||||
GncInvoice *invoice = GNC_INVOICE(invoice_p);
|
||||
GncBillTerm *term, *new_bt;
|
||||
gint32 count;
|
||||
|
||||
@@ -613,7 +604,7 @@ billterm_scrub_invoices (gpointer invoice_p, gpointer ht_p)
|
||||
if (term) {
|
||||
if (billterm_is_grandchild(term)) {
|
||||
PWARN("Fixing i-billterm on invoice %s\n",
|
||||
guid_to_string(gncInvoiceGetGUID(invoice)));
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(invoice))));
|
||||
new_bt = billterm_find_senior(term);
|
||||
gncInvoiceBeginEdit(invoice);
|
||||
gncInvoiceSetTerms(invoice, new_bt);
|
||||
@@ -629,10 +620,10 @@ billterm_scrub_invoices (gpointer invoice_p, gpointer ht_p)
|
||||
}
|
||||
|
||||
static void
|
||||
billterm_scrub_cust (gpointer cust_p, gpointer ht_p)
|
||||
billterm_scrub_cust (QofEntity * cust_p, gpointer ht_p)
|
||||
{
|
||||
GHashTable *ht = ht_p;
|
||||
GncCustomer *cust = cust_p;
|
||||
GncCustomer *cust = GNC_CUSTOMER(cust_p);
|
||||
GncBillTerm *term;
|
||||
gint32 count;
|
||||
|
||||
@@ -645,10 +636,10 @@ billterm_scrub_cust (gpointer cust_p, gpointer ht_p)
|
||||
}
|
||||
|
||||
static void
|
||||
billterm_scrub_vendor (gpointer vendor_p, gpointer ht_p)
|
||||
billterm_scrub_vendor (QofEntity * vendor_p, gpointer ht_p)
|
||||
{
|
||||
GHashTable *ht = ht_p;
|
||||
GncVendor *vendor = vendor_p;
|
||||
GncVendor *vendor = GNC_VENDOR(vendor_p);
|
||||
GncBillTerm *term;
|
||||
gint32 count;
|
||||
|
||||
@@ -668,7 +659,7 @@ billterm_reset_refcount (gpointer key, gpointer value, gpointer notused)
|
||||
|
||||
if (count != gncBillTermGetRefcount(term) && !gncBillTermGetInvisible(term)) {
|
||||
PWARN("Fixing refcount on billterm %s (%lld -> %d)\n",
|
||||
guid_to_string(gncBillTermGetGUID(term)),
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))),
|
||||
gncBillTermGetRefcount(term), count)
|
||||
gncBillTermSetRefcount(term, count);
|
||||
}
|
||||
@@ -682,17 +673,17 @@ billterm_scrub (GNCBook *book)
|
||||
GncBillTerm *parent, *term;
|
||||
GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
|
||||
gncObjectForeach (GNC_INVOICE_MODULE_NAME, book, billterm_scrub_invoices, ht);
|
||||
gncObjectForeach (GNC_CUSTOMER_MODULE_NAME, book, billterm_scrub_cust, ht);
|
||||
gncObjectForeach (GNC_VENDOR_MODULE_NAME, book, billterm_scrub_vendor, ht);
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, billterm_scrub_cb, &list);
|
||||
qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht);
|
||||
qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht);
|
||||
qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht);
|
||||
qof_object_foreach (GNC_ID_BILLTERM, book, billterm_scrub_cb, &list);
|
||||
|
||||
/* destroy the list of "grandchildren" bill terms */
|
||||
for (node = list; node; node = node->next) {
|
||||
term = node->data;
|
||||
|
||||
PINFO ("deleting grandchild billterm: %s\n",
|
||||
guid_to_string(gncBillTermGetGUID(term)));
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
|
||||
|
||||
/* Make sure the parent has no children */
|
||||
parent = gncBillTermGetParent(term);
|
||||
@@ -723,7 +714,7 @@ gnc_billterm_xml_initialize (void)
|
||||
billterm_scrub,
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-bill-term-xml-v2.h -- billing term xml i/o parser/unparsers
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_BILLTERM_XML_V2_H
|
||||
|
||||
@@ -48,9 +48,12 @@
|
||||
#include "gnc-address-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofinstance.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_CUSTOMER_MODULE_NAME
|
||||
#include "xml-helpers.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_CUSTOMER
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -74,17 +77,10 @@ const gchar *customer_version_string = "2.0.0";
|
||||
#define cust_taxtableoverride_string "cust:use-tt"
|
||||
#define cust_slots_string "cust:slots"
|
||||
|
||||
static void
|
||||
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
|
||||
{
|
||||
if (str && strlen(str) > 0)
|
||||
xmlAddChild (ptr, text_to_dom_tree (tag, str));
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
customer_dom_tree_create (GncCustomer *cust)
|
||||
{
|
||||
xmlNodePtr ret;
|
||||
xmlNodePtr ret, kvpnode;
|
||||
gnc_numeric num;
|
||||
GncBillTerm *term;
|
||||
GncTaxTable *taxtable;
|
||||
@@ -93,7 +89,7 @@ customer_dom_tree_create (GncCustomer *cust)
|
||||
xmlSetProp(ret, "version", customer_version_string);
|
||||
|
||||
xmlAddChild(ret, guid_to_dom_tree(cust_guid_string,
|
||||
gncCustomerGetGUID (cust)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(cust))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(cust_name_string,
|
||||
gncCustomerGetName (cust)));
|
||||
@@ -112,7 +108,7 @@ customer_dom_tree_create (GncCustomer *cust)
|
||||
term = gncCustomerGetTerms (cust);
|
||||
if (term)
|
||||
xmlAddChild(ret, guid_to_dom_tree(cust_terms_string,
|
||||
gncBillTermGetGUID (term)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(term))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(cust_taxincluded_string,
|
||||
gncTaxIncludedTypeToString (
|
||||
@@ -137,7 +133,11 @@ customer_dom_tree_create (GncCustomer *cust)
|
||||
taxtable = gncCustomerGetTaxTable (cust);
|
||||
if (taxtable)
|
||||
xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string,
|
||||
gncTaxTableGetGUID (taxtable)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(taxtable))));
|
||||
|
||||
kvpnode = kvp_frame_to_dom_tree (cust_slots_string,
|
||||
qof_instance_get_slots (QOF_INSTANCE(cust)));
|
||||
if (kvpnode) xmlAddChild (ret, kvpnode);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -371,7 +371,9 @@ customer_taxtableoverride_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
static gboolean
|
||||
customer_slots_handler (xmlNodePtr node, gpointer cust_pdata)
|
||||
{
|
||||
return TRUE;
|
||||
struct customer_pdata *pdata = cust_pdata;
|
||||
return dom_tree_to_kvp_frame_given (node,
|
||||
qof_instance_get_slots (QOF_INSTANCE(pdata->customer)));
|
||||
}
|
||||
|
||||
static struct dom_tree_handler customer_handlers_v2[] = {
|
||||
@@ -478,10 +480,10 @@ customer_should_be_saved (GncCustomer *customer)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer cust_p, gpointer count_p)
|
||||
do_count (QofEntity * cust_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
if (customer_should_be_saved (cust_p))
|
||||
if (customer_should_be_saved ((GncCustomer *)cust_p))
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
@@ -489,18 +491,18 @@ static int
|
||||
customer_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_customer (gpointer cust_p, gpointer out_p)
|
||||
xml_add_customer (QofEntity * cust_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncCustomer *cust = cust_p;
|
||||
GncCustomer *cust = (GncCustomer *) cust_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
if (!customer_should_be_saved (cust_p))
|
||||
if (!customer_should_be_saved (cust))
|
||||
return;
|
||||
|
||||
node = customer_dom_tree_create (cust);
|
||||
@@ -512,7 +514,7 @@ xml_add_customer (gpointer cust_p, gpointer out_p)
|
||||
static void
|
||||
customer_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_customer, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_customer, (gpointer) out);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -528,7 +530,7 @@ gnc_customer_xml_initialize (void)
|
||||
NULL, /* scrub */
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-customer-xml-v2.h -- customer xml i/o parser/unparser
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_CUSTOMER_XML_V2_H
|
||||
|
||||
@@ -46,9 +46,10 @@
|
||||
#include "gnc-address-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofobject.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_EMPLOYEE_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_EMPLOYEE
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -87,7 +88,7 @@ employee_dom_tree_create (GncEmployee *employee)
|
||||
xmlSetProp(ret, "version", employee_version_string);
|
||||
|
||||
xmlAddChild(ret, guid_to_dom_tree(employee_guid_string,
|
||||
gncEmployeeGetGUID (employee)));
|
||||
qof_instance_get_guid(QOF_INSTANCE (employee))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(employee_username_string,
|
||||
gncEmployeeGetUsername (employee)));
|
||||
@@ -119,7 +120,7 @@ employee_dom_tree_create (GncEmployee *employee)
|
||||
ccard_acc = gncEmployeeGetCCard (employee);
|
||||
if (ccard_acc)
|
||||
xmlAddChild(ret, guid_to_dom_tree(employee_ccard_string,
|
||||
xaccAccountGetGUID (ccard_acc)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(ccard_acc))));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -392,10 +393,10 @@ employee_should_be_saved (GncEmployee *employee)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer employee_p, gpointer count_p)
|
||||
do_count (QofEntity * employee_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
if (employee_should_be_saved (employee_p))
|
||||
if (employee_should_be_saved ((GncEmployee *) employee_p))
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
@@ -403,15 +404,15 @@ static int
|
||||
employee_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_employee (gpointer employee_p, gpointer out_p)
|
||||
xml_add_employee (QofEntity * employee_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncEmployee *employee = employee_p;
|
||||
GncEmployee *employee = (GncEmployee *) employee_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
if (!employee_should_be_saved (employee))
|
||||
@@ -426,7 +427,7 @@ xml_add_employee (gpointer employee_p, gpointer out_p)
|
||||
static void
|
||||
employee_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_employee, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_employee, (gpointer) out);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -442,7 +443,7 @@ gnc_employee_xml_initialize (void)
|
||||
NULL, /* scrub */
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-employee-xml-v2.h -- employee xml i/o parser/unparser
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_EMPLOYEE_XML_V2_H
|
||||
|
||||
@@ -49,9 +49,10 @@
|
||||
#include "gnc-owner-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofobject.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ENTRY_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_ENTRY
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -123,7 +124,7 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
xmlSetProp(ret, "version", entry_version_string);
|
||||
|
||||
xmlAddChild(ret, guid_to_dom_tree(entry_guid_string,
|
||||
gncEntryGetGUID (entry)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(entry))));
|
||||
|
||||
ts = gncEntryGetDate (entry);
|
||||
xmlAddChild(ret, timespec_to_dom_tree (entry_date_string, &ts));
|
||||
@@ -143,7 +144,7 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
acc = gncEntryGetInvAccount (entry);
|
||||
if (acc)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_invacct_string,
|
||||
xaccAccountGetGUID (acc)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(acc))));
|
||||
|
||||
maybe_add_numeric (ret, entry_iprice_string, gncEntryGetInvPrice (entry));
|
||||
|
||||
@@ -152,7 +153,7 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
invoice = gncEntryGetInvoice (entry);
|
||||
if (invoice) {
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_invoice_string,
|
||||
gncInvoiceGetGUID (invoice)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(invoice))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(entry_idisctype_string,
|
||||
gncAmountTypeToString (
|
||||
@@ -170,14 +171,14 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
taxtable = gncEntryGetInvTaxTable (entry);
|
||||
if (taxtable)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_itaxtable_string,
|
||||
gncTaxTableGetGUID (taxtable)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(taxtable))));
|
||||
|
||||
/* vendor bills */
|
||||
|
||||
acc = gncEntryGetBillAccount (entry);
|
||||
if (acc)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_billacct_string,
|
||||
xaccAccountGetGUID (acc)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(acc))));
|
||||
|
||||
maybe_add_numeric (ret, entry_bprice_string, gncEntryGetBillPrice (entry));
|
||||
|
||||
@@ -185,7 +186,7 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
if (invoice) {
|
||||
GncOwner *owner;
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_bill_string,
|
||||
gncInvoiceGetGUID (invoice)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(invoice))));
|
||||
xmlAddChild(ret, int_to_dom_tree(entry_billable_string,
|
||||
gncEntryGetBillable (entry)));
|
||||
owner = gncEntryGetBillTo (entry);
|
||||
@@ -203,14 +204,14 @@ entry_dom_tree_create (GncEntry *entry)
|
||||
taxtable = gncEntryGetBillTaxTable (entry);
|
||||
if (taxtable)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_btaxtable_string,
|
||||
gncTaxTableGetGUID (taxtable)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(taxtable))));
|
||||
|
||||
/* Other stuff */
|
||||
|
||||
order = gncEntryGetOrder (entry);
|
||||
if (order)
|
||||
xmlAddChild (ret, guid_to_dom_tree (entry_order_string,
|
||||
gncOrderGetGUID (order)));
|
||||
qof_instance_get_guid(QOF_INSTANCE (order))));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -784,7 +785,7 @@ entry_sixtp_parser_create(void)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer entry_p, gpointer count_p)
|
||||
do_count (QofEntity * entry_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
(*count)++;
|
||||
@@ -794,15 +795,15 @@ static int
|
||||
entry_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_entry (gpointer entry_p, gpointer out_p)
|
||||
xml_add_entry (QofEntity * entry_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncEntry *entry = entry_p;
|
||||
GncEntry *entry = (GncEntry *) entry_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
/* Don't save non-attached entries! */
|
||||
@@ -819,7 +820,7 @@ xml_add_entry (gpointer entry_p, gpointer out_p)
|
||||
static void
|
||||
entry_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -835,7 +836,7 @@ gnc_entry_xml_initialize (void)
|
||||
NULL, /* scrub */
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-entry-xml-v2.h -- entry xml i/o parser/unparsers
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_ENTRY_XML_V2_H
|
||||
|
||||
@@ -47,9 +47,10 @@
|
||||
#include "gnc-owner-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofobject.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_INVOICE_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_INVOICE
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -104,7 +105,7 @@ invoice_dom_tree_create (GncInvoice *invoice)
|
||||
xmlSetProp(ret, "version", invoice_version_string);
|
||||
|
||||
xmlAddChild(ret, guid_to_dom_tree(invoice_guid_string,
|
||||
gncInvoiceGetGUID (invoice)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(invoice))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(invoice_id_string,
|
||||
gncInvoiceGetID (invoice)));
|
||||
@@ -121,7 +122,7 @@ invoice_dom_tree_create (GncInvoice *invoice)
|
||||
term = gncInvoiceGetTerms (invoice);
|
||||
if (term)
|
||||
xmlAddChild(ret, guid_to_dom_tree(invoice_terms_string,
|
||||
gncBillTermGetGUID (term)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(term))));
|
||||
|
||||
maybe_add_string (ret, invoice_billing_id_string,
|
||||
gncInvoiceGetBillingID (invoice));
|
||||
@@ -143,7 +144,7 @@ invoice_dom_tree_create (GncInvoice *invoice)
|
||||
acc = gncInvoiceGetPostedAcc (invoice);
|
||||
if (acc)
|
||||
xmlAddChild (ret, guid_to_dom_tree (invoice_postacc_string,
|
||||
xaccAccountGetGUID (acc)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(acc))));
|
||||
|
||||
xmlAddChild
|
||||
(ret,
|
||||
@@ -510,10 +511,10 @@ invoice_should_be_saved (GncInvoice *invoice)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer invoice_p, gpointer count_p)
|
||||
do_count (QofEntity * invoice_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
if (invoice_should_be_saved (invoice_p))
|
||||
if (invoice_should_be_saved ((GncInvoice *)invoice_p))
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
@@ -521,15 +522,15 @@ static int
|
||||
invoice_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_invoice (gpointer invoice_p, gpointer out_p)
|
||||
xml_add_invoice (QofEntity * invoice_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncInvoice *invoice = invoice_p;
|
||||
GncInvoice *invoice = (GncInvoice *) invoice_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
if (!invoice_should_be_saved (invoice))
|
||||
@@ -544,7 +545,7 @@ xml_add_invoice (gpointer invoice_p, gpointer out_p)
|
||||
static void
|
||||
invoice_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_invoice, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_invoice, (gpointer) out);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -560,7 +561,7 @@ gnc_invoice_xml_initialize (void)
|
||||
NULL, /* scrub */
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-invoice-xml-v2.h -- invoice xml i/o parser/unparsers
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_INVOICE_XML_V2_H
|
||||
|
||||
@@ -46,9 +46,10 @@
|
||||
#include "gnc-owner-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "qofobject.h"
|
||||
#include "xml-helpers.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_JOB_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_JOB
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -64,13 +65,6 @@ const gchar *job_version_string = "2.0.0";
|
||||
#define job_active_string "job:active"
|
||||
#define job_slots_string "job:slots"
|
||||
|
||||
static void
|
||||
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
|
||||
{
|
||||
if (str && strlen(str) > 0)
|
||||
xmlAddChild (ptr, text_to_dom_tree (tag, str));
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
job_dom_tree_create (GncJob *job)
|
||||
{
|
||||
@@ -80,7 +74,7 @@ job_dom_tree_create (GncJob *job)
|
||||
xmlSetProp(ret, "version", job_version_string);
|
||||
|
||||
xmlAddChild(ret, guid_to_dom_tree(job_guid_string,
|
||||
gncJobGetGUID (job)));
|
||||
qof_instance_get_guid (QOF_INSTANCE (job))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(job_id_string,
|
||||
gncJobGetID (job)));
|
||||
@@ -297,10 +291,10 @@ job_should_be_saved (GncJob *job)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer job_p, gpointer count_p)
|
||||
do_count (QofEntity * job_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
if (job_should_be_saved (job_p))
|
||||
if (job_should_be_saved ((GncJob *)job_p))
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
@@ -308,15 +302,15 @@ static int
|
||||
job_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_job (gpointer job_p, gpointer out_p)
|
||||
xml_add_job (QofEntity * job_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncJob *job = job_p;
|
||||
GncJob *job = (GncJob *) job_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
if (!job_should_be_saved (job))
|
||||
@@ -331,7 +325,7 @@ xml_add_job (gpointer job_p, gpointer out_p)
|
||||
static void
|
||||
job_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_job, (gpointer) out);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -347,7 +341,7 @@ gnc_job_xml_initialize (void)
|
||||
NULL, /* scrub */
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-job-xml-v2.h -- job xml i/o parser/unparsers
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_JOB_XML_V2_H
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
#include "gncObject.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ORDER_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_ORDER
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -83,7 +83,7 @@ order_dom_tree_create (GncOrder *order)
|
||||
xmlSetProp(ret, "version", order_version_string);
|
||||
|
||||
xmlAddChild(ret, guid_to_dom_tree(order_guid_string,
|
||||
gncOrderGetGUID (order)));
|
||||
qof_instance_get_guid(QOF_INSTANCE (order))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(order_id_string,
|
||||
gncOrderGetID (order)));
|
||||
@@ -333,10 +333,10 @@ order_should_be_saved (GncOrder *order)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer order_p, gpointer count_p)
|
||||
do_count (QofEntity * order_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
if (order_should_be_saved (order_p))
|
||||
if (order_should_be_saved ((GncOrder *) order_p))
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
@@ -349,10 +349,10 @@ order_get_count (GNCBook *book)
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_order (gpointer order_p, gpointer out_p)
|
||||
xml_add_order (QofEntity * order_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncOrder *order = order_p;
|
||||
GncOrder *order = (GncOrder *) order_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
if (!order_should_be_saved (order))
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-order-xml-v2.h -- order xml i/o parser/unparsers
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_ORDER_XML_V2_H
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
#include "io-gncxml-gen.h"
|
||||
#include "io-gncxml-v2.h"
|
||||
|
||||
#include "qofinstance.h"
|
||||
|
||||
#include "gnc-owner-xml-v2.h"
|
||||
#include "gncCustomerP.h"
|
||||
#include "gncJobP.h"
|
||||
@@ -65,16 +67,16 @@ gnc_owner_to_dom_tree (const char *tag, GncOwner *owner)
|
||||
|
||||
switch (gncOwnerGetType (owner)) {
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
type_str = GNC_CUSTOMER_MODULE_NAME;
|
||||
type_str = GNC_ID_CUSTOMER;
|
||||
break;
|
||||
case GNC_OWNER_JOB:
|
||||
type_str = GNC_JOB_MODULE_NAME;
|
||||
type_str = GNC_ID_JOB;
|
||||
break;
|
||||
case GNC_OWNER_VENDOR:
|
||||
type_str = GNC_VENDOR_MODULE_NAME;
|
||||
type_str = GNC_ID_VENDOR;
|
||||
break;
|
||||
case GNC_OWNER_EMPLOYEE:
|
||||
type_str = GNC_EMPLOYEE_MODULE_NAME;
|
||||
type_str = GNC_ID_EMPLOYEE;
|
||||
break;
|
||||
default:
|
||||
PWARN ("Invalid owner type: %d", gncOwnerGetType (owner));
|
||||
@@ -86,7 +88,7 @@ gnc_owner_to_dom_tree (const char *tag, GncOwner *owner)
|
||||
|
||||
xmlAddChild (ret, text_to_dom_tree (owner_type_string, type_str));
|
||||
xmlAddChild (ret, guid_to_dom_tree (owner_id_string,
|
||||
gncOwnerGetGUID (owner)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(owner))));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -106,13 +108,13 @@ owner_type_handler (xmlNodePtr node, gpointer owner_pdata)
|
||||
char* txt = dom_tree_to_text(node);
|
||||
g_return_val_if_fail(txt, FALSE);
|
||||
|
||||
if (!safe_strcmp (txt, GNC_CUSTOMER_MODULE_NAME))
|
||||
if (!safe_strcmp (txt, GNC_ID_CUSTOMER))
|
||||
gncOwnerInitCustomer (pdata->owner, NULL);
|
||||
else if (!safe_strcmp (txt, GNC_JOB_MODULE_NAME))
|
||||
else if (!safe_strcmp (txt, GNC_ID_JOB))
|
||||
gncOwnerInitJob (pdata->owner, NULL);
|
||||
else if (!safe_strcmp (txt, GNC_VENDOR_MODULE_NAME))
|
||||
else if (!safe_strcmp (txt, GNC_ID_VENDOR))
|
||||
gncOwnerInitVendor (pdata->owner, NULL);
|
||||
else if (!safe_strcmp (txt, GNC_EMPLOYEE_MODULE_NAME))
|
||||
else if (!safe_strcmp (txt, GNC_ID_EMPLOYEE))
|
||||
gncOwnerInitEmployee (pdata->owner, NULL);
|
||||
else {
|
||||
PWARN ("Unknown owner type: %s", txt);
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
/* gnc-owner-xml-v2.h -- Owner XML header
|
||||
*
|
||||
* Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_OWNER_XML_V2_H
|
||||
#define GNC_OWNER_XML_V2_H
|
||||
|
||||
#include "gncOwner.h"
|
||||
#include "gnc-book.h"
|
||||
#include "qofbook.h"
|
||||
|
||||
gboolean gnc_dom_tree_to_owner (xmlNodePtr node, GncOwner *owner,
|
||||
GNCBook *book);
|
||||
QofBook *book);
|
||||
xmlNodePtr gnc_owner_to_dom_tree (const char *tag, GncOwner *addr);
|
||||
|
||||
#endif /* GNC_OWNER_XML_V2_H */
|
||||
|
||||
@@ -41,14 +41,15 @@
|
||||
#include "io-gncxml-gen.h"
|
||||
#include "io-gncxml-v2.h"
|
||||
|
||||
#include "gncEntry.h"
|
||||
#include "gncTaxTableP.h"
|
||||
#include "gnc-tax-table-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "gncEntry.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofinstance.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_TAXTABLE_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_TAXTABLE
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -74,7 +75,8 @@ static void
|
||||
maybe_add_guid (xmlNodePtr ptr, const char *tag, GncTaxTable *table)
|
||||
{
|
||||
if (table)
|
||||
xmlAddChild (ptr, guid_to_dom_tree (tag, gncTaxTableGetGUID (table)));
|
||||
xmlAddChild (ptr, guid_to_dom_tree (tag,
|
||||
qof_instance_get_guid(QOF_INSTANCE(table))));
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
@@ -89,7 +91,7 @@ ttentry_dom_tree_create (GncTaxTableEntry *entry)
|
||||
account = gncTaxTableEntryGetAccount (entry);
|
||||
if (account)
|
||||
xmlAddChild(ret, guid_to_dom_tree (ttentry_account_string,
|
||||
xaccAccountGetGUID (account)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(account))));
|
||||
|
||||
amount = gncTaxTableEntryGetAmount (entry);
|
||||
xmlAddChild (ret, gnc_numeric_to_dom_tree (ttentry_amount_string, &amount));
|
||||
@@ -447,7 +449,7 @@ taxtable_sixtp_parser_create(void)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer table_p, gpointer count_p)
|
||||
do_count (QofEntity * table_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
(*count)++;
|
||||
@@ -457,15 +459,15 @@ static int
|
||||
taxtable_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_taxtable (gpointer table_p, gpointer out_p)
|
||||
xml_add_taxtable (QofEntity * table_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncTaxTable *table = table_p;
|
||||
GncTaxTable *table = (GncTaxTable *) table_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
node = taxtable_dom_tree_create (table);
|
||||
@@ -477,7 +479,7 @@ xml_add_taxtable (gpointer table_p, gpointer out_p)
|
||||
static void
|
||||
taxtable_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_taxtable, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_taxtable, (gpointer) out);
|
||||
}
|
||||
|
||||
|
||||
@@ -522,9 +524,9 @@ taxtable_find_senior (GncTaxTable *table)
|
||||
|
||||
/* build a list of tax tables that are grandchildren or bogus (empty entry list). */
|
||||
static void
|
||||
taxtable_scrub_cb (gpointer table_p, gpointer list_p)
|
||||
taxtable_scrub_cb (QofEntity * table_p, gpointer list_p)
|
||||
{
|
||||
GncTaxTable *table = table_p;
|
||||
GncTaxTable *table = GNC_TAXTABLE(table_p);
|
||||
GList **list = list_p;
|
||||
|
||||
if (taxtable_is_grandchild(table) || gncTaxTableGetEntries(table) == NULL)
|
||||
@@ -535,10 +537,10 @@ taxtable_scrub_cb (gpointer table_p, gpointer list_p)
|
||||
* grandchildren, then fix them to point to the most senior child
|
||||
*/
|
||||
static void
|
||||
taxtable_scrub_entries (gpointer entry_p, gpointer ht_p)
|
||||
taxtable_scrub_entries (QofEntity * entry_p, gpointer ht_p)
|
||||
{
|
||||
GHashTable *ht = ht_p;
|
||||
GncEntry *entry = entry_p;
|
||||
GncEntry *entry = GNC_ENTRY(entry_p);
|
||||
GncTaxTable *table, *new_tt;
|
||||
gint32 count;
|
||||
|
||||
@@ -546,7 +548,7 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p)
|
||||
if (table) {
|
||||
if (taxtable_is_grandchild(table)) {
|
||||
PINFO("Fixing i-taxtable on entry %s\n",
|
||||
guid_to_string(gncEntryGetGUID(entry)));
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
|
||||
new_tt = taxtable_find_senior(table);
|
||||
gncEntryBeginEdit(entry);
|
||||
gncEntrySetInvTaxTable(entry, new_tt);
|
||||
@@ -564,7 +566,7 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p)
|
||||
if (table) {
|
||||
if (taxtable_is_grandchild(table)) {
|
||||
PINFO("Fixing b-taxtable on entry %s\n",
|
||||
guid_to_string(gncEntryGetGUID(entry)));
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(entry))));
|
||||
new_tt = taxtable_find_senior(table);
|
||||
gncEntryBeginEdit(entry);
|
||||
gncEntrySetBillTaxTable(entry, new_tt);
|
||||
@@ -580,10 +582,10 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p)
|
||||
}
|
||||
|
||||
static void
|
||||
taxtable_scrub_cust (gpointer cust_p, gpointer ht_p)
|
||||
taxtable_scrub_cust (QofEntity * cust_p, gpointer ht_p)
|
||||
{
|
||||
GHashTable *ht = ht_p;
|
||||
GncCustomer *cust = cust_p;
|
||||
GncCustomer *cust = GNC_CUSTOMER(cust_p);
|
||||
GncTaxTable *table;
|
||||
gint32 count;
|
||||
|
||||
@@ -596,10 +598,10 @@ taxtable_scrub_cust (gpointer cust_p, gpointer ht_p)
|
||||
}
|
||||
|
||||
static void
|
||||
taxtable_scrub_vendor (gpointer vendor_p, gpointer ht_p)
|
||||
taxtable_scrub_vendor (QofEntity * vendor_p, gpointer ht_p)
|
||||
{
|
||||
GHashTable *ht = ht_p;
|
||||
GncVendor *vendor = vendor_p;
|
||||
GncVendor *vendor = GNC_VENDOR(vendor_p);
|
||||
GncTaxTable *table;
|
||||
gint32 count;
|
||||
|
||||
@@ -619,7 +621,7 @@ taxtable_reset_refcount (gpointer key, gpointer value, gpointer notused)
|
||||
|
||||
if (count != gncTaxTableGetRefcount(table) && !gncTaxTableGetInvisible(table)) {
|
||||
PWARN("Fixing refcount on taxtable %s (%lld -> %d)\n",
|
||||
guid_to_string(gncTaxTableGetGUID(table)),
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))),
|
||||
gncTaxTableGetRefcount(table), count)
|
||||
gncTaxTableSetRefcount(table, count);
|
||||
}
|
||||
@@ -633,17 +635,17 @@ taxtable_scrub (GNCBook *book)
|
||||
GncTaxTable *parent, *table;
|
||||
GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
|
||||
gncObjectForeach (GNC_ENTRY_MODULE_NAME, book, taxtable_scrub_entries, ht);
|
||||
gncObjectForeach (GNC_CUSTOMER_MODULE_NAME, book, taxtable_scrub_cust, ht);
|
||||
gncObjectForeach (GNC_VENDOR_MODULE_NAME, book, taxtable_scrub_vendor, ht);
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, taxtable_scrub_cb, &list);
|
||||
qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht);
|
||||
qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht);
|
||||
qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht);
|
||||
qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list);
|
||||
|
||||
/* destroy the list of "grandchildren" tax tables */
|
||||
for (node = list; node; node = node->next) {
|
||||
table = node->data;
|
||||
|
||||
PINFO ("deleting grandchild taxtable: %s\n",
|
||||
guid_to_string(gncTaxTableGetGUID(table)));
|
||||
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(table))));
|
||||
|
||||
/* Make sure the parent has no children */
|
||||
parent = gncTaxTableGetParent(table);
|
||||
@@ -674,7 +676,7 @@ gnc_taxtable_xml_initialize (void)
|
||||
taxtable_scrub,
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-tax-table-xml-v2.h -- tax table xml i/o parser/unparsers
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_TAXTABLE_XML_V2_H
|
||||
|
||||
@@ -48,9 +48,12 @@
|
||||
#include "gnc-address-xml-v2.h"
|
||||
#include "gnc-engine-util.h"
|
||||
|
||||
#include "gncObject.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofobject.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_VENDOR_MODULE_NAME
|
||||
#include "xml-helpers.h"
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ID_VENDOR
|
||||
|
||||
static short module = MOD_IO;
|
||||
|
||||
@@ -71,13 +74,6 @@ const gchar *vendor_version_string = "2.0.0";
|
||||
#define vendor_taxtableoverride_string "vendor:use-tt"
|
||||
#define vendor_slots_string "vendor:slots"
|
||||
|
||||
static void
|
||||
maybe_add_string (xmlNodePtr ptr, const char *tag, const char *str)
|
||||
{
|
||||
if (str && strlen(str) > 0)
|
||||
xmlAddChild (ptr, text_to_dom_tree (tag, str));
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
vendor_dom_tree_create (GncVendor *vendor)
|
||||
{
|
||||
@@ -89,7 +85,7 @@ vendor_dom_tree_create (GncVendor *vendor)
|
||||
xmlSetProp(ret, "version", vendor_version_string);
|
||||
|
||||
xmlAddChild(ret, guid_to_dom_tree(vendor_guid_string,
|
||||
gncVendorGetGUID (vendor)));
|
||||
qof_instance_get_guid (QOF_INSTANCE(vendor))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(vendor_name_string,
|
||||
gncVendorGetName (vendor)));
|
||||
@@ -105,7 +101,7 @@ vendor_dom_tree_create (GncVendor *vendor)
|
||||
term = gncVendorGetTerms (vendor);
|
||||
if (term)
|
||||
xmlAddChild(ret, guid_to_dom_tree(vendor_terms_string,
|
||||
gncBillTermGetGUID (term)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(term))));
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(vendor_taxincluded_string,
|
||||
gncTaxIncludedTypeToString (
|
||||
@@ -124,7 +120,7 @@ vendor_dom_tree_create (GncVendor *vendor)
|
||||
taxtable = gncVendorGetTaxTable (vendor);
|
||||
if (taxtable)
|
||||
xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string,
|
||||
gncTaxTableGetGUID (taxtable)));
|
||||
qof_instance_get_guid(QOF_INSTANCE(taxtable))));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -422,10 +418,10 @@ vendor_should_be_saved (GncVendor *vendor)
|
||||
}
|
||||
|
||||
static void
|
||||
do_count (gpointer vendor_p, gpointer count_p)
|
||||
do_count (QofEntity * vendor_p, gpointer count_p)
|
||||
{
|
||||
int *count = count_p;
|
||||
if (vendor_should_be_saved (vendor_p))
|
||||
if (vendor_should_be_saved ((GncVendor *)vendor_p))
|
||||
(*count)++;
|
||||
}
|
||||
|
||||
@@ -433,15 +429,15 @@ static int
|
||||
vendor_get_count (GNCBook *book)
|
||||
{
|
||||
int count = 0;
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static void
|
||||
xml_add_vendor (gpointer vendor_p, gpointer out_p)
|
||||
xml_add_vendor (QofEntity * vendor_p, gpointer out_p)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
GncVendor *vendor = vendor_p;
|
||||
GncVendor *vendor = (GncVendor *) vendor_p;
|
||||
FILE *out = out_p;
|
||||
|
||||
if (!vendor_should_be_saved (vendor))
|
||||
@@ -456,7 +452,7 @@ xml_add_vendor (gpointer vendor_p, gpointer out_p)
|
||||
static void
|
||||
vendor_write (FILE *out, GNCBook *book)
|
||||
{
|
||||
gncObjectForeach (_GNC_MOD_NAME, book, xml_add_vendor, (gpointer) out);
|
||||
qof_object_foreach (_GNC_MOD_NAME, book, xml_add_vendor, (gpointer) out);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -472,7 +468,7 @@ gnc_vendor_xml_initialize (void)
|
||||
NULL, /* scrub */
|
||||
};
|
||||
|
||||
gncObjectRegisterBackend (_GNC_MOD_NAME,
|
||||
qof_object_register_backend (_GNC_MOD_NAME,
|
||||
GNC_FILE_BACKEND,
|
||||
&be_data);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gnc-vendor-xml-v2.h -- vendor xml i/o parser/unparsers
|
||||
*
|
||||
* Copyright (C) 2000 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_VENDOR_XML_V2_H
|
||||
|
||||
@@ -3,6 +3,24 @@
|
||||
* module definition/initialization for the file backend module
|
||||
*
|
||||
* Copyright (c) 2002 Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncAddress.c -- an Address object *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncAddress.h -- an Address object
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -10,17 +31,17 @@
|
||||
|
||||
#include "gnc-engine-util.h" /* safe_strcmp */
|
||||
#include "qofquerycore.h"
|
||||
#include "qofqueryobject.h"
|
||||
#include "qofclass.h"
|
||||
#include "guid.h"
|
||||
#include "gnc-event-p.h"
|
||||
|
||||
#include "gncAddress.h"
|
||||
#include "gncAddressP.h"
|
||||
|
||||
struct _gncAddress {
|
||||
struct _gncAddress
|
||||
{
|
||||
QofBook * book;
|
||||
const GUID * parent_guid;
|
||||
QofIdType parent_type;
|
||||
QofEntity * parent;
|
||||
gboolean dirty;
|
||||
char * name;
|
||||
char * addr1;
|
||||
@@ -30,7 +51,6 @@ struct _gncAddress {
|
||||
char * phone;
|
||||
char * fax;
|
||||
char * email;
|
||||
|
||||
};
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ADDRESS_MODULE_NAME
|
||||
@@ -44,12 +64,13 @@ mark_address (GncAddress *address)
|
||||
{
|
||||
address->dirty = TRUE;
|
||||
|
||||
gnc_engine_generate_event (address->parent_guid, address->parent_type, GNC_EVENT_MODIFY);
|
||||
gnc_engine_gen_event (address->parent, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* Create/Destroy functions */
|
||||
|
||||
GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptype)
|
||||
GncAddress *
|
||||
gncAddressCreate (QofBook *book, QofEntity *prnt)
|
||||
{
|
||||
GncAddress *addr;
|
||||
|
||||
@@ -58,8 +79,7 @@ GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptyp
|
||||
addr = g_new0 (GncAddress, 1);
|
||||
addr->book = book;
|
||||
addr->dirty = FALSE;
|
||||
addr->parent_guid = parent;
|
||||
addr->parent_type = ptype;
|
||||
addr->parent = prnt;
|
||||
|
||||
addr->name = CACHE_INSERT ("");
|
||||
addr->addr1 = CACHE_INSERT ("");
|
||||
@@ -73,7 +93,33 @@ GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptyp
|
||||
return addr;
|
||||
}
|
||||
|
||||
void gncAddressDestroy (GncAddress *addr){
|
||||
GncAddress *
|
||||
gncCloneAddress (GncAddress *from, QofEntity *new_parent, QofBook *book)
|
||||
{
|
||||
GncAddress *addr;
|
||||
|
||||
if (!book) return NULL;
|
||||
|
||||
addr = g_new0 (GncAddress, 1);
|
||||
addr->book = book;
|
||||
addr->dirty = TRUE;
|
||||
addr->parent = new_parent;
|
||||
|
||||
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;
|
||||
|
||||
CACHE_REMOVE (addr->name);
|
||||
@@ -93,6 +139,7 @@ void gncAddressDestroy (GncAddress *addr){
|
||||
#define SET_STR(member, str) { \
|
||||
char * tmp; \
|
||||
\
|
||||
if (member == str) return; \
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
@@ -236,16 +283,16 @@ int gncAddressCompare (const GncAddress *a, const GncAddress *b)
|
||||
|
||||
gboolean gncAddressRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
static QofParam params[] = {
|
||||
|
||||
{ ADDRESS_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetName },
|
||||
{ ADDRESS_PHONE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetPhone },
|
||||
{ ADDRESS_FAX, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetFax },
|
||||
{ ADDRESS_EMAIL, QOF_QUERYCORE_STRING, (QofAccessFunc)gncAddressGetEmail },
|
||||
{ ADDRESS_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetName, NULL },
|
||||
{ ADDRESS_PHONE, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetPhone, NULL },
|
||||
{ ADDRESS_FAX, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetFax, NULL },
|
||||
{ ADDRESS_EMAIL, QOF_TYPE_STRING, (QofAccessFunc)gncAddressGetEmail, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncAddressCompare, params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncAddressCompare, params);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncAddress.h -- an Address object *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncAddress.h -- an Address object
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -8,15 +29,14 @@
|
||||
#define GNC_ADDRESS_H_
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
|
||||
#define GNC_ADDRESS_MODULE_NAME "gncAddress"
|
||||
#define GNC_ADDRESS_MODULE_NAME "gncAddress"
|
||||
|
||||
struct _gncAddress;
|
||||
typedef struct _gncAddress GncAddress;
|
||||
|
||||
/* Create/Destroy functions */
|
||||
|
||||
GncAddress * gncAddressCreate (QofBook *book, const GUID *parent, QofIdType ptype);
|
||||
GncAddress * gncAddressCreate (QofBook *book, QofEntity *parent);
|
||||
void gncAddressDestroy (GncAddress *addr);
|
||||
|
||||
/* Set functions */
|
||||
@@ -45,9 +65,9 @@ gboolean gncAddressIsDirty (const GncAddress *addr);
|
||||
|
||||
int gncAddressCompare (const GncAddress *a, const GncAddress *b);
|
||||
|
||||
#define ADDRESS_NAME "name"
|
||||
#define ADDRESS_PHONE "phone"
|
||||
#define ADDRESS_FAX "fax"
|
||||
#define ADDRESS_EMAIL "email"
|
||||
#define ADDRESS_NAME "name"
|
||||
#define ADDRESS_PHONE "phone"
|
||||
#define ADDRESS_FAX "fax"
|
||||
#define ADDRESS_EMAIL "email"
|
||||
|
||||
#endif /* GNC_ADDRESS_H_ */
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncAddressP.h -- Private Business Interface: Addresses *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncAddressP.h -- Business Interface: Addresses
|
||||
* Copyright (C) 2001, 2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -7,6 +28,13 @@
|
||||
#ifndef GNC_ADDRESSP_H_
|
||||
#define GNC_ADDRESSP_H_
|
||||
|
||||
#include "gncAddress.h"
|
||||
#include "qofid.h"
|
||||
|
||||
gboolean gncAddressRegister (void);
|
||||
|
||||
/** Make a copy of the address, setting the parent to 'new_parent' */
|
||||
GncAddress * gncCloneAddress (GncAddress *from, QofEntity *new_parent, QofBook *book);
|
||||
|
||||
|
||||
#endif /* GNC_ADDRESSP_H_ */
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
/********************************************************************\
|
||||
* gncBillTerm.c -- the Gnucash Billing Terms 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncBillTerm.c -- the Gnucash Billing Terms interface
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -15,79 +37,117 @@
|
||||
#include "qofquerycore.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
#include "kvp_frame.h"
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofinstance-p.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofqueryobject.h"
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncBillTermP.h"
|
||||
|
||||
|
||||
struct _gncBillTerm {
|
||||
GUID guid;
|
||||
char * name;
|
||||
char * desc;
|
||||
GncBillTermType type;
|
||||
gint due_days;
|
||||
gint disc_days;
|
||||
gnc_numeric discount;
|
||||
gint cutoff;
|
||||
struct _gncBillTerm
|
||||
{
|
||||
QofInstance inst;
|
||||
|
||||
gint64 refcount;
|
||||
QofBook * book;
|
||||
GncBillTerm * parent; /* if non-null, we are an immutable child */
|
||||
GncBillTerm * child; /* if non-null, we have not changed */
|
||||
gboolean invisible;
|
||||
/* 'visible' data fields directly manipulated by user */
|
||||
char * name;
|
||||
char * desc;
|
||||
GncBillTermType type;
|
||||
gint due_days;
|
||||
gint disc_days;
|
||||
gnc_numeric discount;
|
||||
gint cutoff;
|
||||
|
||||
GList * children; /* list of children for disconnection */
|
||||
|
||||
int editlevel;
|
||||
gboolean do_free;
|
||||
|
||||
gboolean dirty;
|
||||
/* Internal management fields */
|
||||
/* See src/doc/business.txt for an explanation of the following */
|
||||
/* Code that handles this is *identical* to that in gncTaxTable */
|
||||
gint64 refcount;
|
||||
GncBillTerm * parent; /* if non-null, we are an immutable child */
|
||||
GncBillTerm * child; /* if non-null, we have not changed */
|
||||
gboolean invisible;
|
||||
GList * children; /* list of children for disconnection */
|
||||
};
|
||||
|
||||
struct _book_info {
|
||||
GncBookInfo bi;
|
||||
GList * terms; /* visible terms */
|
||||
struct _book_info
|
||||
{
|
||||
GList * terms; /* visible terms */
|
||||
};
|
||||
|
||||
static short module = MOD_BUSINESS;
|
||||
static short module = MOD_BUSINESS;
|
||||
|
||||
#define _GNC_MOD_NAME GNC_BILLTERM_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_BILLTERM
|
||||
|
||||
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
||||
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
||||
|
||||
#define SET_STR(obj, member, str) { \
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncBillTermBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncBillTermBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
static void add_or_rem_object (GncBillTerm *term, gboolean add);
|
||||
static void addObj (GncBillTerm *term);
|
||||
static void remObj (GncBillTerm *term);
|
||||
static void maybe_resort_list (GncBillTerm *term);
|
||||
/* ============================================================== */
|
||||
/* Misc inline utilities */
|
||||
|
||||
static void gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child);
|
||||
|
||||
G_INLINE_FUNC void mark_term (GncBillTerm *term);
|
||||
G_INLINE_FUNC void
|
||||
static inline void
|
||||
mark_term (GncBillTerm *term)
|
||||
{
|
||||
term->dirty = TRUE;
|
||||
gncBusinessSetDirtyFlag (term->book, _GNC_MOD_NAME, TRUE);
|
||||
|
||||
gnc_engine_generate_event (&term->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
term->inst.dirty = TRUE;
|
||||
qof_collection_mark_dirty (term->inst.entity.collection);
|
||||
gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
static inline void maybe_resort_list (GncBillTerm *term)
|
||||
{
|
||||
struct _book_info *bi;
|
||||
|
||||
if (term->parent || term->invisible) return;
|
||||
bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME);
|
||||
bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare);
|
||||
}
|
||||
|
||||
static inline void addObj (GncBillTerm *term)
|
||||
{
|
||||
struct _book_info *bi;
|
||||
bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME);
|
||||
bi->terms = g_list_insert_sorted (bi->terms, term,
|
||||
(GCompareFunc)gncBillTermCompare);
|
||||
}
|
||||
|
||||
static inline void remObj (GncBillTerm *term)
|
||||
{
|
||||
struct _book_info *bi;
|
||||
bi = qof_book_get_data (term->inst.book, _GNC_MOD_NAME);
|
||||
bi->terms = g_list_remove (bi->terms, term);
|
||||
}
|
||||
|
||||
static inline void
|
||||
gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child)
|
||||
{
|
||||
g_return_if_fail(table->inst.do_free == FALSE);
|
||||
table->children = g_list_prepend(table->children, child);
|
||||
}
|
||||
|
||||
static inline void
|
||||
gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child)
|
||||
{
|
||||
if (table->inst.do_free) return;
|
||||
table->children = g_list_remove(table->children, child);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
GncBillTerm * gncBillTermCreate (QofBook *book)
|
||||
{
|
||||
@@ -95,21 +155,20 @@ GncBillTerm * gncBillTermCreate (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
term = g_new0 (GncBillTerm, 1);
|
||||
term->book = book;
|
||||
qof_instance_init(&term->inst, _GNC_MOD_NAME, book);
|
||||
term->name = CACHE_INSERT ("");
|
||||
term->desc = CACHE_INSERT ("");
|
||||
term->discount = gnc_numeric_zero ();
|
||||
qof_entity_guid_new (qof_book_get_entity_table (book), &term->guid);
|
||||
addObj (term);
|
||||
gnc_engine_generate_event (&term->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
|
||||
gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_CREATE);
|
||||
return term;
|
||||
}
|
||||
|
||||
void gncBillTermDestroy (GncBillTerm *term)
|
||||
{
|
||||
if (!term) return;
|
||||
term->do_free = TRUE;
|
||||
gncBusinessSetDirtyFlag (term->book, _GNC_MOD_NAME, TRUE);
|
||||
term->inst.do_free = TRUE;
|
||||
qof_collection_mark_dirty (term->inst.entity.collection);
|
||||
gncBillTermCommitEdit (term);
|
||||
}
|
||||
|
||||
@@ -120,12 +179,12 @@ static void gncBillTermFree (GncBillTerm *term)
|
||||
|
||||
if (!term) return;
|
||||
|
||||
gnc_engine_generate_event (&term->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_DESTROY);
|
||||
CACHE_REMOVE (term->name);
|
||||
CACHE_REMOVE (term->desc);
|
||||
remObj (term);
|
||||
|
||||
if (!term->do_free)
|
||||
if (!term->inst.do_free)
|
||||
PERR("free a billterm without do_free set!");
|
||||
|
||||
/* disconnect from parent */
|
||||
@@ -139,44 +198,75 @@ static void gncBillTermFree (GncBillTerm *term)
|
||||
}
|
||||
g_list_free(term->children);
|
||||
|
||||
qof_instance_release(&term->inst);
|
||||
g_free (term);
|
||||
}
|
||||
|
||||
static void
|
||||
gncBillTermAddChild (GncBillTerm *table, GncBillTerm *child)
|
||||
GncBillTerm *
|
||||
gncCloneBillTerm (GncBillTerm *from, QofBook *book)
|
||||
{
|
||||
g_return_if_fail(table);
|
||||
g_return_if_fail(child);
|
||||
g_return_if_fail(table->do_free == FALSE);
|
||||
GList *node;
|
||||
GncBillTerm *term;
|
||||
|
||||
table->children = g_list_prepend(table->children, child);
|
||||
}
|
||||
if (!book || !from) return NULL;
|
||||
|
||||
static void
|
||||
gncBillTermRemoveChild (GncBillTerm *table, GncBillTerm *child)
|
||||
{
|
||||
g_return_if_fail(table);
|
||||
g_return_if_fail(child);
|
||||
term = g_new0 (GncBillTerm, 1);
|
||||
qof_instance_init(&term->inst, _GNC_MOD_NAME, book);
|
||||
qof_instance_gemini (&term->inst, &from->inst);
|
||||
|
||||
if (table->do_free)
|
||||
return;
|
||||
term->name = CACHE_INSERT (from->name);
|
||||
term->desc = CACHE_INSERT (from->desc);
|
||||
term->type = from->type;
|
||||
term->due_days = from->due_days;
|
||||
term->disc_days = from->disc_days;
|
||||
term->discount = from->discount;
|
||||
term->cutoff = from->cutoff;
|
||||
term->invisible = from->invisible;
|
||||
|
||||
table->children = g_list_remove(table->children, child);
|
||||
}
|
||||
term->refcount = 0;
|
||||
|
||||
/* Set Functions */
|
||||
void gncBillTermSetGUID (GncBillTerm *term, const GUID *guid)
|
||||
{
|
||||
if (!term || !guid) return;
|
||||
if (guid_equal (guid, &term->guid)) return;
|
||||
/* Make copies of parents and children. Note that this can be
|
||||
* a recursive copy ... treat as doubly-linked list. */
|
||||
if (from->child)
|
||||
{
|
||||
term->child = gncBillTermObtainTwin (from->child, book);
|
||||
term->child->parent = term;
|
||||
}
|
||||
if (from->parent)
|
||||
{
|
||||
term->parent = gncBillTermObtainTwin (from->parent, book);
|
||||
term->parent->child = term;
|
||||
}
|
||||
for (node=g_list_last(from->children); node; node=node->next)
|
||||
{
|
||||
GncBillTerm *btrm = node->data;
|
||||
btrm = gncBillTermObtainTwin (btrm, book);
|
||||
btrm->parent = term;
|
||||
term->children = g_list_prepend(term->children, btrm);
|
||||
}
|
||||
|
||||
gncBillTermBeginEdit (term);
|
||||
remObj (term);
|
||||
term->guid = *guid;
|
||||
addObj (term);
|
||||
gncBillTermCommitEdit (term);
|
||||
gnc_engine_gen_event (&term->inst.entity, GNC_EVENT_CREATE);
|
||||
return term;
|
||||
}
|
||||
|
||||
GncBillTerm *
|
||||
gncBillTermObtainTwin (GncBillTerm *from, QofBook *book)
|
||||
{
|
||||
GncBillTerm *term;
|
||||
if (!from) return NULL;
|
||||
|
||||
term = (GncBillTerm *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!term)
|
||||
{
|
||||
term = gncCloneBillTerm (from, book);
|
||||
}
|
||||
return term;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Set Functions */
|
||||
|
||||
void gncBillTermSetName (GncBillTerm *term, const char *name)
|
||||
{
|
||||
if (!term || !name) return;
|
||||
@@ -245,6 +335,11 @@ void gncBillTermSetCutoff (GncBillTerm *term, gint cutoff)
|
||||
gncBillTermCommitEdit (term);
|
||||
}
|
||||
|
||||
/* XXX this doesn't seem right. If the parent/child relationship
|
||||
* is a doubly-linked list, then there shouldn't be separate set-parent,
|
||||
* set-child routines, else misuse of the routines will goof up
|
||||
* relationships. These ops should be atomic, I think.
|
||||
*/
|
||||
void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent)
|
||||
{
|
||||
if (!term) return;
|
||||
@@ -270,7 +365,7 @@ void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child)
|
||||
void gncBillTermIncRef (GncBillTerm *term)
|
||||
{
|
||||
if (!term) return;
|
||||
if (term->parent || term->invisible) return; /* children dont need refcounts */
|
||||
if (term->parent || term->invisible) return; /* children dont need refcounts */
|
||||
gncBillTermBeginEdit (term);
|
||||
term->refcount++;
|
||||
gncBillTermCommitEdit (term);
|
||||
@@ -279,7 +374,7 @@ void gncBillTermIncRef (GncBillTerm *term)
|
||||
void gncBillTermDecRef (GncBillTerm *term)
|
||||
{
|
||||
if (!term) return;
|
||||
if (term->parent || term->invisible) return; /* children dont need refcounts */
|
||||
if (term->parent || term->invisible) return; /* children dont need refcounts */
|
||||
gncBillTermBeginEdit (term);
|
||||
term->refcount--;
|
||||
g_return_if_fail (term->refcount >= 0);
|
||||
@@ -297,7 +392,7 @@ void gncBillTermMakeInvisible (GncBillTerm *term)
|
||||
if (!term) return;
|
||||
gncBillTermBeginEdit (term);
|
||||
term->invisible = TRUE;
|
||||
add_or_rem_object (term, FALSE);
|
||||
remObj (term);
|
||||
gncBillTermCommitEdit (term);
|
||||
}
|
||||
|
||||
@@ -309,33 +404,30 @@ void gncBillTermChanged (GncBillTerm *term)
|
||||
|
||||
void gncBillTermBeginEdit (GncBillTerm *term)
|
||||
{
|
||||
GNC_BEGIN_EDIT (term, _GNC_MOD_NAME);
|
||||
GNC_BEGIN_EDIT (&term->inst);
|
||||
}
|
||||
|
||||
static void gncBillTermOnError (GncBillTerm *term, QofBackendError errcode)
|
||||
static void gncBillTermOnError (QofInstance *inst, QofBackendError errcode)
|
||||
{
|
||||
PERR("BillTerm QofBackend Failure: %d", errcode);
|
||||
}
|
||||
|
||||
static void gncBillTermOnDone (GncBillTerm *term)
|
||||
static inline void bill_free (QofInstance *inst)
|
||||
{
|
||||
term->dirty = FALSE;
|
||||
GncBillTerm *term = (GncBillTerm *) inst;
|
||||
gncBillTermFree(term);
|
||||
}
|
||||
|
||||
static inline void on_done (QofInstance *inst) {}
|
||||
|
||||
void gncBillTermCommitEdit (GncBillTerm *term)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (term);
|
||||
GNC_COMMIT_EDIT_PART2 (term, _GNC_MOD_NAME, gncBillTermOnError,
|
||||
gncBillTermOnDone, gncBillTermFree);
|
||||
GNC_COMMIT_EDIT_PART1 (&term->inst);
|
||||
GNC_COMMIT_EDIT_PART2 (&term->inst, gncBillTermOnError,
|
||||
on_done, bill_free);
|
||||
}
|
||||
|
||||
/* Get Functions */
|
||||
GncBillTerm * gncBillTermLookup (QofBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name)
|
||||
{
|
||||
@@ -354,23 +446,10 @@ GList * gncBillTermGetTerms (QofBook *book)
|
||||
struct _book_info *bi;
|
||||
if (!book) return NULL;
|
||||
|
||||
bi = gnc_book_get_data (book, _GNC_MOD_NAME);
|
||||
bi = qof_book_get_data (book, _GNC_MOD_NAME);
|
||||
return bi->terms;
|
||||
}
|
||||
|
||||
|
||||
const GUID *gncBillTermGetGUID (GncBillTerm *term)
|
||||
{
|
||||
if (!term) return NULL;
|
||||
return &term->guid;
|
||||
}
|
||||
|
||||
QofBook *gncBillTermGetBook (GncBillTerm *term)
|
||||
{
|
||||
if (!term) return NULL;
|
||||
return term->book;
|
||||
}
|
||||
|
||||
const char *gncBillTermGetName (GncBillTerm *term)
|
||||
{
|
||||
if (!term) return NULL;
|
||||
@@ -418,7 +497,7 @@ static GncBillTerm *gncBillTermCopy (GncBillTerm *term)
|
||||
GncBillTerm *t;
|
||||
|
||||
if (!term) return NULL;
|
||||
t = gncBillTermCreate (term->book);
|
||||
t = gncBillTermCreate (term->inst.book);
|
||||
|
||||
gncBillTermBeginEdit(t);
|
||||
|
||||
@@ -486,7 +565,7 @@ int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b)
|
||||
gboolean gncBillTermIsDirty (GncBillTerm *term)
|
||||
{
|
||||
if (!term) return FALSE;
|
||||
return term->dirty;
|
||||
return term->inst.dirty;
|
||||
}
|
||||
|
||||
/********************************************************/
|
||||
@@ -496,10 +575,11 @@ gboolean gncBillTermIsDirty (GncBillTerm *term)
|
||||
|
||||
/* Based on the timespec and a proximo type, compute the month and
|
||||
* year this is due. The actual day is filled in below.
|
||||
* XXX explain this, the logic is totally opaque to me.
|
||||
*/
|
||||
static void
|
||||
compute_monthyear (GncBillTerm *term, Timespec post_date,
|
||||
int *month, int *year)
|
||||
int *month, int *year)
|
||||
{
|
||||
int iday, imonth, iyear;
|
||||
int cutoff = term->cutoff;
|
||||
@@ -528,6 +608,8 @@ compute_monthyear (GncBillTerm *term, Timespec post_date,
|
||||
if (year) *year = iyear;
|
||||
}
|
||||
|
||||
/* XXX explain this, the logic is totally opaque to me. */
|
||||
|
||||
static Timespec
|
||||
compute_time (GncBillTerm *term, Timespec post_date, int days)
|
||||
{
|
||||
@@ -569,41 +651,6 @@ gncBillTermComputeDiscountDate (GncBillTerm *term, Timespec post_date)
|
||||
|
||||
/* Package-Private functions */
|
||||
|
||||
static void maybe_resort_list (GncBillTerm *term)
|
||||
{
|
||||
struct _book_info *bi;
|
||||
|
||||
if (term->parent || term->invisible) return;
|
||||
bi = gnc_book_get_data (term->book, _GNC_MOD_NAME);
|
||||
bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare);
|
||||
}
|
||||
|
||||
static void add_or_rem_object (GncBillTerm *term, gboolean add)
|
||||
{
|
||||
struct _book_info *bi;
|
||||
|
||||
if (!term) return;
|
||||
bi = gnc_book_get_data (term->book, _GNC_MOD_NAME);
|
||||
|
||||
if (add)
|
||||
bi->terms = g_list_insert_sorted (bi->terms, term,
|
||||
(GCompareFunc)gncBillTermCompare);
|
||||
else
|
||||
bi->terms = g_list_remove (bi->terms, term);
|
||||
}
|
||||
|
||||
static void addObj (GncBillTerm *term)
|
||||
{
|
||||
gncBusinessAddObject (term->book, _GNC_MOD_NAME, term, &term->guid);
|
||||
add_or_rem_object (term, TRUE);
|
||||
}
|
||||
|
||||
static void remObj (GncBillTerm *term)
|
||||
{
|
||||
gncBusinessRemoveObject (term->book, _GNC_MOD_NAME, &term->guid);
|
||||
add_or_rem_object (term, FALSE);
|
||||
}
|
||||
|
||||
static void _gncBillTermCreate (QofBook *book)
|
||||
{
|
||||
struct _book_info *bi;
|
||||
@@ -611,8 +658,7 @@ static void _gncBillTermCreate (QofBook *book)
|
||||
if (!book) return;
|
||||
|
||||
bi = g_new0 (struct _book_info, 1);
|
||||
bi->bi.ht = guid_hash_table_new ();
|
||||
gnc_book_set_data (book, _GNC_MOD_NAME, bi);
|
||||
qof_book_set_data (book, _GNC_MOD_NAME, bi);
|
||||
}
|
||||
|
||||
static void _gncBillTermDestroy (QofBook *book)
|
||||
@@ -621,51 +667,34 @@ static void _gncBillTermDestroy (QofBook *book)
|
||||
|
||||
if (!book) return;
|
||||
|
||||
bi = gnc_book_get_data (book, _GNC_MOD_NAME);
|
||||
bi = qof_book_get_data (book, _GNC_MOD_NAME);
|
||||
|
||||
/* XXX : Destroy the objects? */
|
||||
g_hash_table_destroy (bi->bi.ht);
|
||||
g_list_free (bi->terms);
|
||||
g_free (bi);
|
||||
}
|
||||
|
||||
static gboolean _gncBillTermIsDirty (QofBook *book)
|
||||
static QofObject gncBillTermDesc =
|
||||
{
|
||||
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncBillTermMarkClean (QofBook *book)
|
||||
{
|
||||
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
||||
}
|
||||
|
||||
static void _gncBillTermForeach (QofBook *book, QofEntityForeachCB cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
||||
}
|
||||
|
||||
static QofObject gncBillTermDesc = {
|
||||
QOF_OBJECT_VERSION,
|
||||
_GNC_MOD_NAME,
|
||||
"Billing Term",
|
||||
_gncBillTermCreate,
|
||||
_gncBillTermDestroy,
|
||||
_gncBillTermIsDirty,
|
||||
_gncBillTermMarkClean,
|
||||
_gncBillTermForeach,
|
||||
NULL /* printable */
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: _GNC_MOD_NAME,
|
||||
type_label: "Billing Term",
|
||||
book_begin: _gncBillTermCreate,
|
||||
book_end: _gncBillTermDestroy,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: NULL
|
||||
};
|
||||
|
||||
gboolean gncBillTermRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
{ QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncBillTermGetBook },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncBillTermGetGUID },
|
||||
static QofParam params[] = {
|
||||
{ QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncBillTermCompare, params);
|
||||
|
||||
return qof_object_register (&gncBillTermDesc);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncBillTerm.h -- the Gnucash Billing Term 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncBillTerm.h -- the Gnucash Billing Term interface
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -9,15 +30,21 @@
|
||||
|
||||
typedef struct _gncBillTerm GncBillTerm;
|
||||
|
||||
#include "gnc-numeric.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-date.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
#include "qofinstance.h"
|
||||
#include "gncBusiness.h"
|
||||
|
||||
#define GNC_BILLTERM_MODULE_NAME "gncBillTerm"
|
||||
#define GNC_ID_BILLTERM "gncBillTerm"
|
||||
#define GNC_IS_BILLTERM(obj) (QOF_CHECK_TYPE((obj), GNC_ID_BILLTERM))
|
||||
#define GNC_BILLTERM(obj) (QOF_CHECK_CAST((obj), GNC_ID_BILLTERM, GncBillTerm))
|
||||
|
||||
/*
|
||||
* How to interpret the amount.
|
||||
* How to interpret the amount.
|
||||
* You can interpret it as a VALUE or a PERCENT.
|
||||
* ??? huh?
|
||||
*/
|
||||
typedef enum {
|
||||
GNC_TERM_TYPE_DAYS = 1,
|
||||
@@ -45,12 +72,20 @@ void gncBillTermBeginEdit (GncBillTerm *term);
|
||||
void gncBillTermCommitEdit (GncBillTerm *term);
|
||||
|
||||
/* Get Functions */
|
||||
GncBillTerm *gncBillTermLookup (QofBook *book, const GUID *guid);
|
||||
|
||||
/** Return a pointer to the instance gncBillTerm that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* instance can't be found.
|
||||
* Equivalent function prototype is
|
||||
* GncBillTerm * gncBillTermLookup (QofBook *book, const GUID *guid);
|
||||
*/
|
||||
#define gncBillTermLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_BILLTERM, GncBillTerm)
|
||||
|
||||
GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name);
|
||||
GList * gncBillTermGetTerms (QofBook *book);
|
||||
KvpFrame* gncBillTermGetSlots (GncBillTerm *term);
|
||||
|
||||
const GUID *gncBillTermGetGUID (GncBillTerm *term);
|
||||
QofBook *gncBillTermGetBook (GncBillTerm *term);
|
||||
const char *gncBillTermGetName (GncBillTerm *term);
|
||||
const char *gncBillTermGetDescription (GncBillTerm *term);
|
||||
GncBillTermType gncBillTermGetType (GncBillTerm *term);
|
||||
@@ -75,4 +110,7 @@ int gncBillTermCompare (GncBillTerm *a, GncBillTerm *b);
|
||||
Timespec gncBillTermComputeDueDate (GncBillTerm *term, Timespec post_date);
|
||||
Timespec gncBillTermComputeDiscountDate (GncBillTerm *term, Timespec post_date);
|
||||
|
||||
/* deprecated */
|
||||
#define gncBillTermGetGUID(x) qof_instance_get_guid (QOF_INSTANCE(x))
|
||||
|
||||
#endif /* GNC_BILLTERM_H_ */
|
||||
|
||||
@@ -1,17 +1,39 @@
|
||||
/********************************************************************\
|
||||
* gncBillTermP.h -- the Gnucash Billing Term private 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncBillTermP.h -- the Gnucash Billing Term interface: private interface
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
#ifndef GNC_BILLTERMP_H_
|
||||
#define GNC_BILLTERMP_H_
|
||||
|
||||
#include "qofid-p.h"
|
||||
#include "gncBillTerm.h"
|
||||
|
||||
gboolean gncBillTermRegister (void);
|
||||
|
||||
void gncBillTermSetGUID (GncBillTerm *term, const GUID *guid);
|
||||
void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent);
|
||||
void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child);
|
||||
void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount);
|
||||
@@ -19,4 +41,31 @@ void gncBillTermMakeInvisible (GncBillTerm *term);
|
||||
|
||||
gboolean gncBillTermGetInvisible (GncBillTerm *term);
|
||||
|
||||
/** The gncCloneBillTerm() routine makes a copy of the indicated
|
||||
* bill term, placing it in the indicated book. It copies
|
||||
* the name, description, type, due-days, discount, etc.
|
||||
* It also copies (as needed) both parents and children, so that
|
||||
* the parent-child relationship is correctly mirrored in the
|
||||
* clone.
|
||||
* XXX the refcount is mis-handled. This needs fixin....
|
||||
* It then adds a pair of 'gemini' kvp pointers so that each copy
|
||||
* can be found from the other.
|
||||
*/
|
||||
|
||||
GncBillTerm * gncCloneBillTerm (GncBillTerm *from, QofBook *);
|
||||
|
||||
/** The gncBillTermObtainTwin() will find the 'twin' of the
|
||||
* indicated bill term in the indicated book. If the twin doesn't
|
||||
* yet exist in the book, it will be created (by calling
|
||||
* gncCloneBillTerm()) 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.
|
||||
*/
|
||||
GncBillTerm * gncBillTermObtainTwin (GncBillTerm *from, QofBook *book);
|
||||
|
||||
#define gncBillTermSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
|
||||
|
||||
|
||||
#endif /* GNC_BILLTERMP_H_ */
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gncBusGuile.c -- Business Guile Helper Functions
|
||||
* Copyright (C) 2003 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gncBusGuile.h -- Business Guile Helper Functions
|
||||
* Copyright (C) 2003 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_BUSINESS_GUILE_H_
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gncBusiness.c -- Business helper functions
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@@ -9,98 +26,9 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gnc-book.h"
|
||||
#include "qofid.h"
|
||||
#include "qofid-p.h"
|
||||
#include "gncBusinessP.h"
|
||||
|
||||
struct _iterate {
|
||||
QofEntityForeachCB cb;
|
||||
gpointer user_data;
|
||||
};
|
||||
|
||||
static void get_list (gpointer key, gpointer item, gpointer arg)
|
||||
{
|
||||
struct _iterate *iter = arg;
|
||||
iter->cb (item, iter->user_data);
|
||||
}
|
||||
|
||||
void gncBusinessForeach (QofBook *book, QofIdType mod_name,
|
||||
QofEntityForeachCB cb, gpointer user_data)
|
||||
{
|
||||
GncBookInfo *bi;
|
||||
struct _iterate iter;
|
||||
|
||||
if (!book || !cb) return;
|
||||
|
||||
iter.cb = cb;
|
||||
iter.user_data = user_data;
|
||||
|
||||
bi = gnc_book_get_data (book, mod_name);
|
||||
if (bi && bi->ht)
|
||||
g_hash_table_foreach (bi->ht, get_list, &iter);
|
||||
}
|
||||
|
||||
void gncBusinessCreate (QofBook *book, QofIdType mod_name)
|
||||
{
|
||||
GncBookInfo *bi;
|
||||
|
||||
if (!book) return;
|
||||
|
||||
bi = g_new0 (GncBookInfo, 1);
|
||||
bi->ht = guid_hash_table_new ();
|
||||
gnc_book_set_data (book, mod_name, bi);
|
||||
}
|
||||
|
||||
void gncBusinessDestroy (QofBook *book, QofIdType mod_name)
|
||||
{
|
||||
GncBookInfo *bi;
|
||||
|
||||
if (!book) return;
|
||||
|
||||
bi = gnc_book_get_data (book, mod_name);
|
||||
|
||||
/* XXX : Destroy the objects? */
|
||||
g_hash_table_destroy (bi->ht);
|
||||
g_free (bi);
|
||||
}
|
||||
|
||||
gboolean gncBusinessIsDirty (QofBook *book, QofIdType mod_name)
|
||||
{
|
||||
GncBookInfo *bi;
|
||||
|
||||
if (!book) return FALSE;
|
||||
|
||||
bi = gnc_book_get_data (book, mod_name);
|
||||
return bi->is_dirty;
|
||||
}
|
||||
|
||||
void gncBusinessSetDirtyFlag (QofBook *book, QofIdType mod_name,
|
||||
gboolean is_dirty)
|
||||
{
|
||||
GncBookInfo *bi;
|
||||
|
||||
if (!book) return;
|
||||
|
||||
bi = gnc_book_get_data (book, mod_name);
|
||||
bi->is_dirty = is_dirty;
|
||||
}
|
||||
|
||||
void gncBusinessAddObject (QofBook *book, QofIdType mod_name,
|
||||
gpointer obj, const GUID *guid)
|
||||
{
|
||||
GncBookInfo *bi;
|
||||
|
||||
qof_entity_store (gnc_book_get_entity_table (book), obj, guid, mod_name);
|
||||
bi = gnc_book_get_data (book, mod_name);
|
||||
g_hash_table_insert (bi->ht, (gpointer)guid, obj);
|
||||
}
|
||||
|
||||
void gncBusinessRemoveObject (QofBook *book, QofIdType mod_name,
|
||||
const GUID *guid)
|
||||
{
|
||||
GncBookInfo *bi;
|
||||
|
||||
qof_entity_remove (gnc_book_get_entity_table (book), guid);
|
||||
bi = gnc_book_get_data (book, mod_name);
|
||||
g_hash_table_remove (bi->ht, guid);
|
||||
}
|
||||
/* This file is currently unused;
|
||||
* its contents have been moved to qofid.[ch]
|
||||
*/
|
||||
// void gncBusinessInitialize (int argc, char **argv) {}
|
||||
|
||||
@@ -2,32 +2,41 @@
|
||||
* gncBusiness.h -- Business Helper Functions
|
||||
* Copyright (C) 2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Currently mostly not used ...
|
||||
*/
|
||||
|
||||
#ifndef GNC_BUSINESS_H_
|
||||
#define GNC_BUSINESS_H_
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofid.h"
|
||||
|
||||
typedef struct _gncBookInfo {
|
||||
GHashTable * ht;
|
||||
gboolean is_dirty;
|
||||
} GncBookInfo;
|
||||
|
||||
void gncBusinessForeach (QofBook *book, QofIdType mod_name,
|
||||
QofEntityForeachCB cb, gpointer user_data);
|
||||
|
||||
void gncBusinessCreate (QofBook *book, QofIdType mod_name);
|
||||
void gncBusinessDestroy (QofBook *book, QofIdType mod_name);
|
||||
gboolean gncBusinessIsDirty (QofBook *book, QofIdType mod_name);
|
||||
void gncBusinessSetDirtyFlag (QofBook *book, QofIdType mod_name,
|
||||
gboolean is_dirty);
|
||||
void gncBusinessAddObject (QofBook *book, QofIdType mod_name,
|
||||
gpointer obj, const GUID *guid);
|
||||
void gncBusinessRemoveObject (QofBook *book, QofIdType mod_name,
|
||||
const GUID *guid);
|
||||
|
||||
/* deprecated backwards-compat definitions */
|
||||
#define GNC_BILLTERM_MODULE_NAME GNC_ID_BILLTERM
|
||||
#define GNC_CUSTOMER_MODULE_NAME GNC_ID_CUSTOMER
|
||||
#define GNC_EMPLOYEE_MODULE_NAME GNC_ID_EMPLOYEE
|
||||
#define GNC_ENTRY_MODULE_NAME GNC_ID_ENTRY
|
||||
#define GNC_INVOICE_MODULE_NAME GNC_ID_INVOICE
|
||||
#define GNC_JOB_MODULE_NAME GNC_ID_JOB
|
||||
#define GNC_ORDER_MODULE_NAME GNC_ID_ORDER
|
||||
#define GNC_OWNER_MODULE_NAME GNC_ID_OWNER
|
||||
#define GNC_TAXTABLE_MODULE_NAME GNC_ID_TAXTABLE
|
||||
#define GNC_VENDOR_MODULE_NAME GNC_ID_VENDOR
|
||||
|
||||
#endif /* GNC_BUSINESS_H_ */
|
||||
|
||||
@@ -2,6 +2,23 @@
|
||||
* gncBusinessP.h -- the Core Business Interface
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef GNC_BUSINESSP_H_
|
||||
|
||||
@@ -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 <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -13,66 +35,70 @@
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "qofobject.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofid.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofinstance-p.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquerycore.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofqueryobject.h"
|
||||
|
||||
#include "gncAddressP.h"
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncBusiness.h"
|
||||
#include "gncCustomer.h"
|
||||
#include "gncCustomerP.h"
|
||||
#include "gncAddress.h"
|
||||
#include "gncJobP.h"
|
||||
#include "gncTaxTableP.h"
|
||||
|
||||
struct _gncCustomer {
|
||||
QofBook * book;
|
||||
GUID guid;
|
||||
char * id;
|
||||
char * name;
|
||||
char * notes;
|
||||
GncBillTerm * terms;
|
||||
GncAddress * addr;
|
||||
GncAddress * shipaddr;
|
||||
gnc_commodity * currency;
|
||||
gnc_numeric discount;
|
||||
gnc_numeric credit;
|
||||
GncTaxIncluded taxincluded;
|
||||
gboolean active;
|
||||
GList * jobs;
|
||||
struct _gncCustomer
|
||||
{
|
||||
QofInstance inst;
|
||||
|
||||
int editlevel;
|
||||
gboolean do_free;
|
||||
/* The following fields are identical to 'vendor' */
|
||||
char * id;
|
||||
char * name;
|
||||
char * notes;
|
||||
GncBillTerm * terms;
|
||||
GncAddress * addr;
|
||||
gnc_commodity * currency;
|
||||
GncTaxTable* taxtable;
|
||||
gboolean taxtable_override;
|
||||
GncTaxIncluded taxincluded;
|
||||
gboolean active;
|
||||
GList * jobs;
|
||||
|
||||
GncTaxTable* taxtable;
|
||||
gboolean taxtable_override;
|
||||
gboolean dirty;
|
||||
/* The following fields aer unique to 'customer' */
|
||||
gnc_numeric credit;
|
||||
gnc_numeric discount;
|
||||
GncAddress * shipaddr;
|
||||
};
|
||||
|
||||
static short module = MOD_BUSINESS;
|
||||
static short module = MOD_BUSINESS;
|
||||
|
||||
#define _GNC_MOD_NAME GNC_CUSTOMER_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_CUSTOMER
|
||||
|
||||
/* ============================================================== */
|
||||
/* misc inline funcs */
|
||||
|
||||
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
||||
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
||||
|
||||
static void addObj (GncCustomer *cust);
|
||||
static void remObj (GncCustomer *cust);
|
||||
|
||||
G_INLINE_FUNC void mark_customer (GncCustomer *customer);
|
||||
G_INLINE_FUNC void
|
||||
mark_customer (GncCustomer *customer)
|
||||
{
|
||||
customer->dirty = TRUE;
|
||||
gncBusinessSetDirtyFlag (customer->book, _GNC_MOD_NAME, TRUE);
|
||||
|
||||
gnc_engine_generate_event (&customer->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
customer->inst.dirty = TRUE;
|
||||
qof_collection_mark_dirty (customer->inst.entity.collection);
|
||||
gnc_engine_gen_event (&customer->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncCustomer *gncCustomerCreate (QofBook *book)
|
||||
@@ -82,23 +108,65 @@ GncCustomer *gncCustomerCreate (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
cust = g_new0 (GncCustomer, 1);
|
||||
cust->book = book;
|
||||
cust->dirty = FALSE;
|
||||
qof_instance_init (&cust->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
cust->id = CACHE_INSERT ("");
|
||||
cust->name = CACHE_INSERT ("");
|
||||
cust->notes = CACHE_INSERT ("");
|
||||
cust->addr = gncAddressCreate (book, &cust->guid, _GNC_MOD_NAME);
|
||||
cust->shipaddr = gncAddressCreate (book, &cust->guid, _GNC_MOD_NAME);
|
||||
cust->discount = gnc_numeric_zero();
|
||||
cust->credit = gnc_numeric_zero();
|
||||
cust->addr = gncAddressCreate (book, &cust->inst.entity);
|
||||
cust->taxincluded = GNC_TAXINCLUDED_USEGLOBAL;
|
||||
cust->active = TRUE;
|
||||
cust->jobs = NULL;
|
||||
|
||||
qof_entity_guid_new (qof_book_get_entity_table (book),&cust->guid);
|
||||
addObj (cust);
|
||||
cust->discount = gnc_numeric_zero();
|
||||
cust->credit = gnc_numeric_zero();
|
||||
cust->shipaddr = gncAddressCreate (book, &cust->inst.entity);
|
||||
|
||||
gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
|
||||
gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return cust;
|
||||
}
|
||||
|
||||
/** Create a copy of a customer, placing the copy into a new book. */
|
||||
GncCustomer *
|
||||
gncCloneCustomer (GncCustomer *from, QofBook *book)
|
||||
{
|
||||
GList *node;
|
||||
GncCustomer *cust;
|
||||
|
||||
cust = g_new0 (GncCustomer, 1);
|
||||
|
||||
qof_instance_init (&cust->inst, _GNC_MOD_NAME, 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->taxtable_override = from->taxtable_override;
|
||||
|
||||
cust->addr = gncCloneAddress (from->addr, &cust->inst.entity, book);
|
||||
cust->shipaddr = gncCloneAddress (from->shipaddr, &cust->inst.entity, book);
|
||||
|
||||
/* Find the matching currency in the new book, assumes
|
||||
* currency has already been copied into new book. */
|
||||
cust->currency = gnc_commodity_obtain_twin (from->currency, book);
|
||||
|
||||
/* Find the matching bill term, tax table in the new book */
|
||||
cust->terms = gncBillTermObtainTwin(from->terms, book);
|
||||
cust->taxtable = gncTaxTableObtainTwin (from->taxtable, book);
|
||||
|
||||
for (node=g_list_last(cust->jobs); node; node=node->next)
|
||||
{
|
||||
GncJob *job = node->data;
|
||||
job = gncJobObtainTwin (job, book);
|
||||
cust->jobs = g_list_prepend(cust->jobs, job);
|
||||
}
|
||||
|
||||
gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return cust;
|
||||
}
|
||||
@@ -106,7 +174,8 @@ GncCustomer *gncCustomerCreate (QofBook *book)
|
||||
void gncCustomerDestroy (GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return;
|
||||
cust->do_free = TRUE;
|
||||
cust->inst.do_free = TRUE;
|
||||
qof_collection_mark_dirty (cust->inst.entity.collection);
|
||||
gncCustomerCommitEdit (cust);
|
||||
}
|
||||
|
||||
@@ -114,7 +183,7 @@ static void gncCustomerFree (GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return;
|
||||
|
||||
gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_DESTROY);
|
||||
|
||||
CACHE_REMOVE (cust->id);
|
||||
CACHE_REMOVE (cust->name);
|
||||
@@ -123,27 +192,41 @@ static void gncCustomerFree (GncCustomer *cust)
|
||||
gncAddressDestroy (cust->shipaddr);
|
||||
g_list_free (cust->jobs);
|
||||
|
||||
remObj (cust);
|
||||
|
||||
if (cust->terms)
|
||||
gncBillTermDecRef (cust->terms);
|
||||
if (cust->taxtable)
|
||||
gncTaxTableDecRef (cust->taxtable);
|
||||
|
||||
qof_instance_release (&cust->inst);
|
||||
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 */
|
||||
|
||||
#define SET_STR(obj, member, str) { \
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncCustomerBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncCustomerBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
void gncCustomerSetID (GncCustomer *cust, const char *id)
|
||||
{
|
||||
@@ -172,18 +255,6 @@ void gncCustomerSetNotes (GncCustomer *cust, const char *notes)
|
||||
gncCustomerCommitEdit (cust);
|
||||
}
|
||||
|
||||
void gncCustomerSetGUID (GncCustomer *cust, const GUID *guid)
|
||||
{
|
||||
if (!cust || !guid) return;
|
||||
if (guid_equal (guid, &cust->guid)) return;
|
||||
|
||||
gncCustomerBeginEdit (cust);
|
||||
remObj (cust);
|
||||
cust->guid = *guid;
|
||||
addObj (cust);
|
||||
gncCustomerCommitEdit (cust);
|
||||
}
|
||||
|
||||
void gncCustomerSetTerms (GncCustomer *cust, GncBillTerm *terms)
|
||||
{
|
||||
if (!cust) return;
|
||||
@@ -282,9 +353,9 @@ void gncCustomerAddJob (GncCustomer *cust, GncJob *job)
|
||||
|
||||
if (g_list_index(cust->jobs, job) == -1)
|
||||
cust->jobs = g_list_insert_sorted (cust->jobs, job,
|
||||
(GCompareFunc)gncJobCompare);
|
||||
(GCompareFunc)gncJobCompare);
|
||||
|
||||
gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job)
|
||||
@@ -301,47 +372,42 @@ void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job)
|
||||
cust->jobs = g_list_remove_link (cust->jobs, node);
|
||||
g_list_free_1 (node);
|
||||
}
|
||||
gnc_engine_generate_event (&cust->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
gnc_engine_gen_event (&cust->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
void gncCustomerBeginEdit (GncCustomer *cust)
|
||||
{
|
||||
GNC_BEGIN_EDIT (cust, _GNC_MOD_NAME);
|
||||
GNC_BEGIN_EDIT (&cust->inst);
|
||||
}
|
||||
|
||||
static void gncCustomerOnError (GncCustomer *cust, QofBackendError errcode)
|
||||
static inline void gncCustomerOnError (QofInstance *inst, QofBackendError errcode)
|
||||
{
|
||||
PERR("Customer QofBackend Failure: %d", errcode);
|
||||
}
|
||||
|
||||
static void gncCustomerOnDone (GncCustomer *cust)
|
||||
static inline void gncCustomerOnDone (QofInstance *inst)
|
||||
{
|
||||
cust->dirty = FALSE;
|
||||
GncCustomer *cust = (GncCustomer *) inst;
|
||||
gncAddressClearDirty (cust->addr);
|
||||
gncAddressClearDirty (cust->shipaddr);
|
||||
}
|
||||
|
||||
static inline void cust_free (QofInstance *inst)
|
||||
{
|
||||
GncCustomer *cust = (GncCustomer *) inst;
|
||||
gncCustomerFree (cust);
|
||||
}
|
||||
|
||||
void gncCustomerCommitEdit (GncCustomer *cust)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (cust);
|
||||
GNC_COMMIT_EDIT_PART2 (cust, _GNC_MOD_NAME, gncCustomerOnError,
|
||||
gncCustomerOnDone, gncCustomerFree);
|
||||
GNC_COMMIT_EDIT_PART1 (&cust->inst);
|
||||
GNC_COMMIT_EDIT_PART2 (&cust->inst, gncCustomerOnError,
|
||||
gncCustomerOnDone, cust_free);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncCustomerGetBook (GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return cust->book;
|
||||
}
|
||||
|
||||
const GUID * gncCustomerGetGUID (GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
return &cust->guid;
|
||||
}
|
||||
|
||||
const char * gncCustomerGetID (GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return NULL;
|
||||
@@ -431,39 +497,18 @@ GList * gncCustomerGetJoblist (GncCustomer *cust, gboolean show_all)
|
||||
for (iterator = cust->jobs; iterator; iterator=iterator->next) {
|
||||
GncJob *j = iterator->data;
|
||||
if (gncJobGetActive (j))
|
||||
list = g_list_append (list, j);
|
||||
list = g_list_append (list, j);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
GUID gncCustomerRetGUID (GncCustomer *customer)
|
||||
{
|
||||
if (!customer)
|
||||
return *guid_null();
|
||||
|
||||
return customer->guid;
|
||||
}
|
||||
|
||||
GncCustomer * gncCustomerLookupDirect (GUID guid, QofBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
return gncCustomerLookup (book, &guid);
|
||||
}
|
||||
|
||||
GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
gboolean gncCustomerIsDirty (GncCustomer *cust)
|
||||
{
|
||||
if (!cust) return FALSE;
|
||||
return (cust->dirty ||
|
||||
gncAddressIsDirty (cust->addr) ||
|
||||
gncAddressIsDirty (cust->shipaddr));
|
||||
return (cust->inst.dirty ||
|
||||
gncAddressIsDirty (cust->addr) ||
|
||||
gncAddressIsDirty (cust->shipaddr));
|
||||
}
|
||||
|
||||
/* Other functions */
|
||||
@@ -477,85 +522,47 @@ int gncCustomerCompare (GncCustomer *a, GncCustomer *b)
|
||||
return(strcmp(a->name, b->name));
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Package-Private functions */
|
||||
|
||||
static void addObj (GncCustomer *cust)
|
||||
{
|
||||
gncBusinessAddObject (cust->book, _GNC_MOD_NAME, cust, &cust->guid);
|
||||
}
|
||||
|
||||
static void remObj (GncCustomer *cust)
|
||||
{
|
||||
gncBusinessRemoveObject (cust->book, _GNC_MOD_NAME, &cust->guid);
|
||||
}
|
||||
|
||||
static void _gncCustomerCreate (QofBook *book)
|
||||
{
|
||||
gncBusinessCreate (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncCustomerDestroy (QofBook *book)
|
||||
{
|
||||
return gncBusinessDestroy (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static gboolean _gncCustomerIsDirty (QofBook *book)
|
||||
{
|
||||
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncCustomerMarkClean (QofBook *book)
|
||||
{
|
||||
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
||||
}
|
||||
|
||||
static void _gncCustomerForeach (QofBook *book, QofEntityForeachCB cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
||||
}
|
||||
|
||||
static const char * _gncCustomerPrintable (gpointer item)
|
||||
{
|
||||
GncCustomer *c;
|
||||
|
||||
GncCustomer *c = item;
|
||||
if (!item) return NULL;
|
||||
|
||||
c = item;
|
||||
return c->name;
|
||||
}
|
||||
|
||||
static QofObject gncCustomerDesc = {
|
||||
QOF_OBJECT_VERSION,
|
||||
_GNC_MOD_NAME,
|
||||
"Customer",
|
||||
_gncCustomerCreate,
|
||||
_gncCustomerDestroy,
|
||||
_gncCustomerIsDirty,
|
||||
_gncCustomerMarkClean,
|
||||
_gncCustomerForeach,
|
||||
_gncCustomerPrintable,
|
||||
static QofObject gncCustomerDesc =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: _GNC_MOD_NAME,
|
||||
type_label: "Customer",
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: _gncCustomerPrintable,
|
||||
};
|
||||
|
||||
gboolean gncCustomerRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
{ CUSTOMER_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncCustomerGetID },
|
||||
{ CUSTOMER_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncCustomerGetName },
|
||||
{ CUSTOMER_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetAddr },
|
||||
{ CUSTOMER_SHIPADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetShipAddr },
|
||||
{ QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncCustomerGetBook },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncCustomerGetGUID },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncCustomerGetActive },
|
||||
static QofParam params[] = {
|
||||
{ CUSTOMER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetID, NULL },
|
||||
{ CUSTOMER_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncCustomerGetName, NULL },
|
||||
{ CUSTOMER_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetAddr, NULL },
|
||||
{ CUSTOMER_SHIPADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncCustomerGetShipAddr, NULL },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncCustomerGetActive, NULL },
|
||||
{ QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncCustomerCompare,params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncCustomerCompare,params);
|
||||
|
||||
return qof_object_register (&gncCustomerDesc);
|
||||
}
|
||||
|
||||
gint64 gncCustomerNextID (QofBook *book)
|
||||
{
|
||||
return gnc_book_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_get_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
@@ -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 <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -9,15 +30,20 @@
|
||||
|
||||
typedef struct _gncCustomer GncCustomer;
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
#include "qofinstance.h"
|
||||
#include "gncAddress.h"
|
||||
#include "gncBillTerm.h"
|
||||
#include "gncTaxTable.h"
|
||||
#include "gncJob.h"
|
||||
|
||||
#include "gnc-numeric.h"
|
||||
#include "kvp_frame.h"
|
||||
|
||||
#define GNC_CUSTOMER_MODULE_NAME "gncCustomer"
|
||||
#define GNC_ID_CUSTOMER "gncCustomer"
|
||||
#define GNC_IS_CUSTOMER(obj) (QOF_CHECK_TYPE((obj), GNC_ID_CUSTOMER))
|
||||
#define GNC_CUSTOMER(obj) (QOF_CHECK_CAST((obj), GNC_ID_CUSTOMER, GncCustomer))
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
@@ -46,9 +72,15 @@ void gncCustomerBeginEdit (GncCustomer *customer);
|
||||
void gncCustomerCommitEdit (GncCustomer *customer);
|
||||
|
||||
/* Get Functions */
|
||||
/** Return a pointer to the instance gncCustomer that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* instance can't be found.
|
||||
* Equivalent function prototype is
|
||||
* GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid);
|
||||
*/
|
||||
#define gncCustomerLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_CUSTOMER, GncCustomer)
|
||||
|
||||
QofBook * gncCustomerGetBook (GncCustomer *customer);
|
||||
const GUID * gncCustomerGetGUID (GncCustomer *customer);
|
||||
const char * gncCustomerGetID (GncCustomer *customer);
|
||||
const char * gncCustomerGetName (GncCustomer *customer);
|
||||
GncAddress * gncCustomerGetAddr (GncCustomer *customer);
|
||||
@@ -64,12 +96,10 @@ gnc_commodity * gncCustomerGetCurrency (GncCustomer *customer);
|
||||
gboolean gncCustomerGetTaxTableOverride (GncCustomer *customer);
|
||||
GncTaxTable* gncCustomerGetTaxTable (GncCustomer *customer);
|
||||
|
||||
KvpFrame *gncCustomerGetSlots (GncCustomer *customer);
|
||||
GList * gncCustomerGetJoblist (GncCustomer *customer, gboolean show_all);
|
||||
|
||||
GUID gncCustomerRetGUID (GncCustomer *customer);
|
||||
GncCustomer * gncCustomerLookupDirect (GUID guid, QofBook *book);
|
||||
|
||||
GncCustomer * gncCustomerLookup (QofBook *book, const GUID *guid);
|
||||
|
||||
gboolean gncCustomerIsDirty (GncCustomer *customer);
|
||||
int gncCustomerCompare (GncCustomer *a, GncCustomer *b);
|
||||
@@ -79,4 +109,10 @@ int gncCustomerCompare (GncCustomer *a, GncCustomer *b);
|
||||
#define CUSTOMER_ADDR "addr"
|
||||
#define CUSTOMER_SHIPADDR "shipaddr"
|
||||
|
||||
/* deprecated functions, should be removed */
|
||||
#define gncCustomerGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
||||
#define gncCustomerRetGUID(x) (*(qof_instance_get_guid(QOF_INSTANCE(x))))
|
||||
#define gncCustomerGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
|
||||
#define gncCustomerLookupDirect(g,b) gncCustomerLookup((b), &(g))
|
||||
|
||||
#endif /* GNC_CUSTOMER_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 <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -8,9 +30,30 @@
|
||||
#define GNC_CUSTOMERP_H_
|
||||
|
||||
#include "gncCustomer.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
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, currency, billing terms and jobs.
|
||||
* 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);
|
||||
|
||||
/** 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);
|
||||
|
||||
#define gncCustomerSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
|
||||
|
||||
#endif /* GNC_CUSTOMERP_H_ */
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
/********************************************************************\
|
||||
* gncEmployee.c -- the Core Employee 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncEmployee.c -- the Core Employee Interface
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -10,64 +32,62 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "guid.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofinstance-p.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofquerycore.h"
|
||||
|
||||
#include "Account.h"
|
||||
#include "messages.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "qofid.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquerycore.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofqueryobject.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
#include "gncAddressP.h"
|
||||
#include "gncBusiness.h"
|
||||
#include "gncEmployee.h"
|
||||
#include "gncEmployeeP.h"
|
||||
#include "gncAddress.h"
|
||||
|
||||
struct _gncEmployee {
|
||||
QofBook * book;
|
||||
GUID guid;
|
||||
char * id;
|
||||
char * username;
|
||||
char * language;
|
||||
char * acl;
|
||||
GncAddress * addr;
|
||||
struct _gncEmployee
|
||||
{
|
||||
QofInstance inst;
|
||||
char * id;
|
||||
char * username;
|
||||
GncAddress * addr;
|
||||
gnc_commodity * currency;
|
||||
gnc_numeric workday;
|
||||
gnc_numeric rate;
|
||||
gboolean active;
|
||||
gboolean dirty;
|
||||
gboolean active;
|
||||
|
||||
char * language;
|
||||
char * acl;
|
||||
gnc_numeric workday;
|
||||
gnc_numeric rate;
|
||||
|
||||
Account * ccard_acc;
|
||||
|
||||
int editlevel;
|
||||
gboolean do_free;
|
||||
Account * ccard_acc;
|
||||
};
|
||||
|
||||
static short module = MOD_BUSINESS;
|
||||
static short module = MOD_BUSINESS;
|
||||
|
||||
#define _GNC_MOD_NAME GNC_EMPLOYEE_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_EMPLOYEE
|
||||
|
||||
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
||||
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
||||
|
||||
static void addObj (GncEmployee *employee);
|
||||
static void remObj (GncEmployee *employee);
|
||||
|
||||
G_INLINE_FUNC void mark_employee (GncEmployee *employee);
|
||||
G_INLINE_FUNC void
|
||||
mark_employee (GncEmployee *employee)
|
||||
{
|
||||
employee->dirty = TRUE;
|
||||
gncBusinessSetDirtyFlag (employee->book, _GNC_MOD_NAME, TRUE);
|
||||
|
||||
gnc_engine_generate_event (&employee->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
employee->inst.dirty = TRUE;
|
||||
qof_collection_mark_dirty (employee->inst.entity.collection);
|
||||
gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncEmployee *gncEmployeeCreate (QofBook *book)
|
||||
@@ -77,22 +97,18 @@ GncEmployee *gncEmployeeCreate (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
employee = g_new0 (GncEmployee, 1);
|
||||
employee->book = book;
|
||||
employee->dirty = FALSE;
|
||||
|
||||
qof_instance_init (&employee->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
employee->id = CACHE_INSERT ("");
|
||||
employee->username = CACHE_INSERT ("");
|
||||
employee->language = CACHE_INSERT ("");
|
||||
employee->acl = CACHE_INSERT ("");
|
||||
employee->addr = gncAddressCreate (book, &employee->guid, _GNC_MOD_NAME);
|
||||
employee->addr = gncAddressCreate (book, &employee->inst.entity);
|
||||
employee->workday = gnc_numeric_zero();
|
||||
employee->rate = gnc_numeric_zero();
|
||||
employee->active = TRUE;
|
||||
|
||||
qof_entity_guid_new (qof_book_get_entity_table (book), &employee->guid);
|
||||
addObj (employee);
|
||||
|
||||
gnc_engine_generate_event (&employee->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
|
||||
gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return employee;
|
||||
}
|
||||
@@ -100,7 +116,7 @@ GncEmployee *gncEmployeeCreate (QofBook *book)
|
||||
void gncEmployeeDestroy (GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return;
|
||||
employee->do_free = TRUE;
|
||||
employee->inst.do_free = TRUE;
|
||||
gncEmployeeCommitEdit(employee);
|
||||
}
|
||||
|
||||
@@ -108,7 +124,7 @@ static void gncEmployeeFree (GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return;
|
||||
|
||||
gnc_engine_generate_event (&employee->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_DESTROY);
|
||||
|
||||
CACHE_REMOVE (employee->id);
|
||||
CACHE_REMOVE (employee->username);
|
||||
@@ -116,21 +132,64 @@ static void gncEmployeeFree (GncEmployee *employee)
|
||||
CACHE_REMOVE (employee->acl);
|
||||
gncAddressDestroy (employee->addr);
|
||||
|
||||
remObj (employee);
|
||||
qof_instance_release (&employee->inst);
|
||||
g_free (employee);
|
||||
}
|
||||
|
||||
GncEmployee *
|
||||
gncCloneEmployee (GncEmployee *from, QofBook *book)
|
||||
{
|
||||
GncEmployee *employee;
|
||||
if (!book || !from) return NULL;
|
||||
|
||||
employee = g_new0 (GncEmployee, 1);
|
||||
qof_instance_init(&employee->inst, _GNC_MOD_NAME, book);
|
||||
qof_instance_gemini (&employee->inst, &from->inst);
|
||||
|
||||
employee->id = CACHE_INSERT (from->id);
|
||||
employee->username = CACHE_INSERT (from->username);
|
||||
employee->language = CACHE_INSERT (from->language);
|
||||
employee->acl = CACHE_INSERT (from->acl);
|
||||
employee->addr = gncCloneAddress (from->addr, &employee->inst.entity, book);
|
||||
employee->workday = from->workday;
|
||||
employee->rate = from->rate;
|
||||
employee->active = from->active;
|
||||
employee->currency = gnc_commodity_obtain_twin(from->currency, book);
|
||||
employee->ccard_acc =
|
||||
GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->ccard_acc), book));
|
||||
|
||||
gnc_engine_gen_event (&employee->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return employee;
|
||||
}
|
||||
|
||||
GncEmployee *
|
||||
gncEmployeeObtainTwin (GncEmployee *from, QofBook *book)
|
||||
{
|
||||
GncEmployee *employee;
|
||||
if (!book) return NULL;
|
||||
|
||||
employee = (GncEmployee *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!employee)
|
||||
{
|
||||
employee = gncCloneEmployee (from, book);
|
||||
}
|
||||
|
||||
return employee;
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Set Functions */
|
||||
|
||||
#define SET_STR(obj, member, str) { \
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncEmployeeBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncEmployeeBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
void gncEmployeeSetID (GncEmployee *employee, const char *id)
|
||||
{
|
||||
@@ -159,17 +218,6 @@ void gncEmployeeSetLanguage (GncEmployee *employee, const char *language)
|
||||
gncEmployeeCommitEdit (employee);
|
||||
}
|
||||
|
||||
void gncEmployeeSetGUID (GncEmployee *employee, const GUID *guid)
|
||||
{
|
||||
if (!employee || !guid) return;
|
||||
if (guid_equal (guid, &employee->guid)) return;
|
||||
gncEmployeeBeginEdit (employee);
|
||||
remObj (employee);
|
||||
employee->guid = *guid;
|
||||
addObj (employee);
|
||||
gncEmployeeCommitEdit (employee);
|
||||
}
|
||||
|
||||
void gncEmployeeSetAcl (GncEmployee *employee, const char *acl)
|
||||
{
|
||||
if (!employee) return;
|
||||
@@ -231,20 +279,8 @@ void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc)
|
||||
gncEmployeeCommitEdit (employee);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncEmployeeGetBook (GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return employee->book;
|
||||
}
|
||||
|
||||
const GUID * gncEmployeeGetGUID (GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
return &employee->guid;
|
||||
}
|
||||
|
||||
const char * gncEmployeeGetID (GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return NULL;
|
||||
@@ -305,56 +341,43 @@ Account * gncEmployeeGetCCard (GncEmployee *employee)
|
||||
return employee->ccard_acc;
|
||||
}
|
||||
|
||||
GncEmployee * gncEmployeeLookup (QofBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
GUID gncEmployeeRetGUID (GncEmployee *employee)
|
||||
{
|
||||
if (!employee)
|
||||
return *guid_null();
|
||||
|
||||
return employee->guid;
|
||||
}
|
||||
|
||||
GncEmployee * gncEmployeeLookupDirect (GUID guid, QofBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
return gncEmployeeLookup (book, &guid);
|
||||
}
|
||||
|
||||
gboolean gncEmployeeIsDirty (GncEmployee *employee)
|
||||
{
|
||||
if (!employee) return FALSE;
|
||||
return (employee->dirty || gncAddressIsDirty (employee->addr));
|
||||
return (employee->inst.dirty || gncAddressIsDirty (employee->addr));
|
||||
}
|
||||
|
||||
void gncEmployeeBeginEdit (GncEmployee *employee)
|
||||
{
|
||||
GNC_BEGIN_EDIT (employee, _GNC_MOD_NAME);
|
||||
GNC_BEGIN_EDIT (&employee->inst);
|
||||
}
|
||||
|
||||
static void gncEmployeeOnError (GncEmployee *employee, QofBackendError errcode)
|
||||
static inline void gncEmployeeOnError (QofInstance *employee, QofBackendError errcode)
|
||||
{
|
||||
PERR("Employee QofBackend Failure: %d", errcode);
|
||||
}
|
||||
|
||||
static void gncEmployeeOnDone (GncEmployee *employee)
|
||||
static inline void gncEmployeeOnDone (QofInstance *inst)
|
||||
{
|
||||
employee->dirty = FALSE;
|
||||
GncEmployee *employee = (GncEmployee *) inst;
|
||||
gncAddressClearDirty (employee->addr);
|
||||
}
|
||||
|
||||
void gncEmployeeCommitEdit (GncEmployee *employee)
|
||||
static inline void emp_free (QofInstance *inst)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (employee);
|
||||
GNC_COMMIT_EDIT_PART2 (employee, _GNC_MOD_NAME, gncEmployeeOnError,
|
||||
gncEmployeeOnDone, gncEmployeeFree);
|
||||
GncEmployee *employee = (GncEmployee *) inst;
|
||||
gncEmployeeFree (employee);
|
||||
}
|
||||
|
||||
|
||||
void gncEmployeeCommitEdit (GncEmployee *employee)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (&employee->inst);
|
||||
GNC_COMMIT_EDIT_PART2 (&employee->inst, gncEmployeeOnError,
|
||||
gncEmployeeOnDone, emp_free);
|
||||
}
|
||||
|
||||
/* ============================================================== */
|
||||
/* Other functions */
|
||||
|
||||
int gncEmployeeCompare (GncEmployee *a, GncEmployee *b)
|
||||
@@ -368,83 +391,44 @@ int gncEmployeeCompare (GncEmployee *a, GncEmployee *b)
|
||||
|
||||
/* Package-Private functions */
|
||||
|
||||
static void addObj (GncEmployee *employee)
|
||||
{
|
||||
gncBusinessAddObject (employee->book, _GNC_MOD_NAME, employee,
|
||||
&employee->guid);
|
||||
}
|
||||
|
||||
static void remObj (GncEmployee *employee)
|
||||
{
|
||||
gncBusinessRemoveObject (employee->book, _GNC_MOD_NAME, &employee->guid);
|
||||
}
|
||||
|
||||
static void _gncEmployeeCreate (QofBook *book)
|
||||
{
|
||||
gncBusinessCreate (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncEmployeeDestroy (QofBook *book)
|
||||
{
|
||||
gncBusinessDestroy (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static gboolean _gncEmployeeIsDirty (QofBook *book)
|
||||
{
|
||||
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncEmployeeMarkClean (QofBook *book)
|
||||
{
|
||||
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
||||
}
|
||||
|
||||
static void _gncEmployeeForeach (QofBook *book, QofEntityForeachCB cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
||||
}
|
||||
|
||||
static const char * _gncEmployeePrintable (gpointer item)
|
||||
{
|
||||
GncEmployee *v;
|
||||
|
||||
GncEmployee *v = item;
|
||||
if (!item) return NULL;
|
||||
|
||||
v = item;
|
||||
return gncAddressGetName(v->addr);
|
||||
}
|
||||
|
||||
static QofObject gncEmployeeDesc = {
|
||||
QOF_OBJECT_VERSION,
|
||||
_GNC_MOD_NAME,
|
||||
"Employee",
|
||||
_gncEmployeeCreate,
|
||||
_gncEmployeeDestroy,
|
||||
_gncEmployeeIsDirty,
|
||||
_gncEmployeeMarkClean,
|
||||
_gncEmployeeForeach,
|
||||
_gncEmployeePrintable
|
||||
static QofObject gncEmployeeDesc =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: _GNC_MOD_NAME,
|
||||
type_label: "Employee",
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: _gncEmployeePrintable,
|
||||
};
|
||||
|
||||
gboolean gncEmployeeRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
{ EMPLOYEE_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEmployeeGetID },
|
||||
{ EMPLOYEE_USERNAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEmployeeGetUsername },
|
||||
{ EMPLOYEE_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncEmployeeGetAddr },
|
||||
{ QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncEmployeeGetBook },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncEmployeeGetGUID },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive },
|
||||
static QofParam params[] = {
|
||||
{ EMPLOYEE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetID, NULL },
|
||||
{ EMPLOYEE_USERNAME, QOF_TYPE_STRING, (QofAccessFunc)gncEmployeeGetUsername, NULL },
|
||||
{ EMPLOYEE_ADDR, GNC_ADDRESS_MODULE_NAME, (QofAccessFunc)gncEmployeeGetAddr, NULL },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEmployeeGetActive, NULL },
|
||||
{ QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare,params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEmployeeCompare,params);
|
||||
|
||||
return qof_object_register (&gncEmployeeDesc);
|
||||
}
|
||||
|
||||
gint64 gncEmployeeNextID (QofBook *book)
|
||||
{
|
||||
return gnc_book_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_get_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncEmployee.h -- the Core Employee 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncEmployee.h -- the Core Employee Interface
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -9,11 +30,15 @@
|
||||
|
||||
typedef struct _gncEmployee GncEmployee;
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
|
||||
#include "gncAddress.h"
|
||||
#include "Account.h"
|
||||
|
||||
#define GNC_EMPLOYEE_MODULE_NAME "gncEmployee"
|
||||
#define GNC_ID_EMPLOYEE "gncEmployee"
|
||||
#define GNC_IS_EMPLOYEE(obj) (QOF_CHECK_TYPE((obj), GNC_ID_EMPLOYEE))
|
||||
#define GNC_EMPLOYEE(obj) (QOF_CHECK_CAST((obj), GNC_ID_EMPLOYEE, GncEmployee))
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
@@ -35,7 +60,6 @@ void gncEmployeeSetCCard (GncEmployee *employee, Account* ccard_acc);
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncEmployeeGetBook (GncEmployee *employee);
|
||||
const GUID * gncEmployeeGetGUID (GncEmployee *employee);
|
||||
const char * gncEmployeeGetID (GncEmployee *employee);
|
||||
const char * gncEmployeeGetUsername (GncEmployee *employee);
|
||||
GncAddress * gncEmployeeGetAddr (GncEmployee *employee);
|
||||
@@ -47,11 +71,18 @@ gnc_commodity * gncEmployeeGetCurrency (GncEmployee *employee);
|
||||
gboolean gncEmployeeGetActive (GncEmployee *employee);
|
||||
Account * gncEmployeeGetCCard (GncEmployee *employee);
|
||||
|
||||
GncEmployee * gncEmployeeLookup (QofBook *book, const GUID *guid);
|
||||
|
||||
/** Return a pointer to the instance gncEmployee that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* instance can't be found.
|
||||
* Equivalent function prototype is
|
||||
* GncEmployee * gncEmployeeLookup (QofBook *book, const GUID *guid);
|
||||
*/
|
||||
#define gncEmployeeLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_EMPLOYEE, GncEmployee)
|
||||
|
||||
gboolean gncEmployeeIsDirty (GncEmployee *employee);
|
||||
|
||||
GUID gncEmployeeRetGUID (GncEmployee *employee);
|
||||
GncEmployee * gncEmployeeLookupDirect (GUID guid, QofBook *book);
|
||||
|
||||
void gncEmployeeBeginEdit (GncEmployee *employee);
|
||||
void gncEmployeeCommitEdit (GncEmployee *employee);
|
||||
@@ -61,4 +92,9 @@ int gncEmployeeCompare (GncEmployee *a, GncEmployee *b);
|
||||
#define EMPLOYEE_USERNAME "username"
|
||||
#define EMPLOYEE_ADDR "addr"
|
||||
|
||||
/** deprecated routines */
|
||||
#define gncEmployeeGetGUID(E) qof_entity_get_guid(QOF_ENTITY(E))
|
||||
#define gncEmployeeRetGUID(E) (*(qof_entity_get_guid(QOF_ENTITY(E))))
|
||||
#define gncEmployeeLookupDirect(G,B) gncEmployeeLookup((B),&(G))
|
||||
|
||||
#endif /* GNC_EMPLOYEE_H_ */
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
/*
|
||||
/********************************************************************\
|
||||
* gncEmployeeP.h -- the Core Employee 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -8,9 +30,34 @@
|
||||
#define GNC_EMPLOYEEP_H_
|
||||
|
||||
#include "gncEmployee.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
gboolean gncEmployeeRegister (void);
|
||||
gint64 gncEmployeeNextID (QofBook *book);
|
||||
void gncEmployeeSetGUID (GncEmployee *employee, const GUID *guid);
|
||||
|
||||
/** The gncCloneEmployee() routine makes a copy of the indicated
|
||||
* employee, placing it in the indicated book. It copies
|
||||
* the username, address, currency, ccard account, etc.
|
||||
* It also copies (as needed) both parents and children, so that
|
||||
* the parent-child relationship is correctly mirrored in the
|
||||
* clone.
|
||||
* It then adds a pair of 'gemini' kvp pointers so that each copy
|
||||
* can be found from the other.
|
||||
*/
|
||||
|
||||
GncEmployee * gncCloneEmployee (GncEmployee *from, QofBook *);
|
||||
|
||||
/** The gncEmployeeObtainTwin() will find the 'twin' of the
|
||||
* indicated employee in the indicated book. If the twin doesn't
|
||||
* yet exist in the book, it will be created (by calling
|
||||
* gncCloneEmployee()) 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.
|
||||
*/
|
||||
GncEmployee * gncEmployeeObtainTwin (GncEmployee *from, QofBook *book);
|
||||
|
||||
#define gncEmployeeSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
|
||||
|
||||
#endif /* GNC_EMPLOYEEP_H_ */
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncEntry.c -- the Core Business Entry 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncEntry.c -- the Core Business Entry Interface
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -9,17 +30,21 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "messages.h"
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "qofid.h"
|
||||
#include "qofquerycore.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofqueryobject.h"
|
||||
#include "gnc-be-utils.h"
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofinstance-p.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofquerycore.h"
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncEntry.h"
|
||||
@@ -27,10 +52,10 @@
|
||||
#include "gncInvoice.h"
|
||||
#include "gncOrder.h"
|
||||
|
||||
struct _gncEntry {
|
||||
QofBook * book;
|
||||
struct _gncEntry
|
||||
{
|
||||
QofInstance inst;
|
||||
|
||||
GUID guid;
|
||||
Timespec date;
|
||||
Timespec date_entered;
|
||||
char * desc;
|
||||
@@ -65,12 +90,7 @@ struct _gncEntry {
|
||||
GncInvoice * invoice;
|
||||
GncInvoice * bill;
|
||||
|
||||
int editlevel;
|
||||
gboolean do_free;
|
||||
gboolean dirty;
|
||||
|
||||
/* CACHED VALUES */
|
||||
|
||||
gboolean values_dirty;
|
||||
|
||||
/* customer invoice */
|
||||
@@ -149,7 +169,7 @@ gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type
|
||||
}
|
||||
#undef GNC_RETURN_ON_MATCH
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ENTRY_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_ENTRY
|
||||
|
||||
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
||||
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
||||
@@ -164,19 +184,16 @@ gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
static void addObj (GncEntry *entry);
|
||||
static void remObj (GncEntry *entry);
|
||||
|
||||
G_INLINE_FUNC void mark_entry (GncEntry *entry);
|
||||
G_INLINE_FUNC void
|
||||
mark_entry (GncEntry *entry)
|
||||
{
|
||||
entry->dirty = TRUE;
|
||||
gncBusinessSetDirtyFlag (entry->book, _GNC_MOD_NAME, TRUE);
|
||||
|
||||
gnc_engine_generate_event (&entry->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
entry->inst.dirty = TRUE;
|
||||
qof_collection_mark_dirty (entry->inst.entity.collection);
|
||||
gnc_engine_gen_event (&entry->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncEntry *gncEntryCreate (QofBook *book)
|
||||
@@ -187,7 +204,7 @@ GncEntry *gncEntryCreate (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
entry = g_new0 (GncEntry, 1);
|
||||
entry->book = book;
|
||||
qof_instance_init (&entry->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
entry->desc = CACHE_INSERT ("");
|
||||
entry->action = CACHE_INSERT ("");
|
||||
@@ -207,10 +224,7 @@ GncEntry *gncEntryCreate (QofBook *book)
|
||||
|
||||
entry->values_dirty = TRUE;
|
||||
|
||||
qof_entity_guid_new (qof_book_get_entity_table (book), &entry->guid);
|
||||
addObj (entry);
|
||||
|
||||
gnc_engine_generate_event (&entry->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
|
||||
gnc_engine_gen_event (&entry->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return entry;
|
||||
}
|
||||
@@ -218,7 +232,7 @@ GncEntry *gncEntryCreate (QofBook *book)
|
||||
void gncEntryDestroy (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return;
|
||||
entry->do_free = TRUE;
|
||||
entry->inst.do_free = TRUE;
|
||||
gncEntryCommitEdit(entry);
|
||||
}
|
||||
|
||||
@@ -226,7 +240,7 @@ static void gncEntryFree (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return;
|
||||
|
||||
gnc_engine_generate_event (&entry->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&entry->inst.entity, GNC_EVENT_DESTROY);
|
||||
|
||||
CACHE_REMOVE (entry->desc);
|
||||
CACHE_REMOVE (entry->action);
|
||||
@@ -239,25 +253,37 @@ static void gncEntryFree (GncEntry *entry)
|
||||
gncTaxTableDecRef (entry->i_tax_table);
|
||||
if (entry->b_tax_table)
|
||||
gncTaxTableDecRef (entry->b_tax_table);
|
||||
remObj (entry);
|
||||
|
||||
qof_instance_release (&entry->inst);
|
||||
g_free (entry);
|
||||
}
|
||||
|
||||
/* Set Functions */
|
||||
|
||||
void gncEntrySetGUID (GncEntry *entry, const GUID *guid)
|
||||
GncEntry *
|
||||
gncCloneEntry (GncEntry *from, QofBook *book)
|
||||
{
|
||||
if (!entry || !guid) return;
|
||||
if (guid_equal (guid, &entry->guid)) return;
|
||||
|
||||
gncEntryBeginEdit (entry);
|
||||
remObj (entry);
|
||||
entry->guid = *guid;
|
||||
addObj (entry);
|
||||
gncEntryCommitEdit (entry);
|
||||
/* XXX unfinished */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GncEntry *
|
||||
gncEntryObtainTwin (GncEntry *from, QofBook *book)
|
||||
{
|
||||
GncEntry *entry;
|
||||
if (!book) return NULL;
|
||||
|
||||
entry = (GncEntry *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!entry)
|
||||
{
|
||||
entry = gncCloneEntry (from, book);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
/* ================================================================ */
|
||||
/* Set Functions */
|
||||
|
||||
void gncEntrySetDate (GncEntry *entry, Timespec date)
|
||||
{
|
||||
if (!entry) return;
|
||||
@@ -512,7 +538,7 @@ void gncEntrySetOrder (GncEntry *entry, GncOrder *order)
|
||||
|
||||
/* Generate an event modifying the Order's end-owner */
|
||||
#if 0
|
||||
gnc_engine_generate_event (gncOwnerGetEndGUID (gncOrderGetOwner (order)),
|
||||
gnc_engine_gen_event (gncOwnerGetEndGUID (gncOrderGetOwner (order)),
|
||||
GNC_EVENT_MODIFY);
|
||||
#endif
|
||||
}
|
||||
@@ -539,12 +565,6 @@ void gncEntrySetBill (GncEntry *entry, GncInvoice *bill)
|
||||
gncEntryCommitEdit (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetDirty (GncEntry *entry, gboolean dirty)
|
||||
{
|
||||
if (!entry) return;
|
||||
entry->dirty = dirty;
|
||||
}
|
||||
|
||||
void gncEntryCopy (const GncEntry *src, GncEntry *dest)
|
||||
{
|
||||
if (!src || !dest) return;
|
||||
@@ -592,20 +612,9 @@ void gncEntryCopy (const GncEntry *src, GncEntry *dest)
|
||||
gncEntryCommitEdit (dest);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncEntryGetBook (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return entry->book;
|
||||
}
|
||||
|
||||
const GUID * gncEntryGetGUID (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return NULL;
|
||||
return &(entry->guid);
|
||||
}
|
||||
|
||||
Timespec gncEntryGetDate (GncEntry *entry)
|
||||
{
|
||||
Timespec ts; ts.tv_sec = 0; ts.tv_nsec = 0;
|
||||
@@ -762,13 +771,7 @@ GncOrder * gncEntryGetOrder (GncEntry *entry)
|
||||
return entry->order;
|
||||
}
|
||||
|
||||
GncEntry * gncEntryLookup (QofBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
/*
|
||||
* This is the logic of computing the total for an Entry, so you know
|
||||
* what values to put into various Splits or to display in the ledger.
|
||||
@@ -1101,32 +1104,38 @@ gnc_numeric gncEntryReturnDiscountValue (GncEntry *entry, gboolean is_inv)
|
||||
return (is_inv ? entry->i_disc_value_rounded : gnc_numeric_zero());
|
||||
}
|
||||
|
||||
/* XXXX this exsitnace of this routine is just wrong */
|
||||
gboolean gncEntryIsOpen (GncEntry *entry)
|
||||
{
|
||||
if (!entry) return FALSE;
|
||||
return (entry->editlevel > 0);
|
||||
return (entry->inst.editlevel > 0);
|
||||
}
|
||||
|
||||
/* ================================================================ */
|
||||
|
||||
void gncEntryBeginEdit (GncEntry *entry)
|
||||
{
|
||||
GNC_BEGIN_EDIT (entry, _GNC_MOD_NAME);
|
||||
GNC_BEGIN_EDIT (&entry->inst);
|
||||
}
|
||||
|
||||
static void gncEntryOnError (GncEntry *entry, QofBackendError errcode)
|
||||
static inline void gncEntryOnError (QofInstance *entry, QofBackendError errcode)
|
||||
{
|
||||
PERR("Entry QofBackend Failure: %d", errcode);
|
||||
}
|
||||
|
||||
static void gncEntryOnDone (GncEntry *entry)
|
||||
static inline void gncEntryOnDone (QofInstance *inst) {}
|
||||
|
||||
static inline void entry_free (QofInstance *inst)
|
||||
{
|
||||
entry->dirty = FALSE;
|
||||
GncEntry *entry = (GncEntry *)inst;
|
||||
gncEntryFree (entry);
|
||||
}
|
||||
|
||||
void gncEntryCommitEdit (GncEntry *entry)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (entry);
|
||||
GNC_COMMIT_EDIT_PART2 (entry, _GNC_MOD_NAME, gncEntryOnError,
|
||||
gncEntryOnDone, gncEntryFree);
|
||||
GNC_COMMIT_EDIT_PART1 (&entry->inst);
|
||||
GNC_COMMIT_EDIT_PART2 (&entry->inst, gncEntryOnError,
|
||||
gncEntryOnDone, entry_free);
|
||||
}
|
||||
|
||||
int gncEntryCompare (GncEntry *a, GncEntry *b)
|
||||
@@ -1149,81 +1158,47 @@ int gncEntryCompare (GncEntry *a, GncEntry *b)
|
||||
compare = safe_strcmp (a->action, b->action);
|
||||
if (compare) return compare;
|
||||
|
||||
return guid_compare (&(a->guid), &(b->guid));
|
||||
return guid_compare (&(a->inst.entity.guid), &(b->inst.entity.guid));
|
||||
}
|
||||
|
||||
/* Package-Private functions */
|
||||
/* ============================================================= */
|
||||
/* Object declaration */
|
||||
|
||||
static void addObj (GncEntry *entry)
|
||||
static QofObject gncEntryDesc =
|
||||
{
|
||||
gncBusinessAddObject (entry->book, _GNC_MOD_NAME, entry, &entry->guid);
|
||||
}
|
||||
|
||||
static void remObj (GncEntry *entry)
|
||||
{
|
||||
gncBusinessRemoveObject (entry->book, _GNC_MOD_NAME, &entry->guid);
|
||||
}
|
||||
|
||||
static void _gncEntryCreate (QofBook *book)
|
||||
{
|
||||
gncBusinessCreate (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncEntryDestroy (QofBook *book)
|
||||
{
|
||||
gncBusinessDestroy (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static gboolean _gncEntryIsDirty (QofBook *book)
|
||||
{
|
||||
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncEntryMarkClean (QofBook *book)
|
||||
{
|
||||
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
||||
}
|
||||
|
||||
static void _gncEntryForeach (QofBook *book, QofEntityForeachCB cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
||||
}
|
||||
|
||||
static QofObject gncEntryDesc = {
|
||||
QOF_OBJECT_VERSION,
|
||||
_GNC_MOD_NAME,
|
||||
"Order/Invoice/Bill Entry",
|
||||
_gncEntryCreate,
|
||||
_gncEntryDestroy,
|
||||
_gncEntryIsDirty,
|
||||
_gncEntryMarkClean,
|
||||
_gncEntryForeach,
|
||||
NULL /* printable */
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: _GNC_MOD_NAME,
|
||||
type_label: "Order/Invoice/Bill Entry",
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: NULL,
|
||||
};
|
||||
|
||||
gboolean gncEntryRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
{ ENTRY_DATE, QOF_QUERYCORE_DATE, (QofAccessFunc)gncEntryGetDate },
|
||||
{ ENTRY_DATE_ENTERED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncEntryGetDateEntered },
|
||||
{ ENTRY_DESC, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEntryGetDescription },
|
||||
{ ENTRY_ACTION, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEntryGetAction },
|
||||
{ ENTRY_NOTES, QOF_QUERYCORE_STRING, (QofAccessFunc)gncEntryGetNotes },
|
||||
{ ENTRY_QTY, QOF_QUERYCORE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity },
|
||||
{ ENTRY_IPRICE, QOF_QUERYCORE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice },
|
||||
{ ENTRY_BPRICE, QOF_QUERYCORE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice },
|
||||
{ ENTRY_INVOICE, GNC_INVOICE_MODULE_NAME, (QofAccessFunc)gncEntryGetInvoice },
|
||||
{ ENTRY_BILL, GNC_INVOICE_MODULE_NAME, (QofAccessFunc)gncEntryGetBill },
|
||||
{ ENTRY_BILLABLE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable },
|
||||
{ ENTRY_BILLTO, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncEntryGetBillTo },
|
||||
{ ENTRY_ORDER, GNC_ORDER_MODULE_NAME, (QofAccessFunc)gncEntryGetOrder },
|
||||
{ QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncEntryGetBook },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncEntryGetGUID },
|
||||
static QofParam params[] = {
|
||||
{ ENTRY_DATE, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDate, NULL },
|
||||
{ ENTRY_DATE_ENTERED, QOF_TYPE_DATE, (QofAccessFunc)gncEntryGetDateEntered, NULL },
|
||||
{ ENTRY_DESC, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetDescription, NULL },
|
||||
{ ENTRY_ACTION, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetAction, NULL },
|
||||
{ ENTRY_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncEntryGetNotes, NULL },
|
||||
{ ENTRY_QTY, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetQuantity, NULL },
|
||||
{ ENTRY_IPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetInvPrice, NULL },
|
||||
{ ENTRY_BPRICE, QOF_TYPE_NUMERIC, (QofAccessFunc)gncEntryGetBillPrice, NULL },
|
||||
{ ENTRY_INVOICE, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetInvoice, NULL },
|
||||
{ ENTRY_BILL, GNC_ID_INVOICE, (QofAccessFunc)gncEntryGetBill, NULL },
|
||||
{ ENTRY_BILLABLE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncEntryGetBillable, NULL },
|
||||
{ ENTRY_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncEntryGetBillTo, NULL },
|
||||
{ ENTRY_ORDER, GNC_ID_ORDER, (QofAccessFunc)gncEntryGetOrder, NULL },
|
||||
{ QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncEntryCompare, params);
|
||||
|
||||
return qof_object_register (&gncEntryDesc);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncEntry.h -- the Core Business Entry 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncEntry.h -- the Core Business Entry Interface
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -20,13 +41,18 @@ typedef enum {
|
||||
GNC_DISC_POSTTAX
|
||||
} GncDiscountHow;
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-date.h"
|
||||
#include "gncTaxTable.h"
|
||||
#include "gncOrder.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofinstance.h"
|
||||
|
||||
#define GNC_ENTRY_MODULE_NAME "gncEntry"
|
||||
#include "gnc-date.h"
|
||||
#include "gncBusiness.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "gncOrder.h"
|
||||
#include "gncTaxTable.h"
|
||||
|
||||
#define GNC_ID_ENTRY "gncEntry"
|
||||
#define GNC_IS_ENTRY(obj) (QOF_CHECK_TYPE((obj), GNC_ID_ENTRY))
|
||||
#define GNC_ENTRY(obj) (QOF_CHECK_CAST((obj), GNC_ID_ENTRY, GncEntry))
|
||||
|
||||
/* How to apply the discount and taxes. There are three distinct ways to
|
||||
* apply them:
|
||||
@@ -82,8 +108,6 @@ void gncEntrySetBillPayment (GncEntry *entry, GncEntryPaymentType type);
|
||||
|
||||
/* GET FUNCTIONS */
|
||||
/* Generic (shared) data */
|
||||
QofBook * gncEntryGetBook (GncEntry *entry);
|
||||
const GUID * gncEntryGetGUID (GncEntry *entry);
|
||||
Timespec gncEntryGetDate (GncEntry *entry);
|
||||
Timespec gncEntryGetDateEntered (GncEntry *entry);
|
||||
const char * gncEntryGetDescription (GncEntry *entry);
|
||||
@@ -148,7 +172,14 @@ GncOrder * gncEntryGetOrder (GncEntry *entry);
|
||||
GncInvoice * gncEntryGetInvoice (GncEntry *entry);
|
||||
GncInvoice * gncEntryGetBill (GncEntry *entry);
|
||||
|
||||
GncEntry * gncEntryLookup (QofBook *book, const GUID *guid);
|
||||
/** Return a pointer to the instance gncEntry that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* instance can't be found.
|
||||
* Equivalent function prototype is
|
||||
* GncEntry * gncEntryLookup (QofBook *book, const GUID *guid);
|
||||
*/
|
||||
#define gncEntryLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_ENTRY, GncEntry)
|
||||
|
||||
gboolean gncEntryIsOpen (GncEntry *entry);
|
||||
void gncEntryBeginEdit (GncEntry *entry);
|
||||
@@ -171,4 +202,7 @@ int gncEntryCompare (GncEntry *a, GncEntry *b);
|
||||
#define ENTRY_INVOICE "invoice"
|
||||
#define ENTRY_BILL "bill"
|
||||
|
||||
/* deprecated functions, should be removed */
|
||||
#define gncEntryGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
||||
|
||||
#endif /* GNC_ENTRY_H_ */
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
/********************************************************************\
|
||||
* gncEntryP.h -- the Core Busines Entry 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncEntryP.h -- the Core Busines Entry Interface
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -8,6 +30,7 @@
|
||||
#define GNC_ENTRYP_H_
|
||||
|
||||
#include "gncEntry.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
gboolean gncEntryRegister (void);
|
||||
void gncEntrySetGUID (GncEntry *entry, const GUID *guid);
|
||||
@@ -16,4 +39,27 @@ void gncEntrySetInvoice (GncEntry *entry, GncInvoice *invoice);
|
||||
void gncEntrySetBill (GncEntry *entry, GncInvoice *bill);
|
||||
void gncEntrySetDirty (GncEntry *entry, gboolean dirty);
|
||||
|
||||
|
||||
/** The gncCloneEntry() routine makes a copy of the indicated
|
||||
* entry, placing it in the indicated book. It copies
|
||||
* the whole kit-n-kaboodle.
|
||||
* It then adds a pair of 'gemini' kvp pointers so that each copy
|
||||
* can be found from the other.
|
||||
*/
|
||||
|
||||
GncEntry * gncCloneEntry (GncEntry *from, QofBook *);
|
||||
|
||||
/** The gncEntryObtainTwin() will find the 'twin' of the
|
||||
* indicated entry in the indicated book. If the twin doesn't
|
||||
* yet exist in the book, it will be created (by calling
|
||||
* gncCloneEntry()) 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.
|
||||
*/
|
||||
GncEntry * gncEntryObtainTwin (GncEntry *from, QofBook *book);
|
||||
|
||||
#define gncEntrySetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
|
||||
|
||||
#endif /* GNC_ENTRYP_H_ */
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
/********************************************************************\
|
||||
* gncInvoice.c -- the Core Business Invoice *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncInvoice.c -- the Core Business Invoice
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -8,35 +30,44 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofinstance-p.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquerycore.h"
|
||||
#include "qofquery.h"
|
||||
|
||||
#include "Transaction.h"
|
||||
#include "Account.h"
|
||||
#include "messages.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-book.h"
|
||||
#include "qofid.h"
|
||||
#include "qofquerycore.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofqueryobject.h"
|
||||
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-lot.h"
|
||||
#include "gnc-be-utils.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncBillTermP.h"
|
||||
#include "gncEntry.h"
|
||||
#include "gncEntryP.h"
|
||||
#include "gncJobP.h"
|
||||
#include "gncInvoice.h"
|
||||
#include "gncInvoiceP.h"
|
||||
#include "gncOwner.h"
|
||||
#include "gncOwnerP.h"
|
||||
|
||||
struct _gncInvoice {
|
||||
QofBook *book;
|
||||
struct _gncInvoice
|
||||
{
|
||||
QofInstance inst;
|
||||
|
||||
GUID guid;
|
||||
char * id;
|
||||
char * notes;
|
||||
gboolean active;
|
||||
|
||||
char * billing_id;
|
||||
char * printname;
|
||||
GncBillTerm * terms;
|
||||
@@ -54,18 +85,11 @@ struct _gncInvoice {
|
||||
Account * posted_acc;
|
||||
Transaction * posted_txn;
|
||||
GNCLot * posted_lot;
|
||||
|
||||
gboolean active;
|
||||
|
||||
int editlevel;
|
||||
gboolean do_free;
|
||||
|
||||
gboolean dirty;
|
||||
};
|
||||
|
||||
static short module = MOD_BUSINESS;
|
||||
|
||||
#define _GNC_MOD_NAME GNC_INVOICE_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_INVOICE
|
||||
|
||||
#define GNC_INVOICE_ID "gncInvoice"
|
||||
#define GNC_INVOICE_GUID "invoice-guid"
|
||||
@@ -83,19 +107,16 @@ static short module = MOD_BUSINESS;
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
static void addObj (GncInvoice *invoice);
|
||||
static void remObj (GncInvoice *invoice);
|
||||
|
||||
static void mark_invoice (GncInvoice *invoice);
|
||||
static void
|
||||
mark_invoice (GncInvoice *invoice)
|
||||
{
|
||||
invoice->dirty = TRUE;
|
||||
gncBusinessSetDirtyFlag (invoice->book, _GNC_MOD_NAME, TRUE);
|
||||
|
||||
gnc_engine_generate_event (&invoice->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
invoice->inst.dirty = TRUE;
|
||||
qof_collection_mark_dirty (invoice->inst.entity.collection);
|
||||
gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncInvoice *gncInvoiceCreate (QofBook *book)
|
||||
@@ -105,7 +126,7 @@ GncInvoice *gncInvoiceCreate (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
invoice = g_new0 (GncInvoice, 1);
|
||||
invoice->book = book;
|
||||
qof_instance_init (&invoice->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
invoice->id = CACHE_INSERT ("");
|
||||
invoice->notes = CACHE_INSERT ("");
|
||||
@@ -116,10 +137,7 @@ GncInvoice *gncInvoiceCreate (QofBook *book)
|
||||
|
||||
invoice->to_charge_amount = gnc_numeric_zero();
|
||||
|
||||
qof_entity_guid_new (qof_book_get_entity_table (book), &invoice->guid);
|
||||
addObj (invoice);
|
||||
|
||||
gnc_engine_generate_event (&invoice->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
|
||||
gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return invoice;
|
||||
}
|
||||
@@ -127,7 +145,7 @@ GncInvoice *gncInvoiceCreate (QofBook *book)
|
||||
void gncInvoiceDestroy (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return;
|
||||
invoice->do_free = TRUE;
|
||||
invoice->inst.do_free = TRUE;
|
||||
gncInvoiceCommitEdit (invoice);
|
||||
}
|
||||
|
||||
@@ -135,36 +153,92 @@ static void gncInvoiceFree (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return;
|
||||
|
||||
gnc_engine_generate_event (&invoice->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_DESTROY);
|
||||
|
||||
CACHE_REMOVE (invoice->id);
|
||||
CACHE_REMOVE (invoice->notes);
|
||||
CACHE_REMOVE (invoice->billing_id);
|
||||
g_list_free (invoice->entries);
|
||||
remObj (invoice);
|
||||
|
||||
if (invoice->printname) g_free (invoice->printname);
|
||||
|
||||
if (invoice->terms)
|
||||
gncBillTermDecRef (invoice->terms);
|
||||
|
||||
qof_instance_release (&invoice->inst);
|
||||
g_free (invoice);
|
||||
}
|
||||
|
||||
/* Set Functions */
|
||||
|
||||
void gncInvoiceSetGUID (GncInvoice *invoice, const GUID *guid)
|
||||
GncInvoice *
|
||||
gncCloneInvoice (GncInvoice *from, QofBook *book)
|
||||
{
|
||||
if (!invoice || !guid) return;
|
||||
if (guid_equal (guid, &invoice->guid)) return;
|
||||
GList *node;
|
||||
GncInvoice *invoice;
|
||||
|
||||
gncInvoiceBeginEdit (invoice);
|
||||
remObj (invoice);
|
||||
invoice->guid = *guid;
|
||||
addObj (invoice);
|
||||
gncInvoiceCommitEdit (invoice);
|
||||
if (!book) return NULL;
|
||||
|
||||
invoice = g_new0 (GncInvoice, 1);
|
||||
qof_instance_init (&invoice->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
invoice->id = CACHE_INSERT (from->id);
|
||||
invoice->notes = CACHE_INSERT (from->notes);
|
||||
invoice->billing_id = CACHE_INSERT (from->billing_id);
|
||||
invoice->active = from->active;
|
||||
|
||||
invoice->billto = gncCloneOwner (&from->billto, book);
|
||||
invoice->owner = gncCloneOwner (&from->owner, book);
|
||||
invoice->job = gncJobObtainTwin (from->job, book);
|
||||
invoice->terms = gncBillTermObtainTwin (from->terms, book);
|
||||
gncBillTermIncRef (invoice->terms);
|
||||
|
||||
|
||||
invoice->to_charge_amount = from->to_charge_amount;
|
||||
invoice->printname = NULL; /* that's right, NULL. See below. */
|
||||
invoice->date_opened = from->date_opened;
|
||||
invoice->date_posted = from->date_posted;
|
||||
|
||||
invoice->currency = gnc_commodity_obtain_twin (from->currency, book);
|
||||
|
||||
invoice->entries = NULL;
|
||||
for (node = g_list_last(from->entries); node; node=node->next)
|
||||
{
|
||||
GncEntry *entry = node->data;
|
||||
entry = gncEntryObtainTwin (entry, book);
|
||||
invoice->entries = g_list_prepend (invoice->entries, entry);
|
||||
}
|
||||
|
||||
/* XXX should probably be obtain-twin not lookup-twin */
|
||||
invoice->posted_acc =
|
||||
GNC_ACCOUNT(qof_instance_lookup_twin(QOF_INSTANCE(from->posted_acc), book));
|
||||
#if 0
|
||||
XXX not done */
|
||||
Transaction * posted_txn;
|
||||
GNCLot * posted_lot;
|
||||
#endif
|
||||
|
||||
gnc_engine_gen_event (&invoice->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return invoice;
|
||||
}
|
||||
|
||||
GncInvoice *
|
||||
gncInvoiceObtainTwin (GncInvoice *from, QofBook *book)
|
||||
{
|
||||
GncInvoice *invoice;
|
||||
if (!book) return NULL;
|
||||
|
||||
invoice = (GncInvoice *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!invoice)
|
||||
{
|
||||
invoice = gncCloneInvoice (from, book);
|
||||
}
|
||||
|
||||
return invoice;
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
/* Set Functions */
|
||||
|
||||
void gncInvoiceSetID (GncInvoice *invoice, const char *id)
|
||||
{
|
||||
if (!invoice || !id) return;
|
||||
@@ -276,12 +350,6 @@ void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount)
|
||||
gncInvoiceCommitEdit (invoice);
|
||||
}
|
||||
|
||||
void gncInvoiceSetDirty (GncInvoice *invoice, gboolean dirty)
|
||||
{
|
||||
if (!invoice) return;
|
||||
invoice->dirty = dirty;
|
||||
}
|
||||
|
||||
void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn)
|
||||
{
|
||||
if (!invoice) return;
|
||||
@@ -365,20 +433,9 @@ void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry)
|
||||
mark_invoice (bill);
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncInvoiceGetBook (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return invoice->book;
|
||||
}
|
||||
|
||||
const GUID * gncInvoiceGetGUID (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
return &(invoice->guid);
|
||||
}
|
||||
|
||||
const char * gncInvoiceGetID (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
@@ -567,12 +624,6 @@ GList * gncInvoiceGetEntries (GncInvoice *invoice)
|
||||
return invoice->entries;
|
||||
}
|
||||
|
||||
gboolean gncInvoiceIsDirty (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return FALSE;
|
||||
return invoice->dirty;
|
||||
}
|
||||
|
||||
static void
|
||||
gncInvoiceDetachFromLot (GNCLot *lot)
|
||||
{
|
||||
@@ -596,7 +647,7 @@ gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
|
||||
if (invoice->posted_lot) return; /* Cannot reset invoice's lot */
|
||||
|
||||
kvp = gnc_lot_get_slots (lot);
|
||||
value = kvp_value_new_guid (gncInvoiceGetGUID (invoice));
|
||||
value = kvp_value_new_guid (qof_instance_get_guid (QOF_INSTANCE(invoice)));
|
||||
kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
|
||||
kvp_value_delete (value);
|
||||
gncInvoiceSetPostedLot (invoice, lot);
|
||||
@@ -617,9 +668,7 @@ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
|
||||
if (!value) return NULL;
|
||||
|
||||
guid = kvp_value_get_guid (value);
|
||||
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
return gncInvoiceLookup(book, guid);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -635,7 +684,7 @@ gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
|
||||
|
||||
xaccTransBeginEdit (txn);
|
||||
kvp = xaccTransGetSlots (txn);
|
||||
value = kvp_value_new_guid (gncInvoiceGetGUID (invoice));
|
||||
value = kvp_value_new_guid (qof_instance_get_guid(QOF_INSTANCE(invoice)));
|
||||
kvp_frame_set_slot_path (kvp, value, GNC_INVOICE_ID, GNC_INVOICE_GUID, NULL);
|
||||
kvp_value_delete (value);
|
||||
xaccTransSetTxnType (txn, TXN_TYPE_INVOICE);
|
||||
@@ -643,7 +692,8 @@ gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
|
||||
gncInvoiceSetPostedTxn (invoice, txn);
|
||||
}
|
||||
|
||||
GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn)
|
||||
GncInvoice *
|
||||
gncInvoiceGetInvoiceFromTxn (Transaction *txn)
|
||||
{
|
||||
KvpFrame *kvp;
|
||||
KvpValue *value;
|
||||
@@ -658,9 +708,7 @@ GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn)
|
||||
if (!value) return NULL;
|
||||
|
||||
guid = kvp_value_get_guid (value);
|
||||
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
return gncInvoiceLookup(book,guid);
|
||||
}
|
||||
|
||||
struct lotmatch {
|
||||
@@ -741,10 +789,10 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
|
||||
/* Create a new lot for this invoice, if we need to do so */
|
||||
if (!lot)
|
||||
lot = gnc_lot_new (invoice->book);
|
||||
lot = gnc_lot_new (invoice->inst.book);
|
||||
|
||||
/* Create a new transaction */
|
||||
txn = xaccMallocTransaction (invoice->book);
|
||||
txn = xaccMallocTransaction (invoice->inst.book);
|
||||
xaccTransBeginEdit (txn);
|
||||
|
||||
name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)));
|
||||
@@ -812,7 +860,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
if (ccard_acct && gncEntryGetBillPayment (entry) == GNC_PAYMENT_CARD) {
|
||||
Split *split;
|
||||
|
||||
split = xaccMallocSplit (invoice->book);
|
||||
split = xaccMallocSplit (invoice->inst.book);
|
||||
/* set action? */
|
||||
xaccSplitSetMemo (split, gncEntryGetDescription (entry));
|
||||
xaccSplitSetAction (split, type);
|
||||
@@ -846,7 +894,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
Split *split;
|
||||
GncAccountValue *acc_val = iter->data;
|
||||
|
||||
split = xaccMallocSplit (invoice->book);
|
||||
split = xaccMallocSplit (invoice->inst.book);
|
||||
/* set action and memo? */
|
||||
|
||||
xaccSplitSetMemo (split, memo);
|
||||
@@ -865,7 +913,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
* we should make that now..
|
||||
*/
|
||||
if (ccard_acct && !gnc_numeric_zero_p (invoice->to_charge_amount)) {
|
||||
Split *split = xaccMallocSplit (invoice->book);
|
||||
Split *split = xaccMallocSplit (invoice->inst.book);
|
||||
|
||||
/* Set memo. action? */
|
||||
xaccSplitSetMemo (split, _("Extra to Charge Card"));
|
||||
@@ -885,7 +933,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
|
||||
/* Now create the Posted split (which is negative -- it's a credit) */
|
||||
{
|
||||
Split *split = xaccMallocSplit (invoice->book);
|
||||
Split *split = xaccMallocSplit (invoice->inst.book);
|
||||
|
||||
/* Set action/memo */
|
||||
xaccSplitSetMemo (split, memo);
|
||||
@@ -928,8 +976,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
char *memo2 = _("Automatic Payment Forward");
|
||||
char *action2 = _("Auto Split");
|
||||
|
||||
t2 = xaccMallocTransaction (invoice->book);
|
||||
lot2 = gnc_lot_new (invoice->book);
|
||||
t2 = xaccMallocTransaction (invoice->inst.book);
|
||||
lot2 = gnc_lot_new (invoice->inst.book);
|
||||
gncOwnerAttachToLot (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)),
|
||||
lot2);
|
||||
|
||||
@@ -946,7 +994,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
xaccTransSetDatePostedTS (t2, post_date);
|
||||
|
||||
/* Balance out this lot */
|
||||
split = xaccMallocSplit (invoice->book);
|
||||
split = xaccMallocSplit (invoice->inst.book);
|
||||
xaccSplitSetMemo (split, memo2);
|
||||
xaccSplitSetAction (split, action2);
|
||||
xaccSplitSetBaseValue (split, gnc_numeric_neg (total),
|
||||
@@ -956,7 +1004,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
||||
gnc_lot_add_split (lot, split);
|
||||
|
||||
/* And apply the pre-payment to a new lot */
|
||||
split = xaccMallocSplit (invoice->book);
|
||||
split = xaccMallocSplit (invoice->inst.book);
|
||||
xaccSplitSetMemo (split, memo2);
|
||||
xaccSplitSetAction (split, action2);
|
||||
xaccSplitSetBaseValue (split, total, invoice->currency);
|
||||
@@ -1236,47 +1284,31 @@ gboolean gncInvoiceIsPaid (GncInvoice *invoice)
|
||||
return gnc_lot_is_closed(invoice->posted_lot);
|
||||
}
|
||||
|
||||
GUID gncInvoiceRetGUID (GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice)
|
||||
return *guid_null();
|
||||
|
||||
return invoice->guid;
|
||||
}
|
||||
|
||||
GncInvoice * gncInvoiceLookupDirect (GUID guid, QofBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
return gncInvoiceLookup (book, &guid);
|
||||
}
|
||||
|
||||
GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
}
|
||||
/* ================================================================== */
|
||||
|
||||
void gncInvoiceBeginEdit (GncInvoice *invoice)
|
||||
{
|
||||
GNC_BEGIN_EDIT (invoice, _GNC_MOD_NAME);
|
||||
GNC_BEGIN_EDIT (&invoice->inst);
|
||||
}
|
||||
|
||||
static void gncInvoiceOnError (GncInvoice *invoice, QofBackendError errcode)
|
||||
static inline void gncInvoiceOnError (QofInstance *inst, QofBackendError errcode)
|
||||
{
|
||||
PERR("Invoice QofBackend Failure: %d", errcode);
|
||||
}
|
||||
|
||||
static void gncInvoiceOnDone (GncInvoice *invoice)
|
||||
static inline void gncInvoiceOnDone (QofInstance *invoice) { }
|
||||
|
||||
static inline void invoice_free (QofInstance *inst)
|
||||
{
|
||||
invoice->dirty = FALSE;
|
||||
GncInvoice *invoice = (GncInvoice *) inst;
|
||||
gncInvoiceFree (invoice);
|
||||
}
|
||||
|
||||
void gncInvoiceCommitEdit (GncInvoice *invoice)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (invoice);
|
||||
GNC_COMMIT_EDIT_PART2 (invoice, _GNC_MOD_NAME, gncInvoiceOnError,
|
||||
gncInvoiceOnDone, gncInvoiceFree);
|
||||
GNC_COMMIT_EDIT_PART1 (&invoice->inst);
|
||||
GNC_COMMIT_EDIT_PART2 (&invoice->inst, gncInvoiceOnError,
|
||||
gncInvoiceOnDone, invoice_free);
|
||||
}
|
||||
|
||||
int gncInvoiceCompare (GncInvoice *a, GncInvoice *b)
|
||||
@@ -1296,54 +1328,19 @@ int gncInvoiceCompare (GncInvoice *a, GncInvoice *b)
|
||||
compare = timespec_cmp (&(a->date_posted), &(b->date_posted));
|
||||
if (compare) return compare;
|
||||
|
||||
return guid_compare (&(a->guid), &(b->guid));
|
||||
return guid_compare (&(a->inst.entity.guid), &(b->inst.entity.guid));
|
||||
}
|
||||
|
||||
/* ============================================================= */
|
||||
/* Package-Private functions */
|
||||
|
||||
static void addObj (GncInvoice *invoice)
|
||||
{
|
||||
gncBusinessAddObject (invoice->book, _GNC_MOD_NAME, invoice, &invoice->guid);
|
||||
}
|
||||
|
||||
static void remObj (GncInvoice *invoice)
|
||||
{
|
||||
gncBusinessRemoveObject (invoice->book, _GNC_MOD_NAME, &invoice->guid);
|
||||
}
|
||||
|
||||
static void _gncInvoiceCreate (QofBook *book)
|
||||
{
|
||||
gncBusinessCreate (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncInvoiceDestroy (QofBook *book)
|
||||
{
|
||||
gncBusinessDestroy (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static gboolean _gncInvoiceIsDirty (QofBook *book)
|
||||
{
|
||||
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncInvoiceMarkClean (QofBook *book)
|
||||
{
|
||||
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
||||
}
|
||||
|
||||
static void _gncInvoiceForeach (QofBook *book, QofEntityForeachCB cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
||||
}
|
||||
|
||||
static const char * _gncInvoicePrintable (gpointer obj)
|
||||
{
|
||||
GncInvoice *invoice = obj;
|
||||
|
||||
g_return_val_if_fail (invoice, NULL);
|
||||
|
||||
if (invoice->dirty || invoice->printname == NULL) {
|
||||
if (invoice->inst.dirty || invoice->printname == NULL) {
|
||||
if (invoice->printname) g_free (invoice->printname);
|
||||
|
||||
invoice->printname =
|
||||
@@ -1354,67 +1351,68 @@ static const char * _gncInvoicePrintable (gpointer obj)
|
||||
return invoice->printname;
|
||||
}
|
||||
|
||||
static QofObject gncInvoiceDesc = {
|
||||
QOF_OBJECT_VERSION,
|
||||
_GNC_MOD_NAME,
|
||||
"Invoice",
|
||||
_gncInvoiceCreate,
|
||||
_gncInvoiceDestroy,
|
||||
_gncInvoiceIsDirty,
|
||||
_gncInvoiceMarkClean,
|
||||
_gncInvoiceForeach,
|
||||
_gncInvoicePrintable,
|
||||
static QofObject gncInvoiceDesc =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: _GNC_MOD_NAME,
|
||||
type_label: "Invoice",
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: _gncInvoicePrintable,
|
||||
};
|
||||
|
||||
static void
|
||||
reg_lot (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
static QofParam params[] = {
|
||||
{ INVOICE_FROM_LOT, _GNC_MOD_NAME,
|
||||
(QofAccessFunc)gncInvoiceGetInvoiceFromLot },
|
||||
(QofAccessFunc)gncInvoiceGetInvoiceFromLot, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (GNC_ID_LOT, NULL, params);
|
||||
qof_class_register (GNC_ID_LOT, NULL, params);
|
||||
}
|
||||
|
||||
static void
|
||||
reg_txn (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
static QofParam params[] = {
|
||||
{ INVOICE_FROM_TXN, _GNC_MOD_NAME,
|
||||
(QofAccessFunc)gncInvoiceGetInvoiceFromTxn },
|
||||
(QofAccessFunc)gncInvoiceGetInvoiceFromTxn, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (GNC_ID_TRANS, NULL, params);
|
||||
qof_class_register (GNC_ID_TRANS, NULL, params);
|
||||
}
|
||||
|
||||
gboolean gncInvoiceRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
{ INVOICE_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetID },
|
||||
{ INVOICE_OWNER, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncInvoiceGetOwner },
|
||||
{ INVOICE_OPENED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened },
|
||||
{ INVOICE_DUE, QOF_QUERYCORE_DATE, (QofAccessFunc)gncInvoiceGetDateDue },
|
||||
{ INVOICE_POSTED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted },
|
||||
{ INVOICE_IS_POSTED, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted },
|
||||
{ INVOICE_IS_PAID, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid },
|
||||
{ INVOICE_BILLINGID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetBillingID },
|
||||
{ INVOICE_NOTES, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetNotes },
|
||||
{ INVOICE_ACC, GNC_ID_ACCOUNT, (QofAccessFunc)gncInvoiceGetPostedAcc },
|
||||
{ INVOICE_POST_TXN, GNC_ID_TRANS, (QofAccessFunc)gncInvoiceGetPostedTxn },
|
||||
{ INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot },
|
||||
{ INVOICE_TYPE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncInvoiceGetType },
|
||||
{ INVOICE_TERMS, GNC_BILLTERM_MODULE_NAME, (QofAccessFunc)gncInvoiceGetTerms },
|
||||
{ INVOICE_BILLTO, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncInvoiceGetBillTo },
|
||||
{ QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncInvoiceGetBook },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncInvoiceGetGUID },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive },
|
||||
static QofParam params[] = {
|
||||
{ INVOICE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID, NULL },
|
||||
{ INVOICE_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL },
|
||||
{ INVOICE_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened, NULL },
|
||||
{ INVOICE_DUE, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateDue, NULL },
|
||||
{ INVOICE_POSTED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted, NULL },
|
||||
{ INVOICE_IS_POSTED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted, NULL },
|
||||
{ INVOICE_IS_PAID, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid, NULL },
|
||||
{ INVOICE_BILLINGID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetBillingID, NULL },
|
||||
{ INVOICE_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetNotes, NULL },
|
||||
{ INVOICE_ACC, GNC_ID_ACCOUNT, (QofAccessFunc)gncInvoiceGetPostedAcc, NULL },
|
||||
{ INVOICE_POST_TXN, GNC_ID_TRANS, (QofAccessFunc)gncInvoiceGetPostedTxn, NULL },
|
||||
{ INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot, NULL },
|
||||
{ INVOICE_TYPE, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetType, NULL },
|
||||
{ INVOICE_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms, NULL },
|
||||
{ INVOICE_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive, NULL },
|
||||
{ QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncInvoiceCompare, params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncInvoiceCompare, params);
|
||||
reg_lot ();
|
||||
reg_txn ();
|
||||
|
||||
@@ -1423,5 +1421,5 @@ gboolean gncInvoiceRegister (void)
|
||||
|
||||
gint64 gncInvoiceNextID (QofBook *book)
|
||||
{
|
||||
return gnc_book_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_get_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncInvoice.h -- the Core Business Invoice 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncInvoice.h -- the Core Business Invoice Interface
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -15,7 +36,12 @@ typedef struct _gncInvoice GncInvoice;
|
||||
#include "gncOwner.h"
|
||||
#include "gnc-lot.h"
|
||||
|
||||
#define GNC_INVOICE_MODULE_NAME "gncInvoice"
|
||||
#include "qofid.h"
|
||||
#include "qofinstance.h"
|
||||
|
||||
#define GNC_ID_INVOICE "gncInvoice"
|
||||
#define GNC_IS_INVOICE(obj) (QOF_CHECK_TYPE((obj), GNC_ID_INVOICE))
|
||||
#define GNC_INVOICE(obj) (QOF_CHECK_CAST((obj), GNC_ID_INVOICE, GncInvoice))
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
@@ -45,8 +71,6 @@ void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry);
|
||||
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncInvoiceGetBook (GncInvoice *invoice);
|
||||
const GUID * gncInvoiceGetGUID (GncInvoice *invoice);
|
||||
const char * gncInvoiceGetID (GncInvoice *invoice);
|
||||
GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
|
||||
Timespec gncInvoiceGetDateOpened (GncInvoice *invoice);
|
||||
@@ -115,10 +139,15 @@ GncInvoice * gncInvoiceGetInvoiceFromTxn (Transaction *txn);
|
||||
/* Given a LOT, find and return the Invoice attached to the lot */
|
||||
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot);
|
||||
|
||||
GUID gncInvoiceRetGUID (GncInvoice *invoice);
|
||||
GncInvoice * gncInvoiceLookupDirect (GUID guid, QofBook *book);
|
||||
/** Return a pointer to the instance gncInvoice that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* instance can't be found.
|
||||
* Equivalent function prototype is
|
||||
* GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid);
|
||||
*/
|
||||
#define gncInvoiceLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_INVOICE, GncInvoice)
|
||||
|
||||
GncInvoice * gncInvoiceLookup (QofBook *book, const GUID *guid);
|
||||
gboolean gncInvoiceIsDirty (GncInvoice *invoice);
|
||||
void gncInvoiceBeginEdit (GncInvoice *invoice);
|
||||
void gncInvoiceCommitEdit (GncInvoice *invoice);
|
||||
@@ -145,4 +174,10 @@ gboolean gncInvoiceIsPaid (GncInvoice *invoice);
|
||||
#define INVOICE_FROM_LOT "invoice-from-lot"
|
||||
#define INVOICE_FROM_TXN "invoice-from-txn"
|
||||
|
||||
/** deprecated functions */
|
||||
#define gncInvoiceGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
|
||||
#define gncInvoiceGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
||||
#define gncInvoiceRetGUID(x) (*(qof_instance_get_guid(QOF_INSTANCE(x))))
|
||||
#define gncInvoiceLookupDirect(G,B) gncInvoiceLookup((B),&(G))
|
||||
|
||||
#endif /* GNC_INVOICE_H_ */
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncInvoiceP.h -- the Core Busines Invoice 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncInvoiceP.h -- the Core Busines Invoice Interface
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -11,14 +32,37 @@
|
||||
#include "Account.h"
|
||||
#include "Transaction.h"
|
||||
#include "gnc-lot.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
gboolean gncInvoiceRegister (void);
|
||||
gint64 gncInvoiceNextID (QofBook *book);
|
||||
void gncInvoiceSetGUID (GncInvoice *invoice, const GUID *guid);
|
||||
void gncInvoiceSetDirty (GncInvoice *invoice, gboolean dirty);
|
||||
void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
|
||||
void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
|
||||
void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);
|
||||
void gncInvoiceSetPaidTxn (GncInvoice *invoice, Transaction *txn);
|
||||
|
||||
|
||||
/** The gncCloneInvoice() routine makes a copy of the indicated
|
||||
* invoice, placing it in the indicated book. It copies
|
||||
* the name, description, type, due-days, discount, etc.
|
||||
* It also copies (as needed) both parents and children, so that
|
||||
* the parent-child relationship is correctly mirrored in the
|
||||
* clone.
|
||||
* It then adds a pair of 'gemini' kvp pointers so that each copy
|
||||
* can be found from the other.
|
||||
*/
|
||||
|
||||
GncInvoice * gncCloneInvoice (GncInvoice *from, QofBook *);
|
||||
|
||||
/** The gncInvoiceObtainTwin() will find the 'twin' of the
|
||||
* indicated invoice in the indicated book. If the twin doesn't
|
||||
* yet exist in the book, it will be created (by calling
|
||||
* gncCloneInvoice()) 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.
|
||||
*/
|
||||
GncInvoice * gncInvoiceObtainTwin (GncInvoice *from, QofBook *book);
|
||||
#define gncInvoiceSetGUID(I,G) qof_entity_set_guid(QOF_ENTITY(I),(G))
|
||||
#endif /* GNC_INVOICEP_H_ */
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
/********************************************************************\
|
||||
* gncJob.c -- the Core Job 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncJob.c -- the Core Job Interface
|
||||
* Copyright (C) 2001, 2002 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -13,53 +35,54 @@
|
||||
#include "messages.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "gnc-book.h"
|
||||
#include "qofid.h"
|
||||
#include "qofquerycore.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofqueryobject.h"
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofinstance-p.h"
|
||||
#include "qofid.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofquerycore.h"
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncJob.h"
|
||||
#include "gncJobP.h"
|
||||
#include "gncOwnerP.h"
|
||||
|
||||
struct _gncJob {
|
||||
QofBook * book;
|
||||
GUID guid;
|
||||
char * id;
|
||||
char * name;
|
||||
char * desc;
|
||||
GncOwner owner;
|
||||
gboolean active;
|
||||
|
||||
int editlevel;
|
||||
gboolean do_free;
|
||||
gboolean dirty;
|
||||
struct _gncJob
|
||||
{
|
||||
QofInstance inst;
|
||||
char * id;
|
||||
char * name;
|
||||
char * desc;
|
||||
GncOwner owner;
|
||||
gboolean active;
|
||||
};
|
||||
|
||||
static short module = MOD_BUSINESS;
|
||||
static short module = MOD_BUSINESS;
|
||||
|
||||
#define _GNC_MOD_NAME GNC_JOB_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_JOB
|
||||
|
||||
/* ================================================================== */
|
||||
/* misc inline functions */
|
||||
|
||||
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
||||
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
||||
|
||||
static void addObj (GncJob *job);
|
||||
static void remObj (GncJob *job);
|
||||
|
||||
G_INLINE_FUNC void mark_job (GncJob *job);
|
||||
G_INLINE_FUNC void
|
||||
mark_job (GncJob *job)
|
||||
{
|
||||
job->dirty = TRUE;
|
||||
gncBusinessSetDirtyFlag (job->book, _GNC_MOD_NAME, TRUE);
|
||||
|
||||
gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
job->inst.dirty = TRUE;
|
||||
qof_collection_mark_dirty (job->inst.entity.collection);
|
||||
gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncJob *gncJobCreate (QofBook *book)
|
||||
@@ -69,26 +92,46 @@ GncJob *gncJobCreate (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
job = g_new0 (GncJob, 1);
|
||||
job->book = book;
|
||||
job->dirty = FALSE;
|
||||
qof_instance_init (&job->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
job->id = CACHE_INSERT ("");
|
||||
job->name = CACHE_INSERT ("");
|
||||
job->desc = CACHE_INSERT ("");
|
||||
job->active = TRUE;
|
||||
|
||||
qof_entity_guid_new (qof_book_get_entity_table (book), &job->guid);
|
||||
addObj (job);
|
||||
/* GncOwner not initialized */
|
||||
gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
|
||||
return job;
|
||||
}
|
||||
|
||||
GncJob *
|
||||
gncCloneJob (GncJob *from, QofBook *book)
|
||||
{
|
||||
GncJob *job;
|
||||
|
||||
if (!book) return NULL;
|
||||
|
||||
job = g_new0 (GncJob, 1);
|
||||
qof_instance_init (&job->inst, _GNC_MOD_NAME, book);
|
||||
qof_instance_gemini (&job->inst, &from->inst);
|
||||
|
||||
job->id = CACHE_INSERT (from->id);
|
||||
job->name = CACHE_INSERT (from->name);
|
||||
job->desc = CACHE_INSERT (from->desc);
|
||||
job->active = from->active;
|
||||
|
||||
job->owner = gncCloneOwner(&from->owner, book);
|
||||
|
||||
gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
void gncJobDestroy (GncJob *job)
|
||||
{
|
||||
if (!job) return;
|
||||
job->do_free = TRUE;
|
||||
job->inst.do_free = TRUE;
|
||||
gncJobCommitEdit (job);
|
||||
}
|
||||
|
||||
@@ -96,7 +139,7 @@ static void gncJobFree (GncJob *job)
|
||||
{
|
||||
if (!job) return;
|
||||
|
||||
gnc_engine_generate_event (&job->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&job->inst.entity, GNC_EVENT_DESTROY);
|
||||
|
||||
CACHE_REMOVE (job->id);
|
||||
CACHE_REMOVE (job->name);
|
||||
@@ -113,22 +156,36 @@ static void gncJobFree (GncJob *job)
|
||||
break;
|
||||
}
|
||||
|
||||
remObj (job);
|
||||
|
||||
qof_instance_release (&job->inst);
|
||||
g_free (job);
|
||||
}
|
||||
|
||||
GncJob *
|
||||
gncJobObtainTwin (GncJob *from, QofBook *book)
|
||||
{
|
||||
GncJob *job;
|
||||
if (!from) return NULL;
|
||||
|
||||
job = (GncJob *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!job)
|
||||
{
|
||||
job = gncCloneJob (from, book);
|
||||
}
|
||||
return job;
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
/* Set Functions */
|
||||
|
||||
#define SET_STR(obj, member, str) { \
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncJobBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
char * tmp; \
|
||||
\
|
||||
if (!safe_strcmp (member, str)) return; \
|
||||
gncJobBeginEdit (obj); \
|
||||
tmp = CACHE_INSERT (str); \
|
||||
CACHE_REMOVE (member); \
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
void gncJobSetID (GncJob *job, const char *id)
|
||||
{
|
||||
@@ -157,24 +214,20 @@ void gncJobSetReference (GncJob *job, const char *desc)
|
||||
gncJobCommitEdit (job);
|
||||
}
|
||||
|
||||
void gncJobSetGUID (GncJob *job, const GUID *guid)
|
||||
{
|
||||
if (!job || !guid) return;
|
||||
if (guid_equal (guid, &job->guid)) return;
|
||||
|
||||
gncJobBeginEdit (job);
|
||||
remObj (job);
|
||||
job->guid = *guid;
|
||||
addObj (job);
|
||||
gncJobCommitEdit (job);
|
||||
}
|
||||
|
||||
void gncJobSetOwner (GncJob *job, GncOwner *owner)
|
||||
{
|
||||
if (!job) return;
|
||||
if (!owner) return;
|
||||
if (gncOwnerEqual (owner, &(job->owner))) return;
|
||||
/* XXX: Fail if we have ANY orders or invoices */
|
||||
|
||||
switch (gncOwnerGetType (&(job->owner))) {
|
||||
case GNC_OWNER_CUSTOMER:
|
||||
case GNC_OWNER_VENDOR:
|
||||
break;
|
||||
default:
|
||||
PERR("Unsupported Owner type");
|
||||
return;
|
||||
}
|
||||
|
||||
gncJobBeginEdit (job);
|
||||
|
||||
@@ -218,34 +271,32 @@ void gncJobSetActive (GncJob *job, gboolean active)
|
||||
|
||||
void gncJobBeginEdit (GncJob *job)
|
||||
{
|
||||
GNC_BEGIN_EDIT (job, _GNC_MOD_NAME);
|
||||
GNC_BEGIN_EDIT (&job->inst);
|
||||
}
|
||||
|
||||
static void gncJobOnError (GncJob *job, QofBackendError errcode)
|
||||
static void gncJobOnError (QofInstance *inst, QofBackendError errcode)
|
||||
{
|
||||
PERR("Job QofBackend Failure: %d", errcode);
|
||||
}
|
||||
|
||||
static void gncJobOnDone (GncJob *job)
|
||||
static inline void job_free (QofInstance *inst)
|
||||
{
|
||||
job->dirty = FALSE;
|
||||
GncJob *job = (GncJob *)inst;
|
||||
gncJobFree (job);
|
||||
}
|
||||
|
||||
static inline void gncJobOnDone (QofInstance *qof) { }
|
||||
|
||||
void gncJobCommitEdit (GncJob *job)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (job);
|
||||
GNC_COMMIT_EDIT_PART2 (job, _GNC_MOD_NAME, gncJobOnError,
|
||||
gncJobOnDone, gncJobFree);
|
||||
GNC_COMMIT_EDIT_PART1 (&job->inst);
|
||||
GNC_COMMIT_EDIT_PART2 (&job->inst, gncJobOnError,
|
||||
gncJobOnDone, job_free);
|
||||
}
|
||||
|
||||
/* ================================================================== */
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncJobGetBook (GncJob *job)
|
||||
{
|
||||
if (!job) return NULL;
|
||||
return job->book;
|
||||
}
|
||||
|
||||
const char * gncJobGetID (GncJob *job)
|
||||
{
|
||||
if (!job) return NULL;
|
||||
@@ -270,45 +321,12 @@ GncOwner * gncJobGetOwner (GncJob *job)
|
||||
return &(job->owner);
|
||||
}
|
||||
|
||||
const GUID * gncJobGetGUID (GncJob *job)
|
||||
{
|
||||
if (!job) return NULL;
|
||||
return &job->guid;
|
||||
}
|
||||
|
||||
GUID gncJobRetGUID (GncJob *job)
|
||||
{
|
||||
const GUID *guid = gncJobGetGUID (job);
|
||||
if (guid)
|
||||
return *guid;
|
||||
return *guid_null ();
|
||||
}
|
||||
|
||||
gboolean gncJobGetActive (GncJob *job)
|
||||
{
|
||||
if (!job) return FALSE;
|
||||
return job->active;
|
||||
}
|
||||
|
||||
GncJob * gncJobLookup (QofBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
GncJob * gncJobLookupDirect (GUID guid, QofBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
return gncJobLookup (book, &guid);
|
||||
}
|
||||
|
||||
gboolean gncJobIsDirty (GncJob *job)
|
||||
{
|
||||
if (!job) return FALSE;
|
||||
return job->dirty;
|
||||
}
|
||||
|
||||
/* Other functions */
|
||||
|
||||
int gncJobCompare (const GncJob * a, const GncJob *b) {
|
||||
@@ -319,87 +337,50 @@ int gncJobCompare (const GncJob * a, const GncJob *b) {
|
||||
return (safe_strcmp(a->id, b->id));
|
||||
}
|
||||
|
||||
|
||||
/* ================================================================== */
|
||||
/* Package-Private functions */
|
||||
|
||||
static void addObj (GncJob *job)
|
||||
{
|
||||
gncBusinessAddObject (job->book, _GNC_MOD_NAME, job, &job->guid);
|
||||
}
|
||||
|
||||
static void remObj (GncJob *job)
|
||||
{
|
||||
gncBusinessRemoveObject (job->book, _GNC_MOD_NAME, &job->guid);
|
||||
}
|
||||
|
||||
static void _gncJobCreate (QofBook *book)
|
||||
{
|
||||
gncBusinessCreate (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncJobDestroy (QofBook *book)
|
||||
{
|
||||
gncBusinessDestroy (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static gboolean _gncJobIsDirty (QofBook *book)
|
||||
{
|
||||
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncJobMarkClean (QofBook *book)
|
||||
{
|
||||
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
||||
}
|
||||
|
||||
static void _gncJobForeach (QofBook *book, QofEntityForeachCB cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
||||
}
|
||||
|
||||
static const char * _gncJobPrintable (gpointer item)
|
||||
{
|
||||
GncJob *c;
|
||||
|
||||
if (!item) return NULL;
|
||||
|
||||
c = item;
|
||||
return c->name;
|
||||
}
|
||||
|
||||
static QofObject gncJobDesc = {
|
||||
QOF_OBJECT_VERSION,
|
||||
_GNC_MOD_NAME,
|
||||
"Job",
|
||||
_gncJobCreate,
|
||||
_gncJobDestroy,
|
||||
_gncJobIsDirty,
|
||||
_gncJobMarkClean,
|
||||
_gncJobForeach,
|
||||
_gncJobPrintable
|
||||
static QofObject gncJobDesc =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: _GNC_MOD_NAME,
|
||||
type_label: "Job",
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: _gncJobPrintable
|
||||
};
|
||||
|
||||
gboolean gncJobRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
{ JOB_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncJobGetID },
|
||||
{ JOB_NAME, QOF_QUERYCORE_STRING, (QofAccessFunc)gncJobGetName },
|
||||
{ JOB_REFERENCE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncJobGetReference },
|
||||
{ JOB_OWNER, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncJobGetOwner },
|
||||
{ JOB_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncJobGetActive },
|
||||
{ QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncJobGetBook },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncJobGetGUID },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncJobGetActive },
|
||||
static QofParam params[] = {
|
||||
{ JOB_ID, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetID, NULL },
|
||||
{ JOB_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetName, NULL },
|
||||
{ JOB_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL },
|
||||
{ JOB_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncJobGetReference, NULL },
|
||||
{ JOB_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncJobGetOwner, NULL },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncJobGetActive, NULL },
|
||||
{ QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncJobCompare, params);
|
||||
|
||||
return qof_object_register (&gncJobDesc);
|
||||
}
|
||||
|
||||
gint64 gncJobNextID (QofBook *book)
|
||||
{
|
||||
return gnc_book_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_get_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncJob.h -- the Core Job 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncJob.h -- the Core Job Interface
|
||||
* Copyright (C) 2001, 2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -9,10 +30,14 @@
|
||||
|
||||
typedef struct _gncJob GncJob;
|
||||
|
||||
#include "qofid.h"
|
||||
#include "qofinstance.h"
|
||||
#include "gncAddress.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
#define GNC_JOB_MODULE_NAME "gncJob"
|
||||
#define GNC_ID_JOB "gncJob"
|
||||
#define GNC_IS_JOB(obj) (QOF_CHECK_TYPE((obj), GNC_ID_JOB))
|
||||
#define GNC_JOB(obj) (QOF_CHECK_CAST((obj), GNC_ID_JOB, GncJob))
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
@@ -32,20 +57,22 @@ void gncJobCommitEdit (GncJob *job);
|
||||
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncJobGetBook (GncJob *job);
|
||||
const GUID * gncJobGetGUID (GncJob *job);
|
||||
const char * gncJobGetID (GncJob *job);
|
||||
const char * gncJobGetName (GncJob *job);
|
||||
const char * gncJobGetReference (GncJob *job);
|
||||
GncOwner * gncJobGetOwner (GncJob *job);
|
||||
gboolean gncJobGetActive (GncJob *job);
|
||||
|
||||
GUID gncJobRetGUID (GncJob *job);
|
||||
GncJob *gncJobLookupDirect (GUID guid, QofBook *book);
|
||||
|
||||
GncJob * gncJobLookup (QofBook *book, const GUID *guid);
|
||||
gboolean gncJobIsDirty (GncJob *job);
|
||||
|
||||
/** Return a pointer to the instance gncJob that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* instance can't be found.
|
||||
* Equivalent function prototype is
|
||||
* GncJob * gncJobLookup (QofBook *book, const GUID *guid);
|
||||
*/
|
||||
#define gncJobLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_JOB, GncJob)
|
||||
|
||||
/* Other functions */
|
||||
|
||||
int gncJobCompare (const GncJob *a, const GncJob *b);
|
||||
@@ -56,4 +83,10 @@ int gncJobCompare (const GncJob *a, const GncJob *b);
|
||||
#define JOB_OWNER "owner"
|
||||
#define JOB_ACTIVE "active"
|
||||
|
||||
/** deprecated functions */
|
||||
#define gncJobGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
|
||||
#define gncJobGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
||||
#define gncJobRetGUID(x) (*(qof_instance_get_guid(QOF_INSTANCE(x))))
|
||||
#define gncJobLookupDirect(G,B) gncJobLookup((B),&(G))
|
||||
|
||||
#endif /* GNC_JOB_H_ */
|
||||
|
||||
@@ -1,6 +1,28 @@
|
||||
/********************************************************************\
|
||||
* gncJobP.h -- the Core Job 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncJobP.h -- the Core Job Interface
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
|
||||
@@ -8,9 +30,30 @@
|
||||
#define GNC_JOBP_H_
|
||||
|
||||
#include "gncJob.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
gboolean gncJobRegister (void);
|
||||
gint64 gncJobNextID (QofBook *book);
|
||||
void gncJobSetGUID (GncJob *job, const GUID *guid);
|
||||
|
||||
/** The gncCloneTaxTable() routine makes a copy of the indicated
|
||||
* tax table, placing it in the indicated book. It copies
|
||||
* the id, name description and owner.
|
||||
* It then adds a pair of 'gemini' kvp pointers so that each copy
|
||||
* can be found from the other.
|
||||
*/
|
||||
GncJob * gncCloneJob (GncJob *from, QofBook *book);
|
||||
|
||||
/** The gncJobObtainTwin() will find the 'twin' of the
|
||||
* 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.
|
||||
*
|
||||
* We called this routine 'Obtain' instead of "Get" to distinguish
|
||||
* it from the other Get routines, which work in fundamentally
|
||||
* different ways.
|
||||
*/
|
||||
GncJob * gncJobObtainTwin (GncJob *from, QofBook *book);
|
||||
|
||||
#define gncJobSetGUID(E,G) qof_entity_set_guid(QOF_ENTITY(E),(G))
|
||||
|
||||
#endif /* GNC_JOBP_H_ */
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncOrder.c -- the Core Business Order *
|
||||
* *
|
||||
* 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncOrder.c -- the Core Business Order
|
||||
* Copyright (C) 2001,2002 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -12,14 +33,19 @@
|
||||
#include "gnc-numeric.h"
|
||||
#include "kvp_frame.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-book.h"
|
||||
|
||||
#include "qofbook.h"
|
||||
#include "qofclass.h"
|
||||
#include "qofid.h"
|
||||
#include "qofquerycore.h"
|
||||
#include "qofid-p.h"
|
||||
#include "qofinstance.h"
|
||||
#include "qofinstance-p.h"
|
||||
#include "qofobject.h"
|
||||
#include "qofquery.h"
|
||||
#include "qofqueryobject.h"
|
||||
#include "qofquerycore.h"
|
||||
|
||||
#include "gnc-event-p.h"
|
||||
#include "gnc-be-utils.h"
|
||||
#include "qofid-p.h"
|
||||
|
||||
#include "gncBusiness.h"
|
||||
#include "gncEntry.h"
|
||||
@@ -27,30 +53,27 @@
|
||||
#include "gncOrder.h"
|
||||
#include "gncOrderP.h"
|
||||
#include "gncOwner.h"
|
||||
#include "gncOwnerP.h"
|
||||
|
||||
struct _gncOrder {
|
||||
QofBook *book;
|
||||
struct _gncOrder
|
||||
{
|
||||
QofInstance inst;
|
||||
|
||||
GUID guid;
|
||||
char * id;
|
||||
char * notes;
|
||||
gboolean active;
|
||||
|
||||
char * reference;
|
||||
char * printname;
|
||||
GncOwner owner;
|
||||
GList * entries;
|
||||
Timespec opened;
|
||||
Timespec closed;
|
||||
gboolean active;
|
||||
|
||||
int editlevel;
|
||||
gboolean do_free;
|
||||
|
||||
gboolean dirty;
|
||||
};
|
||||
|
||||
static short module = MOD_BUSINESS;
|
||||
|
||||
#define _GNC_MOD_NAME GNC_ORDER_MODULE_NAME
|
||||
#define _GNC_MOD_NAME GNC_ID_ORDER
|
||||
|
||||
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
||||
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
||||
@@ -65,19 +88,16 @@ static short module = MOD_BUSINESS;
|
||||
member = tmp; \
|
||||
}
|
||||
|
||||
static void addObj (GncOrder *order);
|
||||
static void remObj (GncOrder *order);
|
||||
|
||||
G_INLINE_FUNC void mark_order (GncOrder *order);
|
||||
G_INLINE_FUNC void
|
||||
mark_order (GncOrder *order)
|
||||
{
|
||||
order->dirty = TRUE;
|
||||
gncBusinessSetDirtyFlag (order->book, _GNC_MOD_NAME, TRUE);
|
||||
|
||||
gnc_engine_generate_event (&order->guid, _GNC_MOD_NAME, GNC_EVENT_MODIFY);
|
||||
order->inst.dirty = TRUE;
|
||||
qof_collection_mark_dirty (order->inst.entity.collection);
|
||||
gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_MODIFY);
|
||||
}
|
||||
|
||||
/* =============================================================== */
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
GncOrder *gncOrderCreate (QofBook *book)
|
||||
@@ -87,7 +107,7 @@ GncOrder *gncOrderCreate (QofBook *book)
|
||||
if (!book) return NULL;
|
||||
|
||||
order = g_new0 (GncOrder, 1);
|
||||
order->book = book;
|
||||
qof_instance_init (&order->inst, _GNC_MOD_NAME, book);
|
||||
|
||||
order->id = CACHE_INSERT ("");
|
||||
order->notes = CACHE_INSERT ("");
|
||||
@@ -95,10 +115,7 @@ GncOrder *gncOrderCreate (QofBook *book)
|
||||
|
||||
order->active = TRUE;
|
||||
|
||||
qof_entity_guid_new (qof_book_get_entity_table (book), &order->guid);
|
||||
addObj (order);
|
||||
|
||||
gnc_engine_generate_event (&order->guid, _GNC_MOD_NAME, GNC_EVENT_CREATE);
|
||||
gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return order;
|
||||
}
|
||||
@@ -106,7 +123,7 @@ GncOrder *gncOrderCreate (QofBook *book)
|
||||
void gncOrderDestroy (GncOrder *order)
|
||||
{
|
||||
if (!order) return;
|
||||
order->do_free = TRUE;
|
||||
order->inst.do_free = TRUE;
|
||||
gncOrderCommitEdit (order);
|
||||
}
|
||||
|
||||
@@ -114,33 +131,73 @@ static void gncOrderFree (GncOrder *order)
|
||||
{
|
||||
if (!order) return;
|
||||
|
||||
gnc_engine_generate_event (&order->guid, _GNC_MOD_NAME, GNC_EVENT_DESTROY);
|
||||
gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_DESTROY);
|
||||
|
||||
g_list_free (order->entries);
|
||||
CACHE_REMOVE (order->id);
|
||||
CACHE_REMOVE (order->notes);
|
||||
CACHE_REMOVE (order->reference);
|
||||
remObj (order);
|
||||
|
||||
if (order->printname) g_free (order->printname);
|
||||
|
||||
qof_instance_release (&order->inst);
|
||||
g_free (order);
|
||||
}
|
||||
|
||||
/* Set Functions */
|
||||
|
||||
void gncOrderSetGUID (GncOrder *order, const GUID *guid)
|
||||
GncOrder *
|
||||
gncCloneOrder (GncOrder *from, QofBook *book)
|
||||
{
|
||||
if (!order || !guid) return;
|
||||
if (guid_equal (guid, &order->guid)) return;
|
||||
GList *node;
|
||||
GncOrder *order;
|
||||
|
||||
gncOrderBeginEdit (order);
|
||||
remObj (order);
|
||||
order->guid = *guid;
|
||||
addObj (order);
|
||||
gncOrderCommitEdit (order);
|
||||
if (!book) return NULL;
|
||||
|
||||
order = g_new0 (GncOrder, 1);
|
||||
qof_instance_init (&order->inst, _GNC_MOD_NAME, book);
|
||||
qof_instance_gemini (&order->inst, &from->inst);
|
||||
|
||||
order->id = CACHE_INSERT (from->id);
|
||||
order->notes = CACHE_INSERT (from->notes);
|
||||
order->reference = CACHE_INSERT (from->reference);
|
||||
|
||||
order->active = from->active;
|
||||
order->printname = NULL; /* yes, null, that's right */
|
||||
order->opened = from->opened;
|
||||
order->closed = from->closed;
|
||||
|
||||
order->owner = gncCloneOwner (&from->owner, book);
|
||||
|
||||
order->entries = NULL;
|
||||
for (node = g_list_last(from->entries); node; node=node->prev)
|
||||
{
|
||||
GncEntry *entry = node->data;
|
||||
entry = gncEntryObtainTwin (entry, book);
|
||||
order->entries = g_list_prepend (order->entries, entry);
|
||||
}
|
||||
|
||||
gnc_engine_gen_event (&order->inst.entity, GNC_EVENT_CREATE);
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
GncOrder *
|
||||
gncOrderObtainTwin (GncOrder *from, QofBook *book)
|
||||
{
|
||||
GncOrder *order;
|
||||
if (!book) return NULL;
|
||||
|
||||
order = (GncOrder *) qof_instance_lookup_twin (QOF_INSTANCE(from), book);
|
||||
if (!order)
|
||||
{
|
||||
order = gncCloneOrder (from, book);
|
||||
}
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
/* =============================================================== */
|
||||
/* Set Functions */
|
||||
|
||||
void gncOrderSetID (GncOrder *order, const char *id)
|
||||
{
|
||||
if (!order || !id) return;
|
||||
@@ -206,12 +263,7 @@ void gncOrderSetActive (GncOrder *order, gboolean active)
|
||||
gncOrderCommitEdit (order);
|
||||
}
|
||||
|
||||
void gncOrderSetDirty (GncOrder *order, gboolean dirty)
|
||||
{
|
||||
if (!order) return;
|
||||
order->dirty = dirty;
|
||||
}
|
||||
|
||||
/* =============================================================== */
|
||||
/* Add an Entry to the Order */
|
||||
void gncOrderAddEntry (GncOrder *order, GncEntry *entry)
|
||||
{
|
||||
@@ -242,18 +294,6 @@ void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry)
|
||||
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncOrderGetBook (GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
return order->book;
|
||||
}
|
||||
|
||||
const GUID * gncOrderGetGUID (GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
return &(order->guid);
|
||||
}
|
||||
|
||||
const char * gncOrderGetID (GncOrder *order)
|
||||
{
|
||||
if (!order) return NULL;
|
||||
@@ -305,19 +345,6 @@ GList * gncOrderGetEntries (GncOrder *order)
|
||||
return order->entries;
|
||||
}
|
||||
|
||||
GncOrder * gncOrderLookup (QofBook *book, const GUID *guid)
|
||||
{
|
||||
if (!book || !guid) return NULL;
|
||||
return qof_entity_lookup (gnc_book_get_entity_table (book),
|
||||
guid, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
gboolean gncOrderIsDirty (GncOrder *order)
|
||||
{
|
||||
if (!order) return FALSE;
|
||||
return order->dirty;
|
||||
}
|
||||
|
||||
gboolean gncOrderIsClosed (GncOrder *order)
|
||||
{
|
||||
if (!order) return FALSE;
|
||||
@@ -325,26 +352,31 @@ gboolean gncOrderIsClosed (GncOrder *order)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* =============================================================== */
|
||||
|
||||
void gncOrderBeginEdit (GncOrder *order)
|
||||
{
|
||||
GNC_BEGIN_EDIT (order, _GNC_MOD_NAME);
|
||||
GNC_BEGIN_EDIT (&order->inst);
|
||||
}
|
||||
|
||||
static void gncOrderOnError (GncOrder *order, QofBackendError errcode)
|
||||
static inline void gncOrderOnError (QofInstance *order, QofBackendError errcode)
|
||||
{
|
||||
PERR("Order QofBackend Failure: %d", errcode);
|
||||
}
|
||||
|
||||
static void gncOrderOnDone (GncOrder *order)
|
||||
static inline void gncOrderOnDone (QofInstance *order) {}
|
||||
|
||||
static inline void order_free (QofInstance *inst)
|
||||
{
|
||||
order->dirty = FALSE;
|
||||
GncOrder *order = (GncOrder *) inst;
|
||||
gncOrderFree (order);
|
||||
}
|
||||
|
||||
void gncOrderCommitEdit (GncOrder *order)
|
||||
{
|
||||
GNC_COMMIT_EDIT_PART1 (order);
|
||||
GNC_COMMIT_EDIT_PART2 (order, _GNC_MOD_NAME, gncOrderOnError,
|
||||
gncOrderOnDone, gncOrderFree);
|
||||
GNC_COMMIT_EDIT_PART1 (&order->inst);
|
||||
GNC_COMMIT_EDIT_PART2 (&order->inst, gncOrderOnError,
|
||||
gncOrderOnDone, order_free);
|
||||
}
|
||||
|
||||
int gncOrderCompare (GncOrder *a, GncOrder *b)
|
||||
@@ -364,54 +396,20 @@ int gncOrderCompare (GncOrder *a, GncOrder *b)
|
||||
compare = timespec_cmp (&(a->closed), &(b->closed));
|
||||
if (compare) return compare;
|
||||
|
||||
return guid_compare (&(a->guid), &(b->guid));
|
||||
return guid_compare (&(a->inst.entity.guid), &(b->inst.entity.guid));
|
||||
}
|
||||
|
||||
/* =========================================================== */
|
||||
/* Package-Private functions */
|
||||
|
||||
static void addObj (GncOrder *order)
|
||||
{
|
||||
gncBusinessAddObject (order->book, _GNC_MOD_NAME, order, &order->guid);
|
||||
}
|
||||
|
||||
static void remObj (GncOrder *order)
|
||||
{
|
||||
gncBusinessRemoveObject (order->book, _GNC_MOD_NAME, &order->guid);
|
||||
}
|
||||
|
||||
static void _gncOrderCreate (QofBook *book)
|
||||
{
|
||||
gncBusinessCreate (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncOrderDestroy (QofBook *book)
|
||||
{
|
||||
gncBusinessDestroy (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static gboolean _gncOrderIsDirty (QofBook *book)
|
||||
{
|
||||
return gncBusinessIsDirty (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
static void _gncOrderMarkClean (QofBook *book)
|
||||
{
|
||||
gncBusinessSetDirtyFlag (book, _GNC_MOD_NAME, FALSE);
|
||||
}
|
||||
|
||||
static void _gncOrderForeach (QofBook *book, QofEntityForeachCB cb,
|
||||
gpointer user_data)
|
||||
{
|
||||
gncBusinessForeach (book, _GNC_MOD_NAME, cb, user_data);
|
||||
}
|
||||
|
||||
static const char * _gncOrderPrintable (gpointer obj)
|
||||
static const char *
|
||||
_gncOrderPrintable (gpointer obj)
|
||||
{
|
||||
GncOrder *order = obj;
|
||||
|
||||
g_return_val_if_fail (order, NULL);
|
||||
|
||||
if (order->dirty || order->printname == NULL) {
|
||||
if (order->inst.dirty || order->printname == NULL) {
|
||||
if (order->printname) g_free (order->printname);
|
||||
|
||||
order->printname =
|
||||
@@ -422,40 +420,41 @@ static const char * _gncOrderPrintable (gpointer obj)
|
||||
return order->printname;
|
||||
}
|
||||
|
||||
static QofObject gncOrderDesc = {
|
||||
QOF_OBJECT_VERSION,
|
||||
_GNC_MOD_NAME,
|
||||
"Order",
|
||||
_gncOrderCreate,
|
||||
_gncOrderDestroy,
|
||||
_gncOrderIsDirty,
|
||||
_gncOrderMarkClean,
|
||||
_gncOrderForeach,
|
||||
_gncOrderPrintable,
|
||||
static QofObject gncOrderDesc =
|
||||
{
|
||||
interface_version: QOF_OBJECT_VERSION,
|
||||
e_type: _GNC_MOD_NAME,
|
||||
type_label: "Order",
|
||||
book_begin: NULL,
|
||||
book_end: NULL,
|
||||
is_dirty: qof_collection_is_dirty,
|
||||
mark_clean: qof_collection_mark_clean,
|
||||
foreach: qof_collection_foreach,
|
||||
printable: _gncOrderPrintable,
|
||||
};
|
||||
|
||||
gboolean gncOrderRegister (void)
|
||||
{
|
||||
static QofQueryObject params[] = {
|
||||
{ ORDER_ID, QOF_QUERYCORE_STRING, (QofAccessFunc)gncOrderGetID },
|
||||
{ ORDER_REFERENCE, QOF_QUERYCORE_STRING, (QofAccessFunc)gncOrderGetReference },
|
||||
{ ORDER_OWNER, GNC_OWNER_MODULE_NAME, (QofAccessFunc)gncOrderGetOwner },
|
||||
{ ORDER_OPENED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncOrderGetDateOpened },
|
||||
{ ORDER_IS_CLOSED, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncOrderIsClosed },
|
||||
{ ORDER_CLOSED, QOF_QUERYCORE_DATE, (QofAccessFunc)gncOrderGetDateClosed },
|
||||
{ ORDER_NOTES, QOF_QUERYCORE_STRING, (QofAccessFunc)gncOrderGetNotes },
|
||||
{ QOF_QUERY_PARAM_BOOK, GNC_ID_BOOK, (QofAccessFunc)gncOrderGetBook },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_QUERYCORE_GUID, (QofAccessFunc)gncOrderGetGUID },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_QUERYCORE_BOOLEAN, (QofAccessFunc)gncOrderGetActive },
|
||||
static QofParam params[] = {
|
||||
{ ORDER_ID, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetID, NULL },
|
||||
{ ORDER_REFERENCE, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetReference, NULL },
|
||||
{ ORDER_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncOrderGetOwner, NULL },
|
||||
{ ORDER_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateOpened, NULL },
|
||||
{ ORDER_IS_CLOSED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderIsClosed, NULL },
|
||||
{ ORDER_CLOSED, QOF_TYPE_DATE, (QofAccessFunc)gncOrderGetDateClosed, NULL },
|
||||
{ ORDER_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncOrderGetNotes, NULL },
|
||||
{ QOF_QUERY_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncOrderGetActive, NULL },
|
||||
{ QOF_QUERY_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
||||
{ QOF_QUERY_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
||||
{ NULL },
|
||||
};
|
||||
|
||||
qof_query_object_register (_GNC_MOD_NAME, (QofSortFunc)gncOrderCompare, params);
|
||||
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncOrderCompare, params);
|
||||
|
||||
return qof_object_register (&gncOrderDesc);
|
||||
}
|
||||
|
||||
gint64 gncOrderNextID (QofBook *book)
|
||||
{
|
||||
return gnc_book_get_counter (book, _GNC_MOD_NAME);
|
||||
return qof_book_get_counter (book, _GNC_MOD_NAME);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,26 @@
|
||||
/********************************************************************\
|
||||
* gncOrder.h -- the Core Business Order 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 *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* gncOrder.h -- the Core Business Order Interface
|
||||
* Copyright (C) 2001 Derek Atkins
|
||||
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||
*/
|
||||
@@ -9,11 +30,15 @@
|
||||
|
||||
typedef struct _gncOrder GncOrder;
|
||||
|
||||
#include "gnc-book.h"
|
||||
#include "gncEntry.h"
|
||||
#include "gncOwner.h"
|
||||
#include "qofbook.h"
|
||||
#include "qofid.h"
|
||||
#include "qofinstance.h"
|
||||
|
||||
#define GNC_ORDER_MODULE_NAME "gncOrder"
|
||||
#define GNC_ID_ORDER "gncOrder"
|
||||
#define GNC_IS_ORDER(obj) (QOF_CHECK_TYPE((obj), GNC_ID_ORDER))
|
||||
#define GNC_ORDER(obj) (QOF_CHECK_CAST((obj), GNC_ID_ORDER, GncOrder))
|
||||
|
||||
/* Create/Destroy Functions */
|
||||
|
||||
@@ -36,8 +61,6 @@ void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry);
|
||||
|
||||
/* Get Functions */
|
||||
|
||||
QofBook * gncOrderGetBook (GncOrder *order);
|
||||
const GUID * gncOrderGetGUID (GncOrder *order);
|
||||
const char * gncOrderGetID (GncOrder *order);
|
||||
GncOwner * gncOrderGetOwner (GncOrder *order);
|
||||
Timespec gncOrderGetDateOpened (GncOrder *order);
|
||||
@@ -49,7 +72,6 @@ gboolean gncOrderGetActive (GncOrder *order);
|
||||
/* Get the list Entries */
|
||||
GList * gncOrderGetEntries (GncOrder *order);
|
||||
|
||||
GncOrder * gncOrderLookup (QofBook *book, const GUID *guid);
|
||||
gboolean gncOrderIsDirty (GncOrder *order);
|
||||
void gncOrderBeginEdit (GncOrder *order);
|
||||
void gncOrderCommitEdit (GncOrder *order);
|
||||
@@ -57,6 +79,15 @@ int gncOrderCompare (GncOrder *a, GncOrder *b);
|
||||
|
||||
gboolean gncOrderIsClosed (GncOrder *order);
|
||||
|
||||
/** Return a pointer to the instance gncOrder that is identified
|
||||
* by the guid, and is residing in the book. Returns NULL if the
|
||||
* instance can't be found.
|
||||
* Equivalent function prototype is
|
||||
* GncOrder * gncOrderLookup (QofBook *book, const GUID *guid);
|
||||
*/
|
||||
#define gncOrderLookup(book,guid) \
|
||||
QOF_BOOK_LOOKUP_ENTITY((book),(guid),GNC_ID_ORDER, GncOrder)
|
||||
|
||||
#define ORDER_ID "id"
|
||||
#define ORDER_REFERENCE "reference"
|
||||
#define ORDER_OWNER "owner"
|
||||
@@ -65,4 +96,8 @@ gboolean gncOrderIsClosed (GncOrder *order);
|
||||
#define ORDER_IS_CLOSED "is_closed?"
|
||||
#define ORDER_NOTES "notes"
|
||||
|
||||
/** deprecated functions */
|
||||
#define gncOrderGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
|
||||
#define gncOrderGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
|
||||
|
||||
#endif /* GNC_ORDER_H_ */
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user