2005-11-07 09:45:58 -06:00
|
|
|
/********************************************************************\
|
2006-01-08 11:51:29 -06:00
|
|
|
* qofbook.c -- dataset access (set of books of entities) *
|
2005-11-07 09:45:58 -06:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2005-11-07 09:45:58 -06:00
|
|
|
\********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FILE:
|
2015-06-27 18:06:56 -05:00
|
|
|
* qofbook.cpp
|
2005-11-07 09:45:58 -06:00
|
|
|
*
|
|
|
|
* FUNCTION:
|
2006-01-08 11:51:29 -06:00
|
|
|
* Encapsulate all the information about a QOF dataset.
|
2005-11-07 09:45:58 -06:00
|
|
|
*
|
|
|
|
* HISTORY:
|
|
|
|
* Created by Linas Vepstas December 1998
|
|
|
|
* Copyright (c) 1998-2001,2003 Linas Vepstas <linas@linas.org>
|
|
|
|
* Copyright (c) 2000 Dave Peticolas
|
2007-05-01 20:57:49 -05:00
|
|
|
* Copyright (c) 2007 David Hampton <hampton@employees.org>
|
2005-11-07 09:45:58 -06:00
|
|
|
*/
|
|
|
|
|
2014-04-25 15:41:11 -05:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
|
2017-10-26 04:14:21 -05:00
|
|
|
#include <config.h>
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
2016-04-05 17:49:02 -05:00
|
|
|
#ifdef GNC_PLATFORM_WINDOWS
|
|
|
|
/* Mingw disables the standard type macros for C++ without this override. */
|
|
|
|
#define __STDC_FORMAT_MACROS = 1
|
|
|
|
#endif
|
2016-03-17 16:37:15 -05:00
|
|
|
#include <inttypes.h>
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2014-04-25 15:41:11 -05:00
|
|
|
}
|
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
#include "qof.h"
|
2006-02-20 13:54:03 -06:00
|
|
|
#include "qofevent-p.h"
|
2016-11-27 16:12:43 -06:00
|
|
|
#include "qofbackend.h"
|
2005-11-07 09:45:58 -06:00
|
|
|
#include "qofbook-p.h"
|
|
|
|
#include "qofid-p.h"
|
|
|
|
#include "qofobject-p.h"
|
2009-12-04 14:26:48 -06:00
|
|
|
#include "qofbookslots.h"
|
2017-08-06 10:12:16 -05:00
|
|
|
#include "kvp-frame.hpp"
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
static QofLogModule log_module = QOF_MOD_ENGINE;
|
2014-05-07 08:37:14 -05:00
|
|
|
#define AB_KEY "hbci"
|
|
|
|
#define AB_TEMPLATES "template-list"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
// PROP_ROOT_ACCOUNT, /* Table */
|
|
|
|
// PROP_ROOT_TEMPLATE, /* Table */
|
2016-06-17 15:48:03 -05:00
|
|
|
/* keep trading accounts property, while adding book-currency, default gains
|
|
|
|
policy and default gains account properties, so that files prior to 2.7 can
|
|
|
|
be read/processed; GUI changed to use all four properties as of 2.7.
|
|
|
|
Trading accounts, on the one hand, and book-currency plus default-gains-
|
|
|
|
policy, and optionally, default gains account, on the other, are mutually
|
|
|
|
exclusive */
|
2014-05-07 08:37:14 -05:00
|
|
|
PROP_OPT_TRADING_ACCOUNTS, /* KVP */
|
2016-06-17 15:48:03 -05:00
|
|
|
/* Book currency and default gains policy properties only apply if currency
|
2015-06-27 18:06:56 -05:00
|
|
|
accounting method selected in GUI is 'book-currency'; both required and
|
|
|
|
both are exclusive with trading accounts */
|
2015-02-28 18:39:34 -06:00
|
|
|
PROP_OPT_BOOK_CURRENCY, /* KVP */
|
2015-06-27 18:06:56 -05:00
|
|
|
PROP_OPT_DEFAULT_GAINS_POLICY, /* KVP */
|
2016-06-17 15:48:03 -05:00
|
|
|
/* Default gains account property only applies if currency accounting method
|
|
|
|
selected in GUI is 'book-currency'; its use is optional but exclusive with
|
|
|
|
trading accounts */
|
|
|
|
PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID, /* KVP */
|
2014-05-07 08:37:14 -05:00
|
|
|
PROP_OPT_AUTO_READONLY_DAYS,/* KVP */
|
|
|
|
PROP_OPT_NUM_FIELD_SOURCE, /* KVP */
|
|
|
|
PROP_OPT_DEFAULT_BUDGET, /* KVP */
|
|
|
|
PROP_OPT_FY_END, /* KVP */
|
|
|
|
PROP_AB_TEMPLATES, /* KVP */
|
|
|
|
N_PROPERTIES /* Just a counter */
|
|
|
|
};
|
|
|
|
|
|
|
|
QOF_GOBJECT_GET_TYPE(QofBook, qof_book, QOF_TYPE_INSTANCE, {});
|
|
|
|
QOF_GOBJECT_DISPOSE(qof_book);
|
|
|
|
QOF_GOBJECT_FINALIZE(qof_book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2014-05-07 08:37:14 -05:00
|
|
|
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
|
2014-05-07 10:55:42 -05:00
|
|
|
#undef G_PARAM_READWRITE
|
|
|
|
#define G_PARAM_READWRITE static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_WRITABLE)
|
2005-11-07 09:45:58 -06:00
|
|
|
/* ====================================================================== */
|
|
|
|
/* constructor / destructor */
|
|
|
|
|
|
|
|
static void coll_destroy(gpointer col)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
qof_collection_destroy((QofCollection *) col);
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qof_book_init (QofBook *book)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return;
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
book->hash_of_collections = g_hash_table_new_full(
|
|
|
|
g_str_hash, g_str_equal,
|
2012-05-21 12:28:30 -05:00
|
|
|
(GDestroyNotify)qof_string_cache_remove, /* key_destroy_func */
|
2009-09-18 14:40:57 -05:00
|
|
|
coll_destroy); /* value_destroy_func */
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
qof_instance_init_data (&book->inst, QOF_ID_BOOK, book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
book->data_tables = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
book->data_table_finalizers = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
|
|
book->book_open = 'y';
|
2011-01-14 17:25:27 -06:00
|
|
|
book->read_only = FALSE;
|
2012-01-09 17:10:20 -06:00
|
|
|
book->session_dirty = FALSE;
|
2009-09-18 14:40:57 -05:00
|
|
|
book->version = 0;
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2014-05-07 08:37:14 -05:00
|
|
|
static void
|
|
|
|
qof_book_get_property (GObject* object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue* value,
|
|
|
|
GParamSpec* pspec)
|
|
|
|
{
|
|
|
|
QofBook *book;
|
|
|
|
gchar *key;
|
|
|
|
|
|
|
|
g_return_if_fail (QOF_IS_BOOK (object));
|
|
|
|
book = QOF_BOOK (object);
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_OPT_TRADING_ACCOUNTS:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_TRADING_ACCOUNTS);
|
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2015-06-27 18:06:56 -05:00
|
|
|
case PROP_OPT_BOOK_CURRENCY:
|
2015-02-09 14:52:29 -06:00
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
2015-06-27 18:06:56 -05:00
|
|
|
OPTION_NAME_BOOK_CURRENCY);
|
2015-02-09 14:52:29 -06:00
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2015-06-27 18:06:56 -05:00
|
|
|
case PROP_OPT_DEFAULT_GAINS_POLICY:
|
2015-02-28 18:39:34 -06:00
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
2015-06-27 18:06:56 -05:00
|
|
|
OPTION_NAME_DEFAULT_GAINS_POLICY);
|
2015-02-28 18:39:34 -06:00
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2016-06-17 15:48:03 -05:00
|
|
|
case PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_DEFAULT_GAINS_LOSS_ACCT_GUID);
|
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2014-05-07 08:37:14 -05:00
|
|
|
case PROP_OPT_AUTO_READONLY_DAYS:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_AUTO_READONLY_DAYS);
|
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
|
|
|
case PROP_OPT_NUM_FIELD_SOURCE:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_NUM_FIELD_SOURCE);
|
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
|
|
|
case PROP_OPT_DEFAULT_BUDGET:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_DEFAULT_BUDGET);
|
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
2015-06-27 18:06:56 -05:00
|
|
|
break;
|
2014-05-07 08:37:14 -05:00
|
|
|
case PROP_OPT_FY_END:
|
2014-05-07 10:55:42 -05:00
|
|
|
key = const_cast<char*>("fy_end");
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
break;
|
|
|
|
case PROP_AB_TEMPLATES:
|
2014-05-07 10:55:42 -05:00
|
|
|
key = const_cast<char*>(AB_KEY "/" AB_TEMPLATES);
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qof_book_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
QofBook *book;
|
|
|
|
gchar *key;
|
|
|
|
|
|
|
|
g_return_if_fail (QOF_IS_BOOK (object));
|
|
|
|
book = QOF_BOOK (object);
|
|
|
|
g_assert (qof_instance_get_editlevel(book));
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_OPT_TRADING_ACCOUNTS:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_TRADING_ACCOUNTS);
|
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2015-06-27 18:06:56 -05:00
|
|
|
case PROP_OPT_BOOK_CURRENCY:
|
2015-02-09 14:52:29 -06:00
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
2015-06-27 18:06:56 -05:00
|
|
|
OPTION_NAME_BOOK_CURRENCY);
|
2015-02-09 14:52:29 -06:00
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2015-06-27 18:06:56 -05:00
|
|
|
case PROP_OPT_DEFAULT_GAINS_POLICY:
|
2015-02-28 18:39:34 -06:00
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
2015-06-27 18:06:56 -05:00
|
|
|
OPTION_NAME_DEFAULT_GAINS_POLICY);
|
2015-02-28 18:39:34 -06:00
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2016-06-17 15:48:03 -05:00
|
|
|
case PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_DEFAULT_GAINS_LOSS_ACCT_GUID);
|
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
2014-05-07 08:37:14 -05:00
|
|
|
case PROP_OPT_AUTO_READONLY_DAYS:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_AUTO_READONLY_DAYS);
|
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
|
|
|
case PROP_OPT_NUM_FIELD_SOURCE:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_NUM_FIELD_SOURCE);
|
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
|
|
|
case PROP_OPT_DEFAULT_BUDGET:
|
|
|
|
key = g_strdup_printf ("%s/%s/%s", KVP_OPTION_PATH,
|
|
|
|
OPTION_SECTION_ACCOUNTS,
|
|
|
|
OPTION_NAME_DEFAULT_BUDGET);
|
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
g_free (key);
|
|
|
|
break;
|
|
|
|
case PROP_OPT_FY_END:
|
2014-05-07 10:55:42 -05:00
|
|
|
key = const_cast<char*>("fy_end");
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
break;
|
|
|
|
case PROP_AB_TEMPLATES:
|
2014-05-07 10:55:42 -05:00
|
|
|
key = const_cast<char*>(AB_KEY "/" AB_TEMPLATES);
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (book), key, value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qof_book_class_init (QofBookClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gobject_class->dispose = qof_book_dispose;
|
|
|
|
gobject_class->finalize = qof_book_finalize;
|
|
|
|
gobject_class->get_property = qof_book_get_property;
|
|
|
|
gobject_class->set_property = qof_book_set_property;
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_TRADING_ACCOUNTS,
|
|
|
|
g_param_spec_string("trading-accts",
|
|
|
|
"Use Trading Accounts",
|
|
|
|
"Scheme true ('t') or NULL. If 't', then the book "
|
|
|
|
"uses trading accounts for managing multiple-currency "
|
|
|
|
"transactions.",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2015-02-28 18:39:34 -06:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_BOOK_CURRENCY,
|
|
|
|
g_param_spec_string("book-currency",
|
|
|
|
"Select Book Currency",
|
|
|
|
"The reference currency used to manage multiple-currency "
|
|
|
|
"transactions when 'book-currency' currency accounting method "
|
2015-06-27 18:06:56 -05:00
|
|
|
"selected; requires valid default gains/loss policy.",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_DEFAULT_GAINS_POLICY,
|
|
|
|
g_param_spec_string("default-gains-policy",
|
|
|
|
"Select Default Gains Policy",
|
|
|
|
"The default policy to be used to calculate gains/losses on "
|
|
|
|
"dispositions of currencies/commodities other than "
|
|
|
|
"'book-currency' when 'book-currency' currency accounting "
|
|
|
|
"method selected; requires valid book-currency.",
|
2015-02-28 18:39:34 -06:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2016-06-17 15:48:03 -05:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_DEFAULT_GAINS_ACCOUNT_GUID,
|
|
|
|
g_param_spec_boxed("default-gain-loss-account-guid",
|
|
|
|
"Select Default Gain/Loss Account",
|
|
|
|
"The default account to be used for calculated gains/losses on "
|
|
|
|
"dispositions of currencies/commodities other than "
|
|
|
|
"'book-currency' when 'book-currency' currency accounting "
|
|
|
|
"method selected; requires valid book-currency.",
|
|
|
|
GNC_TYPE_GUID,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2014-05-07 08:37:14 -05:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_NUM_FIELD_SOURCE,
|
|
|
|
g_param_spec_string("split-action-num-field",
|
|
|
|
"Use Split-Action in the Num Field",
|
|
|
|
"Scheme true ('t') or NULL. If 't', then the book "
|
|
|
|
"will put the split action value in the Num field.",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_AUTO_READONLY_DAYS,
|
|
|
|
g_param_spec_double("autoreadonly-days",
|
|
|
|
"Transaction Auto-read-only Days",
|
|
|
|
"Prevent editing of transactions posted more than "
|
|
|
|
"this many days ago.",
|
|
|
|
0,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_DEFAULT_BUDGET,
|
|
|
|
g_param_spec_boxed("default-budget",
|
|
|
|
"Book Default Budget",
|
|
|
|
"The default Budget for this book.",
|
|
|
|
GNC_TYPE_GUID,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_OPT_FY_END,
|
|
|
|
g_param_spec_boxed("fy-end",
|
|
|
|
"Book Fiscal Year End",
|
|
|
|
"A GDate with a bogus year having the last Month and "
|
|
|
|
"Day of the Fiscal year for the book.",
|
|
|
|
G_TYPE_DATE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class,
|
|
|
|
PROP_AB_TEMPLATES,
|
|
|
|
g_param_spec_boxed("ab-templates",
|
|
|
|
"AQBanking Template List",
|
|
|
|
"A GList of AQBanking Templates",
|
|
|
|
GNC_TYPE_VALUE_LIST,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
}
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
QofBook *
|
|
|
|
qof_book_new (void)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
QofBook *book;
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
ENTER (" ");
|
2014-04-25 15:41:11 -05:00
|
|
|
book = static_cast<QofBook*>(g_object_new(QOF_TYPE_BOOK, NULL));
|
2009-09-18 14:40:57 -05:00
|
|
|
qof_object_book_begin (book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
qof_event_gen (&book->inst, QOF_EVENT_CREATE, NULL);
|
|
|
|
LEAVE ("book=%p", book);
|
|
|
|
return book;
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
book_final (gpointer key, gpointer value, gpointer booq)
|
|
|
|
{
|
2014-04-25 15:41:11 -05:00
|
|
|
QofBookFinalCB cb = reinterpret_cast<QofBookFinalCB>(value);
|
|
|
|
QofBook *book = static_cast<QofBook*>(booq);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
gpointer user_data = g_hash_table_lookup (book->data_tables, key);
|
|
|
|
(*cb) (book, key, user_data);
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2007-04-04 22:10:26 -05:00
|
|
|
static void
|
2014-04-26 13:10:56 -05:00
|
|
|
qof_book_dispose_real (G_GNUC_UNUSED GObject *bookp)
|
2007-04-04 22:10:26 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-04-03 17:30:58 -05:00
|
|
|
static void
|
2014-04-26 13:10:56 -05:00
|
|
|
qof_book_finalize_real (G_GNUC_UNUSED GObject *bookp)
|
2007-04-03 17:30:58 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
void
|
2009-09-18 14:40:57 -05:00
|
|
|
qof_book_destroy (QofBook *book)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
GHashTable* cols;
|
2007-04-04 21:44:47 -05:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return;
|
|
|
|
ENTER ("book=%p", book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
book->shutting_down = TRUE;
|
|
|
|
qof_event_force (&book->inst, QOF_EVENT_DESTROY, NULL);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
/* Call the list of finalizers, let them do their thing.
|
|
|
|
* Do this before tearing into the rest of the book.
|
|
|
|
*/
|
|
|
|
g_hash_table_foreach (book->data_table_finalizers, book_final, book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
qof_object_book_end (book);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
g_hash_table_destroy (book->data_table_finalizers);
|
|
|
|
book->data_table_finalizers = NULL;
|
|
|
|
g_hash_table_destroy (book->data_tables);
|
|
|
|
book->data_tables = NULL;
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
/* qof_instance_release (&book->inst); */
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
/* Note: we need to save this hashtable until after we remove ourself
|
|
|
|
* from it, otherwise we'll crash in our dispose() function when we
|
|
|
|
* DO remove ourself from the collection but the collection had already
|
|
|
|
* been destroyed.
|
|
|
|
*/
|
|
|
|
cols = book->hash_of_collections;
|
|
|
|
g_object_unref (book);
|
|
|
|
g_hash_table_destroy (cols);
|
2009-12-11 18:15:50 -06:00
|
|
|
/*book->hash_of_collections = NULL;*/
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
LEAVE ("book=%p", book);
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
2014-05-07 08:37:14 -05:00
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
/* ====================================================================== */
|
|
|
|
|
|
|
|
gboolean
|
2012-01-09 17:10:20 -06:00
|
|
|
qof_book_session_not_saved (const QofBook *book)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return FALSE;
|
2012-01-09 17:10:20 -06:00
|
|
|
return book->session_dirty;
|
2005-11-07 09:45:58 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-09 17:10:20 -06:00
|
|
|
qof_book_mark_session_saved (QofBook *book)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return;
|
|
|
|
|
|
|
|
book->dirty_time = 0;
|
2012-01-09 17:10:20 -06:00
|
|
|
if (book->session_dirty)
|
2009-09-18 14:40:57 -05:00
|
|
|
{
|
2012-03-16 15:27:09 -05:00
|
|
|
/* Set the session clean upfront, because the callback will check. */
|
|
|
|
book->session_dirty = FALSE;
|
2009-09-18 14:40:57 -05:00
|
|
|
if (book->dirty_cb)
|
|
|
|
book->dirty_cb(book, FALSE, book->dirty_data);
|
|
|
|
}
|
2006-05-06 16:09:59 -05:00
|
|
|
}
|
|
|
|
|
2012-01-09 17:10:20 -06:00
|
|
|
void qof_book_mark_session_dirty (QofBook *book)
|
2006-05-06 16:09:59 -05:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return;
|
2012-01-09 17:10:20 -06:00
|
|
|
if (!book->session_dirty)
|
2009-09-18 14:40:57 -05:00
|
|
|
{
|
2012-03-16 15:27:09 -05:00
|
|
|
/* Set the session dirty upfront, because the callback will check. */
|
|
|
|
book->session_dirty = TRUE;
|
2012-12-01 16:44:13 -06:00
|
|
|
book->dirty_time = gnc_time (NULL);
|
2009-09-18 14:40:57 -05:00
|
|
|
if (book->dirty_cb)
|
|
|
|
book->dirty_cb(book, TRUE, book->dirty_data);
|
|
|
|
}
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2013-06-29 00:57:52 -05:00
|
|
|
void
|
|
|
|
qof_book_print_dirty (const QofBook *book)
|
|
|
|
{
|
|
|
|
if (qof_book_session_not_saved(book))
|
2013-10-09 00:28:15 -05:00
|
|
|
PINFO("book is dirty.");
|
2013-06-29 00:57:52 -05:00
|
|
|
qof_book_foreach_collection
|
|
|
|
(book, (QofCollectionForeachCB)qof_collection_print_dirty, NULL);
|
|
|
|
}
|
|
|
|
|
2012-12-01 16:44:13 -06:00
|
|
|
time64
|
2012-01-09 17:10:20 -06:00
|
|
|
qof_book_get_session_dirty_time (const QofBook *book)
|
2006-05-06 16:09:59 -05:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
return book->dirty_time;
|
2006-05-06 16:09:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (book->dirty_cb)
|
2013-10-09 00:28:15 -05:00
|
|
|
PWARN("Already existing callback %p, will be overwritten by %p\n",
|
2009-09-18 14:40:57 -05:00
|
|
|
book->dirty_cb, cb);
|
|
|
|
book->dirty_data = user_data;
|
|
|
|
book->dirty_cb = cb;
|
2006-05-06 16:09:59 -05:00
|
|
|
}
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
/* ====================================================================== */
|
|
|
|
/* getters */
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
QofBackend *
|
2006-08-17 23:48:18 -05:00
|
|
|
qof_book_get_backend (const QofBook *book)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return NULL;
|
|
|
|
return book->backend;
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2006-08-17 23:48:18 -05:00
|
|
|
qof_book_shutting_down (const QofBook *book)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return FALSE;
|
|
|
|
return book->shutting_down;
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ====================================================================== */
|
|
|
|
/* setters */
|
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_set_backend (QofBook *book, QofBackend *be)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book) return;
|
|
|
|
ENTER ("book=%p be=%p", book, be);
|
|
|
|
book->backend = be;
|
|
|
|
LEAVE (" ");
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ====================================================================== */
|
|
|
|
/* Store arbitrary pointers in the QofBook for data storage extensibility */
|
|
|
|
/* XXX if data is NULL, we should remove the key from the hash table!
|
|
|
|
*/
|
2009-09-18 14:40:57 -05:00
|
|
|
void
|
2005-11-07 09:45:58 -06:00
|
|
|
qof_book_set_data (QofBook *book, const char *key, gpointer data)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book || !key) return;
|
|
|
|
g_hash_table_insert (book->data_tables, (gpointer)key, data);
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
void
|
2005-11-07 09:45:58 -06:00
|
|
|
qof_book_set_data_fin (QofBook *book, const char *key, gpointer data, QofBookFinalCB cb)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book || !key) return;
|
|
|
|
g_hash_table_insert (book->data_tables, (gpointer)key, data);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!cb) return;
|
2014-04-25 15:41:11 -05:00
|
|
|
g_hash_table_insert (book->data_table_finalizers, (gpointer)key,
|
|
|
|
reinterpret_cast<void*>(cb));
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
gpointer
|
2006-08-17 23:48:18 -05:00
|
|
|
qof_book_get_data (const QofBook *book, const char *key)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book || !key) return NULL;
|
|
|
|
return g_hash_table_lookup (book->data_tables, (gpointer)key);
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2011-01-14 17:25:27 -06:00
|
|
|
/* ====================================================================== */
|
|
|
|
gboolean
|
|
|
|
qof_book_is_readonly(const QofBook *book)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail( book != NULL, TRUE );
|
|
|
|
return book->read_only;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_mark_readonly(QofBook *book)
|
|
|
|
{
|
|
|
|
g_return_if_fail( book != NULL );
|
|
|
|
book->read_only = TRUE;
|
|
|
|
}
|
2005-11-07 09:45:58 -06:00
|
|
|
/* ====================================================================== */
|
|
|
|
|
|
|
|
QofCollection *
|
2006-08-17 23:48:18 -05:00
|
|
|
qof_book_get_collection (const QofBook *book, QofIdType entity_type)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
QofCollection *col;
|
|
|
|
|
|
|
|
if (!book || !entity_type) return NULL;
|
|
|
|
|
2014-04-25 15:41:11 -05:00
|
|
|
col = static_cast<QofCollection*>(g_hash_table_lookup (book->hash_of_collections, entity_type));
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!col)
|
|
|
|
{
|
|
|
|
col = qof_collection_new (entity_type);
|
|
|
|
g_hash_table_insert(
|
|
|
|
book->hash_of_collections,
|
2012-05-21 12:28:30 -05:00
|
|
|
qof_string_cache_insert((gpointer) entity_type), col);
|
2009-09-18 14:40:57 -05:00
|
|
|
}
|
|
|
|
return col;
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
struct _iterate
|
|
|
|
{
|
|
|
|
QofCollectionForeachCB fn;
|
|
|
|
gpointer data;
|
2005-11-07 09:45:58 -06:00
|
|
|
};
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
static void
|
2014-04-26 13:10:56 -05:00
|
|
|
foreach_cb (G_GNUC_UNUSED gpointer key, gpointer item, gpointer arg)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2014-04-25 15:41:11 -05:00
|
|
|
struct _iterate *iter = static_cast<_iterate*>(arg);
|
|
|
|
QofCollection *col = static_cast<QofCollection*>(item);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
iter->fn (col, iter->data);
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
void
|
|
|
|
qof_book_foreach_collection (const QofBook *book,
|
2005-11-07 09:45:58 -06:00
|
|
|
QofCollectionForeachCB cb, gpointer user_data)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
struct _iterate iter;
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
g_return_if_fail (book);
|
|
|
|
g_return_if_fail (cb);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
iter.fn = cb;
|
|
|
|
iter.data = user_data;
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
g_hash_table_foreach (book->hash_of_collections, foreach_cb, &iter);
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ====================================================================== */
|
|
|
|
|
|
|
|
void qof_book_mark_closed (QofBook *book)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
if (!book)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
book->book_open = 'n';
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
gint64
|
2010-04-19 11:56:40 -05:00
|
|
|
qof_book_get_counter (QofBook *book, const char *counter_name)
|
2005-11-07 09:45:58 -06:00
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
KvpFrame *kvp;
|
|
|
|
KvpValue *value;
|
|
|
|
|
|
|
|
if (!book)
|
|
|
|
{
|
|
|
|
PWARN ("No book!!!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!counter_name || *counter_name == '\0')
|
|
|
|
{
|
|
|
|
PWARN ("Invalid counter name.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-10 15:38:43 -06:00
|
|
|
/* Use the KVP in the book */
|
2014-05-07 08:37:14 -05:00
|
|
|
kvp = qof_instance_get_slots (QOF_INSTANCE (book));
|
2009-09-18 14:40:57 -05:00
|
|
|
|
|
|
|
if (!kvp)
|
|
|
|
{
|
|
|
|
PWARN ("Book has no KVP_Frame");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-06-23 19:09:51 -05:00
|
|
|
value = kvp->get_slot({"counters", counter_name});
|
2009-09-18 14:40:57 -05:00
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
/* found it */
|
2015-06-23 19:09:51 -05:00
|
|
|
return value->get<int64_t>();
|
2009-09-18 14:40:57 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* New counter */
|
2011-01-10 15:38:54 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 15:39:06 -06:00
|
|
|
gchar *
|
|
|
|
qof_book_increment_and_format_counter (QofBook *book, const char *counter_name)
|
2011-01-10 15:38:54 -06:00
|
|
|
{
|
|
|
|
KvpFrame *kvp;
|
|
|
|
KvpValue *value;
|
|
|
|
gint64 counter;
|
2011-01-10 15:39:18 -06:00
|
|
|
gchar* format;
|
2016-03-17 16:37:15 -05:00
|
|
|
gchar* result;
|
2011-01-10 15:38:54 -06:00
|
|
|
|
|
|
|
if (!book)
|
|
|
|
{
|
|
|
|
PWARN ("No book!!!");
|
2011-01-10 15:39:06 -06:00
|
|
|
return NULL;
|
2011-01-10 15:38:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!counter_name || *counter_name == '\0')
|
|
|
|
{
|
|
|
|
PWARN ("Invalid counter name.");
|
2011-01-10 15:39:06 -06:00
|
|
|
return NULL;
|
2009-09-18 14:40:57 -05:00
|
|
|
}
|
|
|
|
|
2011-01-10 15:38:54 -06:00
|
|
|
/* Get the current counter value from the KVP in the book. */
|
|
|
|
counter = qof_book_get_counter(book, counter_name);
|
|
|
|
|
2012-11-03 06:58:35 -05:00
|
|
|
/* Check if an error occurred */
|
2011-01-10 15:38:54 -06:00
|
|
|
if (counter < 0)
|
2011-01-24 08:10:09 -06:00
|
|
|
return NULL;
|
2011-01-10 15:38:54 -06:00
|
|
|
|
|
|
|
/* Increment the counter */
|
2009-09-18 14:40:57 -05:00
|
|
|
counter++;
|
|
|
|
|
2011-01-10 15:38:54 -06:00
|
|
|
/* Get the KVP from the current book */
|
2014-05-07 08:37:14 -05:00
|
|
|
kvp = qof_instance_get_slots (QOF_INSTANCE (book));
|
2011-01-10 15:38:54 -06:00
|
|
|
|
|
|
|
if (!kvp)
|
|
|
|
{
|
2011-01-24 08:10:09 -06:00
|
|
|
PWARN ("Book has no KVP_Frame");
|
|
|
|
return NULL;
|
2011-01-10 15:38:54 -06:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
/* Save off the new counter */
|
2010-04-19 11:56:40 -05:00
|
|
|
qof_book_begin_edit(book);
|
2015-06-23 19:09:51 -05:00
|
|
|
value = new KvpValue(counter);
|
|
|
|
delete kvp->set_path({"counters", counter_name}, value);
|
2012-01-09 17:10:20 -06:00
|
|
|
qof_instance_set_dirty (QOF_INSTANCE (book));
|
2010-04-19 11:56:40 -05:00
|
|
|
qof_book_commit_edit(book);
|
2009-09-18 14:40:57 -05:00
|
|
|
|
2011-01-10 15:39:18 -06:00
|
|
|
format = qof_book_get_counter_format(book, counter_name);
|
|
|
|
|
|
|
|
if (!format)
|
|
|
|
{
|
|
|
|
PWARN("Cannot get format for counter");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-10 15:39:06 -06:00
|
|
|
/* Generate a string version of the counter */
|
2016-03-17 16:37:15 -05:00
|
|
|
result = g_strdup_printf(format, counter);
|
|
|
|
g_free (format);
|
|
|
|
return result;
|
2011-01-10 15:39:18 -06:00
|
|
|
}
|
|
|
|
|
2016-03-19 08:56:12 -05:00
|
|
|
char *
|
2011-01-10 15:39:18 -06:00
|
|
|
qof_book_get_counter_format(const QofBook *book, const char *counter_name)
|
|
|
|
{
|
|
|
|
KvpFrame *kvp;
|
2016-03-19 08:56:12 -05:00
|
|
|
const char *user_format = NULL;
|
2016-03-17 16:37:15 -05:00
|
|
|
gchar *norm_format = NULL;
|
2011-01-10 15:39:18 -06:00
|
|
|
KvpValue *value;
|
2016-03-17 16:37:15 -05:00
|
|
|
gchar *error = NULL;
|
2011-01-10 15:39:18 -06:00
|
|
|
|
|
|
|
if (!book)
|
|
|
|
{
|
|
|
|
PWARN ("No book!!!");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!counter_name || *counter_name == '\0')
|
|
|
|
{
|
|
|
|
PWARN ("Invalid counter name.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the KVP from the current book */
|
2014-05-07 08:37:14 -05:00
|
|
|
kvp = qof_instance_get_slots (QOF_INSTANCE (book));
|
2011-01-10 15:39:18 -06:00
|
|
|
|
|
|
|
if (!kvp)
|
|
|
|
{
|
|
|
|
PWARN ("Book has no KVP_Frame");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the format string */
|
2015-06-23 19:09:51 -05:00
|
|
|
value = kvp->get_slot({"counter_formats", counter_name});
|
2011-01-10 15:39:18 -06:00
|
|
|
if (value)
|
|
|
|
{
|
2016-03-19 08:56:12 -05:00
|
|
|
user_format = value->get<const char*>();
|
2016-03-17 16:37:15 -05:00
|
|
|
norm_format = qof_book_normalize_counter_format(user_format, &error);
|
|
|
|
if (!norm_format)
|
2011-01-10 15:39:29 -06:00
|
|
|
{
|
2016-03-17 16:37:15 -05:00
|
|
|
PWARN("Invalid counter format string. Format string: '%s' Counter: '%s' Error: '%s')", user_format, counter_name, error);
|
2011-01-10 15:39:29 -06:00
|
|
|
/* Invalid format string */
|
2016-03-17 16:37:15 -05:00
|
|
|
user_format = NULL;
|
2011-01-10 15:39:29 -06:00
|
|
|
g_free(error);
|
|
|
|
}
|
2011-01-10 15:39:18 -06:00
|
|
|
}
|
2011-01-10 15:39:29 -06:00
|
|
|
|
|
|
|
/* If no (valid) format string was found, use the default format
|
|
|
|
* string */
|
2016-03-17 16:37:15 -05:00
|
|
|
if (!norm_format)
|
2011-01-10 15:39:18 -06:00
|
|
|
{
|
|
|
|
/* Use the default format */
|
2016-03-17 17:06:52 -05:00
|
|
|
norm_format = g_strdup ("%.6" PRIi64);
|
2011-01-10 15:39:18 -06:00
|
|
|
}
|
2016-03-17 16:37:15 -05:00
|
|
|
return norm_format;
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
2011-01-10 15:39:29 -06:00
|
|
|
gchar *
|
2016-03-17 16:37:15 -05:00
|
|
|
qof_book_normalize_counter_format(const gchar *p, gchar **err_msg)
|
|
|
|
{
|
|
|
|
const gchar *valid_formats [] = {
|
|
|
|
G_GINT64_FORMAT,
|
|
|
|
"lli",
|
|
|
|
"I64i",
|
2016-03-17 17:06:52 -05:00
|
|
|
PRIi64,
|
2016-03-17 16:37:15 -05:00
|
|
|
"li",
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
int i = 0;
|
|
|
|
gchar *normalized_spec = NULL;
|
|
|
|
|
|
|
|
while (valid_formats[i])
|
|
|
|
{
|
|
|
|
|
|
|
|
if (err_msg && *err_msg)
|
|
|
|
{
|
|
|
|
g_free (*err_msg);
|
|
|
|
*err_msg = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
normalized_spec = qof_book_normalize_counter_format_internal(p, valid_formats[i], err_msg);
|
|
|
|
if (normalized_spec)
|
|
|
|
return normalized_spec; /* Found a valid format specifier, return */
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2011-03-08 05:15:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
2016-03-17 16:37:15 -05:00
|
|
|
qof_book_normalize_counter_format_internal(const gchar *p,
|
|
|
|
const gchar *gint64_format, gchar **err_msg)
|
2011-03-08 05:15:07 -06:00
|
|
|
{
|
2016-03-17 16:37:15 -05:00
|
|
|
const gchar *conv_start, *base, *tmp = NULL;
|
|
|
|
gchar *normalized_str = NULL, *aux_str = NULL;
|
2011-01-10 15:39:29 -06:00
|
|
|
|
|
|
|
/* Validate a counter format. This is a very simple "parser" that
|
|
|
|
* simply checks for a single gint64 conversion specification,
|
|
|
|
* allowing all modifiers and flags that printf(3) specifies (except
|
|
|
|
* for the * width and precision, which need an extra argument). */
|
2016-03-17 16:37:15 -05:00
|
|
|
base = p;
|
2011-01-10 15:39:29 -06:00
|
|
|
|
|
|
|
/* Skip a prefix of any character except % */
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
/* Skip two adjacent percent marks, which are literal percent
|
|
|
|
* marks */
|
|
|
|
if (p[0] == '%' && p[1] == '%')
|
2011-01-24 08:10:09 -06:00
|
|
|
{
|
2011-01-10 15:39:29 -06:00
|
|
|
p += 2;
|
2011-01-24 08:10:09 -06:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-10 15:39:29 -06:00
|
|
|
/* Break on a single percent mark, which is the start of the
|
|
|
|
* conversion specification */
|
|
|
|
if (*p == '%')
|
|
|
|
break;
|
|
|
|
/* Skip all other characters */
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*p)
|
2016-03-17 16:37:15 -05:00
|
|
|
{
|
|
|
|
if (err_msg)
|
|
|
|
*err_msg = g_strdup("Format string ended without any conversion specification");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-10 15:39:29 -06:00
|
|
|
|
|
|
|
/* Store the start of the conversion for error messages */
|
|
|
|
conv_start = p;
|
|
|
|
|
|
|
|
/* Skip the % */
|
|
|
|
p++;
|
|
|
|
|
2011-03-08 05:15:07 -06:00
|
|
|
/* See whether we have already reached the correct format
|
|
|
|
* specification (e.g. "li" on Unix, "I64i" on Windows). */
|
|
|
|
tmp = strstr(p, gint64_format);
|
|
|
|
|
2016-03-17 16:37:15 -05:00
|
|
|
if (!tmp)
|
|
|
|
{
|
|
|
|
if (err_msg)
|
|
|
|
*err_msg = g_strdup_printf("Format string doesn't contain requested format specifier: %s", gint64_format);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-10 15:39:29 -06:00
|
|
|
/* Skip any number of flag characters */
|
2011-03-08 05:15:07 -06:00
|
|
|
while (*p && (tmp != p) && strchr("#0- +'I", *p))
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
tmp = strstr(p, gint64_format);
|
|
|
|
}
|
2011-01-10 15:39:29 -06:00
|
|
|
|
2016-03-17 16:37:15 -05:00
|
|
|
/* Skip any number of field width digits,
|
|
|
|
* and precision specifier digits (including the leading dot) */
|
|
|
|
while (*p && (tmp != p) && strchr("0123456789.", *p))
|
2011-03-08 05:15:07 -06:00
|
|
|
{
|
|
|
|
p++;
|
|
|
|
tmp = strstr(p, gint64_format);
|
|
|
|
}
|
2011-01-10 15:39:29 -06:00
|
|
|
|
2016-03-17 16:37:15 -05:00
|
|
|
if (!*p)
|
2011-01-10 15:39:29 -06:00
|
|
|
{
|
2016-03-17 16:37:15 -05:00
|
|
|
if (err_msg)
|
|
|
|
*err_msg = g_strdup_printf("Format string ended during the conversion specification. Conversion seen so far: %s", conv_start);
|
|
|
|
return NULL;
|
2011-01-10 15:39:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* See if the format string starts with the correct format
|
|
|
|
* specification. */
|
2011-03-08 05:15:07 -06:00
|
|
|
tmp = strstr(p, gint64_format);
|
2011-01-10 15:39:29 -06:00
|
|
|
if (tmp == NULL)
|
|
|
|
{
|
2016-03-17 16:37:15 -05:00
|
|
|
if (err_msg)
|
|
|
|
*err_msg = g_strdup_printf("Invalid length modifier and/or conversion specifier ('%.4s'), it should be: %s", p, gint64_format);
|
|
|
|
return NULL;
|
2011-01-24 08:10:09 -06:00
|
|
|
}
|
|
|
|
else if (tmp != p)
|
|
|
|
{
|
2016-03-17 16:37:15 -05:00
|
|
|
if (err_msg)
|
|
|
|
*err_msg = g_strdup_printf("Garbage before length modifier and/or conversion specifier: '%*s'", (int)(tmp - p), p);
|
|
|
|
return NULL;
|
2011-01-10 15:39:29 -06:00
|
|
|
}
|
|
|
|
|
2016-03-17 16:37:15 -05:00
|
|
|
/* Copy the string we have so far and add normalized format specifier for long int */
|
|
|
|
aux_str = g_strndup (base, p - base);
|
2016-03-17 17:06:52 -05:00
|
|
|
normalized_str = g_strconcat (aux_str, PRIi64, NULL);
|
2016-03-17 16:37:15 -05:00
|
|
|
g_free (aux_str);
|
|
|
|
|
2011-01-10 15:39:29 -06:00
|
|
|
/* Skip length modifier / conversion specifier */
|
2011-03-08 05:15:07 -06:00
|
|
|
p += strlen(gint64_format);
|
2016-03-17 16:37:15 -05:00
|
|
|
tmp = p;
|
2011-01-10 15:39:29 -06:00
|
|
|
|
|
|
|
/* Skip a suffix of any character except % */
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
/* Skip two adjacent percent marks, which are literal percent
|
|
|
|
* marks */
|
|
|
|
if (p[0] == '%' && p[1] == '%')
|
2011-01-24 08:10:09 -06:00
|
|
|
{
|
2011-01-10 15:39:29 -06:00
|
|
|
p += 2;
|
2011-01-24 08:10:09 -06:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-10 15:39:29 -06:00
|
|
|
/* Break on a single percent mark, which is the start of the
|
|
|
|
* conversion specification */
|
|
|
|
if (*p == '%')
|
2016-03-17 16:37:15 -05:00
|
|
|
{
|
|
|
|
if (err_msg)
|
|
|
|
*err_msg = g_strdup_printf("Format string contains unescaped %% signs (or multiple conversion specifications) at '%s'", p);
|
|
|
|
g_free (normalized_str);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-10 15:39:29 -06:00
|
|
|
/* Skip all other characters */
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:37:15 -05:00
|
|
|
/* Add the suffix to our normalized string */
|
|
|
|
aux_str = normalized_str;
|
|
|
|
normalized_str = g_strconcat (aux_str, tmp, NULL);
|
|
|
|
g_free (aux_str);
|
|
|
|
|
2011-01-10 15:39:29 -06:00
|
|
|
/* If we end up here, the string was valid, so return no error
|
|
|
|
* message */
|
2016-03-17 16:37:15 -05:00
|
|
|
return normalized_str;
|
2011-01-10 15:39:29 -06:00
|
|
|
}
|
|
|
|
|
2015-06-27 18:06:56 -05:00
|
|
|
/** Returns pointer to book-currency name for book, if one exists in the
|
|
|
|
* KVP, or NULL; does not validate contents nor determine if there is a valid
|
|
|
|
* default gain/loss policy, both of which are required, for the
|
|
|
|
* 'book-currency' currency accounting method to apply. Use instead
|
2016-06-17 15:48:03 -05:00
|
|
|
* 'gnc_book_get_book_currency_name' which does these validations. */
|
2015-06-27 18:06:56 -05:00
|
|
|
const gchar *
|
2016-06-17 15:48:03 -05:00
|
|
|
qof_book_get_book_currency_name (QofBook *book)
|
2015-02-09 14:52:29 -06:00
|
|
|
{
|
2016-06-17 15:48:03 -05:00
|
|
|
const gchar *opt = NULL;
|
|
|
|
qof_instance_get (QOF_INSTANCE (book),
|
|
|
|
"book-currency", &opt,
|
|
|
|
NULL);
|
|
|
|
return opt;
|
2015-02-09 14:52:29 -06:00
|
|
|
}
|
|
|
|
|
2015-06-27 18:06:56 -05:00
|
|
|
/** Returns pointer to default gain/loss policy for book, if one exists in the
|
|
|
|
* KVP, or NULL; does not validate contents nor determine if there is a valid
|
|
|
|
* book-currency, both of which are required, for the 'book-currency'
|
|
|
|
* currency accounting method to apply. Use instead
|
|
|
|
* 'gnc_book_get_default_gains_policy' which does these validations. */
|
2015-02-28 18:39:34 -06:00
|
|
|
const gchar *
|
2015-06-27 18:06:56 -05:00
|
|
|
qof_book_get_default_gains_policy (QofBook *book)
|
2015-02-28 18:39:34 -06:00
|
|
|
{
|
2016-06-17 15:48:03 -05:00
|
|
|
const gchar *opt = NULL;
|
|
|
|
qof_instance_get (QOF_INSTANCE (book),
|
|
|
|
"default-gains-policy", &opt,
|
|
|
|
NULL);
|
|
|
|
return opt;
|
|
|
|
}
|
2015-02-28 18:39:34 -06:00
|
|
|
|
2016-06-17 15:48:03 -05:00
|
|
|
/** Returns pointer to default gain/loss account GUID for book, if one exists in
|
|
|
|
* the KVP, or NULL; does not validate contents nor determine if there is a
|
|
|
|
* valid book-currency, both of which are required, for the 'book-currency'
|
|
|
|
* currency accounting method to apply. Use instead
|
|
|
|
* 'gnc_book_get_default_gain_loss_acct' which does these validations. */
|
|
|
|
const GncGUID *
|
|
|
|
qof_book_get_default_gain_loss_acct_guid (QofBook *book)
|
|
|
|
{
|
|
|
|
GncGUID *guid = NULL;
|
|
|
|
qof_instance_get (QOF_INSTANCE (book),
|
|
|
|
"default-gain-loss-account-guid", &guid,
|
|
|
|
NULL);
|
|
|
|
return guid;
|
2015-02-28 18:39:34 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
Bug #537476: Implement currency trading accounts optionally, to be enabled per-book.
Patch by Mike Alexander:
This patch implements trading accounts somewhat as described in Peter
Selinger's document at
<http://www.mathstat.dal.ca/~selinger/accounting/gnucash.html>. Although he
describes it as a multiple currency problem, it really applies to any
transactions involving multiple commodities (for example buying or selling a
stock) Hence I've called the trading accounts "commodity exchange accounts"
which seems more descriptive.
In summary these patches add an option to use commodity exchange accounts and
if it is on a transaction must be balanced both in value (in the transaction
currency) and in each commodity or currency used in any split in the
transaction. If a transaction only contains splits in the transaction currency
then this is the same rule as Gnucash has always enforced.
In this patch, the option to use trading accounts has been moved from
Edit->Preferences to File->Properties and is now associated with the active
book instead of being a global option. If you have set the global value on in
a previous version you will need to set it on again in each file for which you
want trading accounts, the previous global setting will be ignored.
A more detailed list of changes follows:
1. Added a "Use commodity exchange accounts" per-book option.
2. Added gnc_monetary and MonetaryList data types.
3. Renamed xaccTransGetImbalance to xaccTransGetImbalanceValue and added a new
xaccTransGetImbalance that returns a MonetaryList. Also added
xaccTransIsBalanced to see if the transaction is balanced without returning a
GList that needs to be freed. It calls both xaccTransGetImbalance and
xaccTransGetImbalanceValue since a transaction may be unbalanced with regard to
either without being unbalanced with regard to the other.
4. Changed gnc_split_register_get_debcred_bg_color to use xaccTransIsBalanced.
5. Changed gnc_split_register_balance_trans to not offer to adjust an existing
split if there imbalances in multiple currencies. Because of bugs in the
register code this is rarely called.
6. Changed importers to use xaccTransGetImbalanceValue to check for imbalance,
assuming that they won't create multiple currency trasactions.
7. Changed xaccTransScrubImbalance to create a balancing split for each
imbalanced commodity in the transaction. Also balances the transaction value.
The commodity balancing splits go into accounts in the hierarchy
Trading:NAMESPACE:COMMODITY. The value balancing splits go into
Imbalance-CURRENCY as before.
8. Changed xaccSplitConvertAmount to use xaccTransIsBalanced instead of
xaccTransGetImbalance.
9. Changed gnc_split_register_get_debcred_entry to sometimes use the split
amount instead of value if using currency accounts.
If the register is a stock register (i.e., shows shares and prices), it uses
the value if the split is in the register commodity (i.e. is for the stock) and
the amount otherwise. It shows the currency symbol unless the commodity is the
default currency.
If the register is not a stock register it always uses the amount and shows the
currency symbol if the split is not in the register commodity.
Also changed it to not return a value for a null split unless the transaction
is unbalanced in exactly one currency. This is what goes in a blank split as
the proposed value.
10. Changed refresh_model_row to use xaccTransGetImbalanceValue to get the
imbalance, assuming that importers don't create transactions in multiple
currencies. Also same change in gnc_import_process_trans_item,
downloaded_transaction_append, and gnc_import_TransInfo_is_balanced.
11. Changed the TRANS_IMBALANCE accessor method in xaccTransRegister to use
xaccTransGetImbalanceValue. As far as I can tell this is only used by the
"pd-balance" query type in gnc_scm2query_term_query_v1() defined in
engine-helpers.c. This query type only tests the result for zero/non-zero.
12. Changed xaccTransGetAccountConvRate to accept any split into the correct
commodity instead of insisting on one into the provided account. Then can use
it in xaccTransScrubImbalance to set the value of the imbalance split from its
amount, however later changed xaccTransScrubImbalance to not use it. Instead
it sets the value for the new split correctly to keep the value of the whole
transaction balanced.
13. Changed the balance sheet report to include a new option to not compute
unrealized gains and losses.
14. Related to 9 above, changed gnc_split_register_auto_calc to not do anything
if given a stock register where the value cell doesn't contain the value.
15. Also related to 9, changed gnc_split_register_save_amount_values to set the
amount and value fields in the split correctly when using trading accounts.
16. Changed the new account and edit account dialogs to allow any commodity or
currency for an income account if using trading accounts. It would be better
to add a new account type for trading accounts, but that's a big deal and I'll
leave that for later after we see whether this set of changes is going to be
accepted or rejected.
17. Change gnc_xfer_dialog_run_exchange_dialog to understand that the new value
is really the split's amount if using trading accounts.
18. Changed xaccSplitGetOtherSplit to ignore trading splits if using commodity
exchange accounts.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18429 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-20 14:11:03 -06:00
|
|
|
/* Determine whether this book uses trading accounts */
|
2010-01-31 14:03:23 -06:00
|
|
|
gboolean
|
|
|
|
qof_book_use_trading_accounts (const QofBook *book)
|
Bug #537476: Implement currency trading accounts optionally, to be enabled per-book.
Patch by Mike Alexander:
This patch implements trading accounts somewhat as described in Peter
Selinger's document at
<http://www.mathstat.dal.ca/~selinger/accounting/gnucash.html>. Although he
describes it as a multiple currency problem, it really applies to any
transactions involving multiple commodities (for example buying or selling a
stock) Hence I've called the trading accounts "commodity exchange accounts"
which seems more descriptive.
In summary these patches add an option to use commodity exchange accounts and
if it is on a transaction must be balanced both in value (in the transaction
currency) and in each commodity or currency used in any split in the
transaction. If a transaction only contains splits in the transaction currency
then this is the same rule as Gnucash has always enforced.
In this patch, the option to use trading accounts has been moved from
Edit->Preferences to File->Properties and is now associated with the active
book instead of being a global option. If you have set the global value on in
a previous version you will need to set it on again in each file for which you
want trading accounts, the previous global setting will be ignored.
A more detailed list of changes follows:
1. Added a "Use commodity exchange accounts" per-book option.
2. Added gnc_monetary and MonetaryList data types.
3. Renamed xaccTransGetImbalance to xaccTransGetImbalanceValue and added a new
xaccTransGetImbalance that returns a MonetaryList. Also added
xaccTransIsBalanced to see if the transaction is balanced without returning a
GList that needs to be freed. It calls both xaccTransGetImbalance and
xaccTransGetImbalanceValue since a transaction may be unbalanced with regard to
either without being unbalanced with regard to the other.
4. Changed gnc_split_register_get_debcred_bg_color to use xaccTransIsBalanced.
5. Changed gnc_split_register_balance_trans to not offer to adjust an existing
split if there imbalances in multiple currencies. Because of bugs in the
register code this is rarely called.
6. Changed importers to use xaccTransGetImbalanceValue to check for imbalance,
assuming that they won't create multiple currency trasactions.
7. Changed xaccTransScrubImbalance to create a balancing split for each
imbalanced commodity in the transaction. Also balances the transaction value.
The commodity balancing splits go into accounts in the hierarchy
Trading:NAMESPACE:COMMODITY. The value balancing splits go into
Imbalance-CURRENCY as before.
8. Changed xaccSplitConvertAmount to use xaccTransIsBalanced instead of
xaccTransGetImbalance.
9. Changed gnc_split_register_get_debcred_entry to sometimes use the split
amount instead of value if using currency accounts.
If the register is a stock register (i.e., shows shares and prices), it uses
the value if the split is in the register commodity (i.e. is for the stock) and
the amount otherwise. It shows the currency symbol unless the commodity is the
default currency.
If the register is not a stock register it always uses the amount and shows the
currency symbol if the split is not in the register commodity.
Also changed it to not return a value for a null split unless the transaction
is unbalanced in exactly one currency. This is what goes in a blank split as
the proposed value.
10. Changed refresh_model_row to use xaccTransGetImbalanceValue to get the
imbalance, assuming that importers don't create transactions in multiple
currencies. Also same change in gnc_import_process_trans_item,
downloaded_transaction_append, and gnc_import_TransInfo_is_balanced.
11. Changed the TRANS_IMBALANCE accessor method in xaccTransRegister to use
xaccTransGetImbalanceValue. As far as I can tell this is only used by the
"pd-balance" query type in gnc_scm2query_term_query_v1() defined in
engine-helpers.c. This query type only tests the result for zero/non-zero.
12. Changed xaccTransGetAccountConvRate to accept any split into the correct
commodity instead of insisting on one into the provided account. Then can use
it in xaccTransScrubImbalance to set the value of the imbalance split from its
amount, however later changed xaccTransScrubImbalance to not use it. Instead
it sets the value for the new split correctly to keep the value of the whole
transaction balanced.
13. Changed the balance sheet report to include a new option to not compute
unrealized gains and losses.
14. Related to 9 above, changed gnc_split_register_auto_calc to not do anything
if given a stock register where the value cell doesn't contain the value.
15. Also related to 9, changed gnc_split_register_save_amount_values to set the
amount and value fields in the split correctly when using trading accounts.
16. Changed the new account and edit account dialogs to allow any commodity or
currency for an income account if using trading accounts. It would be better
to add a new account type for trading accounts, but that's a big deal and I'll
leave that for later after we see whether this set of changes is going to be
accepted or rejected.
17. Change gnc_xfer_dialog_run_exchange_dialog to understand that the new value
is really the split's amount if using trading accounts.
18. Changed xaccSplitGetOtherSplit to ignore trading splits if using commodity
exchange accounts.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18429 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-20 14:11:03 -06:00
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
const char *opt = NULL;
|
|
|
|
qof_instance_get (QOF_INSTANCE (book),
|
|
|
|
"trading-accts", &opt,
|
|
|
|
NULL);
|
Bug #537476: Implement currency trading accounts optionally, to be enabled per-book.
Patch by Mike Alexander:
This patch implements trading accounts somewhat as described in Peter
Selinger's document at
<http://www.mathstat.dal.ca/~selinger/accounting/gnucash.html>. Although he
describes it as a multiple currency problem, it really applies to any
transactions involving multiple commodities (for example buying or selling a
stock) Hence I've called the trading accounts "commodity exchange accounts"
which seems more descriptive.
In summary these patches add an option to use commodity exchange accounts and
if it is on a transaction must be balanced both in value (in the transaction
currency) and in each commodity or currency used in any split in the
transaction. If a transaction only contains splits in the transaction currency
then this is the same rule as Gnucash has always enforced.
In this patch, the option to use trading accounts has been moved from
Edit->Preferences to File->Properties and is now associated with the active
book instead of being a global option. If you have set the global value on in
a previous version you will need to set it on again in each file for which you
want trading accounts, the previous global setting will be ignored.
A more detailed list of changes follows:
1. Added a "Use commodity exchange accounts" per-book option.
2. Added gnc_monetary and MonetaryList data types.
3. Renamed xaccTransGetImbalance to xaccTransGetImbalanceValue and added a new
xaccTransGetImbalance that returns a MonetaryList. Also added
xaccTransIsBalanced to see if the transaction is balanced without returning a
GList that needs to be freed. It calls both xaccTransGetImbalance and
xaccTransGetImbalanceValue since a transaction may be unbalanced with regard to
either without being unbalanced with regard to the other.
4. Changed gnc_split_register_get_debcred_bg_color to use xaccTransIsBalanced.
5. Changed gnc_split_register_balance_trans to not offer to adjust an existing
split if there imbalances in multiple currencies. Because of bugs in the
register code this is rarely called.
6. Changed importers to use xaccTransGetImbalanceValue to check for imbalance,
assuming that they won't create multiple currency trasactions.
7. Changed xaccTransScrubImbalance to create a balancing split for each
imbalanced commodity in the transaction. Also balances the transaction value.
The commodity balancing splits go into accounts in the hierarchy
Trading:NAMESPACE:COMMODITY. The value balancing splits go into
Imbalance-CURRENCY as before.
8. Changed xaccSplitConvertAmount to use xaccTransIsBalanced instead of
xaccTransGetImbalance.
9. Changed gnc_split_register_get_debcred_entry to sometimes use the split
amount instead of value if using currency accounts.
If the register is a stock register (i.e., shows shares and prices), it uses
the value if the split is in the register commodity (i.e. is for the stock) and
the amount otherwise. It shows the currency symbol unless the commodity is the
default currency.
If the register is not a stock register it always uses the amount and shows the
currency symbol if the split is not in the register commodity.
Also changed it to not return a value for a null split unless the transaction
is unbalanced in exactly one currency. This is what goes in a blank split as
the proposed value.
10. Changed refresh_model_row to use xaccTransGetImbalanceValue to get the
imbalance, assuming that importers don't create transactions in multiple
currencies. Also same change in gnc_import_process_trans_item,
downloaded_transaction_append, and gnc_import_TransInfo_is_balanced.
11. Changed the TRANS_IMBALANCE accessor method in xaccTransRegister to use
xaccTransGetImbalanceValue. As far as I can tell this is only used by the
"pd-balance" query type in gnc_scm2query_term_query_v1() defined in
engine-helpers.c. This query type only tests the result for zero/non-zero.
12. Changed xaccTransGetAccountConvRate to accept any split into the correct
commodity instead of insisting on one into the provided account. Then can use
it in xaccTransScrubImbalance to set the value of the imbalance split from its
amount, however later changed xaccTransScrubImbalance to not use it. Instead
it sets the value for the new split correctly to keep the value of the whole
transaction balanced.
13. Changed the balance sheet report to include a new option to not compute
unrealized gains and losses.
14. Related to 9 above, changed gnc_split_register_auto_calc to not do anything
if given a stock register where the value cell doesn't contain the value.
15. Also related to 9, changed gnc_split_register_save_amount_values to set the
amount and value fields in the split correctly when using trading accounts.
16. Changed the new account and edit account dialogs to allow any commodity or
currency for an income account if using trading accounts. It would be better
to add a new account type for trading accounts, but that's a big deal and I'll
leave that for later after we see whether this set of changes is going to be
accepted or rejected.
17. Change gnc_xfer_dialog_run_exchange_dialog to understand that the new value
is really the split's amount if using trading accounts.
18. Changed xaccSplitGetOtherSplit to ignore trading splits if using commodity
exchange accounts.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18429 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-20 14:11:03 -06:00
|
|
|
if (opt && opt[0] == 't' && opt[1] == 0)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
|
|
|
/* Returns TRUE if this book uses split action field as the 'Num' field, FALSE
|
|
|
|
* if it uses transaction number field */
|
|
|
|
gboolean
|
|
|
|
qof_book_use_split_action_for_num_field (const QofBook *book)
|
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
const char *opt = NULL;
|
|
|
|
qof_instance_get (QOF_INSTANCE (book),
|
|
|
|
"split-action-num-field", &opt,
|
|
|
|
NULL);
|
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
|
|
|
|
|
|
|
if (opt && opt[0] == 't' && opt[1] == 0)
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-24 17:34:59 -05:00
|
|
|
gboolean qof_book_uses_autoreadonly (const QofBook *book)
|
2012-03-21 17:18:29 -05:00
|
|
|
{
|
|
|
|
g_assert(book);
|
2012-03-24 17:34:59 -05:00
|
|
|
return (qof_book_get_num_days_autoreadonly(book) != 0);
|
2012-03-21 17:18:29 -05:00
|
|
|
}
|
|
|
|
|
2012-03-24 17:34:59 -05:00
|
|
|
gint qof_book_get_num_days_autoreadonly (const QofBook *book)
|
2012-03-21 17:18:29 -05:00
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
g_assert(book);
|
2015-06-23 19:09:51 -05:00
|
|
|
double tmp;
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_get (QOF_INSTANCE (book),
|
|
|
|
"autoreadonly-days", &tmp,
|
|
|
|
NULL);
|
2012-03-21 17:18:29 -05:00
|
|
|
return (gint) tmp;
|
|
|
|
}
|
|
|
|
|
2012-03-24 17:34:59 -05:00
|
|
|
GDate* qof_book_get_autoreadonly_gdate (const QofBook *book)
|
2012-03-21 17:18:29 -05:00
|
|
|
{
|
2012-03-24 17:34:59 -05:00
|
|
|
gint num_days;
|
|
|
|
GDate* result = NULL;
|
|
|
|
|
2012-03-21 17:18:29 -05:00
|
|
|
g_assert(book);
|
2012-03-24 17:34:59 -05:00
|
|
|
num_days = qof_book_get_num_days_autoreadonly(book);
|
|
|
|
if (num_days > 0)
|
|
|
|
{
|
|
|
|
result = gnc_g_date_new_today();
|
|
|
|
g_date_subtract_days(result, num_days);
|
|
|
|
}
|
2012-03-21 17:18:29 -05:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-31 14:03:23 -06:00
|
|
|
const char*
|
|
|
|
qof_book_get_string_option(const QofBook* book, const char* opt_name)
|
|
|
|
{
|
2015-06-23 19:09:51 -05:00
|
|
|
auto slot = qof_instance_get_slots(QOF_INSTANCE (book))->get_slot(opt_name);
|
|
|
|
if (slot == nullptr)
|
|
|
|
return nullptr;
|
|
|
|
return slot->get<const char*>();
|
2010-01-31 14:03:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val)
|
|
|
|
{
|
|
|
|
qof_book_begin_edit(book);
|
2015-06-23 19:09:51 -05:00
|
|
|
auto frame = qof_instance_get_slots(QOF_INSTANCE(book));
|
2016-03-30 08:09:57 -05:00
|
|
|
if (opt_val && (*opt_val != '\0'))
|
|
|
|
delete frame->set(opt_name, new KvpValue(g_strdup(opt_val)));
|
|
|
|
else
|
|
|
|
delete frame->set(opt_name, nullptr);
|
2012-01-09 17:10:20 -06:00
|
|
|
qof_instance_set_dirty (QOF_INSTANCE (book));
|
2010-01-31 14:03:23 -06:00
|
|
|
qof_book_commit_edit(book);
|
|
|
|
}
|
|
|
|
|
2010-01-30 16:59:37 -06:00
|
|
|
void
|
|
|
|
qof_book_begin_edit (QofBook *book)
|
|
|
|
{
|
2010-02-17 23:31:54 -06:00
|
|
|
qof_begin_edit(&book->inst);
|
2010-01-30 16:59:37 -06:00
|
|
|
}
|
|
|
|
|
2014-04-26 13:10:56 -05:00
|
|
|
static void commit_err (G_GNUC_UNUSED QofInstance *inst, QofBackendError errcode)
|
2010-01-30 16:59:37 -06:00
|
|
|
{
|
2010-02-17 23:31:54 -06:00
|
|
|
PERR ("Failed to commit: %d", errcode);
|
2010-01-30 16:59:37 -06:00
|
|
|
// gnc_engine_signal_commit_error( errcode );
|
|
|
|
}
|
|
|
|
|
2015-07-22 03:49:39 -05:00
|
|
|
#define GNC_FEATURES "features"
|
2014-05-07 08:37:14 -05:00
|
|
|
static void
|
2017-10-05 11:48:37 -05:00
|
|
|
add_feature_to_hash (const gchar *key, KvpValue *value, GHashTable * user_data)
|
2014-05-07 08:37:14 -05:00
|
|
|
{
|
2015-06-23 19:09:51 -05:00
|
|
|
gchar *descr = g_strdup(value->get<const char*>());
|
2014-05-07 08:37:14 -05:00
|
|
|
g_hash_table_insert (*(GHashTable**)user_data, (gchar*)key, descr);
|
|
|
|
}
|
|
|
|
|
|
|
|
GHashTable *
|
|
|
|
qof_book_get_features (QofBook *book)
|
|
|
|
{
|
|
|
|
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
|
2015-06-18 15:02:00 -05:00
|
|
|
GHashTable *features = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
NULL, g_free);
|
2014-05-07 08:37:14 -05:00
|
|
|
|
2015-07-05 18:14:33 -05:00
|
|
|
auto slot = frame->get_slot(GNC_FEATURES);
|
|
|
|
if (slot != nullptr)
|
|
|
|
{
|
2017-10-05 11:48:37 -05:00
|
|
|
frame = slot->get<KvpFrame*>();
|
|
|
|
frame->for_each_slot_temp(&add_feature_to_hash, features);
|
2015-07-05 18:14:33 -05:00
|
|
|
}
|
2014-05-07 08:37:14 -05:00
|
|
|
return features;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr)
|
|
|
|
{
|
|
|
|
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
|
2017-08-20 14:24:02 -05:00
|
|
|
KvpValue* feature = nullptr;
|
|
|
|
auto feature_slot = frame->get_slot(GNC_FEATURES);
|
|
|
|
if (feature_slot)
|
|
|
|
{
|
|
|
|
auto feature_frame = feature_slot->get<KvpFrame*>();
|
|
|
|
feature = feature_frame->get_slot(key);
|
|
|
|
}
|
|
|
|
if (feature == nullptr || g_strcmp0 (feature->get<const char*>(), descr))
|
|
|
|
{
|
|
|
|
qof_book_begin_edit (book);
|
|
|
|
delete frame->set_path({GNC_FEATURES, key}, new KvpValue(descr));
|
|
|
|
qof_instance_set_dirty (QOF_INSTANCE (book));
|
|
|
|
qof_book_commit_edit (book);
|
|
|
|
}
|
2014-05-07 08:37:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_load_options (QofBook *book, GNCOptionLoad load_cb, GNCOptionDB *odb)
|
|
|
|
{
|
2015-06-12 17:19:45 -05:00
|
|
|
load_cb (odb, book);
|
2014-05-07 08:37:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_save_options (QofBook *book, GNCOptionSave save_cb,
|
|
|
|
GNCOptionDB* odb, gboolean clear)
|
|
|
|
{
|
2015-06-12 17:19:45 -05:00
|
|
|
/* Wrap this in begin/commit so that it commits only once instead of doing
|
|
|
|
* so for every option. Qof_book_set_option will take care of dirtying the
|
|
|
|
* book.
|
|
|
|
*/
|
|
|
|
qof_book_begin_edit (book);
|
|
|
|
save_cb (odb, book, clear);
|
|
|
|
qof_book_commit_edit (book);
|
2014-05-07 08:37:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void noop (QofInstance *inst) {}
|
2010-01-30 16:59:37 -06:00
|
|
|
|
|
|
|
void
|
|
|
|
qof_book_commit_edit(QofBook *book)
|
|
|
|
{
|
2010-02-17 23:31:54 -06:00
|
|
|
if (!qof_commit_edit (QOF_INSTANCE(book))) return;
|
|
|
|
qof_commit_edit_part2 (&book->inst, commit_err, noop, noop/*lot_free*/);
|
2010-01-30 16:59:37 -06:00
|
|
|
}
|
|
|
|
|
2015-06-12 17:19:45 -05:00
|
|
|
void
|
|
|
|
qof_book_set_option (QofBook *book, KvpValue *value, GSList *path)
|
|
|
|
{
|
|
|
|
KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE (book));
|
2015-06-23 19:09:51 -05:00
|
|
|
Path path_v {KVP_OPTION_PATH};
|
|
|
|
for (auto item = path; item != nullptr; item = g_slist_next(item))
|
|
|
|
path_v.push_back(static_cast<const char*>(item->data));
|
2015-06-12 17:19:45 -05:00
|
|
|
qof_book_begin_edit (book);
|
2015-06-23 19:09:51 -05:00
|
|
|
delete root->set_path(path_v, value);
|
2015-06-12 17:19:45 -05:00
|
|
|
qof_instance_set_dirty (QOF_INSTANCE (book));
|
|
|
|
qof_book_commit_edit (book);
|
|
|
|
}
|
|
|
|
|
|
|
|
KvpValue*
|
|
|
|
qof_book_get_option (QofBook *book, GSList *path)
|
|
|
|
{
|
|
|
|
KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
|
2015-06-23 19:09:51 -05:00
|
|
|
Path path_v {KVP_OPTION_PATH};
|
|
|
|
for (auto item = path; item != nullptr; item = g_slist_next(item))
|
|
|
|
path_v.push_back(static_cast<const char*>(item->data));
|
|
|
|
return root->get_slot(path_v);
|
2015-06-12 17:19:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-28 13:39:10 -06:00
|
|
|
qof_book_options_delete (QofBook *book, GSList *path)
|
2015-06-12 17:19:45 -05:00
|
|
|
{
|
|
|
|
KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
|
2016-11-28 13:39:10 -06:00
|
|
|
if (path != nullptr)
|
|
|
|
{
|
|
|
|
Path path_v {KVP_OPTION_PATH};
|
|
|
|
for (auto item = path; item != nullptr; item = g_slist_next(item))
|
|
|
|
path_v.push_back(static_cast<const char*>(item->data));
|
|
|
|
delete root->set_path(path_v, nullptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
delete root->set_path(KVP_OPTION_PATH, nullptr);
|
2015-06-12 17:19:45 -05:00
|
|
|
}
|
|
|
|
|
2005-11-07 09:45:58 -06:00
|
|
|
/* QofObject function implementation and registration */
|
|
|
|
gboolean qof_book_register (void)
|
|
|
|
{
|
2009-09-18 14:40:57 -05:00
|
|
|
static QofParam params[] =
|
|
|
|
{
|
|
|
|
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL },
|
|
|
|
{ QOF_PARAM_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL },
|
|
|
|
{ NULL },
|
|
|
|
};
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
qof_class_register (QOF_ID_BOOK, NULL, params);
|
2005-11-07 09:45:58 -06:00
|
|
|
|
2009-09-18 14:40:57 -05:00
|
|
|
return TRUE;
|
2005-11-07 09:45:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ========================== END OF FILE =============================== */
|