35 #include <glib/gi18n.h> 36 #include <qofinstance-p.h> 38 #include "gncCustomerP.h" 39 #include "gncEmployeeP.h" 42 #include "gncOwnerP.h" 43 #include "gncVendorP.h" 49 #include "engine-helpers.h" 51 #define _GNC_MOD_NAME GNC_ID_OWNER 53 #define GNC_OWNER_ID "gncOwner" 55 static QofLogModule log_module = GNC_MOD_ENGINE;
62 o->type = GNC_OWNER_NONE;
78 case GNC_OWNER_UNDEFINED :
80 case GNC_OWNER_CUSTOMER :
82 gncCustomerBeginEdit(owner->owner.customer);
87 gncJobBeginEdit(owner->owner.job);
90 case GNC_OWNER_VENDOR :
92 gncVendorBeginEdit(owner->owner.vendor);
95 case GNC_OWNER_EMPLOYEE :
97 gncEmployeeBeginEdit(owner->owner.employee);
103 void gncOwnerCommitEdit (
GncOwner *owner)
108 case GNC_OWNER_NONE :
109 case GNC_OWNER_UNDEFINED :
111 case GNC_OWNER_CUSTOMER :
113 gncCustomerCommitEdit(owner->owner.customer);
118 gncJobCommitEdit(owner->owner.job);
121 case GNC_OWNER_VENDOR :
123 gncVendorCommitEdit(owner->owner.vendor);
126 case GNC_OWNER_EMPLOYEE :
128 gncEmployeeCommitEdit(owner->owner.employee);
134 void gncOwnerDestroy (
GncOwner *owner)
139 case GNC_OWNER_NONE :
140 case GNC_OWNER_UNDEFINED :
142 case GNC_OWNER_CUSTOMER :
144 gncCustomerDestroy(owner->owner.customer);
149 gncJobDestroy(owner->owner.job);
152 case GNC_OWNER_VENDOR :
154 gncVendorDestroy(owner->owner.vendor);
157 case GNC_OWNER_EMPLOYEE :
159 gncEmployeeDestroy(owner->owner.employee);
165 void gncOwnerInitUndefined (
GncOwner *owner, gpointer obj)
168 owner->type = GNC_OWNER_UNDEFINED;
169 owner->owner.undefined = obj;
175 owner->type = GNC_OWNER_CUSTOMER;
176 owner->owner.customer = customer;
179 void gncOwnerInitJob (
GncOwner *owner, GncJob *job)
182 owner->type = GNC_OWNER_JOB;
183 owner->owner.job = job;
186 void gncOwnerInitVendor (
GncOwner *owner, GncVendor *vendor)
189 owner->type = GNC_OWNER_VENDOR;
190 owner->owner.vendor = vendor;
193 void gncOwnerInitEmployee (
GncOwner *owner, GncEmployee *employee)
196 owner->type = GNC_OWNER_EMPLOYEE;
197 owner->owner.employee = employee;
202 if (!owner)
return GNC_OWNER_NONE;
213 case GNC_OWNER_UNDEFINED:
214 return N_(
"Undefined");
215 case GNC_OWNER_CUSTOMER:
216 return N_(
"Customer");
219 case GNC_OWNER_VENDOR:
221 case GNC_OWNER_EMPLOYEE:
222 return N_(
"Employee");
224 PWARN (
"Unknown owner type");
240 case GNC_OWNER_NONE :
245 case GNC_OWNER_UNDEFINED :
250 case GNC_OWNER_CUSTOMER :
252 type = GNC_ID_CUSTOMER;
260 case GNC_OWNER_VENDOR :
262 type = GNC_ID_VENDOR;
265 case GNC_OWNER_EMPLOYEE :
267 type = GNC_ID_EMPLOYEE;
286 case GNC_OWNER_NONE :
290 case GNC_OWNER_UNDEFINED :
294 case GNC_OWNER_CUSTOMER :
296 ent = QOF_INSTANCE(owner->owner.customer);
301 ent = QOF_INSTANCE(owner->owner.job);
304 case GNC_OWNER_VENDOR :
306 ent = QOF_INSTANCE(owner->owner.vendor);
309 case GNC_OWNER_EMPLOYEE :
311 ent = QOF_INSTANCE(owner->owner.employee);
325 if (0 == g_strcmp0(ent->
e_type, GNC_ID_CUSTOMER))
327 owner->type = GNC_OWNER_CUSTOMER;
330 else if (0 == g_strcmp0(ent->
e_type, GNC_ID_JOB))
332 owner->type = GNC_OWNER_JOB;
333 gncOwnerInitJob(owner, (GncJob*)ent);
335 else if (0 == g_strcmp0(ent->
e_type, GNC_ID_VENDOR))
337 owner->type = GNC_OWNER_VENDOR;
338 gncOwnerInitVendor(owner, (GncVendor*)ent);
340 else if (0 == g_strcmp0(ent->
e_type, GNC_ID_EMPLOYEE))
342 owner->type = GNC_OWNER_EMPLOYEE;
343 gncOwnerInitEmployee(owner, (GncEmployee*)ent);
347 owner->type = GNC_OWNER_NONE;
348 owner->owner.undefined = NULL;
357 return (GNC_IS_VENDOR(ent) ||
358 GNC_IS_CUSTOMER(ent) ||
359 GNC_IS_EMPLOYEE(ent) ||
364 if (!owner)
return NULL;
365 if (owner->type != GNC_OWNER_UNDEFINED)
return NULL;
366 return owner->owner.undefined;
371 if (!owner)
return NULL;
372 if (owner->type != GNC_OWNER_CUSTOMER)
return NULL;
373 return owner->owner.customer;
378 if (!owner)
return NULL;
379 if (owner->type != GNC_OWNER_JOB)
return NULL;
380 return owner->owner.job;
385 if (!owner)
return NULL;
386 if (owner->type != GNC_OWNER_VENDOR)
return NULL;
387 return owner->owner.vendor;
392 if (!owner)
return NULL;
393 if (owner->type != GNC_OWNER_EMPLOYEE)
return NULL;
394 return owner->owner.employee;
399 if (!src || !dest)
return;
400 if (src == dest)
return;
406 if (!a || !b)
return FALSE;
408 return (a->owner.undefined == b->owner.undefined);
419 const char * gncOwnerGetID (
const GncOwner *owner)
421 if (!owner)
return NULL;
425 case GNC_OWNER_UNDEFINED:
428 case GNC_OWNER_CUSTOMER:
429 return gncCustomerGetID (owner->owner.customer);
431 return gncJobGetID (owner->owner.job);
432 case GNC_OWNER_VENDOR:
433 return gncVendorGetID (owner->owner.vendor);
434 case GNC_OWNER_EMPLOYEE:
435 return gncEmployeeGetID (owner->owner.employee);
439 const char * gncOwnerGetName (
const GncOwner *owner)
441 if (!owner)
return NULL;
445 case GNC_OWNER_UNDEFINED:
448 case GNC_OWNER_CUSTOMER:
449 return gncCustomerGetName (owner->owner.customer);
451 return gncJobGetName (owner->owner.job);
452 case GNC_OWNER_VENDOR:
453 return gncVendorGetName (owner->owner.vendor);
454 case GNC_OWNER_EMPLOYEE:
455 return gncEmployeeGetName (owner->owner.employee);
461 if (!owner)
return NULL;
465 case GNC_OWNER_UNDEFINED:
469 case GNC_OWNER_CUSTOMER:
470 return gncCustomerGetAddr (owner->owner.customer);
471 case GNC_OWNER_VENDOR:
472 return gncVendorGetAddr (owner->owner.vendor);
473 case GNC_OWNER_EMPLOYEE:
474 return gncEmployeeGetAddr (owner->owner.employee);
478 gnc_commodity * gncOwnerGetCurrency (
const GncOwner *owner)
480 if (!owner)
return NULL;
484 case GNC_OWNER_UNDEFINED:
487 case GNC_OWNER_CUSTOMER:
488 return gncCustomerGetCurrency (owner->owner.customer);
489 case GNC_OWNER_VENDOR:
490 return gncVendorGetCurrency (owner->owner.vendor);
491 case GNC_OWNER_EMPLOYEE:
492 return gncEmployeeGetCurrency (owner->owner.employee);
494 return gncOwnerGetCurrency (gncJobGetOwner (owner->owner.job));
498 gboolean gncOwnerGetActive (
const GncOwner *owner)
500 if (!owner)
return FALSE;
504 case GNC_OWNER_UNDEFINED:
507 case GNC_OWNER_CUSTOMER:
508 return gncCustomerGetActive (owner->owner.customer);
509 case GNC_OWNER_VENDOR:
510 return gncVendorGetActive (owner->owner.vendor);
511 case GNC_OWNER_EMPLOYEE:
512 return gncEmployeeGetActive (owner->owner.employee);
514 return gncJobGetActive (owner->owner.job);
520 if (!owner)
return NULL;
525 case GNC_OWNER_UNDEFINED:
528 case GNC_OWNER_CUSTOMER:
532 case GNC_OWNER_VENDOR:
534 case GNC_OWNER_EMPLOYEE:
540 gncOwnerSetActive (
const GncOwner *owner, gboolean active)
545 case GNC_OWNER_CUSTOMER:
546 gncCustomerSetActive (owner->owner.customer, active);
548 case GNC_OWNER_VENDOR:
549 gncVendorSetActive (owner->owner.vendor, active);
551 case GNC_OWNER_EMPLOYEE:
552 gncEmployeeSetActive (owner->owner.employee, active);
555 gncJobSetActive (owner->owner.job, active);
558 case GNC_OWNER_UNDEFINED:
574 if (!owner)
return NULL;
578 case GNC_OWNER_UNDEFINED:
581 case GNC_OWNER_CUSTOMER:
582 case GNC_OWNER_VENDOR:
583 case GNC_OWNER_EMPLOYEE:
586 return gncJobGetOwner (owner->owner.job);
592 if (!a && !b)
return 0;
593 if (!a && b)
return 1;
594 if (a && !b)
return -1;
596 if (a->type != b->type)
597 return (a->type - b->type);
602 case GNC_OWNER_UNDEFINED:
605 case GNC_OWNER_CUSTOMER:
606 return gncCustomerCompare (a->owner.customer, b->owner.customer);
607 case GNC_OWNER_VENDOR:
609 case GNC_OWNER_EMPLOYEE:
610 return gncEmployeeCompare (a->owner.employee, b->owner.employee);
612 return gncJobCompare (a->owner.job, b->owner.job);
618 if (!owner)
return NULL;
627 gnc_lot_begin_edit (lot);
633 gnc_lot_commit_edit (lot);
640 GncOwnerType type = GNC_OWNER_NONE;
643 if (!lot || !owner)
return FALSE;
645 book = gnc_lot_get_book (lot);
647 GNC_OWNER_TYPE, &type64,
648 GNC_OWNER_GUID, &guid,
650 type = (GncOwnerType) type64;
653 case GNC_OWNER_CUSTOMER:
654 gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
656 case GNC_OWNER_VENDOR:
657 gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
659 case GNC_OWNER_EMPLOYEE:
660 gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
663 gncOwnerInitJob (owner, gncJobLookup (book, guid));
671 return (owner->owner.undefined != NULL);
676 Split *apar_split = NULL;
678 if (!txn || !owner)
return FALSE;
689 gncOwnerCopy (gncInvoiceGetOwner (invoice), owner);
701 if (!owner)
return FALSE;
702 return (owner->owner.undefined != NULL);
708 const GncOwner *req_owner = user_data;
737 da = gncInvoiceGetDateDue (ia);
742 db = gncInvoiceGetDateDue (ib);
746 return (da > db) - (da < db);
752 gnc_numeric amount, gnc_numeric exch,
time64 date,
753 const char *memo,
const char *num)
758 gnc_commodity *post_comm, *xfer_comm;
759 Split *xfer_split = NULL;
760 Transaction *txn = NULL;
762 gnc_numeric xfer_amount = gnc_numeric_zero();
763 gnc_numeric txn_value = gnc_numeric_zero();
766 if (!owner || !posted_acc || !xfer_acc)
return NULL;
767 g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
770 book = gnc_account_get_book (posted_acc);
777 if (preset_txn && *preset_txn)
787 xfer_split = xaccTransFindSplitByAccount(txn, xfer_acc);
792 if (split == xfer_split)
818 xfer_amount = amount;
836 gnc_set_num_action (NULL, xfer_split, num, _(
"Payment"));
868 payment_lot = gnc_lot_new (book);
899 Split *best_split = NULL;
900 gnc_numeric best_amt = { 0, 1};
908 Split *split = ls_iter->data;
919 PWARN(
"Encountered a split in a payment lot that's not part of any transaction. " 920 "This is unexpected! Skipping split %p.", split);
935 new_flags += is_equal;
936 else if (amt_cmp > 0)
937 new_flags += is_more;
939 new_flags += is_less;
942 new_flags += is_pay_split;
944 if ((new_flags >= best_flags) &&
950 best_flags = new_flags;
951 best_amt = split_amount;
999 xaccSplitSetParent (rem_split, txn);
1012 gchar *memo_prefix = _(
"Offset between documents: ");
1016 GList *titles = NULL, *titer;
1027 Split *split = lts_iter->data;
1029 GncInvoice *invoice;
1043 title = g_strdup_printf (
"%s %s", gncInvoiceGetTypeString (invoice), gncInvoiceGetID (invoice));
1045 titles = g_list_prepend (titles, title);
1046 splits = g_list_prepend (splits, split);
1052 titles = g_list_sort (titles, (GCompareFunc)g_strcmp0);
1055 new_memo = g_strconcat (memo_prefix, titles->data, NULL);
1056 for (titer = titles->next; titer; titer = titer->next)
1058 gchar *tmp_memo = g_strconcat (new_memo,
" - ", titer->data, NULL);
1060 new_memo = tmp_memo;
1062 g_list_free_full (titles, g_free);
1065 for (siter = splits; siter; siter = siter->next)
1071 g_list_free (splits);
1080 static Transaction *
1081 get_ll_transaction_from_lot (GNCLot *lot)
1094 Split *ls = ls_iter->data;
1103 Split *ts = ts_iter->data;
1122 gncOwnerCreateLotLink (GNCLot *from_lot, GNCLot *to_lot,
const GncOwner *owner)
1124 const gchar *action = _(
"Lot Link");
1127 Transaction *ll_txn = NULL;
1128 gnc_numeric from_lot_bal, to_lot_bal;
1129 time64 from_time, to_time;
1141 if (from_time >= to_time)
1142 time_posted = from_time;
1144 time_posted = to_time;
1158 ll_txn = get_ll_transaction_from_lot (from_lot);
1161 ll_txn = get_ll_transaction_from_lot (to_lot);
1180 if (time_posted > time)
1187 gnc_set_num_action (NULL, split, NULL, action);
1197 gnc_set_num_action (NULL, split, NULL, action);
1221 static void gncOwnerOffsetLots (GNCLot *from_lot, GNCLot *to_lot,
const GncOwner *owner)
1223 gnc_numeric target_offset;
1229 PWARN (
"from_lot %p is a document lot. That is not allowed in gncOwnerOffsetLots", from_lot);
1272 for (left_iter = lots; left_iter; left_iter = left_iter->next)
1274 GNCLot *left_lot = left_iter->data;
1275 gnc_numeric left_lot_bal;
1276 gboolean left_lot_has_doc;
1277 gboolean left_modified = FALSE;
1287 if (gnc_lot_count_splits (left_lot) == 0)
1289 gnc_lot_destroy (left_lot);
1290 left_iter->data = NULL;
1306 for (right_iter = left_iter->next; right_iter; right_iter = right_iter->next)
1308 GNCLot *right_lot = right_iter->data;
1309 gnc_numeric right_lot_bal;
1310 gboolean right_lot_has_doc;
1318 if (gnc_lot_count_splits (right_lot) == 0)
1320 gnc_lot_destroy (right_lot);
1321 right_iter->data = NULL;
1351 if (left_lot_has_doc && right_lot_has_doc)
1352 gncOwnerCreateLotLink (left_lot, right_lot, owner);
1353 else if (!left_lot_has_doc && !right_lot_has_doc)
1358 gncOwnerOffsetLots (left_lot, right_lot, owner);
1360 gncOwnerOffsetLots (right_lot, left_lot, owner);
1364 GNCLot *doc_lot = left_lot_has_doc ? left_lot : right_lot;
1365 GNCLot *pay_lot = left_lot_has_doc ? right_lot : left_lot;
1367 gncOwnerOffsetLots (pay_lot, doc_lot, owner);
1377 qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
1379 left_modified = TRUE;
1389 qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
1407 gnc_numeric amount, gnc_numeric exch,
time64 date,
1408 const char *memo,
const char *num, gboolean auto_pay)
1410 GNCLot *payment_lot = NULL;
1411 GList *selected_lots = NULL;
1414 if (!owner || !posted_acc
1416 g_return_if_fail (owner->owner.undefined);
1419 selected_lots = lots;
1422 (gpointer)owner, NULL);
1427 posted_acc, xfer_acc,
1428 amount, exch, date, memo,
1437 selected_lots = g_list_prepend (selected_lots, payment_lot);
1440 g_list_free (selected_lots);
1446 g_return_val_if_fail (owner, NULL);
1450 case GNC_OWNER_CUSTOMER:
1452 case GNC_OWNER_VENDOR:
1453 case GNC_OWNER_EMPLOYEE:
1464 g_return_val_if_fail (owner, NULL);
1465 g_return_val_if_fail (gncOwnerGetCurrency(owner), NULL);
1467 return (g_list_prepend (NULL, gncOwnerGetCurrency(owner)));
1479 const gnc_commodity *report_currency)
1481 gnc_numeric balance = gnc_numeric_zero ();
1483 gnc_commodity *owner_currency;
1485 const gnc_numeric *cached_balance = NULL;
1487 g_return_val_if_fail (owner, gnc_numeric_zero ());
1490 owner_currency = gncOwnerGetCurrency (owner);
1492 cached_balance = gncOwnerGetCachedBalance (owner);
1494 balance = *cached_balance;
1503 for (acct_node = acct_list; acct_node; acct_node = acct_node->next)
1505 Account *account = acct_node->data;
1506 GList *lot_list = NULL, *lot_node;
1519 (gpointer)owner, NULL);
1521 for (lot_node = lot_list; lot_node; lot_node = lot_node->next)
1523 GNCLot *lot = lot_node->data;
1530 g_list_free (lot_list);
1532 g_list_free (acct_list);
1533 g_list_free (acct_types);
1535 gncOwnerSetCachedBalance (owner, &balance);
1540 if (report_currency)
1542 pdb, balance, owner_currency, report_currency);
1552 owner_from_lot (GNCLot *lot)
1556 if (!lot)
return NULL;
1566 static QofParam params[] =
1568 { OWNER_FROM_LOT, _GNC_MOD_NAME, (
QofAccessFunc)owner_from_lot, NULL },
1577 if (!book || !owner || !type || !guid)
return FALSE;
1579 if (0 == g_strcmp0(type, GNC_ID_CUSTOMER))
1581 GncCustomer *customer = gncCustomerLookup(book, guid);
1582 gncOwnerInitCustomer(owner, customer);
1583 return (NULL != customer);
1585 else if (0 == g_strcmp0(type, GNC_ID_JOB))
1587 GncJob *job = gncJobLookup(book, guid);
1588 gncOwnerInitJob(owner, job);
1589 return (NULL != job);
1591 else if (0 == g_strcmp0(type, GNC_ID_VENDOR))
1593 GncVendor *vendor = gncVendorLookup(book, guid);
1594 gncOwnerInitVendor(owner, vendor);
1595 return (NULL != vendor);
1597 else if (0 == g_strcmp0(type, GNC_ID_EMPLOYEE))
1599 GncEmployee *employee = gncEmployeeLookup(book, guid);
1600 gncOwnerInitEmployee(owner, employee);
1601 return (NULL != employee);
1606 gboolean gncOwnerRegister (
void)
1608 static QofParam params[] =
1616 { OWNER_PARENTG, QOF_TYPE_GUID, (
QofAccessFunc)gncOwnerGetEndGUID, NULL },
1617 { OWNER_NAME, QOF_TYPE_STRING, (
QofAccessFunc)gncOwnerGetName, NULL },
1629 gncOwnerGetCachedBalance (
const GncOwner *owner)
1631 if (!owner)
return NULL;
1643 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...
All arguments are required to have the same denominator, that denominator is to be used in the output...
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)
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.
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)
Convenience routine to identify the earliest date in the lot.
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)
Convenience routineto identify the date this lot was closed.
#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...
Find the least common multiple of the arguments' denominators and use that as the denominator of the ...
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.
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)
Returns a list 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...
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
#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...
QofIdType e_type
Entity type.
gboolean gncOwnerLotMatchOwnerFunc(GNCLot *lot, gpointer user_data)
Helper function used to filter a list of lots by owner.
Split * gncOwnerFindOffsettingSplit(GNCLot *lot, gnc_numeric target_amount)
Helper function to find a split in lot that best offsets target_amount Obviously it should be of oppo...
gboolean gnc_lot_is_closed(GNCLot *lot)
Returns closed status of the given lot.
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...
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
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 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
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Account * gnc_lot_get_account(const GNCLot *lot)
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.
gboolean gncOwnerReduceSplitTo(Split *split, gnc_numeric target_amount)
Helper function to reduce the amount of a split to target_amount.
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)
Returns the lot balance.
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.