2006-02-22 15:52:46 -06:00
/********************************************************************\
* Split . c - - split implementation *
* Copyright ( C ) 1997 Robin D . Clark *
* Copyright ( C ) 1997 - 2003 Linas Vepstas < linas @ linas . org > *
* Copyright ( C ) 2000 Bill Gribble < grib @ billgribble . com > *
* Copyright ( c ) 2006 David Hampton < hampton @ employees . org > *
* *
* This program is free software ; you can redistribute it and / or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation ; either version 2 of *
* the License , or ( at your option ) any later version . *
* *
* This program is distributed in the hope that it will be useful , *
* but WITHOUT ANY WARRANTY ; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the *
* GNU General Public License for more details . *
* *
* You should have received a copy of the GNU General Public License *
* along with this program ; if not , contact : *
* *
* Free Software Foundation Voice : + 1 - 617 - 542 - 5942 *
* 51 Franklin Street , Fifth Floor Fax : + 1 - 617 - 542 - 2652 *
* Boston , MA 02110 - 1301 , USA gnu @ gnu . org *
* *
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2017-10-26 04:14:21 -05:00
# include <config.h>
2006-02-22 15:52:46 -06:00
2015-05-22 21:50:25 -05:00
# include <platform.h>
# if PLATFORM(WINDOWS)
# include <windows.h>
# endif
2006-02-22 15:52:46 -06:00
# include <glib.h>
# include <glib/gi18n.h>
# include <stdlib.h>
# include <string.h>
2010-02-25 11:42:43 -06:00
# ifdef HAVE_SYS_TIME_H
# include <sys / time.h>
# endif
2006-02-22 15:52:46 -06:00
# include <time.h>
2010-02-25 11:42:43 -06:00
# ifdef HAVE_UNISTD_H
# include <unistd.h>
# endif
2006-02-22 15:52:46 -06:00
2007-05-02 00:42:41 -05:00
# include "qof.h"
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
# include "qofbook.h"
2006-02-22 15:52:46 -06:00
# include "Split.h"
# include "AccountP.h"
# include "Scrub.h"
# include "TransactionP.h"
# include "TransLog.h"
# include "cap-gains.h"
# include "gnc-commodity.h"
# include "gnc-engine.h"
# include "gnc-lot.h"
2006-03-08 21:58:00 -06:00
# include "gnc-event.h"
2014-05-07 08:37:14 -05:00
# include "qofinstance-p.h"
2006-02-22 15:52:46 -06:00
const char * void_former_amt_str = " void-former-amount " ;
const char * void_former_val_str = " void-former-value " ;
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_ENGINE ;
2014-05-07 08:37:14 -05:00
/* KVP key values used for SX info stored Split's slots. */
# define GNC_SX_ID "sched-xaction"
# define GNC_SX_ACCOUNT "account"
# define GNC_SX_CREDIT_FORMULA "credit-formula"
# define GNC_SX_DEBIT_FORMULA "debit-formula"
# define GNC_SX_CREDIT_NUMERIC "credit-numeric"
# define GNC_SX_DEBIT_NUMERIC "debit-numeric"
# define GNC_SX_SHARES "shares"
2010-03-02 15:40:28 -06:00
enum
{
2010-02-28 11:35:53 -06:00
PROP_0 ,
2014-05-07 08:37:14 -05:00
PROP_TX , /* Table */
PROP_ACCOUNT , /* Table */
PROP_MEMO , /* Table */
PROP_ACTION , /* Table */
// PROP_RECONCILE_STATE, /* Table */
PROP_RECONCILE_DATE , /* Table */
PROP_VALUE , /* Table, in 2 fields */
PROP_SX_ACCOUNT , /* KVP */
PROP_SX_CREDIT_FORMULA , /* KVP */
PROP_SX_CREDIT_NUMERIC , /* KVP */
PROP_SX_DEBIT_FORMULA , /* KVP */
PROP_SX_DEBIT_NUMERIC , /* KVP */
PROP_SX_SHARES , /* KVP */
PROP_LOT , /* KVP */
PROP_ONLINE_ACCOUNT , /* KVP */
PROP_GAINS_SPLIT , /* KVP */
PROP_GAINS_SOURCE , /* KVP */
PROP_RUNTIME_0 ,
PROP_AMOUNT , /* Runtime */
2010-02-28 11:35:53 -06:00
} ;
2007-04-04 19:23:50 -05:00
/* GObject Initialization */
2010-02-28 11:35:53 -06:00
G_DEFINE_TYPE ( Split , gnc_split , QOF_TYPE_INSTANCE )
2007-04-04 19:23:50 -05:00
static void
2007-04-04 22:10:26 -05:00
gnc_split_init ( Split * split )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
/* fill in some sane defaults */
split - > acc = NULL ;
split - > orig_acc = NULL ;
split - > parent = NULL ;
split - > lot = NULL ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > action = CACHE_INSERT ( " " ) ;
split - > memo = CACHE_INSERT ( " " ) ;
split - > reconciled = NREC ;
split - > amount = gnc_numeric_zero ( ) ;
split - > value = gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
2018-08-02 20:19:15 -05:00
split - > date_reconciled = 0 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > balance = gnc_numeric_zero ( ) ;
split - > cleared_balance = gnc_numeric_zero ( ) ;
split - > reconciled_balance = gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > gains = GAINS_STATUS_UNKNOWN ;
split - > gains_split = NULL ;
2010-02-28 11:35:53 -06:00
}
static void
gnc_split_dispose ( GObject * splitp )
{
G_OBJECT_CLASS ( gnc_split_parent_class ) - > dispose ( splitp ) ;
}
2006-02-22 15:52:46 -06:00
2010-02-28 11:35:53 -06:00
static void
gnc_split_finalize ( GObject * splitp )
{
G_OBJECT_CLASS ( gnc_split_parent_class ) - > finalize ( splitp ) ;
}
2013-09-24 15:11:24 -05:00
/* Note that g_value_set_object() refs the object, as does
* g_object_get ( ) . But g_object_get ( ) only unrefs once when it disgorges
* the object , leaving an unbalanced ref , which leaks . So instead of
* using g_value_set_object ( ) , use g_value_take_object ( ) which doesn ' t
* ref the object when used in get_property ( ) .
*/
2010-02-28 11:35:53 -06:00
static void
gnc_split_get_property ( GObject * object ,
2010-03-02 15:40:28 -06:00
guint prop_id ,
GValue * value ,
GParamSpec * pspec )
2010-02-28 11:35:53 -06:00
{
Split * split ;
2014-05-07 08:37:14 -05:00
gchar * key ;
2018-08-02 20:19:15 -05:00
Time64 t ;
2010-02-28 11:35:53 -06:00
g_return_if_fail ( GNC_IS_SPLIT ( object ) ) ;
split = GNC_SPLIT ( object ) ;
2010-03-02 15:40:28 -06:00
switch ( prop_id )
{
2015-05-31 19:59:01 -05:00
case PROP_ACTION :
g_value_set_string ( value , split - > action ) ;
break ;
case PROP_MEMO :
g_value_set_string ( value , split - > memo ) ;
break ;
case PROP_VALUE :
g_value_set_boxed ( value , & split - > value ) ;
break ;
case PROP_AMOUNT :
g_value_set_boxed ( value , & split - > amount ) ;
break ;
case PROP_RECONCILE_DATE :
2018-08-02 20:19:15 -05:00
t . t = split - > date_reconciled ;
g_value_set_boxed ( value , & t ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_TX :
g_value_take_object ( value , split - > parent ) ;
break ;
case PROP_ACCOUNT :
g_value_take_object ( value , split - > acc ) ;
break ;
case PROP_LOT :
g_value_take_object ( value , split - > lot ) ;
break ;
case PROP_SX_CREDIT_FORMULA :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_CREDIT_FORMULA ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_CREDIT_NUMERIC :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_CREDIT_NUMERIC ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_DEBIT_FORMULA :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_DEBIT_FORMULA ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_DEBIT_NUMERIC :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_DEBIT_NUMERIC ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_ACCOUNT :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_ACCOUNT ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_SHARES :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_SHARES ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_ONLINE_ACCOUNT :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 1 , " online_id " ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_GAINS_SPLIT :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 1 , " gains-split " ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_GAINS_SOURCE :
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , value , 1 , " gains-source " ) ;
2015-05-31 19:59:01 -05:00
break ;
default :
G_OBJECT_WARN_INVALID_PROPERTY_ID ( object , prop_id , pspec ) ;
break ;
2010-03-02 15:40:28 -06:00
}
2010-02-28 11:35:53 -06:00
}
static void
gnc_split_set_property ( GObject * object ,
2010-03-02 15:40:28 -06:00
guint prop_id ,
const GValue * value ,
GParamSpec * pspec )
2010-02-28 11:35:53 -06:00
{
Split * split ;
2010-03-02 15:40:28 -06:00
gnc_numeric * number ;
2014-05-07 08:37:14 -05:00
gchar * key ;
2018-08-02 15:29:47 -05:00
Time64 * t ;
2010-02-28 11:35:53 -06:00
g_return_if_fail ( GNC_IS_SPLIT ( object ) ) ;
split = GNC_SPLIT ( object ) ;
2014-05-07 08:37:14 -05:00
if ( prop_id < PROP_RUNTIME_0 & & split - > parent ! = NULL )
g_assert ( qof_instance_get_editlevel ( split - > parent ) ) ;
2010-03-02 15:40:28 -06:00
switch ( prop_id )
{
2015-05-31 19:59:01 -05:00
case PROP_ACTION :
xaccSplitSetAction ( split , g_value_get_string ( value ) ) ;
break ;
case PROP_MEMO :
xaccSplitSetMemo ( split , g_value_get_string ( value ) ) ;
break ;
case PROP_VALUE :
number = g_value_get_boxed ( value ) ;
xaccSplitSetValue ( split , * number ) ;
break ;
case PROP_AMOUNT :
number = g_value_get_boxed ( value ) ;
xaccSplitSetAmount ( split , * number ) ;
break ;
case PROP_RECONCILE_DATE :
2018-08-02 15:29:47 -05:00
t = g_value_get_boxed ( value ) ;
xaccSplitSetDateReconciledSecs ( split , t - > t ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_TX :
xaccSplitSetParent ( split , g_value_get_object ( value ) ) ;
break ;
case PROP_ACCOUNT :
xaccSplitSetAccount ( split , g_value_get_object ( value ) ) ;
break ;
case PROP_LOT :
xaccSplitSetLot ( split , g_value_get_object ( value ) ) ;
break ;
case PROP_SX_CREDIT_FORMULA :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_CREDIT_FORMULA ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_CREDIT_NUMERIC :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_CREDIT_NUMERIC ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_DEBIT_FORMULA :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_DEBIT_FORMULA ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_DEBIT_NUMERIC :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_DEBIT_NUMERIC ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_ACCOUNT :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_ACCOUNT ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_SX_SHARES :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 2 , GNC_SX_ID , GNC_SX_SHARES ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_ONLINE_ACCOUNT :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 1 , " online_id " ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_GAINS_SPLIT :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 1 , " gains-split " ) ;
2015-05-31 19:59:01 -05:00
break ;
case PROP_GAINS_SOURCE :
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , value , 1 , " gains-source " ) ;
2015-05-31 19:59:01 -05:00
break ;
default :
G_OBJECT_WARN_INVALID_PROPERTY_ID ( object , prop_id , pspec ) ;
break ;
2010-03-02 15:40:28 -06:00
}
2010-02-28 11:35:53 -06:00
}
static void
gnc_split_class_init ( SplitClass * klass )
{
GObjectClass * gobject_class = G_OBJECT_CLASS ( klass ) ;
gobject_class - > dispose = gnc_split_dispose ;
gobject_class - > finalize = gnc_split_finalize ;
gobject_class - > set_property = gnc_split_set_property ;
gobject_class - > get_property = gnc_split_get_property ;
2010-03-02 15:40:28 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_ACTION ,
g_param_spec_string ( " action " ,
" Action " ,
" The action is an arbitrary string assigned "
" by the user. It is intended to be a short "
" string that contains extra information about "
" this split. " ,
NULL ,
G_PARAM_READWRITE ) ) ;
2010-03-02 15:40:28 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_MEMO ,
g_param_spec_string ( " memo " ,
" Memo " ,
" The action is an arbitrary string assigned "
" by the user. It is intended to be a short "
" string that describes the purpose of "
" this split. " ,
NULL ,
G_PARAM_READWRITE ) ) ;
2010-02-28 17:19:34 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_VALUE ,
g_param_spec_boxed ( " value " ,
" Split Value " ,
" The value for this split in the common currency. "
" The value and the amount provide enough information to "
" calculate a conversion rate. " ,
GNC_TYPE_NUMERIC ,
G_PARAM_READWRITE ) ) ;
2010-02-28 17:19:34 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_AMOUNT ,
g_param_spec_boxed ( " amount " ,
" Split Amount " ,
" The value for this split in the currency of its account. "
" The value and the amount provide enough information to "
" calculate a conversion rate. " ,
GNC_TYPE_NUMERIC ,
G_PARAM_READWRITE ) ) ;
2010-03-01 10:46:49 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_RECONCILE_DATE ,
g_param_spec_boxed ( " reconcile-date " ,
" Reconcile Date " ,
" The date this split was reconciled. " ,
2018-08-02 15:29:47 -05:00
GNC_TYPE_TIME64 ,
2015-05-31 19:59:01 -05:00
G_PARAM_READWRITE ) ) ;
2010-03-01 10:46:49 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_TX ,
g_param_spec_object ( " transaction " ,
" Transaction " ,
" The transaction that this split belongs to. " ,
GNC_TYPE_TRANSACTION ,
G_PARAM_READWRITE ) ) ;
2010-03-01 10:46:49 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_ACCOUNT ,
g_param_spec_object ( " account " ,
" Account " ,
" The account that this split belongs to. " ,
GNC_TYPE_ACCOUNT ,
G_PARAM_READWRITE ) ) ;
2010-03-01 10:46:49 -06:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_LOT ,
g_param_spec_object ( " lot " ,
" Lot " ,
" The lot that this split belongs to. " ,
GNC_TYPE_LOT ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_SX_DEBIT_FORMULA ,
g_param_spec_string ( " sx-debit-formula " ,
" Schedule Transaction Debit Formula " ,
" The formula used to calculate the actual debit "
" amount when a real split is generated from this "
" SX split. " ,
NULL ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_SX_DEBIT_NUMERIC ,
g_param_spec_boxed ( " sx-debit-numeric " ,
" Scheduled Transaction Debit Numeric " ,
" Numeric value to plug into the Debit Formula when a "
" real split is generated from this SX split. " ,
GNC_TYPE_NUMERIC ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_SX_CREDIT_FORMULA ,
g_param_spec_string ( " sx-credit-formula " ,
" Schedule Transaction Credit Formula " ,
" The formula used to calculate the actual credit "
" amount when a real split is generated from this "
" SX split. " ,
NULL ,
G_PARAM_READWRITE ) ) ;
g_object_class_install_property
( gobject_class ,
PROP_SX_CREDIT_NUMERIC ,
g_param_spec_boxed ( " sx-credit-numeric " ,
" Scheduled Transaction Credit Numeric " ,
" Numeric value to plug into the Credit Formula when a "
" real split is generated from this SX split. " ,
GNC_TYPE_NUMERIC ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
/* FIXME: PROP_SX_SHARES should be stored as a gnc_numeric, but the function
* which uses it , gnc_template_register_save_shares_cell , stores a
* phony string . This is maintained until backwards compatibility can
* be established .
*/
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_SX_SHARES ,
g_param_spec_string ( " sx-shares " ,
" Scheduled Transaction Shares " ,
" Numeric value of shares to insert in a new split when "
" it's generated from this SX split. " ,
NULL ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_SX_ACCOUNT ,
g_param_spec_boxed ( " sx-account " ,
" Scheduled Transaction Account " ,
" The target account for a scheduled transaction split. " ,
GNC_TYPE_GUID ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_ONLINE_ACCOUNT ,
g_param_spec_string ( " online-id " ,
" Online Account ID " ,
" The online account which corresponds to this "
" account for OFX/HCBI import " ,
NULL ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_GAINS_SPLIT ,
g_param_spec_boxed ( " gains-split " ,
" Gains Split " ,
" The capital gains split associated with this "
" split when this split represents the proceeds "
" from the sale of a commodity inside a Lot. " ,
GNC_TYPE_GUID ,
G_PARAM_READWRITE ) ) ;
2014-05-07 08:37:14 -05:00
g_object_class_install_property
2015-05-31 19:59:01 -05:00
( gobject_class ,
PROP_GAINS_SOURCE ,
g_param_spec_boxed ( " gains-source " ,
" Gains Source " ,
" The source split for which this split this is "
" the gains split. " ,
GNC_TYPE_GUID ,
G_PARAM_READWRITE ) ) ;
2010-02-28 11:35:53 -06:00
}
/********************************************************************\
* xaccInitSplit
* Initialize a Split structure
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void
xaccInitSplit ( Split * split , QofBook * book )
{
2010-03-02 15:40:28 -06:00
qof_instance_init_data ( & split - > inst , GNC_ID_SPLIT , book ) ;
2006-02-22 15:52:46 -06:00
}
void
xaccSplitReinit ( Split * split )
{
2010-03-02 15:40:28 -06:00
/* fill in some sane defaults */
split - > acc = NULL ;
split - > orig_acc = NULL ;
split - > parent = NULL ;
split - > lot = NULL ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
CACHE_REPLACE ( split - > action , " " ) ;
CACHE_REPLACE ( split - > memo , " " ) ;
split - > reconciled = NREC ;
split - > amount = gnc_numeric_zero ( ) ;
split - > value = gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
2018-08-02 20:19:15 -05:00
split - > date_reconciled = 0 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > balance = gnc_numeric_zero ( ) ;
split - > cleared_balance = gnc_numeric_zero ( ) ;
split - > reconciled_balance = gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
qof_instance_set_idata ( split , 0 ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > gains = GAINS_STATUS_UNKNOWN ;
split - > gains_split = NULL ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Split *
xaccMallocSplit ( QofBook * book )
{
2010-03-02 15:40:28 -06:00
Split * split ;
g_return_val_if_fail ( book , NULL ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split = g_object_new ( GNC_TYPE_SPLIT , NULL ) ;
xaccInitSplit ( split , book ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return split ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-03-02 15:40:28 -06:00
/* This routine is not exposed externally, since it does weird things,
* like not really setting up the parent account correctly , and ditto
2006-02-22 15:52:46 -06:00
* the parent transaction . This routine is prone to programmer error
* if not used correctly . It is used only by the edit - rollback code .
* Don ' t get duped !
*/
Split *
xaccDupeSplit ( const Split * s )
{
2010-03-02 15:40:28 -06:00
Split * split = g_object_new ( GNC_TYPE_SPLIT , NULL ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* Trash the entity table. We don't want to mistake the cloned
* splits as something official . If we ever use this split , we ' ll
* have to fix this up .
*/
split - > inst . e_type = NULL ;
qof_instance_copy_guid ( split , s ) ;
qof_instance_copy_book ( split , s ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > parent = s - > parent ;
split - > acc = s - > acc ;
split - > orig_acc = s - > orig_acc ;
split - > lot = s - > lot ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > memo = CACHE_INSERT ( s - > memo ) ;
split - > action = CACHE_INSERT ( s - > action ) ;
2006-02-22 15:52:46 -06:00
2015-05-08 17:15:39 -05:00
qof_instance_copy_kvp ( QOF_INSTANCE ( split ) , QOF_INSTANCE ( s ) ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > reconciled = s - > reconciled ;
split - > date_reconciled = s - > date_reconciled ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > value = s - > value ;
split - > amount = s - > amount ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* no need to futz with the balances; these get wiped each time ...
* split - > balance = s - > balance ;
* split - > cleared_balance = s - > cleared_balance ;
* split - > reconciled_balance = s - > reconciled_balance ;
*/
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return split ;
2006-02-22 15:52:46 -06:00
}
Split *
2014-05-07 08:37:14 -05:00
xaccSplitCloneNoKvp ( const Split * s )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
Split * split = g_object_new ( GNC_TYPE_SPLIT , NULL ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > parent = NULL ;
split - > memo = CACHE_INSERT ( s - > memo ) ;
split - > action = CACHE_INSERT ( s - > action ) ;
split - > reconciled = s - > reconciled ;
split - > date_reconciled = s - > date_reconciled ;
split - > value = s - > value ;
split - > amount = s - > amount ;
split - > balance = s - > balance ;
split - > cleared_balance = s - > cleared_balance ;
split - > reconciled_balance = s - > reconciled_balance ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
split - > gains = GAINS_STATUS_UNKNOWN ;
split - > gains_split = NULL ;
2006-02-22 15:52:46 -06:00
2014-05-07 08:37:14 -05:00
qof_instance_init_data ( & split - > inst , GNC_ID_SPLIT ,
qof_instance_get_book ( s ) ) ;
2010-03-02 15:40:28 -06:00
xaccAccountInsertSplit ( s - > acc , split ) ;
if ( s - > lot )
{
/* CHECKME: Is this right? */
gnc_lot_add_split ( s - > lot , split ) ;
}
return split ;
2006-02-22 15:52:46 -06:00
}
2014-05-07 08:37:14 -05:00
void
xaccSplitCopyKvp ( const Split * from , Split * to )
{
2015-05-08 17:15:39 -05:00
qof_instance_copy_kvp ( QOF_INSTANCE ( to ) , QOF_INSTANCE ( from ) ) ;
2014-05-07 08:37:14 -05:00
}
2013-02-28 03:52:12 -06:00
/*################## Added for Reg2 #################*/
/* This is really a helper for xaccTransCopyOnto. It doesn't reparent
the ' to ' split to from ' s transaction , because xaccTransCopyOnto is
responsible for parenting the split to the correct transaction .
Also , from ' s parent transaction may not even be a valid
transaction , so this function may not modify anything about ' from '
or from ' s transaction .
*/
void
xaccSplitCopyOnto ( const Split * from_split , Split * to_split )
{
2015-05-31 19:59:01 -05:00
if ( ! from_split | | ! to_split ) return ;
xaccTransBeginEdit ( to_split - > parent ) ;
2013-02-28 03:52:12 -06:00
2015-05-31 19:59:01 -05:00
xaccSplitSetMemo ( to_split , xaccSplitGetMemo ( from_split ) ) ;
xaccSplitSetAction ( to_split , xaccSplitGetAction ( from_split ) ) ;
xaccSplitSetAmount ( to_split , xaccSplitGetAmount ( from_split ) ) ;
xaccSplitSetValue ( to_split , xaccSplitGetValue ( from_split ) ) ;
/* Setting the account is okay here because, even though the from
split might not really belong to the account it claims to ,
setting the account won ' t cause any event involving from . */
xaccSplitSetAccount ( to_split , xaccSplitGetAccount ( from_split ) ) ;
/* N.B. Don't set parent. */
2013-02-28 03:52:12 -06:00
2015-05-31 19:59:01 -05:00
qof_instance_set_dirty ( QOF_INSTANCE ( to_split ) ) ;
xaccTransCommitEdit ( to_split - > parent ) ;
2013-02-28 03:52:12 -06:00
}
/*################## Added for Reg2 #################*/
2006-02-22 15:52:46 -06:00
# ifdef DUMP_FUNCTIONS
2009-12-17 01:10:49 -06:00
void
2006-02-22 15:52:46 -06:00
xaccSplitDump ( const Split * split , const char * tag )
{
2018-08-02 20:19:15 -05:00
char datebuff [ MAX_DATE_LENGTH + 1 ] ;
memset ( datebuff , 0 , sizeof ( datebuff ) ) ;
qof_print_date_buff ( datebuff , sizeof ( datebuff ) , split - > date_reconciled ) ;
2010-03-02 15:40:28 -06:00
printf ( " %s Split %p " , tag , split ) ;
printf ( " Book: %p \n " , qof_instance_get_book ( split ) ) ;
printf ( " Account: %p (%s) \n " , split - > acc ,
split - > acc ? xaccAccountGetName ( split - > acc ) : " " ) ;
printf ( " Commod: %s \n " ,
split - > acc ?
gnc_commodity_get_printname ( xaccAccountGetCommodity ( split - > acc ) )
: " " ) ;
printf ( " Lot: %p \n " , split - > lot ) ;
printf ( " Parent: %p \n " , split - > parent ) ;
printf ( " Gains: %p \n " , split - > gains_split ) ;
printf ( " Memo: %s \n " , split - > memo ? split - > memo : " (null) " ) ;
printf ( " Action: %s \n " , split - > action ? split - > action : " (null) " ) ;
2015-05-31 19:59:01 -05:00
printf ( " KVP Data: %s \n " , qof_instance_kvp_as_string ( QOF_INSTANCE ( split ) ) ) ;
2018-08-02 20:19:15 -05:00
printf ( " Recncld: %c (date %s) \n " , split - > reconciled , datebuff ) ;
2010-03-02 15:40:28 -06:00
printf ( " Value: %s \n " , gnc_numeric_to_string ( split - > value ) ) ;
printf ( " Amount: %s \n " , gnc_numeric_to_string ( split - > amount ) ) ;
printf ( " Balance: %s \n " , gnc_numeric_to_string ( split - > balance ) ) ;
printf ( " CBalance: %s \n " , gnc_numeric_to_string ( split - > cleared_balance ) ) ;
printf ( " RBalance: %s \n " ,
gnc_numeric_to_string ( split - > reconciled_balance ) ) ;
printf ( " idata: %x \n " , qof_instance_get_idata ( split ) ) ;
2006-02-22 15:52:46 -06:00
}
# endif
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void
xaccFreeSplit ( Split * split )
{
2010-03-02 15:40:28 -06:00
if ( ! split ) return ;
/* Debug double-free's */
if ( ( ( char * ) 1 ) = = split - > memo )
{
PERR ( " double-free %p " , split ) ;
return ;
}
CACHE_REMOVE ( split - > memo ) ;
CACHE_REMOVE ( split - > action ) ;
/* Just in case someone looks up freed memory ... */
split - > memo = ( char * ) 1 ;
split - > action = NULL ;
split - > reconciled = NREC ;
split - > amount = gnc_numeric_zero ( ) ;
split - > value = gnc_numeric_zero ( ) ;
split - > parent = NULL ;
split - > lot = NULL ;
split - > acc = NULL ;
split - > orig_acc = NULL ;
2018-08-02 20:19:15 -05:00
split - > date_reconciled = 0 ;
2015-05-08 17:15:39 -05:00
G_OBJECT_CLASS ( QOF_INSTANCE_GET_CLASS ( & split - > inst ) ) - > dispose ( G_OBJECT ( split ) ) ;
2010-03-02 15:40:28 -06:00
// Is this right?
if ( split - > gains_split ) split - > gains_split - > gains_split = NULL ;
/* qof_instance_release(&split->inst); */
g_object_unref ( split ) ;
2006-02-22 15:52:46 -06:00
}
2006-03-03 18:09:03 -06:00
void mark_split ( Split * s )
{
2010-03-02 15:40:28 -06:00
if ( s - > acc )
{
g_object_set ( s - > acc , " sort-dirty " , TRUE , " balance-dirty " , TRUE , NULL ) ;
}
2006-03-03 18:09:03 -06:00
2010-03-02 15:40:28 -06:00
/* set dirty flag on lot too. */
if ( s - > lot ) gnc_lot_set_closed_unknown ( s - > lot ) ;
2006-03-03 18:09:03 -06:00
}
2006-02-22 15:52:46 -06:00
/*
* Helper routine for xaccSplitEqual .
*/
static gboolean
xaccSplitEqualCheckBal ( const char * tag , gnc_numeric a , gnc_numeric b )
{
2010-03-02 15:40:28 -06:00
char * str_a , * str_b ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( gnc_numeric_equal ( a , b ) )
return TRUE ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
str_a = gnc_numeric_to_string ( a ) ;
str_b = gnc_numeric_to_string ( b ) ;
2006-02-22 15:52:46 -06:00
2013-06-25 12:04:47 -05:00
PINFO ( " %sbalances differ: %s vs %s " , tag , str_a , str_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
g_free ( str_a ) ;
g_free ( str_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return FALSE ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************
* xaccSplitEqual
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
gboolean
xaccSplitEqual ( const Split * sa , const Split * sb ,
gboolean check_guids ,
gboolean check_balances ,
gboolean check_txn_splits )
{
2010-03-25 13:32:40 -05:00
gboolean same_book ;
2010-03-02 15:40:28 -06:00
if ( ! sa & & ! sb ) return TRUE ; /* Arguable. FALSE is better, methinks */
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! sa | | ! sb )
{
2013-06-25 12:04:47 -05:00
PINFO ( " one is NULL " ) ;
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( sa = = sb ) return TRUE ;
2006-02-22 15:52:46 -06:00
2010-03-25 13:32:40 -05:00
same_book = qof_instance_get_book ( QOF_INSTANCE ( sa ) ) = = qof_instance_get_book ( QOF_INSTANCE ( sb ) ) ;
2010-03-02 15:40:28 -06:00
if ( check_guids )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
if ( qof_instance_guid_compare ( sa , sb ) ! = 0 )
{
2013-06-25 12:04:47 -05:00
PINFO ( " GUIDs differ " ) ;
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
}
2010-03-25 13:32:40 -05:00
/* If the same book, since these strings are cached we can just use pointer equality */
2012-08-07 12:24:55 -05:00
if ( ( same_book & & sa - > memo ! = sb - > memo ) | | ( ! same_book & & g_strcmp0 ( sa - > memo , sb - > memo ) ! = 0 ) )
2010-03-02 15:40:28 -06:00
{
2013-06-25 12:04:47 -05:00
PINFO ( " memos differ: (%p)%s vs (%p)%s " ,
2010-03-02 15:40:28 -06:00
sa - > memo , sa - > memo , sb - > memo , sb - > memo ) ;
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2012-08-07 12:24:55 -05:00
if ( ( same_book & & sa - > action ! = sb - > action ) | | ( ! same_book & & g_strcmp0 ( sa - > action , sb - > action ) ! = 0 ) )
2010-03-02 15:40:28 -06:00
{
2013-06-25 12:04:47 -05:00
PINFO ( " actions differ: %s vs %s " , sa - > action , sb - > action ) ;
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2015-05-08 17:15:39 -05:00
if ( qof_instance_compare_kvp ( QOF_INSTANCE ( sa ) , QOF_INSTANCE ( sb ) ) ! = 0 )
2010-03-02 15:40:28 -06:00
{
char * frame_a ;
char * frame_b ;
2006-02-22 15:52:46 -06:00
2015-05-08 17:15:39 -05:00
frame_a = qof_instance_kvp_as_string ( QOF_INSTANCE ( sa ) ) ;
frame_b = qof_instance_kvp_as_string ( QOF_INSTANCE ( sb ) ) ;
2006-02-22 15:52:46 -06:00
2013-06-25 12:04:47 -05:00
PINFO ( " kvp frames differ: \n %s \n \n vs \n \n %s " , frame_a , frame_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
g_free ( frame_a ) ;
g_free ( frame_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( sa - > reconciled ! = sb - > reconciled )
{
2013-06-25 12:04:47 -05:00
PINFO ( " reconcile flags differ: %c vs %c " , sa - > reconciled , sb - > reconciled ) ;
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2018-08-02 20:19:15 -05:00
if ( sa - > date_reconciled ! = sb - > date_reconciled )
2010-03-02 15:40:28 -06:00
{
2013-06-25 12:04:47 -05:00
PINFO ( " reconciled date differs " ) ;
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! gnc_numeric_eq ( xaccSplitGetAmount ( sa ) , xaccSplitGetAmount ( sb ) ) )
{
char * str_a ;
char * str_b ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
str_a = gnc_numeric_to_string ( xaccSplitGetAmount ( sa ) ) ;
str_b = gnc_numeric_to_string ( xaccSplitGetAmount ( sb ) ) ;
2006-02-22 15:52:46 -06:00
2013-06-25 12:04:47 -05:00
PINFO ( " amounts differ: %s vs %s " , str_a , str_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
g_free ( str_a ) ;
g_free ( str_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! gnc_numeric_eq ( xaccSplitGetValue ( sa ) , xaccSplitGetValue ( sb ) ) )
{
char * str_a ;
char * str_b ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
str_a = gnc_numeric_to_string ( xaccSplitGetValue ( sa ) ) ;
str_b = gnc_numeric_to_string ( xaccSplitGetValue ( sb ) ) ;
2006-02-22 15:52:46 -06:00
2013-06-25 12:04:47 -05:00
PINFO ( " values differ: %s vs %s " , str_a , str_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
g_free ( str_a ) ;
g_free ( str_b ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return FALSE ;
}
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( check_balances )
{
if ( ! xaccSplitEqualCheckBal ( " " , sa - > balance , sb - > balance ) )
return FALSE ;
if ( ! xaccSplitEqualCheckBal ( " cleared " , sa - > cleared_balance ,
sb - > cleared_balance ) )
return FALSE ;
if ( ! xaccSplitEqualCheckBal ( " reconciled " , sa - > reconciled_balance ,
sb - > reconciled_balance ) )
return FALSE ;
}
if ( ! xaccTransEqual ( sa - > parent , sb - > parent , check_guids , check_txn_splits ,
check_balances , FALSE ) )
{
2013-06-25 12:04:47 -05:00
PINFO ( " transactions differ " ) ;
2010-03-02 15:40:28 -06:00
return FALSE ;
}
return TRUE ;
2006-02-22 15:52:46 -06:00
}
2012-08-07 12:24:33 -05:00
2012-10-18 03:15:21 -05:00
/*################## Added for Reg2 #################*/
2012-08-07 12:24:33 -05:00
/********************************************************************
* xaccSplitListGetUniqueTransactions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
GList *
xaccSplitListGetUniqueTransactions ( const GList * splits )
{
2012-10-18 03:15:21 -05:00
const GList * snode ;
2012-08-07 12:24:33 -05:00
GList * transList = NULL ;
2012-10-18 03:15:21 -05:00
for ( snode = splits ; snode ; snode = snode - > next )
{
Transaction * trans = xaccSplitGetParent ( ( Split * ) ( snode - > data ) ) ;
GList * item = g_list_find ( transList , trans ) ;
if ( item = = NULL )
transList = g_list_append ( transList , trans ) ;
2012-08-07 12:24:33 -05:00
}
return transList ;
}
2012-10-18 03:15:21 -05:00
/*################## Added for Reg2 #################*/
2012-08-07 12:24:33 -05:00
2006-02-22 15:52:46 -06:00
/********************************************************************
* Account funcs
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Account *
xaccSplitGetAccount ( const Split * s )
{
2010-03-02 15:40:28 -06:00
return s ? s - > acc : NULL ;
2006-02-22 15:52:46 -06:00
}
2006-03-03 18:09:03 -06:00
void
xaccSplitSetAccount ( Split * s , Account * acc )
{
Transaction * trans ;
g_return_if_fail ( s & & acc ) ;
2007-05-01 22:18:46 -05:00
g_return_if_fail ( qof_instance_books_equal ( acc , s ) ) ;
2006-03-03 18:09:03 -06:00
trans = s - > parent ;
if ( trans )
xaccTransBeginEdit ( trans ) ;
s - > acc = acc ;
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
if ( trans )
xaccTransCommitEdit ( trans ) ;
}
2008-10-27 18:42:01 -05:00
static void commit_err ( QofInstance * inst , QofBackendError errcode )
{
2010-03-02 15:40:28 -06:00
PERR ( " commit error: %d " , errcode ) ;
gnc_engine_signal_commit_error ( errcode ) ;
2008-10-27 18:42:01 -05:00
}
2006-03-03 18:09:03 -06:00
/* An engine-private helper for completing xaccTransCommitEdit(). */
void
xaccSplitCommitEdit ( Split * s )
{
2011-10-16 16:01:28 -05:00
Account * acc = NULL ;
Account * orig_acc = NULL ;
2006-03-03 18:09:03 -06:00
g_return_if_fail ( s ) ;
2010-01-30 16:57:55 -06:00
if ( ! qof_instance_is_dirty ( QOF_INSTANCE ( s ) ) )
2006-03-03 18:09:03 -06:00
return ;
orig_acc = s - > orig_acc ;
2011-10-15 07:04:38 -05:00
2011-10-16 16:01:28 -05:00
if ( GNC_IS_ACCOUNT ( s - > acc ) )
2011-10-17 14:07:41 -05:00
acc = s - > acc ;
2011-10-15 07:04:38 -05:00
2006-05-04 19:58:17 -05:00
/* Remove from lot (but only if it hasn't been moved to
new lot already ) */
2010-02-27 09:54:20 -06:00
if ( s - > lot & & ( gnc_lot_get_account ( s - > lot ) ! = acc | | qof_instance_get_destroying ( s ) ) )
2006-05-04 19:58:17 -05:00
gnc_lot_remove_split ( s - > lot , s ) ;
2006-03-03 18:09:03 -06:00
/* Possibly remove the split from the original account... */
2010-03-02 15:40:28 -06:00
if ( orig_acc & & ( orig_acc ! = acc | | qof_instance_get_destroying ( s ) ) )
{
if ( ! gnc_account_remove_split ( orig_acc , s ) )
{
PERR ( " Account lost track of moved or deleted split. " ) ;
2007-04-17 23:50:34 -05:00
}
2010-01-30 16:57:55 -06:00
}
2006-03-03 18:09:03 -06:00
/* ... and insert it into the new account if needed */
2010-03-02 15:40:28 -06:00
if ( acc & & ( orig_acc ! = acc ) & & ! qof_instance_get_destroying ( s ) )
{
if ( gnc_account_insert_split ( acc , s ) )
{
2006-03-03 18:09:03 -06:00
/* If the split's lot belonged to some other account, we
leave it so . */
2010-02-27 09:54:20 -06:00
if ( s - > lot & & ( NULL = = gnc_lot_get_account ( s - > lot ) ) )
2006-03-03 18:09:03 -06:00
xaccAccountInsertLot ( acc , s - > lot ) ;
2010-03-02 15:40:28 -06:00
}
else
{
2007-04-17 23:50:34 -05:00
PERR ( " Account grabbed split prematurely. " ) ;
}
2006-03-03 18:09:03 -06:00
xaccSplitSetAmount ( s , xaccSplitGetAmount ( s ) ) ;
}
2010-03-02 15:40:28 -06:00
if ( s - > parent ! = s - > orig_parent )
{
2006-03-03 18:09:03 -06:00
//FIXME: find better event
2006-04-10 22:12:09 -05:00
if ( s - > orig_parent )
2010-03-02 15:40:28 -06:00
qof_event_gen ( & s - > orig_parent - > inst , QOF_EVENT_MODIFY ,
2006-04-10 22:12:09 -05:00
NULL ) ;
2006-03-03 18:09:03 -06:00
}
2010-03-02 15:40:28 -06:00
if ( s - > lot )
{
2006-03-03 18:09:03 -06:00
/* A change of value/amnt affects gains display, etc. */
2010-02-27 09:54:20 -06:00
qof_event_gen ( QOF_INSTANCE ( s - > lot ) , QOF_EVENT_MODIFY , NULL ) ;
2006-03-03 18:09:03 -06:00
}
/* Important: we save off the original parent transaction and account
so that when we commit , we can generate signals for both the
original and new transactions , for the _next_ begin / commit cycle . */
s - > orig_acc = s - > acc ;
s - > orig_parent = s - > parent ;
2010-10-29 03:39:29 -05:00
if ( ! qof_commit_edit_part2 ( QOF_INSTANCE ( s ) , commit_err , NULL ,
( void ( * ) ( QofInstance * ) ) xaccFreeSplit ) )
return ;
2006-05-07 23:56:17 -05:00
2010-03-02 15:40:28 -06:00
if ( acc )
{
2007-04-17 23:50:34 -05:00
g_object_set ( acc , " sort-dirty " , TRUE , " balance-dirty " , TRUE , NULL ) ;
xaccAccountRecomputeBalance ( acc ) ;
}
2006-03-03 18:09:03 -06:00
}
/* An engine-private helper for completing xaccTransRollbackEdit(). */
void
xaccSplitRollbackEdit ( Split * s )
{
2006-04-10 22:12:09 -05:00
/* Don't use setters because we want to allow NULL. This is legit
only because we don ' t emit events for changing accounts until
the final commit . */
if ( s - > acc ! = s - > orig_acc )
2010-03-02 15:40:28 -06:00
s - > acc = s - > orig_acc ;
2006-04-10 22:12:09 -05:00
/* Undestroy if needed */
2010-03-02 15:40:28 -06:00
if ( qof_instance_get_destroying ( s ) & & s - > parent )
{
2006-04-10 22:12:09 -05:00
GncEventData ed ;
2007-04-30 00:33:33 -05:00
qof_instance_set_destroying ( s , FALSE ) ;
2006-04-10 22:12:09 -05:00
ed . node = s ;
ed . idx = - 1 ; /* unused */
2007-04-01 17:18:50 -05:00
qof_event_gen ( & s - > parent - > inst , GNC_EVENT_ITEM_ADDED , & ed ) ;
2006-04-10 22:12:09 -05:00
}
/* But for the parent trans, we want the intermediate events, so
we use the setter . */
xaccSplitSetParent ( s , s - > orig_parent ) ;
2006-03-03 18:09:03 -06:00
}
2006-02-22 15:52:46 -06:00
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Split *
2010-03-27 16:01:21 -05:00
xaccSplitLookup ( const GncGUID * guid , QofBook * book )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
QofCollection * col ;
if ( ! guid | | ! book ) return NULL ;
col = qof_book_get_collection ( book , GNC_ID_SPLIT ) ;
return ( Split * ) qof_collection_lookup_entity ( col , guid ) ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Routines for marking splits dirty, and for sending out change
* events . Note that we can ' t just mark - n - generate - event in one
* step , since sometimes we need to mark things up before its suitable
* to send out a change event .
*/
/* CHECKME: This function modifies the Split without dirtying or
checking its parent . Is that correct ? */
void
xaccSplitDetermineGainStatus ( Split * split )
{
2010-03-02 15:40:28 -06:00
Split * other ;
2015-05-08 17:15:39 -05:00
GValue v = G_VALUE_INIT ;
2015-06-04 15:29:01 -05:00
GncGUID * guid = NULL ;
2010-03-02 15:40:28 -06:00
if ( GAINS_STATUS_UNKNOWN ! = split - > gains ) return ;
other = xaccSplitGetCapGainsSplit ( split ) ;
if ( other )
{
split - > gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY ;
split - > gains_split = other ;
return ;
}
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , & v , 1 , " gains-source " ) ;
2015-06-04 15:29:01 -05:00
if ( G_VALUE_HOLDS_BOXED ( & v ) )
guid = ( GncGUID * ) g_value_get_boxed ( & v ) ;
2015-05-08 17:15:39 -05:00
if ( ! guid )
2010-03-02 15:40:28 -06:00
{
// CHECKME: We leave split->gains_split alone. Is that correct?
split - > gains = GAINS_STATUS_A_VDIRTY | GAINS_STATUS_DATE_DIRTY ;
}
else
{
QofCollection * col ;
2015-05-08 17:15:39 -05:00
col = qof_book_get_collection ( qof_instance_get_book ( split ) ,
GNC_ID_SPLIT ) ;
2010-03-02 15:40:28 -06:00
split - > gains = GAINS_STATUS_GAINS ;
2015-05-08 17:15:39 -05:00
other = ( Split * ) qof_collection_lookup_entity ( col , guid ) ;
2010-03-02 15:40:28 -06:00
split - > gains_split = other ;
}
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static inline int
get_currency_denom ( const Split * s )
{
if ( ! s )
{
return 0 ;
}
2010-03-02 15:40:28 -06:00
else if ( ! s - > parent | | ! s - > parent - > common_currency )
2006-02-22 15:52:46 -06:00
{
2018-09-21 14:29:56 -05:00
return GNC_COMMODITY_MAX_FRACTION ;
2006-02-22 15:52:46 -06:00
}
else
{
return gnc_commodity_get_fraction ( s - > parent - > common_currency ) ;
}
}
static inline int
2010-03-02 15:40:28 -06:00
get_commodity_denom ( const Split * s )
2006-02-22 15:52:46 -06:00
{
if ( ! s )
{
return 0 ;
}
else if ( ! s - > acc )
{
2018-09-21 14:29:56 -05:00
return GNC_COMMODITY_MAX_FRACTION ;
2006-02-22 15:52:46 -06:00
}
else
{
return xaccAccountGetCommoditySCU ( s - > acc ) ;
}
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-03-02 15:40:28 -06:00
void
2006-02-22 15:52:46 -06:00
xaccSplitSetSharePriceAndAmount ( Split * s , gnc_numeric price , gnc_numeric amt )
{
2010-03-02 15:40:28 -06:00
if ( ! s ) return ;
ENTER ( " " ) ;
xaccTransBeginEdit ( s - > parent ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
s - > amount = gnc_numeric_convert ( amt , get_commodity_denom ( s ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
s - > value = gnc_numeric_mul ( s - > amount , price ,
2010-10-23 05:38:48 -05:00
get_currency_denom ( s ) , GNC_HOW_RND_ROUND_HALF_UP ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
SET_GAINS_A_VDIRTY ( s ) ;
mark_split ( s ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
xaccTransCommitEdit ( s - > parent ) ;
LEAVE ( " " ) ;
2006-02-22 15:52:46 -06:00
}
static void
qofSplitSetSharePrice ( Split * split , gnc_numeric price )
{
2010-03-02 15:40:28 -06:00
g_return_if_fail ( split ) ;
split - > value = gnc_numeric_mul ( xaccSplitGetAmount ( split ) ,
price , get_currency_denom ( split ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
}
void
xaccSplitSetSharePrice ( Split * s , gnc_numeric price )
{
if ( ! s ) return ;
ENTER ( " " ) ;
xaccTransBeginEdit ( s - > parent ) ;
s - > value = gnc_numeric_mul ( xaccSplitGetAmount ( s ) ,
price , get_currency_denom ( s ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
SET_GAINS_VDIRTY ( s ) ;
mark_split ( s ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
xaccTransCommitEdit ( s - > parent ) ;
LEAVE ( " " ) ;
}
2006-02-22 15:52:46 -06:00
static void
qofSplitSetAmount ( Split * split , gnc_numeric amt )
{
2010-03-02 15:40:28 -06:00
g_return_if_fail ( split ) ;
if ( split - > acc )
{
split - > amount = gnc_numeric_convert ( amt ,
2010-10-23 05:38:48 -05:00
get_commodity_denom ( split ) , GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
}
else
{
split - > amount = amt ;
}
2006-02-22 15:52:46 -06:00
}
/* The amount of the split in the _account's_ commodity. */
2010-03-02 15:40:28 -06:00
void
xaccSplitSetAmount ( Split * s , gnc_numeric amt )
{
if ( ! s ) return ;
g_return_if_fail ( gnc_numeric_check ( amt ) = = GNC_ERROR_OK ) ;
ENTER ( " (split=%p) old amt=% " G_GINT64_FORMAT " /% " G_GINT64_FORMAT
" new amt=% " G_GINT64_FORMAT " /% " G_GINT64_FORMAT , s ,
s - > amount . num , s - > amount . denom , amt . num , amt . denom ) ;
xaccTransBeginEdit ( s - > parent ) ;
if ( s - > acc )
2014-12-03 12:11:35 -06:00
{
2010-03-02 15:40:28 -06:00
s - > amount = gnc_numeric_convert ( amt , get_commodity_denom ( s ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2014-12-03 12:11:35 -06:00
g_assert ( gnc_numeric_check ( s - > amount ) = = GNC_ERROR_OK ) ;
}
2010-03-02 15:40:28 -06:00
else
2015-05-31 19:59:01 -05:00
s - > amount = amt ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
SET_GAINS_ADIRTY ( s ) ;
mark_split ( s ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
xaccTransCommitEdit ( s - > parent ) ;
LEAVE ( " " ) ;
2006-02-22 15:52:46 -06:00
}
static void
qofSplitSetValue ( Split * split , gnc_numeric amt )
{
2010-03-02 15:40:28 -06:00
g_return_if_fail ( split ) ;
split - > value = gnc_numeric_convert ( amt ,
2010-10-23 05:38:48 -05:00
get_currency_denom ( split ) , GNC_HOW_RND_ROUND_HALF_UP ) ;
2014-12-03 12:11:35 -06:00
g_assert ( gnc_numeric_check ( split - > value ) ! = GNC_ERROR_OK ) ;
2006-02-22 15:52:46 -06:00
}
/* The value of the split in the _transaction's_ currency. */
2010-03-02 15:40:28 -06:00
void
xaccSplitSetValue ( Split * s , gnc_numeric amt )
{
gnc_numeric new_val ;
if ( ! s ) return ;
g_return_if_fail ( gnc_numeric_check ( amt ) = = GNC_ERROR_OK ) ;
ENTER ( " (split=%p) old val=% " G_GINT64_FORMAT " /% " G_GINT64_FORMAT
" new val=% " G_GINT64_FORMAT " /% " G_GINT64_FORMAT , s ,
s - > value . num , s - > value . denom , amt . num , amt . denom ) ;
xaccTransBeginEdit ( s - > parent ) ;
new_val = gnc_numeric_convert ( amt , get_currency_denom ( s ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2014-12-03 12:11:35 -06:00
if ( gnc_numeric_check ( new_val ) = = GNC_ERROR_OK & &
! ( gnc_numeric_zero_p ( new_val ) & & ! gnc_numeric_zero_p ( amt ) ) )
2010-03-02 15:40:28 -06:00
s - > value = new_val ;
2014-03-29 18:02:26 -05:00
else PERR ( " numeric error %s in converting the split value's denominator with amount %s and denom %d " , gnc_numeric_errorCode_to_string ( gnc_numeric_check ( new_val ) ) , gnc_numeric_to_string ( amt ) , get_currency_denom ( s ) ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
SET_GAINS_VDIRTY ( s ) ;
mark_split ( s ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
xaccTransCommitEdit ( s - > parent ) ;
LEAVE ( " " ) ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-03-02 15:40:28 -06:00
gnc_numeric
xaccSplitGetBalance ( const Split * s )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
return s ? s - > balance : gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
2010-03-02 15:40:28 -06:00
gnc_numeric
xaccSplitGetClearedBalance ( const Split * s )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
return s ? s - > cleared_balance : gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
2010-03-02 15:40:28 -06:00
gnc_numeric
xaccSplitGetReconciledBalance ( const Split * s )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
return s ? s - > reconciled_balance : gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
void
2010-03-02 15:40:28 -06:00
xaccSplitSetBaseValue ( Split * s , gnc_numeric value ,
2006-02-22 15:52:46 -06:00
const gnc_commodity * base_currency )
{
2010-03-02 15:40:28 -06:00
const gnc_commodity * currency ;
const gnc_commodity * commodity ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! s ) return ;
xaccTransBeginEdit ( s - > parent ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! s - > acc )
{
PERR ( " split must have a parent account " ) ;
return ;
}
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
currency = xaccTransGetCurrency ( s - > parent ) ;
commodity = xaccAccountGetCommodity ( s - > acc ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* If the base_currency is the transaction's commodity ('currency'),
* set the value . If it ' s the account commodity , set the
* amount . If both , set both . */
if ( gnc_commodity_equiv ( currency , base_currency ) )
{
if ( gnc_commodity_equiv ( commodity , base_currency ) )
{
s - > amount = gnc_numeric_convert ( value ,
get_commodity_denom ( s ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
}
s - > value = gnc_numeric_convert ( value ,
get_currency_denom ( s ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
}
else if ( gnc_commodity_equiv ( commodity , base_currency ) )
{
s - > amount = gnc_numeric_convert ( value , get_commodity_denom ( s ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
}
else
{
PERR ( " inappropriate base currency %s "
" given split currency=%s and commodity=%s \n " ,
gnc_commodity_get_printname ( base_currency ) ,
gnc_commodity_get_printname ( currency ) ,
gnc_commodity_get_printname ( commodity ) ) ;
return ;
2006-02-22 15:52:46 -06:00
}
2010-03-02 15:40:28 -06:00
SET_GAINS_A_VDIRTY ( s ) ;
mark_split ( s ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
xaccTransCommitEdit ( s - > parent ) ;
2006-02-22 15:52:46 -06:00
}
gnc_numeric
xaccSplitGetBaseValue ( const Split * s , const gnc_commodity * base_currency )
{
2010-03-02 15:40:28 -06:00
if ( ! s | | ! s - > acc | | ! s - > parent ) return gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* be more precise -- the value depends on the currency we want it
* expressed in . */
if ( gnc_commodity_equiv ( xaccTransGetCurrency ( s - > parent ) , base_currency ) )
return xaccSplitGetValue ( s ) ;
if ( gnc_commodity_equiv ( xaccAccountGetCommodity ( s - > acc ) , base_currency ) )
return xaccSplitGetAmount ( s ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
PERR ( " inappropriate base currency %s "
" given split currency=%s and commodity=%s \n " ,
gnc_commodity_get_printname ( base_currency ) ,
gnc_commodity_get_printname ( xaccTransGetCurrency ( s - > parent ) ) ,
gnc_commodity_get_printname ( xaccAccountGetCommodity ( s - > acc ) ) ) ;
return gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
gnc_numeric
2010-03-07 15:28:15 -06:00
xaccSplitConvertAmount ( const Split * split , const Account * account )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
gnc_commodity * acc_com , * to_commodity ;
Transaction * txn ;
gnc_numeric amount , value , convrate ;
Account * split_acc ;
amount = xaccSplitGetAmount ( split ) ;
/* If this split is attached to this account, OR */
split_acc = xaccSplitGetAccount ( split ) ;
if ( split_acc = = account )
return amount ;
/* If split->account->commodity == to_commodity, return the amount */
acc_com = xaccAccountGetCommodity ( split_acc ) ;
to_commodity = xaccAccountGetCommodity ( account ) ;
if ( acc_com & & gnc_commodity_equal ( acc_com , to_commodity ) )
return amount ;
/* Ok, this split is not for the viewed account, and the commodity
* does not match . So we need to do some conversion .
*
* First , we can cheat . If this transaction is balanced and has
* exactly two splits , then we can implicitly determine the exchange
* rate and just return the ' other ' split amount .
*/
txn = xaccSplitGetParent ( split ) ;
if ( txn & & xaccTransIsBalanced ( txn ) )
2006-12-03 21:09:24 -06:00
{
2010-03-02 15:40:28 -06:00
const Split * osplit = xaccSplitGetOtherSplit ( split ) ;
if ( osplit )
{
gnc_commodity * split_comm =
xaccAccountGetCommodity ( xaccSplitGetAccount ( osplit ) ) ;
if ( ! gnc_commodity_equal ( to_commodity , split_comm ) )
{
2014-07-25 16:02:44 -05:00
gchar guidstr [ GUID_ENCODING_LENGTH + 1 ] ;
guid_to_string_buff ( xaccSplitGetGUID ( osplit ) , guidstr ) ;
2010-03-02 15:40:28 -06:00
PERR ( " The split's (%s) amount can't be converted from %s into %s. " ,
2014-07-25 16:02:44 -05:00
guidstr ,
2010-03-02 15:40:28 -06:00
gnc_commodity_get_mnemonic ( split_comm ) ,
gnc_commodity_get_mnemonic ( to_commodity )
) ;
return gnc_numeric_zero ( ) ;
}
return gnc_numeric_neg ( xaccSplitGetAmount ( osplit ) ) ;
2006-12-03 20:20:01 -06:00
}
2006-12-03 21:09:24 -06:00
}
2010-03-02 15:40:28 -06:00
/* ... otherwise, we need to compute the amount from the conversion
* rate into _this account_ . So , find the split into this account ,
* compute the conversion rate ( based on amount / value ) , and then multiply
* this times the split value .
*/
value = xaccSplitGetValue ( split ) ;
if ( gnc_numeric_zero_p ( value ) )
{
return value ;
}
convrate = xaccTransGetAccountConvRate ( txn , account ) ;
return gnc_numeric_mul ( value , convrate ,
gnc_commodity_get_fraction ( to_commodity ) ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
gboolean
xaccSplitDestroy ( Split * split )
{
2010-03-02 15:40:28 -06:00
Account * acc ;
Transaction * trans ;
GncEventData ed ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! split ) return TRUE ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
acc = split - > acc ;
trans = split - > parent ;
if ( acc & & ! qof_instance_get_destroying ( acc )
2018-09-10 11:57:39 -05:00
& & ! qof_instance_get_destroying ( trans )
2015-05-31 19:59:01 -05:00
& & xaccTransGetReadOnly ( trans ) )
2010-03-02 15:40:28 -06:00
return FALSE ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
xaccTransBeginEdit ( trans ) ;
ed . node = split ;
ed . idx = xaccTransGetSplitIndex ( trans , split ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
qof_instance_set_destroying ( split , TRUE ) ;
qof_event_gen ( & trans - > inst , GNC_EVENT_ITEM_REMOVED , & ed ) ;
xaccTransCommitEdit ( trans ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return TRUE ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-04-05 21:31:28 -05:00
gint
xaccSplitOrder ( const Split * sa , const Split * sb )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
int retval ;
int comp ;
char * da , * db ;
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
gboolean action_for_num ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( sa = = sb ) return 0 ;
/* nothing is always less than something */
2011-09-01 01:50:32 -05:00
if ( ! sa ) return - 1 ;
if ( ! sb ) return + 1 ;
2006-02-22 15:52:46 -06:00
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
/* sort in transaction order, but use split action rather than trans num
* according to book option */
action_for_num = qof_book_use_split_action_for_num_field
2015-05-31 19:59:01 -05:00
( xaccSplitGetBook ( sa ) ) ;
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
if ( action_for_num )
retval = xaccTransOrder_num_action ( sa - > parent , sa - > action ,
sb - > parent , sb - > action ) ;
else
retval = xaccTransOrder ( sa - > parent , sb - > parent ) ;
2010-03-02 15:40:28 -06:00
if ( retval ) return retval ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* otherwise, sort on memo strings */
da = sa - > memo ? sa - > memo : " " ;
db = sb - > memo ? sb - > memo : " " ;
retval = g_utf8_collate ( da , db ) ;
if ( retval )
return retval ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* otherwise, sort on action strings */
da = sa - > action ? sa - > action : " " ;
db = sb - > action ? sb - > action : " " ;
retval = g_utf8_collate ( da , db ) ;
if ( retval ! = 0 )
return retval ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* the reconciled flag ... */
if ( sa - > reconciled < sb - > reconciled ) return - 1 ;
if ( sa - > reconciled > sb - > reconciled ) return + 1 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* compare amounts */
comp = gnc_numeric_compare ( xaccSplitGetAmount ( sa ) , xaccSplitGetAmount ( sb ) ) ;
if ( comp < 0 ) return - 1 ;
if ( comp > 0 ) return + 1 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
comp = gnc_numeric_compare ( xaccSplitGetValue ( sa ) , xaccSplitGetValue ( sb ) ) ;
if ( comp < 0 ) return - 1 ;
if ( comp > 0 ) return + 1 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* if dates differ, return */
2018-08-02 20:19:15 -05:00
if ( sa - > date_reconciled < sb - > date_reconciled )
return - 1 ;
else if ( sa - > date_reconciled > sb - > date_reconciled )
return 1 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* else, sort on guid - keeps sort stable. */
retval = qof_instance_guid_compare ( sa , sb ) ;
if ( retval ) return retval ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return 0 ;
2006-02-22 15:52:46 -06:00
}
2007-04-05 21:31:28 -05:00
gint
xaccSplitOrderDateOnly ( const Split * sa , const Split * sb )
{
2010-03-02 15:40:28 -06:00
Transaction * ta , * tb ;
2007-04-05 21:31:28 -05:00
2010-03-02 15:40:28 -06:00
if ( sa = = sb ) return 0 ;
/* nothing is always less than something */
2011-09-01 01:50:32 -05:00
if ( ! sa ) return - 1 ;
if ( ! sb ) return + 1 ;
2007-04-05 21:31:28 -05:00
2010-03-02 15:40:28 -06:00
ta = sa - > parent ;
tb = sb - > parent ;
if ( ! ta & & ! tb ) return 0 ;
2011-09-01 01:50:32 -05:00
if ( ! tb ) return - 1 ;
if ( ! ta ) return + 1 ;
2007-04-05 21:31:28 -05:00
2017-12-31 06:37:02 -06:00
if ( ta - > date_posted = = tb - > date_posted )
return - 1 ; // Keep the same order
return ( ta - > date_posted > tb - > date_posted ) - ( ta - > date_posted < tb - > date_posted ) ;
2007-04-05 21:31:28 -05:00
}
2006-02-22 15:52:46 -06:00
static gboolean
2006-02-23 11:44:42 -06:00
get_corr_account_split ( const Split * sa , const Split * * retval )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
* retval = NULL ;
g_return_val_if_fail ( sa , FALSE ) ;
2015-07-28 10:12:24 -05:00
if ( xaccTransCountSplits ( sa - > parent ) > 2 )
return FALSE ;
2010-03-02 15:40:28 -06:00
2015-07-28 10:12:24 -05:00
* retval = xaccSplitGetOtherSplit ( sa ) ;
if ( * retval )
return TRUE ;
else
return FALSE ;
2006-02-22 15:52:46 -06:00
}
/* TODO: these static consts can be shared. */
2011-11-18 15:53:28 -06:00
const char *
xaccSplitGetCorrAccountName ( const Split * sa )
{
static const char * split_const = NULL ;
const Split * other_split ;
if ( ! get_corr_account_split ( sa , & other_split ) )
{
if ( ! split_const )
split_const = _ ( " -- Split Transaction -- " ) ;
return split_const ;
}
return xaccAccountGetName ( other_split - > acc ) ;
}
2006-02-22 15:52:46 -06:00
char *
2006-03-02 01:20:33 -06:00
xaccSplitGetCorrAccountFullName ( const Split * sa )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
static const char * split_const = NULL ;
const Split * other_split ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! get_corr_account_split ( sa , & other_split ) )
{
if ( ! split_const )
split_const = _ ( " -- Split Transaction -- " ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return g_strdup ( split_const ) ;
}
return gnc_account_get_full_name ( other_split - > acc ) ;
2006-02-22 15:52:46 -06:00
}
const char *
xaccSplitGetCorrAccountCode ( const Split * sa )
{
2010-03-02 15:40:28 -06:00
static const char * split_const = NULL ;
const Split * other_split ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! get_corr_account_split ( sa , & other_split ) )
{
if ( ! split_const )
/* Translators: This string has a disambiguation prefix */
split_const = Q_ ( " Displayed account code of the other account in a multi-split transaction|Split " ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
return split_const ;
}
return xaccAccountGetCode ( other_split - > acc ) ;
2006-02-22 15:52:46 -06:00
}
/* TODO: It's not too hard to make this function avoid the malloc/free. */
2010-03-02 15:40:28 -06:00
int
2006-02-22 15:52:46 -06:00
xaccSplitCompareAccountFullNames ( const Split * sa , const Split * sb )
{
2010-03-02 15:40:28 -06:00
Account * aa , * ab ;
char * full_a , * full_b ;
int retval ;
if ( ! sa & & ! sb ) return 0 ;
if ( ! sa ) return - 1 ;
if ( ! sb ) return 1 ;
aa = sa - > acc ;
ab = sb - > acc ;
full_a = gnc_account_get_full_name ( aa ) ;
full_b = gnc_account_get_full_name ( ab ) ;
retval = g_utf8_collate ( full_a , full_b ) ;
g_free ( full_a ) ;
g_free ( full_b ) ;
return retval ;
2006-02-22 15:52:46 -06:00
}
2010-03-02 15:40:28 -06:00
int
2006-02-22 15:52:46 -06:00
xaccSplitCompareAccountCodes ( const Split * sa , const Split * sb )
{
2010-03-02 15:40:28 -06:00
Account * aa , * ab ;
if ( ! sa & & ! sb ) return 0 ;
if ( ! sa ) return - 1 ;
if ( ! sb ) return 1 ;
aa = sa - > acc ;
ab = sb - > acc ;
2006-02-22 15:52:46 -06:00
2012-08-07 12:24:55 -05:00
return g_strcmp0 ( xaccAccountGetCode ( aa ) , xaccAccountGetCode ( ab ) ) ;
2006-02-22 15:52:46 -06:00
}
2010-03-02 15:40:28 -06:00
int
2006-02-22 15:52:46 -06:00
xaccSplitCompareOtherAccountFullNames ( const Split * sa , const Split * sb )
{
2010-03-02 15:40:28 -06:00
char * ca , * cb ;
int retval ;
if ( ! sa & & ! sb ) return 0 ;
if ( ! sa ) return - 1 ;
if ( ! sb ) return 1 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
/* doesn't matter what separator we use
* as long as they are the same
*/
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
ca = xaccSplitGetCorrAccountFullName ( sa ) ;
cb = xaccSplitGetCorrAccountFullName ( sb ) ;
2012-08-07 12:24:55 -05:00
retval = g_strcmp0 ( ca , cb ) ;
2010-03-02 15:40:28 -06:00
g_free ( ca ) ;
g_free ( cb ) ;
return retval ;
2006-02-22 15:52:46 -06:00
}
int
xaccSplitCompareOtherAccountCodes ( const Split * sa , const Split * sb )
{
2010-03-02 15:40:28 -06:00
const char * ca , * cb ;
if ( ! sa & & ! sb ) return 0 ;
if ( ! sa ) return - 1 ;
if ( ! sb ) return 1 ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
ca = xaccSplitGetCorrAccountCode ( sa ) ;
cb = xaccSplitGetCorrAccountCode ( sb ) ;
2012-08-07 12:24:55 -05:00
return g_strcmp0 ( ca , cb ) ;
2006-02-22 15:52:46 -06:00
}
static void
qofSplitSetMemo ( Split * split , const char * memo )
{
2006-02-23 11:44:42 -06:00
g_return_if_fail ( split ) ;
CACHE_REPLACE ( split - > memo , memo ) ;
2006-02-22 15:52:46 -06:00
}
void
xaccSplitSetMemo ( Split * split , const char * memo )
{
2010-03-02 15:40:28 -06:00
if ( ! split | | ! memo ) return ;
xaccTransBeginEdit ( split - > parent ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
CACHE_REPLACE ( split - > memo , memo ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccTransCommitEdit ( split - > parent ) ;
2006-03-03 18:09:03 -06:00
2006-02-22 15:52:46 -06:00
}
static void
qofSplitSetAction ( Split * split , const char * actn )
{
2010-03-02 15:40:28 -06:00
g_return_if_fail ( split ) ;
CACHE_REPLACE ( split - > action , actn ) ;
2006-02-22 15:52:46 -06:00
}
void
xaccSplitSetAction ( Split * split , const char * actn )
{
2010-03-02 15:40:28 -06:00
if ( ! split | | ! actn ) return ;
xaccTransBeginEdit ( split - > parent ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
CACHE_REPLACE ( split - > action , actn ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccTransCommitEdit ( split - > parent ) ;
2006-03-03 18:09:03 -06:00
2006-02-22 15:52:46 -06:00
}
static void
qofSplitSetReconcile ( Split * split , char recn )
{
2010-03-02 15:40:28 -06:00
g_return_if_fail ( split ) ;
switch ( recn )
{
2015-05-31 19:59:01 -05:00
case NREC :
case CREC :
case YREC :
case FREC :
case VREC :
split - > reconciled = recn ;
mark_split ( split ) ;
xaccAccountRecomputeBalance ( split - > acc ) ;
break ;
default :
PERR ( " Bad reconciled flag " ) ;
break ;
2010-03-02 15:40:28 -06:00
}
2006-02-22 15:52:46 -06:00
}
void
xaccSplitSetReconcile ( Split * split , char recn )
{
2010-03-02 15:40:28 -06:00
if ( ! split | | split - > reconciled = = recn ) return ;
xaccTransBeginEdit ( split - > parent ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
switch ( recn )
{
2015-05-31 19:59:01 -05:00
case NREC :
case CREC :
case YREC :
case FREC :
case VREC :
split - > reconciled = recn ;
mark_split ( split ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccAccountRecomputeBalance ( split - > acc ) ;
break ;
default :
PERR ( " Bad reconciled flag " ) ;
break ;
2010-03-02 15:40:28 -06:00
}
xaccTransCommitEdit ( split - > parent ) ;
2006-03-03 18:09:03 -06:00
2006-02-22 15:52:46 -06:00
}
void
2012-12-01 16:44:53 -06:00
xaccSplitSetDateReconciledSecs ( Split * split , time64 secs )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
if ( ! split ) return ;
xaccTransBeginEdit ( split - > parent ) ;
2006-02-22 15:52:46 -06:00
2018-08-02 20:19:15 -05:00
split - > date_reconciled = secs ;
2010-03-02 15:40:28 -06:00
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccTransCommitEdit ( split - > parent ) ;
2006-03-03 18:09:03 -06:00
2006-02-22 15:52:46 -06:00
}
2013-08-02 12:55:10 -05:00
/*################## Added for Reg2 #################*/
time64
xaccSplitGetDateReconciled ( const Split * split )
{
2018-08-02 20:19:15 -05:00
return split ? split - > date_reconciled : 0 ;
2013-08-02 12:55:10 -05:00
}
/*################## Added for Reg2 #################*/
2006-02-22 15:52:46 -06:00
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* return the parent transaction of the split */
2010-03-02 15:40:28 -06:00
Transaction *
2006-02-22 15:52:46 -06:00
xaccSplitGetParent ( const Split * split )
{
2010-03-02 15:40:28 -06:00
return split ? split - > parent : NULL ;
2006-02-22 15:52:46 -06:00
}
2006-03-03 18:09:03 -06:00
void
xaccSplitSetParent ( Split * s , Transaction * t )
{
Transaction * old_trans ;
2006-04-10 22:12:09 -05:00
GncEventData ed ;
g_return_if_fail ( s ) ;
2006-03-03 18:09:03 -06:00
if ( s - > parent = = t ) return ;
2006-04-10 22:12:09 -05:00
if ( s - > parent ! = s - > orig_parent & & s - > orig_parent ! = t )
2006-03-03 18:09:03 -06:00
PERR ( " You may not add the split to more than one transaction "
" during the BeginEdit/CommitEdit block. " ) ;
xaccTransBeginEdit ( t ) ;
old_trans = s - > parent ;
2006-04-10 22:12:09 -05:00
2006-03-03 18:09:03 -06:00
xaccTransBeginEdit ( old_trans ) ;
2006-04-10 22:12:09 -05:00
ed . node = s ;
2010-03-02 15:40:28 -06:00
if ( old_trans )
{
2006-04-10 22:12:09 -05:00
ed . idx = xaccTransGetSplitIndex ( old_trans , s ) ;
2007-04-01 17:18:50 -05:00
qof_event_gen ( & old_trans - > inst , GNC_EVENT_ITEM_REMOVED , & ed ) ;
2006-04-10 22:12:09 -05:00
}
2006-03-03 18:09:03 -06:00
s - > parent = t ;
xaccTransCommitEdit ( old_trans ) ;
2006-04-10 22:12:09 -05:00
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
2010-03-02 15:40:28 -06:00
if ( t )
{
2006-04-10 22:12:09 -05:00
/* Convert split to new transaction's commodity denominator */
xaccSplitSetValue ( s , xaccSplitGetValue ( s ) ) ;
2010-03-02 15:40:28 -06:00
2006-04-10 22:12:09 -05:00
/* add ourselves to the new transaction's list of pending splits. */
if ( NULL = = g_list_find ( t - > splits , s ) )
t - > splits = g_list_append ( t - > splits , s ) ;
2010-03-02 15:40:28 -06:00
2006-04-10 22:12:09 -05:00
ed . idx = - 1 ; /* unused */
2007-04-01 17:18:50 -05:00
qof_event_gen ( & t - > inst , GNC_EVENT_ITEM_ADDED , & ed ) ;
2006-04-10 22:12:09 -05:00
}
2006-03-03 18:09:03 -06:00
xaccTransCommitEdit ( t ) ;
}
2006-02-22 15:52:46 -06:00
GNCLot *
xaccSplitGetLot ( const Split * split )
{
2010-03-02 15:40:28 -06:00
return split ? split - > lot : NULL ;
2006-02-22 15:52:46 -06:00
}
2008-08-01 11:02:07 -05:00
void
xaccSplitSetLot ( Split * split , GNCLot * lot )
{
2010-03-02 15:40:28 -06:00
xaccTransBeginEdit ( split - > parent ) ;
split - > lot = lot ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccTransCommitEdit ( split - > parent ) ;
2008-08-01 11:02:07 -05:00
}
2006-02-22 15:52:46 -06:00
const char *
xaccSplitGetMemo ( const Split * split )
{
2010-03-02 15:40:28 -06:00
return split ? split - > memo : NULL ;
2006-02-22 15:52:46 -06:00
}
const char *
xaccSplitGetAction ( const Split * split )
{
2010-03-02 15:40:28 -06:00
return split ? split - > action : NULL ;
2006-02-22 15:52:46 -06:00
}
2010-03-02 15:40:28 -06:00
char
xaccSplitGetReconcile ( const Split * split )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
return split ? split - > reconciled : ' ' ;
2006-02-22 15:52:46 -06:00
}
gnc_numeric
xaccSplitGetAmount ( const Split * split )
{
2010-03-02 15:40:28 -06:00
return split ? split - > amount : gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
gnc_numeric
2010-03-02 15:40:28 -06:00
xaccSplitGetValue ( const Split * split )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
return split ? split - > value : gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
gnc_numeric
2010-03-02 15:40:28 -06:00
xaccSplitGetSharePrice ( const Split * split )
{
gnc_numeric amt , val , price ;
if ( ! split ) return gnc_numeric_create ( 1 , 1 ) ;
/* if amount == 0 and value == 0, then return 1.
* if amount = = 0 and value ! = 0 then return 0.
* otherwise return value / amount
*/
amt = xaccSplitGetAmount ( split ) ;
val = xaccSplitGetValue ( split ) ;
if ( gnc_numeric_zero_p ( amt ) )
{
if ( gnc_numeric_zero_p ( val ) )
return gnc_numeric_create ( 1 , 1 ) ;
return gnc_numeric_create ( 0 , 1 ) ;
}
price = gnc_numeric_div ( val , amt ,
GNC_DENOM_AUTO ,
2010-10-23 05:38:48 -05:00
GNC_HOW_RND_ROUND_HALF_UP ) ;
2010-03-02 15:40:28 -06:00
/* During random checks we can get some very weird prices. Let's
* handle some overflow and other error conditions by returning
* zero . But still print an error to let us know it happened .
*/
if ( gnc_numeric_check ( price ) )
{
PERR ( " Computing share price failed (%d): [ % " G_GINT64_FORMAT " / % "
G_GINT64_FORMAT " ] / [ % " G_GINT64_FORMAT " / % " G_GINT64_FORMAT " ] " ,
gnc_numeric_check ( price ) , val . num , val . denom , amt . num , amt . denom ) ;
return gnc_numeric_create ( 0 , 1 ) ;
}
return price ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
QofBook *
xaccSplitGetBook ( const Split * split )
{
return qof_instance_get_book ( QOF_INSTANCE ( split ) ) ;
}
const char *
xaccSplitGetType ( const Split * s )
{
2015-05-08 17:15:39 -05:00
GValue v = G_VALUE_INIT ;
2015-06-04 15:29:01 -05:00
const char * split_type = NULL ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! s ) return NULL ;
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( s ) , & v , 1 , " split-type " ) ;
2015-06-04 15:29:01 -05:00
if ( G_VALUE_HOLDS_STRING ( & v ) )
split_type = g_value_get_string ( & v ) ;
2010-03-02 15:40:28 -06:00
return split_type ? split_type : " normal " ;
2006-02-22 15:52:46 -06:00
}
/* reconfigure a split to be a stock split - after this, you shouldn't
mess with the value , just the amount . */
void
xaccSplitMakeStockSplit ( Split * s )
{
2015-05-08 17:15:39 -05:00
GValue v = G_VALUE_INIT ;
2010-03-02 15:40:28 -06:00
xaccTransBeginEdit ( s - > parent ) ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
s - > value = gnc_numeric_zero ( ) ;
2015-05-08 17:15:39 -05:00
g_value_init ( & v , G_TYPE_STRING ) ;
g_value_set_string ( & v , " stock-split " ) ;
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( s ) , & v , 1 , " split-type " ) ;
2010-03-02 15:40:28 -06:00
SET_GAINS_VDIRTY ( s ) ;
mark_split ( s ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( s ) ) ;
xaccTransCommitEdit ( s - > parent ) ;
2006-02-22 15:52:46 -06:00
}
2015-05-31 19:59:01 -05:00
void
xaccSplitAddPeerSplit ( Split * split , const Split * other_split ,
time64 timestamp )
{
const GncGUID * guid ;
g_return_if_fail ( split ! = NULL ) ;
g_return_if_fail ( other_split ! = NULL ) ;
guid = qof_instance_get_guid ( QOF_INSTANCE ( other_split ) ) ;
xaccTransBeginEdit ( split - > parent ) ;
qof_instance_kvp_add_guid ( QOF_INSTANCE ( split ) , " lot-split " ,
2018-08-02 20:19:15 -05:00
gnc_time ( NULL ) , " peer_guid " , guid_copy ( guid ) ) ;
2015-05-31 19:59:01 -05:00
mark_split ( split ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccTransCommitEdit ( split - > parent ) ;
}
gboolean
xaccSplitHasPeers ( const Split * split )
{
return qof_instance_has_slot ( QOF_INSTANCE ( split ) , " lot-split " ) ;
}
gboolean
xaccSplitIsPeerSplit ( const Split * split , const Split * other_split )
{
const GncGUID * guid ;
g_return_val_if_fail ( split ! = NULL , FALSE ) ;
g_return_val_if_fail ( other_split ! = NULL , FALSE ) ;
guid = qof_instance_get_guid ( QOF_INSTANCE ( other_split ) ) ;
return qof_instance_kvp_has_guid ( QOF_INSTANCE ( split ) , " lot-split " ,
" peer_guid " , guid ) ;
}
void
xaccSplitRemovePeerSplit ( Split * split , const Split * other_split )
{
const GncGUID * guid ;
g_return_if_fail ( split ! = NULL ) ;
g_return_if_fail ( other_split ! = NULL ) ;
guid = qof_instance_get_guid ( QOF_INSTANCE ( other_split ) ) ;
xaccTransBeginEdit ( split - > parent ) ;
qof_instance_kvp_remove_guid ( QOF_INSTANCE ( split ) , " lot-split " ,
" peer_guid " , guid ) ;
mark_split ( split ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccTransCommitEdit ( split - > parent ) ;
}
void
xaccSplitMergePeerSplits ( Split * split , const Split * other_split )
{
xaccTransBeginEdit ( split - > parent ) ;
qof_instance_kvp_merge_guids ( QOF_INSTANCE ( split ) ,
QOF_INSTANCE ( other_split ) , " lot-split " ) ;
mark_split ( split ) ;
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
xaccTransCommitEdit ( split - > parent ) ;
}
2006-02-22 15:52:46 -06:00
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* In the old world, the 'other split' was the other split of a
* transaction that contained only two splits . In the new world ,
* a split may have been cut up between multiple lots , although
* in a conceptual sense , if lots hadn ' t been used , there would be
* only a pair . So we handle this conceptual case : we can still
* identify , unambiguously , the ' other ' split when ' this ' split
2010-03-02 15:40:28 -06:00
* as been cut up across lots . We do this by looking for the
2006-02-22 15:52:46 -06:00
* ' lot - split ' keyword , which occurs only in cut - up splits .
*/
Split *
xaccSplitGetOtherSplit ( const Split * split )
{
2010-03-02 15:40:28 -06:00
int i ;
Transaction * trans ;
int count , num_splits ;
Split * other = NULL ;
2015-05-31 19:59:01 -05:00
gboolean lot_split ;
2010-03-02 15:40:28 -06:00
gboolean trading_accts ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! split ) return NULL ;
trans = split - > parent ;
if ( ! trans ) return NULL ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
trading_accts = xaccTransUseTradingAccounts ( trans ) ;
num_splits = xaccTransCountSplits ( trans ) ;
count = num_splits ;
2015-05-31 19:59:01 -05:00
lot_split = qof_instance_has_slot ( QOF_INSTANCE ( split ) , " lot-split " ) ;
2015-05-08 17:15:39 -05:00
if ( ! lot_split & & ! trading_accts & & ( 2 ! = count ) ) return NULL ;
2010-03-02 15:40:28 -06:00
for ( i = 0 ; i < num_splits ; i + + )
{
Split * s = xaccTransGetSplit ( trans , i ) ;
if ( s = = split )
{
- - count ;
continue ;
}
2015-05-31 19:59:01 -05:00
if ( qof_instance_has_slot ( QOF_INSTANCE ( s ) , " lot-split " ) )
2010-03-02 15:40:28 -06:00
{
- - count ;
continue ;
}
if ( trading_accts & &
2015-05-31 19:59:01 -05:00
xaccAccountGetType ( xaccSplitGetAccount ( s ) ) = = ACCT_TYPE_TRADING )
2010-03-02 15:40:28 -06:00
{
- - count ;
continue ;
}
other = s ;
}
return ( 1 = = count ) ? other : NULL ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
gnc_numeric
xaccSplitVoidFormerAmount ( const Split * split )
{
2015-05-08 17:15:39 -05:00
GValue v = G_VALUE_INIT ;
2015-06-04 15:29:01 -05:00
gnc_numeric * num = NULL ;
2010-03-02 15:40:28 -06:00
g_return_val_if_fail ( split , gnc_numeric_zero ( ) ) ;
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , & v , 1 , void_former_amt_str ) ;
2015-06-04 15:29:01 -05:00
if ( G_VALUE_HOLDS_BOXED ( & v ) )
num = ( gnc_numeric * ) g_value_get_boxed ( & v ) ;
2015-05-08 17:15:39 -05:00
return num ? * num : gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
gnc_numeric
xaccSplitVoidFormerValue ( const Split * split )
{
2015-05-08 17:15:39 -05:00
GValue v = G_VALUE_INIT ;
2015-06-04 15:29:01 -05:00
gnc_numeric * num = NULL ;
2010-03-02 15:40:28 -06:00
g_return_val_if_fail ( split , gnc_numeric_zero ( ) ) ;
2017-12-10 07:42:08 -06:00
qof_instance_get_kvp ( QOF_INSTANCE ( split ) , & v , 1 , void_former_val_str ) ;
2015-06-04 15:29:01 -05:00
if ( G_VALUE_HOLDS_BOXED ( & v ) )
num = ( gnc_numeric * ) g_value_get_boxed ( & v ) ;
2015-05-08 17:15:39 -05:00
return num ? * num : gnc_numeric_zero ( ) ;
2006-02-22 15:52:46 -06:00
}
void
xaccSplitVoid ( Split * split )
{
2015-05-08 17:15:39 -05:00
gnc_numeric zero = gnc_numeric_zero ( ) , num ;
GValue v = G_VALUE_INIT ;
2006-02-22 15:52:46 -06:00
2015-05-08 17:15:39 -05:00
g_value_init ( & v , GNC_TYPE_NUMERIC ) ;
num = xaccSplitGetAmount ( split ) ;
g_value_set_boxed ( & v , & num ) ;
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , & v , 1 , void_former_amt_str ) ;
2015-05-08 17:15:39 -05:00
num = xaccSplitGetValue ( split ) ;
g_value_set_boxed ( & v , & num ) ;
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , & v , 1 , void_former_val_str ) ;
2006-02-22 15:52:46 -06:00
2013-11-30 19:30:03 -06:00
/* Marking dirty handled by SetAmount etc. */
2006-02-22 15:52:46 -06:00
xaccSplitSetAmount ( split , zero ) ;
xaccSplitSetValue ( split , zero ) ;
xaccSplitSetReconcile ( split , VREC ) ;
}
void
xaccSplitUnvoid ( Split * split )
{
xaccSplitSetAmount ( split , xaccSplitVoidFormerAmount ( split ) ) ;
xaccSplitSetValue ( split , xaccSplitVoidFormerValue ( split ) ) ;
xaccSplitSetReconcile ( split , NREC ) ;
2017-12-10 07:42:08 -06:00
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , NULL , 1 , void_former_amt_str ) ;
qof_instance_set_kvp ( QOF_INSTANCE ( split ) , NULL , 1 , void_former_val_str ) ;
2013-11-30 19:30:03 -06:00
qof_instance_set_dirty ( QOF_INSTANCE ( split ) ) ;
2006-02-22 15:52:46 -06:00
}
/********************************************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* QofObject function implementation */
/* Hook into the QofObject registry */
2010-02-27 12:41:49 -06:00
# ifdef _MSC_VER
/* MSVC compiler doesn't have C99 "designated initializers"
* so we wrap them in a macro that is empty on MSVC . */
# define DI(x) /* */
# else
# define DI(x) x
# endif
2010-03-02 15:40:28 -06:00
static QofObject split_object_def =
{
DI ( . interface_version = ) QOF_OBJECT_VERSION ,
DI ( . e_type = ) GNC_ID_SPLIT ,
DI ( . type_label = ) " Split " ,
DI ( . create = ) ( gpointer ) xaccMallocSplit ,
DI ( . book_begin = ) NULL ,
DI ( . book_end = ) NULL ,
DI ( . is_dirty = ) qof_collection_is_dirty ,
DI ( . mark_clean = ) qof_collection_mark_clean ,
DI ( . foreach = ) qof_collection_foreach ,
DI ( . printable = ) ( const char * ( * ) ( gpointer ) ) xaccSplitGetMemo ,
DI ( . version_cmp = ) ( int ( * ) ( gpointer , gpointer ) ) qof_instance_version_cmp ,
2006-02-22 15:52:46 -06:00
} ;
2010-03-02 15:40:28 -06:00
static gpointer
2006-02-22 15:52:46 -06:00
split_account_guid_getter ( gpointer obj , const QofParam * p )
{
2010-03-02 15:40:28 -06:00
Split * s = obj ;
Account * acc ;
2006-02-22 15:52:46 -06:00
2010-03-02 15:40:28 -06:00
if ( ! s ) return NULL ;
acc = xaccSplitGetAccount ( s ) ;
if ( ! acc ) return NULL ;
return ( ( gpointer ) xaccAccountGetGUID ( acc ) ) ;
2006-02-22 15:52:46 -06:00
}
static double /* internal use only */
2010-03-02 15:40:28 -06:00
DxaccSplitGetShareAmount ( const Split * split )
2006-02-22 15:52:46 -06:00
{
2010-03-02 15:40:28 -06:00
return split ? gnc_numeric_to_double ( xaccSplitGetAmount ( split ) ) : 0.0 ;
2006-02-22 15:52:46 -06:00
}
2010-03-02 15:40:28 -06:00
static gpointer
2006-02-22 15:52:46 -06:00
no_op ( gpointer obj , const QofParam * p )
{
2010-03-02 15:40:28 -06:00
return obj ;
2006-02-22 15:52:46 -06:00
}
static void
2007-04-01 17:18:50 -05:00
qofSplitSetParentTrans ( Split * s , QofInstance * ent )
2006-02-22 15:52:46 -06:00
{
2006-03-03 18:09:03 -06:00
Transaction * trans = ( Transaction * ) ent ;
2006-02-22 15:52:46 -06:00
2006-03-03 18:09:03 -06:00
g_return_if_fail ( trans ) ;
xaccSplitSetParent ( s , trans ) ;
2006-02-22 15:52:46 -06:00
}
static void
2007-04-01 17:18:50 -05:00
qofSplitSetAccount ( Split * s , QofInstance * ent )
2006-02-22 15:52:46 -06:00
{
2006-03-03 18:09:03 -06:00
Account * acc = ( Account * ) ent ;
2006-02-22 15:52:46 -06:00
2006-03-03 18:09:03 -06:00
g_return_if_fail ( acc ) ;
xaccSplitSetAccount ( s , acc ) ;
2006-02-22 15:52:46 -06:00
}
gboolean xaccSplitRegister ( void )
{
2010-03-02 15:40:28 -06:00
static const QofParam params [ ] =
{
2015-05-31 19:59:01 -05:00
{
SPLIT_DATE_RECONCILED , QOF_TYPE_DATE ,
2018-04-26 08:48:06 -05:00
( QofAccessFunc ) xaccSplitGetDateReconciled ,
( QofSetterFunc ) xaccSplitSetDateReconciledSecs
2015-05-31 19:59:01 -05:00
} ,
2010-03-02 15:40:28 -06:00
2015-05-31 19:59:01 -05:00
/* d-* are deprecated query params, should not be used in new
* queries , should be removed from old queries . */
{
" d-share-amount " , QOF_TYPE_DOUBLE ,
( QofAccessFunc ) DxaccSplitGetShareAmount , NULL
} ,
{
" d-share-int64 " , QOF_TYPE_INT64 ,
( QofAccessFunc ) qof_entity_get_guid , NULL
} ,
{
SPLIT_BALANCE , QOF_TYPE_NUMERIC ,
( QofAccessFunc ) xaccSplitGetBalance , NULL
} ,
{
SPLIT_CLEARED_BALANCE , QOF_TYPE_NUMERIC ,
( QofAccessFunc ) xaccSplitGetClearedBalance , NULL
} ,
{
SPLIT_RECONCILED_BALANCE , QOF_TYPE_NUMERIC ,
( QofAccessFunc ) xaccSplitGetReconciledBalance , NULL
} ,
{
SPLIT_MEMO , QOF_TYPE_STRING ,
( QofAccessFunc ) xaccSplitGetMemo , ( QofSetterFunc ) qofSplitSetMemo
} ,
{
SPLIT_ACTION , QOF_TYPE_STRING ,
( QofAccessFunc ) xaccSplitGetAction , ( QofSetterFunc ) qofSplitSetAction
} ,
{
SPLIT_RECONCILE , QOF_TYPE_CHAR ,
( QofAccessFunc ) xaccSplitGetReconcile ,
( QofSetterFunc ) qofSplitSetReconcile
} ,
{
SPLIT_AMOUNT , QOF_TYPE_NUMERIC ,
( QofAccessFunc ) xaccSplitGetAmount , ( QofSetterFunc ) qofSplitSetAmount
} ,
{
SPLIT_SHARE_PRICE , QOF_TYPE_NUMERIC ,
( QofAccessFunc ) xaccSplitGetSharePrice ,
( QofSetterFunc ) qofSplitSetSharePrice
} ,
{
SPLIT_VALUE , QOF_TYPE_DEBCRED ,
( QofAccessFunc ) xaccSplitGetValue , ( QofSetterFunc ) qofSplitSetValue
} ,
{ SPLIT_TYPE , QOF_TYPE_STRING , ( QofAccessFunc ) xaccSplitGetType , NULL } ,
{
SPLIT_VOIDED_AMOUNT , QOF_TYPE_NUMERIC ,
( QofAccessFunc ) xaccSplitVoidFormerAmount , NULL
} ,
{
SPLIT_VOIDED_VALUE , QOF_TYPE_NUMERIC ,
( QofAccessFunc ) xaccSplitVoidFormerValue , NULL
} ,
{ SPLIT_LOT , GNC_ID_LOT , ( QofAccessFunc ) xaccSplitGetLot , NULL } ,
{
SPLIT_TRANS , GNC_ID_TRANS ,
( QofAccessFunc ) xaccSplitGetParent ,
( QofSetterFunc ) qofSplitSetParentTrans
} ,
{
SPLIT_ACCOUNT , GNC_ID_ACCOUNT ,
( QofAccessFunc ) xaccSplitGetAccount , ( QofSetterFunc ) qofSplitSetAccount
} ,
{ SPLIT_ACCOUNT_GUID , QOF_TYPE_GUID , split_account_guid_getter , NULL } ,
/* these are no-ops to register the parameter names (for sorting) but
they return an allocated object which getters cannot do . */
{ SPLIT_ACCT_FULLNAME , SPLIT_ACCT_FULLNAME , no_op , NULL } ,
{ SPLIT_CORR_ACCT_NAME , SPLIT_CORR_ACCT_NAME , no_op , NULL } ,
{ SPLIT_CORR_ACCT_CODE , SPLIT_CORR_ACCT_CODE , no_op , NULL } ,
{ QOF_PARAM_BOOK , QOF_ID_BOOK , ( QofAccessFunc ) xaccSplitGetBook , NULL } ,
{
QOF_PARAM_GUID , QOF_TYPE_GUID ,
( QofAccessFunc ) qof_entity_get_guid , NULL
} ,
{ NULL } ,
} ;
2010-03-02 15:40:28 -06:00
qof_class_register ( GNC_ID_SPLIT , ( QofSortFunc ) xaccSplitOrder , params ) ;
qof_class_register ( SPLIT_ACCT_FULLNAME ,
( QofSortFunc ) xaccSplitCompareAccountFullNames , NULL ) ;
qof_class_register ( SPLIT_CORR_ACCT_NAME ,
( QofSortFunc ) xaccSplitCompareOtherAccountFullNames ,
NULL ) ;
qof_class_register ( SPLIT_CORR_ACCT_CODE ,
( QofSortFunc ) xaccSplitCompareOtherAccountCodes , NULL ) ;
return qof_object_register ( & split_object_def ) ;
2006-02-22 15:52:46 -06:00
}
2012-03-31 17:12:36 -05:00
SplitTestFunctions *
_utest_split_fill_functions ( void )
{
SplitTestFunctions * func = g_new ( SplitTestFunctions , 1 ) ;
func - > xaccSplitEqualCheckBal = xaccSplitEqualCheckBal ;
func - > get_currency_denom = get_currency_denom ;
func - > get_commodity_denom = get_commodity_denom ;
func - > get_corr_account_split = get_corr_account_split ;
return func ;
}
2006-02-22 15:52:46 -06:00
/************************ END OF ************************************\
\ * * * * * * * * * * * * * * * * * * * * * * * * * FILE * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */