Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Business objects cpp #1985

Draft
wants to merge 17 commits into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions libgnucash/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,23 @@ set (engine_SOURCES
gnc-rational.cpp
gnc-session.c
gnc-timezone.cpp
gnc-uri-utils.c
gnc-uri-utils.cpp
engine-helpers.c
guid.cpp
policy.cpp
gncAddress.c
gncBillTerm.c
gncAddress.cpp
gncBillTerm.cpp
gncBusiness.c
gncCustomer.c
gncEmployee.c
gncEntry.c
gncCustomer.cpp
gncEmployee.cpp
gncEntry.cpp
gncIDSearch.c
gncInvoice.c
gncJob.c
gncOrder.c
gncOwner.c
gncTaxTable.c
gncVendor.c
gncInvoice.cpp
gncJob.cpp
gncOrder.cpp
gncOwner.cpp
gncTaxTable.cpp
gncVendor.cpp
kvp-frame.cpp
kvp-value.cpp
qof-backend.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ gboolean gnc_uri_is_known_scheme (const gchar *scheme)

for ( node = known_scheme_list; node != NULL; node = node->next )
{
gchar *known_scheme = node->data;
gchar *known_scheme = (char*)node->data;
if ( !g_ascii_strcasecmp (scheme, known_scheme) )
{
is_known_scheme = TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ gncAddressCreate (QofBook *book, QofInstance *prnt)

if (!book) return NULL;

addr = g_object_new (GNC_TYPE_ADDRESS, NULL);
addr = GNC_ADDRESS(g_object_new (GNC_TYPE_ADDRESS, NULL));
qof_instance_init_data(&addr->inst, GNC_ID_ADDRESS, book);
addr->book = book;
addr->dirty = FALSE;
Expand Down Expand Up @@ -631,7 +631,7 @@ static QofObject GncAddressDesc =
DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) GNC_ID_ADDRESS,
DI(.type_label = ) "Address",
DI(.create = ) (gpointer)qofAddressCreate,
DI(.create = ) (void* (*)(QofBook*))qofAddressCreate,
DI(.book_begin = ) NULL,
DI(.book_end = ) NULL,
DI(.is_dirty = ) qof_collection_is_dirty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@ static inline void maybe_resort_list (GncBillTerm *term)
struct _book_info *bi;

if (term->parent || term->invisible) return;
bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
bi = static_cast<_book_info*>(qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME));
bi->terms = g_list_sort (bi->terms, (GCompareFunc)gncBillTermCompare);
}

static inline void addObj (GncBillTerm *term)
{
struct _book_info *bi;
bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
bi = static_cast<_book_info*>(qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME));
bi->terms = g_list_insert_sorted (bi->terms, term,
(GCompareFunc)gncBillTermCompare);
}

static inline void remObj (GncBillTerm *term)
{
struct _book_info *bi;
bi = qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME);
bi = static_cast<_book_info*>(qof_book_get_data (qof_instance_get_book(term), _GNC_MOD_NAME));
bi->terms = g_list_remove (bi->terms, term);
}

Expand Down Expand Up @@ -250,7 +250,7 @@ GncBillTerm * gncBillTermCreate (QofBook *book)
GncBillTerm *term;
if (!book) return NULL;

term = g_object_new (GNC_TYPE_BILLTERM, NULL);
term = GNC_BILLTERM(g_object_new (GNC_TYPE_BILLTERM, NULL));
qof_instance_init_data(&term->inst, _GNC_MOD_NAME, book);
term->name = CACHE_INSERT ("");
term->desc = CACHE_INSERT ("");
Expand Down Expand Up @@ -293,7 +293,7 @@ static void gncBillTermFree (GncBillTerm *term)
/* disconnect from the children */
for (list = term->children; list; list = list->next)
{
child = list->data;
child = GNC_BILLTERM(list->data);
gncBillTermSetParent(child, NULL);
}
g_list_free(term->children);
Expand Down Expand Up @@ -334,7 +334,18 @@ void gncBillTermSetType (GncBillTerm *term, GncBillTermType type)
}

/** \brief Convert bill term types from text. */
FROM_STRING_FUNC(GncBillTermType, ENUM_TERMS_TYPE)
GncBillTermType GncBillTermTypefromString (const char *str)
{
if (str)
{
if (!strcmp (str, "GNC_TERM_TYPE_DAYS"))
return GNC_TERM_TYPE_DAYS;
else if (!strcmp (str, "GNC_TERM_TYPE_PROXIMO"))
return GNC_TERM_TYPE_PROXIMO;
}
PERR ("str cannot be %s", str);
return GNC_TERM_TYPE_DAYS;
}

static
void qofBillTermSetType (GncBillTerm *term, const char *type_label)
Expand Down Expand Up @@ -497,9 +508,9 @@ GncBillTerm *gncBillTermLookupByName (QofBook *book, const char *name)

for ( ; list; list = list->next)
{
GncBillTerm *term = list->data;
GncBillTerm *term = GNC_BILLTERM(list->data);
if (!g_strcmp0 (term->name, name))
return list->data;
return term;
}
return NULL;
}
Expand All @@ -509,7 +520,7 @@ GList * gncBillTermGetTerms (QofBook *book)
struct _book_info *bi;
if (!book) return NULL;

bi = qof_book_get_data (book, _GNC_MOD_NAME);
bi = static_cast<_book_info*>(qof_book_get_data (book, _GNC_MOD_NAME));
return bi->terms;
}

Expand All @@ -527,7 +538,11 @@ const char *gncBillTermGetDescription (const GncBillTerm *term)

GncBillTermType gncBillTermGetType (const GncBillTerm *term)
{
if (!term) return 0;
if (!term)
{
PERR ("term cannot be null");
return GNC_TERM_TYPE_DAYS;
}
return term->type;
}

Expand Down Expand Up @@ -856,7 +871,7 @@ static void _gncBillTermDestroy (QofBook *book)

if (!book) return;

bi = qof_book_get_data (book, _GNC_MOD_NAME);
bi = static_cast<_book_info*>(qof_book_get_data (book, _GNC_MOD_NAME));

col = qof_book_get_collection (book, GNC_ID_BILLTERM);
qof_collection_foreach (col, destroy_billterm_on_book_close, NULL);
Expand All @@ -870,7 +885,7 @@ static QofObject gncBillTermDesc =
DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) _GNC_MOD_NAME,
DI(.type_label = ) "Billing Term",
DI(.create = ) (gpointer)gncBillTermCreate,
DI(.create = ) (void* (*)(QofBook*))gncBillTermCreate,
DI(.book_begin = ) _gncBillTermCreate,
DI(.book_end = ) _gncBillTermDestroy,
DI(.is_dirty = ) qof_collection_is_dirty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ GncCustomer *gncCustomerCreate (QofBook *book)

if (!book) return NULL;

cust = g_object_new (GNC_TYPE_CUSTOMER, NULL);
cust = GNC_CUSTOMER(g_object_new (GNC_TYPE_CUSTOMER, NULL));
qof_instance_init_data (&cust->inst, _GNC_MOD_NAME, book);

cust->id = CACHE_INSERT ("");
Expand Down Expand Up @@ -700,7 +700,7 @@ GList * gncCustomerGetJoblist (const GncCustomer *cust, gboolean show_all)
GList *list = NULL, *iterator;
for (iterator = cust->jobs; iterator; iterator = iterator->next)
{
GncJob *j = iterator->data;
auto j = GNC_JOB(iterator->data);
if (gncJobGetActive (j))
list = g_list_prepend (list, j);
}
Expand Down Expand Up @@ -913,7 +913,7 @@ static QofObject gncCustomerDesc =
DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) _GNC_MOD_NAME,
DI(.type_label = ) "Customer",
DI(.create = ) (gpointer)gncCustomerCreate,
DI(.create = ) (void* (*)(QofBook*))gncCustomerCreate,
DI(.book_begin = ) NULL,
DI(.book_end = ) gnc_customer_book_end,
DI(.is_dirty = ) qof_collection_is_dirty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ gnc_employee_set_property (GObject *object,
gncEmployeeSetLanguage(emp, g_value_get_string(value));
break;
case PROP_CURRENCY:
gncEmployeeSetCurrency(emp, g_value_get_object(value));
gncEmployeeSetCurrency(emp, GNC_COMMODITY(g_value_get_object(value)));
break;
case PROP_ACL:
gncEmployeeSetAcl(emp, g_value_get_string(value));
break;
case PROP_ADDRESS:
qofEmployeeSetAddr(emp, g_value_get_object(value));
qofEmployeeSetAddr(emp, QOF_INSTANCE(g_value_get_object(value)));
break;
case PROP_WORKDAY:
gncEmployeeSetWorkday(emp, *(gnc_numeric*)g_value_get_boxed(value));
Expand All @@ -220,7 +220,7 @@ gnc_employee_set_property (GObject *object,
gncEmployeeSetRate(emp, *(gnc_numeric*)g_value_get_boxed(value));
break;
case PROP_CCARD:
gncEmployeeSetCCard(emp, g_value_get_object(value));
gncEmployeeSetCCard(emp, GNC_ACCOUNT(g_value_get_object(value)));
break;
case PROP_PDF_DIRNAME:
qof_instance_set_kvp (QOF_INSTANCE (emp), value, 1, OWNER_EXPORT_PDF_DIRNAME);
Expand Down Expand Up @@ -431,7 +431,7 @@ GncEmployee *gncEmployeeCreate (QofBook *book)

if (!book) return NULL;

employee = g_object_new (GNC_TYPE_EMPLOYEE, NULL);
employee = GNC_EMPLOYEE(g_object_new (GNC_TYPE_EMPLOYEE, NULL));
qof_instance_init_data (&employee->inst, _GNC_MOD_NAME, book);

employee->id = CACHE_INSERT ("");
Expand Down Expand Up @@ -809,7 +809,7 @@ gboolean gncEmployeeEqual(const GncEmployee* a, const GncEmployee* b)

static const char * _gncEmployeePrintable (gpointer item)
{
GncEmployee *v = item;
auto v = GNC_EMPLOYEE(item);
if (!item) return NULL;
return gncAddressGetName(v->addr);
}
Expand Down Expand Up @@ -899,7 +899,7 @@ static QofObject gncEmployeeDesc =
DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) _GNC_MOD_NAME,
DI(.type_label = ) "Employee",
DI(.create = ) (gpointer)gncEmployeeCreate,
DI(.create = ) (void* (*)(QofBook*))gncEmployeeCreate,
DI(.book_begin = ) NULL,
DI(.book_end = ) gnc_employee_book_end,
DI(.is_dirty = ) qof_collection_is_dirty,
Expand Down
34 changes: 23 additions & 11 deletions libgnucash/engine/gncEntry.c → libgnucash/engine/gncEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ GncEntry *gncEntryCreate (QofBook *book)

if (!book) return NULL;

entry = g_object_new (GNC_TYPE_ENTRY, NULL);
entry = GNC_ENTRY(g_object_new (GNC_TYPE_ENTRY, NULL));
qof_instance_init_data (&entry->inst, _GNC_MOD_NAME, book);

entry->desc = CACHE_INSERT ("");
Expand Down Expand Up @@ -977,13 +977,21 @@ gnc_numeric gncEntryGetInvDiscount (const GncEntry *entry)

GncAmountType gncEntryGetInvDiscountType (const GncEntry *entry)
{
if (!entry) return 0;
if (!entry)
{
PERR ("entry must not be null");
return GNC_AMT_TYPE_VALUE;
}
return entry->i_disc_type;
}

GncDiscountHow gncEntryGetInvDiscountHow (const GncEntry *entry)
{
if (!entry) return 0;
if (!entry)
{
PERR ("entry must not be null");
return GNC_DISC_PRETAX;
}
return entry->i_disc_how;
}

Expand Down Expand Up @@ -1069,7 +1077,11 @@ GncOwner * gncEntryGetBillTo (GncEntry *entry)

GncEntryPaymentType gncEntryGetBillPayment (const GncEntry* entry)
{
if (!entry) return 0;
if (!entry)
{
PERR ("entry must not be null");
return GNC_PAYMENT_CASH;
}
return entry->b_payment;
}

Expand Down Expand Up @@ -1158,7 +1170,7 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
/* First, compute the aggregate tpercent and tvalue numbers */
for (node = entries; node; node = node->next)
{
GncTaxTableEntry *entry = node->data;
auto entry = static_cast<GncTaxTableEntry*>(node->data);
gnc_numeric amount = gncTaxTableEntryGetAmount (entry);

switch (gncTaxTableEntryGetType (entry))
Expand Down Expand Up @@ -1296,7 +1308,7 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
PINFO("Computing tax value list");
for (node = entries; node; node = node->next)
{
GncTaxTableEntry *entry = node->data;
auto entry = static_cast<GncTaxTableEntry*>(node->data);
Account *acc = gncTaxTableEntryGetAccount (entry);
gnc_numeric amount = gncTaxTableEntryGetAmount (entry);

Expand Down Expand Up @@ -1436,7 +1448,7 @@ gncEntryRecomputeValues (GncEntry *entry)
entry->i_tax_value_rounded = gnc_numeric_zero();
for (tv_iter = entry->i_tax_values; tv_iter; tv_iter=tv_iter->next)
{
GncAccountValue *acc_val = tv_iter->data;
auto acc_val = static_cast<GncAccountValue*>(tv_iter->data);
entry->i_tax_value_rounded = gnc_numeric_add (entry->i_tax_value_rounded, acc_val->value,
denom, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
}
Expand All @@ -1447,7 +1459,7 @@ gncEntryRecomputeValues (GncEntry *entry)
entry->b_tax_value_rounded = gnc_numeric_zero();
for (tv_iter = entry->b_tax_values; tv_iter; tv_iter=tv_iter->next)
{
GncAccountValue *acc_val = tv_iter->data;
auto acc_val = static_cast<GncAccountValue*>(tv_iter->data);
entry->b_tax_value_rounded = gnc_numeric_add (entry->b_tax_value_rounded, acc_val->value,
denom, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
}
Expand Down Expand Up @@ -1553,7 +1565,7 @@ AccountValueList * gncEntryGetDocTaxValues (GncEntry *entry, gboolean is_cust_do
/* Make a copy of the list with negated values if necessary. */
for (node = int_values; node; node = node->next)
{
GncAccountValue *acct_val = node->data;
auto acct_val = static_cast<GncAccountValue*>(node->data);
values = gncAccountValueAdd (values, acct_val->account,
(is_cn ? gnc_numeric_neg (acct_val->value)
: acct_val->value));
Expand Down Expand Up @@ -1589,7 +1601,7 @@ AccountValueList * gncEntryGetBalTaxValues (GncEntry *entry, gboolean is_cust_do
/* Make a copy of the list with negated values if necessary. */
for (node = int_values; node; node = node->next)
{
GncAccountValue *acct_val = node->data;
auto acct_val = static_cast<GncAccountValue*>(node->data);
values = gncAccountValueAdd (values, acct_val->account,
(is_cust_doc ? gnc_numeric_neg (acct_val->value)
: acct_val->value));
Expand Down Expand Up @@ -1723,7 +1735,7 @@ static QofObject gncEntryDesc =
DI(.interface_version = ) QOF_OBJECT_VERSION,
DI(.e_type = ) _GNC_MOD_NAME,
DI(.type_label = ) "Order/Invoice/Bill Entry",
DI(.create = ) (gpointer)gncEntryCreate,
DI(.create = ) (void* (*)(QofBook*))gncEntryCreate,
DI(.book_begin = ) NULL,
DI(.book_end = ) gnc_entry_book_end,
DI(.is_dirty = ) qof_collection_is_dirty,
Expand Down
Loading
Loading