GnuCash de0bfde+
Loading...
Searching...
No Matches
Split.cpp
1/********************************************************************\
2 * Split.c -- split implementation *
3 * Copyright (C) 1997 Robin D. Clark *
4 * Copyright (C) 1997-2003 Linas Vepstas <linas@linas.org> *
5 * Copyright (C) 2000 Bill Gribble <grib@billgribble.com> *
6 * Copyright (c) 2006 David Hampton <hampton@employees.org> *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License as *
10 * published by the Free Software Foundation; either version 2 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License*
19 * along with this program; if not, contact: *
20 * *
21 * Free Software Foundation Voice: +1-617-542-5942 *
22 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
23 * Boston, MA 02110-1301, USA gnu@gnu.org *
24 * *
25\********************************************************************/
26
27#include "qofinstance.h"
28#include <config.h>
29
30#include <platform.h>
31#if PLATFORM(WINDOWS)
32#include <windows.h>
33#endif
34
35#include <glib.h>
36#include <glib/gi18n.h>
37#include <stdlib.h>
38#include <string.h>
39#ifdef HAVE_SYS_TIME_H
40# include <sys/time.h>
41#endif
42#include <time.h>
43#ifdef HAVE_UNISTD_H
44# include <unistd.h>
45#endif
46
47#include "qof.h"
48#include "qofbook.h"
49#include "Split.h"
50#include "AccountP.hpp"
51#include "Account.hpp"
52#include "Scrub.h"
53#include "TransactionP.hpp"
54#include "TransLog.h"
55#include "cap-gains.h"
56#include "gnc-commodity.h"
57#include "gnc-engine.h"
58#include "gnc-lot.h"
59#include "gnc-event.h"
60#include "qofinstance-p.h"
61
62const char *void_former_amt_str = "void-former-amount";
63const char *void_former_val_str = "void-former-value";
64
65/* This static indicates the debugging module that this .o belongs to. */
66static QofLogModule log_module = GNC_MOD_ENGINE;
67
68/* KVP key values used for SX info stored Split's slots. */
69#define GNC_SX_ID "sched-xaction"
70#define GNC_SX_ACCOUNT "account"
71#define GNC_SX_CREDIT_FORMULA "credit-formula"
72#define GNC_SX_DEBIT_FORMULA "debit-formula"
73#define GNC_SX_CREDIT_NUMERIC "credit-numeric"
74#define GNC_SX_DEBIT_NUMERIC "debit-numeric"
75#define GNC_SX_SHARES "shares"
76
77enum
78{
79 PROP_0,
80 PROP_TX, /* Table */
81 PROP_ACCOUNT, /* Table */
82 PROP_MEMO, /* Table */
83 PROP_ACTION, /* Table */
84// PROP_RECONCILE_STATE, /* Table */
85 PROP_RECONCILE_DATE, /* Table */
86 PROP_VALUE, /* Table, in 2 fields */
87 PROP_SX_ACCOUNT, /* KVP */
88 PROP_SX_CREDIT_FORMULA, /* KVP */
89 PROP_SX_CREDIT_NUMERIC, /* KVP */
90 PROP_SX_DEBIT_FORMULA, /* KVP */
91 PROP_SX_DEBIT_NUMERIC, /* KVP */
92 PROP_SX_SHARES, /* KVP */
93 PROP_LOT, /* KVP */
94 PROP_ONLINE_ACCOUNT, /* KVP */
95 PROP_GAINS_SPLIT, /* KVP */
96 PROP_GAINS_SOURCE, /* KVP */
97 PROP_RUNTIME_0,
98 PROP_AMOUNT, /* Runtime */
99
100};
101
102static const char * split_type_normal = "normal";
103static const char * split_type_stock_split = "stock-split";
104static const char * split_online_id = "online_id";
105
106/* GObject Initialization */
107G_DEFINE_TYPE(Split, gnc_split, QOF_TYPE_INSTANCE)
108
109static void
110gnc_split_init(Split* split)
111{
112 /* fill in some sane defaults */
113 split->acc = nullptr;
114 split->orig_acc = nullptr;
115 split->parent = nullptr;
116 split->lot = nullptr;
117
118 split->action = CACHE_INSERT("");
119 split->memo = CACHE_INSERT("");
120 split->reconciled = NREC;
121 split->amount = gnc_numeric_zero();
122 split->value = gnc_numeric_zero();
123
124 split->date_reconciled = 0;
125
126 split->balance = gnc_numeric_zero();
127 split->cleared_balance = gnc_numeric_zero();
128 split->reconciled_balance = gnc_numeric_zero();
129 split->noclosing_balance = gnc_numeric_zero();
130
131 split->adjusted_amount = gnc_numeric_zero();
132 split->split_type = nullptr;
133
134 split->gains = GAINS_STATUS_UNKNOWN;
135 split->gains_split = nullptr;
136}
137
138static void
139gnc_split_dispose(GObject *splitp)
140{
141 G_OBJECT_CLASS(gnc_split_parent_class)->dispose(splitp);
142}
143
144static void
145gnc_split_finalize(GObject* splitp)
146{
147 G_OBJECT_CLASS(gnc_split_parent_class)->finalize(splitp);
148}
149/* Note that g_value_set_object() refs the object, as does
150 * g_object_get(). But g_object_get() only unrefs once when it disgorges
151 * the object, leaving an unbalanced ref, which leaks. So instead of
152 * using g_value_set_object(), use g_value_take_object() which doesn't
153 * ref the object when used in get_property().
154 */
155static void
156gnc_split_get_property(GObject *object,
157 guint prop_id,
158 GValue *value,
159 GParamSpec *pspec)
160{
161 Split *split;
162 Time64 t;
163
164 g_return_if_fail(GNC_IS_SPLIT(object));
165
166 split = GNC_SPLIT(object);
167 switch (prop_id)
168 {
169 case PROP_ACTION:
170 g_value_set_string(value, split->action);
171 break;
172 case PROP_MEMO:
173 g_value_set_string(value, split->memo);
174 break;
175 case PROP_VALUE:
176 g_value_set_boxed(value, &split->value);
177 break;
178 case PROP_AMOUNT:
179 g_value_set_boxed(value, &split->amount);
180 break;
181 case PROP_RECONCILE_DATE:
182 t.t = split->date_reconciled;
183 g_value_set_boxed(value, &t);
184 break;
185 case PROP_TX:
186 g_value_take_object(value, split->parent);
187 break;
188 case PROP_ACCOUNT:
189 g_value_take_object(value, split->acc);
190 break;
191 case PROP_LOT:
192 g_value_take_object(value, split->lot);
193 break;
194 case PROP_SX_CREDIT_FORMULA:
195 qof_instance_get_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_CREDIT_FORMULA);
196 break;
197 case PROP_SX_CREDIT_NUMERIC:
198 qof_instance_get_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_CREDIT_NUMERIC);
199 break;
200 case PROP_SX_DEBIT_FORMULA:
201 qof_instance_get_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_DEBIT_FORMULA);
202 break;
203 case PROP_SX_DEBIT_NUMERIC:
204 qof_instance_get_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_DEBIT_NUMERIC);
205 break;
206 case PROP_SX_ACCOUNT:
207 qof_instance_get_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_ACCOUNT);
208 break;
209 case PROP_SX_SHARES:
210 qof_instance_get_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_SHARES);
211 break;
212 case PROP_ONLINE_ACCOUNT:
213 qof_instance_get_kvp (QOF_INSTANCE (split), value, 1, "online_id");
214 break;
215 case PROP_GAINS_SPLIT:
216 qof_instance_get_kvp (QOF_INSTANCE (split), value, 1, "gains-split");
217 break;
218 case PROP_GAINS_SOURCE:
219 qof_instance_get_kvp (QOF_INSTANCE (split), value, 1, "gains-source");
220 break;
221 default:
222 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
223 break;
224 }
225}
226
227static void
228gnc_split_set_property(GObject *object,
229 guint prop_id,
230 const GValue *value,
231 GParamSpec *pspec)
232{
233 Split *split;
234 gnc_numeric* number;
235 Time64 *t;
236 g_return_if_fail(GNC_IS_SPLIT(object));
237
238 split = GNC_SPLIT(object);
239 if (prop_id < PROP_RUNTIME_0 && split->parent != nullptr)
240 g_assert (qof_instance_get_editlevel(split->parent));
241
242 switch (prop_id)
243 {
244 case PROP_ACTION:
245 xaccSplitSetAction(split, g_value_get_string(value));
246 break;
247 case PROP_MEMO:
248 xaccSplitSetMemo(split, g_value_get_string(value));
249 break;
250 case PROP_VALUE:
251 number = static_cast<gnc_numeric*>(g_value_get_boxed(value));
252 xaccSplitSetValue(split, *number);
253 break;
254 case PROP_AMOUNT:
255 number = static_cast<gnc_numeric*>(g_value_get_boxed(value));
256 xaccSplitSetAmount(split, *number);
257 break;
258 case PROP_RECONCILE_DATE:
259 t = static_cast<Time64*>(g_value_get_boxed(value));
261 break;
262 case PROP_TX:
263 xaccSplitSetParent(split, GNC_TRANSACTION(g_value_get_object(value)));
264 break;
265 case PROP_ACCOUNT:
266 xaccSplitSetAccount(split, GNC_ACCOUNT(g_value_get_object(value)));
267 break;
268 case PROP_LOT:
269 xaccSplitSetLot(split, GNC_LOT(g_value_get_object(value)));
270 break;
271 case PROP_SX_CREDIT_FORMULA:
272 qof_instance_set_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_CREDIT_FORMULA);
273 break;
274 case PROP_SX_CREDIT_NUMERIC:
275 qof_instance_set_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_CREDIT_NUMERIC);
276 break;
277 case PROP_SX_DEBIT_FORMULA:
278 qof_instance_set_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_DEBIT_FORMULA);
279 break;
280 case PROP_SX_DEBIT_NUMERIC:
281 qof_instance_set_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_DEBIT_NUMERIC);
282 break;
283 case PROP_SX_ACCOUNT:
284 qof_instance_set_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_ACCOUNT);
285 break;
286 case PROP_SX_SHARES:
287 qof_instance_set_kvp (QOF_INSTANCE (split), value, 2, GNC_SX_ID, GNC_SX_SHARES);
288 break;
289 case PROP_ONLINE_ACCOUNT:
290 qof_instance_set_kvp (QOF_INSTANCE (split), value, 1, "online_id");
291 break;
292 case PROP_GAINS_SPLIT:
293 qof_instance_set_kvp (QOF_INSTANCE (split), value, 1, "gains-split");
294 break;
295 case PROP_GAINS_SOURCE:
296 qof_instance_set_kvp (QOF_INSTANCE (split), value, 1, "gains-source");
297 break;
298 default:
299 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
300 break;
301 }
302}
303
304static void
305gnc_split_class_init(SplitClass* klass)
306{
307 GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
308
309 gobject_class->dispose = gnc_split_dispose;
310 gobject_class->finalize = gnc_split_finalize;
311 gobject_class->set_property = gnc_split_set_property;
312 gobject_class->get_property = gnc_split_get_property;
313
314 g_object_class_install_property
315 (gobject_class,
316 PROP_ACTION,
317 g_param_spec_string("action",
318 "Action",
319 "The action is an arbitrary string assigned "
320 "by the user. It is intended to be a short "
321 "string that contains extra information about "
322 "this split.",
323 nullptr,
324 G_PARAM_READWRITE));
325
326 g_object_class_install_property
327 (gobject_class,
328 PROP_MEMO,
329 g_param_spec_string("memo",
330 "Memo",
331 "The action is an arbitrary string assigned "
332 "by the user. It is intended to be a short "
333 "string that describes the purpose of "
334 "this split.",
335 nullptr,
336 G_PARAM_READWRITE));
337
338 g_object_class_install_property
339 (gobject_class,
340 PROP_VALUE,
341 g_param_spec_boxed("value",
342 "Split Value",
343 "The value for this split in the common currency. "
344 "The value and the amount provide enough information to "
345 "calculate a conversion rate.",
346 GNC_TYPE_NUMERIC,
347 G_PARAM_READWRITE));
348
349 g_object_class_install_property
350 (gobject_class,
351 PROP_AMOUNT,
352 g_param_spec_boxed("amount",
353 "Split Amount",
354 "The value for this split in the currency of its account. "
355 "The value and the amount provide enough information to "
356 "calculate a conversion rate.",
357 GNC_TYPE_NUMERIC,
358 G_PARAM_READWRITE));
359
360 g_object_class_install_property
361 (gobject_class,
362 PROP_RECONCILE_DATE,
363 g_param_spec_boxed("reconcile-date",
364 "Reconcile Date",
365 "The date this split was reconciled.",
366 GNC_TYPE_TIME64,
367 G_PARAM_READWRITE));
368
369 g_object_class_install_property
370 (gobject_class,
371 PROP_TX,
372 g_param_spec_object ("transaction",
373 "Transaction",
374 "The transaction that this split belongs to.",
375 GNC_TYPE_TRANSACTION,
376 G_PARAM_READWRITE));
377
378 g_object_class_install_property
379 (gobject_class,
380 PROP_ACCOUNT,
381 g_param_spec_object ("account",
382 "Account",
383 "The account that this split belongs to.",
384 GNC_TYPE_ACCOUNT,
385 G_PARAM_READWRITE));
386
387 g_object_class_install_property
388 (gobject_class,
389 PROP_LOT,
390 g_param_spec_object ("lot",
391 "Lot",
392 "The lot that this split belongs to.",
393 GNC_TYPE_LOT,
394 G_PARAM_READWRITE));
395
396 g_object_class_install_property
397 (gobject_class,
398 PROP_SX_DEBIT_FORMULA,
399 g_param_spec_string("sx-debit-formula",
400 "Schedule Transaction Debit Formula",
401 "The formula used to calculate the actual debit "
402 "amount when a real split is generated from this "
403 "SX split.",
404 nullptr,
405 G_PARAM_READWRITE));
406
407 g_object_class_install_property
408 (gobject_class,
409 PROP_SX_DEBIT_NUMERIC,
410 g_param_spec_boxed("sx-debit-numeric",
411 "Scheduled Transaction Debit Numeric",
412 "Numeric value to plug into the Debit Formula when a "
413 "real split is generated from this SX split.",
414 GNC_TYPE_NUMERIC,
415 G_PARAM_READWRITE));
416
417 g_object_class_install_property
418 (gobject_class,
419 PROP_SX_CREDIT_FORMULA,
420 g_param_spec_string("sx-credit-formula",
421 "Schedule Transaction Credit Formula",
422 "The formula used to calculate the actual credit "
423 "amount when a real split is generated from this "
424 "SX split.",
425 nullptr,
426 G_PARAM_READWRITE));
427
428 g_object_class_install_property
429 (gobject_class,
430 PROP_SX_CREDIT_NUMERIC,
431 g_param_spec_boxed("sx-credit-numeric",
432 "Scheduled Transaction Credit Numeric",
433 "Numeric value to plug into the Credit Formula when a "
434 "real split is generated from this SX split.",
435 GNC_TYPE_NUMERIC,
436 G_PARAM_READWRITE));
437/* FIXME: PROP_SX_SHARES should be stored as a gnc_numeric, but the function
438 * which uses it, gnc_template_register_save_shares_cell, stores a
439 * phony string. This is maintained until backwards compatibility can
440 * be established.
441 */
442 g_object_class_install_property
443 (gobject_class,
444 PROP_SX_SHARES,
445 g_param_spec_string("sx-shares",
446 "Scheduled Transaction Shares",
447 "Numeric value of shares to insert in a new split when "
448 "it's generated from this SX split.",
449 nullptr,
450 G_PARAM_READWRITE));
451
452 g_object_class_install_property
453 (gobject_class,
454 PROP_SX_ACCOUNT,
455 g_param_spec_boxed("sx-account",
456 "Scheduled Transaction Account",
457 "The target account for a scheduled transaction split.",
458 GNC_TYPE_GUID,
459 G_PARAM_READWRITE));
460
461 g_object_class_install_property
462 (gobject_class,
463 PROP_ONLINE_ACCOUNT,
464 g_param_spec_string ("online-id",
465 "Online Account ID",
466 "The online account which corresponds to this "
467 "account for OFX/HCBI import",
468 nullptr,
469 G_PARAM_READWRITE));
470
471 g_object_class_install_property
472 (gobject_class,
473 PROP_GAINS_SPLIT,
474 g_param_spec_boxed ("gains-split",
475 "Gains Split",
476 "The capital gains split associated with this "
477 "split when this split represents the proceeds "
478 "from the sale of a commodity inside a Lot.",
479 GNC_TYPE_GUID,
480 G_PARAM_READWRITE));
481
482 g_object_class_install_property
483 (gobject_class,
484 PROP_GAINS_SOURCE,
485 g_param_spec_boxed ("gains-source",
486 "Gains Source",
487 "The source split for which this split this is "
488 "the gains split. ",
489 GNC_TYPE_GUID,
490 G_PARAM_READWRITE));
491}
492
493/********************************************************************\
494 * xaccInitSplit
495 * Initialize a Split structure
496\********************************************************************/
497
498static void
499xaccInitSplit(Split * split, QofBook *book)
500{
501 qof_instance_init_data(&split->inst, GNC_ID_SPLIT, book);
502}
503
504void
505xaccSplitReinit(Split * split)
506{
507 /* fill in some sane defaults */
508 split->acc = nullptr;
509 split->orig_acc = nullptr;
510 split->parent = nullptr;
511 split->lot = nullptr;
512
513 CACHE_REPLACE(split->action, "");
514 CACHE_REPLACE(split->memo, "");
515 split->reconciled = NREC;
516 split->amount = gnc_numeric_zero();
517 split->value = gnc_numeric_zero();
518
519 split->date_reconciled = 0;
520
521 split->balance = gnc_numeric_zero();
522 split->cleared_balance = gnc_numeric_zero();
523 split->reconciled_balance = gnc_numeric_zero();
524 split->noclosing_balance = gnc_numeric_zero();
525
526 split->adjusted_amount = gnc_numeric_zero();
527 split->split_type = nullptr;
528
529 qof_instance_set_idata(split, 0);
530
531 split->gains = GAINS_STATUS_UNKNOWN;
532 split->gains_split = nullptr;
533}
534
535/********************************************************************\
536\********************************************************************/
537
538Split *
540{
541 Split *split;
542 g_return_val_if_fail (book, nullptr);
543
544 split = GNC_SPLIT(g_object_new (GNC_TYPE_SPLIT, nullptr));
545 xaccInitSplit (split, book);
546
547 return split;
548}
549
550/********************************************************************\
551\********************************************************************/
552/* This routine is not exposed externally, since it does weird things,
553 * like not really setting up the parent account correctly, and ditto
554 * the parent transaction. This routine is prone to programmer error
555 * if not used correctly. It is used only by the edit-rollback code.
556 * Don't get duped!
557 */
558
559Split *
560xaccDupeSplit (const Split *s)
561{
562 Split *split = GNC_SPLIT(g_object_new (GNC_TYPE_SPLIT, nullptr));
563
564 /* Trash the entity table. We don't want to mistake the cloned
565 * splits as something official. If we ever use this split, we'll
566 * have to fix this up.
567 */
568 split->inst.e_type = nullptr;
569 qof_instance_copy_guid(split, s);
570 qof_instance_copy_book(split, s);
571
572 split->parent = s->parent;
573 split->acc = s->acc;
574 split->orig_acc = s->orig_acc;
575 split->lot = s->lot;
576
577 CACHE_REPLACE(split->memo, s->memo);
578 CACHE_REPLACE(split->action, s->action);
579
580 qof_instance_copy_kvp (QOF_INSTANCE (split), QOF_INSTANCE (s));
581
582 split->reconciled = s->reconciled;
583 split->date_reconciled = s->date_reconciled;
584
585 split->value = s->value;
586 split->amount = s->amount;
587
588 /* no need to futz with the balances; these get wiped each time ...
589 * split->balance = s->balance;
590 * split->cleared_balance = s->cleared_balance;
591 * split->reconciled_balance = s->reconciled_balance;
592 */
593
594 return split;
595}
596
597Split *
598xaccSplitCloneNoKvp (const Split *s)
599{
600 Split *split = GNC_SPLIT(g_object_new (GNC_TYPE_SPLIT, nullptr));
601
602 split->parent = nullptr;
603 split->memo = CACHE_INSERT(s->memo);
604 split->action = CACHE_INSERT(s->action);
605 split->reconciled = s->reconciled;
606 split->date_reconciled = s->date_reconciled;
607 split->value = s->value;
608 split->amount = s->amount;
609 split->balance = s->balance;
610 split->cleared_balance = s->cleared_balance;
611 split->reconciled_balance = s->reconciled_balance;
612 split->noclosing_balance = s->noclosing_balance;
613 split->adjusted_amount = s->adjusted_amount;
614 split->split_type = s->split_type;
615
616 split->gains = GAINS_STATUS_UNKNOWN;
617 split->gains_split = nullptr;
618
619 qof_instance_init_data(&split->inst, GNC_ID_SPLIT,
621 xaccAccountInsertSplit(s->acc, split);
622 if (s->lot)
623 {
624 /* CHECKME: Is this right? */
625 gnc_lot_add_split(s->lot, split);
626 }
627 return split;
628}
629
630void
631xaccSplitCopyKvp (const Split *from, Split *to)
632{
633 qof_instance_copy_kvp (QOF_INSTANCE (to), QOF_INSTANCE (from));
634 /* But not the online-id */
635 qof_instance_set (QOF_INSTANCE (to), "online-id", nullptr, nullptr);
636}
637
638/*################## Added for Reg2 #################*/
639
640/* This is really a helper for xaccTransCopyOnto. It doesn't reparent
641 the 'to' split to from's transaction, because xaccTransCopyOnto is
642 responsible for parenting the split to the correct transaction.
643 Also, from's parent transaction may not even be a valid
644 transaction, so this function may not modify anything about 'from'
645 or from's transaction.
646*/
647void
648xaccSplitCopyOnto(const Split *from_split, Split *to_split)
649{
650 if (!from_split || !to_split) return;
651 xaccTransBeginEdit (to_split->parent);
652
653 xaccSplitSetMemo(to_split, xaccSplitGetMemo(from_split));
654 xaccSplitSetAction(to_split, xaccSplitGetAction(from_split));
655 xaccSplitSetAmount(to_split, xaccSplitGetAmount(from_split));
656 xaccSplitSetValue(to_split, xaccSplitGetValue(from_split));
657 /* Setting the account is okay here because, even though the from
658 split might not really belong to the account it claims to,
659 setting the account won't cause any event involving from. */
660 xaccSplitSetAccount(to_split, xaccSplitGetAccount(from_split));
661 /* N.B. Don't set parent. */
662
663 qof_instance_set_dirty(QOF_INSTANCE(to_split));
664 xaccTransCommitEdit(to_split->parent);
665}
666
667/*################## Added for Reg2 #################*/
668
669
670#ifdef DUMP_FUNCTIONS
671void
672xaccSplitDump (const Split *split, const char *tag)
673{
674 char datebuff[MAX_DATE_LENGTH + 1];
675 memset (datebuff, 0, sizeof(datebuff));
676 qof_print_date_buff (datebuff, MAX_DATE_LENGTH, split->date_reconciled);
677 printf(" %s Split %p", tag, split);
678 printf(" Book: %p\n", qof_instance_get_book(split));
679 printf(" Account: %p (%s)\n", split->acc,
680 split->acc ? xaccAccountGetName(split->acc) : "");
681 printf(" Commod: %s\n",
682 split->acc ?
684 : "");
685 printf(" Lot: %p\n", split->lot);
686 printf(" Parent: %p\n", split->parent);
687 printf(" Gains: %p\n", split->gains_split);
688 printf(" Memo: %s\n", split->memo ? split->memo : "(null)");
689 printf(" Action: %s\n", split->action ? split->action : "(null)");
690 printf(" KVP Data: %s\n", qof_instance_kvp_as_string (QOF_INSTANCE (split)));
691 printf(" Recncld: %c (date %s)\n", split->reconciled, datebuff);
692
693 printf(" Value: %s\n", gnc_numeric_to_string(split->value));
694 printf(" Amount: %s\n", gnc_numeric_to_string(split->amount));
695 printf(" Balance: %s\n", gnc_numeric_to_string(split->balance));
696 printf(" CBalance: %s\n", gnc_numeric_to_string(split->cleared_balance));
697 printf(" RBalance: %s\n",
698 gnc_numeric_to_string(split->reconciled_balance));
699 printf(" NoClose: %s\n", gnc_numeric_to_string(split->noclosing_balance));
700 printf(" AdjAmt: %s\n", gnc_numeric_to_string(split->adjusted_amount));
701 printf(" Type: %s\n", split->split_type ? split->split_type : "(null)");
702 printf(" idata: %x\n", qof_instance_get_idata(split));
703}
704#endif
705
706/********************************************************************\
707\********************************************************************/
708static void
709do_destroy (QofInstance *inst)
710{
711 xaccFreeSplit (GNC_SPLIT (inst));
712}
713
714void
715xaccFreeSplit (Split *split)
716{
717 if (!split) return;
718
719 /* Debug double-free's */
720 if (((char *) 1) == split->memo)
721 {
722 PERR ("double-free %p", split);
723 return;
724 }
725 CACHE_REMOVE(split->memo);
726 CACHE_REMOVE(split->action);
727
728 if (split->inst.e_type) /* Don't do this for dupe splits. */
729 {
730 /* gnc_lot_remove_split needs the account, so do it first. */
731 if (GNC_IS_LOT (split->lot) && !qof_instance_get_destroying (QOF_INSTANCE (split->lot)))
732 gnc_lot_remove_split (split->lot, split);
733 if (GNC_IS_ACCOUNT (split->acc)
734 && !qof_instance_get_destroying (QOF_INSTANCE (split->acc)))
735 {
736 gnc_account_remove_split (split->acc, split);
737 /* gnc_float_split_to_split generates a qof_event_gen via
738 * xaccAccountCommitEdit even though it doesn't touch the
739 * account. That causes QofQueryViews to notice the split
740 * even though it isn't added to the account. We need a
741 * countervailing event so that they'll notice it's not
742 * there any more.
743 */
744 qof_event_gen(&split->acc->inst, QOF_EVENT_MODIFY, nullptr);
745 }
746 /* We should do the same for split->parent but we might be getting
747 * called from xaccFreeTransaction and that would cause trouble.
748 */
749 }
750
751 /* Just in case someone looks up freed memory ... */
752 split->memo = (char *) 1;
753 split->action = nullptr;
754 split->reconciled = NREC;
755 split->amount = gnc_numeric_zero();
756 split->value = gnc_numeric_zero();
757 split->parent = nullptr;
758 split->lot = nullptr;
759 split->acc = nullptr;
760 split->orig_acc = nullptr;
761
762 split->balance = gnc_numeric_zero();
763 split->cleared_balance = gnc_numeric_zero();
764 split->reconciled_balance = gnc_numeric_zero();
765 split->noclosing_balance = gnc_numeric_zero();
766 split->adjusted_amount = gnc_numeric_zero();
767 split->split_type = nullptr;
768
769 split->date_reconciled = 0;
770 G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
771
772 if (split->gains_split)
773 {
774 Split *other = xaccSplitGetOtherSplit(split->gains_split);
775 split->gains_split->gains_split = nullptr;
776 if (other)
777 other->gains_split = nullptr;
778 }
779
780 g_object_unref(split);
781}
782
783void mark_split (Split *s)
784{
785 if (s->acc)
786 {
789 }
790
791 /* set dirty flag on lot too. */
792 if (s->lot)
794}
795
796/*
797 * Helper routine for xaccSplitEqual.
798 */
799static gboolean
800xaccSplitEqualCheckBal (const char *tag, gnc_numeric a, gnc_numeric b)
801{
802 char *str_a, *str_b;
803
804 if (gnc_numeric_equal (a, b))
805 return TRUE;
806
807 str_a = gnc_numeric_to_string (a);
808 str_b = gnc_numeric_to_string (b);
809
810 PINFO ("%sbalances differ: %s vs %s", tag, str_a, str_b);
811
812 g_free (str_a);
813 g_free (str_b);
814
815 return FALSE;
816}
817
818/********************************************************************
819 * xaccSplitEqual
820 ********************************************************************/
821gboolean
822xaccSplitEqual(const Split *sa, const Split *sb,
823 gboolean check_guids,
824 gboolean check_balances,
825 gboolean check_txn_splits)
826{
827 gboolean same_book;
828
829 if (!sa && !sb) return TRUE; /* Arguable. FALSE is better, methinks */
830
831 if (!sa || !sb)
832 {
833 PINFO ("one is nullptr");
834 return FALSE;
835 }
836
837 if (sa == sb) return TRUE;
838
839 same_book = qof_instance_get_book(QOF_INSTANCE(sa)) == qof_instance_get_book(QOF_INSTANCE(sb));
840
841 if (check_guids)
842 {
843 if (qof_instance_guid_compare(sa, sb) != 0)
844 {
845 PINFO ("GUIDs differ");
846 return FALSE;
847 }
848 }
849
850 /* If the same book, since these strings are cached we can just use pointer equality */
851 if ((same_book && sa->memo != sb->memo) || (!same_book && g_strcmp0(sa->memo, sb->memo) != 0))
852 {
853 PINFO ("memos differ: (%p)%s vs (%p)%s",
854 sa->memo, sa->memo, sb->memo, sb->memo);
855 return FALSE;
856 }
857
858 if ((same_book && sa->action != sb->action) || (!same_book && g_strcmp0(sa->action, sb->action) != 0))
859 {
860 PINFO ("actions differ: %s vs %s", sa->action, sb->action);
861 return FALSE;
862 }
863
864 if (qof_instance_compare_kvp (QOF_INSTANCE (sa), QOF_INSTANCE (sb)) != 0)
865 {
866 char *frame_a;
867 char *frame_b;
868
869 frame_a = qof_instance_kvp_as_string (QOF_INSTANCE (sa));
870 frame_b = qof_instance_kvp_as_string (QOF_INSTANCE (sb));
871
872 PINFO ("kvp frames differ:\n%s\n\nvs\n\n%s", frame_a, frame_b);
873
874 g_free (frame_a);
875 g_free (frame_b);
876
877 return FALSE;
878 }
879
880 if (sa->reconciled != sb->reconciled)
881 {
882 PINFO ("reconcile flags differ: %c vs %c", sa->reconciled, sb->reconciled);
883 return FALSE;
884 }
885
886 if (sa->date_reconciled != sb->date_reconciled)
887 {
888 PINFO ("reconciled date differs");
889 return FALSE;
890 }
891
893 {
894 char *str_a;
895 char *str_b;
896
899
900 PINFO ("amounts differ: %s vs %s", str_a, str_b);
901
902 g_free (str_a);
903 g_free (str_b);
904
905 return FALSE;
906 }
907
909 {
910 char *str_a;
911 char *str_b;
912
915
916 PINFO ("values differ: %s vs %s", str_a, str_b);
917
918 g_free (str_a);
919 g_free (str_b);
920
921 return FALSE;
922 }
923
924 if (check_balances)
925 {
926 if (!xaccSplitEqualCheckBal ("", sa->balance, sb->balance))
927 return FALSE;
928 if (!xaccSplitEqualCheckBal ("cleared ", sa->cleared_balance,
929 sb->cleared_balance))
930 return FALSE;
931 if (!xaccSplitEqualCheckBal ("reconciled ", sa->reconciled_balance,
932 sb->reconciled_balance))
933 return FALSE;
934 if (!xaccSplitEqualCheckBal ("noclosing ", sa->noclosing_balance,
935 sb->noclosing_balance))
936 return FALSE;
937 if (!xaccSplitEqualCheckBal ("adjusted ", sa->adjusted_amount,
938 sb->adjusted_amount))
939 return FALSE;
940 }
941
942 if (!xaccTransEqual(sa->parent, sb->parent, check_guids, check_txn_splits,
943 check_balances, FALSE))
944 {
945 PINFO ("transactions differ");
946 return FALSE;
947 }
948
949 return TRUE;
950}
951
952
953
954/********************************************************************
955 * Account funcs
956 ********************************************************************/
957
958Account *
959xaccSplitGetAccount (const Split *s)
960{
961 return s ? s->acc : nullptr;
962}
963
964void
965xaccSplitSetAccount (Split *s, Account *acc)
966{
967 Transaction *trans;
968
969 g_return_if_fail(s && acc);
970 g_return_if_fail(qof_instance_books_equal(acc, s));
971
972 trans = s->parent;
973 if (trans)
974 xaccTransBeginEdit(trans);
975
976 s->acc = acc;
977 qof_instance_set_dirty(QOF_INSTANCE(s));
978
979 if (trans)
980 xaccTransCommitEdit(trans);
981}
982
983static void commit_err (QofInstance *inst, QofBackendError errcode)
984{
985 PERR("commit error: %d", errcode);
986 gnc_engine_signal_commit_error( errcode );
987}
988
989/* An engine-private helper for completing xaccTransCommitEdit(). */
990void
991xaccSplitCommitEdit(Split *s)
992{
993 Account *acc = nullptr;
994 Account *orig_acc = nullptr;
995
996 g_return_if_fail(s);
997 if (!qof_instance_is_dirty(QOF_INSTANCE(s)))
998 return;
999
1000 orig_acc = s->orig_acc;
1001
1002 if (GNC_IS_ACCOUNT(s->acc))
1003 acc = s->acc;
1004
1005 /* Remove from lot (but only if it hasn't been moved to
1006 new lot already) */
1007 if (s->lot && (gnc_lot_get_account(s->lot) != acc || qof_instance_get_destroying(s)))
1008 gnc_lot_remove_split (s->lot, s);
1009
1010 /* Possibly remove the split from the original account... */
1011 if (orig_acc && (orig_acc != acc || qof_instance_get_destroying(s)))
1012 {
1013 if (!gnc_account_remove_split(orig_acc, s))
1014 {
1015 PERR("Account lost track of moved or deleted split.");
1016 }
1017 }
1018
1019 /* ... and insert it into the new account if needed */
1020 if (acc && (orig_acc != acc) && !qof_instance_get_destroying(s))
1021 {
1022 if (gnc_account_insert_split(acc, s))
1023 {
1024 /* If the split's lot belonged to some other account, we
1025 leave it so. */
1026 if (s->lot && (nullptr == gnc_lot_get_account(s->lot)))
1027 xaccAccountInsertLot (acc, s->lot);
1028 }
1029 else
1030 {
1031 PERR("Account grabbed split prematurely.");
1032 }
1034 }
1035
1036 if (s->parent != s->orig_parent)
1037 {
1038 //FIXME: find better event
1039 if (s->orig_parent)
1040 qof_event_gen(&s->orig_parent->inst, QOF_EVENT_MODIFY,
1041 nullptr);
1042 }
1043 if (s->lot)
1044 {
1045 /* A change of value/amnt affects gains display, etc. */
1046 qof_event_gen (QOF_INSTANCE(s->lot), QOF_EVENT_MODIFY, nullptr);
1047 }
1048
1049 /* Important: we save off the original parent transaction and account
1050 so that when we commit, we can generate signals for both the
1051 original and new transactions, for the _next_ begin/commit cycle. */
1052 s->orig_acc = s->acc;
1053 s->orig_parent = s->parent;
1054 if (!qof_commit_edit_part2(QOF_INSTANCE(s), commit_err, nullptr, do_destroy))
1055 return;
1056
1057 if (acc)
1058 {
1062 }
1063}
1064
1065/* An engine-private helper for completing xaccTransRollbackEdit(). */
1066void
1067xaccSplitRollbackEdit(Split *s)
1068{
1069
1070 /* Don't use setters because we want to allow nullptr. This is legit
1071 only because we don't emit events for changing accounts until
1072 the final commit. */
1073 if (s->acc != s->orig_acc)
1074 s->acc = s->orig_acc;
1075
1076 /* Undestroy if needed */
1077 if (qof_instance_get_destroying(s) && s->parent)
1078 {
1079 GncEventData ed;
1080 qof_instance_set_destroying(s, FALSE);
1081 ed.node = s;
1082 ed.idx = -1; /* unused */
1083 qof_event_gen(&s->parent->inst, GNC_EVENT_ITEM_ADDED, &ed);
1084 }
1085
1086 /* But for the parent trans, we want the intermediate events, so
1087 we use the setter. */
1088 xaccSplitSetParent(s, s->orig_parent);
1089}
1090
1091/********************************************************************\
1092\********************************************************************/
1093
1094Split *
1095xaccSplitLookup (const GncGUID *guid, QofBook *book)
1096{
1097 QofCollection *col;
1098 if (!guid || !book) return nullptr;
1099 col = qof_book_get_collection (book, GNC_ID_SPLIT);
1100 return (Split *) qof_collection_lookup_entity (col, guid);
1101}
1102
1103/********************************************************************\
1104\********************************************************************/
1105/* Routines for marking splits dirty, and for sending out change
1106 * events. Note that we can't just mark-n-generate-event in one
1107 * step, since sometimes we need to mark things up before its suitable
1108 * to send out a change event.
1109 */
1110
1111/* CHECKME: This function modifies the Split without dirtying or
1112 checking its parent. Is that correct? */
1113void
1114xaccSplitDetermineGainStatus (Split *split)
1115{
1116 Split *other;
1117
1118 if (GAINS_STATUS_UNKNOWN != split->gains) return;
1119
1120 /* A gains source has a forward "gains-split" link to the split that
1121 * records its gains. */
1122 other = xaccSplitGetCapGainsSplit (split);
1123 if (other)
1124 {
1125 split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
1126 split->gains_split = other;
1127 /* Resolve the gains-recording split too, so it reuses this link
1128 * rather than being re-created if it is processed first. */
1129 if (GAINS_STATUS_UNKNOWN == other->gains)
1130 {
1131 other->gains = GAINS_STATUS_GAINS;
1132 other->gains_split = split;
1133 }
1134 return;
1135 }
1136
1137 /* A gains-recording split has a backward "gains-source" link to the
1138 * split whose gains it records. */
1139 other = xaccSplitGetGainsSourceSplit (split);
1140 if (!other)
1141 {
1142 // CHECKME: We leave split->gains_split alone. Is that correct?
1143 split->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
1144 }
1145 else
1146 {
1147 split->gains = GAINS_STATUS_GAINS;
1148 split->gains_split = other;
1149 /* Resolve the source too, so it reuses this split rather than
1150 * creating a duplicate if the source is processed afterward. */
1151 if (GAINS_STATUS_UNKNOWN == other->gains)
1152 {
1153 other->gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY;
1154 other->gains_split = split;
1155 }
1156 }
1157}
1158
1159/********************************************************************\
1160\********************************************************************/
1161
1162static inline int
1163get_currency_denom(const Split * s)
1164{
1165 if (!(s && s->parent && s->parent->common_currency))
1166 {
1167 return GNC_DENOM_AUTO;
1168 }
1169 else
1170 {
1171 return gnc_commodity_get_fraction (s->parent->common_currency);
1172 }
1173}
1174
1175static inline int
1176get_commodity_denom(const Split * s)
1177{
1178 if (!(s && s->acc))
1179 {
1180 return GNC_DENOM_AUTO;
1181 }
1182 else
1183 {
1184 return xaccAccountGetCommoditySCU(s->acc);
1185 }
1186}
1187
1188/********************************************************************\
1189\********************************************************************/
1190
1191void
1192xaccSplitSetSharePriceAndAmount (Split *s, gnc_numeric price, gnc_numeric amt)
1193{
1194 if (!s) return;
1195 ENTER (" ");
1196 xaccTransBeginEdit (s->parent);
1197
1198 s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
1200 s->value = gnc_numeric_mul(s->amount, price,
1201 get_currency_denom(s), GNC_HOW_RND_ROUND_HALF_UP);
1202
1203 SET_GAINS_A_VDIRTY(s);
1204 mark_split (s);
1205 qof_instance_set_dirty(QOF_INSTANCE(s));
1206 xaccTransCommitEdit(s->parent);
1207 LEAVE ("");
1208}
1209
1210static void
1211qofSplitSetSharePrice (Split *split, gnc_numeric price)
1212{
1213 g_return_if_fail(split);
1214 split->value = gnc_numeric_mul(xaccSplitGetAmount(split),
1215 price, get_currency_denom(split),
1217}
1218
1219void
1220xaccSplitSetSharePrice (Split *s, gnc_numeric price)
1221{
1222 if (!s) return;
1223
1224 if (gnc_numeric_zero_p (price))
1225 return;
1226
1227 ENTER (" ");
1228 xaccTransBeginEdit (s->parent);
1229
1230 s->value = gnc_numeric_mul(xaccSplitGetAmount(s),
1231 price, get_currency_denom(s),
1233
1234 SET_GAINS_VDIRTY(s);
1235 mark_split (s);
1236 qof_instance_set_dirty(QOF_INSTANCE(s));
1237 xaccTransCommitEdit(s->parent);
1238 LEAVE ("");
1239}
1240
1241static void
1242qofSplitSetAmount (Split *split, gnc_numeric amt)
1243{
1244 g_return_if_fail(split);
1245 if (split->acc)
1246 {
1247 split->amount = gnc_numeric_convert(amt,
1248 get_commodity_denom(split), GNC_HOW_RND_ROUND_HALF_UP);
1249 }
1250 else
1251 {
1252 split->amount = amt;
1253 }
1254}
1255
1256/* The amount of the split in the _account's_ commodity. */
1257void
1258xaccSplitSetAmount (Split *s, gnc_numeric amt)
1259{
1260 if (!s) return;
1261 g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
1262 ENTER ("(split=%p) old amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
1263 " new amt=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
1264 s->amount.num, s->amount.denom, amt.num, amt.denom);
1265
1266 xaccTransBeginEdit (s->parent);
1267 if (s->acc)
1268 {
1269 s->amount = gnc_numeric_convert(amt, get_commodity_denom(s),
1271 g_assert (gnc_numeric_check (s->amount) == GNC_ERROR_OK);
1272 }
1273 else
1274 s->amount = amt;
1275 s->adjusted_amount = s->amount;
1276
1277 SET_GAINS_ADIRTY(s);
1278 mark_split (s);
1279 qof_instance_set_dirty(QOF_INSTANCE(s));
1280 xaccTransCommitEdit(s->parent);
1281 LEAVE("");
1282}
1283
1284static void
1285qofSplitSetValue (Split *split, gnc_numeric amt)
1286{
1287 g_return_if_fail(split);
1288 split->value = gnc_numeric_convert(amt,
1289 get_currency_denom(split), GNC_HOW_RND_ROUND_HALF_UP);
1290 g_assert(gnc_numeric_check (split->value) != GNC_ERROR_OK);
1291}
1292
1293/* The value of the split in the _transaction's_ currency. */
1294void
1295xaccSplitSetValue (Split *s, gnc_numeric amt)
1296{
1297 gnc_numeric new_val;
1298 if (!s) return;
1299
1300 g_return_if_fail(gnc_numeric_check(amt) == GNC_ERROR_OK);
1301 ENTER ("(split=%p) old val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT
1302 " new val=%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT, s,
1303 s->value.num, s->value.denom, amt.num, amt.denom);
1304
1305 xaccTransBeginEdit (s->parent);
1306 new_val = gnc_numeric_convert(amt, get_currency_denom(s),
1308 if (gnc_numeric_check(new_val) == GNC_ERROR_OK &&
1309 !(gnc_numeric_zero_p (new_val) && !gnc_numeric_zero_p (amt)))
1310 {
1311 s->value = new_val;
1312 }
1313 else
1314 {
1315 PERR("numeric error %s in converting the split value's denominator with amount %s and denom %d",
1317 gnc_num_dbg_to_string (amt), get_currency_denom(s));
1318 }
1319
1320 SET_GAINS_VDIRTY(s);
1321 mark_split (s);
1322 qof_instance_set_dirty(QOF_INSTANCE(s));
1323 xaccTransCommitEdit(s->parent);
1324 LEAVE ("");
1325}
1326
1327/********************************************************************\
1328\********************************************************************/
1329
1330gnc_numeric
1331xaccSplitGetBalance (const Split *s)
1332{
1333 return s ? s->balance : gnc_numeric_zero();
1334}
1335
1336gnc_numeric
1338{
1339 return s ? s->noclosing_balance : gnc_numeric_zero();
1340}
1341
1342gnc_numeric
1344{
1345 return s ? s->cleared_balance : gnc_numeric_zero();
1346}
1347
1348gnc_numeric
1350{
1351 return s ? s->reconciled_balance : gnc_numeric_zero();
1352}
1353
1354gnc_numeric
1356{
1357 return s ? s->adjusted_amount : gnc_numeric_zero();
1358}
1359
1360void
1361xaccSplitSetAdjustedAmount (Split *s, gnc_numeric amt)
1362{
1363 if (!s) return;
1364 if (gnc_numeric_check (amt)) return;
1365
1366 s->adjusted_amount = amt;
1367}
1368
1369void
1370xaccSplitSetBaseValue (Split *s, gnc_numeric value,
1371 const gnc_commodity * base_currency)
1372{
1373 const gnc_commodity *currency;
1374 const gnc_commodity *commodity;
1375
1376 if (!s) return;
1377
1378 if (!s->acc)
1379 {
1380 PERR ("split must have a parent account");
1381 return;
1382 }
1383
1384 currency = xaccTransGetCurrency (s->parent);
1385 commodity = xaccAccountGetCommodity (s->acc);
1386
1387 std::optional<gnc_numeric> new_amount, new_value;
1388
1389 /* If the base_currency is the transaction's commodity ('currency'),
1390 * set the value. If it's the account commodity, set the
1391 * amount. If both, set both. */
1392 if (gnc_commodity_equiv(currency, base_currency))
1393 {
1394 if (gnc_commodity_equiv(commodity, base_currency))
1395 {
1396 new_amount = gnc_numeric_convert (value,
1397 get_commodity_denom(s),
1399 }
1400 new_value = gnc_numeric_convert (value,
1401 get_currency_denom(s),
1403 }
1404 else if (gnc_commodity_equiv(commodity, base_currency))
1405 {
1406 new_amount = gnc_numeric_convert (value, get_commodity_denom(s),
1408 }
1409 else
1410 {
1411 PERR ("inappropriate base currency %s "
1412 "given split currency=%s and commodity=%s\n",
1413 gnc_commodity_get_printname(base_currency),
1415 gnc_commodity_get_printname(commodity));
1416 return;
1417 }
1418
1419 xaccTransBeginEdit (s->parent);
1420 if (new_amount) s->amount = *new_amount;
1421 if (new_value) s->value = *new_value;
1422 SET_GAINS_A_VDIRTY(s);
1423 mark_split (s);
1424 qof_instance_set_dirty(QOF_INSTANCE(s));
1425 xaccTransCommitEdit(s->parent);
1426}
1427
1428gnc_numeric
1429xaccSplitGetBaseValue (const Split *s, const gnc_commodity * base_currency)
1430{
1431 if (!s || !s->acc || !s->parent) return gnc_numeric_zero();
1432
1433 /* be more precise -- the value depends on the currency we want it
1434 * expressed in. */
1435 if (gnc_commodity_equiv(xaccTransGetCurrency(s->parent), base_currency))
1436 return xaccSplitGetValue(s);
1437 if (gnc_commodity_equiv(xaccAccountGetCommodity(s->acc), base_currency))
1438 return xaccSplitGetAmount(s);
1439
1440 PERR ("inappropriate base currency %s "
1441 "given split currency=%s and commodity=%s\n",
1442 gnc_commodity_get_printname(base_currency),
1445 return gnc_numeric_zero();
1446}
1447
1448/********************************************************************\
1449\********************************************************************/
1450
1451gnc_numeric
1452xaccSplitConvertAmount (const Split *split, const Account * account)
1453{
1454 gnc_commodity *acc_com, *to_commodity;
1455 Transaction *txn;
1456 gnc_numeric amount, value, convrate;
1457 Account * split_acc;
1458
1459 amount = xaccSplitGetAmount (split);
1460
1461 /* If this split is attached to this account, OR */
1462 split_acc = xaccSplitGetAccount (split);
1463 if (split_acc == account)
1464 return amount;
1465
1466 /* If split->account->commodity == to_commodity, return the amount */
1467 acc_com = xaccAccountGetCommodity (split_acc);
1468 to_commodity = xaccAccountGetCommodity (account);
1469 if (acc_com && gnc_commodity_equal (acc_com, to_commodity))
1470 return amount;
1471
1472 /* Ok, this split is not for the viewed account, and the commodity
1473 * does not match. So we need to do some conversion.
1474 *
1475 * First, we can cheat. If this transaction is balanced and has
1476 * exactly two splits, then we can implicitly determine the exchange
1477 * rate and just return the 'other' split amount.
1478 */
1479 txn = xaccSplitGetParent (split);
1480 if (txn && xaccTransIsBalanced (txn))
1481 {
1482 const Split *osplit = xaccSplitGetOtherSplit (split);
1483
1484 if (osplit)
1485 {
1486 gnc_commodity* split_comm =
1488 if (!gnc_commodity_equal(to_commodity, split_comm))
1489 {
1490 gchar guidstr[GUID_ENCODING_LENGTH+1];
1491 guid_to_string_buff(xaccSplitGetGUID(osplit),guidstr);
1492 PERR("The split's (%s) amount can't be converted from %s into %s.",
1493 guidstr,
1494 gnc_commodity_get_mnemonic(split_comm),
1495 gnc_commodity_get_mnemonic(to_commodity)
1496 );
1497 return gnc_numeric_zero();
1498 }
1499 return gnc_numeric_neg (xaccSplitGetAmount (osplit));
1500 }
1501 }
1502
1503 /* ... otherwise, we need to compute the amount from the conversion
1504 * rate into _this account_. So, find the split into this account,
1505 * compute the conversion rate (based on amount/value), and then multiply
1506 * this times the split value.
1507 */
1508 value = xaccSplitGetValue (split);
1509
1510 if (gnc_numeric_zero_p (value))
1511 {
1512 return value;
1513 }
1514
1515 convrate = xaccTransGetAccountConvRate(txn, account);
1516 return gnc_numeric_mul (value, convrate,
1517 gnc_commodity_get_fraction (to_commodity),
1519}
1520
1521/********************************************************************\
1522\********************************************************************/
1523
1524gboolean
1525xaccSplitDestroy (Split *split)
1526{
1527 Account *acc;
1528 Transaction *trans;
1529 GncEventData ed;
1530
1531 if (!split) return TRUE;
1532
1533 acc = split->acc;
1534 trans = split->parent;
1535 if (acc && !qof_instance_get_destroying(acc)
1537 && xaccTransGetReadOnly(trans))
1538 return FALSE;
1539
1540 xaccTransBeginEdit(trans);
1541 ed.node = split;
1542 ed.idx = xaccTransGetSplitIndex(trans, split);
1543 qof_instance_set_dirty(QOF_INSTANCE(split));
1544 qof_instance_set_destroying(split, TRUE);
1545 qof_event_gen(&trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1546 xaccTransCommitEdit(trans);
1547
1548 return TRUE;
1549}
1550
1551/********************************************************************\
1552\********************************************************************/
1553
1554gint
1555xaccSplitOrder (const Split *sa, const Split *sb)
1556{
1557 int retval;
1558 int comp;
1559 const char *da, *db;
1560 gboolean action_for_num;
1561
1562 if (sa == sb) return 0;
1563 /* nothing is always less than something */
1564 if (!sa) return -1;
1565 if (!sb) return +1;
1566
1567 /* sort in transaction order, but use split action rather than trans num
1568 * according to book option */
1570 (xaccSplitGetBook (sa));
1571 if (action_for_num)
1572 retval = xaccTransOrder_num_action (sa->parent, sa->action,
1573 sb->parent, sb->action);
1574 else
1575 retval = xaccTransOrder (sa->parent, sb->parent);
1576 if (retval) return retval;
1577
1578 /* otherwise, sort on memo strings */
1579 da = sa->memo ? sa->memo : "";
1580 db = sb->memo ? sb->memo : "";
1581 retval = g_utf8_collate (da, db);
1582 if (retval)
1583 return retval;
1584
1585 /* otherwise, sort on action strings */
1586 da = sa->action ? sa->action : "";
1587 db = sb->action ? sb->action : "";
1588 retval = g_utf8_collate (da, db);
1589 if (retval != 0)
1590 return retval;
1591
1592 /* the reconciled flag ... */
1593 if (sa->reconciled < sb->reconciled) return -1;
1594 if (sa->reconciled > sb->reconciled) return +1;
1595
1596 /* compare amounts */
1598 if (comp < 0) return -1;
1599 if (comp > 0) return +1;
1600
1602 if (comp < 0) return -1;
1603 if (comp > 0) return +1;
1604
1605 /* if dates differ, return */
1606 if (sa->date_reconciled < sb->date_reconciled)
1607 return -1;
1608 else if (sa->date_reconciled > sb->date_reconciled)
1609 return 1;
1610
1611 /* else, sort on guid - keeps sort stable. */
1612 retval = qof_instance_guid_compare(sa, sb);
1613 if (retval) return retval;
1614
1615 return 0;
1616}
1617
1618gint
1619xaccSplitOrderDateOnly (const Split *sa, const Split *sb)
1620{
1621 if (sa == sb) return 0;
1622 /* nothing is always less than something */
1623 if (!sa) return -1;
1624 if (!sb) return +1;
1625
1626 const auto da = sa->parent ? sa->parent->date_posted : INT64_MAX;
1627 const auto db = sb->parent ? sb->parent->date_posted : INT64_MAX;
1628 return da > db ? 1 : da < db ? -1 : 0;
1629}
1630
1631static gboolean
1632get_corr_account_split(const Split *sa, const Split **retval)
1633{
1634 *retval = nullptr;
1635 g_return_val_if_fail(sa, FALSE);
1636
1637 if (xaccTransCountSplits (sa->parent) > 2)
1638 return FALSE;
1639
1640 *retval = xaccSplitGetOtherSplit (sa);
1641 if (*retval)
1642 return TRUE;
1643 else
1644 return FALSE;
1645}
1646
1647/* TODO: these static consts can be shared. */
1648const char *
1650{
1651 static const char *split_const = nullptr;
1652 const Split *other_split;
1653
1654 if (!get_corr_account_split(sa, &other_split))
1655 {
1656 if (!split_const)
1657 split_const = _("-- Split Transaction --");
1658
1659 return split_const;
1660 }
1661
1662 return xaccAccountGetName(other_split->acc);
1663}
1664
1665char *
1667{
1668 static const char *split_const = nullptr;
1669 const Split *other_split;
1670
1671 if (!get_corr_account_split(sa, &other_split))
1672 {
1673 if (!split_const)
1674 split_const = _("-- Split Transaction --");
1675
1676 return g_strdup(split_const);
1677 }
1678 return gnc_account_get_full_name(other_split->acc);
1679}
1680
1681const char *
1683{
1684 static const char *split_const = nullptr;
1685 const Split *other_split;
1686
1687 if (!get_corr_account_split(sa, &other_split))
1688 {
1689 if (!split_const)
1690 split_const = C_("Displayed account code of the other account in a multi-split transaction", "Split");
1691
1692 return split_const;
1693 }
1694 return xaccAccountGetCode(other_split->acc);
1695}
1696
1697/* TODO: It's not too hard to make this function avoid the malloc/free. */
1698int
1699xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb)
1700{
1701 Account *aa, *ab;
1702 if (sa == sb) return 0;
1703 if (!sa) return -1;
1704 if (!sb) return 1;
1705
1706 aa = sa->acc;
1707 ab = sb->acc;
1708 if (aa == ab) return 0;
1709
1710 auto path_a = gnc_account_get_all_parents (aa);
1711 auto path_b = gnc_account_get_all_parents (ab);
1712 auto mismatch_pair = std::mismatch (path_a.rbegin(), path_a.rend(),
1713 path_b.rbegin(), path_b.rend());
1714
1715 return mismatch_pair.first == path_a.rend() ? -1
1716 : mismatch_pair.second == path_b.rend() ? 1
1717 : g_utf8_collate (xaccAccountGetName (*mismatch_pair.first),
1718 xaccAccountGetName (*mismatch_pair.second));
1719}
1720
1721
1722int
1723xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
1724{
1725 Account *aa, *ab;
1726 if (!sa && !sb) return 0;
1727 if (!sa) return -1;
1728 if (!sb) return 1;
1729
1730 aa = sa->acc;
1731 ab = sb->acc;
1732
1733 return g_strcmp0(xaccAccountGetCode(aa), xaccAccountGetCode(ab));
1734}
1735
1736int
1737xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
1738{
1739 char *ca, *cb;
1740 int retval;
1741 if (!sa && !sb) return 0;
1742 if (!sa) return -1;
1743 if (!sb) return 1;
1744
1745 /* doesn't matter what separator we use
1746 * as long as they are the same
1747 */
1748
1751 retval = g_strcmp0(ca, cb);
1752 g_free(ca);
1753 g_free(cb);
1754 return retval;
1755}
1756
1757int
1758xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb)
1759{
1760 const char *ca, *cb;
1761 if (!sa && !sb) return 0;
1762 if (!sa) return -1;
1763 if (!sb) return 1;
1764
1767 return g_strcmp0(ca, cb);
1768}
1769
1770static void
1771qofSplitSetMemo (Split *split, const char* memo)
1772{
1773 g_return_if_fail(split);
1774 CACHE_REPLACE(split->memo, memo);
1775}
1776
1777void
1778xaccSplitSetMemo (Split *split, const char *memo)
1779{
1780 if (!split || !memo) return;
1781 xaccTransBeginEdit (split->parent);
1782
1783 CACHE_REPLACE(split->memo, memo);
1784 qof_instance_set_dirty(QOF_INSTANCE(split));
1785 xaccTransCommitEdit(split->parent);
1786
1787}
1788
1789static void
1790qofSplitSetAction (Split *split, const char *actn)
1791{
1792 g_return_if_fail(split);
1793 CACHE_REPLACE(split->action, actn);
1794}
1795
1796void
1797xaccSplitSetAction (Split *split, const char *actn)
1798{
1799 if (!split || !actn) return;
1800 xaccTransBeginEdit (split->parent);
1801
1802 CACHE_REPLACE(split->action, actn);
1803 qof_instance_set_dirty(QOF_INSTANCE(split));
1804 xaccTransCommitEdit(split->parent);
1805
1806}
1807
1808static void
1809qofSplitSetReconcile (Split *split, char recn)
1810{
1811 g_return_if_fail(split);
1812 switch (recn)
1813 {
1814 case NREC:
1815 case CREC:
1816 case YREC:
1817 case FREC:
1818 case VREC:
1819 split->reconciled = recn;
1820 mark_split (split);
1821 xaccAccountRecomputeBalance (split->acc);
1822 break;
1823 default:
1824 PERR("Bad reconciled flag");
1825 break;
1826 }
1827}
1828
1829void
1830xaccSplitSetReconcile (Split *split, char recn)
1831{
1832 if (!split || split->reconciled == recn) return;
1833 xaccTransBeginEdit (split->parent);
1834
1835 switch (recn)
1836 {
1837 case NREC:
1838 case CREC:
1839 case YREC:
1840 case FREC:
1841 case VREC:
1842 split->reconciled = recn;
1843 mark_split (split);
1844 qof_instance_set_dirty(QOF_INSTANCE(split));
1845 xaccAccountRecomputeBalance (split->acc);
1846 break;
1847 default:
1848 PERR("Bad reconciled flag");
1849 break;
1850 }
1851 xaccTransCommitEdit(split->parent);
1852
1853}
1854
1855void
1857{
1858 if (!split) return;
1859 xaccTransBeginEdit (split->parent);
1860
1861 split->date_reconciled = secs;
1862 qof_instance_set_dirty(QOF_INSTANCE(split));
1863 xaccTransCommitEdit(split->parent);
1864
1865}
1866
1867
1868/*################## Added for Reg2 #################*/
1869time64
1870xaccSplitGetDateReconciled (const Split * split)
1871{
1872 return split ? split->date_reconciled : 0;
1873}
1874/*################## Added for Reg2 #################*/
1875
1876/********************************************************************\
1877\********************************************************************/
1878
1879/* return the parent transaction of the split */
1880Transaction *
1881xaccSplitGetParent (const Split *split)
1882{
1883 return split ? split->parent : nullptr;
1884}
1885
1886void
1887xaccSplitSetParent(Split *s, Transaction *t)
1888{
1889 Transaction *old_trans;
1890 GncEventData ed;
1891
1892 g_return_if_fail(s);
1893 if (s->parent == t) return;
1894
1895 if (s->parent != s->orig_parent && s->orig_parent != t)
1896 PERR("You may not add the split to more than one transaction"
1897 " during the BeginEdit/CommitEdit block.");
1899 old_trans = s->parent;
1900
1901 xaccTransBeginEdit(old_trans);
1902
1903 ed.node = s;
1904 if (old_trans)
1905 {
1906 ed.idx = xaccTransGetSplitIndex(old_trans, s);
1907 qof_event_gen(&old_trans->inst, GNC_EVENT_ITEM_REMOVED, &ed);
1908 }
1909 s->parent = t;
1910 qof_instance_set_dirty(QOF_INSTANCE(s));
1911
1912 xaccTransCommitEdit(old_trans);
1913
1914 if (t)
1915 {
1916 /* Convert split to new transaction's commodity denominator */
1918
1919 /* add ourselves to the new transaction's list of pending splits. */
1920 if (nullptr == g_list_find(t->splits, s))
1921 t->splits = g_list_append(t->splits, s);
1922
1923 ed.idx = -1; /* unused */
1924 qof_event_gen(&t->inst, GNC_EVENT_ITEM_ADDED, &ed);
1925 }
1927}
1928
1929
1930GNCLot *
1931xaccSplitGetLot (const Split *split)
1932{
1933 return split ? split->lot : nullptr;
1934}
1935
1936void
1937xaccSplitSetLot(Split* split, GNCLot* lot)
1938{
1939 g_return_if_fail (split);
1940 xaccTransBeginEdit (split->parent);
1941 split->lot = lot;
1942 qof_instance_set_dirty(QOF_INSTANCE(split));
1943 xaccTransCommitEdit(split->parent);
1944}
1945
1946const char *
1947xaccSplitGetMemo (const Split *split)
1948{
1949 return split ? split->memo : nullptr;
1950}
1951
1952void
1953xaccSplitSetOnlineID (Split *split, const char *id)
1954{
1955 if (!split) return;
1956 /* No xaccTransBeginEdit/CommitEdit here: the online_id is normally set
1957 * while many other parameters of a transaction are being changed, so
1958 * the caller wraps this in the parent transaction's edit. */
1959 std::optional<const char*> val;
1960 if (id && *id)
1961 val = g_strdup (id);
1962 qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(split), val, {split_online_id});
1963 qof_instance_set_dirty (QOF_INSTANCE(split));
1964}
1965
1966const char *
1967xaccSplitGetOnlineID (const Split *split)
1968{
1969 if (!split) return nullptr;
1970 auto rv{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(split), {split_online_id})};
1971 return rv ? *rv : nullptr;
1972}
1973
1974gboolean
1975xaccSplitHasOnlineID (const Split *split)
1976{
1977 auto id = xaccSplitGetOnlineID (split);
1978 return (id && *id);
1979}
1980
1981const char *
1982xaccSplitGetAction (const Split *split)
1983{
1984 return split ? split->action : nullptr;
1985}
1986
1987char
1988xaccSplitGetReconcile (const Split *split)
1989{
1990 return split ? split->reconciled : ' ';
1991}
1992
1993
1994gnc_numeric
1995xaccSplitGetAmount (const Split * split)
1996{
1997 return split ? split->amount : gnc_numeric_zero();
1998}
1999
2000gnc_numeric
2001xaccSplitGetValue (const Split * split)
2002{
2003 return split ? split->value : gnc_numeric_zero();
2004}
2005
2006gnc_numeric
2007xaccSplitGetSharePrice (const Split * split)
2008{
2009 gnc_numeric amt, val, price;
2010 if (!split) return gnc_numeric_create(0, 1);
2011
2012
2013 /* if amount == 0, return 0
2014 * otherwise return value/amount
2015 */
2016
2017 amt = xaccSplitGetAmount(split);
2018 val = xaccSplitGetValue(split);
2019 if (gnc_numeric_zero_p(amt))
2020 return gnc_numeric_create(0, 1);
2021
2022 price = gnc_numeric_div(val, amt,
2025
2026 /* During random checks we can get some very weird prices. Let's
2027 * handle some overflow and other error conditions by returning
2028 * zero. But still print an error to let us know it happened.
2029 */
2030 if (gnc_numeric_check(price))
2031 {
2032 PERR("Computing share price failed (%d): [ %" G_GINT64_FORMAT " / %"
2033 G_GINT64_FORMAT " ] / [ %" G_GINT64_FORMAT " / %" G_GINT64_FORMAT " ]",
2034 gnc_numeric_check(price), val.num, val.denom, amt.num, amt.denom);
2035 return gnc_numeric_create(0, 1);
2036 }
2037
2038 return price;
2039}
2040
2041/********************************************************************\
2042\********************************************************************/
2043
2044QofBook *
2045xaccSplitGetBook (const Split *split)
2046{
2047 return qof_instance_get_book(QOF_INSTANCE(split));
2048}
2049
2050const char *
2052{
2053 if (!s) return nullptr;
2054
2055 if (!s->split_type)
2056 {
2057 auto type{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(s), {"split-type"})};
2058
2059 if (!type || !g_strcmp0 (*type, split_type_normal))
2060 s->split_type = split_type_normal;
2061 else if (!g_strcmp0 (*type, split_type_stock_split))
2062 s->split_type = split_type_stock_split;
2063 else
2064 {
2065 PERR ("unexpected split-type %s, reset to normal.", *type);
2066 s->split_type = split_type_normal;
2067 }
2068 }
2069 return s->split_type;
2070}
2071
2072/* reconfigure a split to be a stock split - after this, you shouldn't
2073 mess with the value, just the amount. */
2074void
2076{
2077 g_return_if_fail (s);
2078 xaccTransBeginEdit (s->parent);
2079
2080 s->value = gnc_numeric_zero();
2081 s->split_type = split_type_stock_split;
2082 qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(s), g_strdup(split_type_stock_split),
2083 {"split-type"});
2084 SET_GAINS_VDIRTY(s);
2085 mark_split(s);
2086 qof_instance_set_dirty(QOF_INSTANCE(s));
2087 xaccTransCommitEdit(s->parent);
2088}
2089
2090gboolean
2092{
2093 return g_strcmp0(split_type_stock_split, xaccSplitGetType(s)) == 0;
2094}
2095
2096void
2097xaccSplitAddPeerSplit (Split *split, const Split *other_split,
2098 time64 timestamp)
2099{
2100 const GncGUID* guid;
2101
2102 g_return_if_fail (split != nullptr);
2103 g_return_if_fail (other_split != nullptr);
2104
2105 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2106 xaccTransBeginEdit (split->parent);
2107 qof_instance_kvp_add_guid (QOF_INSTANCE (split), "lot-split",
2108 gnc_time(nullptr), "peer_guid", guid_copy(guid));
2109 mark_split (split);
2110 qof_instance_set_dirty (QOF_INSTANCE (split));
2111 xaccTransCommitEdit (split->parent);
2112}
2113
2114gboolean
2115xaccSplitHasPeers (const Split *split)
2116{
2117 return qof_instance_has_slot (QOF_INSTANCE (split), "lot-split");
2118}
2119
2120gboolean
2121xaccSplitIsPeerSplit (const Split *split, const Split *other_split)
2122{
2123 const GncGUID* guid;
2124
2125 g_return_val_if_fail (split != nullptr, FALSE);
2126 g_return_val_if_fail (other_split != nullptr, FALSE);
2127
2128 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2129 return qof_instance_kvp_has_guid (QOF_INSTANCE (split), "lot-split",
2130 "peer_guid", guid);
2131}
2132
2133void
2134xaccSplitRemovePeerSplit (Split *split, const Split *other_split)
2135{
2136 const GncGUID* guid;
2137
2138 g_return_if_fail (split != nullptr);
2139 g_return_if_fail (other_split != nullptr);
2140
2141 guid = qof_instance_get_guid (QOF_INSTANCE (other_split));
2142 xaccTransBeginEdit (split->parent);
2143 qof_instance_kvp_remove_guid (QOF_INSTANCE (split), "lot-split",
2144 "peer_guid", guid);
2145 mark_split (split);
2146 qof_instance_set_dirty (QOF_INSTANCE (split));
2147 xaccTransCommitEdit (split->parent);
2148}
2149
2150void
2151xaccSplitMergePeerSplits (Split *split, const Split *other_split)
2152{
2153 xaccTransBeginEdit (split->parent);
2154 qof_instance_kvp_merge_guids (QOF_INSTANCE (split),
2155 QOF_INSTANCE (other_split), "lot-split");
2156 mark_split (split);
2157 qof_instance_set_dirty (QOF_INSTANCE (split));
2158 xaccTransCommitEdit (split->parent);
2159}
2160
2161/********************************************************************\
2162\********************************************************************/
2163/* In the old world, the 'other split' was the other split of a
2164 * transaction that contained only two splits. In the new world,
2165 * a split may have been cut up between multiple lots, although
2166 * in a conceptual sense, if lots hadn't been used, there would be
2167 * only a pair. So we handle this conceptual case: we can still
2168 * identify, unambiguously, the 'other' split when 'this' split
2169 * as been cut up across lots. We do this by looking for the
2170 * 'lot-split' keyword, which occurs only in cut-up splits.
2171 */
2172
2173Split *
2174xaccSplitGetOtherSplit (const Split *split)
2175{
2176 Transaction *trans;
2177 Split *other = nullptr;
2178
2179 if (!split) return nullptr;
2180 trans = split->parent;
2181 if (!trans) return nullptr;
2182
2183 for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
2184 {
2185 Split *s = GNC_SPLIT(n->data);
2186 if ((s == split) ||
2187 (!xaccTransStillHasSplit(trans, s)) ||
2189 (qof_instance_has_slot (QOF_INSTANCE (s), "lot-split")))
2190 continue;
2191
2192 if (other)
2193 return nullptr;
2194
2195 other = s;
2196 }
2197 return other;
2198}
2199
2200/********************************************************************\
2201\********************************************************************/
2202
2203gnc_numeric
2204xaccSplitVoidFormerAmount(const Split *split)
2205{
2206 g_return_val_if_fail(split, gnc_numeric_zero());
2207 auto num{qof_instance_get_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {void_former_amt_str})};
2208 return num ? *num : gnc_numeric_zero();
2209}
2210
2211gnc_numeric
2212xaccSplitVoidFormerValue(const Split *split)
2213{
2214 g_return_val_if_fail(split, gnc_numeric_zero());
2215 auto num{qof_instance_get_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {void_former_val_str})};
2216 return num ? *num : gnc_numeric_zero();
2217}
2218
2219void
2220xaccSplitVoid(Split *split)
2221{
2222 g_return_if_fail (GNC_IS_SPLIT(split));
2223 qof_instance_set_path_kvp<gnc_numeric> (QOF_INSTANCE(split), xaccSplitGetAmount(split), {void_former_amt_str});
2224 qof_instance_set_path_kvp<gnc_numeric> (QOF_INSTANCE(split), xaccSplitGetValue(split), {void_former_val_str});
2225 qof_instance_set_dirty (QOF_INSTANCE(split));
2226
2227 static gnc_numeric zero = gnc_numeric_zero();
2228 xaccSplitSetAmount (split, zero);
2229 xaccSplitSetValue (split, zero);
2231}
2232
2233void
2234xaccSplitUnvoid(Split *split)
2235{
2236 g_return_if_fail (GNC_IS_SPLIT(split));
2240 qof_instance_set_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {}, {void_former_amt_str});
2241 qof_instance_set_path_kvp<gnc_numeric> (QOF_INSTANCE(split), {}, {void_former_val_str});
2242 qof_instance_set_dirty (QOF_INSTANCE(split));
2243}
2244
2245/********************************************************************\
2246\********************************************************************/
2247/* QofObject function implementation */
2248
2249/* Hook into the QofObject registry */
2250
2251#ifdef _MSC_VER
2252/* MSVC compiler doesn't have C99 "designated initializers"
2253 * so we wrap them in a macro that is empty on MSVC. */
2254# define DI(x) /* */
2255#else
2256# define DI(x) x
2257#endif
2258static QofObject split_object_def =
2259{
2260 DI(.interface_version = ) QOF_OBJECT_VERSION,
2261 DI(.e_type = ) GNC_ID_SPLIT,
2262 DI(.type_label = ) "Split",
2263 DI(.create = ) (void* (*)(QofBook*))xaccMallocSplit,
2264 DI(.book_begin = ) nullptr,
2265 DI(.book_end = ) nullptr,
2266 DI(.is_dirty = ) qof_collection_is_dirty,
2267 DI(.mark_clean = ) qof_collection_mark_clean,
2268 DI(.foreach = ) qof_collection_foreach,
2269 DI(.printable = ) (const char * (*)(gpointer)) xaccSplitGetMemo,
2270 DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
2271};
2272
2273static gpointer
2274split_account_guid_getter (gpointer obj, const QofParam *p)
2275{
2276 Split *s = GNC_SPLIT(obj);
2277 Account *acc;
2278
2279 if (!s) return nullptr;
2280 acc = xaccSplitGetAccount (s);
2281 if (!acc) return nullptr;
2282 return ((gpointer)xaccAccountGetGUID (acc));
2283}
2284
2285static double /* internal use only */
2286DxaccSplitGetShareAmount (const Split * split)
2287{
2288 return split ? gnc_numeric_to_double(xaccSplitGetAmount(split)) : 0.0;
2289}
2290
2291static gpointer
2292no_op (gpointer obj, const QofParam *p)
2293{
2294 return obj;
2295}
2296
2297static void
2298qofSplitSetParentTrans(Split *s, QofInstance *ent)
2299{
2300 Transaction *trans = (Transaction*)ent;
2301
2302 g_return_if_fail(trans);
2303 xaccSplitSetParent(s, trans);
2304}
2305
2306static void
2307qofSplitSetAccount(Split *s, QofInstance *ent)
2308{
2309 Account *acc = (Account*)ent;
2310
2311 g_return_if_fail(acc);
2312 xaccSplitSetAccount(s, acc);
2313}
2314
2315gboolean xaccSplitRegister (void)
2316{
2317 static const QofParam params[] =
2318 {
2319 {
2320 SPLIT_DATE_RECONCILED, QOF_TYPE_DATE,
2323 },
2324
2325 /* d-* are deprecated query params, should not be used in new
2326 * queries, should be removed from old queries. */
2327 {
2328 "d-share-amount", QOF_TYPE_DOUBLE,
2329 (QofAccessFunc)DxaccSplitGetShareAmount, nullptr
2330 },
2331 {
2332 "d-share-int64", QOF_TYPE_INT64,
2334 },
2335 {
2336 SPLIT_BALANCE, QOF_TYPE_NUMERIC,
2338 },
2339 {
2340 SPLIT_CLEARED_BALANCE, QOF_TYPE_NUMERIC,
2342 },
2343 {
2344 SPLIT_RECONCILED_BALANCE, QOF_TYPE_NUMERIC,
2346 },
2347 {
2348 SPLIT_MEMO, QOF_TYPE_STRING,
2350 },
2351 {
2352 SPLIT_ACTION, QOF_TYPE_STRING,
2354 },
2355 {
2356 SPLIT_RECONCILE, QOF_TYPE_CHAR,
2358 (QofSetterFunc)qofSplitSetReconcile
2359 },
2360 {
2361 SPLIT_AMOUNT, QOF_TYPE_NUMERIC,
2363 },
2364 {
2365 SPLIT_SHARE_PRICE, QOF_TYPE_NUMERIC,
2367 (QofSetterFunc)qofSplitSetSharePrice
2368 },
2369 {
2370 SPLIT_VALUE, QOF_TYPE_DEBCRED,
2372 },
2373 { SPLIT_TYPE, QOF_TYPE_STRING, (QofAccessFunc)xaccSplitGetType, nullptr },
2374 {
2375 SPLIT_VOIDED_AMOUNT, QOF_TYPE_NUMERIC,
2377 },
2378 {
2379 SPLIT_VOIDED_VALUE, QOF_TYPE_NUMERIC,
2381 },
2382 { SPLIT_LOT, GNC_ID_LOT, (QofAccessFunc)xaccSplitGetLot, nullptr },
2383 {
2384 SPLIT_TRANS, GNC_ID_TRANS,
2386 (QofSetterFunc)qofSplitSetParentTrans
2387 },
2388 {
2389 SPLIT_ACCOUNT, GNC_ID_ACCOUNT,
2390 (QofAccessFunc)xaccSplitGetAccount, (QofSetterFunc)qofSplitSetAccount
2391 },
2392 { SPLIT_ACCOUNT_GUID, QOF_TYPE_GUID, split_account_guid_getter, nullptr },
2393 /* these are no-ops to register the parameter names (for sorting) but
2394 they return an allocated object which getters cannot do. */
2395 { SPLIT_ACCT_FULLNAME, SPLIT_ACCT_FULLNAME, no_op, nullptr },
2396 { SPLIT_CORR_ACCT_NAME, SPLIT_CORR_ACCT_NAME, no_op, nullptr },
2397 { SPLIT_CORR_ACCT_CODE, SPLIT_CORR_ACCT_CODE, no_op, nullptr },
2398 { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)xaccSplitGetBook, nullptr },
2399 {
2400 QOF_PARAM_GUID, QOF_TYPE_GUID,
2402 },
2403 { nullptr },
2404 };
2405
2406 qof_class_register (GNC_ID_SPLIT, (QofSortFunc)xaccSplitOrder, params);
2407 qof_class_register (SPLIT_ACCT_FULLNAME,
2409 qof_class_register (SPLIT_CORR_ACCT_NAME,
2411 nullptr);
2412 qof_class_register (SPLIT_CORR_ACCT_CODE,
2414
2415 return qof_object_register (&split_object_def);
2416}
2417
2419_utest_split_fill_functions (void)
2420{
2421 SplitTestFunctions *func = g_new (SplitTestFunctions, 1);
2422
2423 func->xaccSplitEqualCheckBal = xaccSplitEqualCheckBal;
2424 func->get_currency_denom = get_currency_denom;
2425 func->get_commodity_denom = get_commodity_denom;
2426 func->get_corr_account_split = get_corr_account_split;
2427 return func;
2428}
2429
2430/************************ END OF ************************************\
2431\************************* FILE *************************************/
This is the private header for the account structure.
Account public routines (C++ api).
convert single-entry accounts to clean double-entry
API for Transactions and Splits (journal entries).
API for the transaction logger.
Utilities to Automatically Compute Capital Gains/Losses.
Commodity handling public routines.
All type declarations for the whole Gnucash engine.
Additional event handling code.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition Account.cpp:3270
void xaccAccountRecomputeBalance(Account *acc)
The following recompute the partial balances (stored with the transaction) and the total balance,...
Definition Account.cpp:2264
gboolean gnc_account_insert_split(Account *acc, Split *s)
Insert the given split from an account.
Definition Account.cpp:1932
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...
Definition Account.cpp:3286
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
Definition Account.cpp:3248
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
Definition Account.cpp:2726
void gnc_account_set_balance_dirty(Account *acc)
Tell the account that the running balances may be incorrect and need to be recomputed.
Definition Account.cpp:1887
#define xaccAccountGetGUID(X)
Definition Account.h:252
gboolean gnc_account_remove_split(Account *acc, Split *s)
Remove the given split from an account.
Definition Account.cpp:1962
void gnc_account_set_sort_dirty(Account *acc)
Tell the account believes that the splits may be incorrectly sorted and need to be resorted.
Definition Account.cpp:1873
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
Definition Account.cpp:3317
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
Definition Account.cpp:3389
@ ACCT_TYPE_TRADING
Account used to record multiple commodity transactions.
Definition Account.h:155
QofBackendError
The errors that can be reported to the GUI & other front-end users.
Definition qofbackend.h:58
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition qofbook.cpp:521
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...
Split * xaccSplitGetCapGainsSplit(const Split *split)
The xaccSplitGetCapGainsSplit() routine returns the split that records the cap gains for this split.
Split * xaccSplitGetGainsSourceSplit(const Split *split)
The xaccSplitGetGainsSourceSplit() routine returns the split that is the source of the cap gains in t...
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
Definition qofclass.h:124
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
Definition qofclass.h:131
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.
Definition qofclass.cpp:86
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
Definition qofclass.h:169
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
Definition gnc-date.h:108
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
size_t qof_print_date_buff(char *buff, const size_t len, time64 t)
Convenience: calls through to qof_print_date_dmy_buff().
Definition gnc-date.cpp:574
time64 gnc_time(time64 *tbuf)
get the current time
Definition gnc-date.cpp:262
int xaccTransOrder(const Transaction *ta, const Transaction *tb)
The xaccTransOrder(ta,tb) method is useful for sorting.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
gboolean xaccTransIsBalanced(const Transaction *trans)
Returns true if the transaction is balanced according to the rules currently in effect.
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
The xaccAccountInsertLot() method will register the indicated lot with this account.
Definition Account.cpp:2129
int xaccTransGetSplitIndex(const Transaction *trans, const Split *split)
Inverse of xaccTransGetSplit().
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.
SplitList * xaccTransGetSplitList(const Transaction *trans)
The xaccTransGetSplitList() method returns a GList of the splits in a transaction.
int xaccTransCountSplits(const Transaction *trans)
Returns the number of splits in this transaction.
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated account.
Definition Account.h:1069
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
const char * xaccTransGetReadOnly(Transaction *trans)
Returns a non-NULL value if this Transaction was marked as read-only with some specific "reason" text...
gboolean xaccTransEqual(const Transaction *ta, const Transaction *tb, gboolean check_guids, gboolean check_splits, gboolean check_balances, gboolean assume_ordered)
Equality.
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition qofid.cpp:209
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
Definition qofid.cpp:232
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition qofevent.cpp:231
#define GNC_EVENT_ITEM_ADDED
These events are used when a split is added to an account.
Definition gnc-event.h:45
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition guid.h:84
GncGUID * guid_copy(const GncGUID *guid)
Returns a newly allocated GncGUID that matches the passed-in GUID.
Definition guid.cpp:155
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...
Definition guid.cpp:208
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
void qof_instance_copy_book(gpointer ptr1, gconstpointer ptr2)
Copy the book from one QofInstances to another.
#define qof_instance_is_dirty
Return value of is_dirty flag.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
void qof_instance_set(QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
gboolean qof_instance_books_equal(gconstpointer ptr1, gconstpointer ptr2)
See if two QofInstances share the same book.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
guint32 qof_instance_get_idata(gconstpointer inst)
get the instance tag number used for kvp management in sql backends.
const GncGUID * qof_entity_get_guid(gconstpointer ent)
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272
void gnc_lot_add_split(GNCLot *lot, Split *split)
Adds a split to this lot.
Definition gnc-lot.cpp:580
Account * gnc_lot_get_account(const GNCLot *lot)
Returns the account with which this lot is associated.
Definition gnc-lot.cpp:377
void gnc_lot_remove_split(GNCLot *lot, Split *split)
Adds a split from this lot.
Definition gnc-lot.cpp:632
void gnc_lot_set_closed_unknown(GNCLot *lot)
Reset closed flag so that it will be recalculated.
Definition gnc-lot.cpp:414
const char * gnc_numeric_errorCode_to_string(GNCNumericErrorCode error_code)
Returns a string representation of the given GNCNumericErrorCode.
double gnc_numeric_to_double(gnc_numeric in)
Convert numeric to floating-point value.
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 ...
gchar * gnc_numeric_to_string(gnc_numeric n)
Convert to string.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gnc_numeric gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Division.
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.
gnc_numeric gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Multiply a times b, returning the product.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
gchar * gnc_num_dbg_to_string(gnc_numeric n)
Convert to string.
@ GNC_ERROR_OK
No error.
@ GNC_HOW_RND_ROUND_HALF_UP
Round to the nearest integer, rounding away from zero when there are two equidistant nearest integers...
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
Definition qofid.cpp:238
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
Definition qofobject.h:63
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
Definition qofquery.h:108
int xaccSplitCompareAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of account.
Definition Split.cpp:1723
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
Definition Split.cpp:1881
void xaccSplitSetAdjustedAmount(Split *s, gnc_numeric amt)
Sets the stock split adjusted amount of a split.
Definition Split.cpp:1361
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
Definition Split.cpp:1830
gboolean xaccSplitDestroy(Split *split)
Destructor.
Definition Split.cpp:1525
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
Definition Split.cpp:1988
#define SPLIT_ACCOUNT_GUID
for guid_match_all
Definition Split.h:571
gnc_numeric xaccSplitGetClearedBalance(const Split *s)
The cleared-balance is the currency-denominated balance of all transactions that have been marked as ...
Definition Split.cpp:1343
void xaccSplitSetMemo(Split *split, const char *memo)
The memo is an arbitrary string associated with a split.
Definition Split.cpp:1778
int xaccSplitCompareOtherAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of the other account.
Definition Split.cpp:1737
void xaccSplitSetSharePrice(Split *s, gnc_numeric price)
Definition Split.cpp:1220
gint xaccSplitOrder(const Split *sa, const Split *sb)
The xaccSplitOrder(sa,sb) method is useful for sorting.
Definition Split.cpp:1555
void xaccSplitMergePeerSplits(Split *split, const Split *other_split)
Merge the other_split's peer splits into split's peers.
Definition Split.cpp:2151
Split * xaccSplitLookup(const GncGUID *guid, QofBook *book)
The xaccSplitLookup() subroutine will return the split associated with the given id,...
Definition Split.cpp:1095
#define xaccSplitGetGUID(X)
Definition Split.h:579
void xaccSplitSetValue(Split *s, gnc_numeric amt)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
Definition Split.cpp:1295
const char * xaccSplitGetCorrAccountName(const Split *sa)
document me
Definition Split.cpp:1649
void xaccSplitRemovePeerSplit(Split *split, const Split *other_split)
Remove a peer split from this split's lot-split list.
Definition Split.cpp:2134
Split * xaccMallocSplit(QofBook *book)
Constructor.
Definition Split.cpp:539
gnc_numeric xaccSplitGetNoclosingBalance(const Split *s)
The noclosing-balance is the currency-denominated balance of all transactions except 'closing' transa...
Definition Split.cpp:1337
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
Definition Split.cpp:1258
const char * xaccSplitGetAction(const Split *split)
Returns the action string.
Definition Split.cpp:1982
#define VREC
split is void
Definition Split.h:77
const char * xaccSplitGetType(Split *s)
Returns the split type, which is either the string "normal", or "stock-split" for a split from a stoc...
Definition Split.cpp:2051
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...
Definition Split.cpp:1931
char * xaccSplitGetCorrAccountFullName(const Split *sa)
These functions take a split, get the corresponding split on the "other side" of the transaction,...
Definition Split.cpp:1666
time64 xaccSplitGetDateReconciled(const Split *split)
Retrieve the date when the Split was reconciled.
Definition Split.cpp:1870
gnc_numeric xaccSplitVoidFormerValue(const Split *split)
Returns the original pre-void value of a split.
Definition Split.cpp:2212
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
Definition Split.cpp:2001
void xaccSplitSetLot(Split *split, GNCLot *lot)
Assigns the split to a specific Lot.
Definition Split.cpp:1937
gnc_numeric xaccSplitGetSharePrice(const Split *split)
Returns the price of the split, that is, the value divided by the amount.
Definition Split.cpp:2007
const char * xaccSplitGetCorrAccountCode(const Split *sa)
document me
Definition Split.cpp:1682
int xaccSplitCompareAccountFullNames(const Split *sa, const Split *sb)
Compare two splits by full name of account.
Definition Split.cpp:1699
gnc_numeric xaccSplitGetReconciledBalance(const Split *s)
Returns the reconciled-balance of this split.
Definition Split.cpp:1349
gboolean xaccSplitEqual(const Split *sa, const Split *sb, gboolean check_guids, gboolean check_balances, gboolean check_txn_splits)
Equality.
Definition Split.cpp:822
gboolean xaccSplitHasPeers(const Split *split)
Does this split have peers?
Definition Split.cpp:2115
Account * xaccSplitGetAccount(const Split *s)
Returns the account of this split, which was set through xaccAccountInsertSplit().
Definition Split.cpp:959
int xaccSplitCompareOtherAccountCodes(const Split *sa, const Split *sb)
Compare two splits by code of the other account.
Definition Split.cpp:1758
void xaccSplitCopyOnto(const Split *from_split, Split *to_split)
This is really a helper for xaccTransCopyOnto.
Definition Split.cpp:648
void xaccSplitSetSharePriceAndAmount(Split *s, gnc_numeric price, gnc_numeric amt)
The xaccSplitSetSharePriceAndAmount() method will simultaneously update the share price and the numbe...
Definition Split.cpp:1192
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
Definition Split.cpp:1947
void xaccSplitSetDateReconciledSecs(Split *split, time64 secs)
Set the date on which this split was reconciled by specifying the time as time64.
Definition Split.cpp:1856
gnc_numeric xaccSplitVoidFormerAmount(const Split *split)
Returns the original pre-void amount of a split.
Definition Split.cpp:2204
void xaccSplitSetOnlineID(Split *split, const char *id)
The online_id is the OFX/HBCI "FITID" recorded on a split when it is imported.
Definition Split.cpp:1953
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...
Definition Split.cpp:1370
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...
Definition Split.cpp:1429
#define NREC
not reconciled or cleared
Definition Split.h:76
const char * xaccSplitGetOnlineID(const Split *split)
Returns the split's online_id.
Definition Split.cpp:1967
#define FREC
frozen into accounting period
Definition Split.h:75
Split * xaccSplitGetOtherSplit(const Split *split)
The xaccSplitGetOtherSplit() is a convenience routine that returns the other of a pair of splits.
Definition Split.cpp:2174
QofBook * xaccSplitGetBook(const Split *split)
Returns the book of this split, i.e.
gnc_numeric xaccSplitGetAdjustedAmount(const Split *s)
Returns the stock-split adjusted amount of the split in the account's commodity.
Definition Split.cpp:1355
#define CREC
The Split has been cleared.
Definition Split.h:73
void xaccSplitAddPeerSplit(Split *split, const Split *other_split, time64 timestamp)
Add a peer split to this split's lot-split list.
Definition Split.cpp:2097
gnc_numeric xaccSplitGetBalance(const Split *s)
Returns the running balance up to and including the indicated split.
Definition Split.cpp:1331
gboolean xaccSplitIsPeerSplit(const Split *split, const Split *other_split)
Report if a split is a peer of this one.
Definition Split.cpp:2121
#define YREC
The Split has been reconciled.
Definition Split.h:74
void xaccSplitSetAction(Split *split, const char *actn)
The Action is an arbitrary user-assigned string.
Definition Split.cpp:1797
gboolean xaccSplitIsStockSplit(Split *s)
Returns true if the split is of type stock split.
Definition Split.cpp:2091
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Definition Split.cpp:1995
void xaccSplitMakeStockSplit(Split *s)
Mark a split to be of type stock split - after this, you shouldn't modify the value anymore,...
Definition Split.cpp:2075
gboolean xaccSplitHasOnlineID(const Split *split)
Returns TRUE if the split has a non-empty online_id.
Definition Split.cpp:1975
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
Encapsulate all the information about a dataset.
Object instance holds common fields that most gnucash objects use.
STRUCTS.
The type used to store guids in C.
Definition guid.h:75
QofBook reference.
Definition qofbook-p.hpp:47