2010-10-02 09:59:21 -05:00
|
|
|
/*
|
|
|
|
* gncBusiness.c -- Business helper functions
|
|
|
|
* Copyright (C) 2010 Christian Stimming
|
|
|
|
* Author: Christian Stimming <christian@cstimming.de>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org
|
|
|
|
*/
|
|
|
|
|
2017-10-26 04:14:21 -05:00
|
|
|
#include <config.h>
|
2010-10-02 09:59:21 -05:00
|
|
|
|
|
|
|
#include "gncBusiness.h"
|
2017-08-10 06:56:00 -05:00
|
|
|
#include "gncOwner.h"
|
2010-10-02 09:59:21 -05:00
|
|
|
|
|
|
|
/* The initialization of the business objects is done in
|
|
|
|
* cashobjects_register() of <engine/cashobjects.h>. */
|
|
|
|
|
|
|
|
struct _get_list_userdata
|
|
|
|
{
|
2010-10-03 07:27:44 -05:00
|
|
|
GList *result;
|
|
|
|
QofAccessFunc is_active_accessor_func;
|
2010-10-02 09:59:21 -05:00
|
|
|
};
|
|
|
|
static void get_list_cb (QofInstance *inst, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct _get_list_userdata* data = user_data;
|
|
|
|
if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL))
|
|
|
|
data->result = g_list_prepend(data->result, inst);
|
|
|
|
}
|
|
|
|
|
2010-10-02 09:59:33 -05:00
|
|
|
|
2010-10-02 09:59:21 -05:00
|
|
|
GList * gncBusinessGetList (QofBook *book, const char *type_name,
|
|
|
|
gboolean all_including_inactive)
|
|
|
|
{
|
|
|
|
struct _get_list_userdata data;
|
|
|
|
data.result = NULL;
|
|
|
|
data.is_active_accessor_func = NULL;
|
|
|
|
|
|
|
|
if (!all_including_inactive)
|
|
|
|
{
|
|
|
|
data.is_active_accessor_func =
|
|
|
|
qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
qof_object_foreach(type_name, book, &get_list_cb, &data);
|
|
|
|
|
|
|
|
return data.result;
|
|
|
|
}
|
2010-10-02 09:59:33 -05:00
|
|
|
|
|
|
|
static void get_ownerlist_cb (QofInstance *inst, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct _get_list_userdata* data = user_data;
|
|
|
|
if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL))
|
|
|
|
{
|
2011-05-11 16:51:17 -05:00
|
|
|
GncOwner *owner = gncOwnerNew();
|
2010-10-02 09:59:33 -05:00
|
|
|
qofOwnerSetEntity(owner, inst);
|
|
|
|
data->result = g_list_prepend(data->result, owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GList * gncBusinessGetOwnerList (QofBook *book, const char *type_name,
|
|
|
|
gboolean all_including_inactive)
|
|
|
|
{
|
|
|
|
struct _get_list_userdata data;
|
|
|
|
data.result = NULL;
|
|
|
|
data.is_active_accessor_func = NULL;
|
|
|
|
|
|
|
|
if (!all_including_inactive)
|
|
|
|
{
|
|
|
|
data.is_active_accessor_func =
|
|
|
|
qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
qof_object_foreach(type_name, book, &get_ownerlist_cb, &data);
|
|
|
|
|
|
|
|
return data.result;
|
|
|
|
}
|
2016-03-25 06:10:10 -05:00
|
|
|
|
|
|
|
gboolean gncBusinessIsPaymentAcctType (GNCAccountType type)
|
|
|
|
{
|
|
|
|
if (xaccAccountIsAssetLiabType(type) ||
|
|
|
|
xaccAccountIsEquityType(type))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|