Branch data Line data Source code
1 : : /*
2 : : * gncBusiness.c -- Business helper functions
3 : : * Copyright (C) 2010 Christian Stimming
4 : : * Author: Christian Stimming <christian@cstimming.de>
5 : : *
6 : : * This program is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU General Public License as
8 : : * published by the Free Software Foundation; either version 2 of
9 : : * the License, or (at your option) any later version.
10 : : *
11 : : * This program is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with this program; if not, contact:
18 : : *
19 : : * Free Software Foundation Voice: +1-617-542-5942
20 : : * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
21 : : * Boston, MA 02110-1301, USA gnu@gnu.org
22 : : */
23 : :
24 : : #include <config.h>
25 : :
26 : : #include "gncBusiness.h"
27 : : #include "gncOwner.h"
28 : :
29 : : /* The initialization of the business objects is done in
30 : : * cashobjects_register() of <engine/cashobjects.h>. */
31 : :
32 : : struct _get_list_userdata
33 : : {
34 : : GList *result;
35 : : QofAccessFunc is_active_accessor_func;
36 : : };
37 : 40 : static void get_list_cb (QofInstance *inst, gpointer user_data)
38 : : {
39 : 40 : struct _get_list_userdata* data = user_data;
40 : 40 : if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL))
41 : 23 : data->result = g_list_prepend(data->result, inst);
42 : 40 : }
43 : :
44 : :
45 : 6 : GList * gncBusinessGetList (QofBook *book, const char *type_name,
46 : : gboolean all_including_inactive)
47 : : {
48 : : struct _get_list_userdata data;
49 : 6 : data.result = NULL;
50 : 6 : data.is_active_accessor_func = NULL;
51 : :
52 : 6 : if (!all_including_inactive)
53 : : {
54 : 3 : data.is_active_accessor_func =
55 : 3 : qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE);
56 : : }
57 : :
58 : 6 : qof_object_foreach(type_name, book, &get_list_cb, &data);
59 : :
60 : 6 : return data.result;
61 : : }
62 : :
63 : 6 : static void get_ownerlist_cb (QofInstance *inst, gpointer user_data)
64 : : {
65 : 6 : struct _get_list_userdata* data = user_data;
66 : 6 : if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL))
67 : : {
68 : 6 : GncOwner *owner = gncOwnerNew();
69 : 6 : qofOwnerSetEntity(owner, inst);
70 : 6 : data->result = g_list_prepend(data->result, owner);
71 : : }
72 : 6 : }
73 : :
74 : 12 : GList * gncBusinessGetOwnerList (QofBook *book, const char *type_name,
75 : : gboolean all_including_inactive)
76 : : {
77 : : struct _get_list_userdata data;
78 : 12 : data.result = NULL;
79 : 12 : data.is_active_accessor_func = NULL;
80 : :
81 : 12 : if (!all_including_inactive)
82 : : {
83 : 6 : data.is_active_accessor_func =
84 : 6 : qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE);
85 : : }
86 : :
87 : 12 : qof_object_foreach(type_name, book, &get_ownerlist_cb, &data);
88 : :
89 : 12 : return data.result;
90 : : }
91 : :
92 : 0 : gboolean gncBusinessIsPaymentAcctType (GNCAccountType type)
93 : : {
94 : 0 : if (xaccAccountIsAssetLiabType(type) ||
95 : 0 : xaccAccountIsEquityType(type))
96 : 0 : return TRUE;
97 : : else
98 : 0 : return FALSE;
99 : : }
|