35 #include <glib/gi18n.h> 38 #ifdef HAVE_SYS_TIME_H 39 # include <sys/time.h> 51 #include "TransactionP.h" 58 #include "qofinstance-p.h" 60 const char *void_former_amt_str =
"void-former-amount";
61 const char *void_former_val_str =
"void-former-value";
64 static QofLogModule log_module = GNC_MOD_ENGINE;
67 #define GNC_SX_ID "sched-xaction" 68 #define GNC_SX_ACCOUNT "account" 69 #define GNC_SX_CREDIT_FORMULA "credit-formula" 70 #define GNC_SX_DEBIT_FORMULA "debit-formula" 71 #define GNC_SX_CREDIT_NUMERIC "credit-numeric" 72 #define GNC_SX_DEBIT_NUMERIC "debit-numeric" 73 #define GNC_SX_SHARES "shares" 86 PROP_SX_CREDIT_FORMULA,
87 PROP_SX_CREDIT_NUMERIC,
88 PROP_SX_DEBIT_FORMULA,
89 PROP_SX_DEBIT_NUMERIC,
100 static const char * is_unset =
"unset";
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)
112 split->orig_acc = NULL;
113 split->parent = NULL;
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;
123 split->split_type = is_unset;
125 split->balance = gnc_numeric_zero();
126 split->cleared_balance = gnc_numeric_zero();
127 split->reconciled_balance = gnc_numeric_zero();
128 split->noclosing_balance = gnc_numeric_zero();
130 split->gains = GAINS_STATUS_UNKNOWN;
131 split->gains_split = NULL;
135 gnc_split_dispose(GObject *splitp)
137 G_OBJECT_CLASS(gnc_split_parent_class)->dispose(splitp);
141 gnc_split_finalize(GObject* splitp)
143 G_OBJECT_CLASS(gnc_split_parent_class)->finalize(splitp);
152 gnc_split_get_property(GObject *
object,
161 g_return_if_fail(GNC_IS_SPLIT(
object));
163 split = GNC_SPLIT(
object);
167 g_value_set_string(value, split->action);
170 g_value_set_string(value, split->memo);
173 g_value_set_boxed(value, &split->value);
176 g_value_set_boxed(value, &split->amount);
178 case PROP_RECONCILE_DATE:
179 t.t = split->date_reconciled;
180 g_value_set_boxed(value, &t);
183 g_value_take_object(value, split->parent);
186 g_value_take_object(value, split->acc);
189 g_value_take_object(value, split->lot);
191 case PROP_SX_CREDIT_FORMULA:
194 case PROP_SX_CREDIT_NUMERIC:
197 case PROP_SX_DEBIT_FORMULA:
200 case PROP_SX_DEBIT_NUMERIC:
203 case PROP_SX_ACCOUNT:
209 case PROP_ONLINE_ACCOUNT:
212 case PROP_GAINS_SPLIT:
215 case PROP_GAINS_SOURCE:
219 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
225 gnc_split_set_property(GObject *
object,
234 g_return_if_fail(GNC_IS_SPLIT(
object));
236 split = GNC_SPLIT(
object);
237 if (prop_id < PROP_RUNTIME_0 && split->parent != NULL)
238 g_assert (qof_instance_get_editlevel(split->parent));
249 number = g_value_get_boxed(value);
253 number = g_value_get_boxed(value);
256 case PROP_RECONCILE_DATE:
257 t = g_value_get_boxed(value);
261 xaccSplitSetParent(split, g_value_get_object(value));
264 xaccSplitSetAccount(split, g_value_get_object(value));
269 case PROP_SX_CREDIT_FORMULA:
272 case PROP_SX_CREDIT_NUMERIC:
275 case PROP_SX_DEBIT_FORMULA:
278 case PROP_SX_DEBIT_NUMERIC:
281 case PROP_SX_ACCOUNT:
287 case PROP_ONLINE_ACCOUNT:
290 case PROP_GAINS_SPLIT:
293 case PROP_GAINS_SOURCE:
297 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
303 gnc_split_class_init(SplitClass* klass)
305 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
307 gobject_class->dispose = gnc_split_dispose;
308 gobject_class->finalize = gnc_split_finalize;
309 gobject_class->set_property = gnc_split_set_property;
310 gobject_class->get_property = gnc_split_get_property;
312 g_object_class_install_property
315 g_param_spec_string(
"action",
317 "The action is an arbitrary string assigned " 318 "by the user. It is intended to be a short " 319 "string that contains extra information about " 324 g_object_class_install_property
327 g_param_spec_string(
"memo",
329 "The action is an arbitrary string assigned " 330 "by the user. It is intended to be a short " 331 "string that describes the purpose of " 336 g_object_class_install_property
339 g_param_spec_boxed(
"value",
341 "The value for this split in the common currency. " 342 "The value and the amount provide enough information to " 343 "calculate a conversion rate.",
347 g_object_class_install_property
350 g_param_spec_boxed(
"amount",
352 "The value for this split in the currency of its account. " 353 "The value and the amount provide enough information to " 354 "calculate a conversion rate.",
358 g_object_class_install_property
361 g_param_spec_boxed(
"reconcile-date",
363 "The date this split was reconciled.",
367 g_object_class_install_property
370 g_param_spec_object (
"transaction",
372 "The transaction that this split belongs to.",
373 GNC_TYPE_TRANSACTION,
376 g_object_class_install_property
379 g_param_spec_object (
"account",
381 "The account that this split belongs to.",
385 g_object_class_install_property
388 g_param_spec_object (
"lot",
390 "The lot that this split belongs to.",
394 g_object_class_install_property
396 PROP_SX_DEBIT_FORMULA,
397 g_param_spec_string(
"sx-debit-formula",
398 "Schedule Transaction Debit Formula",
399 "The formula used to calculate the actual debit " 400 "amount when a real split is generated from this " 405 g_object_class_install_property
407 PROP_SX_DEBIT_NUMERIC,
408 g_param_spec_boxed(
"sx-debit-numeric",
409 "Scheduled Transaction Debit Numeric",
410 "Numeric value to plug into the Debit Formula when a " 411 "real split is generated from this SX split.",
415 g_object_class_install_property
417 PROP_SX_CREDIT_FORMULA,
418 g_param_spec_string(
"sx-credit-formula",
419 "Schedule Transaction Credit Formula",
420 "The formula used to calculate the actual credit " 421 "amount when a real split is generated from this " 426 g_object_class_install_property
428 PROP_SX_CREDIT_NUMERIC,
429 g_param_spec_boxed(
"sx-credit-numeric",
430 "Scheduled Transaction Credit Numeric",
431 "Numeric value to plug into the Credit Formula when a " 432 "real split is generated from this SX split.",
440 g_object_class_install_property
443 g_param_spec_string(
"sx-shares",
444 "Scheduled Transaction Shares",
445 "Numeric value of shares to insert in a new split when " 446 "it's generated from this SX split.",
450 g_object_class_install_property
453 g_param_spec_boxed(
"sx-account",
454 "Scheduled Transaction Account",
455 "The target account for a scheduled transaction split.",
459 g_object_class_install_property
462 g_param_spec_string (
"online-id",
464 "The online account which corresponds to this " 465 "account for OFX/HCBI import",
469 g_object_class_install_property
472 g_param_spec_boxed (
"gains-split",
474 "The capital gains split associated with this " 475 "split when this split represents the proceeds " 476 "from the sale of a commodity inside a Lot.",
480 g_object_class_install_property
483 g_param_spec_boxed (
"gains-source",
485 "The source split for which this split this is " 497 xaccInitSplit(Split * split, QofBook *book)
503 xaccSplitReinit(Split * split)
507 split->orig_acc = NULL;
508 split->parent = NULL;
511 CACHE_REPLACE(split->action,
"");
512 CACHE_REPLACE(split->memo,
"");
513 split->reconciled =
NREC;
514 split->amount = gnc_numeric_zero();
515 split->value = gnc_numeric_zero();
517 split->date_reconciled = 0;
519 split->balance = gnc_numeric_zero();
520 split->cleared_balance = gnc_numeric_zero();
521 split->reconciled_balance = gnc_numeric_zero();
522 split->noclosing_balance = gnc_numeric_zero();
524 qof_instance_set_idata(split, 0);
526 split->gains = GAINS_STATUS_UNKNOWN;
527 split->gains_split = NULL;
537 g_return_val_if_fail (book, NULL);
539 split = g_object_new (GNC_TYPE_SPLIT, NULL);
540 xaccInitSplit (split, book);
555 xaccDupeSplit (
const Split *s)
557 Split *split = g_object_new (GNC_TYPE_SPLIT, NULL);
563 split->inst.e_type = NULL;
564 qof_instance_copy_guid(split, s);
567 split->parent = s->parent;
569 split->orig_acc = s->orig_acc;
572 CACHE_REPLACE(split->memo, s->memo);
573 CACHE_REPLACE(split->action, s->action);
575 qof_instance_copy_kvp (QOF_INSTANCE (split), QOF_INSTANCE (s));
577 split->reconciled = s->reconciled;
578 split->date_reconciled = s->date_reconciled;
580 split->value = s->value;
581 split->amount = s->amount;
593 xaccSplitCloneNoKvp (
const Split *s)
595 Split *split = g_object_new (GNC_TYPE_SPLIT, NULL);
597 split->parent = NULL;
598 split->memo = CACHE_INSERT(s->memo);
599 split->action = CACHE_INSERT(s->action);
600 split->reconciled = s->reconciled;
601 split->date_reconciled = s->date_reconciled;
602 split->value = s->value;
603 split->amount = s->amount;
604 split->balance = s->balance;
605 split->cleared_balance = s->cleared_balance;
606 split->reconciled_balance = s->reconciled_balance;
607 split->noclosing_balance = s->noclosing_balance;
609 split->gains = GAINS_STATUS_UNKNOWN;
610 split->gains_split = NULL;
624 xaccSplitCopyKvp (
const Split *from, Split *to)
626 qof_instance_copy_kvp (QOF_INSTANCE (to), QOF_INSTANCE (from));
641 if (!from_split || !to_split)
return;
654 qof_instance_set_dirty(QOF_INSTANCE(to_split));
661 #ifdef DUMP_FUNCTIONS 663 xaccSplitDump (
const Split *split,
const char *tag)
666 memset (datebuff, 0,
sizeof(datebuff));
668 printf(
" %s Split %p", tag, split);
670 printf(
" Account: %p (%s)\n", split->acc,
672 printf(
" Commod: %s\n",
676 printf(
" Lot: %p\n", split->lot);
677 printf(
" Parent: %p\n", split->parent);
678 printf(
" Gains: %p\n", split->gains_split);
679 printf(
" Memo: %s\n", split->memo ? split->memo :
"(null)");
680 printf(
" Action: %s\n", split->action ? split->action :
"(null)");
681 printf(
" KVP Data: %s\n", qof_instance_kvp_as_string (QOF_INSTANCE (split)));
682 printf(
" Recncld: %c (date %s)\n", split->reconciled, datebuff);
688 printf(
" RBalance: %s\n",
699 xaccFreeSplit (Split *split)
704 if (((
char *) 1) == split->memo)
706 PERR (
"double-free %p", split);
709 CACHE_REMOVE(split->memo);
710 CACHE_REMOVE(split->action);
713 split->memo = (
char *) 1;
714 split->action = NULL;
715 split->reconciled =
NREC;
716 split->amount = gnc_numeric_zero();
717 split->value = gnc_numeric_zero();
718 split->parent = NULL;
721 split->orig_acc = NULL;
722 split->split_type = NULL;
724 split->date_reconciled = 0;
725 G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
727 if (split->gains_split) split->gains_split->gains_split = NULL;
729 g_object_unref(split);
732 void mark_split (Split *s)
736 g_object_set(s->acc,
"sort-dirty", TRUE,
"balance-dirty", TRUE, NULL);
747 xaccSplitEqualCheckBal (
const char *tag, gnc_numeric a, gnc_numeric b)
757 PINFO (
"%sbalances differ: %s vs %s", tag, str_a, str_b);
770 gboolean check_guids,
771 gboolean check_balances,
772 gboolean check_txn_splits)
776 if (!sa && !sb)
return TRUE;
780 PINFO (
"one is NULL");
784 if (sa == sb)
return TRUE;
792 PINFO (
"GUIDs differ");
798 if ((same_book && sa->memo != sb->memo) || (!same_book && g_strcmp0(sa->memo, sb->memo) != 0))
800 PINFO (
"memos differ: (%p)%s vs (%p)%s",
801 sa->memo, sa->memo, sb->memo, sb->memo);
805 if ((same_book && sa->action != sb->action) || (!same_book && g_strcmp0(sa->action, sb->action) != 0))
807 PINFO (
"actions differ: %s vs %s", sa->action, sb->action);
811 if (qof_instance_compare_kvp (QOF_INSTANCE (sa), QOF_INSTANCE (sb)) != 0)
816 frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (sa));
817 frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (sb));
819 PINFO (
"kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
827 if (sa->reconciled != sb->reconciled)
829 PINFO (
"reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
833 if (sa->date_reconciled != sb->date_reconciled)
835 PINFO (
"reconciled date differs");
847 PINFO (
"amounts differ: %s vs %s", str_a, str_b);
863 PINFO (
"values differ: %s vs %s", str_a, str_b);
873 if (!xaccSplitEqualCheckBal (
"", sa->balance, sb->balance))
875 if (!xaccSplitEqualCheckBal (
"cleared ", sa->cleared_balance,
876 sb->cleared_balance))
878 if (!xaccSplitEqualCheckBal (
"reconciled ", sa->reconciled_balance,
879 sb->reconciled_balance))
881 if (!xaccSplitEqualCheckBal (
"noclosing ", sa->noclosing_balance,
882 sb->noclosing_balance))
886 if (!
xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
887 check_balances, FALSE))
889 PINFO (
"transactions differ");
902 xaccSplitListGetUniqueTransactionsReversed (
const GList *splits)
904 GHashTable *txn_hash = g_hash_table_new (NULL, NULL);
905 GList *transList = NULL;
908 for (snode = splits; snode; snode = snode->next)
912 if (g_hash_table_contains (txn_hash, trans))
915 g_hash_table_insert (txn_hash, trans, NULL);
916 transList = g_list_prepend (transList, trans);
918 g_hash_table_destroy (txn_hash);
923 xaccSplitListGetUniqueTransactions(
const GList *splits)
925 return g_list_reverse (xaccSplitListGetUniqueTransactionsReversed (splits));
938 return s ? s->acc : NULL;
942 xaccSplitSetAccount (Split *s,
Account *acc)
946 g_return_if_fail(s && acc);
954 qof_instance_set_dirty(QOF_INSTANCE(s));
962 PERR(
"commit error: %d", errcode);
963 gnc_engine_signal_commit_error( errcode );
968 xaccSplitCommitEdit(Split *s)
977 orig_acc = s->orig_acc;
979 if (GNC_IS_ACCOUNT(s->acc))
985 gnc_lot_remove_split (s->lot, s);
992 PERR(
"Account lost track of moved or deleted split.");
1008 PERR(
"Account grabbed split prematurely.");
1013 if (s->parent != s->orig_parent)
1023 qof_event_gen (QOF_INSTANCE(s->lot), QOF_EVENT_MODIFY, NULL);
1029 s->orig_acc = s->acc;
1030 s->orig_parent = s->parent;
1037 g_object_set(acc,
"sort-dirty", TRUE,
"balance-dirty", TRUE, NULL);
1044 xaccSplitRollbackEdit(Split *s)
1050 if (s->acc != s->orig_acc)
1051 s->acc = s->orig_acc;
1057 qof_instance_set_destroying(s, FALSE);
1065 xaccSplitSetParent(s, s->orig_parent);
1075 if (!guid || !book)
return NULL;
1091 xaccSplitDetermineGainStatus (Split *split)
1094 GValue v = G_VALUE_INIT;
1097 if (GAINS_STATUS_UNKNOWN != split->gains)
return;
1102 split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
1103 split->gains_split = other;
1108 if (G_VALUE_HOLDS_BOXED (&v))
1109 guid = (
GncGUID*)g_value_get_boxed (&v);
1113 split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
1120 split->gains = GAINS_STATUS_GAINS;
1122 split->gains_split = other;
1131 get_currency_denom(
const Split * s)
1137 else if (!s->parent || !s->parent->common_currency)
1148 get_commodity_denom(
const Split * s)
1179 SET_GAINS_A_VDIRTY(s);
1181 qof_instance_set_dirty(QOF_INSTANCE(s));
1187 qofSplitSetSharePrice (Split *split, gnc_numeric price)
1189 g_return_if_fail(split);
1191 price, get_currency_denom(split),
1207 price, get_currency_denom(s),
1210 SET_GAINS_VDIRTY(s);
1212 qof_instance_set_dirty(QOF_INSTANCE(s));
1218 qofSplitSetAmount (Split *split, gnc_numeric amt)
1220 g_return_if_fail(split);
1228 split->amount = amt;
1238 ENTER (
"(split=%p) old amt=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT
1239 " new amt=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT, s,
1240 s->amount.num, s->amount.denom, amt.num, amt.denom);
1252 SET_GAINS_ADIRTY(s);
1254 qof_instance_set_dirty(QOF_INSTANCE(s));
1260 qofSplitSetValue (Split *split, gnc_numeric amt)
1262 g_return_if_fail(split);
1272 gnc_numeric new_val;
1276 ENTER (
"(split=%p) old val=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT
1277 " new val=%" G_GINT64_FORMAT
"/%" G_GINT64_FORMAT, s,
1278 s->value.num, s->value.denom, amt.num, amt.denom);
1288 SET_GAINS_VDIRTY(s);
1290 qof_instance_set_dirty(QOF_INSTANCE(s));
1301 return s ? s->balance : gnc_numeric_zero();
1307 return s ? s->noclosing_balance : gnc_numeric_zero();
1313 return s ? s->cleared_balance : gnc_numeric_zero();
1319 return s ? s->reconciled_balance : gnc_numeric_zero();
1324 const gnc_commodity * base_currency)
1326 const gnc_commodity *currency;
1327 const gnc_commodity *commodity;
1334 PERR (
"split must have a parent account");
1349 get_commodity_denom(s),
1353 get_currency_denom(s),
1363 PERR (
"inappropriate base currency %s " 1364 "given split currency=%s and commodity=%s\n",
1371 SET_GAINS_A_VDIRTY(s);
1373 qof_instance_set_dirty(QOF_INSTANCE(s));
1380 if (!s || !s->acc || !s->parent)
return gnc_numeric_zero();
1389 PERR (
"inappropriate base currency %s " 1390 "given split currency=%s and commodity=%s\n",
1394 return gnc_numeric_zero();
1401 xaccSplitConvertAmount (
const Split *split,
const Account * account)
1403 gnc_commodity *acc_com, *to_commodity;
1405 gnc_numeric amount, value, convrate;
1412 if (split_acc == account)
1435 gnc_commodity* split_comm =
1441 PERR(
"The split's (%s) amount can't be converted from %s into %s.",
1446 return gnc_numeric_zero();
1464 convrate = xaccTransGetAccountConvRate(txn, account);
1480 if (!split)
return TRUE;
1483 trans = split->parent;
1492 qof_instance_set_dirty(QOF_INSTANCE(split));
1493 qof_instance_set_destroying(split, TRUE);
1508 const char *da, *db;
1509 gboolean action_for_num;
1511 if (sa == sb)
return 0;
1522 sb->parent, sb->action);
1525 if (retval)
return retval;
1528 da = sa->memo ? sa->memo :
"";
1529 db = sb->memo ? sb->memo :
"";
1530 retval = g_utf8_collate (da, db);
1535 da = sa->action ? sa->action :
"";
1536 db = sb->action ? sb->action :
"";
1537 retval = g_utf8_collate (da, db);
1542 if (sa->reconciled < sb->reconciled)
return -1;
1543 if (sa->reconciled > sb->reconciled)
return +1;
1547 if (comp < 0)
return -1;
1548 if (comp > 0)
return +1;
1551 if (comp < 0)
return -1;
1552 if (comp > 0)
return +1;
1555 if (sa->date_reconciled < sb->date_reconciled)
1557 else if (sa->date_reconciled > sb->date_reconciled)
1562 if (retval)
return retval;
1568 xaccSplitOrderDateOnly (
const Split *sa,
const Split *sb)
1570 Transaction *ta, *tb;
1572 if (sa == sb)
return 0;
1579 if ( !ta && !tb )
return 0;
1580 if ( !tb )
return -1;
1581 if ( !ta )
return +1;
1583 if (ta->date_posted == tb->date_posted)
1585 return (ta->date_posted > tb->date_posted) - (ta->date_posted < tb->date_posted);
1589 get_corr_account_split(
const Split *sa,
const Split **retval)
1592 g_return_val_if_fail(sa, FALSE);
1608 static const char *split_const = NULL;
1609 const Split *other_split;
1611 if (!get_corr_account_split(sa, &other_split))
1614 split_const = _(
"-- Split Transaction --");
1625 static const char *split_const = NULL;
1626 const Split *other_split;
1628 if (!get_corr_account_split(sa, &other_split))
1631 split_const = _(
"-- Split Transaction --");
1633 return g_strdup(split_const);
1641 static const char *split_const = NULL;
1642 const Split *other_split;
1644 if (!get_corr_account_split(sa, &other_split))
1647 split_const = C_(
"Displayed account code of the other account in a multi-split transaction",
"Split");
1659 char *full_a, *full_b;
1661 if (!sa && !sb)
return 0;
1669 retval = g_utf8_collate(full_a, full_b);
1680 if (!sa && !sb)
return 0;
1695 if (!sa && !sb)
return 0;
1705 retval = g_strcmp0(ca, cb);
1714 const char *ca, *cb;
1715 if (!sa && !sb)
return 0;
1721 return g_strcmp0(ca, cb);
1725 qofSplitSetMemo (Split *split,
const char* memo)
1727 g_return_if_fail(split);
1728 CACHE_REPLACE(split->memo, memo);
1734 if (!split || !memo)
return;
1737 CACHE_REPLACE(split->memo, memo);
1738 qof_instance_set_dirty(QOF_INSTANCE(split));
1744 qofSplitSetAction (Split *split,
const char *actn)
1746 g_return_if_fail(split);
1747 CACHE_REPLACE(split->action, actn);
1753 if (!split || !actn)
return;
1756 CACHE_REPLACE(split->action, actn);
1757 qof_instance_set_dirty(QOF_INSTANCE(split));
1763 qofSplitSetReconcile (Split *split,
char recn)
1765 g_return_if_fail(split);
1773 split->reconciled = recn;
1778 PERR(
"Bad reconciled flag");
1786 if (!split || split->reconciled == recn)
return;
1796 split->reconciled = recn;
1798 qof_instance_set_dirty(QOF_INSTANCE(split));
1802 PERR(
"Bad reconciled flag");
1815 split->date_reconciled = secs;
1816 qof_instance_set_dirty(QOF_INSTANCE(split));
1826 return split ? split->date_reconciled : 0;
1837 return split ? split->parent : NULL;
1841 xaccSplitSetParent(Split *s, Transaction *t)
1843 Transaction *old_trans;
1846 g_return_if_fail(s);
1847 if (s->parent == t)
return;
1849 if (s->parent != s->orig_parent && s->orig_parent != t)
1850 PERR(
"You may not add the split to more than one transaction" 1851 " during the BeginEdit/CommitEdit block.");
1853 old_trans = s->parent;
1861 qof_event_gen(&old_trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1866 qof_instance_set_dirty(QOF_INSTANCE(s));
1874 if (NULL == g_list_find(t->splits, s))
1875 t->splits = g_list_append(t->splits, s);
1887 return split ? split->lot : NULL;
1895 qof_instance_set_dirty(QOF_INSTANCE(split));
1902 return split ? split->memo : NULL;
1908 return split ? split->action : NULL;
1914 return split ? split->reconciled :
' ';
1921 return split ? split->amount : gnc_numeric_zero();
1927 return split ? split->value : gnc_numeric_zero();
1933 gnc_numeric amt, val, price;
1934 if (!split)
return gnc_numeric_create(0, 1);
1944 return gnc_numeric_create(0, 1);
1956 PERR(
"Computing share price failed (%d): [ %" G_GINT64_FORMAT
" / %" 1957 G_GINT64_FORMAT
" ] / [ %" G_GINT64_FORMAT
" / %" G_GINT64_FORMAT
" ]",
1959 return gnc_numeric_create(0, 1);
1977 if (!s)
return NULL;
1978 if (s->split_type == is_unset)
1980 GValue v = G_VALUE_INIT;
1981 Split *split = (Split*) s;
1984 type = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
1985 if (!type || !g_strcmp0 (type, split_type_normal))
1986 split->split_type = (
char*) split_type_normal;
1987 else if (!g_strcmp0 (type, split_type_stock_split))
1988 split->split_type = (
char*) split_type_stock_split;
1991 PERR (
"unexpected split-type %s, reset to normal.", type);
1992 split->split_type = split_type_normal;
1996 return s->split_type;
2004 GValue v = G_VALUE_INIT;
2007 s->value = gnc_numeric_zero();
2008 g_value_init (&v, G_TYPE_STRING);
2009 g_value_set_static_string (&v, split_type_stock_split);
2010 s->split_type = split_type_stock_split;
2012 SET_GAINS_VDIRTY(s);
2014 qof_instance_set_dirty(QOF_INSTANCE(s));
2025 g_return_if_fail (split != NULL);
2026 g_return_if_fail (other_split != NULL);
2030 qof_instance_kvp_add_guid (QOF_INSTANCE (split),
"lot-split",
2033 qof_instance_set_dirty (QOF_INSTANCE (split));
2040 return qof_instance_has_slot (QOF_INSTANCE (split),
"lot-split");
2048 g_return_val_if_fail (split != NULL, FALSE);
2049 g_return_val_if_fail (other_split != NULL, FALSE);
2052 return qof_instance_kvp_has_guid (QOF_INSTANCE (split),
"lot-split",
2061 g_return_if_fail (split != NULL);
2062 g_return_if_fail (other_split != NULL);
2066 qof_instance_kvp_remove_guid (QOF_INSTANCE (split),
"lot-split",
2069 qof_instance_set_dirty (QOF_INSTANCE (split));
2077 qof_instance_kvp_merge_guids (QOF_INSTANCE (split),
2078 QOF_INSTANCE (other_split),
"lot-split");
2080 qof_instance_set_dirty (QOF_INSTANCE (split));
2100 Split *other = NULL;
2102 if (!split)
return NULL;
2103 trans = split->parent;
2104 if (!trans)
return NULL;
2110 (!xaccTransStillHasSplit(trans, s)) ||
2112 (qof_instance_has_slot (QOF_INSTANCE (s),
"lot-split")))
2129 GValue v = G_VALUE_INIT;
2130 gnc_numeric *num = NULL;
2132 g_return_val_if_fail(split, gnc_numeric_zero());
2134 if (G_VALUE_HOLDS_BOXED (&v))
2135 num = (gnc_numeric*)g_value_get_boxed (&v);
2136 retval = num ? *num : gnc_numeric_zero();
2144 GValue v = G_VALUE_INIT;
2145 gnc_numeric *num = NULL;
2147 g_return_val_if_fail(split, gnc_numeric_zero());
2149 if (G_VALUE_HOLDS_BOXED (&v))
2150 num = (gnc_numeric*)g_value_get_boxed (&v);
2151 retval = num ? *num : gnc_numeric_zero();
2157 xaccSplitVoid(Split *split)
2159 gnc_numeric zero = gnc_numeric_zero(), num;
2160 GValue v = G_VALUE_INIT;
2162 g_value_init (&v, GNC_TYPE_NUMERIC);
2164 g_value_set_boxed (&v, &num);
2168 g_value_set_boxed (&v, &num);
2179 xaccSplitUnvoid(Split *split)
2186 qof_instance_set_dirty (QOF_INSTANCE (split));
2202 static QofObject split_object_def =
2205 DI(.e_type = ) GNC_ID_SPLIT,
2206 DI(.type_label = ) "Split",
2208 DI(.book_begin = ) NULL,
2209 DI(.book_end = ) NULL,
2218 split_account_guid_getter (gpointer obj, const QofParam *p)
2223 if (!s)
return NULL;
2225 if (!acc)
return NULL;
2230 DxaccSplitGetShareAmount (
const Split * split)
2236 no_op (gpointer obj,
const QofParam *p)
2242 qofSplitSetParentTrans(Split *s,
QofInstance *ent)
2244 Transaction *trans = (Transaction*)ent;
2246 g_return_if_fail(trans);
2247 xaccSplitSetParent(s, trans);
2255 g_return_if_fail(acc);
2256 xaccSplitSetAccount(s, acc);
2259 gboolean xaccSplitRegister (
void)
2261 static const QofParam params[] =
2264 SPLIT_DATE_RECONCILED, QOF_TYPE_DATE,
2272 "d-share-amount", QOF_TYPE_DOUBLE,
2276 "d-share-int64", QOF_TYPE_INT64,
2280 SPLIT_BALANCE, QOF_TYPE_NUMERIC,
2284 SPLIT_CLEARED_BALANCE, QOF_TYPE_NUMERIC,
2288 SPLIT_RECONCILED_BALANCE, QOF_TYPE_NUMERIC,
2292 SPLIT_MEMO, QOF_TYPE_STRING,
2296 SPLIT_ACTION, QOF_TYPE_STRING,
2300 SPLIT_RECONCILE, QOF_TYPE_CHAR,
2305 SPLIT_AMOUNT, QOF_TYPE_NUMERIC,
2309 SPLIT_SHARE_PRICE, QOF_TYPE_NUMERIC,
2314 SPLIT_VALUE, QOF_TYPE_DEBCRED,
2319 SPLIT_VOIDED_AMOUNT, QOF_TYPE_NUMERIC,
2323 SPLIT_VOIDED_VALUE, QOF_TYPE_NUMERIC,
2328 SPLIT_TRANS, GNC_ID_TRANS,
2333 SPLIT_ACCOUNT, GNC_ID_ACCOUNT,
2339 { SPLIT_ACCT_FULLNAME, SPLIT_ACCT_FULLNAME, no_op, NULL },
2340 { SPLIT_CORR_ACCT_NAME, SPLIT_CORR_ACCT_NAME, no_op, NULL },
2341 { SPLIT_CORR_ACCT_CODE, SPLIT_CORR_ACCT_CODE, no_op, NULL },
2344 QOF_PARAM_GUID, QOF_TYPE_GUID,
2363 _utest_split_fill_functions (
void)
2367 func->xaccSplitEqualCheckBal = xaccSplitEqualCheckBal;
2368 func->get_currency_denom = get_currency_denom;
2369 func->get_commodity_denom = get_commodity_denom;
2370 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.
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.
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 GNC_COMMODITY_MAX_FRACTION
Max fraction is 10^9 because 10^10 would require changing it to an int64_t.
#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.
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)
The gnc_lot_add_split() routine 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.
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.
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
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 qof_collection_foreach(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data)
Call the callback for each entity in the collection.
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...
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...
This is the private header for the account structure.
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.
void xaccSplitSetSharePrice(Split *s, gnc_numeric price)
time64 gnc_time(time64 *tbuf)
get the current local 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
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
Account * gnc_lot_get_account(const GNCLot *lot)
The gnc_lot_get_account() routine returns the account with which this lot is associated.
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.