GnuCash  5.6-150-g038405b370+
gncBusiness.c
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 
33 {
34  GList *result;
35  QofAccessFunc is_active_accessor_func;
36 };
37 static void get_list_cb (QofInstance *inst, gpointer user_data)
38 {
39  struct _get_list_userdata* data = user_data;
40  if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL))
41  data->result = g_list_prepend(data->result, inst);
42 }
43 
44 
45 GList * gncBusinessGetList (QofBook *book, const char *type_name,
46  gboolean all_including_inactive)
47 {
48  struct _get_list_userdata data;
49  data.result = NULL;
50  data.is_active_accessor_func = NULL;
51 
52  if (!all_including_inactive)
53  {
54  data.is_active_accessor_func =
55  qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE);
56  }
57 
58  qof_object_foreach(type_name, book, &get_list_cb, &data);
59 
60  return data.result;
61 }
62 
63 static void get_ownerlist_cb (QofInstance *inst, gpointer user_data)
64 {
65  struct _get_list_userdata* data = user_data;
66  if (!data->is_active_accessor_func || data->is_active_accessor_func(inst, NULL))
67  {
68  GncOwner *owner = gncOwnerNew();
69  qofOwnerSetEntity(owner, inst);
70  data->result = g_list_prepend(data->result, owner);
71  }
72 }
73 
74 GList * gncBusinessGetOwnerList (QofBook *book, const char *type_name,
75  gboolean all_including_inactive)
76 {
77  struct _get_list_userdata data;
78  data.result = NULL;
79  data.is_active_accessor_func = NULL;
80 
81  if (!all_including_inactive)
82  {
83  data.is_active_accessor_func =
84  qof_class_get_parameter_getter(type_name, QOF_PARAM_ACTIVE);
85  }
86 
87  qof_object_foreach(type_name, book, &get_ownerlist_cb, &data);
88 
89  return data.result;
90 }
91 
93 {
94  if (xaccAccountIsAssetLiabType(type) ||
96  return TRUE;
97  else
98  return FALSE;
99 }
OwnerList * gncBusinessGetOwnerList(QofBook *book, QofIdTypeConst type_name, gboolean all_including_inactive)
Returns a GList of all objects of the given type_name in the given book, but each object is wrapped i...
Business Interface: Object OWNERs.
gboolean gncBusinessIsPaymentAcctType(GNCAccountType type)
Returns whether the given account type is a valid type to use in business payments.
Definition: gncBusiness.c:92
QofAccessFunc qof_class_get_parameter_getter(QofIdTypeConst obj_name, const char *parameter)
Return the object&#39;s parameter getter function.
Definition: qofclass.cpp:156
gboolean xaccAccountIsAssetLiabType(GNCAccountType t)
Convenience function to check if the account is a valid Asset or Liability type, but not a business a...
Definition: Account.cpp:4420
void qofOwnerSetEntity(GncOwner *owner, QofInstance *ent)
set the owner from the entity.
Definition: gncOwner.c:319
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
Invoke the callback &#39;cb&#39; on every instance ov a particular object type.
Definition: qofobject.cpp:185
– Business Helper Functions
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
Definition: qofclass.h:178
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
Definition: Account.h:101
GList * gncBusinessGetList(QofBook *book, QofIdTypeConst type_name, gboolean all_including_inactive)
Returns a GList of all objects of the given type_name in the given book.
GncOwner * gncOwnerNew(void)
These two functions are mainly for the convenience of scheme code.
Definition: gncOwner.c:57
gboolean xaccAccountIsEquityType(GNCAccountType t)
Convenience function to check if the account is a valid Equity type.
Definition: Account.cpp:4478