36 #include <glib/gi18n.h> 39 #ifdef HAVE_SYS_TIME_H 40 # include <sys/time.h> 52 #include "TransactionP.hpp" 59 #include "qofinstance-p.h" 61 const char *void_former_amt_str =
"void-former-amount";
62 const char *void_former_val_str =
"void-former-value";
65 static QofLogModule log_module = GNC_MOD_ENGINE;
68 #define GNC_SX_ID "sched-xaction" 69 #define GNC_SX_ACCOUNT "account" 70 #define GNC_SX_CREDIT_FORMULA "credit-formula" 71 #define GNC_SX_DEBIT_FORMULA "debit-formula" 72 #define GNC_SX_CREDIT_NUMERIC "credit-numeric" 73 #define GNC_SX_DEBIT_NUMERIC "debit-numeric" 74 #define GNC_SX_SHARES "shares" 87 PROP_SX_CREDIT_FORMULA,
88 PROP_SX_CREDIT_NUMERIC,
89 PROP_SX_DEBIT_FORMULA,
90 PROP_SX_DEBIT_NUMERIC,
101 static const char * split_type_normal =
"normal";
102 static const char * split_type_stock_split =
"stock-split";
105 G_DEFINE_TYPE(Split, gnc_split, QOF_TYPE_INSTANCE)
108 gnc_split_init(Split* split)
111 split->acc =
nullptr;
112 split->orig_acc =
nullptr;
113 split->parent =
nullptr;
114 split->lot =
nullptr;
116 split->action = CACHE_INSERT(
"");
117 split->memo = CACHE_INSERT(
"");
118 split->reconciled =
NREC;
119 split->amount = gnc_numeric_zero();
120 split->value = gnc_numeric_zero();
122 split->date_reconciled = 0;
124 split->balance = gnc_numeric_zero();
125 split->cleared_balance = gnc_numeric_zero();
126 split->reconciled_balance = gnc_numeric_zero();
127 split->noclosing_balance = gnc_numeric_zero();
129 split->gains = GAINS_STATUS_UNKNOWN;
130 split->gains_split =
nullptr;
134 gnc_split_dispose(GObject *splitp)
136 G_OBJECT_CLASS(gnc_split_parent_class)->dispose(splitp);
140 gnc_split_finalize(GObject* splitp)
142 G_OBJECT_CLASS(gnc_split_parent_class)->finalize(splitp);
151 gnc_split_get_property(GObject *
object,
159 g_return_if_fail(GNC_IS_SPLIT(
object));
161 split = GNC_SPLIT(
object);
165 g_value_set_string(value, split->action);
168 g_value_set_string(value, split->memo);
171 g_value_set_boxed(value, &split->value);
174 g_value_set_boxed(value, &split->amount);
176 case PROP_RECONCILE_DATE:
177 t.t = split->date_reconciled;
178 g_value_set_boxed(value, &t);
181 g_value_take_object(value, split->parent);
184 g_value_take_object(value, split->acc);
187 g_value_take_object(value, split->lot);
189 case PROP_SX_CREDIT_FORMULA:
192 case PROP_SX_CREDIT_NUMERIC:
195 case PROP_SX_DEBIT_FORMULA:
198 case PROP_SX_DEBIT_NUMERIC:
201 case PROP_SX_ACCOUNT:
207 case PROP_ONLINE_ACCOUNT:
210 case PROP_GAINS_SPLIT:
213 case PROP_GAINS_SOURCE:
217 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
223 gnc_split_set_property(GObject *
object,
231 g_return_if_fail(GNC_IS_SPLIT(
object));
233 split = GNC_SPLIT(
object);
234 if (prop_id < PROP_RUNTIME_0 && split->parent !=
nullptr)
235 g_assert (qof_instance_get_editlevel(split->parent));
246 number =
static_cast<gnc_numeric*
>(g_value_get_boxed(value));
250 number =
static_cast<gnc_numeric*
>(g_value_get_boxed(value));
253 case PROP_RECONCILE_DATE:
254 t =
static_cast<Time64*
>(g_value_get_boxed(value));
258 xaccSplitSetParent(split, GNC_TRANSACTION(g_value_get_object(value)));
261 xaccSplitSetAccount(split, GNC_ACCOUNT(g_value_get_object(value)));
266 case PROP_SX_CREDIT_FORMULA:
269 case PROP_SX_CREDIT_NUMERIC:
272 case PROP_SX_DEBIT_FORMULA:
275 case PROP_SX_DEBIT_NUMERIC:
278 case PROP_SX_ACCOUNT:
284 case PROP_ONLINE_ACCOUNT:
287 case PROP_GAINS_SPLIT:
290 case PROP_GAINS_SOURCE:
294 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
300 gnc_split_class_init(SplitClass* klass)
302 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
304 gobject_class->dispose = gnc_split_dispose;
305 gobject_class->finalize = gnc_split_finalize;
306 gobject_class->set_property = gnc_split_set_property;
307 gobject_class->get_property = gnc_split_get_property;
309 g_object_class_install_property
312 g_param_spec_string(
"action",
314 "The action is an arbitrary string assigned " 315 "by the user. It is intended to be a short " 316 "string that contains extra information about " 321 g_object_class_install_property
324 g_param_spec_string(
"memo",
326 "The action is an arbitrary string assigned " 327 "by the user. It is intended to be a short " 328 "string that describes the purpose of " 333 g_object_class_install_property
336 g_param_spec_boxed(
"value",
338 "The value for this split in the common currency. " 339 "The value and the amount provide enough information to " 340 "calculate a conversion rate.",
344 g_object_class_install_property
347 g_param_spec_boxed(
"amount",
349 "The value for this split in the currency of its account. " 350 "The value and the amount provide enough information to " 351 "calculate a conversion rate.",
355 g_object_class_install_property
358 g_param_spec_boxed(
"reconcile-date",
360 "The date this split was reconciled.",
364 g_object_class_install_property
367 g_param_spec_object (
"transaction",
369 "The transaction that this split belongs to.",
370 GNC_TYPE_TRANSACTION,
373 g_object_class_install_property
376 g_param_spec_object (
"account",
378 "The account that this split belongs to.",
382 g_object_class_install_property
385 g_param_spec_object (
"lot",
387 "The lot that this split belongs to.",
391 g_object_class_install_property
393 PROP_SX_DEBIT_FORMULA,
394 g_param_spec_string(
"sx-debit-formula",
395 "Schedule Transaction Debit Formula",
396 "The formula used to calculate the actual debit " 397 "amount when a real split is generated from this " 402 g_object_class_install_property
404 PROP_SX_DEBIT_NUMERIC,
405 g_param_spec_boxed(
"sx-debit-numeric",
406 "Scheduled Transaction Debit Numeric",
407 "Numeric value to plug into the Debit Formula when a " 408 "real split is generated from this SX split.",
412 g_object_class_install_property
414 PROP_SX_CREDIT_FORMULA,
415 g_param_spec_string(
"sx-credit-formula",
416 "Schedule Transaction Credit Formula",
417 "The formula used to calculate the actual credit " 418 "amount when a real split is generated from this " 423 g_object_class_install_property
425 PROP_SX_CREDIT_NUMERIC,
426 g_param_spec_boxed(
"sx-credit-numeric",
427 "Scheduled Transaction Credit Numeric",
428 "Numeric value to plug into the Credit Formula when a " 429 "real split is generated from this SX split.",
437 g_object_class_install_property
440 g_param_spec_string(
"sx-shares",
441 "Scheduled Transaction Shares",
442 "Numeric value of shares to insert in a new split when " 443 "it's generated from this SX split.",
447 g_object_class_install_property
450 g_param_spec_boxed(
"sx-account",
451 "Scheduled Transaction Account",
452 "The target account for a scheduled transaction split.",
456 g_object_class_install_property
459 g_param_spec_string (
"online-id",
461 "The online account which corresponds to this " 462 "account for OFX/HCBI import",
466 g_object_class_install_property
469 g_param_spec_boxed (
"gains-split",
471 "The capital gains split associated with this " 472 "split when this split represents the proceeds " 473 "from the sale of a commodity inside a Lot.",
477 g_object_class_install_property
480 g_param_spec_boxed (
"gains-source",
482 "The source split for which this split this is " 494 xaccInitSplit(Split * split, QofBook *book)
500 xaccSplitReinit(Split * split)
503 split->acc =
nullptr;
504 split->orig_acc =
nullptr;
505 split->parent =
nullptr;
506 split->lot =
nullptr;
508 CACHE_REPLACE(split->action,
"");
509 CACHE_REPLACE(split->memo,
"");
510 split->reconciled =
NREC;
511 split->amount = gnc_numeric_zero();
512 split->value = gnc_numeric_zero();
514 split->date_reconciled = 0;
516 split->balance = gnc_numeric_zero();
517 split->cleared_balance = gnc_numeric_zero();
518 split->reconciled_balance = gnc_numeric_zero();
519 split->noclosing_balance = gnc_numeric_zero();
521 qof_instance_set_idata(split, 0);
523 split->gains = GAINS_STATUS_UNKNOWN;
524 split->gains_split =
nullptr;
534 g_return_val_if_fail (book,
nullptr);
536 split = GNC_SPLIT(g_object_new (GNC_TYPE_SPLIT,
nullptr));
537 xaccInitSplit (split, book);
552 xaccDupeSplit (
const Split *s)
554 Split *split = GNC_SPLIT(g_object_new (GNC_TYPE_SPLIT,
nullptr));
560 split->inst.e_type =
nullptr;
561 qof_instance_copy_guid(split, s);
564 split->parent = s->parent;
566 split->orig_acc = s->orig_acc;
569 CACHE_REPLACE(split->memo, s->memo);
570 CACHE_REPLACE(split->action, s->action);
572 qof_instance_copy_kvp (QOF_INSTANCE (split), QOF_INSTANCE (s));
574 split->reconciled = s->reconciled;
575 split->date_reconciled = s->date_reconciled;
577 split->value = s->value;
578 split->amount = s->amount;
590 xaccSplitCloneNoKvp (
const Split *s)
592 Split *split = GNC_SPLIT(g_object_new (GNC_TYPE_SPLIT,
nullptr));
594 split->parent =
nullptr;
595 split->memo = CACHE_INSERT(s->memo);
596 split->action = CACHE_INSERT(s->action);
597 split->reconciled = s->reconciled;
598 split->date_reconciled = s->date_reconciled;
599 split->value = s->value;
600 split->amount = s->amount;
601 split->balance = s->balance;
602 split->cleared_balance = s->cleared_balance;
603 split->reconciled_balance = s->reconciled_balance;
604 split->noclosing_balance = s->noclosing_balance;
606 split->gains = GAINS_STATUS_UNKNOWN;
607 split->gains_split =
nullptr;
621 xaccSplitCopyKvp (
const Split *from, Split *to)
623 qof_instance_copy_kvp (QOF_INSTANCE (to), QOF_INSTANCE (from));
640 if (!from_split || !to_split)
return;
653 qof_instance_set_dirty(QOF_INSTANCE(to_split));
660 #ifdef DUMP_FUNCTIONS 662 xaccSplitDump (
const Split *split,
const char *tag)
665 memset (datebuff, 0,
sizeof(datebuff));
667 printf(
" %s Split %p", tag, split);
669 printf(
" Account: %p (%s)\n", split->acc,
671 printf(
" Commod: %s\n",
675 printf(
" Lot: %p\n", split->lot);
676 printf(
" Parent: %p\n", split->parent);
677 printf(
" Gains: %p\n", split->gains_split);
678 printf(
" Memo: %s\n", split->memo ? split->memo :
"(null)");
679 printf(
" Action: %s\n", split->action ? split->action :
"(null)");
680 printf(
" KVP Data: %s\n", qof_instance_kvp_as_string (QOF_INSTANCE (split)));
681 printf(
" Recncld: %c (date %s)\n", split->reconciled, datebuff);
687 printf(
" RBalance: %s\n",
699 xaccFreeSplit (GNC_SPLIT (inst));
703 xaccFreeSplit (Split *split)
708 if (((
char *) 1) == split->memo)
710 PERR (
"double-free %p", split);
713 CACHE_REMOVE(split->memo);
714 CACHE_REMOVE(split->action);
716 if (split->inst.e_type)
721 if (GNC_IS_ACCOUNT (split->acc)
740 split->memo = (
char *) 1;
741 split->action =
nullptr;
742 split->reconciled =
NREC;
743 split->amount = gnc_numeric_zero();
744 split->value = gnc_numeric_zero();
745 split->parent =
nullptr;
746 split->lot =
nullptr;
747 split->acc =
nullptr;
748 split->orig_acc =
nullptr;
750 split->date_reconciled = 0;
751 G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
753 if (split->gains_split)
756 split->gains_split->gains_split =
nullptr;
758 other->gains_split =
nullptr;
761 g_object_unref(split);
764 void mark_split (Split *s)
768 g_object_set(s->acc,
"sort-dirty", TRUE,
"balance-dirty", TRUE,
nullptr);
779 xaccSplitEqualCheckBal (
const char *tag, gnc_numeric a, gnc_numeric b)
789 PINFO (
"%sbalances differ: %s vs %s", tag, str_a, str_b);
802 gboolean check_guids,
803 gboolean check_balances,
804 gboolean check_txn_splits)
808 if (!sa && !sb)
return TRUE;
812 PINFO (
"one is nullptr");
816 if (sa == sb)
return TRUE;
824 PINFO (
"GUIDs differ");
830 if ((same_book && sa->memo != sb->memo) || (!same_book && g_strcmp0(sa->memo, sb->memo) != 0))
832 PINFO (
"memos differ: (%p)%s vs (%p)%s",
833 sa->memo, sa->memo, sb->memo, sb->memo);
837 if ((same_book && sa->action != sb->action) || (!same_book && g_strcmp0(sa->action, sb->action) != 0))
839 PINFO (
"actions differ: %s vs %s", sa->action, sb->action);
843 if (qof_instance_compare_kvp (QOF_INSTANCE (sa), QOF_INSTANCE (sb)) != 0)
848 frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (sa));
849 frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (sb));
851 PINFO (
"kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
859 if (sa->reconciled != sb->reconciled)
861 PINFO (
"reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
865 if (sa->date_reconciled != sb->date_reconciled)
867 PINFO (
"reconciled date differs");
879 PINFO (
"amounts differ: %s vs %s", str_a, str_b);
895 PINFO (
"values differ: %s vs %s", str_a, str_b);
905 if (!xaccSplitEqualCheckBal (
"", sa->balance, sb->balance))
907 if (!xaccSplitEqualCheckBal (
"cleared ", sa->cleared_balance,
908 sb->cleared_balance))
910 if (!xaccSplitEqualCheckBal (
"reconciled ", sa->reconciled_balance,
911 sb->reconciled_balance))
913 if (!xaccSplitEqualCheckBal (
"noclosing ", sa->noclosing_balance,
914 sb->noclosing_balance))
918 if (!
xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
919 check_balances, FALSE))
921 PINFO (
"transactions differ");
937 return s ? s->acc :
nullptr;
941 xaccSplitSetAccount (Split *s,
Account *acc)
945 g_return_if_fail(s && acc);
953 qof_instance_set_dirty(QOF_INSTANCE(s));
961 PERR(
"commit error: %d", errcode);
962 gnc_engine_signal_commit_error( errcode );
967 xaccSplitCommitEdit(Split *s)
976 orig_acc = s->orig_acc;
978 if (GNC_IS_ACCOUNT(s->acc))
991 PERR(
"Account lost track of moved or deleted split.");
1007 PERR(
"Account grabbed split prematurely.");
1012 if (s->parent != s->orig_parent)
1022 qof_event_gen (QOF_INSTANCE(s->lot), QOF_EVENT_MODIFY,
nullptr);
1028 s->orig_acc = s->acc;
1029 s->orig_parent = s->parent;
1035 g_object_set(acc,
"sort-dirty", TRUE,
"balance-dirty", TRUE,
nullptr);
1042 xaccSplitRollbackEdit(Split *s)
1048 if (s->acc != s->orig_acc)
1049 s->acc = s->orig_acc;
1055 qof_instance_set_destroying(s, FALSE);
1063 xaccSplitSetParent(s, s->orig_parent);
1073 if (!guid || !book)
return nullptr;
1089 xaccSplitDetermineGainStatus (Split *split)
1092 GValue v = G_VALUE_INIT;
1095 if (GAINS_STATUS_UNKNOWN != split->gains)
return;
1100 split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
1101 split->gains_split = other;
1106 if (G_VALUE_HOLDS_BOXED (&v))
1107 guid = (
GncGUID*)g_value_get_boxed (&v);
1111 split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
1118 split->gains = GAINS_STATUS_GAINS;
1120 split->gains_split = other;
1129 get_currency_denom(
const Split * s)
1131 if (!(s && s->parent && s->parent->common_currency))
1142 get_commodity_denom(
const Split * s)
1169 SET_GAINS_A_VDIRTY(s);
1171 qof_instance_set_dirty(QOF_INSTANCE(s));
1177 qofSplitSetSharePrice (Split *split, gnc_numeric price)
1179 g_return_if_fail(split);
1181 price, get_currency_denom(split),
1197 price, get_currency_denom(s),
1200 SET_GAINS_VDIRTY(s);
1202 qof_instance_set_dirty(QOF_INSTANCE(s));
1208 qofSplitSetAmount (Split *split, gnc_numeric amt)
1210 g_return_if_fail(split);
1218 split->amount = amt;
1228 ENTER (
"(split=%p) old amt=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT
1229 " new amt=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT, s,
1230 s->amount.num, s->amount.denom, amt.num, amt.denom);
1242 SET_GAINS_ADIRTY(s);
1244 qof_instance_set_dirty(QOF_INSTANCE(s));
1250 qofSplitSetValue (Split *split, gnc_numeric amt)
1252 g_return_if_fail(split);
1262 gnc_numeric new_val;
1266 ENTER (
"(split=%p) old val=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT
1267 " new val=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT, s,
1268 s->value.num, s->value.denom, amt.num, amt.denom);
1280 PERR(
"numeric error %s in converting the split value's denominator with amount %s and denom %d",
1285 SET_GAINS_VDIRTY(s);
1287 qof_instance_set_dirty(QOF_INSTANCE(s));
1298 return s ? s->balance : gnc_numeric_zero();
1304 return s ? s->noclosing_balance : gnc_numeric_zero();
1310 return s ? s->cleared_balance : gnc_numeric_zero();
1316 return s ? s->reconciled_balance : gnc_numeric_zero();
1321 const gnc_commodity * base_currency)
1323 const gnc_commodity *currency;
1324 const gnc_commodity *commodity;
1331 PERR (
"split must have a parent account");
1346 get_commodity_denom(s),
1350 get_currency_denom(s),
1360 PERR (
"inappropriate base currency %s " 1361 "given split currency=%s and commodity=%s\n",
1368 SET_GAINS_A_VDIRTY(s);
1370 qof_instance_set_dirty(QOF_INSTANCE(s));
1377 if (!s || !s->acc || !s->parent)
return gnc_numeric_zero();
1386 PERR (
"inappropriate base currency %s " 1387 "given split currency=%s and commodity=%s\n",
1391 return gnc_numeric_zero();
1398 xaccSplitConvertAmount (
const Split *split,
const Account * account)
1400 gnc_commodity *acc_com, *to_commodity;
1402 gnc_numeric amount, value, convrate;
1409 if (split_acc == account)
1432 gnc_commodity* split_comm =
1438 PERR(
"The split's (%s) amount can't be converted from %s into %s.",
1443 return gnc_numeric_zero();
1461 convrate = xaccTransGetAccountConvRate(txn, account);
1477 if (!split)
return TRUE;
1480 trans = split->parent;
1489 qof_instance_set_dirty(QOF_INSTANCE(split));
1490 qof_instance_set_destroying(split, TRUE);
1505 const char *da, *db;
1506 gboolean action_for_num;
1508 if (sa == sb)
return 0;
1519 sb->parent, sb->action);
1522 if (retval)
return retval;
1525 da = sa->memo ? sa->memo :
"";
1526 db = sb->memo ? sb->memo :
"";
1527 retval = g_utf8_collate (da, db);
1532 da = sa->action ? sa->action :
"";
1533 db = sb->action ? sb->action :
"";
1534 retval = g_utf8_collate (da, db);
1539 if (sa->reconciled < sb->reconciled)
return -1;
1540 if (sa->reconciled > sb->reconciled)
return +1;
1544 if (comp < 0)
return -1;
1545 if (comp > 0)
return +1;
1548 if (comp < 0)
return -1;
1549 if (comp > 0)
return +1;
1552 if (sa->date_reconciled < sb->date_reconciled)
1554 else if (sa->date_reconciled > sb->date_reconciled)
1559 if (retval)
return retval;
1565 xaccSplitOrderDateOnly (
const Split *sa,
const Split *sb)
1567 Transaction *ta, *tb;
1569 if (sa == sb)
return 0;
1576 if ( !ta && !tb )
return 0;
1577 if ( !tb )
return -1;
1578 if ( !ta )
return +1;
1580 if (ta->date_posted == tb->date_posted)
1582 return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
1586 get_corr_account_split(
const Split *sa,
const Split **retval)
1589 g_return_val_if_fail(sa, FALSE);
1605 static const char *split_const =
nullptr;
1606 const Split *other_split;
1608 if (!get_corr_account_split(sa, &other_split))
1611 split_const = _(
"-- Split Transaction --");
1622 static const char *split_const =
nullptr;
1623 const Split *other_split;
1625 if (!get_corr_account_split(sa, &other_split))
1628 split_const = _(
"-- Split Transaction --");
1630 return g_strdup(split_const);
1638 static const char *split_const =
nullptr;
1639 const Split *other_split;
1641 if (!get_corr_account_split(sa, &other_split))
1644 split_const = C_(
"Displayed account code of the other account in a multi-split transaction",
"Split");
1656 char *full_a, *full_b;
1658 if (!sa && !sb)
return 0;
1666 retval = g_utf8_collate(full_a, full_b);
1677 if (!sa && !sb)
return 0;
1692 if (!sa && !sb)
return 0;
1702 retval = g_strcmp0(ca, cb);
1711 const char *ca, *cb;
1712 if (!sa && !sb)
return 0;
1718 return g_strcmp0(ca, cb);
1722 qofSplitSetMemo (Split *split,
const char* memo)
1724 g_return_if_fail(split);
1725 CACHE_REPLACE(split->memo, memo);
1731 if (!split || !memo)
return;
1734 CACHE_REPLACE(split->memo, memo);
1735 qof_instance_set_dirty(QOF_INSTANCE(split));
1741 qofSplitSetAction (Split *split,
const char *actn)
1743 g_return_if_fail(split);
1744 CACHE_REPLACE(split->action, actn);
1750 if (!split || !actn)
return;
1753 CACHE_REPLACE(split->action, actn);
1754 qof_instance_set_dirty(QOF_INSTANCE(split));
1760 qofSplitSetReconcile (Split *split,
char recn)
1762 g_return_if_fail(split);
1770 split->reconciled = recn;
1775 PERR(
"Bad reconciled flag");
1783 if (!split || split->reconciled == recn)
return;
1793 split->reconciled = recn;
1795 qof_instance_set_dirty(QOF_INSTANCE(split));
1799 PERR(
"Bad reconciled flag");
1812 split->date_reconciled = secs;
1813 qof_instance_set_dirty(QOF_INSTANCE(split));
1823 return split ? split->date_reconciled : 0;
1834 return split ? split->parent :
nullptr;
1838 xaccSplitSetParent(Split *s, Transaction *t)
1840 Transaction *old_trans;
1843 g_return_if_fail(s);
1844 if (s->parent == t)
return;
1846 if (s->parent != s->orig_parent && s->orig_parent != t)
1847 PERR(
"You may not add the split to more than one transaction" 1848 " during the BeginEdit/CommitEdit block.");
1850 old_trans = s->parent;
1858 qof_event_gen(&old_trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1863 qof_instance_set_dirty(QOF_INSTANCE(s));
1871 if (
nullptr == g_list_find(t->splits, s))
1872 t->splits = g_list_append(t->splits, s);
1884 return split ? split->lot :
nullptr;
1892 qof_instance_set_dirty(QOF_INSTANCE(split));
1899 return split ? split->memo :
nullptr;
1905 return split ? split->action :
nullptr;
1911 return split ? split->reconciled :
' ';
1918 return split ? split->amount : gnc_numeric_zero();
1924 return split ? split->value : gnc_numeric_zero();
1930 gnc_numeric amt, val, price;
1931 if (!split)
return gnc_numeric_create(0, 1);
1941 return gnc_numeric_create(0, 1);
1953 PERR(
"Computing share price failed (%d): [ %" G_GINT64_FORMAT
" / %" 1954 G_GINT64_FORMAT
" ] / [ %" G_GINT64_FORMAT
" / %" G_GINT64_FORMAT
" ]",
1956 return gnc_numeric_create(0, 1);
1974 if (!s)
return nullptr;
1976 GValue v = G_VALUE_INIT;
1979 type = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) :
nullptr;
1981 if (!type || !g_strcmp0 (type, split_type_normal))
1982 rv = split_type_normal;
1983 else if (!g_strcmp0 (type, split_type_stock_split))
1984 rv = split_type_stock_split;
1987 PERR (
"unexpected split-type %s, reset to normal.", type);
1988 rv = split_type_normal;
1999 GValue v = G_VALUE_INIT;
2002 s->value = gnc_numeric_zero();
2003 g_value_init (&v, G_TYPE_STRING);
2004 g_value_set_static_string (&v, split_type_stock_split);
2006 SET_GAINS_VDIRTY(s);
2008 qof_instance_set_dirty(QOF_INSTANCE(s));
2019 g_return_if_fail (split !=
nullptr);
2020 g_return_if_fail (other_split !=
nullptr);
2024 qof_instance_kvp_add_guid (QOF_INSTANCE (split),
"lot-split",
2027 qof_instance_set_dirty (QOF_INSTANCE (split));
2034 return qof_instance_has_slot (QOF_INSTANCE (split),
"lot-split");
2042 g_return_val_if_fail (split !=
nullptr, FALSE);
2043 g_return_val_if_fail (other_split !=
nullptr, FALSE);
2046 return qof_instance_kvp_has_guid (QOF_INSTANCE (split),
"lot-split",
2055 g_return_if_fail (split !=
nullptr);
2056 g_return_if_fail (other_split !=
nullptr);
2060 qof_instance_kvp_remove_guid (QOF_INSTANCE (split),
"lot-split",
2063 qof_instance_set_dirty (QOF_INSTANCE (split));
2071 qof_instance_kvp_merge_guids (QOF_INSTANCE (split),
2072 QOF_INSTANCE (other_split),
"lot-split");
2074 qof_instance_set_dirty (QOF_INSTANCE (split));
2094 Split *other =
nullptr;
2096 if (!split)
return nullptr;
2097 trans = split->parent;
2098 if (!trans)
return nullptr;
2102 Split *s = GNC_SPLIT(n->data);
2104 (!xaccTransStillHasSplit(trans, s)) ||
2106 (qof_instance_has_slot (QOF_INSTANCE (s),
"lot-split")))
2123 GValue v = G_VALUE_INIT;
2124 gnc_numeric *num =
nullptr;
2126 g_return_val_if_fail(split, gnc_numeric_zero());
2128 if (G_VALUE_HOLDS_BOXED (&v))
2129 num = (gnc_numeric*)g_value_get_boxed (&v);
2130 retval = num ? *num : gnc_numeric_zero();
2138 GValue v = G_VALUE_INIT;
2139 gnc_numeric *num =
nullptr;
2141 g_return_val_if_fail(split, gnc_numeric_zero());
2143 if (G_VALUE_HOLDS_BOXED (&v))
2144 num = (gnc_numeric*)g_value_get_boxed (&v);
2145 retval = num ? *num : gnc_numeric_zero();
2151 xaccSplitVoid(Split *split)
2153 gnc_numeric zero = gnc_numeric_zero(), num;
2154 GValue v = G_VALUE_INIT;
2156 g_value_init (&v, GNC_TYPE_NUMERIC);
2158 g_value_set_boxed (&v, &num);
2162 g_value_set_boxed (&v, &num);
2173 xaccSplitUnvoid(Split *split)
2180 qof_instance_set_dirty (QOF_INSTANCE (split));
2196 static QofObject split_object_def =
2199 DI(.e_type = ) GNC_ID_SPLIT,
2200 DI(.type_label = ) "Split",
2202 DI(.book_begin = )
nullptr,
2203 DI(.book_end = )
nullptr,
2206 DI(.foreach = ) qof_collection_foreach,
2212 split_account_guid_getter (gpointer obj, const QofParam *p)
2214 Split *s = GNC_SPLIT(obj);
2217 if (!s)
return nullptr;
2219 if (!acc)
return nullptr;
2224 DxaccSplitGetShareAmount (
const Split * split)
2230 no_op (gpointer obj,
const QofParam *p)
2236 qofSplitSetParentTrans(Split *s,
QofInstance *ent)
2238 Transaction *trans = (Transaction*)ent;
2240 g_return_if_fail(trans);
2241 xaccSplitSetParent(s, trans);
2249 g_return_if_fail(acc);
2250 xaccSplitSetAccount(s, acc);
2253 gboolean xaccSplitRegister (
void)
2255 static const QofParam params[] =
2258 SPLIT_DATE_RECONCILED, QOF_TYPE_DATE,
2266 "d-share-amount", QOF_TYPE_DOUBLE,
2270 "d-share-int64", QOF_TYPE_INT64,
2274 SPLIT_BALANCE, QOF_TYPE_NUMERIC,
2278 SPLIT_CLEARED_BALANCE, QOF_TYPE_NUMERIC,
2282 SPLIT_RECONCILED_BALANCE, QOF_TYPE_NUMERIC,
2286 SPLIT_MEMO, QOF_TYPE_STRING,
2290 SPLIT_ACTION, QOF_TYPE_STRING,
2294 SPLIT_RECONCILE, QOF_TYPE_CHAR,
2299 SPLIT_AMOUNT, QOF_TYPE_NUMERIC,
2303 SPLIT_SHARE_PRICE, QOF_TYPE_NUMERIC,
2308 SPLIT_VALUE, QOF_TYPE_DEBCRED,
2313 SPLIT_VOIDED_AMOUNT, QOF_TYPE_NUMERIC,
2317 SPLIT_VOIDED_VALUE, QOF_TYPE_NUMERIC,
2322 SPLIT_TRANS, GNC_ID_TRANS,
2327 SPLIT_ACCOUNT, GNC_ID_ACCOUNT,
2333 { SPLIT_ACCT_FULLNAME, SPLIT_ACCT_FULLNAME, no_op,
nullptr },
2334 { SPLIT_CORR_ACCT_NAME, SPLIT_CORR_ACCT_NAME, no_op,
nullptr },
2335 { SPLIT_CORR_ACCT_CODE, SPLIT_CORR_ACCT_CODE, no_op,
nullptr },
2338 QOF_PARAM_GUID, QOF_TYPE_GUID,
2357 _utest_split_fill_functions (
void)
2361 func->xaccSplitEqualCheckBal = xaccSplitEqualCheckBal;
2362 func->get_currency_denom = get_currency_denom;
2363 func->get_commodity_denom = get_commodity_denom;
2364 func->get_corr_account_split = get_corr_account_split;
void xaccSplitSetValue(Split *s, gnc_numeric amt)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
gnc_numeric xaccSplitGetClearedBalance(const Split *s)
The cleared-balance is the currency-denominated balance of all transactions that have been marked as ...
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.
void xaccSplitAddPeerSplit(Split *split, const Split *other_split, time64 timestamp)
Add a peer split to this split's lot-split list.
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...
void xaccSplitSetAction(Split *split, const char *actn)
The Action is an arbitrary user-assigned string.
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 xaccSplitMakeStockSplit(Split *s)
Mark a split to be of type stock split - after this, you shouldn't modify the value anymore...
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of account.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
#define qof_instance_is_dirty
Return value of is_dirty flag.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
#define PINFO(format, args...)
Print an informational note.
gnc_numeric xaccSplitGetReconciledBalance(const Split *s)
Returns the reconciled-balance of this split.
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.
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
GncGUID * guid_copy(const GncGUID *guid)
Returns a newly allocated GncGUID that matches the passed-in GUID.
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.
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.
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
Returns TRUE if this book uses split action field as the 'Num' field, FALSE if it uses transaction nu...
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 gnc_lot_add_split(GNCLot *lot, Split *split)
Adds a split to this lot.
gboolean gnc_account_remove_split(Account *acc, Split *s)
Remove the given split from an account.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Object instance holds common fields that most gnucash objects use.
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
The xaccAccountInsertLot() method will register the indicated lot with this account.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
API for Transactions and Splits (journal entries)
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...
void xaccSplitRemovePeerSplit(Split *split, const Split *other_split)
Remove a peer split from this split's lot-split list.
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.
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.
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.
int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of the other account.
#define PERR(format, args...)
Log a serious error.
QofBook * xaccSplitGetBook(const Split *split)
Returns the book of this split, i.e.
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.
gnc_numeric xaccSplitGetBalance(const Split *s)
Returns the running balance up to and including the indicated split.
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
Split * xaccSplitGetCapGainsSplit(const Split *split)
The xaccSplitGetCapGainsSplit() routine returns the split that records the cap gains for this split...
void gnc_lot_set_closed_unknown(GNCLot *lot)
Reset closed flag so that it will be recalculated.
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of account.
#define VREC
split is void
Account used to record multiple commodity transactions.
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
gboolean xaccSplitHasPeers(const Split *split)
Does this split have peers?
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
int xaccTransCountSplits(const Transaction *trans)
Returns the number of splits in this transaction.
#define xaccAccountGetGUID(X)
double gnc_numeric_to_double(gnc_numeric in)
Convert numeric to floating-point value.
convert single-entry accounts to clean double-entry
void xaccSplitMergePeerSplits(Split *split, const Split *other_split)
Merge the other_split's peer splits into split's peers.
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
Returns the original pre-void amount of a split.
Split * xaccSplitLookup(const GncGUID *guid, QofBook *book)
The xaccSplitLookup() subroutine will return the split associated with the given id, or NULL if there is no such split.
guint32 qof_instance_get_idata(gconstpointer inst)
get the instance tag number used for kvp management in sql backends.
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
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 '...
gnc_numeric xaccSplitVoidFormerValue(const Split *split)
Returns the original pre-void value of a split.
#define YREC
The Split has been reconciled.
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
const char * gnc_numeric_errorCode_to_string(GNCNumericErrorCode error_code)
Returns a string representation of the given GNCNumericErrorCode.
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
#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
int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of the other account.
void xaccSplitSetSharePriceAndAmount(Split *s, gnc_numeric price, gnc_numeric amt)
The xaccSplitSetSharePriceAndAmount() method will simultaneously update the share price and the numbe...
void qof_instance_copy_book(gpointer ptr1, gconstpointer ptr2)
Copy the book from one QofInstances to another.
gnc_numeric xaccSplitGetNoclosingBalance(const Split *s)
The noclosing-balance is the currency-denominated balance of all transactions except 'closing' transa...
#define SPLIT_ACCOUNT_GUID
for guid_match_all
void xaccAccountRecomputeBalance(Account *acc)
The following recompute the partial balances (stored with the transaction) and the total balance...
gboolean xaccSplitIsPeerSplit(const Split *split, const Split *other_split)
Report if a split is a peer of this one.
char * xaccSplitGetCorrAccountFullName(const Split *sa)
These functions take a split, get the corresponding split on the "other side" of the transaction...
void gnc_lot_remove_split(GNCLot *lot, Split *split)
Adds a split from this lot.
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
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
#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 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)
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
gnc_numeric xaccSplitGetSharePrice(const Split *split)
Returns the price of the split, that is, the value divided by the amount.
int xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
Inverse of xaccTransGetSplit()
gboolean gnc_numeric_eq(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b are exactly the same (have the same numerator and ...
All type declarations for the whole Gnucash engine.
const GncGUID * qof_entity_get_guid(gconstpointer ent)
#define CREC
The Split has been cleared.
gboolean qof_instance_books_equal(gconstpointer ptr1, gconstpointer ptr2)
See if two QofInstances share the same book.
gnc_numeric xaccSplitGetBaseValue(const Split *s, const gnc_commodity *base_currency)
Depending on the base_currency, return either the value or the amount of this split: If the base_curr...
Split * xaccMallocSplit(QofBook *book)
Constructor.
const char * xaccSplitGetCorrAccountName(const Split *sa)
document me
Encapsulate all the information about a dataset.
gboolean gnc_account_insert_split(Account *acc, Split *s)
Insert the given split from an account.
void xaccSplitSetLot(Split *split, GNCLot *lot)
Assigns the split to a specific Lot.
API for the transaction logger.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
void xaccSplitSetDateReconciledSecs(Split *split, time64 secs)
Set the date on which this split was reconciled by specifying the time as time64. ...
time64 xaccSplitGetDateReconciled(const Split *split)
Retrieve the date when the Split was reconciled.
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Account * xaccSplitGetAccount(const Split *s)
Returns the account of this split, which was set through xaccAccountInsertSplit().
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
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...
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
const char * xaccSplitGetCorrAccountCode(const Split *sa)
document me
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits...
#define LEAVE(format, args...)
Print a function exit debugging message.
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.
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
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...
Account * gnc_lot_get_account(const GNCLot *lot)
Returns the account with which this lot is associated.
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
const char * xaccSplitGetType(const Split *s)
The xaccIsPeerSplit() is a convenience routine that returns TRUE (a non-zero value) if the two splits...
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
#define GNC_EVENT_ITEM_ADDED
These events are used when a split is added to an account.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
The type used to store guids in C.
Utilities to Automatically Compute Capital Gains/Losses.
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.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
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.