36 #include <glib/gi18n.h> 48 #include "TransactionP.hpp" 59 #include <qofinstance-p.h> 174 const char *trans_notes_str =
"notes";
175 const char *void_reason_str =
"void-reason";
176 const char *void_time_str =
"void-time";
177 const char *void_former_notes_str =
"void-former-notes";
178 const char *trans_is_closing_str =
"book_closing";
179 const char *doclink_uri_str =
"assoc_uri";
182 #define TRANS_DATE_DUE_KVP "trans-date-due" 183 #define TRANS_TXN_TYPE_KVP "trans-txn-type" 184 #define TRANS_READ_ONLY_REASON "trans-read-only" 185 #define TRANS_REVERSED_BY "reversed-by" 186 #define GNC_SX_FROM "from-sched-xaction" 188 #define ISO_DATELENGTH 32 191 static QofLogModule log_module = GNC_MOD_ENGINE;
207 check_open (
const Transaction *trans)
209 if (trans && 0 >= qof_instance_get_editlevel(trans))
210 PERR (
"transaction %p not open for editing", trans);
215 xaccTransStillHasSplit(
const Transaction *trans,
const Split *s)
222 #define FOR_EACH_SPLIT(trans, cmd_block) if (trans->splits) { \ 224 for (splits = (trans)->splits; splits; splits = splits->next) { \ 225 Split *s = GNC_SPLIT(splits->data); \ 226 if (xaccTransStillHasSplit(trans, s)) { \ 232 static inline void mark_trans (Transaction *trans);
233 void mark_trans (Transaction *trans)
235 FOR_EACH_SPLIT(trans, mark_split(s));
238 static inline void gen_event_trans (Transaction *trans);
239 void gen_event_trans (Transaction *trans)
243 for (node = trans->splits; node; node = node->next)
245 Split *s = GNC_SPLIT(node->data);
247 GNCLot *lot = s->lot;
254 qof_event_gen (QOF_INSTANCE(lot), QOF_EVENT_MODIFY,
nullptr);
260 G_DEFINE_TYPE(Transaction, gnc_transaction, QOF_TYPE_INSTANCE)
263 gnc_transaction_init(Transaction* trans)
265 ENTER (
"trans=%p", trans);
267 trans->num = CACHE_INSERT(
"");
268 trans->description = CACHE_INSERT(
"");
269 trans->common_currency =
nullptr;
270 trans->splits =
nullptr;
271 trans->date_entered = 0;
272 trans->date_posted = 0;
274 trans->orig =
nullptr;
275 trans->txn_type = TXN_TYPE_UNCACHED;
280 gnc_transaction_dispose(GObject *txnp)
282 G_OBJECT_CLASS(gnc_transaction_parent_class)->dispose(txnp);
286 gnc_transaction_finalize(GObject* txnp)
288 G_OBJECT_CLASS(gnc_transaction_parent_class)->finalize(txnp);
298 gnc_transaction_get_property(GObject*
object,
306 g_return_if_fail(GNC_IS_TRANSACTION(
object));
308 tx = GNC_TRANSACTION(
object);
312 g_value_set_string(value, tx->num);
314 case PROP_DESCRIPTION:
315 g_value_set_string(value, tx->description);
318 g_value_take_object(value, tx->common_currency);
321 time.t = tx->date_posted;
322 g_value_set_boxed(value, &time);
324 case PROP_ENTER_DATE:
325 time.t = tx->date_entered;
326 g_value_set_boxed(value, &time);
334 case PROP_ONLINE_ACCOUNT:
338 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
344 gnc_transaction_set_property(GObject*
object,
352 g_return_if_fail(GNC_IS_TRANSACTION(
object));
354 tx = GNC_TRANSACTION(
object);
355 g_assert (qof_instance_get_editlevel(tx));
362 case PROP_DESCRIPTION:
369 t = (
Time64*)g_value_get_boxed(value);
372 case PROP_ENTER_DATE:
373 t = (
Time64*)g_value_get_boxed(value);
382 case PROP_ONLINE_ACCOUNT:
386 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
392 gnc_transaction_class_init(TransactionClass* klass)
394 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
396 gobject_class->dispose = gnc_transaction_dispose;
397 gobject_class->finalize = gnc_transaction_finalize;
398 gobject_class->set_property = gnc_transaction_set_property;
399 gobject_class->get_property = gnc_transaction_get_property;
401 g_object_class_install_property
404 g_param_spec_string(
"num",
405 "Transaction Number",
406 "The transactionNumber is an arbitrary string " 407 "assigned by the user. It is intended to be " 408 "a short 1-6 character string that is displayed " 409 "by the register. For checks, it is usually the " 410 "check number. For other types of transactions, " 411 "it can be any string.",
415 g_object_class_install_property
418 g_param_spec_string(
"description",
419 "Transaction Description",
420 "The transaction description is an arbitrary string " 421 "assigned by the user. It is usually the customer, " 422 "vendor or other organization associated with the " 427 g_object_class_install_property
430 g_param_spec_object (
"currency",
432 "The base currency for this transaction.",
436 g_object_class_install_property
439 g_param_spec_boxed(
"post-date",
441 "The date the transaction occurred.",
445 g_object_class_install_property
448 g_param_spec_boxed(
"enter-date",
450 "The date the transaction was entered.",
454 g_object_class_install_property(
457 g_param_spec_boxed(
"invoice",
458 "Invoice attached to lot",
459 "Used by GncInvoice",
463 g_object_class_install_property(
466 g_param_spec_boxed(
"from-sched-xaction",
467 "From Scheduled Transaction",
468 "Used by Scheduled Transastions to record the " 469 "originating template transaction for created " 474 g_object_class_install_property
477 g_param_spec_string (
"online-id",
479 "The online account which corresponds to this " 480 "account for OFX/HCBI import",
491 xaccInitTransaction (Transaction * trans, QofBook *book)
493 ENTER (
"trans=%p", trans);
506 g_return_val_if_fail (book,
nullptr);
508 trans = GNC_TRANSACTION(g_object_new(GNC_TYPE_TRANSACTION,
nullptr));
509 xaccInitTransaction (trans, book);
515 #ifdef DUMP_FUNCTIONS 521 xaccTransDump (
const Transaction *trans,
const char *tag)
526 printf(
"%s Trans %p", tag, trans);
527 memset(datebuff, 0,
sizeof(datebuff));
529 printf(
" Entered: %s\n", datebuff);
530 memset(datebuff, 0,
sizeof(datebuff));
532 printf(
" Posted: %s\n", datebuff);
533 printf(
" Num: %s\n", trans->num ? trans->num :
"(null)");
534 printf(
" Description: %s\n",
535 trans->description ? trans->description :
"(null)");
536 printf(
" Currency: %s\n",
538 printf(
" version: %x\n", qof_instance_get_version(trans));
539 printf(
" version_chk: %x\n", qof_instance_get_version_check(trans));
540 printf(
" editlevel: %x\n", qof_instance_get_editlevel(trans));
541 printf(
" orig: %p\n", trans->orig);
544 for (node = trans->splits; node; node = node->next)
546 printf(
"%p ", node->data);
549 for (node = trans->splits; node; node = node->next)
551 xaccSplitDump(GNC_SPLIT(node->data), tag);
560 GList *node, *new_list =
nullptr;
564 for (node = trans->splits; node; node = node->next)
566 split = GNC_SPLIT(node->data);
569 new_list = g_list_prepend (new_list, split);
573 for (node = trans->splits; node; node = node->next)
575 split = GNC_SPLIT(node->data);
578 new_list = g_list_prepend (new_list, split);
582 g_list_free(trans->splits);
583 trans->splits = g_list_reverse (new_list);
595 dupe_trans (
const Transaction *from)
600 to = GNC_TRANSACTION(g_object_new (GNC_TYPE_TRANSACTION,
nullptr));
602 CACHE_REPLACE (to->num, from->num);
603 CACHE_REPLACE (to->description, from->description);
605 to->splits = g_list_copy (from->splits);
606 for (node = to->splits; node; node = node->next)
608 node->data = xaccDupeSplit (GNC_SPLIT(node->data));
611 to->date_entered = from->date_entered;
612 to->date_posted = from->date_posted;
613 qof_instance_copy_version(to, from);
616 to->common_currency = from->common_currency;
622 to->inst.e_type =
nullptr;
625 qof_instance_copy_kvp (QOF_INSTANCE(to), QOF_INSTANCE(from));
643 to = GNC_TRANSACTION(g_object_new (GNC_TYPE_TRANSACTION,
nullptr));
645 to->date_entered = from->date_entered;
646 to->date_posted = from->date_posted;
647 CACHE_REPLACE (to->num, from->num);
648 CACHE_REPLACE (to->description, from->description);
649 to->common_currency = from->common_currency;
650 qof_instance_copy_version(to, from);
651 qof_instance_copy_version_check(to, from);
659 for (node = from->splits; node; node = node->next)
661 split = xaccSplitCloneNoKvp(GNC_SPLIT(node->data));
663 to->splits = g_list_append (to->splits, split);
665 qof_instance_set_dirty(QOF_INSTANCE(to));
677 if (g_list_length (to->splits) != g_list_length (from->splits))
679 PERR (
"Cloned transaction has different number of splits from original");
685 qof_instance_copy_kvp (QOF_INSTANCE (to), QOF_INSTANCE (from));
690 for (GList* lfrom = from->splits, *lto = to->splits; lfrom && lto;
691 lfrom = g_list_next (lfrom), lto = g_list_next (lto))
692 xaccSplitCopyKvp (GNC_SPLIT(lfrom->data), GNC_SPLIT(lto->data));
707 Transaction *to_trans;
712 to_trans = dupe_trans(from_trans);
748 gboolean change_accounts = FALSE;
751 if (!from_trans || !to_trans)
754 change_accounts = from_acc && GNC_IS_ACCOUNT(to_acc) && from_acc != to_acc;
772 for (node = from_trans->splits; node; node = node->next)
777 xaccSplitSetAccount(new_split, to_acc);
778 xaccSplitSetParent(new_split, to_trans);
789 xaccFreeTransaction (Transaction *trans)
793 ENTER (
"(addr=%p)", trans);
794 if (((
char *) 1) == trans->num)
796 PERR (
"double-free %p", trans);
802 g_list_free_full (trans->splits, (GDestroyNotify)xaccFreeSplit);
803 trans->splits =
nullptr;
806 CACHE_REMOVE(trans->num);
807 CACHE_REMOVE(trans->description);
810 trans->num = (
char *) 1;
811 trans->description =
nullptr;
812 trans->date_entered = 0;
813 trans->date_posted = 0;
816 xaccFreeTransaction (trans->orig);
817 trans->orig =
nullptr;
821 g_object_unref(trans);
823 LEAVE (
"(addr=%p)", trans);
838 compare_split_guids (gconstpointer a, gconstpointer b)
840 const Split *sa = GNC_SPLIT(a);
841 const Split *sb = GNC_SPLIT(b);
843 if (sa == sb)
return 0;
844 if (!sa || !sb)
return 1;
851 gboolean check_guids,
852 gboolean check_splits,
853 gboolean check_balances,
854 gboolean assume_ordered)
858 if (!ta && !tb)
return TRUE;
862 PINFO (
"one is nullptr");
866 if (ta == tb)
return TRUE;
874 PINFO (
"GUIDs differ");
881 PINFO (
"commodities differ %s vs %s",
887 if (ta->date_entered != tb->date_entered)
894 PINFO (
"date entered differs: '%s' vs '%s'", buf1, buf2);
898 if (ta->date_posted != tb->date_posted)
905 PINFO (
"date posted differs: '%s' vs '%s'", buf1, buf2);
912 if ((same_book && ta->num != tb->num) || (!same_book && g_strcmp0(ta->num, tb->num) != 0))
914 PINFO (
"num differs: %s vs %s", ta->num, tb->num);
918 if ((same_book && ta->description != tb->description)
919 || (!same_book && g_strcmp0(ta->description, tb->description)))
921 PINFO (
"descriptions differ: %s vs %s", ta->description, tb->description);
925 if (qof_instance_compare_kvp (QOF_INSTANCE (ta), QOF_INSTANCE (tb)) != 0)
930 frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (ta));
931 frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (tb));
934 PINFO (
"kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
944 if ((!ta->splits && tb->splits) || (!tb->splits && ta->splits))
946 PINFO (
"only one has splits");
950 if (ta->splits && tb->splits)
952 GList *node_a, *node_b;
954 for (node_a = ta->splits, node_b = tb->splits;
956 node_a = node_a->next, node_b = node_b->next)
958 Split *split_a = GNC_SPLIT(node_a->data);
963 node_b = g_list_find_custom (tb->splits, split_a,
964 compare_split_guids);
971 PINFO (
"first has split %s and second does not",guidstr);
975 split_b = GNC_SPLIT(node_b->data);
977 if (!
xaccSplitEqual (split_a, split_b, check_guids, check_balances,
986 PINFO (
"splits %s and %s differ", str_a, str_b);
991 if (g_list_length (ta->splits) != g_list_length (tb->splits))
993 PINFO (
"different number of splits");
1021 if (!guid || !book)
return nullptr;
1032 gnc_numeric imbal = gnc_numeric_zero();
1033 if (!trans)
return imbal;
1035 ENTER(
"(trans=%p)", trans);
1038 FOR_EACH_SPLIT(trans, imbal =
1052 MonetaryList *imbal_list =
nullptr;
1053 gnc_numeric imbal_value = gnc_numeric_zero();
1054 gboolean trading_accts;
1056 if (!trans)
return imbal_list;
1058 ENTER(
"(trans=%p)", trans);
1070 FOR_EACH_SPLIT(trans,
1072 gnc_commodity *commodity;
1074 if (trading_accts &&
1085 imbal_list = gnc_monetary_list_add_value(imbal_list,
1086 trans->common_currency,
1089 imbal_list = gnc_monetary_list_add_value(imbal_list, commodity,
1104 imbal_list = gnc_monetary_list_add_value(imbal_list,
1105 trans->common_currency,
1113 LEAVE(
"(trans=%p), imbal=%p", trans, imbal_list);
1120 MonetaryList *imbal_list;
1122 gnc_numeric imbal = gnc_numeric_zero();
1123 gnc_numeric imbal_trading = gnc_numeric_zero();
1125 if (trans ==
nullptr)
return FALSE;
1132 FOR_EACH_SPLIT(trans,
1158 result = imbal_list ==
nullptr;
1167 gnc_numeric total = gnc_numeric_zero ();
1168 if (!trans || !acc)
return total;
1182 gnc_numeric total = gnc_numeric_zero ();
1183 if (!trans || !acc)
return total;
1188 total = gnc_numeric_add_fixed(
1194 xaccTransGetAccountConvRate(
const Transaction *txn,
const Account *acc)
1196 gnc_numeric amount, value, convrate;
1199 gboolean found_acc_match = FALSE;
1208 return gnc_numeric_create(1, 1);
1210 for (splits = txn->splits; splits; splits = splits->next)
1213 gnc_commodity *split_commod;
1215 s = GNC_SPLIT(splits->data);
1217 if (!xaccTransStillHasSplit(txn, s))
1221 if (! (split_acc == acc ||
1225 found_acc_match = TRUE;
1234 PWARN(
"How can amount be nonzero and value be zero?");
1245 if (found_acc_match)
1246 return gnc_numeric_zero();
1248 PERR(
"Cannot convert transaction -- no splits with proper conversion ratio");
1250 return gnc_numeric_create (100, 100);
1258 Split *last_split =
nullptr;
1263 for (node = trans->splits; node; node = node->next)
1265 Split *split = GNC_SPLIT(node->data);
1267 if (!xaccTransStillHasSplit(trans, split))
1294 return trans ? trans->common_currency :
nullptr;
1299 find_new_rate(Transaction *trans, gnc_commodity *curr)
1302 gnc_numeric rate = gnc_numeric_zero();
1303 for (node = trans->splits; node !=
nullptr; node = g_list_next (node))
1305 Split *split = GNC_SPLIT(node->data);
1306 gnc_commodity *split_com =
1322 split_set_new_value(Split* split, gnc_commodity *curr, gnc_commodity *old_curr,
1325 gnc_commodity *split_com =
1353 gnc_commodity *old_curr = trans->common_currency;
1354 if (!trans || !curr || trans->common_currency == curr)
return;
1357 trans->common_currency = curr;
1358 if (old_curr !=
nullptr && trans->splits !=
nullptr)
1360 gnc_numeric rate = find_new_rate(trans, curr);
1363 FOR_EACH_SPLIT(trans, split_set_new_value(s, curr, old_curr, rate));
1371 qof_instance_set_dirty(QOF_INSTANCE(trans));
1395 trans->orig = dupe_trans (trans);
1410 qof_instance_set_destroying(trans, TRUE);
1416 destroy_gains (Transaction *trans)
1419 for (node = trans->splits; node; node = node->next)
1421 Split *s = GNC_SPLIT(node->data);
1422 if (!xaccTransStillHasSplit(trans, s))
1425 if (GAINS_STATUS_UNKNOWN == s->gains) xaccSplitDetermineGainStatus(s);
1426 if (s->gains_split && (GAINS_STATUS_GAINS & s->gains_split->gains))
1428 Transaction *t = s->gains_split->parent;
1430 s->gains_split =
nullptr;
1438 Transaction *trans{GNC_TRANSACTION (inst)};
1445 destroy_gains (trans);
1456 xaccFreeTransaction (trans);
1463 static int scrub_data = 1;
1464 void xaccEnableDataScrubbing(
void)
1468 void xaccDisableDataScrubbing(
void)
1474 static gboolean was_trans_emptied(Transaction *trans)
1476 FOR_EACH_SPLIT(trans,
return FALSE);
1482 Transaction *trans{GNC_TRANSACTION(inst)};
1490 PWARN(
"Another user has modified this transaction\n" 1491 "\tjust a moment ago. Please look at their changes,\n" 1492 "\tand try again, if needed.\n");
1496 gnc_engine_signal_commit_error( errcode );
1499 static void trans_cleanup_commit(
QofInstance *inst)
1501 Transaction *trans{GNC_TRANSACTION(inst)};
1502 GList *slist, *node;
1509 slist = g_list_copy(trans->splits);
1510 for (node = slist; node; node = node->next)
1512 Split *s = GNC_SPLIT(node->data);
1522 ed.idx = g_list_index(trans->splits, s);
1523 trans->splits = g_list_remove(trans->splits, s);
1527 if (s->parent == trans)
1533 xaccSplitCommitEdit(s);
1543 PINFO (
"get rid of rollback trans=%p", trans->orig);
1544 xaccFreeTransaction (trans->orig);
1545 trans->orig =
nullptr;
1552 qof_instance_decrease_editlevel(trans);
1553 g_assert(qof_instance_get_editlevel(trans) == 0);
1555 gen_event_trans (trans);
1563 ENTER (
"(trans=%p)", trans);
1567 LEAVE(
"editlevel non-zero");
1574 qof_instance_increase_editlevel(trans);
1576 if (was_trans_emptied(trans))
1577 qof_instance_set_destroying(trans, TRUE);
1601 if (g_getenv(
"GNC_AUTO_SCRUB_LOTS") !=
nullptr)
1609 if (0 == trans->date_entered)
1611 trans->date_entered =
gnc_time(
nullptr);
1612 qof_instance_set_dirty(QOF_INSTANCE(trans));
1615 trans->txn_type = TXN_TYPE_UNCACHED;
1617 trans_cleanup_commit, do_destroy);
1618 LEAVE (
"(trans=%p)", trans);
1632 GList *node, *onode;
1636 int num_preexist, i;
1645 if (!qof_instance_get_editlevel (QOF_INSTANCE (trans)))
return;
1646 if (qof_instance_get_editlevel (QOF_INSTANCE (trans)) > 1) {
1647 qof_instance_decrease_editlevel (QOF_INSTANCE (trans));
1651 ENTER (
"trans addr=%p\n", trans);
1658 std::swap (trans->num, orig->num);
1659 std::swap (trans->description, orig->description);
1660 trans->date_entered = orig->date_entered;
1661 trans->date_posted = orig->date_posted;
1662 std::swap (trans->common_currency, orig->common_currency);
1663 qof_instance_swap_kvp (QOF_INSTANCE (trans), QOF_INSTANCE (orig));
1671 num_preexist = g_list_length(orig->splits);
1672 slist = g_list_copy(trans->splits);
1673 for (i = 0, node = slist, onode = orig->splits; node;
1674 i++, node = node->next, onode = onode ? onode->next :
nullptr)
1676 Split *s = GNC_SPLIT(node->data);
1681 if (i < num_preexist && onode)
1683 Split *so = GNC_SPLIT(onode->data);
1685 xaccSplitRollbackEdit(s);
1686 std::swap (s->action, so->action);
1687 std::swap (s->memo, so->memo);
1688 qof_instance_copy_kvp (QOF_INSTANCE (s), QOF_INSTANCE (so));
1689 s->reconciled = so->reconciled;
1690 s->amount = so->amount;
1691 s->value = so->value;
1693 s->gains_split = so->gains_split;
1695 s->date_reconciled = so->date_reconciled;
1696 qof_instance_mark_clean(QOF_INSTANCE(s));
1703 trans->splits = g_list_remove(trans->splits, s);
1708 xaccSplitRollbackEdit(s);
1709 trans->splits = g_list_remove(trans->splits, s);
1725 g_list_free_full (orig->splits, (GDestroyNotify)xaccFreeSplit);
1726 orig->splits =
nullptr;
1733 if (qof_backend_can_rollback (be))
1742 while (ERR_BACKEND_NO_ERR != errcode);
1744 qof_backend_rollback_instance (be, &(trans->inst));
1755 do_destroy (QOF_INSTANCE(trans));
1759 LEAVE (
"deleted trans addr=%p\n", trans);
1762 if (ERR_BACKEND_NO_ERR != errcode)
1764 PERR (
"Rollback Failed. Ouch!");
1773 xaccFreeTransaction (trans->orig);
1775 trans->orig =
nullptr;
1776 qof_instance_set_destroying(trans, FALSE);
1779 qof_instance_decrease_editlevel(trans);
1783 gen_event_trans (trans);
1785 LEAVE (
"trans addr=%p\n", trans);
1791 return trans ? (0 < qof_instance_get_editlevel(trans)) : FALSE;
1794 #define SECS_PER_DAY 86400 1813 order_by_int64_or_string (
const char* a,
const char* b)
1815 char *end_a =
nullptr, *end_b =
nullptr;
1817 uint64_t na = strtoull(a, &end_a, 10);
1818 uint64_t nb = strtoull(b, &end_b, 10);
1822 return na < nb ? -1 : 1;
1823 cmp = g_utf8_collate(end_a, end_b);
1827 cmp = g_utf8_collate(a, b);
1829 return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
1834 const Transaction *tb,
const char *actnb)
1836 const char *da, *db;
1839 if ( ta && !tb )
return -1;
1840 if ( !ta && tb )
return +1;
1841 if ( !ta && !tb )
return 0;
1843 if (ta->date_posted != tb->date_posted)
1844 return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
1850 if (ta_is_closing != tb_is_closing)
1851 return (ta_is_closing - tb_is_closing);
1857 retval = order_by_int64_or_string (actna, actnb);
1861 retval = order_by_int64_or_string (ta->num, tb->num);
1866 if (ta->date_entered != tb->date_entered)
1867 return (ta->date_entered > tb->date_entered) - (ta->date_entered < tb->date_entered);
1870 da = ta->description ? ta->description :
"";
1871 db = tb->description ? tb->description :
"";
1872 retval = g_utf8_collate (da, db);
1884 xaccTransSetDateInternal(Transaction *trans,
time64 *dadate,
time64 val)
1893 PINFO (
"addr=%p set date to %" G_GUINT64_FORMAT
".%09ld %s\n",
1894 trans, val.tv_sec, val.tv_nsec, tstr ? tstr :
"(null)");
1899 qof_instance_set_dirty(QOF_INSTANCE(trans));
1913 set_gains_date_dirty (Transaction *trans)
1915 FOR_EACH_SPLIT(trans, s->gains |= GAINS_STATUS_DATE_DIRTY);
1922 xaccTransSetDateInternal(trans, &trans->date_posted, secs);
1923 set_gains_date_dirty(trans);
1937 GValue v = G_VALUE_INIT;
1943 g_value_init (&v, G_TYPE_DATE);
1944 g_value_set_static_boxed (&v, &date);
1948 xaccTransSetDateInternal(trans, &trans->date_posted,
1950 set_gains_date_dirty (trans);
1957 xaccTransSetDateInternal(trans, &trans->date_entered, secs);
1965 date = g_date_new_dmy(day, static_cast<GDateMonth>(mon), year);
1966 if (!g_date_valid(date))
1968 PWARN(
"Attempted to set invalid date %d-%d-%d; set today's date instead.",
1980 GValue v = G_VALUE_INIT;
1982 g_value_init (&v, GNC_TYPE_TIME64);
1983 g_value_set_static_boxed (&v, &time);
1986 qof_instance_set_dirty(QOF_INSTANCE(trans));
1994 char s[2] = {type,
'\0'};
1995 GValue v = G_VALUE_INIT;
1996 g_return_if_fail(trans);
1997 g_value_init (&v, G_TYPE_STRING);
1999 if (!g_strcmp0 (s, g_value_get_string (&v)))
2004 g_value_set_static_string (&v, s);
2007 qof_instance_set_dirty(QOF_INSTANCE(trans));
2012 void xaccTransClearReadOnly (Transaction *trans)
2018 qof_instance_set_dirty(QOF_INSTANCE(trans));
2026 if (trans && reason)
2028 GValue v = G_VALUE_INIT;
2029 g_value_init (&v, G_TYPE_STRING);
2030 g_value_set_static_string (&v, reason);
2033 qof_instance_set_dirty(QOF_INSTANCE(trans));
2045 qofTransSetNum (Transaction *trans,
const char *xnum)
2055 if (!trans || !xnum)
return;
2058 CACHE_REPLACE(trans->num, xnum);
2059 qof_instance_set_dirty(QOF_INSTANCE(trans));
2065 qofTransSetDescription (Transaction *trans,
const char *desc)
2075 if (!trans || !desc)
return;
2078 CACHE_REPLACE(trans->description, desc);
2079 qof_instance_set_dirty(QOF_INSTANCE(trans));
2086 if (!trans || !doclink)
return;
2089 if (doclink[0] ==
'\0')
2095 GValue v = G_VALUE_INIT;
2096 g_value_init (&v, G_TYPE_STRING);
2097 g_value_set_static_string (&v, doclink);
2101 qof_instance_set_dirty(QOF_INSTANCE(trans));
2106 qofTransSetNotes (Transaction *trans,
const char *notes)
2116 GValue v = G_VALUE_INIT;
2117 if (!trans || !notes)
return;
2118 g_value_init (&v, G_TYPE_STRING);
2119 g_value_set_static_string (&v, notes);
2122 qof_instance_set_dirty(QOF_INSTANCE(trans));
2135 GValue v = G_VALUE_INIT;
2136 g_value_init (&v, G_TYPE_INT64);
2137 g_value_set_int64 (&v, 1);
2145 qof_instance_set_dirty(QOF_INSTANCE(trans));
2163 for (
auto node = trans->splits; node; node = node->next)
2165 auto s = GNC_SPLIT(node->data);
2166 if (s && s->parent == trans)
2171 for (
auto node = trans->splits; node; node = node->next)
2173 auto s = GNC_SPLIT(node->data);
2174 if (s && s->parent == trans)
2176 xaccSplitCommitEdit(s);
2179 g_list_free (trans->splits);
2180 trans->splits =
nullptr;
2189 if (!trans || i < 0)
return nullptr;
2191 FOR_EACH_SPLIT(trans, {
if (i == j)
return s; j++; });
2199 g_return_val_if_fail(trans && split, -1);
2201 FOR_EACH_SPLIT(trans, {
if (s == split)
return j; j++; });
2208 return trans ? trans->splits :
nullptr;
2214 GList *pay_splits =
nullptr;
2215 FOR_EACH_SPLIT (trans,
2218 pay_splits = g_list_prepend (pay_splits, s);
2221 pay_splits = g_list_reverse (pay_splits);
2228 GList *apar_splits =
nullptr;
2229 if (!trans)
return nullptr;
2231 FOR_EACH_SPLIT (trans,
2237 apar_splits = g_list_prepend (apar_splits, s);
2245 apar_splits = g_list_prepend (apar_splits, s);
2250 apar_splits = g_list_reverse (apar_splits);
2256 FOR_EACH_SPLIT (trans,
2267 FOR_EACH_SPLIT (trans,
2292 g_return_val_if_fail (trans !=
nullptr, 0);
2293 FOR_EACH_SPLIT(trans, i++);
2300 return trans ? trans->num :
nullptr;
2306 return trans ? trans->description :
nullptr;
2312 g_return_val_if_fail (trans,
nullptr);
2314 GValue v = G_VALUE_INIT;
2316 const char* doclink = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) :
nullptr;
2325 g_return_val_if_fail (trans,
nullptr);
2327 GValue v = G_VALUE_INIT;
2329 const char *notes = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) :
nullptr;
2338 if (!trans)
return FALSE;
2340 GValue v = G_VALUE_INIT;
2343 if (G_VALUE_HOLDS_INT64 (&v))
2344 rv = (g_value_get_int64 (&v) ? 1 : 0);
2358 return trans ? trans->date_posted : 0;
2365 return trans ? trans->date_entered : 0;
2372 return trans ? trans->date_posted : 0;
2379 g_date_clear (&result, 1);
2385 GValue v = G_VALUE_INIT;
2387 if (G_VALUE_HOLDS_BOXED (&v))
2388 result = *(GDate*)g_value_get_boxed (&v);
2390 if (! g_date_valid (&result) ||
gdate_to_time64 (result) == INT64_MAX)
2400 g_date_set_dmy(&result, stm->tm_mday,
2401 (GDateMonth)(stm->tm_mon + 1),
2402 stm->tm_year + 1900);
2413 return trans ? trans->date_entered : 0;
2420 GValue v = G_VALUE_INIT;
2421 if (!trans)
return 0;
2423 if (G_VALUE_HOLDS_BOXED (&v))
2425 ret = ((
Time64*)g_value_get_boxed (&v))->t;
2436 gboolean has_nonAPAR_split = FALSE;
2440 if (trans->txn_type != TXN_TYPE_UNCACHED)
2441 return trans->txn_type;
2452 has_nonAPAR_split = TRUE;
2459 if (invoice && trans == gncInvoiceGetPostedTxn (invoice))
2469 return trans->txn_type;
2478 GValue v = G_VALUE_INIT;
2480 const char *readonly_reason = G_VALUE_HOLDS_STRING (&v) ?
2481 g_value_get_string (&v) :
nullptr;
2483 return readonly_reason;
2487 xaccTransIsSXTemplate (
const Transaction * trans)
2490 if (split0 !=
nullptr)
2492 char* formula =
nullptr;
2493 g_object_get (split0,
"sx-debit-formula", &formula,
nullptr);
2494 if (formula !=
nullptr)
2499 g_object_get (split0,
"sx-credit-formula", &formula,
nullptr);
2500 if (formula !=
nullptr)
2511 GDate *threshold_date;
2522 if (xaccTransIsSXTemplate (trans))
2526 g_assert(threshold_date);
2534 if (g_date_compare(&trans_date, threshold_date) < 0)
2543 g_date_free(threshold_date);
2555 Split *split = GNC_SPLIT(node->data);
2557 if (!xaccTransStillHasSplit(trans, split))
2592 Split *split = GNC_SPLIT(node->data);
2594 if (!xaccTransStillHasSplit(trans, split))
2599 if (split->reconciled == state)
2620 counter_thunk(Transaction *t,
void *data)
2622 (*((guint*)data))++;
2631 counter_thunk, (
void*)&count);
2641 GValue v = G_VALUE_INIT;
2642 char iso8601_str[ISO_DATELENGTH + 1] =
"";
2644 g_return_if_fail(trans && reason);
2651 PWARN (
"Refusing to void a read-only transaction!");
2656 if (G_VALUE_HOLDS_STRING (&v))
2659 g_value_init (&v, G_TYPE_STRING);
2661 g_value_set_static_string (&v, _(
"Voided transaction"));
2663 g_value_set_static_string (&v, reason);
2667 g_value_set_static_string (&v, iso8601_str);
2671 FOR_EACH_SPLIT(trans, xaccSplitVoid(s));
2688 g_return_val_if_fail (trans,
nullptr);
2690 GValue v = G_VALUE_INIT;
2692 const char *void_reason = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) :
nullptr;
2701 GValue v = G_VALUE_INIT;
2702 const char *s =
nullptr;
2705 g_return_val_if_fail(tr, void_time);
2707 if (G_VALUE_HOLDS_STRING (&v))
2709 s = g_value_get_string (&v);
2720 GValue v = G_VALUE_INIT;
2721 const char *s =
nullptr;
2722 g_return_if_fail(trans);
2725 if (s ==
nullptr)
return;
2729 if (G_VALUE_HOLDS_STRING (&v))
2736 FOR_EACH_SPLIT(trans, xaccSplitUnvoid(s));
2739 xaccTransClearReadOnly(trans);
2747 GValue v = G_VALUE_INIT;
2748 g_return_val_if_fail(orig,
nullptr);
2754 qof_instance_set_dirty (QOF_INSTANCE (orig));
2758 g_return_val_if_fail (trans,
nullptr);
2762 FOR_EACH_SPLIT(trans,
2770 g_value_init (&v, GNC_TYPE_GUID);
2776 xaccTransClearReadOnly(trans);
2778 qof_instance_set_dirty(QOF_INSTANCE(trans));
2786 GValue v = G_VALUE_INIT;
2787 Transaction *retval =
nullptr;
2788 g_return_val_if_fail(trans,
nullptr);
2790 if (G_VALUE_HOLDS_BOXED (&v))
2813 xaccTransScrubGainsDate (Transaction *trans)
2816 SplitList *splits_copy = g_list_copy(trans->splits);
2817 for (node = splits_copy; node; node = node->next)
2819 Split *s = GNC_SPLIT(node->data);
2821 if (!xaccTransStillHasSplit(trans, s))
continue;
2822 xaccSplitDetermineGainStatus(s);
2824 if ((GAINS_STATUS_GAINS & s->gains) &&
2826 ((s->gains_split->gains & GAINS_STATUS_DATE_DIRTY) ||
2827 (s->gains & GAINS_STATUS_DATE_DIRTY)))
2829 Transaction *source_trans = s->gains_split->parent;
2830 s->gains &= ~GAINS_STATUS_DATE_DIRTY;
2831 s->gains_split->gains &= ~GAINS_STATUS_DATE_DIRTY;
2833 FOR_EACH_SPLIT(trans, s->gains &= ~GAINS_STATUS_DATE_DIRTY);
2836 g_list_free(splits_copy);
2846 ENTER(
"(trans=%p)", trans);
2849 xaccTransScrubGainsDate(trans);
2853 for (node = trans->splits; node; node = node->next)
2855 Split *s = GNC_SPLIT(node->data);
2857 if (!xaccTransStillHasSplit(trans, s))
continue;
2859 xaccSplitDetermineGainStatus(s);
2860 if (s->gains & GAINS_STATUS_ADIRTY)
2862 gboolean altered = FALSE;
2863 s->gains &= ~GAINS_STATUS_ADIRTY;
2868 if (altered)
goto restart;
2873 FOR_EACH_SPLIT(trans,
2874 if ((s->gains & GAINS_STATUS_VDIRTY) ||
2876 (s->gains_split->gains & GAINS_STATUS_VDIRTY)))
2880 LEAVE(
"(trans=%p)", trans);
2884 xaccTransFindSplitByAccount(
const Transaction *trans,
const Account *acc)
2886 if (!trans || !acc)
return nullptr;
2892 record_price (Split *split,
2898 GNCPriceDB* pricedb;
2899 gnc_commodity* comm;
2900 gnc_commodity* curr;
2902 gnc_numeric price_value, value, amount;
2934 PriceSource oldsource = gnc_price_get_source (price);
2935 price_value = gnc_price_get_value (price);
2942 if (oldsource < source &&
2943 !(oldsource == PRICE_SOURCE_XFER_DLG_VAL &&
2944 source == PRICE_SOURCE_SPLIT_REG))
2957 gnc_price_begin_edit (price);
2958 gnc_price_set_time64 (price, time);
2959 gnc_price_set_source (price, source);
2960 gnc_price_set_typestr (price, PRICE_TYPE_TRN);
2961 gnc_price_set_value (price, value);
2962 gnc_price_commit_edit (price);
2970 gnc_price_begin_edit (price);
2971 gnc_price_set_commodity (price, comm);
2972 gnc_price_set_currency (price, curr);
2973 gnc_price_set_time64 (price, time);
2974 gnc_price_set_source (price, source);
2975 gnc_price_set_typestr (price, PRICE_TYPE_TRN);
2976 gnc_price_set_value (price, value);
2978 gnc_price_commit_edit (price);
2993 destroy_tx_on_book_close(
QofInstance *ent, gpointer data)
2995 Transaction* tx = GNC_TRANSACTION(ent);
3001 trans_reverse_order (
const Transaction* a,
const Transaction* b)
3011 gnc_transaction_book_end(QofBook* book)
3021 (GCompareFunc)trans_reverse_order);
3033 static QofObject trans_object_def =
3036 DI(.e_type = ) GNC_ID_TRANS,
3037 DI(.type_label = ) "Transaction",
3039 DI(.book_begin = )
nullptr,
3040 DI(.book_end = ) gnc_transaction_book_end,
3043 DI(.foreach = ) qof_collection_foreach,
3049 trans_is_balanced_p (const Transaction *trans)
3054 gboolean xaccTransRegister (
void)
3056 static QofParam params[] =
3059 TRANS_NUM, QOF_TYPE_STRING,
3065 TRANS_DESCRIPTION, QOF_TYPE_STRING,
3070 TRANS_DATE_ENTERED, QOF_TYPE_DATE,
3075 TRANS_DATE_POSTED, QOF_TYPE_DATE,
3080 TRANS_DATE_DUE, QOF_TYPE_DATE,
3084 TRANS_IMBALANCE, QOF_TYPE_NUMERIC,
3088 TRANS_NOTES, QOF_TYPE_STRING,
3093 TRANS_DOCLINK, QOF_TYPE_STRING,
3098 TRANS_IS_CLOSING, QOF_TYPE_BOOLEAN,
3102 TRANS_IS_BALANCED, QOF_TYPE_BOOLEAN,
3106 TRANS_TYPE, QOF_TYPE_CHAR,
3111 TRANS_VOID_STATUS, QOF_TYPE_BOOLEAN,
3115 TRANS_VOID_REASON, QOF_TYPE_STRING,
3119 TRANS_VOID_TIME, QOF_TYPE_DATE,
3123 TRANS_SPLITLIST, GNC_ID_SPLIT,
3131 QOF_PARAM_GUID, QOF_TYPE_GUID,
3143 _utest_trans_fill_functions (
void)
3147 func->mark_trans = mark_trans;
3148 func->gen_event_trans = gen_event_trans;
3149 func->xaccFreeTransaction = xaccFreeTransaction;
3150 func->destroy_gains = destroy_gains;
3151 func->do_destroy = do_destroy;
3152 func->was_trans_emptied = was_trans_emptied;
3153 func->trans_on_error = trans_on_error;
3154 func->trans_cleanup_commit = trans_cleanup_commit;
3155 func->xaccTransScrubGainsDate = xaccTransScrubGainsDate;
3156 func->dupe_trans = dupe_trans;
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
GNCPrice * gnc_pricedb_lookup_day_t64(GNCPriceDB *db, const gnc_commodity *c, const gnc_commodity *currency, time64 t)
Return the price between the two commodities on the indicated day.
time64 gnc_iso8601_to_time64_gmt(const gchar *)
The gnc_iso8601_to_time64_gmt() routine converts an ISO-8601 style date/time string to time64...
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
Never round at all, and signal an error if there is a fractional result in a computation.
commit of object update failed because another user has deleted the object
GNCPrice * gnc_price_create(QofBook *book)
gnc_price_create - returns a newly allocated and initialized price with a reference count of 1...
int xaccAccountTreeForEachTransaction(Account *acc, TransactionCallback proc, void *data)
Traverse all of the transactions in the given account group.
gint xaccSplitOrder(const Split *sa, const Split *sb)
The xaccSplitOrder(sa,sb) method is useful for sorting.
This is the private header for the account structure.
High-Level API for imposing Lot constraints.
gboolean xaccTransHasReconciledSplits(const Transaction *trans)
FIXME: document me.
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 xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3))...
gchar * gnc_num_dbg_to_string(gnc_numeric n)
Convert to string.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
void xaccTransClearSplits(Transaction *trans)
Remove all splits from the transaction.
Business Interface: Object OWNERs.
gboolean xaccTransHasSplitsInStateByAccount(const Transaction *trans, const char state, const Account *account)
FIXME: document me.
Split * xaccTransGetSplit(const Transaction *trans, int i)
Return a pointer to the indexed split in this transaction's split list.
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
gboolean xaccTransUseTradingAccounts(const Transaction *trans)
Determine whether this transaction should use commodity trading accounts.
gboolean xaccTransIsReadonlyByPostedDate(const Transaction *trans)
Returns TRUE if this Transaction is read-only because its posted-date is older than the "auto-readonl...
Date and Time handling routines.
#define qof_instance_is_dirty
Return value of is_dirty flag.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean xaccAccountIsPriced(const Account *acc)
Returns true if the account is a stock, mutual fund or currency, otherwise false. ...
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
gboolean xaccTransIsOpen(const Transaction *trans)
The xaccTransIsOpen() method returns TRUE if the transaction is open for editing. ...
gnc_numeric xaccTransGetAccountBalance(const Transaction *trans, const Account *account)
Get the account balance for the specified account after the last split in the specified transaction...
char xaccTransGetTxnType(Transaction *trans)
Returns the Transaction Type: note this type will be derived from the transaction splits...
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
#define TXN_TYPE_INVOICE
Transaction is an invoice.
#define PINFO(format, args...)
Print an informational note.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
gboolean xaccSplitDestroy(Split *split)
Destructor.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
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 xaccTransSetNotes(Transaction *trans, const char *notes)
Sets the transaction Notes.
const char * xaccTransGetVoidReason(const Transaction *trans)
Returns the user supplied textual reason why a transaction was voided.
void xaccTransWriteLog(Transaction *trans, char flag)
void gnc_price_unref(GNCPrice *p)
gnc_price_unref - indicate you're finished with a price (i.e.
void qof_backend_set_error(QofBackend *qof_be, QofBackendError err)
Set the error on the specified QofBackend.
const char * xaccTransGetReadOnly(Transaction *trans)
Returns a non-NULL value if this Transaction was marked as read-only with some specific "reason" text...
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p)
Add a price to the pricedb.
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.
commit of object update failed because another user has modified the object
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.
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
void xaccSplitComputeCapGains(Split *split, Account *gain_acc)
The xaccSplitComputeCapGains() routine computes the cap gains or losses for the indicated split...
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
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.
void xaccTransRecordPrice(Transaction *trans, PriceSource source)
The xaccTransRecordPrice() method iterates through the splits and and record the non-currency equival...
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
void xaccTransCopyOnto(const Transaction *from_trans, Transaction *to_trans)
Copy a transaction to another using the function below without changing any account information...
Object instance holds common fields that most gnucash objects use.
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
Use any denominator which gives an exactly correct ratio of numerator to denominator.
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
gboolean xaccTransIsBalanced(const Transaction *trans)
Returns true if the transaction is balanced according to the rules currently in effect.
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
const char * xaccTransGetNum(const Transaction *trans)
Gets the transaction Number (or ID) field; rather than use this function directly, see 'gnc_get_num_action' and 'gnc_get_action_num' 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.
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
#define PERR(format, args...)
Log a serious error.
gboolean gncBusinessIsPaymentAcctType(GNCAccountType type)
Returns whether the given account type is a valid type to use in business payments.
int xaccTransOrder_num_action(const Transaction *ta, const char *actna, const Transaction *tb, const char *actnb)
The xaccTransOrder_num_action(ta,actna,tb,actnb) method is useful for sorting.
#define ENTER(format, args...)
Print a function entry debugging message.
void qof_collection_foreach_sorted(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data, GCompareFunc sort_fn)
Call the callback for each entity in the collection.
gnc_numeric xaccSplitGetBalance(const Split *s)
Returns the running balance up to and including the indicated split.
Split * xaccTransGetFirstPaymentAcctSplit(const Transaction *trans)
The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first split in this transacti...
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
QofBackendError qof_backend_get_error(QofBackend *qof_be)
Get the last backend error.
void xaccTransSetDatePostedGDate(Transaction *trans, GDate date)
This method modifies posted date of the transaction, specified by a GDate.
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
const char * xaccTransGetDocLink(const Transaction *trans)
Gets the transaction Document Link.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
gboolean xaccTransHasReconciledSplitsByAccount(const Transaction *trans, const Account *account)
FIXME: document me.
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
Account used to record multiple commodity transactions.
void xaccTransDestroy(Transaction *trans)
Destroys a transaction.
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
#define PWARN(format, args...)
Log a warning.
const char * xaccTransGetNotes(const Transaction *trans)
Gets the transaction Notes.
Transaction * xaccTransLookup(const GncGUID *guid, QofBook *book)
The xaccTransLookup() subroutine will return the transaction associated with the given id...
void xaccTransSetIsClosingTxn(Transaction *trans, gboolean is_closing)
Sets whether or not this transaction is a "closing transaction".
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
MonetaryList * gnc_monetary_list_delete_zeros(MonetaryList *list)
Delete all entries in the list that have zero value.
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
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...
#define TXN_TYPE_NONE
No transaction type.
convert single-entry accounts to clean double-entry
gnc_numeric gnc_numeric_invert(gnc_numeric num)
Invert a gnc_numeric.
GList SplitList
GList of Split.
GDate * qof_book_get_autoreadonly_gdate(const QofBook *book)
Returns the GDate that is the threshold for auto-read-only.
gboolean xaccTransHasSplitsInState(const Transaction *trans, const char state)
FIXME: document me.
guint32 qof_instance_get_idata(gconstpointer inst)
get the instance tag number used for kvp management in sql backends.
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
gboolean xaccTransEqual(const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
Equality.
gnc_numeric gnc_numeric_convert(gnc_numeric n, gint64 denom, gint how)
Change the denominator of a gnc_numeric value to the specified denominator under standard arguments '...
Reduce the result value by common factor elimination, using the smallest possible value for the denom...
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
The xaccTransGetImbalanceValue() method returns the total value of the transaction.
void xaccTransSetReadOnly(Transaction *trans, const char *reason)
Set the transaction to be ReadOnly by setting a non-NULL value as "reason".
void xaccTransVoid(Transaction *trans, const char *reason)
xaccTransVoid voids a transaction.
Transaction * xaccTransClone(const Transaction *from)
The xaccTransClone() method will create a complete copy of an existing transaction.
#define YREC
The Split has been reconciled.
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
#define FREC
frozen into accounting period
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code)
Create a gnc_numeric object that signals the error condition noted by error_code, rather than a numbe...
void gnc_monetary_list_free(MonetaryList *list)
Free a MonetaryList and all the monetaries it points to.
void xaccTransScrubImbalance(Transaction *trans, Account *root, Account *account)
Correct transaction imbalances.
void qof_instance_copy_book(gpointer ptr1, gconstpointer ptr2)
Copy the book from one QofInstances to another.
time64 xaccTransRetDatePosted(const Transaction *trans)
Retrieve the posted date of the transaction.
void xaccTransCopyFromClipBoard(const Transaction *from_trans, Transaction *to_trans, const Account *from_acc, Account *to_acc, gboolean no_date)
This function explicitly must robustly handle some unusual input.
void xaccTransScrubGains(Transaction *trans, Account *gain_acc)
The xaccTransScrubGains() routine performs a number of cleanup functions on the indicated transaction...
Transaction * xaccTransCloneNoKvp(const Transaction *from)
The xaccTransCloneNoKvp() method will create a complete copy of an existing transaction except that ...
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
Argument is not a valid number.
– Business Helper Functions
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
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.
#define xaccTransGetBook(X)
gboolean xaccAccountIsAPARType(GNCAccountType t)
Convenience function to check if the account is a valid business account type (meaning an Accounts Pa...
void xaccTransSetDate(Transaction *trans, int day, int mon, int year)
The xaccTransSetDate() method does the same thing as xaccTransSetDate[Posted]Secs(), but takes a convenient day-month-year format.
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
void xaccTransSetDateDue(Transaction *trans, time64 time)
Dates and txn-type for A/R and A/P "invoice" postings.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
Additional event handling code.
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
#define xaccSplitGetGUID(X)
#define GNC_INVOICE_ID
STRING CONSTANTS ********************************************** Used to declare constant KVP keys use...
#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 xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
Inverse of xaccTransGetSplit()
SplitList * xaccTransGetAPARAcctSplitList(const Transaction *trans, gboolean strict)
The xaccTransGetAPARSplitList() method returns a GList of the splits in a transaction that belong to ...
void xaccTransUnvoid(Transaction *trans)
xaccTransUnvoid restores a voided transaction to its original state.
#define TXN_TYPE_PAYMENT
Transaction is a payment.
All type declarations for the whole Gnucash engine.
const GncGUID * qof_entity_get_guid(gconstpointer ent)
time64 xaccTransGetVoidTime(const Transaction *tr)
Returns the time that a transaction was voided.
Split * xaccMallocSplit(QofBook *book)
Constructor.
#define xaccTransGetGUID(X)
time64 xaccTransGetDateEntered(const Transaction *trans)
Retrieve the date of when the transaction was entered.
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
API for the transaction logger.
Business Invoice Interface.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
Transaction * xaccTransReverse(Transaction *orig)
xaccTransReverse creates a Transaction that reverses the given transaction by inverting all the numer...
guint gnc_book_count_transactions(QofBook *book)
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 xaccTransGetVoidStatus(const Transaction *trans)
Retrieve information on whether or not a transaction has been voided.
gboolean qof_book_is_readonly(const QofBook *book)
Return whether the book is read only.
gboolean xaccSplitAssign(Split *split)
The`xaccSplitAssign() routine will take the indicated split and, if it doesn't already belong to a lo...
SplitList * xaccTransGetPaymentAcctSplitList(const Transaction *trans)
The xaccTransGetPaymentAcctSplitList() method returns a GList of the splits in a transaction that bel...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
void qof_event_suspend(void)
Suspend all engine events.
int qof_string_number_compare_func(gpointer a, gpointer b, gint options, QofParam *getter)
Compare two parameter(strings) as if they are numbers! the two objects, a and b, are the objects bein...
void gnc_gdate_set_time64(GDate *gd, time64 time)
Set a GDate to a time64.
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
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.
gboolean xaccTransGetIsClosingTxn(const Transaction *trans)
Returns whether this transaction is a "closing transaction".
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
void qof_event_resume(void)
Resume engine event generation.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
MonetaryList * xaccTransGetImbalance(const Transaction *trans)
The xaccTransGetImbalance method returns a list giving the value of the transaction in each currency ...
void xaccTransSetDocLink(Transaction *trans, const char *doclink)
Sets the transaction Document Link.
PriceSource
Price source enum.
Transaction * xaccTransGetReversedBy(const Transaction *trans)
Returns the transaction that reversed the given transaction.
#define LEAVE(format, args...)
Print a function exit debugging message.
gboolean xaccScrubLot(GNCLot *lot)
The xaccScrubLot() routine makes sure that the indicated lot is self-consistent and properly balanced...
struct tm * gnc_gmtime(const time64 *secs)
fill out a time struct from a 64-bit time value
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the 'unique' name for the specified commodity.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
void xaccSplitSetSharePrice(Split *s, gnc_numeric price)
time64 gnc_time(time64 *tbuf)
get the current time
int xaccTransOrder(const Transaction *ta, const Transaction *tb)
The xaccTransOrder(ta,tb) method is useful for sorting.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
char * gnc_ctime(const time64 *secs)
Return a string representation of a date from a 64-bit time value.
void xaccTransSetDateEnteredSecs(Transaction *trans, time64 secs)
Modify the date of when the transaction was entered.
time64 xaccTransRetDateEntered(const Transaction *trans)
Retrieve the date of when the transaction was entered.
gboolean qof_book_uses_autoreadonly(const QofBook *book)
Returns TRUE if the auto-read-only feature should be used, otherwise FALSE.
QofBackend * qof_book_get_backend(const QofBook *book)
Retrieve the backend used by this book.
gboolean qof_book_shutting_down(const QofBook *book)
Is the book shutting down?
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
void xaccTransSortSplits(Transaction *trans)
Sorts the splits in a transaction, putting the debits first, followed by the credits.
Scheduled Transactions public handling routines.
GDate xaccTransGetDatePostedGDate(const Transaction *trans)
Retrieve the posted date of the transaction.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
The type used to store guids in C.
gboolean qof_book_use_trading_accounts(const QofBook *book)
Returns flag indicating whether this book uses trading accounts.
char * gnc_time64_to_iso8601_buff(time64 time, char *buff)
The gnc_time64_to_iso8601_buff() routine takes the input UTC time64 value and prints it as an ISO-860...
Utilities to Automatically Compute Capital Gains/Losses.
time64 xaccTransRetDateDue(const Transaction *trans)
Dates and txn-type for A/R and A/P "invoice" postings.
size_t qof_print_date_buff(char *buff, size_t buflen, time64 secs)
Convenience: calls through to qof_print_date_dmy_buff().
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
Commodity handling public routines.
void xaccTransRollbackEdit(Transaction *trans)
The xaccTransRollbackEdit() routine rejects all edits made, and sets the transaction back to where it...
Transaction * xaccTransCopyToClipBoard(const Transaction *from_trans)
Copy a transaction to the 'clipboard' transaction using dupe_transaction.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gnc_numeric xaccTransGetAccountAmount(const Transaction *trans, const Account *acc)
Same as xaccTransGetAccountValue, but uses the Account's commodity.
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...
gnc_numeric xaccTransGetAccountValue(const Transaction *trans, const Account *acc)
The xaccTransGetAccountValue() method returns the total value applied to a particular account...
#define NREC
not reconciled or cleared
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
GDate * gnc_g_date_new_today()
Returns a newly allocated date of the current clock time, taken from time(2).