35 #include <glib/gi18n.h> 37 #include <qofinstance-p.h> 39 #include "gncCustomerP.h" 40 #include "gncEmployeeP.h" 43 #include "gncOwnerP.h" 44 #include "gncVendorP.h" 50 #include "engine-helpers.h" 52 #define _GNC_MOD_NAME GNC_ID_OWNER 54 #define GNC_OWNER_ID "gncOwner" 56 static QofLogModule log_module = GNC_MOD_ENGINE;
63 o->type = GNC_OWNER_NONE;
79 case GNC_OWNER_UNDEFINED :
81 case GNC_OWNER_CUSTOMER :
83 gncCustomerBeginEdit(owner->owner.customer);
88 gncJobBeginEdit(owner->owner.job);
91 case GNC_OWNER_VENDOR :
93 gncVendorBeginEdit(owner->owner.vendor);
96 case GNC_OWNER_EMPLOYEE :
98 gncEmployeeBeginEdit(owner->owner.employee);
104 void gncOwnerCommitEdit (
GncOwner *owner)
109 case GNC_OWNER_NONE :
110 case GNC_OWNER_UNDEFINED :
112 case GNC_OWNER_CUSTOMER :
114 gncCustomerCommitEdit(owner->owner.customer);
119 gncJobCommitEdit(owner->owner.job);
122 case GNC_OWNER_VENDOR :
124 gncVendorCommitEdit(owner->owner.vendor);
127 case GNC_OWNER_EMPLOYEE :
129 gncEmployeeCommitEdit(owner->owner.employee);
135 void gncOwnerDestroy (
GncOwner *owner)
140 case GNC_OWNER_NONE :
141 case GNC_OWNER_UNDEFINED :
143 case GNC_OWNER_CUSTOMER :
145 gncCustomerDestroy(owner->owner.customer);
150 gncJobDestroy(owner->owner.job);
153 case GNC_OWNER_VENDOR :
155 gncVendorDestroy(owner->owner.vendor);
158 case GNC_OWNER_EMPLOYEE :
160 gncEmployeeDestroy(owner->owner.employee);
166 void gncOwnerInitUndefined (
GncOwner *owner, gpointer obj)
169 owner->type = GNC_OWNER_UNDEFINED;
170 owner->owner.undefined = obj;
176 owner->type = GNC_OWNER_CUSTOMER;
177 owner->owner.customer = customer;
180 void gncOwnerInitJob (
GncOwner *owner, GncJob *job)
183 owner->type = GNC_OWNER_JOB;
184 owner->owner.job = job;
187 void gncOwnerInitVendor (
GncOwner *owner, GncVendor *vendor)
190 owner->type = GNC_OWNER_VENDOR;
191 owner->owner.vendor = vendor;
194 void gncOwnerInitEmployee (
GncOwner *owner, GncEmployee *employee)
197 owner->type = GNC_OWNER_EMPLOYEE;
198 owner->owner.employee = employee;
203 if (!owner)
return GNC_OWNER_NONE;
214 case GNC_OWNER_UNDEFINED:
215 return N_(
"Undefined");
216 case GNC_OWNER_CUSTOMER:
217 return N_(
"Customer");
220 case GNC_OWNER_VENDOR:
222 case GNC_OWNER_EMPLOYEE:
223 return N_(
"Employee");
225 PWARN (
"Unknown owner type");
241 case GNC_OWNER_NONE :
246 case GNC_OWNER_UNDEFINED :
251 case GNC_OWNER_CUSTOMER :
253 type = GNC_ID_CUSTOMER;
261 case GNC_OWNER_VENDOR :
263 type = GNC_ID_VENDOR;
266 case GNC_OWNER_EMPLOYEE :
268 type = GNC_ID_EMPLOYEE;
287 case GNC_OWNER_NONE :
291 case GNC_OWNER_UNDEFINED :
295 case GNC_OWNER_CUSTOMER :
297 ent = QOF_INSTANCE(owner->owner.customer);
302 ent = QOF_INSTANCE(owner->owner.job);
305 case GNC_OWNER_VENDOR :
307 ent = QOF_INSTANCE(owner->owner.vendor);
310 case GNC_OWNER_EMPLOYEE :
312 ent = QOF_INSTANCE(owner->owner.employee);
326 if (0 == g_strcmp0(ent->e_type, GNC_ID_CUSTOMER))
328 owner->type = GNC_OWNER_CUSTOMER;
331 else if (0 == g_strcmp0(ent->e_type, GNC_ID_JOB))
333 owner->type = GNC_OWNER_JOB;
334 gncOwnerInitJob(owner, (GncJob*)ent);
336 else if (0 == g_strcmp0(ent->e_type, GNC_ID_VENDOR))
338 owner->type = GNC_OWNER_VENDOR;
339 gncOwnerInitVendor(owner, (GncVendor*)ent);
341 else if (0 == g_strcmp0(ent->e_type, GNC_ID_EMPLOYEE))
343 owner->type = GNC_OWNER_EMPLOYEE;
344 gncOwnerInitEmployee(owner, (GncEmployee*)ent);
348 owner->type = GNC_OWNER_NONE;
349 owner->owner.undefined = NULL;
358 return (GNC_IS_VENDOR(ent) ||
359 GNC_IS_CUSTOMER(ent) ||
360 GNC_IS_EMPLOYEE(ent) ||
365 if (!owner)
return NULL;
366 if (owner->type != GNC_OWNER_UNDEFINED)
return NULL;
367 return owner->owner.undefined;
372 if (!owner)
return NULL;
373 if (owner->type != GNC_OWNER_CUSTOMER)
return NULL;
374 return owner->owner.customer;
379 if (!owner)
return NULL;
380 if (owner->type != GNC_OWNER_JOB)
return NULL;
381 return owner->owner.job;
386 if (!owner)
return NULL;
387 if (owner->type != GNC_OWNER_VENDOR)
return NULL;
388 return owner->owner.vendor;
393 if (!owner)
return NULL;
394 if (owner->type != GNC_OWNER_EMPLOYEE)
return NULL;
395 return owner->owner.employee;
400 if (!src || !dest)
return;
401 if (src == dest)
return;
402 memcpy (dest, src,
sizeof (*dest));
407 if (!a || !b)
return FALSE;
409 return (a->owner.undefined == b->owner.undefined);
420 const char * gncOwnerGetID (
const GncOwner *owner)
422 if (!owner)
return NULL;
426 case GNC_OWNER_UNDEFINED:
429 case GNC_OWNER_CUSTOMER:
430 return gncCustomerGetID (owner->owner.customer);
432 return gncJobGetID (owner->owner.job);
433 case GNC_OWNER_VENDOR:
434 return gncVendorGetID (owner->owner.vendor);
435 case GNC_OWNER_EMPLOYEE:
436 return gncEmployeeGetID (owner->owner.employee);
440 const char * gncOwnerGetName (
const GncOwner *owner)
442 if (!owner)
return NULL;
446 case GNC_OWNER_UNDEFINED:
449 case GNC_OWNER_CUSTOMER:
450 return gncCustomerGetName (owner->owner.customer);
452 return gncJobGetName (owner->owner.job);
453 case GNC_OWNER_VENDOR:
454 return gncVendorGetName (owner->owner.vendor);
455 case GNC_OWNER_EMPLOYEE:
456 return gncEmployeeGetName (owner->owner.employee);
462 if (!owner)
return NULL;
466 case GNC_OWNER_UNDEFINED:
470 case GNC_OWNER_CUSTOMER:
471 return gncCustomerGetAddr (owner->owner.customer);
472 case GNC_OWNER_VENDOR:
473 return gncVendorGetAddr (owner->owner.vendor);
474 case GNC_OWNER_EMPLOYEE:
475 return gncEmployeeGetAddr (owner->owner.employee);
479 gnc_commodity * gncOwnerGetCurrency (
const GncOwner *owner)
481 if (!owner)
return NULL;
485 case GNC_OWNER_UNDEFINED:
488 case GNC_OWNER_CUSTOMER:
489 return gncCustomerGetCurrency (owner->owner.customer);
490 case GNC_OWNER_VENDOR:
491 return gncVendorGetCurrency (owner->owner.vendor);
492 case GNC_OWNER_EMPLOYEE:
493 return gncEmployeeGetCurrency (owner->owner.employee);
495 return gncOwnerGetCurrency (gncJobGetOwner (owner->owner.job));
499 gboolean gncOwnerGetActive (
const GncOwner *owner)
501 if (!owner)
return FALSE;
505 case GNC_OWNER_UNDEFINED:
508 case GNC_OWNER_CUSTOMER:
509 return gncCustomerGetActive (owner->owner.customer);
510 case GNC_OWNER_VENDOR:
511 return gncVendorGetActive (owner->owner.vendor);
512 case GNC_OWNER_EMPLOYEE:
513 return gncEmployeeGetActive (owner->owner.employee);
515 return gncJobGetActive (owner->owner.job);
521 if (!owner)
return NULL;
526 case GNC_OWNER_UNDEFINED:
529 case GNC_OWNER_CUSTOMER:
533 case GNC_OWNER_VENDOR:
535 case GNC_OWNER_EMPLOYEE:
541 gncOwnerSetActive (
const GncOwner *owner, gboolean active)
546 case GNC_OWNER_CUSTOMER:
547 gncCustomerSetActive (owner->owner.customer, active);
549 case GNC_OWNER_VENDOR:
550 gncVendorSetActive (owner->owner.vendor, active);
552 case GNC_OWNER_EMPLOYEE:
553 gncEmployeeSetActive (owner->owner.employee, active);
556 gncJobSetActive (owner->owner.job, active);
559 case GNC_OWNER_UNDEFINED:
575 if (!owner)
return NULL;
579 case GNC_OWNER_UNDEFINED:
582 case GNC_OWNER_CUSTOMER:
583 case GNC_OWNER_VENDOR:
584 case GNC_OWNER_EMPLOYEE:
587 return gncJobGetOwner (owner->owner.job);
593 if (!a && !b)
return 0;
594 if (!a && b)
return 1;
595 if (a && !b)
return -1;
597 if (a->type != b->type)
598 return (a->type - b->type);
603 case GNC_OWNER_UNDEFINED:
606 case GNC_OWNER_CUSTOMER:
607 return gncCustomerCompare (a->owner.customer, b->owner.customer);
608 case GNC_OWNER_VENDOR:
610 case GNC_OWNER_EMPLOYEE:
611 return gncEmployeeCompare (a->owner.employee, b->owner.employee);
613 return gncJobCompare (a->owner.job, b->owner.job);
619 if (!owner)
return NULL;
628 gnc_lot_begin_edit (lot);
634 gnc_lot_commit_edit (lot);
641 GncOwnerType type = GNC_OWNER_NONE;
644 if (!lot || !owner)
return FALSE;
646 book = gnc_lot_get_book (lot);
648 GNC_OWNER_TYPE, &type64,
649 GNC_OWNER_GUID, &guid,
651 type = (GncOwnerType) type64;
654 case GNC_OWNER_CUSTOMER:
655 gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
657 case GNC_OWNER_VENDOR:
658 gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
660 case GNC_OWNER_EMPLOYEE:
661 gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
664 gncOwnerInitJob (owner, gncJobLookup (book, guid));
672 return (owner->owner.undefined != NULL);
677 Split *apar_split = NULL;
679 if (!txn || !owner)
return FALSE;
690 gncOwnerCopy (gncInvoiceGetOwner (invoice), owner);
702 if (!owner)
return FALSE;
703 return (owner->owner.undefined != NULL);
709 const GncOwner *req_owner = user_data;
738 da = gncInvoiceGetDateDue (ia);
743 db = gncInvoiceGetDateDue (ib);
747 return (da > db) - (da < db);
753 gnc_numeric amount, gnc_numeric exch,
time64 date,
754 const char *memo,
const char *num)
759 gnc_commodity *post_comm, *xfer_comm;
760 Split *xfer_split = NULL;
761 Transaction *txn = NULL;
763 gnc_numeric xfer_amount = gnc_numeric_zero();
764 gnc_numeric txn_value = gnc_numeric_zero();
767 if (!owner || !posted_acc || !xfer_acc)
return NULL;
768 g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
771 book = gnc_account_get_book (posted_acc);
778 if (preset_txn && *preset_txn)
788 xfer_split = xaccTransFindSplitByAccount(txn, xfer_acc);
793 if (split == xfer_split)
819 xfer_amount = amount;
837 gnc_set_num_action (NULL, xfer_split, num, _(
"Payment"));
869 payment_lot = gnc_lot_new (book);
900 Split *best_split = NULL;
901 gnc_numeric best_val = { 0, 1};
909 Split *split = ls_iter->data;
911 gnc_numeric split_value;
924 PWARN(
"Encountered a split in a payment lot that's not part of any transaction. " 925 "This is unexpected! Skipping split %p.", split);
939 new_flags += is_equal;
940 else if (val_cmp > 0)
941 new_flags += is_more;
943 new_flags += is_less;
946 new_flags += is_pay_split;
948 if ((new_flags >= best_flags) &&
954 best_flags = new_flags;
955 best_val = split_value;
987 xaccSplitSetParent (rem_split, txn);
999 gchar *memo_prefix = _(
"Offset between documents: ");
1003 GList *titles = NULL, *titer;
1014 Split *split = lts_iter->data;
1016 GncInvoice *invoice;
1030 title = g_strdup_printf (
"%s %s", gncInvoiceGetTypeString (invoice), gncInvoiceGetID (invoice));
1032 titles = g_list_prepend (titles, title);
1033 splits = g_list_prepend (splits, split);
1039 titles = g_list_sort (titles, (GCompareFunc)g_strcmp0);
1042 new_memo = g_strconcat (memo_prefix, titles->data, NULL);
1043 for (titer = titles->next; titer; titer = titer->next)
1045 gchar *tmp_memo = g_strconcat (new_memo,
" - ", titer->data, NULL);
1047 new_memo = tmp_memo;
1049 g_list_free_full (titles, g_free);
1052 for (siter = splits; siter; siter = siter->next)
1058 g_list_free (splits);
1067 static Transaction *
1068 get_ll_transaction_from_lot (GNCLot *lot)
1081 Split *ls = ls_iter->data;
1090 Split *ts = ts_iter->data;
1109 gncOwnerCreateLotLink (GNCLot *from_lot, GNCLot *to_lot,
const GncOwner *owner)
1111 const gchar *action = _(
"Lot Link");
1114 Transaction *ll_txn = NULL;
1115 gnc_numeric from_lot_bal, to_lot_bal;
1116 time64 from_time, to_time;
1128 if (from_time >= to_time)
1129 time_posted = from_time;
1131 time_posted = to_time;
1145 ll_txn = get_ll_transaction_from_lot (from_lot);
1148 ll_txn = get_ll_transaction_from_lot (to_lot);
1167 if (time_posted > time)
1174 gnc_set_num_action (NULL, split, NULL, action);
1184 gnc_set_num_action (NULL, split, NULL, action);
1208 static void gncOwnerOffsetLots (GNCLot *from_lot, GNCLot *to_lot,
const GncOwner *owner)
1210 gnc_numeric target_offset;
1216 PWARN (
"from_lot %p is a document lot. That is not allowed in gncOwnerOffsetLots", from_lot);
1259 for (left_iter = lots; left_iter; left_iter = left_iter->next)
1261 GNCLot *left_lot = left_iter->data;
1262 gnc_numeric left_lot_bal;
1263 gboolean left_lot_has_doc;
1264 gboolean left_modified = FALSE;
1274 if (gnc_lot_count_splits (left_lot) == 0)
1276 gnc_lot_destroy (left_lot);
1277 left_iter->data = NULL;
1293 for (right_iter = left_iter->next; right_iter; right_iter = right_iter->next)
1295 GNCLot *right_lot = right_iter->data;
1296 gnc_numeric right_lot_bal;
1297 gboolean right_lot_has_doc;
1305 if (gnc_lot_count_splits (right_lot) == 0)
1307 gnc_lot_destroy (right_lot);
1308 right_iter->data = NULL;
1338 if (left_lot_has_doc && right_lot_has_doc)
1339 gncOwnerCreateLotLink (left_lot, right_lot, owner);
1340 else if (!left_lot_has_doc && !right_lot_has_doc)
1345 gncOwnerOffsetLots (left_lot, right_lot, owner);
1347 gncOwnerOffsetLots (right_lot, left_lot, owner);
1351 GNCLot *doc_lot = left_lot_has_doc ? left_lot : right_lot;
1352 GNCLot *pay_lot = left_lot_has_doc ? right_lot : left_lot;
1354 gncOwnerOffsetLots (pay_lot, doc_lot, owner);
1364 qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
1366 left_modified = TRUE;
1376 qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
1394 gnc_numeric amount, gnc_numeric exch,
time64 date,
1395 const char *memo,
const char *num, gboolean auto_pay)
1397 GNCLot *payment_lot = NULL;
1398 GList *selected_lots = NULL;
1401 if (!owner || !posted_acc
1403 g_return_if_fail (owner->owner.undefined);
1408 posted_acc, xfer_acc,
1409 amount, exch, date, memo,
1413 selected_lots = lots;
1416 (gpointer)owner, NULL);
1423 selected_lots = g_list_prepend (selected_lots, payment_lot);
1425 g_list_free (selected_lots);
1431 g_return_val_if_fail (owner, NULL);
1435 case GNC_OWNER_CUSTOMER:
1437 case GNC_OWNER_VENDOR:
1438 case GNC_OWNER_EMPLOYEE:
1449 g_return_val_if_fail (owner, NULL);
1450 g_return_val_if_fail (gncOwnerGetCurrency(owner), NULL);
1452 return (g_list_prepend (NULL, gncOwnerGetCurrency(owner)));
1464 const gnc_commodity *report_currency)
1466 gnc_numeric balance = gnc_numeric_zero ();
1468 gnc_commodity *owner_currency;
1470 const gnc_numeric *cached_balance = NULL;
1472 g_return_val_if_fail (owner, gnc_numeric_zero ());
1475 owner_currency = gncOwnerGetCurrency (owner);
1477 cached_balance = gncOwnerGetCachedBalance (owner);
1479 balance = *cached_balance;
1488 for (acct_node = acct_list; acct_node; acct_node = acct_node->next)
1490 Account *account = acct_node->data;
1491 GList *lot_list = NULL, *lot_node;
1504 (gpointer)owner, NULL);
1506 for (lot_node = lot_list; lot_node; lot_node = lot_node->next)
1508 GNCLot *lot = lot_node->data;
1515 g_list_free (lot_list);
1517 g_list_free (acct_list);
1518 g_list_free (acct_types);
1520 gncOwnerSetCachedBalance (owner, &balance);
1525 if (report_currency)
1527 pdb, balance, owner_currency, report_currency);
1537 owner_from_lot (GNCLot *lot)
1541 if (!lot)
return NULL;
1551 static QofParam params[] =
1553 { OWNER_FROM_LOT, _GNC_MOD_NAME, (
QofAccessFunc)owner_from_lot, NULL },
1562 if (!book || !owner || !type || !guid)
return FALSE;
1564 if (0 == g_strcmp0(type, GNC_ID_CUSTOMER))
1566 GncCustomer *customer = gncCustomerLookup(book, guid);
1567 gncOwnerInitCustomer(owner, customer);
1568 return (NULL != customer);
1570 else if (0 == g_strcmp0(type, GNC_ID_JOB))
1572 GncJob *job = gncJobLookup(book, guid);
1573 gncOwnerInitJob(owner, job);
1574 return (NULL != job);
1576 else if (0 == g_strcmp0(type, GNC_ID_VENDOR))
1578 GncVendor *vendor = gncVendorLookup(book, guid);
1579 gncOwnerInitVendor(owner, vendor);
1580 return (NULL != vendor);
1582 else if (0 == g_strcmp0(type, GNC_ID_EMPLOYEE))
1584 GncEmployee *employee = gncEmployeeLookup(book, guid);
1585 gncOwnerInitEmployee(owner, employee);
1586 return (NULL != employee);
1591 gboolean gncOwnerRegister (
void)
1593 static QofParam params[] =
1601 { OWNER_PARENTG, QOF_TYPE_GUID, (
QofAccessFunc)gncOwnerGetEndGUID, NULL },
1602 { OWNER_NAME, QOF_TYPE_STRING, (
QofAccessFunc)gncOwnerGetName, NULL },
1614 gncOwnerGetCachedBalance (
const GncOwner *owner)
1616 if (!owner)
return NULL;
1628 void gncOwnerSetCachedBalance (
const GncOwner *owner,
const gnc_numeric *new_bal)
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
GList * gncOwnerGetCommoditiesList(const GncOwner *owner)
Returns a GList of currencies associated with the owner.
#define xaccTransAppendSplit(t, s)
Add a split to the transaction.
Transaction * xaccMallocTransaction(QofBook *book)
The xaccMallocTransaction() will malloc memory and initialize it.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
void xaccSplitSetBaseValue(Split *s, gnc_numeric value, const gnc_commodity *base_currency)
Depending on the base_currency, set either the value or the amount of this split or both: If the base...
gboolean xaccScrubMergeLotSubSplits(GNCLot *lot, gboolean strict)
The xaccScrubMergeLotSubSplits() routine does the same as the xaccScrubMergSubSplits, except that it does it for all of the splits in the lot.
const GncGUID * gncOwnerGetGUID(const GncOwner *owner)
Get the GncGUID of the immediate owner.
void xaccSplitSetAction(Split *split, const char *actn)
The Action is an arbitrary user-assigned string.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
Business Interface: Object OWNERs.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.
Split * xaccTransGetSplit(const Transaction *trans, int i)
Return a pointer to the indexed split in this transaction's split list.
gboolean gncOwnerGetOwnerFromTxn(Transaction *txn, GncOwner *owner)
Convenience function to get the owner from a transaction.
GList * gncOwnerGetAccountTypesList(const GncOwner *owner)
Returns a GList of account-types based on the owner type.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
char xaccTransGetTxnType(Transaction *trans)
Returns the Transaction Type: note this type will be derived from the transaction splits...
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
gboolean xaccSplitDestroy(Split *split)
Destructor.
Utilities to Convert Stock Accounts to use Lots.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
void qof_instance_set(QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
void gnc_lot_add_split(GNCLot *lot, Split *split)
The gnc_lot_add_split() routine adds a split to this lot.
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
gboolean gncOwnerEqual(const GncOwner *a, const GncOwner *b)
Assess equality by checking.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
void xaccTransSetNum(Transaction *trans, const char *xnum)
Sets the transaction Number (or ID) field; rather than use this function directly, see 'gnc_set_num_action' in engine/engine-helpers.c & .h which takes a user-set book option for selecting the source for the num-cell (the transaction-number or the split-action field) in registers/reports into account automatically.
const char * gncOwnerGetTypeString(const GncOwner *owner)
return the type for the owner as an untranslated string.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
API for Transactions and Splits (journal entries)
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b.
QofBook * xaccSplitGetBook(const Split *split)
Returns the book of this split, i.e.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
void gncOwnerBeginEdit(GncOwner *owner)
These are convenience wrappers around gnc{Vendor,Customer,Job,Employee}* functions.
gboolean gncOwnerIsValid(const GncOwner *owner)
Returns TRUE if the given owner is one of the valid objects.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.
Split * gnc_lot_get_earliest_split(GNCLot *lot)
The gnc_lot_get_earliest_split() routine is a convenience routine that helps identify the earliest da...
QofInstance * qofOwnerGetOwner(const GncOwner *owner)
return the owner itself as an entity.
gnc_numeric gnc_pricedb_convert_balance_latest_price(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency)
Convert a balance from one currency to another using the most recent price between the two...
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
void gncOwnerAutoApplyPaymentsWithLots(const GncOwner *owner, GList *lots)
Given a list of lots, try to balance as many of them as possible by creating balancing transactions b...
Split * gnc_lot_get_latest_split(GNCLot *lot)
The gnc_lot_get_latest_split() routine is a convenience routine that helps identify the date this lot...
#define PWARN(format, args...)
Log a warning.
const gchar * QofIdType
QofIdType declaration.
int xaccTransCountSplits(const Transaction *trans)
Returns the number of splits in this transaction.
void xaccTransSetTxnType(Transaction *trans, char type)
Set the Transaction Type: note the type will be saved into the Transaction kvp property as a backward...
int gncOwnerGCompareFunc(const GncOwner *a, const GncOwner *b)
Same as gncOwnerEqual, but returns 0 if equal to be used as a GList custom compare function...
#define TXN_TYPE_NONE
No transaction type.
void gncOwnerApplyPaymentSecs(const GncOwner *owner, Transaction **preset_txn, GList *lots, Account *posted_acc, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, time64 date, const char *memo, const char *num, gboolean auto_pay)
A convenience function to apply a payment to the owner.
GList SplitList
GList of Split.
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
gint gncOwnerLotsSortFunc(GNCLot *lotA, GNCLot *lotB)
Helper function used to sort lots by date.
gboolean gncOwnerReduceSplitTo(Split *split, gnc_numeric target_value)
Helper function to reduce the value of a split to target_value.
gnc_numeric gncOwnerGetBalanceInCurrency(const GncOwner *owner, const gnc_commodity *report_currency)
Given an owner, extract the open balance from the owner and then convert it to the desired currency...
SplitList * gnc_lot_get_split_list(const GNCLot *lot)
The gnc_lot_get_split_list() routine returns a GList of all the splits in this lot.
time64 xaccTransRetDatePosted(const Transaction *trans)
Retrieve the posted date of the transaction.
QofIdTypeConst qofOwnerGetType(const GncOwner *owner)
return the type for the collection.
int gncOwnerCompare(const GncOwner *a, const GncOwner *b)
Sort on name.
void qofOwnerSetEntity(GncOwner *owner, QofInstance *ent)
set the owner from the entity.
void gncOwnerAttachToLot(const GncOwner *owner, GNCLot *lot)
Attach an owner to a lot.
QofIdTypeConst gncOwnerTypeToQofIdType(GncOwnerType t)
Returns the QofIdType of the given GncOwnerType, or NULL if no suitable one exists.
gpointer gncOwnerGetUndefined(const GncOwner *owner)
If the given owner is of type GNC_OWNER_UNDEFINED, returns the undefined pointer, which is usually NU...
gboolean gncOwnerGetOwnerFromLot(GNCLot *lot, GncOwner *owner)
Get the owner from the lot.
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
gnc_numeric gnc_numeric_abs(gnc_numeric a)
Returns a newly created gnc_numeric that is the absolute value of the given gnc_numeric value...
Find the least common multiple of the arguments' denominators and use that as the denominator of the ...
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
#define TXN_TYPE_LINK
Transaction is a link between (invoice and payment) lots.
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
int gncVendorCompare(const GncVendor *a, const GncVendor *b)
XXX should be renamed to RetJobList to be consistent with other usage, since caller must free the cop...
#define TXN_TYPE_PAYMENT
Transaction is a payment.
GNCLot * gncOwnerCreatePaymentLotSecs(const GncOwner *owner, Transaction **preset_txn, Account *posted_acc, Account *xfer_acc, gnc_numeric amount, gnc_numeric exch, time64 date, const char *memo, const char *num)
Create a lot for a payment to the owner using the other parameters passed in.
gboolean gnc_numeric_positive_p(gnc_numeric a)
Returns 1 if a > 0, otherwise returns 0.
Split * xaccMallocSplit(QofBook *book)
Constructor.
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr, currency, taxtable, taxtable_override taxincluded, active and jobs are identical to ::GncVendor.
gboolean GNC_IS_OWNER(QofInstance *ent)
Check if entity is an owner kind.
gnc_numeric gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a-b.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
GList * gnc_account_get_descendants(const Account *account)
This routine returns a flat list of all of the accounts that are descendants of the specified account...
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Business Invoice Interface.
GncJob * gncOwnerGetJob(const GncOwner *owner)
If the given owner is of type GNC_OWNER_JOB, returns the pointer to the job object.
void xaccTransSetDatePostedSecs(Transaction *trans, time64 secs)
The xaccTransSetDatePostedSecs() method will modify the posted date of the transaction, specified by a time64 (see ctime(3)).
Split * xaccTransGetFirstAPARAcctSplit(const Transaction *trans, gboolean strict)
The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first split in this transacti...
gboolean gncOwnerLotMatchOwnerFunc(GNCLot *lot, gpointer user_data)
Helper function used to filter a list of lots by owner.
gboolean gnc_lot_is_closed(GNCLot *lot)
The gnc_lot_is_closed() routine returns a boolean flag: is this lot closed? A lot is closed if its ba...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated account...
Split * gncOwnerFindOffsettingSplit(GNCLot *lot, gnc_numeric target_value)
Helper function to find a split in lot that best offsets target_value Obviously it should be of oppos...
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object...
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object...
time64 gnc_time(time64 *tbuf)
get the current local time
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
void gncOwnerSetLotLinkMemo(Transaction *ll_txn)
To help a user understand what a lot link transaction does, we set the memo to name all documents inv...
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Account * gnc_lot_get_account(const GNCLot *lot)
The gnc_lot_get_account() routine returns the account with which this lot is associated.
LotList * xaccAccountFindOpenLots(const Account *acc, gboolean(*match_func)(GNCLot *lot, gpointer user_data), gpointer user_data, GCompareFunc sort_func)
Find a list of open lots that match the match_func.
void xaccTransSetDateEnteredSecs(Transaction *trans, time64 secs)
Modify the date of when the transaction was entered.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object...
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
API for Transactions and Splits (journal entries)
The type used to store guids in C.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
GncOwner * gncOwnerNew(void)
These two functions are mainly for the convenience of scheme code.
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
Commodity handling public routines.
gnc_numeric gnc_lot_get_balance(GNCLot *lot)
The gnc_lot_get_balance() routine returns the balance of the lot.
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn't be...
#define NREC
not reconciled or cleared
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.